Showing posts with label EMF. Show all posts
Showing posts with label EMF. Show all posts

Thursday, July 19, 2018

[Building Information Modeling] IFC to Ecore Transformation

Introduction:

Building Information Modelling is, in the field of the construction industry, an approach to build semantically-rich 3-dimensional digital models instead of “plain old” CAD models to fulfill different needs of different stakeholders.
The most widely used standard for exchanging BIM models in the industry is defined by the Industry Foundation Classes (IFC). IFC is a standardized data model developed by different domain experts to enable interoperability within the Architecture, Engineering, Construction and Facility Management industries.

Problem Description:

Using IFC software products in research as well as in real projects presents certain challenges – it’s complex, hard to understand for the users and has some consistency issues during import and export of real-world building data.

Many of above mentioned issues can be addressed by transforming this IFC metamodel into a smaller, easier to understand and use model, as an instance of a common linguistic meta-model, such as Ecore. The advantage of an Ecore model is not only a new class diagram, but rather the ability to use a very broad set of Ecore functionalities, such as code, entity and api generation, as well as the ability to check models regarding their syntactical and semantical correctness.

Our project, the transformation to the Ecore Model is a part (step 2) of the bigger picture shown below

The bigger picture
The bigger pictur

We used the Atlas Transformation Language (ATL) for this transformation. 

IFC Structure:

In general, the IFC specification consists of four different Declaration types: 
  • Type Declarations 
  • Entity Declarations 
  • Function Declarations 
  • Rule Declarations 

We focused on the transformation of Type and Entity Declarations and handled the rest as simple EClass “name-only” stubs. 

Type Declarations are similar to "typedef" or "value type" in common programming languages, and refer to a basic information construct, derived from: 

  • an Enumeration
  • a primitive (String, Integer, Real, Boolean) - aka Concrete Type
  • a selector of entites of types - aka Select Types 


Entity Declarations are similar to the term "class", and describe data structures. They are built in the following way (in the express notation)

ENTITY (*Name*) 
    ABSTRACT SUPERTYPE OF (*Classes*); 
    SUBTYPE OF (*Classes*); 
    (*Declarations*); 
END_ENTITY;

Methodology:

The transformation will be shown using the example of the "IFCActuator" entity. The result of this transformation to Ecore looks the following:

IFCActuator
IFCActuator

Type Declarations

In this section we transform the three different types of Type Declarations.

Enumerations:
As you can see on the upper left side, the IFC Actuator contains some enumerations of type "IFCActuatorTypeEnum". Basically they are transformed to an EEnum using the following rule:

In Ecore an EEnum needs a name, which we transform by adding the corresponding IFC!Enum's classname, aswell as a value, which is incremented by 1 for every added Enumeration. 

Enumeration Transformation Rule
Enumeration Transformation Rule



Concrete Types:
Simple Types (for example String) are needed to be converted very often and are realized via helper functions. 

Simple Type Transformation Rule
Simple Type Transformation Rule


Select Types:
Select Types are  converted to eClasses with eAttributes or eReferences, or both, depending on the types declared in the "select_list.named_types", as shown below:

Select Type Transformation Rule

Entity Declarations:

Entities (for example the upper middle IFCActuator entity) are transformed to an EClass, containing a name, some eStructuralFeatures (for example attributes) aswell as an eSuperType for inheritance. 

Entity Transformation Rule


There are many different rules for transforming eStructuralFeatures, depending on the complexity of the underlying type, but in the most simple case, like in the IFCActuator the "PredefinedType", which is an IFC!AttributeSimple, the transformation rule looks the follwoing: 

Simple Attribute Transformation Rule
Simple Attribute Transformation Rule


Relations & Aggregations: 

Relations between entities (for example between IFCElement and IFCIdentifier), as well as aggregations are realized with the EReference class - below there is a transformation rule for a simple case:


Relations and Aggregation Transformation Rule


OCL-Annotations:

In IFC some parts that cannot be transformed to ECore. For example, there is a type declaration called IFCGloballyUniqueId, containing a String with a length that of exactly 22 characters.

TYPE IfcGloballyUniqueId = STRING(22) FIXED;
END_TYPE;

We handle this logic using additional OCL Annotations.
OCL Annotations
OCL Annotations


Results:

The transformation of the Express DML metamodell into the Ecore model is successful. The transformation of the whole IFC4.isoexpall model takes between 0.5 and 2 seconds. There are no missing entities and no errors or warnings in ATL. The resulting target model is a syntactical valid Ecore model.

Next Steps:

Even if the target model has no errors it’s not guaranteed that the model to model transformation is actually valid - ATL doesn’t offer this kind of checking-feature. Therefore the validity of the transformation still needed to be proven.


Friday, July 15, 2016

Automated Scoping, Validation and Quickfixes for xText based languages

By Christian Beikov, Raphael Löffler, Oliver Reiter and Christopher Schwarz.

Xtext is a language development framework and mostly used to create domain specific languages as well as to develop feature-rich editors. Model validation with error highlighting, scoping and quick fixes are also supported, but have to be implemented manually. Our project generates said features automatically based on OCL constraints, which are defined in the underlying model of the language. The goal is to reduce the amount of work creating textual editors for DSLs by following a model based approach. In cause of the fact that the whole work is based on Xtext, a big part of it was to explore Xtext to find possible solutions for integrating the described automated approach. Xtext is one part of the openArchitectureWare (oAW), which is framework for supporting model driven development. The possibility to not only create a new DSL, but also create automatically specified editors for this DSL makes Xtext very interesting. Another big part were our work is based on is the Object Constraint Language (OCL). OCL is a textual formal specification language and is part of the Unified Modeling Language. It is a declarative language and was introduced by the Object Management Group (OMG) to add the possibility of adding constraints to object-oriented models that can not be defined with standard diagrammatic notations.

Validation

For each class, which has OCL constraints defined, a validator is generated in Java, which also tries to find the erroneous feature of the object. These are further used in a custom implementation of AbstractDeclarativeValidator to be used in an Xtext editor. The improvement to the default validation is the localization of the error, which also enables the possibility to provide quickfixes. The pictures below show our implementation (Fig. 2.) in comparison to the default validator (Fig. 1.), which highlights the complete, invalid object.

Fig. 1. Error highlighting with default validators
Fig. 2. Error highlighting with OCL validators

Scoping

A scoping provider basically returns a set of objects, which can be used in a specific context. Therefore scoping rules have to be implemented manually, as the default provider only generates a scope with objects of a valid type. Our project tries to filter these by the OCL constraints of the context. To give an example, Fig. 4. shows the filtered scope in comparison to the unfiltered one (Fig. 3.). A constraint hereby is, that a page element, e.g. a text-field, can only refer to features contained in the handled entity of the form. In this example, this is Event. Another one in this example is, that a date-selection-field can only refer to attributes of the type Date and therefore the other elements are filtered out.

Fig. 3. Scope of the default validator
Fig. 4. Scope of the OCL based validator

Quickfixes

Quickfixes are provided by the editor, if an error is detected. For cross references, this is basically just the combination of validation and scoping, but for primitive data types, these have to be provided seperately. Our implementation detects the type of the erroneous feature and generates a fix at runtime in the validator. There is currently just one limitation: quickfixes are provided only for boolean values and cross references, but this functionality can easily be extended in the future.

Fig. 5. Quickfix of the OCL based provider

Future work

Of course there are some restrictions and limits of our implementation, which can be improved in future. Especially the generated Java code can be optimized in future. As mentioned our generated quickfixes currently support only boolean values. The code generation can be extended in future to also provide other types. Another way to extend our solution is to integrate all OCL operations. Currently we only implemented the most important ones to provide basic functionality of the implementation. These two extensions can be easily introduced by extending the implementation for the wanted functionality.


The source code of the project can be found on Github (https://github.com/Advanced-Model-Engineering-SS16/xtext-ocl-extensions).

Monday, June 30, 2014

Actions in EMF Profiles

Introduction

Since the Eclipse Modeling Framework (EMF) does not provide any native extension mechanism, the project EMF Profiles was invented as a solution for this problem. So called stereotypes can be used to extend and enrich meta-models. Once a stereotype is defined for a meta-model, it can be applied to models that conform to the respective meta-model. This mechanism, however, does not allow to extend models with additional semantic functionality (i.e., behavior), it only allows to annotate models and to add additional information to them.

The possibility to add semantic functionality to stereotypes in terms of stereotype actions enables developers to invoke the functionality of applied stereotypes in the context of annotated models in order to automate time-consuming and repetitive tasks automatically. Some usage examples include stereotypes and respective actions for model-to-code transformation (Entity Model to SQL, Entity Model to Annotated Java classes) or model-to-model transformation, for example pulling up members to super classes or automatically resolve conflicts in models that have conflict information attached in terms of stereotypes.

Our aim was to invent an easy-to-use extension mechanism for adding such semantic functionality to stereotypes in EMF Profiles.

Creating EMF Profile Actions

The first step is to add an implementation of the action functionality.
  1. Create a meta-model
  2. Create an EMF profile package including stereotypes and actions
  3. Implement and register action handlers

Using EMF Profile Actions

Once a profile is extended with actions, a modeler can take advantage of the provided functionality of the stereotypes.
  1. Create a model based on the meta-model
  2. Apply stereotypes using EMF profiles
  3. Execute actions of the applied stereotypes

Exemplary Use Case: ORM Mapper

For our example we want to create an Object-relational mapper (ORM). The generated function, an automatic creation of SQL code, will be minimal, due to demonstration purpose. In the next steps we create an EMF profile with an action and apply the profile to an existing model for executing the action.

Structure of our exemplary Use Case

Step 1

  1. For the meta-model Ecore can be reused as data modeling language.
  2. Next we have to create an EMF Profile "ORM_Mapper_EMFProfilePlugin" with the required annotations necessary to perform the ORM Mapper functionality including the definition of two stereotypes: Entity and Column. The stereotypes will be applied to EClass instances. The figure shows the finished EMF Profile model. Next we define the action CreateSQL, this action is now available for the whole EMF Profile Project and also requires an identifier. The action must be set in the properties of the desired stereotype, in our case the stereotype Entity.

    EMF Profile with Action CreateSQL

  3. In order to execute an action, a Java class has to implement the Action Handler interface in an Eclipse plug-in project, the "ORM_Mapper_ActionPlugin". It contains the code for the automatic generation of the SQL statements.

    Action Handler Class for generating SQL Code


    For the handler registration the extension point needs to be contributed so that the action identifier is bound to the handling class.
Extension Point with Action Handler Class and Action ID

Step 2

  1. In a further Eclipse instance with the registered EMF Profile, a model, the "ORM_Mapper_model", with a corresponding application of the defined EMF Profile from step 1 has to be created.
  2. The stereotypes can easily be applied through the tree-based Ecore editor.
  3. Model with applied Stereotpyes

  4. Now the option to execute our action is provided and are prompted to select from a list, after right-clicking our class "Dog".

    Available actions for the selected object

     The action has exported the create statements for our model into the "create" file.
Output of the create file


Links to the project:

GitHub-Repository: https://github.com/elexx/emf-profiles


Tuesday, October 01, 2013

How to apply EMF profiles to models

In a previous post, we demonstrated how to create EMF profiles based on the example of the famous library metamodel. Once we have created our profile, we want to apply them to corresponding models. In this post, we demonstrate step-by-step how this is done using EMF Profiles.

What we have so far

As shown in our previous post, we created a profile, named MyExtendedLibrary, for the library metamodel. In particular, we wanted to be able to store whether a book is an ebook and, if it is an ebook, in which format it is available (such as ePub or PDF). Additionally, we wanted to be able to annotate books with tags. Therefore, we created a profile containing two stereotypes EBook and TaggedBook, both applicable to instances of Book. The resulting profile is depicted below. Once we created this profile correctly (i.e., it is valid and contains no errors), it is automatically registered to the local profile registry; ready to be applied to library models.

Applying the profile

Assume we have a small library model, that is, an instance of the library metamodel, consisting of two books, named "My Book" and "Another Book". To apply our profile to this model, we first open the model in the Sample Reflective Ecore Editor, or in any other EMF-based modeling editor if available (e.g., a GMF-based editor).

Next, we open the Profile Application View using Window > Show View > Other... > EMF Profiles > EMF Profile Applications. Once the profile application view is visible, again select the library model to be annotated in the modeling editor. The profile application view will now detect automatically that we selected a modeling editor that is supported by EMF profiles and activates the buttons for creating new and loading existing profile applications (the button with the "window plus" icon and the button with the "green plus" icon) in the profile application view.

To create a new profile application, click the button with the "window plus" icon (it should say Apply Profile in the tool tip). This will open up a wizard in which we first have to select the location where we want to save the profile application information. Note that the additional information that is saved in profile applications is stored in a separate file. The extension of profile application files is pa.xmi. Select a location and a file name for the profile application file and click Next >.

In the next step, we choose the profile that we want to apply to the model. Therefore, the wizard lists all profiles that are available in the local profile registry. In this list, we may now select the MyExtendedLibrary profile and hit Finish.

The wizard now creates the empty profile application file for us and shows the profile application in the profile application view.

Now we can start applying stereotypes to our small library model. Therefore, we right-click the model element to which we want to apply a stereotype and select Apply Stereotype in the popup menu. Note that this command is only activated in the popup menu, if there is a stereotype available in the loaded profile that can be applied to the selected model element. In our example, this should be the case for all books that we have in our library model, since the MyExtendedLibrary profile contains two stereotypes that extend the class Book. So let us right-click the book My Book and click Apply Stereotype. This brings up a window in which we can select the stereotype to be applied; let us choose the stereotype <<EBook>> and click Ok.

The stereotype <<EBook>> is now applied to My Book. Thus, a new item indicating this stereotype application is added to the profile application view. Note that only those stereotype applications are shown in the view that are applied to the model element currently selected in the modeling editor (e.g., My Book). If you prefer to see all currently applied stereotypes in the currently loaded profile application file, irrespectively of which model element is selected, unselect the Pin View with Selected Element button in the profile application view.

Since we not only want to apply stereotypes, but also add additional information in terms of tagged values (attributes and references introduced by the stereotypes), we can now select the stereotype application in the profile application view and inspect the standard Eclipse Properties view. This properties view now shows all attributes and references of the applied stereotype; in our case this is for instance the format attribute, for which we can select the value PDF or EPUB, as specified in the MyExtendedLibrary profile. Note that we can apply both stereotypes in this profile only once for each book according to the specified multiplicity of the extension relationship (cf. MyExtendedLibrary profile).

Once we finished applying stereotypes, we can save the profile application by clicking the Save button in the profile application view and closing the modeling editor showing our library model. Of course, we can still load this profile application (or several at the same time) later. This is done by opening the library model and by clicking the Load Profile Application button (the one with the "green plus" icon). This brings up a wizard in which we select the profile application file to be loaded. Modifying the loaded profile application in terms of adding or deleting stereotype applications or modifying their attributes and references works similarly as with new profile applications.

The profile application file

One major advantage of EMF Profiles is that profile application files are common EMF models and, as a result, they can be processed with any EMF-based technology, such as model transformation tools, model-to-code generation frameworks, etc. So lets have a brief look at how these models look like.

Basically, profile application models consist of one container object of type Profile Application and a list of instances of the stereotypes that we applied to the respective model. The model element to which the stereotype has been applied is referred to through the reference appliedTo and the additional values (e.g., the format attribute of the EBook stereotype) are common EMF attributes or references. Loading profile applications as normal EMF models enables us to apply any processing techniques imaginable for common EMF models.

We hope you enjoyed reading this blog post and invite you to try EMF profiles for your needs. If you have any questions or comments, don't hesitate to contact us or post a comment below.

Friday, July 05, 2013

Developing exercises for “Model Engineering”

— by +Robert Bachmann, Martin Kerschberger, +Manuel Mertl, and +Thomas Wruss.

This blog post describes a project implemented in the context of the course “Advanced Model Engineering” in summer semester 2013. The results of the project consist of two parts. On the one hand we created a new exercise for students in the domain of model-driven engineering, and on the other hand we performed a practical evaluation of ATL against an imperative Xtend-based approach.

Model engineering exercise

The general structure of our exercise is based on the structure of the existing exercises that were used in previous instances of the course “Model Engineering”. Our exercise consists of three parts:
  1. Creation of two meta-models
    1. One meta-model for a PIM
    2. One meta-model for a PSM
  2. Model-to-model transformation from PIM to PSM using ATL
  3. Model-to-code transformation from PSM to executable code using Xtend

According to our intended workflow students solve each part in groups and receive a reference implementation of each part after the respective submission deadline. Therefore, we will avoid to publishing figures and code.

Our primary requirement for part 1 was that the PIM and PSM should not be too abstract but from already familiar to most students. Therefore, we chose a meta-model for questionnaires and surveys for part 1.1 (PIM), since most students are probably familiar with questionnaires and surveys. Since we can assume that all students are familiar with web forms, we chose a meta-model for simple web forms for part 1.2 (PSM).

Part 2 uses ATL to transform a questionnaire model into a simple web form model.

Part 3 uses Xtend to transform a simple web form model into an interactive HTML page. Since we do not want to assume that all students are proficient with CSS and JavaScript, we provide a re-usable CSS file and a small JavaScript library. This allows students to avoid boilerplate code and to focus on code generation.

The following screenshot shows an example of a simple generated questionnaire web page:


ATL versus an imperative Xtend-based approach

As mentioned above, we implemented a model-to-model transformation using ATL. The purpose of this transformation is to transfrom a questionnaire model into a simple web form model.

Additionaly we evaluated an imperative Xtend-based approach for model-to-model transformations. Our aim was to find out whether learning a DSL, in this case ATL, is really necessary or if a general-purpose programming language such as Xtend is sufficient. We chose Xtend since it is a modern general-purpose programming language. Since Xtend is Java-based we could leverage EMF’s features.

Xtend transformation infrastructure

Our Xtend-based transformation process consist of three steps:

  1. Model loading: The source model is loaded from disk.
  2. Model transformation: The target model is derived by applying a transformation method to the source model
  3. Model persistence: The target model is saved to disk.

In order to isolate the infrastructure code (step 1 and 3) from the actual model transformation we use the following approach: A transformation is modeled as class which extends the base class AbstractModelToModelTransformation (see source code). The base class is responsible for loading the source model and persisting the target model. The transformation method has to be provided by a concrete sub-class.

The following listing shows the complete implementation of an identity transformation:

Code examples

The following listing shows two ATL rules interspersed with their Xtend counterparts:

The first ATL rule on lines 2–8, is quite similar to its Xtend counterpart. The derivation of the values value and text on lines 5–6 is very similar to its Xtend counterpart on lines 12–13. The second rule on lines 17–22, is also similar to its Xtend counterpart. One noticeable exception is the derivation of the collection resultMessages on line 20 and the corresponding Xtend counterpart on line 26. Line 26 is more verbose since more explicit steps need to be performed to fit into Java’s type model.

Observations

  • ATL transformations tend to be shorter than Xtend transformations (in our case 160 versus 250 lines of code). Xtend (and Java) transformations in turn have the benefit that they use an imperative approach which is probably easier to comprehend for developers which are already familiar with Java.
  • Whereas the result of an ATL transformation is deterministic the execution order of ATL rules is not. By contrast, Xtend transformations follow the standard execution order semantics of a Java program. ATL’s approach would allow the ATL engine to execute multiple rules in parallel, whereas our Xtend transformation approach is strictly intended for non-parallel (single-threaded) execution. Although a multi-threaded Xtend transformation approach would be technically possible, we doubt that such a transformation could be implemented in a way that does not lack readability in comparison to a similar ATL transformation.
  • Both ATL and Xtend provide functional features, however, in a very different form. Most parts of an ATL transformation are functional in the sense that they are free of side effects. Imperative statements — statements with side effects — must be performed in designated areas of the code such as do-blocks. Therefore statements with side effects are easily recognizable by there location in the ATL source code file. By contrast, Xtend is an imperative object-oriented language that additionally provides some functional features. Therefore, there is no way to recognize statements with side-effects by looking for a certain keyword alone.

Monday, April 29, 2013

How to create an EMF Profile

Whenever you want to store additional information to EMF-based models and you cannot or don't want to change the respective metamodel, EMF Profiles provide a convenient solution for extending metamodels in a non-intrusive and lightweight manner; comparable to how UML profiles allow to extend UML. For extending a metamodel, all you have to do is to create a profile, which can then be applied to models in order to store the additional information you want to add to the original model. In the following, we show how profiles are created step by step.

Extending the library metamodel

For illustrating the process of creating a profile, we extend the well-known library example metamodel. This metamodel basically contains three classes: the class Library, Writer, and Book.

Now assume, we need to add additional information to library models without having to change the metamodel and, thus, without the need to re-generate the model-, edit-, and editor code. In particular, we want to be able to store whether a book is an ebook and, if it is an ebook, in which format it is available (such as ePub or PDF). Additionally, we want to be able to annotate books with tags.

Creating a profile project

To create a new profile project, we start the dedicated wizard for profile projects by selecting File > New > Other and select EMF Profile > EMF Profile Project.


After clicking Next, we enter a name for the profile project, as well as additional information about the profile, such as its name and its namespace URI. For the name and the namespace URI, it is recommendable to apply the same naming conventions as for metamodels.


After hitting the Finish button, the wizard creates the EMF profile project and opens the created empty EMF profile diagram, which has been initialized with the information provided in the wizard already, as can be seen in the Properties view.

Modeling the profile

A profile consists of stereotypes, which extend EClasses of metamodels. In our scenario, we want to store additional information to instances of the class Book of the library metamodel. Thus, we will create stereotypes that extend the class Book. Therefore, we first have to import the class Book. To do that, we use the popup menu (right-click the canvas of the profile diagram editor). In the popup menu, we now select Import Metamodel Element... and choose the extlibrary metamodel and, in the next step, the EClass Book. As a result, we obtain a shortcut to Book in our profile diagram canvas.



Now, we can start creating stereotypes using the palette in the profile diagram editor. To store whether a book (i.e., an instance of the class Book) is an ebook, we create the stereotype EBook. As we want to apply this stereotype to instances of Book, we create an Extension relationship from the created stereotype to the imported class Book. Extension relationships have a multiplicity (e.g., 0..1, 0..*, 2..4, etc.). This multiplicity specifies how often a stereotype can be (and must be) applied within one profile application to an instance of the extended class (e.g., Book). In our scenario, the stereotype EBook should not be mandatory, since we might have books that are not ebooks and, thus, should not be annotated with the stereotype EBook. Thus, we use a lower-bound multiplicity of 0. Further, it wouldn't make any sense to apply the stereotype EBook multiple times to the same book. To prohibit multiple applications, we set the upper-bound multiplicity to 1.


Stereotypes may carry additional data. One way to allow for adding additional data is to add tagged values to stereotypes. Since we want to store the format of an ebook, we add the tagged value named format to the stereotype EBook. Tagged values are basically attributes and can have primitive Ecore types, such as EString, EBoolean, ect., as well as custom EEnum types. We want to store whether an EBook is available in the format of EPUB or PDF; thus, we create a new EEnum named EBookFormat with two literals, EPUB and PDF, and set the type of the attribute format to EBookFormat.

Side note: Although this isn't needed in our example, stereotypes may, in general, also contain cross references to existing model elements (in the base model or in the profile application), as well as containment references (i.e., the stereotype application owns additional model elements). For creating references, just use the palette in the diagram editor and set the properties of the added reference accordingly. You can also use inheritance among stereotypes, if needed.

As mentioned above, we also want to be able to annotate books with tags. Therefore, we add another stereotype named TaggedBook, which also extends the class Book, and add a tagged value named tags of type EString to the created stereotype. To enable multiple tags for one book, we may set tags to be multi-valued (i.e., an upper-bound of -1 in the properties of the tagged value) and/or set the multiplicity of the stereotype to be 0..*, which specifies that the stereotype TaggedBook may be applied arbitrarily often to one instance of a book.

Registered profiles

Having finished the profile, we may validate it and save it. If the profile is valid, it will be registered automatically to the local profile registry. You may inspect all currently registered profiles using the Registered EMF Profiles view, which can be added using Window > Show View > Other... > EMF Profiles > Registered EMF Profiles.


As can be seen in the screenshot above, the created profile has been registered correctly. Note that you can still modify your profile; it will be synchronized automatically with the local profile registry, as long as your profile is valid. If it is invalid, it will disappear from the registry until you fix the validation error.

Once your profile is available in the local registry you can apply it to models that conform to the extlibrary metamodel. This, however, will be covered in future posts... so make sure to stay tuned.