Book a Demo

Author Topic: Compartments - how to?  (Read 6462 times)

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Compartments - how to?
« on: February 03, 2017, 12:31:51 pm »
Not having a lot of luck (which seems to be what is required when writing shapescripts) getting Compartments to work.

Trying to read the Help and other posts in the Forum, it seems:
  • You can't create compartments for custom scripts
  • You can only create compartments for Child Elements and Related Elements
  • You can't create compartments ad-hoc even for nativeshapes
Is that correct?

Could some kind soul post a WORKING (preferably with v13) compartment enhanced shape script? 

I tried some shown in the Help, I got a ChildElement script to work - though not as I expected, but I can't get the RelatedElement script to work at all.

What "secret sauce" am I missing?
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8110
  • Karma: +119/-20
    • View Profile
Re: Compartments - how to?
« Reply #1 on: February 03, 2017, 01:52:27 pm »
1. Yes, they work for native shapes (that otherwise draw compartments) only.
2-3. Shape scripts only allow the definition of those two types. However, there is an add-in call that allows an add-in to define ad-hoc compartments. However, if you decide to use it you need to manage caching of the data yourself. It is called with every draw so you will turn your experience to sludge if you try looping through anything in the API.

I suspect your related element script is failing because the related elements are already on the diagram. There is also visibility options for each compartment type that you define.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Compartments - how to?
« Reply #2 on: February 03, 2017, 03:43:02 pm »
[SNIP]
I suspect your related element script is failing because the related elements are already on the diagram. There is also visibility options for each compartment type that you define.
Nope,

Deleted from the diagram and still no joy.  Where else to look?

Can you make the example work?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Compartments - how to?
« Reply #3 on: February 03, 2017, 08:08:07 pm »
I remember also that I tested the related element. I found that a good sleep, a nice day and some coffee helped to get it working. And, as you mentioned, a good portion of luck  :-\

q.

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Compartments - how to?
« Reply #4 on: February 16, 2017, 06:02:51 pm »
So I'm trying to get this to work again...  qwerty's suggestion didn't work - although the espresso was very nice.

So can anybody explain why this code (taken almost directly from the example page) doesn't work at all?

Code: [Select]
shape main
{
if(hasproperty("rectanglenotation","0")) //Icon Form
{
drawnativeshape();
}
else
{
drawnativeshape();
}
}

shape RelatedElement
{
     SetCompartmentName("RelatedElements");
     AppendCompartmentText("appended text");
//Check if the current connector being processed is a Realization
if(HasProperty("Connector.Type", "Realization"))
{
         //Only display this compartment if the related element we
         //are checking is the target of the connector that has this
         //shape scripts element as the source
         if(HasProperty("Element.IsTarget"))
         {
                 //If the element is an interface, display it in
                 //'realizedInterfaces' compartment
                 if(HasProperty("Element.Type", "Interface"))
                 {
                         SetCompartmentName("realizedInterfaces");
                         AppendCompartmentText("#Element.Name#");
                 }
         }
}

//Check if the current connector we are processing has a
//dependency type.
if(HasProperty("Connector.Type", "Dependency"))
{
         //Check if the element we are currently checking is
         //the target of the current connector.
         if(HasProperty("Element.IsTarget"))
         {
                 //Set the compartment Name
                 SetCompartmentName("dependsOn");
                 if(HasProperty("Element.Stereotype", ""))
                 {
                 AppendCompartmentText("??No Stereotype set");
                 }
                 else
                 {
                 AppendCompartmentText("«#Element.Stereotype#» ");
                 }
                 AppendCompartmentText("#Element.Name#");
         }
}
}
I have three elements on the diagram one with a Relaization to the interface and a dependency to another (stereotyped) element.
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Compartments - how to?
« Reply #5 on: February 16, 2017, 07:09:04 pm »
You got me thinking, but...

I tried this example from the help
Code: [Select]
shape RelatedElement
{
     //Check if the current connector we are processing has a
     //dependency type.
     if(HasProperty("Connector.Type", "Dependency"))
     {
          //Check if the element we are currently checking is
          //the target of the current connector.
          if(HasProperty("Element.IsTarget"))
          {
               //Set the compartment Name
               SetCompartmentName("dependsOn");
               if(HasProperty("Element.Stereotype", ""))
               {
               }
               else
               {
                    AppendCompartmentText("«#Element.Stereotype#»");
               }
               AppendCompartmentText("#Element.Name#");
          }
     }
}
where you should see dependent classes. It did not work. I seem to remember that one of the Sparxians mentioned some Feature Visibility check box which appeared only under certain circumstances. But I can't find that again.

I probably tried with another one from the examples. Anyhow, this is a mine field.

q.

P.S. I got this now to work again:
Code: [Select]
shape ChildElement
{
     //Check if a child element has the property stereotype, if so set
     //the compartment name to Properties.
     if(HasProperty("stereotype", "property"))
     {
          SetCompartmentName("Properties");
     }
     //Check if the child element has a public scope and if so add the +
     //symbol to the child compartment.
     if(HasProperty("scope", "public"))
     {
          AppendCompartmentText("+");
     }
     //Add the child elements name to the child compartment.
     AppendCompartmentText("#NAME#");
}
I had to remove the contained element from the diagram which made the compartment visible. Also this one showed Properties as new check box in  Feature Visibility.
« Last Edit: February 16, 2017, 07:17:15 pm by qwerty »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Compartments - how to?
« Reply #6 on: February 17, 2017, 10:09:25 am »
Thanks, qwerty,

I, too, got the Child element stuff to work.  Like you, I found I had to remove the child from the diagram in order to get the compartment to show.  However, once it was visible, I could put the child element back and retain the compartment - pure EAUI?

Anyway, at least it's not personal that the related elements aren't working.  Can a Sparxian, or anyone else, please show us all how to do this?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Compartments - how to?
« Reply #7 on: February 21, 2017, 01:36:55 pm »
[BUMP]

Is it really this hard?  Do I need to submit a formal support request to get an answer?

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Compartments - how to?
« Reply #8 on: February 24, 2017, 11:14:57 am »
Formal support request submitted!

If, and when, I get a working example, I'll post it here.

Paolo
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!