Book a Demo

Author Topic: How to detect an Embedded Element  (Read 9193 times)

Ian Mitchell

  • EA User
  • **
  • Posts: 507
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
How to detect an Embedded Element
« on: June 29, 2016, 11:38:37 pm »
Does anyone know if it's possible to detect when an element is an EA 'embedded element', that is, and element of a type which cannot be dropped onto a diagram ? I've looked through all the obvious attributes of the element, and nothing says 'I'm an  embedded element'.
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: How to detect an Embedded Element
« Reply #1 on: June 29, 2016, 11:41:40 pm »
Hi Ian,

well an embedded element as defined by EA is not restricted from being added to a diagram, e.g. a port is an embedded element (=you can find it in the Element.EmbeddedElements collection) and obviously can be added to a diagram.

Hope that helped!
Jan

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: How to detect an Embedded Element
« Reply #2 on: June 30, 2016, 12:15:33 am »
AFAIK they are limited to Ports, Pins and ... maybe a few more.

q.

Ian Mitchell

  • EA User
  • **
  • Posts: 507
  • Karma: +22/-4
  • The eaDocX and Model Expert guy
    • View Profile
Re: How to detect an Embedded Element
« Reply #3 on: June 30, 2016, 09:00:30 pm »
Ah - so the parent element (the thing in which my element is embedded) know what is embedded in it, but the embedded element would have to look through all the 'embedded elements' collection of all elements to try to find itself.
More SQL....:-(
Ian Mitchell, Designer, eaDocX


www.eaDocX.com
www.theartfulmodeller.com

McMannus

  • EA User
  • **
  • Posts: 108
  • Karma: +4/-1
    • View Profile
Re: How to detect an Embedded Element
« Reply #4 on: June 30, 2016, 09:16:52 pm »
Almost: You have to look in its parent element's EmbeddedElements collection.

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: How to detect an Embedded Element
« Reply #5 on: June 30, 2016, 09:17:27 pm »
Hi Ian,


Well the embedded element wouldn't have to look through the EmbeddedElement collections of all elements. It'd just need to check its own parent's. The child knows who its parent is, and if it finds itself in the parent's EmbeddedElements it's an embedded child.

In the API this is a pretty straightforward check:
Code: (pseudo) [Select]
if childElement.ElementID in Repository.GetElementByID(childElement.ParentID).EmbeddedElements
In terms of SQL though, the regular-vs-embedded distinction doesn't exist. So if it's SQL I think you'll have to check that the (child) element has a parent and then what type it is (Part, Port, etc).

Note, however, that at least Parts and Ports can be dropped onto a diagram if the parent is already there but the embedded child isn't. EA only allows you to select Paste As Link in that situation, and you can drop the child anywhere on the diagram and EA will move it to the parent.

HTH,


/Uffe
My theories are always correct, just apply them to the right reality.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: How to detect an Embedded Element
« Reply #6 on: July 01, 2016, 08:52:54 am »
To determine if a given element is an embedded element (i.e. edge-mounted, can't exist in isolation) test its type against a look-up list. Off the top of my head, it would include: Port, ObjectNode, ActionPin, ActivityParameter, ExpansionNode, RequiredInterface, ProvidedInterface, EntryPoint, ExitPoint.
« Last Edit: July 01, 2016, 12:12:48 pm by KP »
The Sparx Team
[email protected]

philchudley

  • EA User
  • **
  • Posts: 750
  • Karma: +22/-0
  • EA Consultant / Trainer - Sparx Europe
    • View Profile
Re: How to detect an Embedded Element
« Reply #7 on: July 15, 2016, 08:47:02 pm »
Hi All,

The following is the code I used within my EA Extension EA SafeDelete

        private bool isStructuralElement(EA.Repository repository, EA.Element contextElement)
        {
            // Get the object type
            switch (contextElement.Type)
            {
                case "Port":
                    return true;
                case "ActionPin":
                    return true;
                case "ProvidedInterface":
                    return true;
                case "RequiredInterface":
                    return true;
                case "ActivityParameter":
                    return true;
                case "ExpansionNode":
                    return true;
                case "ObjectNode":
                    return true;
                case "Part":
                    return isNotReferencePart(repository, contextElement);
                default:
                    return false;
            }
        }

        private bool isNotReferencePart(EA.Repository repository, EA.Element contextElement)
        {

            // To find this out, we need to extract and examine the Description field in the
            // contextElement's corresponding entry in the t_xref table

            String tXrefDescription = null;

            string sqlSearch = "SELECT t_xref.Description AS [Description]" +
                               "FROM t_object, t_xref " +
                               "WHERE t_object.ea_guid = '" + contextElement.ElementGUID + "'" +
                               "AND   t_object.ea_guid = t_xref.Client";

            string queryResult = string.Empty;
            queryResult = repository.SQLQuery(sqlSearch);

            XmlDocument requirement = new XmlDocument();
            requirement.LoadXml(queryResult);

            // Examine the result
            XmlNode description = requirement.SelectSingleNode("//Row/Description");
            if (description != null)
            {
                tXrefDescription = description.InnerText;

                // Now, the fun begins, we need to
                //
                // First extract the parts of description (delimited by ;)
                // Extract the value that tells us if the element is a reference Part

                String[] descriptionParts = tXrefDescription.Split(new char[] { ';' });

                // We need the eighth part (index 7)
                //
                // This has the format @VALU=n @ENDVALU
                //
                // So we can just test for a contains of 0 for not a reference part

                return descriptionParts[7].Contains('0');
            }
            return true;
        }

This appears to work for me, don't think I missed any Structural Elements (embedded elements).

Cheers

Phil
Models are great!
Correct models are even greater!