Search in sources :

Example 11 with SpeciesContextShape

use of cbit.vcell.graph.SpeciesContextShape in project vcell by virtualcell.

the class SimpleElipticalLayouter method layout.

// 
// 
// 
// protected static JungNode getOrAddInternalNode(ContainerContext cc, Node node) {
// JungNode glgNode = cc.getIntNodeMap().get(node);
// if(glgNode == null) {
// glgNode = new JungNode(node, false);	// internal
// cc.jungGraph.addVertex(glgNode);
// cc.intNodeMap.put(node, glgNode);
// double posX = node.getCenterX();
// double posY = node.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);	// TODO: here
// }
// return glgNode;
// }
// 
// // inode - internal, already dealt with
// // enode - our external candidate
// protected static JungNode getOrAddExternalNode(ContainerContext cc, Node enode, Node inode) {
// JungNode glgNode = cc.getExtNodeMap().get(enode);
// if(glgNode == null) {
// glgNode = new JungNode(enode, true);	// external
// cc.jungGraph.addVertex(glgNode);
// cc.extNodeMap.put(enode, glgNode);
// double posX = enode.getCenterX() - inode.getCenterX();
// double posY = enode.getCenterY() - inode.getCenterY();
// cc.jungLayout.setLocation(glgNode, posX, posY);			// TODO: here
// cc.jungLayout.lock(glgNode, true);
// }
// return glgNode;
// }
// 
// protected static void getOrAddEdge(ContainerContext cc, Edge edge) {
// Node node1 = edge.getNode1();
// Node node2 = edge.getNode2();
// Container container = cc.getContainer();
// if(container.equals(node1.getContainer()) && container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNode2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node1.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNode1 = getOrAddInternalNode(cc, node1);
// JungNode glgNodeExternal2 = getOrAddExternalNode(cc, node2, node1);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode1, glgNodeExternal2);
// cc.edgeMap.put(edge, jungEdge);
// }
// } else if(container.equals(node2.getContainer())) {
// JungEdge jungEdge = cc.getEdgeMap().get(edge);
// if(jungEdge == null) {
// JungNode glgNodeExternal1 = getOrAddExternalNode(cc, node1, node2);
// JungNode glgNode2 = getOrAddInternalNode(cc, node2);
// jungEdge = new JungEdge(edge);
// cc.jungGraph.addEdge(jungEdge, glgNode2, glgNodeExternal1);
// cc.edgeMap.put(edge, jungEdge);
// }
// }
// }
@Override
public void layout(ContainedGraph graph) {
    for (Container container : graph.getContainers()) {
        // ContainerContext containerContext = new ContainerContext(container);
        // int edgeCount = 0;
        // ContainerContext containerContext = new ContainerContext(container);
        // DirectedSparseMultigraph<String, Number> dag = new DirectedSparseMultigraph<>();
        // Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        // Map<String, Node> speciesNodesMap = new HashMap<>();
        // ReactionContainerShape rcs = (ReactionContainerShape)container.getObject();
        // Structure structure = rcs.getStructure();
        // for(Node node : containerNodes) {
        // if(node.object instanceof SpeciesContextShape) {
        // SpeciesContextShape scs = (SpeciesContextShape)node.object;
        // SpeciesContext sc = (SpeciesContext)(scs.getModelObject());
        // dag.addVertex(sc.getName());
        // speciesNodesMap.put(sc.getName(), node);
        // }
        // }
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp1 : rs.getReactionParticipants()) {
        // for(ReactionParticipant rp2 : rs.getReactionParticipants()) {
        // if(structure == rp1.getStructure() && structure == rp2.getStructure()) {
        // if(rp1 instanceof Reactant && rp2 instanceof Product) {		// edges from reactants to products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Catalyst && rp2 instanceof Reactant) {	// edges from catalysts to reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Reactant && rp2 instanceof Reactant && rp1 != rp2) {	// edges between reactants
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // if(rp1 instanceof Product && rp2 instanceof Product && rp1 != rp2) {	// edges between products
        // dag.addEdge(edgeCount, rp1.getName(), rp2.getName());
        // edgeCount++;
        // dag.addEdge(edgeCount, rp2.getName(), rp1.getName());
        // edgeCount++;
        // }
        // }
        // }
        // }
        // }
        // }
        // SpringLayout<String, Number> layout = new SpringLayout<String, Number>(dag);
        // layout.setSize(new Dimension((int)container.width,(int)container.height));
        // 
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // layout.setLocation(v, node.getCenterX(), node.getCenterY());
        // }
        // 
        // int step = 0;
        // while (!springIterate(layout) && step < 1000) {
        // step++;
        // }
        // 
        // // position the nodes on the new locations
        // for(String v : dag.getVertices()) {
        // Node node = speciesNodesMap.get(v);
        // double x = layout.getX(v);
        // double y = layout.getY(v);
        // node.setCenter(x, y);
        // }
        // 
        // // place all the reaction nodes in the center of mass of its reactants
        // for(Node node : containerNodes) {
        // if(node.object instanceof ReactionStepShape) {
        // int count = 0;
        // double x = 0;
        // double y = 0;
        // ReactionStepShape rss = (ReactionStepShape)node.object;
        // ReactionStep rs = (ReactionStep)(rss.getModelObject());
        // for(ReactionParticipant rp : rs.getReactionParticipants()) {
        // if(structure == rp.getStructure()) {
        // x += layout.getX(rp.getName());
        // y += layout.getY(rp.getName());
        // count++;
        // } else {		// reactant is in another structure
        // x += 5;		// just shift it a little
        // y += 5;
        // // TODO: make big correction as if it's far away to the left or to the right
        // // depending on the order of structures in the diagram
        // count++;
        // }
        // }
        // if(count > 0) {
        // node.setCenter(x/count, y/count);
        // }
        // }
        // }
        double centerX = container.getX() + container.getWidth() / 2;
        double centerY = container.getY() + container.getHeight() / 2;
        double quartaxisX = container.getWidth() / 3;
        double quartaxisY = container.getHeight() / 3;
        double semiaxisX = container.getWidth() / 2;
        double semiaxisY = container.getHeight() / 2;
        Collection<? extends Node> containerNodes = graph.getContainerNodes(container);
        int nNodes = containerNodes.size();
        int iNode = 0;
        for (Node node : containerNodes) {
            if (node.object instanceof SpeciesContextShape || node.object instanceof RuleParticipantSignatureDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + quartaxisX * Math.cos(angle), centerY + quartaxisY * Math.sin(angle));
            } else if (node.object instanceof ReactionStepShape || node.object instanceof ReactionRuleDiagramShape) {
                double angle = 2 * Math.PI * (((double) iNode) / ((double) nNodes));
                node.setCenter(centerX + semiaxisX * Math.cos(angle), centerY + semiaxisY * Math.sin(angle));
            }
            ++iNode;
        }
    }
    stretchLayouter.layout(graph);
}
Also used : Container(org.vcell.util.graphlayout.ContainedGraph.Container) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Node(org.vcell.util.graphlayout.ContainedGraph.Node) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape)

Example 12 with SpeciesContextShape

use of cbit.vcell.graph.SpeciesContextShape in project vcell by virtualcell.

the class GraphContainerLayoutVCellClassical method getSeparatorDeepCountFeatureShape.

public Point getSeparatorDeepCountFeatureShape(Shape shape) {
    int selfCountX = 1;
    if (shape.countChildren() > 0) {
        selfCountX++;
    }
    int selfCountY = 1;
    // column1 is speciesContextShapes
    Point column1 = new Point();
    int scShapeCount = 0;
    for (int i = 0; i < shape.countChildren(); i++) {
        Shape child = shape.childShapeList.get(i);
        if (child instanceof SpeciesContextShape) {
            scShapeCount++;
        }
    }
    column1.x = (scShapeCount > 0) ? 1 : 0;
    column1.y = (scShapeCount > 0) ? scShapeCount / 2 : 0;
    // column2 is StructureShapes
    Point column2 = new Point();
    for (int i = 0; i < shape.countChildren(); i++) {
        Shape child = shape.childShapeList.get(i);
        if (child instanceof StructureShape) {
            Point childCount = getSeparatorDeepCount(child);
            column2.x += childCount.x;
            column2.y += childCount.y;
        }
    }
    return new Point(selfCountX + column1.x + column2.x, selfCountY + Math.max(column1.y, column2.y));
}
Also used : SubVolumeContainerShape(cbit.vcell.graph.SubVolumeContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) MembraneShape(cbit.vcell.graph.MembraneShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) GeometryContextStructureShape(cbit.vcell.graph.GeometryContextStructureShape) FeatureShape(cbit.vcell.graph.FeatureShape) StructureMappingStructureShape(cbit.vcell.graph.StructureMappingStructureShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) GeometryContextContainerShape(cbit.vcell.graph.GeometryContextContainerShape) GeometryContextGeometryShape(cbit.vcell.graph.GeometryContextGeometryShape) StructureShape(cbit.vcell.graph.StructureShape) GeometryClassLegendShape(cbit.vcell.graph.GeometryClassLegendShape) BioPaxShape(cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape) GeometryContextStructureShape(cbit.vcell.graph.GeometryContextStructureShape) StructureMappingStructureShape(cbit.vcell.graph.StructureMappingStructureShape) StructureShape(cbit.vcell.graph.StructureShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) Point(java.awt.Point) Point(java.awt.Point)

Example 13 with SpeciesContextShape

use of cbit.vcell.graph.SpeciesContextShape in project vcell by virtualcell.

the class ReactionCartoonTool method mouseClicked.

@Override
public void mouseClicked(MouseEvent event) {
    Point screenPoint = new Point(event.getX(), event.getY());
    Point worldPoint = screenToWorld(screenPoint);
    try {
        if (event.getButton() != MouseEvent.BUTTON1) {
            return;
        }
        switch(mode) {
            case SELECT:
                {
                    if (event.getClickCount() == 2) {
                        final Shape selectedShape = getReactionCartoon().getSelectedShape();
                        if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
                            editInPlace(selectedShape, worldPoint);
                        }
                        if (selectedShape != null) {
                            menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
                        }
                    }
                    break;
                }
            case STEP:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
                            ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
                            positionShapeForObject(structure, reactionStep, worldPoint);
                            saveDiagram();
                        }
                    }
                    break;
                }
            case FLUX:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
                        if (structure instanceof Membrane) {
                            Membrane membrane = (Membrane) structure;
                            FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
                            ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
                            Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
                            frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
                            saveDiagram();
                        // setMode(SELECT_MODE);
                        } else {
                        // setMode(SELECT_MODE);
                        // throw new Exception("fluxes only applicable to membranes");
                        }
                    }
                    break;
                }
            case SPECIES:
                {
                    Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
                    if (pickedShape instanceof ReactionContainerShape) {
                        SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
                        reactionCartoon.clearSelection();
                        getGraphModel().select(speciesContext);
                        positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
                        // showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
                        saveDiagram();
                    }
                }
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println("CartoonTool.mouseClicked: uncaught exception");
        e.printStackTrace(System.out);
        Point canvasLoc = getGraphPane().getLocationOnScreen();
        canvasLoc.x += screenPoint.x;
        canvasLoc.y += screenPoint.y;
        DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
    }
}
Also used : SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) PropertyVetoException(java.beans.PropertyVetoException) UtilCancelException(org.vcell.util.UtilCancelException) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) Membrane(cbit.vcell.model.Membrane) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) Structure(cbit.vcell.model.Structure)

Example 14 with SpeciesContextShape

use of cbit.vcell.graph.SpeciesContextShape in project vcell by virtualcell.

the class ReactionCartoonTool method getLineTypeFromDirection.

private LineType getLineTypeFromDirection(Shape startingShape, Point worldPoint) throws Exception {
    Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
    if (mouseOverShape instanceof ReactionStepShape) {
        if (startingShape instanceof SpeciesContextShape) {
            SpeciesContext speciesContext = (SpeciesContext) startingShape.getModelObject();
            // check if the ReactionStep already has a Product for this SpeciesContext
            ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
            ReactionParticipant[] rps = reactionStep.getReactionParticipants();
            if ((mouseOverShape instanceof SimpleReactionShape) || (mouseOverShape instanceof FluxReactionShape)) {
                for (int i = 0; i < rps.length; i++) {
                    if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                        return LineType.NULL;
                    }
                }
                return LineType.REACTANT;
            }
        // else if (mouseOverShape instanceof FluxReactionShape){
        // for (int i = 0; i < rps.length; i++){
        // if ((rps[i] instanceof Reactant || rps[i] instanceof Product) && rps[i].getSpeciesContext() == speciesContext) {
        // return LineType.NULL;
        // }
        // }
        // return LineType.FLUX;
        // }
        }
    } else if (mouseOverShape instanceof SpeciesContextShape) {
        SpeciesContext speciesContext = (SpeciesContext) mouseOverShape.getModelObject();
        if (startingShape instanceof SpeciesContextShape) {
            // straight from one species to another ... will create a reaction upon release
            return LineType.PRODUCT;
        } else if (startingShape instanceof ReactionStepShape) {
            ReactionStep reactionStep = (ReactionStep) startingShape.getModelObject();
            ReactionParticipant[] rps = reactionStep.getReactionParticipants();
            // } else
            if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
                for (int i = 0; i < rps.length; i++) {
                    if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
                        return LineType.NULL;
                    }
                }
                return LineType.REACTANT;
            }
        }
    }
    return LineType.NULL;
}
Also used : SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) RubberBandRectShape(cbit.gui.graph.RubberBandRectShape) ProductShape(cbit.vcell.graph.ProductShape) ContainerShape(cbit.gui.graph.ContainerShape) CatalystShape(cbit.vcell.graph.CatalystShape) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ContainerContainerShape(cbit.vcell.graph.ContainerContainerShape) ReactantShape(cbit.vcell.graph.ReactantShape) ElipseShape(cbit.gui.graph.ElipseShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) ReactionContainerShape(cbit.vcell.graph.ReactionContainerShape) Shape(cbit.gui.graph.Shape) RuleParticipantSignatureDiagramShape(cbit.vcell.graph.RuleParticipantSignatureDiagramShape) ReactionRuleDiagramShape(cbit.vcell.graph.ReactionRuleDiagramShape) RubberBandEdgeShape(cbit.gui.graph.RubberBandEdgeShape) ReactionParticipantShape(cbit.vcell.graph.ReactionParticipantShape) SimpleReaction(cbit.vcell.model.SimpleReaction) SpeciesContextShape(cbit.vcell.graph.SpeciesContextShape) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) FluxReaction(cbit.vcell.model.FluxReaction) SpeciesContext(cbit.vcell.model.SpeciesContext) ReactionStepShape(cbit.vcell.graph.ReactionStepShape) Reactant(cbit.vcell.model.Reactant) Point(java.awt.Point) FluxReactionShape(cbit.vcell.graph.FluxReactionShape) ReactionStep(cbit.vcell.model.ReactionStep) ReactionParticipant(cbit.vcell.model.ReactionParticipant)

Aggregations

SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)14 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)13 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)13 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)11 Point (java.awt.Point)10 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)9 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)7 CatalystShape (cbit.vcell.graph.CatalystShape)6 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)6 ProductShape (cbit.vcell.graph.ProductShape)6 ReactantShape (cbit.vcell.graph.ReactantShape)6 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)6 ContainerShape (cbit.gui.graph.ContainerShape)5 ElipseShape (cbit.gui.graph.ElipseShape)5 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)5 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)5 Shape (cbit.gui.graph.Shape)5 BioPaxShape (cbit.vcell.client.desktop.biomodel.pathway.shapes.BioPaxShape)5 FeatureShape (cbit.vcell.graph.FeatureShape)5 GeometryClassLegendShape (cbit.vcell.graph.GeometryClassLegendShape)5