Gui: refactor gizmo attachment code
This commit is contained in:
committed by
Kacper Donat
parent
e21f616974
commit
6282b7c08d
@@ -40,6 +40,7 @@
|
||||
#include <Gui/Inventor/Draggers/GizmoStyleParameters.h>
|
||||
#include <Gui/Inventor/So3DAnnotation.h>
|
||||
#include <Gui/Inventor/SoToggleSwitch.h>
|
||||
#include <Gui/ViewProviderDragger.h>
|
||||
#include <Gui/QuantitySpinBox.h>
|
||||
#include <Gui/Utilities.h>
|
||||
#include <Gui/View3DInventorViewer.h>
|
||||
@@ -653,6 +654,8 @@ GizmoContainer::~GizmoContainer()
|
||||
cameraPositionSensor.detach();
|
||||
|
||||
uninitGizmos();
|
||||
|
||||
viewProvider->setGizmoContainer(nullptr);
|
||||
}
|
||||
|
||||
void GizmoContainer::initGizmos()
|
||||
@@ -694,6 +697,8 @@ void GizmoContainer::attachViewer(Gui::View3DInventorViewer* viewer, Base::Place
|
||||
return;
|
||||
}
|
||||
|
||||
setUpAutoScale(viewer->getSoRenderManager()->getCamera());
|
||||
|
||||
auto mat = origin.toMatrix();
|
||||
|
||||
viewer->getDocument()->setEditingTransform(mat);
|
||||
@@ -766,3 +771,17 @@ bool GizmoContainer::isEnabled()
|
||||
|
||||
return hGrp->GetBool("EnableGizmos", true);
|
||||
}
|
||||
|
||||
std::unique_ptr<GizmoContainer> GizmoContainer::create(
|
||||
std::initializer_list<Gui::Gizmo*> gizmos,
|
||||
ViewProviderDragger* vp
|
||||
)
|
||||
{
|
||||
auto gizmoContainer = std::make_unique<GizmoContainer>();
|
||||
gizmoContainer->addGizmos(gizmos);
|
||||
gizmoContainer->viewProvider = vp;
|
||||
|
||||
vp->setGizmoContainer(gizmoContainer.get());
|
||||
|
||||
return gizmoContainer;
|
||||
}
|
||||
|
||||
@@ -50,6 +50,7 @@ class SoLinearDraggerContainer;
|
||||
class SoRotationDragger;
|
||||
class SoRotationDraggerContainer;
|
||||
class View3DInventorViewer;
|
||||
class ViewProviderDragger;
|
||||
|
||||
struct GizmoPlacement
|
||||
{
|
||||
@@ -235,20 +236,16 @@ public:
|
||||
|
||||
// Checks if the gizmos are enabled in the preferences
|
||||
static bool isEnabled();
|
||||
template <typename T>
|
||||
static inline std::unique_ptr<GizmoContainer> createGizmo(std::initializer_list<Gui::Gizmo*> gizmos, T vp)
|
||||
{
|
||||
auto ptr = std::make_unique<GizmoContainer>();
|
||||
ptr->addGizmos(gizmos);
|
||||
vp->setGizmoContainer(ptr.get());
|
||||
|
||||
return ptr;
|
||||
}
|
||||
static std::unique_ptr<GizmoContainer> create(
|
||||
std::initializer_list<Gui::Gizmo*> gizmos,
|
||||
ViewProviderDragger* vp
|
||||
);
|
||||
|
||||
private:
|
||||
std::vector<Gizmo*> gizmos;
|
||||
SoFieldSensor cameraSensor;
|
||||
SoFieldSensor cameraPositionSensor;
|
||||
ViewProviderDragger* viewProvider = nullptr;
|
||||
|
||||
void addGizmo(Gizmo* gizmo);
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
#include "Control.h"
|
||||
#include "Document.h"
|
||||
#include "Inventor/Draggers/SoTransformDragger.h"
|
||||
#include "Inventor/Draggers/Gizmo.h"
|
||||
#include "Inventor/SoFCPlacementIndicatorKit.h"
|
||||
#include "SoFCUnifiedSelection.h"
|
||||
#include "TaskTransform.h"
|
||||
@@ -94,6 +95,12 @@ void ViewProviderDragger::resetTransformOrigin()
|
||||
setTransformOrigin({});
|
||||
}
|
||||
|
||||
|
||||
void ViewProviderDragger::setGizmoContainer(Gui::GizmoContainer* gizmoContainer)
|
||||
{
|
||||
this->gizmoContainer = gizmoContainer;
|
||||
}
|
||||
|
||||
void ViewProviderDragger::onChanged(const App::Property* property)
|
||||
{
|
||||
if (property == &TransformOrigin) {
|
||||
@@ -221,7 +228,11 @@ void ViewProviderDragger::setEditViewer(Gui::View3DInventorViewer* viewer, int M
|
||||
{
|
||||
Q_UNUSED(ModNum);
|
||||
|
||||
if (transformDragger && viewer) {
|
||||
if (!viewer) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (transformDragger) {
|
||||
transformDragger->setUpAutoScale(viewer->getSoRenderManager()->getCamera());
|
||||
|
||||
auto originPlacement = App::GeoFeature::getGlobalPlacement(getObject()) * getObjectPlacement().inverse();
|
||||
@@ -230,6 +241,12 @@ void ViewProviderDragger::setEditViewer(Gui::View3DInventorViewer* viewer, int M
|
||||
viewer->getDocument()->setEditingTransform(mat);
|
||||
viewer->setupEditingRoot(transformDragger, &mat);
|
||||
}
|
||||
|
||||
if (gizmoContainer) {
|
||||
auto originPlacement = App::GeoFeature::getGlobalPlacement(getObject())
|
||||
* getObjectPlacement().inverse();
|
||||
gizmoContainer->attachViewer(viewer, originPlacement);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderDragger::unsetEditViewer([[maybe_unused]] Gui::View3DInventorViewer* viewer)
|
||||
|
||||
@@ -40,6 +40,7 @@ namespace TaskView {
|
||||
|
||||
class SoTransformDragger;
|
||||
class View3DInventorViewer;
|
||||
class GizmoContainer;
|
||||
|
||||
/**
|
||||
* The base class for all view providers modifying the placement
|
||||
@@ -71,6 +72,8 @@ public:
|
||||
/// Resets transform origin to the object origin
|
||||
void resetTransformOrigin();
|
||||
|
||||
void setGizmoContainer(Gui::GizmoContainer* gizmoContainer);
|
||||
|
||||
public:
|
||||
/** @name Edit methods */
|
||||
//@{
|
||||
@@ -147,6 +150,8 @@ private:
|
||||
Base::Vector3d y,
|
||||
Base::Vector3d z,
|
||||
ViewProviderDragger::DraggerComponents components = DraggerComponent::All);
|
||||
|
||||
GizmoContainer* gizmoContainer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace Gui
|
||||
|
||||
@@ -326,7 +326,7 @@ void ThicknessWidget::setupGizmos()
|
||||
delete linearGizmo;
|
||||
return;
|
||||
}
|
||||
gizmoContainer = Gui::GizmoContainer::createGizmo({linearGizmo}, vp);
|
||||
gizmoContainer = Gui::GizmoContainer::create({linearGizmo}, vp);
|
||||
|
||||
setGizmoPositions();
|
||||
}
|
||||
|
||||
@@ -111,25 +111,6 @@ void ViewProviderPart::applyTransparency(float transparency, std::vector<App::Ma
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderPart::setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum)
|
||||
{
|
||||
ViewProviderPartExt::setEditViewer(viewer, ModNum);
|
||||
|
||||
if (gizmoContainer) {
|
||||
gizmoContainer->setUpAutoScale(viewer->getSoRenderManager()->getCamera());
|
||||
|
||||
auto originPlacement = App::GeoFeature::getGlobalPlacement(getObject())
|
||||
* getObjectPlacement().inverse();
|
||||
gizmoContainer->attachViewer(viewer, originPlacement);
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderPart::setGizmoContainer(Gui::GizmoContainer* gizmoContainer)
|
||||
{
|
||||
assert(gizmoContainer);
|
||||
this->gizmoContainer = gizmoContainer;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void ViewProviderShapeBuilder::buildNodes(const App::Property* prop, std::vector<SoNode*>& nodes) const
|
||||
|
||||
@@ -60,8 +60,6 @@ public:
|
||||
~ViewProviderPart() override;
|
||||
bool doubleClicked() override;
|
||||
|
||||
void setGizmoContainer(Gui::GizmoContainer* gizmoContainer);
|
||||
|
||||
protected:
|
||||
void applyColor(const Part::ShapeHistory& hist,
|
||||
const std::vector<Base::Color>& colBase,
|
||||
@@ -71,11 +69,6 @@ protected:
|
||||
std::vector<App::Material>& colBool);
|
||||
void applyTransparency(float transparency, std::vector<Base::Color>& colors);
|
||||
void applyTransparency(float transparency, std::vector<App::Material>& colors);
|
||||
|
||||
void setEditViewer(Gui::View3DInventorViewer* viewer, int ModNum) override;
|
||||
|
||||
private:
|
||||
Gui::GizmoContainer* gizmoContainer = nullptr;
|
||||
};
|
||||
|
||||
} // namespace PartGui
|
||||
|
||||
@@ -383,7 +383,7 @@ void TaskChamferParameters::setupGizmos(ViewProviderDressUp* vp)
|
||||
}
|
||||
});
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({
|
||||
gizmoContainer = GizmoContainer::create({
|
||||
distanceGizmo, secondDistanceGizmo, angleGizmo
|
||||
}, vp);
|
||||
|
||||
|
||||
@@ -1375,7 +1375,7 @@ void TaskExtrudeParameters::setupGizmos()
|
||||
setGizmoPositions();
|
||||
});
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({
|
||||
gizmoContainer = GizmoContainer::create({
|
||||
lengthGizmo1, lengthGizmo2,
|
||||
taperAngleGizmo1, taperAngleGizmo2
|
||||
}, vp);
|
||||
|
||||
@@ -216,7 +216,7 @@ void TaskFilletParameters::setupGizmos(ViewProviderDressUp* vp)
|
||||
radiusGizmo = new Gui::LinearGizmo(ui->filletRadius);
|
||||
radiusGizmo2 = new Gui::LinearGizmo(ui->filletRadius);
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({radiusGizmo, radiusGizmo2}, vp);
|
||||
gizmoContainer = GizmoContainer::create({radiusGizmo, radiusGizmo2}, vp);
|
||||
|
||||
setGizmoPositions();
|
||||
}
|
||||
|
||||
@@ -726,7 +726,7 @@ void TaskHelixParameters::setupGizmos(ViewProviderHelix* vp)
|
||||
heightGizmo->setVisibility(!isPitchTurnsAngle);
|
||||
});
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({heightGizmo}, vp);
|
||||
gizmoContainer = GizmoContainer::create({heightGizmo}, vp);
|
||||
|
||||
setGizmoPositions();
|
||||
|
||||
|
||||
@@ -1172,7 +1172,7 @@ void TaskHoleParameters::setupGizmos(ViewProviderHole* vp)
|
||||
|
||||
holeDepthGizmo = new LinearGizmo(ui->Depth);
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({holeDepthGizmo}, vp);
|
||||
gizmoContainer = GizmoContainer::create({holeDepthGizmo}, vp);
|
||||
|
||||
setGizmoPositions();
|
||||
}
|
||||
|
||||
@@ -739,7 +739,7 @@ void TaskRevolutionParameters::setupGizmos(ViewProvider* vp)
|
||||
rotationGizmo = new Gui::RadialGizmo(ui->revolveAngle);
|
||||
rotationGizmo2 = new Gui::RadialGizmo(ui->revolveAngle2);
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({rotationGizmo, rotationGizmo2}, vp);
|
||||
gizmoContainer = GizmoContainer::create({rotationGizmo, rotationGizmo2}, vp);
|
||||
rotationGizmo->flipArrow();
|
||||
rotationGizmo2->flipArrow();
|
||||
|
||||
|
||||
@@ -278,7 +278,7 @@ void TaskThicknessParameters::setupGizmos(ViewProviderDressUp* vp)
|
||||
|
||||
linearGizmo = new Gui::LinearGizmo(ui->Value);
|
||||
|
||||
gizmoContainer = GizmoContainer::createGizmo({linearGizmo}, vp);
|
||||
gizmoContainer = GizmoContainer::create({linearGizmo}, vp);
|
||||
|
||||
setGizmoPositions();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user