From: vsv Date: Tue, 30 Dec 2014 09:51:13 +0000 (+0300) Subject: Issue #332: Find point by coordinates comparison instead selection X-Git-Tag: V_0.7.0_rc1~11 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2d309adb3c465a840e8f5ceeba28ec145e5a45a2;p=modules%2Fshaper.git Issue #332: Find point by coordinates comparison instead selection --- diff --git a/src/PartSet/PartSet_Module.cpp b/src/PartSet/PartSet_Module.cpp index c1348168e..e3807bd7e 100644 --- a/src/PartSet/PartSet_Module.cpp +++ b/src/PartSet/PartSet_Module.cpp @@ -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(); diff --git a/src/PartSet/PartSet_Module.h b/src/PartSet/PartSet_Module.h index 8fa932b39..9723d53e3 100644 --- a/src/PartSet/PartSet_Module.h +++ b/src/PartSet/PartSet_Module.h @@ -122,7 +122,7 @@ protected slots: virtual void registerFilters(); private slots: - void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape); + void onVertexSelected(); private: diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 78df67edb..dbecad94d 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -308,6 +308,35 @@ void PartSet_Tools::createConstraint(CompositeFeaturePtr theSketch, aFeature->execute(); } +std::shared_ptr PartSet_Tools:: + findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY, + double theTolerance, const QList& theIgnore) +{ + std::shared_ptr aClickedPoint = std::shared_ptr( + new GeomAPI_Pnt2d(theX, theY)); + + std::list > 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 >::const_iterator anIt; + for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) { + std::shared_ptr aCurPoint = + std::dynamic_pointer_cast(*anIt); + double x = aCurPoint->x(); + double y = aCurPoint->y(); + if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) { + return aCurPoint; + } + } + } + } + return std::shared_ptr(); +} + + 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 aFPoint; for (; anIt != aLast && !aFPoint; anIt++) { - std::shared_ptr aCurPoint = std::dynamic_pointer_cast< - GeomDataAPI_Point2D>(*anIt); - if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion()) + std::shared_ptr aCurPoint = + std::dynamic_pointer_cast(*anIt); + if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) { aFPoint = aCurPoint; + break; + } } if (aFPoint) PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint); diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index e3579c9f5..05104bb01 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -78,6 +78,9 @@ class PARTSET_EXPORT PartSet_Tools static std::shared_ptr document(); + static std::shared_ptr findAttributePoint(CompositeFeaturePtr theSketch, + double theX, double theY, double theTolerance, const QList& theIgnore = QList()); + /// Returns a point attribute of the feature by the coordinates if it is /// \param theFeature the feature /// \param theX the horizontal coordinate diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 26f8f6537..5baa133e7 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -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 aShapes; - std::list 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 aShapes; + //std::list 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 aFeaturePoint = std::dynamic_pointer_cast< + GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID())); + QList aIgnore; + aIgnore.append(feature()); + + double aTolerance = aView->Convert(4); + std::shared_ptr aAttrPnt = + PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore); + if (aAttrPnt.get() != NULL) { + + PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint); + emit vertexSelected(); + } emit focusOutWidget(this); } diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index 69e6461ea..ad0395461 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -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);