Search in sources :

Example 11 with DocumentWindowManager

use of cbit.vcell.client.DocumentWindowManager in project vcell by virtualcell.

the class DocumentToExport method run.

/**
 * Insert the method's description here. Creation date: (5/31/2004 6:04:14
 * PM)
 *
 * @param hashTable
 *            java.util.Hashtable
 * @param clientWorker
 *            cbit.vcell.desktop.controls.ClientWorker
 */
@Override
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    TopLevelWindowManager topLevelWindowManager = extractRequired(hashTable, TopLevelWindowManager.class, "topLevelWindowManager");
    VCDocument doc = null;
    if (topLevelWindowManager instanceof DocumentWindowManager) {
        doc = ((DocumentWindowManager) topLevelWindowManager).getVCDocument();
    } else if (topLevelWindowManager instanceof DatabaseWindowManager) {
        DocumentManager documentManager = extractRequired(hashTable, DocumentManager.class, CommonTask.DOCUMENT_MANAGER.name);
        VCDocumentInfo documentInfo = ((DatabaseWindowManager) topLevelWindowManager).getPanelSelection();
        if (documentInfo instanceof BioModelInfo) {
            BioModelInfo bmi = (BioModelInfo) documentInfo;
            doc = documentManager.getBioModel(bmi);
        } else if (documentInfo instanceof MathModelInfo) {
            MathModelInfo mmi = (MathModelInfo) documentInfo;
            doc = documentManager.getMathModel(mmi);
        } else if (documentInfo instanceof GeometryInfo) {
            GeometryInfo gmi = (GeometryInfo) documentInfo;
            doc = documentManager.getGeometry(gmi);
        }
        if (doc == null) {
            throw new IllegalStateException("export called on DatabaseWindowManager with selection " + documentInfo);
        }
    }
    if (doc != null) {
        hashTable.put(EXPORT_DOCUMENT, doc);
    } else {
        throw new UnsupportedOperationException("TopLevelWindowManager subclass " + topLevelWindowManager.getClass().getName() + " does not support exporting to document");
    }
}
Also used : VCDocument(org.vcell.util.document.VCDocument) TopLevelWindowManager(cbit.vcell.client.TopLevelWindowManager) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) VCDocumentInfo(org.vcell.util.document.VCDocumentInfo) DocumentManager(cbit.vcell.clientdb.DocumentManager) BioModelInfo(org.vcell.util.document.BioModelInfo) GeometryInfo(cbit.vcell.geometry.GeometryInfo) MathModelInfo(org.vcell.util.document.MathModelInfo) DatabaseWindowManager(cbit.vcell.client.DatabaseWindowManager)

Example 12 with DocumentWindowManager

use of cbit.vcell.client.DocumentWindowManager in project vcell by virtualcell.

the class FinishSave method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    MDIManager mdiManager = (MDIManager) hashTable.get("mdiManager");
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
        VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
        documentWindowManager.resetDocument(savedDocument);
    }
    mdiManager.unBlockWindow(documentWindowManager.getManagerID());
    mdiManager.showWindow(documentWindowManager.getManagerID());
}
Also used : MDIManager(cbit.vcell.client.MDIManager) VCDocument(org.vcell.util.document.VCDocument) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager)

Example 13 with DocumentWindowManager

use of cbit.vcell.client.DocumentWindowManager in project vcell by virtualcell.

the class RunSims method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    ClientSimManager clientSimManager = (ClientSimManager) hashTable.get("clientSimManager");
    // DocumentManager documentManager = (DocumentManager)hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
    JobManager jobManager = (JobManager) hashTable.get("jobManager");
    Simulation[] simulations = (Simulation[]) hashTable.get("simulations");
    Hashtable<Simulation, Throwable> failures = new Hashtable<Simulation, Throwable>();
    if (simulations != null && simulations.length > 0) {
        // we need to get the new ones if a save occurred...
        if (hashTable.containsKey(SaveDocument.DOC_KEY)) {
            VCDocument savedDocument = (VCDocument) hashTable.get(SaveDocument.DOC_KEY);
            Simulation[] allSims = null;
            if (savedDocument instanceof BioModel) {
                allSims = ((BioModel) savedDocument).getSimulations();
            } else if (savedDocument instanceof MathModel) {
                allSims = ((MathModel) savedDocument).getSimulations();
            }
            Vector<Simulation> v = new Vector<Simulation>();
            for (int i = 0; i < simulations.length; i++) {
                for (int j = 0; j < allSims.length; j++) {
                    if (simulations[i].getName().equals(allSims[j].getName())) {
                        v.add(allSims[j]);
                        break;
                    }
                }
            }
            simulations = (Simulation[]) BeanUtils.getArray(v, Simulation.class);
        }
        for (Simulation sim : simulations) {
            try {
                int dimension = sim.getMathDescription().getGeometry().getDimension();
                if (clientSimManager.getSimulationStatus(sim).isCompleted()) {
                    // completed
                    String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_1, sim.getName());
                    String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                    if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                        continue;
                    }
                }
                DataProcessingInstructions dataProcessingInstructions = sim.getDataProcessingInstructions();
                try {
                    if (dataProcessingInstructions != null) {
                        dataProcessingInstructions.getSampleImageFieldData(sim.getVersion().getOwner());
                    }
                } catch (Exception ex) {
                    DialogUtils.showErrorDialog(documentWindowManager.getComponent(), "Problem found in simulation '" + sim.getName() + "':\n" + ex.getMessage());
                    continue;
                }
                if (dimension > 0) {
                    MeshSpecification meshSpecification = sim.getMeshSpecification();
                    boolean bCellCentered = sim.hasCellCenteredMesh();
                    if (meshSpecification != null && !meshSpecification.isAspectRatioOK(bCellCentered)) {
                        String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_2, sim.getName(), "\u0394x=" + meshSpecification.getDx(bCellCentered) + "\n" + "\u0394y=" + meshSpecification.getDy(bCellCentered) + (dimension < 3 ? "" : "\n\u0394z=" + meshSpecification.getDz(bCellCentered)));
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                    if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.Smoldyn)) {
                        if (!isSmoldynTimeStepOK(sim)) {
                            double s = smoldynTimestepVars.getSpatialResolution();
                            double dMax = smoldynTimestepVars.getMaxDiffusion();
                            double condn = (s * s) / (2.0 * dMax);
                            String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_3, Double.toString(s), Double.toString(dMax), Double.toString(condn));
                            DialogUtils.showErrorDialog(documentWindowManager.getComponent(), warningMessage);
                            continue;
                        }
                    }
                    // check the number of regions if the simulation mesh is coarser.
                    Geometry mathGeometry = sim.getMathDescription().getGeometry();
                    ISize newSize = meshSpecification.getSamplingSize();
                    ISize defaultSize = mathGeometry.getGeometrySpec().getDefaultSampledImageSize();
                    if (!sim.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
                        int defaultTotalVolumeElements = mathGeometry.getGeometrySurfaceDescription().getVolumeSampleSize().getXYZ();
                        int newTotalVolumeElements = meshSpecification.getSamplingSize().getXYZ();
                        if (defaultTotalVolumeElements > newTotalVolumeElements) {
                            // coarser
                            Geometry resampledGeometry = (Geometry) BeanUtils.cloneSerializable(mathGeometry);
                            GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
                            geoSurfaceDesc.setVolumeSampleSize(newSize);
                            geoSurfaceDesc.updateAll();
                            if (mathGeometry.getGeometrySurfaceDescription().getGeometricRegions() == null) {
                                mathGeometry.getGeometrySurfaceDescription().updateAll();
                            }
                            int defaultNumGeometricRegions = mathGeometry.getGeometrySurfaceDescription().getGeometricRegions().length;
                            int numGeometricRegions = geoSurfaceDesc.getGeometricRegions().length;
                            if (numGeometricRegions != defaultNumGeometricRegions) {
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_4, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), numGeometricRegions, defaultNumGeometricRegions);
                                String result = PopupGenerator.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                        if (mathGeometry.getGeometrySpec().hasImage()) {
                            // if it's an image.
                            if (defaultSize.getX() + 1 < newSize.getX() || defaultSize.getY() + 1 < newSize.getY() || defaultSize.getZ() + 1 < newSize.getZ()) {
                                // finer
                                String defaultSizeString = (defaultSize.getX() + 1) + (dimension > 1 ? " x " + (defaultSize.getY() + 1) : "") + (dimension > 2 ? " x " + (defaultSize.getZ() + 1) : "");
                                String warningMessage = VCellErrorMessages.getErrorMessage(VCellErrorMessages.RunSims_5, newSize.getX() + (dimension > 1 ? " x " + newSize.getY() : "") + (dimension > 2 ? " x " + newSize.getZ() : ""), sim.getName(), defaultSizeString, defaultSizeString);
                                String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                                if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                                    continue;
                                }
                            }
                        }
                    }
                    boolean bGiveWarning = false;
                    for (int i = 0; i < sim.getScanCount(); i++) {
                        if (sim.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
                            SimulationJob simJob = new SimulationJob(sim, i, null);
                            if (simJob.getSimulationSymbolTable().hasTimeVaryingDiffusionOrAdvection()) {
                                bGiveWarning = true;
                                break;
                            }
                        }
                    }
                    if (bGiveWarning) {
                        String warningMessage = VCellErrorMessages.RunSims_6;
                        String result = DialogUtils.showWarningDialog(documentWindowManager.getComponent(), warningMessage, new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
                        if (result == null || !result.equals(UserMessage.OPTION_OK)) {
                            continue;
                        }
                    }
                }
                SimulationInfo simInfo = sim.getSimulationInfo();
                if (simInfo != null) {
                    // 
                    // translate to common ancestral simulation (oldest mathematically equivalent simulation)
                    // 
                    SimulationStatus simulationStatus = jobManager.startSimulation(simInfo.getAuthoritativeVCSimulationIdentifier(), sim.getScanCount());
                    // updateStatus
                    clientSimManager.updateStatusFromStartRequest(sim, simulationStatus);
                } else {
                    // this should really not happen...
                    throw new RuntimeException(">>>>>>>>>> trying to run an unsaved simulation...");
                }
            } catch (Throwable exc) {
                exc.printStackTrace(System.out);
                failures.put(sim, exc);
            }
        }
    }
    // we deal with individual request failures here, passing down only other things (that break the whole thing down) to dispatcher
    if (!failures.isEmpty()) {
        Enumeration<Simulation> en = failures.keys();
        while (en.hasMoreElements()) {
            Simulation sim = en.nextElement();
            Throwable exc = (Throwable) failures.get(sim);
            // // updateStatus
            // SimulationStatus simulationStatus = clientSimManager.updateStatusFromStartRequest(sim, true, exc.getMessage());
            // notify user
            PopupGenerator.showErrorDialog(documentWindowManager, "Failed to start simulation'" + sim.getName() + "'\n" + exc.getMessage());
        }
    }
}
Also used : ClientSimManager(cbit.vcell.client.ClientSimManager) MathModel(cbit.vcell.mathmodel.MathModel) GeometrySurfaceDescription(cbit.vcell.geometry.surface.GeometrySurfaceDescription) ISize(org.vcell.util.ISize) JobManager(cbit.vcell.client.server.JobManager) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) DataProcessingInstructions(cbit.vcell.solver.DataProcessingInstructions) Vector(java.util.Vector) SimulationJob(cbit.vcell.solver.SimulationJob) VCDocument(org.vcell.util.document.VCDocument) Hashtable(java.util.Hashtable) ExpressionException(cbit.vcell.parser.ExpressionException) UserCancelException(org.vcell.util.UserCancelException) MeshSpecification(cbit.vcell.solver.MeshSpecification) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) SimulationStatus(cbit.vcell.server.SimulationStatus) BioModel(cbit.vcell.biomodel.BioModel) SimulationInfo(cbit.vcell.solver.SimulationInfo)

Example 14 with DocumentWindowManager

use of cbit.vcell.client.DocumentWindowManager in project vcell by virtualcell.

the class SaveDocument method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    long l1 = System.currentTimeMillis();
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    VCDocument currentDocument = documentWindowManager.getVCDocument();
    DocumentManager documentManager = (DocumentManager) hashTable.get(CommonTask.DOCUMENT_MANAGER.name);
    RequestManager requestManager = (RequestManager) hashTable.get("requestManager");
    boolean bAsNew = hashTable.containsKey("newName");
    String newName = bAsNew ? (String) hashTable.get("newName") : null;
    Simulation[] simulationsToRun = (Simulation[]) hashTable.get("simulations");
    String[] independentSims = null;
    if (simulationsToRun != null && simulationsToRun.length > 0) {
        independentSims = new String[simulationsToRun.length];
        for (int i = 0; i < simulationsToRun.length; i++) {
            independentSims[i] = simulationsToRun[i].getName();
        }
    }
    VCDocument savedDocument = null;
    switch(currentDocument.getDocumentType()) {
        case BIOMODEL_DOC:
            {
                if (bAsNew) {
                    // Substitute Field Func Names-----
                    VersionableTypeVersion originalVersionableTypeVersion = null;
                    if (currentDocument.getVersion() != null) {
                        // From Opened...
                        originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.BioModelMetaData, currentDocument.getVersion());
                    }
                    documentManager.substituteFieldFuncNames((BioModel) currentDocument, originalVersionableTypeVersion);
                    // --------------------------------
                    savedDocument = documentManager.saveAsNew((BioModel) currentDocument, newName, independentSims);
                } else {
                    savedDocument = documentManager.save((BioModel) currentDocument, independentSims);
                }
                break;
            }
        case MATHMODEL_DOC:
            {
                if (bAsNew) {
                    // Substitute Field Func Names-----
                    VersionableTypeVersion originalVersionableTypeVersion = ((MathModelWindowManager) documentWindowManager).getCopyFromBioModelAppVersionableTypeVersion();
                    if (originalVersionableTypeVersion == null && currentDocument.getVersion() != null) {
                        // From Opened...
                        originalVersionableTypeVersion = new VersionableTypeVersion(VersionableType.MathModelMetaData, currentDocument.getVersion());
                    }
                    documentManager.substituteFieldFuncNames((MathModel) currentDocument, originalVersionableTypeVersion);
                    // --------------------------------
                    savedDocument = documentManager.saveAsNew((MathModel) currentDocument, newName, independentSims);
                } else {
                    savedDocument = documentManager.save((MathModel) currentDocument, independentSims);
                }
                break;
            }
        case GEOMETRY_DOC:
            {
                if (bAsNew) {
                    savedDocument = documentManager.saveAsNew((Geometry) currentDocument, newName);
                } else {
                    savedDocument = documentManager.save((Geometry) currentDocument);
                }
                break;
            }
        default:
            {
                throw new RuntimeException("unexpected document type " + currentDocument.getDocumentType().name());
            }
    }
    documentWindowManager.prepareDocumentToLoad(savedDocument, false);
    hashTable.put(SaveDocument.DOC_KEY, savedDocument);
    // generate PerformanceMonitorEvent
    long l2 = System.currentTimeMillis();
    double duration = ((double) (l2 - l1)) / 1000;
// requestManager.getAsynchMessageManager().reportPerformanceMonitorEvent(
// new PerformanceMonitorEvent(
// this, documentManager.getUser(), new PerformanceData(
// "SaveDocument.run()",
// MessageEvent.SAVING_STAT,
// new PerformanceDataEntry[] {
// new PerformanceDataEntry("document saved", savedDocument.getName()),
// new PerformanceDataEntry("remote call duration", Double.toString(duration))
// }
// )
// )
// );
}
Also used : MathModel(cbit.vcell.mathmodel.MathModel) VCDocument(org.vcell.util.document.VCDocument) VersionableTypeVersion(org.vcell.util.document.VersionableTypeVersion) DocumentManager(cbit.vcell.clientdb.DocumentManager) RequestManager(cbit.vcell.client.RequestManager) Simulation(cbit.vcell.solver.Simulation) DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) BioModel(cbit.vcell.biomodel.BioModel)

Example 15 with DocumentWindowManager

use of cbit.vcell.client.DocumentWindowManager in project vcell by virtualcell.

the class SetMathDescription method run.

/**
 * Insert the method's description here.
 * Creation date: (5/31/2004 6:04:14 PM)
 * @param hashTable java.util.Hashtable
 * @param clientWorker cbit.vcell.desktop.controls.ClientWorker
 */
public void run(Hashtable<String, Object> hashTable) throws java.lang.Exception {
    DocumentWindowManager documentWindowManager = (DocumentWindowManager) hashTable.get(CommonTask.DOCUMENT_WINDOW_MANAGER.name);
    if (documentWindowManager.getVCDocument() instanceof BioModel) {
        // try to successfully generate math and geometry region info
        BioModel bioModel = (BioModel) documentWindowManager.getVCDocument();
        SimulationContext[] scArray = bioModel.getSimulationContexts();
        MathDescription[] mathDescArray = (MathDescription[]) hashTable.get("mathDescArray");
        if (scArray != null && mathDescArray != null) {
            for (int i = 0; i < scArray.length; i++) {
                scArray[i].setMathDescription(mathDescArray[i]);
            }
        }
    }
}
Also used : DocumentWindowManager(cbit.vcell.client.DocumentWindowManager) MathDescription(cbit.vcell.math.MathDescription) BioModel(cbit.vcell.biomodel.BioModel) SimulationContext(cbit.vcell.mapping.SimulationContext)

Aggregations

DocumentWindowManager (cbit.vcell.client.DocumentWindowManager)15 VCDocument (org.vcell.util.document.VCDocument)9 BioModel (cbit.vcell.biomodel.BioModel)6 DocumentManager (cbit.vcell.clientdb.DocumentManager)6 MathModel (cbit.vcell.mathmodel.MathModel)4 Simulation (cbit.vcell.solver.Simulation)4 SimulationContext (cbit.vcell.mapping.SimulationContext)3 VCDocumentInfo (org.vcell.util.document.VCDocumentInfo)3 MDIManager (cbit.vcell.client.MDIManager)2 MathModelWindowManager (cbit.vcell.client.MathModelWindowManager)2 Geometry (cbit.vcell.geometry.Geometry)2 GeometryInfo (cbit.vcell.geometry.GeometryInfo)2 MathDescription (cbit.vcell.math.MathDescription)2 Component (java.awt.Component)2 Hashtable (java.util.Hashtable)2 BioModelInfo (org.vcell.util.document.BioModelInfo)2 MathModelInfo (org.vcell.util.document.MathModelInfo)2 Version (org.vcell.util.document.Version)2 ClientSimManager (cbit.vcell.client.ClientSimManager)1 DatabaseWindowManager (cbit.vcell.client.DatabaseWindowManager)1