From 763eb132cffd8b24539f33a907d4d64a1074d404 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 21 Aug 2014 21:46:03 +0200 Subject: [PATCH] + respect placement in VRML and Inventor objects --- src/Gui/ViewProviderInventorObject.cpp | 26 +++++++++++++++++++++++++- src/Gui/ViewProviderVRMLObject.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/Gui/ViewProviderInventorObject.cpp b/src/Gui/ViewProviderInventorObject.cpp index a917198d7..f802d4a70 100644 --- a/src/Gui/ViewProviderInventorObject.cpp +++ b/src/Gui/ViewProviderInventorObject.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include #endif @@ -105,7 +106,7 @@ void ViewProviderInventorObject::updateData(const App::Property* prop) pcBuffer->addChild(node); } } - if (prop == &ivObj->FileName) { + else if (prop == &ivObj->FileName) { // read also from file const char* filename = ivObj->FileName.getValue(); QString fn = QString::fromUtf8(filename); @@ -124,6 +125,29 @@ void ViewProviderInventorObject::updateData(const App::Property* prop) } } } + else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) && + strcmp(prop->getName(), "Placement") == 0) { + // Note: If R is the rotation, c the rotation center and t the translation + // vector then Inventor applies the following transformation: R*(x-c)+c+t + // In FreeCAD a placement only has a rotation and a translation part but + // no rotation center. This means that the following equation must be ful- + // filled: R * (x-c) + c + t = R * x + t + // <==> R * x + t - R * c + c = R * x + t + // <==> (I-R) * c = 0 ==> c = 0 + // This means that the center point must be the origin! + Base::Placement p = static_cast(prop)->getValue(); + float q0 = (float)p.getRotation().getValue()[0]; + float q1 = (float)p.getRotation().getValue()[1]; + float q2 = (float)p.getRotation().getValue()[2]; + float q3 = (float)p.getRotation().getValue()[3]; + float px = (float)p.getPosition().x; + float py = (float)p.getPosition().y; + float pz = (float)p.getPosition().z; + pcTransform->rotation.setValue(q0,q1,q2,q3); + pcTransform->translation.setValue(px,py,pz); + pcTransform->center.setValue(0.0f,0.0f,0.0f); + pcTransform->scaleFactor.setValue(1.0f,1.0f,1.0f); + } } void ViewProviderInventorObject::adjustSelectionNodes(SoNode* child, const char* docname, diff --git a/src/Gui/ViewProviderVRMLObject.cpp b/src/Gui/ViewProviderVRMLObject.cpp index e37a3fece..83141635b 100644 --- a/src/Gui/ViewProviderVRMLObject.cpp +++ b/src/Gui/ViewProviderVRMLObject.cpp @@ -27,6 +27,7 @@ # include # include # include +# include # include #endif @@ -96,4 +97,27 @@ void ViewProviderVRMLObject::updateData(const App::Property* prop) if (node) pcVRML->addChild(node); } } + else if (prop->isDerivedFrom(App::PropertyPlacement::getClassTypeId()) && + strcmp(prop->getName(), "Placement") == 0) { + // Note: If R is the rotation, c the rotation center and t the translation + // vector then Inventor applies the following transformation: R*(x-c)+c+t + // In FreeCAD a placement only has a rotation and a translation part but + // no rotation center. This means that the following equation must be ful- + // filled: R * (x-c) + c + t = R * x + t + // <==> R * x + t - R * c + c = R * x + t + // <==> (I-R) * c = 0 ==> c = 0 + // This means that the center point must be the origin! + Base::Placement p = static_cast(prop)->getValue(); + float q0 = (float)p.getRotation().getValue()[0]; + float q1 = (float)p.getRotation().getValue()[1]; + float q2 = (float)p.getRotation().getValue()[2]; + float q3 = (float)p.getRotation().getValue()[3]; + float px = (float)p.getPosition().x; + float py = (float)p.getPosition().y; + float pz = (float)p.getPosition().z; + pcTransform->rotation.setValue(q0,q1,q2,q3); + pcTransform->translation.setValue(px,py,pz); + pcTransform->center.setValue(0.0f,0.0f,0.0f); + pcTransform->scaleFactor.setValue(1.0f,1.0f,1.0f); + } }