Commit 4e0f7dd4 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

old reaction.getCenterLine method removed

parent 2da95dd8
Pipeline #10421 failed with stage
in 8 minutes and 45 seconds
package lcsb.mapviewer.converter.model.sbgnml;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.HashMap;
......@@ -11,7 +10,8 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbgn.ArcClazz;
import org.sbgn.GlyphClazz;
import org.sbgn.Language;
......@@ -30,6 +30,7 @@ import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter;
import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.modifier.Catalysis;
......@@ -580,9 +581,9 @@ public class SbgnmlXmlExporter {
processGlyph.setClazz(getGlyphClazzFromReaction(reaction).getClazz());
Bbox bbox = new Bbox();
Line2D line = reaction.getCenterLine();
Point2D startPoint = line.getP1();
Point2D endPoint = line.getP2();
PolylineData line = reaction.getLine();
Point2D startPoint = line.getBeginPoint();
Point2D endPoint = line.getEndPoint();
double pointX = (startPoint.getX() + endPoint.getX()) / 2;
double pointY = (startPoint.getY() + endPoint.getY()) / 2;
......
......@@ -562,7 +562,7 @@ public class SbgnmlXmlParser {
productPointList.add(2, newPoint);
}
}
int reactantPointEnds = (productPointList.size()-1) / 2;
int reactantPointEnds = (productPointList.size() - 1) / 2;
int productPointStarts = reactantPointEnds + 1;
Reactant reactant = new Reactant(model.getElementByElementId(source.getId()));
......@@ -949,7 +949,7 @@ public class SbgnmlXmlParser {
ModifierTypeUtils utils = new ModifierTypeUtils();
Point2D result;
Line2D centerLine = reaction.getCenterLine();
Line2D centerLine = reaction.getLine().getLines().get(reaction.getLine().getLines().size() / 2);
double dx = centerLine.getX2() - centerLine.getX1();
double dy = centerLine.getY2() - centerLine.getY1();
double centerLineAngle = Math.atan2(dy, dx);
......
......@@ -6,11 +6,11 @@ import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D;
import java.util.List;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.geometry.EllipseTransformation;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
......
......@@ -12,11 +12,11 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import java.util.List;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.geometry.EllipseTransformation;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException;
......
......@@ -11,7 +11,8 @@ import java.awt.geom.Rectangle2D;
import java.util.ArrayList;
import java.util.List;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.commands.ColorExtractor;
import lcsb.mapviewer.common.Pair;
......@@ -70,8 +71,8 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
public static final ColorSchema DEFAULT_COLOR_SCHEMA = new GenericColorSchema();
/**
* Line width of #DEFAULT_COLOR_SCHEMA used for coloring reactions where we
* have more than one layout.
* Line width of #DEFAULT_COLOR_SCHEMA used for coloring reactions where we have
* more than one layout.
*/
private static final double DEFAULT_COLOR_SCHEMA_LINE_WIDTH = 3.0;
......@@ -115,8 +116,8 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
* Default constructor.
*
* @param colorExtractor
* Object that helps to convert {@link ColorSchema} values into
* colors when drawing {@link Reaction}
* Object that helps to convert {@link ColorSchema} values into colors
* when drawing {@link Reaction}
*/
public ReactionConverter(ColorExtractor colorExtractor) {
super();
......@@ -134,9 +135,33 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
* @param graphics
* where the rectangle should be drawn
*/
protected void drawRectangleData(final Line2D line, final ReactionRect insideType, final Graphics2D graphics) {
Point2D startPoint = line.getP1();
Point2D endPoint = line.getP2();
protected void drawRectangleData(final PolylineData line, final ReactionRect insideType, final Graphics2D graphics) {
Point2D startPoint = line.getPoints().get(line.getPoints().size() / 2 - 1);
Point2D endPoint = line.getPoints().get(line.getPoints().size() / 2);
if (startPoint.distance(endPoint) > RECT_SIZE) {
Point2D rectStartPoint = pointTransformation.getPointOnLine(startPoint, endPoint, 0.5 - RECT_SIZE/(2*startPoint.distance(endPoint)));
Point2D rectEndPoint = pointTransformation.getPointOnLine(startPoint, endPoint, 0.5 + RECT_SIZE/(2*startPoint.distance(endPoint)));
PolylineData preRectangleLine = new PolylineData();
preRectangleLine.addPoint(startPoint);
preRectangleLine.addPoint(rectStartPoint);
PolylineData postRectangleLine = new PolylineData();
postRectangleLine.addPoint(rectEndPoint);
postRectangleLine.addPoint(endPoint);
arrowTransformation.drawLine(preRectangleLine, graphics);
arrowTransformation.drawLine(postRectangleLine, graphics);
startPoint = rectStartPoint;
endPoint = rectEndPoint;
}
if (line.getPoints().size() > 2) {
PolylineData preRectangleLine = line.getSubline(0, line.getPoints().size() / 2);
PolylineData postRectangleLine = line.getSubline(line.getPoints().size() / 2, line.getPoints().size());
arrowTransformation.drawLine(preRectangleLine, graphics);
arrowTransformation.drawLine(postRectangleLine, graphics);
}
double pointX = (startPoint.getX() + endPoint.getX()) / 2;
double pointY = (startPoint.getY() + endPoint.getY()) / 2;
Point2D centerPoint = new Point2D.Double(pointX, pointY);
......@@ -146,10 +171,10 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
if (insideType == null) {
Point2D topPoint = new Point2D.Double(pointX + RECT_SIZE / 2, pointY);
topPoint = new PointTransformation().rotatePoint(topPoint , angle, centerPoint);
topPoint = new PointTransformation().rotatePoint(topPoint, angle, centerPoint);
Point2D bottomPoint = new Point2D.Double(pointX - RECT_SIZE / 2, pointY);
bottomPoint = new PointTransformation().rotatePoint(bottomPoint , angle, centerPoint);
bottomPoint = new PointTransformation().rotatePoint(bottomPoint, angle, centerPoint);
graphics.draw(new Line2D.Double(topPoint, bottomPoint));
} else {
......@@ -160,18 +185,18 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
// rotate graphics by the angle defined by line (instead of rotating
// rectangle)
graphics.rotate(angle, pointX, pointY);
// fill rect
// fill rectangle
Color color = graphics.getColor();
graphics.setColor(Color.white);
graphics.fill(rect);
graphics.setColor(color);
// draw rect border
// draw rectangle border
graphics.draw(rect);
// unrotate the graphics
// un-rotate the graphics
graphics.rotate(-angle, pointX, pointY);
// draw text inside rect
// draw text inside rectangle
Font tmpFont = graphics.getFont();
graphics.setFont(descFont);
String insideDesc = insideType.getText();
......@@ -226,12 +251,13 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
}
// in the end we draw rectangle in the middle
drawRectangleData(reaction.getCenterLine(), reaction.getReactionRect(), graphics);
drawRectangleData(reaction.getLine(), reaction.getReactionRect(), graphics);
graphics.setColor(color);
}
@Override
public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params, List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
public void draw(final Reaction reaction, final Graphics2D graphics, final ConverterParams params,
List<ColorSchema> visualizedLayoutsColorSchemas) throws DrawingException {
if (visualizedLayoutsColorSchemas.size() == 0) {
drawImpl(reaction, graphics, params);
} else if (visualizedLayoutsColorSchemas.size() == 1) {
......@@ -335,7 +361,8 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
radius *= SBGN_RADIUS_MULTIPLIER;
}
// it's a circle
Ellipse2D cir = new Ellipse2D.Double(centerPoint.getX() - radius, centerPoint.getY() - radius, 2 * radius, 2 * radius);
Ellipse2D cir = new Ellipse2D.Double(centerPoint.getX() - radius, centerPoint.getY() - radius, 2 * radius,
2 * radius);
Color color = graphics.getColor();
graphics.setColor(Color.white);
graphics.fill(cir);
......@@ -349,7 +376,8 @@ public class ReactionConverter extends BioEntityConverter<Reaction> {
text = operator.getSBGNOperatorText();
}
Rectangle2D rect = graphics.getFontMetrics().getStringBounds(text, graphics);
graphics.drawString(text, (int) (centerPoint.getX() - rect.getWidth() / 2 + 1), (int) (centerPoint.getY() + rect.getHeight() / 2) - 2);
graphics.drawString(text, (int) (centerPoint.getX() - rect.getWidth() / 2 + 1),
(int) (centerPoint.getY() + rect.getHeight() / 2) - 2);
graphics.setColor(color);
}
}
......
......@@ -53,6 +53,7 @@ public abstract class GraphicsTestFunctions {
reaction.addModifier(modifier);
reaction.addProduct(product);
reaction.addReactant(reactant);
reaction.setLine(new PolylineData(center, center));
reaction.setZ(elementCounter);
return reaction;
}
......
......@@ -41,6 +41,7 @@ import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.SplitOperator;
import lcsb.mapviewer.model.map.reaction.type.ReactionRect;
import lcsb.mapviewer.model.map.reaction.type.UnknownTransitionReaction;
import lcsb.mapviewer.model.map.species.GenericProtein;
......@@ -208,6 +209,7 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
result.addModifier(modifier);
result.addProduct(product);
result.addReactant(reactant);
result.setLine(new PolylineData(new Point2D.Double(105, 90), new Point2D.Double(95, 90)));
return result;
}
......@@ -249,6 +251,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
productOperator.addOutput(product2);
productOperator.setLine(new PolylineData(new Point2D.Double(130, 90), new Point2D.Double(110, 90)));
result.setLine(new PolylineData(new Point2D.Double(105, 90), new Point2D.Double(95, 90)));
result.addModifier(modifier1);
result.addModifier(modifier2);
result.addNode(modifierOperator);
......@@ -409,6 +413,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
Point2D reactantEnd = new Point2D.Double(90, 90);
Point2D productEnd = new Point2D.Double(110, 90);
result.setLine(new PolylineData(new Point2D.Double(105, 90), new Point2D.Double(95, 90)));
Reactant reactant = new Reactant(new GenericProtein("s2"));
reactant.setLine(
......@@ -446,4 +452,67 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
}
}
@Test
public void testDrawRectangleDataSimple() throws Exception {
try {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
PolylineData line = new PolylineData(new Point2D.Double(10, 20),
new Point2D.Double(10 + ReactionConverter.RECT_SIZE, 20));
rc.drawRectangleData(line, ReactionRect.RECT_EMPTY, graphics);
Mockito.verify(graphics, times(1)).fill(any(Shape.class));
Mockito.verify(graphics, times(1)).draw(any(Shape.class));
} catch (Exception e) {
throw e;
}
}
@Test
public void testDrawRectangleDataWithLineAround() throws Exception {
try {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
PolylineData line = new PolylineData(new Point2D.Double(10, 20),
new Point2D.Double(10 + ReactionConverter.RECT_SIZE + 100, 20));
rc.drawRectangleData(line, ReactionRect.RECT_EMPTY, graphics);
Mockito.verify(graphics, times(1)).fill(any(Shape.class));
Mockito.verify(graphics, times(3)).draw(any(Shape.class));
} catch (Exception e) {
throw e;
}
}
@Test
public void testDrawRectangleDataWithPolyLineAround() throws Exception {
try {
Graphics2D graphics = createGraphicsMock();
ReactionConverter rc = new ReactionConverter(colorExtractor);
PolylineData line = new PolylineData();
line.addPoint(new Point2D.Double(10, 20));
line.addPoint(new Point2D.Double(100, 20));
line.addPoint(new Point2D.Double(100, 200));
line.addPoint(new Point2D.Double(200, 200));
line.addPoint(new Point2D.Double(200, 300));
line.addPoint(new Point2D.Double(300, 300));
line.addPoint(new Point2D.Double(300, 400));
rc.drawRectangleData(line, ReactionRect.RECT_EMPTY, graphics);
Mockito.verify(graphics, times(1)).fill(any(Shape.class));
Mockito.verify(graphics, times(5)).draw(any(Shape.class));
} catch (Exception e) {
throw e;
}
}
}
......@@ -220,9 +220,9 @@ public class PolylineData implements Serializable, Drawable {
* Return a line that correspond to the part of line.
*
* @param from
* index of the point where line should start
* index of the point where line should start (included)
* @param to
* index of the point where line should end
* index of the point where line should end (excluded)
* @return line that correspond to the part of line
*/
public PolylineData getSubline(int from, int to) {
......
......@@ -477,16 +477,6 @@ public class Reaction implements BioEntity {
return result;
}
/**
* Returns central line of the reaction. Central line is the line that separates
* inputs from outputs.
*
* @return central line of the reaction
*/
public Line2D getCenterLine() {
return this.line.getLines().get(0);
}
/**
* Removes modifier.
*
......@@ -518,18 +508,6 @@ public class Reaction implements BioEntity {
return null;
}
/**
* Returns central point of the reaction - point on central line (see:
* {@link #getCenterLine()}). This point determines one of the points where
* modifiers are attached.
*
* @return central point of the reaction
*/
public Point2D getCenterPoint() {
Line2D line2D = getCenterLine();
return new Point2D.Double((line2D.getX1() + line2D.getX2()) / 2, (line2D.getY1() + line2D.getY2()) / 2);
}
/**
* Check if one of the nodes reference to the element.
*
......
......@@ -7,14 +7,14 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import org.apache.commons.lang3.SerializationUtils;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
......@@ -33,8 +33,6 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.modifier.Catalysis;
import lcsb.mapviewer.model.map.reaction.type.DissociationReaction;
import lcsb.mapviewer.model.map.reaction.type.HeterodimerAssociationReaction;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
......@@ -245,119 +243,6 @@ public class ReactionTest extends ModelTestFunctions {
}
}
@Test
public void testGetCenterLine() {
try {
Reaction reaction1 = new Reaction();
Reactant reactant = new Reactant();
PolylineData line1 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
reactant.setLine(line1);
reaction1.addReactant(reactant);
Product product = new Product();
PolylineData line2 = new PolylineData(new Point2D.Double(0.0, 2.0), new Point2D.Double(4.0, 0.0));
product.setLine(line2);
reaction1.addProduct(product);
Line2D line = reaction1.getCenterLine();
assertEquals(4.0, line.getP1().distance(line.getP2()), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetCenterPoint() {
try {
Reaction reaction1 = new Reaction();
Reactant reactant = new Reactant();
PolylineData line1 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
reactant.setLine(line1);
reaction1.addReactant(reactant);
Product product = new Product();
PolylineData line2 = new PolylineData(new Point2D.Double(0.0, 2.0), new Point2D.Double(4.0, 0.0));
product.setLine(line2);
reaction1.addProduct(product);
assertEquals(0.0, reaction1.getCenterPoint().distance(new Point2D.Double(2.0, 0.0)), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetCenterLine2() {
try {
Reaction reaction1 = new HeterodimerAssociationReaction();
Reactant reactant = new Reactant();
PolylineData line1 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
reactant.setLine(line1);
reaction1.addReactant(reactant);
Reactant reactant2 = new Reactant();
PolylineData line3 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
reactant2.setLine(line3);
reaction1.addReactant(reactant2);
AndOperator operator = new AndOperator();
operator.addInput(reactant);
operator.addInput(reactant2);
PolylineData line4 = new PolylineData(new Point2D.Double(10.0, 0.0), new Point2D.Double(11.0, 11.0));
operator.setLine(line4);
reaction1.addNode(operator);
Product product = new Product();
PolylineData line2 = new PolylineData(new Point2D.Double(0.0, 2.0), new Point2D.Double(4.0, 0.0));
product.setLine(line2);
reaction1.addProduct(product);
Line2D line = reaction1.getCenterLine();
assertEquals(6.0, line.getP1().distance(line.getP2()), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetCenterLine3() {
try {
Reaction reaction1 = new DissociationReaction();
Reactant reactant = new Reactant();
PolylineData line1 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
reactant.setLine(line1);
reaction1.addReactant(reactant);
Product product = new Product();
PolylineData line2 = new PolylineData(new Point2D.Double(0.0, 2.0), new Point2D.Double(4.0, 0.0));
product.setLine(line2);
reaction1.addProduct(product);
Product product2 = new Product();
PolylineData line3 = new PolylineData(new Point2D.Double(0.0, 0.0), new Point2D.Double(0.0, 1.0));
product2.setLine(line3);
reaction1.addProduct(product2);
SplitOperator operator = new SplitOperator();
operator.addOutput(product);
operator.addOutput(product2);
PolylineData line4 = new PolylineData(new Point2D.Double(10.0, 0.0), new Point2D.Double(11.0, 0.0));
operator.setLine(line4);
reaction1.addNode(operator);
Line2D line = reaction1.getCenterLine();
assertEquals(10.0, line.getP1().distance(line.getP2()), Configuration.EPSILON);
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testSerialization() {
try {
......
......@@ -805,6 +805,8 @@ public class ModelContructor {
output.getLine().trimBegin(ReactionCellDesignerConverter.RECT_SIZE / 2 - 1);
line.addPoint(pt.copyPoint(output.getLine().getBeginPoint()));
}
line.setType(input.getLine().getType());
line.setColor(input.getLine().getColor());
reaction.setLine(line);
}
......
......@@ -5,10 +5,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import java.awt.geom.Line2D;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesignerConverter;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
......@@ -27,6 +30,8 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
private ModelComparator mc = new ModelComparator(1.0);