use of cbit.vcell.units.VCUnitDefinition 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.units.VCUnitDefinition in project vcell by virtualcell.
the class DataSymbolTable method populateDataSymbols.
public void populateDataSymbols(Connection con, KeyValue simContextRef, DataContext dataContext, User simcontextOwner, VCUnitSystem unitSystem) throws SQLException, DataAccessException {
Statement stmt = null;
try {
HashMap<BigDecimal, ExternalDataIdentifier> extDataIDHashMap = new HashMap<BigDecimal, ExternalDataIdentifier>();
stmt = con.createStatement();
ResultSet rset = stmt.executeQuery("SELECT * FROM " + ExternalDataTable.table.getTableName() + " WHERE " + ExternalDataTable.table.ownerRef.getUnqualifiedColName() + " = " + simcontextOwner.getID().toString());
while (rset.next()) {
BigDecimal extdataIDBigDec = rset.getBigDecimal(ExternalDataTable.table.id.getUnqualifiedColName());
ExternalDataIdentifier extdataID = new ExternalDataIdentifier(new KeyValue(extdataIDBigDec), simcontextOwner, rset.getString(ExternalDataTable.table.externalDataName.getUnqualifiedColName()));
extDataIDHashMap.put(extdataIDBigDec, extdataID);
}
rset.close();
rset = stmt.executeQuery("SELECT * FROM " + DataSymbolTable.table.getTableName() + " WHERE " + DataSymbolTable.table.simContextRef.getUnqualifiedColName() + " = " + simContextRef.toString());
while (rset.next()) {
String nextDataSymbolName = rset.getString(DataSymbolTable.table.dataSymbolName.toString());
String nextDataSymbolTypeS = rset.getString(DataSymbolTable.table.dataSymbolType.toString());
DataSymbolType nextDataSymbolType = DataSymbolType.valueOf(nextDataSymbolTypeS);
String nextDataSymbolVCUnitDefS = rset.getString(DataSymbolTable.table.dataSymbolVCUnitDef.toString());
nextDataSymbolVCUnitDefS = TokenMangler.getSQLRestoredString(nextDataSymbolVCUnitDefS);
VCUnitDefinition nextVCUnitDefinition = unitSystem.getInstance(nextDataSymbolVCUnitDefS);
// FieldDataSymbol (ExternalDataIdentifier) - (only data symbol defined right now)
BigDecimal extDataBigDecimal = rset.getBigDecimal(DataSymbolTable.table.fieldDataRef.getUnqualifiedColName());
ExternalDataIdentifier nextExtDataID = null;
if (!rset.wasNull()) {
nextExtDataID = extDataIDHashMap.get(extDataBigDecimal);
if (nextExtDataID == null) {
throw new DataAccessException("PopulateDataSymbols extdataID " + extDataBigDecimal + " not found in database for user " + simcontextOwner.getName());
}
String nextFieldDataVarName = rset.getString(DataSymbolTable.table.fieldDataVarName.getUnqualifiedColName());
String nextFieldDataVarType = rset.getString(DataSymbolTable.table.fieldDataVarType.getUnqualifiedColName());
double nextFieldDataVarTime = rset.getDouble(DataSymbolTable.table.fieldDataVarTime.getUnqualifiedColName());
FieldDataSymbol fieldDataSymbol = new FieldDataSymbol(nextDataSymbolName, nextDataSymbolType, dataContext, nextVCUnitDefinition, nextExtDataID, nextFieldDataVarName, nextFieldDataVarType, nextFieldDataVarTime);
dataContext.addDataSymbol(fieldDataSymbol);
} else {
throw new DataAccessException("DataSymbol has no ExternalDataIdentifier");
}
}
} finally {
if (stmt != null) {
stmt.close();
}
}
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class ModelUnitConverter method convertVarsWithUnitFactors.
private static void convertVarsWithUnitFactors(SymbolTable oldSymbolTable, SymbolTable newSymbolTable, Parameter parameter) throws ExpressionException {
// get old unit
VCUnitDefinition oldExprUnit = null;
Parameter oldParameter = (Parameter) oldSymbolTable.getEntry(parameter.getName());
if (oldParameter == null) {
System.err.println("parameter " + parameter.getName() + " was not found in the old symbol table");
} else if (oldParameter.getUnitDefinition() == null) {
System.err.println("parameter " + parameter.getName() + " has a null unit in old model, can't convert");
} else {
oldExprUnit = oldParameter.getUnitDefinition();
}
// get new unit
VCUnitDefinition newExprUnit = null;
if (parameter.getUnitDefinition() == null) {
System.err.println("parameter " + parameter.getName() + " has a null unit in new model, can't convert");
} else {
newExprUnit = parameter.getUnitDefinition();
}
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldExprUnit, newExprUnit, parameter.getExpression());
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class ModelUnitConverter method createBioModelWithNewUnitSystem.
public static BioModel createBioModelWithNewUnitSystem(BioModel oldBioModel, ModelUnitSystem newUnitSystem) throws ExpressionException, XmlParseException {
// new BioModel has new unit system applied to all built-in units ... but expressions still need to be corrected (see below).
BioModel newBioModel = XmlHelper.cloneBioModelWithNewUnitSystem(oldBioModel, newUnitSystem);
Model newModel = newBioModel.getModel();
Model oldModel = oldBioModel.getModel();
for (Parameter p : newBioModel.getModel().getModelParameters()) {
convertVarsWithUnitFactors(oldBioModel.getModel(), newBioModel.getModel(), p);
}
for (ReactionStep reactionStep : newBioModel.getModel().getReactionSteps()) {
SymbolTable oldSymbolTable = oldBioModel.getModel().getReactionStep(reactionStep.getName());
SymbolTable newSymbolTable = reactionStep;
for (Parameter p : reactionStep.getKinetics().getUnresolvedParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
for (Parameter p : reactionStep.getKinetics().getKineticsParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
}
for (ReactionRule reactionRule : newBioModel.getModel().getRbmModelContainer().getReactionRuleList()) {
SymbolTable oldSymbolTable = oldBioModel.getModel().getRbmModelContainer().getReactionRule(reactionRule.getName()).getKineticLaw().getScopedSymbolTable();
SymbolTable newSymbolTable = reactionRule.getKineticLaw().getScopedSymbolTable();
for (Parameter p : reactionRule.getKineticLaw().getUnresolvedParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
for (Parameter p : reactionRule.getKineticLaw().getLocalParameters()) {
convertVarsWithUnitFactors(oldSymbolTable, newSymbolTable, p);
}
}
for (SimulationContext simContext : newBioModel.getSimulationContexts()) {
SimulationContext oldSimContext = oldBioModel.getSimulationContext(simContext.getName());
// ArrayList<Parameter> parameterList = new ArrayList<Parameter>();
for (StructureMapping mapping : simContext.getGeometryContext().getStructureMappings()) {
Structure oldStructure = oldModel.getStructure(mapping.getStructure().getName());
StructureMapping oldMapping = oldSimContext.getGeometryContext().getStructureMapping(oldStructure);
for (Parameter p : mapping.computeApplicableParameterList()) {
convertVarsWithUnitFactors(oldMapping, mapping, p);
}
}
for (SpeciesContextSpec spec : simContext.getReactionContext().getSpeciesContextSpecs()) {
SpeciesContext oldSpeciesContext = oldModel.getSpeciesContext(spec.getSpeciesContext().getName());
SpeciesContextSpec oldSpec = oldSimContext.getReactionContext().getSpeciesContextSpec(oldSpeciesContext);
for (Parameter p : spec.computeApplicableParameterList()) {
convertVarsWithUnitFactors(oldSpec, spec, p);
}
}
for (int i = 0; i < simContext.getElectricalStimuli().length; i++) {
ElectricalStimulus newElectricalStimulus = simContext.getElectricalStimuli()[i];
ElectricalStimulus oldElectricalStimulus = oldSimContext.getElectricalStimuli()[i];
for (Parameter p : newElectricalStimulus.getParameters()) {
convertVarsWithUnitFactors(oldElectricalStimulus.getNameScope().getScopedSymbolTable(), newElectricalStimulus.getNameScope().getScopedSymbolTable(), p);
}
}
// convert events : trigger and delay parameters and event assignments
for (int i = 0; simContext.getBioEvents() != null && oldSimContext.getBioEvents() != null && i < simContext.getBioEvents().length; i++) {
BioEvent newBioEvent = simContext.getBioEvents()[i];
BioEvent oldBioEvent = oldSimContext.getBioEvent(newBioEvent.getName());
for (Parameter p : newBioEvent.getEventParameters()) {
convertVarsWithUnitFactors(oldBioEvent.getNameScope().getScopedSymbolTable(), newBioEvent.getNameScope().getScopedSymbolTable(), p);
}
// for each event assignment expression
for (int e = 0; e < newBioEvent.getEventAssignments().size(); e++) {
ScopedSymbolTable newSymbolTable = newBioEvent.getNameScope().getScopedSymbolTable();
ScopedSymbolTable oldSymbolTable = oldBioEvent.getNameScope().getScopedSymbolTable();
EventAssignment newEventAssignment = newBioEvent.getEventAssignments().get(e);
EventAssignment oldEventAssignment = oldBioEvent.getEventAssignments().get(e);
VCUnitDefinition oldTargetUnit = oldEventAssignment.getTarget().getUnitDefinition();
VCUnitDefinition newTargetUnit = newEventAssignment.getTarget().getUnitDefinition();
Expression eventAssgnExpr = newEventAssignment.getAssignmentExpression();
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, eventAssgnExpr);
}
}
/**
* @TODO: If rate rule variable unit is TBD, we still need to handle the rate expression unit.
*/
// convert rate rules
RateRule[] rateRules = simContext.getRateRules();
if (rateRules != null && rateRules.length > 0) {
for (RateRule rateRule : rateRules) {
RateRule oldRateRule = oldSimContext.getRateRule(rateRule.getName());
ScopedSymbolTable oldSymbolTable = oldRateRule.getSimulationContext();
ScopedSymbolTable newSymbolTable = rateRule.getSimulationContext();
VCUnitDefinition oldTargetUnit = oldRateRule.getRateRuleVar().getUnitDefinition();
VCUnitDefinition newTargetUnit = rateRule.getRateRuleVar().getUnitDefinition();
Expression rateRuleExpr = rateRule.getRateRuleExpression();
convertExprWithUnitFactors(oldSymbolTable, newSymbolTable, oldTargetUnit, newTargetUnit, rateRuleExpr);
}
}
}
// end for - simulationContext
return newBioModel;
}
use of cbit.vcell.units.VCUnitDefinition in project vcell by virtualcell.
the class ScrollTable method setAutoResizeMode.
@Override
public void setAutoResizeMode(int mode) {
super.setAutoResizeMode(mode);
if (autoResizeMode == AUTO_RESIZE_OFF) {
setDefaultRenderer(ScopedExpression.class, new ScopedExpressionTableCellRenderer());
setDefaultRenderer(VCUnitDefinition.class, new DefaultScrollTableCellRenderer() {
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 VCUnitDefinition) {
setText(((VCUnitDefinition) value).getSymbolUnicode());
}
return this;
}
});
if (componentListener == null) {
componentListener = new ComponentAdapter() {
public void componentResized(ComponentEvent e) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
ScopedExpressionTableCellRenderer.formatTableCellSizes(ScrollTable.this);
}
});
}
};
}
enclosingScrollPane.removeComponentListener(componentListener);
enclosingScrollPane.addComponentListener(componentListener);
} else {
if (componentListener != null) {
enclosingScrollPane.removeComponentListener(componentListener);
}
}
}
Aggregations