use of cbit.vcell.geometry.GeometryClass 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;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class SimulationContextDbDriver method getSimulationContextSQL.
/**
* getModel method comment.
*/
private SimulationContext getSimulationContextSQL(QueryHashtable dbc, Connection con, User user, KeyValue simContextKey) throws /*, ReactStepDbDriver reactStepDB*/
SQLException, DataAccessException, IllegalMappingException, PropertyVetoException {
SimulationContext simContext = null;
String sql;
Field[] f = { new cbit.sql.StarField(simContextTable), userTable.userid };
Table[] t = { simContextTable, userTable };
String condition = simContextTable.id.getQualifiedColName() + " = " + simContextKey + " AND " + simContextTable.ownerRef.getQualifiedColName() + " = " + userTable.id.getQualifiedColName();
sql = DatabasePolicySQL.enforceOwnershipSelect(user, f, t, (OuterJoin) null, condition, null, dbSyntax);
// System.out.println(sql);
Statement stmt = con.createStatement();
try {
ResultSet rset = stmt.executeQuery(sql);
if (rset.next()) {
simContext = simContextTable.getSimContext(dbc, con, user, rset, geomDB, modelDB, mathDescDB);
} else {
throw new ObjectNotFoundException("SimulationContext id=" + simContextKey + " not found for user '" + user + "'");
}
} finally {
stmt.close();
}
DataSymbolTable.table.populateDataSymbols(con, simContextKey, simContext.getDataContext(), user, simContext.getModel().getUnitSystem());
ArrayList<AnnotatedFunction> outputFunctionList = ApplicationMathTable.table.getOutputFunctionsSimcontext(con, simContextKey, dbSyntax);
if (outputFunctionList != null) {
OutputFunctionContext outputFnContext = simContext.getOutputFunctionContext();
outputFnContext.setOutputFunctions(outputFunctionList);
}
SimContextTable.table.readAppComponents(con, simContext, dbSyntax);
assignStimuliSQL(con, simContextKey, simContext);
assignStructureMappingsSQL(dbc, con, simContextKey, simContext);
assignSpeciesContextSpecsSQL(con, simContextKey, simContext);
assignReactionSpecsSQL(con, simContextKey, simContext);
for (GeometryClass gc : simContext.getGeometry().getGeometryClasses()) {
try {
StructureSizeSolver.updateUnitStructureSizes(simContext, gc);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
simContext.getGeometryContext().enforceHierarchicalBoundaryConditions(simContext.getModel().getStructureTopology());
simContext.getModel().refreshDependencies();
assignAnalysisTasksSQL(con, simContextKey, simContext);
// really needed to calculate MembraneMapping parameters that are not stored (inside/outside flux correction factors).
simContext.refreshDependencies();
return simContext;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class StructureMappingTableModel method updateSubdomainComboBox.
@SuppressWarnings({ "rawtypes", "unchecked" })
private void updateSubdomainComboBox() {
GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
DefaultComboBoxModel aModel = new DefaultComboBoxModel();
for (GeometryClass gc : geometryClasses) {
aModel.addElement(gc);
}
JComboBox subdomainComboBoxCellEditor = new JComboBox();
subdomainComboBoxCellEditor.setRenderer(new DefaultListCellRenderer() {
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
setHorizontalTextPosition(SwingConstants.LEFT);
if (value instanceof GeometryClass) {
GeometryClass gc = (GeometryClass) value;
setText(gc.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);
}
}
return this;
}
});
subdomainComboBoxCellEditor.setModel(aModel);
ownerTable.getColumnModel().getColumn(SPATIAL_COLUMN_SUBDOMAIN).setCellEditor(new DefaultCellEditor(subdomainComboBoxCellEditor));
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class SimulationContext method copySimulationContext.
public static SimulationContext copySimulationContext(SimulationContext srcSimContext, String newSimulationContextName, boolean bSpatial, Application simContextType) throws java.beans.PropertyVetoException, ExpressionException, MappingException, GeometryException, ImageException {
Geometry newClonedGeometry = new Geometry(srcSimContext.getGeometry());
newClonedGeometry.precomputeAll(new GeometryThumbnailImageFactoryAWT());
// if stoch copy to ode, we need to check is stoch is using particles. If yes, should convert particles to concentraton.
// the other 3 cases are fine. ode->ode, ode->stoch, stoch-> stoch
SimulationContext destSimContext = new SimulationContext(srcSimContext, newClonedGeometry, simContextType);
if (srcSimContext.getApplicationType() == Application.NETWORK_STOCHASTIC && !srcSimContext.isUsingConcentration() && simContextType == Application.NETWORK_DETERMINISTIC) {
try {
destSimContext.convertSpeciesIniCondition(true);
} catch (MappingException e) {
e.printStackTrace();
throw new java.beans.PropertyVetoException(e.getMessage(), null);
}
}
if (srcSimContext.getGeometry().getDimension() > 0 && !bSpatial) {
// copy the size over
destSimContext.setGeometry(new Geometry("nonspatial", 0));
StructureMapping[] srcStructureMappings = srcSimContext.getGeometryContext().getStructureMappings();
StructureMapping[] destStructureMappings = destSimContext.getGeometryContext().getStructureMappings();
for (StructureMapping destStructureMapping : destStructureMappings) {
for (StructureMapping srcStructureMapping : srcStructureMappings) {
if (destStructureMapping.getStructure() == srcStructureMapping.getStructure()) {
if (srcStructureMapping.getUnitSizeParameter() != null) {
Expression sizeRatio = srcStructureMapping.getUnitSizeParameter().getExpression();
GeometryClass srcGeometryClass = srcStructureMapping.getGeometryClass();
GeometricRegion[] srcGeometricRegions = srcSimContext.getGeometry().getGeometrySurfaceDescription().getGeometricRegions(srcGeometryClass);
if (srcGeometricRegions != null) {
double size = 0;
for (GeometricRegion srcGeometricRegion : srcGeometricRegions) {
size += srcGeometricRegion.getSize();
}
destStructureMapping.getSizeParameter().setExpression(Expression.mult(sizeRatio, new Expression(size)));
}
}
break;
}
}
}
// If changing spatial to non-spatial
// set diffusion to 0, velocity and boundary to null
// srcSimContext.getReactionContext().getspe
Parameter[] allParameters = destSimContext.getAllParameters();
if (allParameters != null && allParameters.length > 0) {
for (int i = 0; i < allParameters.length; i++) {
if (allParameters[i] instanceof SpeciesContextSpecParameter) {
SpeciesContextSpecParameter speciesContextSpecParameter = (SpeciesContextSpecParameter) allParameters[i];
int role = speciesContextSpecParameter.getRole();
if (role == SpeciesContextSpec.ROLE_DiffusionRate) {
speciesContextSpecParameter.setExpression(new Expression(0));
} else if (role == SpeciesContextSpec.ROLE_BoundaryValueXm || role == SpeciesContextSpec.ROLE_BoundaryValueXp || role == SpeciesContextSpec.ROLE_BoundaryValueYm || role == SpeciesContextSpec.ROLE_BoundaryValueYp || role == SpeciesContextSpec.ROLE_BoundaryValueZm || role == SpeciesContextSpec.ROLE_BoundaryValueZp) {
speciesContextSpecParameter.setExpression(null);
} else if (role == SpeciesContextSpec.ROLE_VelocityX || role == SpeciesContextSpec.ROLE_VelocityY || role == SpeciesContextSpec.ROLE_VelocityZ) {
speciesContextSpecParameter.setExpression(null);
}
}
}
}
}
destSimContext.fixFlags();
destSimContext.setName(newSimulationContextName);
return destSimContext;
}
use of cbit.vcell.geometry.GeometryClass in project vcell by virtualcell.
the class SimulationContext method isPDERequired.
/**
* Insert the method's description here.
* Creation date: (8/8/01 3:46:23 PM)
* @param speciesContext cbit.vcell.model.SpeciesContext
* @return boolean
*/
public boolean isPDERequired(SpeciesContext speciesContext) {
//
// compartmental models never need diffusion
//
int dimension = getGeometryContext().getGeometry().getDimension();
if (dimension == 0) {
return false;
}
StructureMapping structureMapping = getGeometryContext().getStructureMapping(speciesContext.getStructure());
GeometryClass geometryClass = structureMapping.getGeometryClass();
if (geometryClass instanceof SubVolume) {
if (dimension < 1) {
return false;
}
} else if (geometryClass instanceof SurfaceClass) {
if (dimension < 2) {
return false;
}
} else {
throw new RuntimeException("structure " + speciesContext.getStructure().getName() + " not mapped, or unsupported GeometryClass " + geometryClass);
}
//
// check speciesContext needs diffusion/advection
//
SpeciesContextSpec scs = getReactionContext().getSpeciesContextSpec(speciesContext);
if (scs.isDiffusing() || scs.isAdvecting()) {
return true;
}
return false;
}
Aggregations