TranslationZWidget Class Reference

The TranslationZWidget JavaScript class. A translatable arrow in the z axis. More...

Signals

void valueChanged (float z)
 valueChanged signal called when the z translation value has been 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 TranslationZWidget JavaScript class. A translatable arrow in the z axis.

A translation along the z axis script widget. This widget offers an arrow manipulators that can be dragged in the Camera view while using the Transform tool. Dragging the arrow will generate a translation in the z axis. If no attribute is given at the construction of this object, the object will generate a double floating point attribute.

The following properties are supported by the widget:

Property Type Default Value Description
data String - The name of the automatically generated double floating point attribute (if none is provided)
data Attribute - An attribute of double (floating point) type that can be shared with another widget or node.
radius float 0.15 The radius of the base of the arrow manipulator in field.
length float 1.0 The lenght of the stick of the arrow manipulator in field.
color ColorRGBA blue The colour of the arrow manipulator.
selection_color ColorRGBA light blue The colour of the arrow manipulator when selected.

The following components constitute the widget:

Component Type
attribute DOUBLE
drag_manipulator TRANSLATION_Z
painter ARROW_Z
picker MONO
local_transformation TRANSLATION_Z

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

{
var translationWidget = new TranslationZWidget(
{
data : "TranslationZ",
min : 0.5,
width : 1,
color : ColorRGBA(0,0,155) ,
selection_color : ColorRGBA(0,0,255)
} );
// Set the widget initial value.
translationWidget.data().setValue(3);
// Register a callback for when a transformation tool value changes.
translationWidget.valueChanged.connect(translationZChanged);
// Register a callback for when the widget is beginning to be dragged
translationWidget.dragStarted.connect(translationDragStart);
// Register the widget in the Controller
Controller.controls.push(translationWidget);
}

The previous example demonstrates how to instantiate a new widget and register it in the Controller global object.

var startPosition = new Point3d;
function getMCPosition()
{
return new Point3d(
node.getAttr(myController.node, frame.current(), "TranslationX").doubleValue(),
node.getAttr(myController.node, frame.current(), "TranslationY").doubleValue(),
node.getAttr(myController.node, frame.current(), "TranslationZ").doubleValue());
}
function translationDragStart(context)
{
// Save the position of the widget at the beginning of the drag.
startPosition = getMCPosition();
}
// Callback when the translation value has changed
function translationZChanged(newtransz)
{
// Apply an iterative translation to the peg.
var myPegPath = getPegPath();
// Get the difference between the previous translation and the current one.
var mcFieldModelPosition = getMCPosition(); // ASSERT(mcFieldModelPosition.z == newtransz);
var mcFieldModelTranslation = mcFieldModelPosition.minus(startPosition);
// Convert the translation from fields units to OGL units.
var mcModelTranslation = scene.toOGL(mcFieldModelTranslation);
// Apply the master controller parent node matrix to convert the translation
// from mc model OGL coordinates to world coordinates
var worldTranslation = getWorldVector3d(mcModelTranslation, myController.node);
// Convert the world coordinates translation into the peg model coordinates
var pegModelTranslation = getModelVector(worldTranslation, myPegPath);
// Convert the translation from OGL units back to field units
var fieldPegModelTranslation = scene.fromOGL(pegModelTranslation);
// Apply the translation to the peg position.
var positionAttributeName = "POSITION";
var isSeparate = node.getAttr(myPegPath, frame.current(), positionAttributeName + ".SEPARATE").boolValue();
var pegPosition = node.getAttr(myPegPath, frame.current(), positionAttributeName).pos3dValue().add(fieldPegModelTranslation);
if(!isSeparate)
{
positionAttributeName += ".3DPATH";
}
node.setTextAttr(myPegPath, positionAttributeName + ".X", frame.current(), pegPosition.x);
node.setTextAttr(myPegPath, positionAttributeName + ".Y", frame.current(), pegPosition.y);
node.setTextAttr(myPegPath, positionAttributeName + ".Z", frame.current(), pegPosition.z);
startPosition = mcFieldModelPosition;
}

This example shows how to apply the difference in translation of a translation widget on an arbitrary peg in the scene.

Member Function Documentation

◆ valueChanged

void TranslationZWidget::valueChanged ( float  z)
signal

valueChanged signal called when the z translation value has been modified by the Transform tool.

Parameters
zthe new z translation value