]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #332: Find point by coordinates comparison instead selection
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 30 Dec 2014 09:51:13 +0000 (12:51 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 30 Dec 2014 09:51:13 +0000 (12:51 +0300)
src/PartSet/PartSet_Module.cpp
src/PartSet/PartSet_Module.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h

index c1348168e8dd5be66e7c0312af78dbb61aa8bc44..e3807bd7ec4cae95a3c9c0836339f2ff58b76d71 100644 (file)
@@ -303,7 +303,7 @@ void PartSet_Module::onNoMoreWidgets()
   }
 }
 
-void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
+void PartSet_Module::onVertexSelected()
 {
   ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
   if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
@@ -335,8 +335,7 @@ QWidget* PartSet_Module::createWidgetByType(const std::string& theType, QWidget*
     aWgt->setWorkshop(aWorkshop);
     aWgt->setSketch(mySketchMgr->activeSketch());
 
-    connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)), 
-      this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
+    connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
 
     theModelWidgets.append(aWgt);
     return aWgt->getControl();
index 8fa932b39f21b9d24a6fd77d9e6d04a65b448ae0..9723d53e3684b01f6fb42840e34ff0bdcd32c86d 100644 (file)
@@ -122,7 +122,7 @@ protected slots:
   virtual void registerFilters();
 
  private slots:
-   void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+   void onVertexSelected();
 
 
  private:
index 78df67edb61f3a0f9a98e7400a2e967329eb67e8..dbecad94d3081513bcc2beeff6d4058356627444 100644 (file)
@@ -308,6 +308,35 @@ void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch,
     aFeature->execute();
 }
 
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+  findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
+  double theTolerance, const QList<FeaturePtr>& theIgnore)
+{
+  std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+      new GeomAPI_Pnt2d(theX, theY));
+
+  std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+  for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+    FeaturePtr aFeature = theSketch->subFeature(i);
+    if (!theIgnore.contains(aFeature)) {
+      anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+
+      std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
+      for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
+        std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+        double x = aCurPoint->x();
+        double y = aCurPoint->y();
+        if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
+          return aCurPoint;
+        }
+      }
+    }
+  }
+  return std::shared_ptr<GeomDataAPI_Point2D>();
+}
+
+
 void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
                                    const std::string& theAttribute, double theClickedX,
                                    double theClickedY)
@@ -338,10 +367,12 @@ void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr the
         aLast = anAttiributes.end();
     std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
     for (; anIt != aLast && !aFPoint; anIt++) {
-      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
-          GeomDataAPI_Point2D>(*anIt);
-      if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
+      std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = 
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+      if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
         aFPoint = aCurPoint;
+        break;
+      }
     }
     if (aFPoint)
       PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
index e3579c9f56b5958559ce8d88e132381a1d696284..05104bb016714dc2e42ab9d47173c04d054c753a 100644 (file)
@@ -78,6 +78,9 @@ class PARTSET_EXPORT PartSet_Tools
   static std::shared_ptr<ModelAPI_Document> document();
 
 
+  static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch, 
+    double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+
   /// Returns a point attribute of the feature by the coordinates if it is
   /// \param theFeature the feature
   /// \param theX the horizontal coordinate
index 26f8f65374be43e28cf5a2853e35c86f50a1da93..5baa133e7e279303c0581dfd5c2d065cc1edcc8c 100644 (file)
@@ -229,27 +229,44 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
 void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
 {
   XGUI_Selection* aSelection = myWorkshop->selector()->selection();
-  NCollection_List<TopoDS_Shape> aShapes;
-  std::list<ObjectPtr> aObjects;
-  aSelection->selectedShapes(aShapes, aObjects);
-  if (aShapes.Extent() > 0) {
-    TopoDS_Shape aShape = aShapes.First();
-    double aX, aY;
-    if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
-      setPoint(aX, aY);
-
-      PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
-      emit vertexSelected(aObjects.front(), aShape);
-      emit focusOutWidget(this);
-      return;
-    }
-  }
+  // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
+  //NCollection_List<TopoDS_Shape> aShapes;
+  //std::list<ObjectPtr> aObjects;
+  //aSelection->selectedShapes(aShapes, aObjects);
+  //if (aShapes.Extent() > 0) {
+  //  TopoDS_Shape aShape = aShapes.First();
+  //  double aX, aY;
+  //  if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
+  //    setPoint(aX, aY);
+
+  //    PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+  //    emit vertexSelected(aObjects.front(), aShape);
+  //    emit focusOutWidget(this);
+  //    return;
+  //  }
+  //}
+  // End of Bug dependent fragment
+
   // A case when point is taken from mouse event
   gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
   double aX, anY;
-  PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+  Handle(V3d_View) aView = theWnd->v3dView();
+  PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
   setPoint(aX, anY);
 
+  std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+      GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+  QList<FeaturePtr> aIgnore;
+  aIgnore.append(feature());
+
+  double aTolerance = aView->Convert(4);
+  std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt = 
+    PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+  if (aAttrPnt.get() != NULL) {
+
+    PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+    emit vertexSelected();
+  }
   emit focusOutWidget(this);
 }
 
index 69e6461ea75b3038667c4743ee9d75c0f2f00dd6..ad0395461f2375f1ac8a4b0c2ad3578f4b69c23a 100644 (file)
@@ -92,7 +92,7 @@ signals:
   /// Signal about selection of an existing vertex from an object
   /// \param theObject - the selected object
   /// \param theShape - the selected shape
-  void vertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+  void vertexSelected();
 
 protected slots:
   void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);