use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class BioPaxInteractionParticipantShape method getCurve.
// very similar with the code in ReactionParticipantShape
@Override
protected final CubicCurve2D.Double getCurve() {
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 BioPaxInteractionShape) {
// index in the array of siblings
int myPosition = 0;
// in total
int numSiblings = 0;
BioPaxInteractionShape reactionStepShape = (BioPaxInteractionShape) endShape;
Interaction rs = reactionStepShape.getInteraction();
for (InteractionParticipant rp : rs.getParticipants()) {
if (rp == participant) {
// myself
if (rp.getType() == InteractionParticipant.Type.LEFT || rp.getType() == InteractionParticipant.Type.RIGHT) {
myPosition = numSiblings;
numSiblings++;
}
} else if (rp.getPhysicalEntity().getName().equals(participant.getPhysicalEntity().getName())) {
if (rp.getType() == InteractionParticipant.Type.LEFT || rp.getType() == InteractionParticipant.Type.RIGHT) {
numSiblings++;
}
}
}
if (numSiblings > 1) {
double offset = numSiblings / 2 - 0.5;
correctionFactor = (myPosition - offset) * 0.08;
}
}
// calculate tangent direction at interaction
double tangentX = 0.0;
double tangentY = 0.0;
if (endShape instanceof BioPaxInteractionShape) {
BioPaxInteractionShape reactionStepShape = (BioPaxInteractionShape) endShape;
for (Shape shape : graphModel.getShapes()) {
if (shape instanceof BioPaxInteractionParticipantShape && ((BioPaxInteractionParticipantShape) shape).endShape == reactionStepShape) {
BioPaxInteractionParticipantShape rpShape = (BioPaxInteractionParticipantShape) shape;
double dx = rpShape.start.getX() - rpShape.end.getX();
double dy = rpShape.start.getY() - rpShape.end.getY();
double len = dx * dx + dy * dy;
if (rpShape.participant.getType() == InteractionParticipant.Type.LEFT) {
tangentX += (rpShape.start.getX() - rpShape.end.getX()) / len;
tangentY += (rpShape.start.getY() - rpShape.end.getY()) / len;
} else if (rpShape.participant.getType() == InteractionParticipant.Type.RIGHT) {
tangentX -= (rpShape.start.getX() - rpShape.end.getX()) / len;
tangentY -= (rpShape.start.getY() - rpShape.end.getY()) / len;
}
}
}
}
double tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
if (tangentLength != 0) {
tangentX = tangentX * CONTROL_WEIGHT / tangentLength;
tangentY = tangentY * CONTROL_WEIGHT / tangentLength;
}
if (participant.getType() == InteractionParticipant.Type.CONTROLLER) {
// 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 (participant.getType() == InteractionParticipant.Type.RIGHT) {
p2ctrl.setLocation(end.getX() + tangentX, end.getY() + tangentY);
} else if (participant.getType() == InteractionParticipant.Type.LEFT) {
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 PathwayGraphModel method refreshParticipant.
private void refreshParticipant(BioPaxInteractionShape interactionShape, InteractionParticipant participant) {
BioPaxInteractionParticipantShape edgeShape = (BioPaxInteractionParticipantShape) getShapeFromModelObject(participant);
PhysicalEntity physicalEntity = participant.getPhysicalEntity();
BioPaxObject ancestorObject = pathwayModel.findTopLevelGroupAncestor(physicalEntity);
if (edgeShape == null) {
Shape shape = getShapeFromModelObject(physicalEntity);
if (shape instanceof BioPaxPhysicalEntityShape) {
BioPaxPhysicalEntityShape physicalEntityShape = (BioPaxPhysicalEntityShape) shape;
edgeShape = new BioPaxInteractionParticipantShape(participant, interactionShape, physicalEntityShape, this);
pathwayContainerShape.addChildShape(edgeShape);
addShape(edgeShape);
}
} else {
// edges without end objects will be removed
if (ancestorObject != physicalEntity) {
removeEdgeShape(edgeShape);
}
}
unwantedShapes.remove(refreshGroup(pathwayContainerShape, ancestorObject, interactionShape, participant));
unwantedShapes.remove(edgeShape);
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class PathwayGraphModel method refreshAll.
@Override
public void refreshAll() {
if (pathwayModel == null) {
clearAllShapes();
fireGraphChanged();
return;
}
unwantedShapes = new HashSet<Shape>();
unwantedShapes.addAll(getShapes());
pathwayContainerShape = (PathwayContainerShape) getShapeFromModelObject(pathwayModel);
if (pathwayContainerShape == null) {
pathwayContainerShape = new PathwayContainerShape(this, pathwayModel);
pathwayContainerShape.getSpaceManager().setSize(400, 300);
addShape(pathwayContainerShape);
}
unwantedShapes.remove(pathwayContainerShape);
Set<BioPaxObject> bioPaxObjects = new HashSet<BioPaxObject>(pathwayModel.getDisplayableBioPaxObjectList());
for (BioPaxObject bpObject : bioPaxObjects) {
BioPaxShape bpObjectShape = (BioPaxShape) getShapeFromModelObject(bpObject);
if (bpObjectShape == null) {
if (bpObject instanceof Conversion) {
bpObjectShape = new BioPaxConversionShape((Conversion) bpObject, this);
} else if (bpObject instanceof MolecularInteraction) {
bpObjectShape = new BioPaxMolecularInteractionShape((MolecularInteraction) bpObject, this);
} else if (bpObject instanceof Protein) {
bpObjectShape = new BioPaxProteinShape((Protein) bpObject, this);
} else if (bpObject instanceof Complex) {
bpObjectShape = new BioPaxComplexShape((Complex) bpObject, this);
} else if (bpObject instanceof SmallMolecule) {
bpObjectShape = new BioPaxSmallMoleculeShape((SmallMolecule) bpObject, this);
} else if (bpObject instanceof Dna) {
bpObjectShape = new BioPaxDnaShape((Dna) bpObject, this);
} else if (bpObject instanceof Rna) {
bpObjectShape = new BioPaxRnaShape((Rna) bpObject, this);
} else if (bpObject instanceof PhysicalEntity) {
bpObjectShape = new BioPaxPhysicalEntityShape((PhysicalEntity) bpObject, this);
} else if (bpObject instanceof GroupObject) {
bpObjectShape = new BioPaxGroupShape((GroupObject) bpObject, this);
} else {
bpObjectShape = new BioPaxObjectShape(bpObject, this);
}
if (!(bpObject instanceof Control)) {
// the Control objects will not be displayed on the diagram
pathwayContainerShape.addChildShape(bpObjectShape);
addShape(bpObjectShape);
}
Dimension shapeSize = bpObjectShape.getSpaceManager().getSize();
Rectangle boundary = getContainerLayout().getBoundaryForAutomaticLayout(pathwayContainerShape);
int xPos = boundary.x + random.nextInt(boundary.width - shapeSize.width);
int yPos = boundary.y + random.nextInt(boundary.height - shapeSize.height);
bpObjectShape.setAbsPos(xPos, yPos);
}
unwantedShapes.remove(bpObjectShape);
}
for (BioPaxObject bpObject : bioPaxObjects) {
if (bpObject instanceof Conversion) {
refreshInteraction((Conversion) bpObject);
} else if (bpObject instanceof MolecularInteraction) {
refreshInteraction((MolecularInteraction) bpObject);
} else if (bpObject instanceof Control) {
refreshControl((Control) bpObject);
} else if (bpObject instanceof GroupObject) {
refreshGroupObject((GroupObject) bpObject);
}
}
for (Shape unwantedShape : unwantedShapes) {
removeShape(unwantedShape);
}
refreshRelationshipInfo();
fireGraphChanged();
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class PathwayGraphModel method refreshGroupInteraction.
private void refreshGroupInteraction(GroupObject groupObject, InteractionParticipant participant) {
BioPaxGroupShape groupShape = (BioPaxGroupShape) getShapeFromModelObject(groupObject);
PhysicalEntity physicalEntity = participant.getPhysicalEntity();
GroupNeighbor groupNeighbor = new GroupNeighbor(groupObject, physicalEntity, participant.getType());
BioPaxGroupNeighborShape edgeShape = (BioPaxGroupNeighborShape) getShapeFromModelObject(groupNeighbor);
BioPaxObject ancestorObject = pathwayModel.findTopLevelGroupAncestor(physicalEntity);
if (edgeShape == null) {
Shape shape = getShapeFromModelObject(physicalEntity);
if (shape instanceof BioPaxPhysicalEntityShape) {
BioPaxPhysicalEntityShape physicalEntityShape = (BioPaxPhysicalEntityShape) shape;
edgeShape = new BioPaxGroupNeighborShape(groupNeighbor, groupShape, physicalEntityShape, this);
pathwayContainerShape.addChildShape(edgeShape);
addShape(edgeShape);
}
} else {
// edges without end objects will be removed
if (ancestorObject != physicalEntity) {
// for grouped objects
removeEdgeShape(edgeShape);
}
}
unwantedShapes.remove(refreshGroup(pathwayContainerShape, ancestorObject, groupShape, participant));
unwantedShapes.remove(edgeShape);
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class RuleParticipantEdgeDiagramShape 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());
// calculate tangent direction at "reactionStep"
double tangentX = 0.0;
double tangentY = 0.0;
if (endShape instanceof ReactionRuleDiagramShape) {
ReactionRuleDiagramShape reactionRuleDiagramShape = (ReactionRuleDiagramShape) endShape;
for (Shape shape : graphModel.getShapes()) {
if (shape instanceof RuleParticipantEdgeDiagramShape && ((RuleParticipantEdgeDiagramShape) shape).endShape == reactionRuleDiagramShape) {
RuleParticipantEdgeDiagramShape rpShape = (RuleParticipantEdgeDiagramShape) 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 ProductPatternEdgeDiagramShape) {
ProductPatternEdgeDiagramShape ps = (ProductPatternEdgeDiagramShape) shape;
tangentX += (ps.start.getX() - ps.end.getX()) / len;
tangentY += (ps.start.getY() - ps.end.getY()) / len;
if (bSibling) {
tangentX = 0.1;
tangentY = 0.1;
}
} else if (shape instanceof ReactantPatternEdgeDiagramShape) {
ReactantPatternEdgeDiagramShape rs = (ReactantPatternEdgeDiagramShape) shape;
tangentX -= (rs.start.getX() - rs.end.getX()) / len;
tangentY -= (rs.start.getY() - rs.end.getY()) / len;
if (bSibling) {
tangentX = -0.1;
tangentY = -0.1;
}
}
}
}
}
double tangentLength = Math.sqrt(tangentX * tangentX + tangentY * tangentY);
if (tangentLength != 0) {
tangentX = tangentX * CONTROL_WEIGHT / tangentLength;
tangentY = tangentY * CONTROL_WEIGHT / tangentLength;
}
// } else
if (this instanceof ProductPatternEdgeDiagramShape) {
p2ctrl.setLocation(end.getX() + tangentX, end.getY() + tangentY);
} else if (this instanceof ReactantPatternEdgeDiagramShape) {
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(), lastp1ctrl.getY(), p2ctrl.getX(), p2ctrl.getY(), end.getX(), end.getY());
lastCurve_Start = new Point(start);
lastCurve_End = new Point(end);
lastp2ctrl = p2ctrl;
}
return lastCurve;
}
Aggregations