Commit 4441b540 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

colinear points are removed when exporting to sbml

parent 3c063d71
Pipeline #10203 passed with stage
in 9 minutes and 23 seconds
......@@ -21,6 +21,7 @@ import org.sbml.jsbml.SpeciesReference;
import org.sbml.jsbml.ext.layout.AbstractReferenceGlyph;
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.LineSegment;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.layout.ReactionGlyph;
......@@ -35,8 +36,10 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
import lcsb.mapviewer.converter.model.celldesigner.geometry.helper.PolylineDataFactory;
import lcsb.mapviewer.converter.model.sbml.SbmlBioEntityExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.kinetics.SbmlKinetics;
......@@ -295,14 +298,38 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
if (isExtensionEnabled(SbmlExtension.RENDER)) {
assignStyleToGlyph(reactionGlyph, createStyle(reaction));
}
if (reactionGlyph.getBoundingBox()==null) {
if (reactionGlyph.getBoundingBox() == null) {
reactionGlyph.setBoundingBox(new BoundingBox());
}
if (reactionGlyph.getBoundingBox().getPosition()==null) {
if (reactionGlyph.getBoundingBox().getPosition() == null) {
reactionGlyph.getBoundingBox().setPosition(new Point());
}
reactionGlyph.getBoundingBox().getPosition().setZ(reaction.getZ());
removeColinearPoints(reactionGlyph);
}
private void removeColinearPoints(ReactionGlyph glyph) {
PolylineData line = createLine(glyph.getCurve());
logger.debug(line);
line = PolylineDataFactory.removeCollinearPoints(line);
logger.debug(line);
Curve curve = createCurve(line, false);
glyph.setCurve(curve);
}
private PolylineData createLine(Curve curve) {
PolylineData result = new PolylineData();
if (curve.getCurveSegmentCount() > 0) {
CurveSegment segment = curve.getCurveSegment(0);
result.addPoint(new Point2D.Double(segment.getStart().getX(), segment.getStart().getY()));
}
for (int i = 0; i < curve.getCurveSegmentCount(); i++) {
CurveSegment segment = curve.getCurveSegment(i);
result.addPoint(new Point2D.Double(segment.getEnd().getX(), segment.getEnd().getY()));
}
return result;
}
private LocalStyle createStyle(ReactionNode node) {
......@@ -358,16 +385,20 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
private SpeciesReferenceGlyph createNodeGlyph(ReactionGlyph reactionGlyph, ReactionNode node) {
SpeciesReferenceGlyph reactantGlyph = reactionGlyph.createSpeciesReferenceGlyph("node_" + getNextId());
reactantGlyph.setSpeciesGlyph(speciesExporter.getSbmlGlyphByElementId(node.getElement().getElementId()).getId());
reactantGlyph.setCurve(createCurve(node, node instanceof Reactant));
Curve curve = createCurve(node.getLine(), node instanceof Reactant);
if (curve.getCurveSegmentCount() == 0) {
logger.warn(new ElementUtils().getElementTag(node) + " Problematic line");
}
reactantGlyph.setCurve(curve);
reactantGlyph.setSpeciesReference(speciesReferenceByReactionNode.get(node));
return reactantGlyph;
}
private Curve createCurve(ReactionNode node, boolean reverse) {
private Curve createCurve(PolylineData polyline, boolean reverse) {
Curve curve = new Curve();
List<Line2D> lines = node.getLine().getLines();
List<Line2D> lines = polyline.getLines();
if (reverse) {
lines = node.getLine().reverse().getLines();
lines = polyline.reverse().getLines();
}
for (Line2D line : lines) {
if (line.getP1().distance(line.getP2()) > Configuration.EPSILON) {
......@@ -377,9 +408,6 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
curve.addCurveSegment(segment);
}
}
if (curve.getCurveSegmentCount() == 0) {
logger.warn(new ElementUtils().getElementTag(node) + " Problematic line");
}
return curve;
}
......
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