Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

VIATRA2/Basics

< VIATRA2
Revision as of 12:32, 16 June 2008 by Rath.mit.bme.hu (Talk | contribs) (Model space wizard)

VIATRA2 Basics

Basic concepts

Model space

VIATRA2 is a model transformation engine which can be used to manipulate abstract models (software, architecture, domain-specific) by creating model-to-model and model-to-code transformations. VIATRA2 stores models in the VIATRA2 Model Space, supports the uniform representation of metamodels and models in a single logical container (as opposed to EMF where metamodels and models are separated), using an arbitrary number of metamodeling levels.

Transformations

Model-to-model and model-to-code transformations are specified using the VIATRA2 Transformation Language (VTCL) which is a textual domain-specific programming language tailored for this specific task. TODO

Model import and export

VIATRA2 supports the programmatic import of metamodels and models from other tools using an Application Programming Interface (API).TODO Model exports are supported using (i) code generation, or (ii) the VIATRA2 modeling API accessible from any Java program.

Simple examples

First steps

Model space wizard

In order to begin working with VIATRA2, you'll first need to create a model space instance to store your models.

  1. Create a new project in Eclipse. The project can be of any type.
  2. In the project, create a new file (right click|new|other).
  3. In the wizard, select "VIATRA2 VPM Model space" from the "VIATRA2 Framework Release3" category.
  4. Specify the file name and click Next (not Finish).
  5. On the modelspace fragments selection screen, select "VPM Core and Datatypes metamodel".
  6. Click Finish.
Fig.1 New Modelspace Wizard

Once the wizard is finished, you should have the new VPML file in your project. VPML files are XML serializations of the VIATRA2 model space, you can have any number of VPML files open at the same time, meaning that you can work with multiple model spaces concurrently.

Model space editor and VIATRA2 views

Double-click the newly created VPML file to open the VIATRA2 model editor (or select Open With|VIATRA2 model editor from the context menu). You should also open the VIATRA2 model spaces view (Window|Show view|Other|VIATRA2 Model spaces) and the VIATRA2 Textual Output view to get the basic home screen:

VIATRA2 Screen 0.png

Editing models with the editor

You can browse around the model space using the tree viewer. It is also practical to open the Properties view to see and edit the properties of model elements. The editor supports creating and deleting elements through the context menu. You can double click on any element to edit its name.

The basic elements in VIATRA2 are entities and relations. Entites represent graph nodes which relations represent graph edges. You can define instanceOf, superTypeOf relations between them (multi-level metamodeling). Entities are arranged into hierarchical name spaces which is displayed in the tree view of the model editor.

The Properties view uses the Fully Qualified names of elements for manipulation. FQNs are generated from the hierarchy, the FQN of a relation is the FQN of its source + the name of the relation (separated with a dot). If you enter an invalid FQN, the properties view will not save your changes.

You can save your model with Ctrl+S (File|Save) or File|Save as.

Creating a simple model

There is two ways to create a simple model in VIATRA2:

  1. Manual editing with the model editor;
  2. Using the textual modeling language (VTML) and importing it into the model space.

For this example, we'll use Option 2.

  • Create a new file in your project and enter "test.vtml" as the file name (File|New|File).
  • Double click the file and enter the following:
entity(Test)
{
	entity(A);
	entity(B);
	relation(R,A,B);
}

This defines a simple model in the "Test" namespace, with two nodes (A,B) and a relation R between them.

  • Save the file, and using drag-and-drop, drop the VTML file onto the "modelspace1" entry in the VIATRA2 Model spaces view.

VIATRA2 Editor Screen2.png

The Hello World transformation

  • Create a new file in your project, name it "helloworld.vtcl".
  • Double click on the file, the VTCL editor will open.
  • Enter the following:
namespace test;
machine hello
{
	rule main() = seq
	{
		println("Hello VIATRA2 world!");
	}
}
  • There are multiple possibilities to load this transformation into VIATRA2:
    • Drag-and-drop the VTCL file onto the "modelspace1" entry just like with model imports;
    • Simply save the file (Ctrl+S), it will be loaded.
    • If you have saved but performed another edit, pressing Alt+P (parse) will have the same effect as saving.
  • After the transformation is loaded, you can run the transformation by:
    • Pressing Alt+R in the editor (the editor has to have focus)
    • Double clicking on the (M) icon in the model spaces view
    • Right-click on the transformation in the model spaces view and select Run.

VIATRA2 Editor Screen 2.png

Advanced examples

Pattern matching

In this example, we'll construct a transformation which looks for pairs of entities (nodes) connected with a relation (edge) in the entire model space.

namespace test;
machine pm
{
	pattern connectedNodes(N1,N2) =
	{
		entity(N1);
		entity(N2);
		relation(R,N1,N2);
	}
	rule main() = seq
	{
		forall Src,Trg with find connectedNodes(Src,Trg) do
			println(fqn(Src) + " -> " + fqn(Trg));
	}
}

VIATRA2 Editor Screen 3.png

Model manipulation

In this example, we'll create an reverse relation (edge) found for each Source-Target pair.

namespace test;
machine pm
{
	pattern connectedNodes(N1,N2) =
	{
		entity(N1);
		entity(N2);
		relation(R,N1,N2);
	}
	rule main() = seq
	{
		forall Src,Trg with find connectedNodes(Src,Trg) do seq
		{
			println(fqn(Src) + " -> " + fqn(Trg));
			let NewR = undef in seq
			{
				new(relation(NewR,Trg,Src));
				rename(NewR,"reverse");
			}
		}
	}
}

VIATRA2 Editor Screen 4.png

On the screen, you can see the newly created relations in selection highlight.

Importing models to VIATRA2

Importing UML2 models

VIATRA2 supports model import for Eclipse UML2 models. This feature was developed and tested with using IBM Rational Software Architect 7.0, but (theoretically) it should also run for other UML tools providing UML2 export.

Now we provide a sample scenario how such UML2 models can be exported to VIATRA.

Exporting UML2 models from IBM Rational Software Architect 7.0

As the first step, your UML needs to be exported from IBM Rational Software Architect 7.0

  • Step 1: First, select the UML model in IBM RSA that you plan to export
    • Right-click on the selected project
    • Choose Export... from the pop-up menu

VIATRA2 RSA UML export 01.png

  • Step 2: Then select Other -> UML Model from the Export dialog

VIATRA2 RSA UML export 02.png

  • Step 3: Finally, choose the model you want to export and the destination directory.
    • Select Recreate IDs and deselect Export applied profiles (TODO: Check this)

VIATRA2 RSA UML export 03.png

Importing UML2 models to VIATRA2

  • Step 0: If you would like to import a UML2 model into an existing model space, then skip Step 1 below.
    • If your model space does not contain the UML2 metamodel (available at uml2.metamodel), then
      • Create a new model space as described below
      • Afterwards, merge the new model space with your existing one (TODO)
  • Step 1: Create a new model space (see above) but also select UML2.1 metamodel in the model space wizard

VIATRA2 UML metamodel import 01.png

  • Step 2: Right click on the designated model space (with the FW icon) in VIATRA2 Model spaces. Then select Native importers -> UML2 Importer (Rational Software Modeler 7.0)

VIATRA2 UML metamodel import 02.png

  • Step 3: Select the previously exported UML2 model, and click on Open

You should find your UML2 model below uml2.models in the tree view editor of the corresponding model space.

Back to the top