X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FPartSet%2FPartSet_WidgetPoint2d.cpp;h=d21d25f0a835ed19efefaa56446cf9425e840b4c;hb=6f1da290c7a4db4432c28887ad9d4073c8d443cb;hp=8c7ce43fc482323b5fdcdb79f6936abf7f2f430e;hpb=cbe48c6adf00fd007031969be04ea1b699e00d37;p=modules%2Fshaper.git diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 8c7ce43fc..d21d25f0a 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -11,7 +11,6 @@ #include #include -#include #include #include #include @@ -89,19 +88,15 @@ PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D() { } -bool PartSet_WidgetPoint2D::setValue(ModuleBase_WidgetValue* theValue) +bool PartSet_WidgetPoint2D::setSelection(ModuleBase_ViewerPrs theValue) { + Handle(V3d_View) aView = myWorkshop->viewer()->activeView(); bool isDone = false; - if (theValue) { - ModuleBase_WidgetValueFeature* aFeatureValue = - dynamic_cast(theValue); - if (aFeatureValue) { - std::shared_ptr aPoint = aFeatureValue->point(); - if (aPoint) { - setPoint(aPoint->x(), aPoint->y()); - isDone = true; - } - } + TopoDS_Shape aShape = theValue.shape(); + double aX, aY; + if (getPoint2d(aView, aShape, aX, aY)) { + setPoint(aX, aY); + isDone = true; } return isDone; } @@ -213,6 +208,24 @@ void PartSet_WidgetPoint2D::deactivate() myWorkshop->moduleConnector()->deactivateSubShapesSelection(); } +bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView, + const TopoDS_Shape& theShape, + double& theX, double& theY) const +{ + if (!theShape.IsNull()) { + if (theShape.ShapeType() == TopAbs_VERTEX) { + const TopoDS_Vertex& aVertex = TopoDS::Vertex(theShape); + if (!aVertex.IsNull()) { + // A case when point is taken from existing vertex + gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); + PartSet_Tools::convertTo2D(aPoint, mySketch, theView, theX, theY); + return true; + } + } + } + return false; +} + void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent) { @@ -222,23 +235,15 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous aSelection->selectedShapes(aShapes, aObjects); if (aShapes.Extent() > 0) { TopoDS_Shape aShape = aShapes.First(); - if (!aShape.IsNull()) { - if (aShape.ShapeType() == TopAbs_VERTEX) { - const TopoDS_Vertex& aVertex = TopoDS::Vertex(aShape); - if (!aVertex.IsNull()) { - // A case when point is taken from existing vertex - gp_Pnt aPoint = BRep_Tool::Pnt(aVertex); - double aX, aY; - PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, aY); - setPoint(aX, aY); - - PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY); - emit vertexSelected(aObjects.front(), aShape); - QApplication::processEvents(); - emit focusOutWidget(this); - return; - } - } + 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); + QApplication::processEvents(); + emit focusOutWidget(this); + return; } } // A case when point is taken from mouse event