Search in sources :

Example 1 with SpatialProcessParameterType

use of cbit.vcell.mapping.spatial.processes.SpatialProcess.SpatialProcessParameterType in project vcell by virtualcell.

the class XmlReader method getSpatialProcesses.

public SpatialProcess[] getSpatialProcesses(SimulationContext simContext, Element spatialProcessesElement) throws XmlParseException {
    Iterator<Element> spatialProcessElementIterator = spatialProcessesElement.getChildren(XMLTags.SpatialProcessTag, vcNamespace).iterator();
    ArrayList<SpatialProcess> spatialProcessList = new ArrayList<SpatialProcess>();
    while (spatialProcessElementIterator.hasNext()) {
        Element spatialProcessElement = (Element) spatialProcessElementIterator.next();
        SpatialProcess spatialProcess = null;
        String name = unMangle(spatialProcessElement.getAttributeValue(XMLTags.NameAttrTag));
        String type = unMangle(spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessTypeAttrTag));
        if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointKinematics)) {
            PointKinematics pointKinematics = new PointKinematics(name, simContext);
            String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
            PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
            pointKinematics.setPointObject(pointObject);
            spatialProcess = pointKinematics;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_PointLocation)) {
            PointLocation pointLocation = new PointLocation(name, simContext);
            String pointObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessPointObjectAttrTag);
            PointObject pointObject = (PointObject) simContext.getSpatialObject(pointObjectName);
            pointLocation.setPointObject(pointObject);
            spatialProcess = pointLocation;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_SurfaceKinematics)) {
            SurfaceKinematics surfaceKinematics = new SurfaceKinematics(name, simContext);
            String surfaceRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessSurfaceObjectAttrTag);
            SurfaceRegionObject surfaceRegionObject = (SurfaceRegionObject) simContext.getSpatialObject(surfaceRegionObjectName);
            surfaceKinematics.setSurfaceRegionObject(surfaceRegionObject);
            spatialProcess = surfaceKinematics;
        } else if (type.equals(XMLTags.SpatialProcessTypeAttrValue_VolumeKinematics)) {
            VolumeKinematics volumeKinematics = new VolumeKinematics(name, simContext);
            String volumeRegionObjectName = spatialProcessElement.getAttributeValue(XMLTags.SpatialProcessVolumeObjectAttrTag);
            VolumeRegionObject volumeRegionObject = (VolumeRegionObject) simContext.getSpatialObject(volumeRegionObjectName);
            volumeKinematics.setVolumeRegionObject(volumeRegionObject);
            spatialProcess = volumeKinematics;
        }
        // set parameters
        Iterator<Element> paramElementIter = spatialProcessElement.getChildren(XMLTags.ParameterTag, vcNamespace).iterator();
        ArrayList<LocalParameter> parameters = new ArrayList<LocalParameter>();
        while (paramElementIter.hasNext()) {
            Element paramElement = paramElementIter.next();
            // Get parameter attributes
            String paramName = paramElement.getAttributeValue(XMLTags.NameAttrTag);
            Expression exp = unMangleExpression(paramElement.getText());
            String roleStr = paramElement.getAttributeValue(XMLTags.ParamRoleAttrTag);
            SpatialProcessParameterType parameterType = SpatialProcessParameterType.fromRoleXmlName(roleStr);
            VCUnitDefinition unit = simContext.getModel().getUnitSystem().getInstance_TBD();
            String unitSymbol = paramElement.getAttributeValue(XMLTags.VCUnitDefinitionAttrTag);
            if (unitSymbol != null) {
                unit = simContext.getModel().getUnitSystem().getInstance(unitSymbol);
            }
            parameters.add(spatialProcess.createNewParameter(paramName, parameterType, exp, unit));
        }
        try {
            spatialProcess.setParameters(parameters.toArray(new LocalParameter[0]));
        } catch (PropertyVetoException | ExpressionBindingException e) {
            e.printStackTrace();
            throw new XmlParseException("failed to read parameters in bioEvent " + name + ": " + e.getMessage(), e);
        }
        spatialProcessList.add(spatialProcess);
    }
    return spatialProcessList.toArray(new SpatialProcess[0]);
}
Also used : VolumeRegionObject(cbit.vcell.mapping.spatial.VolumeRegionObject) PointLocation(cbit.vcell.mapping.spatial.processes.PointLocation) SurfaceKinematics(cbit.vcell.mapping.spatial.processes.SurfaceKinematics) VolumeKinematics(cbit.vcell.mapping.spatial.processes.VolumeKinematics) Element(org.jdom.Element) ArrayList(java.util.ArrayList) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) LocalParameter(cbit.vcell.mapping.ParameterContext.LocalParameter) PropertyVetoException(java.beans.PropertyVetoException) VCUnitDefinition(cbit.vcell.units.VCUnitDefinition) PointObject(cbit.vcell.mapping.spatial.PointObject) Expression(cbit.vcell.parser.Expression) SpatialProcess(cbit.vcell.mapping.spatial.processes.SpatialProcess) PointKinematics(cbit.vcell.mapping.spatial.processes.PointKinematics) SpatialProcessParameterType(cbit.vcell.mapping.spatial.processes.SpatialProcess.SpatialProcessParameterType) SurfaceRegionObject(cbit.vcell.mapping.spatial.SurfaceRegionObject)

Aggregations

LocalParameter (cbit.vcell.mapping.ParameterContext.LocalParameter)1 PointObject (cbit.vcell.mapping.spatial.PointObject)1 SurfaceRegionObject (cbit.vcell.mapping.spatial.SurfaceRegionObject)1 VolumeRegionObject (cbit.vcell.mapping.spatial.VolumeRegionObject)1 PointKinematics (cbit.vcell.mapping.spatial.processes.PointKinematics)1 PointLocation (cbit.vcell.mapping.spatial.processes.PointLocation)1 SpatialProcess (cbit.vcell.mapping.spatial.processes.SpatialProcess)1 SpatialProcessParameterType (cbit.vcell.mapping.spatial.processes.SpatialProcess.SpatialProcessParameterType)1 SurfaceKinematics (cbit.vcell.mapping.spatial.processes.SurfaceKinematics)1 VolumeKinematics (cbit.vcell.mapping.spatial.processes.VolumeKinematics)1 Expression (cbit.vcell.parser.Expression)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 VCUnitDefinition (cbit.vcell.units.VCUnitDefinition)1 PropertyVetoException (java.beans.PropertyVetoException)1 ArrayList (java.util.ArrayList)1 Element (org.jdom.Element)1