Salome HOME
Issue #718 - Translation with parameters - wrong coordinates
authorspo <sergey.pokhodenko@opencascade.com>
Tue, 7 Jul 2015 12:27:53 +0000 (15:27 +0300)
committerspo <sergey.pokhodenko@opencascade.com>
Tue, 7 Jul 2015 12:28:49 +0000 (15:28 +0300)
13 files changed:
src/GeomData/GeomData_Point.cpp
src/GeomData/GeomData_Point.h
src/GeomData/GeomData_Point2D.cpp
src/GeomData/GeomData_Point2D.h
src/GeomDataAPI/GeomDataAPI_Point.h
src/GeomDataAPI/GeomDataAPI_Point2D.h
src/Model/Model_AttributeDouble.cpp
src/Model/Model_AttributeDouble.h
src/ModelAPI/ModelAPI_AttributeDouble.h
src/ParametersPlugin/ParametersPlugin_EvalListener.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/SketchPlugin/CMakeLists.txt
src/SketchPlugin/SketchPlugin_Sketch.cpp

index 7ae96b859bb5ddf46a17392e669e785868ff625a..4fcf2735b7c9ed0c1f400ec2c581e0d266529f8f 100644 (file)
@@ -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<GeomAPI_Pnt>& thePoint)
 {
   setValue(thePoint->x(), thePoint->y(), thePoint->z());
index 30ac5310ff695d4ef5e15d055ce7b073e66013b9..f01814359d3766a3a3401cf00ed17d4d9d7e5289 100644 (file)
@@ -39,6 +39,9 @@ class GeomData_Point : public GeomDataAPI_Point
   /// Returns the 3D point
   GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> 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,
index e02de3eefd3f8ef0fd1237406bea959da05e5851..9b21c8a5c7939acd39a4c86e8266082b1acb9ea6 100644 (file)
@@ -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<GeomAPI_Pnt2d>& thePoint)
 {
   setValue(thePoint->x(), thePoint->y());
index 8a41a4c0c5056613619939b2bd0aabcebd914204..5036741505af82ce5e3c724a5c441e9588971dec 100644 (file)
@@ -37,11 +37,14 @@ class GeomData_Point2D : public GeomDataAPI_Point2D
   /// Returns the 2D point
   GEOMDATA_EXPORT virtual std::shared_ptr<GeomAPI_Pnt2d> 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();
 
index a940b62cbea33913db36ff33098a52b3ec202b1e..e021a4a1a266c7687fe66bd930d084dd50ef7d81 100644 (file)
@@ -34,12 +34,15 @@ class GeomDataAPI_Point : public ModelAPI_Attribute
   /// Returns the 3D point
   GEOMDATAAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt> 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;
index c693456a99f66b4636d43ff7665d9fcd758a7da4..3da9d2f009391dfcef1f12d90b50968836c77348 100644 (file)
@@ -32,11 +32,14 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute
   /// Returns the 2D point
   GEOMDATAAPI_EXPORT virtual std::shared_ptr<GeomAPI_Pnt2d> 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;
 
index 0736eddc0570d7a4611121da979160655e65819f..6128aa892674f49bb26b58b2e20c283df525aaaa 100644 (file)
@@ -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();
index 6c999936593e4b8a37586e3fd0604ef3da1fafc4..d93b6067364fe217044b959ea469f935315c11ef 100644 (file)
@@ -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)
index d30b11c4942b2631087456b17612be763b0520fe..f2b01862b461de47c52f6bdebd4ba491923077b8 100644 (file)
@@ -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)
index c32723cfb1ab29b1e4569429b14254e4e4e620db..3e53238b8bd0dae832af25cb66b5126c564e62c9 100644 (file)
@@ -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()
     );
index e48dc8b0ebc7cc52418008e1ef723fed84b17ecd..977e890a3cca4a9248e35eb0461efcb35ace0a97 100644 (file)
@@ -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);
index b4aa3d2cd75278a921a678bbefe014ee28354261..16c4488bcf9c209f2eda639850febd82e35b4a04 100644 (file)
@@ -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
index 362e7f56f66956f60fccba2c0f3200e047cf4a20..97cf4e0fd4052668bff78eefd5e53cd41dc501e9 100644 (file)
@@ -31,6 +31,7 @@
 #include <SketchPlugin_Sketch.h>
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_SketchEntity.h>
+#include <SketchPlugin_Tools.h>
 
 #include <Events_Loop.h>
 
@@ -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;
 }