0025656: Specification of semantic of Closed flag of an edge
[occt.git] / src / ShapeUpgrade / ShapeUpgrade_FaceDivideArea.cxx
CommitLineData
973c2be1 1// Copyright (c) 1999-2014 OPEN CASCADE SAS
b311480e 2//
973c2be1 3// This file is part of Open CASCADE Technology software library.
b311480e 4//
d5f74e42 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
973c2be1 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.
b311480e 10//
973c2be1 11// Alternatively, this file may be used under the terms of Open CASCADE
12// commercial license or contractual agreement.
b311480e 13
7fd59977 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>
21#include <TopoDS.hxx>
22#include <ShapeExtend.hxx>
23#include <ShapeBuild_ReShape.hxx>
24#include <BRep_Builder.hxx>
b311480e 25
7fd59977 26//=======================================================================
27//function : ShapeUpgrade_FaceDivideArea
28//purpose :
29//=======================================================================
30
31ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
32{
33 myMaxArea = Precision::Infinite();
34 SetPrecision(1.e-5);
35 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
36}
37
38//=======================================================================
39//function : ShapeUpgrade_FaceDivideArea
40//purpose :
41//=======================================================================
42
43ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
44{
45 myMaxArea = Precision::Infinite();
46 SetPrecision(1.e-5);
47 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
48 Init(F);
49}
50
51//=======================================================================
52//function : Perform
53//purpose :
54//=======================================================================
55
56 Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform()
57{
58 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
59 GProp_GProps aGprop;
60
61 BRepGProp::SurfaceProperties(myFace,aGprop,Precision());
62 Standard_Real anArea = aGprop.Mass();
63 if((anArea - myMaxArea) < Precision::Confusion())
64 return Standard_False;
65
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;
74
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();
81
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);
86 Init(aFace);
87 BRep_Builder aB;
88 if(Perform()) {
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());
94 }
95 else
96 aB.Add(aCopyRes,aFace);
97 }
98 if(isModified)
ab860031 99 {
da72a17c 100 if (aCopyRes.ShapeType() == TopAbs_WIRE || aCopyRes.ShapeType() == TopAbs_SHELL)
101 aCopyRes.Closed (BRep_Tool::IsClosed (aCopyRes));
7fd59977 102 Context()->Replace(aResult,aCopyRes);
ab860031 103 }
7fd59977 104 myStatus |= aStatus;
105 myResult = Context()->Apply ( aResult );
106 return Status ( ShapeExtend_DONE );
107}
108