]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 12:38:54 +0000 (16:38 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 24 Apr 2014 12:38:54 +0000 (16:38 +0400)
Providing the local selection for sketch feature

src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_OperationSketch.cpp
src/PartSet/PartSet_OperationSketch.h
src/PartSet/PartSet_OperationSketchBase.cpp
src/PartSet/PartSet_OperationSketchBase.h
src/XGUI/XGUI_Viewer.cpp
src/XGUI/XGUI_Viewer.h

index 76a8c855bd3e8a1ffece003a1653c98abdd6e48e..568f28c865f1fa395a88922bfe42e27ac240a539 100644 (file)
@@ -15,6 +15,8 @@
 #include <Events_Loop.h>
 #include <Events_Message.h>
 
+#include <AIS_ListOfInteractive.hxx>
+
 #include <QObject>
 #include <QString>
 
@@ -37,6 +39,8 @@ PartSet_Module::PartSet_Module(XGUI_Workshop* theWshop)
   connect(anOperationMgr, SIGNAL(operationStarted()), this, SLOT(onOperationStarted()));
   connect(anOperationMgr, SIGNAL(operationStopped(ModuleBase_Operation*)),
           this, SLOT(onOperationStopped(ModuleBase_Operation*)));
+  connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
+          this, SLOT(onViewSelectionChanged()));
 }
 
 PartSet_Module::~PartSet_Module()
@@ -97,11 +101,8 @@ void PartSet_Module::onOperationStarted()
   ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
 
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
-  if (aPreviewOp) {
-    connect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
-            aPreviewOp, SLOT(onViewSelectionChanged()));
+  if (aPreviewOp)
     visualizePreview(true);
-  }
 }
 
 void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
@@ -109,12 +110,22 @@ void PartSet_Module::onOperationStopped(ModuleBase_Operation* theOperation)
   ModuleBase_PropPanelOperation* anOperation = dynamic_cast<ModuleBase_PropPanelOperation*>(theOperation);
   if (!anOperation)
     return;
+  PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
+  if (aPreviewOp)
+    visualizePreview(false);
+}
 
+void PartSet_Module::onViewSelectionChanged()
+{
+  ModuleBase_Operation* anOperation = myWorkshop->operationMgr()->currentOperation();
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp) {
-    disconnect(myWorkshop->mainWindow()->viewer(), SIGNAL(selectionChanged()),
-               aPreviewOp, SLOT(onViewSelectionChanged()));
-    visualizePreview(false);
+    XGUI_Viewer* aViewer = myWorkshop->mainWindow()->viewer();
+    if (aViewer) {
+      AIS_ListOfInteractive aList;
+      aViewer->getSelectedObjects(aList);
+      aPreviewOp->setSelectedObjects(aList);
+    }
   }
 }
 
index 60f78835cc6251f8be2cb3f07c7d6c1d8fbcfcd7..6335136742ec6ad997bb9d487fa979f03505333c 100644 (file)
@@ -28,6 +28,9 @@ public slots:
   /// SLOT, that is called after the operation is stopped. Disconnect the sketch feature
   /// from the viewer selection and show the sketch preview.
   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 listen the selection.
+  void onViewSelectionChanged();
 
 private:
   /// Displays or erase the current operation preview, if it has it.
index 01010ee554d2580b9025f6a2f9ef3e03f553cc8d..c9608cd2e1982d8536a3d49b45da62d9d528897f 100644 (file)
@@ -5,6 +5,11 @@
 #include <PartSet_OperationSketch.h>
 
 #include <SketchPlugin_Feature.h>
+#include <ModelAPI_Data.h>
+#include <ModelAPI_AttributeDocRef.h>
+
+#include <AIS_Shape.hxx>
+#include <AIS_ListOfInteractive.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -31,3 +36,28 @@ int PartSet_OperationSketch::getSelectionMode() const
 {
   return TopAbs_FACE;
 }
+
+void PartSet_OperationSketch::setSelectedObjects(const AIS_ListOfInteractive& theList)
+{
+  if (theList.IsEmpty())
+    return;
+
+  // 1. get selected fase
+  Handle(AIS_Shape) anAISShape = Handle(AIS_Shape)::DownCast(theList.First());
+  if (anAISShape.IsNull())
+    return;
+
+  const TopoDS_Shape& aShape = anAISShape->Shape();
+  boost::shared_ptr<GeomAPI_Shape> aRes(new GeomAPI_Shape);
+  aRes->setImpl(new TopoDS_Shape(aShape));
+
+  // get plane parameters
+  double anX = 1, anY = 0, aZ = 0, anOrigin = 0;
+
+  // set plane parameters to feature
+  //boost::shared_ptr<ModelAPI_Data> aData = feature()->data();
+  //boost::shared_ptr<ModelAPI_AttributeDocRef> anAttr = aData->docRef(SKETCH_ATTR_X);
+  //anAttr->setValue(anX);
+
+  commit();
+}
index ee8df257aa0485a14d60c756cd3bd779035cfe47..83be57a998259b46d5f91f16a8bb88bf2e614e74 100644 (file)
@@ -31,6 +31,10 @@ public:
   /// Returns the operation local selection mode
   /// \return the selection mode
   virtual int getSelectionMode() const;
+
+  /// Gives the current selected objects to be processed by the operation
+  /// \param theList a list of interactive selected objects
+  virtual void setSelectedObjects(const AIS_ListOfInteractive& theList);
 };
 
 #endif
index ba3a626f277cbaf09184d6a579a879a52f826772..519c97f76d5335d3def922e4158b77de59982c2f 100644 (file)
@@ -28,8 +28,3 @@ 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 92500d786fb306f3b06f6c0a494565d6964f8384..b6c160ae7de0870d30a4738ad66d52cde5038f77 100644 (file)
@@ -12,6 +12,8 @@
 #include <ModuleBase_PropPanelOperation.h>
 #include <QObject>
 
+class AIS_ListOfInteractive;
+
 /*!
   \class PartSet_OperationSketchBase
   * \brief The base operation for the sketch features.
@@ -33,7 +35,11 @@ public:
 
   /// Returns the operation local selection mode
   /// \return the selection mode
-  virtual int getSelectionMode() const;
+  virtual int getSelectionMode() const = 0;
+
+  /// Gives the current selected objects to be processed by the operation
+  /// \param a list of interactive selected objects
+  virtual void setSelectedObjects(const AIS_ListOfInteractive& aList) = 0;
 };
 
 #endif
index c78bd72d1bfa7fa6d065fb90bfe2d148682c6880..e6dd6e2b728597c75ae92e6fe7e4429a9b06c0f6 100644 (file)
@@ -231,6 +231,21 @@ void XGUI_Viewer::setGlobalSelection(const bool isUpdateViewer)
   }
 }
 
+void XGUI_Viewer::getSelectedObjects(AIS_ListOfInteractive& theList)
+{
+  theList.Clear();
+  for (myAISContext->InitSelected(); myAISContext->MoreSelected(); myAISContext->NextSelected())
+    theList.Append(myAISContext->SelectedInteractive());
+}
+
+void XGUI_Viewer::setObjectsSelected(const AIS_ListOfInteractive& theList)
+{
+  AIS_ListIteratorOfListOfInteractive aIt;
+  for (aIt.Initialize(theList); aIt.More(); aIt.Next())
+    myAISContext->AddOrRemoveSelected(aIt.Value(), false);
+  myAISContext->UpdateCurrentViewer();
+}
+
 /*! Sets hot button
  *\param theOper - hot operation
  *\param theState - adding state to state map operations.
index 3e33be3ae6a802a191814013328b5bf2e41b7771..c4ae363b613fefe6da0be570a3033a997c0026a7 100644 (file)
@@ -65,6 +65,18 @@ public:
   //! \param isUpdateViewer the state wether the viewer should be updated immediatelly
   void setGlobalSelection(const bool isUpdateViewer);
 
+  /// Return objects selected in 3D viewer
+  /// \param theList - list to be filled with selected objects
+  void  getSelectedObjects(AIS_ListOfInteractive& theList);
+
+  /// Selects objects in 3D viewer. Other selected objects are left as selected
+  /// \param theList - list objects to be selected
+  void  setObjectsSelected(const AIS_ListOfInteractive& theList);
+
+  /// Select the object in 3D viewer.
+  /// \param theIO - list objects to be selected
+  void setSelected(const Handle(AIS_InteractiveObject)& theIO) { myAISContext->SetSelected(theIO); }
+
   //! Trihedron 3d object shown in the viewer
   Handle(AIS_Trihedron) trihedron() const
   {