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) {
}
}
+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());
/// 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,
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);
}
}
+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());
/// 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();
/// 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;
/// 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;
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);
}
}
+void Model_AttributeDouble::setValue(const double theValue)
+{
+ setCalculatedValue(text().empty() ? theValue : value());
+}
+
double Model_AttributeDouble::value()
{
return myReal->Get();
/// 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)
/// 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)
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);
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()
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()
);
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);
SketchPlugin_MultiTranslation.h
SketchPlugin_ExternalValidator.h
SketchPlugin_Validators.h
+ SketchPlugin_Tools.h
)
SET(PROJECT_SOURCES
SketchPlugin_MultiTranslation.cpp
SketchPlugin_ExternalValidator.cpp
SketchPlugin_Validators.cpp
+ SketchPlugin_Tools.cpp
)
SET(PROJECT_LIBRARIES
#include <SketchPlugin_Sketch.h>
#include <SketchPlugin_Feature.h>
#include <SketchPlugin_SketchEntity.h>
+#include <SketchPlugin_Tools.h>
#include <Events_Loop.h>
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;
}