]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Mon, 12 May 2014 09:51:27 +0000 (13:51 +0400)
committernds <natalia.donis@opencascade.com>
Mon, 12 May 2014 09:51:27 +0000 (13:51 +0400)
Mouse released is processed as the selection change.

15 files changed:
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationEditLine.cpp
src/PartSet/PartSet_OperationEditLine.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/PartSet/PartSet_OperationSketchLine.cpp
src/PartSet/PartSet_OperationSketchLine.h
src/XGUI/CMakeLists.txt
src/XGUI/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_ViewerPrs.cpp [new file with mode: 0644]
src/XGUI/XGUI_ViewerPrs.h [new file with mode: 0644]

index 82321d023d8b9ebb84c3d9054372a530a172ea33..2ad243d68852dc33424da4a2821e584c65b1f722 100644 (file)
@@ -54,8 +54,6 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
 
-  connect(myWorkshop->selector(), SIGNAL(selectionChanged()), 
-          this, SLOT(onSelectionChanged()));
   connect(myWorkshop->viewer(), SIGNAL(mousePress(QMouseEvent*)),
           this, SLOT(onMousePressed(QMouseEvent*)));
   connect(myWorkshop->viewer(), SIGNAL(mouseRelease(QMouseEvent*)),
@@ -124,27 +122,6 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   }
 }
 
-void PartSet_Module::onSelectionChanged()
-{
-  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
-  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
-    if (aSelector) {
-      NCollection_List<TopoDS_Shape> aList;
-      aSelector->selectedShapes(aList);
-
-      XGUI_Displayer* aDisplayer = myWorkshop->displayer();
-      boost::shared_ptr<ModelAPI_Feature> aFeature;
-      // only first selected shape is processed
-      if (!aList.IsEmpty()) {
-        aFeature = aDisplayer->GetFeature(aList.First());
-      }
-      aPreviewOp->setSelected(aFeature, !aList.IsEmpty() ? aList.First() : TopoDS_Shape());
-    }
-  }
-}
-
 void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
 {
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(
@@ -161,7 +138,15 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView());
+    XGUI_SelectionMgr* aSelector = myWorkshop->selector();
+    std::list<XGUI_ViewerPrs> aPresentations;
+    if (aSelector) {
+      NCollection_List<TopoDS_Shape> aList;
+      aSelector->selectedShapes(aList);
+
+      aPresentations = myWorkshop->displayer()->GetViewerPrs(aList);
+    }
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
   }
 }
 
index 75dbd306390625c6ae50b52cf6e1cb00b7226f5e..82fe68b4f7828c02f65695d3b18f165b55294a26 100644 (file)
@@ -50,9 +50,6 @@ public slots:
   /// by the operation start
   void onOperationStopped(ModuleBase_Operation* theOperation);
 
-  /// SLOT, that is called by the selection in the viewer is changed.
-  /// The selection is sent to the current operation if it listens selection.
-  void onSelectionChanged();
   /// SLOT, that is called by mouse press in the viewer.
   /// The mouse released point is sent to the current operation to be processed.
   /// \param theEvent the mouse event
index 92ae140d2e630a8716f7b6f7d9fa1148a7fa5ed9..5f7c7ebcaeb43ba48d9859ae80a7f4e9a1b1ae75 100644 (file)
@@ -5,6 +5,8 @@
 #include <PartSet_OperationEditLine.h>
 #include <PartSet_Tools.h>
 
+#include <XGUI_ViewerPrs.h>
+
 #include <SketchPlugin_Feature.h>
 #include <GeomDataAPI_Point2D.h>
 #include <ModelAPI_Data.h>
@@ -79,16 +81,19 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
   myCurPressed = aPoint;
 }
 
-void PartSet_OperationEditLine::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                            const TopoDS_Shape& theShape)
+void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+                                              const std::list<XGUI_ViewerPrs>& theSelected)
 {
-  if (theFeature == feature())
+  boost::shared_ptr<ModelAPI_Feature> aFeature;
+  if (!theSelected.empty())
+    aFeature = theSelected.front().feature();
+  
+  if (aFeature == feature())
     return;
-
+  
   commit();
-
-  if (theFeature)
-    emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
+  if (aFeature)
+    emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
 }
 
 void PartSet_OperationEditLine::startOperation()
index 646416f91aeb6eaa7003bba0390e111164c2caab..a935f2f700e8db04cb09043288957df174ff52eb 100644 (file)
@@ -54,13 +54,12 @@ public:
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
-
   /// Gives the current selected objects to be processed by the operation
-  /// \param theFeature the selected feature
-  /// \param theShape the selected shape
-  virtual void setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           const TopoDS_Shape& theShape);
-
+  /// \param thePoint a point clicked in the viewer
+  /// \param theEvent the mouse event
+  /// \param theSelected the list of selected presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                             const std::list<XGUI_ViewerPrs>& theSelected);
 protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
index b07fd0dff107d841cc110a82eeb1c8c7891ffca7..04de171122195a125f810da00003b7a9bb22e75f 100644 (file)
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
 
+#include <XGUI_ViewerPrs.h>
+
 #include <AIS_Shape.hxx>
 #include <AIS_ListOfInteractive.hxx>
+#include <V3d_View.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -44,18 +47,24 @@ std::list<int> PartSet_OperationSketch::getSelectionModes(boost::shared_ptr<Mode
   return aModes;
 }
 
-void PartSet_OperationSketch::setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                          const TopoDS_Shape& theShape)
+void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                                            const std::list<XGUI_ViewerPrs>& theSelected)
 {
-  if (theShape.IsNull())
+  if (theSelected.empty())
     return;
+  XGUI_ViewerPrs aPrs = theSelected.front();
 
   if (!myIsEditMode) {
-    setSketchPlane(theShape);
-    myIsEditMode = true;
+    const TopoDS_Shape& aShape = aPrs.shape();
+    if (!aShape.IsNull()) {
+      setSketchPlane(aShape);
+      myIsEditMode = true;
+    }
+  }
+  else {
+    if (aPrs.feature())
+      emit launchOperation(PartSet_OperationEditLine::Type(), aPrs.feature());
   }
-  else if (theFeature)
-    emit launchOperation(PartSet_OperationEditLine::Type(), theFeature);
 }
 
 void PartSet_OperationSketch::setSketchPlane(const TopoDS_Shape& theShape)
index b30ce2927526645617d414260eaf1661c247d734..acc374e41d5570233c5d3feda7ec12f66a943a60 100644 (file)
@@ -34,11 +34,12 @@ public:
   /// \return the selection mode
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
-  /// Gives the current selected objects to be processed by the operation
-  /// \param theFeature the selected feature
-  /// \param theShape the selected shape
-  virtual void setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           const TopoDS_Shape& theShape);
+  /// Processes the mouse release in the point
+  /// \param thePoint a point clicked in the viewer
+  /// \param theEvent the mouse event
+  /// \param theSelected the list of selected presentations
+  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                             const std::list<XGUI_ViewerPrs>& theSelected);
 
 signals:
   /// signal about the sketch plane is selected
index 08e7435721d17c2dfe2fc5675b0e778e532ecfda..85c0a2c30297b796bc0e6f4b7dcce66843cbf2c9 100644 (file)
@@ -43,7 +43,8 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
 void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView)
 {
 }
-void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView)
+void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                                                const std::list<XGUI_ViewerPrs>& theSelected)
 {
 }
 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
index 0fce89ea66d44db25da948913967aec24e61b25e..d133585150c33d23a80a6b2b739743e1d366cf6e 100644 (file)
@@ -18,6 +18,7 @@
 class Handle_V3d_View;
 class QMouseEvent;
 class GeomAPI_Shape;
+class XGUI_ViewerPrs;
 
 /*!
   \class PartSet_OperationSketchBase
@@ -51,12 +52,6 @@ public:
   /// \param theFeature the feature
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature) {}
 
-  /// Gives the current selected objects to be processed by the operation
-  /// \param theFeature the selected feature
-  /// \param theShape the selected shape
-  virtual void setSelected(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                           const TopoDS_Shape& theShape) {};
-
   /// Processes the mouse pressed in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
@@ -65,7 +60,9 @@ public:
   /// Processes the mouse release in the point
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView);
+  /// \param theSelected the list of selected presentations
+  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                             const std::list<XGUI_ViewerPrs>& theSelected);
 
   /// Processes the mouse move in the point
   /// \param thePoint a 3D point clicked in the viewer
index 6fe2f6a013724c9ead1dd7f97ca38406a3887531..2538cfd5f02b6d645a45be775357f009512a974a 100644 (file)
@@ -54,7 +54,8 @@ void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFe
   myInitPoint = boost::dynamic_pointer_cast<GeomDataAPI_Point2D>(aData->attribute(LINE_ATTR_END));
 }
 
-void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
+                                                const std::list<XGUI_ViewerPrs>& theSelected)
 {
   gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
   switch (myPointSelectionMode)
index b4979a9c3e3288838fa8ad3d55f6ca567e3593cf..8dda6b9c625c1c4d391d86f72ae2a449c4bc49b0 100644 (file)
@@ -51,7 +51,9 @@ public:
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
-  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView);
+  /// \param theSelected the list of selected presentations
+ virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
+                             const std::list<XGUI_ViewerPrs>& theSelected);
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 9a506a60b2fbc045abb0925e874a4a5b7f81520c..aad18bff78f4752c18dcde17c9696f89057e69c9 100644 (file)
@@ -30,6 +30,7 @@ SET(PROJECT_HEADERS
     XGUI_ErrorDialog.h
     XGUI_SalomeViewer.h
     XGUI_ViewerProxy.h
+    XGUI_ViewerPrs.h
     XGUI_PropertyPanel.h
 )
 
@@ -59,6 +60,7 @@ SET(PROJECT_SOURCES
     XGUI_ActionsMgr.cpp
     XGUI_ErrorDialog.cpp
     XGUI_ViewerProxy.cpp
+    XGUI_ViewerPrs.cpp
     XGUI_PropertyPanel.cpp
 )
 
index 7fcc298946e8bd924de520fd175663c1fe95f8a1..20a6f721e9f38e7285b3440405e7e18a2edf67e5 100644 (file)
@@ -64,6 +64,25 @@ boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(const TopoDS_Shap
   return aFeature;
 }
 
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs
+                                                (const NCollection_List<TopoDS_Shape>& theShapes)
+{
+  std::list<XGUI_ViewerPrs> aPresentations;
+  if (theShapes.IsEmpty())
+    return aPresentations;
+
+  NCollection_List<TopoDS_Shape>::Iterator anIt(theShapes);
+  for (; anIt.More(); anIt.Next()) {
+    const TopoDS_Shape& aShape = anIt.Value();
+    if (aShape.IsNull())
+      continue;
+    boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(aShape);
+    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+  }
+
+  return aPresentations;
+}
+
 void XGUI_Displayer::Erase(boost::shared_ptr<ModelAPI_Feature> theFeature,
                            const bool isUpdateViewer)
 {
index d8da366e8a4ca4e5a7b5e5af310e5f13e18d1d26..cda9331e648489f658a302927900d3a2af8e1d3d 100644 (file)
@@ -13,6 +13,9 @@
 #include <TopoDS_Shape.hxx>
 #include <AIS_InteractiveObject.hxx>
 #include <AIS_InteractiveContext.hxx>
+#include <NCollection_List.hxx>
+
+#include <XGUI_ViewerPrs.h>
 
 #include <map>
 #include <vector>
@@ -57,7 +60,12 @@ public:
   
   /// Returns the feature, that was displayed with this shape
   /// \param theShape a shape
-  boost::shared_ptr<ModelAPI_Feature> GetFeature( const TopoDS_Shape& theShape );
+  boost::shared_ptr<ModelAPI_Feature> GetFeature(const TopoDS_Shape& theShape);
+
+  /// Returns a list of viewer presentations
+  /// \param theShapes list of shapes to find corresponded features
+  /// \return list of presentations
+  std::list<XGUI_ViewerPrs> GetViewerPrs(const NCollection_List<TopoDS_Shape>& theShapes);
 
   /// Display the shape and activate selection of sub-shapes
   /// \param theFeature a feature instance
diff --git a/src/XGUI/XGUI_ViewerPrs.cpp b/src/XGUI/XGUI_ViewerPrs.cpp
new file mode 100644 (file)
index 0000000..4ab8801
--- /dev/null
@@ -0,0 +1,39 @@
+// File:        XGUI_ViewerPrs.cpp
+// Created:     20 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#include "XGUI_ViewerPrs.h"
+
+XGUI_ViewerPrs::XGUI_ViewerPrs()
+{
+}
+
+XGUI_ViewerPrs::XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                               const TopoDS_Shape& theShape)
+: myFeature(theFeature), myShape(theShape)
+{
+}
+
+XGUI_ViewerPrs::~XGUI_ViewerPrs()
+{
+}
+
+void XGUI_ViewerPrs::setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature)
+{
+  myFeature = theFeature;
+}
+
+void XGUI_ViewerPrs::setShape(const TopoDS_Shape& theShape)
+{
+  myShape = theShape;
+}
+
+boost::shared_ptr<ModelAPI_Feature> XGUI_ViewerPrs::feature() const
+{
+  return myFeature;
+}
+
+const TopoDS_Shape& XGUI_ViewerPrs::shape() const
+{
+  return myShape;
+}
diff --git a/src/XGUI/XGUI_ViewerPrs.h b/src/XGUI/XGUI_ViewerPrs.h
new file mode 100644 (file)
index 0000000..957e4dc
--- /dev/null
@@ -0,0 +1,51 @@
+// File:        XGUI_ViewerPrs.h
+// Created:     20 Apr 2014
+// Author:      Natalia ERMOLAEVA
+
+#ifndef XGUI_ViewerPrs_H
+#define XGUI_ViewerPrs_H
+
+#include "XGUI.h"
+
+#include <boost/shared_ptr.hpp>
+#include <TopoDS_Shape.hxx>
+
+class ModelAPI_Feature;
+
+/**\class XGUI_ViewerPrs
+ * \ingroup GUI
+ * \brief Presentation. Provides container to have feature and the shape
+ */
+class XGUI_EXPORT XGUI_ViewerPrs
+{
+public:
+  /// Constructor
+  XGUI_ViewerPrs();
+  /// Constructor
+  XGUI_ViewerPrs(boost::shared_ptr<ModelAPI_Feature> theFeature,
+                 const TopoDS_Shape& theShape);
+  /// Destructor
+  virtual ~XGUI_ViewerPrs();
+
+  /// Sets the feature.
+  /// \param theFeature a feature instance
+  void setFeature(boost::shared_ptr<ModelAPI_Feature> theFeature);
+
+  /// Sets the shape
+  /// \param theShape a shape instance
+  void setShape(const TopoDS_Shape& theShape);
+
+  /// Returns the feature.
+  /// \return a feature instance
+  boost::shared_ptr<ModelAPI_Feature> feature() const;
+
+  /// Returns the shape
+  /// \return a shape instance
+  const TopoDS_Shape& shape() const;
+
+private:
+  boost::shared_ptr<ModelAPI_Feature> myFeature; /// the feature
+  TopoDS_Shape myShape; /// the shape
+};
+
+#endif