ADD_SUBDIRECTORY (src/ConstructionPlugin)
ADD_SUBDIRECTORY (src/BuildPlugin)
ADD_SUBDIRECTORY (src/FeaturesPlugin)
+ADD_SUBDIRECTORY (src/PrimitivesPlugin)
ADD_SUBDIRECTORY (src/SamplePanelPlugin)
ADD_SUBDIRECTORY (src/SketcherPrs)
ADD_SUBDIRECTORY (src/SketchPlugin)
<plugin library="ConstructionPlugin" configuration="plugin-Construction.xml"/>
<plugin library="BuildPlugin" configuration="plugin-Build.xml"/>
<plugin library="FeaturesPlugin" configuration="plugin-Features.xml"/>
+ <plugin library="PrimitivesPlugin" configuration="plugin-Primitives.xml"/>
<plugin library="ExchangePlugin" configuration="plugin-Exchange.xml"/>
<plugin script="addons_Features" configuration="addons_Features.xml"/>
<plugin script="ConnectorPlugin" configuration="plugin-Connector.xml" dependency="Geometry"/>
GeomAlgoAPI_Intersection.h
GeomAlgoAPI_Pipe.h
GeomAlgoAPI_WireBuilder.h
+ GeomAlgoAPI_Box.h
+ GeomAlgoAPI_BoxPoints.h
+ GeomAlgoAPI_DirectAPI.h
+ GeomAlgoAPI_Exception.h
)
SET(PROJECT_SOURCES
GeomAlgoAPI_Intersection.cpp
GeomAlgoAPI_Pipe.cpp
GeomAlgoAPI_WireBuilder.cpp
+ GeomAlgoAPI_Box.cpp
+ GeomAlgoAPI_BoxPoints.cpp
+ GeomAlgoAPI_DirectAPI.cpp
+ GeomAlgoAPI_Exception.cpp
)
SET(PROJECT_LIBRARIES
%include "GeomAlgoAPI_Intersection.h"
%include "GeomAlgoAPI_Pipe.h"
%include "GeomAlgoAPI_WireBuilder.h"
+%include "GeomAlgoAPI_Box.h"
+%include "GeomAlgoAPI_BoxPoints.h"
+%include "GeomAlgoAPI_DirectAPI.h"
+%include "GeomAlgoAPI_Exception.h"
%typemap(out) std::list< std::shared_ptr< GeomAPI_Shape > >::value_type & {
$result = SWIG_NewPointerObj(SWIG_as_voidptr(new std::shared_ptr<GeomAPI_Shape>(*$1)), $descriptor(std::shared_ptr<GeomAPI_Shape> *), SWIG_POINTER_OWN | 0 );
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Box.cpp
+// Created: 10 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <GeomAlgoAPI_Box.h>
+
+#include <BRepPrimAPI_MakeBox.hxx>
+#include <TopoDS_Shape.hxx>
+
+//=================================================================================================
+GeomAlgoAPI_Box::GeomAlgoAPI_Box()
+{
+}
+
+//=================================================================================================
+GeomAlgoAPI_Box::GeomAlgoAPI_Box(const double theDx, const double theDy, const double theDz)
+{
+ myDx = theDx;
+ myDy = theDy;
+ myDz = theDz;
+}
+
+//=================================================================================================
+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.";
+ return false;
+ }
+ return true;
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Box::build()
+{
+ 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<GeomAPI_Shape> 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;
+ }
+ if (!isValid()) {
+ myError = "Box builder with dimensions :: resulting shape is not valid.";
+ return;
+ }
+
+ setImpl(aBoxMaker);
+
+ setDone(true);
+}
+
+//=================================================================================================
+void GeomAlgoAPI_Box::prepareNamingFaces()
+{
+ BRepPrimAPI_MakeBox aBoxMaker = impl<BRepPrimAPI_MakeBox>();
+ std::shared_ptr<GeomAPI_Shape> aShapeFront(new GeomAPI_Shape);
+ aShapeFront->setImpl(new TopoDS_Shape(aBoxMaker.FrontFace()));
+ myCreatedFaces["Front"] = aShapeFront;
+ std::shared_ptr<GeomAPI_Shape> aShapeBack(new GeomAPI_Shape);
+ aShapeBack->setImpl(new TopoDS_Shape(aBoxMaker.BackFace()));
+ myCreatedFaces["Back"] = aShapeBack;
+ std::shared_ptr<GeomAPI_Shape> aShapeTop(new GeomAPI_Shape);
+ aShapeTop->setImpl(new TopoDS_Shape(aBoxMaker.TopFace()));
+ myCreatedFaces["Top"] = aShapeTop;
+ std::shared_ptr<GeomAPI_Shape> aShapeBottom(new GeomAPI_Shape);
+ aShapeBottom->setImpl(new TopoDS_Shape(aBoxMaker.BottomFace()));
+ myCreatedFaces["Bottom"] = aShapeBottom;
+ std::shared_ptr<GeomAPI_Shape> aShapeLeft(new GeomAPI_Shape);
+ aShapeLeft->setImpl(new TopoDS_Shape(aBoxMaker.LeftFace()));
+ myCreatedFaces["Left"] = aShapeLeft;
+ std::shared_ptr<GeomAPI_Shape> aShapeRight(new GeomAPI_Shape);
+ aShapeRight->setImpl(new TopoDS_Shape(aBoxMaker.RightFace()));
+ myCreatedFaces["Right"] = aShapeRight;
+}
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Box.h
+// Created: 17 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#ifndef GeomAlgoAPI_Box_H_
+#define GeomAlgoAPI_Box_H_
+
+#include <GeomAPI_Pnt.h>
+#include <GeomAlgoAPI_MakeShape.h>
+
+/**\class GeomAlgoAPI_Box
+ * \ingroup DataAlgo
+ * \brief Allows to create Box Primitives
+ */
+class GeomAlgoAPI_Box : public GeomAlgoAPI_MakeShape
+{
+ public:
+ 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.
+ GEOMALGOAPI_EXPORT bool check();
+
+ /// Builds the box with the dimensions "Dx", "Dy" and "Dz".
+ GEOMALGOAPI_EXPORT void build();
+
+ /// Prepare the naming (redifined because it is specific for a box).
+ GEOMALGOAPI_EXPORT void prepareNamingFaces();
+
+ private:
+ 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.
+};
+
+
+#endif
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_BoxPoints.cpp
+// Created: 17 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <GeomAlgoAPI_BoxPoints.h>
+
+#include <BRepPrimAPI_MakeBox.hxx>
+#include <TopoDS_Shape.hxx>
+
+#include <iostream>
+
+//=================================================================================================
+GeomAlgoAPI_BoxPoints::GeomAlgoAPI_BoxPoints(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
+ std::shared_ptr<GeomAPI_Pnt> 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<gp_Pnt>();
+ const gp_Pnt& aSecondPoint = mySecondPoint->impl<gp_Pnt>();
+
+ // 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<GeomAPI_Shape> 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;
+ }
+ if (!isValid()) {
+ myError = "Box builder with two points :: resulting shape is not valid.";
+ return;
+ }
+
+ setImpl(aBoxMaker);
+
+ setDone(true);
+}
--- /dev/null
+// 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 <GeomAPI_Pnt.h>
+#include <GeomAlgoAPI_Box.h>
+
+/**\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<GeomAPI_Pnt> theFirstPoint,
+ std::shared_ptr<GeomAPI_Pnt> 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<GeomAPI_Pnt> myFirstPoint; /// First point to create a box.
+ std::shared_ptr<GeomAPI_Pnt> mySecondPoint; /// Second point to create a box.
+};
+
+
+#endif
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_DirectAPI.cpp
+// Created: 17 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#include "GeomAlgoAPI_DirectAPI.h"
+#include <GeomAlgoAPI_Box.h>
+#include <GeomAlgoAPI_BoxPoints.h>
+
+#include <iostream>
+
+namespace GeomAlgoAPI_DirectAPI
+{
+ //=========================================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_DirectAPI::MakeBox(const double theDx, const double theDy,
+ const double theDz) throw (GeomAlgoAPI_Exception)
+ {
+ GeomAlgoAPI_Box aBoxAlgo(theDx,theDy,theDz);
+
+ if (!aBoxAlgo.check()) {
+ throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
+ }
+
+ aBoxAlgo.build();
+
+ if(!aBoxAlgo.isDone()) {
+ throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
+ }
+ return aBoxAlgo.shape();
+ }
+
+ //=========================================================================================================
+ std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_DirectAPI::MakeBox(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
+ std::shared_ptr<GeomAPI_Pnt> theSecondPoint) throw (GeomAlgoAPI_Exception)
+ {
+ GeomAlgoAPI_BoxPoints aBoxAlgo(theFirstPoint, theSecondPoint);
+
+ if (!aBoxAlgo.check()) {
+ throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
+ }
+
+ aBoxAlgo.build();
+
+ if(!aBoxAlgo.isDone()) {
+ throw GeomAlgoAPI_Exception(aBoxAlgo.getError());
+ }
+ return aBoxAlgo.shape();
+ }
+}
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_DirectAPI.h
+// Created: 17 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#ifndef GEOMALGOAPI_DIRECTAPI_H
+#define GEOMALGOAPI_DIRECTAPI_H
+
+#include <GeomAPI_Shape.h>
+#include <GeomAPI_Pnt.h>
+
+#include <GeomAlgoAPI_Exception.h>
+
+namespace GeomAlgoAPI_DirectAPI
+{
+/**\class GeomAlgoAPI_DirectAPI
+ * \ingroup DataAlgo
+ * \brief Allows to access the direct API
+ */
+class GeomAlgoAPI_DirectAPI
+{
+public:
+ /// Creates a box using the dimensions.
+ /// \param theDx The dimension on X
+ /// \param theDy The dimension on Y
+ /// \param theDz The dimension on Z
+ /// \return a shape
+ static std::shared_ptr<GeomAPI_Shape> MakeBox(const double theDx, const double theDy, const double theDz) throw (GeomAlgoAPI_Exception);
+
+ /// 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
+ /// \return a shape
+ static std::shared_ptr<GeomAPI_Shape> MakeBox(std::shared_ptr<GeomAPI_Pnt> theFirstPoint,
+ std::shared_ptr<GeomAPI_Pnt> theSecondPoint)throw (GeomAlgoAPI_Exception);
+};
+}
+#endif
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: GeomAlgoAPI_Exception.cpp
+// Created: 14 April 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <GeomAlgoAPI_Exception.h>
+
+//=================================================================================================
+GeomAlgoAPI_Exception::GeomAlgoAPI_Exception(std::string theMessageError)
+: myMessageError(theMessageError)
+{
+}
+
+//=================================================================================================
+GeomAlgoAPI_Exception::~GeomAlgoAPI_Exception() throw()
+{
+}
+
+//=================================================================================================
+const char* GeomAlgoAPI_Exception::what() const throw()
+{
+ return myMessageError.c_str();
+}
\ No newline at end of file
--- /dev/null
+#ifndef GeomAlgoAPI_Exception_H_
+#define GeomAlgoAPI_Exception_H_
+
+#include <GeomAlgoAPI.h>
+
+#include <iostream>
+
+/**\class GeomAlgoAPI_Exception
+ * \ingroup DataAlgo
+ * \brief Manage exceptions
+ */
+class GeomAlgoAPI_Exception : public std::exception
+{
+ public:
+ /// Create an exception
+ /// \param theMessageError Error message to be displayed
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Exception(std::string theMessageError);
+ /// Destroyer
+ GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Exception() throw();
+ /// Allows to collet the error
+ GEOMALGOAPI_EXPORT const char* what() const throw();
+
+private:
+ std::string myMessageError; /// Error message to be displayed.
+};
+
+
+#endif
\ No newline at end of file
// File: GeomAlgoAPI_MakeShape.cpp
// Created: 20 Oct 2014
// Author: Sergey ZARITCHNY
+//
+// Modified by Clarisse Genrault (CEA) : 17 Mar 2016
#include "GeomAlgoAPI_MakeShape.h"
#include <TopExp_Explorer.hxx>
#include <TopTools_ListOfShape.hxx>
#include <TopTools_ListIteratorOfListOfShape.hxx>
+#include <GeomAPI_ShapeExplorer.h>
//=================================================================================================
GeomAlgoAPI_MakeShape::GeomAlgoAPI_MakeShape()
myMap->bind(aCurrentShape, aCurrentShape);
}
}
+
+//=================================================================================================
+void GeomAlgoAPI_MakeShape::prepareNamingFaces()
+{
+ int index = 1;
+ GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE);
+ for(GeomAPI_ShapeExplorer anExp(shape(), GeomAPI_Shape::FACE); anExp.more(); anExp.next()) {
+ std::shared_ptr<GeomAPI_Shape> aFace = anExp.current();
+ myCreatedFaces["Face_" + std::to_string(index++)] = aFace;
+ }
+}
// File: GeomAlgoAPI_MakeShape.h
// Created: 17 Oct 2014
// Author: Sergey ZARITCHNY
+//
+// Modified by Clarisse Genrault (CEA) : 17 Mar 2016
#ifndef GeomAlgoAPI_MakeShape_H_
#define GeomAlgoAPI_MakeShape_H_
#include <list>
#include <memory>
+#include <map>
/// \class GeomAlgoAPI_MakeShape
/// \ingroup DataAlgo
/// \param[in] theShape base shape.
GEOMALGOAPI_EXPORT virtual bool isDeleted(const std::shared_ptr<GeomAPI_Shape> theShape);
+ /// \return true if the data were correct.
+ GEOMALGOAPI_EXPORT virtual bool check() { return true; };
+
+ /// \return the list of created faces.
+ GEOMALGOAPI_EXPORT std::map< std::string, std::shared_ptr<GeomAPI_Shape> > getCreatedFaces() {return myCreatedFaces;}
+
+ /// \return the error.
+ GEOMALGOAPI_EXPORT std::string getError() { return myError; }
+
+ /// \brief Prepare the naming of faces.
+ GEOMALGOAPI_EXPORT virtual void prepareNamingFaces();
+
protected:
/// \brief Sets builder type.
/// \param[in] theBuilderType new builder type.
/// \param[in] theShape new shape.
void setShape(const std::shared_ptr<GeomAPI_Shape> theShape);
+ std::string myError; /// Error occurred during the execution of an algorithm.
+ std::map< std::string, std::shared_ptr<GeomAPI_Shape> > myCreatedFaces; /// Map of created faces with their name for naming.
+
protected:
std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap; ///< Data map to keep correct orientation of sub-shapes.
#include "GeomAlgoAPI_Intersection.h"
#include "GeomAlgoAPI_Pipe.h"
#include "GeomAlgoAPI_WireBuilder.h"
+ #include "GeomAlgoAPI_Box.h"
+ #include "GeomAlgoAPI_BoxPoints.h"
+ #include "GeomAlgoAPI_DirectAPI.h"
+ #include "GeomAlgoAPI_Exception.h"
#include <memory>
#include <string>
<qresource>
<file>icons/activate.png</file>
<file>icons/angle_32x32.png</file>
+ <file>icons/box.png</file>
+ <file>icons/box_2pt_32x32.png</file>
+ <file>icons/box_dxyz_32x32.png</file>
<file>icons/color.png</file>
<file>icons/deactivate.png</file>
<file>icons/edit.png</file>
--- /dev/null
+SET(PROJECT_HEADERS
+ PrimitivesPlugin.h
+ PrimitivesPlugin_Plugin.h
+ PrimitivesPlugin_Box.h
+)
+
+SET(PROJECT_SOURCES
+ PrimitivesPlugin_Plugin.cpp
+ PrimitivesPlugin_Box.cpp
+)
+
+SET(XML_RESOURCES
+ plugin-Primitives.xml
+ box_widget.xml
+)
+
+INCLUDE_DIRECTORIES(
+ ../ModelAPI
+ ../GeomAPI
+ ../GeomAlgoAPI
+ ../Events
+)
+
+SET(PROJECT_LIBRARIES
+ Events
+ ModelAPI
+ GeomAPI
+ GeomAlgoAPI
+)
+
+ADD_DEFINITIONS(-DPRIMITIVESPLUGIN_EXPORTS)
+ADD_LIBRARY(PrimitivesPlugin MODULE ${PROJECT_SOURCES} ${PROJECT_HEADERS} ${XML_RESOURCES})
+TARGET_LINK_LIBRARIES(PrimitivesPlugin ${PROJECT_LIBRARIES})
+
+INSTALL(TARGETS PrimitivesPlugin DESTINATION ${SHAPER_INSTALL_PLUGIN_FILES})
+INSTALL(FILES ${XML_RESOURCES} DESTINATION ${SHAPER_INSTALL_XML_RESOURCES})
+
+ADD_UNIT_TESTS(UnitTestBox.py
+ UseTestBox.py)
\ No newline at end of file
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#ifndef PRIMITIVESPLUGIN_H
+#define PRIMITIVESPLUGIN_H
+
+#if defined PRIMITIVESPLUGIN_EXPORTS
+#if defined WIN32
+#define PRIMITIVESPLUGIN_EXPORT __declspec( dllexport )
+#else
+#define PRIMITIVESPLUGIN_EXPORT
+#endif
+#else
+#if defined WIN32
+#define PRIMITIVESPLUGIN_EXPORT __declspec( dllimport )
+#else
+#define PRIMITIVESPLUGIN_EXPORT
+#endif
+#endif
+
+#endif
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: PrimitivesPlugin_Box.cpp
+// Created: 10 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#include <PrimitivesPlugin_Box.h>
+
+#include <ModelAPI_Data.h>
+#include <ModelAPI_ResultBody.h>
+#include <ModelAPI_AttributeDouble.h>
+#include <ModelAPI_AttributeSelection.h>
+#include <ModelAPI_AttributeString.h>
+
+#include <GeomAlgoAPI_PointBuilder.h>
+
+#include <memory>
+
+namespace ParametricAPI
+{
+//=================================================================================================
+PrimitivesPlugin_Box::PrimitivesPlugin_Box() // Nothing to do during instantiation
+{
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::initAttributes()
+{
+ data()->addAttribute(PrimitivesPlugin_Box::METHOD(), ModelAPI_AttributeString::typeId());
+
+ data()->addAttribute(PrimitivesPlugin_Box::DX(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::DY(), ModelAPI_AttributeDouble::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::DZ(), ModelAPI_AttributeDouble::typeId());
+
+ data()->addAttribute(PrimitivesPlugin_Box::POINT_FIRST(), ModelAPI_AttributeSelection::typeId());
+ data()->addAttribute(PrimitivesPlugin_Box::POINT_SECOND(), ModelAPI_AttributeSelection::typeId());
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::execute()
+{
+ AttributeStringPtr aMethodTypeAttr = string(PrimitivesPlugin_Box::METHOD());
+ std::string aMethodType = aMethodTypeAttr->value();
+
+ if (aMethodType == "BoxByDimensions")
+ createBoxByDimensions();
+
+ if (aMethodType == "BoxByTwoPoints")
+ createBoxByTwoPoints();
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::createBoxByDimensions()
+{
+ double aDx = real(PrimitivesPlugin_Box::DX())->value();
+ double aDy = real(PrimitivesPlugin_Box::DY())->value();
+ double aDz = real(PrimitivesPlugin_Box::DZ())->value();
+
+ std::shared_ptr<GeomAlgoAPI_Box> aBoxAlgo(new GeomAlgoAPI_Box(aDx,aDy,aDz));
+
+ // These checks should be made to the GUI for the feature but the corresponding validator does not exist yet.
+ if (!aBoxAlgo->check()) {
+ // The error is not displayed in a popup window. It must be in the status bar.
+ setError(aBoxAlgo->getError(), false);
+ return;
+ }
+
+ // Build the box
+ aBoxAlgo->build();
+
+ // Check if the creation of the box
+ if(!aBoxAlgo->isDone()) {
+ setError(aBoxAlgo->getError());
+ return;
+ }
+
+ int aResultIndex = 0;
+ ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aBoxAlgo, aResultBox);
+ setResult(aResultBox, aResultIndex);
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::createBoxByTwoPoints()
+{
+ AttributeSelectionPtr aRef1 = data()->selection(PrimitivesPlugin_Box::POINT_FIRST());
+ AttributeSelectionPtr aRef2 = data()->selection(PrimitivesPlugin_Box::POINT_SECOND());
+
+ std::shared_ptr<GeomAlgoAPI_BoxPoints> aBoxAlgo;
+
+ if ((aRef1.get() != NULL) && (aRef2.get() != NULL)) {
+ GeomShapePtr aShape1 = aRef1->value();
+ if (!aShape1.get()) //If we can't get the points directly, try getting them from the context
+ aShape1 = aRef1->context()->shape();
+ GeomShapePtr aShape2 = aRef2->value();
+ if (!aShape2.get())
+ aShape2 = aRef2->context()->shape();
+ if (aShape1 && aShape2){
+ std::shared_ptr<GeomAPI_Pnt> aFirstPoint = GeomAlgoAPI_PointBuilder::point(aShape1);
+ std::shared_ptr<GeomAPI_Pnt> aSecondPoint = GeomAlgoAPI_PointBuilder::point(aShape2);
+ aBoxAlgo = std::shared_ptr<GeomAlgoAPI_BoxPoints>(new GeomAlgoAPI_BoxPoints(aFirstPoint,aSecondPoint));
+ }
+ }
+
+ // These checks should be made to the GUI for the feature but the corresponding validator does not exist yet.
+ if (!aBoxAlgo->check()) {
+ // The error is not displayed in a popup window. It must be in the status bar.
+ setError(aBoxAlgo->getError(),false);
+ return;
+ }
+
+ // Build the box
+ aBoxAlgo->build();
+
+ // Check if the creation of the box
+ if(!aBoxAlgo->isDone()) {
+ setError(aBoxAlgo->getError());
+ return;
+ }
+
+ int aResultIndex = 0;
+ ResultBodyPtr aResultBox = document()->createBody(data(), aResultIndex);
+ loadNamingDS(aBoxAlgo, aResultBox);
+ setResult(aResultBox, aResultIndex);
+}
+
+//=================================================================================================
+void PrimitivesPlugin_Box::loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBox)
+{
+ // Load the result
+ theResultBox->store(theBoxAlgo->shape());
+
+ // Prepare the naming
+ theBoxAlgo->prepareNamingFaces();
+
+ // Insert to faces
+ int num = 1;
+ std::map< std::string, std::shared_ptr<GeomAPI_Shape> > listOfFaces = theBoxAlgo->getCreatedFaces();
+ for (std::map< std::string, std::shared_ptr<GeomAPI_Shape> >::iterator it=listOfFaces.begin(); it!=listOfFaces.end(); ++it) {
+ std::shared_ptr<GeomAPI_Shape> aFace = (*it).second;
+ theResultBox->generated(aFace, (*it).first, num++);
+ }
+}
+
+} //namespace ParametricAPI
--- /dev/null
+// Copyright (C) 2014-2016 CEA/DEN, EDF R&D
+
+// File: PrimitivesPlugin_Box.h
+// Created: 10 Mar 2016
+// Author: Clarisse Genrault (CEA)
+
+#ifndef PrimitivesPlugin_Box_H_
+#define PrimitivesPlugin_Box_H_
+
+#include <PrimitivesPlugin.h>
+#include <ModelAPI_Feature.h>
+#include <GeomAlgoAPI_Box.h>
+#include <GeomAlgoAPI_BoxPoints.h>
+
+class GeomAPI_Shape;
+class ModelAPI_ResultBody;
+
+namespace ParametricAPI
+{
+/**\class PrimitivesPlugin_Box
+ * \ingroup Plugins
+ * \brief Feature for creation of a box primitive using various methods.
+ *
+ * Box creates a cuboid - Parallelepiped with 6 rectangular faces. It can be built via two
+ * methods : using two points that define a diagonal, or using 3 lengths that define the
+ * rectangular dimensions.
+ */
+class PrimitivesPlugin_Box : public ModelAPI_Feature
+{
+ public:
+ /// Box kind
+ inline static const std::string& ID()
+ {
+ static const std::string MY_BOX_ID("Box");
+ return MY_BOX_ID;
+ }
+
+ /// attribute name for creation method
+ inline static const std::string& METHOD()
+ {
+ static const std::string METHOD_ATTR("CreationMethod");
+ return METHOD_ATTR;
+ }
+
+ /// attribute name of first point
+ inline static const std::string& POINT_FIRST()
+ {
+ static const std::string MY_POINT_FIRST("FirstPoint");
+ return MY_POINT_FIRST;
+ }
+
+ /// attribute name of second point
+ inline static const std::string& POINT_SECOND()
+ {
+ static const std::string MY_POINT_SECOND("SecondPoint");
+ return MY_POINT_SECOND;
+ }
+
+ /// attribute first coordinate
+ inline static const std::string& DX()
+ {
+ static const std::string MY_DX("dx");
+ return MY_DX;
+ }
+
+ /// attribute second coordinate
+ inline static const std::string& DY()
+ {
+ static const std::string MY_DY("dy");
+ return MY_DY;
+ }
+
+ /// attribute third coordinate
+ inline static const std::string& DZ()
+ {
+ static const std::string MY_DZ("dz");
+ return MY_DZ;
+ }
+
+ /// Returns the kind of a feature
+ PRIMITIVESPLUGIN_EXPORT virtual const std::string& getKind()
+ {
+ static std::string MY_KIND = PrimitivesPlugin_Box::ID();
+ return MY_KIND;
+ }
+
+ /// Creates a new part document if needed
+ PRIMITIVESPLUGIN_EXPORT virtual void execute();
+
+ /// Request for initialization of data model of the feature: adding all attributes
+ PRIMITIVESPLUGIN_EXPORT virtual void initAttributes();
+
+ /// Use plugin manager for features creation
+ PrimitivesPlugin_Box();
+
+ private:
+ /// Load Naming data structure of the feature to the document
+ void loadNamingDS(std::shared_ptr<GeomAlgoAPI_Box> theBoxAlgo,
+ std::shared_ptr<ModelAPI_ResultBody> theResultBox);
+
+ ///Perform the creation of the box using two points defining a diagonal
+ void createBoxByTwoPoints();
+
+ ///Perform the creation of the box using three cordinates
+ void createBoxByDimensions();
+
+};
+
+} //namespace ParametricAPI
+
+#endif
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+#include <PrimitivesPlugin_Plugin.h>
+
+#include <PrimitivesPlugin_Box.h>
+
+#include <ModelAPI_Session.h>
+
+#include <string>
+
+#include <memory>
+
+#include <iostream>
+
+using namespace std;
+using namespace ParametricAPI;
+
+// the only created instance of this plugin
+static PrimitivesPlugin_Plugin* MY_PRIMITIVES_INSTANCE = new PrimitivesPlugin_Plugin();
+
+PrimitivesPlugin_Plugin::PrimitivesPlugin_Plugin()
+{
+ // register this plugin
+ ModelAPI_Session::get()->registerPlugin(this);
+}
+
+FeaturePtr PrimitivesPlugin_Plugin::createFeature(string theFeatureID)
+{
+ if (theFeatureID == PrimitivesPlugin_Box::ID()) {
+ return FeaturePtr(new PrimitivesPlugin_Box);
+ }
+ // feature of such kind is not found
+ return FeaturePtr();
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+// File: PrimitivesPlugin_Plugin.hxx
+// Created: 07 July 2014
+// Author: Vitaly SMETANNIKOV
+
+#ifndef PrimitivesPlugin_Plugin_H_
+#define PrimitivesPlugin_Plugin_H_
+
+#include "PrimitivesPlugin.h"
+#include <ModelAPI_Plugin.h>
+#include <ModelAPI_Feature.h>
+
+/**\class PrimitivesPlugin_Plugin
+ * \ingroup Plugins
+ * \brief The main class managing Primitive Features as plugins.
+ */
+class PRIMITIVESPLUGIN_EXPORT PrimitivesPlugin_Plugin : public ModelAPI_Plugin
+{
+ public:
+ /// Creates the feature object of this plugin by the feature string ID
+ virtual FeaturePtr createFeature(std::string theFeatureID);
+
+ public:
+ /// Default constructor
+ PrimitivesPlugin_Plugin();
+};
+
+#endif
--- /dev/null
+from GeomAlgoAPI import GeomAlgoAPI_DirectAPI as shaperpy
+from GeomAlgoAPI import GeomAlgoAPI_Exception as myExcept
+from GeomAPI import GeomAPI_Pnt as pnt
+
+import GEOM
+import salome
+from salome.geom import geomBuilder
+geompy = geomBuilder.New(salome.myStudy)
+
+# Create a box with dimensions
+try :
+ box1 = shaperpy.MakeBox(5.,15.,5.)
+ aDump1 = box1.getShapeStream()
+ aBrep1 = geompy.RestoreShape(aDump1)
+ geompy.addToStudy(aBrep1, "box1")
+
+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)
+ aDump2 = box2.getShapeStream()
+ aBrep2 = geompy.RestoreShape(aDump2)
+ geompy.addToStudy(aBrep2, "box2")
+
+except myExcept,ec:
+ print ec.what()
+
+
+# Create a box with null dimensions
+try :
+ box3 = shaperpy.MakeBox(0.,0.,0.)
+ aDump3 = box1.getShapeStream()
+ aBrep3 = geompy.RestoreShape(aDump3)
+ geompy.addToStudy(aBrep1, "box3")
+
+except myExcept,ec:
+ print ec.what()
\ No newline at end of file
--- /dev/null
+"""
+ 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("BoxByCoordinates")
+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("CreationMethod").setValue("PlaneByFaceAndDistance")
+aSelectionAttr = aPlaneTop.selection("planeFace")
+aSelectionAttr.selectSubShape("face", "Box_1_1/Top_1")
+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.real("x").setValue(2.0)
+aPoint1.real("y").setValue(2.0)
+aPoint1.real("z").setValue(2.0)
+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("CreationMethod").setValue("PlaneByFaceAndDistance")
+aSelectionAttr = aPlaneRight.selection("planeFace")
+aSelectionAttr.selectSubShape("face", "Box_2_1/Right_1")
+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
+#=========================================================================
--- /dev/null
+<!-- Copyright (C) 2015-20xx CEA/DEN, EDF R&D -->
+
+<source>
+ <toolbox id="CreationMethod">
+ <box id="BoxByDimensions" title="By dimensions" icon=":icons/box_dxyz_32x32.png">
+ <doublevalue
+ id="dx"
+ label="DX"
+ step="1.0"
+ default="10.0"
+ min="0.0"
+ icon=""
+ tooltip="Dimension in X">
+ </doublevalue>
+ <doublevalue
+ id="dy"
+ label="DY"
+ step="1.0"
+ default="10.0"
+ min="0.0"
+ icon=""
+ tooltip="Dimension in Y">
+ </doublevalue>
+ <doublevalue
+ id="dz"
+ label="DZ"
+ step="1.0"
+ default="10.0"
+ min="0.0"
+ icon=""
+ tooltip="Dimension in Z">
+ </doublevalue>
+ </box>
+ <box id="BoxByTwoPoints" title="By two points" icon=":icons/box_2pt_32x32.png">
+ <shape_selector id="FirstPoint"
+ label="First point"
+ icon=":icons/point.png"
+ tooltip="Select a first point"
+ shape_types="vertex">
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ </shape_selector>
+ <shape_selector id="SecondPoint"
+ label="Second point"
+ icon=":icons/point.png"
+ tooltip="Select a second point"
+ shape_types="vertex">
+ <validator id="GeomValidators_ShapeType" parameters="vertex"/>
+ <validator id="GeomValidators_DifferentShapes"/>
+ </shape_selector>
+ </box>
+ </toolbox>
+</source>
--- /dev/null
+<!-- Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
+
+<plugin>
+ <workbench id="Primitives" document="Part">
+ <group id="Primitives">
+ <feature id="Box" title="Create a box" tooltip="Create a box" icon=":icons/box.png">
+ <source path="box_widget.xml"/>
+ </feature>
+ </group>
+ </workbench>
+</plugin>
@staticmethod
def ID():
"""Return Id of the feature."""
- return "Box"
+ return "Box_script"
@staticmethod
def WIDTH_ID():
<workbench id="Macros" document="Part">
<group id="Samples">
- <feature id="Box" title="Box" tooltip="Create a box parallel to xyz by extruding a rectangular" icon="icons/Addons/box_ico.png">
+ <feature id="Box_script" title="Box" tooltip="Create a box parallel to xyz by extruding a rectangular" icon="icons/Addons/box_ico.png">
<doublevalue id="width" label="Width: " min="0" step="1.0" default="50" tooltip="Box width">
<validator id="GeomValidators_Positive"/>
</doublevalue>