use of cbit.vcell.model.Structure 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;
}
}
}
}
use of cbit.vcell.model.Structure 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.model.Structure in project vcell by virtualcell.
the class StructurePasteMappingPanel method initialize.
private void initialize() {
Structure structFrom = rsCopy.getFromStructure();
List<String> membranesTo = new ArrayList<>();
List<String> compartmentsTo = new ArrayList<>();
membranesTo.add(CHOOSE_STRUCT);
membranesTo.add(MAKE_NEW);
compartmentsTo.add(CHOOSE_STRUCT);
compartmentsTo.add(MAKE_NEW);
for (Structure struct : modelTo.getStructures()) {
if (struct == structTo) {
continue;
}
if (struct instanceof Membrane) {
membranesTo.add(struct.getName());
} else {
compartmentsTo.add(struct.getName());
}
}
for (Structure from : rsCopy.getStructuresArr()) {
if (from == structFrom) {
// skip the structure from where we copy, it's already mapped
continue;
}
JComboBox<String> comboTo = new JComboBox<>();
if (from instanceof Membrane) {
comboTo.setModel(new DefaultComboBoxModel(membranesTo.toArray()));
int index = membranesTo.indexOf(from.getName());
comboTo.setSelectedIndex(index >= 0 ? index : 0);
} else {
comboTo.setModel(new DefaultComboBoxModel(compartmentsTo.toArray()));
int index = compartmentsTo.indexOf(from.getName());
comboTo.setSelectedIndex(index >= 0 ? index : 0);
}
structureMap.put(from, comboTo);
comboTo.addActionListener(eventHandler);
}
JPanel structPanel = new JPanel();
// structPanel.setPreferredSize(new Dimension(220, 180));
structPanel.setLayout(new GridBagLayout());
// header
int gridy = 0;
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
// top, left, bottom, right
gbc.insets = new Insets(10, 10, 10, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(new JLabel("<html><b>Structures to Paste</b></html>"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.insets = new Insets(10, 10, 10, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
// gbc.fill = GridBagConstraints.HORIZONTAL;
structPanel.add(new JLabel("<html><b>Mapped to: </b></html>"), gbc);
// the first row shows the source and destination structures (not customizable)
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(1, 10, 1, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(new JLabel("<html>" + structFrom.getName() + "</html>"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.insets = new Insets(1, 12, 1, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(new JLabel("<html>" + structTo.getName() + "</html>"), gbc);
for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
// the first row shows the source and destination structures (not customizable)
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.insets = new Insets(1, 10, 2, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(new JLabel("<html>" + entry.getKey().getName() + "</html>"), gbc);
gbc = new GridBagConstraints();
gbc.gridx = 1;
gbc.gridy = gridy;
gbc.insets = new Insets(2, 10, 1, 10);
gbc.weightx = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(entry.getValue(), gbc);
}
gridy++;
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = gridy;
gbc.gridwidth = 4;
gbc.weightx = 1;
// fake cell used for filling all the vertical empty space
gbc.weighty = 1;
gbc.anchor = GridBagConstraints.WEST;
structPanel.add(new JLabel(""), gbc);
// JPanel issuesPanel = new JPanel();
// issuesPanel.setLayout(new BorderLayout());
// issuesPanel.add(issuesPane, BorderLayout.CENTER);
JScrollPane upper = new JScrollPane(structPanel);
upper.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
upper.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
JScrollPane lower = new JScrollPane(issuesPane);
lower.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
lower.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
setLayout(new BorderLayout());
JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, upper, lower);
splitPane.setOneTouchExpandable(true);
splitPane.setDividerLocation(150);
add(splitPane, BorderLayout.CENTER);
recalculateIssues();
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class StructurePasteMappingPanel method recalculateIssues.
private void recalculateIssues() {
String issues = "";
issueVector.clear();
Set<String> duplicateCheck = new HashSet<>();
duplicateCheck.add(structTo.getName());
for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
if (entry.getValue().getSelectedItem().equals(CHOOSE_STRUCT) || entry.getValue().getSelectedItem().equals(MAKE_NEW)) {
continue;
}
if (duplicateCheck.contains(entry.getValue().getSelectedItem())) {
String msg = "Multiple Structures to be Pasted are mapped to the same destination " + entry.getValue().getSelectedItem();
Issue issue = new Issue(modelTo, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.WARNING);
issueVector.add(issue);
issues += msg + "\n";
} else {
duplicateCheck.add((String) (entry.getValue().getSelectedItem()));
}
}
for (Map.Entry<Structure, JComboBox<String>> entry : structureMap.entrySet()) {
if (entry.getValue().getSelectedItem().equals(CHOOSE_STRUCT)) {
String msg = "Map each Structure to be Pasted to an existing Structure or create a new one";
Issue issue = new Issue(modelTo, issueContext, IssueCategory.CopyPaste, msg, Issue.Severity.ERROR);
issueVector.add(issue);
issues += msg + "\n";
break;
}
}
issuesPane.setText(issues);
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class ReactionCartoonTool method lineAction.
private void lineAction(ReactionStep reactionStart, Structure endStructure) throws Exception {
Structure startStructure = reactionStart.getStructure();
if (StructureUtil.reactionHereCanHaveParticipantThere(startStructure, endStructure)) {
// if reactionStart is a SimpleRxn OR FluxRxn without a product, add speciesContext as pdt
if ((reactionStart instanceof SimpleReaction) || ((reactionStart instanceof FluxReaction) && !reactionStart.hasProduct())) {
SpeciesContext speciesContext = getModel().createSpeciesContext(endStructure);
reactionStart.addProduct(speciesContext, 1);
positionShapeForObject(endStructure, speciesContext, edgeShape.getEnd());
}
if (((startStructure instanceof Feature && endStructure instanceof Feature) || (startStructure instanceof Membrane && endStructure instanceof Membrane)) && startStructure != endStructure) {
// ============ change kinetics to lumped or warn user ?????????
// reactionStart.setKinetics(new GeneralLumpedKinetics(reactionStart));
}
getReactionCartoon().notifyChangeEvent();
}
}
Aggregations