Commit bd04c4d5 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

remove duplicate entries in lines

parent 22754eae
......@@ -231,7 +231,6 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
}
}
getMinervaModel().addReaction(reactionWithLayout);
} catch (Exception e) {
......@@ -355,10 +354,6 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
operator = new AndOperator();
}
PolylineData line = extractCurve(reactionGlyph, reactionWithLayout, operator.getClass());
if (line.getPoints().size() == 0) {
line.addPoint(reactionWithLayout.getReactants().get(0).getLine().getEndPoint());
line.addPoint(reactionWithLayout.getReactants().get(0).getLine().getEndPoint());
}
operator.addInputs(reactionWithLayout.getReactants());
operator.setLine(line);
return operator;
......@@ -525,21 +520,37 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
return centerPoint;
}
private Curve getCurve(ReactionGlyph reactionGlyph) {
Curve getCurve(ReactionGlyph reactionGlyph) {
Curve curve = reactionGlyph.getCurve();
if (curve == null) {
BoundingBox box = reactionGlyph.getBoundingBox();
if (box != null && box.getDimensions() != null && box.getPosition() != null) {
curve = new Curve(getSbmlModel().getLevel(), getSbmlModel().getVersion());
LineSegment curveSegment = new LineSegment(getSbmlModel().getLevel(), getSbmlModel().getVersion());
curveSegment.setStart(new Point(box.getPosition()));
curveSegment.setEnd(new Point(box.getPosition().getX() + box.getDimensions().getWidth(),
box.getPosition().getY() + box.getDimensions().getHeight()));
curve.addCurveSegment(curveSegment);
if (box.getDimensions().getWidth() > 0 || box.getDimensions().getHeight() > 0) {
LineSegment curveSegment = new LineSegment(getSbmlModel().getLevel(), getSbmlModel().getVersion());
Point start = new Point(getSbmlModel().getLevel(), getSbmlModel().getVersion());
start.setX(box.getPosition().getX());
start.setY(box.getPosition().getY());
start.setZ(box.getPosition().getZ());
curveSegment.setStart(start);
curveSegment.setEnd(new Point(box.getPosition().getX() + box.getDimensions().getWidth(),
box.getPosition().getY() + box.getDimensions().getHeight()));
curve.addCurveSegment(curveSegment);
}
} else {
curve = null;
}
}
if (curve != null) {
curve = new Curve(curve);
for (int i = curve.getChildCount() - 1; i >= 0; i--) {
Point start = curve.getCurveSegment(i).getStart();
Point end = curve.getCurveSegment(i).getEnd();
if (start.equals(end)) {
curve.removeCurveSegment(i);
}
}
}
return curve;
}
......@@ -623,10 +634,12 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
for (CurveSegment segment : speciesRefernceGlyph.getCurve().getListOfCurveSegments()) {
Point2D start = new Point2D.Double(segment.getStart().getX(), segment.getStart().getY());
Point2D end = new Point2D.Double(segment.getEnd().getX(), segment.getEnd().getY());
if (line == null) {
line = new PolylineData(start, end);
} else {
line.addPoint(end);
if (!start.equals(end)) {
if (line == null) {
line = new PolylineData(start, end);
} else {
line.addPoint(end);
}
}
}
if (line == null) {
......
......@@ -8,19 +8,22 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import org.apache.logging.log4j.*;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.common.geometry.PointTransformation;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.converter.model.celldesigner.reaction.ReactionLineData;
import lcsb.mapviewer.converter.model.sbml.SbmlExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlParser;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.model.Model;
......@@ -43,7 +46,9 @@ import lcsb.mapviewer.model.map.species.Ion;
import lcsb.mapviewer.modelutils.map.ElementUtils;
@RunWith(Parameterized.class)
public class SbmlReactionExportArrowType {
public class SbmlReactionExportArrowType extends SbmlTestFunctions {
private static PointTransformation pt = new PointTransformation();
@SuppressWarnings("unused")
private static Logger logger = LogManager.getLogger(SbmlReactionExportArrowType.class);
......@@ -64,7 +69,8 @@ public class SbmlReactionExportArrowType {
}
private static Model createModelForReactionType(Class<?> clazz) throws InstantiationException, IllegalAccessException,
InvocationTargetException, NoSuchMethodException, InconsistentModelException, InvalidInputDataExecption {
InvocationTargetException, NoSuchMethodException, InconsistentModelException, InvalidInputDataExecption,
Exception {
Model model = new ModelFullIndexed(null);
model.setWidth(1000);
model.setHeight(1000);
......@@ -79,7 +85,8 @@ public class SbmlReactionExportArrowType {
Reaction reaction = (Reaction) clazz.getConstructor().newInstance();
reaction.setIdReaction("reactionId");
reaction.addReactant(createReactant(ion));
Reactant reactant = createReactant(ion);
reaction.addReactant(reactant);
Product product = createProduct(ion2);
reaction.addProduct(product);
if (SimpleReactionInterface.class.isAssignableFrom(clazz)) {
......@@ -96,7 +103,8 @@ public class SbmlReactionExportArrowType {
product.getLine().setType(lineData.getLineType());
}
operator.addInputs(reaction.getReactants());
operator.setLine(new PolylineData(new Point2D.Double(100, 100), new Point2D.Double(100, 200)));
operator.setLine(new PolylineData(pt.copyPoint(reactant.getLine().getEndPoint()),
pt.copyPoint(product.getLine().getBeginPoint())));
reaction.addNode(operator);
} else if (TwoProductReactionInterface.class.isAssignableFrom(clazz)) {
reaction.addProduct(createProduct(ion3));
......@@ -110,6 +118,7 @@ public class SbmlReactionExportArrowType {
} else {
throw new NotImplementedException();
}
reaction.setZ(1);
reaction.setLine(new PolylineData(new Point2D.Double(10, 40), new Point2D.Double(10, 60)));
model.addReaction(reaction);
......@@ -126,11 +135,12 @@ public class SbmlReactionExportArrowType {
ion.setWidth(100);
ion.setHeight(100);
ion.setX(200 * (id % 2 + 1));
ion.setY(50 * (id / 2 + 1));
ion.setY(100 * id);
ion.setOnlySubstanceUnits(true);
ion.setConstant(true);
ion.setInitialAmount(2.0);
ion.setBoundaryCondition(true);
ion.setZ(1);
return ion;
}
......@@ -146,7 +156,7 @@ public class SbmlReactionExportArrowType {
Product result = new Product(ion);
Point2D point = ion.getCenter();
point.setLocation(point.getX() + 300, point.getY());
result.setLine(new PolylineData(ion.getCenter(), point));
result.setLine(new PolylineData(point, ion.getCenter()));
return result;
}
......@@ -173,13 +183,4 @@ public class SbmlReactionExportArrowType {
throw e;
}
}
private Model getModelAfterSerializing(Model originalModel) throws Exception {
exporter.setProvideDefaults(false);
String xml = exporter.toXml(originalModel);
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
Model result = parser.createModel(new ConverterParams().inputStream(stream));
return result;
}
}
......@@ -9,9 +9,13 @@ import java.io.FileNotFoundException;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.Test;
import org.sbml.jsbml.ext.layout.BoundingBox;
import org.sbml.jsbml.ext.layout.Curve;
import org.sbml.jsbml.ext.layout.CurveSegment;
import org.sbml.jsbml.ext.layout.Dimensions;
import org.sbml.jsbml.ext.layout.LineSegment;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.layout.ReactionGlyph;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.converter.ConverterParams;
......@@ -322,4 +326,42 @@ public class SbmlReactionParserTest extends SbmlTestFunctions {
}
}
@Test
public void testGetCurveFromEmptyBoundingBox() throws Exception {
try {
SbmlReactionParser sbmlReactionParser = new SbmlReactionParser(new org.sbml.jsbml.Model(), null, null, null);
ReactionGlyph glyph = new ReactionGlyph(3, 2);
BoundingBox box = new BoundingBox(3, 2);
box.setPosition(new Point(1, 1, 1, 3, 2));
box.setDimensions(new Dimensions(3, 2));
glyph.setBoundingBox(box);
Curve result = sbmlReactionParser.getCurve(glyph);
assertNotNull(result);
assertEquals(0, result.getCurveSegmentCount());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
@Test
public void testGetCurveFromNonEmptyBoundingBox() throws Exception {
try {
SbmlReactionParser sbmlReactionParser = new SbmlReactionParser(new org.sbml.jsbml.Model(), null, null, null);
ReactionGlyph glyph = new ReactionGlyph(3, 2);
BoundingBox box = new BoundingBox(3, 2);
box.setPosition(new Point(1, 1, 1, 3, 2));
box.setDimensions(new Dimensions(2, 2, 2, 3, 2));
glyph.setBoundingBox(box);
Curve result = sbmlReactionParser.getCurve(glyph);
assertNotNull(result);
assertEquals(1, result.getCurveSegmentCount());
} catch (Exception e) {
e.printStackTrace();
throw e;
}
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment