Search in sources :

Example 1 with LocalState

use of cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState 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;
}
Also used : User(org.vcell.util.document.User) DataViewerController(cbit.vcell.client.data.DataViewerController) SimulationMessage(cbit.vcell.solver.server.SimulationMessage) Enumeration(java.util.Enumeration) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) EventObject(java.util.EventObject) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) Vector(java.util.Vector) DataViewer(cbit.vcell.client.data.DataViewer) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) SmoldynSolver(org.vcell.solver.smoldyn.SmoldynSolver) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) SimulationContext(cbit.vcell.mapping.SimulationContext) PrintWriter(java.io.PrintWriter) VisitSupport(cbit.vcell.resource.VisitSupport) Simulation(cbit.vcell.solver.Simulation) NetworkGenerationRequirements(cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements) VCDataManager(cbit.vcell.simdata.VCDataManager) BeanUtils(org.vcell.util.BeanUtils) Solver(cbit.vcell.solver.server.Solver) Collection(java.util.Collection) SimulationWorkspace(cbit.vcell.client.desktop.simulation.SimulationWorkspace) SolverListener(cbit.vcell.solver.server.SolverListener) VtkManager(cbit.vcell.simdata.VtkManager) SolverEvent(cbit.vcell.solver.server.SolverEvent) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) Dimension(java.awt.Dimension) SimulationJob(cbit.vcell.solver.SimulationJob) ClientTaskDispatcher(cbit.vcell.client.task.ClientTaskDispatcher) VCellConfiguration(cbit.vcell.resource.VCellConfiguration) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) SimulationOwner(cbit.vcell.solver.SimulationOwner) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) VCellClientDataServiceImpl(cbit.vcell.client.data.VCellClientDataServiceImpl) OutputContext(cbit.vcell.simdata.OutputContext) SimulationTask(cbit.vcell.messaging.server.SimulationTask) VCDocument(org.vcell.util.document.VCDocument) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) TempSimulation(cbit.vcell.solver.TempSimulation) ArrayList(java.util.ArrayList) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) SolverFactory(cbit.vcell.solver.server.SolverFactory) SolverStatus(cbit.vcell.solver.server.SolverStatus) SimDataConstants(cbit.vcell.simdata.SimDataConstants) SolverException(cbit.vcell.solver.SolverException) Hashtable(java.util.Hashtable) SimulationStatusDetailsPanel(cbit.vcell.client.desktop.simulation.SimulationStatusDetailsPanel) SimulationStatus(cbit.vcell.server.SimulationStatus) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) PDEDataManager(cbit.vcell.simdata.PDEDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ResourceUtil(cbit.vcell.resource.ResourceUtil) ODEDataManager(cbit.vcell.simdata.ODEDataManager) SmoldynFileWriter(org.vcell.solver.smoldyn.SmoldynFileWriter) IOException(java.io.IOException) PropertyLoader(cbit.vcell.resource.PropertyLoader) InputStreamReader(java.io.InputStreamReader) File(java.io.File) SolverUtilities(cbit.vcell.solver.SolverUtilities) TokenMangler(org.vcell.util.TokenMangler) SolverDescription(cbit.vcell.solver.SolverDescription) DialogUtils(org.vcell.util.gui.DialogUtils) SimulationStatusDetails(cbit.vcell.client.desktop.simulation.SimulationStatusDetails) ProgressDialogListener(org.vcell.util.ProgressDialogListener) DataManager(cbit.vcell.simdata.DataManager) InputStream(java.io.InputStream) UserCancelException(org.vcell.util.UserCancelException) LocalState(cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) ArrayList(java.util.ArrayList) SimulationDataSetRef(cbit.vcell.client.pyvcellproxy.SimulationDataSetRef) AsynchClientTaskFunction(cbit.vcell.client.task.AsynchClientTaskFunction) DataViewerController(cbit.vcell.client.data.DataViewerController) DataViewer(cbit.vcell.client.data.DataViewer) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) VCDataManager(cbit.vcell.simdata.VCDataManager) SimulationWorkspaceModelInfo(cbit.vcell.client.data.SimulationWorkspaceModelInfo) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) VCDataManager(cbit.vcell.simdata.VCDataManager) PDEDataManager(cbit.vcell.simdata.PDEDataManager) ODEDataManager(cbit.vcell.simdata.ODEDataManager) DataManager(cbit.vcell.simdata.DataManager) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VtkManager(cbit.vcell.simdata.VtkManager) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) OutputContext(cbit.vcell.simdata.OutputContext) Simulation(cbit.vcell.solver.Simulation) TempSimulation(cbit.vcell.solver.TempSimulation) PDEDataManager(cbit.vcell.simdata.PDEDataManager) SimulationWindow(cbit.vcell.client.desktop.simulation.SimulationWindow) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ODEDataManager(cbit.vcell.simdata.ODEDataManager) File(java.io.File)

Aggregations

ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 DataViewer (cbit.vcell.client.data.DataViewer)1 DataViewerController (cbit.vcell.client.data.DataViewerController)1 SimulationWorkspaceModelInfo (cbit.vcell.client.data.SimulationWorkspaceModelInfo)1 VCellClientDataServiceImpl (cbit.vcell.client.data.VCellClientDataServiceImpl)1 SimulationStatusDetails (cbit.vcell.client.desktop.simulation.SimulationStatusDetails)1 SimulationStatusDetailsPanel (cbit.vcell.client.desktop.simulation.SimulationStatusDetailsPanel)1 SimulationWindow (cbit.vcell.client.desktop.simulation.SimulationWindow)1 LocalState (cbit.vcell.client.desktop.simulation.SimulationWindow.LocalState)1 SimulationWorkspace (cbit.vcell.client.desktop.simulation.SimulationWorkspace)1 SimulationDataSetRef (cbit.vcell.client.pyvcellproxy.SimulationDataSetRef)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 AsynchClientTaskFunction (cbit.vcell.client.task.AsynchClientTaskFunction)1 ClientTaskDispatcher (cbit.vcell.client.task.ClientTaskDispatcher)1 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)1 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 NetworkGenerationRequirements (cbit.vcell.mapping.SimulationContext.NetworkGenerationRequirements)1 SimulationTask (cbit.vcell.messaging.server.SimulationTask)1 PropertyLoader (cbit.vcell.resource.PropertyLoader)1