b311480e |
1 | // Created on: 1999-04-26 |
2 | // Created by: Andrey BETENEV |
3 | // Copyright (c) 1999-1999 Matra Datavision |
973c2be1 |
4 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
5 | // |
973c2be1 |
6 | // This file is part of Open CASCADE Technology software library. |
b311480e |
7 | // |
d5f74e42 |
8 | // This library is free software; you can redistribute it and/or modify it under |
9 | // the terms of the GNU Lesser General Public License version 2.1 as published |
973c2be1 |
10 | // by the Free Software Foundation, with special exception defined in the file |
11 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
12 | // distribution for complete text of the license and disclaimer of any warranty. |
b311480e |
13 | // |
973c2be1 |
14 | // Alternatively, this file may be used under the terms of Open CASCADE |
15 | // commercial license or contractual agreement. |
b311480e |
16 | |
7fd59977 |
17 | // gka 01.06.99 S4205: changing order of splitting surface/curves for converting to bezier |
18 | |
19 | #include <ShapeUpgrade_FaceDivide.ixx> |
20 | #include <Precision.hxx> |
21 | #include <ShapeExtend.hxx> |
22 | #include <ShapeBuild_Edge.hxx> |
23 | #include <BRep_Builder.hxx> |
24 | #include <BRep_Tool.hxx> |
25 | #include <TopoDS.hxx> |
26 | #include <TopoDS_Edge.hxx> |
27 | #include <TopoDS_Vertex.hxx> |
28 | #include <TopoDS_Iterator.hxx> |
29 | #include <ShapeFix_ComposeShell.hxx> |
30 | #include <BRepTools.hxx> |
31 | #include <ShapeExtend_CompositeSurface.hxx> |
32 | #include <TopExp_Explorer.hxx> |
33 | #include <Bnd_Box2d.hxx> |
34 | #include <ShapeAnalysis.hxx> |
35 | #include <ShapeAnalysis_Edge.hxx> |
36 | #include <ShapeBuild_ReShape.hxx> |
37 | |
38 | //======================================================================= |
39 | //function : ShapeUpgrade_FaceDivide |
40 | //purpose : |
41 | //======================================================================= |
42 | |
43 | ShapeUpgrade_FaceDivide::ShapeUpgrade_FaceDivide(): |
44 | ShapeUpgrade_Tool(), myStatus(0) |
45 | { |
46 | mySegmentMode = Standard_True; |
47 | mySplitSurfaceTool = new ShapeUpgrade_SplitSurface; |
48 | myWireDivideTool = new ShapeUpgrade_WireDivide; |
49 | } |
50 | |
51 | //======================================================================= |
52 | //function : ShapeUpgrade_FaceDivide |
53 | //purpose : |
54 | //======================================================================= |
55 | |
56 | ShapeUpgrade_FaceDivide::ShapeUpgrade_FaceDivide (const TopoDS_Face &F): |
57 | ShapeUpgrade_Tool(), myStatus(0) |
58 | { |
59 | mySegmentMode = Standard_True; |
60 | mySplitSurfaceTool = new ShapeUpgrade_SplitSurface; |
61 | myWireDivideTool = new ShapeUpgrade_WireDivide; |
62 | Init ( F ); |
63 | } |
64 | |
65 | //======================================================================= |
66 | //function : Init |
67 | //purpose : |
68 | //======================================================================= |
69 | |
70 | void ShapeUpgrade_FaceDivide::Init (const TopoDS_Face &F) |
71 | { |
72 | myResult = myFace = F; |
73 | } |
74 | |
75 | |
76 | //======================================================================= |
77 | //function : SetSurfaceSegmentMode |
78 | //purpose : |
79 | //======================================================================= |
80 | |
81 | void ShapeUpgrade_FaceDivide::SetSurfaceSegmentMode(const Standard_Boolean Segment) |
82 | { |
83 | mySegmentMode = Segment; |
84 | } |
85 | |
86 | |
87 | //======================================================================= |
88 | //function : Perform |
89 | //purpose : |
90 | //======================================================================= |
91 | |
92 | Standard_Boolean ShapeUpgrade_FaceDivide::Perform () |
93 | { |
94 | myStatus = ShapeExtend::EncodeStatus ( ShapeExtend_OK ); |
95 | if ( myFace.IsNull() ) return Standard_False; |
96 | myResult = myFace; |
97 | SplitSurface(); |
98 | SplitCurves(); |
99 | return Status ( ShapeExtend_DONE ); |
100 | } |
101 | |
102 | //======================================================================= |
103 | //function : SplitSurface |
104 | //purpose : |
105 | //======================================================================= |
106 | |
107 | Standard_Boolean ShapeUpgrade_FaceDivide::SplitSurface () |
108 | { |
109 | Handle(ShapeUpgrade_SplitSurface) SplitSurf = GetSplitSurfaceTool(); |
110 | if ( SplitSurf.IsNull() ) return Standard_False; |
111 | |
112 | // myResult should be face; else return with FAIL |
113 | if ( myResult.IsNull() || myResult.ShapeType() != TopAbs_FACE ) { |
114 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 ); |
115 | return Standard_False; |
116 | } |
117 | TopoDS_Face face = TopoDS::Face ( myResult ); |
118 | |
119 | TopLoc_Location L; |
120 | Handle(Geom_Surface) surf; |
121 | surf = BRep_Tool::Surface ( face, L ); |
122 | |
123 | Standard_Real Uf,Ul,Vf,Vl; |
124 | // BRepTools::UVBounds(myFace,Uf,Ul,Vf,Vl); |
125 | ShapeAnalysis::GetFaceUVBounds ( face, Uf, Ul, Vf, Vl ); |
126 | if(Precision::IsInfinite(Uf) || Precision::IsInfinite(Ul) || |
127 | Precision::IsInfinite(Vf) || Precision::IsInfinite(Vl)) |
128 | return Standard_False; |
129 | |
130 | SplitSurf->Init ( surf, Uf, Ul, Vf, Vl ); |
131 | SplitSurf->Perform(mySegmentMode); |
132 | |
133 | // If surface was neither splitted nor modified, do nothing |
134 | if ( ! SplitSurf->Status ( ShapeExtend_DONE ) ) return Standard_False; |
135 | |
136 | // if surface was modified, force copying all vertices (and edges as consequence) |
137 | // to protect original shape from increasing tolerance after SameParameter |
138 | if ( SplitSurf->Status ( ShapeExtend_DONE3 ) ) |
139 | for (TopExp_Explorer exp(face,TopAbs_VERTEX); exp.More(); exp.Next() ) { |
140 | if ( Context()->IsRecorded ( exp.Current() ) ) continue; |
141 | //smh#8 |
142 | TopoDS_Shape emptyCopied = exp.Current().EmptyCopied(); |
143 | TopoDS_Vertex V = TopoDS::Vertex ( emptyCopied ); |
144 | Context()->Replace ( exp.Current(), V ); |
145 | } |
146 | |
147 | Handle(ShapeExtend_CompositeSurface) Grid = SplitSurf->ResSurfaces(); |
148 | |
149 | ShapeFix_ComposeShell CompShell; |
150 | CompShell.Init( Grid, L, face, Precision() ); |
151 | CompShell.SetContext(Context()); |
152 | CompShell.SetMaxTolerance(MaxTolerance()); |
153 | Handle(ShapeUpgrade_WireDivide) SplitWire = GetWireDivideTool(); |
154 | if ( ! SplitWire.IsNull() ) |
155 | CompShell.SetTransferParamTool(GetWireDivideTool()->GetTransferParamTool()); |
156 | CompShell.Perform(); |
157 | if ( CompShell.Status ( ShapeExtend_FAIL ) || |
158 | ! CompShell.Status ( ShapeExtend_DONE ) ) |
159 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL2 ); |
160 | |
161 | myResult = CompShell.Result(); |
162 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 ); |
163 | |
164 | return Standard_True; |
165 | } |
166 | |
167 | //======================================================================= |
168 | //function : SplitCurves |
169 | //purpose : |
170 | //======================================================================= |
171 | |
172 | Standard_Boolean ShapeUpgrade_FaceDivide::SplitCurves () |
173 | { |
174 | Handle(ShapeUpgrade_WireDivide) SplitWire = GetWireDivideTool(); |
175 | if ( SplitWire.IsNull() ) return Standard_False; |
176 | |
177 | SplitWire->SetMaxTolerance(MaxTolerance()); |
178 | for ( TopExp_Explorer explf(myResult,TopAbs_FACE); explf.More(); explf.Next()) { |
179 | TopoDS_Shape S = Context()->Apply ( explf.Current(), TopAbs_SHAPE); |
180 | |
181 | // S should be face; else return with FAIL |
182 | if ( S.IsNull() || S.ShapeType() != TopAbs_FACE ) { |
183 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL3 ); |
184 | return Standard_False; |
185 | } |
186 | TopoDS_Face F = TopoDS::Face ( S ); |
187 | |
188 | SplitWire->SetFace ( F ); |
189 | for ( TopoDS_Iterator wi(F,Standard_False); wi.More(); wi.Next() ) { |
190 | //TopoDS_Wire wire = TopoDS::Wire ( wi.Value() ); |
191 | // modifications already defined in context are to be applied inside SplitWire |
192 | if(wi.Value().ShapeType() !=TopAbs_WIRE) |
193 | continue; |
194 | TopoDS_Wire wire = TopoDS::Wire(wi.Value()); |
195 | SplitWire->Load ( wire ); |
196 | SplitWire->SetContext(Context()); |
197 | SplitWire->Perform (); |
198 | if ( SplitWire->Status ( ShapeExtend_FAIL ) ) |
199 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_FAIL1 ); |
200 | if ( SplitWire->Status ( ShapeExtend_DONE ) ) { |
201 | myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 ); |
202 | Context()->Replace ( wire, SplitWire->Wire() ); |
203 | } |
204 | } |
205 | } |
206 | myResult = Context()->Apply ( myResult ); |
207 | return Status ( ShapeExtend_DONE ); |
208 | } |
209 | |
210 | //======================================================================= |
211 | //function : Shell |
212 | //purpose : |
213 | //======================================================================= |
214 | |
215 | TopoDS_Shape ShapeUpgrade_FaceDivide::Result () const |
216 | { |
217 | return myResult; |
218 | } |
219 | |
220 | //======================================================================= |
221 | //function : Status |
222 | //purpose : |
223 | //======================================================================= |
224 | |
225 | Standard_Boolean ShapeUpgrade_FaceDivide::Status (const ShapeExtend_Status status) const |
226 | { |
227 | return ShapeExtend::DecodeStatus ( myStatus, status ); |
228 | } |
229 | |
230 | //======================================================================= |
231 | //function : SetSplitSurfaceTool |
232 | //purpose : |
233 | //======================================================================= |
234 | |
235 | void ShapeUpgrade_FaceDivide::SetSplitSurfaceTool(const Handle(ShapeUpgrade_SplitSurface)& splitSurfaceTool) |
236 | { |
237 | mySplitSurfaceTool = splitSurfaceTool; |
238 | } |
239 | |
240 | //======================================================================= |
241 | //function : SetWireDivideTool |
242 | //purpose : |
243 | //======================================================================= |
244 | |
245 | void ShapeUpgrade_FaceDivide::SetWireDivideTool(const Handle(ShapeUpgrade_WireDivide)& wireDivideTool) |
246 | { |
247 | myWireDivideTool = wireDivideTool; |
248 | } |
249 | |
250 | //======================================================================= |
251 | //function : GetSplitSurfaceTool |
252 | //purpose : |
253 | //======================================================================= |
254 | |
255 | Handle(ShapeUpgrade_SplitSurface) ShapeUpgrade_FaceDivide::GetSplitSurfaceTool () const |
256 | { |
257 | return mySplitSurfaceTool; |
258 | } |
259 | |
260 | //======================================================================= |
261 | //function : GetWireDivideTool |
262 | //purpose : |
263 | //======================================================================= |
264 | |
265 | Handle(ShapeUpgrade_WireDivide) ShapeUpgrade_FaceDivide::GetWireDivideTool () const |
266 | { |
267 | return myWireDivideTool; |
268 | } |