Diagram class

 

Diagram overview

 

class Diagram extends InternalProduct;

 

Graphical representation of a model.  A Diagram is a kind of product that is attached to a ModelElement.  It contains ViewElements that constitute the representation of a model.  For example, a Package can be attached to Class Diagrams, that will be made up of ViewElements representing some of the elements of the Package, their Links, properties, etc.

 

The subclasses of Diagram represent each kind of diagram specified by UML and supported by Objecteering.

 

Figure 4. Detailed class diagram of Diagram

 

See also:   ModelElement, ViewBox, ViewLink.

 

 

Diagram properties

The Diagram class has the following associations:

·         ViewComponent:ViewElement: Link to the graphical elements that constitute the Diagram.  This link is only valid after the open operation has been called.

·         interaction:Interaction: Link allowing diagrams associated with an interaction to be retrieved.  This link is only valid for sequence diagrams and object diagrams.

 

It has the following attributes:

·         LayoutSpaceX: integer

·         LayoutSpaceY: integer

 

X and Y spacing between boxes is taken into account, particularly for automatic positioning.

 

·         detailedDisplay: boolean.  The detailedDisplay attribute is used to indicate the level of detail shown in the diagram.

·         taggedVisible: boolean.  The taggedVisible attribute indicates whether or not tagged values are visible when elements are created (default values depend on general parameterization, which is carried out through the "Formalism" set of Objecteering Modeler parameters).

·         stereotypeDisplay: This can use one of the following values:

·         NoneStereotypeDisplayMode: Stereotypes are not displayed.

·         IconStereotypeDisplayMode: Stereotypes are displayed using an icon.

·         LabelStereotypeDisplayMode: Stereotypes are displayed using a label.

·         showSystemBoundary: boolean.  The showSystemBoundary attribute indicates whether or not the boundaries of use cases (in other words, their oval encirclement) in use case diagrams are to be visible.

 

 

Diagram consistency rules

Not every type of diagram can be created for every type of element.  The following table resumes what it is possible to create on different elements.

 

Model element ...

possible associated diagram ...

Package, Sub-system, Class

Class Diagram

Package, Sub-system

Use Case Diagram

Package, Sub-system, Class, Collaboration, UseCase

Sequence Diagram

Package, Sub-system, Class

Object Diagram

Collaboration

Collaboration Diagram

ActivityGraph

Activity Diagram

StateMachine

State Diagram

Package, Sub-system

Deployment Diagram

Package, Sub-system

Deployment Instance Diagram

 

 

Diagram constructors

Diagram ModelElement:createUseCaseDiagram

                     (in String pName)

This operation creates a UseCaseDiagram whose name is given.

 

 

Diagram ModelElement:createAndAddUseCaseDiagram (in String pName)

This operation creates and adds to the current element a UseCaseDiagram whose name is given.

Example:

UseCaseDiagram MyDiag =MyPackage.<createAndAddUseCaseDiagram

           ("MyUseCaseDiag");

 

 

Diagram ModelElement:createStaticClassDiagram

                     (in String pName)

This operation creates a ClassDiagram whose name is given.

Example:

ClassDiagram MyDiagram =createStaticClassDiagram

                        ("MyDiagram");

 

 

ModelElement:addDiagram (in Diagram pDiagram)

This operation adds a Diagram to the current Element.

Example:

MyPackage.<addDiagram (MyDiagram);

 

 

Diagram ModelElement:createAndAddStaticClassDiagram

                     (in String pName)

This operation creates and adds to the current element a ClassDiagram whose name is given.

Example:

ClassDiagram MyDiag MyPackage.<createAndAddStaticClassDiagram

                              ("MyClassDiag");

 

 

ModelElement:createAndAddObjectDiagram (String Name);

 

 

 

ModelElement:createAndAddCollaborationDiagram

             (String Name);

 

 

ModelElement:createAndAddSequenceDiagram (String Name);

 

 

ModelElement:createAndAddDeploymentDiagram

             (String Name);

 

 

ModelElement:createAndAddInstanceDeploymentDiagram

             (String Name);

 

 

Operation:createAndAddStateDiagram (String Name);

NameSpace:createAndAddStateDiagram (String Name);

 

 

Operation:createAndAddActivityDiagram (String Name);

NameSpace:createAndAddActivityDiagram (String Name);

 

These methods create a Diagram related to ModelElement, that will have the Name Name, and the kind related to the name of the method.  This should be carried out only for authorized ModelElements (see table below).

 

Every ModelElement that can have diagrams (Class, Package, UseCase, StateMachine, Collaboration, and so on) provides the following service:

 

private Diagram[] getDiagrams();       

This is the most thorough way of getting existing diagrams.

 

 

Diagram methods

String kind()

Returns the kind of diagram which can be: Activity, Class, Collaboration, ComponentDeployment, InstanceDeployment, Object, Sequence, State, UseCase.

 

boolean dump (in String format, inout String fileName)

Generates a diagram in a file. The format can be: "png", "ps", or "emf".  "png the correct format for HTML, "emf" is the windows metafile format, and "ps" is PostScript.

 

Object:setDiagramDumpPath (in String path)

Sets the directory used by the documentation generation for the diagrams (dump()).

 

open();

This is an essential operation, used to handle the diagram's ViewElements.  The diagram is opened in modification mode (without opening the graphic view).  This is necessary is you wish to carry out operations in diagrams.

 

show();

This opens the current diagram in edit mode.  This service replaces the openInEditor() service.  To facilitate upward compatibility, the latter is still functional.

 

hide();

This closes the graphic view of the current diagram (irrespective of whether the diagram was opened using the show() call or through the graphic interface).  This is the equivalent of clicking on the diagram's "Close" button.

 

close(bool hide=false);

This closes a diagram.  The "hide" parameter is used to specify whether or not you also wish to close the graphic view of the current diagram.  If "hide" is false, then the graphic view of the diagram is not closed. 

 

By default, the graphic view of the diagram is not closed.

 

showContent();

This displays the elements contained in a diagram.

 

layoutViewElements (inoutViewBox [] boxes,

                    inoutViewLink [] links);

A method which ensures the automatic positioning of links and boxes in a diagram through parameterization.

Example:

layoutViewElements (myDiagram .<ViewComponentViewBox,

                    myDiagram .<ViewComponentViewLink);

 

This command guarantees the automatic positioning of the entire "MyDiagram" diagram.

 

A diagram must always be open for its representation elements to be modified.

 

When the modification session is complete, the close instruction allows the modifications to be taken into account, and the diagram to be refreshed.

 

Note:      An active editor is only taken into account once the execution of the J program is complete.

 

 

Methods specific to sequence diagrams

SequenceDiagram:deleteMessageRepresentation

               (inout ViewLink link)

This method deletes the ViewLink used as a parameter of the graphic view of the sequence diagram.  The ViewLink in a sequence diagram represents a SequenceMessage.

 

This method does not destroy the SequenceMessage semantic object represented by the ViewLink.

 

SequenceDiagram:deleteInstanceRepresentation

               (inout ViewBox box)

This method is used to delete the ViewBox used as a parameter of the graphic view of the sequence diagram.  In a sequence diagram, Viewboxes correspond to instances, notes and constraints.

The method only takes into account ViewBoxes of the type Instance.  The deletion of the ViewBox will only be carried out if no ViewLinks attached to ViewBoxes are displayed.  Therefore, ViewLinks should first be deleted and then ViewBoxes.

 

This method does not destroy the Instance semantic object represented by the ViewBox.

 

SequenceDiagram:getAllMessages(out ViewLink[] links)

This method returns (in the "links" parameter) the list of ViewLinks present in the sequence diagram on which the method is run.

 

SequenceDiagram:getAllInstances(out ViewBox[] boxes)

This method returns (in the "boxes" parameter) the list of ViewBoxes of Instance type present in the sequence diagram on which the method is run.

 

 

Example 1

This macro is used to create a Sequence diagram on a package. This also creates instances and SequenceMessages.

 

Package pack;

Diagram d;

SequenceMessage syncmsg;

SequenceMessage syncmsg_ret;

SequenceMessage asyncmsg;

SequenceMessage asyncmsg_ret;

Instance sender;

Instance receiver;

boolean sync = true;

Interaction interact;

 

if (ClassOf() == Package)

{

      pack = this;

      createAndAddSequenceDiagram ("Example SequenceDiagram")

      {

           d = this;

       

           setdetailedDisplay(false);

           //First we open a graphic session

           open();

       

           //Creating a first instance

            sender = Instance.new();

            sender.setName("instancesender");

            pack.appendDeclared(sender);

           sender.appendBase(pack);

           //First instance created

 

           //Creating a second instance

           receiver = Instance.new();

           receiver.setName("instancereceiver");

        pack.appendDeclared(receiver);

           receiver.appendBase(pack);

           //Second instance created

 

           //Creating a first sequence message which is synchronous

           interact= this.interactionInteraction;

           sync = true;

        syncmsg = SequenceMessage.new();

           syncmsg.setName("synchronous message");

           syncmsg.setIsSynchronous(sync);

           //Create the appropriate links in the metamodel

           syncmsg.appendSender(sender);

           syncmsg.appendReceiver(receiver);     

           interact.appendOwned(syncmsg);

 

           syncmsg_ret = SequenceMessage.new();

           syncmsg_ret.setName("synchronous message return");

        syncmsg_ret.setIsSynchronous(sync);

           syncmsg_ret.setKindOfAction(ReturnAction);

           //Create the appropriate links in the metamodel

        syncmsg_ret.appendSender(receiver);

        syncmsg_ret.appendReceiver(sender);

        interact.appendOwned(syncmsg_ret);

        //First sequence message created     

 

        //Creating a second sequence message which is asynchronous

        sync = false;

           asyncmsg = SequenceMessage.new();

           asyncmsg.setName("asynchronous message");

            asyncmsg.setIsSynchronous(sync);

            asyncmsg.setKindOfAction(CallAction);

            asyncmsg.appendSender(sender);

            asyncmsg.appendReceiver(receiver);

            interact.appendOwned(asyncmsg);

       

            asyncmsg_ret = SequenceMessage.new();

            asyncmsg_ret.setName("asynchronous message return");

            asyncmsg_ret.setIsSynchronous(sync);

            asyncmsg_ret.setKindOfAction(ReturnAction);        

            asyncmsg_ret.appendSender(receiver);

            asyncmsg_ret.appendReceiver(sender);

            interact.appendOwned(asyncmsg_ret);

            //Second sequence message created

 

            d.createAddAndMoveViewBox(sender,15, 15, 50, 40);

            d.createAddAndMoveViewBox(receiver,50, 50, 50, 40);

        //The links representing the SequenceMessages have to be created in the correct order

           d.createAndAddViewLink(syncmsg);

           d.createAndAddViewLink(asyncmsg);     

           d.createAndAddViewLink(asyncmsg_ret);

           d.createAndAddViewLink(syncmsg_ret);  

 

           //We finally close the graphic session

           close();

           //We open the diagram in the Objecteering interface

           show();

      }

}

else

{

   StdOut.write("Macro not available in this element (only in   package element)", NL);

}

 

 

Example 2

This macro is used to delete SequenceMessages whose name is "synchronous message".

 

SequenceDiagram     currentDiag = this;

ViewLink[]          links;

ViewLink            linkMsg;

 

//We list the SequenceMessages before deletion of the SequenceMessages representation

//Note : here we do not need to open a graphic session to navigate through the metamodel

StdOut.write("*** Existing SequenceMessage in the current diagram ***", NL);

currentDiag.<interactionInteraction.<OwnedSequenceMessage

{

   StdOut.write("message: '", this.<Name(), "'", NL);

}

 

//We open a graphic session

currentDiag.open();

    

// Deletion of ViewLinks related to SequenceMessages present in current diagram

//Note : here we need to have an opened graphic session to navigate through the graphic objects

currentDiag.getAllMessages(links);

links

{

        linkMsg = this;

      RepresentedModelSequenceMessage ()

        {

            StdOut.write("***** Information about the current message ***** ", NL);        

            StdOut.write("Name : ", Name, NL);

            if (IsSynchronous == true)

                 StdOut.write("This is a synchronous message", NL);

            else

                    StdOut.write("This is an asynchronous message", NL);

            StdOut.write("Kind of Action : ", KindOfAction, NL);

            if (Name=="synchronous message")

            {

                      StdOut.write("*** Warning *** The current SequenceMessage representation will be deleted.");

                    currentDiag.deleteMessageRepresentation(linkMsg);//This is equivalent to the 'mask' command on diagrams

                      //this.delete; //Uncommenting this line allows to delete the SequenceMessage

              }

      }

}

//We close the graphic session  

currentDiag.close();

 

//We list the SequenceMessages after deletion of the SequenceMessages representation

//We can establish that all the SequenceMessages are still existing

//So the graphic representation of "synchronous message" have been deleted

StdOut.write("*** Existing SequenceMessage in the current diagram ***", NL);

currentDiag.<interactionInteraction.<OwnedSequenceMessage

{

   StdOut.write("message: '", this.<Name(), "'", NL);

}

 

 

Example 3

This macro is used to delete Instance representation whose name is "boxtodelete".

 

SequenceDiagram    currentDiag = this;

ViewBox[]          boxes;

ViewBox            box;

 

 

//We open a graphic session

currentDiag.open();

//We get the list of ViewBoxes of Instance type present in the current diagram

currentDiag.getAllInstances(boxes);    

// Deletion of ViewBox related to Instances present in current diagram.

boxes

{

        box = this;

        RepresentedModelInstance ()

        {

             StdOut.write("***** Information about the current instance ***** ", NL);        

               StdOut.write("Name : ", Name, NL);

                 if (Name=="boxtodelete")

            {

                      StdOut.write("*** Warning *** The current Instance representation will be deleted.", NL);

                    currentDiag.deleteInstanceRepresentation(box);//This is equivalent to the 'mask' command on diagrams

                      //this.delete; //Uncommenting this line allows to delete the Instance

                 }

          }

}

//We close the graphic session  

currentDiag.close();