“I am your container”, Darth Sirius

Continuing the Sirius blog posts series, today we will see a small tip: how to create artificial containers in your diagram?

One of the main advantage of Sirius is that the graphical representations are independent from the metamodel’s structure. This means that you can choose to not respect the containment hierarchy of your model when you display it graphically. This is possible thanks to Sirius being based on queries.

In the following example, we define a metamodel of a family:

To begin with, we define a Flat diagram, which displays all the members of the family at the same level:

In the Person mapping, we use the Semantic Candidates Expression to provide which semantic elements must be represented. These expressions returning model elements are called queries. To write these queries, there are different languages provided by default in Sirius: specialized interpreters (var, feature, service), Acceleo, raw OCL or Java. Here, we use the feature interpreter to get for a family all the persons referenced by the members reference. You can easily identify interpreted expressions by their yellow background in the Properties tab of an element.

We create a first diagram which represents the flattened Skywalker family:

The next step is to add a level to model the Family as a container. We create a new Family diagram which contains a Family container mapping and a Person mapping as sub nodes:

The Family diagram is created and all the members are represented inside the Skywalker container.

Here we represent graphically the containment reference members. But what to do if we want to create an artificial container which does not exist in the metamodel as a containment reference?

Let’s see! Now imagine that we want to add a level to represent The Force and if the person is related to the dark side or the light side. To do this we create a new ForceSide diagram:

We add a new container to represent the DarkSide of the force :

The dark side must be represented once for each family, the semantic candidate returns var:self which means the current family. As it should contain persons, it is defined as a FreeForm container.

We need to represent, in the Dark Side container, the persons that are from the dark side of the force. So we define a new sub node Person with the Semantic expression set to: [self.members->select(p|p.oclAsType(Person).dark)/]
This query returns all the members of a family and selects only the Person which has the attribute dark set to true.

Then we reuse the Person mapping to represent the person in its force side container.

Finally, we do the same for the light side of the force and we create a LightSide container and the Person mapping to represent members of the family in this new container who are influenced by the light side: [not self.members->select(p|p.oclAsType(Person).dark)/]
A new ForceSide diagram is created in the Skywalker family and we discover that only Darth Vader is from the dark side of the force and that his children are driven by the light side of the force.

Thanks to the queries in Sirius, it is easy to create artificial containers which are not related to containment referencers in the metamodel.

“May the Sirius Force be with you” ;)

The sample code from this example is available on github: https://github.com/mbats/sirius-blog/tree/master/artificial-container

 

Refine diagrams with interpolated colors

This article is part 4 of a series covering cool features of Sirius and tips to create advanced modelers. See http://melb.enix.org/category/sirius/ for the complete series.

Today we will present how diagrams can be refined to display information using interpolated colors.

Diagrams with meaningful colors

In your Viewpoint Specification Model (VSM), the specifier is not limited to use the provided colors but can define a palette with custom colors. A color can be defined using a RGB code (Red/Green/Blue).

However, using this new color in a mapping will paint every mapping candidates to this color. As our goal is giving colors a meaning, it needs to be defined by an expression. Sirius provides two solutions: Computed Colors and Interpolated Colors.

Note that RGB codes are defined with three integer values between 0 and 255. If the value is over 255, Sirius will use it as a 255 value.

Diagrams with computed colors

Computed colors are alike RGB Colors but instead of choosing an int value for the Red/Green/Blue fields, an expression will be given.

On this sample the color is computed depending on the depth of the package to represent. As this information is far from a RGB value transposition, the expressions are unfortunately not really natural to write. The Interpolated Colors will offer a more natural conversion.

Diagrams with interpolated colors

An Interpolated Color is defined by an expression and several Color Steps. The expression should return an integer value. Here is an example where the expression calculate the depth of the current element using the ancestors() service.

A Color Step is the association of a color and an integer value. Note that the color selection is not limited by the provided color, but can also be a custom color. In this sample, the selected colors are RGB Colors.

Depending on the return value of the expression, a color will be created between the defined Color Steps. As close the return value is of a Color Step, as close the result color will be to this Color Step.

On the previous example, the interpolated was used in order to display EPackage element with a graduation of color depending on the depth because both steps where different tint of a similar color. Of course, the Color Steps can be of different colors and the number of steps is not limited.
On the next example, we want to present the EPackage again but this time the yellow color graduation will depend on the number of contained EClasses. Moreover, we decide that for future refactoring/cleaning purpose, the empty EPackage should be white. Furthermore, the recommended EPackage size is between one and eight EClasses and should be displayed yellow with a tint darker the more contained EClasses there are. Twelve or more EClasses is seen as too many and should be displayed as red. To represent this as an Interpolated Color we have:

  • An expression computing the contained Eclasses number: [eContents()->filter(EClass)->size()/];
  • A first color step defined as white for value 0;
  • A second color step defined as light yellow for value 1;
  • A third color step defined as dark yellow for value 8;
  • A fourth color step defined as red for value 12.

On this sample:

  • p1121 and p1123 are empty and displayed as white;
  • p112 has 1 EClass and is displayed as light yellow;
  • p1 has 3 EClasses and is displayed as a slightly darker yellow;
  • p111 has 8 EClasses and is displayed as dark yellow;
  • p1122 has 10 EClasses and is displayed some kind of orange/brown as a result of beeing a mix of dark yellow and red;
  • p12 has 16 EClasses and is displayed as red.

Interpolated colors are an easy way to display meaningful information and an alternative from text display. Furthermore it can produce beautiful diagrams using nice colors that can be created using simple tools like www.colourlovers.com or colourco.de.

The sample code from this example is available on github: https://github.com/mbats/sirius-blog/tree/master/interpolated-colors

Keyboard shortcuts

Usually when you are using a graphical modeler, you do most of the actions with the mouse. Sirius based modelers have several built-in shortcut keys that you can use to save time in your day to day workflow. Shortcut keys are commonly accessed by using the key, key, or key in conjunction with other keys.

  1. Keyboards shortcuts
    1. Common shortcuts
    2. Diagram shortcuts
      1. Navigate
      2. Select
      3. Edit
      4. Diagram editor
      5. Palette
    3. Table & Tree shortcuts

Common shortcuts

Some shortcuts are available for all the representations (diagram, table, tree…).

Action Shortcut Description
Go to open editors + To get a direct access to an editor, just press Ctrl + E, and either use the arrow buttons, or type the name of the representation you are editing.
Navigate between visited representations + or + To cycle between visited representations use Alt + Arrows. On Mac : + +
Select All +
Direct Edit
Open Help +
Undo + On Mac: +
Redo + On Linux : + + , On Mac: + +
Save +
Save all + +

Diagram shortcuts

Shortcut keys help providing an easier and usually quicker method of navigation.

Action Shortcut Description
Cycle between shapes on the diagram from left to right
Cycle between shapes on the diagram from right to left +
Navigate between shapes on the diagram +
Navigate into a container +
Navigate out of a container +
Navigate clockwise among the existing edges
Navigate counter-clockwise among the existing edges
Show quick outline + On Mac : +

Select

Below is a list of the shortcut keys that allow to select elements on the diagrams.

Action Shortcut Description
Select in sequence + Hold down Shift, use navigation keys to select additional components.
Select multiple + + Hold down Ctrl, use navigation keys to navigate to additional components, press Space to select additional components.
Deselect + Deselect the selected shape/edge by showing the shape/edge in an outline.
Select diagram Select the diagram and so deselect all other previous selections.

Edit

It is also possible to use shortcuts to edit a diagram.

Action Shortcut Description
Refresh Force an update of the diagram according to the latest version of the semantic model.
Copy semantic element + On Mac : +
Paste semantic element + On Mac : +
Copy layout + + + See Sirius copy/paste layout documentation.
Paste layout + + + See Sirius copy/paste layout documentation.
Hide element + See Sirius hide elements documentation.
Hide label + See Sirius hide labels documentation. On Mac : +
Show label + + On Mac : + +
Move shape
Cycle on element handles Cycle on Position Handle / 8 Side and Corner Size Handles / Position Handle. Clockwise rotation.
Cycle through edge points Cycle through the endpoints, bendpoints, and midpoints of a connection. Clockwise rotation.
Manage edge + + Remove all the bend-points to retrieve an original straight edge. See Sirius manage edge documentation. On Mac : + +
Move a component + Cycle once to the Move handle using the period key (.), use navigation keys to move, press Enter to accept new location or press Escape to cancel the move.
Constrained move + This action constrained the move by snaping the shape to the grid.
Move without snap + This action allows to ignore the snap while dragging a shape. On Mac : +
Resize a component + Resize Cycle to desired resize handle using the period key, use navigation keys to resize, press Enter to accept new size or press Escape to cancel the resize.
Centered resize + Expands the shape on both opposite sides. See Sirius resize elements documentation. On Mac : +
Resize that keeps the ratio + See Sirius resize elements documentation.
Resize without snap + Temporarily disables the snap during the resize if it is activated. See Sirius resize elements documentation. On Mac : +
Resize container keeping children relative + When the shape is resized using the left and/or top border, the children (contained nodes for container and border nodes for all shapes) are moved with the border. See Sirius resize elements documentation.
Reset diagram + The diagram can have a negative origin or can be shifted toward the bottom-right with a blank zone at the top-left. This action aims to move all diagram elements to retrieve its origin while keeping the element layout. See Sirius reset diagram documentation. On Mac : +

Diagram editor

The following shortcuts allow to zoom, scroll or invoke the context menu from the diagram.

Action Shortcut Description
Zoom in +
Zoom out +
Pan when zoomed in + Hold down spacebar and drag the mouse
Scroll in diagram + +
Invokes the context menu for the shape +

Palette

Keyboard shortcuts save you time by letting you explore the palette quickly.

Action Shortcut
Collapse or expand the selected group or
Select tool or
Stack popup list appears +
Navigate between group & tools or

Table & Tree shortcuts

Some specific key shortcuts are also available on tables and trees.

Action Shortcut
Expand direct children
Collapse or
Expand all children

Use keyboard shortcuts and increase your productivity!

This post is available on github : https://github.com/mbats/sirius-blog/tree/master/keyboard