Permalink
Browse files

added Layout extension for the sbml

  • Loading branch information...
applecool committed Sep 14, 2013
1 parent 572a34b commit c63532edd82ec8bb30dceb0c9809e40444165dc8
Showing with 112 additions and 4 deletions.
  1. +112 −4 src/org/pathvisio/sbml/LayoutAbstract.java
@@ -29,6 +29,7 @@
import org.pathvisio.core.view.Graphics;
import org.pathvisio.core.view.VPathway;
import org.pathvisio.gui.SwingEngine;
import org.pathvisio.sbgn.SbgnFormat;
/**
* LayoutAbstract Class<p>
* Abstract class with functions used by all layout algorithms
@@ -44,6 +45,7 @@
boolean selection;
List<PathwayElement> pwyNodes;
List<PathwayElement> pwyLines;
List<PathwayElement> pwyStates;
LayoutAbstract(SwingEngine se){
this(se,false);
@@ -55,25 +57,35 @@
this.selection = selection;
pwyNodes = new ArrayList<PathwayElement>();
pwyLines = new ArrayList<PathwayElement>();
pwyStates = new ArrayList<PathwayElement>();
if (selection){
List<Graphics> graphics = vpwy.getSelectedGraphics();
for (Graphics g : graphics){
PathwayElement pe = g.getPathwayElement();
if (pe.getObjectType().equals(ObjectType.DATANODE)){
if (pe.getObjectType().equals(ObjectType.DATANODE)|| pe.getObjectType().equals(ObjectType.LABEL)){
pwyNodes.add(pe);
}
else if (pe.getObjectType().equals(ObjectType.LINE)){
pwyLines.add(pe);
if ("true".equals (pe.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT)))
pwyStates.add(pe);
else pwyLines.add(pe);
}
}
}
else {
for (PathwayElement pe : pwy.getDataObjects()){
if (pe.getObjectType().equals(ObjectType.DATANODE)){
if (pe.getObjectType().equals(ObjectType.DATANODE)||pe.getObjectType().equals(ObjectType.LABEL)){
pwyNodes.add(pe);
}
else if (pe.getObjectType().equals(ObjectType.LINE)){
pwyLines.add(pe);
if ("true".equals (pe.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT)))
pwyStates.add(pe);
else pwyLines.add(pe);
}
}
}
@@ -201,4 +213,100 @@ protected void drawLines(){
line.getMEnd().linkTo(endNode);
}
}
private String getSpecies(String graphId) {
for (PathwayElement pe : pwy.getDataObjects()){
if (pe.getObjectType().equals(ObjectType.LINE) ){
if (!("true".equals (pe.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT))))
{
if(pe.getEndGraphRef().equalsIgnoreCase(graphId))
return pe.getStartGraphRef();
if(pe.getStartGraphRef().equalsIgnoreCase(graphId))
return pe.getEndGraphRef();
}
}
}
return "";
}
protected String getReaction(String graphId) {
for (PathwayElement pe : pwy.getDataObjects()){
if (pe.getObjectType().equals(ObjectType.LINE) ){
if (("true".equals (pe.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT))))
{
if(pe.getMAnchors().get(0).getGraphId().equalsIgnoreCase(graphId))
return pe.getStartGraphRef();
}
}
}
return "";
}
protected void drawStates(){
for (PathwayElement line : pwy.getDataObjects())
if (line.getObjectType().equals(ObjectType.LINE)){
if ("true".equals (line.getDynamicProperty(SbgnFormat.PROPERTY_SBGN_IS_PORT)))
{
PathwayElement startNode = pwy.getElementById(line.getStartGraphRef());
PathwayElement endNode = pwy.getElementById(getSpecies(line.getMAnchors().get(0).getGraphId()));
line.getMStart().unlink();
line.getMEnd().unlink();
double differenceX;
double differenceY;
boolean startBiggerX = true;
boolean startBiggerY = true;
if (startNode.getMCenterX() < endNode.getMCenterX()){
double endSide = endNode.getMCenterX() - endNode.getMWidth()/2;
double startSide = startNode.getMCenterX() + startNode.getMWidth()/2;
differenceX = endSide - startSide;
startBiggerX = false;
}
else {
double startSide = startNode.getMCenterX() - startNode.getMWidth()/2;
double endSide = endNode.getMCenterX() + endNode.getMWidth()/2;
differenceX = startSide - endSide;
}
if (startNode.getMCenterY() < endNode.getMCenterY()){
double startSide = startNode.getMCenterY() + startNode.getMHeight()/2;
double endSide = endNode.getMCenterY() - endNode.getMHeight()/2;
differenceY = endSide - startSide;
startBiggerY = false;
}
else {
double startSide = startNode.getMCenterY() - startNode.getMHeight()/2;
double endSide = endNode.getMCenterY() + endNode.getMHeight()/2;
differenceY = startSide - endSide;
}
if (differenceX>differenceY && startBiggerX) {
line.setMStartY(startNode.getMCenterY());
line.setMStartX(startNode.getMCenterX() - startNode.getMWidth() / 2);
line.setMEndY(endNode.getMCenterY());
line.setMEndX(endNode.getMCenterX() + endNode.getMWidth() / 2);
} else if (differenceX>differenceY && !startBiggerX) {
line.setMStartY(startNode.getMCenterY());
line.setMStartX(startNode.getMCenterX() + startNode.getMWidth() / 2);
line.setMEndY(endNode.getMCenterY());
line.setMEndX(endNode.getMCenterX() - endNode.getMWidth() / 2);
} else if (differenceX<differenceY && startBiggerY){
line.setMStartX(startNode.getMCenterX());
line.setMStartY((startNode.getMCenterY() - startNode.getMHeight() /2));
line.setMEndX(endNode.getMCenterX());
line.setMEndY(endNode.getMCenterY() + startNode.getMHeight() /2);
} else {
line.setMStartX(startNode.getMCenterX());
line.setMStartY(startNode.getMCenterY() + startNode.getMHeight() / 2);
line.setMEndX(endNode.getMCenterX());
line.setMEndY(endNode.getMCenterY() - endNode.getMHeight() / 2);
}
line.getMStart().linkTo(startNode);
line.getMEnd().linkTo(endNode);
}
}
}
}

0 comments on commit c63532e

Please sign in to comment.