From: mpv Date: Wed, 11 Jul 2018 13:30:02 +0000 (+0300) Subject: Fix the point by XYZ coordinates python export/dump X-Git-Tag: SHAPER_V9_1_0RC1~134 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=e303d57e616d6f4f99abed086396f672904aa3e8;p=modules%2Fshaper.git Fix the point by XYZ coordinates python export/dump --- diff --git a/src/ConstructionAPI/ConstructionAPI_Point.cpp b/src/ConstructionAPI/ConstructionAPI_Point.cpp index 7d536c9fd..7dcca33b6 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.cpp +++ b/src/ConstructionAPI/ConstructionAPI_Point.cpp @@ -139,6 +139,7 @@ void ConstructionAPI_Point::setByXYZ(const ModelHighAPI_Double& theX, //fillAttribute(theZ, myz); fillAttribute(ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ(), mycreationMethod); + fillAttribute(theX, theY, theZ, mypoint); execute(false); } @@ -265,7 +266,7 @@ void ConstructionAPI_Point::dump(ModelHighAPI_Dumper& theDumper) const if (aMeth == "" || // default is XYZ aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_XYZ()) { - theDumper << point() << ")" << std::endl; + theDumper << point(); } else if (aMeth == ConstructionPlugin_Point::CREATION_METHOD_BY_INTERSECTION()) { const std::string anIntersectionType = intersectionType()->value(); if (anIntersectionType == ConstructionPlugin_Point::INTERSECTION_TYPE_BY_LINES()) diff --git a/src/ConstructionAPI/ConstructionAPI_Point.h b/src/ConstructionAPI/ConstructionAPI_Point.h index 2cd8934e5..32e2878d5 100644 --- a/src/ConstructionAPI/ConstructionAPI_Point.h +++ b/src/ConstructionAPI/ConstructionAPI_Point.h @@ -81,7 +81,7 @@ public: virtual ~ConstructionAPI_Point(); INTERFACE_25(ConstructionPlugin_Point::ID(), - point, ConstructionPlugin_Point::point3d(), + point, ConstructionPlugin_Point::POINT3D(), GeomDataAPI_Point, /** Point attribute */, creationMethod, ConstructionPlugin_Point::CREATION_METHOD(), ModelAPI_AttributeString, /** Creation method */, diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp index 03c12caff..bb59c3d55 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.cpp +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.cpp @@ -52,7 +52,7 @@ const std::string& ConstructionPlugin_Point::getKind() //================================================================================================== void ConstructionPlugin_Point::initAttributes() { - data()->addAttribute(point3d(), GeomDataAPI_Point::typeId()); + data()->addAttribute(POINT3D(), GeomDataAPI_Point::typeId()); data()->addAttribute(CREATION_METHOD(), ModelAPI_AttributeString::typeId()); @@ -162,7 +162,7 @@ bool ConstructionPlugin_Point::customisePresentation(ResultPtr theResult, std::shared_ptr ConstructionPlugin_Point::createByXYZ() { AttributePointPtr aPoint = - std::dynamic_pointer_cast(data()->attribute(point3d())); + std::dynamic_pointer_cast(data()->attribute(POINT3D())); return GeomAlgoAPI_PointBuilder::vertex(aPoint->x(), aPoint->y(), aPoint->z()); } diff --git a/src/ConstructionPlugin/ConstructionPlugin_Point.h b/src/ConstructionPlugin/ConstructionPlugin_Point.h index e04696cbc..bf63d8baf 100644 --- a/src/ConstructionPlugin/ConstructionPlugin_Point.h +++ b/src/ConstructionPlugin/ConstructionPlugin_Point.h @@ -89,7 +89,7 @@ public: return MY_CREATION_METHOD_ID; } - inline static const std::string& point3d() + inline static const std::string& POINT3D() { static const std::string POINT_ATTR("point3d"); return POINT_ATTR; diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 7e59e15ed..cb6b8d47d 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -80,6 +80,38 @@ double GeomData_Point::z() const return myExpression[2]->value(); } +void GeomData_Point::setX(const double theX) +{ + if (!myIsInitialized) { + setCalculatedValue(theX, 0, 0); + } else if (x() != theX) { + myExpression[0]->setValue(theX); + owner()->data()->sendAttributeUpdated(this); + } +} + +void GeomData_Point::setY(const double theY) +{ + if (!myIsInitialized) { + setCalculatedValue(0, theY, 0); + } else if (y() != theY) { + myExpression[1]->setValue(theY); + owner()->data()->sendAttributeUpdated(this); + } +} + +void GeomData_Point::setZ(const double theZ) +{ + if (!myIsInitialized) { + setCalculatedValue(0, 0, theZ); + } + else if (z() != theZ) { + myExpression[2]->setValue(theZ); + owner()->data()->sendAttributeUpdated(this); + } +} + + std::shared_ptr GeomData_Point::pnt() { std::shared_ptr aResult(new GeomAPI_Pnt(x(), y(), z())); @@ -100,6 +132,48 @@ void GeomData_Point::setText(const std::string& theX, } } +void GeomData_Point::setTextX(const std::string& theX) +{ + if (!myIsInitialized) { + static const std::string aDefaultText = "0"; + setText(theX, aDefaultText, aDefaultText); + } + else if (textX() != theX) { + myExpression[0]->setText(theX); + // Send it to evaluator to convert into the double and store in the attribute + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); + owner()->data()->sendAttributeUpdated(this); + } +} + +void GeomData_Point::setTextY(const std::string& theY) +{ + if (!myIsInitialized) { + static const std::string aDefaultText = "0"; + setText(aDefaultText, theY, aDefaultText); + } + else if (textY() != theY) { + myExpression[1]->setText(theY); + // Send it to evaluator to convert into the double and store in the attribute + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); + owner()->data()->sendAttributeUpdated(this); + } +} + +void GeomData_Point::setTextZ(const std::string& theZ) +{ + if (!myIsInitialized) { + static const std::string aDefaultText = "0"; + setText(aDefaultText, aDefaultText, theZ); + } + else if (textZ() != theZ) { + myExpression[2]->setText(theZ); + // Send it to evaluator to convert into the double and store in the attribute + ModelAPI_AttributeEvalMessage::send(owner()->data()->attribute(id()), this); + owner()->data()->sendAttributeUpdated(this); + } +} + std::string GeomData_Point::textX() { return myExpression[0]->text(); diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index ee2de40a5..dbb6baf45 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -49,6 +49,13 @@ class GeomData_Point : public GeomDataAPI_Point GEOMDATA_EXPORT virtual double y() const; /// Returns the Z double value GEOMDATA_EXPORT virtual double z() const; + /// Defines the X coordinate value + GEOMDATA_EXPORT void setX(const double theX); + /// Defines the Y coordinate value + GEOMDATA_EXPORT void setY(const double theY); + /// Defines the Z coordinate value + GEOMDATA_EXPORT void setZ(const double theZ); + /// Returns the 3D point GEOMDATA_EXPORT virtual std::shared_ptr pnt(); @@ -60,6 +67,12 @@ class GeomData_Point : public GeomDataAPI_Point GEOMDATA_EXPORT virtual void setText(const std::string& theX, const std::string& theY, const std::string& theZ); + /// Defines the X text value + GEOMDATA_EXPORT virtual void setTextX(const std::string& theX); + /// Defines the Y text value + GEOMDATA_EXPORT virtual void setTextY(const std::string& theY); + /// Defines the Z text value + GEOMDATA_EXPORT virtual void setTextZ(const std::string& theZ); /// Returns the X text value GEOMDATA_EXPORT virtual std::string textX(); diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index 69238cb4b..d47e3048d 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -55,11 +55,25 @@ class GeomDataAPI_Point : public ModelAPI_Attribute GEOMDATAAPI_EXPORT virtual void setCalculatedValue(const double theX, const double theY, const double theZ) = 0; + /// Defines the X coordinate value + GEOMDATAAPI_EXPORT virtual void setX(const double theX) = 0; + /// Defines the Y coordinate value + GEOMDATAAPI_EXPORT virtual void setY(const double theY) = 0; + /// Defines the Z coordinate value + GEOMDATAAPI_EXPORT virtual void setZ(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; + /// Defines the X text value + GEOMDATAAPI_EXPORT virtual void setTextX(const std::string& theX) = 0; + /// Defines the Y text value + GEOMDATAAPI_EXPORT virtual void setTextY(const std::string& theY) = 0; + /// Defines the Z text value + GEOMDATAAPI_EXPORT virtual void setTextZ(const std::string& theZ) = 0; + /// Returns the text value for X GEOMDATAAPI_EXPORT virtual std::string textX() = 0; /// Returns the text value for Y diff --git a/src/ModelAPI/Test/TestUndoRedo.py b/src/ModelAPI/Test/TestUndoRedo.py index 5f748b665..68f29eec2 100644 --- a/src/ModelAPI/Test/TestUndoRedo.py +++ b/src/ModelAPI/Test/TestUndoRedo.py @@ -19,6 +19,8 @@ ## from ModelAPI import * +from GeomDataAPI import * + aSession = ModelAPI_Session.get() aDoc = aSession.moduleDocument() assert(not aSession.canUndo()) @@ -26,12 +28,7 @@ assert(not aSession.canRedo()) aSession.startOperation() aFeature = aDoc.addFeature("Point") -# Since validators are introduced we have to initialize all -# the feature's attributes -# aFeature.string("creation_method").setValue("by_xyz") -aFeature.real("x").setValue(1.) -aFeature.real("y").setValue(-1.) -aFeature.real("z").setValue(0.) +geomDataAPI_Point(aFeature.attribute("point3d")).setValue(1., -1., 0.) aFeature.string("creation_method").setValue("by_xyz") aFeatureName = aFeature.name() # "2" is because Origin is the first point diff --git a/src/ModelHighAPI/ModelHighAPI_Double.cpp b/src/ModelHighAPI/ModelHighAPI_Double.cpp index 72667c3ec..aa02d3cdb 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Double.cpp @@ -21,6 +21,7 @@ #include "ModelHighAPI_Double.h" #include +#include //-------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------- @@ -55,3 +56,23 @@ void ModelHighAPI_Double::fillAttribute( case VT_STRING: theAttribute->setText(myString); return; } } + +void ModelHighAPI_Double::fillAttribute( + const std::shared_ptr & thePoint, + const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ) const +{ + switch (theX.myVariantType) { + case VT_DOUBLE: thePoint->setX(theX.myDouble); break; + case VT_STRING: thePoint->setTextX(theX.myString); + } + switch (theY.myVariantType) { + case VT_DOUBLE: thePoint->setY(theY.myDouble); break; + case VT_STRING: thePoint->setTextY(theY.myString); + } + switch (theZ.myVariantType) { + case VT_DOUBLE: thePoint->setZ(theZ.myDouble); break; + case VT_STRING: thePoint->setTextZ(theZ.myString); + } +} diff --git a/src/ModelHighAPI/ModelHighAPI_Double.h b/src/ModelHighAPI/ModelHighAPI_Double.h index 59686dfa2..f7997c904 100644 --- a/src/ModelHighAPI/ModelHighAPI_Double.h +++ b/src/ModelHighAPI/ModelHighAPI_Double.h @@ -28,6 +28,7 @@ #include //-------------------------------------------------------------------------------------- class ModelAPI_AttributeDouble; +class GeomDataAPI_Point; //-------------------------------------------------------------------------------------- /**\class ModelHighAPI_Double * \ingroup CPPHighAPI @@ -53,6 +54,13 @@ public: MODELHIGHAPI_EXPORT virtual void fillAttribute(const std::shared_ptr & theAttribute) const; + /// Sets the zero-based coordinates of a point + MODELHIGHAPI_EXPORT virtual void fillAttribute( + const std::shared_ptr & thePoint, + const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ) const; + private: enum VariantType { VT_DOUBLE, VT_STRING } myVariantType; double myDouble; diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.cpp b/src/ModelHighAPI/ModelHighAPI_Tools.cpp index ce7245fba..b7b5f1dab 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.cpp +++ b/src/ModelHighAPI/ModelHighAPI_Tools.cpp @@ -239,6 +239,15 @@ void fillAttribute(const std::list & theValue, theAttribute->setValue(anIndex, it->intValue()); // use only values, no text support in array } +void fillAttribute(const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ, + const std::shared_ptr & theAttribute) +{ + theX.fillAttribute(theAttribute, theX, theY, theZ); +} + + //================================================================================================== GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr) { diff --git a/src/ModelHighAPI/ModelHighAPI_Tools.h b/src/ModelHighAPI/ModelHighAPI_Tools.h index c9d55b1ca..e3bea3305 100644 --- a/src/ModelHighAPI/ModelHighAPI_Tools.h +++ b/src/ModelHighAPI/ModelHighAPI_Tools.h @@ -147,6 +147,12 @@ MODELHIGHAPI_EXPORT void fillAttribute(const std::list & theValue, const std::shared_ptr & theAttribute); +MODELHIGHAPI_EXPORT +void fillAttribute(const ModelHighAPI_Double & theX, + const ModelHighAPI_Double & theY, + const ModelHighAPI_Double & theZ, + const std::shared_ptr & theAttribute); + MODELHIGHAPI_EXPORT GeomAPI_Shape::ShapeType shapeTypeByStr(std::string theShapeTypeStr);