]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1343: Make faces with/without holes from sketch wires.
authordbv <dbv@opencascade.com>
Wed, 13 Apr 2016 12:51:39 +0000 (15:51 +0300)
committerdbv <dbv@opencascade.com>
Wed, 13 Apr 2016 12:51:57 +0000 (15:51 +0300)
src/FeaturesPlugin/FeaturesPlugin_CompositeSketch.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h

index 5e7c13d43b14d6b22555231d2e65e0b87f055c40..114b0a3b18f94a7d5d01bd3d8cf98d89e5e28afb 100644 (file)
 #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>
 
 //=================================================================================================
@@ -111,6 +115,7 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis
   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.");
@@ -123,7 +128,7 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis
   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();
@@ -134,14 +139,24 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis
         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();
@@ -162,7 +177,7 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis
         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);
@@ -171,6 +186,20 @@ void FeaturesPlugin_CompositeSketch::getBaseShapes(ListOfShape& theBaseShapesLis
     }
   }
 
+  // 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;
index fda821e1f4eb5ee5d578ab6ae6acbdc70d990617..f793d5b0e87c9df39b89c3cc765bf6ffb9aa3c00 100644 (file)
@@ -4,28 +4,31 @@
 // 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>
@@ -35,6 +38,9 @@
 #include <TopExp_Explorer.hxx>
 
 
+void mapWireFaces(const TopoDS_Shape& theShape,
+                  BOPCol_IndexedDataMapOfShapeListOfShape& theMapWireFaces);
+
 //=================================================================================================
 double GeomAlgoAPI_ShapeTools::volume(const std::shared_ptr<GeomAPI_Shape> theShape)
 {
@@ -333,3 +339,35 @@ void GeomAlgoAPI_ShapeTools::findBounds(const std::shared_ptr<GeomAPI_Shape> the
   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);
+  }
+}
index 8726f670a5dd12414650efab90f0cdc8b2c4314a..6e23642182cc5bda28ade2cef0fb0120c9f62eb3 100644 (file)
@@ -9,10 +9,13 @@
 
 #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.
@@ -20,18 +23,18 @@ class GEOMALGOAPI_EXPORT GeomAlgoAPI_ShapeTools
 {
 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);
@@ -43,14 +46,14 @@ public:
   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
@@ -58,10 +61,17 @@ public:
   /// 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