diff --git a/src/Gui/SoDatumLabel.cpp b/src/Gui/SoDatumLabel.cpp index 05d005880a..a2cde08acd 100644 --- a/src/Gui/SoDatumLabel.cpp +++ b/src/Gui/SoDatumLabel.cpp @@ -1021,3 +1021,12 @@ void SoDatumLabel::GLRender(SoGLRenderAction * action) glPopAttrib(); state->pop(); } + +void SoDatumLabel::setPoints(SbVec3f p1, SbVec3f p2) +{ + pnts.setNum(2); + SbVec3f* verts = pnts.startEditing(); + verts[0] = p1; + verts[1] = p2; + pnts.finishEditing(); +} \ No newline at end of file diff --git a/src/Gui/SoDatumLabel.h b/src/Gui/SoDatumLabel.h index f4eb5685d3..183076ec0d 100644 --- a/src/Gui/SoDatumLabel.h +++ b/src/Gui/SoDatumLabel.h @@ -60,6 +60,10 @@ public: static void initClass(); SoDatumLabel(); + /*The points have to be on XY plane, ie they need to be 2D points. + To draw on other planes, you need to attach a SoTransform to the SoDatumLabel (or parent).*/ + void setPoints(SbVec3f p1, SbVec3f p2); + SoMFString string; SoSFColor textColor; SoSFEnum datumtype; diff --git a/src/Gui/TaskView/TaskImage.cpp b/src/Gui/TaskView/TaskImage.cpp index e3eb38b8ef..4ee5236c3f 100644 --- a/src/Gui/TaskView/TaskImage.cpp +++ b/src/Gui/TaskView/TaskImage.cpp @@ -540,6 +540,7 @@ void InteractiveScale::collectPoint(const SbVec3f& pos3d) if (points.empty()) { points.push_back(pos3d); + measureLabel->setPoints(getCoordsOnImagePlane(pos3d), getCoordsOnImagePlane(pos3d)); root->addChild(measureLabel); } else if (points.size() == 1) { @@ -608,12 +609,7 @@ void InteractiveScale::getMousePosition(void * ud, SoEventCallback * ecb) valueStr = quantity.getUserString(factor, unitStr); scale->measureLabel->string = SbString(valueStr.toUtf8().constData()); - //Update the SoDatumLabel. It needs 2D points! - scale->measureLabel->pnts.setNum(2); - SbVec3f* verts = scale->measureLabel->pnts.startEditing(); - verts[0] = scale->getCoordsOnImagePlane(scale->points[0]); - verts[1] = scale->getCoordsOnImagePlane(pos3d); - scale->measureLabel->pnts.finishEditing(); + scale->measureLabel->setPoints(scale->getCoordsOnImagePlane(scale->points[0]), scale->getCoordsOnImagePlane(pos3d)); } } @@ -672,6 +668,8 @@ void InteractiveScale::setPlacement(Base::Placement plc) double x, y, z, w; placement.getRotation().getValue(x, y, z, w); transform->rotation.setValue(x, y, z, w); + Base::Vector3d pos = placement.getPosition(); + transform->translation.setValue(pos.x, pos.y, pos.z); Base::Vector3d RN(0, 0, 1); RN = placement.getRotation().multVec(RN);