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