]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Avoid of reference to not-initialized attributes values
authormpv <mpv@opencascade.com>
Thu, 18 Aug 2016 09:17:17 +0000 (12:17 +0300)
committermpv <mpv@opencascade.com>
Thu, 18 Aug 2016 09:17:17 +0000 (12:17 +0300)
src/GeomData/GeomData_Point2D.cpp
src/GeomValidators/GeomValidators_Different.cpp
src/Model/Model_Expression.cpp
src/ModuleBase/ModuleBase_WidgetDoubleValue.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/SketchPlugin/SketchPlugin_Arc.cpp
src/SketchPlugin/SketchPlugin_ConstraintAngle.cpp
src/SketchPlugin/SketchPlugin_ConstraintLength.cpp
src/SketcherPrs/SketcherPrs_Tools.cpp

index fb7bdc99f2fc0b9ed89483344d7f2b1065705d1f..8b6116b63e51cf7fd7e019d5088cd291119c562b 100644 (file)
@@ -59,6 +59,8 @@ std::shared_ptr<GeomAPI_Pnt2d> 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);
index 617161f9c1624faad28e75b0ceaab38191e0c956..8c324f40b70ec2ce2c9d2a8560cc340f7a8e0535 100644 (file)
@@ -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)
index 1624e8d02ddc21250a80bfb5093dcab14f9e570a..73484f32808d7d970f179e5c6bdc618bdd251b78 100644 (file)
@@ -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.");
 }
index 296f0e0caaeb1d1b90399c10a9fe6b0d3b8f27cf..9dc18d5981db4b0c238bdf77e58dcb2c4787bac8 100644 (file)
@@ -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;
 }
index f4490eb7301c5869cafa46bfb40448b33c06b1bf..a36b0a0c1bff9acaffccf8a32258baad5886f09a 100644 (file)
@@ -275,8 +275,8 @@ bool PartSet_WidgetPoint2D::restoreValueCustom()
   std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
   std::shared_ptr<GeomDataAPI_Point2D> aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       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;
index 5ba8163ea1618e85e1d821d47da324ec60e15d3b..9873f01afcdf4bffb1a6f3126886a80a0f0536d8 100644 (file)
@@ -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
index e66758f034347fdc6e765e30a82bf04b412d2f7f..2bf082f6145f721c1805406b3766aaeae2b5e009 100644 (file)
@@ -255,7 +255,8 @@ bool SketchPlugin_ConstraintAngle::compute(const std::string& theAttributeId)
 
   std::shared_ptr<GeomDataAPI_Point2D> 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();
index 949908b293f628672969fdd7e52a85d5b3204d34..ba18dae3e82b711fe03b25772d411ff0aaee6932 100644 (file)
@@ -93,7 +93,8 @@ bool SketchPlugin_ConstraintLength::compute(const std::string& theAttributeId)
 
   std::shared_ptr<GeomAPI_Lin2d> aLine = 
     std::shared_ptr<GeomAPI_Lin2d>(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<GeomAPI_Pnt2d> aFPnt = aLine->shiftedLocation(aDist);
     aFlyOutAttr->setValue(aFPnt);
index 84d0878f66df2d68817c3f3f12620e322a5bd50b..b8e37cc53219fad4b3248a423e77942ea8077958 100644 (file)
@@ -246,7 +246,9 @@ double getFlyoutDistance(const ModelAPI_Feature* theConstraint)
   std::shared_ptr<GeomDataAPI_Point2D> aFlyoutPoint =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
       const_cast<ModelAPI_Feature*>(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();
 }