use of org.vcell.sbml.gui.SimulationSelectionPanel in project vcell by virtualcell.
the class SbmlExtensionFilter method askUser.
@Override
public void askUser(ChooseContext c) throws UserCancelException {
BioModel bioModel = c.chosenContext.getBioModel();
JFrame currentWindow = c.currentWindow;
selectedSimWOSBE = null;
selectedSimContext = c.chosenContext;
// get user choice of structure and its size and computes absolute sizes of compartments using the StructureSizeSolver.
Structure[] structures = bioModel.getModel().getStructures();
// get the nonspatial simulationContexts corresponding to names in applicableAppNameList
// This is needed in ApplnSelectionAndStructureSizeInputPanel
String strucName = null;
double structSize = 1.0;
int structSelection = -1;
int option = JOptionPane.CANCEL_OPTION;
ApplnSelectionAndStructureSizeInputPanel applnStructInputPanel = null;
while (structSelection < 0) {
applnStructInputPanel = new ApplnSelectionAndStructureSizeInputPanel();
applnStructInputPanel.setSimContext(c.chosenContext);
applnStructInputPanel.setStructures(structures);
if (applnStructInputPanel.isNeedStructureSizes()) {
applnStructInputPanel.setPreferredSize(new java.awt.Dimension(350, 400));
applnStructInputPanel.setMaximumSize(new java.awt.Dimension(350, 400));
option = DialogUtils.showComponentOKCancelDialog(currentWindow, applnStructInputPanel, "Specify Structure Size to Export:");
structSelection = applnStructInputPanel.getStructSelectionIndex();
if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
break;
} else if (option == JOptionPane.OK_OPTION && structSelection < 0) {
DialogUtils.showErrorDialog(currentWindow, "Please select a structure and set its size");
}
} else {
// adapt to legacy logic ...
structSelection = 0;
option = JOptionPane.OK_OPTION;
}
}
if (option == JOptionPane.OK_OPTION) {
applnStructInputPanel.applyStructureNameAndSizeValues();
strucName = applnStructInputPanel.getSelectedStructureName();
selectedSimContext = applnStructInputPanel.getSelectedSimContext();
GeometryContext geoContext = selectedSimContext.getGeometryContext();
if (!isSpatial) {
// calculate structure Sizes only if appln is not spatial
structSize = applnStructInputPanel.getStructureSize();
// Invoke StructureSizeEvaluator to compute absolute sizes of compartments if all sizes are not set
if ((geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || ((strucName == null || structSize <= 0.0) && (geoContext.isAllSizeSpecifiedNull() && geoContext.isAllVolFracAndSurfVolSpecified())) || (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecifiedNull()) || (!geoContext.isAllSizeSpecifiedPositive() && !geoContext.isAllVolFracAndSurfVolSpecified()) || (geoContext.isAllSizeSpecifiedNull() && !geoContext.isAllVolFracAndSurfVolSpecified())) {
DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment sizes being set. This can be automatically " + " computed if the absolute size of at least one compartment and the relative sizes (Surface-to-volume-ratio/Volume-fraction) " + " of all compartments are known. Sufficient information is not available to perform this computation." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure sizes in the 'StructureMapping' tab.");
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
if (!geoContext.isAllSizeSpecifiedPositive() && geoContext.isAllVolFracAndSurfVolSpecified()) {
Structure chosenStructure = selectedSimContext.getModel().getStructure(strucName);
StructureMapping chosenStructMapping = selectedSimContext.getGeometryContext().getStructureMapping(chosenStructure);
try {
StructureSizeSolver.updateAbsoluteStructureSizes(selectedSimContext, chosenStructure, structSize, chosenStructMapping.getSizeParameter().getUnitDefinition());
} catch (Exception e) {
throw new ProgrammingException("exception updating sizes", e);
}
}
} else {
if (!geoContext.isAllUnitSizeParameterSetForSpatial()) {
DialogUtils.showErrorDialog(currentWindow, "Cannot export to SBML without compartment size ratios being set." + "\n\nThis can be fixed by going back to the application '" + selectedSimContext.getName() + "' and setting structure" + " size ratios in the 'StructureMapping' tab.");
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
}
// Select simulation whose overrides need to be exported
// If simContext doesn't have simulations, don't pop up simulationSelectionPanel
Simulation[] sims = bioModel.getSimulations(selectedSimContext);
// display only those simulations that have overrides in the simulationSelectionPanel.
Vector<Simulation> orSims = new Vector<Simulation>();
for (int s = 0; (sims != null) && (s < sims.length); s++) {
if (sims[s].getMathOverrides().hasOverrides()) {
orSims.addElement(sims[s]);
}
}
Simulation[] overriddenSims = orSims.toArray(new Simulation[orSims.size()]);
if (overriddenSims.length > 0) {
SimulationSelectionPanel simSelectionPanel = new SimulationSelectionPanel();
simSelectionPanel.setPreferredSize(new java.awt.Dimension(600, 400));
simSelectionPanel.setMaximumSize(new java.awt.Dimension(600, 400));
simSelectionPanel.setSimulations(overriddenSims);
int simOption = DialogUtils.showComponentOKCancelDialog(currentWindow, simSelectionPanel, "Select Simulation whose overrides should be exported:");
if (simOption == JOptionPane.OK_OPTION) {
selectedSimWOSBE = simSelectionPanel.getSelectedSimulation();
// if (chosenSimulation != null) {
// CARRY hashTable.put("selectedSimulation", chosenSimulation);
// }
} else if (simOption == JOptionPane.CANCEL_OPTION || simOption == JOptionPane.CLOSED_OPTION) {
// Hence canceling the entire export to SBML operation.
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
}
} else if (option == JOptionPane.CANCEL_OPTION || option == JOptionPane.CLOSED_OPTION) {
// Hence canceling the entire export to SBML operation.
throw UserCancelException.CANCEL_XML_TRANSLATION;
}
if (selectedSimWOSBE != null) {
String selectedFileName = c.filename;
// rename file to contain exported simulation.
String ext = FilenameUtils.getExtension(selectedFileName);
String base = FilenameUtils.getBaseName(selectedFileName);
String path = FilenameUtils.getPath(selectedFileName);
base += "_" + TokenMangler.mangleToSName(selectedSimWOSBE.getName());
selectedFileName = path + base + ext;
c.selectedFile.renameTo(new File(selectedFileName));
}
}
Aggregations