Book a Demo

Author Topic: shape script and bounding box  (Read 6803 times)

spirax

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
shape script and bounding box
« on: October 05, 2011, 11:33:52 am »
I have some elements with shape scripts, and their bounding boxes (series of little black boxes around the element when selected) is far larger than the shape.
This means that connectors/association lines don't join the shape - there's a big gap around it.
I have tried setting a defSize(x, y) but this has not made any difference. There doesn't seem to be any way of changing this box via a shape script - or is there?
Thanks

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: shape script and bounding box
« Reply #1 on: October 05, 2011, 12:59:52 pm »
For the majority of shape script commands, the parameters you supply are not a size in pixels but a percentage of the drawing area (bounding rectangle). So, for example,
Code: [Select]
rectangle(0,0,50,50);does not create a 50x50 pixel square, it creates a rectangle that fills the top left quarter of the overall shape. For a 50x50 square, you would need
Code: [Select]
defsize(50,50);
rectangle(0,0,100,100);
The Sparx Team
[email protected]

spirax

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: shape script and bounding box
« Reply #2 on: October 05, 2011, 01:28:45 pm »
Thanks, but I'm using moveto and lineto.
« Last Edit: October 05, 2011, 02:24:02 pm by spirax »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: shape script and bounding box
« Reply #3 on: October 05, 2011, 02:05:59 pm »
Moveto() and Lineto() both take percentage values.

Defsize() takes pixel values, and you only want one in a shape script unless you have if...else constructs in which case you might choose to have one in the if block and one in the else block. I can't think of any reason why it wouldn't work unless it's the element type: what element type are you working on?
« Last Edit: October 05, 2011, 02:06:59 pm by KP »
The Sparx Team
[email protected]

spirax

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: shape script and bounding box
« Reply #4 on: October 05, 2011, 02:11:37 pm »
Not sure what you mean - but the shape script is for a stereotype which is extending a Requirement metaclass.

Basically its a "shield" shape - here is the script I'm using.
 
Oh, and this is version 8 build 862.

Just noticed when I scale this up a bit, the defsize isn't working - I hadn't noticed because it had shrunk the overall size of the shape! So, I'm actually no better off with all these defsizes  ::)

Code: [Select]
shape main{
      noshadow = true;
      fixedAspectRatio = true;
      startpath();
      defsize(40, 50);
      moveto(25, 5);
      lineto(50, 5);
      lineto(50, 35);
      lineto(25, 35);
      lineto(25, 5);
      endpath();
      setfillcolor(100, 100, 50);
      fillandstrokepath();
      
      startpath();
      defsize(40, 80);
      moveto(25, 35);
      lineto(25, 75);
      lineto(50, 100);
      lineto(50, 35);
      lineto(25, 35);
      endpath();
      setfillcolor(255, 255, 255);
      fillandstrokepath();
      
      startpath();
      defsize(40, 80);
      moveto(50, 35);
      lineto(50, 100);
      lineto(75, 75);
      lineto(75, 35);
      lineto(50, 35);
      endpath();
      setfillcolor(100, 100, 50);
      fillandstrokepath();
      
      startpath();
      defsize(40, 50);
      moveto(50, 5);
      lineto(75, 5);
      lineto(75, 35);
      lineto(50, 35);
      lineto(50, 5);
      endpath();
      setfillcolor(255, 255, 255);
      fillandstrokepath();
}

thanks
« Last Edit: October 05, 2011, 02:24:45 pm by spirax »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: shape script and bounding box
« Reply #5 on: October 05, 2011, 02:25:20 pm »
You have 4 defsize commands but only the first one (or maybe the last one - I forget which) counts. I'm guessing you want the total size of the shape to be 80x130, in which case you need something like this:
Code: [Select]
shape main{
      noshadow = true;
      fixedAspectRatio = true;
      defsize(80,130);
      startpath();
      moveto(0, 0);
      lineto(50, 0);
      lineto(50, 35);
      lineto(0, 35);
      lineto(0, 0);
      endpath();
      setfillcolor(100, 100, 50);
      fillandstrokepath();
      
      startpath();
      moveto(0, 35);
      lineto(0, 75);
      lineto(50, 100);
      lineto(50, 35);
      lineto(0, 35);
      endpath();
      setfillcolor(255, 255, 255);
      fillandstrokepath();
      
      startpath();
      moveto(50, 35);
      lineto(50, 100);
      lineto(100, 75);
      lineto(100, 35);
      lineto(50, 35);
      endpath();
      setfillcolor(100, 100, 50);
      fillandstrokepath();
      
      startpath();
      moveto(50, 0);
      lineto(100, 0);
      lineto(100, 35);
      lineto(50, 35);
      lineto(50, 0);
      endpath();
      setfillcolor(255, 255, 255);
      fillandstrokepath();
}
« Last Edit: October 05, 2011, 02:27:03 pm by KP »
The Sparx Team
[email protected]

spirax

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: shape script and bounding box
« Reply #6 on: October 05, 2011, 02:32:34 pm »
That's what I started with - the bounding box is way outside the shape. How do I get the bounding box to be the same size as the shape?

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +55/-3
    • View Profile
Re: shape script and bounding box
« Reply #7 on: October 05, 2011, 02:52:42 pm »
Did you copy and paste my whole solution? I changed a lot of the numbers in the lineto() and moveto() commands: I replaced all x values of 25 with 0 so the left edge of the shape is on the edge of the bounding rect, replaced all x values of 75 with 100 to fix the right edge, and all y values of 5 with 0 to fix the top edge.
The Sparx Team
[email protected]

spirax

  • EA User
  • **
  • Posts: 25
  • Karma: +0/-0
    • View Profile
Re: shape script and bounding box
« Reply #8 on: October 06, 2011, 07:12:01 am »
Oh! no I didn't, sorry.  But yes that works. Thanks.