Please note : This help page is not for the latest version of Enterprise Architect. The latest help can be found here.

Add Custom Compartments to Element

Enterprise Architect enables you to add custom compartments to elements, via a Toolbox profile in an MDG Technology.

Guide:

The following topics provide a guide and some examples of how to add custom compartments to elements.

Topic

Description

See also

Develop script

At step 5 of the Create Toolbox Profile procedure, add an attribute called _image.

Click on the ( ... ) button next to the Initial Value field to display the shape script editor.

Replace shape main  with shape ChildElement.

You can keep shape main if you prefer, to adjust some properties of the main element (such as color); however, the main shape then requires a call to DrawNativeShape() in order to work correctly.

At this point, you can use the HasProperty query method to search child elements for specific properties (such as stereotypes) to be displayed in compartments.

Below are two examples of shape scripts that you might use.

 

Create Toolbox Profiles

Shape Editor

 

 

Drawing Methods

 

Query Methods

Example 1 - Without Adjusting the Parent Element

 

//Add compartments for Child elements.

shape ChildElement

{

      //Check if a child element has the property stereotype, if so set our compartment name to Properties.

       if(HasProperty("stereotype", "property"))

       {

               SetCompartmentName("Properties");

       }

 

      //Check if our child element has a public scope and add the + symbol if so to the child compartment.

       if(HasProperty("scope", "public"))

      {

               AppendCompartmentText("+");

       }

 

      //Add the child elements name to the child compartment.

       AppendCompartmentText("#NAME#");

}

 

The shape script checks all child elements to see if they have a stereotype of property. If this stereotype is found, the SetCompartmentName function sets a compartment called Properties.

The script then checks whether the child has a public scope and, if it does, appends the + symbol .

Finally, the AppendCompartmentText function adds the child's name to the compartment.

If a compartment has already been declared by SetCompartmentName, any additional children that fall under the same compartment are automatically added to it without having to declare a new compartment name (that is, all children with the stereotype property end up in the Properties compartment).

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Drawing Methods

Example 2 - Adjust the Color of the Parent Element and Add Child Compartments

 

//Shape main affects the parent

shape main

{

       //Set the color of the parent element to red

       setfillcolor(255,0,0);

       //draw the parents native shape

       drawnativeshape();

}

 

//Shape ChildElement adds Child Compartments to the parent.

shape ChildElement

{

        if(HasProperty("stereotype", "part"))

        {

               SetCompartmentName("Parts");

         }

        else if(HasProperty("stereotype", "mystereotype"))

        {

              SetCompartmentName("My Stereotype");

         }

 

         AppendCompartmentText("#NAME#");

}

 

The shape main  section sets the color of the main element to red and then proceeds to add the child compartments as for Example 1.

In this case, however, the script checks whether a child has either the Part stereotype or the custom stereotype MyStereotype applied to it. If there are two child elements, one a Part and the other using MyStereotype, two compartments are created, called Parts and My Stereotype.

In order to display the compartments, AppendCompartmentText must be called.

Note that SetCompartmentName and AppendCompartmentText do not accept new line characters; that is, the following call is not supported:

 

SetCompartmentName(_T("My Name \n My New Name"))

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Drawing Methods

Complete the Toolbox Profile

After adding the shape script, continue following the steps for creating a Toolbox Profile and save and import the profile.

You can then apply the shape script by simply dragging the element from the Toolbox onto the diagram and adding the appropriate children to that element.

 

Create Toolbox Profiles

Deploy An MDG Technology