From: Clarisse Genrault Date: Thu, 17 Nov 2016 07:54:04 +0000 (+0100) Subject: Updating Primitive Box. X-Git-Tag: V_2.6.0~85 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=8438647a5fb5186e3b5893fd69092792edef9ca8;p=modules%2Fshaper.git Updating Primitive Box. --- 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/GeomAlgoAPI/Test/TestAPI_Box.py b/src/GeomAlgoAPI/Test/TestAPI_Box.py new file mode 100644 index 000000000..01103fafe --- /dev/null +++ b/src/GeomAlgoAPI/Test/TestAPI_Box.py @@ -0,0 +1,47 @@ +# 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 + +# Create a box with dimensions +try : + box1 = shaperpy.makeBox(5.,15.,5.) + +except myExcept,ec: + print ec.what() + +# Create a box with two points defining the diagonal +try : + pnt1 = pnt(0.,0.,0.) + pnt2 = pnt(10.,10.,10.) + box2 = shaperpy.makeBox(pnt1,pnt2) + +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/APIDirectTestBox.py b/src/PrimitivesPlugin/Test/APIDirectTestBox.py deleted file mode 100644 index 57927ac00..000000000 --- a/src/PrimitivesPlugin/Test/APIDirectTestBox.py +++ /dev/null @@ -1,27 +0,0 @@ -from GeomAlgoAPI import GeomAlgoAPI_ShapeAPI as shaperpy -from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept -from GeomAPI import GeomAPI_Pnt as pnt - -# Create a box with dimensions -try : - box1 = shaperpy.makeBox(5.,15.,5.) - -except myExcept,ec: - print ec.what() - -# Create a box with two points defining the diagonal -try : - pnt1 = pnt(0.,0.,0.) - pnt2 = pnt(10.,10.,10.) - box2 = shaperpy.makeBox(pnt1,pnt2) - -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() \ No newline at end of file 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 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 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 @@ - - +