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;
}
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);
}
}
Aggregations