Commit 963b391a authored by Piotr Gawron's avatar Piotr Gawron
Browse files

Merge branch '1278-semanticzoom-terms-in-textarea-are-exported-as-celldesigner' into 'master'

Resolve "SemanticZoom terms in textArea are exported as CellDesigner"

Closes #1278

See merge request !1170
parents 7bb43312 8422ec7f
Pipeline #28071 passed with stage
in 11 minutes and 6 seconds
......@@ -18,6 +18,8 @@ minerva (15.0.0~beta.5) unstable; urgency=medium
(#1274)
* Bug fix: uploading map with elements having identifiers like "artX" could
break upload (#1273)
* Bug fix: export from minerva does not include SemanticZoom terms for text
notes (#1287)
-- Piotr Gawron <piotr.gawron@uni.lu> Tue, 2 Jun 2020 16:00:00 +0200
......
......@@ -496,16 +496,6 @@ public class LayerXmlParser {
if (node.getNodeType() == Node.ELEMENT_NODE) {
if (node.getNodeName().equalsIgnoreCase("celldesigner:layerNotes")) {
String notes = XmlParser.getNodeValue(node).trim();
Color backgroundColor = extractBackgroundColor(notes);
if (backgroundColor != null) {
result.setBackgroundColor(backgroundColor);
notes = removeBackgroundColor(notes);
}
Color borderColor = extractBorderColor(notes);
if (borderColor != null) {
result.setBorderColor(borderColor);
notes = removeBorderColor(notes);
}
result.setNotes(notes);
} else if (node.getNodeName().equalsIgnoreCase("celldesigner:paint")) {
result.setColor(commonParser.getColor(node));
......@@ -545,25 +535,6 @@ public class LayerXmlParser {
return result.toString();
}
Color extractBackgroundColor(String notes) {
return extractColor(notes, "BackgroundColor");
}
Color extractBorderColor(String notes) {
return extractColor(notes, "BorderColor");
}
private Color extractColor(String notes, String string) {
String lines[] = notes.split("[\n\r]+");
for (String line : lines) {
if (line.startsWith(string + "=") || line.startsWith(string + ":")) {
String colorString = line.replace(string + "=", "").replace(string + ":", "");
return new ColorParser().parse(colorString);
}
}
return null;
}
/**
* Transforms LayerText object into CellDesigner xml node.
*
......
package lcsb.mapviewer.converter.model.celldesigner.annotation;
import lcsb.mapviewer.model.map.*;
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;
......@@ -134,6 +135,12 @@ public enum NoteField {
@ImportOnly
TRANSPARENCY_ZOOM_LEVEL_VISIBILITY("SemanticZoomLevelTransparency", Element.class, null),
@ImportOnly
BACKGROUND_COLOR("BackgroundColor", LayerText.class, null),
@ImportOnly
BORDER_COLOR("BorderColor", LayerText.class, null),
/**
* {@link Element#getSemanticZoomLevelVisibility()}.
*/
......
package lcsb.mapviewer.converter.model.celldesigner.annotation;
import java.awt.Color;
import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.util.*;
......@@ -14,7 +15,10 @@ import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.comparator.*;
import lcsb.mapviewer.common.exception.*;
import lcsb.mapviewer.common.geometry.ColorParser;
import lcsb.mapviewer.converter.annotation.XmlAnnotationParser;
import lcsb.mapviewer.model.LogMarker;
import lcsb.mapviewer.model.ProjectLogEntryType;
import lcsb.mapviewer.model.map.*;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.reaction.Reaction;
......@@ -761,10 +765,13 @@ public class RestAnnotationParser {
for (String string2 : string) {
boolean remove = false;
for (NoteField field : NoteField.values()) {
if (string2.startsWith(field.getCommonName() + ":") && field.getClazz().isAssignableFrom(object.getClass())) {
remove = true;
} else if (string2.startsWith(field.getCommonName() + "=")
&& field.getClazz().isAssignableFrom(object.getClass())) {
remove = true;
}
}
if (remove) {
annotations.append(string2 + "\n");
......@@ -775,7 +782,10 @@ public class RestAnnotationParser {
String ann = annotations.toString();
setZIndex(object, ann);
if (object instanceof LayerText) {
((LayerText) object).setNotes(newNotes.toString().trim());
LayerText layerText = (LayerText) object;
setBackgroundColor(layerText, ann);
setBorderColor(layerText, ann);
layerText.setNotes(newNotes.toString().trim());
}
if (object instanceof BioEntity) {
BioEntity bioEntity = (BioEntity) object;
......@@ -814,6 +824,47 @@ public class RestAnnotationParser {
}
}
private void setBackgroundColor(LayerText layerText, String ann) {
Color color = getColor(ann, NoteField.BACKGROUND_COLOR.getCommonName());
if (color == null) {
return;
}
if (layerText.getBackgroundColor() == null || layerText.getBackgroundColor().equals(Color.LIGHT_GRAY)) {
layerText.setBackgroundColor(color);
} else if (!layerText.getBackgroundColor().equals(color)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, layerText),
" New background color different than default [" + color + "]["
+ layerText.getBackgroundColor() + "]. Ignoring.");
}
}
private void setBorderColor(LayerText layerText, String ann) {
Color color = getColor(ann, NoteField.BORDER_COLOR.getCommonName());
if (color == null) {
return;
}
if (layerText.getBorderColor() == null || layerText.getBorderColor().equals(Color.LIGHT_GRAY)) {
layerText.setBorderColor(color);
} else if (!layerText.getBorderColor().equals(color)) {
logger.warn(new LogMarker(ProjectLogEntryType.PARSING_ISSUE, layerText),
" New border color different than default [" + color + "]["
+ layerText.getBorderColor() + "]. Ignoring.");
}
}
Color getColor(String notes, String string) {
String lines[] = notes.split("[\n\r]+");
for (String line : lines) {
if (line.startsWith(string + "=") || line.startsWith(string + ":")) {
String colorString = line.replace(string + "=", "").replace(string + ":", "");
return new ColorParser().parse(colorString);
}
}
return null;
}
/**
* Process RDF description from notes, removes it from the description and adds
* appropriate information to miriam data set.
......
......@@ -279,24 +279,6 @@ public class LayerXmlParserTest extends CellDesignerTestFunctions {
assertNotNull(xml);
}
@Test
public void testExtractBackgroundColor() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc");
assertNotNull(color);
}
@Test
public void testExtractBackgroundColorWithColon() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundColor:#ccffcc");
assertNotNull(color);
}
@Test
public void testExtractNonExistingBackgroundColor() throws Exception {
Color color = parser.extractBackgroundColor("dcxvxcvxcvx\nBackgroundCffcc");
assertNull(color);
}
@Test
public void testRemoveBackgroundColor() throws Exception {
String notes = parser.removeBackgroundColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc");
......
......@@ -2,6 +2,7 @@ package lcsb.mapviewer.converter.model.celldesigner.annotation;
import static org.junit.Assert.*;
import java.awt.Color;
import java.util.List;
import java.util.Set;
......@@ -18,6 +19,7 @@ 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.*;
......@@ -333,4 +335,27 @@ public class RestAnnotationParserTest extends CellDesignerTestFunctions {
assertFalse(protein.getNotes().contains("Description"));
}
@Test
public void testExtractBackgroundColor() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundColor=#ccffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNotNull(color);
}
@Test
public void testExtractBackgroundColorWithColon() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundColor:#ccffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNotNull(color);
}
@Test
public void testExtractNonExistingBackgroundColor() throws Exception {
RestAnnotationParser parser = new RestAnnotationParser();
Color color = parser.getColor("dcxvxcvxcvx\nBackgroundCffcc", NoteField.BACKGROUND_COLOR.getCommonName());
assertNull(color);
}
}
......@@ -187,6 +187,7 @@ public class CreateHierarchyCommand extends ModelCommand {
compartment.setZ(text.getZ());
compartment.setGlyph(text.getGlyph());
rap.processNotes(compartment);
text.setNotes(compartment.getName() + "\n" + compartment.getNotes());
compartment.setNamePoint(new Point2D.Double(text.getX() + DEFAULT_TITLE_X_COORD_IN_ARTIFITIAL_COMPARTMENT,
text.getY() + DEFAULT_TITLE_Y_COORD_IN_ARTIFITIAL_COMPARTMENT));
......
......@@ -17,8 +17,7 @@ import lcsb.mapviewer.converter.ConverterParams;
import lcsb.mapviewer.converter.model.celldesigner.CellDesignerXmlParser;
import lcsb.mapviewer.model.map.compartment.Compartment;
import lcsb.mapviewer.model.map.compartment.PathwayCompartment;
import lcsb.mapviewer.model.map.layout.graphics.Layer;
import lcsb.mapviewer.model.map.layout.graphics.LayerRect;
import lcsb.mapviewer.model.map.layout.graphics.*;
import lcsb.mapviewer.model.map.model.Model;
import lcsb.mapviewer.model.map.model.ModelFullIndexed;
import lcsb.mapviewer.model.map.species.*;
......@@ -329,7 +328,7 @@ public class CreateHierarchyCommandTest extends CommandTestFunctions {
layerRect2.setFillColor(Color.YELLOW);
layer.addLayerRect(layerRect2);
model.addLayer(layer);
Protein protein = createProtein();
protein.setElementId("art0");
model.addElement(protein);
......@@ -346,4 +345,37 @@ public class CreateHierarchyCommandTest extends CommandTestFunctions {
assertNotNull(pathway);
}
@Test
public void testProcessNotesForLayerText() throws Exception {
Model model = new ModelFullIndexed(null);
Layer layer = new Layer();
LayerText layerText = new LayerText();
layerText.setNotes("colors check\n" +
"SemanticZoomLevelVisibility: 3\n" +
"SemanticZoomLevelTransparency: 4\n" +
"BackgroundColor:#0000ee\n" +
"BorderColor:#00ee00");
layer.addLayerText(layerText);
model.addLayer(layer);
Protein protein = createProtein();
protein.setElementId("art0");
model.addElement(protein);
Protein protein2 = createProtein();
protein2.setElementId("art1");
model.addElement(protein2);
CreateHierarchyCommand command = new CreateHierarchyCommand(model, 4, 80);
command.createArtificials();
PathwayCompartment pathway = (PathwayCompartment) model.getCompartments().get(0);
assertNotNull(pathway);
assertFalse(layerText.getNotes().contains("SemanticZoomLevelVisibility"));
}
}
......@@ -4,6 +4,7 @@ import org.apache.logging.log4j.Marker;
import lcsb.mapviewer.common.exception.NotImplementedException;
import lcsb.mapviewer.model.map.BioEntity;
import lcsb.mapviewer.model.map.layout.graphics.LayerText;
import lcsb.mapviewer.model.map.reaction.ReactionNode;
public class LogMarker implements Marker {
......@@ -29,6 +30,15 @@ public class LogMarker implements Marker {
}
}
public LogMarker(ProjectLogEntryType type, LayerText layerText) {
entry = new ProjectLogEntry();
entry.setType(type);
if (layerText != null) {
entry.setObjectIdentifier(layerText.getElementId());
entry.setObjectClass(layerText.getClass().getSimpleName());
}
}
public LogMarker(ProjectLogEntryType type, ReactionNode node) {
entry = new ProjectLogEntry();
entry.setType(type);
......
......@@ -34,11 +34,8 @@ public class PolylineDataComparatorTest extends ModelTestFunctions {
@Test(expected = NotImplementedException.class)
public void testInvalid() {
class Tmp extends PolylineData {
private static final long serialVersionUID = 1L;
}
Tmp pd1 = new Tmp();
Tmp pd2 = new Tmp();
PolylineData pd1 = Mockito.mock(PolylineData.class);
PolylineData pd2 = Mockito.mock(PolylineData.class);
comparator.compare(pd1, pd2);
}
......
......@@ -113,11 +113,8 @@ public class LayerOvalComparatorTest extends ModelTestFunctions {
@Test(expected = NotImplementedException.class)
public void testInvalid() {
class Tmp extends LayerOval {
private static final long serialVersionUID = 1L;
}
Tmp layer1 = new Tmp();
Tmp layer2 = new Tmp();
LayerOval layer1 = Mockito.mock(LayerOval.class);
LayerOval layer2 = Mockito.mock(LayerOval.class);
comparator.compare(layer1, layer2);
}
......
......@@ -112,11 +112,8 @@ public class LayerRectComparatorTest extends ModelTestFunctions {
@Test(expected = NotImplementedException.class)
public void testInvalid() {
class Tmp extends LayerRect {
private static final long serialVersionUID = 1L;
}
Tmp layer1 = new Tmp();
Tmp layer2 = new Tmp();
LayerRect layer1 = Mockito.mock(LayerRect.class);
LayerRect layer2 = Mockito.mock(LayerRect.class);
comparator.compare(layer1, layer2);
}
......
......@@ -42,11 +42,8 @@ public class LayerTextComparatorTest extends ModelTestFunctions {
@Test(expected = NotImplementedException.class)
public void testInvalid() {
class Tmp extends LayerText {
private static final long serialVersionUID = 1L;
}
Tmp layer1 = new Tmp();
Tmp layer2 = new Tmp();
LayerText layer1 = Mockito.mock(LayerText.class);
LayerText layer2 = Mockito.mock(LayerText.class);
comparator.compare(layer1, layer2);
}
......
......@@ -899,6 +899,9 @@ public class ModelContructor {
e.getLine().setEndAtd(mt.getAtd());
e.getLine().setType(mt.getLineType());
mod.setLine(e.getLine());
mod.getLine().trimEnd(mt.getTrimLength());
return mod;
}
......
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