Search in sources :

Example 1 with LocalVCDataIdentifier

use of org.vcell.util.document.LocalVCDataIdentifier 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)

Example 2 with LocalVCDataIdentifier

use of org.vcell.util.document.LocalVCDataIdentifier in project vcell by virtualcell.

the class PDEExportDataPanel method startExport.

/**
 * Comment
 */
private void startExport() {
    if (getExportSettings1().getSelectedFormat() == ExportFormat.QUICKTIME && getJSlider1().getValue() == getJSlider2().getValue()) {
        DialogUtils.showWarningDialog(this, "User selected 'begin' and 'end' export times are the same.  'Movie' export format 'begin' and 'end' times must be different");
        return;
    }
    DisplayPreferences[] displayPreferences = null;
    @SuppressWarnings("deprecation") Object[] variableSelections = getJListVariables().getSelectedValues();
    boolean selectionHasVolumeVariables = false;
    boolean selectionHasMembraneVariables = false;
    switch(getExportSettings1().getSelectedFormat()) {
        case PLY:
        case QUICKTIME:
        case GIF:
        case FORMAT_JPEG:
        case ANIMATED_GIF:
            {
                displayPreferences = new DisplayPreferences[variableSelections.length];
                StringBuffer noScaleInfoNames = new StringBuffer();
                for (int i = 0; i < displayPreferences.length; i++) {
                    BitSet domainValid = null;
                    try {
                        if (dataInfoProvider != null) {
                            DataIdentifier varSelectionDataIdnetDataIdentifier = null;
                            for (int j = 0; j < dataInfoProvider.getPDEDataContext().getDataIdentifiers().length; j++) {
                                if (dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j].getName().equals(variableSelections[i])) {
                                    varSelectionDataIdnetDataIdentifier = dataInfoProvider.getPDEDataContext().getDataIdentifiers()[j];
                                }
                            }
                            if (varSelectionDataIdnetDataIdentifier != null) {
                                selectionHasVolumeVariables = selectionHasVolumeVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.POSTPROCESSING) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.VOLUME_REGION);
                                selectionHasMembraneVariables = selectionHasMembraneVariables || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE) || varSelectionDataIdnetDataIdentifier.getVariableType().equals(VariableType.MEMBRANE_REGION);
                                CartesianMesh cartesianMesh = dataInfoProvider.getPDEDataContext().getCartesianMesh();
                                int dataLength = cartesianMesh.getDataLength(varSelectionDataIdnetDataIdentifier.getVariableType());
                                domainValid = new BitSet(dataLength);
                                domainValid.clear();
                                for (int j = 0; j < dataLength; j++) {
                                    if (dataInfoProvider.isDefined(varSelectionDataIdnetDataIdentifier, j)) {
                                        domainValid.set(j);
                                    }
                                }
                            } else {
                                throw new Exception("No DataIdentifer found for variable name '" + variableSelections[i] + "'");
                            }
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                        DialogUtils.showErrorDialog(this, "Error during domain evaluation:\n" + e.getMessage());
                        return;
                    }
                    displayPreferences[i] = new DisplayPreferences(getDisplayAdapterService().getDisplayPreferences((String) variableSelections[i]), domainValid);
                    if (!getDisplayAdapterService().hasStateID((String) variableSelections[i])) {
                        noScaleInfoNames.append("--- " + (String) variableSelections[i] + "\n");
                    }
                }
                break;
            }
        case CSV:
            {
                // check for membrane variables... warn for 3D geometry...
                // one gets the whole nine yards by index, not generally useful... except for a few people like Boris :)
                boolean mbVars = false;
                DataIdentifier[] dataIDs = getPdeDataContext().getDataIdentifiers();
                for (int i = 0; i < variableSelections.length; i++) {
                    String varName = (String) variableSelections[i];
                    for (int j = 0; j < dataIDs.length; j++) {
                        if (dataIDs[j].getName().equals(varName) && dataIDs[j].getVariableType().equals(VariableType.MEMBRANE)) {
                            mbVars = true;
                            break;
                        }
                    }
                }
                if (mbVars && getPdeDataContext().getCartesianMesh().getGeometryDimension() == 3 && getJRadioButtonSlice().isSelected()) {
                    String choice = PopupGenerator.showWarningDialog(this, getDataViewerManager().getUserPreferences(), UserMessage.warn_exportMembraneData3D, null);
                    if (choice.equals(UserMessage.OPTION_CANCEL)) {
                        // user canceled
                        return;
                    }
                }
                getExportSettings1().setSimulationSelector(createSimulationSelector());
                getExportSettings1().setIsCSVExport(true);
                break;
            }
        case NRRD:
        case IMAGEJ:
        case UCD:
        case VTK_IMAGE:
        case VTK_UNSTRUCT:
            break;
        default:
            break;
    }
    ;
    if (getJRadioButtonROI().isSelected() && getROISelections().getSelectedIndex() == -1) {
        PopupGenerator.showErrorDialog(this, "To export selections, you must select at least one item from the ROI selection list");
    }
    getExportSettings1().setTimeSpecs(new TimeSpecs(getJSlider1().getValue(), getJSlider2().getValue(), getPdeDataContext().getTimePoints(), ExportConstants.TIME_RANGE));
    getExportSettings1().setDisplayPreferences(displayPreferences, Arrays.asList(variableSelections).toArray(new String[0]), viewZoom);
    getExportSettings1().setSliceCount(FormatSpecificSpecs.getSliceCount(getJRadioButtonFull().isSelected(), getNormalAxis(), getPdeDataContext().getCartesianMesh()));
    getExportSettings1().setImageSizeCalculationInfo(getPdeDataContext().getCartesianMesh(), getNormalAxis());
    getExportSettings1().setIsSmoldyn(isSmoldyn);
    ExportFormat format = getSelectedFormat();
    if (format.equals(ExportFormat.PLY)) {
        getExportSettings1().setFormatSpecificSpecs(new PLYSpecs(true, displayPreferences));
    }
    if (format.requiresFollowOn()) {
        Frame theFrame = JOptionPane.getFrameForComponent(this);
        boolean okToExport = getExportSettings1().showFormatSpecificDialog(theFrame, selectionHasVolumeVariables, selectionHasMembraneVariables);
        if (!okToExport) {
            return;
        }
    }
    if (format.equals(ExportFormat.IMAGEJ)) {
        // export nrrd for imagej direct, the we'll send to imagej from vcell client
        getExportSettings1().setFormatSpecificSpecs(new RasterSpecs(ExportConstants.NRRD_SINGLE, false));
    }
    // determine of sim result is from local (quick) run or on server.
    final OutputContext outputContext = ((ClientPDEDataContext) getPdeDataContext()).getDataManager().getOutputContext();
    final ExportSpecs exportSpecs = getExportSpecs();
    boolean isLocalSimResult = false;
    VCDataIdentifier vcId = exportSpecs.getVCDataIdentifier();
    if (vcId instanceof LocalVCDataIdentifier) {
        isLocalSimResult = true;
    }
    // find out if smoldyn export choice is 'particle' - not available at this time
    boolean isParticle = false;
    if (getExportSettings1().getFormatSpecificSpecs() instanceof ImageSpecs) {
        isParticle = ((ImageSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    } else if (getExportSettings1().getFormatSpecificSpecs() instanceof MovieSpecs) {
        isParticle = ((MovieSpecs) getExportSettings1().getFormatSpecificSpecs()).getParticleMode() == FormatSpecificSpecs.PARTICLE_SELECT;
    }
    if (isLocalSimResult && isParticle) {
        DialogUtils.showErrorDialog(this, "Particle export for Smoldyn particles unavailable in local data at this time.");
        return;
    }
    // pass the export request down the line; non-blocking call
    if (!isLocalSimResult) {
        // for sims that ran on server, do as before.
        getDataViewerManager().startExport(this, outputContext, exportSpecs);
    } else {
        final String SOURCE_FILE_KEY = "SOURCE_FILE_KEY";
        final String DESTINATION_FILE_KEY = "DEESTINATION_FILE_KEY";
        AsynchClientTask localExportTast = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                try {
                    File primaryDir = ResourceUtil.getLocalRootDir();
                    User usr = User.tempUser;
                    File usrDir = new File(primaryDir.getAbsolutePath(), usr.getName());
                    System.setProperty(PropertyLoader.exportBaseDirInternalProperty, usrDir.getAbsolutePath() + File.separator);
                    System.setProperty(PropertyLoader.exportBaseURLProperty, usrDir.toURI().toURL().toString());
                    DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
                    ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
                    DataServerImpl dataServerImpl = new DataServerImpl(dataSetControllerImpl, localExportServiceImpl);
                    ExportEvent localExportEvent = dataServerImpl.makeRemoteFile(outputContext, usr, exportSpecs);
                    File sourceFile = new File(usrDir, new File((new URL(localExportEvent.getLocation()).getPath())).getName());
                    hashTable.put(SOURCE_FILE_KEY, sourceFile);
                } catch (Exception e) {
                    throw new Exception("Unable to export local sim results data : " + e.getMessage(), e);
                }
            }
        };
        AsynchClientTask localSaveTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                JFileChooser jFileChooser = new JFileChooser();
                jFileChooser.setSelectedFile(new File(sourceFile.getName()));
                if (jFileChooser.showSaveDialog(PDEExportDataPanel.this) == JFileChooser.APPROVE_OPTION) {
                    File destinationFile = jFileChooser.getSelectedFile();
                    if (destinationFile.exists()) {
                        final String OVERWRITE = "Overwrite";
                        final String CANCEL = "Cancel";
                        String response = DialogUtils.showWarningDialog(PDEExportDataPanel.this, "OK to Overwrite " + destinationFile.getAbsolutePath() + "?", new String[] { OVERWRITE, CANCEL }, OVERWRITE);
                        if (response == null || !response.equals(OVERWRITE)) {
                            return;
                        }
                    }
                    hashTable.put(DESTINATION_FILE_KEY, destinationFile);
                }
            }
        };
        AsynchClientTask localDeleteTempTask = new AsynchClientTask("Start Local Export", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING, false, false) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                File sourceFile = (File) hashTable.get(SOURCE_FILE_KEY);
                File destinationFile = (File) hashTable.get(DESTINATION_FILE_KEY);
                if (sourceFile != null && sourceFile.exists()) {
                    try {
                        if (destinationFile != null) {
                            copyFile(sourceFile, destinationFile);
                        }
                    } finally {
                        sourceFile.delete();
                    }
                }
            }
        };
        ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { localExportTast, localSaveTask, localDeleteTempTask }, false, true, null);
    }
}
Also used : DataServerImpl(cbit.vcell.simdata.DataServerImpl) JFrame(javax.swing.JFrame) Frame(java.awt.Frame) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) RasterSpecs(cbit.vcell.export.server.RasterSpecs) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ExportEvent(cbit.rmi.event.ExportEvent) URL(java.net.URL) DisplayPreferences(cbit.image.DisplayPreferences) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) TimeSpecs(cbit.vcell.export.server.TimeSpecs) Hashtable(java.util.Hashtable) PLYSpecs(cbit.vcell.export.server.PLYSpecs) BitSet(java.util.BitSet) ExportFormat(cbit.vcell.export.server.ExportFormat) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) MovieSpecs(cbit.vcell.export.server.MovieSpecs) JFileChooser(javax.swing.JFileChooser) ImageSpecs(cbit.vcell.export.server.ImageSpecs) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) LocalVCDataIdentifier(org.vcell.util.document.LocalVCDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Aggregations

AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)2 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)2 OutputContext (cbit.vcell.simdata.OutputContext)2 DisplayPreferences (cbit.image.DisplayPreferences)1 ExportEvent (cbit.rmi.event.ExportEvent)1 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 AsynchClientTaskFunction (cbit.vcell.client.task.AsynchClientTaskFunction)1 ClientTaskDispatcher (cbit.vcell.client.task.ClientTaskDispatcher)1 ExportFormat (cbit.vcell.export.server.ExportFormat)1