From: azv Date: Fri, 30 May 2014 11:57:32 +0000 (+0400) Subject: Changes for modifying of GeomData objects by GeomAPI objects X-Git-Tag: V_0.4.4~338^2^2 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=98be939e3a6c58498b6dd763301d3e5fa50bf397;p=modules%2Fshaper.git Changes for modifying of GeomData objects by GeomAPI objects --- diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index cf21d319f..ad741d302 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -7,6 +7,7 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) SET(PROJECT_HEADERS GeomAPI.h GeomAPI_Interface.h + GeomAPI_XY.h GeomAPI_XYZ.h GeomAPI_Pnt.h GeomAPI_Pnt2d.h @@ -19,6 +20,7 @@ SET(PROJECT_HEADERS SET(PROJECT_SOURCES GeomAPI_Interface.cpp + GeomAPI_XY.cpp GeomAPI_XYZ.cpp GeomAPI_Pnt.cpp GeomAPI_Pnt2d.cpp diff --git a/src/GeomAPI/GeomAPI_Dir.cpp b/src/GeomAPI/GeomAPI_Dir.cpp index c3ad12fb9..abe357b2b 100644 --- a/src/GeomAPI/GeomAPI_Dir.cpp +++ b/src/GeomAPI/GeomAPI_Dir.cpp @@ -36,3 +36,8 @@ const boost::shared_ptr GeomAPI_Dir::xyz() { return boost::shared_ptr(new GeomAPI_XYZ(MY_DIR->X(), MY_DIR->Y(), MY_DIR->Z())); } + +double GeomAPI_Dir::dot(const boost::shared_ptr& theArg) const +{ + return MY_DIR->Dot(theArg->impl()); +} diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h index a8b4022ce..6ab0f1dd2 100644 --- a/src/GeomAPI/GeomAPI_Dir.h +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -32,6 +32,9 @@ public: /// returns coordinates of the direction const boost::shared_ptr xyz(); + + /// result is a scalar product of directions + double dot(const boost::shared_ptr& theArg) const; }; #endif diff --git a/src/GeomAPI/GeomAPI_Pnt2d.cpp b/src/GeomAPI/GeomAPI_Pnt2d.cpp index f1cbb8e22..1b4ee554b 100644 --- a/src/GeomAPI/GeomAPI_Pnt2d.cpp +++ b/src/GeomAPI/GeomAPI_Pnt2d.cpp @@ -3,7 +3,7 @@ // Author: Artem ZHIDKOV #include -#include +#include #include @@ -13,6 +13,10 @@ GeomAPI_Pnt2d::GeomAPI_Pnt2d(const double theX, const double theY) : GeomAPI_Interface(new gp_Pnt2d(theX, theY)) {} +GeomAPI_Pnt2d::GeomAPI_Pnt2d(const boost::shared_ptr& theCoords) + : GeomAPI_Interface(new gp_Pnt2d(theCoords->x(), theCoords->y())) +{} + double GeomAPI_Pnt2d::x() const { return MY_PNT2D->X(); @@ -33,6 +37,11 @@ void GeomAPI_Pnt2d::setY(const double theY) return MY_PNT2D->SetY(theY); } +const boost::shared_ptr GeomAPI_Pnt2d::xy() +{ + return boost::shared_ptr(new GeomAPI_XY(MY_PNT2D->X(), MY_PNT2D->Y())); +} + double GeomAPI_Pnt2d::distance(const boost::shared_ptr& theOther) const { return MY_PNT2D->Distance(theOther->impl()); diff --git a/src/GeomAPI/GeomAPI_Pnt2d.h b/src/GeomAPI/GeomAPI_Pnt2d.h index 097e8786e..a1faf626c 100644 --- a/src/GeomAPI/GeomAPI_Pnt2d.h +++ b/src/GeomAPI/GeomAPI_Pnt2d.h @@ -8,7 +8,7 @@ #include #include -class GeomAPI_XYZ; +class GeomAPI_XY; /**\class GeomAPI_Pnt2d * \ingroup DataModel @@ -20,6 +20,8 @@ class GEOMAPI_EXPORT GeomAPI_Pnt2d: public GeomAPI_Interface public: /// Creation of point by coordinates GeomAPI_Pnt2d(const double theX, const double theY); + /// Creation of point by coordinates + GeomAPI_Pnt2d(const boost::shared_ptr& theCoords); /// returns X coordinate double x() const; @@ -31,6 +33,9 @@ public: /// sets Y coordinate void setY(const double theY); + /// returns coordinates of the point + const boost::shared_ptr xy(); + /// Distance between two points double distance(const boost::shared_ptr& theOther) const; }; diff --git a/src/GeomAPI/GeomAPI_XY.cpp b/src/GeomAPI/GeomAPI_XY.cpp new file mode 100644 index 000000000..94341c31e --- /dev/null +++ b/src/GeomAPI/GeomAPI_XY.cpp @@ -0,0 +1,65 @@ +// File: GeomAPI_XY.cpp +// Created: 30 May 2014 +// Author: Artem ZHIDKOV + +#include + +#include + +#define MY_XY static_cast(myImpl) + +GeomAPI_XY::GeomAPI_XY(const double theX, const double theY) + : GeomAPI_Interface(new gp_XY(theX, theY)) +{} + +double GeomAPI_XY::x() const +{ + return MY_XY->X(); +} + +double GeomAPI_XY::y() const +{ + return MY_XY->Y(); +} + +void GeomAPI_XY::setX(const double theX) +{ + return MY_XY->SetX(theX); +} + +void GeomAPI_XY::setY(const double theY) +{ + return MY_XY->SetY(theY); +} + +const boost::shared_ptr GeomAPI_XY::added( + const boost::shared_ptr& theArg) +{ + boost::shared_ptr aResult( + new GeomAPI_XY(MY_XY->X() + theArg->x(), MY_XY->Y() + theArg->y())); + return aResult; +} + +const boost::shared_ptr GeomAPI_XY::multiplied(const double theArg) +{ + boost::shared_ptr aResult( + new GeomAPI_XY(MY_XY->X() * theArg, MY_XY->Y() * theArg)); + return aResult; +} + +double GeomAPI_XY::dot(const boost::shared_ptr& theArg) const +{ + return MY_XY->Dot(theArg->impl()); +} + +double GeomAPI_XY::cross(const boost::shared_ptr& theArg) const +{ + return MY_XY->Crossed(theArg->impl()); +} + +double GeomAPI_XY::distance(const boost::shared_ptr& theOther) const +{ + gp_XY aResult(theOther->x() - x(), theOther->y() - y()); + return aResult.Modulus(); +} + diff --git a/src/GeomAPI/GeomAPI_XY.h b/src/GeomAPI/GeomAPI_XY.h new file mode 100644 index 000000000..0f0187ae6 --- /dev/null +++ b/src/GeomAPI/GeomAPI_XY.h @@ -0,0 +1,47 @@ +// File: GeomAPI_XY.hxx +// Created: 30 May 2014 +// Author: Artem ZHIDKOV + +#ifndef GeomAPI_XY_HeaderFile +#define GeomAPI_XY_HeaderFile + +#include +#include + +/**\class GeomAPI_XY + * \ingroup DataModel + * \brief 2 coordinates: they may represent vector or point or something else + */ + +class GEOMAPI_EXPORT GeomAPI_XY: public GeomAPI_Interface +{ +public: + /// Creation by coordinates + GeomAPI_XY(const double theX, const double theY); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + + /// sets X coordinate + void setX(const double theX); + /// sets Y coordinate + void setY(const double theY); + + /// result is sum of coordinates of this and the given argument + const boost::shared_ptr added(const boost::shared_ptr& theArg); + /// result is coordinates multiplied by the argument + const boost::shared_ptr multiplied(const double theArg); + + /// result is a scalar product of two triplets + double dot(const boost::shared_ptr& theArg) const; + /// result is a cross product of two triplets + double cross(const boost::shared_ptr& theArg) const; + + /// Distance between two pairs + double distance(const boost::shared_ptr& theOther) const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_XYZ.cpp b/src/GeomAPI/GeomAPI_XYZ.cpp index 3cc18eeb1..f413005fd 100644 --- a/src/GeomAPI/GeomAPI_XYZ.cpp +++ b/src/GeomAPI/GeomAPI_XYZ.cpp @@ -50,6 +50,14 @@ const boost::shared_ptr GeomAPI_XYZ::added( return aResult; } +const boost::shared_ptr GeomAPI_XYZ::decreased( + const boost::shared_ptr& theArg) +{ + boost::shared_ptr aResult(new GeomAPI_XYZ(MY_XYZ->X() - theArg->x(), + MY_XYZ->Y() - theArg->y(), MY_XYZ->Z() - theArg->z())); + return aResult; +} + const boost::shared_ptr GeomAPI_XYZ::multiplied(const double theArg) { boost::shared_ptr aResult(new GeomAPI_XYZ(MY_XYZ->X() * theArg, diff --git a/src/GeomAPI/GeomAPI_XYZ.h b/src/GeomAPI/GeomAPI_XYZ.h index 85c60779e..ffcaa9d86 100644 --- a/src/GeomAPI/GeomAPI_XYZ.h +++ b/src/GeomAPI/GeomAPI_XYZ.h @@ -35,6 +35,8 @@ public: /// result is sum of coordinates of this and the given argument const boost::shared_ptr added(const boost::shared_ptr& theArg); + /// result is difference between coordinates of this and the given argument + const boost::shared_ptr decreased(const boost::shared_ptr& theArg); /// result is coordinates multiplied by the argument const boost::shared_ptr multiplied(const double theArg); diff --git a/src/GeomData/GeomData_Dir.cpp b/src/GeomData/GeomData_Dir.cpp index 070e94562..44f04fe30 100644 --- a/src/GeomData/GeomData_Dir.cpp +++ b/src/GeomData/GeomData_Dir.cpp @@ -22,6 +22,11 @@ void GeomData_Dir::setValue(const double theX, const double theY, const double t } } +void GeomData_Dir::setValue(const boost::shared_ptr& theDir) +{ + setValue(theDir->x(), theDir->y(), theDir->z()); +} + double GeomData_Dir::x() const { return myCoords->Value(0); diff --git a/src/GeomData/GeomData_Dir.h b/src/GeomData/GeomData_Dir.h index a7c1a2497..1b6dd6c64 100644 --- a/src/GeomData/GeomData_Dir.h +++ b/src/GeomData/GeomData_Dir.h @@ -23,6 +23,8 @@ class GeomData_Dir : public GeomDataAPI_Dir public: /// Defines the double value GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ); + /// Defines the direction + GEOMDATA_EXPORT virtual void setValue(const boost::shared_ptr& theDir); /// Returns the X double value GEOMDATA_EXPORT virtual double x() const; diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp index 6ad2ac564..da6299703 100644 --- a/src/GeomData/GeomData_Point.cpp +++ b/src/GeomData/GeomData_Point.cpp @@ -21,6 +21,11 @@ void GeomData_Point::setValue(const double theX, const double theY, const double } } +void GeomData_Point::setValue(const boost::shared_ptr& thePoint) +{ + setValue(thePoint->x(), thePoint->y(), thePoint->z()); +} + double GeomData_Point::x() const { return myCoords->Value(0); diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h index ee319e89e..116039cf1 100644 --- a/src/GeomData/GeomData_Point.h +++ b/src/GeomData/GeomData_Point.h @@ -21,6 +21,8 @@ class GeomData_Point : public GeomDataAPI_Point public: /// Defines the double value GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY, const double theZ); + /// Defines the point + GEOMDATA_EXPORT virtual void setValue(const boost::shared_ptr& thePoint); /// Returns the X double value GEOMDATA_EXPORT virtual double x() const; diff --git a/src/GeomData/GeomData_Point2D.cpp b/src/GeomData/GeomData_Point2D.cpp index 8af702953..334d2070a 100644 --- a/src/GeomData/GeomData_Point2D.cpp +++ b/src/GeomData/GeomData_Point2D.cpp @@ -5,6 +5,7 @@ #include "GeomData_Point2D.h" #include "Model_Events.h" #include +#include using namespace std; @@ -19,6 +20,11 @@ void GeomData_Point2D::setValue(const double theX, const double theY) } } +void GeomData_Point2D::setValue(const boost::shared_ptr& thePoint) +{ + setValue(thePoint->x(), thePoint->y()); +} + double GeomData_Point2D::x() const { return myCoords->Value(0); @@ -29,6 +35,13 @@ double GeomData_Point2D::y() const return myCoords->Value(1); } +boost::shared_ptr GeomData_Point2D::pnt() +{ + boost::shared_ptr aResult( + new GeomAPI_Pnt2d(myCoords->Value(0), myCoords->Value(1))); + return aResult; +} + GeomData_Point2D::GeomData_Point2D(TDF_Label& theLabel) { // check the attribute could be already presented in this doc (after load document) diff --git a/src/GeomData/GeomData_Point2D.h b/src/GeomData/GeomData_Point2D.h index 4b3d4671c..8e3c124b3 100644 --- a/src/GeomData/GeomData_Point2D.h +++ b/src/GeomData/GeomData_Point2D.h @@ -21,11 +21,15 @@ class GeomData_Point2D : public GeomDataAPI_Point2D public: /// Defines the double value GEOMDATA_EXPORT virtual void setValue(const double theX, const double theY); + /// Defines the point + GEOMDATA_EXPORT virtual void setValue(const boost::shared_ptr& thePoint); /// Returns the X double value GEOMDATA_EXPORT virtual double x() const; /// Returns the Y double value GEOMDATA_EXPORT virtual double y() const; + /// Returns the 2D point + GEOMDATA_EXPORT virtual boost::shared_ptr pnt(); protected: /// Initializes attributes diff --git a/src/GeomDataAPI/GeomDataAPI_Dir.h b/src/GeomDataAPI/GeomDataAPI_Dir.h index dbe8ef5e2..a25c9faaf 100644 --- a/src/GeomDataAPI/GeomDataAPI_Dir.h +++ b/src/GeomDataAPI/GeomDataAPI_Dir.h @@ -20,6 +20,8 @@ class GeomDataAPI_Dir : public ModelAPI_Attribute public: /// Defines the double value virtual void setValue(const double theX, const double theY, const double theZ) = 0; + /// Defines the direction + virtual void setValue(const boost::shared_ptr& theDir) = 0; /// Returns the X double value virtual double x() const = 0; diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h index c9581b2be..5f08bde02 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point.h +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -20,6 +20,8 @@ class GeomDataAPI_Point : public ModelAPI_Attribute public: /// Defines the double value virtual void setValue(const double theX, const double theY, const double theZ) = 0; + /// Defines the point + virtual void setValue(const boost::shared_ptr& thePoint) = 0; /// Returns the X double value virtual double x() const = 0; diff --git a/src/GeomDataAPI/GeomDataAPI_Point2D.h b/src/GeomDataAPI/GeomDataAPI_Point2D.h index bfc8094c2..f5eb42938 100644 --- a/src/GeomDataAPI/GeomDataAPI_Point2D.h +++ b/src/GeomDataAPI/GeomDataAPI_Point2D.h @@ -8,6 +8,8 @@ #include "GeomDataAPI.h" #include +class GeomAPI_Pnt2d; + /**\class GeomDataAPI_Point2D * \ingroup DataModel * \brief Attribute that contains 2D point coordinates. @@ -18,11 +20,15 @@ class GeomDataAPI_Point2D : public ModelAPI_Attribute public: /// Defines the double value virtual void setValue(const double theX, const double theY) = 0; + /// Defines the point + virtual void setValue(const boost::shared_ptr& thePoint) = 0; /// Returns the X double value virtual double x() const = 0; /// Returns the Y double value virtual double y() const = 0; + /// Returns the 2D point + virtual boost::shared_ptr pnt() = 0; /// Returns the type of this class of attributes static inline std::string type() {return std::string("Point2D");}