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