Gui: Improve object center rotation mode
This commit is contained in:
@@ -1082,8 +1082,9 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev)
|
||||
if (!cam) // no camera
|
||||
return;
|
||||
|
||||
// Get the bounding box center of the physical object group
|
||||
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
|
||||
action.apply(viewer->getSceneGraph());
|
||||
action.apply(viewer->objectGroup);
|
||||
SbBox3f boundingBox = action.getBoundingBox();
|
||||
SbVec3f boundingBoxCenter = boundingBox.getCenter();
|
||||
setRotationCenter(boundingBoxCenter);
|
||||
|
||||
@@ -335,6 +335,7 @@ View3DInventorViewer::View3DInventorViewer(QWidget* parent, const QtGLWidget* sh
|
||||
: Quarter::SoQTQuarterAdaptor(parent, sharewidget)
|
||||
, SelectionObserver(false, ResolveMode::NoResolve)
|
||||
, editViewProvider(nullptr)
|
||||
, objectGroup(nullptr)
|
||||
, navigation(nullptr)
|
||||
, renderType(Native)
|
||||
, framebuffer(nullptr)
|
||||
@@ -354,6 +355,7 @@ View3DInventorViewer::View3DInventorViewer(const QtGLFormat& format, QWidget* pa
|
||||
: Quarter::SoQTQuarterAdaptor(format, parent, sharewidget)
|
||||
, SelectionObserver(false, ResolveMode::NoResolve)
|
||||
, editViewProvider(nullptr)
|
||||
, objectGroup(nullptr)
|
||||
, navigation(nullptr)
|
||||
, renderType(Native)
|
||||
, framebuffer(nullptr)
|
||||
@@ -482,6 +484,11 @@ void View3DInventorViewer::init()
|
||||
pcEditingRoot->addChild(pcEditingTransform);
|
||||
pcViewProviderRoot->addChild(pcEditingRoot);
|
||||
|
||||
// Create group for the physical object
|
||||
objectGroup = new SoGroup();
|
||||
objectGroup->ref();
|
||||
pcViewProviderRoot->addChild(objectGroup);
|
||||
|
||||
// Set our own render action which show a bounding box if
|
||||
// the SoFCSelection::BOX style is set
|
||||
//
|
||||
@@ -569,6 +576,8 @@ View3DInventorViewer::~View3DInventorViewer()
|
||||
coinRemoveAllChildren(this->pcViewProviderRoot);
|
||||
this->pcViewProviderRoot->unref();
|
||||
this->pcViewProviderRoot = nullptr;
|
||||
this->objectGroup->unref();
|
||||
this->objectGroup = nullptr;
|
||||
this->backlight->unref();
|
||||
this->backlight = nullptr;
|
||||
|
||||
@@ -759,8 +768,15 @@ void View3DInventorViewer::addViewProvider(ViewProvider* pcProvider)
|
||||
SoSeparator* root = pcProvider->getRoot();
|
||||
|
||||
if (root) {
|
||||
if(pcProvider->canAddToSceneGraph())
|
||||
pcViewProviderRoot->addChild(root);
|
||||
if (pcProvider->canAddToSceneGraph()) {
|
||||
// Add to the physical object group if related to the physical object otherwise add to the scene graph
|
||||
if (pcProvider->isPartOfPhysicalObject()) {
|
||||
objectGroup->addChild(root);
|
||||
}
|
||||
else {
|
||||
pcViewProviderRoot->addChild(root);
|
||||
}
|
||||
}
|
||||
_ViewProviderMap[root] = pcProvider;
|
||||
}
|
||||
|
||||
@@ -784,9 +800,15 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider)
|
||||
SoSeparator* root = pcProvider->getRoot();
|
||||
|
||||
if (root) {
|
||||
int index = pcViewProviderRoot->findChild(root);
|
||||
if(index>=0)
|
||||
int index = objectGroup->findChild(root);
|
||||
if (index >= 0) {
|
||||
objectGroup->removeChild(index);
|
||||
}
|
||||
|
||||
index = pcViewProviderRoot->findChild(root);
|
||||
if (index >= 0) {
|
||||
pcViewProviderRoot->removeChild(index);
|
||||
}
|
||||
_ViewProviderMap.erase(root);
|
||||
}
|
||||
|
||||
|
||||
@@ -485,7 +485,10 @@ private:
|
||||
SoSeparator * foregroundroot;
|
||||
SoDirectionalLight* backlight;
|
||||
|
||||
// Scene graph root
|
||||
SoSeparator * pcViewProviderRoot;
|
||||
// Child group in the scene graph that contains view providers related to the physical object
|
||||
SoGroup* objectGroup;
|
||||
|
||||
std::unique_ptr<View3DInventorSelection> inventorSelection;
|
||||
|
||||
|
||||
@@ -142,6 +142,8 @@ public:
|
||||
virtual SoSeparator* getBackRoot() const;
|
||||
///Indicate whether to be added to scene graph or not
|
||||
virtual bool canAddToSceneGraph() const {return true;}
|
||||
// Indicate whether to be added to object group (true) or only to scene graph (false)
|
||||
virtual bool isPartOfPhysicalObject() const {return true;}
|
||||
|
||||
/** deliver the children belonging to this object
|
||||
* this method is used to deliver the objects to
|
||||
|
||||
@@ -120,6 +120,11 @@ ViewProviderMeasureDistance::~ViewProviderMeasureDistance()
|
||||
pLines->unref();
|
||||
}
|
||||
|
||||
bool ViewProviderMeasureDistance::isPartOfPhysicalObject() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProviderMeasureDistance::onChanged(const App::Property* prop)
|
||||
{
|
||||
if (prop == &Mirror || prop == &DistFactor) {
|
||||
@@ -313,6 +318,11 @@ ViewProviderPointMarker::~ViewProviderPointMarker()
|
||||
pMarker->unref();
|
||||
}
|
||||
|
||||
bool ViewProviderPointMarker::isPartOfPhysicalObject() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void ViewProviderMeasureDistance::measureDistanceCallback(void * ud, SoEventCallback * n)
|
||||
{
|
||||
auto view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());
|
||||
|
||||
@@ -66,6 +66,7 @@ class GuiExport ViewProviderPointMarker : public ViewProviderDocumentObject
|
||||
public:
|
||||
ViewProviderPointMarker();
|
||||
~ViewProviderPointMarker() override;
|
||||
bool isPartOfPhysicalObject() const override;
|
||||
|
||||
protected:
|
||||
SoCoordinate3 * pCoords;
|
||||
@@ -81,6 +82,7 @@ public:
|
||||
/// Constructor
|
||||
ViewProviderMeasureDistance();
|
||||
~ViewProviderMeasureDistance() override;
|
||||
bool isPartOfPhysicalObject() const override;
|
||||
|
||||
// Display properties
|
||||
App::PropertyColor TextColor;
|
||||
|
||||
Reference in New Issue
Block a user