use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class ReactionCartoonTool method lineActon.
private void lineActon(Structure startStructure, ReactionStep reactionEnd) throws Exception {
Structure endStructure = reactionEnd.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(endStructure, startStructure)) {
// if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as reactant
if ((reactionEnd instanceof SimpleReaction) || ((reactionEnd instanceof FluxReaction) && !reactionEnd.hasReactant())) {
SpeciesContext speciesContext = getReactionCartoon().getModel().createSpeciesContext(startStructure);
reactionEnd.addReactant(speciesContext, 1);
positionShapeForObject(startStructure, speciesContext, edgeShape.getStart());
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// simpleReaction.setKinetics(new GeneralLumpedKinetics(simpleReaction));
}
getReactionCartoon().notifyChangeEvent();
}
}
use of cbit.vcell.model.SpeciesContext 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.vcell.model.SpeciesContext 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.vcell.model.SpeciesContext in project vcell by virtualcell.
the class ReactionCartoonTool method deleteReactionsAndSpecies.
public static void deleteReactionsAndSpecies(Component requester, ReactionStep[] reactionStepArr, SpeciesContext[] speciesContextArr) throws Exception, UserCancelException {
if ((speciesContextArr == null && reactionStepArr == null) || (reactionStepArr == null && speciesContextArr != null && speciesContextArr.length == 0) || (speciesContextArr == null && reactionStepArr != null && reactionStepArr.length == 0) || (speciesContextArr != null && speciesContextArr.length == 0 && reactionStepArr != null && reactionStepArr.length == 0)) {
return;
}
int rxCount = (reactionStepArr != null ? reactionStepArr.length : 0);
int speciesCount = (speciesContextArr != null ? speciesContextArr.length : 0);
boolean bHasBoth = speciesCount > 0 && rxCount > 0;
ReactionCartoon rxCartoon = null;
if (requester instanceof GraphPane && ((GraphPane) requester).getGraphModel() instanceof ReactionCartoon) {
rxCartoon = (ReactionCartoon) (((GraphPane) requester).getGraphModel());
} else if (requester instanceof ReactionCartoonEditorPanel) {
rxCartoon = ((ReactionCartoonEditorPanel) requester).getReactionCartoon();
} else {
throw new IllegalArgumentException("ReactionCartoonTool.deleteSpeciesContext not implemented for type '" + requester.getClass().getName() + "'");
}
DeleteSpeciesInfo deleteSpeciesInfo = null;
final String DETAILS = "Details...";
while (true) {
String response = DialogUtils.showWarningDialog(requester, RXSPECIES_DELETE + " " + (bHasBoth ? "Reactions and Species." : (rxCount > 0 ? "Reactions." : (speciesCount > 0 ? "Species." : ""))), RXSPECIES_DELETE + " " + (bHasBoth ? rxCount + " Reactions and " + speciesCount + " Species." : (rxCount > 0 ? rxCount + " Reactions." : (speciesCount > 0 ? speciesCount + " Species." : ""))), new String[] { RXSPECIES_DELETE, DETAILS, RXSPECIES_CANCEL }, RXSPECIES_DELETE);
if (response == null || response.equals(RXSPECIES_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
}
deleteSpeciesInfo = (deleteSpeciesInfo == null ? detailsDeleteSpecies(requester, speciesContextArr, reactionStepArr, rxCartoon) : deleteSpeciesInfo);
if (response.equals(DETAILS)) {
TableListResult tableListResult = showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, false);
// if(!tableListResult.selectedOption.equals(RXSPECIES_BACK)){
// //if(!tableListResult.selectedOption.equals((bCut?RXSPECIES_CUT:RXSPECIES_DELETE))){
// throw UserCancelException.CANCEL_GENERIC;
// }
} else {
break;
}
}
if (deleteSpeciesInfo != null) {
for (Boolean errors : deleteSpeciesInfo.getbUnresolvableHashMap().values()) {
if (errors) {
while (true) {
String response = DialogUtils.showWarningDialog(requester, "Error warning.", "Warning: 1 or more SpeciesContexts have Model references that could cause Model corruption if " + RXSPECIES_DELETE + ".", new String[] { DETAILS, RXSPECIES_CANCEL }, DETAILS);
if (response == null || response.equals(RXSPECIES_CANCEL)) {
throw UserCancelException.CANCEL_GENERIC;
}
showDeleteDetails(requester, deleteSpeciesInfo, reactionStepArr, true);
}
}
}
}
if (reactionStepArr != null) {
for (int i = 0; i < reactionStepArr.length; i += 1) {
rxCartoon.getModel().removeReactionStep(reactionStepArr[i]);
}
}
if (deleteSpeciesInfo != null) {
// remove all ReactionParticipants ("lines" between reaction and species in "Reaction Diagram") that have this speciesContext before deleting SpeciesContext
for (SpeciesContext objSpeciesContext : deleteSpeciesInfo.getRxPartHashMap().keySet()) {
if (deleteSpeciesInfo.getbUnresolvableHashMap().get(objSpeciesContext)) {
continue;
}
Iterator<ReactionParticipant> iterRxPart = deleteSpeciesInfo.getRxPartHashMap().get(objSpeciesContext).iterator();
while (iterRxPart.hasNext()) {
ReactionParticipant objRxPart = iterRxPart.next();
if (rxCartoon.getObjects().contains(objRxPart)) {
// Reaction delete may have already removed
objRxPart.getReactionStep().removeReactionParticipant(objRxPart);
}
}
}
// remove the SpeciesContext
for (int i = 0; i < speciesContextArr.length; i++) {
if (deleteSpeciesInfo.getbUnresolvableHashMap().get(speciesContextArr[i])) {
continue;
}
if (rxCartoon.getObjects().contains(speciesContextArr[i])) {
// Reaction delete may have already removed
rxCartoon.getModel().removeSpeciesContext(speciesContextArr[i]);
}
}
}
}
use of cbit.vcell.model.SpeciesContext in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(Structure startStructure, Structure endStructure, Shape endShape) throws Exception, PropertyVetoException, ExpressionException {
Point startPos = edgeShape.getStart();
Point endPos = edgeShape.getEnd();
if (endStructure.equals(startStructure)) {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(endStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(endStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
} else {
if (endStructure instanceof Membrane && startStructure instanceof Feature) {
Membrane endMembrane = (Membrane) endStructure;
Feature startFeature = (Feature) startStructure;
// if(structTopology.getOutsideFeature(endMembrane).equals(startFeature) || structTopology.getInsideFeature(endMembrane).equals(startFeature))
// {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startFeature);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endMembrane);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(endMembrane);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startFeature, speciesContext1, startPos);
positionShapeForObject(endMembrane, speciesContext2, endPos);
// finding correct insertion point for reaction, statements below should be put into a utility if used often
int memAbsXmin = endShape.getSpaceManager().getAbsLoc().x;
int memAbsXmax = memAbsXmin + endShape.getSpaceManager().getSize().width;
int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
int reactionAbsX = (startPos.x + endPos.x) / 2;
if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
reactionAbsX = memAbsXmin;
} else {
reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
}
positionShapeForObject(endMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
// }
} else if (endStructure instanceof Feature && startStructure instanceof Membrane) {
Membrane startMembrane = (Membrane) startStructure;
Feature endFeature = (Feature) endStructure;
// if(structTopology.getOutsideFeature(startMembrane).equals(endFeature) || structTopology.getInsideFeature(startMembrane).equals(endFeature))
// {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startMembrane);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endFeature);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startMembrane);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startMembrane, speciesContext1, startPos);
positionShapeForObject(endFeature, speciesContext2, endPos);
// finding correct insertion point for reaction, statements below should be put into a utility if used often
int memAbsXmin = startShape.getSpaceManager().getAbsLoc().x;
int memAbsXmax = memAbsXmin + startShape.getSpaceManager().getSize().width;
int reactionWidth = new SimpleReactionShape(reaction, getReactionCartoon()).getSpaceManager().getSize().width;
int reactionAbsX = (startPos.x + endPos.x) / 2;
if ((memAbsXmax - memAbsXmin) <= reactionWidth) {
reactionAbsX = memAbsXmin;
} else {
reactionAbsX = Math.max(reactionAbsX, memAbsXmin);
reactionAbsX = Math.min(reactionAbsX, (memAbsXmax - reactionWidth));
}
positionShapeForObject(startMembrane, reaction, new Point(reactionAbsX, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
// }
} else if (endStructure instanceof Feature && startStructure instanceof Feature) {
Feature startFeature = (Feature) startStructure;
Feature endFeature = (Feature) endStructure;
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
reaction.setKinetics(new GeneralLumpedKinetics(reaction));
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
} else if (endStructure instanceof Membrane && startStructure instanceof Membrane) {
SpeciesContext speciesContext1 = getReactionCartoon().getModel().createSpeciesContext(startStructure);
SpeciesContext speciesContext2 = getReactionCartoon().getModel().createSpeciesContext(endStructure);
SimpleReaction reaction = getReactionCartoon().getModel().createSimpleReaction(startStructure);
reaction.addReactant(speciesContext1, 1);
reaction.addProduct(speciesContext2, 1);
reaction.setKinetics(new GeneralLumpedKinetics(reaction));
getReactionCartoon().notifyChangeEvent();
positionShapeForObject(startStructure, speciesContext1, startPos);
positionShapeForObject(endStructure, speciesContext2, endPos);
positionShapeForObject(startStructure, reaction, new Point((startPos.x + endPos.x) / 2, (startPos.y + endPos.y) / 2));
getGraphModel().clearSelection();
getGraphModel().select(reaction);
}
}
}
Aggregations