Skip to content

Commit fcbee3a

Browse files
Rexbaschennes
authored andcommitted
Gui: Improve object center rotation mode
1 parent 7d92236 commit fcbee3a

File tree

6 files changed

+45
-5
lines changed

6 files changed

+45
-5
lines changed

src/Gui/NavigationStyle.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1082,8 +1082,9 @@ void NavigationStyle::saveCursorPosition(const SoEvent * const ev)
10821082
if (!cam) // no camera
10831083
return;
10841084

1085+
// Get the bounding box center of the physical object group
10851086
SoGetBoundingBoxAction action(viewer->getSoRenderManager()->getViewportRegion());
1086-
action.apply(viewer->getSceneGraph());
1087+
action.apply(viewer->objectGroup);
10871088
SbBox3f boundingBox = action.getBoundingBox();
10881089
SbVec3f boundingBoxCenter = boundingBox.getCenter();
10891090
setRotationCenter(boundingBoxCenter);

src/Gui/View3DInventorViewer.cpp

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,7 @@ View3DInventorViewer::View3DInventorViewer(QWidget* parent, const QtGLWidget* sh
335335
: Quarter::SoQTQuarterAdaptor(parent, sharewidget)
336336
, SelectionObserver(false, ResolveMode::NoResolve)
337337
, editViewProvider(nullptr)
338+
, objectGroup(nullptr)
338339
, navigation(nullptr)
339340
, renderType(Native)
340341
, framebuffer(nullptr)
@@ -354,6 +355,7 @@ View3DInventorViewer::View3DInventorViewer(const QtGLFormat& format, QWidget* pa
354355
: Quarter::SoQTQuarterAdaptor(format, parent, sharewidget)
355356
, SelectionObserver(false, ResolveMode::NoResolve)
356357
, editViewProvider(nullptr)
358+
, objectGroup(nullptr)
357359
, navigation(nullptr)
358360
, renderType(Native)
359361
, framebuffer(nullptr)
@@ -482,6 +484,11 @@ void View3DInventorViewer::init()
482484
pcEditingRoot->addChild(pcEditingTransform);
483485
pcViewProviderRoot->addChild(pcEditingRoot);
484486

487+
// Create group for the physical object
488+
objectGroup = new SoGroup();
489+
objectGroup->ref();
490+
pcViewProviderRoot->addChild(objectGroup);
491+
485492
// Set our own render action which show a bounding box if
486493
// the SoFCSelection::BOX style is set
487494
//
@@ -569,6 +576,8 @@ View3DInventorViewer::~View3DInventorViewer()
569576
coinRemoveAllChildren(this->pcViewProviderRoot);
570577
this->pcViewProviderRoot->unref();
571578
this->pcViewProviderRoot = nullptr;
579+
this->objectGroup->unref();
580+
this->objectGroup = nullptr;
572581
this->backlight->unref();
573582
this->backlight = nullptr;
574583

@@ -759,8 +768,15 @@ void View3DInventorViewer::addViewProvider(ViewProvider* pcProvider)
759768
SoSeparator* root = pcProvider->getRoot();
760769

761770
if (root) {
762-
if(pcProvider->canAddToSceneGraph())
763-
pcViewProviderRoot->addChild(root);
771+
if (pcProvider->canAddToSceneGraph()) {
772+
// Add to the physical object group if related to the physical object otherwise add to the scene graph
773+
if (pcProvider->isPartOfPhysicalObject()) {
774+
objectGroup->addChild(root);
775+
}
776+
else {
777+
pcViewProviderRoot->addChild(root);
778+
}
779+
}
764780
_ViewProviderMap[root] = pcProvider;
765781
}
766782

@@ -784,9 +800,15 @@ void View3DInventorViewer::removeViewProvider(ViewProvider* pcProvider)
784800
SoSeparator* root = pcProvider->getRoot();
785801

786802
if (root) {
787-
int index = pcViewProviderRoot->findChild(root);
788-
if(index>=0)
803+
int index = objectGroup->findChild(root);
804+
if (index >= 0) {
805+
objectGroup->removeChild(index);
806+
}
807+
808+
index = pcViewProviderRoot->findChild(root);
809+
if (index >= 0) {
789810
pcViewProviderRoot->removeChild(index);
811+
}
790812
_ViewProviderMap.erase(root);
791813
}
792814

src/Gui/View3DInventorViewer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,10 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
485485
SoSeparator * foregroundroot;
486486
SoDirectionalLight* backlight;
487487

488+
// Scene graph root
488489
SoSeparator * pcViewProviderRoot;
490+
// Child group in the scene graph that contains view providers related to the physical object
491+
SoGroup* objectGroup;
489492

490493
std::unique_ptr<View3DInventorSelection> inventorSelection;
491494

src/Gui/ViewProvider.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class GuiExport ViewProvider : public App::TransactionalObject
142142
virtual SoSeparator* getBackRoot() const;
143143
///Indicate whether to be added to scene graph or not
144144
virtual bool canAddToSceneGraph() const {return true;}
145+
// Indicate whether to be added to object group (true) or only to scene graph (false)
146+
virtual bool isPartOfPhysicalObject() const {return true;}
145147

146148
/** deliver the children belonging to this object
147149
* this method is used to deliver the objects to

src/Gui/ViewProviderMeasureDistance.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ ViewProviderMeasureDistance::~ViewProviderMeasureDistance()
120120
pLines->unref();
121121
}
122122

123+
bool ViewProviderMeasureDistance::isPartOfPhysicalObject() const
124+
{
125+
return false;
126+
}
127+
123128
void ViewProviderMeasureDistance::onChanged(const App::Property* prop)
124129
{
125130
if (prop == &Mirror || prop == &DistFactor) {
@@ -313,6 +318,11 @@ ViewProviderPointMarker::~ViewProviderPointMarker()
313318
pMarker->unref();
314319
}
315320

321+
bool ViewProviderPointMarker::isPartOfPhysicalObject() const
322+
{
323+
return false;
324+
}
325+
316326
void ViewProviderMeasureDistance::measureDistanceCallback(void * ud, SoEventCallback * n)
317327
{
318328
auto view = static_cast<Gui::View3DInventorViewer*>(n->getUserData());

src/Gui/ViewProviderMeasureDistance.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ class GuiExport ViewProviderPointMarker : public ViewProviderDocumentObject
6666
public:
6767
ViewProviderPointMarker();
6868
~ViewProviderPointMarker() override;
69+
bool isPartOfPhysicalObject() const override;
6970

7071
protected:
7172
SoCoordinate3 * pCoords;
@@ -81,6 +82,7 @@ class GuiExport ViewProviderMeasureDistance : public ViewProviderDocumentObject
8182
/// Constructor
8283
ViewProviderMeasureDistance();
8384
~ViewProviderMeasureDistance() override;
85+
bool isPartOfPhysicalObject() const override;
8486

8587
// Display properties
8688
App::PropertyColor TextColor;

0 commit comments

Comments
 (0)