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

Merge branch '744-sbml-reaction-color-coding' into 'devel_12.2.x'

Resolve "color coding for reaction in sbml is improperly used (Copasi doesn't reaction colors provided by minerva)"

See merge request minerva/core!718
parents 31199bb0 0205bf8f
minerva (12.2.1) stable; urgency=medium
* Bug fix: export of reaction colorsi in SBML is properly encoded (COPASI can
read colors properly) (#744)
-- Piotr Gawron <piotr.gawron@uni.lu> Mon, 1 Apr 2019 17:00:00 +0200
minerva (12.2.0) stable; urgency=medium
* Feature: bug report utility
* Feature: url GET parameters support all kind of search and selected overlays
......
package lcsb.mapviewer.common.comparator;
import java.util.Comparator;
import lcsb.mapviewer.common.Configuration;
/**
* Comparator used for {@link Float} class.
*
* @author Piotr Gawron
*
*/
public class FloatComparator implements Comparator<Float> {
/**
* Epsilon value used for comparison of doubles.
*/
private double epsilon;
/**
* Default constructor.
*/
public FloatComparator() {
this(Configuration.EPSILON);
}
/**
* Constructor that requires {@link #epsilon} parameter.
*
* @param epsilon
* {@link #epsilon}
*/
public FloatComparator(double epsilon) {
this.epsilon = epsilon;
}
@Override
public int compare(Float arg0, Float arg1) {
if (arg0 == null) {
if (arg1 == null) {
return 0;
} else {
return 1;
}
} else if (arg1 == null) {
return -1;
}
if (Math.abs(arg0 - arg1) < epsilon) {
return 0;
} else {
return arg0.compareTo(arg1);
}
}
}
......@@ -293,10 +293,10 @@ public class SbmlReactionExporter extends SbmlBioEntityExporter<Reaction, org.sb
LocalStyle style = new LocalStyle();
style.setGroup(new RenderGroup());
renderInformation.addLocalStyle(style);
style.getGroup().setStroke(node.getLine().getType().name());
ColorDefinition color = getColorDefinition(node.getLine().getColor());
style.getGroup().setStrokeWidth(node.getLine().getWidth());
style.getGroup().setStroke(color.getId());
style.getGroup().setFill(color.getId());
style.getGroup().setStrokeWidth(node.getLine().getWidth());
style.getGroup().setStrokeDashArray(strokeToArray(node.getLine().getType().getStroke()));
return style;
......
......@@ -30,6 +30,7 @@ import org.sbml.jsbml.ext.render.LocalStyle;
import org.sbml.jsbml.ext.render.RenderGroup;
import org.w3c.dom.Node;
import lcsb.mapviewer.common.XmlParser;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.exception.InvalidStateException;
import lcsb.mapviewer.common.exception.InvalidXmlSchemaException;
......@@ -247,21 +248,16 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
private void applyStyleToReactionNode(ReactionNode modifier, LocalStyle style, boolean reverse) {
RenderGroup group = style.getGroup();
if (group.isSetFill()) {
Color color = getColorByColorDefinition(group.getFill());
if (group.isSetStroke()) {
Color color = getColorByColorDefinition(group.getStroke());
modifier.getLine().setColor(color);
}
if (group.isSetStrokeWidth()) {
modifier.getLine().setWidth(group.getStrokeWidth());
}
if (group.isSetStroke()) {
try {
LineType type = LineType.valueOf(group.getStroke());
modifier.getLine().setType(type);
} catch (Exception e) {
logger.warn(new ElementUtils().getElementTag(modifier.getReaction()) + "Problematic line type: "
+ group.getStroke(), e);
}
if (group.isSetStrokeDashArray()) {
LineType type = LineType.getTypeByDashArray(group.getStrokeDashArray());
modifier.getLine().setType(type);
}
if (group.isSetEndHead()) {
try {
......@@ -413,8 +409,8 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
public void applyStyleToReaction(Reaction reactionWithLayout, LocalStyle style) {
RenderGroup group = style.getGroup();
if (group.getFill() != null) {
Color color = getColorByColorDefinition(group.getFill());
if (group.isSetStroke()) {
Color color = getColorByColorDefinition(group.getStroke());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setColor(color);
}
......@@ -424,15 +420,10 @@ public class SbmlReactionParser extends SbmlBioEntityParser {
node.getLine().setWidth(group.getStrokeWidth());
}
}
if (group.isSetStroke()) {
try {
LineType type = LineType.valueOf(group.getStroke());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setType(type);
}
} catch (Exception e) {
logger.warn(new ElementUtils().getElementTag(reactionWithLayout) + "Problematic line type: "
+ group.getStroke(), e);
if (group.isSetStrokeDashArray()) {
LineType type = LineType.getTypeByDashArray(group.getStrokeDashArray());
for (AbstractNode node : reactionWithLayout.getNodes()) {
node.getLine().setType(type);
}
}
if (group.isSetEndHead()) {
......
......@@ -2,7 +2,9 @@ package lcsb.mapviewer.model.graphics;
import java.awt.BasicStroke;
import java.awt.Stroke;
import java.util.List;
import lcsb.mapviewer.common.comparator.FloatComparator;
import lcsb.mapviewer.common.geometry.CompositeStroke;
/**
......@@ -21,7 +23,7 @@ public enum LineType {
* Solid bold line.
*/
SOLID_BOLD(3),
/**
* Dash-dot-dot line:
*
......@@ -30,7 +32,7 @@ public enum LineType {
* </pre>
*/
DASH_DOT_DOT(1, new float[] { 11.0f, 3.0f, 1.0f, 3.0f, 1.0f, 3.0f }),
/**
* Dash-dot line:
*
......@@ -132,4 +134,25 @@ public enum LineType {
public Stroke getStroke() {
return stroke;
}
public static LineType getTypeByDashArray(List<Short> strokeDashArray) {
FloatComparator doubleComparator = new FloatComparator();
for (LineType type : LineType.values()) {
if (type.getStroke() instanceof BasicStroke) {
BasicStroke basicStroke = (BasicStroke) type.getStroke();
if (basicStroke.getDashArray() != null && strokeDashArray.size() == basicStroke.getDashArray().length) {
boolean match = true;
for (int i = 0; i < strokeDashArray.size(); i++) {
if (doubleComparator.compare(basicStroke.getDashArray()[i], (float) strokeDashArray.get(i)) != 0) {
match = false;
}
}
if (match) {
return type;
}
}
}
}
return LineType.SOLID;
}
}
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