Book a Demo

Author Topic: Printing position in connector shape script  (Read 7738 times)

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Printing position in connector shape script
« on: January 03, 2008, 06:27:52 am »
Does anyone know whether there is a way to influence the position of the print() command's output within a shape script for a connector?

It seems to me like subshapes do not work for connectors at all, and moveto() only works for the pen position and not for the print() command.

The following shape script draws a connector just like a dependency, plus a tagged value "SortIndex":

Code: [Select]

shape main
{
      noshadow=true;
      setlinestyle("dash");
      moveto(0,0);
      lineto(100,0);
}

shape source
{
      print("#TAG:SortIndex#");
}

shape target
{
      rotatable = true;
      startpath();
      moveto(0,0);
      lineto(16,6);
      endpath();
      strokepath();
      startpath();
      moveto(0,0);
      lineto(16,-6);
      endpath();
      strokepath();
}


It looks allright when the arrow is going down or from left to right, but when it's going up or from right to left the value is printed in the source element.

The print() command must not be in the main shape, because then it is duplicated every time the line is bent. So I put it in the source script, but I'd rather have it within a label or at least within a rectangle or something.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing position in connector shape script
« Reply #1 on: January 03, 2008, 07:39:49 am »
Play around with the ShowLabel() and HideLabel() methods. The documentation is woefully inadequate.
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Printing position in connector shape script
« Reply #2 on: January 04, 2008, 12:41:49 am »
Quote
Play around with the ShowLabel() and HideLabel() methods.


I don't see how these methods would help. I can add a line like hidelabel("MiddleBottom") to suppress the stereotype, but something like showlabel("MyOwn") or showlabel("#TAG:SortIndex#") does nothing at all.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing position in connector shape script
« Reply #3 on: January 04, 2008, 05:33:03 am »
Frank,

I see what you mean. This is an area that's not well explained, to say the least. It is difficult to tell whether the function is missing from EA or just the documentation.

Can you use one of the predefined label names for a subshape? This would be something along the lines of using the reserved name "label" in an element script. Perhaps you could then show the subshape, causing your text to appear in the appropriate spot.

This is just a guess, but probably worth a try.

At the very least - once you have a better grip on the product versus documentation picture - you should file a feature request. Cite this thread, and please keep us abreast of what Sparx has to say on the subject.

David
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Printing position in connector shape script
« Reply #4 on: January 07, 2008, 12:37:30 am »
David,

subshades don't seem to work at all for connectors, and using predefined label names for subshapes has no effect even in scripts for element stereotypes.

Anyway, there IS a command for positioning the print output, only I can't get it to work. Documentation being extremely poor, I decided not to use shape scripts for the time being, but I have filed a support request with

"Details":
Quote
The setorigin command, which according to documentation should "position the cursor for the next print command", does not do a thing at all.


and "Steps to Reproduction":
Quote
Define a shape script

shape main
{
   rectangle(0,0,100,100);
   setorigin("CENTER",0,0);
   print("#name#");
}

for an element stereotype. The element name will be printed in the upper left corner of the rectangle, no matter what parameters you set for setorigin.


Let's see if they come up with something.

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing position in connector shape script
« Reply #5 on: January 07, 2008, 04:30:54 am »
Please let us know what you hear Frank.
No, you can't have it!

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Printing position in connector shape script
« Reply #6 on: January 10, 2008, 12:49:42 am »
Got an answer from support:

Quote
setorigin() has never worked in the way it is described in the help file. Its use has always been to position floating text labels relative to the main shape. We will correct the help file.


For element shape scripts they suggested this solution:

Quote
Here is an example of a shape script that uses a shape script to print the object's name in the bottom left corner of the shape.


Code: [Select]

shape main
{

layouttype="border";

rectangle(0,0,100,100);

addsubshape("name","s");


text name

{


preferredheight=15;


h_align="left";


print("#NAME#");

}
}


This works fine indeed.

But it doesn't solve my original problem with printing a tagged value on a dependency stereotype, cause subshapes don't seem to work on connectors at all. So I've asked for more support.

Frank Horn

  • EA User
  • **
  • Posts: 535
  • Karma: +1/-0
    • View Profile
Re: Printing position in connector shape script
« Reply #7 on: January 15, 2008, 12:18:42 am »
Got more support and a solution for my problem. A shape script can redefine the contents of a predefined label.

I have a dependency stereotype "Source" with a tagged value "SortIndex" which I want to appear on diagrams. The solution is to not draw the whole line and arrow again, but just to substitute the contents of a label by writing a shape script that consists of nothing but

Code: [Select]

label middlebottomlabel
{
println("<#STEREOTYPE#>");
println("SortIndex=#TAG:SortIndex#");
}


That way instead of the stereotype and the link name the middle bottom label will show the stereotype and my tagged value.

Maybe one day Sparx will provide better documentation and some more examples for shape scripts, and maybe then more people will be using them...

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Printing position in connector shape script
« Reply #8 on: January 15, 2008, 06:09:16 am »
Quote
...
Maybe one day Sparx will provide better documentation and some more examples for shape scripts, and maybe then more people will be using them...

Make a feature request Frank. They are working to improve the documentation, but someone has to tell them what's hurting the most.

David
No, you can't have it!