]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMAlgo/GEOMAlgo_Builder_3.cxx
Salome HOME
NPAL15298: KindOfShape(). A tool by PKV.
[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_DSFiller.hxx>
60 #include <NMTTools_PaveFiller.hxx>
61
62 #include <GEOMAlgo_Tools3D.hxx>
63 #include <GEOMAlgo_BuilderSolid.hxx>
64 #include <GEOMAlgo_ShapeSet.hxx>
65 #include <GEOMAlgo_DataMapOfShapeShapeSet.hxx>
66 #include <GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet.hxx>
67
68
69
70 static
71   void OwnInternalShapes(const TopoDS_Shape& ,
72                          TopTools_IndexedMapOfShape& );
73
74 //=======================================================================
75 //function : FillImagesSolids
76 //purpose  : 
77 //=======================================================================
78   void GEOMAlgo_Builder::FillImagesSolids()
79 {
80   myErrorStatus=0;
81   //
82   FillIn3DParts();
83   BuildSplitSolids();
84   FillInternalShapes();
85 }
86 //=======================================================================
87 //function : BuildDraftSolid
88 //purpose  : 
89 //=======================================================================
90   void GEOMAlgo_Builder::BuildDraftSolid(const TopoDS_Shape& theSolid,
91                                         TopoDS_Shape& theDraftSolid,
92                                         TopTools_ListOfShape& theLIF)
93 {
94   myErrorStatus=0;
95   //
96   const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS(); 
97   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
98   IntTools_Context& aCtx= pPF->ChangeContext();
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=myDSFiller->DS(); 
190   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
191   IntTools_Context& aCtx= pPF->ChangeContext();
192   //
193   Standard_Boolean bIsIN, bHasImage;
194   Standard_Integer aNbS, aNbSolids, i, j, aNbFaces, aNbFP, aNbFPx, aNbFIN, aNbLIF;// k,
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         TopExp::MapShapesAndAncestors(aShell, TopAbs_EDGE, TopAbs_FACE, aMEF);
286       }
287     }
288     //
289     // 2 all faces that are not from aSolid [ aLFP1 ]
290     Standard_Integer aNbEFP;
291     TopTools_IndexedDataMapOfShapeListOfShape aMEFP;
292     TopTools_ListIteratorOfListOfShape aItFP, aItEx;
293     TopTools_MapOfShape aMFence;
294     TopTools_ListOfShape aLFP1, aLFP2, aLFP, aLCBF, aLFIN, aLEx;//*pLFP,
295     //
296     // for all non-solid faces build EF map [ aMEFP ]
297     for (j=1; j<=aNbFaces; ++j) {
298       const TopoDS_Shape& aFace=aMFaces(j);
299       if (!aMS.Contains(aFace)) {
300         TopExp::MapShapesAndAncestors(aFace, TopAbs_EDGE, TopAbs_FACE, aMEFP);
301       }
302     }
303     //
304     // among all faces from aMEFP select these that have same edges
305     // with the solid (i.e aMEF). These faces will be treated first 
306     // to prevent the usage of 3D classifier.
307     // The full list of faces to process is aLFP1. 
308     aNbEFP=aMEFP.Extent();
309     for (j=1; j<=aNbEFP; ++j) {
310       const TopoDS_Shape& aE=aMEFP.FindKey(j);
311       //
312       if (aMEF.Contains(aE)) { // !!
313         const TopTools_ListOfShape& aLF=aMEFP(j);
314         aItFP.Initialize(aLF);
315         for (; aItFP.More(); aItFP.Next()) {
316           const TopoDS_Shape& aF=aItFP.Value();
317           if (aMFence.Add(aF)) {
318             aLFP1.Append(aF);
319           }
320         }
321       }
322       else {
323         aLEx.Append(aE);
324       }
325     }
326     //
327     aItEx.Initialize(aLEx);
328     for (; aItEx.More(); aItEx.Next()) {
329       const TopoDS_Shape& aE=aItEx.Value();
330       const TopTools_ListOfShape& aLF=aMEFP.FindFromKey(aE);
331       aItFP.Initialize(aLF);
332       for (; aItFP.More(); aItFP.Next()) {
333         const TopoDS_Shape& aF=aItFP.Value();
334         if (aMFence.Add(aF)) {
335           aLFP2.Append(aF);
336         }
337       }
338     }
339     aLFP1.Append(aLFP2);
340     //==========
341     //
342     // 3 Process faces aLFP1
343     aNbFP=aLFP1.Extent();
344     aItFP.Initialize(aLFP1);
345     for (; aItFP.More(); aItFP.Next()) {
346       const TopoDS_Shape& aSP=aItFP.Value();
347       if (!aMFDone.Add(aSP)) {
348         continue;
349       }
350       
351       //
352       // first face to process
353       aFP=TopoDS::Face(aSP);
354       bIsIN= GEOMAlgo_Tools3D::IsInternalFace(aFP, aSolidSp, aMEF, 1.e-14, aCtx);
355       aState=(bIsIN) ? TopAbs_IN : TopAbs_OUT;
356       //
357       // collect faces to process [ aFP is the first ]
358       aLFP.Clear();
359       aLFP.Append(aFP);
360       aItS.Initialize(aLFP1);
361       for (; aItS.More(); aItS.Next()) {
362         const TopoDS_Shape& aSk=aItS.Value();
363         if (!aMFDone.Contains(aSk)) {
364           aLFP.Append(aSk);
365         }
366       }
367       //
368       // Connexity Block that spreads from aFP the Bound 
369       // or till the end of the block itself
370       aLCBF.Clear();
371       GEOMAlgo_Tools3D::MakeConnexityBlock(aLFP, aMS, aLCBF);
372       //
373       // fill states for the Connexity Block 
374       aItS.Initialize(aLCBF);
375       for (; aItS.More(); aItS.Next()) {
376         const TopoDS_Shape& aSx=aItS.Value();
377         aMFDone.Add(aSx);
378         if (aState==TopAbs_IN) {
379           aMFIN.Add(aSx);
380         }
381       }
382       //
383       aNbFPx=aMFDone.Extent();
384       if (aNbFPx==aNbFP) {
385         break;
386       }
387     }//for (; aItFP.More(); aItFP.Next())
388     //
389     // faces Inside aSolid
390     aLFIN.Clear();
391     aNbFIN=aMFIN.Extent();
392     if (aNbFIN || aNbLIF) {
393       for (j=1; j<=aNbFIN; ++j) {
394         const TopoDS_Shape& aFIN=aMFIN(j);
395         aLFIN.Append(aFIN);
396       }
397       //
398       aItS.Initialize(aLIF);
399       for (; aItS.More(); aItS.Next()) {
400         const TopoDS_Shape& aFIN=aItS.Value();
401         aLFIN.Append(aFIN);
402       }
403       //
404       myInParts.Add(aSolid, aLFIN);
405     }
406     if (aNbFIN || bHasImage) {
407       myDraftSolids.Add(aSolid, aSolidSp);
408     }
409   }//for (i=1; i<=aNbSolids; ++i) { // next solid
410 }
411 //=======================================================================
412 //function : BuildSplitSolids
413 //purpose  : 
414 //=======================================================================
415   void GEOMAlgo_Builder::BuildSplitSolids()
416 {
417   myErrorStatus=0;
418   // 
419   const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
420   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
421   IntTools_Context& aCtx= pPF->ChangeContext();
422   //
423   Standard_Integer i, aNbS, iErr;
424   TopExp_Explorer aExp;
425   TopTools_ListOfShape aSFS, aLSEmpty;
426   TopTools_MapOfShape aMFence;
427   TopTools_ListIteratorOfListOfShape aIt;
428   GEOMAlgo_BuilderSolid aSB;
429   GEOMAlgo_DataMapIteratorOfDataMapOfShapeShapeSet aItSS;
430   GEOMAlgo_DataMapOfShapeShapeSet aMSS;
431   GEOMAlgo_ShapeSet aSSi;
432   //
433   //modified by NIZNHY-PKV Wed Dec  6 17:08:03 2006f
434   //
435   // 0. Find same domain solids for non-interferred solids
436   aNbS=aDS.NumberOfShapesOfTheObject();
437   for (i=1; i<=aNbS; ++i) {
438     const TopoDS_Shape& aS=aDS.Shape(i);
439     if (aS.ShapeType()!=TopAbs_SOLID) {
440       continue;
441     }
442     if (!aMFence.Add(aS)) {
443       continue;
444     }
445     if(myDraftSolids.Contains(aS)) {
446       continue;
447     }
448     //
449     aSSi.Clear();
450     aSSi.Add(aS, TopAbs_FACE);
451     //
452     aMSS.Bind(aS, aSSi);
453   } //for (i=1; i<=aNbS; ++i) 
454   //
455   //modified by NIZNHY-PKV Wed Dec  6 17:08:09 2006t
456   //
457   // 1. Build solids for interferred source solids
458   //
459   aSB.SetContext(aCtx);
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     //
518     // 1.3 Build new solids
519     aSB.SetShapes(aSFS1);
520     aSB.Perform();
521     iErr=aSB.ErrorStatus();
522     if (iErr) {
523       myErrorStatus=30; // SolidBuilder failed
524       return;
525     }
526     //
527     const TopTools_ListOfShape& aLSR=aSB.Areas();
528     //
529     // 1.4 Collect resulting solids and theirs set of faces 
530     aIt.Initialize(aLSR);
531     for (; aIt.More(); aIt.Next()) {
532       const TopoDS_Shape& aSR=aIt.Value();
533       //
534       aSSi.Clear();
535       aExp.Init(aSR, TopAbs_FACE);
536       for (; aExp.More(); aExp.Next()) {
537         const TopoDS_Shape& aF=aExp.Current();
538         aSSi.Add(aF);
539       }
540       aMSS.Bind(aSR, aSSi);
541     }
542     //
543     // Update images
544     if (myImages.HasImage(aS)) {
545       myImages.Add(aS, aLSR);
546     }
547     else {
548       myImages.Bind(aS, aLSR);
549     }
550   } // for (i=1; i<=aNbS; ++i) {
551   //modified by NIZNHY-PKV Wed Dec  6 17:07:47 2006f
552   /*
553   //
554   // 2. Find same domain solids for non-interferred solids
555   aNbS=aDS.NumberOfShapesOfTheObject();
556   for (i=1; i<=aNbS; ++i) {
557     const TopoDS_Shape& aS=aDS.Shape(i);
558     if (aS.ShapeType()!=TopAbs_SOLID) {
559       continue;
560     }
561     if (!aMFence.Add(aS)) {
562       continue;
563     }
564     if(myImages.HasImage(aS)) {
565       continue;
566     }
567     //
568     aSSi.Clear();
569     aSSi.Add(aS, TopAbs_FACE);
570     //
571     aItSS.Initialize(aMSS);
572     for (; aItSS.More(); aItSS.Next()) {
573       const TopoDS_Shape& aSR=aItSS.Key(); 
574       const GEOMAlgo_ShapeSet& aSSR=aItSS.Value();
575       if (aSSi.Contains(aSSR)) {
576         myImages.Bind(aS, aSR);
577         break;
578       }
579     }
580   } //for (i=1; i<=aNbS; ++i) 
581   */
582   //modified by NIZNHY-PKV Wed Dec  6 17:07:55 2006t
583 }
584 //=======================================================================
585 //function :FillInternalShapes 
586 //purpose  : 
587 //=======================================================================
588   void GEOMAlgo_Builder::FillInternalShapes()
589 {
590   myErrorStatus=0;
591   //
592   const NMTDS_ShapesDataStructure& aDS=myDSFiller->DS();
593   NMTTools_PaveFiller* pPF=(NMTTools_PaveFiller*)&(myDSFiller->PaveFiller());
594   IntTools_Context& aCtx= pPF->ChangeContext();
595   //
596   //Standard_Boolean bHasImage;
597   Standard_Integer i, j, jT, aNbS, aNbSI, aNbSx, aNbSd;
598   TopAbs_ShapeEnum aType, aT[]={ TopAbs_VERTEX, TopAbs_EDGE };
599   TopAbs_State aState;
600   TopTools_ListIteratorOfListOfShape aIt, aIt1;
601   TopTools_IndexedDataMapOfShapeListOfShape aMSx;
602   TopTools_IndexedMapOfShape aMx;
603   TopTools_MapOfShape aMSI, aMFence, aMSOr;
604   TopTools_MapIteratorOfMapOfShape aItM;
605   TopTools_ListOfShape aLSI, aLSd;
606   TopoDS_Iterator aItS;
607   BRep_Builder aBB;
608   //
609   // 1. Shapes to process
610   //
611   // 1.1 Shapes from pure arguments aMSI 
612   // 1.1.1 vertex, edge
613   for (i=0; i<2; ++i) {
614     jT=(Standard_Integer)aT[i];
615     const TopTools_ListOfShape &aLS=myShapes1[jT];
616     aIt.Initialize(aLS);
617     for (; aIt.More(); aIt.Next()) {
618       const TopoDS_Shape& aS=aIt.Value();
619       if (aMFence.Add(aS)) {
620         aLSI.Append(aS);
621       }
622     }
623   }
624   // 1.1.2 wire
625   {  
626     jT=(Standard_Integer)TopAbs_WIRE;
627     const TopTools_ListOfShape &aLW=myShapes1[jT];
628     aIt.Initialize(aLW);
629     for (; aIt.More(); aIt.Next()) {
630       const TopoDS_Shape& aW=aIt.Value();
631       aItS.Initialize(aW);
632       for (; aItS.More(); aItS.Next()) {
633         const TopoDS_Shape& aE=aItS.Value();
634         if (aMFence.Add(aE)) {
635           aLSI.Append(aE);
636         }
637       }
638     }
639   }
640   // 1.1.3 theirs images/sources 
641   aIt1.Initialize(aLSI);
642   for (; aIt1.More(); aIt1.Next()) {
643     const TopoDS_Shape& aS=aIt1.Value();
644     if (myImages.HasImage(aS)) {
645       const TopTools_ListOfShape &aLSp=myImages.Image(aS);
646       aIt.Initialize(aLSp);
647       for (; aIt.More(); aIt.Next()) {
648         const TopoDS_Shape& aSI=aIt.Value();
649         aMSI.Add(aSI);
650       }
651     }
652     else {
653       aMSI.Add(aS);
654     }
655   }
656   aLSI.Clear();
657   aNbSI=aMSI.Extent();
658   //
659   // 2. Internal vertices, edges from source solids
660   aMFence.Clear();
661   aLSd.Clear();
662   //
663   aNbS=aDS.NumberOfShapesOfTheObject();
664   for (i=1; i<=aNbS; ++i) {
665     const TopoDS_Shape& aS=aDS.Shape(i);
666     aType=aS.ShapeType();
667     if (aType==TopAbs_SOLID) {
668       //
669       aMx.Clear();
670       OwnInternalShapes(aS, aMx);
671       //
672       aNbSx=aMx.Extent();
673       for (j=1; j<=aNbSx; ++j) {
674         const TopoDS_Shape& aSI=aMx(j);
675         if (myImages.HasImage(aSI)) {
676           const TopTools_ListOfShape &aLSp=myImages.Image(aSI);
677           aIt.Initialize(aLSp);
678           for (; aIt.More(); aIt.Next()) {
679             const TopoDS_Shape& aSp=aIt.Value();
680             aMSI.Add(aSp);
681           }
682         }
683         else {
684           aMSI.Add(aSI);
685         }
686       }
687       //
688       // build aux map from splits of solids
689       if (myImages.HasImage(aS)) {
690         const TopTools_ListOfShape &aLSp=myImages.Image(aS);
691         aIt.Initialize(aLSp);
692         for (; aIt.More(); aIt.Next()) {
693           const TopoDS_Shape& aSp=aIt.Value();
694           if (aMFence.Add(aSp)) { 
695             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
696             TopExp::MapShapesAndAncestors(aSp, TopAbs_VERTEX, TopAbs_FACE, aMSx);
697             TopExp::MapShapesAndAncestors(aSp, TopAbs_EDGE  , TopAbs_FACE, aMSx);
698             aLSd.Append(aSp);
699           }
700         }
701       }
702       else {
703         if (aMFence.Add(aS)) {
704           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_EDGE, aMSx);
705           TopExp::MapShapesAndAncestors(aS, TopAbs_VERTEX, TopAbs_FACE, aMSx);
706           TopExp::MapShapesAndAncestors(aS, TopAbs_EDGE  , TopAbs_FACE, aMSx);
707           aLSd.Append(aS);
708           aMSOr.Add(aS); 
709         }
710       }
711     }//if (aType==TopAbs_SOLID)
712   }
713   //
714   aNbSd=aLSd.Extent();
715   //
716   // 3. Some shapes of aMSI can be already tied with faces of 
717   //    split solids
718   aItM.Initialize(aMSI); 
719   for (; aItM.More(); aItM.Next()) {
720     const TopoDS_Shape& aSI=aItM.Key();
721     if (aMSx.Contains(aSI)) {
722       const TopTools_ListOfShape &aLSx=aMSx.FindFromKey(aSI);
723       aNbSx=aLSx.Extent();
724       if (aNbSx) {
725         aMSI.Remove(aSI);
726       }
727     }
728   }
729   //
730   // 4. Just check it
731   aNbSI=aMSI.Extent();
732   if (!aNbSI) {
733     return;
734   }
735   //
736   // 5 Settle internal vertices and edges into solids
737   aMx.Clear();
738   aIt.Initialize(aLSd);
739   for (; aIt.More(); aIt.Next()) {
740     TopoDS_Solid aSd=TopoDS::Solid(aIt.Value());
741     //
742     aItM.Initialize(aMSI); 
743     for (; aItM.More(); aItM.Next()) {
744       TopoDS_Shape aSI=aItM.Key();
745       aSI.Orientation(TopAbs_INTERNAL);
746       //
747       aState=GEOMAlgo_Tools3D::ComputeStateByOnePoint(aSI, aSd, 1.e-11, aCtx);
748       if (aState==TopAbs_IN) {
749         //
750         if(aMSOr.Contains(aSd)) {
751           //
752           TopoDS_Solid aSdx;
753           //
754           aBB.MakeSolid(aSdx);
755           aItS.Initialize(aSd);
756           for (; aItS.More(); aItS.Next()) {
757             const TopoDS_Shape& aSh=aItS.Value();
758             aBB.Add(aSdx, aSh);
759           }
760           //
761           aBB.Add(aSdx, aSI);
762           //
763           myImages.Bind(aSd, aSdx);
764           aMSOr.Remove(aSd);
765           aSd=aSdx;
766         }
767         else {
768           aBB.Add(aSd, aSI);
769         }
770         //
771         aMSI.Remove(aSI);
772       } //if (aState==TopAbs_IN) {
773     }// for (; aItM.More(); aItM.Next()) {
774   }//for (; aIt1.More(); aIt1.Next()) {
775 }
776 //=======================================================================
777 //function : OwnInternalShapes
778 //purpose  : 
779 //=======================================================================
780   void OwnInternalShapes(const TopoDS_Shape& theS,
781                          TopTools_IndexedMapOfShape& theMx)
782 {
783   TopoDS_Iterator aIt;
784   //
785   aIt.Initialize(theS);
786   for (; aIt.More(); aIt.Next()) {
787     const TopoDS_Shape& aSx=aIt.Value();
788     if (aSx.ShapeType()!=TopAbs_SHELL) {
789       theMx.Add(aSx);
790     }
791   }
792 }
793 //
794 // ErrorStatus
795 // 30 - SolidBuilder failed
796