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