]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMAlgo/GEOMAlgo_Builder_3.cxx
Salome HOME
0021434: Boolean operations generate a shape with big vertex tolerance.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_Builder_3.cxx
1 // Copyright (C) 2007-2011  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 //  File    : GEOMAlgo_Builder_3.cxx
23 //  Author  : Peter KURNEV
24
25 #include <GEOMAlgo_Builder.hxx>
26
27 #include <Basics_OCCTVersion.hxx>
28
29 #include <GEOMAlgo_Tools3D.hxx>
30 #include <GEOMAlgo_BuilderSolid.hxx>
31 #include <GEOMAlgo_ShapeSet.hxx>
32 #include <GEOMAlgo_DataMapOfShapeShapeSet.hxx>
33 #include <GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet.hxx>
34
35 #include <NMTTools_PaveFiller.hxx>
36
37 #include <NMTDS_ShapesDataStructure.hxx>
38
39 #include <TopAbs_State.hxx>
40
41 #include <TopoDS.hxx>
42 #include <TopoDS_Iterator.hxx>
43 #include <TopoDS_Solid.hxx>
44 #include <TopoDS_Shape.hxx>
45 #include <TopoDS_Face.hxx>
46 #include <TopoDS_Solid.hxx>
47 #include <TopoDS_Iterator.hxx>
48 #include <TopoDS_Shell.hxx>
49 #include <TopoDS_Compound.hxx>
50
51 #include <TopExp.hxx>
52 #include <TopExp_Explorer.hxx>
53
54 #include <BRep_Builder.hxx>
55 #include <BRepTools.hxx>
56 #include <BRepClass3d_SolidClassifier.hxx>
57
58 #include <TopTools_ListOfShape.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
62 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TopTools_MapIteratorOfMapOfShape.hxx>
64 #include <TopTools_DataMapOfShapeShape.hxx>
65 #include <TopTools_DataMapOfShapeInteger.hxx>
66 #include <TopTools_DataMapIteratorOfDataMapOfShapeInteger.hxx>
67 #include <TopTools_MapOfShape.hxx>
68
69 #include <IntTools_Context.hxx>
70
71
72 static
73   void OwnInternalShapes(const TopoDS_Shape& ,
74                          TopTools_IndexedMapOfShape& );
75
76 //=======================================================================
77 //function : FillImagesSolids
78 //purpose  :
79 //=======================================================================
80   void GEOMAlgo_Builder::FillImagesSolids()
81 {
82   myErrorStatus=0;
83   //
84   FillIn3DParts();
85   BuildSplitSolids();
86   FillInternalShapes();
87 }
88 //=======================================================================
89 //function : BuildDraftSolid
90 //purpose  :
91 //=======================================================================
92 void GEOMAlgo_Builder::BuildDraftSolid (const TopoDS_Shape& theSolid,
93                                         TopoDS_Shape& theDraftSolid,
94                                         TopTools_ListOfShape& theLIF)
95 {
96   myErrorStatus=0;
97   //
98   NMTTools_PaveFiller* pPF=myPaveFiller;
99 #if OCC_VERSION_LARGE > 0x06050200
100   const Handle(IntTools_Context)& aCtx=pPF->Context();
101 #else
102   IntTools_Context& aCtx=pPF->ChangeContext();
103 #endif
104   //
105   Standard_Boolean bToReverse;
106   Standard_Integer  iFlag;
107   TopAbs_Orientation aOrF, aOrSh, aOrSd;
108   TopoDS_Iterator aIt1, aIt2;
109   TopTools_ListIteratorOfListOfShape aItS;
110   BRep_Builder aBB;
111   TopoDS_Shell aShD;
112   TopoDS_Shape aFSDx, aFx;
113   //
114   aOrSd=theSolid.Orientation();
115   theDraftSolid.Orientation(aOrSd);
116   //
117   aIt1.Initialize(theSolid);
118   for (; aIt1.More(); aIt1.Next()) {
119     const TopoDS_Shape& aSh=aIt1.Value();
120     if(aSh.ShapeType()!=TopAbs_SHELL) {
121       continue; // mb internal edges,vertices
122     }
123     //
124     aOrSh=aSh.Orientation();
125     aBB.MakeShell(aShD);
126     aShD.Orientation(aOrSh);
127     iFlag=0;
128     //
129     aIt2.Initialize(aSh);
130     for (; aIt2.More(); aIt2.Next()) {
131       const TopoDS_Shape& aF=aIt2.Value();
132       aOrF=aF.Orientation();
133       //
134       if (myImages.HasImage(aF)) {
135         const TopTools_ListOfShape& aLSp=myImages.Image(aF);
136         aItS.Initialize(aLSp);
137         for (; aItS.More(); aItS.Next()) {
138           aFx=aItS.Value();
139           //
140           if (mySameDomainShapes.Contains(aFx)) {
141             aFSDx=mySameDomainShapes.FindFromKey(aFx);
142             //
143             if (aOrF==TopAbs_INTERNAL) {
144               aFSDx.Orientation(aOrF);
145               theLIF.Append(aFSDx);
146             }
147             else {
148               bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFSDx, aF, aCtx);
149               if (bToReverse) {
150                 aFSDx.Reverse();
151               }
152               //
153               iFlag=1;
154               aBB.Add(aShD, aFSDx);
155             }
156           }// if (mySameDomainShapes.Contains(aFx)) {
157           else {
158             aFx.Orientation(aOrF);
159             if (aOrF==TopAbs_INTERNAL) {
160               theLIF.Append(aFx);
161             }
162             else{
163               iFlag=1;
164               aBB.Add(aShD, aFx);
165             }
166           }
167         }
168       } //if (myImages.HasImage(aF)) {
169       //
170       else {
171         if (aOrF==TopAbs_INTERNAL) {
172           theLIF.Append(aF);
173         }
174         else{
175           iFlag=1;
176           aBB.Add(aShD, aF);
177         }
178       }
179     } //for (; aIt2.More(); aIt2.Next()) {
180     //
181     if (iFlag) {
182       aBB.Add(theDraftSolid, aShD);
183     }
184   } //for (; aIt1.More(); aIt1.Next()) {
185 }
186 //=======================================================================
187 //function : FillIn3DParts
188 //purpose  :
189 //=======================================================================
190   void GEOMAlgo_Builder::FillIn3DParts()
191 {
192   myErrorStatus=0;
193   //
194   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
195   NMTTools_PaveFiller* pPF=myPaveFiller;
196 #if OCC_VERSION_LARGE > 0x06050200
197   const Handle(IntTools_Context)& aCtx=pPF->Context();
198 #else
199   IntTools_Context& aCtx=pPF->ChangeContext();
200 #endif
201   //
202   Standard_Boolean bIsIN, bHasImage;
203   Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF;
204   TopAbs_ShapeEnum aType;
205   TopAbs_State aState;
206   TopTools_IndexedMapOfShape aMSolids, aMS, aMFaces, aMFIN;
207   TopTools_MapOfShape aMFDone;
208   TopTools_IndexedDataMapOfShapeListOfShape aMEF;
209   TopTools_ListIteratorOfListOfShape aItS;
210   TopoDS_Iterator aIt, aItF;
211   BRep_Builder aBB;
212   TopoDS_Solid aSolidSp;
213   TopoDS_Face aFP;
214   //
215   myDraftSolids.Clear();
216   //
217   aNbS=aDS.NumberOfShapesOfTheObject();
218   for (i=1; i<=aNbS; ++i) {
219     const TopoDS_Shape& aS=aDS.Shape(i);
220     //
221     aType=aS.ShapeType();
222     if (aType==TopAbs_SOLID) {
223       // all solids from DS
224       aMSolids.Add(aS);
225     }
226     else if (aType==TopAbs_FACE) {
227       // all faces (originals from DS or theirs images)
228       if (myImages.HasImage(aS)) {
229         const TopTools_ListOfShape& aLS=myImages.Image(aS);
230         aItS.Initialize(aLS);
231         for (; aItS.More(); aItS.Next()) {
232           const TopoDS_Shape& aFx=aItS.Value();
233           //
234           if (mySameDomainShapes.Contains(aFx)) {
235             const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aFx);
236             aMFaces.Add(aFSDx);
237           }
238           else {
239             aMFaces.Add(aFx);
240           }
241         }
242       }
243       else {
244         if (mySameDomainShapes.Contains(aS)) {
245           const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aS);
246           aMFaces.Add(aFSDx);
247         }
248         else {
249           aMFaces.Add(aS);
250         }
251       }
252     }
253   }
254   //
255   aNbFaces=aMFaces.Extent();
256   aNbSolids=aMSolids.Extent();
257   //
258   for (i=1; i<=aNbSolids; ++i) {
259     const TopoDS_Solid& aSolid=TopoDS::Solid(aMSolids(i));
260     aMFDone.Clear();
261     aMFIN.Clear();
262     aMEF.Clear();
263     //
264     aBB.MakeSolid(aSolidSp);
265     //
266     TopTools_ListOfShape aLIF;
267     //
268     BuildDraftSolid(aSolid, aSolidSp, aLIF);
269     aNbLIF=aLIF.Extent();
270     //
271     // 1 all faces/edges from aSolid [ aMS ]
272     bHasImage=Standard_False;
273     aMS.Clear();
274     aIt.Initialize(aSolid);
275     for (; aIt.More(); aIt.Next()) {
276       const TopoDS_Shape& aShell=aIt.Value();
277       //
278       if (myImages.HasImage(aShell)) {
279         bHasImage=Standard_True;
280         //
281         const TopTools_ListOfShape& aLS=myImages.Image(aShell);
282         aItS.Initialize(aLS);
283         for (; aItS.More(); aItS.Next()) {
284           const TopoDS_Shape& aSx=aItS.Value();
285           aMS.Add(aSx);
286           TopExp::MapShapes(aSx, TopAbs_FACE, aMS);
287           TopExp::MapShapes(aSx, TopAbs_EDGE, aMS);
288           TopExp::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF);
289         }
290       }
291       else {
292         //aMS.Add(aShell);
293         TopExp::MapShapes(aShell, TopAbs_FACE, aMS);
294         //modified by NIZNHY-PKV Fri Dec 03 11:18:45 2010f
295         TopExp::MapShapes(aShell, TopAbs_EDGE, aMS);
296         //modified by NIZNHY-PKV Fri Dec 03 11:18:51 2010t
297         TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
298       }
299     }
300     //
301     // 2 all faces that are not from aSolid [ aLFP1 ]
302     Standard_Integer aNbEFP;
303     TopTools_IndexedDataMapOfShapeListOfShape aMEFP;
304     TopTools_ListIteratorOfListOfShape aItFP, aItEx;
305     TopTools_MapOfShape aMFence;
306     TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP,
307     //
308     // for all non-solid faces build EF map [ aMEFP ]
309     for (j=1; j<=aNbFaces; ++j) {
310       const TopoDS_Shape& aFace=aMFaces(j);
311       if (!aMS.Contains(aFace)) {
312         TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
313       }
314     }
315     //
316     // among all faces from aMEFP select these that have same edges
317     // with the solid (i.e aMEF). These faces will be treated first
318     // to prevent the usage of 3D classifier.
319     // The full list of faces to process is aLFP1.
320     aNbEFP=aMEFP.Extent();
321     for (j=1; j<=aNbEFP; ++j) {
322       const TopoDS_Shape& aE=aMEFP.FindKey(j);
323       //
324       if (aMEF.Contains(aE)) { // !!
325         const TopTools_ListOfShape& aLF=aMEFP(j);
326         aItFP.Initialize(aLF);
327         for (; aItFP.More(); aItFP.Next()) {
328           const TopoDS_Shape& aF=aItFP.Value();
329           if (aMFence.Add(aF)) {
330             aLFP1.Append(aF);
331           }
332         }
333       }
334       else {
335         aLEx.Append(aE);
336       }
337     }
338     //
339     aItEx.Initialize(aLEx);
340     for (; aItEx.More(); aItEx.Next()) {
341       const TopoDS_Shape& aE=aItEx.Value();
342       const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE);
343       aItFP.Initialize(aLF);
344       for (; aItFP.More(); aItFP.Next()) {
345         const TopoDS_Shape& aF=aItFP.Value();
346         if (aMFence.Add(aF)) {
347           aLFP2.Append(aF);
348         }
349       }
350     }
351     aLFP1.Append(aLFP2);
352     //==========
353     //
354     // 3 Process faces aLFP1
355     aNbFP=aLFP1.Extent();
356     aItFP.Initialize(aLFP1);
357     for (; aItFP.More(); aItFP.Next()) {
358       const TopoDS_Shape& aSP=aItFP.Value();
359       if (!aMFDone.Add(aSP)) {
360         continue;
361       }
362
363       //
364       // first face to process
365       aFP=TopoDS::Face(aSP);
366       bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx);
367       aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
368       //
369       // collect faces to process [ aFP is the first ]
370       aLFP.Clear();
371       aLFP.Append(aFP);
372       aItS.Initialize(aLFP1);
373       for (; aItS.More(); aItS.Next()) {
374         const TopoDS_Shape& aSk=aItS.Value();
375         if (!aMFDone.Contains(aSk)) {
376           aLFP.Append(aSk);
377         }
378       }
379       //
380       // Connexity Block that spreads from aFP the Bound
381       // or till the end of the block itself
382       aLCBF.Clear();
383       GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF);
384       //
385       // fill states for the Connexity Block
386       aItS.Initialize(aLCBF);
387       for (; aItS.More(); aItS.Next()) {
388         const TopoDS_Shape& aSx=aItS.Value();
389         aMFDone.Add(aSx);
390         if (aState==TopAbs_IN) {
391           aMFIN.Add(aSx);
392         }
393       }
394       //
395       aNbFPx=aMFDone.Extent();
396       if (aNbFPx==aNbFP) {
397         break;
398       }
399     }//for (; aItFP.More(); aItFP.Next())
400     //
401     // faces Inside aSolid
402     aLFIN.Clear();
403     aNbFIN=aMFIN.Extent();
404     if (aNbFIN || aNbLIF) {
405       for (j=1; j<=aNbFIN; ++j) {
406         const TopoDS_Shape& aFIN=aMFIN(j);
407         aLFIN.Append(aFIN);
408       }
409       //
410       aItS.Initialize(aLIF);
411       for (; aItS.More(); aItS.Next()) {
412         const TopoDS_Shape& aFIN=aItS.Value();
413         aLFIN.Append(aFIN);
414       }
415       //
416       myInParts.Add(aSolid, aLFIN);
417     }
418     if (aNbFIN || bHasImage) {
419       myDraftSolids.Add(aSolid, aSolidSp);
420     }
421   }//for (i=1; i<=aNbSolids; ++i) { // next solid
422 }
423 //=======================================================================
424 //function : BuildSplitSolids
425 //purpose  :
426 //=======================================================================
427   void GEOMAlgo_Builder::BuildSplitSolids()
428 {
429   myErrorStatus=0;
430   //
431   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
432   NMTTools_PaveFiller* pPF=myPaveFiller;
433 #if OCC_VERSION_LARGE > 0x06050200
434   const Handle(IntTools_Context)& aCtx=pPF->Context();
435 #else
436   IntTools_Context& aCtx=pPF->ChangeContext();
437 #endif
438   //
439   Standard_Integer i, aNbS, iErr;
440   TopExp_Explorer aExp;
441   TopTools_ListOfShape aSFS, aLSEmpty;
442   TopTools_MapOfShape aMFence;
443   TopTools_ListIteratorOfListOfShape aIt;
444   GEOMAlgo_BuilderSolid aSB;
445   GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet aItSS;
446   GEOMAlgo_DataMapOfShapeShapeSet aMSS;
447   GEOMAlgo_ShapeSet aSSi;
448   //
449   // 0. Find same domain solids for non-interferred solids
450   aNbS=aDS.NumberOfShapesOfTheObject();
451   for (i=1; i<=aNbS; ++i) {
452     const TopoDS_Shape& aS=aDS.Shape(i);
453     if (aS.ShapeType()!=TopAbs_SOLID) {
454       continue;
455     }
456     if (!aMFence.Add(aS)) {
457       continue;
458     }
459     if(myDraftSolids.Contains(aS)) {
460       continue;
461     }
462     //
463     aSSi.Clear();
464     aSSi.Add(aS, TopAbs_FACE);
465     //
466     aMSS.Bind(aS, aSSi);
467   } //for (i=1; i<=aNbS; ++i)
468   //
469   // 1. Build solids for interferred source solids
470   aSB.SetContext(aCtx);
471   aSB.ComputeInternalShapes(myComputeInternalShapes);
472   aNbS=myDraftSolids.Extent();
473   for (i=1; i<=aNbS; ++i) {
474     const TopoDS_Shape& aS =myDraftSolids.FindKey(i);
475     const TopoDS_Shape& aSD=myDraftSolids.FindFromIndex(i);
476     const TopTools_ListOfShape& aLFIN=
477       (myInParts.Contains(aS)) ? myInParts.FindFromKey(aS) : aLSEmpty;
478     //
479     // 1.1 Fill Shell Faces Set
480     aSFS.Clear();
481
482     aExp.Init(aSD, TopAbs_FACE);
483     for (; aExp.More(); aExp.Next()) {
484       const TopoDS_Shape& aF=aExp.Current();
485       aSFS.Append(aF);
486     }
487     //
488     aIt.Initialize(aLFIN);
489     for (; aIt.More(); aIt.Next()) {
490       TopoDS_Shape aF=aIt.Value();
491       //
492       aF.Orientation(TopAbs_FORWARD);
493       aSFS.Append(aF);
494       aF.Orientation(TopAbs_REVERSED);
495       aSFS.Append(aF);
496     }
497     //
498     Standard_Integer aNbSFS;
499     aNbSFS=aSFS.Extent();
500     //
501     // 1.2
502     // Check whether aSFS contains a subsets of faces
503     // of solids that have been already built.
504     // If yes, shrink aSFS by these subsets.
505     aSSi.Clear();
506     aSSi.Add(aSFS);
507     //
508     aItSS.Initialize(aMSS);
509     for (; aItSS.More(); aItSS.Next()) {
510       const TopoDS_Shape& aSR=aItSS.Key();
511       const GEOMAlgo_ShapeSet& aSSR=aItSS.Value();
512       if (aSSi.Contains(aSSR)) {
513         // the aSR is SD solid for aS
514         aSSi.Subtract(aSSR);
515         // update images
516         if(myImages.HasImage(aS)) {
517           myImages.Add(aS, aSR);
518         }
519         else {
520           myImages.Bind(aS, aSR);
521         }
522         //
523         // update SD Shapes
524         mySameDomainShapes.Add(aSR, aSR);
525       }
526     }
527     const TopTools_ListOfShape& aSFS1=aSSi.GetSet();
528     aNbSFS=aSFS1.Extent();
529     //modified by NIZNHY-PKV Wed Oct 27 09:53:15 2010f
530     if (!aNbSFS) {
531       continue;
532     }
533     //modified by NIZNHY-PKV Wed Oct 27 09:53:18 2010t
534     //
535     // 1.3 Build new solids
536 #if OCC_VERSION_LARGE > 0x06050200
537     aSB.SetContext(aCtx);
538 #endif
539     aSB.SetShapes(aSFS1);
540     aSB.Perform();
541     iErr=aSB.ErrorStatus();
542     if (iErr) {
543       myErrorStatus=30; // SolidBuilder failed
544       return;
545     }
546     //
547     const TopTools_ListOfShape& aLSR=aSB.Areas();
548     //
549       // 1.4 Collect resulting solids and theirs set of faces
550     aIt.Initialize(aLSR);
551     for (; aIt.More(); aIt.Next()) {
552       const TopoDS_Shape& aSR=aIt.Value();
553       //
554       aSSi.Clear();
555       aExp.Init(aSR, TopAbs_FACE);
556       for (; aExp.More(); aExp.Next()) {
557         const TopoDS_Shape& aF=aExp.Current();
558         aSSi.Add(aF);
559       }
560       aMSS.Bind(aSR, aSSi);
561     }
562     //
563     // Update images
564     if (myImages.HasImage(aS)) {
565       myImages.Add(aS, aLSR);
566     }
567     else {
568       myImages.Bind(aS, aLSR);
569     }
570   } // for (i=1; i<=aNbS; ++i) {
571 }
572 //=======================================================================
573 //function :FillInternalShapes
574 //purpose  :
575 //=======================================================================
576   void GEOMAlgo_Builder::FillInternalShapes()
577 {
578   myErrorStatus=0;
579   //
580   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
581   NMTTools_PaveFiller* pPF=myPaveFiller;
582 #if OCC_VERSION_LARGE > 0x06050200
583   const Handle(IntTools_Context)& aCtx= pPF->Context();
584 #else
585   IntTools_Context& aCtx= pPF->ChangeContext();
586 #endif
587   //
588   //Standard_Boolean bHasImage;
589   Standard_Integer i, j, jT, aNbS, aNbSI, aNbSx, aNbSd;
590   TopAbs_ShapeEnum aType, aT[]={ TopAbs_VERTEX, TopAbs_EDGE };
591   TopAbs_State aState;
592   TopTools_ListIteratorOfListOfShape aIt, aIt1;
593   TopTools_IndexedDataMapOfShapeListOfShape aMSx;
594   TopTools_IndexedMapOfShape aMx;
595   TopTools_MapOfShape aMSI, aMFence, aMSOr;
596   TopTools_MapIteratorOfMapOfShape aItM;
597   TopTools_ListOfShape aLSI, aLSd;
598   TopoDS_Iterator aItS;
599   BRep_Builder aBB;
600   //
601   // 1. Shapes to process
602   //
603   // 1.1 Shapes from pure arguments aMSI
604   // 1.1.1 vertex, edge
605   for (i=0; i<2; ++i) {
606     jT=(Standard_Integer)aT[i];
607     const TopTools_ListOfShape &aLS=myShapes1[jT];
608     aIt.Initialize(aLS);
609     for (; aIt.More(); aIt.Next()) {
610       const TopoDS_Shape& aS=aIt.Value();
611       if (aMFence.Add(aS)) {
612         aLSI.Append(aS);
613       }
614     }
615   }
616   // 1.1.2 wire
617   {
618     jT=(Standard_Integer)TopAbs_WIRE;
619     const TopTools_ListOfShape &aLW=myShapes1[jT];
620     aIt.Initialize(aLW);
621     for (; aIt.More(); aIt.Next()) {
622       const TopoDS_Shape& aW=aIt.Value();
623       aItS.Initialize(aW);
624       for (; aItS.More(); aItS.Next()) {
625         const TopoDS_Shape& aE=aItS.Value();
626         if (aMFence.Add(aE)) {
627           aLSI.Append(aE);
628         }
629       }
630     }
631   }
632   // 1.1.3 theirs images/sources
633   aIt1.Initialize(aLSI);
634   for (; aIt1.More(); aIt1.Next()) {
635     const TopoDS_Shape& aS=aIt1.Value();
636     if (myImages.HasImage(aS)) {
637       const TopTools_ListOfShape &aLSp=myImages.Image(aS);
638       aIt.Initialize(aLSp);
639       for (; aIt.More(); aIt.Next()) {
640         const TopoDS_Shape& aSI=aIt.Value();
641         aMSI.Add(aSI);
642       }
643     }
644     else {
645       aMSI.Add(aS);
646     }
647   }
648   aLSI.Clear();
649   aNbSI=aMSI.Extent();
650   //
651   // 2. Internal vertices, edges from source solids
652   aMFence.Clear();
653   aLSd.Clear();
654   //
655   aNbS=aDS.NumberOfShapesOfTheObject();
656   for (i=1; i<=aNbS; ++i) {
657     const TopoDS_Shape& aS=aDS.Shape(i);
658     aType=aS.ShapeType();
659     if (aType==TopAbs_SOLID) {
660       //
661       aMx.Clear();
662       OwnInternalShapes(aS, aMx);
663       //
664       aNbSx=aMx.Extent();
665       for (j=1; j<=aNbSx; ++j) {
666         const TopoDS_Shape& aSI=aMx(j);
667         if (myImages.HasImage(aSI)) {
668           const TopTools_ListOfShape &aLSp=myImages.Image(aSI);
669           aIt.Initialize(aLSp);
670           for (; aIt.More(); aIt.Next()) {
671             const TopoDS_Shape& aSp=aIt.Value();
672             aMSI.Add(aSp);
673           }
674         }
675         else {
676           aMSI.Add(aSI);
677         }
678       }
679       //
680       // build aux map from splits of solids
681       if (myImages.HasImage(aS)) {
682         const TopTools_ListOfShape &aLSp=myImages.Image(aS);
683         aIt.Initialize(aLSp);
684         for (; aIt.More(); aIt.Next()) {
685           const TopoDS_Shape& aSp=aIt.Value();
686           if (aMFence.Add(aSp)) {
687             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
688             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
689             TopExp::MapShapesAndAncestors(aSp, TopAbs_EDGE  , TopAbs_FACE, aMSx);
690             aLSd.Append(aSp);
691           }
692         }
693       }
694       else {
695         if (aMFence.Add(aS)) {
696           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
697           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
698           TopExp::MapShapesAndAncestors(aS, TopAbs_EDGE  , TopAbs_FACE, aMSx);
699           aLSd.Append(aS);
700           aMSOr.Add(aS);
701         }
702       }
703     }//if (aType==TopAbs_SOLID)
704   }
705   //
706   aNbSd=aLSd.Extent();
707   //
708   // 3. Some shapes of aMSI can be already tied with faces of
709   //    split solids
710   aItM.Initialize(aMSI);
711   for (; aItM.More(); aItM.Next()) {
712     const TopoDS_Shape& aSI=aItM.Key();
713     if (aMSx.Contains(aSI)) {
714       const TopTools_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
715       aNbSx=aLSx.Extent();
716       if (aNbSx) {
717         aMSI.Remove(aSI);
718       }
719     }
720   }
721   //
722   // 4. Just check it
723   aNbSI=aMSI.Extent();
724   if (!aNbSI) {
725     return;
726   }
727   //
728   // 5 Settle internal vertices and edges into solids
729   aMx.Clear();
730   aIt.Initialize(aLSd);
731   for (; aIt.More(); aIt.Next()) {
732     TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
733     //
734     aItM.Initialize(aMSI);
735     for (; aItM.More(); aItM.Next()) {
736       TopoDS_Shape aSI=aItM.Key();
737       aSI.Orientation(TopAbs_INTERNAL);
738       //
739       aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
740       if (aState==TopAbs_IN) {
741         //
742         if(aMSOr.Contains(aSd)) {
743           //
744           TopoDS_Solid aSdx;
745           //
746           aBB.MakeSolid(aSdx);
747           aItS.Initialize(aSd);
748           for (; aItS.More(); aItS.Next()) {
749             const TopoDS_Shape& aSh=aItS.Value();
750             aBB.Add(aSdx, aSh);
751           }
752           //
753           aBB.Add(aSdx, aSI);
754           //
755           myImages.Bind(aSd, aSdx);
756           aMSOr.Remove(aSd);
757           aSd=aSdx;
758         }
759         else {
760           aBB.Add(aSd, aSI);
761         }
762         //
763         aMSI.Remove(aSI);
764       } //if (aState==TopAbs_IN) {
765     }// for (; aItM.More(); aItM.Next()) {
766   }//for (; aIt1.More(); aIt1.Next()) {
767 }
768 //=======================================================================
769 //function : OwnInternalShapes
770 //purpose  :
771 //=======================================================================
772   void OwnInternalShapes(const TopoDS_Shape& theS,
773                          TopTools_IndexedMapOfShape& theMx)
774 {
775   TopoDS_Iterator aIt;
776   //
777   aIt.Initialize(theS);
778   for (; aIt.More(); aIt.Next()) {
779     const TopoDS_Shape& aSx=aIt.Value();
780     if (aSx.ShapeType()!=TopAbs_SHELL) {
781       theMx.Add(aSx);
782     }
783   }
784 }
785 //
786 // ErrorStatus
787 // 30 - SolidBuilder failed