Book a Demo

Author Topic: buiding class diagram / associations  (Read 2918 times)

ludovich

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
buiding class diagram / associations
« on: June 11, 2010, 09:21:01 am »
Hello,

I am using mdg with Eclipse, doing a reverse engineering of the code which spread accross packages.
I want ot build a class diagram from the different packages and classes.
1/ Is it possible to auto generate a class diagram from several packages? (basically a tree of packages generating a single class diagram).
2/ Is there a way to automatically have the associations added to the diagram if the 2 classes of the association are already on the diagram (to automatically materialize the associations)?

thank you
Ludovic

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: buiding class diagram / associations
« Reply #1 on: June 11, 2010, 02:56:56 pm »
EA's reverse engineering will only create the static class structure and optionally class diagrams for each package.  It does not create a single diagram for an entire application.  In any real world example this will be too large to benefit anyone.

Instead I would recommend making use of your knowledge of the product, and some of EA's features to make more useful diagrams.

For example:

The hierarchy view shows you multiple levels of relationships for the currently selected class. The relationships window shows more information about each of the direct relationships to the current class, and also allows you to drop the objects onto the diagram. Finally, the Insert Related command (in the context menu of an object on a diagram) allows you to insert many related objects all at once.

So, with appropriate use of known significant objects you should be able to achieve some more useful diagrams.

However, if you still want to pursue that path we have a scripting example that adds all elements under the selected package to the selected diagram.  A warning though, this could take quite some time, especially the layout at the end.


Code: [Select]
dim left
dim top
dim width
dim height
dim padding
dim layoutLeft
dim layoutWidth

layoutLeft = 10
left = layoutLeft
top = 10
width = 100
height = 100
padding = 30
layoutWidth = 2000


sub AddElementToDiagram ( theDiagram, theElement )
 
 ' Cast theDiagram to EA.Diagram so we get intellisense
 dim currentDiagram as EA.Diagram
 set currentDiagram = theDiagram
 
 ' Cast theElement to EA.Element so we get intellisense
 dim currentElement as EA.Element
 set currentElement = theElement
 
 ' Add the element to the diagram
 dim diagramObjects as EA.Collection
 set diagramObjects = currentDiagram.DiagramObjects
 
 if left + width > layoutWidth then
  left = layoutLeft
  top = top + height + padding
 end if
 
 dim testDiagramObject as EA.DiagramObject
 set testDiagramObject = diagramObjects.AddNew( "l=" & left & ";r=" & left + width & ";t=" & top & ";b=" & top + height & ";", "" )
 testDiagramObject.ElementID( currentElement.ElementID )
 testDiagramObject.Update()
 
 left = left + width + padding
 
end sub

sub AddElementsToDiagram ( theDiagram, thePackage )
 
 ' Cast thePackage to EA.Package so we get intellisense
 dim currentPackage as EA.Package
 set currentPackage = thePackage
 
 ' Iterate through all elements and add them to the diagram
 dim currentElement as EA.Element
 for each currentElement in currentPackage.Elements
  AddElementToDiagram theDiagram, currentElement
 next
 
 ' Recursively process any child packages
 dim childPackage as EA.Package
 for each childPackage in currentPackage.Packages
  AddElementsToDiagram theDiagram, childPackage
 next
 
end sub

dim rootPackage as EA.Package
set rootPackage = GetTreeSelectedPackage()

dim currentDiagram as EA.Diagram
set currentDiagram = GetCurrentDiagram()

AddElementsToDiagram currentDiagram, rootPackage
ReloadDiagram currentDiagram.DiagramID

GetProjectInterface().LayoutDiagram currentDiagram.DiagramGUID, 0

ludovich

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: buiding class diagram / associations
« Reply #2 on: June 12, 2010, 07:58:42 am »
hi,

That would be a very good feature to automatically generate 'intelligent/usefull' more global class diagrams.

What about the automatic 'display' of dependency from one object to another on the same class diagram? Is it something possible to perform?

thank you
Ludovic

ludovich

  • EA Novice
  • *
  • Posts: 5
  • Karma: +0/-0
    • View Profile
Re: buiding class diagram / associations ?
« Reply #3 on: June 17, 2010, 04:53:20 am »
Hi,

No answer for my other question?

thx
Ludovic