Commit 6c7454a0 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

import/export of sbml supports z-index

parent 9efbf1b3
......@@ -48,6 +48,8 @@ minerva (13.1.0~alpha.0) unstable; urgency=low
* Small improvement: allow admin to disable CORS check (#802)
* Small improvement: TransparencyZoomLevelVisibility parameter renamed to
SemanticZoomLevelTransparency (#801)
* Small improvement: export/import from SBML support z-index in LAYOUT
extension
* Bug fix: progress bar of gene genome mapping upload is refreshing properly
(#728)
* Bug fix: when editing project Disease and Organism could not be removed
......
......@@ -301,7 +301,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createCircleLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(-2, 0, 4, 4);
BoundingBox boundingBox = createBoundingBox(-2, 0, 4, 4, 0);
result.getGroup().setFill(getColorDefinition(Color.WHITE).getId());
result.setBoundingBox(boundingBox);
Ellipse ellipse = new Ellipse();
......@@ -317,7 +317,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createOpenLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(-12, -6, 12, 12);
BoundingBox boundingBox = createBoundingBox(-12, -6, 12, 12, 0);
result.setBoundingBox(boundingBox);
Polygon polygon = new Polygon();
polygon.addElement(createRenderPoint(0, 0));
......@@ -328,7 +328,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createDiamondLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(-18, -6, 18, 12);
BoundingBox boundingBox = createBoundingBox(-18, -6, 18, 12, 0);
result.setBoundingBox(boundingBox);
result.getGroup().setFill(getColorDefinition(Color.WHITE).getId());
Polygon polygon = new Polygon();
......@@ -341,7 +341,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createCrossBarLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(0, -6, 1, 12);
BoundingBox boundingBox = createBoundingBox(0, -6, 1, 12, 0);
result.setBoundingBox(boundingBox);
Polygon crossBar = new Polygon();
crossBar.addElement(createRenderPoint(0, 0));
......@@ -355,7 +355,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createFullLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(-12, -6, 12, 12);
BoundingBox boundingBox = createBoundingBox(-12, -6, 12, 12, 0);
result.setBoundingBox(boundingBox);
result.getGroup().setFill(getColorDefinition(Color.BLACK).getId());
Polygon polygon = new Polygon();
......@@ -367,7 +367,7 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
}
private void createBlankCrossBarLineEnding(LineEnding result) {
BoundingBox boundingBox = createBoundingBox(-18, -6, 18, 12);
BoundingBox boundingBox = createBoundingBox(-18, -6, 18, 12, 0);
result.setBoundingBox(boundingBox);
result.getGroup().setFill(getColorDefinition(Color.WHITE).getId());
Polygon polygon = new Polygon();
......@@ -397,10 +397,10 @@ public abstract class SbmlBioEntityExporter<T extends BioEntity, S extends org.s
return result;
}
protected BoundingBox createBoundingBox(double x, double y, double w, double h) {
protected BoundingBox createBoundingBox(double x, double y, int z, double w, double h) {
BoundingBox boundingBox = new BoundingBox();
boundingBox.setPosition(new Point(x, y));
boundingBox.setPosition(new Point(x, y, z));
Dimensions dimensions = new Dimensions();
dimensions.setWidth(w);
......
......@@ -39,13 +39,14 @@ public abstract class SbmlElementExporter<T extends Element, S extends org.sbml.
protected void assignLayoutToGlyph(T element, AbstractReferenceGlyph speciesGlyph) {
BoundingBox boundingBox = new BoundingBox();
boundingBox.setPosition(new Point(element.getX(), element.getY()));
boundingBox.setPosition(new Point(element.getX(), element.getY(), element.getZ()));
Dimensions dimensions = new Dimensions();
dimensions.setWidth(element.getWidth());
dimensions.setHeight(element.getHeight());
boundingBox.setDimensions(dimensions);
speciesGlyph.setBoundingBox(boundingBox);
if (isExtensionEnabled(SbmlExtension.RENDER)) {
LocalStyle style = createStyle(element);
......
......@@ -74,7 +74,7 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
if (style != null) {
applyStyleToElement(source, style);
}
used.add(source.getElementId());
AbstractReferenceGlyph glyph = idGlyphPair.getRight();
if (glyph.getId() == null || glyph.getId().equals("")) {
......@@ -104,6 +104,9 @@ public abstract class SbmlElementParser<T extends org.sbml.jsbml.Symbol> extends
elementWithLayout.setElementId(glyph.getId());
elementWithLayout.setX(glyph.getBoundingBox().getPosition().getX());
elementWithLayout.setY(glyph.getBoundingBox().getPosition().getY());
if (glyph.getBoundingBox().getPosition().isSetZ()) {
elementWithLayout.setZ((int) glyph.getBoundingBox().getPosition().getZ());
}
elementWithLayout.setWidth(glyph.getBoundingBox().getDimensions().getWidth());
elementWithLayout.setHeight(glyph.getBoundingBox().getDimensions().getHeight());
......
......@@ -22,6 +22,7 @@ import lcsb.mapviewer.converter.Converter;
import lcsb.mapviewer.converter.ConverterException;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.InvalidInputDataExecption;
import lcsb.mapviewer.converter.ZIndexPopulator;
import lcsb.mapviewer.converter.model.sbml.compartment.SbmlCompartmentParser;
import lcsb.mapviewer.converter.model.sbml.reaction.SbmlReactionParser;
import lcsb.mapviewer.converter.model.sbml.species.SbmlSpeciesParser;
......@@ -200,6 +201,7 @@ public class SbmlParser extends Converter {
} catch (CommandExecutionException e) {
throw new InvalidInputDataExecption("Problem with generating layout", e);
}
new ZIndexPopulator().populateZIndex(model);
}
private void updateModifierTypes(Reaction reaction) {
......
......@@ -136,7 +136,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
if (element.getElementId().equals("default")) {
BoundingBox boundingBox = new BoundingBox();
boundingBox.setPosition(new Point(element.getX(), element.getY()));
boundingBox.setPosition(new Point(element.getX(), element.getY(), 0));
Dimensions dimensions = new Dimensions();
if (getMinervaModel().getWidth() != null) {
......@@ -151,7 +151,7 @@ public class SbmlCompartmentExporter extends SbmlElementExporter<Compartment, or
Point2D point = element.getNamePoint();
double width = element.getWidth() - (point.getX() - element.getX());
double height = element.getHeight() - (point.getY() - element.getY());
textGlyph.setBoundingBox(createBoundingBox(point.getX(), point.getY(), width, height));
textGlyph.setBoundingBox(createBoundingBox(point.getX(), point.getY(), element.getZ() + 1, width, height));
textGlyph.setReference(speciesGlyph.getId());
if (isExtensionEnabled(SbmlExtension.RENDER)) {
......
......@@ -10,7 +10,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import lcsb.mapviewer.common.XmlParser;
import org.apache.log4j.Logger;
import org.sbml.jsbml.ASTNode;
import org.sbml.jsbml.KineticLaw;
......@@ -20,6 +19,7 @@ import org.sbml.jsbml.SimpleSpeciesReference;
import org.sbml.jsbml.Species;
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.LineSegment;
import org.sbml.jsbml.ext.layout.Point;
......@@ -33,6 +33,7 @@ import org.sbml.jsbml.ext.render.RenderGroup;
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.sbml.SbmlBioEntityExporter;
import lcsb.mapviewer.converter.model.sbml.SbmlExtension;
......@@ -55,7 +56,6 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
/**
* Default class logger.
*/
@SuppressWarnings("unused")
private static Logger logger = Logger.getLogger(SbmlReactionExporter.class);
private SbmlBioEntityExporter<lcsb.mapviewer.model.map.species.Species, Species> speciesExporter;
......@@ -295,6 +295,13 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
if (isExtensionEnabled(SbmlExtension.RENDER)) {
assignStyleToGlyph(reactionGlyph, createStyle(reaction));
}
if (reactionGlyph.getBoundingBox()==null) {
reactionGlyph.setBoundingBox(new BoundingBox());
}
if (reactionGlyph.getBoundingBox().getPosition()==null) {
reactionGlyph.getBoundingBox().setPosition(new Point());
}
reactionGlyph.getBoundingBox().getPosition().setZ(reaction.getZ());
}
......
......@@ -117,6 +117,12 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
Reaction reactionWithLayout = source.copy();
// getId doesn't have to be unique, therefore we concatenate with reaction
reactionWithLayout.setIdReaction(glyph.getReaction() + "__" + glyph.getId());
//z index
if (glyph.getBoundingBox() != null && glyph.getBoundingBox().getPosition() != null
&& glyph.getBoundingBox().getPosition().isSetZ()) {
reactionWithLayout.setZ((int) glyph.getBoundingBox().getPosition().getZ());
}
for (SpeciesReferenceGlyph speciesRefernceGlyph : glyph.getListOfSpeciesReferenceGlyphs()) {
SpeciesGlyph speciesGlyph = getLayout().getSpeciesGlyph(speciesRefernceGlyph.getSpeciesGlyph());
ReactionNode minervaNode = null;
......
......@@ -545,7 +545,8 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
}
TextGlyph textGlyph = getLayout().createTextGlyph("text_" + element.getElementId(), element.getName());
textGlyph
.setBoundingBox(createBoundingBox(element.getX(), element.getY(), element.getWidth(), element.getHeight()));
.setBoundingBox(createBoundingBox(element.getX(), element.getY(), element.getZ() + 1, element.getWidth(),
element.getHeight()));
textGlyph.setReference(speciesGlyph.getId());
if (isExtensionEnabled(SbmlExtension.RENDER)) {
......@@ -601,7 +602,7 @@ public class SbmlSpeciesExporter extends SbmlElementExporter<Species, org.sbml.j
double x = mr.getPosition().getX() - width / 2;
double y = mr.getPosition().getY() - height / 2;
BoundingBox boundingBox = new BoundingBox();
boundingBox.setPosition(new Point(x, y));
boundingBox.setPosition(new Point(x, y, mr.getSpecies().getZ() + 1));
Dimensions dimensions = new Dimensions();
dimensions.setWidth(width);
dimensions.setHeight(height);
......
......@@ -19,11 +19,10 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
@RunWith(Parameterized.class)
public class ElementPropertiesExport {
public class ElementPropertiesExport extends SbmlTestFunctions {
static Logger logger = Logger.getLogger(ElementPropertiesExport.class.getName());
......@@ -37,21 +36,21 @@ public class ElementPropertiesExport {
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<>();
data.add(createTestEntry("Empty", createElement()));
data.add(createTestEntry("Empty", createProtein()));
Species element = createElement();
Species element = createProtein();
element.setInitialConcentration(1.0);
data.add(createTestEntry("Initial concentration", element));
element = createElement();
element = createProtein();
element.setInitialAmount(2.0);
data.add(createTestEntry("Initial amount", element));
element = createElement();
element = createProtein();
element.setBoundaryCondition(true);
data.add(createTestEntry("Boundary condition", element));
element = createElement();
element = createProtein();
element.setConstant(true);
data.add(createTestEntry("Constatnt", element));
......@@ -67,15 +66,6 @@ public class ElementPropertiesExport {
return new Object[] { string, result };
}
private static Species createElement() {
Species element = new GenericProtein("id");
element.setX(10);
element.setY(10);
element.setWidth(1000);
element.setHeight(30);
return element;
}
@Test
public void createModelTest() throws Exception {
try {
......
......@@ -19,11 +19,10 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
@RunWith(Parameterized.class)
public class ElementPropertiesExportToLayoutTest {
public class ElementPropertiesExportToLayoutTest extends SbmlTestFunctions {
static Logger logger = Logger.getLogger(ElementPropertiesExportToLayoutTest.class.getName());
......@@ -37,9 +36,9 @@ public class ElementPropertiesExportToLayoutTest {
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<>();
data.add(createTestEntry("Empty", createElement()));
data.add(createTestEntry("Empty", createProtein()));
Species element = createElement();
Species element = createProtein();
element.setFontSize(40);
data.add(createTestEntry("Font size", element));
......@@ -55,15 +54,6 @@ public class ElementPropertiesExportToLayoutTest {
return new Object[] { string, result };
}
private static Species createElement() {
Species element = new GenericProtein("id");
element.setX(10);
element.setY(10);
element.setWidth(1000);
element.setHeight(30);
return element;
}
@Test
public void createModelTest() throws Exception {
try {
......
......@@ -20,11 +20,10 @@ import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
@RunWith(Parameterized.class)
public class ElementPropertiesExportToMultiTest {
public class ElementPropertiesExportToMultiTest extends SbmlTestFunctions {
static Logger logger = Logger.getLogger(ElementPropertiesExportToMultiTest.class.getName());
......@@ -38,45 +37,45 @@ public class ElementPropertiesExportToMultiTest {
public static Collection<Object[]> data() throws IOException {
Collection<Object[]> data = new ArrayList<>();
data.add(createTestEntry("Empty", createElement()));
data.add(createTestEntry("Empty", createProtein()));
Species element = createElement();
Species element = createProtein();
element.setAbbreviation("xyz");
data.add(createTestEntry("Abbreviation", element));
element = createElement();
element = createProtein();
element.setFormerSymbols(Arrays.asList(new String[] { "symbol 1", "s2" }));
data.add(createTestEntry("Former Symbols", element));
element = createElement();
element = createProtein();
element.setFormula("C2H5OH");
data.add(createTestEntry("Formula", element));
element = createElement();
element = createProtein();
element.setFullName("Amazing element");
data.add(createTestEntry("Full name", element));
element = createElement();
element = createProtein();
element.setHomodimer(4);
data.add(createTestEntry("Homodimer", element));
element = createElement();
element = createProtein();
element.setCharge(5);
data.add(createTestEntry("Charge", element));
element = createElement();
element = createProtein();
element.setHypothetical(true);
data.add(createTestEntry("Hypothetical", element));
element = createElement();
element = createProtein();
element.setActivity(true);
data.add(createTestEntry("Activity", element));
element = createElement();
element = createProtein();
element.setSymbol("H2O");
data.add(createTestEntry("Symbol", element));
element = createElement();
element = createProtein();
element.setSynonyms(Arrays.asList(new String[] { "syn 1", "s2" }));
data.add(createTestEntry("Synonyms", element));
......@@ -92,15 +91,6 @@ public class ElementPropertiesExportToMultiTest {
return new Object[] { string, result };
}
private static Species createElement() {
Species element = new GenericProtein("id");
element.setX(10);
element.setY(10);
element.setWidth(1000);
element.setHeight(30);
return element;
}
@Test
public void createModelTest() throws Exception {
try {
......
......@@ -15,8 +15,6 @@ import lcsb.mapviewer.model.map.reaction.Reaction;
public class SbmlExporterFromCellDesignerTest extends SbmlTestFunctions {
Logger logger = Logger.getLogger(SbmlExporterFromCellDesignerTest.class);
SbmlParser parser = new SbmlParser();
SbmlExporter exporter = new SbmlExporter();
CellDesignerXmlParser cellDesignerXmlParser = new CellDesignerXmlParser();
......@@ -51,14 +49,4 @@ public class SbmlExporterFromCellDesignerTest extends SbmlTestFunctions {
}
}
private Model getModelAfterSerializing(Model originalModel) throws Exception {
String xml = exporter.toXml(originalModel);
// logger.debug(xml);
ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
Model result = parser.createModel(new ConverterParams().inputStream(stream));
// showImage(originalModel);
// showImage(result);
return result;
}
}
......@@ -8,7 +8,6 @@ import static org.junit.Assert.assertTrue;
import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Point2D;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.lang.reflect.Modifier;
import java.util.Arrays;
......@@ -30,17 +29,13 @@ import lcsb.mapviewer.common.comparator.LineComparator;
import lcsb.mapviewer.common.comparator.ListComparator;
import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelComparator;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.reaction.AbstractNode;
import lcsb.mapviewer.model.map.reaction.Product;
import lcsb.mapviewer.model.map.reaction.Reactant;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.reaction.ReactionNode;
import lcsb.mapviewer.model.map.reaction.type.StateTransitionReaction;
import lcsb.mapviewer.model.map.species.Element;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
......@@ -50,13 +45,11 @@ import lcsb.mapviewer.model.map.species.field.Residue;
public class SbmlExporterTest extends SbmlTestFunctions {
Logger logger = Logger.getLogger(SbmlExporterTest.class);
SbmlParser parser = new SbmlParser();
SbmlExporter exporter;
ModelComparator comparator = new ModelComparator();
public SbmlExporterTest() {
exporter = new SbmlExporter();
exporter.setProvideDefaults(false);
}
@Test
......@@ -82,16 +75,6 @@ public class SbmlExporterTest extends SbmlTestFunctions {
return getModelAfterSerializing(originalModel);
}
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));
// showImage(originalModel);
// showImage(result);
return result;
}
@Test
public void testExportSpecies() throws Exception {
Model model = getModelAfterSerializing("testFiles/layoutExample/SpeciesGlyph_Example_level2_level3.xml");
......@@ -188,31 +171,13 @@ public class SbmlExporterTest extends SbmlTestFunctions {
private Model createModelWithReaction() {
Model model = createEmptyModel();
GenericProtein p1 = new GenericProtein("s1");
p1.setWidth(100);
p1.setHeight(20);
p1.setX(10);
GenericProtein p1 = createProtein();
p1.setY(10);
model.addElement(p1);
GenericProtein p2 = new GenericProtein("s2");
p2.setWidth(100);
p2.setHeight(20);
p2.setX(10);
GenericProtein p2 = createProtein();
p2.setY(50);
model.addElement(p2);
Reaction reaction = new StateTransitionReaction();
Reactant reactant = new Reactant(p1);
Product product = new Product(p2);
PolylineData reactantLine = new PolylineData();
reactantLine.addPoint(new Point2D.Double(50, 20));
reactantLine.addPoint(new Point2D.Double(50, 30));
reactant.setLine(reactantLine);
PolylineData productLine = new PolylineData();
productLine.addPoint(new Point2D.Double(50, 40));
productLine.addPoint(new Point2D.Double(50, 60));
product.setLine(productLine);
reaction.addReactant(reactant);
reaction.addProduct(product);
Reaction reaction = createReaction(p1, p2);
model.addReaction(reaction);
return model;
}
......@@ -344,6 +309,7 @@ public class SbmlExporterTest extends SbmlTestFunctions {
element.setWidth(10);
element.setY(10);
element.setHeight(10);
element.setZ(127);
model.addElement(element);
Model deserializedModel = getModelAfterSerializing(model);
......@@ -480,12 +446,7 @@ public class SbmlExporterTest extends SbmlTestFunctions {
public void testMultiExtensionProteinStateInTypes() throws Exception {
String structuralState = "xxx";
Model model = createEmptyModel();
GenericProtein element = new GenericProtein("id");
element.setName("test name");
element.setX(10);
element.setWidth(10);
element.setY(10);
element.setHeight(10);
GenericProtein element = createProtein();
element.setStructuralState(structuralState);
model.addElement(element);
org.sbml.jsbml.Model sbmlModel = exporter.toSbmlDocument(model).getModel();
......@@ -509,20 +470,10 @@ public class SbmlExporterTest extends SbmlTestFunctions {
public void testMultiExtensionProteinStateSuplicateInTypes() throws Exception {
String structuralState = "xxx";
Model model = createEmptyModel();
GenericProtein element = new GenericProtein("id");
element.setName("test name");
element.setX(10);
element.setWidth(10);
element.setY(10);
element.setHeight(10);
GenericProtein element = createProtein();
element.setStructuralState(structuralState);
model.addElement(element);
element = new GenericProtein("id2");
element.setName("test name");
element.setX(10);