use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonFull method setPositionsFromReactionCartoon.
public void setPositionsFromReactionCartoon(Diagram diagram) {
List<NodeReference> nodeList = new ArrayList<NodeReference>();
NodeReference.Mode mode = NodeReference.Mode.full;
for (Shape shape : getShapes()) {
if (shape instanceof FluxReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SimpleReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof ReactionRuleDiagramShape) {
nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SpeciesContextShape) {
nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
} else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
System.out.println("ReactionCartoonFull, Invalid shape type 'RuleParticipantSignatureShortDiagramShape'");
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
}
}
diagram.setNodeReferences(mode, nodeList);
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonFull method applyDefaults.
public void applyDefaults(Diagram diagram) {
List<NodeReference> nodeList = diagram.getNodeFullList();
List<NodeReference> orphansList = new ArrayList<NodeReference>();
for (int i = 0; i < nodeList.size(); i++) {
NodeReference node = nodeList.get(i);
Object obj = null;
Structure struct = diagram.getStructure();
boolean found = false;
switch(node.nodeType) {
case NodeReference.SIMPLE_REACTION_NODE:
obj = getModel().getReactionStep(node.name);
if (!(obj instanceof SimpleReaction)) {
System.out.println("ReactionCartoon.applyDefaults(), diagram reaction " + node.name + " type mismatch in model, using location anyway");
}
break;
case NodeReference.FLUX_REACTION_NODE:
obj = getModel().getReactionStep(node.name);
if (!(obj instanceof FluxReaction)) {
System.out.println("ReactionCartoon.applyDefaults(), diagram flux " + node.name + " type mismatch in model, using location anyway");
}
break;
case NodeReference.SPECIES_CONTEXT_NODE:
obj = getModel().getSpeciesContext(node.name);
break;
case NodeReference.REACTION_RULE_NODE:
obj = getModel().getRbmModelContainer().getReactionRule(node.name);
break;
case // obj is a RuleParticipantSignature
NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE:
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == struct && signature.compareByCriteria(node.getName(), GroupingCriteria.full)) {
obj = signature;
found = true;
break;
}
}
if (!found) {
orphansList.add(node);
}
break;
case NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE:
System.out.println("ReactionCartoonFull, RULE_PARTICIPANT_SIGNATURE_SHORT_NODE detected");
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == struct && signature.compareByCriteria(node.getName(), GroupingCriteria.full)) {
obj = signature;
found = true;
break;
}
}
if (!found) {
orphansList.add(node);
}
break;
}
// -- switch
Shape shape = getShapeFromModelObject(obj);
if (shape != null) {
Point relPosOld = shape.getRelPos();
Point relPosNew = node.location;
// In old models, the same node can appear in multiple diagrams.
// Now, we have only one diagram, so if a node has multiple positions,
// some would overwrite others.
// This attempts to prevent overwriting a position with a worse one.
// if(relPosOld.x + relPosOld.y < relPosNew.x + relPosNew.y) {
shape.setRelPos(relPosNew);
// }
}
}
if (!orphansList.isEmpty()) {
diagram.removeNodeReferences(NodeReference.Mode.full, orphansList);
}
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonMolecule method setPositionsFromReactionCartoon.
public void setPositionsFromReactionCartoon(Diagram diagram) {
List<NodeReference> nodeList = new ArrayList<NodeReference>();
NodeReference.Mode mode = NodeReference.Mode.molecule;
for (Shape shape : getShapes()) {
if (shape instanceof FluxReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.FLUX_REACTION_NODE, ((FluxReaction) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SimpleReactionShape) {
nodeList.add(new NodeReference(mode, NodeReference.SIMPLE_REACTION_NODE, ((ReactionStep) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof ReactionRuleDiagramShape) {
nodeList.add(new NodeReference(mode, NodeReference.REACTION_RULE_NODE, ((ReactionRule) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof SpeciesContextShape) {
nodeList.add(new NodeReference(mode, NodeReference.SPECIES_CONTEXT_NODE, ((SpeciesContext) shape.getModelObject()).getName(), shape.getSpaceManager().getRelPos()));
} else if (shape instanceof RuleParticipantSignatureFullDiagramShape) {
System.out.println("ReactionCartoonMolecule, Invalid shape type 'RuleParticipantSignatureFullDiagramShape'");
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
} else if (shape instanceof RuleParticipantSignatureShortDiagramShape) {
RuleParticipantSignature ruleParticipantSignature = (RuleParticipantSignature) shape.getModelObject();
if (ruleParticipantSignature.getStructure() == diagram.getStructure()) {
String spAsString = ruleParticipantSignature.getFirstSpeciesPatternAsString();
NodeReference nr = new NodeReference(mode, NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE, spAsString, shape.getSpaceManager().getRelPos());
nr.speciesPattern = ruleParticipantSignature.getSpeciesPattern();
nodeList.add(nr);
}
}
}
diagram.setNodeReferences(mode, nodeList);
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class WorkflowCartoonTool method mouseReleased.
@Override
public void mouseReleased(MouseEvent event) {
if (getGraphModel() == null) {
return;
}
try {
// Pick shape
int eventX = event.getX();
int eventY = event.getY();
java.awt.Point worldPoint = new Point((int) (eventX * 100.0 / getGraphModel().getZoomPercent()), (int) (eventY * 100.0 / getGraphModel().getZoomPercent()));
Shape pickedShape = getGraphModel().pickWorld(worldPoint);
// if mouse popupMenu event, popup menu
if (event.isPopupTrigger() && mode == Mode.SELECT) {
if (pickedShape == getGraphModel().getSelectedShape()) {
popupMenu(getGraphModel().getSelectedShape(), event.getX(), event.getY());
}
return;
}
if ((event.getModifiers() & (InputEvent.BUTTON2_MASK | InputEvent.BUTTON3_MASK)) != 0) {
return;
}
// else do select and move
switch(mode) {
case SELECT:
{
getGraphPane().setCursor(Cursor.getDefaultCursor());
if (bMoving) {
getGraphPane().invalidate();
((JViewport) getGraphPane().getParent()).revalidate();
getGraphPane().repaint();
} else if (bRectStretch) {
Point absLoc = rectShape.getSpaceManager().getRelPos();
Dimension size = rectShape.getSpaceManager().getSize();
// remove temporary rectangle
getGraphModel().removeShape(rectShape);
rectShape = null;
Rectangle rect = new Rectangle(absLoc.x, absLoc.y, size.width, size.height);
boolean bShift = (event.getModifiers() & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK;
boolean bCntrl = (event.getModifiers() & InputEvent.CTRL_MASK) == InputEvent.CTRL_MASK;
selectEventFromWorld(rect, bShift, bCntrl);
getGraphPane().repaint();
}
bMoving = false;
movingShape = null;
bRectStretch = false;
rectShape = null;
break;
}
default:
{
break;
}
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseReleased: uncaught exception");
e.printStackTrace(System.out);
}
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class WorkflowCartoonTool method layout.
public void layout(String layoutName) throws Exception {
Blackboard bb = new Blackboard();
HashMap<String, Shape> nodeShapeMap = new HashMap<String, Shape>();
// add nodes
boolean bHasSelections = getGraphModel().getSelectedShape() != null;
ArrayList<Shape> vcellShapeList = new ArrayList<Shape>();
for (Shape shape : getGraphModel().getShapes()) {
vcellShapeList.add(shape);
edu.rpi.graphdrawing.Node newNode = null;
if (ShapeUtil.isMovable(shape)) {
if (!bHasSelections || shape.isSelected()) {
String shapeIndexStr = "node" + Integer.toString(vcellShapeList.indexOf(shape));
newNode = bb.addNode(shapeIndexStr);
}
}
// initialize node location to current absolute position
if (newNode != null) {
newNode.XY(shape.getSpaceManager().getAbsLoc().x, shape.getSpaceManager().getAbsLoc().y);
nodeShapeMap.put(newNode.label(), shape);
}
}
for (Shape shape : getGraphModel().getShapes()) {
if (shape instanceof EdgeShape) {
EdgeShape eShape = (EdgeShape) shape;
Shape node1Shape = eShape.getStartShape();
Shape node2Shape = eShape.getEndShape();
if (!bHasSelections || (node1Shape.isSelected() && node2Shape.isSelected())) {
String node1IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node1Shape));
String node2IndexStr = "node" + Integer.toString(vcellShapeList.indexOf(node2Shape));
bb.addEdge(node1IndexStr, node2IndexStr);
}
}
}
bb.setArea(0, 0, getGraphPane().getWidth(), getGraphPane().getHeight());
bb.globals.D(20);
bb.addEmbedder(GraphLayoutManager.OldLayouts.ANNEALER, new Annealer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CIRCULARIZER, new Circularizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.CYCLEIZER, new Cycleizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.FORCEDIRECT, new ForceDirect(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.LEVELLER, new Leveller(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RANDOMIZER, new Randomizer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.RELAXER, new Relaxer(bb));
bb.addEmbedder(GraphLayoutManager.OldLayouts.STABILIZER, new Stabilizer(bb));
bb.setEmbedding(layoutName);
@SuppressWarnings("unchecked") List<Node> nodeList = bb.nodes();
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
System.out.println("Node " + node.label() + " @ (" + node.x() + "," + node.y() + ")");
}
bb.PreprocessNodes();
Embedder embedder = bb.embedder();
embedder.Init();
for (int i = 0; i < 1000; i++) {
embedder.Embed();
}
bb.removeDummies();
@SuppressWarnings("unchecked") Vector<Node> nodes = bb.nodes();
nodeList = nodes;
//
// calculate offset and scaling so that resulting graph fits on canvas
//
double lowX = 100000;
double highX = -100000;
double lowY = 100000;
double highY = -100000;
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
lowX = Math.min(lowX, node.x());
highX = Math.max(highX, node.x());
lowY = Math.min(lowY, node.y());
highY = Math.max(highY, node.y());
}
double scaleX = getGraphPane().getWidth() / (1.5 * (highX - lowX));
double scaleY = getGraphPane().getHeight() / (1.5 * (highY - lowY));
int offsetX = getGraphPane().getWidth() / 6;
int offsetY = getGraphPane().getHeight() / 6;
for (int i = 0; i < nodeList.size(); i++) {
Node node = nodeList.get(i);
Shape shape = nodeShapeMap.get(node.label());
Point parentLoc = shape.getParent().getSpaceManager().getAbsLoc();
shape.getSpaceManager().setAbsLoc(new Point((int) (scaleX * (node.x() - lowX)) + offsetX + parentLoc.x, (int) ((scaleY * (node.y() - lowY)) + offsetY + parentLoc.y)));
System.out.println("Shape " + shape.getLabel() + " @ " + shape.getSpaceManager().getAbsLoc());
}
getGraphPane().repaint();
}
Aggregations