]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #208 - A correction to filter the selected/highlighted objects to belong the...
authornds <natalia.donis@opencascade.com>
Mon, 10 Nov 2014 10:39:42 +0000 (13:39 +0300)
committernds <natalia.donis@opencascade.com>
Mon, 10 Nov 2014 10:39:42 +0000 (13:39 +0300)
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h

index d1369536111582223c3d8a32afcfb399a680a85d..364d7c9d20e1b0985cd195a0d0ae2f46c89a6d15 100644 (file)
@@ -152,13 +152,25 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
                                         FeaturePtr theSketch,
                                         const QList<ModuleBase_ViewerPrs>& theSelected,
                                         const QList<ModuleBase_ViewerPrs>& theHighlighted)
+{
+  // firstly it finds the feature in the list of highlight
+  ObjectPtr aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theHighlighted);
+  if (!aDeltaObject)
+    // secondly it finds the feature in the list of selected objects
+    aDeltaObject  = nearestFeature(thePoint, theView, theSketch, theSelected);
+
+  return aDeltaObject;
+}
+
+ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView,
+                                        FeaturePtr theSketch,
+                                        const QList<ModuleBase_ViewerPrs>& thePresentations)
 {
   ObjectPtr aDeltaObject;
-  // 1. find the object in the highlighted list
-  if (theHighlighted.size() > 0) {
-    aDeltaObject = theHighlighted.first().object();
-  }
-  // 2. find it in the selected list by the selected point
+
+  CompositeFeaturePtr aSketch = 
+      boost::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
+  // 1. find it in the selected list by the selected point
   if (!aDeltaObject) {
     double aX, anY;
     gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(thePoint, theView);
@@ -167,13 +179,13 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
     FeaturePtr aFeature;
     double aMinDelta = -1;
     ModuleBase_ViewerPrs aPrs;
-    foreach (ModuleBase_ViewerPrs aPrs, theSelected) {
+    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
       if (!aPrs.object())
         continue;
       FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
       boost::shared_ptr<SketchPlugin_Feature> aSketchFeature = boost::dynamic_pointer_cast<
           SketchPlugin_Feature>(aFeature);
-      if (!aSketchFeature)
+      if (!aSketchFeature || !aSketch->isSub(aSketchFeature))
         continue;
 
       double aDelta = aSketchFeature->distanceToPoint(
@@ -184,10 +196,17 @@ ObjectPtr PartSet_Tools::nearestFeature(QPoint thePoint, Handle_V3d_View theView
       }
     }
   }
-  // 3. if the object is not found, returns the first selected one
-  if (!aDeltaObject && theSelected.size() > 0)
-    aDeltaObject = theSelected.first().object();
-
+  // 2. if the object is not found, returns the first selected sketch feature
+  if (!aDeltaObject && thePresentations.size() > 0) {
+    // there can be some highlighted objects, e.g. a result of boolean operation and a sketch point
+    foreach (ModuleBase_ViewerPrs aPrs, thePresentations) {
+      if (!aPrs.object())
+        continue;
+      FeaturePtr aFeature = ModelAPI_Feature::feature(aPrs.object());
+      if (aFeature && aSketch->isSub(aFeature))
+        aDeltaObject = aPrs.object();
+    }
+  }
   return aDeltaObject;
 }
 
index 912db7307b5b9de3be76a4e3ca7b53b629193fb4..30838ae09f66fc9869e36d6e48c87a3d5a7421e0 100644 (file)
@@ -160,6 +160,18 @@ class PARTSET_EXPORT PartSet_Tools
   /// \param theY the output vertical coordinate of the point
   static bool hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
                              Handle_V3d_View theView, double& theX, double& theY);
+protected:
+  /// Returns an object that is under the mouse point. Firstly it checks the highlighting,
+  /// if it exists, the first object is returned. Secondly, there is an iteration on
+  /// the selected list to find the point. Thirdly, if the object is not found under the
+  /// the point, the first selected object is returned.
+  /// \param thePoint a screen point
+  /// \param theView a 3D view
+  /// \param theSketch the sketch feature
+  /// \param thePresentations the list of presentations
+  static ObjectPtr nearestFeature(QPoint thePoint, Handle_V3d_View theView, FeaturePtr theSketch,
+                                  const QList<ModuleBase_ViewerPrs>& thePresentations);
+
 };
 
 #endif