#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeString.h>
#include <ModelAPI_AttributeReference.h>
-#include <GeomAPI_Pln.h>
-#include <GeomAPI_XYZ.h>
#include <GeomAlgoAPI_Extrusion.h>
#include <GeomAlgoAPI_FaceBuilder.h>
#include <GeomAlgoAPI_Prism.h>
aBaseShape = std::dynamic_pointer_cast<GeomAPI_Shape>(aConstruction->face(aFaceIndex));
}
- // If bounding faces was not set creating them.
- std::shared_ptr<GeomAPI_Face> aBaseFace(new GeomAPI_Face(aBaseShape));
- std::shared_ptr<GeomAPI_Pln> aBasePln = aBaseFace->getPlane();
- std::shared_ptr<GeomAPI_Dir> aBaseDir = aBasePln->direction();
- std::shared_ptr<GeomAPI_Pnt> aBaseLoc = aBasePln->location();
- std::shared_ptr<GeomAPI_Shape> aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
-
- std::shared_ptr<GeomAPI_Shape> aBoundingFromShape = aFromShape ? aFromShape : aBasePlane;
- std::shared_ptr<GeomAPI_Shape> aBoundingToShape = aToShape ? aToShape : aBasePlane;
-
- // Moving bounding faces according to "from" and "to" sizes.
- std::shared_ptr<GeomAPI_Face> aFromFace(new GeomAPI_Face(aBoundingFromShape));
- std::shared_ptr<GeomAPI_Pln> aFromPln = aFromFace->getPlane();
- std::shared_ptr<GeomAPI_Pnt> aFromLoc = aFromPln->location();
- std::shared_ptr<GeomAPI_Dir> aFromDir = aFromPln->direction();
-
- std::shared_ptr<GeomAPI_Face> aToFace(new GeomAPI_Face(aBoundingToShape));
- std::shared_ptr<GeomAPI_Pln> aToPln = aToFace->getPlane();
- std::shared_ptr<GeomAPI_Pnt> aToLoc = aToPln->location();
- std::shared_ptr<GeomAPI_Dir> aToDir = aToPln->direction();
-
- bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
-
- std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? aFromSize : -aFromSize))));
- aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
-
- std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(aSign ? -aToSize : aToSize))));
- aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
-
- //GeomAlgoAPI_Extrusion aFeature(aFace, aFromSize);
- GeomAlgoAPI_Prism aFeature(aBaseShape, aBoundingFromShape, aBoundingToShape);
+ GeomAlgoAPI_Prism aFeature(aBaseShape, aFromShape, aFromSize, aToShape, aToSize);
if(!aFeature.isDone()) {
static const std::string aFeatureError = "Extrusion algorithm failed";
setError(aFeatureError);
else
theResultBody->storeGenerated(theBasis, theFeature.shape());
- GeomAPI_DataMapOfShapeShape* aSubShapes = new GeomAPI_DataMapOfShapeShape();
- theFeature.mapOfShapes(*aSubShapes);
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> aSubShapes = theFeature.mapOfShapes();
//Insert lateral face : Face from Edge
std::string aLatName = "LateralFace";
- theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes);
+ theResultBody->loadAndOrientGeneratedShapes(theFeature.makeShape().get(), theBasis, EDGE,_LATERAL_TAG, aLatName, *aSubShapes.get());
//Insert bottom face
std::string aBotName = "BottomFace";
#include <GeomAlgoAPI_Prism.h>
+#include <GeomAPI_Face.h>
+#include <GeomAPI_Pln.h>
+#include <GeomAPI_Pnt.h>
+#include <GeomAPI_XYZ.h>
#include <GeomAlgoAPI_DFLoader.h>
+#include <GeomAlgoAPI_FaceBuilder.h>
#include <BRep_Tool.hxx>
#include <BRepCheck_Analyzer.hxx>
#include <TopoDS.hxx>
//=================================================================================================
-GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theFromShape,
- std::shared_ptr<GeomAPI_Shape> theToShape)
-: myFromShape(theFromShape),
- myToShape(theToShape),
- myDone(false),
- myShape(new GeomAPI_Shape()),
- myFirst(new GeomAPI_Shape()),myLast(new GeomAPI_Shape())
+GeomAlgoAPI_Prism::GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+ const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+ double theFromDistance,
+ const std::shared_ptr<GeomAPI_Shape>& theToShape,
+ double theToDistance)
+: myDone(false)
{
- build(theBasis);
+ build(theBasis, theFromShape, theFromDistance, theToShape, theToDistance);
}
//=================================================================================================
-void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis)
+void GeomAlgoAPI_Prism::build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+ const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+ double theFromDistance,
+ const std::shared_ptr<GeomAPI_Shape>& theToShape,
+ double theToDistance)
{
- if(!theBasis || !myFromShape || !myToShape ||
- (myFromShape && myToShape && myFromShape->isEqual(myToShape))) {
+ if(!theBasis ||
+ (((!theFromShape && !theToShape) || (theFromShape && theToShape && theFromShape->isEqual(theToShape)))
+ && (theFromDistance == 0.0 && theToDistance == 0.0))) {
return;
}
+ // If bounding faces was not set creating them.
+ std::shared_ptr<GeomAPI_Face> aBaseFace(new GeomAPI_Face(theBasis));
+ std::shared_ptr<GeomAPI_Pln> aBasePln = aBaseFace->getPlane();
+ std::shared_ptr<GeomAPI_Dir> aBaseDir = aBasePln->direction();
+ std::shared_ptr<GeomAPI_Pnt> aBaseLoc = aBasePln->location();
+ std::shared_ptr<GeomAPI_Shape> aBasePlane = GeomAlgoAPI_FaceBuilder::planarFace(aBaseLoc, aBaseDir);
+
+ std::shared_ptr<GeomAPI_Shape> aBoundingFromShape = theFromShape ? theFromShape : aBasePlane;
+ std::shared_ptr<GeomAPI_Shape> aBoundingToShape = theToShape ? theToShape : aBasePlane;
+
+ // Moving bounding faces according to "from" and "to" sizes.
+ std::shared_ptr<GeomAPI_Face> aFromFace(new GeomAPI_Face(aBoundingFromShape));
+ std::shared_ptr<GeomAPI_Pln> aFromPln = aFromFace->getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aFromLoc = aFromPln->location();
+ std::shared_ptr<GeomAPI_Dir> aFromDir = aFromPln->direction();
+
+ std::shared_ptr<GeomAPI_Face> aToFace(new GeomAPI_Face(aBoundingToShape));
+ std::shared_ptr<GeomAPI_Pln> aToPln = aToFace->getPlane();
+ std::shared_ptr<GeomAPI_Pnt> aToLoc = aToPln->location();
+ std::shared_ptr<GeomAPI_Dir> aToDir = aToPln->direction();
+
+ bool aSign = aFromLoc->xyz()->dot(aBaseDir->xyz()) > aToLoc->xyz()->dot(aBaseDir->xyz());
+
+ std::shared_ptr<GeomAPI_Pnt> aFromPnt(new GeomAPI_Pnt(aFromLoc->xyz()->added(aBaseDir->xyz()->multiplied(
+ aSign ? theFromDistance : -theFromDistance))));
+ aBoundingFromShape = GeomAlgoAPI_FaceBuilder::planarFace(aFromPnt, aFromDir);
+
+ std::shared_ptr<GeomAPI_Pnt> aToPnt(new GeomAPI_Pnt(aToLoc->xyz()->added(aBaseDir->xyz()->multiplied(
+ aSign ? -theToDistance : theToDistance))));
+ aBoundingToShape = GeomAlgoAPI_FaceBuilder::planarFace(aToPnt, aToDir);
+
TopoDS_Face aBasis = TopoDS::Face(theBasis->impl<TopoDS_Shape>());
Handle(Geom_Plane) aPlane = Handle(Geom_Plane)::DownCast(BRep_Tool::Surface(aBasis));
if(aPlane.IsNull()) { // non-planar shapes is not supported for extrusion yet
BRepFeat_MakePrism* aBuilder = new BRepFeat_MakePrism(aBasis, aBasis, aBasis, aNormal, 2, Standard_True);
if(aBuilder) {
- setImpl(aBuilder);
- TopoDS_Shape aFromShape = myFromShape->impl<TopoDS_Shape>();
- TopoDS_Shape aToShape = myToShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aFromShape = aBoundingFromShape->impl<TopoDS_Shape>();
+ const TopoDS_Shape& aToShape = aBoundingToShape->impl<TopoDS_Shape>();
aBuilder->Perform(aFromShape, aToShape);
myDone = aBuilder->IsDone() == Standard_True;
if(myDone){
aResult = GeomAlgoAPI_DFLoader::refineResult(aResult);
}
// fill data map to keep correct orientation of sub-shapes
+ myMap = std::make_shared<GeomAPI_DataMapOfShapeShape>();
for (TopExp_Explorer Exp(aResult,TopAbs_FACE); Exp.More(); Exp.Next()) {
std::shared_ptr<GeomAPI_Shape> aCurrentShape(new GeomAPI_Shape());
aCurrentShape->setImpl(new TopoDS_Shape(Exp.Current()));
- myMap.bind(aCurrentShape, aCurrentShape);
+ myMap->bind(aCurrentShape, aCurrentShape);
}
+ myShape = std::make_shared<GeomAPI_Shape>();
myShape->setImpl(new TopoDS_Shape(aResult));
+ myFirst = std::make_shared<GeomAPI_Shape>();
myFirst->setImpl(new TopoDS_Shape(aBuilder->Modified(aFromShape).First()));
+ myLast = std::make_shared<GeomAPI_Shape>();
myLast->setImpl(new TopoDS_Shape(aBuilder->Modified(aToShape).First()));
- myMkShape = new GeomAlgoAPI_MakeShape (aBuilder);
+ myMkShape = std::shared_ptr<GeomAlgoAPI_MakeShape>(new GeomAlgoAPI_MakeShape());
+ myMkShape->setImpl(aBuilder);
}
}
}
//=================================================================================================
-const bool GeomAlgoAPI_Prism::isDone() const
+bool GeomAlgoAPI_Prism::isDone() const
{
return myDone;
}
//=================================================================================================
-const bool GeomAlgoAPI_Prism::isValid() const
+bool GeomAlgoAPI_Prism::isValid() const
{
BRepCheck_Analyzer aChecker(myShape->impl<TopoDS_Shape>());
return (aChecker.IsValid() == Standard_True);
}
//=================================================================================================
-const bool GeomAlgoAPI_Prism::hasVolume() const
+bool GeomAlgoAPI_Prism::hasVolume() const
{
bool hasVolume(false);
if(isValid()) {
}
//=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::shape () const
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::shape() const
{
return myShape;
}
//=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::firstShape()
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::firstShape() const
{
return myFirst;
}
//=================================================================================================
-const std::shared_ptr<GeomAPI_Shape>& GeomAlgoAPI_Prism::lastShape()
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_Prism::lastShape() const
{
return myLast;
}
//=================================================================================================
-void GeomAlgoAPI_Prism::mapOfShapes (GeomAPI_DataMapOfShapeShape& theMap) const
+std::shared_ptr<GeomAPI_DataMapOfShapeShape> GeomAlgoAPI_Prism::mapOfShapes() const
{
- theMap = myMap;
+ return myMap;
}
//=================================================================================================
-GeomAlgoAPI_MakeShape* GeomAlgoAPI_Prism::makeShape() const
+std::shared_ptr<GeomAlgoAPI_MakeShape> GeomAlgoAPI_Prism::makeShape() const
{
return myMkShape;
}
-
-//=================================================================================================
-GeomAlgoAPI_Prism::~GeomAlgoAPI_Prism()
-{
- if (myImpl) {
- myMap.clear();
- }
-}
\ No newline at end of file
{
public:
/** \brief Creates extrusion for the given shape along the normal for this shape.
- * \param[in] theBasis face or wire to be extruded;
- * \param[in] theFromShape bottom bounding shape;
- * \param[in] theToShape top bounding shape;
+ * \param[in] theBasis face or wire to be extruded.
+ * \param[in] theFromShape bottom bounding shape.
+ * \param[in] theFromDistance offset for "from" plane.
+ * \param[in] theToShape top bounding shape.
+ * \param[in] theToDistance offset for "to" plane.
*/
- GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(std::shared_ptr<GeomAPI_Shape> theBasis,
- std::shared_ptr<GeomAPI_Shape> theFromShape,
- std::shared_ptr<GeomAPI_Shape> theToShape);
+ GEOMALGOAPI_EXPORT GeomAlgoAPI_Prism(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+ const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+ double theFromDistance,
+ const std::shared_ptr<GeomAPI_Shape>& theToShape,
+ double theToDistance);
/// \return true if algorithm succeed.
- GEOMALGOAPI_EXPORT const bool isDone() const;
+ GEOMALGOAPI_EXPORT bool isDone() const;
/// \return true if resulting shape is valid.
- GEOMALGOAPI_EXPORT const bool isValid() const;
+ GEOMALGOAPI_EXPORT bool isValid() const;
/// \return true if resulting shape has volume.
- GEOMALGOAPI_EXPORT const bool hasVolume() const;
+ GEOMALGOAPI_EXPORT bool hasVolume() const;
/// \return result of the Prism algorithm.
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& shape() const;
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> shape() const;
/// \returns the first shape.
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& firstShape();
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> firstShape() const;
/// \return the last shape.
- GEOMALGOAPI_EXPORT const std::shared_ptr<GeomAPI_Shape>& lastShape();
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_Shape> lastShape() const;
/// \return map of sub-shapes of the result. To be used for History keeping.
- GEOMALGOAPI_EXPORT void mapOfShapes(GeomAPI_DataMapOfShapeShape& theMap) const;
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAPI_DataMapOfShapeShape> mapOfShapes() const;
/// \return interface for History processing.
- GEOMALGOAPI_EXPORT GeomAlgoAPI_MakeShape* makeShape() const;
-
- /// Destructor.
- GEOMALGOAPI_EXPORT ~GeomAlgoAPI_Prism();
+ GEOMALGOAPI_EXPORT std::shared_ptr<GeomAlgoAPI_MakeShape> makeShape() const;
private:
/// Builds resulting shape.
- void build(const std::shared_ptr<GeomAPI_Shape>& theBasis);
+ void build(const std::shared_ptr<GeomAPI_Shape>& theBasis,
+ const std::shared_ptr<GeomAPI_Shape>& theFromShape,
+ double theFromDistance,
+ const std::shared_ptr<GeomAPI_Shape>& theToShape,
+ double theToDistance);
private:
/// Fields.
- std::shared_ptr<GeomAPI_Shape> myFromShape;
- std::shared_ptr<GeomAPI_Shape> myToShape;
bool myDone;
std::shared_ptr<GeomAPI_Shape> myShape;
std::shared_ptr<GeomAPI_Shape> myFirst;
std::shared_ptr<GeomAPI_Shape> myLast;
- GeomAPI_DataMapOfShapeShape myMap;
- GeomAlgoAPI_MakeShape* myMkShape;
+ std::shared_ptr<GeomAPI_DataMapOfShapeShape> myMap;
+ std::shared_ptr<GeomAlgoAPI_MakeShape> myMkShape;
};
#endif