Property NodesWith property nodes, you can start making your program more powerful and a lot more fun. Property nodes allow you to programmatically control the properties of a front panel object: things such as color, visibility, position, numeric display format, and so on. The key word here is programmaticallythat is, changing the properties of a front panel object according to an algorithm in your diagram. For example, you could change the color of a dial to go through blue, green, and red as its numerical value increases. Or you could selectively present the user with different controls, each set of them appearing or disappearing according to what buttons were pressed. You could even animate your screen by having a custom control move around to symbolize some physical process. To create a property node, pop up on either the front panel object or its terminal and select a property from the Create>>Property Node submenu. A terminal with the same name as the variable will appear on the diagram. To see what options you can set in a control's property node, click on the node with the Operating tool or pop up on the node and choose Property (see Figure 13.28). Now you have the choice of which property or properties you wish to select. Each object has a set of base properties (common to all types of controls), and usually, an additional set of properties specific to that type of control. Figure 13.28. Some of the many properties available for controls and indicators
Just as with local variables, you can either read or write the property of an object (although a few properties are read-only). To change the mode of a property, pop up on it and select the Change to Write/Read option. The small arrow inside the property node's terminal tells you which mode it's in. A property node in write mode has the arrow on the left, indicating the data is flowing into the node, writing a new property. A property node in read mode has the arrow on the right, reading the current property and providing this data. The same analogy we used for locals, a control (read mode) and an indicator (write mode), holds for property nodes. An interesting feature of property nodes is that you can use one terminal on the block diagrams for several properties (but always affecting the same control or indicator). To add an additional property, you can use the Positioning tool to resize the terminal and get the number of properties you need, much in the same way multiple inputs are added to functions like Bundle, Build Array, etc. Figure 13.29 shows two properties on the same terminal for the numeric control gain. Figure 13.29. Property Node with Visible property in read mode and Numeric Text Colors in write mode
Note that the Visible property is in read mode and the NumText.Colors property is in write mode. You can configure each property from its pop-up menu by choosing Change To Write or Change To Read. You can change all properties on the node by choosing Change All To Write or Change All To Read. Let's look at a simple example VI, PropertyNode Example.vi, which may be found on the CD-ROM in the EVERYONE\CH13 folder (see Figures 13.29 and 13.30). Suppose you wanted to have a front panel that would hide certain specialized controls except for those occasions when they were needed. In the following front panel, we see a tension gauge and a Boolean alarm switch (see Figure 13.29). We include a button that says show/hide advanced controls..., hinting at the possibility that if you pressed it, some really obscure and intricate options will pop up (see Figure 13.30). Figure 13.30. PropertyNode Example.vi front panel with advanced controls hidden
In this example, we've included two more controls, gain and offset, which are made invisible by setting their property nodes' option "Visible" to false unless the button is pressed. If the show/hide advanced controls . . . button is pressed, then ta-da! . . . the two knobs become visible (see Figure 13.31). Figure 13.31. PropertyNode Example.vi front panel with advanced controls visible
The entire block diagram would be encompassed in a While Loop like the one shown next to make the button control the visibility of the two knobs and thus give the "pop-up" effect (see Figure 13.32). Figure 13.32. PropertyNode Example.vi block diagram
You will learn about the tab control in the section, "Cool GUI Stuff: Look What I Can Do!." Once you are familiar with it, come back to this example and see if you can save some front panel real estate by putting the "advanced" controls (gain and offset) into different pages of a tab control. Often you will want to use more than one option in an object's property node. Remember, instead of creating another property node, you can select several options at a time by enlarging the terminal with the Positioning tool (much like you enlarge cluster and array terminals). You will see each new option appear in sequence; you can later change these if you like by clicking on any item with the Operating tool. What do some of the base options in a property node refer to?
The Help window really is helpful when using property nodes. If you move the cursor onto the terminal of a property node, the Help window will show you what the property means, and what kind of data it expects. Also, you can pop up on a property node and select Help to open the LabVIEW help file topic for the property that you popped up on, as shown in Figure 13.33. Figure 13.33. Showing the LabVIEW help for a specific property from its pop-up menuIf you are unsure about the data type to wire to a property (in write mode), you can pop up on the property node terminal and choose Create Constant to create a constant of the correct data typethis is an especially handy time-saver when the input is a cluster. Almost all controls or indicators have the base properties. Most of them have many more, especially tables and graphs (which can have over 100 properties!). We won't even begin to go into most of these properties, partly because you may never care about many of them and you can always look up the details in the manuals. The best way to learn about property nodes is to create some to go with your application and begin to play around with them. You'll find that property nodes are very handy for making your program more dynamic, flexible, and user-friendly (always good for impressing your non-technical manager). Another ExampleGraphs and charts have zillions of options in their property nodes, as you can see by popping up on the terminal of a chart's property node (see Figure 13.34). Figure 13.34. The zillions of properties of charts and graphs
This next example, which can be found in the property node examples in the full version of LabVIEW, shows just one of the many aspects of a graph you can control programmatically (see Figure 13.35). Chart Property Node.vi lets you select one of three display types for the chart: Strip, Scope, and Sweep (if you need to, review Chapter 8, "LabVIEW's Exciting Visual Displays: Charts and Graphs," to see what they do). Figure 13.35. Chart Property Node.vi front panel
You can select the chart mode and watch it change even while the VI is running. The way this is done is through the Update Mode option on a chart's property node (see Figure 13.36). Figure 13.36. Chart Property Node.vi block diagram
Activity 13-4: Using Property Nodes with ChartsWrite a VI that graphs three channels of data (either real-time data through a DAQ board, or random data). Let the user turn on or off any of the plots with three buttons. Because this is a chart and not a graph, the data will accumulate along with the old data, even if the VI is closed and re-opened. Add a "CLEAR" button that clears the chart (see Figure 13.37). Figure 13.37. Front panel of the VI you will create during this activity
When using a multiplot graph or chart, you can only affect the properties of one plot at a time. The plots are numbered 0, 1, . . ., n for property node purposes. A specific property, called Active Plot, is used to select the plot for the properties you are modifying or reading. In this exercise, you will need to build some case statements like the ones shown in Figures 13.38 and 13.39. Figure 13.38. Part of the block diagram you will create, which shows plot 0
Figure 13.39. Part of the block diagram you will create, which hides plot 0
The Boolean text of the checkbox (or any Boolean, for that matter) is clickable, meaning that when you click on the text, it is the same as clicking on the Booleanit will change states. When you place a checkbox (found on the System palette), it will appear with both its label and Boolean text visible. Hide the label (right-click the checkbox and unselect Label from the Visible Items submenu) and change the Boolean text to anything you wishin our case "Channel 1 Visible" (etc). Test whether clicking the Boolean text causes the checkbox to change values. To clear a chart, use the History Data property of the chart. Then wire an empty array to this property node. Save your VI as Property Nodes-Graph.vi. |