1 // Copyright (c) 1999-2012 OPEN CASCADE SAS
3 // The content of this file is subject to the Open CASCADE Technology Public
4 // License Version 6.5 (the "License"). You may not use the content of this file
5 // except in compliance with the License. Please obtain a copy of the License
6 // at http://www.opencascade.org and read it completely before using this file.
8 // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
9 // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
11 // The Original Code and all software distributed under the License is
12 // distributed on an "AS IS" basis, without warranty of any kind, and the
13 // Initial Developer hereby disclaims all such warranties, including without
14 // limitation, any warranties of merchantability, fitness for a particular
15 // purpose or non-infringement. Please see the License for the specific terms
16 // and conditions governing the rights and limitations under the License.
18 #include <ShapeUpgrade_FaceDivideArea.ixx>
19 #include <GProp_GProps.hxx>
20 #include <BRepGProp.hxx>
21 #include <Precision.hxx>
22 #include <ShapeUpgrade_SplitSurfaceArea.hxx>
23 #include <TopoDS_Shape.hxx>
24 #include <TopExp_Explorer.hxx>
26 #include <ShapeExtend.hxx>
27 #include <ShapeBuild_ReShape.hxx>
28 #include <BRep_Builder.hxx>
30 //=======================================================================
31 //function : ShapeUpgrade_FaceDivideArea
33 //=======================================================================
35 ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
37 myMaxArea = Precision::Infinite();
39 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
42 //=======================================================================
43 //function : ShapeUpgrade_FaceDivideArea
45 //=======================================================================
47 ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
49 myMaxArea = Precision::Infinite();
51 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
55 //=======================================================================
58 //=======================================================================
60 Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform()
62 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
65 BRepGProp::SurfaceProperties(myFace,aGprop,Precision());
66 Standard_Real anArea = aGprop.Mass();
67 if((anArea - myMaxArea) < Precision::Confusion())
68 return Standard_False;
70 Standard_Integer anbParts = RealToInt(ceil(anArea/myMaxArea));
71 Handle(ShapeUpgrade_SplitSurfaceArea) aSurfTool= Handle(ShapeUpgrade_SplitSurfaceArea)::
72 DownCast(GetSplitSurfaceTool ());
73 if(aSurfTool.IsNull())
74 return Standard_False;
75 aSurfTool->NbParts() = anbParts;
76 if(!ShapeUpgrade_FaceDivide::Perform())
77 return Standard_False;
79 TopoDS_Shape aResult = Result();
80 if(aResult.ShapeType() == TopAbs_FACE)
81 return Standard_False;
82 Standard_Integer aStatus = myStatus;
83 TopExp_Explorer aExpF(aResult,TopAbs_FACE);
84 TopoDS_Shape aCopyRes = aResult.EmptyCopied();
86 Standard_Boolean isModified = Standard_False;
87 for( ; aExpF.More() ; aExpF.Next()) {
88 TopoDS_Shape aSh = Context()->Apply(aExpF.Current());
89 TopoDS_Face aFace = TopoDS::Face(aSh);
93 isModified = Standard_True;
94 TopoDS_Shape aRes = Result();
95 TopExp_Explorer aExpR(aRes,TopAbs_FACE);
96 for( ; aExpR.More(); aExpR.Next())
97 aB.Add(aCopyRes,aExpR.Current());
100 aB.Add(aCopyRes,aFace);
103 Context()->Replace(aResult,aCopyRes);
105 myResult = Context()->Apply ( aResult );
106 return Status ( ShapeExtend_DONE );