Linking Attributes Between Master Controller Widgets

T-HSCP-002-007

By default, Master Controller widgets are created with their own attributes. It is possible to link the attributes between several widgets using the data property.

In the following example, a widget that is composed of two 2D points which are linked by a line is created. There is no such widget in the Master Controller API, but there is a 2D Point widget (Point2dWidget) and a 2D Line Display widget (Line2dDisplayWidget) , the data property of the latter is an array of two 2D Points. Hence, we can simply create two Point2dWidget, then create a Line2dDisplayWidget and set its data property to an array of the data properties of both Point2dWidget. The Line2dDisplayWidget will follow the position of the two 2D Points.

// Create 2 2d point widgets. var pointWidgetA = new Point2dWidget(); var pointWidgetB = new Point2dWidget(); Controller.controls.push(pointWidgetA); Controller.controls.push(pointWidgetB); // Display a line linking the 2 2d point widgets. Controller.controls.push(new Line2dDisplayWidget( { data : [pointWidgetA.data(), pointWidgetB.data()] }));

This capability can be used to create a widget consisting of a more complex network of lines and points.

Another way to do this is by setting the data property of two widgets with an identical string. For example, if two Point2dWidget are created with an identical string in their data property, they will share the same attribute.

// Create a 2d point widget. Controller.controls.push(new Point2dWidget( { data : "Magnet", // name of the created attribute size : 0.05, // the diameter of the point selection_color : ColorRGBA(80,50,50) // the colour of the point manipulator when selected. })); // Create a 2d point widget. Controller.controls.push(new Point2dWidget( { data : "Magnet", // name of the created attribute size : 0.1, // the diameter of the point selection_color : ColorRGBA(20,70,70) // the colour of the point manipulator when selected. }));

Quiz


You must be logged in to take the Quiz

Sign Up     Sign In