Salome HOME
Porting to OCCT development version: Standard_PI -> M_PI
[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 //  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   /*const NMTDS_ShapesDataStructure& aDS=**/myPaveFiller->DS();
98   NMTTools_PaveFiller* pPF=myPaveFiller;
99   IntTools_Context& aCtx= pPF->ChangeContext();
100   //
101   Standard_Boolean bToReverse;
102   Standard_Integer  iFlag;
103   TopAbs_Orientation aOrF, aOrSh, aOrSd;
104   TopoDS_Iterator aIt1, aIt2;
105   TopTools_ListIteratorOfListOfShape aItS;
106   BRep_Builder aBB;
107   TopoDS_Shell aShD;
108   TopoDS_Shape aFSDx, aFx;
109   //
110   aOrSd=theSolid.Orientation();
111   theDraftSolid.Orientation(aOrSd);
112   //
113   aIt1.Initialize(theSolid);
114   for (; aIt1.More(); aIt1.Next()) {
115     const TopoDS_Shape& aSh=aIt1.Value();
116     if(aSh.ShapeType()!=TopAbs_SHELL) {
117       continue; // mb internal edges,vertices
118     }
119     //
120     aOrSh=aSh.Orientation();
121     aBB.MakeShell(aShD);
122     aShD.Orientation(aOrSh);
123     iFlag=0;
124     //
125     aIt2.Initialize(aSh);
126     for (; aIt2.More(); aIt2.Next()) {
127       const TopoDS_Shape& aF=aIt2.Value();
128       aOrF=aF.Orientation();
129       //
130       if (myImages.HasImage(aF)) {
131         const TopTools_ListOfShape& aLSp=myImages.Image(aF);
132         aItS.Initialize(aLSp);
133         for (; aItS.More(); aItS.Next()) {
134           aFx=aItS.Value();
135           //
136           if (mySameDomainShapes.Contains(aFx)) {
137             aFSDx=mySameDomainShapes.FindFromKey(aFx);
138             //
139             if (aOrF==TopAbs_INTERNAL) {
140               aFSDx.Orientation(aOrF);
141               theLIF.Append(aFSDx);
142             }
143             else {
144               bToReverse=GEOMAlgo_Tools3D::IsSplitToReverse(aFSDx, aF, aCtx);
145               if (bToReverse) {
146                 aFSDx.Reverse();
147               }
148               //
149               iFlag=1;
150               aBB.Add(aShD, aFSDx);
151             }
152           }// if (mySameDomainShapes.Contains(aFx)) {
153           else {
154             aFx.Orientation(aOrF);
155             if (aOrF==TopAbs_INTERNAL) {
156               theLIF.Append(aFx);
157             }
158             else{
159               iFlag=1;
160               aBB.Add(aShD, aFx);
161             }
162           }
163         }
164       } //if (myImages.HasImage(aF)) {
165       //
166       else {
167         if (aOrF==TopAbs_INTERNAL) {
168           theLIF.Append(aF);
169         }
170         else{
171           iFlag=1;
172           aBB.Add(aShD, aF);
173         }
174       }
175     } //for (; aIt2.More(); aIt2.Next()) {
176     //
177     if (iFlag) {
178       aBB.Add(theDraftSolid, aShD);
179     }
180   } //for (; aIt1.More(); aIt1.Next()) {
181 }
182 //=======================================================================
183 //function : FillIn3DParts
184 //purpose  :
185 //=======================================================================
186   void GEOMAlgo_Builder::FillIn3DParts()
187 {
188   myErrorStatus=0;
189   //
190   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
191   NMTTools_PaveFiller* pPF=myPaveFiller;
192   IntTools_Context& aCtx= pPF->ChangeContext();
193   //
194   Standard_Boolean bIsIN, bHasImage;
195   Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF;
196   TopAbs_ShapeEnum aType;
197   TopAbs_State aState;
198   TopTools_IndexedMapOfShape aMSolids, aMS, aMFaces, aMFIN;
199   TopTools_MapOfShape aMFDone;
200   TopTools_IndexedDataMapOfShapeListOfShape aMEF;
201   TopTools_ListIteratorOfListOfShape aItS;
202   TopoDS_Iterator aIt, aItF;
203   BRep_Builder aBB;
204   TopoDS_Solid aSolidSp;
205   TopoDS_Face aFP;
206   //
207   myDraftSolids.Clear();
208   //
209   aNbS=aDS.NumberOfShapesOfTheObject();
210   for (i=1; i<=aNbS; ++i) {
211     const TopoDS_Shape& aS=aDS.Shape(i);
212     //
213     aType=aS.ShapeType();
214     if (aType==TopAbs_SOLID) {
215       // all solids from DS
216       aMSolids.Add(aS);
217     }
218     else if (aType==TopAbs_FACE) {
219       // all faces (originals from DS or theirs images)
220       if (myImages.HasImage(aS)) {
221         const TopTools_ListOfShape& aLS=myImages.Image(aS);
222         aItS.Initialize(aLS);
223         for (; aItS.More(); aItS.Next()) {
224           const TopoDS_Shape& aFx=aItS.Value();
225           //
226           if (mySameDomainShapes.Contains(aFx)) {
227             const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aFx);
228             aMFaces.Add(aFSDx);
229           }
230           else {
231             aMFaces.Add(aFx);
232           }
233         }
234       }
235       else {
236         if (mySameDomainShapes.Contains(aS)) {
237           const TopoDS_Shape& aFSDx=mySameDomainShapes.FindFromKey(aS);
238           aMFaces.Add(aFSDx);
239         }
240         else {
241           aMFaces.Add(aS);
242         }
243       }
244     }
245   }
246   //
247   aNbFaces=aMFaces.Extent();
248   aNbSolids=aMSolids.Extent();
249   //
250   for (i=1; i<=aNbSolids; ++i) {
251     const TopoDS_Solid& aSolid=TopoDS::Solid(aMSolids(i));
252     aMFDone.Clear();
253     aMFIN.Clear();
254     aMEF.Clear();
255     //
256     aBB.MakeSolid(aSolidSp);
257     //
258     TopTools_ListOfShape aLIF;
259     //
260     BuildDraftSolid(aSolid, aSolidSp, aLIF);
261     aNbLIF=aLIF.Extent();
262     //
263     // 1 all faces/edges from aSolid [ aMS ]
264     bHasImage=Standard_False;
265     aMS.Clear();
266     aIt.Initialize(aSolid);
267     for (; aIt.More(); aIt.Next()) {
268       const TopoDS_Shape& aShell=aIt.Value();
269       //
270       if (myImages.HasImage(aShell)) {
271         bHasImage=Standard_True;
272         //
273         const TopTools_ListOfShape& aLS=myImages.Image(aShell);
274         aItS.Initialize(aLS);
275         for (; aItS.More(); aItS.Next()) {
276           const TopoDS_Shape& aSx=aItS.Value();
277           aMS.Add(aSx);
278           TopExp::MapShapes(aSx, TopAbs_FACE, aMS);
279           TopExp::MapShapes(aSx, TopAbs_EDGE, aMS);
280           TopExp::MapShapesAndAncestors(aSx, TopAbs_EDGE, TopAbs_FACE, aMEF);
281         }
282       }
283       else {
284         //aMS.Add(aShell);
285         TopExp::MapShapes(aShell, TopAbs_FACE, aMS);
286         //modified by NIZNHY-PKV Fri Dec 03 11:18:45 2010f
287         TopExp::MapShapes(aShell, TopAbs_EDGE, aMS);
288         //modified by NIZNHY-PKV Fri Dec 03 11:18:51 2010t
289         TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
290       }
291     }
292     //
293     // 2 all faces that are not from aSolid [ aLFP1 ]
294     Standard_Integer aNbEFP;
295     TopTools_IndexedDataMapOfShapeListOfShape aMEFP;
296     TopTools_ListIteratorOfListOfShape aItFP, aItEx;
297     TopTools_MapOfShape aMFence;
298     TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP,
299     //
300     // for all non-solid faces build EF map [ aMEFP ]
301     for (j=1; j<=aNbFaces; ++j) {
302       const TopoDS_Shape& aFace=aMFaces(j);
303       if (!aMS.Contains(aFace)) {
304         TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
305       }
306     }
307     //
308     // among all faces from aMEFP select these that have same edges
309     // with the solid (i.e aMEF). These faces will be treated first
310     // to prevent the usage of 3D classifier.
311     // The full list of faces to process is aLFP1.
312     aNbEFP=aMEFP.Extent();
313     for (j=1; j<=aNbEFP; ++j) {
314       const TopoDS_Shape& aE=aMEFP.FindKey(j);
315       //
316       if (aMEF.Contains(aE)) { // !!
317         const TopTools_ListOfShape& aLF=aMEFP(j);
318         aItFP.Initialize(aLF);
319         for (; aItFP.More(); aItFP.Next()) {
320           const TopoDS_Shape& aF=aItFP.Value();
321           if (aMFence.Add(aF)) {
322             aLFP1.Append(aF);
323           }
324         }
325       }
326       else {
327         aLEx.Append(aE);
328       }
329     }
330     //
331     aItEx.Initialize(aLEx);
332     for (; aItEx.More(); aItEx.Next()) {
333       const TopoDS_Shape& aE=aItEx.Value();
334       const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE);
335       aItFP.Initialize(aLF);
336       for (; aItFP.More(); aItFP.Next()) {
337         const TopoDS_Shape& aF=aItFP.Value();
338         if (aMFence.Add(aF)) {
339           aLFP2.Append(aF);
340         }
341       }
342     }
343     aLFP1.Append(aLFP2);
344     //==========
345     //
346     // 3 Process faces aLFP1
347     aNbFP=aLFP1.Extent();
348     aItFP.Initialize(aLFP1);
349     for (; aItFP.More(); aItFP.Next()) {
350       const TopoDS_Shape& aSP=aItFP.Value();
351       if (!aMFDone.Add(aSP)) {
352         continue;
353       }
354
355       //
356       // first face to process
357       aFP=TopoDS::Face(aSP);
358       bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx);
359       aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
360       //
361       // collect faces to process [ aFP is the first ]
362       aLFP.Clear();
363       aLFP.Append(aFP);
364       aItS.Initialize(aLFP1);
365       for (; aItS.More(); aItS.Next()) {
366         const TopoDS_Shape& aSk=aItS.Value();
367         if (!aMFDone.Contains(aSk)) {
368           aLFP.Append(aSk);
369         }
370       }
371       //
372       // Connexity Block that spreads from aFP the Bound
373       // or till the end of the block itself
374       aLCBF.Clear();
375       GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF);
376       //
377       // fill states for the Connexity Block
378       aItS.Initialize(aLCBF);
379       for (; aItS.More(); aItS.Next()) {
380         const TopoDS_Shape& aSx=aItS.Value();
381         aMFDone.Add(aSx);
382         if (aState==TopAbs_IN) {
383           aMFIN.Add(aSx);
384         }
385       }
386       //
387       aNbFPx=aMFDone.Extent();
388       if (aNbFPx==aNbFP) {
389         break;
390       }
391     }//for (; aItFP.More(); aItFP.Next())
392     //
393     // faces Inside aSolid
394     aLFIN.Clear();
395     aNbFIN=aMFIN.Extent();
396     if (aNbFIN || aNbLIF) {
397       for (j=1; j<=aNbFIN; ++j) {
398         const TopoDS_Shape& aFIN=aMFIN(j);
399         aLFIN.Append(aFIN);
400       }
401       //
402       aItS.Initialize(aLIF);
403       for (; aItS.More(); aItS.Next()) {
404         const TopoDS_Shape& aFIN=aItS.Value();
405         aLFIN.Append(aFIN);
406       }
407       //
408       myInParts.Add(aSolid, aLFIN);
409     }
410     if (aNbFIN || bHasImage) {
411       myDraftSolids.Add(aSolid, aSolidSp);
412     }
413   }//for (i=1; i<=aNbSolids; ++i) { // next solid
414 }
415 //=======================================================================
416 //function : BuildSplitSolids
417 //purpose  :
418 //=======================================================================
419   void GEOMAlgo_Builder::BuildSplitSolids()
420 {
421   myErrorStatus=0;
422   //
423   const NMTDS_ShapesDataStructure& aDS=*myPaveFiller->DS();
424   NMTTools_PaveFiller* pPF=myPaveFiller;
425   IntTools_Context& aCtx= pPF->ChangeContext();
426   //
427   Standard_Integer i, aNbS, iErr;
428   TopExp_Explorer aExp;
429   TopTools_ListOfShape aSFS, aLSEmpty;
430   TopTools_MapOfShape aMFence;
431   TopTools_ListIteratorOfListOfShape aIt;
432   GEOMAlgo_BuilderSolid aSB;
433   GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet aItSS;
434   GEOMAlgo_DataMapOfShapeShapeSet aMSS;
435   GEOMAlgo_ShapeSet aSSi;
436   //
437   // 0. Find same domain solids for non-interferred solids
438   aNbS=aDS.NumberOfShapesOfTheObject();
439   for (i=1; i<=aNbS; ++i) {
440     const TopoDS_Shape& aS=aDS.Shape(i);
441     if (aS.ShapeType()!=TopAbs_SOLID) {
442       continue;
443     }
444     if (!aMFence.Add(aS)) {
445       continue;
446     }
447     if(myDraftSolids.Contains(aS)) {
448       continue;
449     }
450     //
451     aSSi.Clear();
452     aSSi.Add(aS, TopAbs_FACE);
453     //
454     aMSS.Bind(aS, aSSi);
455   } //for (i=1; i<=aNbS; ++i)
456   //
457   // 1. Build solids for interferred source solids
458   aSB.SetContext(aCtx);
459   aSB.ComputeInternalShapes(myComputeInternalShapes);
460   aNbS=myDraftSolids.Extent();
461   for (i=1; i<=aNbS; ++i) {
462     const TopoDS_Shape& aS =myDraftSolids.FindKey(i);
463     const TopoDS_Shape& aSD=myDraftSolids.FindFromIndex(i);
464     const TopTools_ListOfShape& aLFIN=
465       (myInParts.Contains(aS)) ? myInParts.FindFromKey(aS) : aLSEmpty;
466     //
467     // 1.1 Fill Shell Faces Set
468     aSFS.Clear();
469
470     aExp.Init(aSD, TopAbs_FACE);
471     for (; aExp.More(); aExp.Next()) {
472       const TopoDS_Shape& aF=aExp.Current();
473       aSFS.Append(aF);
474     }
475     //
476     aIt.Initialize(aLFIN);
477     for (; aIt.More(); aIt.Next()) {
478       TopoDS_Shape aF=aIt.Value();
479       //
480       aF.Orientation(TopAbs_FORWARD);
481       aSFS.Append(aF);
482       aF.Orientation(TopAbs_REVERSED);
483       aSFS.Append(aF);
484     }
485     //
486     Standard_Integer aNbSFS;
487     aNbSFS=aSFS.Extent();
488     //
489     // 1.2
490     // Check whether aSFS contains a subsets of faces
491     // of solids that have been already built.
492     // If yes, shrink aSFS by these subsets.
493     aSSi.Clear();
494     aSSi.Add(aSFS);
495     //
496     aItSS.Initialize(aMSS);
497     for (; aItSS.More(); aItSS.Next()) {
498       const TopoDS_Shape& aSR=aItSS.Key();
499       const GEOMAlgo_ShapeSet& aSSR=aItSS.Value();
500       if (aSSi.Contains(aSSR)) {
501         // the aSR is SD solid for aS
502         aSSi.Subtract(aSSR);
503         // update images
504         if(myImages.HasImage(aS)) {
505           myImages.Add(aS, aSR);
506         }
507         else {
508           myImages.Bind(aS, aSR);
509         }
510         //
511         // update SD Shapes
512         mySameDomainShapes.Add(aSR, aSR);
513       }
514     }
515     const TopTools_ListOfShape& aSFS1=aSSi.GetSet();
516     aNbSFS=aSFS1.Extent();
517     //modified by NIZNHY-PKV Wed Oct 27 09:53:15 2010f
518     if (!aNbSFS) {
519       continue;
520     }
521     //modified by NIZNHY-PKV Wed Oct 27 09:53:18 2010t
522     //
523     // 1.3 Build new solids
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   IntTools_Context& aCtx= pPF->ChangeContext();
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