From 10f0f48c36b418c844bdb845428a2d374cc810ab Mon Sep 17 00:00:00 2001 From: vsv Date: Thu, 29 Jan 2015 15:46:47 +0300 Subject: [PATCH] Issue #61: Limit input of points coordinates by 1e12 value --- src/PartSet/PartSet_WidgetPoint2d.cpp | 17 ++++++++++++----- src/PartSet/PartSet_WidgetPoint2d.h | 3 ++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 1e061643c..a8cd1a823 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -44,6 +44,9 @@ #include #include +const double MaxCoordinate = 1e12; + + PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent, const Config_WidgetAPI* theData, const std::string& theParentId) @@ -98,15 +101,17 @@ bool PartSet_WidgetPoint2D::setSelection(ModuleBase_ViewerPrs theValue) TopoDS_Shape aShape = theValue.shape(); double aX, aY; if (getPoint2d(aView, aShape, aX, aY)) { - setPoint(aX, aY); - isDone = true; + isDone = setPoint(aX, aY); } return isDone; } -void PartSet_WidgetPoint2D::setPoint(double theX, double theY) +bool PartSet_WidgetPoint2D::setPoint(double theX, double theY) { - + if (fabs(theX) >= MaxCoordinate) + return false; + if (fabs(theY) >= MaxCoordinate) + return false; bool isBlocked = this->blockSignals(true); myXSpin->blockSignals(true); myXSpin->setValue(theX); @@ -118,6 +123,7 @@ void PartSet_WidgetPoint2D::setPoint(double theX, double theY) this->blockSignals(isBlocked); emit valuesChanged(); + return true; } bool PartSet_WidgetPoint2D::storeValue() const @@ -257,7 +263,8 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous double aX, anY; Handle(V3d_View) aView = theWnd->v3dView(); PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY); - //setPoint(aX, anY); + if (!setPoint(aX, anY)) + return; std::shared_ptr aFeaturePoint = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID())); diff --git a/src/PartSet/PartSet_WidgetPoint2d.h b/src/PartSet/PartSet_WidgetPoint2d.h index b5ee13c47..bb5006963 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.h +++ b/src/PartSet/PartSet_WidgetPoint2d.h @@ -87,7 +87,8 @@ Q_OBJECT /// Fill the widget values by given point /// \param theX the X coordinate /// \param theY the Y coordinate - void setPoint(double theX, double theY); + /// \returns True in case of success + bool setPoint(double theX, double theY); /// Returns coordinate X currently defined in the control double x() const; -- 2.39.2