Search in sources :

Example 41 with SubVolume

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

the class StructureMappingTableRenderer method getTableCellRendererComponent.

public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    setIcon(null);
    if (table.getModel() instanceof StructureMappingTableModel) {
        StructureMappingTableModel structureMappingTableModel = (StructureMappingTableModel) table.getModel();
        String toolTip = structureMappingTableModel.getToolTip(row, column);
        if (value instanceof Structure) {
            Structure structure = (Structure) value;
            setText(structure.getName());
        } else if (value instanceof Double && structureMappingTableModel.isNewSizeColumn(column)) {
            StructureMapping structureMapping = structureMappingTableModel.getStructureMapping(row);
            if (structureMappingTableModel.isNonSpatial()) {
                VCUnitDefinition unitDefinition = structureMapping.getStructure().getStructureSize().getUnitDefinition();
                TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                if (sizeIcon == null) {
                    sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                    unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                }
                setIcon(sizeIcon);
            } else {
                // spatial
                if (structureMapping.getUnitSizeParameter() != null) {
                    VCUnitDefinition unitDefinition = structureMapping.getUnitSizeParameter().getUnitDefinition();
                    TextIcon sizeIcon = unitIconHash.get(unitDefinition.getSymbol());
                    if (sizeIcon == null) {
                        sizeIcon = new TextIcon("[ " + unitDefinition.getSymbolUnicode() + " ]");
                        unitIconHash.put(unitDefinition.getSymbol(), sizeIcon);
                    }
                    setIcon(sizeIcon);
                }
            }
        }
        if (structureMappingTableModel.isSubdomainColumn(column)) {
            // can be null
            if (value == null) {
                setText("Unmapped");
                setForeground(Color.red);
                setIcon(null);
            } else {
                if (value instanceof GeometryClass) {
                    setText(((GeometryClass) value).getName());
                    if (value instanceof SubVolume) {
                        SubVolume subVolume = (SubVolume) value;
                        java.awt.Color handleColor = new java.awt.Color(colormap[subVolume.getHandle()]);
                        // small square icon with subdomain color
                        Icon icon = new ColorIcon(10, 10, handleColor, true);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                        setIcon(icon);
                    } else if (value instanceof SurfaceClass) {
                        SurfaceClass sc = (SurfaceClass) value;
                        Set<SubVolume> sv = sc.getAdjacentSubvolumes();
                        Iterator<SubVolume> iterator = sv.iterator();
                        SubVolume sv1 = iterator.next();
                        SubVolume sv2 = iterator.next();
                        java.awt.Color c1 = new java.awt.Color(colormap[sv2.getHandle()]);
                        java.awt.Color c2 = new java.awt.Color(colormap[sv1.getHandle()]);
                        Icon icon = new ColorIconEx(10, 10, c1, c2);
                        setIcon(icon);
                        setHorizontalTextPosition(SwingConstants.RIGHT);
                    }
                } else {
                    setText(value.toString());
                    setIcon(null);
                }
            }
        }
        if (value instanceof BoundaryConditionType) {
            // we get here only for spatial
            Object candidate = structureMappingTableModel.getValueAt(row, StructureMappingTableModel.SPATIAL_COLUMN_SUBDOMAIN);
            if (candidate instanceof SurfaceClass) {
                SurfaceClass surfaceClass = (SurfaceClass) candidate;
                cbit.vcell.model.Model model = structureMappingTableModel.getGeometryContext().getModel();
                SimulationContext simContext = structureMappingTableModel.getGeometryContext().getSimulationContext();
                Pair<SubVolume, SubVolume> ret = DiffEquMathMapping.computeBoundaryConditionSource(model, simContext, surfaceClass);
                SubVolume innerSubVolume = ret.one;
                java.awt.Color handleColor = new java.awt.Color(colormap[innerSubVolume.getHandle()]);
                // small square icon with subdomain color
                Icon icon = new ColorIcon(8, 8, handleColor, true);
                setHorizontalTextPosition(SwingConstants.LEFT);
                setIcon(icon);
                setText("from");
                // override default tooltip
                toolTip = "Boundary condition inherited from Subdomain '" + innerSubVolume.getName() + "'";
                setToolTipText(toolTip);
            } else {
                setText(((BoundaryConditionType) value).boundaryTypeStringValue());
            }
        }
        List<Issue> issueList = structureMappingTableModel.getIssues(row, column, Issue.SEVERITY_ERROR);
        if (issueList.size() > 0) {
            // override default tooltip
            setToolTipText(Issue.getHtmlIssueMessage(issueList));
            if (column == 0) {
                setBorder(new MatteBorder(1, 1, 1, 0, Color.red));
            } else if (column == table.getColumnCount() - 1) {
                setBorder(new MatteBorder(1, 0, 1, 1, Color.red));
            } else {
                setBorder(new MatteBorder(1, 0, 1, 0, Color.red));
            }
        } else {
            setToolTipText(toolTip);
            setBorder(DEFAULT_GAP);
        }
    }
    return this;
}
Also used : Color(java.awt.Color) GeometryClass(cbit.vcell.geometry.GeometryClass) Set(java.util.Set) Issue(org.vcell.util.Issue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) AttributedString(java.text.AttributedString) StructureMapping(cbit.vcell.mapping.StructureMapping) MatteBorder(javax.swing.border.MatteBorder) SubVolume(cbit.vcell.geometry.SubVolume) Iterator(java.util.Iterator) Structure(cbit.vcell.model.Structure) ColorIconEx(org.vcell.util.gui.ColorIconEx) ColorIcon(org.vcell.util.gui.ColorIcon) Color(java.awt.Color) SimulationContext(cbit.vcell.mapping.SimulationContext) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) ColorIcon(org.vcell.util.gui.ColorIcon) Icon(javax.swing.Icon)

Example 42 with SubVolume

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

the class GeomDbDriver method getSubVolumesFromGeometry.

/**
 * getModel method comment.
 */
private SubVolume[] getSubVolumesFromGeometry(QueryHashtable dbc, Connection con, KeyValue geomKey) throws SQLException, DataAccessException {
    // log.print("GeomDbDriver.getSubVolumesFromGeometry(geometryKey="+geomKey+")");
    String sql;
    sql = " SELECT * " + " FROM " + subVolumeTable.getTableName() + " WHERE " + subVolumeTable.geometryRef + " = " + geomKey + " ORDER BY " + subVolumeTable.ordinal;
    // System.out.println(sql);
    Statement stmt = con.createStatement();
    Vector<SubVolume> subVolumeList = new Vector<SubVolume>();
    try {
        ResultSet rset = stmt.executeQuery(sql);
        // showMetaData(rset);
        SubVolume subVolume = null;
        while (rset.next()) {
            subVolume = getSubVolume(dbc, con, rset);
            subVolumeList.addElement(subVolume);
        }
        if (subVolumeList.size() > 0) {
            SubVolume[] subVolumes = new SubVolume[subVolumeList.size()];
            subVolumeList.copyInto(subVolumes);
            return subVolumes;
        } else {
            return null;
        }
    } catch (ExpressionException e) {
        throw new DataAccessException(e.getMessage());
    } finally {
        // Release resources include resultset
        stmt.close();
    }
}
Also used : Statement(java.sql.Statement) SubVolume(cbit.vcell.geometry.SubVolume) ResultSet(java.sql.ResultSet) Vector(java.util.Vector) ExpressionException(cbit.vcell.parser.ExpressionException) DataAccessException(org.vcell.util.DataAccessException)

Example 43 with SubVolume

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

the class GeomDbDriver method getGeometry.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.model.Model
 * @param rset java.sql.ResultSet
 */
private Geometry getGeometry(QueryHashtable dbc, Connection con, User user, ResultSet rset) throws SQLException, DataAccessException {
    // 
    // get Image reference
    // 
    java.math.BigDecimal bigD = rset.getBigDecimal(geomTable.imageRef.toString());
    KeyValue imageRef = null;
    if (!rset.wasNull()) {
        imageRef = new KeyValue(bigD);
    }
    // 
    // get geometry object
    // 
    Geometry tempGeometry = null;
    try {
        tempGeometry = geomTable.getGeometry(rset, con);
    } catch (PropertyVetoException e) {
        throw new DataAccessException(e.getMessage());
    }
    Geometry geom = null;
    // 
    // get image for this geometry
    // 
    VCImage vcImage = null;
    if (imageRef != null) {
        // permission checking for the image is disabled because it is a child of this geometry
        vcImage = getVCImage(dbc, con, user, imageRef, false);
    }
    if (vcImage != null) {
        geom = new Geometry(tempGeometry, vcImage);
    } else {
        geom = tempGeometry;
    }
    // 
    // get SubVolumes for this geometry
    // 
    SubVolume[] subVolumes = getSubVolumesFromGeometry(dbc, con, geom.getVersion().getVersionKey());
    if (subVolumes != null) {
        try {
            geom.getGeometrySpec().setSubVolumes(subVolumes);
        } catch (java.beans.PropertyVetoException e) {
            lg.error(e.getMessage(), e);
            throw new DataAccessException(e.getMessage());
        }
    }
    // 
    if (geom.getDimension() > 0) {
        getSurfaceDescription(con, geom);
    }
    // 
    if (geom.getDimension() > 0) {
        getFilaments(con, geom);
    }
    // 
    // get SurfaceClasses for this geometry
    // 
    SurfaceClass[] surfaceClasses = getSurfaceClassesFromGeometry(dbc, con, geom.getVersion().getVersionKey());
    if (surfaceClasses != null) {
        try {
            geom.getGeometrySurfaceDescription().setSurfaceClasses(surfaceClasses);
        } catch (java.beans.PropertyVetoException e) {
            lg.error(e.getMessage(), e);
            throw new DataAccessException(e.getMessage());
        }
    }
    return geom;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) VCImage(cbit.image.VCImage) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) PropertyVetoException(java.beans.PropertyVetoException) BigDecimal(java.math.BigDecimal) SubVolume(cbit.vcell.geometry.SubVolume) DataAccessException(org.vcell.util.DataAccessException)

Example 44 with SubVolume

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

the class GeomDbDriver method getSurfaceClass.

private SurfaceClass getSurfaceClass(QueryHashtable dbc, Connection con, ResultSet rset) throws SQLException, DataAccessException, ExpressionException {
    // showMetaData(rset);
    // 
    // if already in cache, then return that instance instead of a new one
    // 
    KeyValue surfaceClassKey = new KeyValue(rset.getBigDecimal(SurfaceClassTable.table.id.toString()));
    SurfaceClass surfaceClass = (SurfaceClass) dbc.get(surfaceClassKey);
    if (surfaceClass != null) {
        return surfaceClass;
    }
    String surfaceClassName = rset.getString(SurfaceClassTable.table.name.toString());
    BigDecimal subVolumeRef1 = rset.getBigDecimal(SurfaceClassTable.table.subVolumeRef1.toString());
    BigDecimal subVolumeRef2 = rset.getBigDecimal(SurfaceClassTable.table.subVolumeRef2.toString());
    KeyValue subVolumeref1Key = null;
    KeyValue subVolumeref2Key = null;
    HashSet<SubVolume> subVolumeSet = new HashSet<SubVolume>();
    if (subVolumeRef1 != null) {
        subVolumeref1Key = new KeyValue(subVolumeRef1);
        SubVolume subvolume = (SubVolume) dbc.get(subVolumeref1Key);
        if (subvolume != null) {
            subVolumeSet.add(subvolume);
        } else {
            throw new DataAccessException("Subvolume key=" + subVolumeref1Key + " not found in cache");
        }
    }
    if (subVolumeRef2 != null) {
        subVolumeref2Key = new KeyValue(subVolumeRef2);
        SubVolume subvolume = (SubVolume) dbc.get(subVolumeref2Key);
        if (subvolume != null) {
            subVolumeSet.add(subvolume);
        } else {
            throw new DataAccessException("Subvolume key=" + subVolumeref1Key + " not found in cache");
        }
    }
    SurfaceClass surfaceclass = new SurfaceClass(subVolumeSet, surfaceClassKey, surfaceClassName);
    // 
    // put newly read SumVolume into object cache
    // 
    dbc.put(surfaceClassKey, surfaceclass);
    return surfaceclass;
}
Also used : KeyValue(org.vcell.util.document.KeyValue) SurfaceClass(cbit.vcell.geometry.SurfaceClass) SubVolume(cbit.vcell.geometry.SubVolume) BigDecimal(java.math.BigDecimal) DataAccessException(org.vcell.util.DataAccessException) HashSet(java.util.HashSet)

Example 45 with SubVolume

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

the class GeomDbDriver method getSubVolume.

/**
 * getModel method comment.
 */
private SubVolume getSubVolume(QueryHashtable dbc, Connection con, ResultSet rset) throws SQLException, DataAccessException, ExpressionException {
    // showMetaData(rset);
    // 
    // if already in cache, then return that instance instead of a new one
    // 
    KeyValue svKey = new KeyValue(rset.getBigDecimal(subVolumeTable.id.toString()));
    SubVolume subVolume = (SubVolume) dbc.get(svKey);
    if (subVolume != null) {
        return subVolume;
    }
    java.math.BigDecimal imageRegionKeyBigDecimal = rset.getBigDecimal(subVolumeTable.imageRegionRef.toString());
    KeyValue imageRegionKey = null;
    if (!rset.wasNull()) {
        imageRegionKey = new KeyValue(imageRegionKeyBigDecimal);
    }
    if (imageRegionKey == null) {
        subVolume = subVolumeTable.getAnalyticOrCompartmentSubVolume(svKey, rset);
    } else {
        VCPixelClass vcPixelClass = getPixelClass(dbc, con, imageRegionKey);
        subVolume = subVolumeTable.getImageSubVolume(svKey, rset, vcPixelClass);
    }
    // 
    // put newly read SumVolume into object cache
    // 
    dbc.put(svKey, subVolume);
    return subVolume;
}
Also used : BigDecimal(java.math.BigDecimal) VCPixelClass(cbit.image.VCPixelClass) KeyValue(org.vcell.util.document.KeyValue) SubVolume(cbit.vcell.geometry.SubVolume)

Aggregations

SubVolume (cbit.vcell.geometry.SubVolume)84 SurfaceClass (cbit.vcell.geometry.SurfaceClass)42 Expression (cbit.vcell.parser.Expression)33 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)26 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)22 GeometryClass (cbit.vcell.geometry.GeometryClass)21 ArrayList (java.util.ArrayList)21 Geometry (cbit.vcell.geometry.Geometry)20 MathDescription (cbit.vcell.math.MathDescription)17 SpeciesContext (cbit.vcell.model.SpeciesContext)17 PropertyVetoException (java.beans.PropertyVetoException)17 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)16 CompartmentSubVolume (cbit.vcell.geometry.CompartmentSubVolume)15 Model (cbit.vcell.model.Model)15 ImageException (cbit.image.ImageException)14 VCImage (cbit.image.VCImage)14 Feature (cbit.vcell.model.Feature)14 Structure (cbit.vcell.model.Structure)14 MembraneSubDomain (cbit.vcell.math.MembraneSubDomain)13 ExpressionException (cbit.vcell.parser.ExpressionException)13