Author Topic: ShapeScript for BPMN activity  (Read 16400 times)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShapeScript for BPMN activity
« Reply #15 on: February 15, 2017, 10:53:23 pm »
Check the code for the decoration for example Archimate Business process

Code: [Select]
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);
}

I just tested this and adding a tagged value with name "showdecoration" and value "true" makes the process decoration appear in the top left corner.

Geert


Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript for BPMN activity
« Reply #16 on: February 16, 2017, 02:06:51 am »
Check the code for the decoration for example Archimate Business process

Code: [Select]
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);
}

I just tested this and adding a tagged value with name "showdecoration" and value "true" makes the process decoration appear in the top left corner. Geert

Thank you, Geert. My undestanding was that you script has been extracted from EA. And the original script does not ask for the tag, but for the property Archimate property showdecoration. Or is property also a tag? But then the script would have been worked on my computer, because the property is set.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShapeScript for BPMN activity
« Reply #17 on: February 16, 2017, 03:07:18 am »
Yes, Archimate properties are also tagged values.

This is really the shapescript that is embedded in the standard Archimate MDG, so if you have the tagged value set to true then the decoration should show.

Geert

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript for BPMN activity
« Reply #18 on: February 16, 2017, 05:27:04 am »
Yes, Archimate properties are also tagged values.
Now I understand. Thank you.

I am confused because I have alternate definitions of shapes in my script. Could I write the script like the one below? I cannot imagine, because "decoration" has to be on the top level. But then decoration would affect all shapes. Or would I need to add an if-than statement to the decoration? 

shape main
{
   layouttype="border";
   if(hasproperty("diagram.mdgtype", " BPMN2.0::Business Process "))
   {
      //BPMN
      AddSubShape("Activity","center");
   }
   else
   {
      //ArchiMate as default
      AddSubShape("ProcessStep","center");
   }

   shape Activity
   {
      {
         layouttype="border";
         ...
      }

      shape label
      {
         ...
      }

      decoration process
      {
         ...
      }
   }

   shape ProcessStep
   {
      ...
   }
}
« Last Edit: February 16, 2017, 05:56:02 am by Viking »

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13387
  • Karma: +564/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: ShapeScript for BPMN activity
« Reply #19 on: February 16, 2017, 06:05:32 am »
I guess you'll have to write the same condition in the decoration as in the main shape to distinguish between one or the other shape.

Geert

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript for BPMN activity
« Reply #20 on: February 16, 2017, 07:56:07 pm »
I guess you'll have to write the same condition in the decoration as in the main shape to distinguish between one or the other shape. Geert
O.K. I tried this. But my / our script does not work. It always shows a rounded rectangle with a small rectangle inside the rectangle. And it also changes the colour. I get mad (or schizophrenic). Any ideas, why the script does not work?

Code: [Select]
shape main
{
layouttype="border";
if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
//BPMN
AddSubShape("Activity","center");
}
else
{
//default (ArchiMate)
AddSubShape("ProcessStep","center");
}

//BPMN
shape Activity
{
layouttype="border";
if(hasTag("triggeredByEvent","true")) // 99x: 8-4-2011
{
setlinestyle("dot");
}
defsize(110,60);
startpath();
roundrect(0,0,100,100,10,10);
endpath();
fillandstrokepath();

if(hasTag("isACalledActivity","true"))
{
setpenwidth(2);
startpath();
roundrect(0,0,100,100,10,10);
endpath();
fillandstrokepath();
}
if(HasTag("isATransaction","true"))
{
roundrect(2,3,98,98,10,10);
}

if(HasProperty("BPMNexpanded","1"))
{
if(hastag("taskType","Abstract"))
{
addsubshape("nametopleft","N");
addsubshape("base","S");
addsubshape("padding","W");
addsubshape("padding","E");
addsubshape("comp","CENTER");
}
else
{
addsubshape("padding","N");
addsubshape("base","S");
addsubshape("padding","W");
addsubshape("padding","E");
addsubshape("Name","CENTER"); //BJS C13011371. Added name back to ter so it doesn't overlap
  //icons.
}
}
else
{
addsubshape("padding","N");
addsubshape("base","S");
addsubshape("padding","W");
addsubshape("padding","E");
addsubshape("Name","CENTER"); //BJS C13011371. Added name back to center so it esn't overlap
  //icons.
}

shape nametopleft
{
h_align = "left";

Printwrapped("#NAME#");
}
shape comp
{
DrawComposedDiagram();
}

shape name
{
layouttype = "border";
h_align = "center";

Printwrapped("#NAME#");

//BJS C13011371.
if(hasproperty("ShowComposedDiagram", "true"))
{
addsubshape("padding", "N");
addsubshape("Comp", "CENTER");
}

shape padding
{
preferredHeight = 35;
}

shape comp
{
DrawComposedDiagram();
}

}

shape padding
{
preferredHeight=20;
preferredWidth=6;
}

shape base
{
layouttype="border";
preferredHeight=20;

addsubshape("null","N");
addsubshape("null","S");
addsubshape("baseshapes","CENTER");

shape null
{
preferredHeight=3;
}

shape baseshapes
{
layouttype="leftright";
scalable=false;
v_align="CENTER";
h_align="CENTER";

addsubshape("spacer");
if (HasTag("loopCharacteristics","Standard"))
{
addSubShape("loop");
addsubshape("spacer");
}
if (HasTag("loopCharacteristics","MultiInstance"))
{
if(hasTag("isSequential","false"))
{
addSubShape("parallelMultiple");
addsubshape("spacer");
}
else
{
addSubShape("sequentialMultiple");
addsubshape("spacer");
}
}
if (HasTag("isForCompensation","true"))
{
addSubShape("compensation");
addsubshape("spacer");
}
if (HasTag("activityType","Sub-Process"))
{
if(HasProperty("ShowComposedDiagram", "false"))
{
if(HasProperty("BPMNexpanded","1"))
{
}
else
{
addSubShape("collapsed");
addsubshape("spacer");
}
}
}
else
{
if(HasProperty("ShowComposedDiagram", "false"))
{
if(HasProperty("iscomposite","true"))
{
addSubShape("collapsed");
addsubshape("spacer");
}
}
}
if (HasTag("adHoc","true"))
{
addSubShape("adhoc");
addsubshape("spacer");


//Sharon C12111022: Do not render any shape for "adHocOrdering" ng.
//Sharon C14033070: remove the redundant code for ocOrdering"
}
shape spacer
{
preferredWidth=2;
}

shape loop
{
preferredWidth=15;
preferredHeight=15;
setpenwidth(2);
moveto(0,90);
//bezierto(-80,-30,170,-30,80,100); 
//Sharon C11128881: Use arc() to render Loop shape.
moveto(70,90);
arc(0,0,100,100,70,90,30,90);
setfillcolor(getuserbordercolor());
startpath();
moveto(-20,100);
lineto(40,100);
lineto(40,60);
endpath();
fillpath();
}

shape sequentialMultiple
{
preferredWidth=15;
preferredHeight=15;
setfillcolor(getuserbordercolor());

startpath();
rectangle(0,10,100,25);
endpath();
fillandstrokepath();
startpath();
rectangle(0,42,100,63);
endpath();
fillandstrokepath();
startpath();
rectangle(0,80,100,95);
endpath();
fillandstrokepath();
}

shape parallelMultiple
{
preferredWidth=15;
preferredHeight=15;
setfillcolor(getuserbordercolor());

startpath();
rectangle(10,0,25,100);
endpath();
fillandstrokepath();
startpath();
rectangle(47,0,58,100);
endpath();
fillandstrokepath();
startpath();
rectangle(80,0,95,100);
endpath();
fillandstrokepath();
}

shape compensation
{
preferredWidth=15;
preferredHeight=15;

setfillcolor(getuserfillcolor());

startpath();
moveto(0,50);
lineto(50,0);
lineto(50,100);
endpath();
fillandstrokepath();
startpath();
moveto(50,50);
lineto(100,0);
lineto(100,100);
endpath();
fillandstrokepath();
}

shape collapsed
{
preferredWidth=15;
preferredHeight=15;
rectangle(0,0,100,100);
moveto(15,50);
lineto(50,50);
moveto(85,50);
lineto(50,50);
moveto(50,15);
lineto(50,50);
moveto(50,85);
lineto(50,50);
}

Shape adhoc
{
preferredWidth=15;
preferredHeight=15;
SetPenWidth(3);
MoveTo(0,50);
StartPath();
PolyBezierTo(50,0,50,100,100,50);
EndPath();
StrokePath();
}
}
}
}

//default (ArchiMate)
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#");
}
}
}

//BPMN Decoration
decoration TaskType
{
orientation="nw";
layouttype="topdown";
if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
if(hastag("activityType","Task"))
{
if(hastag("taskType","Send"))
{
setfillcolor(getuserbordercolor());
setpencolor(getuserfillcolor());

rectangle(0,0,100,90);
setpenwidth(2);
moveto(0,0);
lineto(50,50);
lineto(100,0);
}
if(hastag("taskType","Receive"))
{
if (hastag("instantiate","true")) //30/03/2011
{
ellipse(0,0,100,100);
rectangle(20,20,75,70);
moveto(20,20);
lineto(50,50);
lineto(75,20);
}
else
{
rectangle(0,0,100,90);
moveto(0,0);
lineto(50,50);
lineto(100,0);
}
}
if(hastag("taskType","BusinessRule"))
{
rectangle(0,0,120,90);
setfillcolor(192,192,192);
rectangle(0,0,120,20);

moveto(30,20);
lineto(30,90);

moveto(0,57);
lineto(120,57);
}
if(hastag("taskType","Script"))
{
moveto(20,0);
lineto(90,0); 
bezierto(50,40,110,55,90,100);
lineto(20,100);
bezierto(50,55,-10,40,20,0);

moveto(25,20);
lineto(60,20);
moveto(23, 40);
lineto(67,40);
moveto(30,60);
lineto(68,60);
moveto(35,80);
lineto(72,80);
}
if(hastag("taskType","Manual"))
{
moveto(0,80);
lineto(10,100);
lineto(80,100);
bezierto(85,100,95,90,80,85);
lineto(65,85);

moveto(80,85);
lineto(85,85);
bezierto(90,85,104,78,85,70);
lineto(60,70);

moveto(65,70);
lineto(90,70);
bezierto(90,70,115,56,75,55);
lineto(60,55);

moveto(65,55);
lineto(85,55);
bezierto(95,57,135,37,60,40);
lineto(40,40);

moveto(55,40);
bezierto(70,40,70,20,60,25);
lineto(10,25);
lineto(0,40);
}
if(hastag("taskType","User"))
{
moveto(38,50);
bezierto(14,56,5,56,0,85);
lineto(0,100);
lineto(100,100);
lineto(100,85);
bezierto(95,58,86,58,62,50);

moveto(38,45);
lineto(38,55);
lineto(62,55);
lineto(62,45);

moveto(30,90);
lineto(30,100);
moveto(70,90);
lineto(70,100);

moveto(64,50);
//Sharon C11128881: use arc() replace bezierto().
//bezierto(115,-20,-15,-20,40,47);
arc(25,0,75,50,64,50,38,49);
setfillcolor(0,0,0);
startpath();
moveto(64,25);
arcto(25,0,75,50,64,25,38,25);
lineto(64,25);
endpath();
fillandstrokepath();
}
if(hastag("taskType","Service"))
{
//Sharon C11128881: use arc() replace bezierto().
addsubshape("sub1",125,125,25,28);
addsubshape("sub2",125,125,-6,-130);

shape sub1
{
layouttype = "leftright";

moveto(79,55);
lineto(100,55);
lineto(100,45);
lineto(79,45);
arc(20,20,80,80,78,45,75,32);

moveto(75,32);
lineto(89,18);
lineto(82,11);
lineto(68,25);
arc(20,20,80,80,68,25,56,20);

moveto(56,20);
lineto(55,20);
lineto(55,0);
lineto(45,0);
lineto(45,20);

//up-left
arc(20,20,80,80,45,20,33,25);
moveto(33,25);
lineto(19,11);
lineto(11,19);
lineto(25,33);

arc(20,20,80,80,25,33,20,45);
moveto(20,45);
lineto(0,45);
lineto(0,55);
lineto(20,55);

//down-left
arc(20,20,80,80,20,55,25,67);
moveto(25,67);
lineto(11,82);
lineto(19,89);
lineto(33,75);

arc(20,20,80,80,33,75,45,80);
moveto(45,80);
lineto(45,100);
lineto(55,100);
lineto(55,80);

//down-right
arc(20,20,80,80,55,80,67,75);
moveto(67,75);
lineto(82,89);
lineto(89,82);
lineto(75,67);

arc(20,20,80,80,75,67,79,55);

addsubshape("middle", 50,50,23,24);

shape middle
{
moveto(79,55);
lineto(100,55);
lineto(100,45);
lineto(79,45);
arc(20,20,80,80,78,45,75,32);

moveto(75,32);
lineto(89,18);
lineto(82,11);
lineto(68,25);
arc(20,20,80,80,68,25,56,20);

moveto(56,20);
lineto(55,20);
lineto(55,0);
lineto(45,0);
lineto(45,20);

//up-left
arc(20,20,80,80,45,20,33,25);
moveto(33,25);
lineto(19,11);
lineto(11,19);
lineto(25,33);

arc(20,20,80,80,25,33,20,45);
moveto(20,45);
lineto(0,45);
lineto(0,55);
lineto(20,55);

//down-left
arc(20,20,80,80,20,55,25,67);
moveto(25,67);
lineto(11,82);
lineto(19,89);
lineto(33,75);

arc(20,20,80,80,33,75,45,80);
moveto(45,80);
lineto(45,100);
lineto(55,100);
lineto(55,80);

//down-right
arc(20,20,80,80,55,80,67,75);
moveto(67,75);
lineto(82,89);
lineto(89,82);
lineto(75,67);

arc(20,20,80,80,75,67,79,55);
}
}

shape sub2
{
layouttype="topdown";

v_align="CENTER";
h_align="CENTER";

moveto(75,32);
lineto(89,18);
lineto(82,11);
lineto(68,25);
arc(20,20,80,80,78,45,75,32);
arc(20,20,80,80,68,25,56,20);

moveto(56,20);
lineto(55,20);
lineto(55,0);
lineto(45,0);
lineto(45,20);

//up-left
arc(20,20,80,80,45,20,33,25);
moveto(33,25);
lineto(19,11);
lineto(11,19);
lineto(25,33);

arc(20,20,80,80,25,33,20,45);
moveto(20,45);
lineto(0,45);
lineto(0,55);
lineto(20,55);

//down-left
arc(20,20,80,80,20,55,25,67);
moveto(25,67);
lineto(11,82);
lineto(19,89);
lineto(25,83);
}
}
}
}
}

//default decorations (ArchiMate)
decoration process
{
orientation="ne";

if(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
}
else
{
if(hasproperty("rectanglenotation","0"))
{
}
else
{
/*
adding a tagged value with name "showdecoration" and value "true" makes the process decoration appear in the top left corner.
*/
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(hasproperty("diagram.mdgtype", "BPMN2.0::Business Process"))
{
}
else
{
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("diagram.mdgtype", "BPMN2.0::Business Process"))
{
}
else
{
if(hasproperty("iscomposite","true"))
{
ellipse(0,40,40,60);
ellipse(60,40,100,60);
moveto(30,50);
lineto(70,50);
}
}
}

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript for BPMN activity
« Reply #21 on: February 17, 2017, 12:12:47 am »
It works now. But a new issue arose. That's why I started a new thread. As soon as the script works properly I will publish it in ths thread.

Viking

  • EA User
  • **
  • Posts: 453
  • Karma: +2/-2
    • View Profile
Re: ShapeScript for BPMN activity
« Reply #22 on: February 20, 2017, 02:01:46 am »
The proplem has been solved. I missed a bracket. The correct code can be found in "ShapeScript - conditional setting of variables" http://sparxsystems.com/forums/smf/index.php/topic,37909.0.html.

Thank you all for your valuable input.
« Last Edit: February 20, 2017, 02:11:15 am by Viking »