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);
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)
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.");
}
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;
}
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;
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
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();
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);
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();
}