Book a Demo

Author Topic: ShapeScript NotesVisible property  (Read 5280 times)

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
ShapeScript NotesVisible property
« on: February 28, 2020, 06:48:20 pm »
Hello everybody,


In 1310 the NotesVisible property was introduced in shape scripts:
Quote
  • NotesVisible - Available for any element, allows querying if user has requested display of notes for this object or this diagram

Can't get it to work in 1512.

HasProperty("NotesVisible") evaluates to true, so the property does exist. But how do I set it?

I've tried both the diagram's properties (Elements - Notes) and the element's compartment visibility. Either way, the NotesVisible property is stubbornly stuck at false.

What am I doing wrong?


/Uffe
My theories are always correct, just apply them to the right reality.

kevinlyons

  • EA Novice
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #1 on: April 08, 2020, 04:52:45 pm »
Hi Uffe,

It seems to be working for me.

Here is a script that shows notes or not depending on the settings for a Diagram or the Element Feature Visibility properties.

The 'NotesVisible' is true if either the Diagram > Element Properties has Notes ticked (right-click on a blank part of the diagram and select properties, then Elements)
OR
The Feature and Compartment Visibility of an Element on the Diagram has the Notes ticked. (right-click on an element on the diagram and select 'Features and Properties > Feature and Compartment Visibility').

shape main
{
   layouttype="border";
   editablefield="name";
   v_align="top";
   h_align="left";
   
   RoundRect(0,0,100,100,10,10);
   
   addsubshape("namePanel","n");
   if (HasProperty('NotesVisible'))
   {
      addsubshape("notesPanel","center");
   }
   shape namePanel
   {
      layouttype="border";
      preferredheight=20;
      addsubshape("padding","n");
      addsubshape("padding","s");
      addsubshape("padding","e");
      addsubshape("padding","w");
      addsubshape("name","center");
      shape name
      {
         v_align="top";
         h_align="center";
         printwrapped("#name#");
      }
   }
   shape notesPanel
   {
      layouttype="border";
      preferredwidth=100;
      
      if(HasProperty('NotesVisible','true'))
      {
      addsubshape("padding","n");
      addsubshape("padding","s");
      addsubshape("padding","e");
      addsubshape("padding","w");
      addsubshape("notes","center");
      }   
      shape notes
      {
         v_align="top";
         h_align="left";
         printwrapped("#notes#");
      }         
   }
   
   shape padding
   {
      preferredheight=6;
      preferredwidth=6;
   }
}

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #2 on: April 08, 2020, 05:26:03 pm »
HasProperty("NotesVisible") evaluates to true, so the property does exist. But how do I set it?

You set it in the context menu of an element Feature Visibility / the diagram Element properties. In the shape script you can only test it and have (as in the answer above) to add your own Notes compartment.

q.
« Last Edit: April 08, 2020, 05:28:22 pm by qwerty »

Uffe

  • EA Practitioner
  • ***
  • Posts: 1859
  • Karma: +133/-14
  • Flutes: 1; Clarinets: 1; Saxes: 5 and counting
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #3 on: April 08, 2020, 08:21:30 pm »
Hi guys,


Well you're both wrong, but thanks for playing. :)

But thanks to Kevin reminding me I did some more testing, and found the bug:
NotesVisible only evaluates to True if the Notes field is non-empty.

So
The 'NotesVisible' is true if
(either the Diagram > Element Properties has Notes ticked
OR
The Feature and Compartment Visibility of an Element on the Diagram has the Notes ticked)
AND
The element's Notes field is not empty.

The diagram Notes visibility and the element's Notes feature visibility are equivalent. That part works.
But the element must have a non-empty Notes field for the NotesVisible property to evaluate to True.

Side note:
Quote
   if (HasProperty('NotesVisible'))
   {
      addsubshape("notesPanel","center");
   }
This always evaluates to True. The property always exists. You have to check the value for the test to work.

The following script illustrates the problem:
Code: (Shape script) [Select]
shape main {
Rectangle(0,0,100,100);
if (HasProperty("NotesVisible")) {
PrintLn("NotesVisible property exists");
} else {
PrintLn("NotesVisible property does not exist");
}
if (HasProperty("NotesVisible", "True")) {
PrintLn("NotesVisible property is True");
} else {
PrintLn("NotesVisible property is not True");
}
}
  • Create an element stereotype with that shape script.
  • Switch the diagram's Notes display on.
  • Observe.
  • Add some text to the element's Notes field.
  • Observe.
  • Clear the text from the element's Notes field.
  • Observe.
Of course the property isn't really documented in the manual, but the release notes from its introduction, which I quoted in the OP, make it clear that the intent is to report whether either the diagram's or the element's notes visibility has been ticked. But that's not what the property actually reports.


/Uffe
My theories are always correct, just apply them to the right reality.

qwerty

  • EA Guru
  • *****
  • Posts: 13584
  • Karma: +397/-301
  • I'm no guru at all
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #4 on: April 08, 2020, 08:58:48 pm »
Quote
   if (HasProperty('NotesVisible'))
This always evaluates to True.
Yes, of course. I stumbled over it, but not hard enough ;-)

q.

kevinlyons

  • EA Novice
  • *
  • Posts: 7
  • Karma: +1/-0
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #5 on: April 09, 2020, 12:36:58 pm »
Hi Uffe,

In response to your original question,
I've tried both the diagram's properties (Elements - Notes) and the element's compartment visibility. Either way, the NotesVisible property is stubbornly stuck at false.

The assumption I made (incorrectly as it turned out) was that you had Notes, with content, that you wanted to display.
Both Qwerty and I answered that question correctly. You set it in Diagram Properties OR Element Feature Visibility.

But thank you for highlighting the redundant code for checking existence of the property, I won't do that again.

And yes the complete set of criteria for whether 'NotesVisible' equates to 'true' does indeed require content in the Notes field. Terrible name for the property, because sometimes you may want to display a compartment for Notes whether there is content or not.

The 'NotesVisible' property should only refer to the settings which would indicate a desire to show the Notes.
A separate property to test for content in the Notes, such as 'HasNotes', should be used to determine if the notes aren't blank.

Glad I could jog your memory. We are all trying to help each other after all.

kevin

Paolo F Cantoni

  • EA Guru
  • *****
  • Posts: 8626
  • Karma: +259/-129
  • Inconsistently correct systems DON'T EXIST!
    • View Profile
Re: ShapeScript NotesVisible property
« Reply #6 on: April 09, 2020, 12:59:33 pm »
[SNIP]

The 'NotesVisible' property should only refer to the settings which would indicate a desire to show the Notes.
A separate property to test for content in the Notes, such as 'HasNotes', should be used to determine if the notes aren't blank.

Glad I could jog your memory. We are all trying to help each other after all.

kevin
Kevin,

Please submit a Bug Report / Feature Request to Sparx using the links below...

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