Author Topic: Z-order by  DiagramObject.Sequence does not work  (Read 6070 times)

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Z-order by  DiagramObject.Sequence does not work
« on: June 06, 2013, 01:15:09 am »
Hi all,

I'm struggling with the DiagramObject.Sequence attribute.
My Code:

Code: [Select]
       public static void putElementInDiagram(EA.Repository Repository, EA.Element element, ElementLayout layout, int diagramID)
        {
            EA.Diagram diagram = Repository.GetDiagramByID(diagramID);
            EA.DiagramObject newDiagObject = diagram.DiagramObjects.AddNew(layout.getEAPosString(), "");
            newDiagObject.ElementID = element.ElementID;
            newDiagObject.Sequence = 1;
            newDiagObject.Update();
            Repository.SaveDiagram(diagramID);
            Repository.ReloadDiagram(diagramID);
        }

To my knowledge, newDiagObject.Sequence = 1 brings the diagram object in front of all others. Unfortunately, this has no effect to the t_diagramobjects table, although I invoke the Update method.

Any advice?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #1 on: June 06, 2013, 04:51:03 am »
I'm using the current build and had no problem with above code. I assigned seq. 12 and that was a) reflected in t_diagramobjects and b) displayed correctly on the diagram.

q.
« Last Edit: June 06, 2013, 04:51:49 am by qwerty »

Aaron B

  • EA Administrator
  • EA User
  • *****
  • Posts: 941
  • Karma: +18/-0
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #2 on: June 06, 2013, 10:03:23 am »
Try getting rid of the SaveDiagram() call.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #3 on: June 06, 2013, 05:00:33 pm »
There is a subtle difference between Repository.SaveDiagram() and Diagram.Update().
Repository.SaveDiagram() will the save the unsaved changes in an opened diagram.
Diagram.Update() will save the changes you have made to the EA.Diagram object in memory (and thus ignore all unsaved changes on the opened diagram)
So since you are calling Repository.SaveDiagram() it it saving the object in the memory of the EA GUI, and not the object your are working with in your add-in.

But in this particular case you don't even need to save the diagram because you are not changing anything to the diagram, only to a DiagramObject.

Geert

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #4 on: June 06, 2013, 05:32:42 pm »
Well, I just tried my code again with one element and Sequence=12 as qwerty suggested. This worked! But am I wrong when I think of a setting where I have multiple objects with sequences 1,2,3,4,5,... and just add a new DiagramObject at Sequence=1 to bring it in front of all others, so that EA automatically increases all other sequence numbers by one automatically?

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #5 on: June 06, 2013, 05:40:41 pm »
EA doesn't do much automatically when using the API.

Geert

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #6 on: June 06, 2013, 05:45:55 pm »
I see, unfortunately not a very consistent approach, since one would assume that EA takes care in its API that the invariant "only one diagramobject per layer" is always true, no matter what is assigned to any sequence number.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #7 on: June 06, 2013, 10:58:14 pm »
Sparx' definition of consistency is obviously different to that of many users posting here. As Geert said: if you're using the API then YOU are responsible. That goes for quite some other use cases too - even worse.
q.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13241
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #8 on: June 07, 2013, 03:50:00 pm »
I always consider the API as a very thin layer around the actual database. So not much different to actually working with the database directly.

And don't forget, there's hardly any constraint defined on that database :'(

Geert

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #9 on: June 07, 2013, 04:48:34 pm »
It's always the same tradeoffs API developers have to consider: Flexibility vs. Convenience ;)

Helmut Ortmann

  • EA User
  • **
  • Posts: 967
  • Karma: +42/-1
    • View Profile
Re: Z-order by  DiagramObject.Sequence does not wo
« Reply #10 on: November 29, 2013, 02:22:31 am »
Hi,

I do it wirh SQL:
  • Add 1 to all sequences of diagram (sql update)
  • Create & update() DiagramObject with EA API
  • Add 1 to sequence of just created DiagramObject (sql update)

Code snippet:
Code: [Select]
string updateStr = @"update t_DiagramObjects set sequence = sequence + 1 "+
                       " where diagram_id = " + dia.DiagramID.ToString();

            rep.Execute(updateStr);
Code: [Select]
string updateStr = @"update t_DiagramObjects set sequence = " + sequence +
                       " where diagram_id = " + dia.DiagramID.ToString() +
                       " AND instance_id = " + obj.InstanceID.ToString();

            rep.Execute(updateStr);

Helmut
Coaching, Training, Workshop (Addins: hoTools, Search&Replace, LineStyle)