Author Topic: ShapeScript - conditional setting of variables  (Read 10280 times)

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
ShapeScript - conditional setting of variables
« on: February 17, 2017, 12:23:56 am »
Hello together,

Is there a possiblity to set a variable inside an if-statement? I have a script with decorations. The decoration has to be excuted dependant on a condition. But before the condition can execute, the variables has to be set. This destroys the shape. Unfortunately there seems no function available doing the same. A function would help, because it could be executed after an if-statement.

Please find a snipet below. V

decoration process
{
   orientation="ne";

   if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
   {
   }
   else
   {
      if(hasproperty("rectanglenotation","0"))
      {
      }
      else
      {
         if(hastag("showdecoration","true"))
         {
            moveto(0,25);
            lineto(55,25);
            ...
         }
      }
   }
}
« Last Edit: February 17, 2017, 01:30:28 am by Viking »

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #1 on: February 17, 2017, 08:59:46 am »
So if I understand you correctly, you want to change the orientation of a decoration dependent on an if-condition, but you have found that you can only have one orientation assignment per decoration. What you could do is have two decorations, each with their own orientation assignment, one for the if-condition and the other for the else-condition.
The Sparx Team
[email protected]

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #2 on: February 17, 2017, 05:53:39 pm »
So if I understand you correctly, you want to change the orientation of a decoration dependent on an if-condition, but you have found that you can only have one orientation assignment per decoration. What you could do is have two decorations, each with their own orientation assignment, one for the if-condition and the other for the else-condition.
Hello KP. It is more a problem with "Decoration". My understanding is, that this statement has to be on top-level. So I cannot put an if-than-statement before. Because the variables-settings (like "Orientation") have to be at the beginning of the "Decoration"-statement, the if-then-statement is after the variables-settings. So I have to run the code (variables-settings) without wanting to do that. V

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #3 on: February 17, 2017, 06:11:35 pm »
Hi Viking,

I think you are misunderstanding what the orientation statement is, it is NOT setting a variable, it is initialising a rendering attribute for that decoration (subshape).

We have conditional decorations all over the place, typically altering the icon we place at the top right (Orientation="NE"), based upon the values in tagged values.

Once you've decided where the decoration needs to go, you can only put one decoration there (AFAIK).

By the nature of its design, the decoration should not be moved from its notional orientation by conditionalisation.  However, that doesn't mean that the content (shape you produce), can't be placed almost anywhere on the Item.

Does that help?
Paolo
« Last Edit: February 17, 2017, 06:19:44 pm by Paolo F Cantoni »
Inconsistently correct systems DON'T EXIST!
... Therefore, aim for consistency; in the expectation of achieving correctness....
-Semantica-
Helsinki Principle Rules!

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #4 on: February 17, 2017, 08:59:52 pm »
Hi Viking,

I think you are misunderstanding what the orientation statement is, it is NOT setting a variable, it is initialising a rendering attribute for that decoration (subshape).

We have conditional decorations all over the place, typically altering the icon we place at the top right (Orientation="NE"), based upon the values in tagged values.

Once you've decided where the decoration needs to go, you can only put one decoration there (AFAIK).

By the nature of its design, the decoration should not be moved from its notional orientation by conditionalisation.  However, that doesn't mean that the content (shape you produce), can't be placed almost anywhere on the Item.

Does that help?
Paolo

Dear Paolo, many thanks for your feedback. I thought, that decoration is a statement that has to be on top level (like shape). The "compiler" of EA complained this. Maybe it was another reason. I have to try. V

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #5 on: February 18, 2017, 06:19:12 am »
Hi Paolo,
If I use the if-statement at the end of the script, the shape does not get chance resp. does not show the arrow on the top right. If I leave the if-statement away, than the arrow appears. The if-statement is false, so the script should be passed.
V

Code: [Select]
if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
}
else
{
decoration process
{
orientation="ne";

if(hasproperty("rectanglenotation","0"))
{
}
else
{
if(hastag("showdecoration","true"))
{
moveto(0,25);
lineto(55,25);
lineto(55,0);
lineto(80,50);
lineto(55,100);
lineto(55,75);
lineto(0,75);
lineto(0,25);
}
}
}
}
}

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #6 on: February 18, 2017, 06:25:09 am »
... and if I use the decoration statement after a shape-statement, it is not excuted either.

Code: [Select]
shape ProcessStep
{
layouttype="border";
v_align="center";
h_align="center";

if(hasproperty("rectanglenotation","0"))
{
defsize(90,40);
startpath();
moveto(0,0);
lineto(75,0);
lineto(75,-30);
lineto(100,50);
lineto(75,130);
lineto(75,100);
lineto(0,100);
lineto(0,0);
endpath();
fillandstrokepath();
}
else
{
defsize(105,70);
roundrect(0,0,100,100,20,20);
addsubshape("padding","n");
addsubshape("name","center");

shape padding
{
preferredheight=20;
}

shape name
{
h_align="center";
print("#name#");
}
}

shape label
{
setorigin("sw",0,0);

if(hasproperty("rectanglenotation","0"))
{
print("#name#");
}
}

decoration process
{
orientation="ne";

if(hasproperty("rectanglenotation","0"))
{
}
else
{
if(hastag("showdecoration","true"))
{
moveto(0,25);
lineto(55,25);
lineto(55,0);
lineto(80,50);
lineto(55,100);
lineto(55,75);
lineto(0,75);
lineto(0,25);
}
}
}

decoration atomic
{
orientation="nw";

if(hastag("atomic","true"))
{
ellipse(0,0,100,100);
moveto(20,80);
lineto(50,20);
lineto(80,80);
moveto(35,50);
lineto(65,50);
}
}

decoration composite
{
orientation="SE";
if(hasproperty("iscomposite","true"))
{
ellipse(0,40,40,60);
ellipse(60,40,100,60);
moveto(30,50);
lineto(70,50);
}
}
}

If I put the decoration-statement after the shape-statement (on the same level resp. top-level) it gets executed.

Why?

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #7 on: February 18, 2017, 07:26:36 am »
Because decoration needs to be on top level.

q.

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #8 on: February 19, 2017, 10:51:26 pm »
Because decoration needs to be on top level.q.
O.K., this is also what I told Paolo.

That's why I wanted to use an if-statement. But the variable-seeting has to be before the if-statement. Is there a way to put the variable-setting inside the if-statement?

The reason why I stick to the decorations is that I want to reuse the standard-shapescripts due to maintenance.
« Last Edit: February 19, 2017, 10:54:01 pm by Viking »

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #9 on: February 20, 2017, 01:54:17 am »
My problem has been solved. I "forgot" one bracket and the editor did not recognize, that there are more open than close brackets. Many thanks to all. It is always a good choice using the outliner carefully.

Thank you all for your valuable input.

Edit: Unfortunately it is not solved. Now I run into property-issues :-(
« Last Edit: February 20, 2017, 07:09:53 pm by Viking »

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8607
  • Karma: +257/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #10 on: February 20, 2017, 10:59:57 am »
My problem has been solved. I "forgot" one bracket and the editor did not recognize, that there are more open than close brackets. Many thanks to all. It is always a good choice using the outliner carefully.

Thank you all for your valuable input.

Edit: Unfortunately it not solved. Now I run into property-issues :-(
Ah yes, the "unbalanced parentheses" problem.  We've all been there.  Put in a bug report.  The compiler should pick it up.

The decoration shape is a top-level shape (as qwerty says).  You can define multiple decorations in a shape script.  However, as I said, you can only define one per orientation.  EA will draw the main shape and then any decorations.

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

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: ShapeScript - conditional setting of variables
« Reply #11 on: February 20, 2017, 12:01:44 pm »
That's why I wanted to use an if-statement. But the variable-seeting has to be before the if-statement. Is there a way to put the variable-setting inside the if-statement?

Do something like this:
Code: [Select]
decoration one
{
    orientation="NE";
    if (<if-expression>)
    {
        <drawing-commands>
    }
}

decoration two
{
    orientation="NW";
    if (<if-expression>)
    {
    }
    else
    {
        <drawing-commands>
    }
}
The Sparx Team
[email protected]