Jump to content

Events from an array of clusters?


Recommended Posts

I have created a cluster to control the various parameters of a device we are building. Included in the cluster are three buttons, Start, Stop, and Select. The cluster controls 1 of 8 channels the device has. Since the channel controls are identical and I need to iterate through all of them regularly, naturally I thought this would be an ideal place to use an array...

Now I'm faced with the problem of figuring out how to generate and handle events from within each array element/cluster. The event handler structure doesn't appear to let me drill down into array elements. It *will* generate an event if I click somewhere within the array. Using a complex series of coordinate masks, mouse button filtering, and value change comparisons I was able to get the Select button to behave how I want, but it's going to get really messy if I try to implement Start and Stop buttons in a similar fashion.

Is there an easier way to access cluster element events that are embedded in an array? Or am I completely missing the boat by trying to use an array for this?

Thanks

Link to comment

QUOTE(Daklu @ Aug 14 2007, 01:47 PM)

Is there an easier way to access cluster element events that are embedded in an array? Or am I completely missing the boat by trying to use an array for this?

The thing about accessing properties of array elements is that the properties and methods are all treated as the same. This means you can't disable, blink, etc individual array elements because they would all be disabled,blink,etc. You've also found that it requires some work to figure out if a particular element has changed without comparing the old values with the new values. Even with your event handling for the select button, you aren't testing to see *which* select button was clicked, just to see if *any* of them were clicked inside the array.

For future expandability and to keep the code sane, I would choose a cluster versus an array for this application's front panel UI with 8 individual typedef'ed clusters inside. Now, this doesn't mean that your program can't take the cluster values that are in the UI and convert them into array elements when needed (using the cluster to array primative) to do "array" type operations internally... that's the beauty of using typedefs.

Cheers!

  • Like 1
Link to comment

QUOTE(orko @ Aug 14 2007, 02:56 PM)

For future expandability and to keep the code sane, I would choose a cluster versus an array for this application's front panel UI with 8 individual typedef'ed clusters inside. Now, this doesn't mean that your program can't take the cluster values that are in the UI and convert them into array elements when needed (using the cluster to array primative) to do "array" type operations internally... that's the beauty of using typedefs.

I agree. I was thinking about how to explain what you would have to do to accomplish what you want... It is possible, but for the front panel it is not the best construct. So only to reiterate -- you need to choose front panel components that work well for the user and for the GUI code (events, etc.). And you need to choose data constructs behind the scenes (i.e. block diagram) that work well for managing your data and processing it.

Arrays of clusters just tend to be problematic for front panels.

Link to comment

OOOOOoooooh

This is one of my favorite hacks.

Do not give up on the array just yet, although I am a member of the camp that tries to avoid arrays on FP.

SIDE NOTE: if the baby (Anna) does not start crying before the end of this post, I'll make a quick code snibbit detailing this process

That being said, you CAN get a reference to the element of an array, now keep in mind that it is a generic reference BUT and this is a big BUT

You can register that event to a value change event/and or whatever other event you are looking to trigger off of.

And here is the beauty of it all. Say you register that array element for the mouse up event, the event structure will give you a CtrlRef to the specific array element that fired the event, thus allowing you to get the value of the specific array element that triggered the event.

Now the only caveat is that you have to do some mouse/ctrl position magic to determine which # element changed in the array, but you're in luck, this code already exists somewhere on this forum, possibly in the CR.

Well the baby did start to cry...... REALLY Cry and I'm out for now, i'll try to update the post later

ok back... inside of this VI you will see 2 examples

1. Registration of the entire element of the array to a val change event

2. Registration of an element of the array to the val change event.

The way to get the static reference of the lower level elements is to simply right click the element and say make reference.

Enjoy

From your friendly neighborhood captain

Link to comment

QUOTE(NormKirchner @ Aug 14 2007, 04:53 PM)

Don't just give up, run the other way!! It's a hack!! :laugh:

QUOTE(NormKirchner @ Aug 14 2007, 04:53 PM)

Now the only caveat is that you have to do some mouse/ctrl position magic to determine which # element changed in the array, but you're in luck, this code already exists somewhere on this forum, possibly in the CR.

Arrays can indeed be useful at times, otherwise I suppose that I wouldn't have made that CR code that you referred to. So whatever works best for you.

David

Link to comment

QUOTE(dsaunders @ Aug 15 2007, 02:56 AM)

Another way to determine which array element was changed is XOR the old and new value!

Their should be just one value true, I'm not totally sure about an array of clusters since I've never done it but it should work.

Ton

Link to comment

QUOTE(tcplomp @ Aug 15 2007, 12:19 AM)

Another way to determine which array element was changed is XOR the old and new value!

Their should be just one value true, I'm not totally sure about an array of clusters since I've never done it but it should work.

Ton

Pre-coffee reply:

There are invoke nodes that translate clicks to cells.

May not be available fo rhtis object.

Now where is my coffee?

Ben

Link to comment

QUOTE(Daklu @ Aug 14 2007, 01:47 PM)

Is there an easier way to access cluster element events that are embedded in an array? Or am I completely missing the boat by trying to use an array for this?

I fear we may be digressing slightly from the original question (event detection for cluster elements inside an array). I thought the poster was interested in more than just value change detection.

But hey, that's okay we'll benefit from this discussion too. I've already (re)learned a few things :thumbup:

Link to comment

QUOTE(orko @ Aug 15 2007, 11:03 AM)

I fear we may be digressing slightly from the original question (event detection for cluster elements inside an array). I thought the poster was interested in more than just value change detection.

But hey, that's okay we'll benefit from this discussion too. I've already (re)learned a few things :thumbup:

Just re-read his original post and I think we're right on. Being able to detect events from elemnets inside of a cluster as an element of an array. No?

Link to comment

QUOTE(NormKirchner @ Aug 15 2007, 01:18 PM)

Just re-read his original post and I think we're right on. Being able to detect events from elemnets inside of a cluster as an element of an array. No?

Semantics, I guess :D

Sometimes when I read someone's post I remember the problems I had to solve, and read things into it. Maybe I did this here. For arrays of clusters my biggest "gotcha" was when I realized that you couldn't fire events on controls inside one of the clusters in the array and tell which specific control fired it, for example a mouse enter/leave event on the second element cluster's boolean... or a shortcut menu activation on the third element cluster's numeric... without some coding involving coordinate mapping, you wouldn't easily be able to tell which element's boolean/numeric control that the mouse was over when the array element event fired. With value change events you can test which one changed as you and others have pointed out.

One other caveat of having clusters inside of an array is that it makes it impossible to change the behaviour/properties of a specific control inside one of the clusters, like blinking or disabling, since all of the properties of each element follow suit and they all blink/disable.

I've personally found it much easier when dealing with multiple identical clusters to put them into another cluster versus an array, then translating the values into an array of clusters for internal data manipulation. But it does depend on what you're after, as always.

Link to comment

Although arrays are not automatic, they can be done.

THe example below illustrates a method that works on 2-d array.

http://forums.lavag.org/index.php?act=attach&type=post&id=6635

Not Equal compare agregatres inside nested For Loop structure to get array of changed.

Divide index by column count gives row and column. Index NewVal on you know what changed and what the new value is. Old value optional.

Array size change detection is left as an exercise for the reader. ;)

Ben

http://forums.lavag.org/index.php?act=attach&type=post&id=6636

Link to comment

QUOTE(Ben @ Aug 15 2007, 04:01 AM)

Pre-coffee reply:

There are invoke nodes that translate clicks to cells.

May not be available for this object.

Unfortunately they did not make this invoke function available for arrays. (Not even in 8.5) Would be a great product suggestion, though.

With 8.2, the tabular controls got additional properties for things like 'content rect'. There is nothing like this for arrays, so the code is still ugly. I just looked at my CR code again and remembered that it could be a lot cleaner by just using the 'Master Rect' property -- but that is a scripting property. :thumbdown:

Link to comment

QUOTE

Being able to detect events from elemnets inside of a cluster as an element of an array. No?

Yep, spot on. When you put it like that my request seems rather silly. :)

QUOTE

One other caveat of having clusters inside of an array is that it makes it impossible to change the behaviour/properties of a specific control inside one of the clusters, like blinking or disabling, since all of the properties of each element follow suit and they all blink/disable.

I discovered this too and it put the kabosh on the whole idea of clusters inside arrays on the front panel.

In addition to my original question I learned a fundamental concept I hadn't picked up on. Building arrays in the block diagram provides most of the benefits of an array while avoiding the front panel restrictions. Thanks orko!

Link to comment

QUOTE(Daklu @ Aug 16 2007, 01:04 PM)

Yep, spot on. When you put it like that my request seems rather silly. :)

Don't sell yourself short, I don't think it sounds silly in the least and i'm sure as you program more and more it will come up again in the future, especially since what you requested is possible. The trick is to remember these nuggest and pull them out when it makes the most sense.

Link to comment

Here is a framework for having an event for each cluster element in the array. In the Value Change for the Array of Cluster, the element is selected using the height of the array and element. Then an event is executed for the actual cluster element that changed (or in the case of the Start, Stop and Select a Mouse Up event). The Value Change for the array always executes first.

Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.