Actor Framework Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

Display actor instance in subpanel

Hello there,

I have 6 sub-actors, all instances of the same type.  I'd like the user to be able to conditionally display their front panels in a subpanel of a top-level actor.

I'm wondering how best to reveal the VI reference of the sub-actor back to the parent.  I can see that the sub-actor could send a message back to the parent saying 'here is my vi ref' but that then runs the risk of the parent doing something nefarious with the vi ref. 

Any best-practice tips please?

Thank you,

Martin

0 Kudos
Message 1 of 12
(12,360 Views)

I have done quite a bit of work with actors in subpanels. Here's how I do it:

  • My parent launches each sub-actor. Before launch, it writes its own subpanel ref onto the class wire of the sub-actor.
  • When the sub-actor launches it can insert itself into the subpanel of the parent.
  • If the parent needs to change sub-actors it just messages the first sub-actor to stop and then launches the second one.
  • Whenever any new sub-actor inserts itself, it preemptively removes any existing sub-actor first...

This works pretty well in practice, and the parent doesn't need any VI refs of the sub-actors.

Message 2 of 12
(6,416 Views)

Ahh yes, that works perfectly and feels much better - thank you very much.

0 Kudos
Message 3 of 12
(6,416 Views)

You can also send the subpanel ref in a message to an (already running) subactor, rather than preload it before launch.

Message 4 of 12
(6,416 Views)

Thank you for the tip.  I have the app up and running now, it works really nicely.

0 Kudos
Message 5 of 12
(6,416 Views)

You might also want to look at this thread:

https://decibel.ni.com/content/message/43265

0 Kudos
Message 6 of 12
(6,416 Views)

fabric wrote:

I have done quite a bit of work with actors in subpanels. Here's how I do it:

  • My parent launches each sub-actor. Before launch, it writes its own subpanel ref onto the class wire of the sub-actor.
  • When the sub-actor launches it can insert itself into the subpanel of the parent.
  • If the parent needs to change sub-actors it just messages the first sub-actor to stop and then launches the second one.
  • Whenever any new sub-actor inserts itself, it preemptively removes any existing sub-actor first...

This works pretty well in practice, and the parent doesn't need any VI refs of the sub-actors.

Would you mind elaborating on "it writes it own subpanel ref"? Do you mean that your top level GUI actor (your parent) somehow obtains a reference to it's own subpanel and passed that to the sub GUI actors (launched by the parent)? If that is what you mean, would you mind explaining how you do this?

EDIT: I have made an working example with your approach. The reference to the subpanel can be obtained by rightclicking on the subpanel on the front panel and choose "Creat" -> "Reference". Might I now ask how you close your actors when another actor is inserted into the subpanel?

Do all your sub-gui-actors have an reference to the other sub-gui-actors so they can send stop messages to them? Or do you in your main gui keep an reference to the current actor being displayed so you can close it?

0 Kudos
Message 7 of 12
(6,416 Views)

Hi Jonas,

Attached is a quick mockup of a subpanel app using AF... Hopefully it gives you the missing pieces of the puzzle!

The key trick is that the sub-actors "insert themselves" into the container in the parent. To enable this we write the subpanel ref onto the class wire of each sub-actor before it is launched. There are other ways to do this but I have found this technique to be the simplest to manage.

Each sub-actor inherits from an abstract subpanel parent which contains the code for handling insertion into the container. Again, this makes it easier when switching between multiple subpanel VIs since all the common code is in the one place.

Message 8 of 12
(6,416 Views)

For another example of subpanels and actors check out the Windows 8 Style UI demo - https://decibel.ni.com/content/docs/DOC-26625

It uses subpanels heavily. To make development easier any actor that has a UI inherits from "ViewableActor"

Screen Shot 2013-05-28 at 10.05.22 AM.png

Each of the public methods (denoted by a + above) are callable via a message. The "UI VI Ref" is a reference to the VI which implements the UI of the actor (most commonly an overridden Actor Core), "SubPanel Ref" is null to begin with and then stores the reference to the containing subpanel if the VI is loaded in a subpanel. Checking to see if "SubPanel Ref" is a valid refnum allows the ViewableActor to check if it is currently in a subpanel.

0 Kudos
Message 9 of 12
(6,416 Views)

Hello,

I am trying to use the subpanels example in a slightly different way. I am trying to insert multiple VIs (of the same type) in the subpanel as actors. I am new to AF, and can't quite wrap my head around the proper way to make this work using Actors/Messages.

I would like to use actors and send each actor messages, as well as receive data from them. I can add many VI inside the single subpanel, however I am not using AF correctly as actors. I am simply using several methods I have added to the subpanels class.

If anyone can point me in the right direction to do this I would be very appreciative.

I have attached the modified subpanels code to this post as an example of the functionality I would like. I have created an "Add" button to demonstrate the functionality I am looking for, but I would like to make each subVI an actor, and use messages to communicate with them.

Any guidance is appreciated!

0 Kudos
Message 10 of 12
(6,416 Views)