Merge pull request #17782 from wwmayer/issue_17770
Unhandled std exception dragging Cylindrical joint
This commit is contained in:
@@ -2657,14 +2657,14 @@ SbVec2f View3DInventorViewer::getNormalizedPosition(const SbVec2s& pnt) const
|
||||
return {pX, pY};
|
||||
}
|
||||
|
||||
SbVec3f View3DInventorViewer::getPointOnXYPlaneOfPlacement(const SbVec2s& pnt, Base::Placement& plc) const
|
||||
SbVec3f View3DInventorViewer::getPointOnXYPlaneOfPlacement(const SbVec2s& pnt,
|
||||
const Base::Placement& plc) const
|
||||
{
|
||||
SbVec2f pnt2d = getNormalizedPosition(pnt);
|
||||
SoCamera* pCam = this->getSoRenderManager()->getCamera();
|
||||
|
||||
if (!pCam) {
|
||||
// return invalid point
|
||||
return {};
|
||||
throw Base::RuntimeError("No camera node found");
|
||||
}
|
||||
|
||||
SbViewVolume vol = pCam->getViewVolume();
|
||||
@@ -2674,23 +2674,19 @@ SbVec3f View3DInventorViewer::getPointOnXYPlaneOfPlacement(const SbVec2s& pnt, B
|
||||
// Calculate the plane using plc
|
||||
Base::Rotation rot = plc.getRotation();
|
||||
Base::Vector3d normalVector = rot.multVec(Base::Vector3d(0, 0, 1));
|
||||
SbVec3f planeNormal(normalVector.x, normalVector.y, normalVector.z);
|
||||
SbVec3f planeNormal = Base::convertTo<SbVec3f>(normalVector);
|
||||
|
||||
// Get the position and convert Base::Vector3d to SbVec3f
|
||||
Base::Vector3d pos = plc.getPosition();
|
||||
SbVec3f planePosition(pos.x, pos.y, pos.z);
|
||||
SbVec3f planePosition = Base::convertTo<SbVec3f>(pos);
|
||||
SbPlane xyPlane(planeNormal, planePosition);
|
||||
|
||||
SbVec3f pt;
|
||||
if (xyPlane.intersect(line, pt)) {
|
||||
return pt; // Intersection point on the XY plane
|
||||
}
|
||||
else {
|
||||
// No intersection found
|
||||
return {};
|
||||
}
|
||||
|
||||
return pt;
|
||||
throw Base::RuntimeError("No intersection found");
|
||||
}
|
||||
|
||||
SbVec3f projectPointOntoPlane(const SbVec3f& point, const SbPlane& plane) {
|
||||
|
||||
@@ -309,7 +309,7 @@ public:
|
||||
SbVec3f getPointOnLine(const SbVec2s&, const SbVec3f& axisCenter, const SbVec3f& axis) const;
|
||||
|
||||
/** Returns the 3d point on the XY plane of a placement to the given 2d point. */
|
||||
SbVec3f getPointOnXYPlaneOfPlacement(const SbVec2s&, Base::Placement&) const;
|
||||
SbVec3f getPointOnXYPlaneOfPlacement(const SbVec2s&, const Base::Placement&) const;
|
||||
|
||||
/** Returns the 2d coordinates on the viewport to the given 3d point. */
|
||||
SbVec2s getPointOnViewport(const SbVec3f&) const;
|
||||
|
||||
@@ -342,6 +342,17 @@ bool ViewProviderAssembly::keyPressed(bool pressed, int key)
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
try {
|
||||
return tryMouseMove(cursorPos, viewer);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Warning("%s\n", e.what());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ViewProviderAssembly::tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
if (!isInEditMode()) {
|
||||
return false;
|
||||
@@ -819,6 +830,16 @@ ViewProviderAssembly::DragMode ViewProviderAssembly::findDragMode()
|
||||
}
|
||||
|
||||
void ViewProviderAssembly::initMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
try {
|
||||
tryInitMove(cursorPos, viewer);
|
||||
}
|
||||
catch (const Base::Exception& e) {
|
||||
Base::Console().Warning("%s\n", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
void ViewProviderAssembly::tryInitMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer)
|
||||
{
|
||||
dragMode = findDragMode();
|
||||
if (dragMode == DragMode::None) {
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
/// is called when the Provider is in edit and a key event ocours. Only ESC ends edit.
|
||||
bool keyPressed(bool pressed, int key) override;
|
||||
/// is called when the provider is in edit and the mouse is moved
|
||||
bool mouseMove(const SbVec2s& pos, Gui::View3DInventorViewer* viewer) override;
|
||||
bool mouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer) override;
|
||||
/// is called when the Provider is in edit and the mouse is clicked
|
||||
bool mouseButtonPressed(int Button,
|
||||
bool pressed,
|
||||
@@ -226,6 +226,10 @@ public:
|
||||
SoSwitch* asmDraggerSwitch = nullptr;
|
||||
SoFieldSensor* translationSensor = nullptr;
|
||||
SoFieldSensor* rotationSensor = nullptr;
|
||||
|
||||
private:
|
||||
bool tryMouseMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer);
|
||||
void tryInitMove(const SbVec2s& cursorPos, Gui::View3DInventorViewer* viewer);
|
||||
};
|
||||
|
||||
} // namespace AssemblyGui
|
||||
|
||||
Reference in New Issue
Block a user