From: mbs Date: Wed, 2 Oct 2024 08:39:57 +0000 (+0100) Subject: [bos #37689] EDF 28575 - vertical edges are recognised as horizontal X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=refs%2Ftlpr%2F72%2Fhead;p=modules%2Fshaper.git [bos #37689] EDF 28575 - vertical edges are recognised as horizontal There are different algorithms used to compute the orientation of a new sketch and the orientation of the view. Explicitly set up vector to the view orientation to match the sketch orientation. --- diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index c9c070176..83555284a 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -97,6 +97,16 @@ Q_OBJECT virtual void setViewProjection( double theX, double theY, double theZ, double theTwist ) = 0; + //! Sets the view projection and up direction + /// \param theX the X projection value + /// \param theY the Y projection value + /// \param theZ the Z projection value + /// \param theUpX the X value of the up direction vector + /// \param theUpY the Y value of the up direction vector + /// \param theUpZ the Z value of the up direction vector + virtual void setViewProjection( double theX, double theY, double theZ, + double theUpX, double theUpY, double theUpZ) = 0; + /// Add selection filter to the viewer /// \param theFilter a selection filter virtual void addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) = 0; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index fd71ff50b..3b088851f 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -307,8 +307,17 @@ std::shared_ptr PartSet_Tools::sketchPlane(CompositeFeaturePtr theS theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); if (aNormal.get() && aNormal->isInitialized() && - anOrigin.get() && anOrigin->isInitialized()) - aPlane = std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir())); + anOrigin.get() && anOrigin->isInitialized()) { + std::shared_ptr aDirX = std::dynamic_pointer_cast( + theSketch->data()->attribute(SketchPlugin_Sketch::DIRX_ID())); + if (aDirX.get() && aDirX->isInitialized()) { + std::shared_ptr anAxes = std::shared_ptr(new GeomAPI_Ax3(anOrigin->pnt(), aDirX->dir(), aNormal->dir())); + aPlane = std::shared_ptr(new GeomAPI_Pln(anAxes)); + } + else { + aPlane = std::shared_ptr(new GeomAPI_Pln(anOrigin->pnt(), aNormal->dir())); + } + } return aPlane; } diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index e1f71f19a..08c6d7f41 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -88,6 +88,30 @@ #define DBL_MAX 1.7976931348623158e+308 #endif + + +//============================================================================= +//function : setViewProjection +//purpose : Set the view projection with a specific plane orientation +//============================================================================= +static void setViewProjection(ModuleBase_IWorkshop* theWorkshop, const GeomPlanePtr thePlane, bool theReversed) +{ + GeomDirPtr aDirection = thePlane->direction(); + GeomDirPtr aXDirection = thePlane->xDirection(); + gp_Dir aNormDir = aDirection->impl(); + gp_Dir aXDirPln = aXDirection->impl(); + if (theReversed) { + aNormDir.Reverse(); + aXDirPln.Reverse(); + } + + gp_Dir aYDirPln = aNormDir.Crossed(aXDirPln); + + // Set the view projection and up direction + theWorkshop->viewer()->setViewProjection(aNormDir.X(), aNormDir.Y(), aNormDir.Z(), aYDirPln.X(), aYDirPln.Y(), aYDirPln.Z()); +} + + PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent, ModuleBase_IWorkshop* theWorkshop, const Config_WidgetAPI* theData, @@ -383,15 +407,12 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs } // 2. if the planes were displayed, change the view projection - std::shared_ptr aDir = aPlane->direction(); - gp_XYZ aXYZ = aDir->impl().XYZ(); - double aTwist = 0.0; - // Rotate view if the sketcher plane is selected only from preview planes // Preview planes are created only if there is no any shape bool aRotate = Config_PropManager::boolean(SKETCH_TAB_NAME, "rotate_to_plane"); if (aRotate) { - myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist); + bool aReversed = myViewInverted->isChecked(); + setViewProjection(myWorkshop, aPlane, aReversed); } if (isSetSizeOfView && aSizeOfView > 0) { Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); @@ -739,11 +760,9 @@ void PartSet_WidgetSketchLabel::onSetPlaneView() { std::shared_ptr aPlane = plane(); if (aPlane.get()) { - std::shared_ptr aDirection = aPlane->direction(); - gp_Dir aDir = aDirection->impl(); - if (myViewInverted->isChecked()) - aDir.Reverse(); - myWorkshop->viewer()->setViewProjection(aDir.X(), aDir.Y(), aDir.Z(), 0.); + bool aReversed = myViewInverted->isChecked(); + setViewProjection(myWorkshop, aPlane, aReversed); + PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); if (aModule) aModule->onViewTransformed(); diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp index d14bfcbcb..3b282ad97 100644 --- a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.cpp @@ -430,6 +430,26 @@ void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY, } } +//********************************************** +void SHAPERGUI_SalomeViewer::setViewProjection(double theX, double theY, double theZ, double theUpX, double theUpY, double theUpZ) +{ + if (!mySelector) + return; + + SUIT_ViewManager* aMgr = mySelector->viewer()->getViewManager(); + OCCViewer_ViewFrame* aVFrame = dynamic_cast(aMgr->getActiveView()); + if (aVFrame) { + Handle(V3d_View) aView3d = aVFrame->getViewPort()->getView(); + if (!aView3d.IsNull()) { + aView3d->SetProj(theX, theY, theZ); + aView3d->SetUp (theUpX, theUpY, theUpZ); + aView3d->FitAll(0.01, false); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); + } + } +} + //*************************************** void SHAPERGUI_SalomeViewer::addSelectionFilter(const Handle(SelectMgr_Filter)& theFilter) { diff --git a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h index 3657b0474..60f9d3822 100644 --- a/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h +++ b/src/SHAPERGUI/SHAPERGUI_SalomeViewer.h @@ -135,6 +135,16 @@ Q_OBJECT virtual void setViewProjection( double theX, double theY, double theZ, double theTwist ); + //! Sets the view projection and up direction + /// \param theX the X projection value + /// \param theY the Y projection value + /// \param theZ the Z projection value + /// \param theUpX the X value of the up direction vector + /// \param theUpY the Y value of the up direction vector + /// \param theUpZ the Z value of the up direction vector + virtual void setViewProjection( double theX, double theY, double theZ, + double theUpX, double theUpY, double theUpZ); + /// Set selector /// \param theSel a selector instance void setSelector(SHAPERGUI_OCCSelector* theSel); diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index cc73e969d..7cbd62111 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -128,6 +128,18 @@ void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, } } +void XGUI_ViewerProxy::setViewProjection(double theX, double theY, double theZ, double theUpX, double theUpY, double theUpZ) +{ + Handle(V3d_View) aView3d = activeView(); + if (!aView3d.IsNull()) { + aView3d->SetProj(theX, theY, theZ); + aView3d->SetUp (theUpX, theUpY, theUpZ); + aView3d->FitAll(0.01, false); + if (aView3d->Depth() < 0.1) + aView3d->DepthFitAll(); + } +} + void XGUI_ViewerProxy::fitAll() { #ifdef HAVE_SALOME diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index d4b029cba..d8965af30 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -93,6 +93,16 @@ Q_OBJECT virtual void setViewProjection( double theX, double theY, double theZ, double theTwist ); + //! Sets the view projection and up direction + /// \param theX the X projection value + /// \param theY the Y projection value + /// \param theZ the Z projection value + /// \param theUpX the X value of the up direction vector + /// \param theUpY the Y value of the up direction vector + /// \param theUpZ the Z value of the up direction vector + virtual void setViewProjection( double theX, double theY, double theZ, + double theUpX, double theUpY, double theUpZ); + //! Sets the view fitted all virtual void fitAll();