@@ -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
0 commit comments