Point2dWidget Class Reference

The Point2dWidget JavaScript class. A 2 dimensional point widget of various shape. More...

Signals

void valueChanged (QScriptValue &point2d)
 Signal notifying the user that the 2d point value was modified by the Transform Tool. More...
 
- Signals inherited from WidgetBase
void dragStarted (QScriptValue dragContext)
 signal called on mouse down when picking this widget with the Transform tool More...
 
void drag (QScriptValue dragContext)
 signal called when this widget is dragged with the Transform tool More...
 
void dragEnded ()
 signal called on mouse up after having manipulated this widget with the Transform tool More...
 

Additional Inherited Members

- Public Slots inherited from WidgetBase
Attributedata (int index=0)
 

Detailed Description

The Point2dWidget JavaScript class. A 2 dimensional point widget of various shape.

A 2 dimensional point script widget that can be dragged inside a bounding box specified by the user. The widget manipulator is 2 concentric circles. The color of each circle can be specified at the object creation. The widget can be dragged in the Camera view while using the Transform tool. Dragging the widget will modify the value of the widget position in model Field coordinates.

If no 2d position attribute is given at the construction of this object, the object will generate one of the proper type.

The following properties are supported by the widget:

Property Type Default Value Description
data String - The name of the automatically generated 2d position attribute (if none is provided)
data Attribute - An attribute of 2d position type that can be shared with another widget or node.
size float 0.01 The size (diameter) of the point manipulator in percentage of 350 pixels.
color ColorRGBA 255, 0, 0 The colour of the point manipulator.
inner_color ColorRGBA color value The colour of the inner point manipulator (override the color property if both are found).
outer_color ColorRGBA color value The colour of the outer point manipulator (override the color property if both are found).
selection_color ColorRGBA light blue The colour of the point manipulator when selected.
xmin float -float max The left boundary of the point bounding box in fields.
xmax float float max The right boundary of the point bounding box in fields.
ymin float -float max The bottom boundary of the point bounding box in fields.
ymax float float max The top boundary of the point bounding box in fields.
show_limits bool false Draw the bounding box
box_color ColorRGBA 0, 0, 0 Bounding box color
point_style String "Circle" Point Style ("Circle","Square","Triangle", "Diamond")
label String "text" Label text
label_color ColorRGBA 255, 255, 255 Label foreground (text) color.
label_bg_color ColorRGBA 0, 0, 0, 128 Label background color. Accepts transparency values.
label_font String "Arial" Label font name.
label_size float 10.0 Label font size, in points.
label_pos Point2d Point2d(0,0) Label position, in fields.
label_justify String "Left" Horizontal label text alignment ("Left"/"Center").
label_screenspace bool true Forces the label size to remain constant relative to screen.
label_screenspace_offset Point2d Point2d(0,0) Label position offset, in screen space.

The following components constitute the widget:

Component Type
attribute POSITION_2D
drag_manipulator POSITION_2D
painter POINT_2D
picker MULTI
local_transformation -

Connect to this scriptWidget valueChanged signal to be notified when a modification has been applied to the widget. In the callback function, transfer the new widget value into an action (like modifying a peg attribute value).

{
var point2dWidget = new Point2dWidget(
{
data : "MyPoint",
// bounding box properties
xmin : -1,
xmax : 1,
ymin : -0.5,
ymax : 0.5,
// color properties
color : ColorRGBA(155,0,0),
selection_color : ColorRGBA(255,0,0)
} );
// Set the widget default value.
point2dWidget.data().setValue(getPoint2dValue()); // getPoint2dValue() returns a Point2d
// Connect the widget valueChanged signal to the point2dValueChanged slot.
point2dWidget.valueChanged.connect(point2dValueChanged);
// Register the widget to the Controller.
Controller.controls.push(point2dWidget);
}

Create a point 2d widget in the Controller onShowControl method. Extrapolate its default valuel from a peg position.

// Callback when the 2D point value has changed
function point2dValueChanged(newValue)
{
var normalizedNewXValue = ((newValue.x + 1) / 2); // The bounding box starts at -1 and is 2 fields wide
var normalizedNewYValue = ((newValue.y + 1) / 2); // The bounding box starts at -1 and is 2 fields high
// Compute the new value
var newXValue = normalizedNewXValue * 24 - 12;
var newYValue = normalizedNewYValue * 18 - 9;
// Set the new value (this will create a command, so this will be undoable)
node.setTextAttr("Top/MyPeg", "POSITION.X", frame.current(), newXValue);
node.setTextAttr("Top/MyPeg", "POSITION.Y", frame.current(), newYValue);
}

When the value of the script widget changes, update the peg position from the point position in its bounding box.

// Compute the widget position from the Peg position.
function getPoint2dValue()
{
// Compute the default position value.
var oldPoint = node.getAttr("Top/MyPeg", frame.current(), "POSITION").pos2dValue();
var normalizedNewXValue = (oldPoint.x + 12) / 24;
var normalizedNewYValue = (oldPoint.y + 9) / 18;
return new Point2d(normalizedNewXValue * 2 - 1, normalizedNewYValue * 2 - 1);
}
// Called when the current frame changes
{
// If the widget has been registered.
{
// Compute the position of the widget from its controlled Peg node position.
var defaultPoint = getPoint2dValue();
node.getAttr(Controller.node, frame.current(), "MyPoint2D").setValue(defaultPoint);
}
}

When the current frame changes, update the widget position from the position of the peg at the new current frame.

Member Function Documentation

◆ valueChanged

void Point2dWidget::valueChanged ( QScriptValue &  point2d)
signal

Signal notifying the user that the 2d point value was modified by the Transform Tool.

Parameters
point2dthe new 2d point value. point2d is of JavaScript type Point2d