/*************************************************************************** * Copyright (c) 2011 Thomas Anderson * * * * This file is part of the FreeCAD CAx development system. * * * * This library is free software; you can redistribute it and/or * * modify it under the terms of the GNU Library General Public * * License as published by the Free Software Foundation; either * * version 2 of the License, or (at your option) any later version. * * * * This library is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Library General Public License for more details. * * * * You should have received a copy of the GNU Library General Public * * License along with this library; see the file COPYING.LIB. If not, * * write to the Free Software Foundation, Inc., 59 Temple Place, * * Suite 330, Boston, MA 02111-1307, USA * * * ***************************************************************************/ #ifndef MODELREFINE_H #define MODELREFINE_H #include #include #include #include #include #include #include #include #include #include #include #include #include #include namespace ModelRefine { using FaceVectorType = std::vector; using EdgeVectorType = std::vector; using ShapeVectorType = std::vector; using ShapePairType = std::pair; void getFaceEdges(const TopoDS_Face &face, EdgeVectorType &edges); void boundaryEdges(const FaceVectorType &faces, EdgeVectorType &edgesOut); TopoDS_Shell removeFaces(const TopoDS_Shell &shell, const FaceVectorType &faces); class FaceTypedBase { private: FaceTypedBase() = default; protected: FaceTypedBase(const GeomAbs_SurfaceType &typeIn){surfaceType = typeIn;} public: virtual bool isEqual(const TopoDS_Face &faceOne, const TopoDS_Face &faceTwo) const = 0; virtual GeomAbs_SurfaceType getType() const = 0; virtual TopoDS_Face buildFace(const FaceVectorType &faces) const = 0; static GeomAbs_SurfaceType getFaceType(const TopoDS_Face &faceIn); protected: virtual void boundarySplit(const FaceVectorType &facesIn, std::vector &boundariesOut) const; GeomAbs_SurfaceType surfaceType; }; class FaceTypedPlane : public FaceTypedBase { private: FaceTypedPlane(); public: bool isEqual(const TopoDS_Face &faceOne, const TopoDS_Face &faceTwo) const override; GeomAbs_SurfaceType getType() const override; TopoDS_Face buildFace(const FaceVectorType &faces) const override; friend FaceTypedPlane& getPlaneObject(); }; FaceTypedPlane& getPlaneObject(); class FaceTypedCylinder : public FaceTypedBase { private: FaceTypedCylinder(); public: bool isEqual(const TopoDS_Face &faceOne, const TopoDS_Face &faceTwo) const override; GeomAbs_SurfaceType getType() const override; TopoDS_Face buildFace(const FaceVectorType &faces) const override; friend FaceTypedCylinder& getCylinderObject(); protected: void boundarySplit(const FaceVectorType &facesIn, std::vector &boundariesOut) const override; }; FaceTypedCylinder& getCylinderObject(); class FaceTypedBSpline : public FaceTypedBase { private: FaceTypedBSpline(); public: bool isEqual(const TopoDS_Face &faceOne, const TopoDS_Face &faceTwo) const override; GeomAbs_SurfaceType getType() const override; TopoDS_Face buildFace(const FaceVectorType &faces) const override; friend FaceTypedBSpline& getBSplineObject(); }; FaceTypedBSpline& getBSplineObject(); class FaceTypeSplitter { using SplitMapType = std::map; public: FaceTypeSplitter() = default; void addShell(const TopoDS_Shell &shellIn); void registerType(const GeomAbs_SurfaceType &type); bool hasType(const GeomAbs_SurfaceType &type) const; void split(); const FaceVectorType& getTypedFaceVector(const GeomAbs_SurfaceType &type) const; private: SplitMapType typeMap; TopoDS_Shell shell; }; class FaceAdjacencySplitter { public: FaceAdjacencySplitter(const TopoDS_Shell &shell); void split(const FaceVectorType &facesIn); std::size_t getGroupCount() const {return adjacencyArray.size();} const FaceVectorType& getGroup(const std::size_t &index) const {return adjacencyArray[index];} private: FaceAdjacencySplitter() = default; void recursiveFind(const TopoDS_Face &face, FaceVectorType &outVector); std::vector adjacencyArray; TopTools_MapOfShape processedMap; TopTools_MapOfShape facesInMap; TopTools_IndexedDataMapOfShapeListOfShape faceToEdgeMap; TopTools_IndexedDataMapOfShapeListOfShape edgeToFaceMap; }; class FaceEqualitySplitter { public: FaceEqualitySplitter() = default; void split(const FaceVectorType &faces, FaceTypedBase *object); std::size_t getGroupCount() const {return equalityVector.size();} const FaceVectorType& getGroup(const std::size_t &index) const {return equalityVector[index];} private: std::vector equalityVector; }; class FaceUniter { private: FaceUniter() = default; public: FaceUniter(const TopoDS_Shell &shellIn); bool process(); const TopoDS_Shell& getShell() const {return workShell;} bool isModified(){return modifiedSignal;} const std::vector& getModifiedShapes() const {return modifiedShapes;} const ShapeVectorType& getDeletedShapes() const {return deletedShapes;} private: TopoDS_Shell workShell; std::vector typeObjects; std::vector modifiedShapes; ShapeVectorType deletedShapes; bool modifiedSignal; }; } /* excerpt from GeomAbs_SurfaceType.hxx enum GeomAbs_SurfaceType { GeomAbs_Plane, GeomAbs_Cylinder, GeomAbs_Cone, GeomAbs_Sphere, GeomAbs_Torus, GeomAbs_BezierSurface, GeomAbs_BSplineSurface, GeomAbs_SurfaceOfRevolution, GeomAbs_SurfaceOfExtrusion, GeomAbs_OffsetSurface, GeomAbs_OtherSurface }; */ namespace Part { class PartExport BRepBuilderAPI_RefineModel : public BRepBuilderAPI_MakeShape { public: BRepBuilderAPI_RefineModel(const TopoDS_Shape&); #if OCC_VERSION_HEX >= 0x070600 void Build(const Message_ProgressRange& theRange = Message_ProgressRange()) override; #else void Build() override; #endif const TopTools_ListOfShape& Modified(const TopoDS_Shape& S) override; Standard_Boolean IsDeleted(const TopoDS_Shape& S) override; private: void LogModifications(const ModelRefine::FaceUniter& uniter); protected: TopTools_DataMapOfShapeListOfShape myModified; TopTools_ListOfShape myEmptyList; TopTools_ListOfShape myDeleted; }; } #endif // MODELREFINE_H