Search in sources :

Example 26 with Shape

use of cbit.gui.graph.Shape in project vcell by virtualcell.

the class ReactionCartoonTool method copyRelativePosition.

public static void copyRelativePosition(GraphModel graphModel, BioModelEntityObject origEntity, BioModelEntityObject newEntity) {
    Shape origEntityShape = graphModel.getShapeFromModelObject(origEntity);
    if (origEntityShape == null) {
        // happens when using BioModel 'Searchable Reactions...'
        return;
    }
    Shape newEntityShape = graphModel.getShapeFromModelObject(newEntity);
    newEntityShape.setRelPos(new Point(origEntityShape.getRelPos()));
    // offset if completely overlap another shape
    for (Shape shape : graphModel.getShapes()) {
        if (shape.getModelObject() instanceof BioModelEntityObject && shape != newEntityShape) {
            if (shape.getRelPos().equals(newEntityShape.getRelPos())) {
                newEntityShape.setRelPos(new Point(newEntityShape.getRelX() + 5, newEntityShape.getRelY() + 5));
                break;
            }
        }
    }
}
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) Point(java.awt.Point) BioModelEntityObject(cbit.vcell.model.BioModelEntityObject)

Example 27 with Shape

use of cbit.gui.graph.Shape in project vcell by virtualcell.

the class ReactionCartoonTool method updateRXContainerDropTargetInfoMap.

private HashMap<RXContainerDropTargetInfo, Boolean> updateRXContainerDropTargetInfoMap(Point pointWorld) {
    HashMap<RXContainerDropTargetInfo, Boolean> rxContainerDropTargetInfoMap = null;
    if (rxContainerDropTargetInfoMap == null) {
        // System.out.println("-----redoing map...");
        AllStructureSuite allStructureSuite = (getReactionCartoon().getStructureSuite() instanceof AllStructureSuite ? (AllStructureSuite) getReactionCartoon().getStructureSuite() : null);
        if (allStructureSuite == null) {
            throw new RuntimeException("Expecting " + AllStructureSuite.class.getName());
        }
        rxContainerDropTargetInfoMap = new HashMap<ReactionCartoonTool.RXContainerDropTargetInfo, Boolean>();
        Structure[] originalOrderedStructArr = allStructureSuite.getStructures().toArray(new Structure[0]);
        for (int i = 0; i < originalOrderedStructArr.length; i++) {
            Shape currentRXContainerShape = getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i]);
            if (i == 0) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_BEGINNING), false);
            } else {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, (ReactionContainerShape) getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i - 1]), null), false);
            }
            if (i == (originalOrderedStructArr.length - 1)) {
                rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_END), false);
            }
        }
    }
    // System.out.println("-----Starting to update selection..."+pointWorld);
    for (RXContainerDropTargetInfo rxcContainerDropTargetInfo : rxContainerDropTargetInfoMap.keySet()) {
        if (rxcContainerDropTargetInfo.absoluteRectangle.contains(pointWorld)) {
            // System.out.println(rxcContainerDropTargetInfo.dropShape.getLabel()+" "+rxcContainerDropTargetInfo.closestNeighborShape);
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, true);
        } else {
            rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, false);
        }
    }
    return rxContainerDropTargetInfoMap;
}
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) AllStructureSuite(cbit.vcell.graph.structures.AllStructureSuite) Structure(cbit.vcell.model.Structure) Point(java.awt.Point)

Example 28 with Shape

use of cbit.gui.graph.Shape 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)

Example 29 with Shape

use of cbit.gui.graph.Shape 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 30 with Shape

use of cbit.gui.graph.Shape in project vcell by virtualcell.

the class ReactionCartoonTool method lineAction.

private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
    Structure endStructure = reactionEnd.getStructure();
    Structure startStructure = speciesContextStart.getStructure();
    if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
        int stoichiometry = 1;
        Reactant reactant = null;
        for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
            if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
                reactant = (Reactant) participant;
            }
        }
        if (reactant != null) {
            // only increase stoichiometry if reaction is SimpleReaction
            if (reactionEnd instanceof SimpleReaction) {
                reactant.setStoichiometry(reactant.getStoichiometry() + 1);
            }
            Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
            if (shape != null) {
                shape.refreshLabel();
            }
        } else {
            // add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
            if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
                reactionEnd.addReactant(speciesContextStart, stoichiometry);
            }
        }
        if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
        // ============ change kinetics to lumped or warn user ?????????
        // simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
        }
        getReactionCartoon().notifyChangeEvent();
    }
}
Also used : SimpleReaction(cbit.vcell.model.SimpleReaction) 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) Membrane(cbit.vcell.model.Membrane) FluxReaction(cbit.vcell.model.FluxReaction) Structure(cbit.vcell.model.Structure) Reactant(cbit.vcell.model.Reactant) ReactionParticipant(cbit.vcell.model.ReactionParticipant) Feature(cbit.vcell.model.Feature) Point(java.awt.Point)

Aggregations

Shape (cbit.gui.graph.Shape)57 Point (java.awt.Point)30 ContainerShape (cbit.gui.graph.ContainerShape)21 EdgeShape (cbit.gui.graph.EdgeShape)20 RubberBandRectShape (cbit.gui.graph.RubberBandRectShape)20 ArrayList (java.util.ArrayList)15 ElipseShape (cbit.gui.graph.ElipseShape)14 RubberBandEdgeShape (cbit.gui.graph.RubberBandEdgeShape)14 ReactionContainerShape (cbit.vcell.graph.ReactionContainerShape)14 CatalystShape (cbit.vcell.graph.CatalystShape)13 ContainerContainerShape (cbit.vcell.graph.ContainerContainerShape)13 FluxReactionShape (cbit.vcell.graph.FluxReactionShape)13 ProductShape (cbit.vcell.graph.ProductShape)13 ReactantShape (cbit.vcell.graph.ReactantShape)13 ReactionParticipantShape (cbit.vcell.graph.ReactionParticipantShape)13 ReactionRuleDiagramShape (cbit.vcell.graph.ReactionRuleDiagramShape)13 ReactionStepShape (cbit.vcell.graph.ReactionStepShape)13 RuleParticipantSignatureDiagramShape (cbit.vcell.graph.RuleParticipantSignatureDiagramShape)13 SimpleReactionShape (cbit.vcell.graph.SimpleReactionShape)13 SpeciesContextShape (cbit.vcell.graph.SpeciesContextShape)13