From 78efa4fea52a3cf85c3f2b8745fda9202c9d9041 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Wed, 8 May 2019 20:34:53 +0200 Subject: [PATCH] z-index can be passed as a parameter in cell designer file --- .../model/celldesigner/LayerXmlParser.java | 2 + .../celldesigner/annotation/ImportOnly.java | 13 +++ .../celldesigner/annotation/NoteField.java | 6 +- .../annotation/RestAnnotationParser.java | 87 ++++++++++++------- .../celldesigner/LayerXmlParserTest.java | 13 +++ .../annotation/RestAnnotationParserTest.java | 6 +- .../layer_text_with_z_index.xml | 9 ++ .../model/graphics/PolylineData.java | 4 + .../lcsb/mapviewer/model/map/BioEntity.java | 2 - .../lcsb/mapviewer/model/map/Drawable.java | 2 + .../model/map/layout/graphics/LayerOval.java | 7 +- .../model/map/layout/graphics/LayerRect.java | 6 ++ .../model/map/layout/graphics/LayerText.java | 5 ++ .../mapviewer/model/map/species/Element.java | 5 +- .../modelutils/map/ElementUtils.java | 15 +--- 15 files changed, 131 insertions(+), 51 deletions(-) create mode 100644 converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/ImportOnly.java create mode 100644 converter-CellDesigner/testFiles/xmlNodeTestExamples/layer_text_with_z_index.xml diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java index 8507bccf69..d84b7d7567 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParser.java @@ -13,6 +13,7 @@ import org.w3c.dom.NodeList; import lcsb.mapviewer.common.XmlParser; import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.geometry.ColorParser; +import lcsb.mapviewer.converter.model.celldesigner.annotation.RestAnnotationParser; import lcsb.mapviewer.model.graphics.ArrowType; import lcsb.mapviewer.model.graphics.LineType; import lcsb.mapviewer.model.graphics.PolylineData; @@ -522,6 +523,7 @@ public class LayerXmlParser { } } } + new RestAnnotationParser().processNotes(result.getNotes(), result); return result; } diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/ImportOnly.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/ImportOnly.java new file mode 100644 index 0000000000..3f62862dcf --- /dev/null +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/ImportOnly.java @@ -0,0 +1,13 @@ +package lcsb.mapviewer.converter.model.celldesigner.annotation; + +import static java.lang.annotation.ElementType.FIELD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +@Retention(RUNTIME) +@Target(FIELD) +public @interface ImportOnly { + +} diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/NoteField.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/NoteField.java index 6926d78e61..6b7826e7de 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/NoteField.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/NoteField.java @@ -135,7 +135,11 @@ public enum NoteField { */ @Deprecated TRANSPARENCY_ZOOM_LEVEL_VISIBILITY_OLD("TransparencyZoomLevelVisibility", Element.class, null), - ; + + @ImportOnly + Z_INDEX("Z-Index", BioEntity.class, null), + + ; /** * Name used in the notes to distinguish fields. diff --git a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParser.java b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParser.java index a2861c3f3e..94e0a5f499 100644 --- a/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParser.java +++ b/converter-CellDesigner/src/main/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParser.java @@ -23,9 +23,11 @@ import lcsb.mapviewer.common.exception.InvalidXmlSchemaException; import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.converter.annotation.XmlAnnotationParser; import lcsb.mapviewer.model.map.BioEntity; +import lcsb.mapviewer.model.map.Drawable; import lcsb.mapviewer.model.map.MiriamData; import lcsb.mapviewer.model.map.MiriamRelationType; import lcsb.mapviewer.model.map.MiriamType; +import lcsb.mapviewer.model.map.layout.graphics.LayerText; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.species.Element; import lcsb.mapviewer.model.map.species.Species; @@ -702,6 +704,24 @@ public class RestAnnotationParser { } } + private void setZIndex(Drawable element, String annotationString) { + String zIndex = getParamByPrefix(annotationString, + NoteField.Z_INDEX.getCommonName() + ":"); + if (zIndex != null) { + try { + Integer z = Integer.valueOf(zIndex); + if (element.getZ() == null) { + element.setZ(z); + } else if (!element.getZ().equals(z)) { + logger.warn(elementUtils.getElementTag(element) + " New " + NoteField.Z_INDEX.getCommonName() + + " different than default [" + zIndex + "][" + element.getZ() + "]. Ignoring."); + } + } catch (NumberFormatException e) { + logger.warn("Invalid e index", e); + } + } + } + /** * Assigns notes to the element from notes string. This might look strange. The * idea is that sometimes we have notes from more then one source. And the data @@ -739,7 +759,7 @@ public class RestAnnotationParser { * @param object * where the structural data should be put */ - public void processNotes(String notes, BioEntity object) { + public void processNotes(String notes, Drawable object) { StringBuilder annotations = new StringBuilder(); String[] string = notes.split("\n"); @@ -758,38 +778,45 @@ public class RestAnnotationParser { newNotes.append(string2 + "\n"); } } - object.setNotes(newNotes.toString().trim()); - String ann = annotations.toString(); - setNotes(object, ann); - setSymbol(object, ann); - setSynonyms(object, ann); - setSemanticZoomLevelVisibility(object, ann); - setAbbreviation(object, ann); - setFormula(object, ann); - if (object instanceof Reaction) { - Reaction reaction = (Reaction) object; - setMechanicalConfidenceScoreToReaction(reaction, ann); - setLowerBoundToReaction(reaction, ann); - setUpperBoundToReaction(reaction, ann); - setSubsystemToReaction(reaction, ann); - setGeneProteinReactionToReaction(reaction, ann); - } else if (object instanceof Element) { - setTransparencyZoomLevelVisibility((Element) object, ann); - setFullNameToSpecies((Element) object, ann); - setFormerSymbolsToSpecies((Element) object, ann); - if (object instanceof Species) { - setCharge((Species) object, ann); + setZIndex(object, ann); + if (object instanceof LayerText) { + ((LayerText) object).setNotes(newNotes.toString().trim()); + } + if (object instanceof BioEntity) { + BioEntity bioEntity = (BioEntity) object; + bioEntity.setNotes(newNotes.toString().trim()); + + setNotes(bioEntity, ann); + setSymbol(bioEntity, ann); + setSynonyms(bioEntity, ann); + setSemanticZoomLevelVisibility(bioEntity, ann); + setAbbreviation(bioEntity, ann); + setFormula(bioEntity, ann); + if (object instanceof Reaction) { + Reaction reaction = (Reaction) object; + setMechanicalConfidenceScoreToReaction(reaction, ann); + setLowerBoundToReaction(reaction, ann); + setUpperBoundToReaction(reaction, ann); + setSubsystemToReaction(reaction, ann); + setGeneProteinReactionToReaction(reaction, ann); + } else if (object instanceof Element) { + setTransparencyZoomLevelVisibility((Element) object, ann); + setFullNameToSpecies((Element) object, ann); + setFormerSymbolsToSpecies((Element) object, ann); + if (object instanceof Species) { + setCharge((Species) object, ann); + } + } else { + throw new NotImplementedException("Don't know how to process class: " + object.getClass()); } - } else { - throw new NotImplementedException("Don't know how to process class: " + object.getClass()); - } - try { - processRdfDescription(object); - } catch (InvalidXmlSchemaException e) { - String warning = elementUtils.getElementTag(object) + " Problem with processing notes. Invalid RDF node."; - logger.warn(warning); + try { + processRdfDescription(bioEntity); + } catch (InvalidXmlSchemaException e) { + String warning = elementUtils.getElementTag(object) + " Problem with processing notes. Invalid RDF node."; + logger.warn(warning); + } } } diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParserTest.java index bcbebd1dda..cd86511d35 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/LayerXmlParserTest.java @@ -391,6 +391,19 @@ public class LayerXmlParserTest extends CellDesignerTestFunctions { } } + @Test + public void testGetLayerTextWithZIndex() throws Exception { + try { + String xmlString = readFile("testFiles/xmlNodeTestExamples/layer_text_with_z_index.xml"); + Node node = getNodeFromXmlString(xmlString); + LayerText layer = parser.getLayerText(node); + assertEquals((Integer) 19, layer.getZ()); + } catch (Exception e) { + e.printStackTrace(); + throw e; + } + } + @Test public void testParseInvalidLayerText() throws Exception { try { diff --git a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java index 8954ef209f..ad764b200d 100644 --- a/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java +++ b/converter-CellDesigner/src/test/java/lcsb/mapviewer/converter/model/celldesigner/annotation/RestAnnotationParserTest.java @@ -295,17 +295,19 @@ public class RestAnnotationParserTest extends CellDesignerTestFunctions { for (NoteField field : NoteField.values()) { boolean deprecated = false; + boolean importOnly = false; try { Field f = NoteField.class.getField(field.name()); if (f.isAnnotationPresent(Deprecated.class)) deprecated = true; + if (f.isAnnotationPresent(ImportOnly.class)) + importOnly = true; } catch (NoSuchFieldException | SecurityException e) { } - if (!deprecated) { + if (!deprecated && !importOnly) { if (field.getClazz().isAssignableFrom(element.getClass()) - || CellDesignerElement.class.isAssignableFrom(field.getClazz())) { assertTrue("Export string doesn't contain info about: " + field.getCommonName(), str.indexOf(field.getCommonName()) >= 0); diff --git a/converter-CellDesigner/testFiles/xmlNodeTestExamples/layer_text_with_z_index.xml b/converter-CellDesigner/testFiles/xmlNodeTestExamples/layer_text_with_z_index.xml new file mode 100644 index 0000000000..68185b6d00 --- /dev/null +++ b/converter-CellDesigner/testFiles/xmlNodeTestExamples/layer_text_with_z_index.xml @@ -0,0 +1,9 @@ +<celldesigner:layerSpeciesAlias x="0.0" y="0.0"> +<celldesigner:layerNotes> +text node +Z-Index: 19 +</celldesigner:layerNotes> +<celldesigner:bounds x="55.0" y="37.0" w="152.0" h="105.0"/> +<celldesigner:paint color="ff000000"/> +<celldesigner:font size="11"/> +</celldesigner:layerSpeciesAlias> diff --git a/model/src/main/java/lcsb/mapviewer/model/graphics/PolylineData.java b/model/src/main/java/lcsb/mapviewer/model/graphics/PolylineData.java index c6579e150b..efb5eb7076 100644 --- a/model/src/main/java/lcsb/mapviewer/model/graphics/PolylineData.java +++ b/model/src/main/java/lcsb/mapviewer/model/graphics/PolylineData.java @@ -551,4 +551,8 @@ public class PolylineData implements Serializable, Drawable { return 0; } + @Override + public String getElementId() { + return toString(); + } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/BioEntity.java b/model/src/main/java/lcsb/mapviewer/model/map/BioEntity.java index b7ab37bcb5..9879bc60c5 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/BioEntity.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/BioEntity.java @@ -196,8 +196,6 @@ public interface BioEntity extends Serializable, Drawable { */ Model getModel(); - String getElementId(); - BioEntity copy(); } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/Drawable.java b/model/src/main/java/lcsb/mapviewer/model/map/Drawable.java index 72c198d181..473fdeed72 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/Drawable.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/Drawable.java @@ -37,5 +37,7 @@ public interface Drawable { */ void setZ(Integer z); + String getElementId(); + double getSize(); } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerOval.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerOval.java index 4361ed2ada..88b9d684d2 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerOval.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerOval.java @@ -276,7 +276,12 @@ public class LayerOval implements Serializable, Drawable { @Override public double getSize() { - return width*height; + return width * height; + } + + @Override + public String getElementId() { + return "x=" + x + ";y=" + y + "; w=" + width + ", h=" + height; } } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerRect.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerRect.java index 493d3ab9e7..e0a163b9f8 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerRect.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerRect.java @@ -261,4 +261,10 @@ public class LayerRect implements Serializable, Drawable { public double getSize() { return width * height; } + + @Override + public String getElementId() { + return "x=" + x + ";y=" + y + "; w=" + width + ", h=" + height; + } + } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java index af87c2ee02..d866c3e6e1 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/layout/graphics/LayerText.java @@ -372,4 +372,9 @@ public class LayerText implements Serializable, Drawable { return width * height; } + @Override + public String getElementId() { + return "x=" + x + ";y=" + y + "; w=" + width + ", h=" + height; + } + } diff --git a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java index bef7a61fc7..9623aaa428 100644 --- a/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java +++ b/model/src/main/java/lcsb/mapviewer/model/map/species/Element.java @@ -640,10 +640,7 @@ public abstract class Element implements BioEntity, Serializable, SbmlArgument { this.fontSize = fontSize; } - /** - * @return the elementId - * @see #elementId - */ + @Override public String getElementId() { return elementId; } diff --git a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java index 932fb236d8..1998162145 100644 --- a/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java +++ b/model/src/main/java/lcsb/mapviewer/modelutils/map/ElementUtils.java @@ -11,8 +11,8 @@ import java.util.Set; import org.apache.log4j.Logger; import org.reflections.Reflections; -import lcsb.mapviewer.common.exception.NotImplementedException; import lcsb.mapviewer.model.map.BioEntity; +import lcsb.mapviewer.model.map.Drawable; import lcsb.mapviewer.model.map.reaction.Reaction; import lcsb.mapviewer.model.map.reaction.ReactionNode; import lcsb.mapviewer.model.map.species.Element; @@ -57,7 +57,7 @@ public final class ElementUtils { * tag for this element is created * @return tag that identifies element */ - public String getElementTag(BioEntity element) { + public String getElementTag(Drawable element) { return getElementTag(element, null); } @@ -72,15 +72,8 @@ public final class ElementUtils { * null (in such situation it will be skipped in the tag) * @return tag that identifies element */ - public String getElementTag(BioEntity element, Object annotator) { - String id = null; - if (element instanceof Element) { - id = ((Element) element).getElementId(); - } else if (element instanceof Reaction) { - id = ((Reaction) element).getIdReaction(); - } else { - throw new NotImplementedException("Unknown class: " + element.getClass()); - } + public String getElementTag(Drawable element, Object annotator) { + String id = element.getElementId(); if (annotator != null) { return "[" + annotator.getClass().getSimpleName() + "]\t[" + element.getClass().getSimpleName() + " " + id + "]\t"; -- GitLab