Book a Demo

Author Topic: Shape Scripts - addSubshape  (Read 5285 times)

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Shape Scripts - addSubshape
« on: November 13, 2019, 03:58:47 am »
We are using Shape Scripts like the one below and I am trying to understand what the 2 numeric parameters after the compartment name do, how do they work and why do the produce the weird results they produce.

My understanding is that they specify the height and width as percents of each compartment. This would we fine if weren't for the fact that I have not manage to figure out a combination of values where the stereotype compartment is not too small (height wise) or the name compartment is not high.

Code: [Select]
shape main{

dockable="standard";

noShadow=true;

rectangle(0,0,100,100);

setfontcolor(0, 0, 0);
setfillcolor(255,255,255);

addSubshape("stereotypecompartment", 100, 30);

addSubshape("namecompartment", 100, 70);

shape stereotypecompartment
{

h_align = "right";
v_align = "top";

rectangle(0,0,100,100);

println("#stereotype#");


}

shape namecompartment
{
h_align = "center";
v_align = "center";

editablefield = "name";
rectangle(0,0,100,100);

printwrapped("#name#");

}
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #1 on: November 13, 2019, 04:44:05 am »
It's documented in the help (quite unusual, isn't it?) and specifies width and height (in units) of the compartment. How that effects the rendered shape is a different question. It depends on the layoutType specification.

q.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #2 on: November 13, 2019, 05:15:46 am »
It's documented in the help (quite unusual, isn't it?) and specifies width and height (in units) of the compartment. How that effects the rendered shape is a different question. It depends on the layoutType specification.

q.
I am assuming, perhaps incorrectly, that default layouttype is"TopDown", that if I do not specify it Sparx EA assumes "TopDown".

I must also admit that the help is a bit puzzling. For example, the example on https://sparxsystems.com/enterprise_architect_user_guide/14.0/modeling_tools/sub-shapes.html for a "topdown" layout appears to apply to what I would describe as a "LeftRight" - just look at the shape depicted at the bottom of the page. The 2 extra parameters are not described anywhere, all I can do is guess their purpose.

Also the description of addSubShape on https://sparxsystems.com/enterprise_architect_user_guide/14.0/modeling_tools/drawing_methods.html does not explain if the width or height is expressed as a percent or as units (and what those units are).

By the way, the script if posted is an variation of the following script from https://sparxsystems.com/enterprise_architect_user_guide/14.0/modeling_tools/example_scripts.html withe compartments swapped around. Needless to say, I cannot get the script to draw the shape as neatly as per the image next to the example.

Code: [Select]
// EDITABLE FIELD SHAPE
shape main
{
     rectangle(0, 0, 100, 100);
     addsubshape("namecompartment", 100, 20);
     addsubshape("stereotypecompartment", 100, 40);
     shape namecompartment
     {
               h_align = "center";
               editablefield = "name";
               rectangle(0, 0, 100, 100);
               println("name: #name#");
     }
     shape stereotypecompartment
     {
               h_align = "center";
               editablefield = "stereotype";
              rectangle(0, 0, 100, 100);
              println("stereotype: #stereotype#");
     }
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #3 on: November 13, 2019, 09:08:37 am »
Yeah. The sarcastic undertone in my reply might e a bit unrecognizable (though reading my other posts it should be obvious). The only thing that helps is to try and fail with EA. Currently I'm feeling like Don Quixote fighting against shape scripts in decorations. That gives me the creeps...

q.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #4 on: November 13, 2019, 09:18:33 am »
You could try setting preferredHeight in your subshapes. Give it an absolute value. Something like:

Code: [Select]
shape main
{
layouttype="border";
rectangle(0,0,100,100);
addsubshape("name","N");

shape name
{
preferredheight=16;
moveto(0,100);
lineto(100,100);
print("#name#");
}
}
The Sparx Team
[email protected]

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #5 on: November 13, 2019, 11:20:56 am »
That's quite useful. I wasn't aware of that effect.

q.

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #6 on: November 13, 2019, 10:23:40 pm »
Thanks KP, very useful.

qwerty - sorry I did not fully spotted your irony at the end of day fighting with Sparx shape scripts.

This does the best job. It still leaves an awful amount of white space at the bottom of the name compartment on (v13) which I attribute to the fact that  v_align = "center" does not really do a center vertical alignment.

I also do not understand why I need to specify preferredheight=200. It is the best value, insofar as it renders the best result, of 100, 50 & 30. But do not understand what 200 stands for.

Code: [Select]
shape main{

dockable="standard";
layouttype="border";

rectangle(0,0,100,100);

setfontcolor(0, 0, 0);
setfillcolor(255,255,255);

addSubshape("stereotypecompartment", "n");

addSubshape("namecompartment", "s");

shape stereotypecompartment
{

h_align = "right";
v_align = "top";

preferredheight=20;

moveto(0,100);
lineto(100,100);

println("#stereotype#");
}

shape namecompartment
{

h_align = "center";
v_align = "center";

preferredheight=200;

editablefield = "name";

printwrapped("#name#");

}
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #7 on: November 13, 2019, 11:26:52 pm »
As said: Fail with EA. Fail better with EA.

Don't start trying to make sense of such things. When it works for you just put it in a box and forget about it. Frustrating? Yes, but you get used to it after some time.

For me it was helpful to create that left bar of a requirement element. I had already given up, but this way it works.

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: Shape Scripts - addSubshape
« Reply #8 on: November 13, 2019, 11:41:40 pm »
The preferredheigth parameters is in absolute pixels

So setting it to 200 should set it to a fixed value of 200 pixels (which is rather large for a regular sized shapescript).
Are you sure this is how you want to use it?

Seems you actually want the name compartment in the center rather then in the south.

This seems to give a much better result:
Code: [Select]
shape main{

dockable="standard";
layouttype="border";

rectangle(0,0,100,100);

setfontcolor(0, 0, 0);
setfillcolor(255,255,255);

addSubshape("stereotypecompartment", "n");

addSubshape("namecompartment", "center");

shape stereotypecompartment
{

h_align = "right";
v_align = "top";

preferredheight=20;

moveto(0,100);
lineto(100,100);

println("#stereotype#");
}

shape namecompartment
{

h_align = "center";
v_align = "center";

editablefield = "name";

printwrapped("#name#");

}
}

Geert

Modesto Vega

  • EA Practitioner
  • ***
  • Posts: 1183
  • Karma: +30/-8
    • View Profile
Re: Shape Scripts - addSubshape
« Reply #9 on: November 14, 2019, 12:21:27 am »
Thanks Geert, much appreciated, that does a better job.