Skip to content
Snippets Groups Projects
Commit 78efa4fe authored by Piotr Gawron's avatar Piotr Gawron
Browse files

z-index can be passed as a parameter in cell designer file

parent 0b2d056a
No related branches found
No related tags found
1 merge request!768Resolve "Custom images as overlay levels or background"
Showing
with 131 additions and 51 deletions
......@@ -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;
}
......
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 {
}
......@@ -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.
......
......@@ -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);
}
}
}
......
......@@ -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 {
......
......@@ -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);
......
<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>
......@@ -551,4 +551,8 @@ public class PolylineData implements Serializable, Drawable {
return 0;
}
@Override
public String getElementId() {
return toString();
}
}
......@@ -196,8 +196,6 @@ public interface BioEntity extends Serializable, Drawable {
*/
Model getModel();
String getElementId();
BioEntity copy();
}
......@@ -37,5 +37,7 @@ public interface Drawable {
*/
void setZ(Integer z);
String getElementId();
double getSize();
}
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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;
}
......
......@@ -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";
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment