From 84c21dd48f2b4be389dfa4042bc8084589c5e521 Mon Sep 17 00:00:00 2001 From: mpv Date: Wed, 23 Apr 2014 12:01:23 +0400 Subject: [PATCH] Added interfaces to OCC data and algos: features must not depend on OCC --- CMakeLists.txt | 6 ++- src/Config/plugin-Sketch.xml | 18 ------- src/GeomAPI/CMakeLists.txt | 54 +++++++++++++++++++++ src/GeomAPI/GeomAPI.h | 18 +++++++ src/GeomAPI/GeomAPI.i | 28 +++++++++++ src/GeomAPI/GeomAPI_Dir.cpp | 28 +++++++++++ src/GeomAPI/GeomAPI_Dir.h | 30 ++++++++++++ src/GeomAPI/GeomAPI_Interface.cpp | 33 +++++++++++++ src/GeomAPI/GeomAPI_Interface.h | 37 ++++++++++++++ src/GeomAPI/GeomAPI_Pnt.cpp | 43 ++++++++++++++++ src/GeomAPI/GeomAPI_Pnt.h | 37 ++++++++++++++ src/GeomAPI/GeomAPI_Shape.cpp | 13 +++++ src/GeomAPI/GeomAPI_Shape.h | 23 +++++++++ src/GeomAlgoAPI/CMakeLists.txt | 49 +++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI.h | 18 +++++++ src/GeomAlgoAPI/GeomAlgoAPI.i | 18 +++++++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 23 +++++++++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h | 28 +++++++++++ src/PartSet/CMakeLists.txt | 2 + src/PartSet/PartSet_OperationSketchBase.cpp | 2 +- src/SketchPlugin/CMakeLists.txt | 12 ++--- src/SketchPlugin/SketchPlugin_Feature.cpp | 4 +- src/SketchPlugin/SketchPlugin_Feature.h | 8 +-- src/SketchPlugin/SketchPlugin_Sketch.cpp | 43 +++++----------- src/SketchPlugin/SketchPlugin_Sketch.h | 4 +- 25 files changed, 513 insertions(+), 66 deletions(-) delete mode 100644 src/Config/plugin-Sketch.xml create mode 100644 src/GeomAPI/CMakeLists.txt create mode 100644 src/GeomAPI/GeomAPI.h create mode 100644 src/GeomAPI/GeomAPI.i create mode 100644 src/GeomAPI/GeomAPI_Dir.cpp create mode 100644 src/GeomAPI/GeomAPI_Dir.h create mode 100644 src/GeomAPI/GeomAPI_Interface.cpp create mode 100644 src/GeomAPI/GeomAPI_Interface.h create mode 100644 src/GeomAPI/GeomAPI_Pnt.cpp create mode 100644 src/GeomAPI/GeomAPI_Pnt.h create mode 100644 src/GeomAPI/GeomAPI_Shape.cpp create mode 100644 src/GeomAPI/GeomAPI_Shape.h create mode 100644 src/GeomAlgoAPI/CMakeLists.txt create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI.h create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI.i create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp create mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h diff --git a/CMakeLists.txt b/CMakeLists.txt index dc4b8fd19..b61b62709 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,11 +22,13 @@ ADD_SUBDIRECTORY (src/Config) ADD_SUBDIRECTORY (src/Event) ADD_SUBDIRECTORY (src/Model) ADD_SUBDIRECTORY (src/ModelAPI) -ADD_SUBDIRECTORY (src/ModuleBase) -ADD_SUBDIRECTORY (src/PartSet) +ADD_SUBDIRECTORY (src/GeomAPI) +ADD_SUBDIRECTORY (src/GeomAlgoAPI) ADD_SUBDIRECTORY (src/PartSetPlugin) ADD_SUBDIRECTORY (src/ConstructionPlugin) ADD_SUBDIRECTORY (src/SketchPlugin) +ADD_SUBDIRECTORY (src/ModuleBase) +ADD_SUBDIRECTORY (src/PartSet) ADD_SUBDIRECTORY (src/PyConsole) ADD_SUBDIRECTORY (src/PyEvent) ADD_SUBDIRECTORY (src/PyInterp) diff --git a/src/Config/plugin-Sketch.xml b/src/Config/plugin-Sketch.xml deleted file mode 100644 index 755458ba0..000000000 --- a/src/Config/plugin-Sketch.xml +++ /dev/null @@ -1,18 +0,0 @@ - - - - - - - - - - - - - - - diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt new file mode 100644 index 000000000..151626786 --- /dev/null +++ b/src/GeomAPI/CMakeLists.txt @@ -0,0 +1,54 @@ +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(FindCAS) + +INCLUDE(${SWIG_USE_FILE}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(PROJECT_HEADERS + GeomAPI.h + GeomAPI_Interface.h + GeomAPI_Pnt.h + GeomAPI_Dir.h + GeomAPI_Shape.h +) + +SET(PROJECT_SOURCES + GeomAPI_Interface.cpp + GeomAPI_Pnt.cpp + GeomAPI_Dir.cpp + GeomAPI_Shape.cpp +) + +ADD_DEFINITIONS(-DGEOMAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(GeomAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) + +SET(CMAKE_SWIG_FLAGS "") + +SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(GeomAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +INCLUDE_DIRECTORIES( + ${CAS_INCLUDE_DIRS} +) + +TARGET_LINK_LIBRARIES(GeomAPI ${PROJECT_LIBRARIES} ${CAS_KERNEL}) + +SET(SWIG_SCRIPTS + ${CMAKE_CURRENT_BINARY_DIR}/GeomAPI.py +) + +SET(SWIG_LINK_LIBRARIES + GeomAPI + ${PYTHON_LIBRARIES} +) + +SWIG_ADD_MODULE(GeomAPI python GeomAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(GeomAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_GeomAPI PROPERTIES DEBUG_OUTPUT_NAME _GeomAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _GeomAPI DESTINATION swig) +INSTALL(TARGETS GeomAPI DESTINATION bin) +INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) diff --git a/src/GeomAPI/GeomAPI.h b/src/GeomAPI/GeomAPI.h new file mode 100644 index 000000000..f27fc481a --- /dev/null +++ b/src/GeomAPI/GeomAPI.h @@ -0,0 +1,18 @@ +#ifndef GEOMAPI_H +#define GEOMAPI_H + +#if defined GEOMAPI_EXPORTS +#if defined WIN32 +#define GEOMAPI_EXPORT __declspec( dllexport ) +#else +#define GEOMAPI_EXPORT +#endif +#else +#if defined WIN32 +#define GEOMAPI_EXPORT __declspec( dllimport ) +#else +#define GEOMAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/GeomAPI/GeomAPI.i b/src/GeomAPI/GeomAPI.i new file mode 100644 index 000000000..717c7d264 --- /dev/null +++ b/src/GeomAPI/GeomAPI.i @@ -0,0 +1,28 @@ +/* GeomAPI.i */ +%module GeomAPI +%{ + #include "memory" + #include "GeomAPI.h" + #include "GeomAPI_Interface.h" + #include "GeomAPI_Pnt.h" + #include "GeomAPI_Shape.h" +%} + +// to avoid error on this +#define GEOMAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_string.i" +%include + +// boost pointers +// %include +%shared_ptr(GeomAPI_Interface) +%shared_ptr(GeomAPI_Pnt) +%shared_ptr(GeomAPI_Shape) + +// all supported interfaces +%include "GeomAPI_Interface.h" +%include "GeomAPI_Pnt.h" +%include "GeomAPI_Shape.h" diff --git a/src/GeomAPI/GeomAPI_Dir.cpp b/src/GeomAPI/GeomAPI_Dir.cpp new file mode 100644 index 000000000..bf0941c31 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Dir.cpp @@ -0,0 +1,28 @@ +// File: GeomAPI_Dir.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include + +#include + +#define MY_DIR static_cast(myImpl) + +GeomAPI_Dir::GeomAPI_Dir(const double theX, const double theY, const double theZ) + : GeomAPI_Interface(new gp_Dir(theX, theY, theZ)) +{} + +double GeomAPI_Dir::x() const +{ + return MY_DIR->X(); +} + +double GeomAPI_Dir::y() const +{ + return MY_DIR->Y(); +} + +double GeomAPI_Dir::z() const +{ + return MY_DIR->Z(); +} diff --git a/src/GeomAPI/GeomAPI_Dir.h b/src/GeomAPI/GeomAPI_Dir.h new file mode 100644 index 000000000..a003d3826 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Dir.h @@ -0,0 +1,30 @@ +// File: GeomAPI_Dir.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Dir_HeaderFile +#define GeomAPI_Dir_HeaderFile + +#include + +/**\class GeomAPI_Dir + * \ingroup DataModel + * \brief 3D direction defined by three normalized coordinates + */ + +class GEOMAPI_EXPORT GeomAPI_Dir: public GeomAPI_Interface +{ +public: + /// Creation of direction by coordinates + GeomAPI_Dir(const double theX, const double theY, const double theZ); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + /// returns Z coordinate + double z() const; +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Interface.cpp b/src/GeomAPI/GeomAPI_Interface.cpp new file mode 100644 index 000000000..5e9b257fb --- /dev/null +++ b/src/GeomAPI/GeomAPI_Interface.cpp @@ -0,0 +1,33 @@ +// File: GeomAPI_Interface.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include + +GeomAPI_Interface::GeomAPI_Interface() +{ + myImpl = 0; +} + +GeomAPI_Interface::GeomAPI_Interface(void* theImpl) +{ + myImpl = theImpl; +} + +GeomAPI_Interface::~GeomAPI_Interface() +{ + if (myImpl) + delete myImpl; +} + +void* GeomAPI_Interface::implementation() +{ + return myImpl; +} + +void GeomAPI_Interface::setImplementation(void* theImpl) +{ + if (myImpl) + delete myImpl; + myImpl = theImpl; +} diff --git a/src/GeomAPI/GeomAPI_Interface.h b/src/GeomAPI/GeomAPI_Interface.h new file mode 100644 index 000000000..1a605595b --- /dev/null +++ b/src/GeomAPI/GeomAPI_Interface.h @@ -0,0 +1,37 @@ +// File: GeomAPI_Interface.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Interface_HeaderFile +#define GeomAPI_Interface_HeaderFile + +#include + +/**\class GeomAPI_Interface + * \ingroup DataModel + * \brief General base class for all interfaces in this package + */ + +class GEOMAPI_EXPORT GeomAPI_Interface +{ +protected: + void* myImpl; ///< pointer to the internal implementation object + +public: + /// None - constructor + GeomAPI_Interface(); + + /// Constructor by the implementation pointer (used for internal needs) + GeomAPI_Interface(void* theImpl); + + /// Destructor + virtual ~GeomAPI_Interface(); + + /// Returns the pointer to the implementation + void* implementation(); + /// Updates the implementation (deletes the old one) + void setImplementation(void* theImpl); +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Pnt.cpp b/src/GeomAPI/GeomAPI_Pnt.cpp new file mode 100644 index 000000000..6414a2dc3 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pnt.cpp @@ -0,0 +1,43 @@ +// File: GeomAPI_Pnt.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include + +#include + +#define MY_PNT static_cast(myImpl) + +GeomAPI_Pnt::GeomAPI_Pnt(const double theX, const double theY, const double theZ) + : GeomAPI_Interface(new gp_Pnt(theX, theY, theZ)) +{} + +double GeomAPI_Pnt::x() const +{ + return MY_PNT->X(); +} + +double GeomAPI_Pnt::y() const +{ + return MY_PNT->Y(); +} + +double GeomAPI_Pnt::z() const +{ + return MY_PNT->Z(); +} + +void GeomAPI_Pnt::setX(const double theX) +{ + return MY_PNT->SetX(theX); +} + +void GeomAPI_Pnt::setY(const double theY) +{ + return MY_PNT->SetY(theY); +} + +void GeomAPI_Pnt::setZ(const double theZ) +{ + return MY_PNT->SetZ(theZ); +} diff --git a/src/GeomAPI/GeomAPI_Pnt.h b/src/GeomAPI/GeomAPI_Pnt.h new file mode 100644 index 000000000..8f80bef18 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pnt.h @@ -0,0 +1,37 @@ +// File: GeomAPI_Pnt.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Pnt_HeaderFile +#define GeomAPI_Pnt_HeaderFile + +#include + +/**\class GeomAPI_Pnt + * \ingroup DataModel + * \brief 3D point defined by three coordinates + */ + +class GEOMAPI_EXPORT GeomAPI_Pnt: public GeomAPI_Interface +{ +public: + /// Creation of point by coordinates + GeomAPI_Pnt(const double theX, const double theY, const double theZ); + + /// returns X coordinate + double x() const; + /// returns Y coordinate + double y() const; + /// returns Z coordinate + double z() const; + + /// sets X coordinate + void setX(const double theX); + /// sets Y coordinate + void setY(const double theY); + /// sets Z coordinate + void setZ(const double theZ); +}; + +#endif + diff --git a/src/GeomAPI/GeomAPI_Shape.cpp b/src/GeomAPI/GeomAPI_Shape.cpp new file mode 100644 index 000000000..e662ea254 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Shape.cpp @@ -0,0 +1,13 @@ +// File: GeomAPI_Shape.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include + +#include + +#define MY_PNT static_cast(myImpl) + +GeomAPI_Shape::GeomAPI_Shape() + : GeomAPI_Interface(new TopoDS_Shape()) +{} diff --git a/src/GeomAPI/GeomAPI_Shape.h b/src/GeomAPI/GeomAPI_Shape.h new file mode 100644 index 000000000..8a9d3b26c --- /dev/null +++ b/src/GeomAPI/GeomAPI_Shape.h @@ -0,0 +1,23 @@ +// File: GeomAPI_Shape.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Shape_HeaderFile +#define GeomAPI_Shape_HeaderFile + +#include + +/**\class GeomAPI_Shape + * \ingroup DataModel + * \brief Interface to the topological shape object + */ + +class GEOMAPI_EXPORT GeomAPI_Shape: public GeomAPI_Interface +{ +public: + /// Creation of empty (null) shape + GeomAPI_Shape(); +}; + +#endif + diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt new file mode 100644 index 000000000..509d8ac2d --- /dev/null +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -0,0 +1,49 @@ +FIND_PACKAGE(SWIG REQUIRED) +INCLUDE(FindCAS) + +INCLUDE(${SWIG_USE_FILE}) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) + +SET(PROJECT_HEADERS + GeomAlgoAPI.h + GeomAlgoAPI_FaceBuilder.h +) + +SET(PROJECT_SOURCES + GeomAlgoAPI_FaceBuilder.cpp +) + +ADD_DEFINITIONS(-DGEOMALGOAPI_EXPORTS ${CAS_DEFINITIONS}) +ADD_LIBRARY(GeomAlgoAPI SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) + +SET(CMAKE_SWIG_FLAGS "") + +SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES CPLUSPLUS ON) +SET_SOURCE_FILES_PROPERTIES(GeomAlgoAPI.i PROPERTIES SWIG_DEFINITIONS "-shadow") + +INCLUDE_DIRECTORIES( + ../GeomAPI + ${CAS_INCLUDE_DIRS} +) + +TARGET_LINK_LIBRARIES(GeomAlgoAPI ${PROJECT_LIBRARIES} GeomAPI ${CAS_KERNEL} ${CAS_MODELER}) + +SET(SWIG_SCRIPTS + ${CMAKE_CURRENT_BINARY_DIR}/GeomAlgoAPI.py +) + +SET(SWIG_LINK_LIBRARIES + GeomAlgoAPI + ${PYTHON_LIBRARIES} +) + +SWIG_ADD_MODULE(GeomAlgoAPI python GeomAlgoAPI.i ${PROJECT_HEADERS}) +SWIG_LINK_LIBRARIES(GeomAlgoAPI ${SWIG_LINK_LIBRARIES}) + +IF(WIN32) + SET_TARGET_PROPERTIES(_GeomAlgoAPI PROPERTIES DEBUG_OUTPUT_NAME _GeomAlgoAPI_d) +ENDIF(WIN32) + +INSTALL(TARGETS _GeomAlgoAPI DESTINATION swig) +INSTALL(TARGETS GeomAlgoAPI DESTINATION bin) +INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION swig) diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.h b/src/GeomAlgoAPI/GeomAlgoAPI.h new file mode 100644 index 000000000..fc7d33bbe --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI.h @@ -0,0 +1,18 @@ +#ifndef GEOMALGOAPI_H +#define GEOMALGOAPI_H + +#if defined GEOMALGOAPI_EXPORTS +#if defined WIN32 +#define GEOMALGOAPI_EXPORT __declspec( dllexport ) +#else +#define GEOMALGOAPI_EXPORT +#endif +#else +#if defined WIN32 +#define GEOMALGOAPI_EXPORT __declspec( dllimport ) +#else +#define GEOMALGOAPI_EXPORT +#endif +#endif + +#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i new file mode 100644 index 000000000..4e71ea109 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -0,0 +1,18 @@ +/* GeomAPI.i */ +%module GeomAlgoAPI +%{ + #include "memory" + #include "GeomAlgoAPI.h" + #include "GeomAlgoAPI_FaceBuilder.h" +%} + +// to avoid error on this +#define GEOMALGOAPI_EXPORT + +// standard definitions +%include "typemaps.i" +%include "std_string.i" +%include + +// all supported interfaces +%include "GeomAlgoAPI_FaceBuilder.h" diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp new file mode 100644 index 000000000..bec2c7f1b --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -0,0 +1,23 @@ +// File: GeomAlgoAPI_FaceBuilder.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include +#include +#include +#include + +std::shared_ptr GeomAlgoAPI_FaceBuilder::square( + std::shared_ptr theCenter, std::shared_ptr theNormal, + const double theSize) +{ + gp_Pnt* aCenter = static_cast(theCenter->implementation()); + gp_Dir* aDir = static_cast(theNormal->implementation()); + gp_Pln aPlane(*aCenter, *aDir); + // half of the size in each direction from the center + BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, + -theSize / 2., theSize / 2., -theSize / 2., theSize / 2.); + std::shared_ptr aRes(new GeomAPI_Shape); + aRes->setImplementation(new TopoDS_Shape(aFaceBuilder.Face())); + return aRes; +} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h new file mode 100644 index 000000000..15243f233 --- /dev/null +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.h @@ -0,0 +1,28 @@ +// File: GeomAlgoAPI_FaceBuilder.h +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAlgoAPI_FaceBuilder_HeaderFile +#define GeomAlgoAPI_FaceBuilder_HeaderFile + +#include +#include +#include +#include +#include + +/**\class GeomAlgoAPI_FaceBuilder + * \ingroup DataAlgo + * \brief Allows to create face-shapes by different parameters + */ + +class GEOMALGOAPI_EXPORT GeomAlgoAPI_FaceBuilder +{ +public: + /// Creates square planar face by given point of the center, + /// normal to the plane and size of square + static std::shared_ptr square(std::shared_ptr theCenter, + std::shared_ptr theNormal, const double theSize); +}; + +#endif diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index c4d25a782..a50b8cb1f 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -27,6 +27,7 @@ SET(TEXT_RESOURCES SET(PROJECT_LIBRARIES ModuleBase Config + GeomAPI ${QT_LIBRARIES} ${CAS_KERNEL} ) @@ -47,6 +48,7 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/XGUI ${CMAKE_SOURCE_DIR}/src/ModuleBase ${CMAKE_SOURCE_DIR}/src/ModelAPI ${CMAKE_SOURCE_DIR}/src/SketchPlugin + ${CMAKE_SOURCE_DIR}/src/GeomAPI ${CAS_INCLUDE_DIRS} ) diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index c5b70b0e0..0201255b8 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -32,7 +32,7 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase() const TopoDS_Shape& PartSet_OperationSketchBase::preview() const { shared_ptr aFeature = dynamic_pointer_cast(feature()); - return aFeature->preview(); + return *(static_cast(aFeature->preview()->implementation())); } /*! diff --git a/src/SketchPlugin/CMakeLists.txt b/src/SketchPlugin/CMakeLists.txt index f9e47c7a8..c075da118 100644 --- a/src/SketchPlugin/CMakeLists.txt +++ b/src/SketchPlugin/CMakeLists.txt @@ -1,5 +1,4 @@ INCLUDE(Common) -INCLUDE(FindCAS) SET(PROJECT_HEADERS SketchPlugin.h @@ -15,17 +14,18 @@ SET(PROJECT_SOURCES ) SET(PROJECT_LIBRARIES - ${CAS_KERNEL} - ${CAS_MODELER} + GeomAPI + GeomAlgoAPI ) -ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS} ${CAS_DEFINITIONS}) +ADD_DEFINITIONS(-DSKETCHPLUGIN_EXPORTS ${BOOST_DEFINITIONS}) ADD_LIBRARY(SketchPlugin SHARED ${PROJECT_SOURCES} ${PROJECT_HEADERS}) -TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES} ModelAPI) +TARGET_LINK_LIBRARIES(SketchPlugin ${PROJECT_LIBRARIES} ModelAPI GeomAPI GeomAlgoAPI) INCLUDE_DIRECTORIES( - ${CAS_INCLUDE_DIRS} ../ModelAPI + ../GeomAPI + ../GeomAlgoAPI ) SET(XML_RESOURCES diff --git a/src/SketchPlugin/SketchPlugin_Feature.cpp b/src/SketchPlugin/SketchPlugin_Feature.cpp index 57bc3582d..27040b92d 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.cpp +++ b/src/SketchPlugin/SketchPlugin_Feature.cpp @@ -3,7 +3,7 @@ /** * Returns the sketch preview */ -const TopoDS_Shape& SketchPlugin_Feature::preview() +const std::shared_ptr& SketchPlugin_Feature::preview() { return myPreview; } @@ -12,7 +12,7 @@ const TopoDS_Shape& SketchPlugin_Feature::preview() * Set the shape to the internal preview field * \param theShape a preview shape */ -void SketchPlugin_Feature::setPreview(const TopoDS_Shape& theShape) +void SketchPlugin_Feature::setPreview(const std::shared_ptr& theShape) { myPreview = theShape; } diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 4b91631c9..a440dbdfd 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -8,7 +8,7 @@ #include "SketchPlugin.h" #include -#include "TopoDS_Shape.hxx" +#include /**\class SketchPlugin_Feature * \ingroup DataModel @@ -17,13 +17,13 @@ class SketchPlugin_Feature: public ModelAPI_Feature { public: - SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview() = 0; + SKETCHPLUGIN_EXPORT virtual const std::shared_ptr& preview() = 0; protected: - void setPreview(const TopoDS_Shape& theShape); ///< the preview shape + void setPreview(const std::shared_ptr& theShape); ///< the preview shape private: - TopoDS_Shape myPreview; ///< the preview shape + std::shared_ptr myPreview; ///< the preview shape }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Sketch.cpp b/src/SketchPlugin/SketchPlugin_Sketch.cpp index 7fb20f079..9a3624daf 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.cpp +++ b/src/SketchPlugin/SketchPlugin_Sketch.cpp @@ -3,25 +3,13 @@ // Author: Mikhail PONIKAROV #include "SketchPlugin_Sketch.h" -#include "ModelAPI_Data.h" -#include "ModelAPI_AttributeDocRef.h" +#include +#include using namespace std; -#include -#include -#include -#include -#include - -#include -#include -#include - -const double PLANE_U_MIN = -100; -const double PLANE_U_MAX = 100; -const double PLANE_V_MIN = -100; -const double PLANE_V_MAX = 100; +// face of the square-face displayed for selection of general plane +const double PLANE_SIZE = 200; SketchPlugin_Sketch::SketchPlugin_Sketch() { @@ -29,28 +17,23 @@ SketchPlugin_Sketch::SketchPlugin_Sketch() void SketchPlugin_Sketch::initAttributes() { - data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); + //data()->addAttribute(PART_ATTR_DOC_REF, ModelAPI_AttributeDocRef::type()); } void SketchPlugin_Sketch::execute() { - /*shared_ptr aDocRef = data()->docRef(PART_ATTR_DOC_REF); - if (!aDocRef->value()) { // create a document if not yet created - shared_ptr aPartSetDoc = ModelAPI_PluginManager::get()->rootDocument(); - aDocRef->setValue(aPartSetDoc->subDocument(data()->getName())); - }*/ } -const TopoDS_Shape& SketchPlugin_Sketch::preview() +const shared_ptr& SketchPlugin_Sketch::preview() { - if (SketchPlugin_Feature::preview().IsNull()) + if (!SketchPlugin_Feature::preview()) { - gp_Pnt anOrigin(0, 0, 0); - gp_Dir aDir(gp_Vec(gp_Pnt(0,0,0), gp_Pnt(1,0,0))); - gp_Pln aPlane(anOrigin, aDir); - BRepBuilderAPI_MakeFace aFaceBuilder(aPlane, PLANE_U_MIN, PLANE_U_MAX, PLANE_V_MIN, - PLANE_V_MAX); - setPreview(aFaceBuilder.Face()); + + shared_ptr anOrigin(new GeomAPI_Pnt(0, 0, 0)); + shared_ptr aNormal(new GeomAPI_Dir(1, 0, 0)); + shared_ptr aFace = + GeomAlgoAPI_FaceBuilder::square(anOrigin, aNormal, PLANE_SIZE); + setPreview(aFace); } return SketchPlugin_Feature::preview(); } diff --git a/src/SketchPlugin/SketchPlugin_Sketch.h b/src/SketchPlugin/SketchPlugin_Sketch.h index a2b63388a..e261df1a8 100644 --- a/src/SketchPlugin/SketchPlugin_Sketch.h +++ b/src/SketchPlugin/SketchPlugin_Sketch.h @@ -8,8 +8,6 @@ #include "SketchPlugin.h" #include -#include - /// part reference attribute const std::string PART_ATTR_DOC_REF = "SketchDocument"; @@ -35,7 +33,7 @@ public: SKETCHPLUGIN_EXPORT virtual void initAttributes(); /// Returns the sketch preview - SKETCHPLUGIN_EXPORT virtual const TopoDS_Shape& preview(); + SKETCHPLUGIN_EXPORT virtual const std::shared_ptr& preview(); /// Use plugin manager for features creation SketchPlugin_Sketch(); -- 2.39.2