Search in sources :

Example 1 with RunSims

use of cbit.vcell.client.task.RunSims 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);
}
Also used : DocumentValidTask(cbit.vcell.client.task.DocumentValidTask) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCDocument(org.vcell.util.document.VCDocument) FinishSave(cbit.vcell.client.task.FinishSave) DeleteOldDocument(cbit.vcell.client.task.DeleteOldDocument) Hashtable(java.util.Hashtable) UserCancelException(org.vcell.util.UserCancelException) SetMathDescription(cbit.vcell.client.task.SetMathDescription) SaveDocument(cbit.vcell.client.task.SaveDocument) JFrame(javax.swing.JFrame) CheckUnchanged(cbit.vcell.client.task.CheckUnchanged) BioModel(cbit.vcell.biomodel.BioModel) CSGObject(cbit.vcell.geometry.CSGObject) NewName(cbit.vcell.client.task.NewName) RunSims(cbit.vcell.client.task.RunSims) CheckBeforeDelete(cbit.vcell.client.task.CheckBeforeDelete)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 CheckBeforeDelete (cbit.vcell.client.task.CheckBeforeDelete)1 CheckUnchanged (cbit.vcell.client.task.CheckUnchanged)1 DeleteOldDocument (cbit.vcell.client.task.DeleteOldDocument)1 DocumentValidTask (cbit.vcell.client.task.DocumentValidTask)1 FinishSave (cbit.vcell.client.task.FinishSave)1 NewName (cbit.vcell.client.task.NewName)1 RunSims (cbit.vcell.client.task.RunSims)1 SaveDocument (cbit.vcell.client.task.SaveDocument)1 SetMathDescription (cbit.vcell.client.task.SetMathDescription)1 CSGObject (cbit.vcell.geometry.CSGObject)1 Hashtable (java.util.Hashtable)1 JFrame (javax.swing.JFrame)1 UserCancelException (org.vcell.util.UserCancelException)1 VCDocument (org.vcell.util.document.VCDocument)1