Author Topic: How to create Diagrams from other Diagrams  (Read 7250 times)

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
How to create Diagrams from other Diagrams
« on: July 04, 2013, 12:43:25 am »
Hello everyone,

I need to perform Model-to-Model (M2M) transformations in order to generate some diagrams (Class Diagrams) from other diagrams (Use Case and Class Diagrams).
Can anyone advise me what's the best way of doing this using EA?
I know that EA allows the definition of code templates, but what about generating other models?

Thanks in advance.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #1 on: July 04, 2013, 01:50:17 am »
Search the help for Model Transformation. They use a proprietary scripting language (like for code gen.). There are a couple of pre-defined scripts included (e.g. for generating DDL).

q.

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #2 on: July 05, 2013, 12:48:13 am »
Thanks for the answer q.
I've already looked to the Model Transformation documentation and some default templates, but I was unable to find an example that converts, for instance, a certain diagram type to another. Instead, the examples create diagrams of the same type of the original with different elements (stereotyped and so on). I need to know if it's possible to define the type of a certain diagram.
I've also noticed that the original positioning is lost in the transformed diagram. Thus, I would like to know if It's possible to define the positioning of each generated element.

If someone could give some more hints I would be very grateful.
Thanks in advance.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #3 on: July 05, 2013, 03:06:48 am »
Sorry, I did not read well enough. You can not transform diagrams out of the box. To do that you need to script what has to be done. Anyway scripting via API is more flexible than EA's proprietary  scripting language.

q.

g.makulik

  • EA User
  • **
  • Posts: 355
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #4 on: July 05, 2013, 03:49:44 am »
Quote
Sorry, I did not read well enough. You can not transform diagrams out of the box. To do that you need to script what has to be done. Anyway scripting via API is more flexible than EA's proprietary  scripting language.

q.
I'd guess the OP needs both, a transformation to generate the elements, and a script or add-in method to setup a diagram with these elements.
Using EA9.3, UML2.3, C++, linux, my brain, http://makulik.github.com/sttcl/

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #5 on: July 05, 2013, 07:42:24 pm »
Thank you for the feedback, but I'm still a little lost.
Is it possible to create diagrams programmatically with EA?
If so, can you give any example or documentation about it?

Many thanks!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #6 on: July 05, 2013, 08:12:09 pm »
As said, you need to write a script to do that. It's not too difficult, but you need at least little experience in using the API. Once you have that you can get further help with details here.

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to create Diagrams from other Diagrams
« Reply #7 on: July 05, 2013, 08:25:20 pm »
Quote
Thank you for the feedback, but I'm still a little lost.
Is it possible to create diagrams programmatically with EA?
If so, can you give any example or documentation about it?

Many thanks!

André,

Documentation can be found here:

- the help file: there a whole automation section in the help file
- Thomas Kilians scripting book: https://leanpub.com/ScriptingEA
- The examples in the installation folder (on my machine on C:\Program Files (x86)\Sparx Systems\EA\Scripts)
- The community site: http://community.sparxsystems.com/community-resources
- this forum (there are a lot of posts with code snippets)
- My blog http://bellekens.com/2011/01/29/tutorial-create-your-first-c-enterprise-architect-addin-in-10-minutes/
- My open source repositories (C#) https://github.com/GeertBellekens

Geert

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #8 on: July 05, 2013, 09:00:16 pm »
I've already successfully created an Add-in in C# to validate diagrams and then call a jar to generate code, so I can say I have some experience.
My doubt is that I was unable to find a way to create Diagrams using the Automation Interface. Probably, some of you have done something similar or so.

Thanks once again.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +566/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: How to create Diagrams from other Diagrams
« Reply #9 on: July 05, 2013, 09:41:27 pm »
Adding diagrams is not difficult.
Just use Package.Diagrams.AddNew() or Element.Diagram.AddNew()

Adding elements to your now diagram is a bit harder but not much.
I've recently added such function to my EA Navigator add-in (still in alpha version)
You can find the code for adding elements to the currently opened diagram here: Diagram.cs in the operation addToDiagram()

Code: [Select]
/// <summary>
/// adds an element to the diagram
/// </summary>
/// <param name="element">the element to add</param>
/// <returns>the new diagramElement</returns>
public UML.Diagrams.DiagramElement addToDiagram(UML.Classes.Kernel.Element element)
{
      UML.Diagrams.DiagramElement diagramElement = null;
      //first check whether this element is not already added to this diagram
      diagramElement = this.diagramObjectWrappers.FirstOrDefault(x=> x.element.Equals(element));
      if (diagramElement == null)
      {
            if (element is EA.ElementWrapper)
            {
                  //first save the diagram to make sure we don't loos any unsaved changes
                  this.model.saveOpenedDiagram(this);
                  global::EA.DiagramObject newDiagramObject = this.wrappedDiagram.DiagramObjects.AddNew("","") as global::EA.DiagramObject;
                  diagramElement = ((Factory)this.model.factory).createDiagramElement(newDiagramObject) ;
                  diagramElement.element = element;
                  //save the element diagramObject
                  ((DiagramObjectWrapper)diagramElement).save();
                  // now refresh to make sure we see the new element on the diagram
                  this.reFresh();
            }

            else if (!(element.owner is UML.Classes.Kernel.Package))
            {
                  diagramElement = this.addToDiagram(element.owner);
            }
      }
      return diagramElement;
}

/// <summary>
/// add the given diagram to this diagram
/// </summary>
/// <param name="diagram">the diagram to add</param>
/// <returns>the diagramElement representing the diagram</returns>
public UML.Diagrams.DiagramElement addToDiagram(UML.Diagrams.Diagram diagram)
{      
      if (this.owner is ElementWrapper)
      {
            ElementWrapper elementDiagram = ((ElementWrapper)this.owner).addOwnedElement<ElementWrapper>(diagram.name,"UMLDiagram");
            elementDiagram.save();
            //to make the elementDiagram actuall link to the diagram we need to set PDATA1 to the diagramID
            // and NType = 0 for Frame or 1 for Reference
            this.model.executeSQL("update t_object set Ntype = 0, PDATA1 = "+ ((Diagram)diagram).DiagramID.ToString() +" where ea_guid = '" + elementDiagram.WrappedElement.ElementGUID + "'");
            return this.addToDiagram(elementDiagram);
      }
      else return null;
}

Geert

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #10 on: July 05, 2013, 10:03:12 pm »
Thanks Geert!  ;)
I will take a look at that.

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #11 on: July 06, 2013, 03:02:38 am »
Hi Geert,

I was able to create new Diagrams and Elements, but I couldn't link those elements to the respective diagram.
If I add a new DiagramObject to the Diagram nothing happens and the element doesn't appear:
Code: [Select]
newDiag.DiagramObjects.AddNew("Dummy1", "Class")If I add a new Element to the Diagram's Package, the Element appears:
Code: [Select]
package.Elements.AddNew("Dummy2", "Class")
I couldn't find the function Execute (not even in the documentation http://www.sparxsystems.com/uml_tool_guide/sdk_for_enterprise_architect/repository3.htm) in Repository that you use in the second addToDiagram function. I've tried SQLQuery but it only performs select queries.

Thanks once again!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #12 on: July 06, 2013, 06:20:38 am »
When manipulating diagrams you need to reload it so EA renders it new. It’s not done when you add DiagramObjects.

Execute is NOT official and therefore not documented. You can use it to perform UPDATEs.

q.

André Ribeiro

  • EA User
  • **
  • Posts: 51
  • Karma: +0/-0
    • View Profile
Re: How to create Diagrams from other Diagrams
« Reply #13 on: July 08, 2013, 12:58:52 am »
I finally generated new diagrams with new elements.
Thanks guys! You're the best!  :D