Salome HOME
Merge branch 'master' of newgeom:newgeom
authornds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 10:51:27 +0000 (14:51 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 10:51:27 +0000 (14:51 +0400)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h

index 2b2a3ddb10be1e020ff46fa80f2b3a08ac3e16d5..76a8c855bd3e8a1ffece003a1653c98abdd6e48e 100644 (file)
@@ -128,8 +128,12 @@ void PartSet_Module::visualizePreview(bool isDisplay)
   if (!aPreviewOp)
     return;
 
-  if (isDisplay)
-    myWorkshop->displayer()->Display(anOperation->feature(), aPreviewOp->preview());
-  else
+  if (isDisplay) {
+    myWorkshop->displayer()->LocalSelection(anOperation->feature(), aPreviewOp->preview(),
+                                            aPreviewOp->getSelectionMode());
+  }
+  else {
+    myWorkshop->displayer()->GlobalSelection(false);
     myWorkshop->displayer()->Erase(anOperation->feature(), aPreviewOp->preview());
+  }
 }
index a12c38b0a4cdc8e7264b20a06e4ee9a1259dc038..01010ee554d2580b9025f6a2f9ef3e03f553cc8d 100644 (file)
@@ -26,3 +26,8 @@ bool PartSet_OperationSketch::isPerformedImmediately() const
 {
   return false;
 }
+
+int PartSet_OperationSketch::getSelectionMode() const
+{
+  return TopAbs_FACE;
+}
index 63375e5e60bae4cbe03c5c384b82e99fca12a185..ee8df257aa0485a14d60c756cd3bd779035cfe47 100644 (file)
@@ -27,6 +27,10 @@ public:
 
   /// The sketch can not be created immediately, firstly a plane should be set
   virtual bool isPerformedImmediately() const;
+
+  /// Returns the operation local selection mode
+  /// \return the selection mode
+  virtual int getSelectionMode() const;
 };
 
 #endif
index 519c97f76d5335d3def922e4158b77de59982c2f..ba3a626f277cbaf09184d6a579a879a52f826772 100644 (file)
@@ -28,3 +28,8 @@ const TopoDS_Shape& PartSet_OperationSketchBase::preview() const
     boost::dynamic_pointer_cast<SketchPlugin_Feature>(feature());
   return aFeature->preview()->impl<TopoDS_Shape>();
 }
+
+int PartSet_OperationSketchBase::getSelectionMode() const
+{
+  return 0;
+}
index 1a99babc94de8702687a8af90ff1981150952988..92500d786fb306f3b06f6c0a494565d6964f8384 100644 (file)
@@ -30,6 +30,10 @@ public:
 
   /// Returns the feature preview shape
   const TopoDS_Shape& preview() const;
+
+  /// Returns the operation local selection mode
+  /// \return the selection mode
+  virtual int getSelectionMode() const;
 };
 
 #endif
index 489d0248e0bdc4222c8939251a35ab8f38ffc8d0..a036e8f7503f43064338e915fdbdcf9720503a93 100644 (file)
@@ -8,6 +8,8 @@
 #include <ModelAPI_Document.h>
 
 #include <AIS_InteractiveContext.hxx>
+#include <AIS_ListOfInteractive.hxx>
+
 #include <AIS_Shape.hxx>
 
 XGUI_Displayer::XGUI_Displayer(XGUI_Viewer* theViewer)
@@ -19,24 +21,47 @@ XGUI_Displayer::~XGUI_Displayer()
 {
 }
 
-void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature)
+void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                             const bool isUpdateViewer)
 {
 }
 
 void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                             const TopoDS_Shape& theShape)
+                             const TopoDS_Shape& theShape, const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
 
   Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
   aContext->Display(anAIS, Standard_False);
 
-  aContext->UpdateCurrentViewer();
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
 }
 
 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           const TopoDS_Shape& theShape)
+                           const TopoDS_Shape& theShape, const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
   aContext->EraseAll();
+  if (isUpdateViewer)
+    aContext->UpdateCurrentViewer();
 }
+
+void XGUI_Displayer::LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                                    const TopoDS_Shape& theShape,
+                                    const int theMode, const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) aContext = myViewer->AISContext();
+
+  Handle(AIS_Shape) anAIS = new AIS_Shape(theShape);
+  aContext->Display(anAIS, Standard_False);
+  AIS_ListOfInteractive anAISList;
+  anAISList.Append(anAIS);
+  myViewer->setLocalSelection(anAISList, theMode, true);
+}
+
+void XGUI_Displayer::GlobalSelection(const bool isUpdateViewer)
+{
+  myViewer->setGlobalSelection(true);
+}
+
index 06ebcba1ef5f9ba567a5324d15e299be37dd7b89..1dc238b906be7046c02f67a4ae8552df01562110 100644 (file)
@@ -30,17 +30,34 @@ public:
 
   /// Display the feature. Obtain the visualized object from the feature.
   /// \param theFeature a feature instance
-  void Display(boost::shared_ptr<ModelAPI_Feature> theFeature);
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const bool isUpdateViewer = true);
 
   /// Display the feature and a shape. This shape would be associated to the given feature
   /// \param theFeature a feature instance
-  /// \param theFeature a shape
-  void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+  /// \param theShape a shape
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+               const bool isUpdateViewer = true);
+  
+  /// Display the shape and activate selection of sub-shapes
+  /// \param theFeature a feature instance
+  /// \param theShape a shape
+  /// \param theMode a local selection mode
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void LocalSelection(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+                      const int theMode, const bool isUpdateViewer = true);
 
   /// Erase the feature and a shape.
   /// \param theFeature a feature instance
   /// \param theFeature a shape
-  void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape);
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void Erase(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
+             const bool isUpdateViewer = true);
+
+  /// Deactivates selection of sub-shapes
+  /// \param isUpdateViewer the parameter whether the viewer should be update immediatelly
+  void GlobalSelection(const bool isUpdateViewer = true);
 
 protected:
   XGUI_Viewer* myViewer; ///< the viewer where the objects should be visualized
index 6d4c100681cd3677f60761ca556c521ef5172601..c78bd72d1bfa7fa6d065fb90bfe2d148682c6880 100644 (file)
@@ -19,6 +19,8 @@
 #include <V3d_View.hxx>
 #include <Visual3d_View.hxx>
 #include <AIS_ListOfInteractive.hxx>
+#include <AIS_ListIteratorOfListOfInteractive.hxx>
+#include <AIS_Shape.hxx>
 
 #include <QMouseEvent>
 
@@ -188,6 +190,47 @@ QMdiSubWindow* XGUI_Viewer::createView(V3d_TypeOfView theType)
   return aWnd;
 }
 
+void XGUI_Viewer::setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode,
+                                    const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) ic = AISContext();
+
+  // Open local context if there is no one
+  bool allObjects = false; // calculate by AIS shape
+  if (!ic->HasOpenedContext()) {
+    ic->ClearCurrents(false);
+    ic->OpenLocalContext(allObjects, true, true);
+  }
+
+  // Activate selection of objects from prs
+  AIS_ListIteratorOfListOfInteractive aIter(theAISObjects);
+  for (; aIter.More(); aIter.Next()) {
+    Handle(AIS_InteractiveObject) anAIS = aIter.Value();
+    if (!anAIS.IsNull()) {
+      if (anAIS->IsKind(STANDARD_TYPE(AIS_Shape))) {
+        ic->Load(anAIS, -1, false);
+        ic->Activate(anAIS, AIS_Shape::SelectionMode((TopAbs_ShapeEnum)theMode));
+      }
+      else if (anAIS->DynamicType() != STANDARD_TYPE(AIS_Trihedron)) {
+        ic->Load(anAIS, -1, false);
+        ic->Activate(anAIS, theMode);
+      }
+    }
+  }
+  if (isUpdateViewer)
+    ic->UpdateCurrentViewer();
+}
+
+void XGUI_Viewer::setGlobalSelection(const bool isUpdateViewer)
+{
+  Handle(AIS_InteractiveContext) ic = AISContext();
+  if (!ic.IsNull()) {
+    ic->CloseAllContexts(false);
+    if (isUpdateViewer)
+      ic->UpdateCurrentViewer();
+  }
+}
+
 /*! Sets hot button
  *\param theOper - hot operation
  *\param theState - adding state to state map operations.
index 5b68ebdf0b9a47e516d0ea7d28973311a6f9742d..3e33be3ae6a802a191814013328b5bf2e41b7771 100644 (file)
@@ -18,6 +18,8 @@ class XGUI_ViewWindow;
 class QMouseEvent;
 class QKeyEvent;
 
+class AIS_ListOfInteractive;
+
 /**\class XGUI_Viewer
  * \ingroup GUI
  * \brief Represents a 3d viewer. The viewer manages 3d scene and a set of view windows
@@ -53,6 +55,16 @@ public:
     return myAISContext;
   }
 
+  //! Activate local selection
+  //! \param theAIS the list of objects
+  //! \param theMode the selection mode
+  //! \param isUpdateViewer the state wether the viewer should be updated immediatelly
+  void setLocalSelection(const AIS_ListOfInteractive& theAISObjects, const int theMode,
+                         const bool isUpdateViewer);
+  //! Deactivate local selection
+  //! \param isUpdateViewer the state wether the viewer should be updated immediatelly
+  void setGlobalSelection(const bool isUpdateViewer);
+
   //! Trihedron 3d object shown in the viewer
   Handle(AIS_Trihedron) trihedron() const
   {