Search in sources :

Example 1 with PdeTimePlotMultipleVariablesPanel

use of cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel in project vcell by virtualcell.

the class PDEDataViewer method showTimePlot.

// private static final String PROPERTY_PDEDC = "pdedc";
/**
 * Comment
 */
private void showTimePlot() {
    VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
    // Collect all sample curves created by user
    SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(true, true);
    SpatialSelection[] spatialSelectionArr2 = null;
    if (varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME) || varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_POSTPROCESSING)) {
        spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType, true, true);
    } else {
        spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType.equals(VariableType.MEMBRANE) ? VariableType.MEMBRANE_REGION : VariableType.MEMBRANE, true, true);
    }
    final Vector<SpatialSelection> singlePointSSOnly = new Vector<SpatialSelection>();
    final Vector<SpatialSelection> singlePointSSOnly2 = new Vector<SpatialSelection>();
    if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
        for (int i = 0; i < spatialSelectionArr.length; i++) {
            if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof SinglePoint)) {
                singlePointSSOnly.add(spatialSelectionArr[i]);
            }
            if (spatialSelectionArr2[i].isPoint() || (spatialSelectionArr2[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr2[i]).getSelectionSource() instanceof SinglePoint)) {
                singlePointSSOnly2.add(spatialSelectionArr2[i]);
            }
        }
    }
    final String varName = getPdeDataContext().getVariableName();
    if (singlePointSSOnly.size() == 0) {
        PopupGenerator.showErrorDialog(this, "No Time sampling points match DataType=" + varType);
        return;
    }
    try {
        int[] indices = null;
        // 
        indices = new int[singlePointSSOnly.size()];
        for (int i = 0; i < singlePointSSOnly.size(); i++) {
            if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
                SpatialSelectionVolume ssv = (SpatialSelectionVolume) singlePointSSOnly.get(i);
                indices[i] = ssv.getIndex(0);
            } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
                SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) singlePointSSOnly.get(i);
                indices[i] = ssm.getIndex(0);
            }
        }
        double[] timePoints = getPdeDataContext().getTimePoints();
        final TimeSeriesJobSpec tsjs = new TimeSeriesJobSpec(new String[] { varName }, new int[][] { indices }, null, timePoints[0], 1, timePoints[timePoints.length - 1], VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
        if (!tsjs.getVcDataJobID().isBackgroundTask()) {
            throw new RuntimeException("Use getTimeSeries(...) if not a background job");
        }
        Hashtable<String, Object> hash = new Hashtable<String, Object>();
        hash.put(StringKey_timeSeriesJobSpec, tsjs);
        AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieving Data for '" + varName + "'...", PDEDataViewer.this, getPdeDataContext());
        AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext(), PDEDataViewer.this.getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
                hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("showing time plot for '" + varName + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                Exception timeSeriesJobFailed = (Exception) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobException);
                if (timeSeriesJobFailed != null) {
                    throw timeSeriesJobFailed;
                }
                TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(StringKey_timeSeriesJobResults);
                // Make independent Plotviewer that is unaffected by changes (time,var,paramscan) in 'this' PDEDataviewer except to pass-thru OutputContext changes
                PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = (PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY);
                try {
                    PdeTimePlotMultipleVariablesPanel pdeTimePlotPanel = new PdeTimePlotMultipleVariablesPanel(multiTimePlotHelper, singlePointSSOnly, singlePointSSOnly2, tsJobResultsNoStats);
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
                    String prefix = "Time Plot (" + getPDEPlotControlPanel1().getPlotVariableJList().getSelectedValue().getVariableType().getTypeName() + ") ";
                    ChildWindow childWindow = childWindowManager.addChildWindow(pdeTimePlotPanel, pdeTimePlotPanel, createContextTitle(PDEDataViewer.this.isPostProcess(), prefix, getPdeDataContext(), getSimulationModelInfo(), getSimulation()));
                    childWindow.getParent().addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            super.windowClosing(e);
                            multiTimePlotHelper.removeallPropertyChangeListeners();
                        }

                        @Override
                        public void windowClosed(WindowEvent e) {
                            super.windowClosed(e);
                            multiTimePlotHelper.removeallPropertyChangeListeners();
                        }
                    });
                    // childWindow.addChildWindowListener(new ChildWindowListener() {
                    // @Override
                    // public void closing(ChildWindow childWindow) {
                    // multiTimePlotHelper.removeallPropertyChangeListeners();
                    // }
                    // @Override
                    // public void closed(ChildWindow childWindow) {
                    // multiTimePlotHelper.removeallPropertyChangeListeners();
                    // }
                    // });
                    childWindow.setSize(900, 550);
                    childWindow.setIsCenteredOnParent();
                    childWindow.show();
                } catch (Exception e) {
                    e.printStackTrace();
                    multiTimePlotHelper.removeallPropertyChangeListeners();
                }
            }
        };
        // ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1,multiTimePlotHelperTask, task2 }, true, true, null);
        ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, multiTimePlotHelperTask, task2 }, null, false, false, true, null, false);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) WindowAdapter(java.awt.event.WindowAdapter) SinglePoint(cbit.vcell.geometry.SinglePoint) PdeTimePlotMultipleVariablesPanel(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel) SpatialSelection(cbit.vcell.simdata.SpatialSelection) Vector(java.util.Vector) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) WindowEvent(java.awt.event.WindowEvent) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Aggregations

ImageException (cbit.image.ImageException)1 ChildWindowManager (cbit.vcell.client.ChildWindowManager)1 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 SinglePoint (cbit.vcell.geometry.SinglePoint)1 VariableType (cbit.vcell.math.VariableType)1 SpatialSelection (cbit.vcell.simdata.SpatialSelection)1 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)1 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)1 PdeTimePlotMultipleVariablesPanel (cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel)1 MultiTimePlotHelper (cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper)1 Point (java.awt.Point)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 PropertyVetoException (java.beans.PropertyVetoException)1 Hashtable (java.util.Hashtable)1 Vector (java.util.Vector)1 DataAccessException (org.vcell.util.DataAccessException)1 UserCancelException (org.vcell.util.UserCancelException)1 TSJobResultsNoStats (org.vcell.util.document.TSJobResultsNoStats)1