1 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 // This file is part of Open CASCADE Technology software library.
5 // This library is free software; you can redistribute it and/or modify it under
6 // the terms of the GNU Lesser General Public License version 2.1 as published
7 // by the Free Software Foundation, with special exception defined in the file
8 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
9 // distribution for complete text of the license and disclaimer of any warranty.
11 // Alternatively, this file may be used under the terms of Open CASCADE
12 // commercial license or contractual agreement.
14 #include <ShapeUpgrade_FaceDivideArea.ixx>
15 #include <GProp_GProps.hxx>
16 #include <BRepGProp.hxx>
17 #include <Precision.hxx>
18 #include <ShapeUpgrade_SplitSurfaceArea.hxx>
19 #include <TopoDS_Shape.hxx>
20 #include <TopExp_Explorer.hxx>
22 #include <ShapeExtend.hxx>
23 #include <ShapeBuild_ReShape.hxx>
24 #include <BRep_Builder.hxx>
26 //=======================================================================
27 //function : ShapeUpgrade_FaceDivideArea
29 //=======================================================================
31 ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
33 myMaxArea = Precision::Infinite();
35 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
38 //=======================================================================
39 //function : ShapeUpgrade_FaceDivideArea
41 //=======================================================================
43 ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
45 myMaxArea = Precision::Infinite();
47 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
51 //=======================================================================
54 //=======================================================================
56 Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform()
58 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
61 BRepGProp::SurfaceProperties(myFace,aGprop,Precision());
62 Standard_Real anArea = aGprop.Mass();
63 if((anArea - myMaxArea) < Precision::Confusion())
64 return Standard_False;
66 Standard_Integer anbParts = RealToInt(ceil(anArea/myMaxArea));
67 Handle(ShapeUpgrade_SplitSurfaceArea) aSurfTool= Handle(ShapeUpgrade_SplitSurfaceArea)::
68 DownCast(GetSplitSurfaceTool ());
69 if(aSurfTool.IsNull())
70 return Standard_False;
71 aSurfTool->NbParts() = anbParts;
72 if(!ShapeUpgrade_FaceDivide::Perform())
73 return Standard_False;
75 TopoDS_Shape aResult = Result();
76 if(aResult.ShapeType() == TopAbs_FACE)
77 return Standard_False;
78 Standard_Integer aStatus = myStatus;
79 TopExp_Explorer aExpF(aResult,TopAbs_FACE);
80 TopoDS_Shape aCopyRes = aResult.EmptyCopied();
82 Standard_Boolean isModified = Standard_False;
83 for( ; aExpF.More() ; aExpF.Next()) {
84 TopoDS_Shape aSh = Context()->Apply(aExpF.Current());
85 TopoDS_Face aFace = TopoDS::Face(aSh);
89 isModified = Standard_True;
90 TopoDS_Shape aRes = Result();
91 TopExp_Explorer aExpR(aRes,TopAbs_FACE);
92 for( ; aExpR.More(); aExpR.Next())
93 aB.Add(aCopyRes,aExpR.Current());
96 aB.Add(aCopyRes,aFace);
99 Context()->Replace(aResult,aCopyRes);
101 myResult = Context()->Apply ( aResult );
102 return Status ( ShapeExtend_DONE );