Commit 48148d6b authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1457-generate-process-rectangles-for-sbml-render-layout' into 'master'

Resolve "generate process rectangles for SBML render layout"

Closes #1457

See merge request !1286
parents 34762474 bd5424a0
Pipeline #38621 failed with stages
in 35 minutes and 35 seconds
......@@ -22,13 +22,15 @@ minerva (16.0.0~alpha.1) stable; urgency=medium
residues (#1456)
* Small improvement: SBML render contains information about structural states
(#1456)
* Small improvement: SBML render contains process rectangle for reactions
(#1457)
* Bug fix: refreshing page after removing last project on the page redirect to
proper page (#1051)
* Bug fix: removing plugin that does not exist anymore does not raise an error
(#1289)
* Bug fix: broken overlays crashed minerva upgrade (#1453)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 9 Feb 2020 08:00:00 +0200
-- Piotr Gawron <piotr.gawron@uni.lu> Fri, 19 Mar 2021 10:00:00 +0200
minerva (16.0.0~alpha.0) stable; urgency=medium
* Backward incompatibility: deprecated columns in data overlay table are no
......
......@@ -228,4 +228,10 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
return sbmlModelUtils.createStyle();
}
protected void createAbsolutePoint(Polygon polygon, double x, double y) {
RenderPoint p1 = polygon.createRenderPoint();
p1.setX(new RelAbsVector(Math.round(x)));
p1.setY(new RelAbsVector(Math.round(y)));
}
}
package lcsb.mapviewer.converter.model.sbml.reaction;
import java.awt.BasicStroke;
import java.awt.Stroke;
import java.awt.*;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.util.*;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.sbml.jsbml.*;
import org.sbml.jsbml.ext.layout.*;
import org.sbml.jsbml.ext.render.*;
import org.sbml.jsbml.ext.layout.Point;
import org.sbml.jsbml.ext.render.ColorDefinition;
import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.Polygon;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.Configuration;
......@@ -38,6 +42,8 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
*/
private static Logger logger = LogManager.getLogger();
private static final double RECT_SIZE = 10;
private SbmlBioEntityExporter<lcsb.mapviewer.model.map.species.Species, Species> speciesExporter;
private SbmlBioEntityExporter<Compartment, org.sbml.jsbml.Compartment> compartmentExporter;
......@@ -289,7 +295,38 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
@Override
protected LocalStyle createStyle(Reaction reaction) {
return createStyle(reaction.getLine());
LocalStyle style = createStyle(reaction.getLine());
ColorDefinition color = getColorDefinition(Color.WHITE);
style.getGroup().setFill(color.getId());
Point2D startPoint = reaction.getLine().getLines().get((reaction.getLine().getLines().size() - 1) / 2).getP1();
Point2D endPoint = reaction.getLine().getLines().get((reaction.getLine().getLines().size() - 1) / 2).getP2();
double pointX = (startPoint.getX() + endPoint.getX()) / 2;
double pointY = (startPoint.getY() + endPoint.getY()) / 2;
double dx = endPoint.getX() - startPoint.getX();
double dy = endPoint.getY() - startPoint.getY();
double angle = Math.atan2(dy, dx);
if (reaction.getProcessCoordinates() != null) {
angle = 0;
pointX = reaction.getProcessCoordinates().getX();
pointY = reaction.getProcessCoordinates().getY();
}
angle += Math.PI / 4;
Polygon polygon = new Polygon();
double dist = Math.sqrt(2) * RECT_SIZE / 2;
createAbsolutePoint(polygon, pointX - dist * Math.cos(angle), pointY - dist * Math.sin(angle));
createAbsolutePoint(polygon, pointX + dist * Math.sin(angle), pointY - dist * Math.cos(angle));
createAbsolutePoint(polygon, pointX + dist * Math.cos(angle), pointY + dist * Math.sin(angle));
createAbsolutePoint(polygon, pointX - dist * Math.sin(angle), pointY + dist * Math.cos(angle));
style.getGroup().addElement(polygon);
return style;
}
void removeColinearPoints(ReactionGlyph glyph) {
......
......@@ -745,12 +745,6 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
p1.setY(new RelAbsVector(0, Math.round(y)));
}
private void createAbsolutePoint(Polygon polygon, double x, double y) {
RenderPoint p1 = polygon.createRenderPoint();
p1.setX(new RelAbsVector(Math.round(x)));
p1.setY(new RelAbsVector(Math.round(y)));
}
private void createAbsoluteBezierPoint(Polygon polygon, double x, double y, double x1, double y1, double x2,
double y2) {
RenderCubicBezier result = (RenderCubicBezier) polygon.createRenderCubicBezier();
......
......@@ -10,8 +10,7 @@ import org.apache.logging.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
import lcsb.mapviewer.converter.model.sbml.SbmlTestFunctions;
import lcsb.mapviewer.converter.model.sbml.*;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
......@@ -38,7 +37,7 @@ public class SbmlSpeciesExporterTest extends SbmlTestFunctions {
model.addElement(protein1);
model.addElement(protein2);
SbmlSpeciesExporter exporter = helper.createExporter(model);
SbmlBioEntityExporter<Species, org.sbml.jsbml.Species> exporter = helper.createExporter(model);
exporter.exportElements();
......@@ -58,7 +57,7 @@ public class SbmlSpeciesExporterTest extends SbmlTestFunctions {
model.addElement(protein2);
model.addElement(compartment);
SbmlSpeciesExporter exporter = helper.createExporter(model);
SbmlBioEntityExporter<Species, org.sbml.jsbml.Species> exporter = helper.createExporter(model);
exporter.exportElements();
......
......@@ -5,11 +5,11 @@ import java.util.Collection;
import org.sbml.jsbml.SBMLDocument;
import lcsb.mapviewer.converter.model.sbml.SbmlExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
import lcsb.mapviewer.converter.model.sbml.*;
import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentExporter;
import lcsb.mapviewer.model.map.InconsistentModelException;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.species.Species;
public class SbmlSpeciesExporterTestHelper {
org.sbml.jsbml.Model sbmlModel;
......
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