Search in sources :

Example 56 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class DbDriver method setVersioned.

/**
 * This method was created in VisualAge.
 * @param vTable cbit.sql.VersionTable
 * @param versionKey cbit.sql.KeyValue
 */
protected void setVersioned(Connection con, User user, Versionable versionable) throws ObjectNotFoundException, SQLException, DataAccessException {
    String sql;
    if (versionable instanceof SimulationContext) {
        SimulationContext sc = (SimulationContext) versionable;
        setVersioned(con, user, sc.getGeometryContext().getGeometry());
        setVersioned(con, user, sc.getGeometryContext().getModel());
        if (sc.getMathDescription() != null) {
            setVersioned(con, user, sc.getMathDescription());
        }
    } else if (versionable instanceof MathDescription) {
        MathDescription math = (MathDescription) versionable;
        setVersioned(con, user, math.getGeometry());
    } else if (versionable instanceof Geometry) {
        Geometry geo = (Geometry) versionable;
        if (geo.getGeometrySpec().getImage() != null) {
            setVersioned(con, user, geo.getGeometrySpec().getImage());
        }
    }
    // 
    if (versionable.getVersion().getOwner().compareEqual(user)) {
        VersionTable vTable = VersionTable.getVersionTable(versionable);
        sql = "UPDATE " + vTable.getTableName() + " SET " + vTable.versionFlag + " = " + VersionFlag.Archived.getIntValue() + " WHERE " + vTable.id + " = " + versionable.getVersion().getVersionKey() + // " AND " + vTable.versionFlag + " = " + VersionFlag.CURRENT +
        " AND " + vTable.ownerRef + " = " + user.getID();
        if (updateCleanSQL(con, sql) != 1) {
            throw new DataAccessException("setVersioned failed for :" + versionable.getVersion());
        }
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) MathDescription(cbit.vcell.math.MathDescription) SimulationContext(cbit.vcell.mapping.SimulationContext) DataAccessException(org.vcell.util.DataAccessException)

Example 57 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class ServerDocumentManager method saveGeometry.

/**
 * Insert the method's description here.
 * Creation date: (10/28/00 12:08:30 AM)
 */
public String saveGeometry(QueryHashtable dbc, User user, String geometryXML, String newName) throws DataAccessException, cbit.vcell.xml.XmlParseException, java.sql.SQLException {
    Geometry geometry = XmlHelper.XMLToGeometry(new XMLSource(geometryXML));
    forceDeepDirtyIfForeign(user, geometry);
    // 
    if (newName != null) {
        try {
            geometry.setName(newName);
        } catch (java.beans.PropertyVetoException e) {
            e.printStackTrace(System.out);
            throw new DataAccessException("couldn't set new name for Geometry: " + e.getMessage());
        }
    }
    // 
    // if geometry has an image, save it if necessary
    // 
    KeyValue updatedImageKey = null;
    if (geometry.getGeometrySpec().getImage() != null) {
        VCImage image = geometry.getGeometrySpec().getImage();
        if (image.getKey() == null || !image.getVersion().getName().equals(image.getName())) {
            // 
            try {
                fixNullImageName(image);
                int count = 0;
                while (dbServer.getDBTopLevel().isNameUsed(user, VersionableType.VCImage, image.getName(), true)) {
                    try {
                        image.setName(TokenMangler.getNextRandomToken(image.getName()));
                    } catch (java.beans.PropertyVetoException e) {
                        e.printStackTrace(System.out);
                    }
                    if (count++ > 5) {
                        throw new DataAccessException("failed to find unique image name '" + image.getName() + "' is last name tried");
                    }
                }
            } catch (Exception ex) {
                ex.printStackTrace(System.out);
                throw new DataAccessException(ex.getMessage(), ex);
            }
            updatedImageKey = dbServer.getDBTopLevel().insertVersionable(user, image, image.getName(), false, true);
        } else {
            // 
            // Image has been saved previously, get old image from database
            // 
            VCImage origImage = dbServer.getDBTopLevel().getVCImage(dbc, user, image.getKey(), false);
            if (origImage == null || !origImage.compareEqual(image)) {
                updatedImageKey = dbServer.getDBTopLevel().updateVersionable(user, image, false, true);
            } else {
                // image didn't need to be saved
                updatedImageKey = image.getKey();
            }
        }
    }
    // 
    // save geometry
    // 
    KeyValue geometryKey = null;
    if (geometry.getVersion() != null && geometry.getName().equals(geometry.getVersion().getName())) {
        geometryKey = dbServer.getDBTopLevel().updateVersionable(dbc, user, geometry, updatedImageKey, false, true);
    } else {
        geometryKey = dbServer.getDBTopLevel().insertVersionable(dbc, user, geometry, updatedImageKey, geometry.getName(), false, true);
    }
    return dbServer.getGeometryXML(user, geometryKey).toString();
}
Also used : Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) KeyValue(org.vcell.util.document.KeyValue) VCImage(cbit.image.VCImage) XMLSource(cbit.vcell.xml.XMLSource) DataAccessException(org.vcell.util.DataAccessException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) PropertyVetoException(java.beans.PropertyVetoException) XmlParseException(cbit.vcell.xml.XmlParseException) DataAccessException(org.vcell.util.DataAccessException) MappingException(cbit.vcell.mapping.MappingException)

Example 58 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class SimContextTable method getSimContext.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.mapping.SimulationContext
 * @param rset java.sql.ResultSet
 * @param log cbit.vcell.server.SessionLog
 * @deprecated shouldn't do recursive query
 */
public SimulationContext getSimContext(QueryHashtable dbc, Connection con, User user, ResultSet rset, GeomDbDriver geomDB, ModelDbDriver modelDB, MathDescriptionDbDriver mathDB) throws SQLException, DataAccessException, java.beans.PropertyVetoException {
    java.math.BigDecimal groupid = rset.getBigDecimal(VersionTable.privacy_ColumnName);
    Version version = getVersion(rset, DbDriver.getGroupAccessFromGroupID(con, groupid));
    KeyValue geomKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.geometryRef.toString()));
    Geometry geom = (Geometry) geomDB.getVersionable(dbc, con, user, VersionableType.Geometry, geomKey, false);
    KeyValue modelKey = new KeyValue(rset.getBigDecimal(SimContextTable.table.modelRef.toString()));
    Model model = (Model) modelDB.getVersionable(dbc, con, user, VersionableType.Model, modelKey);
    // 
    // read characteristic size (may be null)
    // 
    Double characteristicSize = null;
    BigDecimal size = rset.getBigDecimal(charSize.toString());
    if (!rset.wasNull() && size != null) {
        characteristicSize = new Double(size.doubleValue());
    }
    // 
    // get mathKey (may be null)
    // 
    MathDescription mathDesc = null;
    BigDecimal mathKeyValue = rset.getBigDecimal(SimContextTable.table.mathRef.toString());
    if (!rset.wasNull()) {
        KeyValue mathKey = new KeyValue(mathKeyValue);
        mathDesc = (MathDescription) mathDB.getVersionable(dbc, con, user, VersionableType.MathDescription, mathKey);
    }
    boolean bStochastic = mathDesc.isNonSpatialStoch() || mathDesc.isSpatialStoch() || mathDesc.isSpatialHybrid();
    boolean bRuleBased = mathDesc.isRuleBased();
    SimulationContext simContext = new SimulationContext(model, geom, mathDesc, version, bStochastic, bRuleBased);
    if (characteristicSize != null) {
        simContext.setCharacteristicSize(characteristicSize);
    }
    return simContext;
}
Also used : Geometry(cbit.vcell.geometry.Geometry) BigDecimal(java.math.BigDecimal) KeyValue(org.vcell.util.document.KeyValue) Version(org.vcell.util.document.Version) VCellSoftwareVersion(org.vcell.util.document.VCellSoftwareVersion) MathDescription(cbit.vcell.math.MathDescription) Model(cbit.vcell.model.Model) SimulationContext(cbit.vcell.mapping.SimulationContext) BigDecimal(java.math.BigDecimal)

Example 59 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class ROIMultiPaintManager method showGUI.

public Geometry showGUI(final String okButtonText, final String sourceDataName, final Component parentComponent, String initalAnnotation, final VCPixelClass[] vcPixelClasses, UserPreferences userPreferences) {
    originalAnnotation = initalAnnotation;
    final Geometry[] finalGeometryHolder = new Geometry[1];
    if (overlayEditorPanelJAI == null) {
        overlayEditorPanelJAI = new OverlayEditorPanelJAI();
        overlayEditorPanelJAI.setCalcCoords(new CalcCoords());
        overlayEditorPanelJAI.setUserPreferences(userPreferences);
        overlayEditorPanelJAI.setMinimumSize(new Dimension(700, 600));
        overlayEditorPanelJAI.setPreferredSize(new Dimension(700, 600));
        overlayEditorPanelJAI.addPropertyChangeListener(ROIMultiPaintManager.this);
    }
    // delete all names
    overlayEditorPanelJAI.deleteROIName(null);
    // when user selects image "from DB" or "from current geometry"
    applyPixelClasses(vcPixelClasses, parentComponent);
    if (getImageDataset().length > 1) {
        String[] channelNames = new String[getImageDataset().length];
        for (int i = 0; i < channelNames.length; i++) {
            channelNames[i] = "channel " + i;
        }
        overlayEditorPanelJAI.setChannelNames(channelNames);
    } else {
        overlayEditorPanelJAI.setChannelNames(null);
    }
    updateUnderlayHistogramDisplay();
    overlayEditorPanelJAI.setContrastToMinMax();
    overlayEditorPanelJAI.setAllROICompositeImage(roiComposite, OverlayEditorPanelJAI.FRAP_DATA_INIT_PROPERTY);
    final JDialog jDialog = new JDialog(JOptionPane.getFrameForComponent(parentComponent));
    jDialog.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
    jDialog.setTitle("Geometry Editor (" + sourceDataName + ")");
    jDialog.setModal(true);
    final JButton cancelJButton = new JButton("Cancel");
    cancelJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final String QUIT_ANSWER = "Quit Geometry Editor";
            String result = DialogUtils.showWarningDialog(jDialog, "Confirm cancel", "Quit geometry editor and lose all changes?", new String[] { QUIT_ANSWER, "back" }, QUIT_ANSWER);
            if (result != null && result.equals(QUIT_ANSWER)) {
                jDialog.dispose();
            }
        }
    });
    jDialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            super.windowOpened(e);
            if (bHasOriginalData) {
                calculateHistogram();
            }
            updateUndoAfter(false);
            if (vcPixelClasses == null) {
                askInitialize(false);
            }
        }

        @Override
        public void windowClosing(WindowEvent e) {
            // TODO Auto-generated method stub
            super.windowClosing(e);
            cancelJButton.doClick();
        }
    });
    final JPanel okCancelJPanel = new JPanel(new FlowLayout());
    JButton okJButton = new JButton(okButtonText);
    okJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                VCImage finalImage = checkAll();
                finalImage.setDescription((editedGeometryAttributes != null ? editedGeometryAttributes.annotation : originalAnnotation));
                finalGeometryHolder[0] = new Geometry((String) null, finalImage);
                finalGeometryHolder[0].getGeometrySpec().setOrigin((editedGeometryAttributes != null ? editedGeometryAttributes.origin : originalOrigin));
                finalGeometryHolder[0].getGeometrySpec().setExtent((editedGeometryAttributes != null ? editedGeometryAttributes.extent : originalExtent));
                finalGeometryHolder[0].setDescription((editedGeometryAttributes != null ? editedGeometryAttributes.annotation : originalAnnotation));
                jDialog.dispose();
            } catch (UserCancelException uce) {
            } catch (Exception exc) {
                DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Error validating compartments.\n" + exc.getMessage(), exc);
            }
        }
    });
    JButton attributesJButton = new JButton("Attributes...");
    attributesJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            try {
                editedGeometryAttributes = showEditGeometryAttributes(jDialog, editedGeometryAttributes);
            } catch (UserCancelException uce) {
            // ignore
            }
        }
    });
    // JButton surfaceButton = new JButton("View Surfaces...");
    // surfaceButton.addActionListener(new ActionListener() {
    // public void actionPerformed(ActionEvent e) {
    // showDataValueSurfaceViewer(geomAttr);
    // }
    // });
    JButton exportJButton = new JButton("Export...");
    exportJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            export();
        }
    });
    JButton importJButton = new JButton("Import stl...");
    importJButton.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            JFileChooser importJFC = new JFileChooser(ClientRequestManager.getPreferredPath(UserPreferences.getLastUserPreferences()));
            importJFC.setDialogTitle("Choose .stl file(s) to import");
            importJFC.setMultiSelectionEnabled(true);
            int result = importJFC.showOpenDialog(overlayEditorPanelJAI);
            if (result == JFileChooser.APPROVE_OPTION) {
                File[] selectedFiles = importJFC.getSelectedFiles();
                if (selectedFiles != null && selectedFiles.length > 0) {
                    ClientRequestManager.setPreferredPath(UserPreferences.getLastUserPreferences(), selectedFiles[0]);
                    Vect3d sampleSize = new Vect3d(getImageDataset()[0].getISize().getX(), getImageDataset()[0].getISize().getY(), getImageDataset()[0].getISize().getZ());
                    ArrayList<AsynchClientTask> stlImportTasks = getImportSTLtasks(selectedFiles, sampleSize, new Vect3d(0, 0, 0));
                    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<>(), stlImportTasks.toArray(new AsynchClientTask[0]));
                } else {
                    DialogUtils.showErrorDialog(overlayEditorPanelJAI, "Select at least 1 .stl file for import.");
                }
            }
        }
    });
    okCancelJPanel.add(okJButton);
    okCancelJPanel.add(attributesJButton);
    okCancelJPanel.add(exportJButton);
    okCancelJPanel.add(importJButton);
    // okCancelJPanel.add(surfaceButton);
    okCancelJPanel.add(cancelJButton);
    jDialog.getContentPane().add(overlayEditorPanelJAI, BorderLayout.CENTER);
    jDialog.getContentPane().add(okCancelJPanel, BorderLayout.SOUTH);
    jDialog.setSize(700, 600);
    DialogUtils.showModalJDialogOnTop(jDialog, parentComponent);
    if (finalGeometryHolder[0] == null) {
        throw UserCancelException.CANCEL_GENERIC;
    }
    return finalGeometryHolder[0];
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) JButton(javax.swing.JButton) UserCancelException(org.vcell.util.UserCancelException) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) VCImage(cbit.image.VCImage) Dimension(java.awt.Dimension) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException) Vect3d(cbit.vcell.render.Vect3d) Geometry(cbit.vcell.geometry.Geometry) ActionListener(java.awt.event.ActionListener) JFileChooser(javax.swing.JFileChooser) WindowEvent(java.awt.event.WindowEvent) JDialog(javax.swing.JDialog)

Example 60 with Geometry

use of cbit.vcell.geometry.Geometry in project vcell by virtualcell.

the class ChomboMeshSpecificationPanel method updateDisplay.

private void updateDisplay(boolean bSolverChanged) throws ChomboGeometryException, ChomboInvalidGeometryException {
    if (!simulation.getSolverTaskDescription().getSolverDescription().isChomboSolver()) {
        setVisible(false);
        return;
    }
    Geometry geometry = simulation.getMathDescription().getGeometry();
    Extent extent = geometry.getExtent();
    int dimension = geometry.getDimension();
    switch(dimension) {
        case 0:
            setVisible(false);
            break;
        case 1:
            getGeometrySizeTextField().setText("" + extent.getX());
            NyLabel.setVisible(false);
            NyComboBox.setVisible(false);
            NzLabel.setVisible(false);
            NzComboBox.setVisible(false);
            break;
        case 2:
            getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ")");
            NzLabel.setVisible(false);
            NzComboBox.setVisible(false);
            break;
        case 3:
            getGeometrySizeTextField().setText("(" + extent.getX() + ", " + extent.getY() + ", " + extent.getZ() + ")");
            break;
    }
    String error;
    ChomboMeshRecommendation meshRecommendation = new ChomboMeshValidator(geometry.getDimension(), geometry.getExtent(), simulation.getSolverTaskDescription().getChomboSolverSpec().getBlockFactor()).computeMeshSpecs();
    if (meshRecommendation.validate()) {
        // remove ActionListener, here we only want to set values
        removeComboBoxListener();
        HComboBox.removeAll();
        NxComboBox.removeAll();
        NyComboBox.removeAll();
        NzComboBox.removeAll();
        for (ChomboMeshSpec meshSpec : meshRecommendation.validMeshSpecList) {
            HComboBox.addItem((float) meshSpec.H);
            NxComboBox.addItem(meshSpec.Nx[0]);
            if (geometry.getDimension() > 1) {
                NyComboBox.addItem(meshSpec.Nx[1]);
                if (geometry.getDimension() == 3) {
                    NzComboBox.addItem(meshSpec.Nx[2]);
                }
            }
        }
        addComboBoxListener();
        if (bSolverChanged) {
            NxComboBox.setSelectedIndex(0);
        } else {
            ISize samplingSize = simulation.getMeshSpecification().getSamplingSize();
            NxComboBox.setSelectedItem(samplingSize.getX());
            // double check if existing mesh size is an option in drop down
            Integer selectedNx = (Integer) NxComboBox.getSelectedItem();
            Integer selectedNy = geometry.getDimension() > 1 ? (Integer) NyComboBox.getSelectedItem() : 1;
            Integer selectedNz = geometry.getDimension() > 2 ? (Integer) NzComboBox.getSelectedItem() : 1;
            boolean bMatchFound = selectedNx == samplingSize.getX() && (dimension < 2 || selectedNy == samplingSize.getY()) && (dimension < 3 || selectedNz == samplingSize.getZ());
            if (!bMatchFound) {
                NxComboBox.setSelectedIndex(0);
                throw new ChomboGeometryException(ChomboMeshValidator.ERROR_MESSAGE_INCOMPATIBLE_MESH_SIZE);
            }
        }
    } else {
        throw new ChomboInvalidGeometryException(meshRecommendation);
    }
}
Also used : Geometry(cbit.vcell.geometry.Geometry) ChomboMeshRecommendation(org.vcell.chombo.ChomboMeshValidator.ChomboMeshRecommendation) ChomboMeshValidator(org.vcell.chombo.ChomboMeshValidator) ChomboGeometryException(cbit.vcell.geometry.ChomboGeometryException) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ChomboMeshSpec(org.vcell.chombo.ChomboMeshValidator.ChomboMeshSpec) ChomboInvalidGeometryException(cbit.vcell.geometry.ChomboInvalidGeometryException)

Aggregations

Geometry (cbit.vcell.geometry.Geometry)121 MathDescription (cbit.vcell.math.MathDescription)32 SimulationContext (cbit.vcell.mapping.SimulationContext)31 Simulation (cbit.vcell.solver.Simulation)29 PropertyVetoException (java.beans.PropertyVetoException)24 BioModel (cbit.vcell.biomodel.BioModel)23 DataAccessException (org.vcell.util.DataAccessException)23 VCImage (cbit.image.VCImage)22 SubVolume (cbit.vcell.geometry.SubVolume)21 MathModel (cbit.vcell.mathmodel.MathModel)21 Expression (cbit.vcell.parser.Expression)19 ISize (org.vcell.util.ISize)19 Hashtable (java.util.Hashtable)18 GeometryThumbnailImageFactoryAWT (cbit.vcell.geometry.GeometryThumbnailImageFactoryAWT)17 UserCancelException (org.vcell.util.UserCancelException)17 KeyValue (org.vcell.util.document.KeyValue)17 ImageException (cbit.image.ImageException)16 Extent (org.vcell.util.Extent)16 SurfaceClass (cbit.vcell.geometry.SurfaceClass)15 ExpressionException (cbit.vcell.parser.ExpressionException)15