Search in sources :

Example 6 with BoundaryConditionType

use of cbit.vcell.math.BoundaryConditionType in project vcell by virtualcell.

the class StructureMappingTableModel method setValueAt.

public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
    if (rowIndex < 0 || rowIndex >= getRowCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), row = " + rowIndex + " out of range [" + 0 + "," + (getRowCount() - 1) + "]");
    }
    if (columnIndex < 0 || columnIndex >= getColumnCount()) {
        throw new RuntimeException("StructureMappingTableModel.setValueAt(), column = " + columnIndex + " out of range [" + 0 + "," + (getColumnCount() - 1) + "]");
    }
    StructureMapping structureMapping = getValueAt(rowIndex);
    Structure structure = structureMapping.getStructure();
    if (bNonSpatial) {
        switch(columnIndex) {
            case NONSPATIAL_COLUMN_SIZE:
                {
                    try {
                        Expression exp = null;
                        if (aValue instanceof String) {
                            exp = new Expression((String) aValue);
                        } else if (aValue instanceof Double) {
                            exp = new Expression(((Double) aValue).doubleValue());
                        }
                        // if the input volumn is null, leave it as it was.
                        if (exp != null) {
                            // for old ode model, once one size is input, solve the rest.                                                                                                          if it is unnamed compartment(the only one), we don't need to solve anything
                            if (!getGeometryContext().getSimulationContext().isStoch() && getGeometryContext().isAllSizeSpecifiedNull() && getGeometryContext().isAllVolFracAndSurfVolSpecified() && getGeometryContext().getStructureMappings().length > 1) {
                                structureMapping.getSizeParameter().setExpression(exp);
                                double size;
                                try {
                                    size = exp.evaluateConstant();
                                    VCUnitDefinition volumeUnit = getGeometryContext().getSimulationContext().getModel().getUnitSystem().getVolumeUnit();
                                    StructureSizeSolver.updateAbsoluteStructureSizes(getGeometryContext().getSimulationContext(), structure, size, volumeUnit);
                                    fireTableRowsUpdated(0, getRowCount());
                                } catch (ExpressionException ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, "Size of Feature " + structure.getName() + " can not be solved as constant!");
                                } catch (Exception ex) {
                                    ex.printStackTrace(System.out);
                                    PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                }
                            } else {
                                structureMapping.getSizeParameter().setExpression(exp);
                                // set fraction in stoch math description, because these might be used when copy from stoch app to ode app.
                                if (getGeometryContext().isAllSizeSpecifiedPositive()) /*&& !getGeometryContext().getSimulationContext().isStoch()*/
                                {
                                    try {
                                        StructureSizeSolver.updateRelativeStructureSizes(getGeometryContext().getSimulationContext());
                                    } catch (Exception ex) {
                                        ex.printStackTrace(System.out);
                                        PopupGenerator.showErrorDialog(ownerTable, ex.getMessage());
                                    }
                                }
                            }
                        }
                    } catch (ExpressionException e) {
                        e.printStackTrace(System.out);
                        PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                    }
                    break;
                }
        }
    } else {
        switch(columnIndex) {
            case SPATIAL_COLUMN_SUBDOMAIN:
                {
                    GeometryClass geometryClass = null;
                    if (aValue instanceof String) {
                        String svname = (String) aValue;
                        geometryClass = getGeometryContext().getGeometry().getGeometryClass(svname);
                    } else if (aValue instanceof GeometryClass) {
                        geometryClass = (GeometryClass) aValue;
                    }
                    if (geometryClass != null) {
                        try {
                            getGeometryContext().assignStructure(structure, geometryClass);
                        } catch (PropertyVetoException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (IllegalMappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        } catch (MappingException e) {
                            e.printStackTrace(System.out);
                            PopupGenerator.showErrorDialog(ownerTable, e.getMessage());
                        }
                    }
                    break;
                }
            case SPATIAL_COLUMN_SIZERATIO:
                try {
                    Expression exp = null;
                    if (aValue instanceof String) {
                        exp = new Expression((String) aValue);
                    } else if (aValue instanceof Double) {
                        exp = new Expression(((Double) aValue).doubleValue());
                    }
                    if (exp != null) {
                        structureMapping.getUnitSizeParameter().setExpression(exp);
                        StructureSizeSolver.updateUnitStructureSizes(getGeometryContext().getSimulationContext(), structureMapping.getGeometryClass());
                    }
                } catch (ExpressionException e) {
                    e.printStackTrace(System.out);
                    PopupGenerator.showErrorDialog(ownerTable, "expression error\n" + e.getMessage());
                }
                break;
            case SPATIAL_COLUMN_X_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_X_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeXp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Y_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeYp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_MINUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZm(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
            case SPATIAL_COLUMN_Z_PLUS:
                {
                    if (aValue != null) {
                        structureMapping.setBoundaryConditionTypeZp(new BoundaryConditionType((String) aValue));
                    }
                    break;
                }
        }
    }
}
Also used : GeometryClass(cbit.vcell.geometry.GeometryClass) BoundaryConditionType(cbit.vcell.math.BoundaryConditionType) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) StructureMapping(cbit.vcell.mapping.StructureMapping) ExpressionException(cbit.vcell.parser.ExpressionException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) PropertyVetoException(java.beans.PropertyVetoException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) ExpressionException(cbit.vcell.parser.ExpressionException) MappingException(cbit.vcell.mapping.MappingException) IllegalMappingException(cbit.vcell.mapping.IllegalMappingException) MappingException(cbit.vcell.mapping.MappingException) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) Expression(cbit.vcell.parser.Expression) Structure(cbit.vcell.model.Structure)

Example 7 with BoundaryConditionType

use of cbit.vcell.math.BoundaryConditionType 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 8 with BoundaryConditionType

use of cbit.vcell.math.BoundaryConditionType in project vcell by virtualcell.

the class StructureMapping method setBoundaryConditionTypeZm.

/**
 * This method was created by a SmartGuide.
 * @param bct java.lang.String
 * @exception java.lang.Exception The exception description.
 */
public void setBoundaryConditionTypeZm(BoundaryConditionType bc) {
    BoundaryConditionType oldBCType = getBoundaryConditionTypeZm();
    setBoundaryCondition(BoundaryLocation.getZM(), bc);
    BoundaryConditionType newBCType = getBoundaryConditionTypeZm();
    firePropertyChange("boundaryConditionTypeZm", oldBCType, newBCType);
}
Also used : BoundaryConditionType(cbit.vcell.math.BoundaryConditionType)

Example 9 with BoundaryConditionType

use of cbit.vcell.math.BoundaryConditionType in project vcell by virtualcell.

the class StructureMapping method setBoundaryConditionTypeXp.

/**
 * This method was created by a SmartGuide.
 * @param bct java.lang.String
 * @exception java.lang.Exception The exception description.
 */
public void setBoundaryConditionTypeXp(BoundaryConditionType bc) {
    BoundaryConditionType oldBCType = getBoundaryConditionTypeXp();
    setBoundaryCondition(BoundaryLocation.getXP(), bc);
    BoundaryConditionType newBCType = getBoundaryConditionTypeXp();
    firePropertyChange("boundaryConditionTypeXp", oldBCType, newBCType);
}
Also used : BoundaryConditionType(cbit.vcell.math.BoundaryConditionType)

Example 10 with BoundaryConditionType

use of cbit.vcell.math.BoundaryConditionType in project vcell by virtualcell.

the class StructureMapping method setBoundaryConditionTypeYm.

/**
 * This method was created by a SmartGuide.
 * @param bct java.lang.String
 * @exception java.lang.Exception The exception description.
 */
public void setBoundaryConditionTypeYm(BoundaryConditionType bc) {
    BoundaryConditionType oldBCType = getBoundaryConditionTypeYm();
    setBoundaryCondition(BoundaryLocation.getYM(), bc);
    BoundaryConditionType newBCType = getBoundaryConditionTypeYm();
    firePropertyChange("boundaryConditionTypeYm", oldBCType, newBCType);
}
Also used : BoundaryConditionType(cbit.vcell.math.BoundaryConditionType)

Aggregations

BoundaryConditionType (cbit.vcell.math.BoundaryConditionType)18 Expression (cbit.vcell.parser.Expression)6 ExpressionException (cbit.vcell.parser.ExpressionException)6 GeometryClass (cbit.vcell.geometry.GeometryClass)5 StructureMapping (cbit.vcell.mapping.StructureMapping)5 SubVolume (cbit.vcell.geometry.SubVolume)4 MathException (cbit.vcell.math.MathException)4 PropertyVetoException (java.beans.PropertyVetoException)4 Element (org.jdom.Element)4 SurfaceClass (cbit.vcell.geometry.SurfaceClass)3 FeatureMapping (cbit.vcell.mapping.FeatureMapping)3 MappingException (cbit.vcell.mapping.MappingException)3 CompartmentSubDomain (cbit.vcell.math.CompartmentSubDomain)3 Structure (cbit.vcell.model.Structure)3 ImageException (cbit.image.ImageException)2 BioModel (cbit.vcell.biomodel.BioModel)2 AnalyticSubVolume (cbit.vcell.geometry.AnalyticSubVolume)2 GeometrySpec (cbit.vcell.geometry.GeometrySpec)2 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)2 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)2