0025418: Debug output to be limited to OCC development environment
[occt.git] / src / ShapeFix / ShapeFix_Solid.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 <ShapeFix_Solid.ixx>
b311480e 15
7fd59977 16#include <Standard_ErrorHandler.hxx>
17#include <Standard_Failure.hxx>
b311480e 18
7fd59977 19#include <BRep_Builder.hxx>
20#include <BRepClass3d_SolidClassifier.hxx>
21#include <Precision.hxx>
22#include <TopoDS_Shape.hxx>
23#include <ShapeBuild_ReShape.hxx>
24#include <TopoDS_Iterator.hxx>
25#include <TopoDS.hxx>
26#include <ShapeExtend.hxx>
27#include <ShapeAnalysis_Edge.hxx>
28#include <ShapeAnalysis_Curve.hxx>
29#include <TopoDS_Wire.hxx>
30#include <ShapeExtend_WireData.hxx>
31#include <TopTools_MapIteratorOfMapOfShape.hxx>
32#include <TopoDS_Iterator.hxx>
33#include <TopTools_MapOfShape.hxx>
34#include <TopTools_DataMapOfShapeListOfShape.hxx>
35#include <TopTools_SequenceOfShape.hxx>
36#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
37#include <TopExp.hxx>
38#include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
39#include <gp_Pnt.hxx>
40#include <Bnd_Box2d.hxx>
41#include <ShapeAnalysis.hxx>
42#include <TopoDS_Edge.hxx>
43#include <BRep_Tool.hxx>
44#include <Geom_Surface.hxx>
45#include <TopTools_ListOfShape.hxx>
46#include <Precision.hxx>
47#include <TopAbs.hxx>
48#include <TopTools_ListIteratorOfListOfShape.hxx>
49#include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
50#include <TopTools_ListIteratorOfListOfShape.hxx>
51#include <TopoDS_Solid.hxx>
52#include <BRep_Builder.hxx>
53#include <TopoDS_CompSolid.hxx>
54#include <TopTools_DataMapIteratorOfDataMapOfShapeShape.hxx>
55#include <TopAbs.hxx>
56#include <BRep_Tool.hxx>
57#include <TopTools_IndexedMapOfShape.hxx>
58#include <TopTools_IndexedDataMapOfShapeShape.hxx>
59#include <Message_Msg.hxx>
b485ee79 60#include <Message_ProgressSentry.hxx>
7fd59977 61#include <TopoDS_Vertex.hxx>
62#include <TopTools_IndexedMapOfShape.hxx>
63
64#include <TopTools_DataMapOfShapeInteger.hxx>
65#include <Geom_Curve.hxx>
66#include <ShapeAnalysis_FreeBounds.hxx>
b311480e 67
7fd59977 68//======================================================
69//function : ShapeFix_Solid
70//purpose :
71//=======================================================================
72
73ShapeFix_Solid::ShapeFix_Solid()
74{
75 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
76 myFixShellMode = -1;
77 myFixShell = new ShapeFix_Shell;
78 myCreateOpenSolidMode = Standard_False;
79}
80
81//=======================================================================
82//function : ShapeFix_Solid
83//purpose :
84//=======================================================================
85
86ShapeFix_Solid::ShapeFix_Solid(const TopoDS_Solid& solid)
87{
88 myStatus = ShapeExtend::EncodeStatus (ShapeExtend_OK);
89 myFixShellMode = -1;
90 myFixShell = new ShapeFix_Shell;
91 myCreateOpenSolidMode = Standard_False;
92 Init(solid);
93}
94
95//=======================================================================
96//function : Init
97//purpose :
98//=======================================================================
99
100 void ShapeFix_Solid::Init(const TopoDS_Solid& solid)
101{
102 mySolid = solid;
103 //mySolid = TopoDS::Solid(shape.EmptyCopied());
104 //BRep_Builder B;
105 // for( TopoDS_Iterator iter(solid); iter.More(); iter.Next())
106 // B.Add(mySolid,TopoDS::Shell(iter.Value()));
107 myShape = solid;
108}
0797d9d3 109#ifdef OCCT_DEBUG_GET_MIDDLE_POINT
7fd59977 110//=======================================================================
4e18e72a 111//function : GetMiddlePoint
7fd59977 112//purpose :
113//=======================================================================
114static void GetMiddlePoint(const TopoDS_Shape& aShape, gp_Pnt& pmid)
115{
116 TopExp_Explorer aExp(aShape,TopAbs_EDGE);
117 gp_XYZ center(0.0,0.0,0.0);
118 Standard_Integer numpoints =0;
119 for( ; aExp.More(); aExp.Next()) {
120 TopoDS_Edge e1 = TopoDS::Edge(aExp.Current());
121 Standard_Real f,l;
122 Handle(Geom_Curve) c3d = BRep_Tool::Curve(e1,f,l);
123 if(!c3d.IsNull()) {
124 for(Standard_Integer i =1 ; i <=5; i++) {
125 Standard_Real param = f+(l-f)/4*(i-1);
126 gp_Pnt pt;
127 numpoints++;
128 c3d->D0(param,pt);
129 center+=pt.XYZ();
130
131 }
132 }
133 }
134 center /= numpoints;
135 pmid.SetXYZ(center);
136}
4e18e72a 137#endif
138//=======================================================================
139//function : CollectSolids
140//purpose :
141//=======================================================================
7fd59977 142static void CollectSolids(const TopTools_SequenceOfShape& aSeqShells ,
143 TopTools_DataMapOfShapeListOfShape& aMapShellHoles,
144 TopTools_DataMapOfShapeInteger& theMapStatus)
145{
146 TopTools_MapOfShape aMapHoles;
147 for ( Standard_Integer i1 = 1; i1 <= aSeqShells.Length(); i1++ ) {
148 TopoDS_Shell aShell1 = TopoDS::Shell(aSeqShells.Value(i1));
149 TopTools_ListOfShape lshells;
150 aMapShellHoles.Bind(aShell1,lshells);
151 }
152 //Finds roots shells and hole shells.
153 for ( Standard_Integer i = 1; i <= aSeqShells.Length(); i++ ) {
154 TopoDS_Shell aShell1 = TopoDS::Shell(aSeqShells.Value(i));
155 TopExp_Explorer aExpEdges(aShell1,TopAbs_EDGE);
156 if(!BRep_Tool::IsClosed(aShell1) || !aExpEdges.More()) continue;
157 TopoDS_Solid solid;
158 BRep_Builder B;
159 B.MakeSolid (solid);
160 B.Add (solid,aShell1);
161 try {
162 OCC_CATCH_SIGNALS
163 TopAbs_State infinstatus = TopAbs_UNKNOWN;
164 BRepClass3d_SolidClassifier bsc3d (solid);
165 Standard_Integer st = 0;
166 if(!theMapStatus.IsBound(aShell1)) {
167
168 bsc3d.PerformInfinitePoint(Precision::Confusion());
169 infinstatus = bsc3d.State();
170
171 if(infinstatus != TopAbs_UNKNOWN && infinstatus !=TopAbs_ON)
172 st = (infinstatus == TopAbs_IN ? 1 :2);
173 theMapStatus.Bind(aShell1,st);
174
175
176 }
177 else {
178 st = theMapStatus.Find(aShell1);
179 if(st)
180 infinstatus = (theMapStatus.Find(aShell1) == 1 ? TopAbs_IN : TopAbs_OUT);
181 }
182 if(!st) continue;
183 for ( Standard_Integer j = 1; j <= aSeqShells.Length(); j++ ) {
184 if(i==j) continue;
185 TopoDS_Shape aShell2 = aSeqShells.Value(j);
186 if(!BRep_Tool::IsClosed(aShell2)) continue;
187 if(aMapHoles.Contains(aShell2)) continue;
188 if(aMapShellHoles.IsBound(aShell2)) {
189 Standard_Boolean isAnalysis = Standard_False;
190 const TopTools_ListOfShape& ls = aMapShellHoles.Find(aShell2);
191 for(TopTools_ListIteratorOfListOfShape li(ls); li.More() && !isAnalysis; li.Next())
192 isAnalysis = li.Value().IsSame(aShell1);
193 if(isAnalysis) continue;
194 }
195 TopAbs_State pointstatus = TopAbs_UNKNOWN;
196 Standard_Integer numon =0;
197 TopTools_IndexedMapOfShape amapVert;
198 for(TopExp_Explorer aExpVert(aShell2,TopAbs_VERTEX); aExpVert.More() && amapVert.Extent() < 10; aExpVert.Next())
199 amapVert.Add(aExpVert.Current());
200 for(Standard_Integer k = 1; k <= amapVert.Extent() &&
201 (pointstatus ==TopAbs_UNKNOWN || (pointstatus ==TopAbs_ON && numon < 3)); k++) {
202 TopoDS_Vertex aV = TopoDS::Vertex(amapVert.FindKey(k));
203 gp_Pnt aPf = BRep_Tool::Pnt(aV);
204 bsc3d.Perform(aPf,Precision::Confusion());
205 pointstatus =bsc3d.State();
206 if(pointstatus ==TopAbs_ON) numon++;
207 }
208
209 if(numon == 3 && pointstatus ==TopAbs_ON) {
0797d9d3 210#ifdef OCCT_DEBUG_GET_MIDDLE_POINT
4e18e72a 211 gp_Pnt pmid;
212 GetMiddlePoint(aShell2,pmid);
213 bsc3d.Perform(pmid,Precision::Confusion());
214#endif
7fd59977 215 pointstatus = /*(bsc3d.State() == TopAbs_IN ? TopAbs_IN :*/TopAbs_OUT;
216 }
217 if(pointstatus != infinstatus) {
218 aMapShellHoles.ChangeFind(aShell1).Append(aShell2);
219 if( aMapHoles.Contains(aShell2))
220 aMapHoles.Remove(aShell2);
221 else aMapHoles.Add(aShell2);
222 }
223 }
224 }
225 catch(Standard_Failure) {
0797d9d3 226#ifdef OCCT_DEBUG
7fd59977 227 cout << "Warning: ShapeFix_Solid::SolidFromShell: Exception: ";
228 Standard_Failure::Caught()->Print(cout); cout << endl;
229#endif
230 continue;
231 }
232 }
233 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItShellHoles( aMapShellHoles);
234 for(; aItShellHoles.More();aItShellHoles.Next()) {
235 if(aMapHoles.Contains(aItShellHoles.Key())) continue;
236 const TopTools_ListOfShape& lHoles =aItShellHoles.Value();
237 if(lHoles.IsEmpty()) continue;
238 for(TopTools_ListIteratorOfListOfShape lItHoles(lHoles);lItHoles.More(); lItHoles.Next()) {
239 if(aMapHoles.Contains(lItHoles.Value())) {
240 const TopTools_ListOfShape& lUnHoles = aMapShellHoles.Find(lItHoles.Value());
241 for(TopTools_ListIteratorOfListOfShape lItUnHoles(lUnHoles);lItUnHoles.More(); lItUnHoles.Next())
242 aMapHoles.Remove(lItUnHoles.Value());
243 }
244 }
245 }
246 for(TopTools_MapIteratorOfMapOfShape aIterHoles(aMapHoles);aIterHoles.More(); aIterHoles.Next())
247 aMapShellHoles.UnBind(aIterHoles.Key());
248
249}
250//=======================================================================
251//function : CreateSolids
252//purpose :
253//=======================================================================
254
255static Standard_Boolean CreateSolids(const TopoDS_Shape aShape,TopTools_IndexedMapOfShape& aMapSolids)
256{
257 TopTools_SequenceOfShape aSeqShells;
258 Standard_Boolean isDone = Standard_False;
259
260 for(TopExp_Explorer aExpShell(aShape,TopAbs_SHELL); aExpShell.More(); aExpShell.Next()) {
261 aSeqShells.Append(aExpShell.Current());
262 }
263 TopTools_DataMapOfShapeListOfShape aMapShellHoles;
264 TopTools_DataMapOfShapeInteger aMapStatus;
265 CollectSolids(aSeqShells,aMapShellHoles,aMapStatus);
266 TopTools_IndexedDataMapOfShapeShape ShellSolid;
267 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItShellHoles( aMapShellHoles);
268 //Defines correct orientation of shells
269 for(; aItShellHoles.More();aItShellHoles.Next()) {
270 TopoDS_Shell aShell = TopoDS::Shell(aItShellHoles.Key());
271 TopExp_Explorer aExpEdges(aShell,TopAbs_EDGE);
272 if(!BRep_Tool::IsClosed(aShell) || !aExpEdges.More()) {
273 ShellSolid.Add(aShell,aShell);
274 isDone = Standard_True;
275 continue;
276 }
277 BRep_Builder B;
278 TopAbs_State infinstatus = TopAbs_UNKNOWN;
279 TopoDS_Solid aSolid;
280 B.MakeSolid (aSolid);
281 B.Add (aSolid,aShell);
282 if(aMapStatus.IsBound(aShell)) {
283 Standard_Integer st = aMapStatus.Find(aShell);
284 if(st)
285 infinstatus = (aMapStatus.Find(aShell) == 1 ? TopAbs_IN : TopAbs_OUT);
286 }
287
288 else {
289
290 try {
291 OCC_CATCH_SIGNALS
292 BRepClass3d_SolidClassifier bsc3d (aSolid);
293 bsc3d.PerformInfinitePoint(Precision::Confusion());
294 infinstatus = bsc3d.State();
295 }
296 catch(Standard_Failure) {
0797d9d3 297#ifdef OCCT_DEBUG
7fd59977 298 cout << "Warning: ShapeFix_Solid::SolidFromShell: Exception: ";
299 Standard_Failure::Caught()->Print(cout); cout << endl;
300#endif
301 ShellSolid.Add(aShell,aSolid);
302 continue;
303 }
304 }
305 if (infinstatus == TopAbs_IN) {
306 isDone = Standard_True;
307 aShell.Reverse();
308 TopoDS_Solid aTmpSolid;
309 B.MakeSolid (aTmpSolid);
310 B.Add (aTmpSolid,aShell);
311 aSolid = aTmpSolid;
312 }
313
314 const TopTools_ListOfShape& lHoles = aItShellHoles.Value();
315 for(TopTools_ListIteratorOfListOfShape lItHoles(lHoles); lItHoles.More();lItHoles.Next()) {
316 TopoDS_Shell aShellHole = TopoDS::Shell(lItHoles.Value());
317 if(aMapStatus.IsBound(aShellHole)) {
318 infinstatus = (aMapStatus.Find(aShellHole) == 1 ? TopAbs_IN : TopAbs_OUT);
319 }
320 else {
321 TopoDS_Solid solid;
322 B.MakeSolid (solid);
323 B.Add (solid,aShellHole);
324 BRepClass3d_SolidClassifier bsc3dHol (solid);
325 bsc3dHol.PerformInfinitePoint(Precision::Confusion());
326 infinstatus = bsc3dHol.State();
327 }
328 if (infinstatus == TopAbs_OUT) {
329 aShellHole.Reverse();
330 isDone = Standard_True;
331 }
332 B.Add(aSolid,aShellHole);
333 }
334 ShellSolid.Add(aShell,aSolid);
335 }
336 //Creation of compsolid from shells containing shared faces.
337 TopTools_IndexedDataMapOfShapeListOfShape aMapFaceShells;
338 TopExp::MapShapesAndAncestors(aShape,TopAbs_FACE,TopAbs_SHELL,aMapFaceShells);
339 for(Standard_Integer i =1; i <= aMapFaceShells.Extent(); i++) {
340 const TopTools_ListOfShape& lshells = aMapFaceShells.FindFromIndex(i);
341 if(lshells.Extent() <2) continue;
342 TopoDS_CompSolid aCompSolid;
343 BRep_Builder aB;
344 aB.MakeCompSolid(aCompSolid);
345 isDone = (aShape.ShapeType() != TopAbs_COMPSOLID || isDone);
346 for(TopTools_ListIteratorOfListOfShape lItSh(lshells);lItSh.More(); lItSh.Next()) {
347 if(ShellSolid.Contains(lItSh.Value())) {
348 for(TopExp_Explorer aExpSol(ShellSolid.FindFromKey(lItSh.Value()),TopAbs_SOLID);aExpSol.More(); aExpSol.Next())
349 aB.Add(aCompSolid,aExpSol.Current());
350 ShellSolid.ChangeFromKey(lItSh.Value()) = aCompSolid;
351 }
352 }
353 }
354 for(Standard_Integer kk =1 ; kk <= ShellSolid.Extent();kk++)
355 if(!aMapSolids.Contains(ShellSolid.FindFromIndex(kk)))
356 aMapSolids.Add(ShellSolid.FindFromIndex(kk));
357 isDone = (aMapSolids.Extent() >1 || isDone);
358 return isDone;
359}
360//=======================================================================
361//function : Perform
362//purpose :
363//=======================================================================
364
b485ee79 365Standard_Boolean ShapeFix_Solid::Perform(const Handle(Message_ProgressIndicator)& theProgress)
7fd59977 366{
367
368 Standard_Boolean status = Standard_False;
b485ee79 369 if ( Context().IsNull() )
7fd59977 370 SetContext ( new ShapeBuild_ReShape );
371 myFixShell->SetContext(Context());
b485ee79
KD
372
373 Standard_Integer NbShells = 0;
7fd59977 374 TopoDS_Shape S = Context()->Apply ( myShape );
b485ee79
KD
375
376 // Calculate number of underlying shells
377 Standard_Integer aNbShells = 0;
378 for ( TopExp_Explorer aExpSh(S, TopAbs_SHELL); aExpSh.More(); aExpSh.Next() )
379 aNbShells++;
380
381 // Start progress scope (no need to check if progress exists -- it is safe)
382 Message_ProgressSentry aPSentry(theProgress, "Fixing solid stage", 0, 2, 1);
383
384 if ( NeedFix(myFixShellMode) )
385 {
386 // Start progress scope (no need to check if progress exists -- it is safe)
387 Message_ProgressSentry aPSentry(theProgress, "Fixing shell", 0, aNbShells, 1);
388
389 // Fix shell by shell using ShapeFix_Shell tool
390 for ( TopExp_Explorer aExpSh(S, TopAbs_SHELL); aExpSh.More() && aPSentry.More(); aExpSh.Next(), aPSentry.Next() )
391 {
392 TopoDS_Shape sh = aExpSh.Current();
393
394 myFixShell->Init( TopoDS::Shell(sh) );
395 if ( myFixShell->Perform(theProgress) )
396 {
7fd59977 397 status = Standard_True;
398 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE1 );
399 }
400 NbShells+= myFixShell->NbShells();
401 }
b485ee79
KD
402
403 // Halt algorithm in case of user's abort
404 if ( !aPSentry.More() )
405 return Standard_False;
7fd59977 406 }
b485ee79
KD
407 else
408 {
409 NbShells = aNbShells;
7fd59977 410 }
b485ee79
KD
411
412 // Switch to the second stage
413 aPSentry.Next();
7fd59977 414
415 if(NbShells ==1) {
416 TopoDS_Shape tmpShape = Context()->Apply(myShape);
417 TopExp_Explorer aExp(tmpShape,TopAbs_SHELL);
418 Standard_Boolean isClosed = Standard_False;
419 if(aExp.More()) {
420 TopoDS_Shell aShtmp = TopoDS::Shell(aExp.Current());
421 ShapeAnalysis_FreeBounds sfb(aShtmp);
422 TopoDS_Compound aC1 = sfb.GetClosedWires();
423 TopoDS_Compound aC2 = sfb.GetOpenWires();
424 Standard_Integer numedge =0;
425 TopExp_Explorer aExp1(aC1,TopAbs_EDGE);
426 for( ; aExp1.More(); aExp1.Next())
427 numedge++;
428 for(aExp1.Init(aC2,TopAbs_EDGE) ; aExp1.More(); aExp1.Next())
429 numedge++;
430 isClosed = (!numedge);
431 aShtmp.Closed(isClosed);
432 }
433
434 if(isClosed || myCreateOpenSolidMode) {
435 if(BRep_Tool::IsClosed(tmpShape)) {
436 TopoDS_Iterator itersh(tmpShape);
437 TopoDS_Shell aShell;
438 if(itersh.More() && itersh.Value().ShapeType() == TopAbs_SHELL)
439 aShell = TopoDS::Shell(itersh.Value());
440 if(!aShell.IsNull()) {
441 TopoDS_Solid aSol = SolidFromShell(aShell);
442 if(ShapeExtend::DecodeStatus(myStatus,ShapeExtend_DONE2)) {
443 SendWarning (Message_Msg ("FixAdvSolid.FixOrientation.MSG20"));// Orientaion of shell was corrected.
444 Context()->Replace(tmpShape,aSol);
445 tmpShape = aSol;
446 }
447 }
448 }
449 mySolid = TopoDS::Solid(tmpShape);
450 }
451 else {
452 TopoDS_Iterator aIt(tmpShape,Standard_False);
453 Context()->Replace(tmpShape,aIt.Value());
454 SendFail (Message_Msg ("FixAdvSolid.FixShell.MSG10")); // Solid can not be created from open shell.
455 }
456 }
457 else {
458 TopoDS_Shape aResShape = Context()->Apply(myShape);
459 TopTools_SequenceOfShape aSeqShells;
460 TopTools_IndexedMapOfShape aMapSolids;
461 if(CreateSolids(aResShape,aMapSolids)) {
462 SendWarning (Message_Msg ("FixAdvSolid.FixOrientation.MSG20"));// Orientaion of shell was corrected..
463 if(aMapSolids.Extent() ==1) {
464 TopoDS_Shape aResSol = aMapSolids.FindKey(1);
465 if(aResShape.ShapeType() == TopAbs_SHELL && myCreateOpenSolidMode) {
466 TopoDS_Solid solid;
467 BRep_Builder B;
468 B.MakeSolid (solid);
469 B.Add (solid,aResSol);
470 mySolid = solid;
471 }
472 else {
473 mySolid =aResSol;
474 if(aResSol.ShapeType() == TopAbs_SHELL)
475 SendFail (Message_Msg ("FixAdvSolid.FixShell.MSG10")); // Solid can not be created from open shell.
476 }
477 Context()->Replace(aResShape,mySolid);
478 }
479 else if(aMapSolids.Extent() >1) {
480 SendWarning (Message_Msg ("FixAdvSolid.FixOrientation.MSG30"));// Bad connected solid a few solids were created.
481 BRep_Builder aB;
482 TopoDS_Compound aComp;
483 aB.MakeCompound(aComp);
b485ee79
KD
484 Message_ProgressSentry aPSentry(theProgress, "Creating solid",
485 0, aMapSolids.Extent(), 1);
486 for(Standard_Integer i =1; (i <= aMapSolids.Extent()) && (aPSentry.More());
487 i++, aPSentry.Next())
488 {
7fd59977 489 TopoDS_Shape aResSh =aMapSolids.FindKey(i);
490 if(aResShape.ShapeType() == TopAbs_SHELL && myCreateOpenSolidMode) {
491 aResSh.Closed(Standard_False);
492 TopoDS_Solid solid;
493 BRep_Builder B;
494 B.MakeSolid (solid);
495 B.Add (solid,aResSh);
496 aResSh = solid;
497 }
498 else if (aResShape.ShapeType() == TopAbs_SHELL)
499 SendFail(Message_Msg ("FixAdvSolid.FixShell.MSG10")); // Solid can not be created from open shell.
500 aB.Add(aComp,aResSh);
501
502 }
b485ee79
KD
503 if ( !aPSentry.More() )
504 return Standard_False; // aborted execution
7fd59977 505 Context()->Replace(aResShape,aComp);
506 }
507 }
508 }
509 myShape = Context()->Apply(myShape);
510 return status;
511}
512//=======================================================================
513//function : Shape
514//purpose :
515//=======================================================================
516
517TopoDS_Shape ShapeFix_Solid::Shape()
518{
519 return myShape;
520}
521//=======================================================================
522//function : SolidFromShell
523//purpose :
524//=======================================================================
525
526TopoDS_Solid ShapeFix_Solid::SolidFromShell (const TopoDS_Shell& shell)
527{
528 TopoDS_Shell sh = shell;
529 if (!sh.Free ()) sh.Free(Standard_True);
530
531 TopoDS_Solid solid;
532 BRep_Builder B;
533 B.MakeSolid (solid);
534 B.Add (solid,sh);
535// Pas encore fini : il faut une bonne orientation
536 try {
537 OCC_CATCH_SIGNALS
538 BRepClass3d_SolidClassifier bsc3d (solid);
539 Standard_Real t = Precision::Confusion(); // tolerance moyenne
540 bsc3d.PerformInfinitePoint(t);
541
542 if (bsc3d.State() == TopAbs_IN) {
543 // Ensuite, inverser C-A-D REPRENDRE LES SHELLS
544 // (l inversion du solide n est pas bien prise en compte)
545 sh = shell;
546 if (!sh.Free ()) sh.Free(Standard_True);
547 TopoDS_Solid soli2;
548 B.MakeSolid (soli2); // on recommence
549 sh.Reverse();
550 B.Add (soli2,sh);
551 solid = soli2;
552 myStatus |= ShapeExtend::EncodeStatus ( ShapeExtend_DONE2 );
553 }
554 }
555 catch(Standard_Failure) {
0797d9d3 556#ifdef OCCT_DEBUG
7fd59977 557 cout << "Warning: ShapeFix_Solid::SolidFromShell: Exception: ";
558 Standard_Failure::Caught()->Print(cout); cout << endl;
559#endif
560 return solid;
561 }
562 return solid;
563}
564
565//=======================================================================
566//function : Status
567//purpose :
568//=======================================================================
569
570 Standard_Boolean ShapeFix_Solid::Status(const ShapeExtend_Status /*status*/) const
571{
572 return myStatus;
573}
574
575//=======================================================================
576//function : Solid
577//purpose :
578//=======================================================================
579
580 TopoDS_Shape ShapeFix_Solid::Solid() const
581{
582 return mySolid;
583}
584
585//=======================================================================
586//function : SetMsgRegistrator
587//purpose :
588//=======================================================================
589
590void ShapeFix_Solid::SetMsgRegistrator(const Handle(ShapeExtend_BasicMsgRegistrator)& msgreg)
591{
592 ShapeFix_Root::SetMsgRegistrator ( msgreg );
593 myFixShell->SetMsgRegistrator ( msgreg );
594}
595
596//=======================================================================
597//function : SetPrecision
598//purpose :
599//=======================================================================
600
601void ShapeFix_Solid::SetPrecision (const Standard_Real preci)
602{
603 ShapeFix_Root::SetPrecision ( preci );
604 myFixShell->SetPrecision ( preci );
605}
606
607//=======================================================================
608//function : SetMinTolerance
609//purpose :
610//=======================================================================
611
612void ShapeFix_Solid::SetMinTolerance (const Standard_Real mintol)
613{
614 ShapeFix_Root::SetMinTolerance ( mintol );
615 myFixShell->SetMinTolerance ( mintol );
616}
617
618//=======================================================================
619//function : SetMaxTolerance
620//purpose :
621//=======================================================================
622
623void ShapeFix_Solid::SetMaxTolerance (const Standard_Real maxtol)
624{
625 ShapeFix_Root::SetMaxTolerance ( maxtol );
626 myFixShell->SetMaxTolerance ( maxtol );
627}