How to Retype Nodes and Edges

This article is meant to help with understanding the syntax behind retyping Nodes and/or Edges. Retyping elements can be of great help to enrich your data model or to allow for the modification and visualization of specific elements. The first part of the article provides an example on how to retype nodes in your Soley Studio solution. The second part deals with retyping edges.

How to retype nodes

Retyping nodes in rules

Let’s suppose we have two Node types in our solution – Part and COPart. It is in our interest to make all nodes of the type Part change to COPart. The way to do this in a rule is:

rule retypeNodes {
     n:Part;
     modify {
          newN:COPart<n>;
    } 
}

The starting graph containing Part type nodes looked like this:

Change the type of a node to another type in Soley Studio.
Graph with Part Nodes

And after our transformation changed to:

Retyping of Nodes and Edges in Soley Studio. Changing the type of a node.
Graph with COPart Nodes

Retyping nodes in functions, procedures or sequences

Retyping nodes and edges can also be done in functions, procedures or sequences. The syntax is slightly different to the rule syntax:

 procedure retypeProcedure{
     for(n:Part in nodes(Part)) {
         retype(n,COPart);
     }
     return();
 }

How to retype Edges

Retyping edges in rules

The same logic can be applied to retyping edges. The only visible differences are in the syntax used. In the previous images, the edge type used is the TestEdge. A rule for retyping this edge type to Contains edges could look like this:

rule retypeEdges {
     -e:TestEdge->;
     modify {
          -newE:Contains<e>->;
    } 
}

As you can see, the two rules have exactly the same structure, with only the syntax adjusted to nodes and edges, respectively.

Change both the Node and Edge types of your Soley Studio solution components.
COPart Node and Contains Edge

Retyping edges in functions, procedures or sequences

This works exactly the same way as retyping nodes in in functions, procedures or sequences. As the syntax is exactly the same, please see the section on nodes for details.

Additional notes on retyping nodes and edges

Attribute Transfer

An integral part of the retyping functions within Soley Studio is the attribute transfer. When retyping elements from one class to another, the original node is deleted and a new node is created, which has all the relations (meaning edges) of the original node. Further, if retyping from a parent to a child class, all attribute values will be copied, too. However, this only works from parent to child class. Even if the two classes have the exact same set of attributes but are not in a parent-child relation, the attribute values of the original node will not be copied to the retyped node automatically. In such a case, the required attribute values need to be copied actively, e.g. as part of the retyping rule:

 rule RetypeN{
     n:MyNode;
     modify {
         newN:YourNode<n>;
         eval {
             newN.id = n.id;  //copy id value from original node to retyped node
         }
     }
 }

By simply adding all the attributes you want to transfer to the eval part, the selected attributes will be copied. In the example above, only the id property is transferred.

Calling retyping rules

If you want to retype all elements of a class, think about the metamodel structure before selecting the * or the [] operators to call the rule in a sequence (retypeNodes* or [retypeNodes]). For example, if you retype from the class Part to the class COPart and COPart is a child class of Part, then you cannot use the * operator. This would cause an infinite rule application loop, as every COPart is also a Part. If you are not aware of the operators learn more about them in this article.

Was this article helpful?

Related Articles