Book a Demo

Author Topic: Display some tags but not others  (Read 11241 times)

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Display some tags but not others
« on: April 19, 2016, 01:39:36 am »
Hello all

I'd like to show some element tags, but not others, in the tags compartment of elements on a diagram.

I'm using EA 12.1 Sys Eng and SysML 1.4.   I've extended some SysML types via a profile by adding tags (as described here: http://sparxsystems.com/forums/smf/index.php/topic,30606.msg222941.html#msg222941)

I'd like to display my new tags in the element's compartment but not other tags that I don't use (e.g. id, risk, source).   Is that possible?
I guess it could either be done at "display time" when I add the element to a diagram, or more likely at the time I create the new element type in a profile - I don't know how to though.
Any hints?



qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Display some tags but not others
« Reply #1 on: April 19, 2016, 01:47:34 am »
Unless you write a shape script to individually display tagged values you've got only the all or nothing option from Feature and Compartment Visibility.

q.

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Display some tags but not others
« Reply #2 on: April 19, 2016, 01:49:18 am »
That's a clear response, thanks qwerty.  I'll roll-up my sleeves and learn about shape scripts :-)
Many thanks.

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Display some tags but not others
« Reply #3 on: April 19, 2016, 11:34:55 pm »
Bother, I've not managed to display tags with a shape script.  I like the sound of qwerty's suggestion but I can't work out how to write the shape script.

Ideally I'd like the element to be drawn "as normal" but with the addition of a new compartment for the tags I want to always show.

This help topic looks like exactly what I want:
http://www.sparxsystems.com/enterprise_architect_user_guide/10/extending_uml_models/add_custom_compartments_to_ele.html
However that appears to be for "child elements" whereas I'm working with this-element's tags.   I've read all(?) the other related help topics and examples, searched the forum and looked at the ebook: https://leanpub.com/shapescript

I've tried building the shape "from scratch".  Like this:
shape main
{
   rectangle(0,0,100,100);
   
   addsubshape("namecompartment", 100, 30);
   addsubshape("tagscompartment", 100, 30);
   addsubshape("notescompartment", 100,40);
   
   
   shape namecompartment
   {
      h_align = "center";
      //rectangle(0,0,100,30);
      println("<<#stereotype#>>");
      println("#name#");
   }
   
   shape tagscompartment
   {
      //rectangle(0,0,100,30);
      println("MyTag_1: #TAG:MyTag_1#");
      println("MyTag_2: #TAG:MyTag_2#");
   }
   
   shape notescompartment
   {
      //rectangle(0,0,100,40);
      SetCompartmentName("notes");
      println("#notes#");
   }

}


This looks close but I've a couple of issues I need help with:

1) How do I get the stereotype and name (in the namecompartment) to be drawn in bold font?
2) How do I draw the notes in gray color, italic font?
3) How do I position the compartments correctly (vertically) and have horizontal lines between them? (Note I've commented out calls to rectangle in the script above... I don't know how/where to position them).




qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Display some tags but not others
« Reply #4 on: April 19, 2016, 11:57:42 pm »
1&2: you can't
3: There's an example script in the help which you can follow to produce compartments.

q.

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Display some tags but not others
« Reply #5 on: April 20, 2016, 01:18:14 am »
Okay, thanks qwerty.

I've been trying these help topics and can't get the sizing (and resizing) right.

http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/example_scripts.html
and
http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/add_custom_compartments_to_ele.html


The help on adding compartments appears to be in the context of child-elements, not for "this" element.

Here's the best I've got so far:
shape main
{
   rectangle(0,0,100,100);
   
   AddSubShape("namecompartment", 100, 20);
   addsubshape("tagscompartment", 100, 10);
   addsubshape("notescompartment", 100,30);
   
   shape namecompartment
   {
      h_align = "center";
      println("<<#stereotype#>>");
      println("#name#");
   }
   
   shape tagscompartment
   {
      rectangle(0,0,100,100);
      println("MyTag_1: #TAG:MyTag_1#");
      println("MyTag_2: #TAG:MyTag_2#");
   }
   
   shape notescompartment
   {
      h_align = "center";
      println("notes");
      println("#notes#");
   }

}


The above script is "not bad" but it doesn't resize correctly as (say) the notes field is longer/short or the user resizes the element in a diagram.

Here's another attempt, using DrawNativeShape() to start with the existing shape.  Here my two tags are drawn top-left of the shape over the top of the shape's stereotype label and title text.
shape main
{
   DrawNativeShape();
   addsubshape("tagscompartment", 100, 100);
   
   shape tagscompartment
   {
      println("MyTag_1: #TAG:MyTag_1#");
      println("MyTag_2: #TAG:MyTag_2#");

   }
}



I might have to give-up with this and find a better strategy: I was attempting to have a specialised "requirement stereotype" for all requirements to do with a set of messages.  The system I'm modelling will have about 100 messages each with a Message_ID and a Message_Name.  I want one requirement for each message and that requirement to have a fields for the message ID and message name.  I could embedded the message ID and Name in the requirement title.... but I was hoping to have a more "concrete", less free-text, method.

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Display some tags but not others
« Reply #6 on: April 20, 2016, 01:59:25 am »
Don't give up, you are on the right track.

Here's a shape script I did for requirements that shows text from tagged values
Code: [Select]
shape main
{
 // Initialisation Attributes - these must be
// before drawing commands
 noshadow = "true";
 h_align = "left";
 DefSize(340,140);
 Rectangle(0,0,100,100);
 AddSubShape("nameCompartment",90,20,3,0);
 AddSubShape("translations",90,20,3,0);
 //setPen(128,0,0);
 //SetFillColor(128,0,0);
 rectangle(-10,0,-1,100);
 

 shape nameCompartment
 {
h_align = "center";
editablefield = "name";
SetFontColor(128,0,0);
println("[#name#]");
  }
 shape translations
  {
println("[NL]: #TAG:Title NL#");
println("[FR]: #TAG:Title FR#");
  }
 shape borderblock {
  rectangle(-10,0,-1,100);
 }
}

decoration process
{
orientation="ne";
if (HasTag("CustomDevelopment", "True"))
{
setfillcolor(128,0,0);
SetPenColor(128,0,0);

//top of the wrench
startpath();
Moveto( 18,35);
ArcTo(5,5,47,47,4,22,28,45);
LineTo(47,29);
ArcTo(5,5,47,47,47,29,22,4);
lineto(36,18);
lineto(18,35);
EndPath();

fillandstrokepath();
//handle
startpath();
moveto(28,46);
lineto(79,97);
ArcTo(66,66,97,97,79,97,97,79);
lineto(46,28);
EndPath();

fillandstrokepath();
//screwdriver handle
startpath();
Moveto(70,44);
LineTo(97,15);
Lineto(85,3);
Lineto(55,29);
Lineto(58,32);
Lineto(84,8);
// Lineto(86,10);
// Lineto(61,35);
// Lineto(65,39);
Lineto(90,14);
Lineto(92,16);
Lineto(67,41);
Lineto(70,44);
EndPath();
fillandstrokepath();
//screwdriver point
startpath();
MoveTo(35,59);
LineTo(21,74);
LineTo(15,75);
LineTo(4,92);
LineTo(8,96);
LineTo(25,85);
LineTo(25,79);
LineTo(40,65);
LineTo(35,59);
EndPath();

fillandstrokepath();
}
}
 
Hope this helps

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: Display some tags but not others
« Reply #7 on: April 20, 2016, 10:11:39 am »
Like the wrench and screwdriver!  ;D 

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

Geert Bellekens

  • EA Guru
  • *****
  • Posts: 13523
  • Karma: +574/-33
  • Make EA work for YOU!
    • View Profile
    • Enterprise Architect Consultant and Value Added Reseller
Re: Display some tags but not others
« Reply #8 on: April 20, 2016, 12:15:46 pm »
Like the wrench and screwdriver!  ;D 

Paolo

Thanks, had a bit of fun doing that one  ;)

Geert

ChB

  • EA User
  • **
  • Posts: 40
  • Karma: +4/-0
    • View Profile
Re: Display some tags but not others
« Reply #9 on: April 20, 2016, 06:28:29 pm »
Thanks Geert for the encouragement and your useful example.

Following further experiments my feelings are:

1) It's not possible to replicate the native shape's resize behaviour via a shape script.  For example, if the name of an element wraps over several lines, native shapes resize correctly whereas homemade shapes don't.  By incorrect I mean that the text from one compartment can overlap with another.

2) The documentation for the shape script language is lacking.  For instance I notice (from Geert's example) that AddSubShape() can take 5 parameters whereas the user guide and tooltip indicate it can take 1 or 3 parameters only.

Tip for other learners: watch out for x,y parameters being either absolute or percentage - that tripped me up at one point!

I've decided (at the moment) to keep things simple and to use the native shape with the tags I always want to see squeezed-in in the top left corner:

shape main
{
   DrawNativeShape();
   addsubshape("tagscompartment",100,20);

   shape tagscompartment
   {
      println("#TAG:MyTag_1#");
      println("#TAG:MyTag_2#");
   }
}


Or even more simply:

shape main
{
   DrawNativeShape();
   println("#TAG:MyTag_1#");
   println("#TAG:MyTag_2#");
}


That's not "big or clever" but I think it serves my need.  The first line (first tag) is shared with the <<stereotype>> label, the second line (second tag) is shared with the element's alias label (because I have "show alias" switched on).

Do people want to refute my (1) above and demonstrate otherwise?

Cheers,
ChB

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: Display some tags but not others
« Reply #10 on: April 20, 2016, 06:40:02 pm »
1) Yes. Shapescript is very limited in what it can do.

2) You have AddSubShape(shapeName,width,height) and AddSubShape(shapeName,width,height,xOffset,yOffset) which are used in examples here: http://sparxsystems.com/enterprise_architect_user_guide/12.1/building_models/sub-shapes.html (of course the parameters are not described, which is why I wrote my Shapescript book).

q.