Sparx Systems Forum

Enterprise Architect => Automation Interface, Add-Ins and Tools => Topic started by: 2pointO on January 27, 2016, 07:32:53 pm

Title: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: 2pointO on January 27, 2016, 07:32:53 pm
Hello,

I have following problem.
First the idea what I want to achieve :
I have a component diagram with the standard displaying of the component shapes. For visualizing spezific tagged values I added a shapescript to a stereotype which is working fine.
Now I'm trying to write a script to automatically change the appearance of all elements of a packages through assigning the customized stereotype to them which also works see this JScript :

Code: [Select]
function main()
{

var thePackage as EA.Package;
thePackage = Repository.GetTreeSelectedPackage();

var elements as EA.Collection;
elements=thePackage.Elements;


for (var i=0;i<elements.Count;i++){
var currentElement as EA.Element;
currentElement = elements.GetAt(i);
currentElement.Stereotype="custom";
currentElement.Update();
thePackage.Elements.Refresh();
}

Session.Output("Stereotype changed into CUSTOM");


}

main();

So now everything is displaying the way I want it to and I can get my wished diagram view for presenting purposes.

Here's where the problem is:

Now I want to change the appearance back to the default component type.
Because I have over a few hundred components in my package it would take a long time to reset them manually.

I had 2 thoughts on that , either delete the existing stereotype assigned to the element (but without deleting the stereotype definition because I later want to use it again with the shape script) or assign it a new stereotype which only shows the default appearance.

I tried it this way :
Code: [Select]
function main()
{

var thePackage as EA.Package;
thePackage = Repository.GetTreeSelectedPackage();


var elements as EA.Collection;
elements=thePackage.Elements;


for (var i=0;i<elements.Count;i++){

var currentElement as EA.Element;
currentElement = elements.GetAt(i);


var currentStereotype as EA.Stereotype;
currentStereotype=currentElement.Stereotype;


if(currentStereotype.Name="custom"){
currentStereotype.Name = null;

}


currentElement.Update();


thePackage.Elements.Refresh();
}

Session.Output(currentStereotype);


}

main();

But now it tells me that edit and continue are unsupported for the stereotype. If I give it another name , it just adds a blank stereotype of the name to the already existing custom stereotype to the element which doesn't override the appearance of the custom shape script. (looks like << blank , custom >>)
I even tried to assign it the _strickness attribute for only having one stereotype at a time but somehow this doesn't do anything.

The Idea behind this was to build a switch to have elements in 2 versions for displaying different attributes visually and to go back and forth between those two whenever needed.

Maybe someone can help me or knows another way around this?

Greetings Sarah
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Geert Bellekens on January 27, 2016, 08:17:16 pm
Sarah,

The stereotype is meant to indicate the meta-type of an element; which should normally never change.
If you want something to use to change the visual appearance then I suggest you use a tagged value.
In shapescripts you can check the value of a tagged value to decide how you want to visualize it.

Changing the value of a tagged value is a whole lot more straightforward then changing the stereotype.

Geert
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Glassboy on January 28, 2016, 07:52:06 am
Geert (as usual) is correct.  There is an example (multi-conditional shape) here http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/example_scripts.html
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: 2pointO on January 28, 2016, 10:27:16 pm
Hello,

I know figured it out with only taggedValues and it is working fine.

My next concern would be how do I add a shape to another shape with the following behaviour:

If I reszise the component the added shape should stay at the same spot onto the component but without resizing the shape.
I have scalable ="false" already on but when I resize the component for example because a lot of information is given in the compartment of the component , how do I get it that the shape stays as small as it's supposed to but moves with the component.

I have the DrawNativShape() and another Circle at the right lower corner overlapping (or just docking not overlapping would be fine too). Can I dock them ?

Thanks for your help so far :)
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Geert Bellekens on January 28, 2016, 10:42:25 pm
I'm sorry, I don't understand your question

Geert
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: qwerty on January 28, 2016, 10:45:46 pm
My next concern would be how do I add a shape to another shape with the following behaviour: ...
Maybe you post your script, tell what it does and what you expect it to do. I don't understand the question either.

q.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: 2pointO on January 29, 2016, 12:04:42 am
Code: [Select]
shape main
{

dockable="standard";
DrawNativeShape();

addsubshape("element",10,10,11,-10);
addsubshape("element",10,10,11,-10);
addsubshape("element",10,10,11,-10);
addsubshape("element",10,10,11,-10);
addsubshape("Circle",30,30,80,75);

shape Circle {
dockable="standard";
scalable="false";
setfillcolor(218,165,32);
ellipse(0,0,35,35);

}

shape element
{
scalable="false";
setfillcolor(255,255,255);
rectangle(00,0,-24,-18);
}


I have a script similar to this (but with a lot of if clauses but thats not important)

So now I have a nativ looking component with 4 appended elements attached to the component shape at the left upper side,
and a circle at the left bottom corner, perfect.

Now I rescale the component to a bigger then default size in the diagram but the circle and the elements now move and don't stay fixed at the components shape that I want to. I know it works if I set the the scalable="true" but I have to find a solution where it's possible that those elemens stay always at the same position relativly to the component shape.

If I have a lot of information in the component and rescale it really big the appended shapes get REALLY big and block a lot of the screen which I don't want so scalable="false" is a must in that case but without the elements moving up and down as I resize the componet.

Edit:  Or how can I align or join the nativ shape with the other shapes, both have the attributes dockable="standard" but how do I "dock" it onto each other?
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: qwerty on January 29, 2016, 01:48:59 am
I see what you mean. But I can't help. This is shape script. When it comes to calculations and conditions it is very, very limited. You might ask for a new feature, but...

Maybe a smart Sparxian has some idea.

q.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: KP on January 29, 2016, 09:01:10 am
Instead of subshapes, try using decorations.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Eve on January 29, 2016, 09:18:27 am
Decorations would be the normal way to do it.

If you want more flexibility use setfixedregion. To pin it to any edge, just extend the border to that edge as shown below.
Code: [Select]
shape main
{
    drawparentshape();
   
    //top left
    setfixedregion(0,0,40,40);
    ellipse(20,20,40,40);
   
    // bottom right
    setfixedregion(70,50,100,100);
    rectangle(70,50,90,70);
   
    // bottom left of center
    setfixedregion(30,75,50,95);
    Polygon(40,85,3,10,0);
}
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: qwerty on January 29, 2016, 11:16:20 am
SetFixedRegion is a new one, isn't it?

q.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Eve on January 29, 2016, 01:04:57 pm
SetFixedRegion is a new one, isn't it?
Since build 900.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: 2pointO on January 29, 2016, 06:33:42 pm
Thank you , decorations is just the thing I needed :)

I'm gonna try to transfer my shapes with the new input. Thanks for everyones help.

Sarah
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: qwerty on January 30, 2016, 06:40:09 am
Since build 900.
That's new  ;D

Thanks!

q.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Glassboy on February 02, 2016, 08:54:59 am
Code: [Select]
    // bottom right
    setfixedregion(70,50,100,100);
    rectangle(70,50,90,70);

This gives me a square middle right.  :)
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Eve on February 02, 2016, 09:09:24 am
The bottom right maintains a constant distance to the bottom right (because the fixed region ends at 100) If the height of the element is 80, it will be centered on the height.
If you wanted middle right set the fixed region to an equal amount above and below 50.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Glassboy on February 02, 2016, 09:33:00 am
Not disputing that, just pointing out that it's a better example if you actually draw the rectangle in the bottom right quadrant of the parent shape.  it was a surprise to cut and post the code and have the rectangle sitting midway in the parent shape.
Title: Re: Switching between Stereotypes (ShapeScripts) for individual displaying purposes
Post by: Eve on February 02, 2016, 09:53:43 am
Oh well, when I wrote it, I applied the script to a UI screen so it was larger and my statement was correct.

The example was also intended to illustrate the absolute positioning capabilities offered, so I won't try to change it now.