From c1bc28d34120d2206f9db487718630c3da7acde7 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 24 Apr 2014 16:36:43 +0400 Subject: [PATCH] Geom attribute: Point --- CMakeLists.txt | 2 + src/GeomAPI/GeomAPI_Pln.cpp | 5 +++ src/GeomAPI/GeomAPI_Pln.h | 5 ++- src/GeomAlgoAPI/CMakeLists.txt | 1 + src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 22 +++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 4 ++ src/GeomData/CMakeLists.txt | 25 +++++++++++++ src/GeomData/GeomData.h | 18 +++++++++ src/GeomData/GeomData_Point.cpp | 38 +++++++++++++++++++ src/GeomData/GeomData_Point.h | 37 +++++++++++++++++++ src/GeomDataAPI/CMakeLists.txt | 36 ++++++++++++++++++ src/GeomDataAPI/GeomDataAPI.h | 18 +++++++++ src/GeomDataAPI/GeomDataAPI.i | 22 +++++++++++ src/GeomDataAPI/GeomDataAPI_Point.h | 41 +++++++++++++++++++++ src/SketchPlugin/SketchPlugin_Sketch.cpp | 6 ++- src/SketchPlugin/SketchPlugin_Sketch.h | 12 ++++-- 16 files changed, 286 insertions(+), 6 deletions(-) create mode 100644 src/GeomData/CMakeLists.txt create mode 100644 src/GeomData/GeomData.h create mode 100644 src/GeomData/GeomData_Point.cpp create mode 100644 src/GeomData/GeomData_Point.h create mode 100644 src/GeomDataAPI/CMakeLists.txt create mode 100644 src/GeomDataAPI/GeomDataAPI.h create mode 100644 src/GeomDataAPI/GeomDataAPI.i create mode 100644 src/GeomDataAPI/GeomDataAPI_Point.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f29f9a8ba..223001654 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ ADD_SUBDIRECTORY (src/Model) ADD_SUBDIRECTORY (src/ModelAPI) ADD_SUBDIRECTORY (src/GeomAPI) ADD_SUBDIRECTORY (src/GeomAlgoAPI) +ADD_SUBDIRECTORY (src/GeomData) +ADD_SUBDIRECTORY (src/GeomDataAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/SketchPlugin) diff --git a/src/GeomAPI/GeomAPI_Pln.cpp b/src/GeomAPI/GeomAPI_Pln.cpp index d01803102..5780b3d81 100644 --- a/src/GeomAPI/GeomAPI_Pln.cpp +++ b/src/GeomAPI/GeomAPI_Pln.cpp @@ -34,3 +34,8 @@ boost::shared_ptr GeomAPI_Pln::direction() const gp_Dir& aDir = impl().Axis().Direction(); return boost::shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); } + +void GeomAPI_Pln::coefficients(double& theA, double& theB, double& theC, double& theD) +{ + impl().Coefficients(theA, theB, theC, theD); +} diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h index 0d0208430..217f74331 100644 --- a/src/GeomAPI/GeomAPI_Pln.h +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -23,7 +23,7 @@ public: GeomAPI_Pln(const boost::shared_ptr& thePoint, const boost::shared_ptr& theNormal); - /// Creation of plane by coefficients A * X + B * Y + C * Z + D = 0.0 + /// Creation of plane by coefficients (Ax+By+Cz+D=0) GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD); /// Returns a point of this plane @@ -31,6 +31,9 @@ public: /// Returns a plane normal boost::shared_ptr direction(); + + /// Returns the plane coefficients (Ax+By+Cz+D=0) + void coefficients(double& theA, double& theB, double& theC, double& theD); }; #endif diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index 40fcc4633..c05fa5a25 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -35,6 +35,7 @@ SET(SWIG_SCRIPTS ) SET(SWIG_LINK_LIBRARIES + GeomAPI GeomAlgoAPI ${PYTHON_LIBRARIES} ) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index 4b2ebc4d2..f543c06a6 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -6,6 +6,9 @@ #include #include #include +#include +#include +#include boost::shared_ptr GeomAlgoAPI_FaceBuilder::square( boost::shared_ptr theCenter, boost::shared_ptr theNormal, @@ -21,3 +24,22 @@ boost::shared_ptr GeomAlgoAPI_FaceBuilder::square( aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); return aRes; } + +boost::shared_ptr GeomAlgoAPI_FaceBuilder::plane( + boost::shared_ptr theFace) +{ + boost::shared_ptr aResult; + if (!theFace) return aResult; // bad shape + TopoDS_Shape aShape = theFace->impl(); + if (aShape.IsNull()) return aResult; // null shape + TopoDS_Face aFace = TopoDS::Face(aShape); + if (aFace.IsNull()) return aResult; // not face + Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace); + if (aSurf.IsNull()) return aResult; // no surface + Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(aSurf); + if (aPlane.IsNull()) return aResult; // not planar + double aA, aB, aC, aD; + aPlane->Coefficients(aA, aB, aC, aD); + aResult = boost::shared_ptr(new GeomAPI_Pln(aA, aB, aC, aD)); + return aResult; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h index 61ebfaeb6..5d6d731de 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -23,6 +24,9 @@ public: /// normal to the plane and size of square static boost::shared_ptr square(boost::shared_ptr theCenter, boost::shared_ptr theNormal, const double theSize); + + /// Returns the plane of the planar face. If it is not planar, returns empty ptr. + static boost::shared_ptr plane(boost::shared_ptr theFace); }; #endif diff --git a/src/GeomData/CMakeLists.txt b/src/GeomData/CMakeLists.txt new file mode 100644 index 000000000..05ee5eb3c --- /dev/null +++ b/src/GeomData/CMakeLists.txt @@ -0,0 +1,25 @@ +INCLUDE(Common) +INCLUDE(FindCAS) + +SET(PROJECT_HEADERS + GeomData.h + GeomData_Point.h +) + +SET(PROJECT_SOURCES + GeomData_Point.cpp +) + +ADD_DEFINITIONS(-DGEOMDATA_EXPORTS ${CAS_DEFINITIONS} ${BOOST_DEFINITIONS}) +ADD_LIBRARY(GeomData SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) +TARGET_LINK_LIBRARIES(GeomData ${PROJECT_LIBRARIES} ${CAS_OCAF} ModelAPI Events Config) + +INCLUDE_DIRECTORIES( + ../ModelAPI + ../GeomDataAPI + ../Events + ../Config + ${CAS_INCLUDE_DIRS} +) + +INSTALL(TARGETS GeomData DESTINATION bin) diff --git a/src/GeomData/GeomData.h b/src/GeomData/GeomData.h new file mode 100644 index 000000000..c17c76cf5 --- /dev/null +++ b/src/GeomData/GeomData.h @@ -0,0 +1,18 @@ +#ifndef GEOMDATA_H +#define GEOMDATA_H + +#if defined GEOMDATA_EXPORTS +#if defined WIN32 +#define GEOMDATA_EXPORT __declspec( dllexport ) +#else +#define GEOMDATA_EXPORT +#endif +#else +#if defined WIN32 +#define GEOMDATA_EXPORT __declspec( dllimport ) +#else +#define GEOMDATA_EXPORT +#endif +#endif + +#endif diff --git a/src/GeomData/GeomData_Point.cpp b/src/GeomData/GeomData_Point.cpp new file mode 100644 index 000000000..9fbb5f424 --- /dev/null +++ b/src/GeomData/GeomData_Point.cpp @@ -0,0 +1,38 @@ +// File: ModelAPI_AttributeDouble.cxx +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#include "GeomData_Point.h" + +using namespace std; + +void GeomData_Point::setValue(const double theX, const double theY, const double theZ) +{ + myCoords->SetValue(0, theX); + myCoords->SetValue(1, theY); + myCoords->SetValue(2, theZ); +} + +double GeomData_Point::x() const +{ + return myCoords->Value(0); +} + +double GeomData_Point::y() const +{ + return myCoords->Value(1); +} + +double GeomData_Point::z() const +{ + return myCoords->Value(2); +} + +GeomData_Point::GeomData_Point(TDF_Label& theLabel) +{ + // check the attribute could be already presented in this doc (after load document) + if (!theLabel.FindAttribute(TDataStd_RealArray::GetID(), myCoords)) { + // create attribute: not initialized by value yet, just zero + myCoords = TDataStd_RealArray::Set(theLabel, 0, 2); + } +} diff --git a/src/GeomData/GeomData_Point.h b/src/GeomData/GeomData_Point.h new file mode 100644 index 000000000..06f84959a --- /dev/null +++ b/src/GeomData/GeomData_Point.h @@ -0,0 +1,37 @@ +// File: GeomData_Point.h +// Created: 24 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomData_Point_HeaderFile +#define GeomData_Point_HeaderFile + +#include "GeomData.h" +#include "GeomDataAPI_Point.h" +#include +#include + +/**\class GeomData_Point + * \ingroup DataModel + * \brief Attribute that contains real value with double precision. + */ + +class GeomData_Point : public ModelAPI_Attribute +{ + Handle_TDataStd_RealArray myCoords; ///< X, Y and Z doubles as real array attribute [0; 2] +public: + /// Defines the double value + virtual void setValue(const double theX, const double theY, const double theZ); + + /// Returns the X double value + virtual double x() const; + /// Returns the Y double value + virtual double y() const; + /// Returns the Z double value + virtual double z() const; + +protected: + /// Initializes attributes + GeomData_Point(TDF_Label& theLabel); +}; + +#endif diff --git a/src/GeomDataAPI/CMakeLists.txt b/src/GeomDataAPI/CMakeLists.txt new file mode 100644 index 000000000..9f09481b0 --- /dev/null +++ b/src/GeomDataAPI/CMakeLists.txt @@ -0,0 +1,36 @@ +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(${SWIG_USE_FILE}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(PROJECT_HEADERS + GeomDataAPI.h + GeomDataAPI_Point.h +) + +SET(CMAKE_SWIG_FLAGS "") + +SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(GeomDataAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +INCLUDE_DIRECTORIES( + ../ModelAPI +) + +SET(SWIG_SCRIPTS + ${CMAKE_CURRENT_BINARY_DIR}/GeomDataAPI.py +) + +SET(SWIG_LINK_LIBRARIES + ModelAPI + ${PYTHON_LIBRARIES} +) + +SWIG_ADD_MODULE(GeomDataAPI python GeomDataAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(GeomDataAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_GeomDataAPI PROPERTIES DEBUG_OUTPUT_NAME _GeomDataAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _GeomDataAPI DESTINATION swig) +INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) diff --git a/src/GeomDataAPI/GeomDataAPI.h b/src/GeomDataAPI/GeomDataAPI.h new file mode 100644 index 000000000..1449986df --- /dev/null +++ b/src/GeomDataAPI/GeomDataAPI.h @@ -0,0 +1,18 @@ +#ifndef GEOMDATAAPI_H +#define GEOMDATAAPI_H + +#if defined GEOMDATAAPI_EXPORTS +#if defined WIN32 +#define GEOMDATAAPI_EXPORT __declspec( dllexport ) +#else +#define GEOMDATAAPI_EXPORT +#endif +#else +#if defined WIN32 +#define GEOMDATAAPI_EXPORT __declspec( dllimport ) +#else +#define GEOMDATAAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/GeomDataAPI/GeomDataAPI.i b/src/GeomDataAPI/GeomDataAPI.i new file mode 100644 index 000000000..f759848d9 --- /dev/null +++ b/src/GeomDataAPI/GeomDataAPI.i @@ -0,0 +1,22 @@ +/* GeomDataAPI.i */ +%module GeomDataAPI +%{ + #include "GeomDataAPI.h" + #include "GeomDataAPI_Point.h" + #include +%} + +// to avoid error on this +#define GEOMDATAAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_string.i" +//%include + +// boost pointers +%include +%shared_ptr(GeomDataAPI_Point) + +// all supported interfaces +%include "GeomDataAPI_Point.h" diff --git a/src/GeomDataAPI/GeomDataAPI_Point.h b/src/GeomDataAPI/GeomDataAPI_Point.h new file mode 100644 index 000000000..d53271fd7 --- /dev/null +++ b/src/GeomDataAPI/GeomDataAPI_Point.h @@ -0,0 +1,41 @@ +// File: GeomData_AttributeDouble.h +// Created: 2 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomData_AttributeDouble_HeaderFile +#define GeomData_AttributeDouble_HeaderFile + +#include "GeomDataAPI.h" +#include + +/**\class GeomData_AttributeDouble + * \ingroup DataModel + * \brief Attribute that contains real value with double precision. + */ + +class GeomDataAPI_Point : public ModelAPI_Attribute +{ +public: + /// Defines the double value + virtual void setValue(const double theX, const double theY, const double theZ) = 0; + + /// Returns the X double value + virtual double x() = 0; + /// Returns the Y double value + virtual double y() = 0; + /// Returns the Z double value + virtual double z() = 0; + + /// Returns the type of this class of attributes + static inline std::string type() {return std::string("Point");} + + /// Returns the type of this class of attributes, not static method + virtual std::string attributeType() {return type();} + +protected: + /// Objects are created for features automatically + GeomDataAPI_Point() + {} +}; + +#endif diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 2eaa512c8..878670ec2 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -4,6 +4,7 @@ #include "SketchPlugin_Sketch.h" #include +#include #include #include @@ -18,7 +19,10 @@ SketchPlugin_Sketch::SketchPlugin_Sketch() void SketchPlugin_Sketch::initAttributes() { - //data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); + data()->addAttribute(SKETCH_ATTR_PLANE_A, ModelAPI_AttributeDouble::type()); + data()->addAttribute(SKETCH_ATTR_PLANE_B, ModelAPI_AttributeDouble::type()); + data()->addAttribute(SKETCH_ATTR_PLANE_C, ModelAPI_AttributeDouble::type()); + data()->addAttribute(SKETCH_ATTR_PLANE_D, ModelAPI_AttributeDouble::type()); } void SketchPlugin_Sketch::execute() diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index ed936bde9..ec81fe62e 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -7,11 +7,16 @@ #include "SketchPlugin.h" #include - #include -/// part reference attribute -const std::string PART_ATTR_DOC_REF = "SketchDocument"; +/// Coefficient A of the sketch plane (Ax+By+Cz+D=0) +const std::string SKETCH_ATTR_PLANE_A("PlaneA"); +/// Coefficient B of the sketch plane +const std::string SKETCH_ATTR_PLANE_B("PlaneB"); +/// Coefficient C of the sketch plane +const std::string SKETCH_ATTR_PLANE_C("PlaneC"); +/// Coefficient D of the sketch plane +const std::string SKETCH_ATTR_PLANE_D("PlaneD"); /**\class SketchPlugin_Sketch * \ingroup DataModel @@ -47,7 +52,6 @@ protected: /// \param theShapes the list of result shapes void addPlane(double theX, double theY, double theZ, std::list >& theShapes) const; - }; #endif -- 2.39.2