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