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; package lcsb.mapviewer.converter.model.sbgnml;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
...@@ -11,7 +10,8 @@ import java.util.stream.Collectors; ...@@ -11,7 +10,8 @@ import java.util.stream.Collectors;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils; 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.ArcClazz;
import org.sbgn.GlyphClazz; import org.sbgn.GlyphClazz;
import org.sbgn.Language; import org.sbgn.Language;
...@@ -30,6 +30,7 @@ import lcsb.mapviewer.common.comparator.DoubleComparator; ...@@ -30,6 +30,7 @@ import lcsb.mapviewer.common.comparator.DoubleComparator;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter; import lcsb.mapviewer.converter.graphics.bioEntity.reaction.ReactionConverter;
import lcsb.mapviewer.model.graphics.ArrowType; import lcsb.mapviewer.model.graphics.ArrowType;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.modifier.Catalysis; import lcsb.mapviewer.model.map.modifier.Catalysis;
...@@ -580,9 +581,9 @@ public class SbgnmlXmlExporter { ...@@ -580,9 +581,9 @@ public class SbgnmlXmlExporter {
processGlyph.setClazz(getGlyphClazzFromReaction(reaction).getClazz()); processGlyph.setClazz(getGlyphClazzFromReaction(reaction).getClazz());
Bbox bbox = new Bbox(); Bbox bbox = new Bbox();
Line2D line = reaction.getCenterLine(); PolylineData line = reaction.getLine();
Point2D startPoint = line.getP1(); Point2D startPoint = line.getBeginPoint();
Point2D endPoint = line.getP2(); Point2D endPoint = line.getEndPoint();
double pointX = (startPoint.getX() + endPoint.getX()) / 2; double pointX = (startPoint.getX() + endPoint.getX()) / 2;
double pointY = (startPoint.getY() + endPoint.getY()) / 2; double pointY = (startPoint.getY() + endPoint.getY()) / 2;
......
...@@ -562,7 +562,7 @@ public class SbgnmlXmlParser { ...@@ -562,7 +562,7 @@ public class SbgnmlXmlParser {
productPointList.add(2, newPoint); productPointList.add(2, newPoint);
} }
} }
int reactantPointEnds = (productPointList.size()-1) / 2; int reactantPointEnds = (productPointList.size() - 1) / 2;
int productPointStarts = reactantPointEnds + 1; int productPointStarts = reactantPointEnds + 1;
Reactant reactant = new Reactant(model.getElementByElementId(source.getId())); Reactant reactant = new Reactant(model.getElementByElementId(source.getId()));
...@@ -949,7 +949,7 @@ public class SbgnmlXmlParser { ...@@ -949,7 +949,7 @@ public class SbgnmlXmlParser {
ModifierTypeUtils utils = new ModifierTypeUtils(); ModifierTypeUtils utils = new ModifierTypeUtils();
Point2D result; Point2D result;
Line2D centerLine = reaction.getCenterLine(); Line2D centerLine = reaction.getLine().getLines().get(reaction.getLine().getLines().size() / 2);
double dx = centerLine.getX2() - centerLine.getX1(); double dx = centerLine.getX2() - centerLine.getX1();
double dy = centerLine.getY2() - centerLine.getY1(); double dy = centerLine.getY2() - centerLine.getY1();
double centerLineAngle = Math.atan2(dy, dx); double centerLineAngle = Math.atan2(dy, dx);
...@@ -1315,7 +1315,7 @@ public class SbgnmlXmlParser { ...@@ -1315,7 +1315,7 @@ public class SbgnmlXmlParser {
} else { } else {
reaction.getProducts().get(0).getLine().trimBegin(ReactionCellDesignerConverter.RECT_SIZE / 2 - 1); reaction.getProducts().get(0).getLine().trimBegin(ReactionCellDesignerConverter.RECT_SIZE / 2 - 1);
} }
PolylineData centerLine = new PolylineData(pt.copyPoint(centerPointStart), pt.copyPoint(centerPointEnd)); PolylineData centerLine = new PolylineData(pt.copyPoint(centerPointStart), pt.copyPoint(centerPointEnd));
reaction.setLine(centerLine); reaction.setLine(centerLine);
......
...@@ -6,11 +6,11 @@ import java.awt.Graphics2D; ...@@ -6,11 +6,11 @@ import java.awt.Graphics2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.List; 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.commands.ColorExtractor;
import lcsb.mapviewer.common.Configuration; import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.geometry.EllipseTransformation;
import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.graphics.ConverterParams; import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException; import lcsb.mapviewer.converter.graphics.DrawingException;
......
...@@ -12,11 +12,11 @@ import java.awt.geom.Point2D; ...@@ -12,11 +12,11 @@ import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D; import java.awt.geom.Rectangle2D;
import java.util.List; 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.commands.ColorExtractor;
import lcsb.mapviewer.common.exception.InvalidArgumentException; import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.geometry.EllipseTransformation;
import lcsb.mapviewer.common.geometry.LineTransformation; import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.converter.graphics.ConverterParams; import lcsb.mapviewer.converter.graphics.ConverterParams;
import lcsb.mapviewer.converter.graphics.DrawingException; import lcsb.mapviewer.converter.graphics.DrawingException;
......
...@@ -53,6 +53,7 @@ public abstract class GraphicsTestFunctions { ...@@ -53,6 +53,7 @@ public abstract class GraphicsTestFunctions {
reaction.addModifier(modifier); reaction.addModifier(modifier);
reaction.addProduct(product); reaction.addProduct(product);
reaction.addReactant(reactant); reaction.addReactant(reactant);
reaction.setLine(new PolylineData(center, center));
reaction.setZ(elementCounter); reaction.setZ(elementCounter);
return reaction; return reaction;
} }
......
...@@ -41,6 +41,7 @@ import lcsb.mapviewer.model.map.reaction.Product; ...@@ -41,6 +41,7 @@ import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant; import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.SplitOperator; 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.reaction.type.UnknownTransitionReaction;
import lcsb.mapviewer.model.map.species.GenericProtein; import lcsb.mapviewer.model.map.species.GenericProtein;
...@@ -208,6 +209,7 @@ public class ReactionConverterTest extends GraphicsTestFunctions { ...@@ -208,6 +209,7 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
result.addModifier(modifier); result.addModifier(modifier);
result.addProduct(product); result.addProduct(product);
result.addReactant(reactant); result.addReactant(reactant);
result.setLine(new PolylineData(new Point2D.Double(105, 90), new Point2D.Double(95, 90)));
return result; return result;
} }
...@@ -249,6 +251,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions { ...@@ -249,6 +251,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
productOperator.addOutput(product2); productOperator.addOutput(product2);
productOperator.setLine(new PolylineData(new Point2D.Double(130, 90), new Point2D.Double(110, 90))); 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(modifier1);
result.addModifier(modifier2); result.addModifier(modifier2);
result.addNode(modifierOperator); result.addNode(modifierOperator);
...@@ -409,6 +413,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions { ...@@ -409,6 +413,8 @@ public class ReactionConverterTest extends GraphicsTestFunctions {
Point2D reactantEnd = new Point2D.Double(90, 90); Point2D reactantEnd = new Point2D.Double(90, 90);
Point2D productEnd = new Point2D.Double(110, 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 reactant = new Reactant(new GenericProtein("s2"));
reactant.setLine( reactant.setLine(
...@@ -446,4 +452,67 @@ public class ReactionConverterTest extends GraphicsTestFunctions { ...@@ -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 { ...@@ -220,9 +220,9 @@ public class PolylineData implements Serializable, Drawable {
* Return a line that correspond to the part of line. * Return a line that correspond to the part of line.
* *
* @param from * @param from
* index of the point where line should start * index of the point where line should start (included)
* @param to * @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 * @return line that correspond to the part of line
*/ */
public PolylineData getSubline(int from, int to) { public PolylineData getSubline(int from, int to) {
......
...@@ -477,16 +477,6 @@ public class Reaction implements BioEntity { ...@@ -477,16 +477,6 @@ public class Reaction implements BioEntity {
return result; 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. * Removes modifier.
* *
...@@ -518,18 +508,6 @@ public class Reaction implements BioEntity { ...@@ -518,18 +508,6 @@ public class Reaction implements BioEntity {
return null; 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. * Check if one of the nodes reference to the element.
* *
......
...@@ -7,14 +7,14 @@ import static org.junit.Assert.assertNull; ...@@ -7,14 +7,14 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D; import java.awt.geom.Point2D;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import org.apache.commons.lang3.SerializationUtils; 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.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
...@@ -33,8 +33,6 @@ import lcsb.mapviewer.model.map.model.Model; ...@@ -33,8 +33,6 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelData; import lcsb.mapviewer.model.map.model.ModelData;
import lcsb.mapviewer.model.map.model.ModelFullIndexed; import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.modifier.Catalysis; 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.GenericProtein;
import lcsb.mapviewer.model.map.species.Species; import lcsb.mapviewer.model.map.species.Species;
...@@ -245,119 +243,6 @@ public class ReactionTest extends ModelTestFunctions { ...@@ -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 @Test
public void testSerialization() { public void testSerialization() {
try { try {
......
...@@ -805,6 +805,8 @@ public class ModelContructor { ...@@ -805,6 +805,8 @@ public class ModelContructor {
output.getLine().trimBegin(ReactionCellDesignerConverter.RECT_SIZE / 2 - 1); output.getLine().trimBegin(ReactionCellDesignerConverter.RECT_SIZE / 2 - 1);
line.addPoint(pt.copyPoint(output.getLine().getBeginPoint())); line.addPoint(pt.copyPoint(output.getLine().getBeginPoint()));
} }
line.setType(input.getLine().getType());
line.setColor(input.getLine().getColor());
reaction.setLine(line); reaction.setLine(line);
} }
......
...@@ -5,10 +5,13 @@ import static org.junit.Assert.assertFalse; ...@@ -5,10 +5,13 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import java.awt.geom.Line2D;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.junit.Test; import org.junit.Test;
import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesignerConverter; import lcsb.mapviewer.converter.model.celldesigner.geometry.ReactionCellDesignerConverter;
import lcsb.mapviewer.model.map.compartment.Compartment; import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model; import lcsb.mapviewer.model.map.model.Model;
...@@ -27,6 +30,8 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions { ...@@ -27,6 +30,8 @@ public class GPMLToModelTest extends WikipathwaysTestFunctions {
private ModelComparator mc = new ModelComparator(1.0); private ModelComparator mc = new ModelComparator(1.0);
private PointTransformation pt = new PointTransformation();
@Test @Test
public void DopamineTest() throws Exception { public void DopamineTest() throws Exception {
try {