capellambse.pvmt package

Provides easy access to the Polarsys Capella PVMT extension.

The public API of this submodule uses raw LXML elements. For a more object oriented and user friendly way to access property values in a model, see the capellambse.model.MelodyModel class.

Submodules

capellambse.pvmt.core module

Core functionality shared by all PVMT submodules.

class capellambse.pvmt.core.Generic

Bases: object

Base class for PropertyValues, Domains etc.

__init__(xml_element, *args, **kwargs)
classmethod from_xml_element(element)

Construct an object from the given XML element.

This function is used to allow subclasses more control over how they are instantiated from existing XML elements, compared to creating them from scratch.

Parameters:

element (_Element)

Return type:

Generic

idx
name
sid
class capellambse.pvmt.core.XMLDictProxy

Bases: Generic, XMLDictProxy

Makes using XMLDictProxy with PVMT easier.

__init__(xml_element, *args, **kwargs)

Initialize the XMLDictProxy.

Parameters:
  • xml_element (_Element) – The underlying XML element.

  • childtag – The XML tag of handled child elements.

  • keyattr – The element attribute to use as dictionary key.

  • model – Reference to the original MelodyLoader. If not None, the loader will be informed about element creation and deletion.

Return type:

None

capellambse.pvmt.exceptions module

Exceptions that may be raised by the PVMT module.

exception capellambse.pvmt.exceptions.CastingError

Bases: PropertyValueError

A supplied value cannot be cast from or to the XML representation.

exception capellambse.pvmt.exceptions.GroupNotAppliedError

Bases: PropertyValueError, KeyError

The property value group has not been applied to this element.

exception capellambse.pvmt.exceptions.PropertyValueError

Bases: Exception

Base class for all property-value related errors.

exception capellambse.pvmt.exceptions.ScopeError

Bases: PropertyValueError

Attempted to apply a PV group to an element outside its scope.

exception capellambse.pvmt.exceptions.UndefinedKeyError

Bases: PropertyValueError, KeyError

A key is attempted to be added which is not defined for the group.

capellambse.pvmt.model module

Provides easy access to the Polarsys Capella PVMT extensions.

class capellambse.pvmt.model.Domain

Bases: XMLDictProxy

A PVMT Domain.

__init__(element, *args, parent=None, **kwargs)

Initialize the XMLDictProxy.

Parameters:
  • xml_element – The underlying XML element.

  • childtag – The XML tag of handled child elements.

  • keyattr – The element attribute to use as dictionary key.

  • model – Reference to the original MelodyLoader. If not None, the loader will be informed about element creation and deletion.

property groups

Return a list of all property value groups in this domain.

class capellambse.pvmt.model.Group

Bases: XMLDictProxy

PVMT Group.

__init__(*args, parent=None, **kwargs)

Initialize the XMLDictProxy.

Parameters:
  • xml_element – The underlying XML element.

  • childtag – The XML tag of handled child elements.

  • keyattr – The element attribute to use as dictionary key.

  • model – Reference to the original MelodyLoader. If not None, the loader will be informed about element creation and deletion.

classmethod from_xml_element(element)

Construct an object from the given XML element.

Parameters:

element (_Element)

Return type:

Group

parent: Any | None
property properties

Return a list of all properties defined in this group.

scope
class capellambse.pvmt.model.PVMTExtension

Bases: XMLDictProxy

Facilitates access to property values.

__init__(element, model=None)

Initialize the XMLDictProxy.

Parameters:
  • xml_element – The underlying XML element.

  • childtag – The XML tag of handled child elements.

  • keyattr – The element attribute to use as dictionary key.

  • model – Reference to the original MelodyLoader. If not None, the loader will be informed about element creation and deletion.

property domains

Return a list of all property value domains in the model.

get_element_pv(element, groupname, create=True)

Return the named PVMT group on element.

Parameters:
  • element – An LXML element with property value groups.

  • groupname – The fully qualified name of the property value group, in the format “domain.group”.

  • create – True to create (apply) the group if necessary.

Return type:

AppliedPropertyValueGroup

capellambse.pvmt.model.load_pvmt_from_model(model)

Load the Property Value management extension for the given model.

This function is the main entry point for the pvmt module. It should be called after constructing a MelodyLoader instance on the model file. It will return a PVMTExtension object, which can be used to easily access the property values of the model given during intialization.

capellambse.pvmt.types module

Classes that represent different property value types.

class capellambse.pvmt.types.AppliedPropertyValueGroup

Bases: XMLDictProxy

A group of applied property values.

__init__(pvmt_ext, *args, **kwargs)

Create an AppliedPropertyValueGroup.

Parameters:

pvmt_ext – The capellambse.pvmt.model.PVMTExtension object of the model.

classmethod applyto(pvmt_ext, xml_element, groupname)

Apply the named property value group to the given element.

Parameters:
  • pvmt_ext – The PVMT extension object

  • xml_element – The XML element of the target object

  • groupname – The fully qualified name of the PVMT group

Returns:

The newly created XML element, a child of xml_element.

Return type:

lxml.etree._Element

get_definition(key)

Return the PV definition instance for the given key.

class capellambse.pvmt.types.BooleanPropertyValue

Bases: GenericPropertyValue

A boolean property value.

static cast(value)

Cast the given string into an appropriate Python object.

classmethod serialize(value, element=None)

Serialize the given value into an XML string.

This function must be able to handle two types of input values:

  1. The type produced by .cast(), which shall be turned back into its XML form, so that it can be passed into .cast() again.

  2. The XML representation of a valid value, i.e. its own output.

If it is ambiguous which of the two types is being handled, the former shall be assumed.

Note that escaping of XML special characters is handled by the underlying XML library.

The default implementation works for the simple case where cast is a type constructor, but for more complex cases it should be overridden.

Parameters:
  • value – The value that should be serialized.

  • element – The XML element into which the value will be inserted. This may be used to construct links across fragment boundaries. This parameter may be None, in which case it is assumed that all elements exist within the same fragment.

class capellambse.pvmt.types.EnumerationPropertyType

Bases: XMLDictProxy

Maps the literals’ UUIDs to their human-readable values.

__init__(*args, **kwargs)

Initialize the XMLDictProxy.

Parameters:
  • xml_element – The underlying XML element.

  • childtag – The XML tag of handled child elements.

  • keyattr – The element attribute to use as dictionary key.

  • model – Reference to the original MelodyLoader. If not None, the loader will be informed about element creation and deletion.

property literals

Return a list of valid literal values for this enumeration.

class capellambse.pvmt.types.EnumerationPropertyValue

Bases: GenericPropertyValue

An enumeration property value.

__init__(*args, typedef=None, **kwargs)
static applyto(pvmt_ext, defelem, modelobj, targetelem)

Apply a property value to targetelem.

Parameters:
  • pvmt_ext – The PVMT Extension object.

  • defelem – The ownedPropertyValues element that should be applied.

  • modelobj – A model object’s XML element that will be a (direct or indirect) parent to this property value.

  • targetelem – The new ownedPropertyValues element.

cast(value)

Cast the given string into an appropriate Python object.

property default_value

Return this property’s default value.

property parent

Return the parent group of this property value.

serialize(value, element=None)

Serialize the given value into an XML string.

This function must be able to handle two types of input values:

  1. The type produced by .cast(), which shall be turned back into its XML form, so that it can be passed into .cast() again.

  2. The XML representation of a valid value, i.e. its own output.

If it is ambiguous which of the two types is being handled, the former shall be assumed.

Note that escaping of XML special characters is handled by the underlying XML library.

The default implementation works for the simple case where cast is a type constructor, but for more complex cases it should be overridden.

Parameters:
  • value – The value that should be serialized.

  • element – The XML element into which the value will be inserted. This may be used to construct links across fragment boundaries. This parameter may be None, in which case it is assumed that all elements exist within the same fragment.

property typedef

Return the type definition of this enumeration.

class capellambse.pvmt.types.FloatPropertyValue

Bases: GenericPropertyValue

A floating point property value.

cast

alias of float

property unit

Return the measurement unit of this property value.

class capellambse.pvmt.types.GenericPropertyValue

Bases: Generic

Base class for property value types.

__init__(*args, **kwargs)
static applyto(pvmt_ext, defelem, modelobj, targetelem)

Apply a property value to targetelem.

Parameters:
  • pvmt_ext – The PVMT Extension object.

  • defelem – The ownedPropertyValues element that should be applied.

  • modelobj – A model object’s XML element that will be a (direct or indirect) parent to this property value.

  • targetelem – The new ownedPropertyValues element.

abstract static cast(value)

Cast the given string into an appropriate Python object.

description
serialize(value, element=None)

Serialize the given value into an XML string.

This function must be able to handle two types of input values:

  1. The type produced by .cast(), which shall be turned back into its XML form, so that it can be passed into .cast() again.

  2. The XML representation of a valid value, i.e. its own output.

If it is ambiguous which of the two types is being handled, the former shall be assumed.

Note that escaping of XML special characters is handled by the underlying XML library.

The default implementation works for the simple case where cast is a type constructor, but for more complex cases it should be overridden.

Parameters:
  • value – The value that should be serialized.

  • element – The XML element into which the value will be inserted. This may be used to construct links across fragment boundaries. This parameter may be None, in which case it is assumed that all elements exist within the same fragment.

xtype
class capellambse.pvmt.types.IntegerPropertyValue

Bases: GenericPropertyValue

An integer property value.

cast

alias of int

property unit

Return the measurement unit of this property value.

class capellambse.pvmt.types.StringPropertyValue

Bases: GenericPropertyValue

A string property value.

cast

alias of str

capellambse.pvmt.types.select_property_loader(element)

Execute the appropriate loader for the PV definition element.

capellambse.pvmt.validation module

Validation functions for PVMT.

capellambse.pvmt.validation.validate_group_scope(pvmt_ext, groupdef, xml_element)

Verify that the groupdef’s scope applies to the given element.