Skip to content

Commit

Permalink
Gui: Improve object center rotation mode
Browse files Browse the repository at this point in the history
(cherry picked from commit fcbee3a)
  • Loading branch information
Rexbas committed Sep 25, 2023
1 parent 15def85 commit 629f719
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Gui/NavigationStyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,8 +1078,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);
Expand Down
30 changes: 26 additions & 4 deletions src/Gui/View3DInventorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,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)
Expand All @@ -350,6 +351,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)
Expand Down Expand Up @@ -477,6 +479,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
//
Expand Down Expand Up @@ -564,6 +571,8 @@ View3DInventorViewer::~View3DInventorViewer()
coinRemoveAllChildren(this->pcViewProviderRoot);
this->pcViewProviderRoot->unref();
this->pcViewProviderRoot = nullptr;
this->objectGroup->unref();
this->objectGroup = nullptr;
this->backlight->unref();
this->backlight = nullptr;

Expand Down Expand Up @@ -754,8 +763,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;
}

Expand All @@ -779,9 +795,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);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Gui/View3DInventorViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,10 @@ class GuiExport View3DInventorViewer : public Quarter::SoQTQuarterAdaptor, publi
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;

Expand Down
2 changes: 2 additions & 0 deletions src/Gui/ViewProvider.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ class GuiExport ViewProvider : public App::TransactionalObject
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
Expand Down
10 changes: 10 additions & 0 deletions src/Gui/ViewProviderMeasureDistance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/Gui/ViewProviderMeasureDistance.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class GuiExport ViewProviderPointMarker : public ViewProviderDocumentObject
public:
ViewProviderPointMarker();
~ViewProviderPointMarker() override;
bool isPartOfPhysicalObject() const override;

protected:
SoCoordinate3 * pCoords;
Expand All @@ -81,6 +82,7 @@ class GuiExport ViewProviderMeasureDistance : public ViewProviderDocumentObject
/// Constructor
ViewProviderMeasureDistance();
~ViewProviderMeasureDistance() override;
bool isPartOfPhysicalObject() const override;

// Display properties
App::PropertyColor TextColor;
Expand Down

0 comments on commit 629f719

Please sign in to comment.