DiscoverLearnDocumentationGet OpenPLXSearch Contact

Concepts Fundamentals

This concepts page introduces the OpenPLX core workflow:

  • define models
  • declare typed attributes
  • instantiate and configure models
  • organize reusable structures

Minimal model

An openplx model is defined on root level in an .openplx file.

Let’s create an empty model.

MyFirstModel

MyFirstModel is a valid model, but it has no attributes defined, so it does not do very much.

Adding attributes

To add model attributes, we need to end the model name by a colon. And therefter add attributes indented by 4 spaces. The attribute type must be specified.

MyFirstModel:
    my_first_attribute is Real

Try:

1: Add the colon, but no attribute 2: Add the attrubute with name only 3: Try load the model above.

None of these three steps are valid. - What type of error do you get?

Error 1: Expected indented block and No model could be found Error 2: Expected an is keyword Error 3: Missing assignment MyFirstModel.my_first_attribute, owning model is not complete

For the model to be valid and therefore instantiable, values have to be set to all attributes. 3. above will therefore give you: Missing assignment MyFirstModel.my_first_attribute, owning model is not complete

Fixing the model

To make the model above valid, we may either specify a value for the attribute, or declare the attribute as optional

MyFirstModel:
    my_first_attribute is Real: 1.0
MyFirstModel:
    optional my_first_attribute is Real

Inheritance

OpenPLX models use single inheritance and traits.

Single inheritance

A model can inherit from another one, and therefore include all attributes of the parent model.

MySecondModel is MyFirstModel:
    my_second_attribute is Real: 2.0

Traits

If you like many models to share a set of attributes, you can define a reusable trait that can be used to inject a set of attributes.

trait ReusableAttributes:
    my_second_attribute is Real: 2.0
    my_third_attribute is Real: 3.0

This trait can then be used for any model, as long as it does not inject an attribute of an already existing name.

MyModelWithTraits is MyFirstModel:
    with ReusableAttributes

Which is valid, while:

MyModelWithTraits is MySecondModel:
    with ReusableAttributes

will give you an error: Symbol "my_second_attribute" already defined.

Expressions

Given the MyModelWithTraits with you have three variables that can be used to declare an axpression.

MyModelWithAnExpression is MyModelWithTraits:
    expression is Real: my_second_attribute + my_first_attribute - my_third_attribute
OpenPLX is a work in progress. This draft version will evolve with user feedback and experience. We welcome your input and collaboration.
X