Book a Demo

Author Topic: Tree position  (Read 5924 times)

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Tree position
« on: June 11, 2013, 06:21:54 pm »
Hello,

i just wanted to get all informations about my current package chapter for an individual element.

To achieve that i wanted to recurse the packages according their Parentpackage and log down the Treeposition.

BUT...

the Treeposition i got from the Database or from the API does not correspondent to the project browser treeview.

Bug, issue or my fault?

Here is the code I call to walk through the packages.

Code: [Select]
                   sb.Append(Convert.ToString(rePackage.Element.TreePos));
                    sb.Append(".");
                    sb.Append(pkgstruct.ToString());
                    return getpkgstructure(_Repository.GetPackageByID(rePackage.ParentID), _Repository, sb.ToString());  

I know package treeview starts with "0" "Zero" ad has to be increased by +1 to make it usable.

Why is the database content not consistent with the project treeview?

Best regards

Stefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

Helmut Ortmann

  • EA User
  • **
  • Posts: 970
  • Karma: +42/-1
    • View Profile
Re: Tree position
« Reply #1 on: June 11, 2013, 08:09:02 pm »
Hello,

good ways to get familare with EA scripting/addins are:
  • Thomas Kilians Ebooks (Inside+Scripting)
  • The EA Examples in the Scripting View (Manage PagagesExample)
  • The EA Examples in the Scripting View (Manage Elements Example)

     (in group Local Scripts)
[/list]

In essence you have to rercursively go through the collection Packages. TreePos is the position in the current collection of packages.

Best regards,

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

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Tree position
« Reply #2 on: June 11, 2013, 08:29:42 pm »
Hi,

i'm very sorry i missed the half of the recursion. However this is not the matter

Complete code:
Code: [Select]
       public string getpkgstructure(EA.Package rePackage, EA.Repository _Repository, string pkgstruct)
        {
            StringBuilder sb = new StringBuilder();
            
            if (rePackage.ParentID != 0)
            {
                if (pkgstruct.Length == 0)
                {
                    pkgstruct = rePackage.Element.TreePos.ToString();
                    return getpkgstructure(_Repository.GetPackageByID(rePackage.ParentID), _Repository, pkgstruct);  
                }
                else
                {
                    sb.Append(Convert.ToString(rePackage.Element.TreePos));
                    sb.Append(".");
                    sb.Append(pkgstruct.ToString());
                    return getpkgstructure(_Repository.GetPackageByID(rePackage.ParentID), _Repository, sb.ToString());  
                }                              
            }
            else
            {
                return pkgstruct;
            }
                
        }

If you take a look at the tPOS column in the databases, or eap-file or with ENARSpy - you will see a discrepancy between the shown model in the project browsers' tree - than the underlying information. (And the mismatch is not the "-1" - The TPOS integer starts with "0")  ;)

How is that mismatch betwen Project browser and database handled?

Regards

Stefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Tree position
« Reply #3 on: June 11, 2013, 09:07:07 pm »
Can you show an example of the discrepancy?

q.

Stefan Bolleininger

  • EA User
  • **
  • Posts: 308
  • Karma: +0/-0
    • View Profile
Re: Tree position
« Reply #4 on: June 11, 2013, 09:45:12 pm »
Hi,

I investigated the following:

if you are deleting or moving an package or element to another parent, the moved element gets re-adjusted.

BUT the other elements are not informed about this update, nd are not adjusted.

The project browser just calles ALL elements and shows all existing according their TPOS. Blank TPOS are not filled up, they are just empty spaces.
e.g. TPOS: 1,5,7,8,9,10,25,30 is possible and all elements are shown in the model view.

So, this is just feature, not a bug  :P :P :P

I need to correct my code by "filtering all elements with the same parent and TPOS < myelement.TPOS

Best regards

Stefan
Enterprise Architect in "safetycritical development" like medical device industry. My free Add-in at my Website

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Tree position
« Reply #5 on: June 11, 2013, 11:23:29 pm »
I know about that (but don't remember how often I've posted it). TPOS is only respected when you use the hand symbol. Or in strange conjunction with the "Show Features Alphabetically" and "Free Sorting". To get the order shown in the browser you need a not so easy to construct wrapper.

q.

[edit:]
Quote
6.1 Ordering of Collections
You will find that the ordering of collections does not match that you find in EA’s project browser. Most objects have a Pos or a TPos property. Only if this is non-zero it is valid and supersedes the occurrence in the collection. Also you will find that the browser has some rules to internally group packages, diagrams and elements. Further there is a Sort Features Alphabetically option under Tools/Options/General which interferes. So if you need the same ordering as in the browser you have to code a bit.
from my Scripting book.
« Last Edit: June 11, 2013, 11:39:45 pm by qwerty »