use of org.vcell.util.document.VCDocument in project vcell by virtualcell.
the class ClientRequestManager method runSimulations.
public void runSimulations(final ClientSimManager clientSimManager, final Simulation[] simulations) {
DocumentWindowManager documentWindowManager = clientSimManager.getDocumentWindowManager();
/* run some quick checks to see if we need to do a SaveAs */
boolean needSaveAs = false;
if (documentWindowManager.getVCDocument().getVersion() == null) {
// never saved
needSaveAs = true;
} else if (!documentWindowManager.getVCDocument().getVersion().getOwner().compareEqual(getDocumentManager().getUser())) {
// not the owner
// keep the user informed this time
String choice = PopupGenerator.showWarningDialog(documentWindowManager, getUserPreferences(), UserMessage.warn_SaveNotOwner, null);
if (choice.equals(UserMessage.OPTION_SAVE_AS_NEW)) {
needSaveAs = true;
} else {
// user canceled, just show existing document
getMdiManager().showWindow(documentWindowManager.getManagerID());
throw new UserCancelException("user canceled");
}
}
// Before running the simulation, check if all the sizes of structures are set
if (simulations != null && simulations.length > 0) {
VCDocument vcd = documentWindowManager.getVCDocument();
if (vcd instanceof BioModel) {
String stochChkMsg = null;
// we want to check when there is stochastic application if the rate laws set in model can be automatically transformed.
for (int i = 0; i < simulations.length; i++) {
if (simulations[i].getMathDescription().isNonSpatialStoch() || simulations[i].getMathDescription().isSpatialStoch() || simulations[i].getMathDescription().isSpatialHybrid()) {
if (stochChkMsg == null) {
stochChkMsg = ((BioModel) vcd).getModel().isValidForStochApp();
}
if (!(stochChkMsg.equals(""))) {
DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem in simulation: " + simulations[i].getName() + ".\n" + stochChkMsg);
throw new RuntimeException("Problem in simulation: " + simulations[i].getName() + "\n" + stochChkMsg);
}
}
}
}
}
//
for (int i = 0; simulations != null && i < simulations.length; i++) {
if (simulations[i].getSimulationVersion() != null && simulations[i].getSimulationVersion().getParentSimulationReference() != null) {
simulations[i].clearVersion();
}
}
/* now start the dirty work */
/* block document window */
JFrame currentDocumentWindow = getMdiManager().blockWindow(documentWindowManager.getManagerID());
/* prepare hashtable for tasks */
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put("mdiManager", getMdiManager());
hash.put(DocumentManager.IDENT, getDocumentManager());
hash.put(CommonTask.DOCUMENT_WINDOW_MANAGER.name, documentWindowManager);
hash.put("currentDocumentWindow", currentDocumentWindow);
hash.put("clientSimManager", clientSimManager);
hash.put("simulations", simulations);
hash.put("jobManager", getClientServerManager().getJobManager());
hash.put("requestManager", this);
/* create tasks */
AsynchClientTask[] tasks = null;
if (needSaveAs) {
// check document consistency first
AsynchClientTask documentValid = new DocumentValidTask();
AsynchClientTask setMathDescription = new SetMathDescription();
// get a new name
AsynchClientTask newName = new NewName();
// save it
AsynchClientTask saveDocument = new SaveDocument();
// clean up
AsynchClientTask finishSave = new FinishSave();
// run the simulations
AsynchClientTask runSims = new RunSims();
// assemble array
tasks = new AsynchClientTask[] { documentValid, setMathDescription, newName, saveDocument, finishSave, runSims };
} else {
// check document consistency first
AsynchClientTask documentValid = new DocumentValidTask();
AsynchClientTask setMathDescription = new SetMathDescription();
// check if unchanged document
AsynchClientTask checkUnchanged = new CheckUnchanged(true);
// save it
AsynchClientTask saveDocument = new SaveDocument();
// check for lost results
AsynchClientTask checkBeforeDelete = new CheckBeforeDelete();
// delete old document
AsynchClientTask deleteOldDocument = new DeleteOldDocument();
// clean up
AsynchClientTask finishSave = new FinishSave();
// run the simulations
AsynchClientTask runSims = new RunSims();
// assemble array
tasks = new AsynchClientTask[] { documentValid, setMathDescription, checkUnchanged, saveDocument, checkBeforeDelete, deleteOldDocument, finishSave, runSims };
}
/* run the tasks */
ClientTaskDispatcher.dispatch(currentDocumentWindow, hash, tasks, true);
}
use of org.vcell.util.document.VCDocument in project vcell by virtualcell.
the class Translator method translate.
public VCDocument translate(Reader reader, boolean validationOn) throws Exception {
if (validationOn) {
this.sRoot = (XmlUtil.readXML(reader, schemaLocation, null, schemaLocationPropName)).getRootElement();
String errorLog = XmlUtil.getErrorLog();
if (errorLog.length() > 0) {
System.err.println(errorLog);
if (vcLogger != null) {
vcLogger.sendMessage(VCLogger.Priority.LowPriority, VCLogger.ErrorType.SchemaValidation);
// vcLogger.sendMessage(VCLogger.LOW_PRIORITY, TranslationMessage.SCHEMA_VALIDATION_ERROR,
// "The source model has invalid elements/attributes:\n" + errorLog)
}
}
} else {
this.sRoot = (XmlUtil.readXML(reader, null, null, null)).getRootElement();
}
VCDocument vcDoc = translate();
if (vcLogger != null && vcLogger.hasMessages()) {
vcLogger.sendAllMessages();
}
return vcDoc;
}
use of org.vcell.util.document.VCDocument in project vcell by virtualcell.
the class ClientSimManager method showSimulationResults0.
private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
// Create the AsynchClientTasks
ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
taskList.add(new AsynchClientTaskFunction(h -> {
h.put(H_LOCAL_SIM, isLocal);
h.put(H_VIEWER_TYPE, viewerType);
}, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
if (simWindow == null && (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only)) {
try {
// make the manager and wire it up
DataViewerController dataViewerController = null;
if (!isLocal) {
dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
// For changes in time or variable
documentWindowManager.addDataListener(dataViewerController);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
DataManager dataManager = null;
if (sim.isSpatial()) {
dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
} else {
dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
}
dataViewerController = new SimResultsViewerController(dataManager, sim);
dataSetControllerImpl.addDataJobListener(documentWindowManager);
}
// make the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
if (dataViewerControllers == null) {
dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
}
dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
try {
if (viewerType == ViewerType.PythonViewer_only || viewerType == ViewerType.BothNativeAndPython) {
VtkManager vtkManager = null;
if (!isLocal) {
vtkManager = documentWindowManager.getRequestManager().getVtkManager(outputContext, new VCSimulationDataIdentifier(vcSimulationIdentifier, 0));
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
vtkManager = new VtkManager(outputContext, vcDataManager, simulationDataIdentifier);
}
//
// test ability to read data
//
VtuVarInfo[] vtuVarInfos = vtkManager.getVtuVarInfos();
double[] times = vtkManager.getDataSetTimes();
//
// create the SimulationDataSetRef
//
VCDocument modelDocument = null;
if (documentWindowManager instanceof BioModelWindowManager) {
modelDocument = ((BioModelWindowManager) documentWindowManager).getBioModel();
} else if (documentWindowManager instanceof MathModelWindowManager) {
modelDocument = ((MathModelWindowManager) documentWindowManager).getMathModel();
}
SimulationDataSetRef simulationDataSetRef = VCellClientDataServiceImpl.createSimulationDataSetRef(sim, modelDocument, 0, isLocal);
// Hashtable<VCSimulationIdentifier, SimulationDataSetRef> simDataSetRefs = (Hashtable<VCSimulationIdentifier, SimulationDataSetRef>)hashTable.get(H_SIM_DATASET_REFS);
// if (simDataSetRefs == null) {
// simDataSetRefs = new Hashtable<VCSimulationIdentifier, SimulationDataSetRef>();
// hashTable.put(H_SIM_DATASET_REFS, simDataSetRefs);
// }
// simDataSetRefs.put(vcSimulationIdentifier, simulationDataSetRef);
File visitExe = VCellConfiguration.getFileProperty(PropertyLoader.visitExe);
if (visitExe != null) {
VisitSupport.launchVisTool(visitExe, simulationDataSetRef);
}
}
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
}
};
taskList.add(retrieveResultsTask);
AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
if (failures != null && failures.containsKey(sim)) {
continue;
}
final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
if (simWindow != null) {
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
if (childWindow == null) {
childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
childWindow.pack();
childWindow.setIsCenteredOnParent();
childWindow.show();
}
setFinalWindow(hashTable, childWindow);
simWindow.setLocalState(localState);
} else {
// wire it up the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
Throwable ex = (failures == null ? null : failures.get(sim));
if (viewerController != null && ex == null) {
// no failure
DataViewer viewer = viewerController.createViewer();
getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
documentWindowManager.addExportListener(viewer);
// For data related activities such as calculating statistics
documentWindowManager.addDataJobListener(viewer);
viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
viewer.setDataViewerManager(documentWindowManager);
SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
documentWindowManager.addResultsFrame(newWindow);
setFinalWindow(hashTable, viewer);
newWindow.setLocalState(localState);
}
}
}
StringBuffer failMessage = new StringBuffer();
if (failures != null) {
if (!failures.isEmpty()) {
failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
}
}
}
if (failMessage.length() > 0) {
PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
}
}
};
if (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only) {
taskList.add(displayResultsTask);
}
// Dispatch the tasks using the ClientTaskDispatcher.
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
return taskArray;
}
use of org.vcell.util.document.VCDocument in project vcell by virtualcell.
the class PopupGenerator method showErrorDialog.
/**
* showErrorDialog. If requester is of type DocumentWindowManager, offer to send context information
* to VCellSupport
* @param requester
* @param message to display
* @param ex may be null
*/
public static void showErrorDialog(TopLevelWindowManager requester, String message, Throwable ex) {
DialogUtils.ErrorContext errorContext = null;
if (requester instanceof DocumentWindowManager) {
DocumentWindowManager dwm = (DocumentWindowManager) requester;
VCDocument doc = dwm.getVCDocument();
String contextString = doc.getName();
Version v = doc.getVersion();
if (v != null) {
contextString += " " + v.identificationString();
}
errorContext = new DialogUtils.ErrorContext(contextString, requester.getUserPreferences());
}
showErrorDialog(requester.getComponent(), message, ex, errorContext);
}
use of org.vcell.util.document.VCDocument in project vcell by virtualcell.
the class IssueTableModel method getComparator.
@Override
protected Comparator<Issue> getComparator(final int col, final boolean ascending) {
return new Comparator<Issue>() {
public int compare(Issue o1, Issue o2) {
VCDocument vcDocument = (issueManager != null) ? (issueManager.getVCDocument()) : null;
int scale = ascending ? 1 : -1;
switch(col) {
case COLUMN_DESCRIPTION:
{
Severity s1 = o1.getSeverity();
Severity s2 = o2.getSeverity();
if (s1 == s2) {
return scale * o1.getMessage().compareTo(o2.getMessage());
} else {
return scale * s1.compareTo(s2);
}
}
case COLUMN_URL:
{
String u1 = o1.getHyperlink();
String u2 = o2.getHyperlink();
return u1 != null ? u1.compareTo(u2) : -1;
}
case COLUMN_SOURCE:
return scale * getSourceObjectDescription(vcDocument, o1).compareTo(getSourceObjectDescription(vcDocument, o2));
case COLUMN_PATH:
return scale * getSourceObjectPathDescription(vcDocument, o1).compareTo(getSourceObjectPathDescription(vcDocument, o2));
}
return 0;
}
};
}
Aggregations