From: mpv Date: Thu, 18 Aug 2016 09:17:17 +0000 (+0300) Subject: Avoid of reference to not-initialized attributes values X-Git-Tag: V_2.5.0~137^2~28 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2fa5d023f97dc00aa70c068d2ef29357136ed4d2;p=modules%2Fshaper.git Avoid of reference to not-initialized attributes values --- diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index fb7bdc99f..8b6116b63 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -59,6 +59,8 @@ std::shared_ptr GeomData_Point2D::pnt() void GeomData_Point2D::setText(const std::string& theX, const std::string& theY) { + if (!myIsInitialized && theX.empty() && theY.empty()) + return; // empty strings are not good initializers if (!myIsInitialized || textX() != theX || textY() != theY) { myExpression[0]->setText(theX); myExpression[1]->setText(theY); diff --git a/src/GeomValidators/GeomValidators_Different.cpp b/src/GeomValidators/GeomValidators_Different.cpp index 617161f9c..8c324f40b 100644 --- a/src/GeomValidators/GeomValidators_Different.cpp +++ b/src/GeomValidators/GeomValidators_Different.cpp @@ -27,7 +27,8 @@ To extend GeomValidators_Different validator with new attribute types: bool isEqual(const AttributePoint2DPtr& theLeft, const AttributePoint2DPtr& theRight) { - return theLeft->pnt()->distance(theRight->pnt()) < tolerance; + return theLeft->isInitialized() && theRight->isInitialized() && + theLeft->pnt()->distance(theRight->pnt()) < tolerance; } bool isEqualAttributes(const AttributePtr& theLeft, const AttributePtr& theRight) diff --git a/src/Model/Model_Expression.cpp b/src/Model/Model_Expression.cpp index 1624e8d02..73484f328 100644 --- a/src/Model/Model_Expression.cpp +++ b/src/Model/Model_Expression.cpp @@ -34,8 +34,10 @@ Model_Expression::Model_Expression(TDF_Label& theLabel) void Model_Expression::setText(const std::string& theValue) { - if (text() != theValue) + if (text() != theValue) { myText->Set(TCollection_ExtendedString(theValue.c_str())); + myIsInitialized = true; // the value will be set very soon + } setError(text().empty() ? "" : "Not a double value."); } diff --git a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp index 296f0e0ca..9dc18d598 100644 --- a/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp +++ b/src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp @@ -155,7 +155,7 @@ bool ModuleBase_WidgetDoubleValue::restoreValueCustom() if (!aTextRepr.empty()) { ModuleBase_Tools::setSpinText(mySpinBox, QString::fromStdString(aTextRepr)); } else { - ModuleBase_Tools::setSpinValue(mySpinBox, aRef->value()); + ModuleBase_Tools::setSpinValue(mySpinBox, aRef->isInitialized() ? aRef->value() : 0); } return true; } diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index f4490eb73..a36b0a0c1 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -275,8 +275,8 @@ bool PartSet_WidgetPoint2D::restoreValueCustom() std::shared_ptr aData = myFeature->data(); std::shared_ptr aPoint = std::dynamic_pointer_cast( aData->attribute(attributeID())); - QString aTextX = QString::fromStdString(aPoint->textX()); - QString aTextY = QString::fromStdString(aPoint->textY()); + QString aTextX = QString::fromStdString(aPoint->isInitialized() ? aPoint->textX() : "0"); + QString aTextY = QString::fromStdString(aPoint->isInitialized() ? aPoint->textY() : "0"); bool isDouble = false; double aVal = 0; diff --git a/src/SketchPlugin/SketchPlugin_Arc.cpp b/src/SketchPlugin/SketchPlugin_Arc.cpp index 5ba8163ea..9873f01af 100644 --- a/src/SketchPlugin/SketchPlugin_Arc.cpp +++ b/src/SketchPlugin/SketchPlugin_Arc.cpp @@ -486,11 +486,11 @@ void SketchPlugin_Arc::attributeChanged(const std::string& theID) double aNewAngle = aPassedParam >= aStartParam && aPassedParam <= aEndParam ? ((aEndParam - aStartParam) * 180.0 / PI) : ((aEndParam - aStartParam - 2.0 * PI) * 180.0 / PI); - if (fabs(aNewAngle - anAngleAttr->value()) > tolerance) + if (!anAngleAttr->isInitialized() || fabs(aNewAngle - anAngleAttr->value()) > tolerance) anAngleAttr->setValue(aNewAngle); } else { double aNewAngle = (aEndParam - aStartParam) * 180.0 / PI; - if (fabs(aNewAngle - anAngleAttr->value()) > tolerance) + if (!anAngleAttr->isInitialized() || fabs(aNewAngle - anAngleAttr->value()) > tolerance) anAngleAttr->setValue(aNewAngle); } // do not need to inform that other parameters were changed in this basis mode: these arguments diff --git a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp index e66758f03..2bf082f61 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp @@ -255,7 +255,8 @@ bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId) std::shared_ptr aFlyOutAttr = std::dynamic_pointer_cast< GeomDataAPI_Point2D>(attribute(theAttributeId)); - if (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance) + if (aFlyOutAttr->isInitialized() && + (fabs(aFlyOutAttr->x()) >= tolerance || fabs(aFlyOutAttr->y()) >= tolerance)) return false; DataPtr aData = data(); diff --git a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp index 949908b29..ba18dae3e 100644 --- a/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintLength.cpp @@ -93,7 +93,8 @@ bool SketchPlugin_ConstraintLength::compute(const std::string& theAttributeId) std::shared_ptr aLine = std::shared_ptr(new GeomAPI_Lin2d(aStartPoint->pnt(), anEndPoint->pnt())); - if (fabs(aFlyOutAttr->x()) < tolerance && fabs(aFlyOutAttr->y()) < tolerance) { + if (!aFlyOutAttr->isInitialized() || + (fabs(aFlyOutAttr->x()) < tolerance && fabs(aFlyOutAttr->y()) < tolerance)) { double aDist = aPoint1->distance(aPoint2)/5.; std::shared_ptr aFPnt = aLine->shiftedLocation(aDist); aFlyOutAttr->setValue(aFPnt); diff --git a/src/SketcherPrs/SketcherPrs_Tools.cpp b/src/SketcherPrs/SketcherPrs_Tools.cpp index 84d0878f6..b8e37cc53 100644 --- a/src/SketcherPrs/SketcherPrs_Tools.cpp +++ b/src/SketcherPrs/SketcherPrs_Tools.cpp @@ -246,7 +246,9 @@ double getFlyoutDistance(const ModelAPI_Feature* theConstraint) std::shared_ptr aFlyoutPoint = std::dynamic_pointer_cast( const_cast(theConstraint)->attribute(SketchPlugin_Constraint::FLYOUT_VALUE_PNT())); - + // for not initialized values return zero distance to avoid Presentation crash + if (!aFlyoutPoint->isInitialized()) + return 0; return aFlyoutPoint->y(); }