Book a Demo

Author Topic: Finding operations in all diagrams / traceability  (Read 17099 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #15 on: May 29, 2010, 12:05:03 am »
You don't, you create a new Class Library application.
This will create a dll.
In VS you can setup your dll to be COM-Visible so it can be registered and EA can pick it up (after you have told it to do so in the registry)

Geert


mikob

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Finding operations in all diagrams / traceabil
« Reply #16 on: May 31, 2010, 07:33:15 pm »
Hi Geert,

I'm trying to set up a basic C# addin that I got from the website (http://www.sparxsystems.com/resources/developers/autint.html). In the readme file it says that I have to go to the EAaddin folder in regedit. Problem is that I haven't got an EAaddin folder in the registry.

Any idea's? I'm using EA8.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #17 on: May 31, 2010, 07:51:33 pm »
You have to make it.

this is how an export of one of my addins looks like:
Code: [Select]
[HKEY_CURRENT_USER\Software\Sparx Systems\EAAddIns\EANavigator]
@="EANavigator.EANavigatorAddin"

Geert

mikob

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Finding operations in all diagrams / traceabil
« Reply #18 on: May 31, 2010, 08:07:03 pm »
Woohooo! It works!!

Oke. But I still don't get how I can use your code.  :-/ Can I alter this addin? Or do I have to make a new one? And how!????

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #19 on: May 31, 2010, 08:45:02 pm »
You could use that one to start with.
First thing to do is show (context) menu when an operation is selected.
This is the first part of the code for my addin class:
Code: [Select]
namespace EANavigator
{


    [ComVisible(true)]
    [Guid("c72f24fb-cc0a-40c4-b241-5f35f3d11521")]
    [ClassInterface(ClassInterfaceType.AutoDual)]
    public class EANavigatorAddin
    {
        /// <summary>
        /// nothing needed here.
        /// </summary>
        /// <param name="Repository">the ea repository</param>
        /// <returns>a string</returns>
        public String EA_Connect(EA.Repository Repository)
        {
            //No special processing required.
            return "a string";
        }


        /// <summary>
        /// Called when user Click Add-Ins Menu item from within EA.
        /// Populates the Menu with our desired selections.
        /// Location can be "TreeView" "MainMenu" or "Diagram".
        /// </summary>
        /// <param name="Repository">the repository</param>
        /// <param name="Location">the location of the menu</param>
        /// <param name="MenuName">the name of the menu</param>
        /// <returns></returns>
        public object EA_GetMenuItems(EA.Repository Repository, string Location, string MenuName)
        {
            Object selectedItem;
            EA.ObjectType selectedType = Repository.GetContextItem(out selectedItem);


                switch (MenuName)
                {
                    case "":
                        return "-&Navigate";
                    case "-&Navigate":
                        string[] ar = null;
                        //operation
                        if (selectedType == EA.ObjectType.otMethod)
                        {
                            string[] operationOptions = { "&Implementation", "&In Diagrams" };
                            ar = operationOptions;
                        }
                        
                        
                        return ar;
                }
            

            return "";
        }

/// <summary>
        /// returns true if a project is currently opened
        /// </summary>
        /// <param name="Repository">the repository</param>
        /// <returns>true if a project is opened in EA</returns>
        bool IsProjectOpen(EA.Repository Repository)
        {
            try
            {
                EA.Collection c = Repository.Models;
                return true;
            }
            catch
            {
                return false;
            }
        }

        /// <summary>
        /// Called once Menu has been opened to see what menu items are active.
        /// </summary>
        /// <param name="Repository">the repository</param>
        /// <param name="Location">the location of the menu</param>
        /// <param name="MenuName">the name of the menu</param>
        /// <param name="ItemName">the name of the menu item</param>
        /// <param name="IsEnabled">boolean indicating whethe the menu item is enabled</param>
        /// <param name="IsChecked">boolean indicating whether the menu is checked</param>
        public void EA_GetMenuState(EA.Repository Repository, string Location, string MenuName, string ItemName, ref bool IsEnabled, ref bool IsChecked)
        {
            if (IsProjectOpen(Repository))
            {
                Object selectedItem;
                EA.ObjectType selectedType = Repository.GetContextItem(out selectedItem);

                if (selectedType == EA.ObjectType.otMethod)
                    
                {
                    IsEnabled = true;
                }
                else
                {
                    IsEnabled = false;
                }

                
            }
            else
                // If no open project, disable all menu options
                IsEnabled = false;
        }

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #20 on: May 31, 2010, 08:48:03 pm »
And it continues here to actually do something when the user has selected your menu option.

Code: [Select]
/// <summary>
        /// Called when user makes a selection in the menu.
        /// This is your main exit point to the rest of your Add-in
        ///
        /// </summary>
        /// <param name="Repository">the repository</param>
        /// <param name="Location">the location of the menu</param>
        /// <param name="MenuName">the name of the menu</param>
        /// <param name="ItemName">the name of the selected menu item</param>
        public void EA_MenuClick(EA.Repository Repository, string Location, string MenuName, string ItemName)
        {
            switch (ItemName)
            {
                
                case "&In Diagrams":
                    this.getUsingDiagramsForOperation(Repository);
                    break;
            }
        }
 /// <summary>
        /// opens all diagrams with a message calling the selected operation
        /// </summary>
        public void getUsingDiagramsForOperation(EA.Repository eaRepository)
        {
            ACVModel model = new ACVModel(new EAModel(eaRepository));
            ACVDocumentable selectedItem = model.getSelectedDocumentable();
            if (selectedItem != null && selectedItem is ACVOperation)
            {
                ACVOperation operation = selectedItem as ACVOperation;
                Dictionary<ACVDiagram,ACVDiagramSelectable> diagrams = operation.getReferencingDiagrams();
                if (diagrams.Count > 0)
                {
                    ModelNavigator.NavigateDiagrams(diagrams);
                }
                else
                {
                    //no referencing diagrams, alert user
                    MessageBox.Show("No diagrams found");
                }
            }
        }

mikob

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Finding operations in all diagrams / traceabil
« Reply #21 on: May 31, 2010, 09:24:31 pm »
Hi Geert,

Thanks again. Do I put the code in the Main.cs? Or does the second code you've posted go elsewhere?

Miko

mikob

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Finding operations in all diagrams / traceabil
« Reply #22 on: May 31, 2010, 09:30:29 pm »
Is it possible for you to zip your c# project so I can open it in Visual studio and use it?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #23 on: May 31, 2010, 10:41:05 pm »
Mico,

If you have a look at the example you will see that the addin-class (the one that EA talks to) has some standard methods.
The code I just posted is for the addin class.

Unfortunately I can't send you my complete project since I don't own its rights. (even posting snippets of the code is on the limit :-/)

Geert

mikob

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Finding operations in all diagrams / traceabil
« Reply #24 on: May 31, 2010, 11:01:56 pm »
OK. I get the point.

Mmmm... it isn't getting any easier. It doesn't seem to work. I'm getting a lot of errors while trying to build. I see that you use ACVModel, AVCDocumentable and AVCOperation. Is this specific for your model?

Regards

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #25 on: June 01, 2010, 12:46:59 am »
Yes, those are wrappers around EA wrappers who wrap the API objects.
Whenever you see something like wrapped<something> that is the actual EA API object.

You don't need all those layers of wrapping, so you could work directly with the API objects, but the principle of what you need to do stays the same, get the operation, get all messages that call this operation, and then get the diagrams where those messages are displayed.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #26 on: June 22, 2010, 01:54:01 pm »
Mico,

I've recreated the navigator addin from scratch, and I've uploaded it to the community site. As soon as it gets published you can download both the binaries and the source.
The addin shows you all sequence diagrams that use an operation, and select an operation starting from a message on the sequence diagram.
If you want I could already send you the files by email, since it seems to take some time to get published.

Geert

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Finding operations in all diagrams / traceabil
« Reply #27 on: June 29, 2010, 04:42:13 pm »
My Navigator addin got published on the
community site.
I've included a separate package with the source code.

Enjoy.

Geert