use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class SpeciesPatternRoundShape method paintCompartment.
public void paintCompartment(Graphics g) {
Color structureColor = Color.black;
Structure structure = null;
if (owner instanceof ReactionRule && !speciesShapes.isEmpty()) {
ReactionRule rr = (ReactionRule) owner;
ReactantPattern rp = rr.getReactantPattern(sp);
ProductPattern pp = rr.getProductPattern(sp);
if (rp != null) {
structure = rp.getStructure();
} else if (pp != null) {
structure = pp.getStructure();
} else {
structure = ((ReactionRule) owner).getStructure();
}
} else if (owner instanceof SpeciesContext && ((SpeciesContext) owner).hasSpeciesPattern()) {
structure = ((SpeciesContext) owner).getStructure();
structureColor = Color.gray;
} else if (owner instanceof RbmObservable && !speciesShapes.isEmpty()) {
structure = ((RbmObservable) owner).getStructure();
} else {
// other things don't have structure
return;
}
if (structure == null) {
return;
}
// don't have a real structure, so we show them structureless (for now)
if (structure.getName() == null) {
return;
}
Graphics2D g2 = (Graphics2D) g;
Color colorOld = g2.getColor();
Paint paintOld = g2.getPaint();
Font fontOld = g2.getFont();
Font font;
// width of compartment shape, adjusted continuously based on zoom factor
int w;
String name = structure.getName();
int z = shapePanel.getZoomFactor();
if (z > -3) {
font = fontOld.deriveFont(Font.BOLD);
g.setFont(font);
w = 46 + 3 * z;
name = buildCompartmentName(g, name, "..", w);
} else if (z < LargeShapeCanvas.SmallestZoomFactorWithText) {
font = fontOld.deriveFont(fontOld.getSize2D() * 0.8f);
g.setFont(font);
w = 20;
name = buildCompartmentName(g, name, ".", w);
} else {
font = fontOld;
g.setFont(font);
w = 44 + 3 * z;
name = buildCompartmentName(g, name, "..", w);
}
// a bit darker for border
Color darker = Color.gray;
Rectangle2D border = new Rectangle2D.Double(xPos - 9, yPos - 4, w, 58);
g2.setColor(darker);
g2.draw(border);
Color lighter = new Color(224, 224, 224);
Rectangle2D filling = new Rectangle2D.Double(xPos - 9, yPos - 3, w, 57);
g2.setPaint(lighter);
g2.fill(filling);
g.setColor(structureColor);
g2.drawString(name, xPos - 4, yPos + 48);
g2.setFont(fontOld);
g2.setPaint(paintOld);
g2.setColor(colorOld);
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class StructureMappingCartoon method refreshAll.
@Override
public void refreshAll() {
{
if (getGeometryContext() == null || getGeometryContext().getGeometry() == null) {
return;
}
GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
if (geometryClasses == null) {
return;
}
for (int i = 0; i < geometryClasses.length; i++) {
Shape testShape = getShapeFromModelObject(geometryClasses[i]);
if (testShape instanceof GeometryClassLegendShape) {
geometryClasses[i].removePropertyChangeListener((GeometryClassLegendShape) testShape);
}
}
}
clearAllShapes();
if (getSimulationContext() == null) {
fireGraphChanged(new GraphEvent(this));
return;
}
GeometryContextGeometryShape geometryShape = new GeometryContextGeometryShape(this, getGeometryContext().getGeometry());
GeometryContextStructureShape structureContainerShape = new GeometryContextStructureShape(this, getGeometryContext().getModel());
GeometryContextContainerShape containerShape = new GeometryContextContainerShape(this, getGeometryContext(), structureContainerShape, geometryShape);
addShape(containerShape);
addShape(geometryShape);
addShape(structureContainerShape);
getGeometryContext().removePropertyChangeListener(this);
getGeometryContext().addPropertyChangeListener(this);
// create all StructureShapes
Structure[] structures = getGeometryContext().getModel().getStructures();
for (int i = 0; i < structures.length; i++) {
StructureMappingStructureShape smShape = new StructureMappingStructureShape((Structure) structures[i], getGeometryContext().getModel(), this);
addShape(smShape);
structureContainerShape.addChildShape(smShape);
structures[i].removePropertyChangeListener(this);
structures[i].addPropertyChangeListener(this);
}
// create all SubvolumeLegendShapes (for legend)
GeometryClass[] geometryClasses = getGeometryContext().getGeometry().getGeometryClasses();
for (int i = 0; i < geometryClasses.length; i++) {
GeometryClassLegendShape geometryClassLegendShape = new GeometryClassLegendShape(geometryClasses[i], getGeometryContext().getGeometry(), this, 10);
geometryClasses[i].addPropertyChangeListener(geometryClassLegendShape);
addShape(geometryClassLegendShape);
geometryShape.addChildShape(geometryClassLegendShape);
}
if ((subVolumeContainerShape == null) || (subVolumeContainerShape.getModelObject() != getGeometryContext().getGeometry())) {
subVolumeContainerShape = new SubVolumeContainerShape(getGeometryContext().getGeometry(), this);
}
subVolumeContainerShape.removeAllChildren();
subVolumeContainerShape.setBrightImage(getGeometryContext().getGeometry().getGeometrySpec().getThumbnailImage().getCurrentValue());
addShape(subVolumeContainerShape);
geometryShape.addChildShape(subVolumeContainerShape);
StructureMapping[] structureMappings = getGeometryContext().getStructureMappings();
for (int i = 0; i < structureMappings.length; i++) {
StructureMapping structureMapping = structureMappings[i];
structureMapping.removePropertyChangeListener(this);
structureMapping.addPropertyChangeListener(this);
if (structureMapping.getGeometryClass() != null) {
StructureShape sShape = (StructureShape) getShapeFromModelObject(structureMapping.getStructure());
GeometryClassLegendShape geometryClassLegendShape = (GeometryClassLegendShape) getShapeFromModelObject(structureMapping.getGeometryClass());
StructureMappingShape smShape = new StructureMappingShape(structureMapping, sShape, geometryClassLegendShape, this);
addShape(smShape);
containerShape.addChildShape(smShape);
}
}
// // assign children to shapes according to heirarchy in Model
// int nullParentCount=0;
// Collection<Shape> shapes = getShapes();
// for(Shape shape : shapes) {
// // for each featureShape, find corresponding featureShape
// if (shape instanceof StructureShape){
// StructureShape fs = (FeatureShape)shape;
// if(!structureContainerShape.contains(fs)) {
// structureContainerShape.addChildShape(fs);
// }
// nullParentCount++;
// }
// }
fireGraphChanged(new GraphEvent(this));
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class AllStructureSuite method getStructures.
public List<Structure> getStructures() {
if (bModelStructureOrder) {
ArrayList<Structure> modelStructures = new ArrayList<Structure>();
Diagram[] modelDiagrams = modelOwner.getModel().getDiagrams();
for (Diagram diagram : modelDiagrams) {
modelStructures.add(diagram.getStructure());
}
return modelStructures;
}
return Arrays.asList(StructureSorter.sortStructures(modelOwner.getModel()));
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class AbstractMathMapping method getDefaultGeometryClass.
protected GeometryClass getDefaultGeometryClass(Expression expr) throws ExpressionException, MappingException {
GeometryClass geometryClass = null;
if (simContext.getGeometry().getDimension() == 0) {
return null;
}
String[] symbols = expr.getSymbols();
// if expr has no symbols, model param cannot be localized to a domain (its a const).
if (symbols == null) {
return null;
} else {
Expression modelParamExpr = substituteGlobalParameters(expr);
symbols = modelParamExpr.getSymbols();
for (int k = 0; symbols != null && k < symbols.length; k++) {
Structure symbolStructure = null;
SymbolTableEntry ste = modelParamExpr.getSymbolBinding(symbols[k]);
if (ste instanceof SpeciesContext) {
symbolStructure = ((SpeciesContext) ste).getStructure();
} else if (ste instanceof StructureSize) {
symbolStructure = ((StructureSize) ste).getStructure();
} else if (ste instanceof MembraneVoltage) {
symbolStructure = ((MembraneVoltage) ste).getMembrane();
}
if (symbolStructure != null) {
StructureMapping sm = simContext.getGeometryContext().getStructureMapping(symbolStructure);
GeometryClass symbolGeomClass = sm.getGeometryClass();
if (geometryClass == null) {
geometryClass = symbolGeomClass;
} else {
if (geometryClass != symbolGeomClass) {
if (geometryClass instanceof SurfaceClass) {
if (symbolGeomClass instanceof SurfaceClass) {
throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & surface domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
} else if (symbolGeomClass instanceof SubVolume) {
// geomClass : surfaceClass; symbolGeomClass : subVol
if (!((SurfaceClass) geometryClass).isAdjacentTo((SubVolume) symbolGeomClass)) {
throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
}
} else {
throw new MappingException("unexpected geometry class : " + symbolGeomClass.getClass());
}
} else if (geometryClass instanceof SubVolume) {
// geometryClass is a SubVolume
if (symbolGeomClass instanceof SubVolume) {
// check if adjacent; if so, choose separating membrane.
SurfaceClass surfaceClass = simContext.getGeometry().getGeometrySurfaceDescription().getSurfaceClass((SubVolume) symbolGeomClass, (SubVolume) geometryClass);
if (surfaceClass != null) {
geometryClass = surfaceClass;
} else {
throw new MappingException("The expression '" + expr.infix() + "' references variables in volume domain '" + geometryClass.getName() + "' & volume domain '" + symbolGeomClass.getName() + "' that cannot be evaluated.");
}
} else {
// geomClass : subVol; symbolGeomClass = surfaceClass
SurfaceClass surfaceSymbolGeomClass = (SurfaceClass) symbolGeomClass;
if (!surfaceSymbolGeomClass.isAdjacentTo((SubVolume) geometryClass)) {
throw new MappingException("The expression '" + expr.infix() + "' references variables in surface domain '" + surfaceSymbolGeomClass.getName() + "' & volume domain '" + geometryClass.getName() + "' that cannot be evaluated.");
} else {
geometryClass = symbolGeomClass;
}
}
} else {
throw new MappingException("unexpected geometry class : " + geometryClass.getClass());
}
}
}
}
}
}
return geometryClass;
}
use of cbit.vcell.model.Structure in project vcell by virtualcell.
the class DiffEquMathMapping method computeBoundaryConditionSource.
// determine membrane inside and outside subvolume
public static Pair<SubVolume, SubVolume> computeBoundaryConditionSource(Model model, SimulationContext simContext, SurfaceClass surfaceClass) {
SubVolume outerSubVolume = null;
SubVolume innerSubVolume = null;
Structure[] mappedStructures = simContext.getGeometryContext().getStructuresFromGeometryClass(surfaceClass);
// inside and outside correspond to structure hierarchy when present
for (Structure s : mappedStructures) {
if (s instanceof Membrane) {
Membrane m = (Membrane) s;
Feature infeature = model.getStructureTopology().getInsideFeature(m);
if (infeature != null) {
FeatureMapping insm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(infeature);
if (insm.getGeometryClass() instanceof SubVolume) {
innerSubVolume = (SubVolume) insm.getGeometryClass();
}
}
Feature outfeature = model.getStructureTopology().getOutsideFeature(m);
if (outfeature != null) {
FeatureMapping outsm = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(outfeature);
if (outsm.getGeometryClass() instanceof SubVolume) {
outerSubVolume = (SubVolume) outsm.getGeometryClass();
}
}
}
}
// make the choice deterministic
if (innerSubVolume == null || outerSubVolume == null || innerSubVolume == outerSubVolume) {
Set<SubVolume> sv = surfaceClass.getAdjacentSubvolumes();
Iterator<SubVolume> iterator = sv.iterator();
innerSubVolume = iterator.next();
outerSubVolume = iterator.next();
if (innerSubVolume.getName().compareTo(outerSubVolume.getName()) > 0) {
SubVolume temp = innerSubVolume;
innerSubVolume = outerSubVolume;
outerSubVolume = temp;
}
}
Pair<SubVolume, SubVolume> ret = new Pair<>(innerSubVolume, outerSubVolume);
return ret;
}
Aggregations