]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2293 Size of the view of a sketch is lost when pressing Set Plane View
authornds <nds@opencascade.com>
Thu, 16 Nov 2017 12:56:46 +0000 (15:56 +0300)
committernds <nds@opencascade.com>
Thu, 16 Nov 2017 12:56:46 +0000 (15:56 +0300)
src/PartSet/PartSet_PreviewSketchPlane.cpp
src/PartSet/PartSet_PreviewSketchPlane.h
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchLabel.cpp

index 9ef700df78402ee29741f49ff94674badc62528f..f0f614bb0f4ec9d7dccc2037b878fa7b1f784433 100644 (file)
@@ -41,7 +41,7 @@
 #include <SketchPlugin_SketchEntity.h>
 
 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<GeomDataAPI_Dir> aNormal = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
           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()) {
index 11eabebd69e25b4f1cc49d5615e386120a56ad4e..b797b2dd4fbc04c13c2460aa40c8e80f31105c71 100644 (file)
@@ -53,6 +53,15 @@ public:
   void createSketchPlane(const std::shared_ptr<ModelAPI_CompositeFeature>& 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<GeomAPI_AISObject> createPreviewPlane();
@@ -61,6 +70,9 @@ private:
   bool myPreviewIsDisplayed;
   std::shared_ptr<GeomAPI_AISObject> myPlane; //! visualized presentation
   std::shared_ptr<GeomAPI_Shape> 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
index a1bd76150cb8264ed0ab1597a6a0ef2aef8833f0..f31198234f3d9be6d5d423019c3021f3522d811f 100644 (file)
@@ -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();
index d3908d81e0e350937d88b90f512c7156dd2fe35d..63cd3927ee2a66112b1837dd45677cc43786346a 100644 (file)
@@ -278,7 +278,20 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
   if (aModule) {
     CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(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<PartSet_Module*>(myWorkshop->module());
     if (aModule)
       aModule->onViewTransformed();