From: vsv Date: Mon, 9 Sep 2019 15:26:56 +0000 (+0300) Subject: Implementation of Fitter X-Git-Tag: V9_4_0a2~4^2~81^2~16 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e983f3f4fd2886547669584821c4c9abfa30b573;p=modules%2Fshaper.git Implementation of Fitter --- diff --git a/src/ModuleBase/ModuleBase_IViewer.h b/src/ModuleBase/ModuleBase_IViewer.h index c52c0d952..825879490 100644 --- a/src/ModuleBase/ModuleBase_IViewer.h +++ b/src/ModuleBase/ModuleBase_IViewer.h @@ -21,6 +21,7 @@ #define ModuleBase_IViewer_H #include "ModuleBase.h" + #include #include #include diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 1c4c03e07..1576ff0b1 100644 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -1099,10 +1099,20 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch); workshop()->viewer()->set2dMode(true); + + PartSet_Fitter* aFitter = new PartSet_Fitter(myCurrentSketch); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + aWorkshop->viewer()->setFitter(aFitter); } void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) { + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); + XGUI_Workshop* aWorkshop = aConnector->workshop(); + PartSet_Fitter* aFitter = (PartSet_Fitter*)aWorkshop->viewer()->currentFitter(); + aWorkshop->viewer()->unsetFitter(); + delete aFitter; + myIsMouseOverWindow = false; myIsConstraintsShown[PartSet_Tools::Geometrical] = true; myIsConstraintsShown[PartSet_Tools::Dimensional] = true; @@ -1114,8 +1124,6 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) } onShowPoints(false); - XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); - DataPtr aData = myCurrentSketch->data(); if (!aData->isValid()) { XGUI_Displayer* aDisplayer = aConnector->workshop()->displayer(); @@ -2100,3 +2108,28 @@ void PartSet_SketcherMgr::onShowPoints(bool toShow) if (aToUpdate) aViewer->update(); } + + +void PartSet_Fitter::fitScene(Handle(V3d_View) theView) +{ + Bnd_Box aBndBox; + int aNumberOfSubs = mySketch->numberOfSubs(); + for (int i = 0; i < aNumberOfSubs; i++) { + FeaturePtr aFeature = mySketch->subFeature(i); + std::list aResults = aFeature->results(); + std::list::const_iterator aIt; + ResultPtr aRes; + double aXmin, aYmin, aZmin, aXmax, aYmax, aZmax; + for (aIt = aResults.begin(); aIt != aResults.end(); ++aIt) { + aRes = (*aIt); + if (aRes->isDisplayed()) { + GeomShapePtr aShape = aRes->shape(); + aShape->computeSize(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + Bnd_Box aBox; + aBox.Update(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax); + aBndBox.Add(aBox); + } + } + } + theView->FitAll(aBndBox, 0.01); +} diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index 6dfe03cc2..4920caa39 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -36,6 +36,13 @@ #include +#ifdef HAVE_SALOME + #include +#else + #include +#endif + + #include #include @@ -55,12 +62,34 @@ class ModuleBase_ModelWidget; class ModuleBase_Operation; class XGUI_OperationMgr; class XGUI_Workshop; +class XGUI_Displayer; class PartSet_ExternalPointsMgr; class AIS_InteractiveObject; class QMouseEvent; + +#ifdef HAVE_SALOME +class PartSet_Fitter : public OCCViewer_Fitter +#else +class PartSet_Fitter : public AppElements_Fitter +#endif +{ +public: + PartSet_Fitter(CompositeFeaturePtr theCurrentSketch): + mySketch(theCurrentSketch) {} + + /// A method which has top be reimplemented to provide alterantive implementation FitAll command + /// \param theView - a view which has to be fit + virtual void fitScene(Handle(V3d_View) theView); + +private: + CompositeFeaturePtr mySketch; +}; + + + /** * \ingroup Modules * A class for management of sketch operations diff --git a/src/XGUI/XGUI_ViewerProxy.cpp b/src/XGUI/XGUI_ViewerProxy.cpp index 0523975ff..16fe9ee86 100644 --- a/src/XGUI/XGUI_ViewerProxy.cpp +++ b/src/XGUI/XGUI_ViewerProxy.cpp @@ -723,4 +723,36 @@ void XGUI_ViewerProxy::setupColorScale() // aView3d->DepthFitAll(); // } //#endif -//} \ No newline at end of file +//} + + +#ifdef HAVE_SALOME +void XGUI_ViewerProxy::setFitter(OCCViewer_Fitter* theFitter) +{ + myWorkshop->salomeConnector()->viewer()->setFitter(theFitter); +} + +OCCViewer_Fitter* XGUI_ViewerProxy::currentFitter() const +{ + return myWorkshop->salomeConnector()->viewer()->currentFitter(); +} +#else +void XGUI_ViewerProxy::setFitter(AppElements_Fitter* theFitter) +{ + myWorkshop->mainWindow()->viewer()->setFitter(theFitter); +} + +AppElements_Fitter* XGUI_ViewerProxy::currentFitter() const +{ + return myWorkshop->mainWindow()->viewer()->currentFitter(); +} +#endif + +void XGUI_ViewerProxy::unsetFitter() +{ +#ifdef HAVE_SALOME + myWorkshop->salomeConnector()->viewer()->unsetFitter(); +#else + myWorkshop->mainWindow()->viewer()->unsetFitter(); +#endif +} diff --git a/src/XGUI/XGUI_ViewerProxy.h b/src/XGUI/XGUI_ViewerProxy.h index bb3a445d5..d87e4fcfa 100644 --- a/src/XGUI/XGUI_ViewerProxy.h +++ b/src/XGUI/XGUI_ViewerProxy.h @@ -28,10 +28,15 @@ #include #include -#ifndef HAVE_SALOME +#ifdef HAVE_SALOME +#include +#else + #include #include #endif + + class XGUI_Workshop; /** * \ingroup GUI @@ -164,6 +169,16 @@ Q_OBJECT // Fit all along Z (perpendicular to display) //virtual void Zfitall(); +#ifdef HAVE_SALOME + void setFitter(OCCViewer_Fitter* theFitter); + OCCViewer_Fitter* currentFitter() const; +#else + void setFitter(AppElements_Fitter* theFitter); + AppElements_Fitter* currentFitter() const; +#endif + + void unsetFitter(); + signals: /// Emits by mouse entering the view port void enterViewPort();