#include <GEOM_Function.hxx>
+#include <BRep_Tool.hxx>
#include <BRepOffsetAPI_Sewing.hxx>
+#include <Geom_Plane.hxx>
+#include <Geom_Surface.hxx>
#include <Standard_Version.hxx>
+#include <TopExp.hxx>
+#include <TopExp_Explorer.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
+
#include <TFunction_Logbook.hxx>
#include <ShapeConvert_CanonicAPI.hxx>
+#include <ShapeConvert_Surface.hxx>
#include <ShapeConvert_UnionFaces.hxx>
#include <ShapeConvert_UnionEdges.hxx>
#include <Standard_LicenseError.hxx>
#endif // CANREC_HASLICENSE
+/**
+ * This function returns the number of shapes of a certain type.
+ *
+ * \param theShape the shape.
+ * \param theType the required type.
+ * \return the number of shapes of a certain type.
+ */
+static Standard_Integer GetNbShapes(const TopoDS_Shape &theShape,
+ const TopAbs_ShapeEnum theType)
+{
+ TopTools_IndexedMapOfShape aMapShapes;
+
+ TopExp::MapShapes(theShape, theType, aMapShapes);
+
+ const Standard_Integer aResult = aMapShapes.Extent();
+
+ return aResult;
+}
+
const Standard_GUID& CANRECPluginImpl_Driver::GetID()
{
static Standard_GUID aGUID("7e1492bb-b4cd-4a40-ad8f-102902b0047e");
return aGUID;
}
+Standard_Integer CANRECPluginImpl_Driver::GetNbCanonicalFaces
+ (const TopoDS_Shape &theShape)
+{
+ TopExp_Explorer anExp(theShape, TopAbs_FACE);
+ TopLoc_Location aLoc;
+ Standard_Integer aNbSurf = 0;
+ TopTools_MapOfShape aMapFence;
+
+ for (; anExp.More(); anExp.Next()) {
+ const TopoDS_Shape &aShFace = anExp.Current();
+
+ if (aMapFence.Add(aShFace)) {
+ TopoDS_Face aFace = TopoDS::Face(aShFace);
+ Handle(Geom_Surface) aSurface = BRep_Tool::Surface(aFace, aLoc);
+
+ if(aSurface->IsKind(STANDARD_TYPE(Geom_Plane)) ||
+ ShapeConvert_Surface::IsCanonical(aSurface)) {
+ aNbSurf++;
+ }
+ }
+ }
+
+ return aNbSurf;
+}
+
CANRECPluginImpl_Driver::CANRECPluginImpl_Driver()
{
}
aRecognizer.SurfaceMode() = isNeedMergeSurf;
aRecognizer.CurveMode() = isNeedMergeCurves;
+ const Standard_Integer anInitNbFaces = GetNbShapes(aShape, TopAbs_FACE);
+ const Standard_Integer anInitNbCanonical = GetNbCanonicalFaces(aShape);
+
// 1. Recognizing
aRecognizer.SetShape( aShape );
aRecognizer.UnifyMode() = false;
aSewing.Add( aResultingShape );
aSewing.Perform();
aResultingShape = aSewing.SewedShape();
-
+
+ const Standard_Integer aNbConverted =
+ GetNbCanonicalFaces(aResultingShape) - anInitNbCanonical;
+ Standard_Integer aNbMergedFaces = -1;
+ Standard_Integer aNbMergedEdges = -1;
+
// 3.1. Union Surfaces
if ( isNeedMergeSurf ) {
ShapeConvert_UnionFaces aFaceUnifier;
aFaceUnifier.GetTolerance() = aTolerance;
aResultingShape = aFaceUnifier.Perform( aResultingShape );
+ aNbMergedFaces = anInitNbFaces - GetNbShapes(aResultingShape, TopAbs_FACE);
}
// 3.2. Union Curves
if ( isNeedMergeCurves ) {
ShapeConvert_UnionEdges anEdgeUnifier;
- aResultingShape = anEdgeUnifier.Perform( aResultingShape, aTolerance );
+ aNbMergedEdges = GetNbShapes(aResultingShape, TopAbs_EDGE);
+ aResultingShape = anEdgeUnifier.Perform( aResultingShape, aTolerance );
+ aNbMergedEdges -= GetNbShapes(aResultingShape, TopAbs_EDGE);
}
if ( aResultingShape.IsNull() ) return 0;
+ // Create statistics
+ Handle(TColStd_HArray1OfInteger) aStat = new TColStd_HArray1OfInteger(1, 5);
+
+ aStat->SetValue(1, anInitNbFaces);
+ aStat->SetValue(2, anInitNbCanonical);
+ aStat->SetValue(3, aNbConverted);
+ aStat->SetValue(4, aNbMergedFaces);
+ aStat->SetValue(5, aNbMergedEdges);
+
+ aData.SetStatistics(aStat);
+
aFunction->SetValue( aResultingShape );
log.SetTouched( Label() );