Book a Demo

Author Topic: Hidding all links to element on diagram  (Read 7975 times)

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Hidding all links to element on diagram
« on: March 19, 2013, 06:51:53 pm »
Hello,

I try to hide all element links after placeing it on a diagram. The purpose is to hide all visible links between the element and other diagram elements. Modifications should be visible immediately. I use "EA_OnPostNewDiagramObject" but after "Repository.ReloadDiagram" or "Repository.CloseDiagram" EA crashes.

I tried to update diagram object, element, diagram link, diagram, save diagram, save all diagram, refresh all diagrams but to no avail - modifications are visible only after the diagram is reloaded manually.

I would appreciate any suggestions.

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #1 on: March 19, 2013, 06:53:55 pm »
I forgot to write that I use EA 9.3, Visual Studio 2010 C#, .Net 4.0.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Hidding all links to element on diagram
« Reply #2 on: March 19, 2013, 07:27:04 pm »
Two suggestions
- Post your code here so we might be able to spot the error
- Report a bug to Sparx. No matter what you do in your code, EA should not crash.

Geert

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #3 on: March 19, 2013, 08:32:10 pm »
using System;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using System.Collections.ObjectModel;

namespace UkryjKonektory
{
    public class UkryjKonektoryClass
    {
        public String EA_Connect(EA.Repository Repository)
        {
            //No special processing required.
            return "a string";
        }

        public virtual bool EA_OnPostNewDiagramObject(EA.Repository Repository, EA.EventProperties Info)
        {
            EA.Element nowyElement;
            int elementID = 0;
            EA.Diagram tenDiagram;
            EA.Collection linkiDiagramu;
            EA.Collection linkiElementu;
            int idDiagramu = 0;
            EA.DiagramObject obiektDiagramu;
            EA.Collection obiektyDiagramu;

            foreach (EA.EventProperty eventproperty in Info)
            {
                elementID = System.Convert.ToInt32(eventproperty.Value);
            }

            nowyElement = Repository.GetElementByID(elementID);
            linkiElementu = nowyElement.Connectors;
            tenDiagram = Repository.GetCurrentDiagram();
            obiektyDiagramu = tenDiagram.DiagramObjects;
            obiektDiagramu = obiektyDiagramu.GetAt(0);
            for (short x = 0; x < obiektyDiagramu.Count; x++)
            {
                if (obiektyDiagramu.GetAt(x).ElementID == nowyElement.ElementID)
                {
                    obiektDiagramu = obiektyDiagramu.GetAt(x);
                }
            }
            idDiagramu = System.Convert.ToInt32(tenDiagram.DiagramID);
            linkiDiagramu = tenDiagram.DiagramLinks;

            if (linkiDiagramu.Count > 0 && linkiElementu.Count > 0)
            {
                for (short i = 0; i < linkiElementu.Count; i++)
                {
                    EA.Connector linkElementu = linkiElementu.GetAt(i);
                    for (short j = 0; j < linkiDiagramu.Count; j++)
                    {
                        EA.DiagramLink linkDiagramu = linkiDiagramu.GetAt(j);
                        if (linkDiagramu.ConnectorID == linkElementu.ConnectorID && linkDiagramu.IsHidden == false)
                        {
                            linkDiagramu.IsHidden = true;
                            linkDiagramu.Update();
                            tenDiagram.Update();
                            nowyElement.Update();
                            obiektDiagramu.Update();
                
                            //Repository.CloseDiagram(tenDiagram.DiagramID);
                            //Repository.OpenDiagram(tenDiagram.DiagramID);
                            MessageBox.Show("Uwaga! Konektory elementu '" + nowyElement.Name + "' zosta[ch322]y ukryte na diagramie.");

                            Repository.SaveDiagram(tenDiagram.DiagramID);
                          
                            //MessageBox.Show(idDiagramu.ToString());
                            //Repository.RefreshOpenDiagrams(false);
                            //try
                            //{

                             //   Repository.CloseDiagram(tenDiagram.DiagramID);
                                    

                            //}
                            //catch (Exception e)
                            //{
                             //   MessageBox.Show(e.ToString());
                            //}
                                                      
                        }
                    }
                }
            }
            Repository.RefreshOpenDiagrams(true);
            
            return true;
        }
        public virtual void EA_OnPostCloseDiagram(EA.Repository Repository, int DiagramID) { }
        public virtual void EA_OnPostOpenDiagram(EA.Repository Repository, int DiagramID) { }
    }
}

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Hidding all links to element on diagram
« Reply #4 on: March 19, 2013, 08:51:38 pm »
I would not do all of these updates:
Code: [Select]
tenDiagram.Update();
nowyElement.Update();
obiektDiagramu.Update();
Repository.SaveDiagram(tenDiagram.DiagramID);
and after the loop I would do a
Code: [Select]
ReloadDiagram (tenDiagram.DiagramID)instead of
Code: [Select]
Repository.RefreshOpenDiagrams(true);
Geert

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #5 on: March 19, 2013, 09:25:21 pm »
Line "Repository.ReloadDiagram (tenDiagram.DiagramID)" after the loop is the one that crashes EA (when I place element on diagram).  

I also tried:

"Repository.CloseDiagram (tenDiagram.DiagramID)" "Repository.OpenDiagram (tenDiagram.DiagramID)"

but EA crashes after "Repository.CloseDiagram (tenDiagram.DiagramID)".

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Hidding all links to element on diagram
« Reply #6 on: March 19, 2013, 10:44:12 pm »
So what happens if you leave the line out?
Do you have to close and re-open the diagram before your changes become visible?

Geert

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #7 on: March 19, 2013, 11:26:36 pm »
Without the line (ReloadDiagram), EA works normally, but I cant see the changes on diagram - i have to reopen it.  

If I leave the line and put an element on a diagram, EA shows message "EA stopped workind. Windows is searching for the solution". Windows can't find the solution, i'm forced to close EA. When I open it again, changes are available.  

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Hidding all links to element on diagram
« Reply #8 on: March 20, 2013, 12:09:59 am »
Maybe EA doesn't like it when you reload a diagram in a EA_OnPostNewDiagramObject event?

A workaround could be to reload it in another event (EA_OnContextItemChanged?)

Geert


qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Hidding all links to element on diagram
« Reply #9 on: March 20, 2013, 02:48:39 am »
The documentation does not tell anything along those lines. If EA crashes with ReloadDiagram it's simply a bug (to be reported).

q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Hidding all links to element on diagram
« Reply #10 on: March 20, 2013, 03:26:20 am »
Quote
The documentation does not tell anything along those lines. If EA crashes with ReloadDiagram it's simply a bug (to be reported).

q.
No doubt about that, should definitely be reported.

Geert

magdah

  • EA Novice
  • *
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #11 on: March 20, 2013, 05:04:09 am »
I will report the ReloadDiagram problem.

Meantime, I tried the workaround (reloading diagram in EA_OnContextItemChanged) and it seams to be working  :).

Thanks a lot :).

Danny F

  • EA User
  • **
  • Posts: 60
  • Karma: +0/-0
    • View Profile
Re: Hidding all links to element on diagram
« Reply #12 on: March 22, 2013, 08:43:19 pm »
I ran into the same problem

this is an actual line in my code  :D :
Code: [Select]
 // system crashes ! ev.Repository.ReloadDiagram(diag.DiagramID);



My work-around for it, using a static Context object in which I save the diagramGUID to be reloaded.
then on each EA_OnNotifyContextItemModified :
Code: [Select]

....
 if (ot == EA.ObjectType.otDiagram)
....
 if (Context.isDiagramSaveLoad(GUID))
 {
      Context.SaveLoadDiagram(GUID);
 }
....

Code: [Select]

internal static void  SaveLoadDiagram(String GUID)
        {
            EA.Diagram diag = Repository.GetDiagramByGuid(GUID);
            DiagramSaveLoad.Remove(GUID);
            Repository.SaveDiagram(diag.DiagramID);
            Repository.ReloadDiagram(diag.DiagramID);
        }


Especially useful in a EA_OnPredelete.... because the reload crashes EA each and every time.

Also not that not every action on a diagram triggers an EA_OnNotifyContextItemModified (or EA_OnNotifyContextItemChanged for that matter) with ot == diagram ! for example re-routing of a stateflow on a statechart.
And on the same subject, should you be in that case, know that when re-routing the client-end you get 1 EA_OnNotifyContextItemModified ot = otConnector      
notification, when you re-route the target-end you get 2 notifications.

gr


Reg.

Danny