From 8438647a5fb5186e3b5893fd69092792edef9ca8 Mon Sep 17 00:00:00 2001 From: Clarisse Genrault Date: Thu, 17 Nov 2016 08:54:04 +0100 Subject: [PATCH] Updating Primitive Box. --- src/GeomAlgoAPI/CMakeLists.txt | 7 +- src/GeomAlgoAPI/GeomAlgoAPI.i | 1 - src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp | 121 ++++++++-- src/GeomAlgoAPI/GeomAlgoAPI_Box.h | 32 ++- src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.cpp | 65 ----- src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.h | 38 --- src/GeomAlgoAPI/GeomAlgoAPI_ShapeAPI.cpp | 3 +- src/GeomAlgoAPI/GeomAlgoAPI_swig.h | 1 - .../Test/TestAPI_Box.py} | 22 +- src/PrimitivesPlugin/CMakeLists.txt | 7 +- src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp | 5 +- src/PrimitivesPlugin/PrimitivesPlugin_Box.h | 1 - src/PrimitivesPlugin/Test/TestBox.py | 53 ++++ src/PrimitivesPlugin/Test/UnitTestBox.py | 154 ------------ src/PrimitivesPlugin/icons/SVG/box.svg | 116 +++++++++ .../icons/SVG/box_2pt_32x32.svg | 103 ++++++++ .../icons/SVG/box_dxyz_32x32.svg | 227 ++++++++++++++++++ src/PrimitivesPlugin/icons/box.png | Bin 482 -> 528 bytes src/PrimitivesPlugin/icons/box_2pt_32x32.png | Bin 895 -> 674 bytes src/PrimitivesPlugin/plugin-Primitives.xml | 3 +- 20 files changed, 662 insertions(+), 297 deletions(-) delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.cpp delete mode 100644 src/GeomAlgoAPI/GeomAlgoAPI_BoxPoints.h rename src/{PrimitivesPlugin/Test/APIDirectTestBox.py => GeomAlgoAPI/Test/TestAPI_Box.py} (56%) create mode 100644 src/PrimitivesPlugin/Test/TestBox.py delete mode 100644 src/PrimitivesPlugin/Test/UnitTestBox.py create mode 100644 src/PrimitivesPlugin/icons/SVG/box.svg create mode 100644 src/PrimitivesPlugin/icons/SVG/box_2pt_32x32.svg create mode 100644 src/PrimitivesPlugin/icons/SVG/box_dxyz_32x32.svg diff --git a/src/GeomAlgoAPI/CMakeLists.txt b/src/GeomAlgoAPI/CMakeLists.txt index c4ff34d4d..75015c1f3 100644 --- a/src/GeomAlgoAPI/CMakeLists.txt +++ b/src/GeomAlgoAPI/CMakeLists.txt @@ -4,6 +4,7 @@ FIND_PACKAGE(SWIG REQUIRED) INCLUDE(${SWIG_USE_FILE}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) +INCLUDE(UnitTest) SET(PROJECT_HEADERS GeomAlgoAPI.h @@ -42,7 +43,6 @@ SET(PROJECT_HEADERS GeomAlgoAPI_ShapeAPI.h GeomAlgoAPI_Exception.h GeomAlgoAPI_Box.h - GeomAlgoAPI_BoxPoints.h GeomAlgoAPI_XAOExport.h GeomAlgoAPI_XAOImport.h GeomAlgoAPI_Copy.h @@ -84,7 +84,6 @@ SET(PROJECT_SOURCES GeomAlgoAPI_ShapeAPI.cpp GeomAlgoAPI_Exception.cpp GeomAlgoAPI_Box.cpp - GeomAlgoAPI_BoxPoints.cpp GeomAlgoAPI_XAOExport.cpp GeomAlgoAPI_XAOImport.cpp GeomAlgoAPI_Copy.cpp @@ -151,3 +150,7 @@ ENDIF(WIN32) INSTALL(TARGETS _GeomAlgoAPI DESTINATION ${SHAPER_INSTALL_SWIG}) INSTALL(TARGETS GeomAlgoAPI DESTINATION ${SHAPER_INSTALL_BIN}) INSTALL(FILES ${SWIG_SCRIPTS} DESTINATION ${SHAPER_INSTALL_SWIG}) + +ADD_UNIT_TESTS(TestAPI_Box.py +) + diff --git a/src/GeomAlgoAPI/GeomAlgoAPI.i b/src/GeomAlgoAPI/GeomAlgoAPI.i index 7e6272505..be79ae013 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI.i +++ b/src/GeomAlgoAPI/GeomAlgoAPI.i @@ -34,7 +34,6 @@ %shared_ptr(GeomAlgoAPI_Translation) %shared_ptr(GeomAlgoAPI_Transform) %shared_ptr(GeomAlgoAPI_Box) -%shared_ptr(GeomAlgoAPI_BoxPoints) %shared_ptr(GeomAlgoAPI_Copy) // all supported interfaces diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp index c8b7baa94..7543812f2 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.cpp @@ -20,19 +20,57 @@ 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.get()) { + myError = "Box builder with points :: the first point is not a correct"; + return false; + } + if (!mySecondPoint.get()) { + myError = "Box builder with points :: the second point is not a correct"; + return false; + } + if (myFirstPoint->distance(mySecondPoint) < Precision::Confusion()) { + myError = "Box builder with points :: the distance between the two points is null."; + return false; + } + double aDiffX = myFirstPoint->x() - mySecondPoint->x(); + double aDiffY = myFirstPoint->y() - mySecondPoint->y(); + double aDiffZ = myFirstPoint->z() - mySecondPoint->z(); + if (fabs(aDiffX) < Precision::Confusion() || + fabs(aDiffY) < Precision::Confusion() || + fabs(aDiffZ) < Precision::Confusion()) { + myError = "The points belong both to one of the OXY, OYZ or OZX planes"; + return false; + } + } else { + myError = "Box builder :: Method not implemented."; return false; } return true; @@ -41,31 +79,80 @@ bool GeomAlgoAPI_Box::check() //================================================================================================= void GeomAlgoAPI_Box::build() { - myCreatedFaces.clear(); + 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(); + // Construct the box BRepPrimAPI_MakeBox *aBoxMaker = new BRepPrimAPI_MakeBox(myDx, myDy, myDz); aBoxMaker->Build(); - + // Test the algorithm if (!aBoxMaker->IsDone()) { myError = "Box builder with dimensions :: algorithm failed."; return; } - + TopoDS_Shape aResult = aBoxMaker->Shape(); std::shared_ptr aShape(new GeomAPI_Shape()); aShape->setImpl(new TopoDS_Shape(aResult)); setShape(aShape); - + // Test on the shapes if (!aShape.get() || aShape->isNull()) { myError = "Box builder with dimensions :: resulting shape is null."; return; } - + setImpl(aBoxMaker); + + 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); } @@ -79,16 +166,16 @@ void GeomAlgoAPI_Box::prepareNamingFaces() std::shared_ptr aShapeBack(new GeomAPI_Shape); aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace())); myCreatedFaces["Back"] = aShapeBack; - std::shared_ptr aShapeTop(new GeomAPI_Shape); + std::shared_ptr aShapeTop(new GeomAPI_Shape); aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace())); myCreatedFaces["Top"] = aShapeTop; - std::shared_ptr aShapeBottom(new GeomAPI_Shape); + std::shared_ptr aShapeBottom(new GeomAPI_Shape); aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace())); myCreatedFaces["Bottom"] = aShapeBottom; - std::shared_ptr aShapeLeft(new GeomAPI_Shape); + std::shared_ptr aShapeLeft(new GeomAPI_Shape); aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace())); myCreatedFaces["Left"] = aShapeLeft; - std::shared_ptr aShapeRight(new GeomAPI_Shape); + std::shared_ptr aShapeRight(new GeomAPI_Shape); aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace())); myCreatedFaces["Right"] = aShapeRight; } diff --git a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h index 4f772eed4..c01213131 100644 --- a/src/GeomAlgoAPI/GeomAlgoAPI_Box.h +++ b/src/GeomAlgoAPI/GeomAlgoAPI_Box.h @@ -17,27 +17,47 @@ 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. /// \param theDx The dimension on X /// \param theDy The dimension on Y /// \param theDz The dimension on Z GEOMALGOAPI_EXPORT GeomAlgoAPI_Box(const double theDx, const double theDy, const double theDz); - - /// Checks if each dimension "Dx", Dy" and "Dz" for the box construction is OK. + + /// 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 data 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 c177f86ee..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 f6cedd3aa..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 f6126bddc..420b323d8 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 @@ -43,7 +42,7 @@ namespace GeomAlgoAPI_ShapeAPI std::shared_ptr theFirstPoint, 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/PrimitivesPlugin/Test/APIDirectTestBox.py b/src/GeomAlgoAPI/Test/TestAPI_Box.py similarity index 56% rename from src/PrimitivesPlugin/Test/APIDirectTestBox.py rename to src/GeomAlgoAPI/Test/TestAPI_Box.py index 57927ac00..01103fafe 100644 --- a/src/PrimitivesPlugin/Test/APIDirectTestBox.py +++ b/src/GeomAlgoAPI/Test/TestAPI_Box.py @@ -1,3 +1,9 @@ +# Copyright (C) 2014-2016 CEA/DEN, EDF R&D + +# File: TestAPI_Box.py +# Created: 16 Sept 2016 +# Author: Clarisse Genrault (CEA) + from GeomAlgoAPI import GeomAlgoAPI_ShapeAPI as shaperpy from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept from GeomAPI import GeomAPI_Pnt as pnt @@ -18,10 +24,24 @@ try : except myExcept,ec: print ec.what() - # Create a box with null dimensions try : box3 = shaperpy.makeBox(0.,0.,0.) +except myExcept,ec: + print ec.what() + +# Create a box with negative dimensions +try : + box4 = shaperpy.makeBox(-5.,15.,5.) + +except myExcept,ec: + print ec.what() + +# Create a box with two same points +try : + pnt1 = pnt(0.,0.,0.) + box5 = shaperpy.makeBox(pnt1,pnt1) + except myExcept,ec: print ec.what() \ No newline at end of file diff --git a/src/PrimitivesPlugin/CMakeLists.txt b/src/PrimitivesPlugin/CMakeLists.txt index 86a5f1683..faa66cc8a 100644 --- a/src/PrimitivesPlugin/CMakeLists.txt +++ b/src/PrimitivesPlugin/CMakeLists.txt @@ -1,8 +1,8 @@ -# Copyright (C) 2015-2016 CEA/DEN, EDF R&D +# Copyright (C) 2014-2016 CEA/DEN, EDF R&D # File: CMakeLists.txt # Created: 07 Apr 2016 -# Author: CEA (delegation to Alyotech) +# Author: Clarisse genrault (CEA) INCLUDE(UnitTest) @@ -44,7 +44,6 @@ INSTALL(TARGETS PrimitivesPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES}) INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}) INSTALL(DIRECTORY icons/ DESTINATION ${SHAPER_INSTALL_XML_RESOURCES}/icons/Primitives) -ADD_UNIT_TESTS(UnitTestBox.py - APIDirectTestBox.py +ADD_UNIT_TESTS(TestBox.py ) diff --git a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp index 709c3c8d4..554e7012b 100644 --- a/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp +++ b/src/PrimitivesPlugin/PrimitivesPlugin_Box.cpp @@ -91,7 +91,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(); @@ -103,8 +103,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 c13403c92..5f63df2eb 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/Test/TestBox.py b/src/PrimitivesPlugin/Test/TestBox.py new file mode 100644 index 000000000..3caff58e0 --- /dev/null +++ b/src/PrimitivesPlugin/Test/TestBox.py @@ -0,0 +1,53 @@ +""" +Test case for Primitive Box feature. +Written on High API. +""" +from ModelAPI import * +from GeomAPI import * + +import model + +# Get session +aSession = ModelAPI_Session.get() + +# Create a part +aDocument = aSession.activeDocument() +aSession.startOperation() +model.addPart(aDocument) +aDocument = aSession.activeDocument() +aSession.finishOperation() + +# Create a box with dimensions +aSession.startOperation() +aBox1 = model.addBox(aDocument, 10, 10, 10).result() +aSession.finishOperation() +assert (aBox1 is not None) + +# Create a first point +aSession.startOperation() +aFirstPoint = model.addPoint(aDocument, 0, 0, 0).result() +aSession.finishOperation() + +# Create a second point +aSession.startOperation() +aSecondPoint = model.addPoint(aDocument, 50, 50, 50).result() +aSession.finishOperation() + +# Create a box with 2 points +aSession.startOperation() +aBox2 = model.addBox(aDocument, aFirstPoint, aSecondPoint).result() +aSession.finishOperation() +assert (aBox2 is not None) + +# Create a box with dimensions (error) +aSession.startOperation() +aBox3 = model.addBox(aDocument, -10, 10, 10).result() +aSession.finishOperation() +assert (aBox3 is not None) + +# Create a box with 2 points (error) +aSession.startOperation() +aBox4 = model.addBox(aDocument, aFirstPoint, aFirstPoint).result() +aSession.finishOperation() +assert (aBox4 is not None) + diff --git a/src/PrimitivesPlugin/Test/UnitTestBox.py b/src/PrimitivesPlugin/Test/UnitTestBox.py deleted file mode 100644 index ebbac5509..000000000 --- a/src/PrimitivesPlugin/Test/UnitTestBox.py +++ /dev/null @@ -1,154 +0,0 @@ -""" - UnitTestBox.py - Unit Test of PrimitivesPlugin_Box class - -class PrimitivesPlugin_Box : public ModelAPI_Feature - static const std::string MY_BOX_ID("Box"); - static const std::string METHOD_ATTR("CreationMethod"); - static const std::string MY_POINT_FIRST("FirstPoint"); - static const std::string MY_POINT_SECOND("SecondPoint"); - static const std::string MY_DX("dx"); - static const std::string MY_DY("dy"); - static const std::string MY_DZ("dz"); - - data()->addAttribute(METHOD(), ModelAPI_AttributeString::typeId()); - data()->addAttribute(POINT_FIRST(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(POINT_SECOND(), ModelAPI_AttributeSelection::typeId()); - data()->addAttribute(DX(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(DY(), ModelAPI_AttributeDouble::typeId()); - data()->addAttribute(DZ(), ModelAPI_AttributeDouble::typeId()); - -""" - -#========================================================================= -# Initialization of the test -#========================================================================= -from ModelAPI import * -from GeomDataAPI import * -from GeomAlgoAPI import * -from GeomAPI import * -import math - -__updated__ = "2016-01-04" - -aSession = ModelAPI_Session.get() -aDocument = aSession.moduleDocument() -# Create a part for creation of a box -aSession.startOperation() -aPartFeature = aDocument.addFeature("Part") -aSession.finishOperation() -assert (len(aPartFeature.results()) == 1) - -aPartResult = modelAPI_ResultPart(aPartFeature.firstResult()) -aPart = aPartResult.partDoc() -#========================================================================= -# Creation of a Box by coordinates -#========================================================================= -aSession.startOperation() -aBoxBy3Dims = aPart.addFeature("Box") -assert (aBoxBy3Dims.getKind() == "Box") - -aBoxBy3Dims.string("CreationMethod").setValue("BoxByDimensions") -aBoxBy3Dims.real("dx").setValue(1.6) -aBoxBy3Dims.real("dy").setValue(1.6) -aBoxBy3Dims.real("dz").setValue(1.6) -aBoxBy3Dims.execute() - -# Check box results -assert (len(aBoxBy3Dims.results()) > 0) -aBoxResult = modelAPI_ResultBody(aBoxBy3Dims.firstResult()) -assert (aBoxResult is not None) - -# Check box volume -aRefVolume = 1.6 * 1.6 * 1.6 -aResVolume = GeomAlgoAPI_ShapeTools_volume(aBoxResult.shape()) -assert (math.fabs(aResVolume - aRefVolume) < 10 ** -5) - - -#Check the naming by selecting a face and making a plane out of it -aPlaneTop = aPart.addFeature("Plane") -assert(aPlaneTop.getKind() == "Plane") -aPlaneTop.string("creation_method").setValue("by_other_plane") -aSelectionAttr = aPlaneTop.selection("plane") -aSelectionAttr.selectSubShape("face", "Box_1_1/Top_1") -aPlaneTop.string("by_other_plane_option").setValue("by_distance_from_other") -aPlaneTop.real("distance").setValue(0.4) -aPlaneTop.execute() - -#The face should be at 1.6, so the plane should be at 1.6 + 0.4 = 2. -aRefPlaneTopLocation = 2. - -#location() is a method from GeomAPI_Face that returns a GeomAPI_Pnt, from which we can extract the z coordinate -aPlaneTopResult = aPlaneTop.firstResult() -aPlaneTopFace = GeomAPI_Face(aPlaneTopResult.shape()) -aPlaneTestLocation = aPlaneTopFace.getPlane() -aPlaneLocation = aPlaneTestLocation.location().z() -assert(math.fabs(aPlaneLocation - aRefPlaneTopLocation) < 10 ** -5) - -aSession.finishOperation() - -#========================================================================= -# Creation of a Box by two points -#========================================================================= - -aSession.startOperation() - -#Create two points -aPoint1 = aPart.addFeature("Point") -aPoint2 = aPart.addFeature("Point") -assert(aPoint1.getKind() == "Point") -assert(aPoint2.getKind() == "Point") -# aPoint1.string("creation_method").setValue("by_xyz") -aPoint1.real("x").setValue(2.0) -aPoint1.real("y").setValue(2.0) -aPoint1.real("z").setValue(2.0) -# aPoint2.string("creation_method").setValue("by_xyz") -aPoint2.real("x").setValue(2.5) -aPoint2.real("y").setValue(2.5) -aPoint2.real("z").setValue(2.5) -aPoint1.execute() -aPoint2.execute() -aPoint1Result = aPoint1.firstResult() -aPoint2Result = aPoint2.firstResult() -aPoint1Vertex = aPoint1Result.shape() -aPoint2Vertex = aPoint2Result.shape() - -aBoxBy2Pts = aPart.addFeature("Box") -assert (aBoxBy2Pts.getKind() == "Box") -aBoxBy2Pts.string("CreationMethod").setValue("BoxByTwoPoints") -aBoxBy2Pts.selection("FirstPoint").setValue(aPoint1Result, aPoint1Vertex) -aBoxBy2Pts.selection("SecondPoint").setValue(aPoint2Result, aPoint2Vertex) -aBoxBy2Pts.execute() - -# Check box volume -aBoxResult2 = modelAPI_ResultBody(aBoxBy2Pts.firstResult()) -aRefVolume2 = 0.5 * 0.5 * 0.5 -aResVolume2 = GeomAlgoAPI_ShapeTools_volume(aBoxResult2.shape()) -assert (math.fabs(aResVolume2 - aRefVolume2) < 10 ** -5) - -#Check the naming by selecting a face and making a plane out of it -aPlaneRight = aPart.addFeature("Plane") -assert(aPlaneRight.getKind() == "Plane") -aPlaneRight.string("creation_method").setValue("by_other_plane") -aSelectionAttr = aPlaneRight.selection("plane") -aSelectionAttr.selectSubShape("face", "Box_2_1/Right_1") -aPlaneRight.string("by_other_plane_option").setValue("by_distance_from_other") -aPlaneRight.real("distance").setValue(0.5) -aPlaneRight.execute() - -#The face should be at 2.5, so the plane should be at 2.5 + 0.5 = 3. -aRefPlaneRightLocation = 3. - -#location() is a method from GeomAPI_Face that returns a GeomAPI_Pnt, -#from which we can extract the y coordinate -aPlaneRightResult = aPlaneRight.firstResult() -aPlaneRightFace = GeomAPI_Face(aPlaneRightResult.shape()) -aPlaneTestLocation = aPlaneRightFace.getPlane() -aPlaneLocation = aPlaneTestLocation.location().y() -assert(math.fabs(aPlaneLocation - aRefPlaneRightLocation) < 10 ** -5) - -aSession.finishOperation() - -#========================================================================= -# End of test -#========================================================================= 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 8e707cbc668bae30e2f4c3d9c43e1727212eae3e..2b0757b055f0b982a04cb52ab53c3379201c1720 100644 GIT binary patch delta 443 zcmV;s0Yv`d1CRueI|~ih000fw0YWI7c#%dZe~n2*K~y-6)sjyrgJB%Uzt6LGn=Plg zVDDVq93;zyLJnd~8p|k0rBFno99&$S=0KU`z>JbVQ%cRr!A&B|pKN<0S6TADd;jcl zklM62=H^q+<@gwOR zf7&`sdh%8D8tXgTDOHip^ec3ggneuJ}5;?wwWD&evp8 z&Lu~0Z^`EFwl+C5YIfM|^j#DI02~1ee-)U_YWVo5B7A%#>TQ=K(K<6eWpeO5&CEFf zWPWz8&}y;hxlj}ZBhwR78P6NP&uA_oAO3N{002ovPDHLkV1nKc+qeJ# delta 396 zcmV;70dxM41mXjbI|~jb000gq0iy3E{Ei?;%16RMR)N(kWTkm2T+cXd#qRja47LGs{lNX1$hW`{(FWFxv}QJl_(c<=ZSYF@?Az#vkYG-o}F5rwt4C1ksOcs;sm ziXW3t2nR#xu-TBxq`@T49}Ldj5D*6^N1_ofYZ^Wa1riR1;PZHKb9V~>U_x-0OHtsk zI~so)z(+0zcUQOYdAvXN7y;o6v-8r_cEn^ekIkJeRCK*=PMfM0@{bER=YKEAzP}+B zKdVrQ-ZS&{dc3{ATPc-FNv?DMuP!KSn*h{>Mc#%@5NCgi{K~E|+6p9}F3ltHAdaBrihk8|t3WA7@ zCJK?HD(G%99@5m!56#=ANe*@3vFyH?{d}37eQ%zqD($pDTj?zmAhKii8bxGFYXyi* ze*sH~90L}B`(6>2>3jNPaobTI0wbm|0ab3>eZ*4Br3eurUUIgGgs+p3H)cXt8;L2{hx0lJW3ARNdMgo$_4-AhUXE2*##R{_3 zbpXBs`%wJ^bu!QheEDONtJ61`-nEBUe?8kdeCPyob|1h@3I0z3jl!?px{m9*ycitf z<>P03?hJ8m{|Kl~d3|dZ;YPtrv60o-La_$QtSSQ=4X+nll>tXt0-^w^beaoSE*ZhS z=0|v~8i@KPR+yix{dFO_o0#mLqTQ#b&sS{!gnIH92MM&Y>@E8ybVe3M4`1Bffw3Sosa&4#OL{c}OH ct?ir9Z%6%=EaMG#x&QzG07*qoM6N<$f+AK~z|U?UqYOR8bhmf8V|1cr6VI zOGwM|J^<3JN$lp_uh{qN+}W&Us9e@rbjx|7SfonlpK*^YNI38 zfAiU^w~e$^V7*eL+GVeq`EKl~4XRMr#PQY~-kf1}r6=i@Q*}}*v2-9Se|;9{HNa%M zZ~#pd$JhGU; zNl-*T9Z_Jg;I;K$E|e4#w1lGarIdd=%j5T%9K7LX|FxVGxO;B>CNOC5hI-DI6a!!+ z8|>dxz^L&n0I-yB^I7J5fS&{g3trby&-tsD!tg@RJ|<0=7_m0|7lhz-fD2&Nf66?j zO_@sjm(RA~Pa2<5TviG|ieYfTQ@|wGgg@4Y1r&Otz=*!*is~vVs;g|l`zOUPDD)IC zaR4}kUcr?7{N(=d!N}g7yQ9J()Pdml3?bzk0E-qZBs*(dT+o-zO+0$~1b{K=qhmVr z+a#PheFi!1d2tB3H)CI-g^ynb$0bXJ_ zHxXz2$_y-t1_u!9fm9)q2ly=|&qJN)e%GG5B=^|5r*_GXln<(@va&nYdQpv}s!k~t rQAg?Ep-Pi0BKm3EJ-6(_7vsqf)O1lP9N>#|00000NkvXXu0mjfF^Y>w diff --git a/src/PrimitivesPlugin/plugin-Primitives.xml b/src/PrimitivesPlugin/plugin-Primitives.xml index 22a4b366a..e3ababf71 100644 --- a/src/PrimitivesPlugin/plugin-Primitives.xml +++ b/src/PrimitivesPlugin/plugin-Primitives.xml @@ -1,6 +1,5 @@ - - + -- 2.39.2