Author Topic: Shape script - conditionally apply?  (Read 6437 times)

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Shape script - conditionally apply?
« on: May 22, 2006, 08:58:21 pm »
Is it possible to have shape script conditionally apply - depending on the package / view / model containing a diagram on which it appears?

My problem is.... one set of architects would like an application (a package with an "application" stereotype) to appear one way, the other group want just a plain UML rendering (ie. a standard package).

Problem is - it is the one "element" in the model and I need to be able to render it 2 ways.

Any help really appreciated.

Cheers,
David.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

mark.myers

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #1 on: January 03, 2007, 03:25:51 am »
Dave,

did you get anywhere with this?  I want to do exactly the same thing - seems like it would be a very useful feature!

Regards,
Mark.
Cheers, Mark

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: Shape script - conditionally apply?
« Reply #2 on: January 03, 2007, 01:23:29 pm »
There is a function you can use in shape scripts to revert to default rendering: DrawNativeShape(). You can use it like this:

shape main
{
 if (HasTag("UseShapeScript","true"))
 {
   // put shape script commands here...
 }
 else
 {
   DrawNativeShape();
 }
}

You would need to define the boolean tagged value "UseShapeScript".
« Last Edit: January 03, 2007, 02:50:47 pm by AshK »
The Sparx Team
[email protected]

mark.myers

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #3 on: January 03, 2007, 02:52:48 pm »
Quote
There is a function you can use in shape scripts to revert to default rendering: DrawNativeShape(). You can use it like this:

shape main
{
  if (HasTag("UseShapeScript","true"))
  {
    // put shape script commands here...
  }
  else
    DrawNativeShape();
}

You would need to define the boolean tagged value "UseShapeScript".


Yes I know about that but this is not what I am after.  I want to conditionally change the shape based on the diagram the shape is in NOT on any property of the element itself (because a property of the element will be the same in every diagram it is in).
Cheers, Mark

AshK

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #4 on: January 03, 2007, 03:39:00 pm »
Sorry, currently there are no means to access diagram properties from a shape script.

Would really be nice if diagrams had tagged values for this purpose.

To achieve a per diagram symbol rendering, we could expose "diagram.name" and "diagram.stereotype"?

Thoughts?

Ash :)



The Sparx Team
[email protected]

AshK

  • EA User
  • **
  • Posts: 137
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #5 on: January 03, 2007, 03:51:56 pm »
Oh, and diagram.type (thanks kp)
The Sparx Team
[email protected]

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Shape script - conditionally apply?
« Reply #6 on: January 04, 2007, 06:06:52 am »
Ash,

Sounds like a very powerful idea, and it wouldn't bend the scripts all out of shape [sorry, I just had to].  :D

I've got a few half-baked ideas for consideration, but will wait until I can state them clearly before sending them in via the usual channels.

David
No, you can't have it!

mark.myers

  • EA User
  • **
  • Posts: 97
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #7 on: January 04, 2007, 02:26:04 pm »
Quote
Sorry, currently there are no means to access diagram properties from a shape script.

Would really be nice if diagrams had tagged values for this purpose.

To achieve a per diagram symbol rendering, we could expose "diagram.name" and "diagram.stereotype"?

Thoughts?

Ash :)


Thanks, Ash.  That sounds good.
For my immeadiate requirement I have re-thought my approach and no longer need to do this - for the time being. I still think it would be a very useful feature.

Mark.
Cheers, Mark

«Midnight»

  • EA Guru
  • *****
  • Posts: 5651
  • Karma: +0/-0
  • That nice Mister Grey
    • View Profile
Re: Shape script - conditionally apply?
« Reply #8 on: February 15, 2007, 09:59:46 am »
Does anyone (speak up Sparxians!) know whether this has yet been done? Perhaps for 804 (he says, hopefully).
No, you can't have it!

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #9 on: February 15, 2007, 12:15:28 pm »
In terms of diagram properties... testing within a shape script is getting too fancy and doesn't actually achieve my requirement.

I'd just like a static "use shape script" property on every diagram that EA internally would use to determine whether to apply shape scripts or not.

It doesn't have to be script based.

The reason to do this - is you don't have to use a tagged value (which would require some extension to EA I believe) and you don't have to obscure the setting via a composite of stereotype, name, type etc... ie. a simple property makes it easier for a user making diagrams.

Besides - being able to test stereotype, name, type for a diagram within the shapescript doesn't actually help.  I just want to be able to say "yes" or "no" to render shapesscripts on a per diagram basis - regardless of its type, stereotype, name etc.. (there's no logic here!)

Sparx - also don't forget... whatever you apply, make sure it works for the HTML and RTF rendering too.

Cheers,
David.
« Last Edit: February 15, 2007, 12:16:38 pm by Dave_Bullet »
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #10 on: July 24, 2007, 05:14:53 pm »
Hi there,

Any new features in 7.0 to allow me to test what diagram the shapescript is being executed on then conditionally apply (or drawnativeshape())

I retract my last post.  Actually being able to test diagram properties in shapescript is the way to go (as it would be the most flexible for more EA users).

AshK / KP - any more thoughts re features for 7.0?  I am happy to submit a formal request if nothing has been included in the current release.

Thanks,
DAvid.
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #11 on: July 24, 2007, 05:17:50 pm »
PS: The main reason I am asking for this is so ex-Visio users and UML purists can use the same EA model.

Visio people - like symbols on their deployment diagrams
UML architects - want to render nodes and the like as plain UML boxes.

I need the same node (which I have stereotyped "server") to be plain rendered or use an image depending on the diagram it is used on.

In my case, I could use diagram properties in shapescript - but would test the diagram type (ie. deployment = render image, otherwise = drawnativeshape())

Cheers,
DAvid.,
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #12 on: July 24, 2007, 05:42:42 pm »
Solved.  EA7.0 supports this (may have been supported earlier?) via the "diagram.type" property.

THANKYOU SPARX!    ;D ;D ;D ;D

Here's some sample script to demonstrate:

shape main
{
layouttype="border";
noshadow="true";
if(hasproperty("diagram.type", "Deployment"))
{
println("i am in a deployment diagram");
}
else
{
println("i am in something else");
}
}

"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"

KP

  • EA Administrator
  • EA Expert
  • *****
  • Posts: 2919
  • Karma: +54/-3
    • View Profile
Re: Shape script - conditionally apply?
« Reply #13 on: July 24, 2007, 06:22:13 pm »
Quote
Solved.  EA7.0 supports this (may have been supported earlier?) via the "diagram.type" property.

"diagram.name" and "diagram.stereotype" have also been exposed. The full list of properties are in
the SDK on the page "Shape Scripts > Writing Scripts > Displaying Element Properties".
The Sparx Team
[email protected]

Dave_Bullet

  • EA User
  • **
  • Posts: 295
  • Karma: +0/-0
    • View Profile
Re: Shape script - conditionally apply?
« Reply #14 on: July 24, 2007, 06:56:45 pm »
Thanks KP - that's how I found it.  Downloaded the SDK file.  Thanks guys for putting that together.  Will come in quite handy and will save me from asking you all the annoying RTFM questions  ;D

Cheers,
David.
« Last Edit: July 24, 2007, 06:57:16 pm by Dave_Bullet »
"I know I'm close to a good design, but it's like the balloon animals, squeeze in one spot and the problem moves down the line"