Search in sources :

Example 6 with SimpleReactionShape

use of cbit.vcell.graph.SimpleReactionShape 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 7 with SimpleReactionShape

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

the class ReactionCartoonTool method lineAction.

private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
    Point startPos = edgeShape.getStart();
    Point endPos = edgeShape.getEnd();
    if (endStructure.equals(startStructure)) {
        SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
        SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
        reaction.addReactant(speciesContext1, 1);
        reaction.addProduct(speciesContext2, 1);
        getReactionCartoon().notifyChangeEvent();
        positionShapeForObject(endStructure, speciesContext1, startPos);
        positionShapeForObject(endStructure, speciesContext2, endPos);
        positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
        getGraphModel().clearSelection();
        getGraphModel().select(reaction);
    } else {
        if (endStructure instanceof Membrane && startStructure instanceof Feature) {
            Membrane endMembrane = (Membrane) endStructure;
            Feature startFeature = (Feature) startStructure;
            // if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startFeature, speciesContext1, startPos);
            positionShapeForObject(endMembrane, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
            Membrane startMembrane = (Membrane) startStructure;
            Feature endFeature = (Feature) endStructure;
            // if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
            // {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startMembrane, speciesContext1, startPos);
            positionShapeForObject(endFeature, speciesContext2, endPos);
            // finding correct insertion point for reaction, statements below should be put into a utility if used often
            int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
            int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
            int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
            int reactionAbsX = (startPos.x + endPos.x) / 2;
            if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
                reactionAbsX = memAbsXmin;
            } else {
                reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
                reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
            }
            positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        // }
        } else if (endStructure instanceof Feature && startStructure instanceof Feature) {
            Feature startFeature = (Feature) startStructure;
            Feature endFeature = (Feature) endStructure;
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        } else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
            SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
            SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
            SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
            reaction.addReactant(speciesContext1, 1);
            reaction.addProduct(speciesContext2, 1);
            reaction.setKinetics(new GeneralLumpedKinetics(reaction));
            getReactionCartoon().notifyChangeEvent();
            positionShapeForObject(startStructure, speciesContext1, startPos);
            positionShapeForObject(endStructure, speciesContext2, endPos);
            positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
            getGraphModel().clearSelection();
            getGraphModel().select(reaction);
        }
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) Membrane(cbit.vcell.model.Membrane) SimpleReactionShape(cbit.vcell.graph.SimpleReactionShape) Point(java.awt.Point) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralLumpedKinetics(cbit.vcell.model.GeneralLumpedKinetics) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Aggregations

SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)7 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)6 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)6 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)6 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)6 Point (java.awt.Point)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 CatalystShape (cbit.vcell.graph.CatalystShape)5 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)5 ProductShape (cbit.vcell.graph.ProductShape)5 ReactantShape (cbit.vcell.graph.ReactantShape)5 ReactionParticipantShape (cbit.vcell.graph.ReactionParticipantShape)5 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)5 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)5 ReactionStep (cbit.vcell.model.ReactionStep)5 SpeciesContext (cbit.vcell.model.SpeciesContext)5