Author Topic: Switching between Stereotypes (ShapeScripts) for individual displaying purposes  (Read 18973 times)

2pointO

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
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

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
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

2pointO

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
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 :)

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13240
  • Karma: +554/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
I'm sorry, I don't understand your question

Geert

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
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.

2pointO

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
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?
« Last Edit: January 29, 2016, 01:22:19 am by 2pointO »

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
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.

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Instead of subshapes, try using decorations.
The Sparx Team
[email protected]

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
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);
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile
SetFixedRegion is a new one, isn't it?

q.

Eve

  • EA Administrator
  • EA Guru
  • *****
  • Posts: 8061
  • Karma: +118/-20
    • View Profile
SetFixedRegion is a new one, isn't it?
Since build 900.

2pointO

  • EA Novice
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
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

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +396/-301
  • I'm no guru at all
    • View Profile

Glassboy

  • EA Practitioner
  • ***
  • Posts: 1367
  • Karma: +112/-75
    • View Profile
Code: [Select]
    // bottom right
    setfixedregion(70,50,100,100);
    rectangle(70,50,90,70);

This gives me a square middle right.  :)