From: nds Date: Thu, 16 Nov 2017 12:56:46 +0000 (+0300) Subject: Issue #2293 Size of the view of a sketch is lost when pressing Set Plane View X-Git-Tag: V_2.10.0RC~158 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ac536f818ec04b3a89d770acca8cbb4788ec2646;p=modules%2Fshaper.git Issue #2293 Size of the view of a sketch is lost when pressing Set Plane View --- diff --git a/src/PartSet/PartSet_PreviewSketchPlane.cpp b/src/PartSet/PartSet_PreviewSketchPlane.cpp index 9ef700df7..f0f614bb0 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.cpp +++ b/src/PartSet/PartSet_PreviewSketchPlane.cpp @@ -41,7 +41,7 @@ #include PartSet_PreviewSketchPlane::PartSet_PreviewSketchPlane() - : myPreviewIsDisplayed(false) + : myPreviewIsDisplayed(false), mySizeOfView(0), myIsUseSizeOfView(false) { } @@ -88,8 +88,10 @@ void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& th theSketch->data()->attribute(SketchPlugin_Sketch::ORIGIN_ID())); std::shared_ptr aNormal = std::dynamic_pointer_cast( theSketch->data()->attribute(SketchPlugin_Sketch::NORM_ID())); - myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(), - Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size")); + + double aFaceSize = myIsUseSizeOfView ? mySizeOfView + : Config_PropManager::integer(SKETCH_TAB_NAME, "planes_size"); + myShape = GeomAlgoAPI_FaceBuilder::squareFace(anOrigin->pnt(), aNormal->dir(), aFaceSize); } myPlane = createPreviewPlane(); } @@ -99,6 +101,12 @@ void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& th myPreviewIsDisplayed = true; } +void PartSet_PreviewSketchPlane::setSizeOfView(double theSizeOfView, bool isUseSizeOfView) +{ + mySizeOfView = theSizeOfView; + myIsUseSizeOfView = isUseSizeOfView; +} + AISObjectPtr PartSet_PreviewSketchPlane::createPreviewPlane() { if (myPlane.get()) { diff --git a/src/PartSet/PartSet_PreviewSketchPlane.h b/src/PartSet/PartSet_PreviewSketchPlane.h index 11eabebd6..b797b2dd4 100644 --- a/src/PartSet/PartSet_PreviewSketchPlane.h +++ b/src/PartSet/PartSet_PreviewSketchPlane.h @@ -53,6 +53,15 @@ public: void createSketchPlane(const std::shared_ptr& theSketch, ModuleBase_IWorkshop* theWorkshop); + /// Returns whether custom size of view is set + /// \return boolean value + bool isUseSizeOfView() const { return myIsUseSizeOfView; } + + /// Sets the size of default created face + /// \param theSizeOfView value + /// \param isUseSizeOfView state whether the size should be used + void setSizeOfView(double theSizeOfView, bool isUseSizeOfView); + private: /// Create a square face by parameters std::shared_ptr createPreviewPlane(); @@ -61,6 +70,9 @@ private: bool myPreviewIsDisplayed; std::shared_ptr myPlane; //! visualized presentation std::shared_ptr myShape; //! current shape to be displayed + + double mySizeOfView; //! size that should be used by creating a default face + bool myIsUseSizeOfView; //! state if the size is custom or from preferences }; #endif \ No newline at end of file diff --git a/src/PartSet/PartSet_WidgetSketchCreator.cpp b/src/PartSet/PartSet_WidgetSketchCreator.cpp index a1bd76150..f31198234 100644 --- a/src/PartSet/PartSet_WidgetSketchCreator.cpp +++ b/src/PartSet/PartSet_WidgetSketchCreator.cpp @@ -195,6 +195,10 @@ bool PartSet_WidgetSketchCreator::isValidSelectionCustom(const ModuleBase_Viewer void PartSet_WidgetSketchCreator::activateSelectionControl() { + // reset previously set size of view needed on restart extrusion after Sketch + if (myModule->sketchMgr()->previewSketchPlane()->isUseSizeOfView()) + myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(0, false); + // we need to call activate here as the widget has no focus accepted controls // if these controls are added here, activate will happens automatically after focusIn() XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myModule->workshop()); @@ -359,20 +363,18 @@ bool PartSet_WidgetSketchCreator::startSketchOperation( // Set View size if a plane is selected if (myPreviewPlanes->isPreviewDisplayed() && myPreviewPlanes->isPreviewShape(aValue->shape())) { + // set default plane size + bool isSetSizeOfView = false; + double aSizeOfView = 0; QString aSizeOfViewStr = mySizeOfView->text(); if (!aSizeOfViewStr.isEmpty()) { - bool isOk; - double aSizeOfView = aSizeOfViewStr.toDouble(&isOk); - if (isOk && aSizeOfView > 0) { - Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); - if (!aView3d.IsNull()) { - Bnd_Box aBndBox; - double aHalfSize = aSizeOfView/2.0; - aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize); - aView3d->FitAll(aBndBox, 0.01, false); - } + aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView); + if (isSetSizeOfView && aSizeOfView <= 0) { + isSetSizeOfView = false; } } + if (isSetSizeOfView) + myModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true); } // manually deactivation because the widget was not activated as has no focus acceptin controls deactivate(); diff --git a/src/PartSet/PartSet_WidgetSketchLabel.cpp b/src/PartSet/PartSet_WidgetSketchLabel.cpp index d3908d81e..63cd3927e 100644 --- a/src/PartSet/PartSet_WidgetSketchLabel.cpp +++ b/src/PartSet/PartSet_WidgetSketchLabel.cpp @@ -278,7 +278,20 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); if (aModule) { CompositeFeaturePtr aSketch = std::dynamic_pointer_cast(myFeature); + bool isSetSizeOfView = false; + double aSizeOfView = 0; + QString aSizeOfViewStr = mySizeOfView->text(); + if (!aSizeOfViewStr.isEmpty()) { + aSizeOfView = aSizeOfViewStr.toDouble(&isSetSizeOfView); + if (isSetSizeOfView && aSizeOfView <= 0) { + isSetSizeOfView = false; + } + } + if (isSetSizeOfView) + aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, true); aModule->sketchMgr()->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop); + if (isSetSizeOfView) + aModule->sketchMgr()->previewSketchPlane()->setSizeOfView(aSizeOfView, false); } // 2. if the planes were displayed, change the view projection const GeomShapePtr& aShape = thePrs->shape(); @@ -334,20 +347,6 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs if (aRotate) { myWorkshop->viewer()->setViewProjection(aXYZ.X(), aXYZ.Y(), aXYZ.Z(), aTwist); } - QString aSizeOfViewStr = mySizeOfView->text(); - if (!aSizeOfViewStr.isEmpty()) { - bool isOk; - double aSizeOfView = aSizeOfViewStr.toDouble(&isOk); - if (isOk && aSizeOfView > 0) { - Handle(V3d_View) aView3d = myWorkshop->viewer()->activeView(); - if (!aView3d.IsNull()) { - Bnd_Box aBndBox; - double aHalfSize = aSizeOfView/2.0; - aBndBox.Update(-aHalfSize, -aHalfSize, -aHalfSize, aHalfSize, aHalfSize, aHalfSize); - aView3d->FitAll(aBndBox, 0.01, false); - } - } - } PartSet_Module* aModule = dynamic_cast(myWorkshop->module()); if (aModule) aModule->onViewTransformed();