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

data model contain border coordinates for text label in Element

parent 28333f55
......@@ -162,7 +162,11 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
"Don't know what to do with celldesigner:point for class: " + result.getClass());
}
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:namePoint")) {
result.setNamePoint(getCommonParser().getPosition(node));
Point2D position = getCommonParser().getPosition(node);
result.setNameX(position.getX());
result.setNameY(position.getY());
result.setWidth(result.getWidth() - (result.getNameX() - result.getX()));
result.setHeight(result.getHeight() - (result.getNameY() - result.getY()));
result.setNameHorizontalAlign(HorizontalAlign.LEFT);
result.setNameVerticalAlign(VerticalAlign.TOP);
} else {
......@@ -171,9 +175,13 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
}
}
}
if (result.getNamePoint()==null) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE,result),"Name point is not defined");
result.setNamePoint(new Point2D.Double(result.getX(), result.getY()));
if (result.getNameX() == null || result.getNameY() == null || result.getNameWidth() == null
|| result.getNameHeight() == null) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, result), "Name point is not defined");
result.setNameX(result.getX());
result.setNameY(result.getY());
result.setNameWidth(result.getWidth());
result.setNameHeight(result.getHeight());
result.setNameHorizontalAlign(HorizontalAlign.LEFT);
result.setNameVerticalAlign(VerticalAlign.TOP);
}
......@@ -222,8 +230,8 @@ public class CompartmentAliasXmlParser extends AbstractAliasXmlParser<Compartmen
}
sb.append("<celldesigner:namePoint ");
sb.append("x=\"" + compartment.getNamePoint().getX() + "\" ");
sb.append("y=\"" + compartment.getNamePoint().getY() + "\"/>\n");
sb.append("x=\"" + compartment.getNameX() + "\" ");
sb.append("y=\"" + compartment.getNameY() + "\"/>\n");
sb.append(getDoubleLineNode(compartment));
......
package lcsb.mapviewer.converter.model.celldesigner.alias;
import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.Map;
......@@ -176,7 +175,10 @@ public class ComplexAliasXmlParser extends AbstractAliasXmlParser<Complex> {
}
complexAliasesMapById.put(result.getElementId(), result);
species.updateModelElementAfterLayoutAdded(result);
result.setNamePoint(new Point2D.Double(result.getCenterX(), result.getY() + result.getHeight() - 2));
result.setNameX(result.getX());
result.setNameY(result.getY());
result.setNameWidth(result.getWidth());
result.setNameHeight(result.getHeight());
result.setNameHorizontalAlign(HorizontalAlign.CENTER);
result.setNameVerticalAlign(VerticalAlign.BOTTOM);
return result;
......
......@@ -156,7 +156,10 @@ public class SpeciesAliasXmlParser extends AbstractAliasXmlParser<Species> {
}
species.updateModelElementAfterLayoutAdded(result);
result.setNamePoint(result.getCenter());
result.setNameX(result.getX());
result.setNameY(result.getY());
result.setNameWidth(result.getWidth());
result.setNameHeight(result.getHeight());
result.setNameHorizontalAlign(HorizontalAlign.CENTER);
result.setNameVerticalAlign(VerticalAlign.MIDDLE);
return result;
......
......@@ -227,10 +227,10 @@ public abstract class CellDesignerTestFunctions {
Model model2 = serializeModel(model);
ModelComparator comparator = new ModelComparator();
//import of unbounded compartments is problematic
for (Compartment compartment :model.getCompartments()) {
if (compartment instanceof BottomSquareCompartment ||
// import of unbounded compartments is problematic
for (Compartment compartment : model.getCompartments()) {
if (compartment instanceof BottomSquareCompartment ||
compartment instanceof TopSquareCompartment ||
compartment instanceof LeftSquareCompartment ||
compartment instanceof RightSquareCompartment) {
......@@ -261,26 +261,39 @@ public abstract class CellDesignerTestFunctions {
GenericProtein protein = new GenericProtein("id" + (idCounter++));
protein.setActivity(true);
protein.setFontSize(4);
protein.setHeight(10);
protein.setWidth(20);
protein.setX(30);
protein.setY(40);
protein.setStateLabel("xxx");
protein.setStatePrefix("yyy");
protein.setNamePoint(protein.getCenter());
protein.setNameHorizontalAlign(HorizontalAlign.CENTER);
protein.setNameVerticalAlign(VerticalAlign.MIDDLE);
assignCoordinates(30, 40, 10, 20, protein);
return protein;
}
protected SimpleMolecule createSimpleMolecule() {
SimpleMolecule result = new SimpleMolecule("id" + (idCounter++));
result.setX(50);
result.setY(60);
result.setNamePoint(result.getCenter());
result.setNameHorizontalAlign(HorizontalAlign.CENTER);
result.setNameVerticalAlign(VerticalAlign.MIDDLE);
assignCoordinates(50, 60, 20, 20, result);
return result;
}
static int zIndex = 10;
protected static void assignCoordinates(lcsb.mapviewer.model.map.species.Element element) {
assignCoordinates(10, 20, 30, 40, element);
}
protected static void assignCoordinates(double x, double y, double width, double height,
lcsb.mapviewer.model.map.species.Element element) {
element.setX(x);
element.setY(y);
element.setZ(zIndex++);
element.setWidth(width);
element.setHeight(height);
element.setNameX(x);
element.setNameY(y);
element.setNameWidth(width);
element.setNameHeight(height);
element.setNameVerticalAlign(VerticalAlign.MIDDLE);
element.setNameHorizontalAlign(HorizontalAlign.CENTER);
}
}
......@@ -2,7 +2,6 @@ package lcsb.mapviewer.converter.model.celldesigner.alias;
import static org.junit.Assert.*;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import java.util.List;
......@@ -285,11 +284,7 @@ public class AliasCollectionXmlParserTest extends CellDesignerTestFunctions {
private Compartment createCompartment(String id) {
Compartment compartment = new SquareCompartment(id);
compartment.setName("name" + id);
compartment.setX(13);
compartment.setY(14);
compartment.setWidth(100);
compartment.setHeight(120);
compartment.setNamePoint(new Point2D.Double(0, 1));
assignCoordinates(13, 14, 100, 120, compartment);
return compartment;
}
......
......@@ -2,8 +2,6 @@ package lcsb.mapviewer.converter.model.celldesigner.alias;
import static org.junit.Assert.*;
import java.awt.geom.Point2D;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
......@@ -54,8 +52,10 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
assertEquals(compartment.getWidth(), alias2.getWidth(), 1e-6);
assertEquals(compartment.getX(), alias2.getX(), 1e-6);
assertEquals(compartment.getY(), alias2.getY(), 1e-6);
assertEquals(compartment.getNamePoint().getX(), alias2.getNamePoint().getX(), 1e-6);
assertEquals(compartment.getNamePoint().getY(), alias2.getNamePoint().getY(), 1e-6);
assertEquals(compartment.getNameX(), alias2.getNameX(), 1e-6);
assertEquals(compartment.getNameY(), alias2.getNameY(), 1e-6);
assertEquals(compartment.getNameWidth(), alias2.getNameWidth(), 1e-6);
assertEquals(compartment.getNameHeight(), alias2.getNameHeight(), 1e-6);
assertNotNull(alias2.getNameHorizontalAlign());
assertNotNull(alias2.getNameVerticalAlign());
}
......@@ -63,11 +63,7 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
private Compartment createCompartment() {
Compartment compartment = new SquareCompartment("comp_id");
compartment.setName("name");
compartment.setX(13);
compartment.setY(14);
compartment.setWidth(100);
compartment.setHeight(120);
compartment.setNamePoint(new Point2D.Double(0, 1));
assignCoordinates(13, 14, 100, 120, compartment);
return compartment;
}
......@@ -127,8 +123,9 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
assertEquals(139.0, alias.getX(), 1e-6);
assertEquals(55.0, alias.getY(), 1e-6);
assertEquals(522.0, alias.getWidth(), 1e-6);
assertEquals(392.5, alias.getNamePoint().getX(), 1e-6);
assertEquals(196.5, alias.getNamePoint().getY(), 1e-6);
assertEquals(392.5, alias.getNameX(), 1e-6);
assertEquals(196.5, alias.getNameY(), 1e-6);
assertEquals(522.0, alias.getNameWidth(), 1e-6);
assertEquals(0xffcccc00, alias.getFillColor().getRGB());
}
......@@ -142,7 +139,7 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
@Test
public void testLeftToXml() throws Exception {
Compartment alias = new LeftSquareCompartment("id");
alias.setNamePoint(new Point2D.Double());
assignCoordinates(alias);
String xml = parser.toXml(alias);
assertNotNull(xml);
}
......@@ -150,7 +147,7 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
@Test
public void testRightToXml() throws Exception {
Compartment alias = new RightSquareCompartment("id");
alias.setNamePoint(new Point2D.Double());
assignCoordinates(alias);
String xml = parser.toXml(alias);
assertNotNull(xml);
}
......@@ -158,7 +155,7 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
@Test
public void testTopToXml() throws Exception {
Compartment alias = new TopSquareCompartment("id");
alias.setNamePoint(new Point2D.Double());
assignCoordinates(alias);
String xml = parser.toXml(alias);
assertNotNull(xml);
}
......@@ -166,7 +163,7 @@ public class CompartmentAliasXmlParserTest extends CellDesignerTestFunctions {
@Test
public void testBotttomToXml() throws Exception {
Compartment alias = new BottomSquareCompartment("id");
alias.setNamePoint(new Point2D.Double());
assignCoordinates(alias);
String xml = parser.toXml(alias);
assertNotNull(xml);
}
......
......@@ -73,7 +73,10 @@ public class ComplexAliasXmlParserTest extends CellDesignerTestFunctions {
assertEquals(100.0, alias.getWidth(), Configuration.EPSILON);
assertEquals(744.0, alias.getX(), Configuration.EPSILON);
assertEquals(0.0, alias.getY(), Configuration.EPSILON);
assertNotNull(alias.getNamePoint());
assertNotNull(alias.getNameX());
assertNotNull(alias.getNameY());
assertNotNull(alias.getNameWidth());
assertNotNull(alias.getNameHeight());
assertNotNull(alias.getNameHorizontalAlign());
assertNotNull(alias.getNameVerticalAlign());
}
......
......@@ -67,7 +67,10 @@ public class SpeciesAliasXmlParserTest extends CellDesignerTestFunctions {
assertEquals(11813.0, alias.getX(), 1e-6);
assertEquals(2840.5, alias.getY(), 1e-6);
assertEquals("ca1", alias.getCompartment().getElementId());
assertNotNull(alias.getNamePoint());
assertNotNull(alias.getNameX());
assertNotNull(alias.getNameY());
assertNotNull(alias.getNameWidth());
assertNotNull(alias.getNameHeight());
assertNotNull(alias.getNameHorizontalAlign());
assertNotNull(alias.getNameVerticalAlign());
}
......
......@@ -19,7 +19,6 @@ import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.reaction.Reaction;
import lcsb.mapviewer.model.map.species.*;
......
......@@ -2,8 +2,6 @@ package lcsb.mapviewer.converter.model.celldesigner.compartment;
import static org.junit.Assert.*;
import java.awt.geom.Point2D;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.junit.*;
......@@ -137,7 +135,7 @@ public class CompartmentParserTests extends CellDesignerTestFunctions {
Model model = new ModelFullIndexed(null);
Compartment compartment = new SquareCompartment("c");
compartment.setName("xyz");
compartment.setNamePoint(new Point2D.Double());
assignCoordinates(compartment);
model.addElement(compartment);
Model model2 = super.serializeModel(model);
......@@ -148,7 +146,7 @@ public class CompartmentParserTests extends CellDesignerTestFunctions {
public void testToXmlWithCompartmentIdNotRecognizedByCellDesignerAndChildren() throws Exception {
Model model = new ModelFullIndexed(null);
Compartment compartment = new SquareCompartment("c");
compartment.setNamePoint(new Point2D.Double());
assignCoordinates(compartment);
compartment.setName("xyz");
model.addElement(compartment);
......
......@@ -17,7 +17,6 @@ import org.xml.sax.InputSource;
import lcsb.mapviewer.common.Pair;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerElementCollection;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.species.ProteinXmlParserTest;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerCompartment;
import lcsb.mapviewer.model.map.compartment.Compartment;
......
......@@ -3,18 +3,14 @@ package lcsb.mapviewer.converter.model.celldesigner.types;
import static org.junit.Assert.*;
import java.awt.geom.Point2D;
import java.lang.reflect.Field;
import org.junit.*;
import org.mockito.Mockito;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerTestFunctions;
import lcsb.mapviewer.converter.model.celldesigner.structure.CellDesignerElement;
import lcsb.mapviewer.model.graphics.PolylineData;
import lcsb.mapviewer.model.map.reaction.*;
import lcsb.mapviewer.model.map.species.GenericProtein;
import lcsb.mapviewer.model.map.species.Species;
public class ModifierTypeUtilsTest extends CellDesignerTestFunctions {
......
......@@ -761,9 +761,10 @@ public class SbgnmlXmlParser {
if (g.getLabel() != null) {
newSpecies.setName(g.getLabel().getText());
if (g.getLabel().getBbox() != null) {
double x = g.getLabel().getBbox().getX() + g.getLabel().getBbox().getW() / 2;
double y = g.getLabel().getBbox().getY() + g.getLabel().getBbox().getH() / 2;
newSpecies.setNamePoint(x, y);
newSpecies.setNameX(g.getLabel().getBbox().getX());
newSpecies.setNameY(g.getLabel().getBbox().getY());
newSpecies.setNameWidth(g.getLabel().getBbox().getW());
newSpecies.setNameHeight(g.getLabel().getBbox().getH());
newSpecies.setNameHorizontalAlign(HorizontalAlign.CENTER);
newSpecies.setNameVerticalAlign(VerticalAlign.MIDDLE);
}
......@@ -918,13 +919,16 @@ public class SbgnmlXmlParser {
species.setWidth(new Double(glyph.getBbox().getW()));
species.setX(new Double(glyph.getBbox().getX()));
species.setY(new Double(glyph.getBbox().getY()));
if (species.getNamePoint() == null) {
if (species.getNameX() == null || species.getNameY() == null) {
species.setNameX(species.getX());
species.setNameY(species.getY());
species.setNameWidth(species.getWidth());
species.setNameHorizontalAlign(HorizontalAlign.CENTER);
if (species instanceof Complex) {
species.setNamePoint(new Point2D.Double(species.getCenterX(), species.getY() + species.getHeight() - 2));
species.setNameVerticalAlign(VerticalAlign.BOTTOM);
species.setNameHeight(species.getHeight() - 2);
} else {
species.setNamePoint(species.getCenter());
species.setNameHeight(species.getHeight());
species.setNameVerticalAlign(VerticalAlign.MIDDLE);
}
}
......@@ -1067,7 +1071,10 @@ public class SbgnmlXmlParser {
nullParent.setHeight(Double.MAX_VALUE);
nullParent.setX(0.0);
nullParent.setY(0.0);
nullParent.setNamePoint(new Point2D.Double(10, 10));
nullParent.setNameX(10);
nullParent.setNameY(10);
nullParent.setNameWidth(Double.MAX_VALUE);
nullParent.setNameHeight(Double.MAX_VALUE);
nullParent.setNameHorizontalAlign(HorizontalAlign.LEFT);
nullParent.setNameVerticalAlign(VerticalAlign.TOP);
Compartment parent = nullParent;
......@@ -1986,12 +1993,18 @@ public class SbgnmlXmlParser {
compartment.setBorderColor(COMPARTMENT_COLOR);
if (glyph.getLabel() != null && glyph.getLabel().getBbox() != null) {
compartment.setNamePoint(glyph.getLabel().getBbox().getX(), glyph.getLabel().getBbox().getY());
compartment.setNameX(glyph.getLabel().getBbox().getX());
compartment.setNameY(glyph.getLabel().getBbox().getY());
compartment.setNameWidth(glyph.getLabel().getBbox().getW());
compartment.setNameHeight(glyph.getLabel().getBbox().getH());
compartment.setNameHorizontalAlign(HorizontalAlign.LEFT);
compartment.setNameVerticalAlign(VerticalAlign.TOP);
} else {
compartment.setNamePoint(compartment.getX() + compartment.getThickness() + CONTAINER_NAME_MARGIN,
compartment.getY() + compartment.getThickness() + CONTAINER_NAME_MARGIN);
compartment.setNameX(compartment.getX() + compartment.getThickness() + CONTAINER_NAME_MARGIN);
compartment.setNameY(compartment.getY() + compartment.getThickness() + CONTAINER_NAME_MARGIN);
compartment.setNameWidth(compartment.getWidth() - 2 * (compartment.getThickness() + CONTAINER_NAME_MARGIN));
compartment.setNameHeight(compartment.getHeight() - 2 * (compartment.getThickness() + CONTAINER_NAME_MARGIN));
compartment.setNameHorizontalAlign(HorizontalAlign.LEFT);
compartment.setNameVerticalAlign(VerticalAlign.TOP);
}
......
......@@ -95,12 +95,18 @@ public class SbgnmlXmlParserTest extends SbgnmlTestFunctions {
model2.setNotes(model.getNotes());
for (Element element : model.getElements()) {
element.setNamePoint(null);
element.setNameX(0);
element.setNameY(0);
element.setNameWidth(0);
element.setNameHeight(0);
element.setNameHorizontalAlign(null);
element.setNameVerticalAlign(null);
}
for (Element element : model2.getElements()) {
element.setNamePoint(null);
element.setNameX(0);
element.setNameY(0);
element.setNameWidth(0);
element.setNameHeight(0);
element.setNameHorizontalAlign(null);
element.setNameVerticalAlign(null);
}
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.geom.*;
import java.awt.geom.Area;
import java.awt.geom.Rectangle2D;
import java.util.List;
import org.apache.logging.log4j.LogManager;
......@@ -154,10 +155,10 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
// draw description
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
Rectangle2D tmpBorder = compartment.getNameBorder();
compartment.setNameBorder(compartment.getBorder());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
compartment.setNameBorder(tmpBorder);
}
}
......@@ -223,9 +224,8 @@ public abstract class CompartmentConverter<T extends Compartment> extends Elemen
}
} else {
border = new Rectangle2D.Double(
compartment.getNamePoint().getX(), compartment.getNamePoint().getY(),
compartment.getWidth() - (compartment.getNamePoint().getX() - compartment.getX()),
compartment.getHeight() - (compartment.getNamePoint().getY() - compartment.getY()));
compartment.getNameX(), compartment.getNameY(),
compartment.getNameWidth(), compartment.getNameHeight());
}
double fontSize = compartment.getFontSize() * params.getScale();
......
package lcsb.mapviewer.converter.graphics.bioEntity.element.compartment;
import java.awt.*;
import java.awt.geom.Point2D;
import java.awt.geom.Rectangle2D;
import lcsb.mapviewer.commands.ColorExtractor;
......@@ -61,10 +60,10 @@ public class PathwayCompartmentConverter extends CompartmentConverter<PathwayCom
// draw description of the compartment
if (fill) {
Point2D tmpPoint = compartment.getNamePoint();
compartment.setNamePoint(compartment.getCenter());
Rectangle2D tmpBorder = compartment.getNameBorder();
compartment.setNameBorder(compartment.getBorder());
drawText(compartment, graphics, params);
compartment.setNamePoint(tmpPoint);
compartment.setNameBorder(tmpBorder);
} else {
if (!compartment.containsIdenticalSpecies()) {
drawText(compartment, graphics, params);
......
......@@ -207,7 +207,7 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
* the text is given as a point. Both parameters centered described if text
* should be automatically centered horizontally and vertically.
*
* @param point
* @param border
* where the text should be drawn
* @param text
* text to draw
......@@ -218,37 +218,38 @@ public abstract class SpeciesConverter<T extends Species> extends ElementConvert
* @param verticalCentered
* should the text be vertically centered
*/
protected void drawText(final Point2D point, final String text, final Graphics2D graphics,
protected void drawText(final Rectangle2D border, final String text, final Graphics2D graphics,
HorizontalAlign horizontalAlign, VerticalAlign verticalAlign) {
double height = getTextHeight(text, graphics);
double x = point.getX();
double y = point.getY();
double y = border.getY();
String[] lines = text.split("\n");
double lineHeight = graphics.getFontMetrics().getHeight();
switch (verticalAlign) {
case TOP:
y = border.getMinY();
break;
case MIDDLE:
y -= height / 2 - graphics.getFontMetrics().getAscent();
y = border.getCenterY() - (height / 2 - graphics.getFontMetrics().getAscent());
break;
case BOTTOM:
y -= height - graphics.getFontMetrics().getAscent();
y = border.getMaxY() - (height - graphics.getFontMetrics().getAscent());
break;
default:
throw new InvalidArgumentException("Don't know how to align text with: " + verticalAlign);
}
for (String string : lines) {
double currX = x;
double currX;
switch (horizontalAlign) {
case LEFT:
currX = border.getX();
break;
case CENTER:
currX -= getTextWidth(string, graphics) / 2;
currX = border.getCenterX() - getTextWidth(string, graphics) / 2;
break;
case RIGTH:
currX -= getTextWidth(string, graphics);
currX = border.getMaxX() - getTextWidth(string, graphics);