#include <GeomAlgoAPI_Prism.h>
#include <GeomAlgoAPI_Revolution.h>
#include <GeomAlgoAPI_ShapeTools.h>
+#include <GeomAlgoAPI_SketchBuilder.h>
+
+#include <GeomAPI_PlanarEdges.h>
#include <GeomAPI_ShapeExplorer.h>
+#include <map>
#include <sstream>
//=================================================================================================
theBaseShapesList.clear();
ListOfShape aBaseFacesList;
+ std::map<ResultConstructionPtr, ListOfShape> aSketchWiresMap;
AttributeSelectionListPtr aBaseObjectsSelectionList = selectionList(BASE_OBJECTS_ID());
if(!aBaseObjectsSelectionList.get()) {
setError("Error: Could not get base objects selection list.");
for(int anIndex = 0; anIndex < aBaseObjectsSelectionList->size(); anIndex++) {
AttributeSelectionPtr aBaseObjectSelection = aBaseObjectsSelectionList->value(anIndex);
if(!aBaseObjectSelection.get()) {
- setError("Error: One of the selected base objects is empty.");
+ setError("Error: Selected base object is empty.");
return;
}
GeomShapePtr aBaseShape = aBaseObjectSelection->value();
setError("Error: Selected shapes has unsupported type.");
return;
}
- aST == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) :
- theBaseShapesList.push_back(aBaseShape);
+ if(aST == GeomAPI_Shape::WIRE) {
+ ResultConstructionPtr aConstruction =
+ std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
+ if(aConstruction.get() && !aBaseShape->isEqual(aConstruction->shape())) {
+ // It is a wire on the sketch, store it to make face later.
+ aSketchWiresMap[aConstruction].push_back(aBaseShape);
+ continue;
+ }
+ } else {
+ aST == GeomAPI_Shape::FACE ? aBaseFacesList.push_back(aBaseShape) :
+ theBaseShapesList.push_back(aBaseShape);
+ }
} else {
// This may be the whole sketch result selected, check and get faces.
ResultConstructionPtr aConstruction =
std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aBaseObjectSelection->context());
if(!aConstruction.get()) {
- setError("Error: One of selected sketches does not have results.");
+ setError("Error: Selected sketches does not have results.");
return;
}
int aFacesNum = aConstruction->facesNum();
for(int aFaceIndex = 0; aFaceIndex < aFacesNum; aFaceIndex++) {
GeomShapePtr aBaseFace = aConstruction->face(aFaceIndex);
if(!aBaseFace.get() || aBaseFace->isNull()) {
- setError("Error: One of the faces on selected sketch is Null.");
+ setError("Error: One of the faces on selected sketch is null.");
return;
}
aBaseFacesList.push_back(aBaseFace);
}
}
+ // Make faces from sketch wires.
+ for(std::map<ResultConstructionPtr, ListOfShape>::const_iterator anIt = aSketchWiresMap.cbegin();
+ anIt != aSketchWiresMap.cend(); ++anIt) {
+ const std::shared_ptr<GeomAPI_PlanarEdges> aSketchPlanarEdges =
+ std::dynamic_pointer_cast<GeomAPI_PlanarEdges>((*anIt).first->shape());
+ const ListOfShape& aWiresList = (*anIt).second;
+ ListOfShape aFaces;
+ GeomAlgoAPI_ShapeTools::makeFacesWithHoles(aSketchPlanarEdges->origin(),
+ aSketchPlanarEdges->norm(),
+ aWiresList,
+ aFaces);
+ aBaseFacesList.insert(aBaseFacesList.end(), aFaces.begin(), aFaces.end());
+ }
+
// Searching faces with common edges.
if(theIsMakeShells) {
ListOfShape aShells;
// Created: 3 August 2015
// Author: Dmitry Bobylev
-#include <GeomAlgoAPI_ShapeTools.h>
+#include "GeomAlgoAPI_ShapeTools.h"
-#include <GeomAlgoAPI_CompoundBuilder.h>
+#include "GeomAlgoAPI_SketchBuilder.h"
-#include <gp_Pln.hxx>
+#include <GeomAPI_Dir.h>
+#include <GeomAPI_PlanarEdges.h>
+#include <GeomAPI_Pnt.h>
#include <Bnd_Box.hxx>
#include <BOPTools.hxx>
+#include <BRep_Builder.hxx>
+#include <BRepAlgo_FaceRestrictor.hxx>
#include <BRepBndLib.hxx>
#include <BRepBuilderAPI_MakeFace.hxx>
#include <BRepGProp.hxx>
-#include <BRepTools.hxx>
#include <BRep_Tool.hxx>
#include <Geom_Plane.hxx>
#include <GeomLib_IsPlanarSurface.hxx>
#include <GeomLib_Tool.hxx>
+#include <gp_Pln.hxx>
#include <GProp_GProps.hxx>
#include <IntAna_IntConicQuad.hxx>
#include <IntAna_Quadric.hxx>
#include <NCollection_Vector.hxx>
#include <ShapeAnalysis.hxx>
-#include <TCollection_AsciiString.hxx>
#include <TopoDS_Builder.hxx>
#include <TopoDS_Face.hxx>
#include <TopoDS_Shape.hxx>
#include <TopExp_Explorer.hxx>
+void mapWireFaces(const TopoDS_Shape& theShape,
+ BOPCol_IndexedDataMapOfShapeListOfShape& theMapWireFaces);
+
//=================================================================================================
double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
{
theV1 = aGeomV1;
theV2 = aGeomV2;
}
+
+//=================================================================================================
+void GeomAlgoAPI_ShapeTools::makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
+ const std::shared_ptr<GeomAPI_Dir> theDirection,
+ const ListOfShape& theWires,
+ ListOfShape& theFaces)
+{
+ BRepBuilderAPI_MakeFace aMKFace(gp_Pln(theOrigin->impl<gp_Pnt>(),
+ theDirection->impl<gp_Dir>()));
+ TopoDS_Face aFace = aMKFace.Face();
+
+ BRepAlgo_FaceRestrictor aFRestrictor;
+ aFRestrictor.Init(aFace);
+ for(ListOfShape::const_iterator anIt = theWires.cbegin();
+ anIt != theWires.cend();
+ ++anIt) {
+ TopoDS_Wire aWire = TopoDS::Wire((*anIt)->impl<TopoDS_Shape>());
+ aFRestrictor.Add(aWire);
+ }
+
+ aFRestrictor.Perform();
+
+ if(!aFRestrictor.IsDone()) {
+ return;
+ }
+
+ for(; aFRestrictor.More(); aFRestrictor.Next()) {
+ GeomShapePtr aShape(new GeomAPI_Shape());
+ aShape->setImpl(new TopoDS_Shape(aFRestrictor.Current()));
+ theFaces.push_back(aShape);
+ }
+}
#include "GeomAlgoAPI.h"
-#include <GeomAPI_Pnt.h>
#include <GeomAPI_Shape.h>
#include <GeomAPI_Vertex.h>
+class GeomAPI_Dir;
+class GeomAPI_PlanarEdges;
+class GeomAPI_Pnt;
+
/// \class GeomAlgoAPI_ShapeTools
/// \ingroup DataAlgo
/// \brief Useful tools for working with shapes.
{
public:
/// \return the total volume of the solids of the current shape or 0.0 if it can be computed.
- static double volume(const std::shared_ptr<GeomAPI_Shape> theShape);
+ static double volume(const GeomShapePtr theShape);
/// \return the centre of mass of the current face. The coordinates returned for the center of mass
/// are expressed in the absolute Cartesian coordinate system. (This function works only for surfaces).
- static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const std::shared_ptr<GeomAPI_Shape> theShape);
+ static std::shared_ptr<GeomAPI_Pnt> centreOfMass(const GeomShapePtr theShape);
/// \brief Combines faces with common edges to shells, or solids to compsolids.
/// \param[in] theCompound compound of shapes.
/// \param[in] theType type of combine.
/// \param[out] theCombinedShapes resulting shapes.
/// \param[out] theFreeShapes shapes that does not have common subshapes.
- static void combineShapes(const std::shared_ptr<GeomAPI_Shape> theCompound,
+ static void combineShapes(const GeomShapePtr theCompound,
const GeomAPI_Shape::ShapeType theType,
ListOfShape& theCombinedShapes,
ListOfShape& theFreeShapes);
static std::list<std::shared_ptr<GeomAPI_Pnt> > getBoundingBox(const ListOfShape& theShapes, const double theEnlarge = 0.0);
/// \return infinite plane received from theFace plane.
- static std::shared_ptr<GeomAPI_Shape> faceToInfinitePlane(const std::shared_ptr<GeomAPI_Shape> theFace);
+ static GeomShapePtr faceToInfinitePlane(const GeomShapePtr theFace);
/// \brief Enlarges or reduces plane to fit bounding box.
/// \return plane that fits to bounding box.
/// \param[in] thePlane base plane.
/// \param[in] thePoints bounding box points (shoud be eight).
- static std::shared_ptr<GeomAPI_Shape> fitPlaneToBox(const std::shared_ptr<GeomAPI_Shape> thePlane,
- const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
+ static GeomShapePtr fitPlaneToBox(const GeomShapePtr thePlane,
+ const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints);
/// \brief Finds the start and end vertices of theShape. theShape can be of the following type:\n
/// Vertex: theV1 and theV2 are the same and equal to theShape;\n
/// Wire : theV1 is start vertex of the first edge, theV2 is end vertex of the last edge. If wire
/// contains no edges theV1 and theV2 are nullified.\n
/// If none of the above theV1 and theV2 are nullified.
- static void findBounds(const std::shared_ptr<GeomAPI_Shape> theShape,
+ static void findBounds(const GeomShapePtr theShape,
std::shared_ptr<GeomAPI_Vertex>& theV1,
std::shared_ptr<GeomAPI_Vertex>& theV2);
+ /// \Creates faces with holes from wires.
+ /// \param[in] theWires base wires.
+ /// \param[out] theFaces resulting faces.
+ static void makeFacesWithHoles(const std::shared_ptr<GeomAPI_Pnt> theOrigin,
+ const std::shared_ptr<GeomAPI_Dir> theDirection,
+ const ListOfShape& theWires,
+ ListOfShape& theFaces);
};
#endif