Salome HOME
Issue #2923: Change sketch plane
authorvsv <vsv@opencascade.com>
Thu, 30 May 2019 07:30:20 +0000 (10:30 +0300)
committervsv <vsv@opencascade.com>
Thu, 30 May 2019 07:30:20 +0000 (10:30 +0300)
src/ModuleBase/ModuleBase_ModelWidget.h
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_PreviewSketchPlane.cpp
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h
src/XGUI/XGUI_ActiveControlMgr.cpp
src/XGUI/XGUI_ActiveControlSelector.h
src/XGUI/XGUI_PropertyPanelSelector.cpp
src/XGUI/XGUI_PropertyPanelSelector.h

index 0e6514374c929724c59082a40929f8efe00805a1..8ba7db2cb64271bbc2208ac80f75dffda7462847 100644 (file)
@@ -205,7 +205,7 @@ Q_OBJECT
   virtual void updateAfterActivation() {}
 
   /// The method called if widget should be activated always
-  virtual bool needToBeActiated() { return false; }
+  virtual bool needToBeActivated() { return false; }
 
   /// Returns list of widget controls
   /// \return a control list
index 65be58122bb5aa6a040b67e4a13778e52f043bed..ee3f43ae50c933d242095eebaf1eb575b7e2eeae 100644 (file)
@@ -177,6 +177,7 @@ PartSet_Module::PartSet_Module(ModuleBase_IWorkshop* theWshop)
 
   Events_Loop* aLoop = Events_Loop::loop();
   aLoop->registerListener(this, Events_Loop::eventByName(EVENT_DOCUMENT_CHANGED));
+  aLoop->registerListener(this, Events_Loop::eventByName(EVENT_OBJECT_TO_REDISPLAY));
 
   registerSelectionFilter(SF_GlobalFilter, new PartSet_GlobalFilter(myWorkshop));
   registerSelectionFilter(SF_FilterInfinite, new PartSet_FilterInfinite(myWorkshop));
@@ -1512,6 +1513,12 @@ void PartSet_Module::processEvent(const std::shared_ptr<Events_Message>& theMess
       }
     }
   }
+  else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_TO_REDISPLAY)) {
+    CompositeFeaturePtr aSketch = mySketchMgr->activeSketch();
+    if (aSketch.get()) {
+      mySketchMgr->previewSketchPlane()->createSketchPlane(aSketch, myWorkshop);
+    }
+  }
 }
 
 //******************************************************
index f8790b45a3736f0e8f2213a404ba32c0f86e3e0d..55db2ece6d0e16e97db624514738b40f4f28c096 100644 (file)
@@ -64,45 +64,43 @@ void PartSet_PreviewSketchPlane::eraseSketchPlane(ModuleBase_IWorkshop* theWorks
 void PartSet_PreviewSketchPlane::createSketchPlane(const CompositeFeaturePtr& theSketch,
                                                    ModuleBase_IWorkshop* theWorkshop)
 {
-  // the preview plane has been already created and displayed
-  if (myPreviewIsDisplayed)
-    return;
-
   // plane is visualized only if sketch plane is filled
   if (!PartSet_Tools::sketchPlane(theSketch).get())
     return;
 
-  if (!myPlane) { // If planes are not created
-    // Create Preview
-    // selected linear face parameters
-    AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-      (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-    if (aSelAttr) {
-      myShape = aSelAttr->value();
-      // this case is needed by constructing sketch on a plane, where result shape is equal
-      // to context result, therefore value() returns NULL and we should use shape of context.
-      if (!myShape.get() && aSelAttr->context().get())
-        myShape = aSelAttr->context()->shape();
-    }
-    if (!myShape.get()) {
-      // Create Preview for default planes
-      std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
-          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()));
-
-      double aFaceSize = myIsUseSizeOfView ? mySizeOfView
-        : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size");
-      if (aFaceSize <= Precision::Confusion())
-        aFaceSize = 200;   // Set default value
-
-      myShape = GeomAlgoAPI_FaceBuilder::squareFace(
-        myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize);
-    }
-    myPlane = createPreviewPlane();
+  XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
+  if (myPreviewIsDisplayed) {
+    aDisp->eraseAIS(myPlane, false);
   }
 
-  XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
+  // Create Preview
+  // selected linear face parameters
+  AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+    (theSketch->data()->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+  if (aSelAttr) {
+    myShape = aSelAttr->value();
+    // this case is needed by constructing sketch on a plane, where result shape is equal
+    // to context result, therefore value() returns NULL and we should use shape of context.
+    if (!myShape.get() && aSelAttr->context().get())
+      myShape = aSelAttr->context()->shape();
+  }
+  if (!myShape.get()) {
+    // Create Preview for default planes
+    std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+        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()));
+
+    double aFaceSize = myIsUseSizeOfView ? mySizeOfView
+      : Config_PropManager::real(SKETCH_TAB_NAME, "planes_size");
+    if (aFaceSize <= Precision::Confusion())
+      aFaceSize = 200;   // Set default value
+
+    myShape = GeomAlgoAPI_FaceBuilder::squareFace(
+      myViewCentralPoint.get() ? myViewCentralPoint : anOrigin->pnt(), aNormal->dir(), aFaceSize);
+  }
+  myPlane = createPreviewPlane();
+
   aDisp->displayAIS(myPlane, false/*load object in selection*/, 1/*shaded*/, false);
   myPreviewIsDisplayed = true;
 }
index 5779d33bb9113104757939211571e46636bbfdc7..3ef5b735f9fd6124b25fce78ca250a7aff826e6d 100644 (file)
@@ -311,6 +311,17 @@ std::shared_ptr<GeomAPI_Pln> PartSet_Tools::sketchPlane(CompositeFeaturePtr theS
   return aPlane;
 }
 
+void PartSet_Tools::nullifySketchPlane(CompositeFeaturePtr theSketch)
+{
+  std::shared_ptr<GeomDataAPI_Point> anOrigin = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+    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()));
+
+  aNormal->reset();
+  anOrigin->reset();
+}
+
 std::shared_ptr<GeomAPI_Pnt> PartSet_Tools::point3D(std::shared_ptr<GeomAPI_Pnt2d> thePoint2D,
                                                       CompositeFeaturePtr theSketch)
 {
index 0bd4159c45290407fa968856cb5a8eaecc808c4b..0de36c1e24af8ca322a21f3a310043065f64f8ca 100644 (file)
@@ -143,6 +143,11 @@ public:
   /// \return API object of geom plane
   static std::shared_ptr<GeomAPI_Pln> sketchPlane(CompositeFeaturePtr theSketch);
 
+  /// Create a sketch plane instance
+  /// \param theSketch a sketch feature
+  /// \return API object of geom plane
+  static void nullifySketchPlane(CompositeFeaturePtr theSketch);
+
   /// Create a point 3D on a basis of point 2D and sketch feature
   /// \param thePoint2D a point on a sketch
   /// \param theSketch a sketch feature
index 7f4fcd8ae40db8fe0092621b4d602aeb30a95a3a..f8e8d39245c5747559aedd97d7981abad1187d92 100644 (file)
@@ -41,6 +41,7 @@
 #include <ModuleBase_ViewerPrs.h>
 #include <ModuleBase_Tools.h>
 #include <ModuleBase_IModule.h>
+#include <ModuleBase_IPropertyPanel.h>
 
 #include <GeomAlgoAPI_FaceBuilder.h>
 #include <GeomAlgoAPI_ShapeTools.h>
@@ -84,7 +85,7 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
                         ModuleBase_IWorkshop* theWorkshop,
                         const Config_WidgetAPI* theData,
                         const QMap<PartSet_Tools::ConstraintVisibleState, bool>& toShowConstraints)
-: ModuleBase_WidgetValidated(theParent, theWorkshop, theData)
+: ModuleBase_WidgetValidated(theParent, theWorkshop, theData), myOpenTransaction(false)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
@@ -160,6 +161,11 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
       aShowConstraints->setChecked(toShowConstraints[aState]);
   }
 
+
+  QPushButton* aPlaneBtn = new QPushButton(tr("Change sketch plane"), aSecondWgt);
+  connect(aPlaneBtn, SIGNAL(clicked(bool)), SLOT(onChangePlane()));
+  aLayout->addWidget(aPlaneBtn);
+
   myStackWidget->addWidget(aSecondWgt);
   //setLayout(aLayout);
 
@@ -331,6 +337,11 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   if (aModule)
     aModule->onViewTransformed();
 
+  if (myOpenTransaction) {
+    SessionPtr aMgr = ModelAPI_Session::get();
+    aMgr->finishOperation();
+    myOpenTransaction = false;
+  }
   // 3. Clear text in the label
   myStackWidget->setCurrentIndex(1);
   //myLabel->setText("");
@@ -643,3 +654,30 @@ QList<std::shared_ptr<ModuleBase_ViewerPrs>> PartSet_WidgetSketchLabel::findCirc
   }
   return aResult;
 }
+
+//******************************************************
+void PartSet_WidgetSketchLabel::onChangePlane()
+{
+  PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+  if (aModule) {
+    mySizeOfViewWidget->setVisible(false);
+    myStackWidget->setCurrentIndex(0);
+
+    CompositeFeaturePtr aSketch = std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(myFeature);
+    PartSet_Tools::nullifySketchPlane(aSketch);
+
+    Handle(SelectMgr_Filter) aFilter = aModule->selectionFilter(SF_SketchPlaneFilter);
+    if (!aFilter.IsNull()) {
+      std::shared_ptr<GeomAPI_Pln> aPln;
+      Handle(ModuleBase_ShapeInPlaneFilter)::DownCast(aFilter)->setPlane(aPln);
+    }
+    XGUI_Workshop* aWorkshop = aModule->getWorkshop();
+
+    aWorkshop->selectionActivate()->updateSelectionFilters();
+    aWorkshop->selectionActivate()->updateSelectionModes();
+
+    SessionPtr aMgr = ModelAPI_Session::get();
+    aMgr->startOperation();
+    myOpenTransaction = true;
+  }
+}
\ No newline at end of file
index 3bfcf883cd6a1142d4c95be9e656cd98216883d3..6f7b1a8d05f4e56acf63627e46a0c556f10f13d0 100644 (file)
@@ -91,7 +91,7 @@ public:
   virtual void deactivate();
 
   /// The method called if widget should be activated always
-  virtual bool needToBeActiated() { return true; }
+  virtual bool needToBeActivated() { return true; }
 
   /// Returns sketcher plane
   std::shared_ptr<GeomAPI_Pln> plane() const;
@@ -192,6 +192,8 @@ private slots:
   /// \param theOn a flag show constraints or not
   void onShowConstraint(bool theOn);
 
+  void onChangePlane();
+
 private:
   /// Set sketch plane by shape
   /// \param theShape a planar face
@@ -219,6 +221,8 @@ private:
   QWidget* mySizeOfViewWidget; ///< Size of view widget, visualized if preview planes are shown
   QLineEdit* mySizeOfView; ///< Value of square of size of View
   QStackedWidget* myStackWidget;
+
+  bool myOpenTransaction;
 };
 
 #endif
index beffebcee689835db9609a7215e0cb397c42a781..775985d76c44bef1dbbea65d8de1b7d18778feb0 100644 (file)
@@ -106,7 +106,7 @@ void XGUI_ActiveControlMgr::onSelectorDeactivated()
   XGUI_ActiveControlSelector* aSelectorToBeActivated = 0;
   for (int i = 0, aCount = mySelectors.count(); i < aCount; i++)
   {
-    if (!mySelectors[i]->needToBeActiated())
+    if (!mySelectors[i]->needToBeActivated())
       continue;
     aSelectorToBeActivated = mySelectors[i];
     break;
index eb45000843cabc9a0dc932926b66670c1c6901f5..f39abd8cf561791417c2471f48d74c0d411492db 100644 (file)
@@ -59,7 +59,7 @@ public:
 
   /// Returns whether the selector should be activated as soon as possible (by deactivatate other)
   /// \return boolean result
-  XGUI_EXPORT virtual bool needToBeActiated() const { return false; }
+  XGUI_EXPORT virtual bool needToBeActivated() const { return false; }
 
   /// Processes current selection of workshop. Reaction to selection change in workshop.
   XGUI_EXPORT virtual void processSelection() = 0;
index 8e797ebc58d7d2cbe0c0056f27528d5491fccc40..c206ab95a2c7143c7c086e93b5d3ddc3f8c59f14 100644 (file)
@@ -46,7 +46,7 @@ void XGUI_PropertyPanelSelector::setActive(const bool& isActive)
 
   if (!isActive) { // on deactivating, store previous active widget
     ModuleBase_ModelWidget* aWidget = myPanel->activeWidget();
-    if (aWidget && aWidget->needToBeActiated())
+    if (aWidget && aWidget->needToBeActivated())
     {
       myWidgetToBeActivated = aWidget;
     }
@@ -55,7 +55,7 @@ void XGUI_PropertyPanelSelector::setActive(const bool& isActive)
 }
 
 //********************************************************************
-bool XGUI_PropertyPanelSelector::needToBeActiated() const
+bool XGUI_PropertyPanelSelector::needToBeActivated() const
 {
   return myWidgetToBeActivated != NULL;
 }
index 2341f0913ddbd62f8ee377d898b40902d7029bf4..522562750e1c38dab0d54cc5ef5d04b20c5d0dd5 100644 (file)
@@ -56,7 +56,7 @@ public:
 
   /// Returns whether the selector should be activated as soon as possible (by deactivatate other)
   /// \return boolean result
-  XGUI_EXPORT virtual bool needToBeActiated() const;
+  XGUI_EXPORT virtual bool needToBeActivated() const;
 
   /// Processes current selection of workshop. Reaction to selection change in workshop.
   XGUI_EXPORT virtual void processSelection();