From: spo Date: Tue, 7 Jul 2015 12:27:53 +0000 (+0300) Subject: Issue #718 - Translation with parameters - wrong coordinates X-Git-Tag: V_1.3.0~89 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=32f6c2d8959088d7083711d79ffb7bdc8426f4c7;p=modules%2Fshaper.git Issue #718 - Translation with parameters - wrong coordinates --- diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 7ae96b859..4fcf2735b 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -12,7 +12,7 @@ using namespace std; -void GeomData_Point::setValue(const double theX, const double theY, const double theZ) +void GeomData_Point::setCalculatedValue(const double theX, const double theY, const double theZ) { if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY || myCoords->Value(2) != theZ) { @@ -23,6 +23,13 @@ void GeomData_Point::setValue(const double theX, const double theY, const double } } +void GeomData_Point::setValue(const double theX, const double theY, const double theZ) +{ + setCalculatedValue(textX().empty() ? theX : x(), + textY().empty() ? theY : y(), + textZ().empty() ? theZ : z()); +} + void GeomData_Point::setValue(const std::shared_ptr& thePoint) { setValue(thePoint->x(), thePoint->y(), thePoint->z()); diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index 30ac5310f..f01814359 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -39,6 +39,9 @@ class GeomData_Point : public GeomDataAPI_Point /// Returns the 3D point GEOMDATA_EXPORT virtual std::shared_ptr pnt(); + /// Defines the calculated double value + GEOMDATA_EXPORT virtual void setCalculatedValue(const double theX, const double theY, const double theZ); + /// Defines the text values GEOMDATA_EXPORT virtual void setText(const std::string& theX, const std::string& theY, diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index e02de3eef..9b21c8a5c 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -12,7 +12,7 @@ using namespace std; -void GeomData_Point2D::setValue(const double theX, const double theY) +void GeomData_Point2D::setCalculatedValue(const double theX, const double theY) { if (!myIsInitialized || myCoords->Value(0) != theX || myCoords->Value(1) != theY) { myCoords->SetValue(0, theX); @@ -21,6 +21,12 @@ void GeomData_Point2D::setValue(const double theX, const double theY) } } +void GeomData_Point2D::setValue(const double theX, const double theY) +{ + setCalculatedValue(textX().empty() ? theX : x(), + textY().empty() ? theY : y()); +} + void GeomData_Point2D::setValue(const std::shared_ptr& thePoint) { setValue(thePoint->x(), thePoint->y()); diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h index 8a41a4c0c..503674150 100644 --- a/src/GeomData/GeomData_Point2D.h +++ b/src/GeomData/GeomData_Point2D.h @@ -37,11 +37,14 @@ class GeomData_Point2D : public GeomDataAPI_Point2D /// Returns the 2D point GEOMDATA_EXPORT virtual std::shared_ptr pnt(); - /// Defines the double values + /// Defines the calculated double value + GEOMDATA_EXPORT virtual void setCalculatedValue(const double theX, const double theY); + + /// Defines the text values GEOMDATA_EXPORT virtual void setText(const std::string& theX, const std::string& theY); - /// Returns the double values + /// Returns the text values GEOMDATA_EXPORT virtual std::string textX(); GEOMDATA_EXPORT virtual std::string textY(); diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index a940b62cb..e021a4a1a 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -34,12 +34,15 @@ class GeomDataAPI_Point : public ModelAPI_Attribute /// Returns the 3D point GEOMDATAAPI_EXPORT virtual std::shared_ptr pnt() = 0; - /// Defines the double values + /// Defines the calculated double value + GEOMDATAAPI_EXPORT virtual void setCalculatedValue(const double theX, const double theY, const double theZ) = 0; + + /// Defines the text values GEOMDATAAPI_EXPORT virtual void setText(const std::string& theX, const std::string& theY, const std::string& theZ) = 0; - /// Returns the double values + /// Returns the text values GEOMDATAAPI_EXPORT virtual std::string textX() = 0; GEOMDATAAPI_EXPORT virtual std::string textY() = 0; GEOMDATAAPI_EXPORT virtual std::string textZ() = 0; diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h index c693456a9..3da9d2f00 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.h +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -32,11 +32,14 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute /// Returns the 2D point GEOMDATAAPI_EXPORT virtual std::shared_ptr pnt() = 0; - /// Defines the double values + /// Defines the calculated double value + GEOMDATAAPI_EXPORT virtual void setCalculatedValue(const double theX, const double theY) = 0; + + /// Defines the text values GEOMDATAAPI_EXPORT virtual void setText(const std::string& theX, const std::string& theY) = 0; - /// Returns the double values + /// Returns the text values GEOMDATAAPI_EXPORT virtual std::string textX() = 0; GEOMDATAAPI_EXPORT virtual std::string textY() = 0; diff --git a/src/Model/Model_AttributeDouble.cpp b/src/Model/Model_AttributeDouble.cpp index 0736eddc0..6128aa892 100644 --- a/src/Model/Model_AttributeDouble.cpp +++ b/src/Model/Model_AttributeDouble.cpp @@ -15,7 +15,7 @@ using namespace std; -void Model_AttributeDouble::setValue(const double theValue) +void Model_AttributeDouble::setCalculatedValue(const double theValue) { if (!myIsInitialized || myReal->Get() != theValue) { myReal->Set(theValue); @@ -23,6 +23,11 @@ void Model_AttributeDouble::setValue(const double theValue) } } +void Model_AttributeDouble::setValue(const double theValue) +{ + setCalculatedValue(text().empty() ? theValue : value()); +} + double Model_AttributeDouble::value() { return myReal->Get(); diff --git a/src/Model/Model_AttributeDouble.h b/src/Model/Model_AttributeDouble.h index 6c9999365..d93b60673 100644 --- a/src/Model/Model_AttributeDouble.h +++ b/src/Model/Model_AttributeDouble.h @@ -30,10 +30,13 @@ class Model_AttributeDouble : public ModelAPI_AttributeDouble /// Returns the double value MODEL_EXPORT virtual double value(); - /// Defines the double value + /// Defines the calculated double value + MODEL_EXPORT virtual void setCalculatedValue(const double theValue); + + /// Defines the text value MODEL_EXPORT virtual void setText(const std::string& theText); - /// Returns the double value + /// Returns the text value MODEL_EXPORT virtual std::string text(); /// Allows to set expression (text) as invalid (by the parameters listener) diff --git a/src/ModelAPI/ModelAPI_AttributeDouble.h b/src/ModelAPI/ModelAPI_AttributeDouble.h index d30b11c49..f2b01862b 100644 --- a/src/ModelAPI/ModelAPI_AttributeDouble.h +++ b/src/ModelAPI/ModelAPI_AttributeDouble.h @@ -23,10 +23,13 @@ class ModelAPI_AttributeDouble : public ModelAPI_Attribute /// Returns the double value MODELAPI_EXPORT virtual double value() = 0; - /// Defines the double value + /// Defines the calculated double value + MODELAPI_EXPORT virtual void setCalculatedValue(const double theValue) = 0; + + /// Defines the text value MODELAPI_EXPORT virtual void setText(const std::string& theText) = 0; - /// Returns the double value + /// Returns the text value MODELAPI_EXPORT virtual std::string text() = 0; /// Allows to set expression (text) as invalid (by the parameters listener) diff --git a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp index c32723cfb..3e53238b8 100644 --- a/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp +++ b/src/ParametersPlugin/ParametersPlugin_EvalListener.cpp @@ -96,7 +96,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( std::string anError; double aValue = evaluate(aDoubleAttribute->text(), anError); if (anError.empty()) { - aDoubleAttribute->setValue(aValue); + aDoubleAttribute->setCalculatedValue(aValue); aDoubleAttribute->setExpressionInvalid(false); } else { // set feature as invalid-parameter arguments aDoubleAttribute->setExpressionInvalid(true); @@ -122,7 +122,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( aPointAttribute->setExpressionInvalid(1, !isValid[1]); aPointAttribute->setExpressionInvalid(2, !isValid[2]); - aPointAttribute->setValue( + aPointAttribute->setCalculatedValue( isValid[0] ? aValue[0] : aPointAttribute->x(), isValid[1] ? aValue[1] : aPointAttribute->y(), isValid[2] ? aValue[2] : aPointAttribute->z() @@ -145,7 +145,7 @@ void ParametersPlugin_EvalListener::processEvaluationEvent( aPoint2DAttribute->setExpressionInvalid(0, !isValid[0]); aPoint2DAttribute->setExpressionInvalid(1, !isValid[1]); - aPoint2DAttribute->setValue( + aPoint2DAttribute->setCalculatedValue( isValid[0] ? aValue[0] : aPoint2DAttribute->x(), isValid[1] ? aValue[1] : aPoint2DAttribute->y() ); diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index e48dc8b0e..977e890a3 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -165,13 +165,14 @@ bool PartSet_WidgetPoint2D::storeValueCustom() const PartSet_WidgetPoint2D* that = (PartSet_WidgetPoint2D*) this; bool isBlocked = that->blockSignals(true); bool isImmutable = aPoint->setImmutable(true); - - if (myXSpin->hasVariable() || myYSpin->hasVariable()) { - aPoint->setText(myXSpin->text().toStdString(), myYSpin->text().toStdString()); - } else { - aPoint->setValue(myXSpin->value(), myYSpin->value()); - aPoint->setText("", ""); - } + + // if text is not empty then setValue will be ignored + // so we should set the text at first + aPoint->setText(myXSpin->hasVariable() ? myXSpin->text().toStdString() : "", + myYSpin->hasVariable() ? myYSpin->text().toStdString() : ""); + aPoint->setValue(!myXSpin->hasVariable() ? myXSpin->value() : aPoint->x(), + !myYSpin->hasVariable() ? myYSpin->value() : aPoint->y()); + // after movement the solver will call the update event: optimization moveObject(myFeature); aPoint->setImmutable(isImmutable); diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index b4aa3d2cd..16c4488bc 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -32,6 +32,7 @@ SET(PROJECT_HEADERS SketchPlugin_MultiTranslation.h SketchPlugin_ExternalValidator.h SketchPlugin_Validators.h + SketchPlugin_Tools.h ) SET(PROJECT_SOURCES @@ -61,6 +62,7 @@ SET(PROJECT_SOURCES SketchPlugin_MultiTranslation.cpp SketchPlugin_ExternalValidator.cpp SketchPlugin_Validators.cpp + SketchPlugin_Tools.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 362e7f56f..97cf4e0fd 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -287,6 +288,8 @@ FeaturePtr SketchPlugin_Sketch::addUniqueNamedCopiedFeature(FeaturePtr theFeatur theFeature->data()->copyTo(aNewFeature->data()); // as a name for the feature, the generated unique name is set aNewFeature->data()->setName(aUniqueFeatureName); + // text expressions could block setValue of some attributes + clearExpressions(aNewFeature); return aNewFeature; }