Commit 3e1f5c37 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

export to sbml puts z index on every line and exports process coordinates if necessary

parent 6ce44a43
Pipeline #28898 passed with stage
in 11 minutes and 50 seconds
......@@ -195,7 +195,7 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
assignStyleToGlyph(reactantGlyph, style);
}
}
Curve curve = createCurve(reaction.getLine(), false);
Curve curve = createCurve(reaction.getLine(), false, reaction.getZ());
for (int i = 0; i < curve.getCurveSegmentCount(); i++) {
reactionGlyph.getCurve().addCurveSegment(new LineSegment(curve.getCurveSegment(i)));
}
......@@ -227,9 +227,10 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
for (Modifier modifier : reaction.getModifiers()) {
SpeciesReferenceGlyph modifierGlyph = createNodeGlyph(reactionGlyph, modifier);
for (NodeOperator operator: reaction.getOperators()) {
for (NodeOperator operator : reaction.getOperators()) {
if (operator.getInputs().contains(modifier)) {
modifierGlyph.setCurve(joinCurves(modifierGlyph.getCurve(), createCurve(operator.getLine(), false)));
modifierGlyph
.setCurve(joinCurves(modifierGlyph.getCurve(), createCurve(operator.getLine(), false, reaction.getZ())));
}
}
if (modifier instanceof Inhibition) {
......@@ -250,47 +251,22 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
if (isExtensionEnabled(SbmlExtension.RENDER)) {
assignStyleToGlyph(reactionGlyph, createStyle(reaction));
}
if (reaction.getProcessCoordinates() != null) {
if (reactionGlyph.getBoundingBox() == null) {
reactionGlyph.setBoundingBox(new BoundingBox());
}
if (reactionGlyph.getBoundingBox().getPosition() == null) {
reactionGlyph.getBoundingBox().setPosition(curveToPoint(reactionGlyph.getCurve()));
reactionGlyph.getBoundingBox().setDimensions(curveToDimension(reactionGlyph.getCurve()));
int rectSize = 10;
double x = reaction.getProcessCoordinates().getX() - rectSize / 2;
double y = reaction.getProcessCoordinates().getY() - rectSize / 2;
reactionGlyph.getBoundingBox().setPosition(new Point(x, y, reaction.getZ()));
reactionGlyph.getBoundingBox().setDimensions(
new Dimensions(rectSize, rectSize, 0, getSbmlModel().getLevel(), getSbmlModel().getVersion()));
}
reactionGlyph.getBoundingBox().getPosition().setZ(reaction.getZ());
removeColinearPoints(reactionGlyph);
}
private Dimensions curveToDimension(Curve curve) {
Point p = curveToPoint(curve);
double x = Double.MIN_VALUE;
double y = Double.MIN_VALUE;
for (int i = 0; i < curve.getCurveSegmentCount(); i++) {
LineSegment segment = (LineSegment) curve.getCurveSegment(i);
x = Math.max(x, segment.getStart().getX());
x = Math.max(x, segment.getEnd().getX());
y = Math.max(y, segment.getStart().getY());
y = Math.max(y, segment.getEnd().getY());
}
return new Dimensions(x - p.getX(), y - p.getY(), 0, getSbmlModel().getLevel(), getSbmlModel().getVersion());
}
private Point curveToPoint(Curve curve) {
double x = Double.MAX_VALUE;
double y = Double.MAX_VALUE;
for (int i = 0; i < curve.getCurveSegmentCount(); i++) {
LineSegment segment = (LineSegment) curve.getCurveSegment(i);
x = Math.min(x, segment.getStart().getX());
x = Math.min(x, segment.getEnd().getX());
y = Math.min(y, segment.getStart().getY());
y = Math.min(y, segment.getEnd().getY());
}
return new Point(x, y);
removeColinearPoints(reactionGlyph);
}
@Override
......@@ -320,7 +296,7 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
private void removeColinearPoints(ReactionGlyph glyph) {
PolylineData line = createLine(glyph.getCurve());
line = PolylineDataFactory.removeCollinearPoints(line);
Curve curve = createCurve(line, false);
Curve curve = createCurve(line, false, (int) glyph.getCurve().getCurveSegment(0).getStart().getZ());
glyph.setCurve(curve);
}
......@@ -387,7 +363,7 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
SpeciesReferenceGlyph reactantGlyph = reactionGlyph.createSpeciesReferenceGlyph("node_" + getNextId());
reactantGlyph.setSpeciesGlyph(
speciesExporter.getSbmlGlyphByElementId(speciesExporter.getElementId(node.getElement())).getId());
Curve curve = createCurve(node.getLine(), node instanceof Reactant);
Curve curve = createCurve(node.getLine(), node instanceof Reactant, node.getReaction().getZ());
if (curve.getCurveSegmentCount() == 0) {
logger.warn(new ElementUtils().getElementTag(node) + " Problematic line");
}
......@@ -396,7 +372,7 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
return reactantGlyph;
}
private Curve createCurve(PolylineData polyline, boolean reverse) {
private Curve createCurve(PolylineData polyline, boolean reverse, int z) {
Curve curve = new Curve();
List<Line2D> lines = polyline.getLines();
if (reverse) {
......@@ -405,8 +381,8 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
for (Line2D line : lines) {
if (line.getP1().distance(line.getP2()) > Configuration.EPSILON) {
LineSegment segment = new LineSegment();
segment.setStart(new Point(line.getX1(), line.getY1()));
segment.setEnd(new Point(line.getX2(), line.getY2()));
segment.setStart(new Point(line.getX1(), line.getY1(), z));
segment.setEnd(new Point(line.getX2(), line.getY2(), z));
curve.addCurveSegment(segment);
}
}
......@@ -416,14 +392,14 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
private Curve joinCurves(Curve curve1, Curve curve2) {
Curve curve = new Curve();
for (int i = 0; i < curve1.getCurveSegmentCount(); i++) {
LineSegment source = ((LineSegment)curve1.getCurveSegment(i));
LineSegment source = ((LineSegment) curve1.getCurveSegment(i));
LineSegment segment = new LineSegment();
segment.setStart(new Point(source.getStart().getX(), source.getStart().getY()));
segment.setEnd(new Point(source.getEnd().getX(), source.getEnd().getY()));
curve.addCurveSegment(segment);
}
for (int i = 0; i < curve2.getCurveSegmentCount(); i++) {
LineSegment source = ((LineSegment)curve2.getCurveSegment(i));
LineSegment source = ((LineSegment) curve2.getCurveSegment(i));
LineSegment segment = new LineSegment();
segment.setStart(new Point(source.getStart().getX(), source.getStart().getY()));
segment.setEnd(new Point(source.getEnd().getX(), source.getEnd().getY()));
......
......@@ -91,10 +91,19 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
reactionWithLayout.setIdReaction(glyph.getReaction() + "__" + glyph.getId());
// z index
if (glyph.getCurve() != null
&& glyph.getCurve().getCurveSegmentCount() > 0
&& glyph.getCurve().getCurveSegment(0).getStart() != null
&& glyph.getCurve().getCurveSegment(0).getStart().isSetZ()) {
reactionWithLayout.setZ((int) glyph.getCurve().getCurveSegment(0).getStart().getZ());
}
if (reactionWithLayout.getZ() == null) {
if (glyph.getBoundingBox() != null && glyph.getBoundingBox().getPosition() != null
&& glyph.getBoundingBox().getPosition().isSetZ()) {
reactionWithLayout.setZ((int) glyph.getBoundingBox().getPosition().getZ());
}
}
Set<Pair<Element, ReactionNode>> usedReactionNodes = new HashSet<>();
for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
SpeciesGlyph speciesGlyph = getLayout().getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
......
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