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.
15 #include <BRep_Builder.hxx>
16 #include <BRepGProp.hxx>
17 #include <GProp_GProps.hxx>
18 #include <Precision.hxx>
19 #include <ShapeBuild_ReShape.hxx>
20 #include <ShapeExtend.hxx>
21 #include <ShapeUpgrade_FaceDivideArea.hxx>
22 #include <ShapeUpgrade_SplitSurfaceArea.hxx>
23 #include <Standard_Type.hxx>
24 #include <TopExp_Explorer.hxx>
26 #include <TopoDS_Face.hxx>
27 #include <TopoDS_Shape.hxx>
29 IMPLEMENT_STANDARD_RTTIEXT(ShapeUpgrade_FaceDivideArea,ShapeUpgrade_FaceDivide)
31 //=======================================================================
32 //function : ShapeUpgrade_FaceDivideArea
34 //=======================================================================
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);
104 if (aCopyRes.ShapeType() == TopAbs_WIRE || aCopyRes.ShapeType() == TopAbs_SHELL)
105 aCopyRes.Closed (BRep_Tool::IsClosed (aCopyRes));
106 Context()->Replace(aResult,aCopyRes);
109 myResult = Context()->Apply ( aResult );
110 return Status ( ShapeExtend_DONE );