]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1343 Improvement of Extrusion and Revolution operations: preview planes visual...
authornds <nds@opencascade.com>
Tue, 22 Mar 2016 13:18:17 +0000 (16:18 +0300)
committerdbv <dbv@opencascade.com>
Wed, 6 Apr 2016 10:22:06 +0000 (13:22 +0300)
12 files changed:
src/Config/Config_Keywords.h
src/FeaturesPlugin/extrusion_widget.xml
src/FeaturesPlugin/extrusionsketch_widget.xml
src/FeaturesPlugin/revolutionsketch_widget.xml
src/PartSet/CMakeLists.txt
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_PreviewPlanes.cpp [new file with mode: 0755]
src/PartSet/PartSet_PreviewPlanes.h [new file with mode: 0755]
src/PartSet/PartSet_WidgetSketchCreator.cpp
src/PartSet/PartSet_WidgetSketchCreator.h
src/PartSet/PartSet_WidgetSketchLabel.cpp
src/PartSet/PartSet_WidgetSketchLabel.h

index da2a16f6b257d70f9642ea1630f75022c1d88e49..a59fc84730addc42ab107d55b87adff302868f9a 100644 (file)
@@ -116,9 +116,4 @@ const static char* NODE_ICON = "icon";
 const static char* SHOW_EMPTY = "show_empty";
 const static char* LINK_ITEM = "from_result";
 
-/*
- * Hardcoded xml entities for composite features
- */
-const static char* USE_BODY = "use_body";
-
 #endif /* CONFIG_KEYWORDS_H_ */
index 6f0faf6104e04b91309f3cdb869f543a6fb7218a..1cf80deb2e69c74f74affc28e89727802476df30 100644 (file)
@@ -7,7 +7,6 @@
 2. An existing sketch face or contour. Extrusion will be filled with them. 3.A shape on existing result: wires/edge/vertices.
 Extrusion will be filled with them"
     icon=":icons/sketch.png"
-    use_body="false"
     tooltip="Create or edit a sketch"
     shape_types="face objects">
   </sketch_launcher>
index a5c74f6d01ca3c31260ca0a9e0f5c9d039715058..7394fd863f9d13c52f0add8ddc0234037df40ccc 100644 (file)
@@ -5,7 +5,6 @@
     <sketch_launcher id="sketch"
       label="Sketch"
       icon=":icons/sketch.png"
-      use_body="false"
       tooltip="Create or edit a sketch">
     </sketch_launcher>
     <toolbox id="CreationMethod">
index 36d836a985ff799dcedf31b80a05e5aa6c67b8ba..1af1dae902fadef04de924570cc414ef0c7cb457 100644 (file)
@@ -5,7 +5,6 @@
     <sketch_launcher id="sketch"
       label="Sketch"
       icon=":icons/sketch.png"
-      use_body="false"
       tooltip="Create or edit a sketch">
     </sketch_launcher>
     <toolbox id="CreationMethod">
index 17b1fdedc478608acca1e76a9d838be3299d3253..86da38c63a53adaa33137cdc7fbce76eca6bfe6f 100644 (file)
@@ -12,6 +12,7 @@ SET(PROJECT_HEADERS
        PartSet_Module.h
        PartSet_OperationPrs.h
         PartSet_OverconstraintListener.h
+        PartSet_PreviewPlanes.h
        PartSet_Tools.h
        PartSet_WidgetSketchLabel.h
        PartSet_Validators.h
@@ -39,6 +40,7 @@ SET(PROJECT_SOURCES
        PartSet_Module.cpp
        PartSet_OperationPrs.cpp
         PartSet_OverconstraintListener.cpp
+        PartSet_PreviewPlanes.cpp
        PartSet_Tools.cpp
        PartSet_WidgetSketchLabel.cpp
        PartSet_Validators.cpp
index 8a43baadc556e7762f36365f66a7c29d2f9b4f82..48e605f5540c63294a3fbde59b0f7db6311f25b5 100755 (executable)
@@ -4,6 +4,7 @@
 #include "PartSet_WidgetSketchLabel.h"
 #include "PartSet_Validators.h"
 #include "PartSet_Tools.h"
+#include "PartSet_PreviewPlanes.h"
 #include "PartSet_WidgetPoint2d.h"
 #include "PartSet_WidgetPoint2dDistance.h"
 #include "PartSet_WidgetPoint2DFlyout.h"
diff --git a/src/PartSet/PartSet_PreviewPlanes.cpp b/src/PartSet/PartSet_PreviewPlanes.cpp
new file mode 100755 (executable)
index 0000000..f773533
--- /dev/null
@@ -0,0 +1,102 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_PreviewPlanes.cpp
+// Created:     19 Jun 2015
+// Author:      Natalia ERMOLAEVA
+
+#include "PartSet_PreviewPlanes.h"
+
+#include <ModuleBase_IWorkshop.h>
+
+#include <ModelAPI_ResultBody.h>
+
+#include <XGUI_Tools.h>
+#include <XGUI_Displayer.h>
+#include <XGUI_Workshop.h>
+
+#include <Config_PropManager.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
+
+#include <SketchPlugin_Sketch.h>
+
+PartSet_PreviewPlanes::PartSet_PreviewPlanes()
+ : myPreviewDisplayed(false)
+{
+}
+
+bool PartSet_PreviewPlanes::hasVisualizedBodies(ModuleBase_IWorkshop* theWorkshop)
+{
+  bool aBodyIsVisualized = false;
+
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(theWorkshop);
+  XGUI_Displayer* aDisp = aWorkshop->displayer();
+  QObjectPtrList aDisplayed = aDisp->displayedObjects();
+  foreach (ObjectPtr anObj, aDisplayed) {
+    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
+    if (aResult.get() != NULL) {
+      aBodyIsVisualized = aResult->groupName() == ModelAPI_ResultBody::group();
+      if (aBodyIsVisualized)
+        break;
+    }
+  }
+  return aBodyIsVisualized;
+}
+
+void PartSet_PreviewPlanes::erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
+{
+  if (myPreviewDisplayed) {
+    XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
+    aDisp->eraseAIS(myYZPlane, false);
+    aDisp->eraseAIS(myXZPlane, false);
+    aDisp->eraseAIS(myXYPlane, false);
+    myPreviewDisplayed = false;
+  }
+}
+
+void PartSet_PreviewPlanes::showPreviewPlanes(ModuleBase_IWorkshop* theWorkshop)
+{
+  if (myPreviewDisplayed)
+    return;
+
+  if (!myYZPlane) { // If planes are not created
+    // Create Preview
+    std::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
+    std::shared_ptr<GeomAPI_Dir> aYZDir(new GeomAPI_Dir(1, 0, 0));
+    // -1, not 1 for correct internal sketch coords (issue 898)
+    std::shared_ptr<GeomAPI_Dir> aXZDir(new GeomAPI_Dir(0, -1, 0));
+    std::shared_ptr<GeomAPI_Dir> aXYDir(new GeomAPI_Dir(0, 0, 1));
+
+    std::vector<int> aYZRGB, aXZRGB, aXYRGB;
+    aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color",
+                                                        YZ_PLANE_COLOR);
+    aXZRGB = Config_PropManager::color("Visualization", "xz_plane_color",
+                                                        XZ_PLANE_COLOR);
+    aXYRGB = Config_PropManager::color("Visualization", "xy_plane_color",
+                                                        XY_PLANE_COLOR);
+    int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]};
+    int aG[] = {aXZRGB[0], aXZRGB[1], aXZRGB[2]};
+    int aB[] = {aXYRGB[0], aXYRGB[1], aXYRGB[2]};
+
+    myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR);
+    myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
+    myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
+  }
+  XGUI_Displayer* aDisp = XGUI_Tools::workshop(theWorkshop)->displayer();
+  aDisp->displayAIS(myYZPlane, true, false);
+  aDisp->displayAIS(myXZPlane, true, false);
+  aDisp->displayAIS(myXYPlane, true, false);
+  myPreviewDisplayed = true;
+}
+
+AISObjectPtr PartSet_PreviewPlanes::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
+                                                       std::shared_ptr<GeomAPI_Dir> theNorm, 
+                                                       const int theRGB[3])
+{
+  double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
+  std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
+  AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
+  aAIS->createShape(aFace);
+  aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
+  aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]);
+  return aAIS;
+}
diff --git a/src/PartSet/PartSet_PreviewPlanes.h b/src/PartSet/PartSet_PreviewPlanes.h
new file mode 100755 (executable)
index 0000000..d64f10f
--- /dev/null
@@ -0,0 +1,71 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        PartSet_PreviewPlanes.h
+// Created:     22 Mar 2016
+// Author:      Natalia ERMOLAEVA
+
+#ifndef PartSet_PreviewPlanes_H
+#define PartSet_PreviewPlanes_H
+
+#include <GeomAPI_AISObject.h>
+
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_AISObject.h>
+
+class ModuleBase_IWorkshop;
+
+/// the plane edge width
+#define SKETCH_WIDTH        "4"
+/// face of the square-face displayed for selection of general plane
+#define PLANE_SIZE          "200"
+
+/**
+* \class PartSet_PreviewPlanes
+* \ingroup Modules
+* A class to show/hide sketch preview planes
+*/
+class PartSet_PreviewPlanes
+{
+public:
+  /// Constructor
+  PartSet_PreviewPlanes();
+
+  ~PartSet_PreviewPlanes() {};
+
+  /// Returns true if there is body visualized in the viewer
+  /// \param theWorkshop the application workshop
+  /// \return boolean value
+  static bool hasVisualizedBodies(ModuleBase_IWorkshop* theWorkshop);
+
+  /// Returns if the preview was displayed
+  /// \param theWorkshop the application workshop
+  /// \return boolean value
+  bool isPreviewDisplayed() const { return myPreviewDisplayed; }
+
+  /// Erase preview planes
+  /// \param theWorkshop the application workshop
+  void erasePreviewPlanes(ModuleBase_IWorkshop* theWorkshop);
+
+  /// Show preview planes
+  /// \param theWorkshop the application workshop
+  void showPreviewPlanes(ModuleBase_IWorkshop* theWorkshop);
+
+private:
+     /// Create preview of planes for sketch plane selection
+   /// \param theOrigin an origin of the plane
+   /// \param theNorm a normal vector of the plane
+   /// \param theRGB a color of plane presentation [r, g, b] array
+  AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
+                                  std::shared_ptr<GeomAPI_Dir> theNorm, 
+                                  const int theRGB[3]);
+
+private:
+  bool myPreviewDisplayed;
+
+  AISObjectPtr myYZPlane;
+  AISObjectPtr myXZPlane;
+  AISObjectPtr myXYPlane;
+};
+
+#endif
\ No newline at end of file
index cecf69f4dd94c001d488fea56d239644dd23fa65..52e518297b1bf06b06740ddd4fda34113b59c68e 100644 (file)
@@ -7,6 +7,7 @@
 #include "PartSet_WidgetSketchCreator.h"
 #include "PartSet_Module.h"
 #include "PartSet_WidgetSketchLabel.h"
+#include "PartSet_PreviewPlanes.h"
 
 #include <Config_Keywords.h>
 
@@ -17,6 +18,7 @@
 #include <XGUI_OperationMgr.h>
 #include <XGUI_PropertyPanel.h>
 #include <XGUI_Tools.h>
+#include <XGUI_ViewerProxy.h>
 
 #include <GeomAPI_Face.h>
 
@@ -48,7 +50,7 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
                                                          PartSet_Module* theModule,
                                                          const Config_WidgetAPI* theData)
 : ModuleBase_WidgetSelector(theParent, theModule->workshop(), theData),
-  myModule(theModule), myUseBody(true)
+  myModule(theModule)
 {
   myAttributeListID = theData->getProperty("attribute_list_id");
 
@@ -76,15 +78,12 @@ PartSet_WidgetSketchCreator::PartSet_WidgetSketchCreator(QWidget* theParent,
 
   myLabel->setToolTip(aToolTip);
 
-  QString aUseBody = QString::fromStdString(theData->getProperty(USE_BODY));
-  if(!aUseBody.isEmpty()) {
-    myUseBody = QVariant(aUseBody).toBool();
-  }
-
   aLayout->addRow(myLabel, myTextLine);*/
 
   std::string aTypes = theData->getProperty("shape_types");
   myShapeTypes = QString(aTypes.c_str()).split(' ', QString::SkipEmptyParts);
+
+  myPreviewPlanes = new PartSet_PreviewPlanes();
 }
 
 PartSet_WidgetSketchCreator::~PartSet_WidgetSketchCreator()
@@ -132,6 +131,19 @@ void PartSet_WidgetSketchCreator::setVisibleSelectionControl(const bool theSelec
         aWidget->setVisible(true);
     }
   }
+
+  if (theSelectionControl) {
+    bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
+    if (!aBodyIsVisualized) {
+      // We have to select a plane before any operation
+      myPreviewPlanes->showPreviewPlanes(myWorkshop);
+    }
+  } else {
+    bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
+    myPreviewPlanes->showPreviewPlanes(myWorkshop);
+    if (aHidePreview)
+      aWorkshop->viewer()->update();
+  }
 }
 
 QIntList PartSet_WidgetSketchCreator::getShapeTypes() const
@@ -214,6 +226,8 @@ bool PartSet_WidgetSketchCreator::startSketchOperation(const QList<ModuleBase_Vi
 
   // manually deactivation because the widget was not activated as has no focus acceptin controls
   deactivate();
+  bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
+  myPreviewPlanes->erasePreviewPlanes(myWorkshop);
 
   // Launch Sketch operation
   CompositeFeaturePtr aCompFeature = 
@@ -309,33 +323,24 @@ void PartSet_WidgetSketchCreator::onResumed(ModuleBase_Operation* theOp)
 
 
     // Add Selected body were created the sketcher to list of selected objects
-    if(myUseBody) {
-      std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID();
-      AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute);
-      if (aSelList.get()) {
-        DataPtr aData = aSketchFeature->data();
-        AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-                                      (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
-        ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr();
-        if (aRes.get()) {
-          SessionPtr aMgr = ModelAPI_Session::get();
-          ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
-          AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute);
-          std::string aValidatorID, anError;
-          aSelList->append(aRes, GeomShapePtr());
-          if (aFactory->validate(anAttribute, aValidatorID, anError))
-            updateObject(aCompFeature);
-          else
-            aSelList->clear();
-        }
+    std::string anObjectsAttribute = FeaturesPlugin_CompositeBoolean::BOOLEAN_OBJECTS_ID();
+    AttributeSelectionListPtr aSelList = aCompFeature->data()->selectionList(anObjectsAttribute);
+    if (aSelList.get()) {
+      DataPtr aData = aSketchFeature->data();
+      AttributeSelectionPtr aSelAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+                                    (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID()));
+      ResultPtr aRes = aSelAttr.get() ? aSelAttr->context() : ResultPtr();
+      if (aRes.get()) {
+        SessionPtr aMgr = ModelAPI_Session::get();
+        ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
+        AttributePtr anAttribute = myFeature->attribute(anObjectsAttribute);
+        std::string aValidatorID, anError;
+        aSelList->append(aRes, GeomShapePtr());
+        if (aFactory->validate(anAttribute, aValidatorID, anError))
+          updateObject(aCompFeature);
+        else
+          aSelList->clear();
       }
     }
-    else {
-      // this is a workarount to display the feature results in the operation selection mode
-      // if this is absent, sketch point/line local selection is available on extrusion cut result
-      static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
-      ModelAPI_EventCreator::get()->sendUpdated(feature(), anUpdateEvent);
-      updateObject(feature());
-    }
   }
 }
index aa25800bd9242e8f56993332040f1bb3ea9b9ec5..011608ef07938784e477e053cdcd4965415968d1 100644 (file)
@@ -15,7 +15,7 @@ class QLabel;
 class QLineEdit;
 class PartSet_Module;
 class ModuleBase_Operation;
-
+class PartSet_PreviewPlanes;
 
 /**
 * \ingroup Modules
@@ -106,9 +106,8 @@ private:
   /// List of accepting shapes types
   QStringList myShapeTypes;
 
-  /// To check if we need to use body for composite feature or not
-  bool myUseBody;
-
+  /// class to show/hide preview planes
+  PartSet_PreviewPlanes* myPreviewPlanes;
 };
 
 #endif
\ No newline at end of file
index d5040dc78d0da6f6041cd2b0ec21370f1bf5b179..9daed51e2ee3ba3410147ce43fe052446e950254 100644 (file)
@@ -7,6 +7,7 @@
 #include "PartSet_WidgetSketchLabel.h"
 #include "PartSet_Tools.h"
 #include "PartSet_Module.h"
+#include "PartSet_PreviewPlanes.h"
 
 #include "SketchPlugin_SketchEntity.h"
 
@@ -16,6 +17,7 @@
 #include <XGUI_Selection.h>
 #include <XGUI_ViewerProxy.h>
 #include <XGUI_ActionsMgr.h>
+#include <XGUI_Tools.h>
 #include <XGUI_ModuleConnector.h>
 
 #include <ModuleBase_Operation.h>
@@ -58,8 +60,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),
-  myPreviewDisplayed(false)
+: ModuleBase_WidgetValidated(theParent, theWorkshop, theData)
 {
   QVBoxLayout* aLayout = new QVBoxLayout(this);
   ModuleBase_Tools::zeroMargins(aLayout);
@@ -122,6 +123,8 @@ PartSet_WidgetSketchLabel::PartSet_WidgetSketchLabel(QWidget* theParent,
 
   myStackWidget->addWidget(aSecondWgt);
   //setLayout(aLayout);
+
+  myPreviewPlanes = new PartSet_PreviewPlanes();
 }
 
 PartSet_WidgetSketchLabel::~PartSet_WidgetSketchLabel()
@@ -209,7 +212,7 @@ void PartSet_WidgetSketchLabel::blockAttribute(const bool& theToBlock, bool& isF
 void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs& thePrs)
 {
   // 1. hide main planes if they have been displayed
-  erasePreviewPlanes();
+  myPreviewPlanes->erasePreviewPlanes(myWorkshop);
   // 2. if the planes were displayed, change the view projection
   const GeomShapePtr& aShape = thePrs.shape();
   std::shared_ptr<GeomAPI_Shape> aGShape;
@@ -258,13 +261,14 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   myStackWidget->setCurrentIndex(1);
   //myLabel->setText("");
   //myLabel->setToolTip("");
-  disconnect(workshop()->selector(), SIGNAL(selectionChanged()), 
+  XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop);
+  disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()), 
               this, SLOT(onSelectionChanged()));
   // 4. deactivate face selection filter
   activateFilters(false);
 
   // 5. Clear selection mode and define sketching mode
-  //XGUI_Displayer* aDisp = workshop()->displayer();
+  //XGUI_Displayer* aDisp = aWorkshop->displayer();
   //aDisp->closeLocalContexts();
   emit planeSelected(plane());
   // after the plane is selected in the sketch, the sketch selection should be activated
@@ -273,7 +277,7 @@ void PartSet_WidgetSketchLabel::updateByPlaneSelected(const ModuleBase_ViewerPrs
   activateSelection(true);
 
   // 6. Update sketcher actions
-  XGUI_ActionsMgr* anActMgr = workshop()->actionsMgr();
+  XGUI_ActionsMgr* anActMgr = aWorkshop->actionsMgr();
   myWorkshop->updateCommandStatus();
   myWorkshop->viewer()->update();
 }
@@ -400,36 +404,26 @@ void PartSet_WidgetSketchLabel::activateCustom()
   }
 
   myStackWidget->setCurrentIndex(0);
-  bool aBodyIsVisualized = false;
-  XGUI_Displayer* aDisp = workshop()->displayer();
-  QObjectPtrList aDisplayed = aDisp->displayedObjects();
-  foreach (ObjectPtr anObj, aDisplayed) {
-    ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(anObj);
-    if (aResult.get() != NULL) {
-      aBodyIsVisualized = aResult->groupName() == ModelAPI_ResultBody::group();
-      if (aBodyIsVisualized)
-        break;
-    }
-  }
-
+  bool aBodyIsVisualized = myPreviewPlanes->hasVisualizedBodies(myWorkshop);
   if (!aBodyIsVisualized) {
     // We have to select a plane before any operation
-    showPreviewPlanes();
+    myPreviewPlanes->showPreviewPlanes(myWorkshop);
   }
   activateSelection(true);
 
   //myLabel->setText(myText);
   //myLabel->setToolTip(myTooltip);
 
-  connect(workshop()->selector(), SIGNAL(selectionChanged()), this, SLOT(onSelectionChanged()));
+  connect(XGUI_Tools::workshop(myWorkshop)->selector(), SIGNAL(selectionChanged()),
+          this, SLOT(onSelectionChanged()));
   activateFilters(true);
 }
 
 void PartSet_WidgetSketchLabel::deactivate()
 {
   ModuleBase_ModelWidget::deactivate();
-  bool aHidePreview = myPreviewDisplayed;
-  erasePreviewPlanes();
+  bool aHidePreview = myPreviewPlanes->isPreviewDisplayed();
+  myPreviewPlanes->erasePreviewPlanes(myWorkshop);
   activateSelection(false);
 
   activateFilters(false);
@@ -454,66 +448,6 @@ void PartSet_WidgetSketchLabel::activateSelection(bool toActivate)
   }
 }
 
-void PartSet_WidgetSketchLabel::erasePreviewPlanes()
-{
-  if (myPreviewDisplayed) {
-    XGUI_Displayer* aDisp = workshop()->displayer();
-    aDisp->eraseAIS(myYZPlane, false);
-    aDisp->eraseAIS(myXZPlane, false);
-    aDisp->eraseAIS(myXYPlane, false);
-    myPreviewDisplayed = false;
-  }
-}
-
-void PartSet_WidgetSketchLabel::showPreviewPlanes()
-{
-  if (myPreviewDisplayed)
-    return;
-
-  if (!myYZPlane) { // If planes are not created
-    // Create Preview
-    std::shared_ptr<GeomAPI_Pnt> anOrigin(new GeomAPI_Pnt(0, 0, 0));
-    std::shared_ptr<GeomAPI_Dir> aYZDir(new GeomAPI_Dir(1, 0, 0));
-    // -1, not 1 for correct internal sketch coords (issue 898)
-    std::shared_ptr<GeomAPI_Dir> aXZDir(new GeomAPI_Dir(0, -1, 0));
-    std::shared_ptr<GeomAPI_Dir> aXYDir(new GeomAPI_Dir(0, 0, 1));
-
-    std::vector<int> aYZRGB, aXZRGB, aXYRGB;
-    aYZRGB = Config_PropManager::color("Visualization", "yz_plane_color",
-                                                        YZ_PLANE_COLOR);
-    aXZRGB = Config_PropManager::color("Visualization", "xz_plane_color",
-                                                        XZ_PLANE_COLOR);
-    aXYRGB = Config_PropManager::color("Visualization", "xy_plane_color",
-                                                        XY_PLANE_COLOR);
-    int aR[] = {aYZRGB[0], aYZRGB[1], aYZRGB[2]};
-    int aG[] = {aXZRGB[0], aXZRGB[1], aXZRGB[2]};
-    int aB[] = {aXYRGB[0], aXYRGB[1], aXYRGB[2]};
-
-    myYZPlane = createPreviewPlane(anOrigin, aYZDir, aR);
-    myXZPlane = createPreviewPlane(anOrigin, aXZDir, aG);
-    myXYPlane = createPreviewPlane(anOrigin, aXYDir, aB);
-  }
-  XGUI_Displayer* aDisp = workshop()->displayer();
-  aDisp->displayAIS(myYZPlane, true, false);
-  aDisp->displayAIS(myXZPlane, true, false);
-  aDisp->displayAIS(myXYPlane, true, false);
-  myPreviewDisplayed = true;
-}
-
-
-AISObjectPtr PartSet_WidgetSketchLabel::createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
-                                                           std::shared_ptr<GeomAPI_Dir> theNorm, 
-                                                           const int theRGB[3])
-{
-  double aSize = Config_PropManager::integer("Sketch planes", "planes_size", PLANE_SIZE);
-  std::shared_ptr<GeomAPI_Shape> aFace = GeomAlgoAPI_FaceBuilder::square(theOrigin, theNorm, aSize);
-  AISObjectPtr aAIS = AISObjectPtr(new GeomAPI_AISObject());
-  aAIS->createShape(aFace);
-  aAIS->setWidth(Config_PropManager::integer("Sketch planes", "planes_thickness", SKETCH_WIDTH));
-  aAIS->setColor(theRGB[0], theRGB[1], theRGB[2]);
-  return aAIS;
-}
-
 
 std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const FeaturePtr& theFeature,
                                                                        const TopoDS_Shape& theShape)
@@ -564,13 +498,6 @@ std::shared_ptr<GeomAPI_Dir> PartSet_WidgetSketchLabel::setSketchPlane(const Fea
   return aDir;
 }
 
-XGUI_Workshop* PartSet_WidgetSketchLabel::workshop() const
-{
-  XGUI_ModuleConnector* aConnector = dynamic_cast<XGUI_ModuleConnector*>(myWorkshop);
-  return aConnector->workshop();
-}
-
-
 void PartSet_WidgetSketchLabel::onSetPlaneView()
 {
   std::shared_ptr<GeomAPI_Pln> aPlane = plane();
index 956b06ee0ec71a8ae29c5de77187b733808cba22..7ab807bd2c169b3e79dcd8aa42cb9043dc0ee87a 100644 (file)
 #include <ModuleBase_WidgetValidated.h>
 #include <ModuleBase_ViewerFilters.h>
 
-#include <GeomAPI_Pnt.h>
 #include <GeomAPI_Dir.h>
-#include <GeomAPI_AISObject.h>
 
 #include <TopoDS_Shape.hxx>
 
 #include <QMap>
 
+class PartSet_PreviewPlanes;
+
 class QLabel;
 class XGUI_OperationMgr;
 class XGUI_Workshop;
 class QCheckBox;
 class QStackedWidget;
 
-/// the plane edge width
-#define SKETCH_WIDTH        "4"
-
-/// face of the square-face displayed for selection of general plane
-#define PLANE_SIZE          "200"
-
 /**
 * \ingroup Modules
 * A model widget implementation for a label which provides specific behaviour 
@@ -155,33 +149,15 @@ protected:
   void onShowConstraint(bool theOn);
 
  private:
-   /// Create preview of planes for sketch plane selection
-   /// \param theOrigin an origin of the plane
-   /// \param theNorm a normal vector of the plane
-   /// \param theRGB a color of plane presentation [r, g, b] array
-  AISObjectPtr createPreviewPlane(std::shared_ptr<GeomAPI_Pnt> theOrigin, 
-                                  std::shared_ptr<GeomAPI_Dir> theNorm, 
-                                  const int theRGB[3]);
-
-  //! Returns workshop
-  XGUI_Workshop* workshop() const;
-
   /// Set sketch plane by shape
   /// \param theShape a planar face
   static std::shared_ptr<GeomAPI_Dir> setSketchPlane(const FeaturePtr& theFeature,
                                                      const TopoDS_Shape& theShape);
 
-  /// Erase preview planes
-  void erasePreviewPlanes();
-
-  /// Show preview planes
-  void showPreviewPlanes();
-
 
-  AISObjectPtr myYZPlane;
-  AISObjectPtr myXZPlane;
-  AISObjectPtr myXYPlane;
-  bool myPreviewDisplayed;
+private:
+  /// class to show/hide preview planes
+  PartSet_PreviewPlanes* myPreviewPlanes;
 
   QCheckBox* myViewInverted;