Search in sources :

Example 1 with UnitInfo

use of cbit.vcell.solver.SimulationOwner.UnitInfo in project vcell by virtualcell.

the class SimulationEditor method prepareToEdit.

/**
 * Comment
 * @param simulation not null
 * @param parent
 * @throws ChomboInvalidGeometryException
 * @throws NullPointerException
 */
public void prepareToEdit(Simulation simulation, Component parent) throws ChomboInvalidGeometryException {
    Objects.requireNonNull(simulation);
    try {
        Simulation clonedSimulation = (Simulation) BeanUtils.cloneSerializable(simulation);
        clonedSimulation.refreshDependencies();
        getMathOverridesPanel1().setMathOverrides(clonedSimulation == null ? null : clonedSimulation.getMathOverrides());
        getMeshTabPanel().setSimulation(parent, clonedSimulation);
        SolverTaskDescriptionAdvancedPanel stdap = getSolverTaskDescriptionAdvancedPanel1();
        {
            SimulationOwner so = simulation.getSimulationOwner();
            UnitInfo unitInfo = so.getUnitInfo();
            stdap.setUnitInfo(unitInfo);
        }
        stdap.setSolverTaskDescription(clonedSimulation == null ? null : clonedSimulation.getSolverTaskDescription());
        boolean shouldMeshBeEnabled = false;
        MeshSpecification meshSpec = clonedSimulation.getMeshSpecification();
        if (meshSpec != null && meshSpec.getGeometry() != null && meshSpec.getGeometry().getDimension() > 0) {
            shouldMeshBeEnabled = true;
        }
        if (!shouldMeshBeEnabled) {
            getJTabbedPane1().remove(getMeshTabPanel());
        }
        setClonedSimulation(clonedSimulation);
    } catch (ChomboInvalidGeometryException exc) {
        // if this happens, sim is not allowed to edit
        exc.printStackTrace(System.out);
        throw exc;
    } catch (Throwable exc) {
        exc.printStackTrace(System.out);
        JOptionPane.showMessageDialog(this, "Could not initialize simulation editor\n" + exc.getMessage(), "Error:", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : SimulationOwner(cbit.vcell.solver.SimulationOwner) UnitInfo(cbit.vcell.solver.SimulationOwner.UnitInfo) Simulation(cbit.vcell.solver.Simulation) SolverTaskDescriptionAdvancedPanel(cbit.vcell.solver.ode.gui.SolverTaskDescriptionAdvancedPanel) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException) MeshSpecification(cbit.vcell.solver.MeshSpecification)

Example 2 with UnitInfo

use of cbit.vcell.solver.SimulationOwner.UnitInfo in project vcell by virtualcell.

the class SimulationListPanel method initConnections.

/**
 * Initializes connections
 * @exception java.lang.Exception The exception description.
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() throws java.lang.Exception {
    // user code begin {1}
    // user code end
    getNewButton().addActionListener(ivjEventHandler);
    getEditButton().addActionListener(ivjEventHandler);
    getDeleteButton().addActionListener(ivjEventHandler);
    getRunButton().addActionListener(ivjEventHandler);
    // getPythonResultsButton().addActionListener(ivjEventHandler);
    getNativeResultsButton().addActionListener(ivjEventHandler);
    getMoreActionsButton().addActionListener(ivjEventHandler);
    getScrollPaneTable().addPropertyChangeListener(ivjEventHandler);
    getOutputFunctionsPanel().addPropertyChangeListener(ivjEventHandler);
    getScrollPaneTable().getSelectionModel().addListSelectionListener(ivjEventHandler);
    DefaultScrollTableCellRenderer renderer = new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof OutputTimeSpec) {
                SimulationWorkspace sw = getSimulationWorkspace();
                SimulationOwner so = sw.getSimulationOwner();
                UnitInfo unitInfo = so.getUnitInfo();
                Objects.requireNonNull(unitInfo);
                OutputTimeSpec ots = (OutputTimeSpec) value;
                String text = ots.describe(unitInfo);
                setText(text);
            } else if (value instanceof Double) {
                setText(value + "");
            }
            boolean bFinitVolumeRerun = false;
            if (value instanceof SolverDescription) {
                SolverDescription solverDescription = (SolverDescription) value;
                try {
                    if (FINITEVOLUME_CUTTOFF != null && solverDescription.equals(SolverDescription.FiniteVolume)) /*Compiled Solver*/
                    {
                        SimulationStatus simStatus = getSimulationWorkspace().getSimulationStatus(getSimulationListTableModel1().getValueAt(row));
                        if (simStatus.getHasData()) {
                            int statusIndex = 0;
                            while (simStatus.getJobStatus(statusIndex) != null) {
                                if (simStatus.getJobStatus(statusIndex).getEndDate().compareTo(FINITEVOLUME_CUTTOFF) > 0) {
                                    bFinitVolumeRerun = true;
                                    break;
                                }
                                statusIndex++;
                            }
                        }
                    }
                } catch (Exception e) {
                    // ignore, let table cell render anyway
                    e.printStackTrace();
                }
                setText(solverDescription.getShortDisplayLabel());
                setToolTipText(solverDescription.getDisplayLabel());
            } else {
                setToolTipText(getText());
            }
            if (bFinitVolumeRerun) {
                setText(getText() + (bFinitVolumeRerun ? "(*)" : ""));
                setToolTipText(getToolTipText() + (bFinitVolumeRerun ? " (data regenerated using FiniteVolumeStandalone)" : ""));
            }
            return this;
        }
    };
    getScrollPaneTable().setDefaultRenderer(OutputTimeSpec.class, renderer);
    getScrollPaneTable().setDefaultRenderer(Double.class, renderer);
    getScrollPaneTable().setDefaultRenderer(String.class, renderer);
    getScrollPaneTable().setDefaultRenderer(SolverDescription.class, renderer);
    getScrollPaneTable().setDefaultEditor(OutputTimeSpec.class, new DefaultCellEditor(new JTextField()));
    getScrollPaneTable().setDefaultRenderer(SimulationStatus.class, new DefaultScrollTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            Object obj = getSimulationStatusDisplay(row);
            if (obj instanceof JProgressBar) {
                return (JProgressBar) obj;
            }
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            if (value instanceof SimulationStatus) {
                setText(obj.toString());
                String details = ((SimulationStatus) value).getDetails();
                setToolTipText(details);
            }
            return this;
        }
    });
}
Also used : SolverDescription(cbit.vcell.solver.SolverDescription) JProgressBar(javax.swing.JProgressBar) JTextField(javax.swing.JTextField) PropertyVetoException(java.beans.PropertyVetoException) IOException(java.io.IOException) DefaultCellEditor(javax.swing.DefaultCellEditor) SimulationOwner(cbit.vcell.solver.SimulationOwner) UnitInfo(cbit.vcell.solver.SimulationOwner.UnitInfo) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) SimulationStatus(cbit.vcell.server.SimulationStatus) JTable(javax.swing.JTable) DefaultScrollTableCellRenderer(org.vcell.util.gui.DefaultScrollTableCellRenderer) Component(java.awt.Component)

Aggregations

SimulationOwner (cbit.vcell.solver.SimulationOwner)2 UnitInfo (cbit.vcell.solver.SimulationOwner.UnitInfo)2 ChomboInvalidGeometryException (cbit.vcell.geometry.ChomboInvalidGeometryException)1 SimulationStatus (cbit.vcell.server.SimulationStatus)1 MeshSpecification (cbit.vcell.solver.MeshSpecification)1 OutputTimeSpec (cbit.vcell.solver.OutputTimeSpec)1 Simulation (cbit.vcell.solver.Simulation)1 SolverDescription (cbit.vcell.solver.SolverDescription)1 SolverTaskDescriptionAdvancedPanel (cbit.vcell.solver.ode.gui.SolverTaskDescriptionAdvancedPanel)1 Component (java.awt.Component)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 DefaultCellEditor (javax.swing.DefaultCellEditor)1 JProgressBar (javax.swing.JProgressBar)1 JTable (javax.swing.JTable)1 JTextField (javax.swing.JTextField)1 DefaultScrollTableCellRenderer (org.vcell.util.gui.DefaultScrollTableCellRenderer)1