use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionParticipantShape method getCurve.
@Override
protected final CubicCurve2D.Double getCurve() {
// TODO is this the best place for layout?
refreshLayoutSelf();
// default behavior of control points is for direction at ends to follow secant between end-points.
if (lastCurve_Start == null || !lastCurve_Start.equals(start) || lastCurve_End == null || !lastCurve_End.equals(end)) {
lastp1ctrl = new Point2D.Double((1.0 - FRACT_WEIGHT) * start.getX() + FRACT_WEIGHT * end.getX(), (1.0 - FRACT_WEIGHT) * start.getY() + FRACT_WEIGHT * end.getY());
}
Point2D.Double p2ctrl = new Point2D.Double(FRACT_WEIGHT * start.getX() + (1.0 - FRACT_WEIGHT) * end.getX(), FRACT_WEIGHT * start.getY() + (1.0 - FRACT_WEIGHT) * end.getY());
// check for siblings in the reaction (like a+a-> or a->a) and calculate a correction factor
// so that the edges won't overlap
correctionFactor = 0;
if (endShape instanceof ReactionStepShape) {
// index in the array of siblings
int myPosition = 0;
// including myself
int numSiblingsReactant = 0;
int numSiblingsProduct = 0;
// in total
int numSiblings = 0;
int numOthers = 0;
ReactionStepShape reactionStepShape = (ReactionStepShape) endShape;
ReactionStep rs = reactionStepShape.getReactionStep();
for (ReactionParticipant rp : rs.getReactionParticipants()) {
if (rp == reactionParticipant) {
// myself
if (rp instanceof Reactant) {
myPosition = numSiblings;
numSiblingsReactant++;
numSiblings++;
} else {
myPosition = numSiblings;
numSiblingsProduct++;
numSiblings++;
}
} else if (rp.getSpeciesContext().getName().equals(reactionParticipant.getSpeciesContext().getName())) {
if (rp instanceof Reactant) {
numSiblingsReactant++;
numSiblings++;
} else {
numSiblingsProduct++;
numSiblings++;
}
} else {
numOthers++;
}
}
if (numSiblings > 1) {
if (!(numSiblingsReactant == 1 && numSiblingsProduct == 1 && numOthers >= 1)) {
double offset = numSiblings / 2 - 0.5;
correctionFactor = (myPosition - offset) * 0.08;
} else {
// TODO: comment out the next 2 lines to have the "old style" behavior for a+b->a
double offset = numSiblings / 2 - 0.5;
correctionFactor = (myPosition - offset) * 0.08;
}
}
}
// calculate tangent direction at "reactionStep"
double tangentX = 0.0;
double tangentY = 0.0;
if (endShape instanceof ReactionStepShape) {
ReactionStepShape reactionStepShape = (ReactionStepShape) endShape;
for (Shape shape : graphModel.getShapes()) {
if (shape instanceof ReactionParticipantShape && ((ReactionParticipantShape) shape).endShape == reactionStepShape) {
ReactionParticipantShape rpShape = (ReactionParticipantShape) shape;
double dx = rpShape.start.getX() - rpShape.end.getX();
double dy = rpShape.start.getY() - rpShape.end.getY();
double len = dx * dx + dy * dy;
if (shape instanceof ProductShape) {
ProductShape ps = (ProductShape) shape;
tangentX += (ps.start.getX() - ps.end.getX()) / len;
tangentY += (ps.start.getY() - ps.end.getY()) / len;
} else if (shape instanceof ReactantShape) {
ReactantShape rs = (ReactantShape) shape;
tangentX -= (rs.start.getX() - rs.end.getX()) / len;
tangentY -= (rs.start.getY() - rs.end.getY()) / len;
}
}
}
}
double tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
if (tangentLength != 0) {
tangentX = tangentX * CONTROL_WEIGHT / tangentLength;
tangentY = tangentY * CONTROL_WEIGHT / tangentLength;
}
// tangentY = 0.0;
if (this instanceof CatalystShape) {
// choose side based on inner product with displacement vector between catalyst and reactionStep
if (((start.getX() - end.getX()) * tangentY - (start.getY() - end.getY()) * tangentX) > 0) {
p2ctrl.setLocation(end.getX() + tangentY, end.getY() - tangentX);
} else {
p2ctrl.setLocation(end.getX() - tangentY, end.getY() + tangentX);
}
} else if (this instanceof ProductShape) {
p2ctrl.setLocation(end.getX() + tangentX, end.getY() + tangentY);
} else if (this instanceof ReactantShape) {
p2ctrl.setLocation(end.getX() - tangentX, end.getY() - tangentY);
}
if (lastCurve != null && lastCurve_Start != null && lastCurve_Start.equals(start) && lastCurve_End != null && lastCurve_End.equals(end) && lastp2ctrl != null && lastp2ctrl.equals(p2ctrl)) {
// Do Nothing
} else {
lastCurve = new CubicCurve2D.Double(start.getX(), start.getY(), lastp1ctrl.getX() * (1 + correctionFactor), lastp1ctrl.getY() * (1 + correctionFactor), p2ctrl.getX(), p2ctrl.getY(), end.getX(), end.getY());
lastCurve_Start = new Point(start);
lastCurve_End = new Point(end);
lastp2ctrl = p2ctrl;
}
return lastCurve;
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class StructureMappingCartoon method refreshAll.
@Override
public void refreshAll() {
{
if (getGeometryContext() == null || getGeometryContext().getGeometry() == null) {
return;
}
GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
if (geometryClasses == null) {
return;
}
for (int i = 0; i < geometryClasses.length; i++) {
Shape testShape = getShapeFromModelObject(geometryClasses[i]);
if (testShape instanceof GeometryClassLegendShape) {
geometryClasses[i].removePropertyChangeListener((GeometryClassLegendShape) testShape);
}
}
}
clearAllShapes();
if (getSimulationContext() == null) {
fireGraphChanged(new GraphEvent(this));
return;
}
GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
GeometryContextStructureShape structureContainerShape = new GeometryContextStructureShape(this, getGeometryContext().getModel());
GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this, getGeometryContext(), structureContainerShape, geometryShape);
addShape(containerShape);
addShape(geometryShape);
addShape(structureContainerShape);
getGeometryContext().removePropertyChangeListener(this);
getGeometryContext().addPropertyChangeListener(this);
// create all StructureShapes
Structure[] structures = getGeometryContext().getModel().getStructures();
for (int i = 0; i < structures.length; i++) {
StructureMappingStructureShape smShape = new StructureMappingStructureShape((Structure) structures[i], getGeometryContext().getModel(), this);
addShape(smShape);
structureContainerShape.addChildShape(smShape);
structures[i].removePropertyChangeListener(this);
structures[i].addPropertyChangeListener(this);
}
// create all SubvolumeLegendShapes (for legend)
GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
GeometryClassLegendShape geometryClassLegendShape = new GeometryClassLegendShape(geometryClasses[i], getGeometryContext().getGeometry(), this, 10);
geometryClasses[i].addPropertyChangeListener(geometryClassLegendShape);
addShape(geometryClassLegendShape);
geometryShape.addChildShape(geometryClassLegendShape);
}
if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
}
subVolumeContainerShape.removeAllChildren();
subVolumeContainerShape.setBrightImage(getGeometryContext().getGeometry().getGeometrySpec().getThumbnailImage().getCurrentValue());
addShape(subVolumeContainerShape);
geometryShape.addChildShape(subVolumeContainerShape);
StructureMapping[] structureMappings = getGeometryContext().getStructureMappings();
for (int i = 0; i < structureMappings.length; i++) {
StructureMapping structureMapping = structureMappings[i];
structureMapping.removePropertyChangeListener(this);
structureMapping.addPropertyChangeListener(this);
if (structureMapping.getGeometryClass() != null) {
StructureShape sShape = (StructureShape) getShapeFromModelObject(structureMapping.getStructure());
GeometryClassLegendShape geometryClassLegendShape = (GeometryClassLegendShape) getShapeFromModelObject(structureMapping.getGeometryClass());
StructureMappingShape smShape = new StructureMappingShape(structureMapping, sShape, geometryClassLegendShape, this);
addShape(smShape);
containerShape.addChildShape(smShape);
}
}
// // assign children to shapes according to heirarchy in Model
// int nullParentCount=0;
// Collection<Shape> shapes = getShapes();
// for(Shape shape : shapes) {
// // for each featureShape, find corresponding featureShape
// if (shape instanceof StructureShape){
// StructureShape fs = (FeatureShape)shape;
// if(!structureContainerShape.contains(fs)) {
// structureContainerShape.addChildShape(fs);
// }
// nullParentCount++;
// }
// }
fireGraphChanged(new GraphEvent(this));
}
use of cbit.gui.graph.Shape 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);
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ConstraintsGraphModel method refreshAll.
public void refreshAll() {
Set<Shape> unwantedShapes = new HashSet<Shape>();
unwantedShapes.addAll(getShapes());
for (Shape shape : getShapes()) {
if (shape instanceof ConstraintVarNode) {
((ConstraintVarNode) shape).setDegree(1);
}
}
ContainerShape containerShape = (ContainerShape) getShapeFromModelObject(getConstraintContainerImpl());
if (containerShape == null) {
containerShape = new SimpleContainerShape(getConstraintContainerImpl(), this, "constraint network");
containerShape.setLabel("constraint network");
addShape(containerShape);
}
containerShape.refreshLabel();
unwantedShapes.remove(containerShape);
//
// add nodes for GeneralConstraints and edges to its Variables (add Variable when necessary)
//
GeneralConstraint[] generalConstraints = getConstraintContainerImpl().getGeneralConstraints();
for (int i = 0; i < generalConstraints.length; i++) {
String[] symbols = generalConstraints[i].getExpression().getSymbols();
if (symbols == null) {
continue;
}
GeneralConstraintNode generalConstraintNode = (GeneralConstraintNode) getShapeFromModelObject(generalConstraints[i]);
if (generalConstraintNode == null) {
generalConstraintNode = new GeneralConstraintNode(generalConstraints[i], this, symbols.length);
containerShape.addChildShape(generalConstraintNode);
addShape(generalConstraintNode);
}
generalConstraintNode.refreshLabel();
unwantedShapes.remove(generalConstraintNode);
for (int j = 0; j < symbols.length; j++) {
ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(symbols[j]);
if (constraintVarNode == null) {
constraintVarNode = new ConstraintVarNode(symbols[j], this, 1);
containerShape.addChildShape(constraintVarNode);
addShape(constraintVarNode);
} else {
constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
}
constraintVarNode.refreshLabel();
unwantedShapes.remove(constraintVarNode);
ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
for (Shape shape : getShapes()) {
if (shape instanceof ConstraintDependencyEdgeShape) {
if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == generalConstraintNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
}
}
}
if (constraintDependencyEdgeShape == null) {
constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(generalConstraintNode, constraintVarNode, this);
containerShape.addChildShape(constraintDependencyEdgeShape);
addShape(constraintDependencyEdgeShape);
}
unwantedShapes.remove(constraintDependencyEdgeShape);
}
}
//
// add nodes for SimpleBounds and edges to its Variables (add Variable when necessary)
//
cbit.vcell.constraints.SimpleBounds[] simpleBounds = getConstraintContainerImpl().getSimpleBounds();
for (int i = 0; i < simpleBounds.length; i++) {
BoundsNode boundsNode = (BoundsNode) getShapeFromModelObject(simpleBounds[i]);
if (boundsNode == null) {
boundsNode = new BoundsNode(simpleBounds[i], this);
containerShape.addChildShape(boundsNode);
addShape(boundsNode);
}
boundsNode.refreshLabel();
unwantedShapes.remove(boundsNode);
ConstraintVarNode constraintVarNode = (ConstraintVarNode) getShapeFromLabel(simpleBounds[i].getIdentifier());
if (constraintVarNode == null) {
constraintVarNode = new ConstraintVarNode(simpleBounds[i].getIdentifier(), this, 1);
containerShape.addChildShape(constraintVarNode);
addShape(constraintVarNode);
} else {
constraintVarNode.setDegree(constraintVarNode.getDegree() + 1);
}
constraintVarNode.refreshLabel();
unwantedShapes.remove(constraintVarNode);
ConstraintDependencyEdgeShape constraintDependencyEdgeShape = null;
for (Shape shape : getShapes()) {
if (shape instanceof ConstraintDependencyEdgeShape) {
if (((ConstraintDependencyEdgeShape) shape).getConstraintShape() == boundsNode && ((ConstraintDependencyEdgeShape) shape).getVarShape() == constraintVarNode) {
constraintDependencyEdgeShape = (ConstraintDependencyEdgeShape) shape;
}
}
}
if (constraintDependencyEdgeShape == null) {
constraintDependencyEdgeShape = new ConstraintDependencyEdgeShape(boundsNode, constraintVarNode, this);
containerShape.addChildShape(constraintDependencyEdgeShape);
addShape(constraintDependencyEdgeShape);
}
constraintDependencyEdgeShape.refreshLabel();
unwantedShapes.remove(constraintDependencyEdgeShape);
}
for (Shape unwantedShape : unwantedShapes) {
removeShape(unwantedShape);
}
fireGraphChanged(new GraphEvent(this));
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class PathwayGraphModel method refreshGroup.
private BioPaxGroupNeighborShape refreshGroup(PathwayContainerShape pathwayContainerShape, BioPaxObject ancObject, BioPaxShape bioPaxShape, InteractionParticipant participant) {
if (ancObject == null)
return null;
if (ancObject instanceof GroupObject) {
GroupObject groupObject = (GroupObject) ancObject;
Shape shapeG = getShapeFromModelObject(groupObject);
if (shapeG instanceof BioPaxGroupShape) {
BioPaxGroupShape groupShape = (BioPaxGroupShape) shapeG;
if (bioPaxShape instanceof BioPaxInteractionShape) {
BioPaxInteractionShape interactionShape = (BioPaxInteractionShape) bioPaxShape;
GroupNeighbor groupNeighbor = new GroupNeighbor(groupObject, interactionShape.getInteraction(), participant.getType());
BioPaxGroupNeighborShape neighborShape = (BioPaxGroupNeighborShape) getShapeFromModelObject(groupNeighbor);
if (neighborShape == null) {
neighborShape = new BioPaxGroupNeighborShape(groupNeighbor, interactionShape, groupShape, this);
pathwayContainerShape.addChildShape(neighborShape);
addShape(neighborShape);
}
return neighborShape;
} else if (bioPaxShape instanceof BioPaxGroupShape) {
BioPaxGroupShape groupConversionShape = (BioPaxGroupShape) bioPaxShape;
GroupNeighbor groupNeighbor = new GroupNeighbor(groupConversionShape.getGroupObject(), groupObject, participant.getType());
BioPaxGroupNeighborShape neighborShape = (BioPaxGroupNeighborShape) getShapeFromModelObject(groupNeighbor);
if (neighborShape == null) {
neighborShape = new BioPaxGroupNeighborShape(groupNeighbor, groupConversionShape, groupShape, this);
pathwayContainerShape.addChildShape(neighborShape);
addShape(neighborShape);
}
return neighborShape;
}
}
}
return null;
}
Aggregations