use of cbit.vcell.model.NodeReference in project vcell by virtualcell.
the class ReactionCartoonMolecule method setPositionsFromReactionCartoon.
public void setPositionsFromReactionCartoon(Diagram diagram) {
List<NodeReference> nodeList = new ArrayList<NodeReference>();
NodeReference.Mode mode = NodeReference.Mode.molecule;
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) {
System.out.println("ReactionCartoonMolecule, 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);
}
}
}
diagram.setNodeReferences(mode, nodeList);
}
use of cbit.vcell.model.NodeReference in project vcell by virtualcell.
the class ReactionCartoonMolecule method rebindAll.
// for the RULE_PARTICIPANT_SIGNATURE_NODE nodes we initialize the node's speciesPattern field
// from the matching signature
public void rebindAll(Diagram diagram) {
String nodeStructure = diagram.getStructure().getName();
List<NodeReference> nodeList = diagram.getNodeMoleculeList();
for (int i = 0; i < nodeList.size(); i++) {
NodeReference node = nodeList.get(i);
if (node.nodeType == NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE) {
if (node.speciesPattern != null) {
continue;
}
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (!signature.getStructure().getName().equals(nodeStructure)) {
continue;
}
String speciesPatternName = signature.getFirstSpeciesPatternAsString();
if (speciesPatternName.equals(node.name)) {
node.speciesPattern = signature.getSpeciesPattern();
break;
}
}
} else if (node.nodeType == NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE) {
System.out.println("ReactionCartoonMolecule, rebindAll(), wrong NodeReference type RULE_PARTICIPANT_SIGNATURE_FULL_NODE");
}
}
}
use of cbit.vcell.model.NodeReference in project vcell by virtualcell.
the class ReactionCartoonFull method rebindAll.
// for the RULE_PARTICIPANT_SIGNATURE_NODE nodes we initialize the node's speciesPattern field
// from the matching signature
public void rebindAll(Diagram diagram) {
String nodeStructure = diagram.getStructure().getName();
List<NodeReference> nodeList = diagram.getNodeFullList();
for (int i = 0; i < nodeList.size(); i++) {
NodeReference node = nodeList.get(i);
if (node.nodeType == NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE) {
if (node.speciesPattern != null) {
continue;
}
for (RuleParticipantSignature signature : ruleParticipantSignatures) {
if (!signature.getStructure().getName().equals(nodeStructure)) {
continue;
}
String speciesPatternName = signature.getFirstSpeciesPatternAsString();
if (speciesPatternName.equals(node.name)) {
node.speciesPattern = signature.getSpeciesPattern();
break;
}
}
} else if (node.nodeType == NodeReference.RULE_PARTICIPANT_SIGNATURE_SHORT_NODE) {
System.out.println("ReactionCartoonFull, rebindAll(), wrong NodeReference type RULE_PARTICIPANT_SIGNATURE_SHORT_NODE");
}
}
}
use of cbit.vcell.model.NodeReference in project vcell by virtualcell.
the class ReactionCartoonMolecule method applyDefaults.
public void applyDefaults(Diagram diagram) {
List<NodeReference> nodeList = diagram.getNodeMoleculeList();
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:
System.out.println("ReactionCartoonMolecule, RULE_PARTICIPANT_SIGNATURE_FULL_NODE detected");
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:
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.molecule, orphansList);
}
}
use of cbit.vcell.model.NodeReference in project vcell by virtualcell.
the class ReactionCartoonRule method applyDefaults.
public void applyDefaults(Diagram diagram) {
List<NodeReference> nodeList = diagram.getNodeRuleList();
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 // TODO: aici
NodeReference.REACTION_RULE_NODE:
obj = getModel().getRbmModelContainer().getReactionRule(node.name);
break;
case // obj is a RuleParticipantSignature
NodeReference.RULE_PARTICIPANT_SIGNATURE_FULL_NODE:
System.out.println("ReactionCartoonRule, RULE_PARTICIPANT_SIGNATURE_FULL_NODE detected");
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:
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.rule, orphansList);
}
}
Aggregations