use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method copyRelativePosition.
public static void copyRelativePosition(GraphModel graphModel, BioModelEntityObject origEntity, BioModelEntityObject newEntity) {
Shape origEntityShape = graphModel.getShapeFromModelObject(origEntity);
if (origEntityShape == null) {
// happens when using BioModel 'Searchable Reactions...'
return;
}
Shape newEntityShape = graphModel.getShapeFromModelObject(newEntity);
newEntityShape.setRelPos(new Point(origEntityShape.getRelPos()));
// offset if completely overlap another shape
for (Shape shape : graphModel.getShapes()) {
if (shape.getModelObject() instanceof BioModelEntityObject && shape != newEntityShape) {
if (shape.getRelPos().equals(newEntityShape.getRelPos())) {
newEntityShape.setRelPos(new Point(newEntityShape.getRelX() + 5, newEntityShape.getRelY() + 5));
break;
}
}
}
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method updateRXContainerDropTargetInfoMap.
private HashMap<RXContainerDropTargetInfo, Boolean> updateRXContainerDropTargetInfoMap(Point pointWorld) {
HashMap<RXContainerDropTargetInfo, Boolean> rxContainerDropTargetInfoMap = null;
if (rxContainerDropTargetInfoMap == null) {
// System.out.println("-----redoing map...");
AllStructureSuite allStructureSuite = (getReactionCartoon().getStructureSuite() instanceof AllStructureSuite ? (AllStructureSuite) getReactionCartoon().getStructureSuite() : null);
if (allStructureSuite == null) {
throw new RuntimeException("Expecting " + AllStructureSuite.class.getName());
}
rxContainerDropTargetInfoMap = new HashMap<ReactionCartoonTool.RXContainerDropTargetInfo, Boolean>();
Structure[] originalOrderedStructArr = allStructureSuite.getStructures().toArray(new Structure[0]);
for (int i = 0; i < originalOrderedStructArr.length; i++) {
Shape currentRXContainerShape = getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i]);
if (i == 0) {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_BEGINNING), false);
} else {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, (ReactionContainerShape) getReactionCartoon().getShapeFromModelObject(originalOrderedStructArr[i - 1]), null), false);
}
if (i == (originalOrderedStructArr.length - 1)) {
rxContainerDropTargetInfoMap.put(new RXContainerDropTargetInfo((ReactionContainerShape) currentRXContainerShape, null, RXContainerDropTargetInfo.INSERT_END), false);
}
}
}
// System.out.println("-----Starting to update selection..."+pointWorld);
for (RXContainerDropTargetInfo rxcContainerDropTargetInfo : rxContainerDropTargetInfoMap.keySet()) {
if (rxcContainerDropTargetInfo.absoluteRectangle.contains(pointWorld)) {
// System.out.println(rxcContainerDropTargetInfo.dropShape.getLabel()+" "+rxcContainerDropTargetInfo.closestNeighborShape);
rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, true);
} else {
rxContainerDropTargetInfoMap.put(rxcContainerDropTargetInfo, false);
}
}
return rxContainerDropTargetInfoMap;
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method getLineTypeFromDirection.
private LineType getLineTypeFromDirection(Shape startingShape, Point worldPoint) throws Exception {
Shape mouseOverShape = getReactionCartoon().pickWorld(worldPoint);
if (mouseOverShape instanceof ReactionStepShape) {
if (startingShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) startingShape.getModelObject();
// check if the ReactionStep already has a Product for this SpeciesContext
ReactionStep reactionStep = (ReactionStep) mouseOverShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
if ((mouseOverShape instanceof SimpleReactionShape) || (mouseOverShape instanceof FluxReactionShape)) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
// else if (mouseOverShape instanceof FluxReactionShape){
// for (int i = 0; i < rps.length; i++){
// if ((rps[i] instanceof Reactant || rps[i] instanceof Product) && rps[i].getSpeciesContext() == speciesContext) {
// return LineType.NULL;
// }
// }
// return LineType.FLUX;
// }
}
} else if (mouseOverShape instanceof SpeciesContextShape) {
SpeciesContext speciesContext = (SpeciesContext) mouseOverShape.getModelObject();
if (startingShape instanceof SpeciesContextShape) {
// straight from one species to another ... will create a reaction upon release
return LineType.PRODUCT;
} else if (startingShape instanceof ReactionStepShape) {
ReactionStep reactionStep = (ReactionStep) startingShape.getModelObject();
ReactionParticipant[] rps = reactionStep.getReactionParticipants();
// } else
if (reactionStep instanceof SimpleReaction || reactionStep instanceof FluxReaction) {
for (int i = 0; i < rps.length; i++) {
if (rps[i] instanceof Reactant && rps[i].getSpeciesContext() == speciesContext) {
return LineType.NULL;
}
}
return LineType.REACTANT;
}
}
}
return LineType.NULL;
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method mouseClicked.
@Override
public void mouseClicked(MouseEvent event) {
Point screenPoint = new Point(event.getX(), event.getY());
Point worldPoint = screenToWorld(screenPoint);
try {
if (event.getButton() != MouseEvent.BUTTON1) {
return;
}
switch(mode) {
case SELECT:
{
if (event.getClickCount() == 2) {
final Shape selectedShape = getReactionCartoon().getSelectedShape();
if (selectedShape instanceof ReactionContainerShape || selectedShape instanceof SpeciesContextShape || selectedShape instanceof SimpleReactionShape || selectedShape instanceof FluxReactionShape || selectedShape instanceof ReactionRuleDiagramShape || selectedShape instanceof RuleParticipantSignatureDiagramShape) {
editInPlace(selectedShape, worldPoint);
}
if (selectedShape != null) {
menuAction(selectedShape, CartoonToolMiscActions.Properties.MENU_ACTION);
}
}
break;
}
case STEP:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (getReactionCartoon().getStructureSuite().areReactionsShownFor(structure)) {
ReactionStep reactionStep = getReactionCartoon().getModel().createSimpleReaction(structure);
positionShapeForObject(structure, reactionStep, worldPoint);
saveDiagram();
}
}
break;
}
case FLUX:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
Structure structure = ((ReactionContainerShape) pickedShape).getStructure();
if (structure instanceof Membrane) {
Membrane membrane = (Membrane) structure;
FluxReaction fluxReaction = getReactionCartoon().getModel().createFluxReaction(membrane);
ReactionStepShape frShape = (ReactionStepShape) getReactionCartoon().getShapeFromModelObject(fluxReaction);
Point parentLocation = frShape.getParent().getSpaceManager().getAbsLoc();
frShape.getSpaceManager().setRelPos(worldPoint.x - parentLocation.x, worldPoint.y - parentLocation.y);
saveDiagram();
// setMode(SELECT_MODE);
} else {
// setMode(SELECT_MODE);
// throw new Exception("fluxes only applicable to membranes");
}
}
break;
}
case SPECIES:
{
Shape pickedShape = getReactionCartoon().pickWorld(worldPoint);
if (pickedShape instanceof ReactionContainerShape) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(((ReactionContainerShape) pickedShape).getStructure());
reactionCartoon.clearSelection();
getGraphModel().select(speciesContext);
positionShapeForObject(speciesContext.getStructure(), speciesContext, worldPoint);
// showCreateSpeciesContextDialog(getGraphPane(), getReactionCartoon().getModel(), ((ReactionContainerShape) pickedShape).getStructure(), scShapeLocation);
saveDiagram();
}
}
default:
break;
}
} catch (Exception e) {
System.out.println("CartoonTool.mouseClicked: uncaught exception");
e.printStackTrace(System.out);
Point canvasLoc = getGraphPane().getLocationOnScreen();
canvasLoc.x += screenPoint.x;
canvasLoc.y += screenPoint.y;
DialogUtils.showErrorDialog(getGraphPane(), e.getMessage(), e);
}
}
use of cbit.gui.graph.Shape in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(SpeciesContext speciesContextStart, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
Structure startStructure = speciesContextStart.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
int stoichiometry = 1;
Reactant reactant = null;
for (ReactionParticipant participant : reactionEnd.getReactionParticipants()) {
if (participant instanceof Reactant && participant.getSpeciesContext().equals(speciesContextStart)) {
reactant = (Reactant) participant;
}
}
if (reactant != null) {
// only increase stoichiometry if reaction is SimpleReaction
if (reactionEnd instanceof SimpleReaction) {
reactant.setStoichiometry(reactant.getStoichiometry() + 1);
}
Shape shape = getReactionCartoon().getShapeFromModelObject(reactant);
if (shape != null) {
shape.refreshLabel();
}
} else {
// add speciesContextEnd as pdt to reactionStart only if reactionStart is a SimpleRxn or if it is a FluxRxn and doesn't have a pdt.
if (reactionEnd instanceof SimpleReaction || ((reactionEnd instanceof FluxReaction) && !(reactionEnd.hasReactant()))) {
reactionEnd.addReactant(speciesContextStart, stoichiometry);
}
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReactionEnd.setKinetics(new GeneralLumpedKinetics(simpleReactionEnd));
}
getReactionCartoon().notifyChangeEvent();
}
}
Aggregations