From 6861e302bc1262afc17afc626b050295333a3af1 Mon Sep 17 00:00:00 2001 From: mpv Date: Thu, 24 Apr 2014 09:50:51 +0400 Subject: [PATCH] Templates for implementation of Geom classes receiving --- src/Config/Config_XMLReader.cpp | 4 +-- src/GeomAPI/CMakeLists.txt | 2 ++ src/GeomAPI/GeomAPI.i | 6 ++++ src/GeomAPI/GeomAPI_Interface.cpp | 7 +--- src/GeomAPI/GeomAPI_Interface.h | 15 +++++---- src/GeomAPI/GeomAPI_Pln.cpp | 36 ++++++++++++++++++++ src/GeomAPI/GeomAPI_Pln.h | 37 +++++++++++++++++++++ src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp | 8 ++--- src/ModuleBase/ModuleBase_Operation.cpp | 6 ++-- src/PartSet/PartSet_OperationSketchBase.cpp | 5 +-- src/XGUI/XGUI_PartDataModel.h | 4 +-- 11 files changed, 104 insertions(+), 26 deletions(-) create mode 100644 src/GeomAPI/GeomAPI_Pln.cpp create mode 100644 src/GeomAPI/GeomAPI_Pln.h diff --git a/src/Config/Config_XMLReader.cpp b/src/Config/Config_XMLReader.cpp index 002c9df49..8f4412f3c 100644 --- a/src/Config/Config_XMLReader.cpp +++ b/src/Config/Config_XMLReader.cpp @@ -58,7 +58,7 @@ void Config_XMLReader::readAll() /* * Allows to customize reader's behavior for a node. Virtual. - * The default implementation does nothing. (In debug mode prints + * The default impl does nothing. (In debug mode prints * some info) */ void Config_XMLReader::processNode(xmlNodePtr aNode) @@ -72,7 +72,7 @@ void Config_XMLReader::processNode(xmlNodePtr aNode) /* * Defines which nodes should be processed recursively. Virtual. - * The default implementation is to read all nodes. + * The default impl is to read all nodes. */ bool Config_XMLReader::processChildren(xmlNodePtr aNode) { diff --git a/src/GeomAPI/CMakeLists.txt b/src/GeomAPI/CMakeLists.txt index 151626786..c0c67230e 100644 --- a/src/GeomAPI/CMakeLists.txt +++ b/src/GeomAPI/CMakeLists.txt @@ -9,6 +9,7 @@ SET(PROJECT_HEADERS GeomAPI_Interface.h GeomAPI_Pnt.h GeomAPI_Dir.h + GeomAPI_Pln.h GeomAPI_Shape.h ) @@ -16,6 +17,7 @@ SET(PROJECT_SOURCES GeomAPI_Interface.cpp GeomAPI_Pnt.cpp GeomAPI_Dir.cpp + GeomAPI_Pln.cpp GeomAPI_Shape.cpp ) diff --git a/src/GeomAPI/GeomAPI.i b/src/GeomAPI/GeomAPI.i index 3f65f05f2..67d8297f7 100644 --- a/src/GeomAPI/GeomAPI.i +++ b/src/GeomAPI/GeomAPI.i @@ -5,6 +5,8 @@ #include "GeomAPI.h" #include "GeomAPI_Interface.h" #include "GeomAPI_Pnt.h" + #include "GeomAPI_Dir.h" + #include "GeomAPI_Pln.h" #include "GeomAPI_Shape.h" %} @@ -21,9 +23,13 @@ // %include %shared_ptr(GeomAPI_Interface) %shared_ptr(GeomAPI_Pnt) +%shared_ptr(GeomAPI_Dir) +%shared_ptr(GeomAPI_Pln) %shared_ptr(GeomAPI_Shape) // all supported interfaces %include "GeomAPI_Interface.h" %include "GeomAPI_Pnt.h" +%include "GeomAPI_Dir.h" +%include "GeomAPI_Pln.h" %include "GeomAPI_Shape.h" diff --git a/src/GeomAPI/GeomAPI_Interface.cpp b/src/GeomAPI/GeomAPI_Interface.cpp index 5e9b257fb..a583aa564 100644 --- a/src/GeomAPI/GeomAPI_Interface.cpp +++ b/src/GeomAPI/GeomAPI_Interface.cpp @@ -20,12 +20,7 @@ GeomAPI_Interface::~GeomAPI_Interface() delete myImpl; } -void* GeomAPI_Interface::implementation() -{ - return myImpl; -} - -void GeomAPI_Interface::setImplementation(void* theImpl) +void GeomAPI_Interface::setImpl(void* theImpl) { if (myImpl) delete myImpl; diff --git a/src/GeomAPI/GeomAPI_Interface.h b/src/GeomAPI/GeomAPI_Interface.h index 1a605595b..bd9a77ab1 100644 --- a/src/GeomAPI/GeomAPI_Interface.h +++ b/src/GeomAPI/GeomAPI_Interface.h @@ -15,23 +15,24 @@ class GEOMAPI_EXPORT GeomAPI_Interface { protected: - void* myImpl; ///< pointer to the internal implementation object + void* myImpl; ///< pointer to the internal impl object public: /// None - constructor GeomAPI_Interface(); - /// Constructor by the implementation pointer (used for internal needs) + /// Constructor by the impl 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); + /// Returns the pointer to the impl + template inline T* implPtr() {return dynamic_cast(myImpl);} + /// Returns the reference object of the impl + template inline const T& impl() {return *(static_cast(myImpl));} + /// Updates the impl (deletes the old one) + void setImpl(void* theImpl); }; #endif - diff --git a/src/GeomAPI/GeomAPI_Pln.cpp b/src/GeomAPI/GeomAPI_Pln.cpp new file mode 100644 index 000000000..d6b476cf2 --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pln.cpp @@ -0,0 +1,36 @@ +// File: GeomAPI_Pln.cpp +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#include +#include +#include + +#include + +using namespace std; + +GeomAPI_Pln::GeomAPI_Pln(const shared_ptr& thePoint, + const shared_ptr& theNormal) +: GeomAPI_Interface(new gp_Pln(thePoint->impl(), + theNormal->impl())) +{ +} + +GeomAPI_Pln::GeomAPI_Pln( + const double theA, const double theB, const double theC, const double theD) +: GeomAPI_Interface(new gp_Pln(theA, theB, theC, theD)) +{ +} + +shared_ptr GeomAPI_Pln::location() +{ + gp_Pnt aLoc = impl().Location(); + return shared_ptr(new GeomAPI_Pnt(aLoc.X(), aLoc.Y(), aLoc.Z())); +} + +shared_ptr GeomAPI_Pln::direction() +{ + const gp_Dir& aDir = impl().Axis().Direction(); + return shared_ptr(new GeomAPI_Dir(aDir.X(), aDir.Y(), aDir.Z())); +} diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h new file mode 100644 index 000000000..49b4a9d5f --- /dev/null +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -0,0 +1,37 @@ +// File: GeomAPI_Pln.hxx +// Created: 23 Apr 2014 +// Author: Mikhail PONIKAROV + +#ifndef GeomAPI_Pln_HeaderFile +#define GeomAPI_Pln_HeaderFile + +#include +#include + +class GeomAPI_Pnt; +class GeomAPI_Dir; + +/**\class GeomAPI_Pln + * \ingroup DataModel + * \brief 3D point defined by three coordinates + */ + +class GEOMAPI_EXPORT GeomAPI_Pln: public GeomAPI_Interface +{ +public: + /// Creation of plane by the point and normal + GeomAPI_Pln(const std::shared_ptr& thePoint, + const std::shared_ptr& theNormal); + + /// Creation of plane by coefficients A * X + B * Y + C * Z + D = 0.0 + GeomAPI_Pln(const double theA, const double theB, const double theC, const double theD); + + /// Returns a point of this plane + std::shared_ptr location(); + + /// Returns a plane normal + std::shared_ptr direction(); +}; + +#endif + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp index 642e90996..4b2ebc4d2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_FaceBuilder.cpp @@ -11,13 +11,13 @@ boost::shared_ptr GeomAlgoAPI_FaceBuilder::square( boost::shared_ptr theCenter, boost::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); + const gp_Pnt& aCenter = theCenter->impl(); + const gp_Dir& aDir = theNormal->impl(); + 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.); boost::shared_ptr aRes(new GeomAPI_Shape); - aRes->setImplementation(new TopoDS_Shape(aFaceBuilder.Face())); + aRes->setImpl(new TopoDS_Shape(aFaceBuilder.Face())); return aRes; } diff --git a/src/ModuleBase/ModuleBase_Operation.cpp b/src/ModuleBase/ModuleBase_Operation.cpp index 8a1ddc82d..76459c132 100644 --- a/src/ModuleBase/ModuleBase_Operation.cpp +++ b/src/ModuleBase/ModuleBase_Operation.cpp @@ -100,7 +100,7 @@ bool ModuleBase_Operation::isValid(ModuleBase_Operation*) const * \return Returns TRUE if current operation must not be checked for ActiveOperation->IsValid( this ) * * This method must be redefined in derived operation if operation of derived class - * must be always can start above any launched one. Default implementation returns FALSE, + * must be always can start above any launched one. Default impl returns FALSE, * so it is being checked for IsValid, but some operations may overload IsGranted() * In this case they will always start, no matter what operation is running. */ @@ -268,7 +268,7 @@ void ModuleBase_Operation::storeReal(double theValue) * \brief Verifies whether operator is ready to start. * \return TRUE if operation is ready to start * - * Default implementation returns TRUE. Redefine this method to add own verifications + * Default impl returns TRUE. Redefine this method to add own verifications */ bool ModuleBase_Operation::isReadyToStart() const { @@ -279,7 +279,7 @@ bool ModuleBase_Operation::isReadyToStart() const * \brief Virtual method called when operation is started * * Virtual method called when operation started (see start() method for more description) - * Default implementation calls corresponding slot and commits immediately. + * Default impl calls corresponding slot and commits immediately. */ void ModuleBase_Operation::startOperation() { diff --git a/src/PartSet/PartSet_OperationSketchBase.cpp b/src/PartSet/PartSet_OperationSketchBase.cpp index ec0d695d5..04d5be756 100644 --- a/src/PartSet/PartSet_OperationSketchBase.cpp +++ b/src/PartSet/PartSet_OperationSketchBase.cpp @@ -31,8 +31,9 @@ PartSet_OperationSketchBase::~PartSet_OperationSketchBase() */ const TopoDS_Shape& PartSet_OperationSketchBase::preview() const { - boost::shared_ptr aFeature = boost::dynamic_pointer_cast(feature()); - return *(static_cast(aFeature->preview()->implementation())); + boost::shared_ptr aFeature = + boost::dynamic_pointer_cast(feature()); + return aFeature->preview()->impl(); } /*! diff --git a/src/XGUI/XGUI_PartDataModel.h b/src/XGUI/XGUI_PartDataModel.h index f81f303f4..e1f0246ef 100644 --- a/src/XGUI/XGUI_PartDataModel.h +++ b/src/XGUI/XGUI_PartDataModel.h @@ -17,7 +17,7 @@ public: XGUI_TopDataModel(const boost::shared_ptr& theDocument, QObject* theParent); virtual ~XGUI_TopDataModel(); - // Reimplementation from QAbstractItemModel + // Reimpl from QAbstractItemModel virtual QVariant data(const QModelIndex& theIndex, int theRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; @@ -66,7 +66,7 @@ public: XGUI_PartDataModel(const boost::shared_ptr& theDocument, QObject* theParent); virtual ~XGUI_PartDataModel(); - // Reimplementation from QAbstractItemModel + // Reimpl from QAbstractItemModel virtual QVariant data(const QModelIndex& theIndex, int theRole) const; virtual QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; -- 2.39.2