0026488: The class ShapeUpgrade_UnifySameDomain is not documented.
[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
42cf5bc1 14
15#include <BRep_Builder.hxx>
7fd59977 16#include <BRepGProp.hxx>
42cf5bc1 17#include <GProp_GProps.hxx>
18#include <Precision.hxx>
7fd59977 19#include <ShapeBuild_ReShape.hxx>
42cf5bc1 20#include <ShapeExtend.hxx>
21#include <ShapeUpgrade_FaceDivideArea.hxx>
22#include <ShapeUpgrade_SplitSurfaceArea.hxx>
23#include <Standard_Type.hxx>
24#include <TopExp_Explorer.hxx>
25#include <TopoDS.hxx>
26#include <TopoDS_Face.hxx>
27#include <TopoDS_Shape.hxx>
b311480e 28
7fd59977 29//=======================================================================
30//function : ShapeUpgrade_FaceDivideArea
31//purpose :
32//=======================================================================
7fd59977 33ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea()
34{
35 myMaxArea = Precision::Infinite();
36 SetPrecision(1.e-5);
37 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
38}
39
40//=======================================================================
41//function : ShapeUpgrade_FaceDivideArea
42//purpose :
43//=======================================================================
44
45ShapeUpgrade_FaceDivideArea::ShapeUpgrade_FaceDivideArea(const TopoDS_Face& F)
46{
47 myMaxArea = Precision::Infinite();
48 SetPrecision(1.e-5);
49 SetSplitSurfaceTool (new ShapeUpgrade_SplitSurfaceArea);
50 Init(F);
51}
52
53//=======================================================================
54//function : Perform
55//purpose :
56//=======================================================================
57
58 Standard_Boolean ShapeUpgrade_FaceDivideArea::Perform()
59{
60 myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK );
61 GProp_GProps aGprop;
62
63 BRepGProp::SurfaceProperties(myFace,aGprop,Precision());
64 Standard_Real anArea = aGprop.Mass();
65 if((anArea - myMaxArea) < Precision::Confusion())
66 return Standard_False;
67
68 Standard_Integer anbParts = RealToInt(ceil(anArea/myMaxArea));
69 Handle(ShapeUpgrade_SplitSurfaceArea) aSurfTool= Handle(ShapeUpgrade_SplitSurfaceArea)::
70 DownCast(GetSplitSurfaceTool ());
71 if(aSurfTool.IsNull())
72 return Standard_False;
73 aSurfTool->NbParts() = anbParts;
74 if(!ShapeUpgrade_FaceDivide::Perform())
75 return Standard_False;
76
77 TopoDS_Shape aResult = Result();
78 if(aResult.ShapeType() == TopAbs_FACE)
79 return Standard_False;
80 Standard_Integer aStatus = myStatus;
81 TopExp_Explorer aExpF(aResult,TopAbs_FACE);
82 TopoDS_Shape aCopyRes = aResult.EmptyCopied();
83
84 Standard_Boolean isModified = Standard_False;
85 for( ; aExpF.More() ; aExpF.Next()) {
86 TopoDS_Shape aSh = Context()->Apply(aExpF.Current());
87 TopoDS_Face aFace = TopoDS::Face(aSh);
88 Init(aFace);
89 BRep_Builder aB;
90 if(Perform()) {
91 isModified = Standard_True;
92 TopoDS_Shape aRes = Result();
93 TopExp_Explorer aExpR(aRes,TopAbs_FACE);
94 for( ; aExpR.More(); aExpR.Next())
95 aB.Add(aCopyRes,aExpR.Current());
96 }
97 else
98 aB.Add(aCopyRes,aFace);
99 }
100 if(isModified)
ab860031 101 {
da72a17c 102 if (aCopyRes.ShapeType() == TopAbs_WIRE || aCopyRes.ShapeType() == TopAbs_SHELL)
103 aCopyRes.Closed (BRep_Tool::IsClosed (aCopyRes));
7fd59977 104 Context()->Replace(aResult,aCopyRes);
ab860031 105 }
7fd59977 106 myStatus |= aStatus;
107 myResult = Context()->Apply ( aResult );
108 return Status ( ShapeExtend_DONE );
109}
110