7fd59977 |
1 | #include <ShapeUpgrade_FaceDivideArea.ixx> |
2 | #include <GProp_GProps.hxx> |
3 | #include <BRepGProp.hxx> |
4 | #include <Precision.hxx> |
5 | #include <ShapeUpgrade_SplitSurfaceArea.hxx> |
6 | #include <TopoDS_Shape.hxx> |
7 | #include <TopExp_Explorer.hxx> |
8 | #include <TopoDS.hxx> |
9 | #include <ShapeExtend.hxx> |
10 | #include <ShapeBuild_ReShape.hxx> |
11 | #include <BRep_Builder.hxx> |
12 | |
13 | //======================================================================= |
14 | //function : ShapeUpgrade_FaceDivideArea |
15 | //purpose : |
16 | //======================================================================= |
17 | |
18 | ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea() |
19 | { |
20 | myMaxArea = Precision::Infinite(); |
21 | SetPrecision(1.e-5); |
22 | SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea); |
23 | } |
24 | |
25 | //======================================================================= |
26 | //function : ShapeUpgrade_FaceDivideArea |
27 | //purpose : |
28 | //======================================================================= |
29 | |
30 | ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F) |
31 | { |
32 | myMaxArea = Precision::Infinite(); |
33 | SetPrecision(1.e-5); |
34 | SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea); |
35 | Init(F); |
36 | } |
37 | |
38 | //======================================================================= |
39 | //function : Perform |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform() |
44 | { |
45 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); |
46 | GProp_GProps aGprop; |
47 | |
48 | BRepGProp::SurfaceProperties(myFace,aGprop,Precision()); |
49 | Standard_Real anArea = aGprop.Mass(); |
50 | if((anArea - myMaxArea) < Precision::Confusion()) |
51 | return Standard_False; |
52 | |
53 | Standard_Integer anbParts = RealToInt(ceil(anArea/myMaxArea)); |
54 | Handle(ShapeUpgrade_SplitSurfaceArea) aSurfTool= Handle(ShapeUpgrade_SplitSurfaceArea):: |
55 | DownCast(GetSplitSurfaceTool ()); |
56 | if(aSurfTool.IsNull()) |
57 | return Standard_False; |
58 | aSurfTool->NbParts() = anbParts; |
59 | if(!ShapeUpgrade_FaceDivide::Perform()) |
60 | return Standard_False; |
61 | |
62 | TopoDS_Shape aResult = Result(); |
63 | if(aResult.ShapeType() == TopAbs_FACE) |
64 | return Standard_False; |
65 | Standard_Integer aStatus = myStatus; |
66 | TopExp_Explorer aExpF(aResult,TopAbs_FACE); |
67 | TopoDS_Shape aCopyRes = aResult.EmptyCopied(); |
68 | |
69 | Standard_Boolean isModified = Standard_False; |
70 | for( ; aExpF.More() ; aExpF.Next()) { |
71 | TopoDS_Shape aSh = Context()->Apply(aExpF.Current()); |
72 | TopoDS_Face aFace = TopoDS::Face(aSh); |
73 | Init(aFace); |
74 | BRep_Builder aB; |
75 | if(Perform()) { |
76 | isModified = Standard_True; |
77 | TopoDS_Shape aRes = Result(); |
78 | TopExp_Explorer aExpR(aRes,TopAbs_FACE); |
79 | for( ; aExpR.More(); aExpR.Next()) |
80 | aB.Add(aCopyRes,aExpR.Current()); |
81 | } |
82 | else |
83 | aB.Add(aCopyRes,aFace); |
84 | } |
85 | if(isModified) |
86 | Context()->Replace(aResult,aCopyRes); |
87 | myStatus |= aStatus; |
88 | myResult = Context()->Apply ( aResult ); |
89 | return Status ( ShapeExtend_DONE ); |
90 | } |
91 | |