]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
refs #30 - Sketch base GUI: create, draw lines
authornds <natalia.donis@opencascade.com>
Thu, 22 May 2014 10:50:48 +0000 (14:50 +0400)
committernds <natalia.donis@opencascade.com>
Thu, 22 May 2014 10:50:48 +0000 (14:50 +0400)
The edit operation correction. It is necessary to move any object without preliminary selection. Drag a highlighted object and move it somewhere.

12 files changed:
src/PartSet/PartSet_Module.cpp
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/XGUI_Displayer.cpp
src/XGUI/XGUI_Displayer.h
src/XGUI/XGUI_Viewer.cpp

index b54dc192afca8965a7bb3250fbbdc6222cd8b3b6..606c5789966eee02a806b0a68e020ab71126e0ed 100644 (file)
@@ -128,8 +128,11 @@ void PartSet_Module::onMousePressed(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
-    aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+    aPreviewOp->mousePressed(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
   }
 }
 
@@ -139,8 +142,11 @@ void PartSet_Module::onMouseReleased(QMouseEvent* theEvent)
                                        myWorkshop->operationMgr()->currentOperation());
   if (aPreviewOp)
   {
-    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
-    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aPresentations);
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+
+    aPreviewOp->mouseReleased(theEvent, myWorkshop->viewer()->activeView(), aSelected, aHighlighted);
   }
 }
 
@@ -173,8 +179,10 @@ void PartSet_Module::onLaunchOperation(std::string theName, boost::shared_ptr<Mo
   PartSet_OperationSketchBase* aPreviewOp = dynamic_cast<PartSet_OperationSketchBase*>(anOperation);
   if (aPreviewOp)
   {
-    std::list<XGUI_ViewerPrs> aPresentations = myWorkshop->displayer()->GetViewerPrs();
-    aPreviewOp->init(theFeature, aPresentations);
+    XGUI_Displayer* aDisplayer = myWorkshop->displayer();
+    std::list<XGUI_ViewerPrs> aSelected = aDisplayer->GetSelected();
+    std::list<XGUI_ViewerPrs> aHighlighted = aDisplayer->GetHighlighted();
+    aPreviewOp->init(theFeature, aSelected, aHighlighted);
   }
   myWorkshop->actionsMgr()->setActionChecked(anOperation->getDescription()->operationId(), true);
   sendOperation(anOperation);
@@ -197,6 +205,10 @@ void PartSet_Module::onStopSelection(const std::list<XGUI_ViewerPrs>& theFeature
     }
   }
   aDisplayer->StopSelection(theFeatures, isStop, false);
+
+  XGUI_ViewerProxy* aViewer = myWorkshop->viewer();
+  aViewer->enableSelection(!isStop);
+
   aDisplayer->UpdateViewer();
 }
 
index 7b37976e8a0f041f2f19f85a18b9aa9ec11437dd..561ae86e3a5718fa351629d7897f0c2a9c966ba1 100644 (file)
@@ -53,10 +53,28 @@ std::list<int> PartSet_OperationEditLine::getSelectionModes(boost::shared_ptr<Mo
 }
 
 void PartSet_OperationEditLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                     const std::list<XGUI_ViewerPrs>& thePresentations)
+                                     const std::list<XGUI_ViewerPrs>& theSelected,
+                                     const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
   setFeature(theFeature);
-  myFeatures = thePresentations;
+
+  if (!theHighlighted.empty()) {
+    // if there is highlighted object, we check whether it is in the list of selected objects
+    // in that case this object is a handle of the moved lines. If there no such object in the selection,
+    // the hightlighted object should moved and the selection is skipped. The skipped selection will be
+    // deselected in the viewer by blockSelection signal in the startOperation method.
+    bool isSelected = false;
+    std::list<XGUI_ViewerPrs>::const_iterator anIt = theSelected.begin(), aLast = theSelected.end();
+    for (; anIt != aLast && !isSelected; anIt++) {
+      isSelected = (*anIt).feature() == feature();
+    }
+    if (!isSelected)
+      myFeatures = theHighlighted;
+    else
+      myFeatures = theSelected;
+  }
+  else
+    myFeatures = theSelected;
 }
 
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
@@ -64,12 +82,27 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::sketch() const
   return mySketch;
 }
 
-void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView)
+void PartSet_OperationEditLine::mousePressed(QMouseEvent* theEvent, Handle(V3d_View) theView,
+                                             const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                             const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
-  if (!(theEvent->buttons() &  Qt::LeftButton))
-    return;
-  gp_Pnt aPoint = PartSet_Tools::ConvertClickToPoint(theEvent->pos(), theView);
-  myCurPoint.setPoint(aPoint);
+  if (myFeatures.size() == 1)
+  {
+    boost::shared_ptr<ModelAPI_Feature> aFeature;
+    if (!theHighlighted.empty())
+      aFeature = theHighlighted.front().feature();
+
+    if (aFeature && aFeature == feature()) { // continue the feature edit
+      blockSelection(true);
+    }
+    else {
+      commit();
+      emit featureConstructed(feature(), FM_Deactivation);
+      if (aFeature) {
+        emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+      }
+    }
+  }
 }
 
 void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
@@ -107,16 +140,12 @@ void PartSet_OperationEditLine::mouseMoved(QMouseEvent* theEvent, Handle(V3d_Vie
 }
 
 void PartSet_OperationEditLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                              const std::list<XGUI_ViewerPrs>& theSelected)
+                                              const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                              const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   std::list<XGUI_ViewerPrs> aFeatures = myFeatures;
   if (myFeatures.size() == 1) {
-    if (theSelected.empty())
-      return;
-
-    boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
-    commit();
-    emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
+    blockSelection(false);
   }
   else {
     commit();
@@ -133,22 +162,34 @@ void PartSet_OperationEditLine::startOperation()
 {
   // do nothing in order to do not create a new feature
   emit multiSelectionEnabled(false);
-  emit setSelection(std::list<XGUI_ViewerPrs>());
-  emit stopSelection(myFeatures, true);
+
+  blockSelection(true);
+
   myCurPoint.clear();
 }
 
 void PartSet_OperationEditLine::stopOperation()
 {
   emit multiSelectionEnabled(true);
-  bool isSelectFeatures = myFeatures.size() > 1;
-  emit stopSelection(myFeatures, false);
-  if (isSelectFeatures)
-    emit setSelection(myFeatures);
+
+  blockSelection(false, myFeatures.size() > 1);
 
   myFeatures.clear();
 }
 
+void PartSet_OperationEditLine::blockSelection(bool isBlocked, const bool isRestoreSelection)
+{
+  if (isBlocked) {
+    emit setSelection(std::list<XGUI_ViewerPrs>());
+    emit stopSelection(myFeatures, true);
+  }
+  else {
+    emit stopSelection(myFeatures, false);
+    if (isRestoreSelection)
+      emit setSelection(myFeatures);
+  }
+}
+
 boost::shared_ptr<ModelAPI_Feature> PartSet_OperationEditLine::createFeature()
 {
   // do nothing in order to do not create a new feature
index 14fd56959cfebedd8688389b7c6140c40ca797b9..8f0b62361174db341d136997d8c33436728cb377 100644 (file)
@@ -72,28 +72,36 @@ public:
 
   /// Initializes some fields accorging to the feature
   /// \param theFeature the feature
-  /// \param thePresentations the list of additional presentations
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                    const std::list<XGUI_ViewerPrs>& thePresentations);
+                    const std::list<XGUI_ViewerPrs>& theSelected,
+                    const std::list<XGUI_ViewerPrs>& theHighlighted);
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
   virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
 
   /// Processes the mouse pressed in the point
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
-  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView);
+  /// \param theView a viewer to have the viewer the eye position
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
+  virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
   /// Gives the current mouse point in the viewer
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
   /// Gives the current selected objects to be processed by the operation
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
   /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<XGUI_ViewerPrs>& theSelected);
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
 protected:
   /// \brief Virtual method called when operation is started
   /// Virtual method called when operation started (see start() method for more description)
@@ -110,6 +118,13 @@ protected:
   virtual boost::shared_ptr<ModelAPI_Feature> createFeature();
 
 protected:
+  /// Emits a signal about the selection blocking. Emits a signal to change the selection.
+  /// If the block is true, the signal clear selection, otherwise if restore selection flag allows,
+  /// the internal operation features are to be selected
+  /// \param isBlocked the state whether the operation is blocked or unblocked
+  /// \param isRestoreSelection the state whether the selected objects should be reselected
+  void blockSelection(bool isBlocked, const bool isRestoreSelection = true);
+
   /// \brief Save the point to the line.
   /// \param theFeature the source feature
   /// \param theDeltaX the delta for X coordinate is moved
index d527cd0f3f1aee9d07598e9a2b2c36c40f1cbf6f..e818e5ec12df7737cb10b06b00fe0675ac2ab4df 100644 (file)
@@ -57,19 +57,11 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketch::sketch() const
 }
 
 void PartSet_OperationSketch::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                           const std::list<XGUI_ViewerPrs>& theSelected)
+                                           const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                           const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
-  myFeatures = theSelected;
-}
-
-void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                            const std::list<XGUI_ViewerPrs>& theSelected)
-{
-  if (theSelected.empty())
-    return;
-
   if (!myIsEditMode) {
-    XGUI_ViewerPrs aPrs = theSelected.front();
+    XGUI_ViewerPrs aPrs = theHighlighted.front();
     const TopoDS_Shape& aShape = aPrs.shape();
     if (!aShape.IsNull()) {
       setSketchPlane(aShape);
@@ -77,13 +69,14 @@ void PartSet_OperationSketch::mouseReleased(QMouseEvent* theEvent, Handle_V3d_Vi
     }
   }
   else {
-    if (theSelected.size() == 1) {
-      boost::shared_ptr<ModelAPI_Feature> aFeature = theSelected.front().feature();
+    if (theHighlighted.size() == 1) {
+      boost::shared_ptr<ModelAPI_Feature> aFeature = theHighlighted.front().feature();
       if (aFeature)
         emit launchOperation(PartSet_OperationEditLine::Type(), aFeature);
     }
+    else
+      myFeatures = theHighlighted;
   }
-  myFeatures.clear();
 }
 
 void PartSet_OperationSketch::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
index fbb0eb376afba999656a2a675bb42d6e37a76f15..010b28d86f09c60865fef09d35632cd3402b0d0f 100644 (file)
@@ -39,17 +39,13 @@ public:
   virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
 
   /// Processes the mouse pressed in the point
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<XGUI_ViewerPrs>& theSelected);
-  /// 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);
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 18fdea1fd16c5ce20a82d1ea53232f032e0e5b32..0527d9c6829a0ef6992b23c42fb1657cc942c198 100644 (file)
@@ -61,11 +61,13 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchBase::createFeature()
 
 
 void PartSet_OperationSketchBase::mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                               const std::list<XGUI_ViewerPrs>& theSelected)
+                                               const std::list<XGUI_ViewerPrs>& theSelected,
+                                               const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
 }
 void PartSet_OperationSketchBase::mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                                                const std::list<XGUI_ViewerPrs>& theSelected)
+                                                const std::list<XGUI_ViewerPrs>& theSelected,
+                                                const std::list<XGUI_ViewerPrs>& theHighlighted)
 {
 }
 void PartSet_OperationSketchBase::mouseMoved(QMouseEvent* theEvent, Handle(V3d_View) theView)
index 0045a8e87b1a6c19b2cf227188974d3ea7099387..53916ee6f8dc2321caf2fb15506a15fb5686f661 100644 (file)
@@ -55,32 +55,37 @@ public:
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const = 0;
 
   /// Initializes some fields accorging to the feature
-  /// \param theFeature the feature
-  /// \param thePresentations the list of additional presentations
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                    const std::list<XGUI_ViewerPrs>& thePresentations) {}
+                    const std::list<XGUI_ViewerPrs>& theSelected,
+                    const std::list<XGUI_ViewerPrs>& theHighlighted) {}
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
   virtual boost::shared_ptr<ModelAPI_Feature> sketch() const = 0;
 
   /// Processes the mouse pressed in the point
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void mousePressed(QMouseEvent* theEvent, Handle_V3d_View theView,
-                            const std::list<XGUI_ViewerPrs>& theSelected);
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
 
   /// Processes the mouse release in the point
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<XGUI_ViewerPrs>& theSelected);
+                             const std::list<XGUI_ViewerPrs>& theSelected,
+                             const std::list<XGUI_ViewerPrs>& theHighlighted);
 
   /// Processes the mouse move in the point
-  /// \param thePoint a 3D point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   virtual void mouseMoved(QMouseEvent* theEvent, Handle_V3d_View theView);
 
   /// Processes the key pressed in the view
index 6b64cd2759cff1930c142411f11a40d44ab5d1bc..4ccf1c16cfee09af1bcbd49a082dc99959226af7 100644 (file)
@@ -67,7 +67,8 @@ std::list<int> PartSet_OperationSketchLine::getSelectionModes(boost::shared_ptr<
 }
 
 void PartSet_OperationSketchLine::init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                                       const std::list<XGUI_ViewerPrs>& /*thePresentations*/)
+                                       const std::list<XGUI_ViewerPrs>& /*theSelected*/,
+                                       const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   if (!theFeature || theFeature->getKind() != "SketchLine")
     return;
@@ -82,7 +83,8 @@ boost::shared_ptr<ModelAPI_Feature> PartSet_OperationSketchLine::sketch() const
 }
 
 void PartSet_OperationSketchLine::mouseReleased(QMouseEvent* theEvent, Handle(V3d_View) theView,
-                                                const std::list<XGUI_ViewerPrs>& theSelected)
+                                                const std::list<XGUI_ViewerPrs>& theSelected,
+                                                const std::list<XGUI_ViewerPrs>& /*theHighlighted*/)
 {
   double aX, anY;
 
@@ -198,8 +200,16 @@ void PartSet_OperationSketchLine::keyReleased(const int theKey)
       emit launchOperation(PartSet_OperationSketchLine::Type(), boost::shared_ptr<ModelAPI_Feature>());
     }
     break;
+    case Qt::Key_Escape: {
+      if (myPointSelectionMode == SM_DonePoint)
+      {
+        commit();
+        emit featureConstructed(feature(), FM_Deactivation);
+      }
+      else
+        abort();
+    }
     default:
-      PartSet_OperationSketchBase::keyReleased(theKey); 
     break;
   }
 }
index 09c33f6f452621540d8d17e9ede546f703c417e7..0d556d2c06103b69e30d2549f715820993960049 100644 (file)
@@ -46,21 +46,24 @@ public:
   virtual std::list<int> getSelectionModes(boost::shared_ptr<ModelAPI_Feature> theFeature) const;
 
   /// Initializes some fields accorging to the feature
-  /// \param theFeature the feature
-  /// \param thePresentations the list of additional presentations
+  /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
   virtual void init(boost::shared_ptr<ModelAPI_Feature> theFeature,
-                    const std::list<XGUI_ViewerPrs>& thePresentations);
+                    const std::list<XGUI_ViewerPrs>& theSelected,
+                    const std::list<XGUI_ViewerPrs>& theHighlighted);
 
   /// Returns the operation sketch feature
   /// \returns the sketch instance
   virtual boost::shared_ptr<ModelAPI_Feature> sketch() const;
 
   /// Gives the current selected objects to be processed by the operation
-  /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
+  /// \param theView a viewer to have the viewer the eye position
   /// \param theSelected the list of selected presentations
+  /// \param theHighlighted the list of highlighted presentations
  virtual void mouseReleased(QMouseEvent* theEvent, Handle_V3d_View theView,
-                             const std::list<XGUI_ViewerPrs>& theSelected);
+                            const std::list<XGUI_ViewerPrs>& theSelected,
+                            const std::list<XGUI_ViewerPrs>& theHighlighted);
   /// Gives the current mouse point in the viewer
   /// \param thePoint a point clicked in the viewer
   /// \param theEvent the mouse event
index 7f6bb00d77885b772f7febee71cd8fac6d7fa6b7..4073b30b435838c86319ab4286eb1c3e558488b9 100644 (file)
@@ -12,6 +12,7 @@
 #include <ModelAPI_Data.h>
 
 #include <AIS_InteractiveContext.hxx>
+#include <AIS_LocalContext.hxx>
 #include <AIS_ListOfInteractive.hxx>
 #include <AIS_ListIteratorOfListOfInteractive.hxx>
 
@@ -52,7 +53,7 @@ void XGUI_Displayer::Display(boost::shared_ptr<ModelAPI_Feature> theFeature,
 }*/
 
 
-std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs()
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetSelected()
 {
   std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
   std::list<XGUI_ViewerPrs> aPresentations;
@@ -62,15 +63,26 @@ std::list<XGUI_ViewerPrs> XGUI_Displayer::GetViewerPrs()
     Handle(AIS_InteractiveObject) anIO = aContext->SelectedInteractive();
     TopoDS_Shape aShape = aContext->SelectedShape();
 
-    boost::shared_ptr<ModelAPI_Feature> aFeature;
-    FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
-                                    aFLast = myFeature2AISObjectMap.end();
-    for (; aFIt != aFLast && !aFeature; aFIt++) {
-      Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
-      if (anAIS != anIO)
-        continue;
-      aFeature = (*aFIt).first;
-    }
+    boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
+    if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
+      continue;
+    aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
+    aPrsFeatures.insert(aFeature);
+  }
+  return aPresentations;
+}
+
+std::list<XGUI_ViewerPrs> XGUI_Displayer::GetHighlighted()
+{
+  std::set<boost::shared_ptr<ModelAPI_Feature> > aPrsFeatures;
+  std::list<XGUI_ViewerPrs> aPresentations;
+
+  Handle(AIS_InteractiveContext) aContext = AISContext();
+  for (aContext->InitDetected(); aContext->MoreDetected(); aContext->NextDetected()) {
+    Handle(AIS_InteractiveObject) anIO = aContext->DetectedInteractive();
+    TopoDS_Shape aShape = aContext->DetectedShape();
+
+    boost::shared_ptr<ModelAPI_Feature> aFeature = GetFeature(anIO);
     if (aPrsFeatures.find(aFeature) != aPrsFeatures.end())
       continue;
     aPresentations.push_back(XGUI_ViewerPrs(aFeature, aShape));
@@ -203,7 +215,12 @@ void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, c
   boost::shared_ptr<ModelAPI_Feature> aFeature;
 
   Handle(AIS_Shape) anAIS;
-  aContext->ClearSelected();
+  // we need to unhighligth objects manually in the current local context
+  // in couple with the selection clear (TODO)
+  Handle(AIS_LocalContext) aLocalContext = aContext->LocalContext();
+  if (!aLocalContext.IsNull())
+    aLocalContext->UnhilightLastDetected(myWorkshop->viewer()->activeView());
+  aContext->ClearSelected(false);
 
   for (; anIt != aLast; anIt++) {
     aFeature = (*anIt).feature();
@@ -213,6 +230,7 @@ void XGUI_Displayer::SetSelected(const std::list<XGUI_ViewerPrs>& theFeatures, c
       continue;
     aContext->AddOrRemoveSelected(anAIS, false);
   }
   if (isUpdateViewer)
     aContext->UpdateCurrentViewer();
 }
@@ -267,10 +285,24 @@ void XGUI_Displayer::EraseDeletedFeatures(const bool isUpdateViewer)
 
 void XGUI_Displayer::CloseLocalContexts(const bool isUpdateViewer)
 {
-  closeAllContexts(true);
+  CloseAllContexts(true);
+}
+
+boost::shared_ptr<ModelAPI_Feature> XGUI_Displayer::GetFeature(Handle(AIS_InteractiveObject) theIO)
+{
+  boost::shared_ptr<ModelAPI_Feature> aFeature;
+  FeatureToAISMap::const_iterator aFIt = myFeature2AISObjectMap.begin(),
+                                  aFLast = myFeature2AISObjectMap.end();
+  for (; aFIt != aFLast && !aFeature; aFIt++) {
+    Handle(AIS_InteractiveObject) anAIS = (*aFIt).second;
+    if (anAIS != theIO)
+      continue;
+    aFeature = (*aFIt).first;
+  }
+  return aFeature;
 }
 
-void XGUI_Displayer::closeAllContexts(const bool isUpdateViewer)
+void XGUI_Displayer::CloseAllContexts(const bool isUpdateViewer)
 {
   Handle(AIS_InteractiveContext) ic = AISContext();
   if (!ic.IsNull()) {
index 5973cd67e6d1ce064356503dff519a7b2514201e..080fef76a2ae4ed9e7c691599ec001e6da1fdb78 100644 (file)
@@ -58,9 +58,13 @@ public:
   //void Display(boost::shared_ptr<ModelAPI_Feature> theFeature, const TopoDS_Shape& theShape,
   //             const bool isUpdateViewer = true);
   
-  /// Returns a list of viewer presentations
+  /// Returns a list of viewer selected presentations
   /// \return list of presentations
-  std::list<XGUI_ViewerPrs> GetViewerPrs();
+  std::list<XGUI_ViewerPrs> GetSelected();
+
+  /// Returns a list of viewer highlited presentations
+  /// \return list of presentations
+  std::list<XGUI_ViewerPrs> GetHighlighted();
 
   /// Display the shape and activate selection of sub-shapes
   /// \param theFeature a feature instance
@@ -111,9 +115,13 @@ public:
   void UpdateViewer();
 
 protected:
+  /// Searches the feature by interactive object
+  /// \param theIO an interactive object
+  /// \return feature the feature or NULL if it not visualized
+  boost::shared_ptr<ModelAPI_Feature> GetFeature(Handle(AIS_InteractiveObject) theIO);
   /// Deactivate local selection
   /// \param isUpdateViewer the state wether the viewer should be updated immediatelly
-  void closeAllContexts(const bool isUpdateViewer);
+  void CloseAllContexts(const bool isUpdateViewer);
 
   /// Returns currently installed AIS_InteractiveContext
   Handle(AIS_InteractiveContext) AISContext() const;
index 734a1a469e48ab9ff6bbed1d29a8302e6c63ab13..3d5af347ade6fc484c4c3f65ec9856abe9ff698f 100644 (file)
@@ -506,9 +506,9 @@ void XGUI_Viewer::onMousePressed(XGUI_ViewWindow* theWindow, QMouseEvent* theEve
 */
 void XGUI_Viewer::onMouseMove(XGUI_ViewWindow* theWindow, QMouseEvent* theEvent)
 {
+  myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
   if (!mySelectionEnabled) return;
 
-  myCurPnt.setX(theEvent->x()); myCurPnt.setY(theEvent->y());
   Handle(V3d_View) aView3d = theWindow->viewPort()->getView();
   if ( !aView3d.IsNull() ) {
     myAISContext->MoveTo(theEvent->x(), theEvent->y(), aView3d);