Search in sources :

Example 1 with NodeReference

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

the class XmlReader method getNodeReference.

/**
 * This method returns a nodeReference onject from a XML representation.
 * Creation date: (4/24/2001 5:35:56 PM)
 * @return cbit.vcell.model.NodeReference
 * @param param org.jdom.Element
 */
private NodeReference getNodeReference(Element param) throws XmlParseException {
    String tempname = param.getName();
    NodeReference newNodeRef = null;
    int type = NodeReference.UNKNOWN_NODE;
    String name = null;
    // determine the type of nodereference to create
    if (tempname.equalsIgnoreCase(XMLTags.SpeciesContextShapeTag)) {
        type = NodeReference.SPECIES_CONTEXT_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.SpeciesContextRefAttrTag));
    } else if (tempname.equalsIgnoreCase(XMLTags.SimpleReactionShapeTag)) {
        type = NodeReference.SIMPLE_REACTION_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.SimpleReactionRefAttrTag));
    } else if (tempname.equalsIgnoreCase(XMLTags.FluxReactionShapeTag)) {
        type = NodeReference.FLUX_REACTION_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.FluxReactionRefAttrTag));
    } else if (tempname.equalsIgnoreCase(XMLTags.ReactionRuleShapeTag)) {
        type = NodeReference.REACTION_RULE_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.ReactionRuleRef2AttrTag));
    } else if (tempname.equalsIgnoreCase(XMLTags.RuleParticipantFullShapeTag) || tempname.equalsIgnoreCase(XMLTags.RuleParticipantShapeTag)) {
        type = NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.RuleParticipantRefAttrTag));
    } else if (tempname.equalsIgnoreCase(XMLTags.RuleParticipantShortShapeTag)) {
        type = NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE;
        name = unMangle(param.getAttributeValue(XMLTags.RuleParticipantRefAttrTag));
    } else {
        throw new XmlParseException("An unknown type was found " + tempname + ",when processing noderefence!");
    }
    String modeString = unMangle(param.getAttributeValue(XMLTags.NodeReferenceModeAttrTag));
    NodeReference.Mode mode = NodeReference.Mode.none;
    if (modeString != null) {
        mode = Mode.fromValue(modeString);
    }
    java.awt.Point location = new java.awt.Point(Integer.parseInt(param.getAttributeValue(XMLTags.LocationXAttrTag)), Integer.parseInt(param.getAttributeValue(XMLTags.LocationYAttrTag)));
    newNodeRef = new NodeReference(mode, type, name, location);
    return newNodeRef;
}
Also used : Mode(cbit.vcell.model.NodeReference.Mode) NodeReference(cbit.vcell.model.NodeReference)

Example 2 with NodeReference

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

the class XmlReader method getDiagram.

/**
 * This method returns a Diagram object from a XML element.
 * Creation date: (4/4/2001 4:20:52 PM)
 * @return cbit.vcell.model.Diagram
 * @param param org.jdom.Element
 */
private Diagram getDiagram(Element param, Model model) throws XmlParseException {
    // get Attibutes
    String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
    String structureName = unMangle(param.getAttributeValue(XMLTags.StructureAttrTag));
    Structure structureref = model.getStructure(structureName);
    if (structureref == null) {
        throw new XmlParseException("The structure " + structureName + "could not be resolved!");
    }
    // try to create the new Diagram
    Diagram newdiagram = new Diagram(structureref, name);
    // Add Nodereferences (Shapes)
    List<Element> children = param.getChildren();
    if (children.size() > 0) {
        List<NodeReference> nodeRefList = new ArrayList<>();
        for (int i = 0; i < children.size(); i++) {
            nodeRefList.add(getNodeReference(children.get(i)));
        }
        newdiagram.setNodeReferences(nodeRefList);
    }
    return newdiagram;
}
Also used : NodeReference(cbit.vcell.model.NodeReference) Element(org.jdom.Element) ArrayList(java.util.ArrayList) Structure(cbit.vcell.model.Structure) Diagram(cbit.vcell.model.Diagram)

Example 3 with NodeReference

use of cbit.vcell.model.NodeReference 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 4 with NodeReference

use of cbit.vcell.model.NodeReference 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);
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) Shape(cbit.gui.graph.Shape) ReactionRule(cbit.vcell.model.ReactionRule) NodeReference(cbit.vcell.model.NodeReference) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction)

Example 5 with NodeReference

use of cbit.vcell.model.NodeReference 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);
    }
}
Also used : RuleParticipantSignature(cbit.vcell.model.RuleParticipantSignature) RuleParticipantLongSignature(cbit.vcell.model.RuleParticipantLongSignature) SimpleReaction(cbit.vcell.model.SimpleReaction) Shape(cbit.gui.graph.Shape) NodeReference(cbit.vcell.model.NodeReference) ArrayList(java.util.ArrayList) FluxReaction(cbit.vcell.model.FluxReaction) Point(java.awt.Point) Point(java.awt.Point) RuleParticipantShortSignature(cbit.vcell.model.RuleParticipantShortSignature) Structure(cbit.vcell.model.Structure)

Aggregations

NodeReference (cbit.vcell.model.NodeReference)11 RuleParticipantSignature (cbit.vcell.model.RuleParticipantSignature)8 ArrayList (java.util.ArrayList)7 Shape (cbit.gui.graph.Shape)6 FluxReaction (cbit.vcell.model.FluxReaction)6 Point (java.awt.Point)5 Structure (cbit.vcell.model.Structure)4 RuleParticipantLongSignature (cbit.vcell.model.RuleParticipantLongSignature)3 RuleParticipantShortSignature (cbit.vcell.model.RuleParticipantShortSignature)3 SimpleReaction (cbit.vcell.model.SimpleReaction)3 ReactionRule (cbit.vcell.model.ReactionRule)2 Element (org.jdom.Element)2 Diagram (cbit.vcell.model.Diagram)1 Mode (cbit.vcell.model.NodeReference.Mode)1 ReactionRuleShortSignature (cbit.vcell.model.ReactionRuleShortSignature)1