Search in sources :

Example 1 with ReactionRuleShortSignature

use of cbit.vcell.model.ReactionRuleShortSignature in project vcell by virtualcell.

the class ReactionCartoonRule method setPositionsFromReactionCartoon.

public void setPositionsFromReactionCartoon(Diagram diagram) {
    List<NodeReference> nodeList = new ArrayList<NodeReference>();
    NodeReference.Mode mode = NodeReference.Mode.rule;
    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 ReactionRuleShortDiagramShape) {
            // can only be short
            ReactionRuleShortSignature signature = (ReactionRuleShortSignature) shape.getModelObject();
            // the display name is the number of rules in the signature's list of rules
            String name = signature.getDisplayName();
            NodeReference nr = new NodeReference(mode, NodeReference.REACTION_RULE_NODE, name, shape.getSpaceManager().getRelPos());
            nodeList.add(nr);
        } 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("ReactionCartoonRule, 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);
            }
        }
    }
    // add all to nodeRuleList
    diagram.setNodeReferences(mode, nodeList);
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) NodeReference(cbit.vcell.model.NodeReference) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) ReactionRuleShortSignature(cbit.vcell.model.ReactionRuleShortSignature)

Example 2 with ReactionRuleShortSignature

use of cbit.vcell.model.ReactionRuleShortSignature in project vcell by virtualcell.

the class ReactionCartoonRule method refreshAll.

@Override
protected void refreshAll(boolean reallocateShapes) {
    try {
        if (getModel() == null || getStructureSuite() == null) {
            return;
        }
        System.out.println("ReactionCartoonRule, RefreshAll()");
        for (Structure structure : structureSuite.getStructures()) {
            Diagram diagram = getModel().getDiagram(structure);
            if (diagram != null) {
                // Maintain consistency between rule participant nodes, signatures and
                // species pattern when a molecule is being modified.
                rebindAll(diagram);
            }
        }
        Set<Shape> unwantedShapes = new HashSet<Shape>();
        Set<RuleParticipantSignature> unwantedSignatures = new HashSet<RuleParticipantSignature>();
        Set<ReactionRuleShortSignature> unwantedRuleSignatures = new HashSet<ReactionRuleShortSignature>();
        unwantedShapes.addAll(getShapes());
        unwantedSignatures.addAll(ruleParticipantSignatures);
        unwantedRuleSignatures.addAll(reactionRuleShortSignatures);
        // ContainerContainerShape containerShape = (ContainerContainerShape) getShapeFromModelObject(getModel());
        // List<ReactionContainerShape> reactionContainerShapeList = new ArrayList<ReactionContainerShape>();
        // List<Structure> structureList = new ArrayList<Structure>(getStructureSuite().getStructures());
        // 
        // // create all ReactionContainerShapes (one for each Structure)
        // for(Structure structure : structureList) {
        // if (structure instanceof Membrane) {
        // Membrane membrane = (Membrane) structure;
        // ReactionContainerShape membraneShape =
        // (ReactionContainerShape) getShapeFromModelObject(membrane);
        // if (membraneShape == null) {
        // membraneShape = new ReactionContainerShape(membrane, structureSuite, this);
        // addShape(membraneShape);
        // membrane.getMembraneVoltage().removePropertyChangeListener(this);
        // membrane.getMembraneVoltage().addPropertyChangeListener(this);
        // } else {
        // membraneShape.setStructureSuite(structureSuite);
        // }
        // membrane.removePropertyChangeListener(this);
        // membrane.addPropertyChangeListener(this);
        // membraneShape.refreshLabel();
        // unwantedShapes.remove(membraneShape);
        // reactionContainerShapeList.add(membraneShape);
        // }else if (structure instanceof Feature){
        // Feature feature = (Feature) structure;
        // ReactionContainerShape featureShape = (ReactionContainerShape) getShapeFromModelObject(feature);
        // if (featureShape == null) {
        // featureShape = new ReactionContainerShape(feature, structureSuite, this);
        // addShape(featureShape);
        // } else {
        // featureShape.setStructureSuite(structureSuite);
        // }
        // feature.removePropertyChangeListener(this);
        // feature.addPropertyChangeListener(this);
        // featureShape.refreshLabel();
        // unwantedShapes.remove(featureShape);
        // reactionContainerShapeList.add(featureShape);
        // }
        // }
        // if (containerShape == null) {
        // containerShape = new ContainerContainerShape(this, getModel(), reactionContainerShapeList);
        // addShape(containerShape);
        // } else {
        // containerShape.setReactionContainerShapeList(reactionContainerShapeList);
        // }
        // containerShape.refreshLabel();
        // unwantedShapes.remove(containerShape);
        // // add all species context shapes within the structures
        // for(Structure structure : getStructureSuite().getStructures()) {
        // ReactionContainerShape reactionContainerShape =	(ReactionContainerShape) getShapeFromModelObject(structure);
        // structure.removePropertyChangeListener(this);
        // structure.addPropertyChangeListener(this);
        // for(SpeciesContext structSpeciesContext : getModel().getSpeciesContexts(structure)) {
        // SpeciesContextShape ss = (SpeciesContextShape) getShapeFromModelObject(structSpeciesContext);
        // if (ss == null) {
        // ss = new SpeciesContextShape(structSpeciesContext, this);
        // ss.truncateLabelName(false);
        // structSpeciesContext.getSpecies().removePropertyChangeListener(this);
        // structSpeciesContext.getSpecies().addPropertyChangeListener(this);
        // reactionContainerShape.addChildShape(ss);
        // addShape(ss);
        // ss.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
        // }
        // structSpeciesContext.removePropertyChangeListener(this);
        // structSpeciesContext.addPropertyChangeListener(this);
        // ss.refreshLabel();
        // unwantedShapes.remove(ss);
        // }
        // }
        // // add all reactionSteps that are in this structure (ReactionContainerShape), and draw the lines
        // getModel().removePropertyChangeListener(this);
        // getModel().addPropertyChangeListener(this);
        // //
        // // =================================== Rules ================================================
        // //
        // for(ReactionRule rr : getModel().getRbmModelContainer().getReactionRuleList()) {
        // rr.removePropertyChangeListener(this);
        // rr.addPropertyChangeListener(this);
        // Structure structure = rr.getStructure();
        // if(getStructureSuite().areReactionsShownFor(structure)) {
        // ReactionContainerShape reactionContainerShape =	(ReactionContainerShape) getShapeFromModelObject(structure);
        // 
        // ReactionRuleShortSignature ruleSignature = null;
        // int matches = 0;	// any rule must be part of one and only one ReactionRuleShortSignature object
        // for(ReactionRuleShortSignature rrss : reactionRuleShortSignatures) {
        // if(rrss.compareBySignature(rr)) {
        // ruleSignature = rrss;
        // matches++;
        // // 							break;		// once this code gets stable uncomment the break and remove the matches counter
        // } else {
        // // remove the rule if it's in the list even though the signature doesn't match
        // rrss.remove(rr);
        // }
        // }
        // if(matches > 1) {
        // throw new RuntimeException("Rule " + rr.getDisplayName() + " found in multiple ReactionRuleShortSignatures");
        // }
        // 
        // ReactionRuleShortDiagramShape rrShape = null;
        // if(ruleSignature == null) {
        // ruleSignature = new ReactionRuleShortSignature(rr);
        // reactionRuleShortSignatures.add(ruleSignature);
        // rrShape = new ReactionRuleShortDiagramShape(ruleSignature, this);
        // addShape(rrShape);
        // rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
        // reactionContainerShape.addChildShape(rrShape);
        // rrShape.getSpaceManager().setRelPos(reactionContainerShape.getRandomPosition());
        // } else {
        // ruleSignature.add(rr);	// add the rule if it's not there
        // rrShape = (ReactionRuleShortDiagramShape) getShapeFromModelObject(ruleSignature);
        // }
        // 
        // rrShape.refreshLabel();
        // unwantedShapes.remove(rrShape);
        // unwantedRuleSignatures.remove(ruleSignature);
        // if(matches != 0) {
        // continue;		// don't make other shapes or edges for this rule, the rule signature already has them from a previous rule
        // }
        // 
        // //
        // // add reaction participants as edges and SignatureShapes as needed
        // //
        // List<ReactionRuleParticipant> participants = rr.getReactionRuleParticipants();
        // List<RuleParticipantEdgeDiagramShape> ruleEdges = new ArrayList<> ();
        // for(ReactionRuleParticipant participant : participants) {
        // participant.getSpeciesPattern().removePropertyChangeListener(this);
        // participant.getSpeciesPattern().addPropertyChangeListener(this);
        // Structure speciesStructure = participant.getStructure();
        // Structure reactionStructure = rr.getStructure();
        // 
        // if(getStructureSuite().getStructures().contains(speciesStructure) && getStructureSuite().areReactionsShownFor(reactionStructure)) {
        // //
        // // find existing RuleParticipantSignatureShape in cartoon
        // //
        // RuleParticipantShortSignature ruleParticipantShortSignature = null;
        // for (RuleParticipantSignature signature : ruleParticipantSignatures) {
        // if (signature instanceof RuleParticipantLongSignature && signature.getStructure() == participant.getStructure()) {
        // System.out.println("ReactionCartoonMolecule, refreshAll(), RuleParticipantLongSignature");
        // break;
        // }
        // }
        // for (RuleParticipantSignature signature : ruleParticipantSignatures) {
        // if (signature instanceof RuleParticipantShortSignature && signature.getStructure() == participant.getStructure() &&
        // signature.compareByCriteria(participant.getSpeciesPattern(), GroupingCriteria.molecule)) {
        // ruleParticipantShortSignature = (RuleParticipantShortSignature)signature;
        // break;
        // }
        // }
        // //
        // // if didn't find signature in cartoons list of signatures, then create one (and create a shape for it).
        // //
        // RuleParticipantSignatureShortDiagramShape signatureShape = null;
        // if (ruleParticipantShortSignature == null) {
        // ruleParticipantShortSignature = RuleParticipantShortSignature.fromReactionRuleParticipant(participant, this);
        // ruleParticipantSignatures.add(ruleParticipantShortSignature);
        // signatureShape = new RuleParticipantSignatureShortDiagramShape(ruleParticipantShortSignature, this);
        // addShape(signatureShape);
        // ReactionContainerShape participantContainerShape =	(ReactionContainerShape) getShapeFromModelObject(participant.getStructure());
        // signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
        // participantContainerShape.addChildShape(signatureShape);
        // signatureShape.getSpaceManager().setRelPos(participantContainerShape.getRandomPosition());
        // } else {
        // signatureShape = (RuleParticipantSignatureShortDiagramShape) getShapeFromModelObject(ruleParticipantShortSignature);
        // }
        // 
        // unwantedShapes.remove(signatureShape);
        // unwantedSignatures.remove(ruleParticipantShortSignature);
        // signatureShape.refreshLabel();
        // signatureShape.setVisible(true);
        // 
        // //
        // // add edge for ReactionRuleParticipant if not already present.
        // //
        // RuleParticipantEdgeDiagramShape ruleParticipantShape = (RuleParticipantEdgeDiagramShape) getShapeFromModelObject(participant);
        // if (ruleParticipantShape == null || ruleParticipantShape.getRuleParticipantSignatureShape() != signatureShape) {
        // if (participant instanceof ReactantPattern && signatureShape.isVisible()) {
        // ruleParticipantShape = new ReactantPatternEdgeDiagramShape((ReactantPattern) participant, (ElipseShape)rrShape, signatureShape, this);
        // } else if (participant instanceof ProductPattern && signatureShape.isVisible()) {
        // ruleParticipantShape = new ProductPatternEdgeDiagramShape((ProductPattern) participant, (ElipseShape)rrShape, signatureShape, this);
        // } else {
        // throw new RuntimeException("unsupported ReactionRuleParticipant " + participant.getClass());
        // }
        // addShape(ruleParticipantShape);
        // }
        // if(!containerShape.getChildren().contains(ruleParticipantShape)) {
        // containerShape.addChildShape(ruleParticipantShape);
        // }
        // unwantedShapes.remove(ruleParticipantShape);
        // ruleParticipantShape.refreshLabel();
        // ruleEdges.add(ruleParticipantShape);	// all the edges for this rule
        // }
        // }
        // // now let's see if any reactant and product pair have the same signature - means we need to draw a reactant and
        // // a product edge (a closed loop) between the rule diagram shape and the signature diagram shape
        // for(RuleParticipantEdgeDiagramShape ours : ruleEdges) {
        // ours.setSibling(false);		// reset them all
        // }
        // for(RuleParticipantEdgeDiagramShape ours : ruleEdges) {
        // for(RuleParticipantEdgeDiagramShape theirs : ruleEdges) {
        // if(ours == theirs) {
        // continue;			// don't compare with self
        // }
        // if(ours.getRuleParticipantSignatureShape() == theirs.getRuleParticipantSignatureShape()) {
        // ours.setSibling(true);
        // theirs.setSibling(true);
        // }
        // }
        // }
        // }
        // }
        ruleParticipantSignatures.removeAll(unwantedSignatures);
        reactionRuleShortSignatures.removeAll(unwantedRuleSignatures);
        // }
        for (Shape unwantedShape : unwantedShapes) {
            removeShape(unwantedShape);
        }
    // // update diagrams
    // for(Structure structure : structureSuite.getStructures()) {
    // Diagram diagram = getModel().getDiagram(structure);
    // if (diagram != null) {
    // applyDefaults(diagram);
    // }
    // }
    // fireGraphChanged(new GraphEvent(this));
    } catch (Throwable e) {
        handleException(e);
    }
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) ReactionRuleShortSignature(cbit.vcell.model.ReactionRuleShortSignature) Structure(cbit.vcell.model.Structure) Diagram(cbit.vcell.model.Diagram) HashSet(java.util.HashSet)

Aggregations

Shape (cbit.gui.graph.Shape)2 ReactionRuleShortSignature (cbit.vcell.model.ReactionRuleShortSignature)2 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)2 Diagram (cbit.vcell.model.Diagram)1 FluxReaction (cbit.vcell.model.FluxReaction)1 NodeReference (cbit.vcell.model.NodeReference)1 Structure (cbit.vcell.model.Structure)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1