| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2017 Werner Mayer <wmayer[at]users.sourceforge.net> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This library is free software; you can redistribute it and/or * |
| 7 |
* modify it under the terms of the GNU Library General Public * |
| 8 |
* License as published by the Free Software Foundation; either * |
| 9 |
* version 2 of the License, or (at your option) any later version. * |
| 10 |
* * |
| 11 |
* This library is distributed in the hope that it will be useful, * |
| 12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 14 |
* GNU Library General Public License for more details. * |
| 15 |
* * |
| 16 |
* You should have received a copy of the GNU Library General Public * |
| 17 |
* License along with this library; see the file COPYING.LIB. If not, * |
| 18 |
* write to the Free Software Foundation, Inc., 59 Temple Place, * |
| 19 |
* Suite 330, Boston, MA 02111-1307, USA * |
| 20 |
* * |
| 21 |
***************************************************************************/ |
| 22 |
|
| 23 |
#include <memory> |
| 24 |
#include <ranges> |
| 25 |
#include <string> |
| 26 |
#include <QAction> |
| 27 |
#include <QMenu> |
| 28 |
#include <Inventor/draggers/SoDragger.h> |
| 29 |
#include <Inventor/nodes/SoPickStyle.h> |
| 30 |
#include <Inventor/nodes/SoTransform.h> |
| 31 |
|
| 32 |
#include <App/GeoFeature.h> |
| 33 |
#include <App/DocumentObjectGroup.h> |
| 34 |
#include <Base/Tools.h> |
| 35 |
#include <Base/Placement.h> |
| 36 |
#include <Base/Vector3D.h> |
| 37 |
#include <Base/Converter.h> |
| 38 |
|
| 39 |
#include "Application.h" |
| 40 |
#include "BitmapFactory.h" |
| 41 |
#include "Control.h" |
| 42 |
#include "Document.h" |
| 43 |
#include "Inventor/Draggers/SoTransformDragger.h" |
| 44 |
#include "Inventor/Draggers/Gizmo.h" |
| 45 |
#include "Inventor/SoFCPlacementIndicatorKit.h" |
| 46 |
#include "Inventor/So3DAnnotation.h" |
| 47 |
#include "SoFCUnifiedSelection.h" |
| 48 |
#include "TaskTransform.h" |
| 49 |
#include "View3DInventorViewer.h" |
| 50 |
#include "ViewProviderDragger.h" |
| 51 |
#include "Utilities.h" |
| 52 |
#include "ViewParams.h" |
| 53 |
#include "ViewProviderLink.h" |
| 54 |
|
| 55 |
|
| 56 |
using namespace Gui; |
| 57 |
|
| 58 |
PROPERTY_SOURCE(Gui::ViewProviderDragger, Gui::ViewProviderDocumentObject) |
| 59 |
|
| 60 |
ViewProviderDragger::ViewProviderDragger() |
| 61 |
{ |
| 62 |
ADD_PROPERTY_TYPE(TransformOrigin, ({}), nullptr, App::Prop_Hidden, nullptr); |
| 63 |
|
| 64 |
pcPlacement = new SoSwitch; |
| 65 |
pcPlacement->whichChild = SO_SWITCH_NONE; |
| 66 |
}; |
| 67 |
|
| 68 |
ViewProviderDragger::~ViewProviderDragger() = default; |
| 69 |
|
| 70 |
void ViewProviderDragger::updateData(const App::Property* prop) |
| 71 |
{ |
| 72 |
if (prop->isDerivedFrom<App::PropertyPlacement>() && strcmp(prop->getName(), "Placement") == 0) { |
| 73 |
// Note: If R is the rotation, c the rotation center and t the translation |
| 74 |
// vector then Inventor applies the following transformation: R*(x-c)+c+t |
| 75 |
// In FreeCAD a placement only has a rotation and a translation part but |
| 76 |
// no rotation center. This means that the following equation must be ful- |
| 77 |
// filled: R * (x-c) + c + t = R * x + t |
| 78 |
// <==> R * x + t - R * c + c = R * x + t |
| 79 |
// <==> (I-R) * c = 0 ==> c = 0 |
| 80 |
// This means that the center point must be the origin! |
| 81 |
Base::Placement p = static_cast<const App::PropertyPlacement*>(prop)->getValue(); |
| 82 |
updateTransform(p, pcTransform); |
| 83 |
} |
| 84 |
|
| 85 |
ViewProviderDocumentObject::updateData(prop); |
| 86 |
} |
| 87 |
|
| 88 |
void ViewProviderDragger::setTransformOrigin(const Base::Placement& placement) |
| 89 |
{ |
| 90 |
TransformOrigin.setValue(placement); |
| 91 |
} |
| 92 |
|
| 93 |
void ViewProviderDragger::resetTransformOrigin() |
| 94 |
{ |
| 95 |
setTransformOrigin({}); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
void ViewProviderDragger::setGizmoContainer(Gui::GizmoContainer* gizmoContainer) |
| 100 |
{ |
| 101 |
this->gizmoContainer = gizmoContainer; |
| 102 |
} |
| 103 |
|
| 104 |
void ViewProviderDragger::onChanged(const App::Property* property) |
| 105 |
{ |
| 106 |
if (property == &TransformOrigin) { |
| 107 |
updateDraggerPosition(); |
| 108 |
} |
| 109 |
|
| 110 |
ViewProviderDocumentObject::onChanged(property); |
| 111 |
} |
| 112 |
|
| 113 |
TaskView::TaskDialog* ViewProviderDragger::getTransformDialog() |
| 114 |
{ |
| 115 |
return new TaskTransformDialog(this, transformDragger); |
| 116 |
} |
| 117 |
|
| 118 |
bool ViewProviderDragger::doubleClicked() |
| 119 |
{ |
| 120 |
Gui::Application::Instance->activeDocument()->setEdit(this, (int)ViewProvider::Default); |
| 121 |
return true; |
| 122 |
} |
| 123 |
|
| 124 |
void ViewProviderDragger::setupContextMenu(QMenu* menu, QObject* receiver, const char* member) |
| 125 |
{ |
| 126 |
QIcon iconObject = mergeGreyableOverlayIcons(Gui::BitmapFactory().pixmap("Std_TransformManip.svg")); |
| 127 |
QAction* act = menu->addAction(iconObject, QObject::tr("Transform"), receiver, member); |
| 128 |
act->setData(QVariant((int)ViewProvider::Transform)); |
| 129 |
ViewProviderDocumentObject::setupContextMenu(menu, receiver, member); |
| 130 |
} |
| 131 |
|
| 132 |
ViewProvider* ViewProviderDragger::startEditing(int mode) |
| 133 |
{ |
| 134 |
forwardedViewProvider = nullptr; |
| 135 |
|
| 136 |
auto ret = ViewProviderDocumentObject::startEditing(mode); |
| 137 |
if (!ret) { |
| 138 |
return ret; |
| 139 |
} |
| 140 |
|
| 141 |
return forwardedViewProvider ? forwardedViewProvider : ret; |
| 142 |
} |
| 143 |
|
| 144 |
bool ViewProviderDragger::forwardToLink() |
| 145 |
{ |
| 146 |
// typically we want to transform the selected object, but if the selected object is in the |
| 147 |
// link, we want to transform the link instead. |
| 148 |
// |
| 149 |
// To achieve that, we use the sub object path and look for the first link in the chain, and |
| 150 |
// we forward the request there. |
| 151 |
const auto findFirstLinkViewProvider = [this]() -> ViewProvider* { |
| 152 |
ViewProviderDocumentObject* vpParent = nullptr; |
| 153 |
std::string subname; |
| 154 |
|
| 155 |
auto doc = Application::Instance->editDocument(); |
| 156 |
if (!doc) { |
| 157 |
return nullptr; |
| 158 |
} |
| 159 |
|
| 160 |
doc->getInEdit(&vpParent, &subname); |
| 161 |
if (!vpParent) { |
| 162 |
return nullptr; |
| 163 |
} |
| 164 |
|
| 165 |
for (const auto subObjects = vpParent->getObject()->getSubObjectList(subname.c_str()); |
| 166 |
const auto subObject : std::views::reverse(subObjects)) { |
| 167 |
|
| 168 |
// we don't want to try to edit objects in other documents |
| 169 |
if (subObject->getDocument() != getObject()->getDocument()) { |
| 170 |
return nullptr; |
| 171 |
} |
| 172 |
|
| 173 |
if (auto subObjectViewProvider = Application::Instance->getViewProvider(subObject); |
| 174 |
subObjectViewProvider && subObjectViewProvider->isDerivedFrom<ViewProviderLink>()) { |
| 175 |
return subObjectViewProvider; |
| 176 |
} |
| 177 |
} |
| 178 |
|
| 179 |
return nullptr; |
| 180 |
}; |
| 181 |
|
| 182 |
if (ViewProvider* subObjectViewProvider = findFirstLinkViewProvider(); |
| 183 |
subObjectViewProvider && subObjectViewProvider != this) { |
| 184 |
forwardedViewProvider = subObjectViewProvider->startEditing(Transform); |
| 185 |
} |
| 186 |
|
| 187 |
return forwardedViewProvider != nullptr; |
| 188 |
} |
| 189 |
|
| 190 |
bool ViewProviderDragger::setEdit(int ModNum) |
| 191 |
{ |
| 192 |
Q_UNUSED(ModNum); |
| 193 |
|
| 194 |
if (forwardToLink()) { |
| 195 |
return true; |
| 196 |
} |
| 197 |
|
| 198 |
assert(!transformDragger); |
| 199 |
|
| 200 |
transformDragger = new SoTransformDragger(); |
| 201 |
transformDragger->setAxisColors( |
| 202 |
Gui::ViewParams::instance()->getAxisXColor(), |
| 203 |
Gui::ViewParams::instance()->getAxisYColor(), |
| 204 |
Gui::ViewParams::instance()->getAxisZColor() |
| 205 |
); |
| 206 |
transformDragger->draggerSize.setValue(ViewParams::instance()->getDraggerScale()); |
| 207 |
|
| 208 |
transformDragger->addStartCallback(dragStartCallback, this); |
| 209 |
transformDragger->addFinishCallback(dragFinishCallback, this); |
| 210 |
transformDragger->addMotionCallback(dragMotionCallback, this); |
| 211 |
|
| 212 |
Gui::Control().showDialog(getTransformDialog()); |
| 213 |
|
| 214 |
updateDraggerPosition(); |
| 215 |
|
| 216 |
return true; |
| 217 |
} |
| 218 |
|
| 219 |
void ViewProviderDragger::unsetEdit(int ModNum) |
| 220 |
{ |
| 221 |
Q_UNUSED(ModNum); |
| 222 |
|
| 223 |
transformDragger.reset(); |
| 224 |
|
| 225 |
Gui::Control().closeDialog(); |
| 226 |
} |
| 227 |
|
| 228 |
void ViewProviderDragger::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum) |
| 229 |
{ |
| 230 |
Q_UNUSED(ModNum); |
| 231 |
|
| 232 |
if (!viewer) { |
| 233 |
return; |
| 234 |
} |
| 235 |
|
| 236 |
if (transformDragger) { |
| 237 |
transformDragger->setUpAutoScale(viewer->getSoRenderManager()->getCamera()); |
| 238 |
|
| 239 |
auto originPlacement = App::GeoFeature::getGlobalPlacement(getObject()) |
| 240 |
* getObjectPlacement().inverse(); |
| 241 |
auto mat = originPlacement.toMatrix(); |
| 242 |
|
| 243 |
viewer->getDocument()->setEditingTransform(mat); |
| 244 |
viewer->setupEditingRoot(transformDragger, &mat); |
| 245 |
} |
| 246 |
|
| 247 |
if (gizmoContainer) { |
| 248 |
auto originPlacement = App::GeoFeature::getGlobalPlacement(getObject()) |
| 249 |
* getObjectPlacement().inverse(); |
| 250 |
gizmoContainer->attachViewer(viewer, originPlacement); |
| 251 |
} |
| 252 |
} |
| 253 |
|
| 254 |
void ViewProviderDragger::unsetEditViewer([[maybe_unused]] Gui::View3DInventorViewer* viewer) |
| 255 |
{} |
| 256 |
|
| 257 |
void ViewProviderDragger::dragStartCallback(void* data, [[maybe_unused]] SoDragger* d) |
| 258 |
{ |
| 259 |
// This is called when a manipulator has done manipulating |
| 260 |
auto vp = static_cast<ViewProviderDragger*>(data); |
| 261 |
|
| 262 |
vp->draggerPlacement = vp->getDraggerPlacement(); |
| 263 |
vp->transformDragger->clearIncrementCounts(); |
| 264 |
} |
| 265 |
|
| 266 |
void ViewProviderDragger::dragFinishCallback(void* data, [[maybe_unused]] SoDragger* d) |
| 267 |
{ |
| 268 |
// This is called when a manipulator has done manipulating |
| 269 |
auto vp = static_cast<ViewProviderDragger*>(data); |
| 270 |
|
| 271 |
vp->draggerPlacement = vp->getDraggerPlacement(); |
| 272 |
vp->transformDragger->clearIncrementCounts(); |
| 273 |
|
| 274 |
vp->updatePlacementFromDragger(); |
| 275 |
} |
| 276 |
|
| 277 |
void ViewProviderDragger::dragMotionCallback(void* data, [[maybe_unused]] SoDragger* d) |
| 278 |
{ |
| 279 |
auto vp = static_cast<ViewProviderDragger*>(data); |
| 280 |
|
| 281 |
vp->updateTransformFromDragger(); |
| 282 |
} |
| 283 |
|
| 284 |
void ViewProviderDragger::updatePlacementFromDragger(DraggerComponents components) |
| 285 |
{ |
| 286 |
const auto placement = getObject()->getPlacementProperty(); |
| 287 |
|
| 288 |
if (!placement) { |
| 289 |
return; |
| 290 |
} |
| 291 |
|
| 292 |
// Get new target dragger placement |
| 293 |
Base::Placement newDraggerPlacement = getDraggerPlacement(); |
| 294 |
Base::Vector3d newDraggerPosition = newDraggerPlacement.getPosition(); |
| 295 |
Base::Rotation newDraggerRotation = newDraggerPlacement.getRotation(); |
| 296 |
|
| 297 |
// Get old dragger placement before movement |
| 298 |
const Base::Placement oldObjectPlacement = placement->getValue(); |
| 299 |
const Base::Placement oldDraggerPlacement = oldObjectPlacement * getTransformOrigin(); |
| 300 |
const Base::Vector3d oldDraggerPosition = oldDraggerPlacement.getPosition(); |
| 301 |
const Base::Rotation oldDraggerRotation = oldDraggerPlacement.getRotation(); |
| 302 |
|
| 303 |
// --- Mask translation --- |
| 304 |
const Base::Vector3d deltaPositionGlobal = newDraggerPosition - oldDraggerPosition; |
| 305 |
const Base::Vector3d deltaPositionLocal = oldDraggerRotation.inverse().multVec(deltaPositionGlobal); |
| 306 |
Base::Vector3d maskedDeltaPositionLocal = deltaPositionLocal; |
| 307 |
|
| 308 |
if (!components.testFlag(DraggerComponent::XPos)) { |
| 309 |
maskedDeltaPositionLocal.x = 0.0; |
| 310 |
} |
| 311 |
if (!components.testFlag(DraggerComponent::YPos)) { |
| 312 |
maskedDeltaPositionLocal.y = 0.0; |
| 313 |
} |
| 314 |
if (!components.testFlag(DraggerComponent::ZPos)) { |
| 315 |
maskedDeltaPositionLocal.z = 0.0; |
| 316 |
} |
| 317 |
|
| 318 |
const Base::Vector3d maskedDeltaPositionGlobal = oldDraggerRotation.multVec( |
| 319 |
maskedDeltaPositionLocal |
| 320 |
); |
| 321 |
Base::Vector3d finalPosition = oldDraggerPosition + maskedDeltaPositionGlobal; |
| 322 |
|
| 323 |
// --- Mask rotation --- |
| 324 |
Base::Vector3d oldX = oldDraggerRotation.multVec(Base::Vector3d::UnitX); |
| 325 |
Base::Vector3d oldY = oldDraggerRotation.multVec(Base::Vector3d::UnitY); |
| 326 |
Base::Vector3d oldZ = oldDraggerRotation.multVec(Base::Vector3d::UnitZ); |
| 327 |
|
| 328 |
Base::Vector3d newX = newDraggerRotation.multVec(Base::Vector3d::UnitX); |
| 329 |
Base::Vector3d newY = newDraggerRotation.multVec(Base::Vector3d::UnitY); |
| 330 |
Base::Vector3d newZ = newDraggerRotation.multVec(Base::Vector3d::UnitZ); |
| 331 |
|
| 332 |
// Choose which axes to align |
| 333 |
Base::Vector3d x = components.testFlag(DraggerComponent::XRot) ? newX : oldX; |
| 334 |
Base::Vector3d y = components.testFlag(DraggerComponent::YRot) ? newY : oldY; |
| 335 |
Base::Vector3d z = components.testFlag(DraggerComponent::ZRot) ? newZ : oldZ; |
| 336 |
|
| 337 |
Base::Rotation finalRotation = orthonormalize(x, y, z, components); |
| 338 |
|
| 339 |
// Create new dragger placement, only if components are masked |
| 340 |
Base::Placement finalDraggerPlacement(newDraggerPosition, newDraggerRotation); |
| 341 |
if (!components.testFlag(DraggerComponent::All)) { |
| 342 |
finalDraggerPlacement.setPosition(finalPosition); |
| 343 |
finalDraggerPlacement.setRotation(finalRotation); |
| 344 |
} |
| 345 |
|
| 346 |
placement->setValue((finalDraggerPlacement * getTransformOrigin().inverse())); |
| 347 |
updateDraggerPosition(); |
| 348 |
} |
| 349 |
|
| 350 |
Base::Rotation Gui::ViewProviderDragger::orthonormalize( |
| 351 |
Base::Vector3d x, |
| 352 |
Base::Vector3d y, |
| 353 |
Base::Vector3d z, |
| 354 |
ViewProviderDragger::DraggerComponents components |
| 355 |
) |
| 356 |
{ |
| 357 |
// Orthonormalize (Gram–Schmidt process) to find perpendicular unit vector depending on masked axes |
| 358 |
if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::XRot) |
| 359 |
&& components.testFlag(Gui::ViewProviderDragger::DraggerComponent::YRot)) { |
| 360 |
x.Normalize(); |
| 361 |
y = y - x * (x * y); |
| 362 |
y.Normalize(); |
| 363 |
z = x.Cross(y); |
| 364 |
z.Normalize(); |
| 365 |
} |
| 366 |
else if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::XRot) |
| 367 |
&& components.testFlag(Gui::ViewProviderDragger::DraggerComponent::ZRot)) { |
| 368 |
x.Normalize(); |
| 369 |
z = z - x * (x * z); |
| 370 |
z.Normalize(); |
| 371 |
y = z.Cross(x); |
| 372 |
y.Normalize(); |
| 373 |
} |
| 374 |
else if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::YRot) |
| 375 |
&& components.testFlag(Gui::ViewProviderDragger::DraggerComponent::ZRot)) { |
| 376 |
y.Normalize(); |
| 377 |
z = z - y * (y * z); |
| 378 |
z.Normalize(); |
| 379 |
x = y.Cross(z); |
| 380 |
x.Normalize(); |
| 381 |
} |
| 382 |
else if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::XRot)) { |
| 383 |
x.Normalize(); |
| 384 |
y = y - x * (x * y); |
| 385 |
y.Normalize(); |
| 386 |
z = x.Cross(y); |
| 387 |
z.Normalize(); |
| 388 |
} |
| 389 |
else if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::YRot)) { |
| 390 |
y.Normalize(); |
| 391 |
x = x - y * (x * y); |
| 392 |
x.Normalize(); |
| 393 |
z = x.Cross(y); |
| 394 |
z.Normalize(); |
| 395 |
} |
| 396 |
else if (components.testFlag(Gui::ViewProviderDragger::DraggerComponent::ZRot)) { |
| 397 |
z.Normalize(); |
| 398 |
x = x - z * (x * z); |
| 399 |
x.Normalize(); |
| 400 |
y = z.Cross(x); |
| 401 |
y.Normalize(); |
| 402 |
} |
| 403 |
|
| 404 |
return Base::Rotation::makeRotationByAxes(x, y, z); |
| 405 |
} |
| 406 |
|
| 407 |
void ViewProviderDragger::updateTransformFromDragger() |
| 408 |
{ |
| 409 |
const auto placement = getDraggerPlacement() * getTransformOrigin().inverse(); |
| 410 |
|
| 411 |
pcTransform->translation.setValue(Base::convertTo<SbVec3f>(placement.getPosition())); |
| 412 |
pcTransform->rotation.setValue(Base::convertTo<SbRotation>(placement.getRotation())); |
| 413 |
} |
| 414 |
|
| 415 |
Base::Placement ViewProviderDragger::getObjectPlacement() const |
| 416 |
{ |
| 417 |
if (auto placement = getObject()->getPlacementProperty()) { |
| 418 |
return placement->getValue(); |
| 419 |
} |
| 420 |
|
| 421 |
return {}; |
| 422 |
} |
| 423 |
|
| 424 |
Base::Placement ViewProviderDragger::getDraggerPlacement() const |
| 425 |
{ |
| 426 |
const double translationStep = transformDragger->translationIncrement.getValue(); |
| 427 |
const int xSteps = transformDragger->translationIncrementCountX.getValue(); |
| 428 |
const int ySteps = transformDragger->translationIncrementCountY.getValue(); |
| 429 |
const int zSteps = transformDragger->translationIncrementCountZ.getValue(); |
| 430 |
|
| 431 |
const auto rotation = draggerPlacement.getRotation(); |
| 432 |
const auto xBase = rotation.multVec(Base::Vector3d(1, 0, 0)); |
| 433 |
const auto yBase = rotation.multVec(Base::Vector3d(0, 1, 0)); |
| 434 |
const auto zBase = rotation.multVec(Base::Vector3d(0, 0, 1)); |
| 435 |
|
| 436 |
const auto positionIncrement = xBase * (translationStep * xSteps) |
| 437 |
+ yBase * (translationStep * ySteps) + zBase * (translationStep * zSteps); |
| 438 |
|
| 439 |
const double rotationStep = transformDragger->rotationIncrement.getValue(); |
| 440 |
const int xRotationSteps = transformDragger->rotationIncrementCountX.getValue(); |
| 441 |
const int yRotationSteps = transformDragger->rotationIncrementCountY.getValue(); |
| 442 |
const int zRotationSteps = transformDragger->rotationIncrementCountZ.getValue(); |
| 443 |
|
| 444 |
auto newRotation = rotation; |
| 445 |
newRotation = newRotation |
| 446 |
* Base::Rotation(Base::Vector3d(1, 0, 0), xRotationSteps * rotationStep); |
| 447 |
newRotation = newRotation |
| 448 |
* Base::Rotation(Base::Vector3d(0, 1, 0), yRotationSteps * rotationStep); |
| 449 |
newRotation = newRotation |
| 450 |
* Base::Rotation(Base::Vector3d(0, 0, 1), zRotationSteps * rotationStep); |
| 451 |
|
| 452 |
return Base::Placement(draggerPlacement.getPosition() + positionIncrement, newRotation); |
| 453 |
} |
| 454 |
|
| 455 |
Base::Placement ViewProviderDragger::getOriginalDraggerPlacement() const |
| 456 |
{ |
| 457 |
return draggerPlacement; |
| 458 |
} |
| 459 |
|
| 460 |
void ViewProviderDragger::setDraggerPlacement(const Base::Placement& placement) |
| 461 |
{ |
| 462 |
transformDragger->translation.setValue(Base::convertTo<SbVec3f>(placement.getPosition())); |
| 463 |
transformDragger->rotation.setValue(Base::convertTo<SbRotation>(placement.getRotation())); |
| 464 |
|
| 465 |
draggerPlacement = placement; |
| 466 |
transformDragger->clearIncrementCounts(); |
| 467 |
} |
| 468 |
|
| 469 |
void ViewProviderDragger::attach(App::DocumentObject* pcObject) |
| 470 |
{ |
| 471 |
ViewProviderDocumentObject::attach(pcObject); |
| 472 |
|
| 473 |
getAnnotation()->addChild(pcPlacement); |
| 474 |
|
| 475 |
auto* pcAxisCrossKit = new Gui::SoFCPlacementIndicatorKit(); |
| 476 |
|
| 477 |
auto* pcAnnotation = new So3DAnnotation(); |
| 478 |
pcAnnotation->addChild(pcAxisCrossKit); |
| 479 |
|
| 480 |
pcPlacement->addChild(pcAnnotation); |
| 481 |
} |
| 482 |
|
| 483 |
void ViewProviderDragger::updateDraggerPosition() |
| 484 |
{ |
| 485 |
if (!transformDragger) { |
| 486 |
return; |
| 487 |
} |
| 488 |
|
| 489 |
auto placement = getObjectPlacement() * getTransformOrigin(); |
| 490 |
|
| 491 |
setDraggerPlacement(placement); |
| 492 |
} |
| 493 |
|
| 494 |
void ViewProviderDragger::updateTransform(const Base::Placement& from, SoTransform* to) |
| 495 |
{ |
| 496 |
to->rotation.setValue(Base::convertTo<SbRotation>(from.getRotation())); |
| 497 |
to->translation.setValue(Base::convertTo<SbVec3f>(from.getPosition())); |
| 498 |
to->center.setValue(0.0f, 0.0f, 0.0f); |
| 499 |
to->scaleFactor.setValue(1.0f, 1.0f, 1.0f); |
| 500 |
} |