Skip to content
Snippets Groups Projects

Resolve "Inability to export network to CellDesigner + probably invalid SBGN"

8 files
+ 1150
35
Compare changes
  • Side-by-side
  • Inline
Files
8
@@ -7,6 +7,7 @@ import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import lcsb.mapviewer.common.Configuration;
import lcsb.mapviewer.common.exception.InvalidArgumentException;
import lcsb.mapviewer.common.geometry.LineTransformation;
import lcsb.mapviewer.common.geometry.PointTransformation;
@@ -67,6 +68,15 @@ public class CellDesignerLineTransformation extends LineTransformation {
double dx2 = -dy1;
double dy2 = dx1;
double distDx = dx1 * dx1 + dy1 * dy1;
// this is special case if end and start point are equal then CellDesigner uses
// relative coordinates
if (distDx <= Configuration.EPSILON) {
dx1 = 1;
dy2 = 1;
}
result.add(new Point2D.Double(startPoint.getX(), startPoint.getY()));
if (midPoints != null) {
@@ -74,6 +84,7 @@ public class CellDesignerLineTransformation extends LineTransformation {
if (!pt.isValidPoint(p)) {
throw new InvalidArgumentException("Invalid point: " + p);
}
double x = startPoint.getX() + dx1 * p.getX() + dx2 * p.getY();
double y = startPoint.getY() + dy1 * p.getX() + dy2 * p.getY();
result.add(new Point2D.Double(x, y));
@@ -86,8 +97,8 @@ public class CellDesignerLineTransformation extends LineTransformation {
}
/**
* Transform line of typical xy coordinates into coordinates used by
* celldesigner.
* Transform line of typical x,y coordinates into coordinates used by
* CellDesigner.
*
* CellDesigner format stores coordinates of a line in a different base. In this
* base we have two points that define a base: vector between these points is 1
@@ -120,19 +131,24 @@ public class CellDesignerLineTransformation extends LineTransformation {
List<Point2D> result = new ArrayList<Point2D>();
if (dy * dy + dx * dx == 0) {
throw new InvalidArgumentException("First and last point in the line must differ but found: "
+ line.getBeginPoint() + ", " + line.getEndPoint());
}
// this is special case - if start and end point are equals then cell designer
// requires relative coordinates
for (int i = 1; i < line.getPoints().size() - 1; i++) {
double ox = line.getPoints().get(i).getX();
double oy = line.getPoints().get(i).getY();
for (int i = 1; i < line.getPoints().size() - 1; i++) {
double ox = line.getPoints().get(i).getX();
double oy = line.getPoints().get(i).getY();
double py = (dy * (ax - ox) + dx * (oy - ay)) / (dy * dy + dx * dx);
double px = (dx * (ox - ax) + dy * (oy - ay)) / (dx * dx + dy * dy);
result.add(new Point2D.Double(px, py));
result.add(new Point2D.Double(ox - ax, oy - ay));
}
} else {
for (int i = 1; i < line.getPoints().size() - 1; i++) {
double ox = line.getPoints().get(i).getX();
double oy = line.getPoints().get(i).getY();
double py = (dy * (ax - ox) + dx * (oy - ay)) / (dy * dy + dx * dx);
double px = (dx * (ox - ax) + dy * (oy - ay)) / (dx * dx + dy * dy);
result.add(new Point2D.Double(px, py));
}
}
return result;
}
}
Loading