Jump to content

Create Element Wrappers Retooler


jgcode

Recommended Posts

A while back AQ issued a request to finish some code located in <resource>\Framework\Providers\LVClassLibrary\NewAccessors

The with great power come great responsibility line always stuck in my head and it was on my to-do list however, it took me a while to look at it (plus my scripting skills have improved slightly since then :)).

Basically the code operates on a Class which has other Classes as Data Members (composition) and allows the end user to create an API that wraps the required Data Member methods (delegation):

Remember, with great power comes great responsibility. What do I mean by this? I mean that I'd like someone to finish writing the ElementWrapperRetooler.lvclass for me. :-) It's one of the classes that is now unlocked. That class is the start of a solution to "I have a class X that has another class Y as a private data member. I want to create a new method on X that has the same conpane as a method on Y but with all terminals of type Y replaced with terminals of type X. On the block diagram, I want to unbundle the Y, call Y's method, and if there's an output, put the Y back into my X cluster." This has been requested by many people over the four years since LV was released to accelerate development of the Delegate pattern and similar patterns, but I've never finished writing it.

post-10325-0-50706400-1331994166.png

I have now finished off the existing code and bolted on a UI and included it with LVOOP Assistant.

I made this a separate thread for a few reasons (not discussed here).

Feedback on this feature would be really appreciated.

I thought I'd put it out for testing and to get feedback.

The aim of this tool is to speed up development.

This wasn't my first choice in how to design the GUI etc... integrating it into the current LVOOP GUI's that ship with LabVIEW would be grand, but these are locked.

So this way was by far the easiest for me.

My next mission is to see if I can get this natively included with LabVIEW :P

Instructions:

Class A contains other Classes as Data Members

Nesting of Data Members (stored in clusters) is also supported

post-10325-0-31519900-1331994159.png

Public methods are may be selected

In this case Class B is Friends with A - which means A can have B's community-scoped on their block diagram

Private and Protected scoped methods are not supported as

  • Private would break
  • Protected is not logical as LabVIEW does not allow a Child as a Data Member of a Parent

post-10325-0-71348200-1331994212_thumb.p

The script is accessed through the Project Provider by right-clicking on a Class (that contains data members) and selecting LVOOP Assistant >> Create Element Wrappers

post-10325-0-22671300-1331994165.png

The GUI will appear and allow the end user to select the Data Member that will be worked on as well the methods that will be wrapped

Public methods and green, Community methods are blue

Click a method to check/uncheck it, or use the buttons to batch check/uncheck etc...

post-10325-0-07639200-1331994163_thumb.p

In the example Data Member 2 is chosen - which is an instance of Class B, which has the following methods

post-10325-0-80646500-1331994161.png

Clicking OK creates the following methods for Class A

post-10325-0-59007700-1331994160.png

What is happening from a scripting perspective is that Class B's method is copied

post-10325-0-66431800-1331994156_thumb.p

Converted to a Class A method

post-10325-0-53406800-1331994154_thumb.p

Class A's BD is cleared, then the method is delegated to Class B.

post-10325-0-50706400-1331994166.png

Here is a demonstration (no sound)

<!-- copy and paste. Modify height and width if desired. --> <object id="scPlayer" width="957" height="652" type="application/x-shockwave-flash" data="http://content.screencast.com/users/jgcode/folders/LVOOP%20Assistant/media/d749a41d-0411-46de-a9ac-2df37c6dc6f9/jingswfplayer.swf" > <param name="movie" value="http://content.screencast.com/users/jgcode/folders/LVOOP%20Assistant/media/d749a41d-0411-46de-a9ac-2df37c6dc6f9/jingswfplayer.swf" /> <param name="quality" value="high" /> <param name="bgcolor" value="#FFFFFF" /> <param name="flashVars" value="thumb=http://content.screencast.com/users/jgcode/folders/LVOOP%20Assistant/media/d749a41d-0411-46de-a9ac-2df37c6dc6f9/FirstFrame.jpg&containerwidth=957&containerheight=652&content=http://content.screencast.com/users/jgcode/folders/LVOOP%20Assistant/media/d749a41d-0411-46de-a9ac-2df37c6dc6f9/LVOOP%20Assistant%20-%20CEW.swf&blurover=false" /> <param name="allowFullScreen" value="true" /> <param name="scale" value="showall" /> <param name="allowScriptAccess" value="always" /> <param name="base" value="http://content.screencast.com/users/jgcode/folders/LVOOP%20Assistant/media/d749a41d-0411-46de-a9ac-2df37c6dc6f9/" /> Unable to display content. Adobe Flash is required.</object>

Enjoy!

-JG

Example Code in LabVIEW 2011

cew example_LV2011.zip

  • Like 2
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.