From: Clarisse Genrault Date: Thu, 15 Sep 2016 09:27:34 +0000 (+0200) Subject: Update box and add dump for box. X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=687ebabcde6889fb21d0464838ae4bbf4583758c;p=modules%2Fshaper.git Update box and add dump for box. --- diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index c4ff34d4d..623ddacef 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -42,10 +42,11 @@ SET(PROJECT_HEADERS GeomAlgoAPI_ShapeAPI.h GeomAlgoAPI_Exception.h GeomAlgoAPI_Box.h - GeomAlgoAPI_BoxPoints.h GeomAlgoAPI_XAOExport.h GeomAlgoAPI_XAOImport.h GeomAlgoAPI_Copy.h + GeomAlgoAPI_ChangeOrientation.h + GeomAlgoAPI_DivideEdge.h ) SET(PROJECT_SOURCES @@ -84,10 +85,11 @@ SET(PROJECT_SOURCES GeomAlgoAPI_ShapeAPI.cpp GeomAlgoAPI_Exception.cpp GeomAlgoAPI_Box.cpp - GeomAlgoAPI_BoxPoints.cpp GeomAlgoAPI_XAOExport.cpp GeomAlgoAPI_XAOImport.cpp GeomAlgoAPI_Copy.cpp + GeomAlgoAPI_ChangeOrientation.cpp + GeomAlgoAPI_DivideEdge.cpp ) SET(PROJECT_LIBRARIES diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index ee03a2224..1737b8aa3 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -20,19 +20,40 @@ GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const d myDx = theDx; myDy = theDy; myDz = theDz; + myMethodType = MethodType::BOX_DIM; +} + +//================================================================================================= +GeomAlgoAPI_Box::GeomAlgoAPI_Box(std::shared_ptr theFirstPoint, + std::shared_ptr theSecondPoint) +:GeomAlgoAPI_Box() +{ + myFirstPoint = theFirstPoint; + mySecondPoint = theSecondPoint; + myMethodType = MethodType::BOX_POINTS; } //================================================================================================= bool GeomAlgoAPI_Box::check() { - if (myDx < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dx is null."; - return false; - } else if (myDy < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dy is null."; - return false; - } else if (myDz < Precision::Confusion()) { - myError = "Box builder with dimensions :: Dz is null."; + if (myMethodType == MethodType::BOX_DIM) { + if (myDx < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dx is null."; + return false; + } else if (myDy < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dy is null."; + return false; + } else if (myDz < Precision::Confusion()) { + myError = "Box builder with dimensions :: Dz is null."; + return false; + } + } else if (myMethodType == MethodType::BOX_POINTS) { + if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) { + myError = "Box builder with points :: the distance between the two points is null."; + return false; + } + } else { + myError = "Box builder :: Method not implemented."; return false; } return true; @@ -40,6 +61,19 @@ bool GeomAlgoAPI_Box::check() //================================================================================================= void GeomAlgoAPI_Box::build() +{ + if (myMethodType == MethodType::BOX_DIM) { + buildWithDimensions(); + } else if (myMethodType == MethodType::BOX_POINTS) { + buildWithPoints(); + } else { + myError = "Box builder :: Method not implemented."; + return; + } +} + +//================================================================================================= +void GeomAlgoAPI_Box::buildWithDimensions() { myCreatedFaces.clear(); @@ -69,6 +103,42 @@ void GeomAlgoAPI_Box::build() setDone(true); } + +//================================================================================================= +void GeomAlgoAPI_Box::buildWithPoints() +{ + myCreatedFaces.clear(); + + const gp_Pnt& aFirstPoint = myFirstPoint->impl(); + const gp_Pnt& aSecondPoint = mySecondPoint->impl(); + + // Construct the box + BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint); + aBoxMaker->Build(); + + // Test the algorithm + if(!aBoxMaker->IsDone()) { + myError = "Box builder with two points :: algorithm failed."; + return; + } + + TopoDS_Shape aResult = aBoxMaker->Shape(); + + std::shared_ptr aShape(new GeomAPI_Shape()); + aShape->setImpl(new TopoDS_Shape(aResult)); + setShape(aShape); + + // Tests on the shape + if (!aShape.get() || aShape->isNull()) { + myError = "Box builder with two points :: resulting shape is null."; + return; + } + + setImpl(aBoxMaker); + + setDone(true); +} + //================================================================================================= void GeomAlgoAPI_Box::prepareNamingFaces() { diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h index 23bcb8d35..5c08abf96 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h @@ -17,6 +17,12 @@ class GeomAlgoAPI_Box : public GeomAlgoAPI_MakeShape { public: + /// Type of box operation + enum MethodType { + BOX_DIM, ///< Box with dimensions + BOX_POINTS, ///< Box with points + }; + GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(); /// Creates a box using the dimensions. @@ -25,19 +31,33 @@ class GeomAlgoAPI_Box : public GeomAlgoAPI_MakeShape /// \param theDz The dimension on Z GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(const double theDx, const double theDy, const double theDz); + /// Creates a box using the two points that defined a diagonal. + /// \param theFirstPoint One extermity of the diagonal + /// \param theSecondPoint The other extremity of the diagonal + GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(std::shared_ptr theFirstPoint, + std::shared_ptr theSecondPoint); + /// Checks if each dimension "Dx", Dy" and "Dz" for the box construction is OK. GEOMALGOAPI_EXPORT bool check(); - /// Builds the box with the dimensions "Dx", "Dy" and "Dz". + /// Builds the box. GEOMALGOAPI_EXPORT void build(); /// Prepare the naming (redifined because it is specific for a box). GEOMALGOAPI_EXPORT void prepareNamingFaces(); private: + /// Builds the box with the dimensions "Dx", "Dy" and "Dz". + void buildWithDimensions(); + /// Builds the box with two points + void buildWithPoints(); + double myDx; /// Dimension on X to create a box. double myDy; /// Dimension on Y to create a box. double myDz; /// Dimension Z to create a box. + std::shared_ptr myFirstPoint; /// First point to create a box. + std::shared_ptr mySecondPoint; /// Second point to create a box. + MethodType myMethodType; /// Type of method used. }; diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.cpp deleted file mode 100644 index dcfd835c5..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.cpp +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_BoxPoints.cpp -// Created: 17 Mar 2016 -// Author: Clarisse Genrault (CEA) - -#include - -#include -#include - -#include - -//================================================================================================= -GeomAlgoAPI_BoxPoints::GeomAlgoAPI_BoxPoints(std::shared_ptr theFirstPoint, - std::shared_ptr theSecondPoint) -:GeomAlgoAPI_Box() -{ - myFirstPoint = theFirstPoint; - mySecondPoint = theSecondPoint; -} - -//================================================================================================= -bool GeomAlgoAPI_BoxPoints::check() -{ - // The distance between myFirstPoint and mySecondPoint must not be null. - if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) - return false; - return true; -} - -//================================================================================================= -void GeomAlgoAPI_BoxPoints::build() -{ - myCreatedFaces.clear(); - - const gp_Pnt& aFirstPoint = myFirstPoint->impl(); - const gp_Pnt& aSecondPoint = mySecondPoint->impl(); - - // Construct the box - BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(aFirstPoint, aSecondPoint); - aBoxMaker->Build(); - - // Test the algorithm - if(!aBoxMaker->IsDone()) { - myError = "Box builder with two points :: algorithm failed."; - return; - } - - TopoDS_Shape aResult = aBoxMaker->Shape(); - - std::shared_ptr aShape(new GeomAPI_Shape()); - aShape->setImpl(new TopoDS_Shape(aResult)); - setShape(aShape); - - // Tests on the shape - if (!aShape.get() || aShape->isNull()) { - myError = "Box builder with two points :: resulting shape is null."; - return; - } - - setImpl(aBoxMaker); - - setDone(true); -} diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.h b/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.h deleted file mode 100644 index 159715f21..000000000 --- a/src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2014-2016 CEA/DEN, EDF R&D - -// File: GeomAlgoAPI_BoxPoints.h -// Created: 17 Mar 2016 -// Author: Clarisse Genrault (CEA) - -#ifndef GeomAlgoAPI_BoxPoints_H_ -#define GeomAlgoAPI_BoxPoints_H_ - -#include -#include - -/**\class GeomAlgoAPI_BoxPoints - * \ingroup DataAlgo - * \brief Allows to create Box Primitives using the two points that defined a diagonal. - */ -class GeomAlgoAPI_BoxPoints : public GeomAlgoAPI_Box -{ - public: - /// Creates a box using the two points that defined a diagonal. - /// \param theFirstPoint One extermity of the diagonal - /// \param theSecondPoint The other extremity of the diagonal - GEOMALGOAPI_EXPORT GeomAlgoAPI_BoxPoints(std::shared_ptr theFirstPoint, - std::shared_ptr theSecondPoint); - - /// \return true if the data of the construction of the box were correct. - GEOMALGOAPI_EXPORT bool check(); - - /// Builds the box. - GEOMALGOAPI_EXPORT void build(); - - private: - std::shared_ptr myFirstPoint; /// First point to create a box. - std::shared_ptr mySecondPoint; /// Second point to create a box. -}; - - -#endif diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp index 6945ee370..a2e1184e6 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp @@ -6,7 +6,6 @@ #include "GeomAlgoAPI_ShapeAPI.h" #include -#include #include #include @@ -18,7 +17,7 @@ namespace GeomAlgoAPI_ShapeAPI { //========================================================================================================= std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox(const double theDx, const double theDy, - const double theDz) throw (GeomAlgoAPI_Exception) + const double theDz) throw (GeomAlgoAPI_Exception) { GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz); @@ -39,9 +38,9 @@ namespace GeomAlgoAPI_ShapeAPI //========================================================================================================= std::shared_ptr GeomAlgoAPI_ShapeAPI::makeBox(std::shared_ptr theFirstPoint, - std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception) + std::shared_ptr theSecondPoint) throw (GeomAlgoAPI_Exception) { - GeomAlgoAPI_BoxPoints aBoxAlgo(theFirstPoint, theSecondPoint); + GeomAlgoAPI_Box aBoxAlgo(theFirstPoint, theSecondPoint); if (!aBoxAlgo.check()) { throw GeomAlgoAPI_Exception(aBoxAlgo.getError()); diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_swig.h b/src/GeomAlgoAPI/GeomAlgoAPI_swig.h index 39468c701..df537f620 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_swig.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_swig.h @@ -44,7 +44,6 @@ #include "GeomAlgoAPI_Exception.h" #include "GeomAlgoAPI_ShapeAPI.h" #include "GeomAlgoAPI_Box.h" - #include "GeomAlgoAPI_BoxPoints.h" #include "GeomAlgoAPI_Copy.h" #include diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.cpp b/src/PrimitivesAPI/PrimitivesAPI_Box.cpp index 2c2e016cb..db8048c84 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Box.cpp +++ b/src/PrimitivesAPI/PrimitivesAPI_Box.cpp @@ -6,6 +6,7 @@ #include "PrimitivesAPI_Box.h" +#include #include //================================================================================================== @@ -65,6 +66,31 @@ void PrimitivesAPI_Box::setPoints(const ModelHighAPI_Selection& theFirstPoint, execute(); } +//================================================================================================== +void PrimitivesAPI_Box::dump(ModelHighAPI_Dumper& theDumper) const +{ + FeaturePtr aBase = feature(); + const std::string& aDocName = theDumper.name(aBase->document()); + + theDumper << aBase << " = model.addBox(" << aDocName; + + std::string aCreationMethod = aBase->string(PrimitivesPlugin_Box::CREATION_METHOD())->value(); + + if(aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_DIMENSIONS()) { + AttributeDoublePtr anAttrDx = aBase->real(PrimitivesPlugin_Box::DX_ID()); + AttributeDoublePtr anAttrDy = aBase->real(PrimitivesPlugin_Box::DY_ID()); + AttributeDoublePtr anAttrDz = aBase->real(PrimitivesPlugin_Box::DZ_ID()); + + theDumper << ", " << anAttrDx << ", " << anAttrDy << ", " << anAttrDz; + } else if (aCreationMethod == PrimitivesPlugin_Box::CREATION_METHOD_BY_TWO_POINTS()) { + AttributeSelectionPtr anAttrFirstPnt = aBase->selection(PrimitivesPlugin_Box::POINT_FIRST_ID()); + AttributeSelectionPtr anAttrSecondPnt = aBase->selection(PrimitivesPlugin_Box::POINT_SECOND_ID()); + + theDumper << ", " << anAttrFirstPnt << ", " << anAttrSecondPnt; + } + + theDumper << ")" << std::endl; +} //================================================================================================== BoxPtr addBox(const std::shared_ptr& thePart, diff --git a/src/PrimitivesAPI/PrimitivesAPI_Box.h b/src/PrimitivesAPI/PrimitivesAPI_Box.h index acf8bdffb..1f8415b8b 100644 --- a/src/PrimitivesAPI/PrimitivesAPI_Box.h +++ b/src/PrimitivesAPI/PrimitivesAPI_Box.h @@ -63,6 +63,10 @@ public: PRIMITIVESAPI_EXPORT void setPoints(const ModelHighAPI_Selection& theFirstPoint, const ModelHighAPI_Selection& theSecondPoint); + + /// Dump wrapped feature + PRIMITIVESAPI_EXPORT + virtual void dump(ModelHighAPI_Dumper& theDumper) const; }; /// Pointer on primitive Box object diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp index 8f150802e..f502f71fc 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp @@ -88,7 +88,7 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints() AttributeSelectionPtr aRef1 = data()->selection(PrimitivesPlugin_Box::POINT_FIRST_ID()); AttributeSelectionPtr aRef2 = data()->selection(PrimitivesPlugin_Box::POINT_SECOND_ID()); - std::shared_ptr aBoxAlgo; + std::shared_ptr aBoxAlgo; if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) { GeomShapePtr aShape1 = aRef1->value(); @@ -100,7 +100,7 @@ void PrimitivesPlugin_Box::createBoxByTwoPoints() if (aShape1 && aShape2){ std::shared_ptr aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1); std::shared_ptr aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2); - aBoxAlgo = std::shared_ptr(new GeomAlgoAPI_BoxPoints(aFirstPoint,aSecondPoint)); + aBoxAlgo = std::shared_ptr(new GeomAlgoAPI_Box(aFirstPoint,aSecondPoint)); } } diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.h b/src/PrimitivesPlugin/PrimitivesPlugin_Box.h index 8db0d5417..991099301 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.h +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.h @@ -10,7 +10,6 @@ #include #include #include -#include class GeomAPI_Shape; class ModelAPI_ResultBody; diff --git a/src/PrimitivesPlugin/icons/SVG/box.svg b/src/PrimitivesPlugin/icons/SVG/box.svg new file mode 100644 index 000000000..f9dd6a32a --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/box.svg @@ -0,0 +1,116 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/SVG/box_2pt_32x32.svg b/src/PrimitivesPlugin/icons/SVG/box_2pt_32x32.svg new file mode 100644 index 000000000..fe8517b64 --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/box_2pt_32x32.svg @@ -0,0 +1,103 @@ + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/SVG/box_dxyz_32x32.svg b/src/PrimitivesPlugin/icons/SVG/box_dxyz_32x32.svg new file mode 100644 index 000000000..6913b550d --- /dev/null +++ b/src/PrimitivesPlugin/icons/SVG/box_dxyz_32x32.svg @@ -0,0 +1,227 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + image/svg+xml + + + + + + + + + + + + + + diff --git a/src/PrimitivesPlugin/icons/box.png b/src/PrimitivesPlugin/icons/box.png index 8e707cbc6..2b0757b05 100644 Binary files a/src/PrimitivesPlugin/icons/box.png and b/src/PrimitivesPlugin/icons/box.png differ diff --git a/src/PrimitivesPlugin/icons/box_2pt_32x32.png b/src/PrimitivesPlugin/icons/box_2pt_32x32.png index 900cb41e1..1294e0391 100644 Binary files a/src/PrimitivesPlugin/icons/box_2pt_32x32.png and b/src/PrimitivesPlugin/icons/box_2pt_32x32.png differ