]> SALOME platform Git repositories - modules/geom.git/blob - src/GEOMAlgo/GEOMAlgo_GetInPlace.cxx
Salome HOME
0021434: Boolean operations generate a shape with big vertex tolerance.
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_GetInPlace.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_GetInPlace.cxx
23 // Author:   Peter KURNEV
24
25 #include <GEOMAlgo_GetInPlace.hxx>
26
27 #include <GEOMAlgo_Tools.hxx>
28
29 #include <NMTTools_CoupleOfShape.hxx>
30
31 #include <NMTDS_BoxBndTree.hxx>
32
33 #include <Basics_OCCTVersion.hxx>
34
35 #include <NCollection_UBTreeFiller.hxx>
36
37 #include <Bnd_Box.hxx>
38 #include <gp_Pnt.hxx>
39
40 #include <TColStd_ListOfInteger.hxx>
41 #include <TColStd_ListIteratorOfListOfInteger.hxx>
42
43 #include <TopAbs_ShapeEnum.hxx>
44
45 #include <TopoDS_Iterator.hxx>
46 #include <TopoDS_Shape.hxx>
47 #include <TopoDS_Vertex.hxx>
48 #include <TopoDS_Edge.hxx>
49 #include <TopoDS_Face.hxx>
50 #include <TopoDS_Compound.hxx>
51
52 #include <BRep_Tool.hxx>
53 #include <BRep_Builder.hxx>
54
55 #include <BRepBndLib.hxx>
56
57 #include <TopExp.hxx>
58
59 #include <TopTools_IndexedMapOfShape.hxx>
60 #include <TopTools_ListOfShape.hxx>
61 #include <TopTools_DataMapOfShapeListOfShape.hxx>
62 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
63 #include <TopTools_ListIteratorOfListOfShape.hxx>
64 #include <TopTools_MapOfShape.hxx>
65 #include <TopTools_MapIteratorOfMapOfShape.hxx>
66
67
68 static
69   void MapBRepShapes(const TopoDS_Shape& aS,
70                      TopTools_IndexedMapOfShape& aM);
71
72
73 //=======================================================================
74 //function : GEOMAlgo_GetInPlace
75 //purpose  :
76 //=======================================================================
77 GEOMAlgo_GetInPlace::GEOMAlgo_GetInPlace()
78 :
79   GEOMAlgo_GluerAlgo(),
80   GEOMAlgo_Algo()
81 {
82   myTolerance=0.0001;
83   myTolMass=0.0001;
84   myTolCG=0.0001;
85   myFound=Standard_False;
86   myCheckGeometry=Standard_True;
87 }
88 //=======================================================================
89 //function : ~
90 //purpose  :
91 //=======================================================================
92 GEOMAlgo_GetInPlace::~GEOMAlgo_GetInPlace()
93 {
94 }
95 //=======================================================================
96 //function : SetTolMass
97 //purpose  :
98 //=======================================================================
99 void GEOMAlgo_GetInPlace::SetTolMass(const Standard_Real theTol)
100 {
101   myTolMass=theTol;
102 }
103 //=======================================================================
104 //function : TolMass
105 //purpose  :
106 //=======================================================================
107 Standard_Real GEOMAlgo_GetInPlace::TolMass()const
108 {
109   return myTolMass;
110 }
111 //=======================================================================
112 //function : SetTolCG
113 //purpose  :
114 //=======================================================================
115 void GEOMAlgo_GetInPlace::SetTolCG(const Standard_Real theTol)
116 {
117   myTolCG=theTol;
118 }
119 //=======================================================================
120 //function : TolCG
121 //purpose  :
122 //=======================================================================
123 Standard_Real GEOMAlgo_GetInPlace::TolCG()const
124 {
125   return myTolCG;
126 }
127 //=======================================================================
128 //function : IsFound
129 //purpose  :
130 //=======================================================================
131 Standard_Boolean GEOMAlgo_GetInPlace::IsFound()const
132 {
133   return myFound;
134 }
135 //=======================================================================
136 //function : SetShapeWhere
137 //purpose  :
138 //=======================================================================
139 void GEOMAlgo_GetInPlace::SetShapeWhere(const TopoDS_Shape& theShape)
140 {
141   myShapeWhere=theShape;
142 }
143 //=======================================================================
144 //function : ShapeWhere
145 //purpose  :
146 //=======================================================================
147 const TopoDS_Shape& GEOMAlgo_GetInPlace::ShapeWhere()const
148 {
149   return myShapeWhere;
150 }
151 //=======================================================================
152 //function : ShapesIn
153 //purpose  :
154 //=======================================================================
155 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesIn()const
156 {
157   return myShapesIn;
158 }
159 //=======================================================================
160 //function : ShapesOn
161 //purpose  :
162 //=======================================================================
163 const GEOMAlgo_DataMapOfShapeMapOfShape& GEOMAlgo_GetInPlace::ShapesOn()const
164 {
165   return myShapesOn;
166 }
167 //=======================================================================
168 //function : Clear
169 //purpose  :
170 //=======================================================================
171 void GEOMAlgo_GetInPlace::Clear()
172 {
173   myErrorStatus=0;
174   myWarningStatus=0;
175   //
176   GEOMAlgo_GluerAlgo::Clear();
177   myIterator.Clear();
178   myShapesIn.Clear();
179   myShapesOn.Clear();
180   myMapShapePnt.Clear();
181 }
182 //=======================================================================
183 //function : Perform
184 //purpose  :
185 //=======================================================================
186 void GEOMAlgo_GetInPlace::Perform()
187 {
188   myFound=Standard_False;
189   myErrorStatus=0;
190   myWarningStatus=0;
191   //
192   Clear();
193   if (myErrorStatus) {
194     return;
195   }
196   //
197   CheckData();
198   if (myErrorStatus) {
199     return;
200   }
201   //
202 #if OCC_VERSION_LARGE > 0x06050200
203   // Initialize the context
204   GEOMAlgo_GluerAlgo::Perform();
205 #endif
206   //
207   Intersect();
208   if (myErrorStatus) {
209     return;
210   }
211   //
212   PerformVV();
213   if (myErrorStatus) {
214     return;
215   }
216   //
217   FillEdgesOn();
218   if (myErrorStatus) {
219     return;
220   }
221   //
222   PerformVE();
223   if (myErrorStatus) {
224     return;
225   }
226   //
227   PerformEE();
228   if (myErrorStatus) {
229     return;
230   }
231   //
232   PerformVF();
233   if (myErrorStatus) {
234     return;
235   }
236   //
237   FillFacesOn();
238   if (myErrorStatus) {
239     return;
240   }
241   //
242   PerformEF();
243   if (myErrorStatus) {
244     return;
245   }
246   //
247   PerformFF();
248   if (myErrorStatus) {
249     return;
250   }
251   //
252   FillSolidsOn();
253   if (myErrorStatus) {
254     return;
255   }
256   //
257   PerformZF();
258   if (myErrorStatus) {
259     return;
260   }
261   //
262   PerformZZ();
263   if (myErrorStatus) {
264     return;
265   }
266   //
267   FillImages();
268   if (myErrorStatus) {
269     return;
270   }
271   //
272   CheckGProps();
273   if (myErrorStatus) {
274     return;
275   }
276 }
277 //=======================================================================
278 //function : CheckData
279 //purpose  :
280 //=======================================================================
281 void GEOMAlgo_GetInPlace::CheckData()
282 {
283   myErrorStatus=0;
284   myWarningStatus=0;
285   //
286   if (myArgument.IsNull()) {
287     myErrorStatus=2;
288     return;
289   }
290   //
291   if (myShapeWhere.IsNull()) {
292     myErrorStatus=3;
293     return;
294   }
295 }
296 //=======================================================================
297 //function : Intersect
298 //purpose  :
299 //=======================================================================
300 void GEOMAlgo_GetInPlace::Intersect()
301 {
302   Standard_Integer i, j, aNbS1, aNbS2, aNbSD;
303   TColStd_ListIteratorOfListOfInteger aItLI;
304   TopTools_IndexedMapOfShape aMS1, aMS2;
305   TopTools_DataMapOfShapeListOfShape aDMSLS;
306   TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
307   TopTools_ListIteratorOfListOfShape aItLS;
308   NMTTools_CoupleOfShape aCS;
309   //
310   NMTDS_BoxBndTreeSelector aSelector;
311   NMTDS_BoxBndTree aBBTree;
312   NCollection_UBTreeFiller <Standard_Integer, Bnd_Box> aTreeFiller(aBBTree);
313   //
314   myErrorStatus=0;
315   myWarningStatus=0;
316   //
317   myIterator.Clear();
318   //
319   MapBRepShapes(myArgument, aMS1);
320   aNbS1=aMS1.Extent();
321   for (i=1; i<=aNbS1; ++i) {
322     Bnd_Box aBox1;
323     //
324     const TopoDS_Shape& aS1=aMS1(i);
325     BRepBndLib::Add(aS1, aBox1);
326     //modified by NIZNHY-PKV Fri Jun 10 08:20:03 2011f
327     //aBox1.SetGap(myTolerance);
328     aBox1.Enlarge(myTolerance);
329     //modified by NIZNHY-PKV Fri Jun 10 08:20:06 2011t
330     //
331     aTreeFiller.Add(i, aBox1);
332   }
333   //
334   aTreeFiller.Fill();
335   //
336   MapBRepShapes(myShapeWhere, aMS2);
337   aNbS2=aMS2.Extent();
338   for (j=1; j<=aNbS2; ++j) {
339     Bnd_Box aBox2;
340     //
341     const TopoDS_Shape& aS2=aMS2(j);
342     BRepBndLib::Add(aS2, aBox2);
343     //modified by NIZNHY-PKV Fri Jun 10 08:20:23 2011f
344     //aBox2.SetGap(myTolerance);
345     aBox2.Enlarge(myTolerance);
346     //modified by NIZNHY-PKV Fri Jun 10 08:20:25 2011t
347     //
348     aSelector.Clear();
349     aSelector.SetBox(aBox2);
350     aNbSD=aBBTree.Select(aSelector);
351     if (!aNbSD) {
352       continue;  // it should not be
353     }
354     //
355     const TColStd_ListOfInteger& aLI=aSelector.Indices();
356     aItLI.Initialize(aLI);
357     for (; aItLI.More(); aItLI.Next()) {
358       i=aItLI.Value();
359       const TopoDS_Shape& aS1=aMS1(i);
360       //
361       if (aDMSLS.IsBound(aS1)) {
362         TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aS1);
363         aLS.Append(aS2);
364       }
365       else {
366         TopTools_ListOfShape aLS;
367         //
368         aLS.Append(aS2);
369         aDMSLS.Bind(aS1, aLS);
370       }
371     }
372   }// for (j=1; j<=aNbS2; ++j) {
373   //
374   aItDMSLS.Initialize(aDMSLS);
375   for (; aItDMSLS.More(); aItDMSLS.Next()) {
376     const TopoDS_Shape& aS1=aItDMSLS.Key();
377     const TopTools_ListOfShape& aLS2=aItDMSLS.Value();
378     aCS.SetShape1(aS1);
379     aItLS.Initialize(aLS2);
380     for (; aItLS.More(); aItLS.Next()) {
381       const TopoDS_Shape& aS2=aItLS.Value();
382       aCS.SetShape2(aS2);
383       myIterator.AppendPair(aCS);
384     }
385   }
386 }
387 //=======================================================================
388 //function : PerformVV
389 //purpose  :
390 //=======================================================================
391 void GEOMAlgo_GetInPlace::PerformVV()
392 {
393   myErrorStatus=0;
394   myWarningStatus=0;
395   //
396   myIterator.Initialize(TopAbs_VERTEX, TopAbs_VERTEX);
397   for (; myIterator.More(); myIterator.Next()) {
398     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
399     const TopoDS_Shape& aV1=aCS.Shape1();
400     const TopoDS_Shape& aV2=aCS.Shape2();
401     //
402     FillShapesOn(aV1, aV2);
403   }
404 }
405 //=======================================================================
406 //function : FillEdgesOn
407 //purpose  :
408 //=======================================================================
409 void GEOMAlgo_GetInPlace::FillEdgesOn()
410 {
411   Standard_Integer i, aNbE;
412   TopoDS_Iterator aIt;
413   TopTools_IndexedMapOfShape aME;
414   TopTools_MapIteratorOfMapOfShape aItMS;
415   //
416   TopExp::MapShapes(myArgument, TopAbs_EDGE, aME);
417   aNbE=aME.Extent();
418   for (i=1; i<=aNbE; ++i) {
419     const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
420     if (BRep_Tool::Degenerated(aE1)) {
421       continue;
422     }
423     //
424     aIt.Initialize(aE1);
425     for (; aIt.More(); aIt.Next()) {
426       const TopoDS_Shape& aV1=aIt.Value();
427       if (myShapesOn.IsBound(aV1)) {
428         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aV1);
429         //aNbSOn=aMSOn.Extent();
430         aItMS.Initialize(aMSOn);
431         for (; aItMS.More(); aItMS.Next()) {
432           const TopoDS_Shape& aV2=aItMS.Key();
433           FillShapesOn(aE1, aV2);
434         }
435       }
436     }
437   }
438 }
439 //=======================================================================
440 //function : PerformVE
441 //purpose  :
442 //=======================================================================
443 void GEOMAlgo_GetInPlace::PerformVE()
444 {
445   Standard_Boolean bFound;
446   //
447   myErrorStatus=0;
448   myWarningStatus=0;
449   //
450   // 2. Fill Shapes In
451   myIterator.Initialize(TopAbs_EDGE, TopAbs_VERTEX);
452   for (; myIterator.More(); myIterator.Next()) {
453     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
454     const TopoDS_Shape& aE1=aCS.Shape1();
455     const TopoDS_Shape& aV2=aCS.Shape2();
456     //
457     if (myShapesOn.IsBound(aE1)) {
458       const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
459       if (aMSOn.Contains(aV2)) {
460         continue;
461       }
462     }
463     //
464     bFound=CheckCoincidence(aE1, aV2);
465     if (myErrorStatus) {
466       return;
467     }
468     if (bFound) {
469       FillShapesIn(aE1, aV2);
470     }
471   }
472 }
473 //=======================================================================
474 //function : PerformEE
475 //purpose  :
476 //=======================================================================
477 void GEOMAlgo_GetInPlace::PerformEE()
478 {
479   Standard_Boolean bHasOn, bHasIn, bFound;
480   TopoDS_Iterator aIt;
481   TopTools_MapOfShape aMSX;
482   //
483   myErrorStatus=0;
484   myWarningStatus=0;
485   //
486   myIterator.Initialize(TopAbs_EDGE, TopAbs_EDGE);
487   for (; myIterator.More(); myIterator.Next()) {
488     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
489     const TopoDS_Shape& aE1=aCS.Shape1();
490     const TopoDS_Shape& aE2=aCS.Shape2();
491     //
492     bHasOn=myShapesOn.IsBound(aE1);
493     bHasIn=myShapesIn.IsBound(aE1);
494     const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aE1) : aMSX;
495     const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aE1) : aMSX;
496     //
497     bFound=Standard_True;
498     aIt.Initialize(aE2);
499     for (; aIt.More(); aIt.Next()) {
500       const TopoDS_Shape& aV2=aIt.Value();
501       if (!(aMSOn.Contains(aV2) || aMSIn.Contains(aV2))) {
502         bFound=!bFound;
503         break;
504       }
505     }
506     if (!bFound) {
507       continue;
508     }
509     //
510     bFound=CheckCoincidence(aE1, aE2);
511     if (myErrorStatus) {
512       return;
513     }
514     if (bFound) {
515       FillShapesIn(aE1, aE2);
516     }
517   }
518 }
519 //=======================================================================
520 //function : PerformVF
521 //purpose  :
522 //=======================================================================
523 void GEOMAlgo_GetInPlace::PerformVF()
524 {
525   Standard_Boolean bHasOn, bHasIn, bFound;
526   Standard_Integer i, aNbE;
527   TopTools_MapOfShape aMSX;
528   TopTools_IndexedMapOfShape aME;
529   //
530   myErrorStatus=0;
531   myWarningStatus=0;
532   //
533   myIterator.Initialize(TopAbs_FACE, TopAbs_VERTEX);
534   for (; myIterator.More(); myIterator.Next()) {
535     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
536     const TopoDS_Shape& aF1=aCS.Shape1();
537     const TopoDS_Shape& aV2=aCS.Shape2();
538     //
539     aME.Clear();
540     TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
541     //
542     bFound=Standard_False;
543     aNbE=aME.Extent();
544     for (i=1; i<=aNbE; ++i) {
545       const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(i));
546       if (BRep_Tool::Degenerated(aE1)) {
547         continue;
548       }
549       //
550       bHasOn=myShapesOn.IsBound(aE1);
551       bHasIn=myShapesIn.IsBound(aE1);
552       const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aE1) : aMSX;
553       const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aE1) : aMSX;
554       bFound= (aMSOn.Contains(aV2) || aMSIn.Contains(aV2));
555       if (bFound) {
556         break;
557       }
558     }
559     //
560     if (bFound) {
561       continue;
562     }
563     //
564     bFound=CheckCoincidence(aF1, aV2);
565     if (myErrorStatus) {
566       return;
567     }
568     if (bFound) {
569       FillShapesIn(aF1, aV2);
570     }
571   }
572 }
573 //=======================================================================
574 //function : FillFacesOn
575 //purpose  :
576 //=======================================================================
577 void GEOMAlgo_GetInPlace::FillFacesOn()
578 {
579   Standard_Integer i, j, aNbF, aNbE;
580   TopoDS_Iterator aIt;
581   TopTools_IndexedMapOfShape aMF, aME;
582   TopTools_MapIteratorOfMapOfShape aItMS;
583   //
584   TopExp::MapShapes(myArgument, TopAbs_FACE, aMF);
585   aNbF=aMF.Extent();
586   for (i=1; i<=aNbF; ++i) {
587     const TopoDS_Face& aF1=*((TopoDS_Face*)&aMF(i));
588     //
589     aME.Clear();
590     TopExp::MapShapes(aF1, TopAbs_EDGE, aME);
591     aNbE=aME.Extent();
592     for (j=1; j<=aNbE; ++j) {
593       const TopoDS_Edge& aE1=*((TopoDS_Edge*)&aME(j));
594       if (BRep_Tool::Degenerated(aE1)) {
595         continue;
596       }
597       //
598       if (myShapesOn.IsBound(aE1)) {
599         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aE1);
600         aItMS.Initialize(aMSOn);
601         for (; aItMS.More(); aItMS.Next()) {
602           const TopoDS_Shape& aS2=aItMS.Key();
603           FillShapesOn(aF1, aS2);
604         }
605       }
606       //
607       if (myShapesIn.IsBound(aE1)) {
608         const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aE1);
609         aItMS.Initialize(aMSIn);
610         for (; aItMS.More(); aItMS.Next()) {
611           const TopoDS_Shape& aS2=aItMS.Key();
612           FillShapesOn(aF1, aS2);
613         }
614       }
615     }//for (j=1; j<=aNbE; ++j) {
616   }//for (i=1; i<=aNbF; ++i) {
617 }
618 //=======================================================================
619 //function : PerformEF
620 //purpose  :
621 //=======================================================================
622 void GEOMAlgo_GetInPlace::PerformEF()
623 {
624   Standard_Boolean  bFound, bHasOnF, bHasInF;
625   TopoDS_Iterator aIt;
626   TopTools_MapOfShape aMSX;
627   //
628   myErrorStatus=0;
629   myWarningStatus=0;
630   //
631   myIterator.Initialize(TopAbs_FACE, TopAbs_EDGE);
632   for (; myIterator.More(); myIterator.Next()) {
633     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
634     const TopoDS_Shape& aF1=aCS.Shape1();
635     const TopoDS_Shape& aE2=aCS.Shape2();
636     //
637     // 1.
638     bHasOnF=myShapesOn.IsBound(aF1);
639     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aF1) : aMSX;
640     bFound=aMSOnF.Contains(aE2);
641     if (bFound) {
642       continue;
643     }
644     //
645     // 2.
646     bHasInF=myShapesIn.IsBound(aF1);
647     const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(aF1) : aMSX;
648     //
649     aIt.Initialize(aE2);
650     for (; aIt.More(); aIt.Next()) {
651       const TopoDS_Shape& aV2=aIt.Value();
652       bFound=(aMSOnF.Contains(aV2) || aMSInF.Contains(aV2));
653       if (!bFound) {
654         break;
655       }
656     }
657     if (!bFound) {
658       continue;
659     }
660     //------------------------------
661     bFound=CheckCoincidence(aF1, aE2);
662     if (myErrorStatus) {
663       return;
664     }
665     if (bFound) {
666       FillShapesIn(aF1, aE2);
667     }
668   }
669 }
670 //=======================================================================
671 //function : PerformFF
672 //purpose  :
673 //=======================================================================
674 void GEOMAlgo_GetInPlace::PerformFF()
675 {
676   Standard_Boolean  bFound, bHasOnF, bHasInF;
677   Standard_Integer i, aNbS2;
678   TopTools_MapOfShape aMSX;
679   TopTools_IndexedMapOfShape aMS2;
680   //
681   myErrorStatus=0;
682   myWarningStatus=0;
683   //
684   myIterator.Initialize(TopAbs_FACE, TopAbs_FACE);
685   for (; myIterator.More(); myIterator.Next()) {
686     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
687     const TopoDS_Shape& aF1=aCS.Shape1();
688     const TopoDS_Shape& aF2=aCS.Shape2();
689     //
690     bHasOnF=myShapesOn.IsBound(aF1);
691     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aF1) : aMSX;
692     //
693     bHasInF=myShapesIn.IsBound(aF1);
694     const TopTools_MapOfShape& aMSInF=(bHasInF) ? myShapesIn.Find(aF1) : aMSX;
695     //
696     aMS2.Clear();
697     MapBRepShapes(aF2, aMS2);
698     //
699     bFound=Standard_False;
700     aNbS2=aMS2.Extent();
701     for (i=1; i<=aNbS2; ++i) {
702       const TopoDS_Shape& aS2=aMS2(i);
703       if (aS2.IsSame(aF2)) {
704         continue;
705       }
706       bFound=(aMSOnF.Contains(aS2) || aMSInF.Contains(aS2));
707       if (!bFound) {
708         break;
709       }
710     }
711     if (!bFound) {
712       continue;
713     }
714     //
715     bFound=CheckCoincidence(aF1, aF2);
716     if (myErrorStatus) {
717       return;
718     }
719     if (bFound) {
720       FillShapesIn(aF1, aF2);
721     }
722   }
723 }
724 //=======================================================================
725 //function : FillSolidsOn
726 //purpose  :
727 //=======================================================================
728 void GEOMAlgo_GetInPlace::FillSolidsOn()
729 {
730   Standard_Integer i, j, aNbS, aNbF;
731   TopTools_IndexedMapOfShape aMS, aMF;
732   TopTools_MapIteratorOfMapOfShape aItMS;
733   //
734   TopExp::MapShapes(myArgument, TopAbs_SOLID, aMS);
735   //
736   aNbS=aMS.Extent();
737   for (i=1; i<=aNbS; ++i) {
738     const TopoDS_Shape& aSD1=aMS(i);
739     //
740     aMF.Clear();
741     TopExp::MapShapes(aSD1, TopAbs_FACE, aMF);
742     aNbF=aMF.Extent();
743     for (j=1; j<=aNbF; ++j) {
744       const TopoDS_Shape& aF1=aMF(j);
745       //
746       if (myShapesOn.IsBound(aF1)) {
747         const TopTools_MapOfShape& aMSOn=myShapesOn.Find(aF1);
748         aItMS.Initialize(aMSOn);
749         for (; aItMS.More(); aItMS.Next()) {
750           const TopoDS_Shape& aS2=aItMS.Key();
751           FillShapesOn(aSD1, aS2);
752         }
753       }
754       //
755       if (myShapesIn.IsBound(aF1)) {
756         const TopTools_MapOfShape& aMSIn=myShapesIn.Find(aF1);
757         aItMS.Initialize(aMSIn);
758         for (; aItMS.More(); aItMS.Next()) {
759           const TopoDS_Shape& aS2=aItMS.Key();
760           FillShapesOn(aSD1, aS2);
761         }
762       }
763     }//for (j=1; j<=aNbF; ++j) {
764   }//for (i=1; i<=aNbS; ++i) {
765 }
766 //=======================================================================
767 //function : PerformZF
768 //purpose  :
769 //=======================================================================
770 void GEOMAlgo_GetInPlace::PerformZF()
771 {
772   Standard_Boolean  bFound, bHasOnF;
773   TopTools_MapOfShape aMSX;
774   //
775   myErrorStatus=0;
776   myWarningStatus=0;
777   //
778   myIterator.Initialize(TopAbs_SOLID, TopAbs_FACE);
779   for (; myIterator.More(); myIterator.Next()) {
780     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
781     const TopoDS_Shape& aSo1=aCS.Shape1();
782     const TopoDS_Shape& aF2=aCS.Shape2();
783     //
784     bHasOnF=myShapesOn.IsBound(aSo1);
785     const TopTools_MapOfShape& aMSOnF=(bHasOnF) ? myShapesOn.Find(aSo1) : aMSX;
786     bFound=aMSOnF.Contains(aF2);
787     if (bFound) {
788       continue;
789     }
790     //------------------------------
791     bFound=CheckCoincidence(aSo1, aF2);
792     if (myErrorStatus) {
793       return;
794     }
795     if (bFound) {
796       FillShapesIn(aSo1, aF2);
797     }
798   }
799 }
800 //=======================================================================
801 //function : PerformZZ
802 //purpose  :
803 //=======================================================================
804 void GEOMAlgo_GetInPlace::PerformZZ()
805 {
806   Standard_Boolean bFound, bHasOn, bHasIn;
807   Standard_Integer i, aNbS2, iCntOn, iCntIn, iCntOut;
808   TopTools_MapOfShape aMSX;
809   TopTools_IndexedMapOfShape aMS2;
810   //
811   myErrorStatus=0;
812   myWarningStatus=0;
813   //
814   myIterator.Initialize(TopAbs_SOLID, TopAbs_SOLID);
815   for (; myIterator.More(); myIterator.Next()) {
816     const NMTTools_CoupleOfShape& aCS=myIterator.Value();
817     const TopoDS_Shape& aSo1=aCS.Shape1();
818     const TopoDS_Shape& aSo2=aCS.Shape2();
819     //
820     bHasOn=myShapesOn.IsBound(aSo1);
821     const TopTools_MapOfShape& aMSOn=(bHasOn) ? myShapesOn.Find(aSo1) : aMSX;
822     //
823     bHasIn=myShapesIn.IsBound(aSo1);
824     const TopTools_MapOfShape& aMSIn=(bHasIn) ? myShapesIn.Find(aSo1) : aMSX;
825     //
826     aMS2.Clear();
827     TopExp::MapShapes(aSo2, TopAbs_FACE, aMS2);
828     //
829     iCntIn=0;
830     iCntOn=0;
831     iCntOut=0;
832     bFound=Standard_False;
833     aNbS2=aMS2.Extent();
834     for (i=1; i<=aNbS2; ++i) {
835       const TopoDS_Shape& aF2=aMS2(i);
836       //
837       if (aMSIn.Contains(aF2)) {
838         ++iCntIn;
839         bFound=Standard_True;
840         break;
841       }
842       else if (!aMSOn.Contains(aF2)) {
843         ++iCntOut;
844         bFound=Standard_False;// out
845         break;
846       }
847       else {
848         ++iCntOn; //on
849       }
850     }
851     //
852     if (!bFound && iCntOut) {
853       continue;
854     }
855     //
856     if (!iCntIn) {
857       bFound=CheckCoincidence(aSo1, aSo2);
858       if (myErrorStatus) {
859         return;
860       }
861     }
862     if (bFound) {
863       FillShapesIn(aSo1, aSo2);
864     }
865   }// for (; myIterator.More(); myIterator.Next()) {
866 }
867 //=======================================================================
868 //function : FillImages
869 //purpose  :
870 //=======================================================================
871 void GEOMAlgo_GetInPlace::FillImages()
872 {
873   Standard_Integer i, aNbS, aNbSx, aNbSi;
874   TopAbs_ShapeEnum aType;
875   TopoDS_Iterator aIt;
876   TopTools_ListOfShape aLSx;
877   TopTools_ListIteratorOfListOfShape aItLS;
878   TopTools_IndexedMapOfShape aMS;
879   TopTools_MapIteratorOfMapOfShape aItMS;
880   //
881   myErrorStatus=0;
882   myWarningStatus=0;
883   //
884   myImages.Clear();
885   //
886   // 1. Vertices
887   aMS.Clear();
888   TopExp::MapShapes(myArgument, TopAbs_VERTEX, aMS);
889   aNbS=aMS.Extent();
890   for (i=1; i<=aNbS; ++i) {
891     const TopoDS_Shape& aV=aMS(i);
892     if (myShapesOn.IsBound(aV)) {
893       const TopTools_MapOfShape& aMSx=myShapesOn.Find(aV);
894       aNbSx=aMSx.Extent();
895       //
896       aLSx.Clear();
897       aItMS.Initialize(aMSx);
898       for (; aItMS.More(); aItMS.Next()) {
899         const TopoDS_Shape& aVx=aItMS.Key();
900         aLSx.Append(aVx);
901       }
902       //
903       myImages.Bind(aV, aLSx);
904     }
905   }
906   //
907   // 2. Edges
908   aMS.Clear();
909   TopExp::MapShapes(myArgument, TopAbs_EDGE, aMS);
910   aNbS=aMS.Extent();
911   for (i=1; i<=aNbS; ++i) {
912     const TopoDS_Shape& aE=aMS(i);
913     if (myShapesIn.IsBound(aE)) {
914       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aE);
915       aNbSx=aMSx.Extent();
916       //
917       aLSx.Clear();
918       aItMS.Initialize(aMSx);
919       for (; aItMS.More(); aItMS.Next()) {
920         const TopoDS_Shape& aEx=aItMS.Key();
921         aType=aEx.ShapeType();
922         if (aType==TopAbs_EDGE){
923           aLSx.Append(aEx);
924         }
925       }
926       //
927       myImages.Bind(aE, aLSx);
928     }
929   }
930   //
931   // 3. Wires
932   aMS.Clear();
933   TopExp::MapShapes(myArgument, TopAbs_WIRE, aMS);
934   aNbS=aMS.Extent();
935   for (i=1; i<=aNbS; ++i) {
936     const TopoDS_Shape& aW=aMS(i);
937     aLSx.Clear();
938     aIt.Initialize(aW);
939     for(; aIt.More(); aIt.Next()) {
940       const TopoDS_Shape& aE=aIt.Value();
941       if (myImages.IsBound(aE)) {
942         const TopTools_ListOfShape& aLSi=myImages.Find(aE);
943         aNbSi=aLSi.Extent();
944         //
945         aItLS.Initialize(aLSi);
946         for (; aItLS.More(); aItLS.Next()) {
947           const TopoDS_Shape& aEi=aItLS.Value();
948           aLSx.Append(aEi);
949         }
950       }
951     }
952     myImages.Bind(aW, aLSx);
953   }
954   //
955   // 4. Faces
956   aMS.Clear();
957   TopExp::MapShapes(myArgument, TopAbs_FACE, aMS);
958   aNbS=aMS.Extent();
959   for (i=1; i<=aNbS; ++i) {
960     const TopoDS_Shape& aF=aMS(i);
961     if (myShapesIn.IsBound(aF)) {
962       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aF);
963       aNbSx=aMSx.Extent();
964       //
965       aLSx.Clear();
966       aItMS.Initialize(aMSx);
967       for (; aItMS.More(); aItMS.Next()) {
968         const TopoDS_Shape& aFx=aItMS.Key();
969         aType=aFx.ShapeType();
970         if (aType==TopAbs_FACE){
971           aLSx.Append(aFx);
972         }
973       }
974       //
975       myImages.Bind(aF, aLSx);
976     }
977   }
978   //
979   // 5. Shells
980   aMS.Clear();
981   TopExp::MapShapes(myArgument, TopAbs_SHELL, aMS);
982   aNbS=aMS.Extent();
983   for (i=1; i<=aNbS; ++i) {
984     const TopoDS_Shape& aSh=aMS(i);
985     aLSx.Clear();
986     aIt.Initialize(aSh);
987     for(; aIt.More(); aIt.Next()) {
988       const TopoDS_Shape& aF=aIt.Value();
989       if (myImages.IsBound(aF)) {
990         const TopTools_ListOfShape& aLSi=myImages.Find(aF);
991         aNbSi=aLSi.Extent();
992         //
993         aItLS.Initialize(aLSi);
994         for (; aItLS.More(); aItLS.Next()) {
995           const TopoDS_Shape& aFi=aItLS.Value();
996           aLSx.Append(aFi);
997         }
998       }
999     }
1000     myImages.Bind(aSh, aLSx);
1001   }
1002   //
1003   // 6. Solids
1004   aMS.Clear();
1005   TopExp::MapShapes(myArgument, TopAbs_SOLID, aMS);
1006   aNbS=aMS.Extent();
1007   for (i=1; i<=aNbS; ++i) {
1008     const TopoDS_Shape& aZ=aMS(i);
1009     if (myShapesIn.IsBound(aZ)) {
1010       const TopTools_MapOfShape& aMSx=myShapesIn.Find(aZ);
1011       aNbSx=aMSx.Extent();
1012       //
1013       aLSx.Clear();
1014       aItMS.Initialize(aMSx);
1015       for (; aItMS.More(); aItMS.Next()) {
1016         const TopoDS_Shape& aZx=aItMS.Key();
1017         aType=aZx.ShapeType();
1018         if (aType==TopAbs_SOLID){
1019           aLSx.Append(aZx);
1020         }
1021       }
1022       //
1023       myImages.Bind(aZ, aLSx);
1024     }
1025   }
1026   //
1027   // 7. CompSolids
1028   aMS.Clear();
1029   TopExp::MapShapes(myArgument, TopAbs_COMPSOLID, aMS);
1030   aNbS=aMS.Extent();
1031   for (i=1; i<=aNbS; ++i) {
1032     const TopoDS_Shape& aCs=aMS(i);
1033     aLSx.Clear();
1034     aIt.Initialize(aCs);
1035     for(; aIt.More(); aIt.Next()) {
1036       const TopoDS_Shape& aZ=aIt.Value();
1037       if (myImages.IsBound(aZ)) {
1038         const TopTools_ListOfShape& aLSi=myImages.Find(aZ);
1039         aNbSi=aLSi.Extent();
1040         //
1041         aItLS.Initialize(aLSi);
1042         for (; aItLS.More(); aItLS.Next()) {
1043           const TopoDS_Shape& aZi=aItLS.Value();
1044           aLSx.Append(aZi);
1045         }
1046       }
1047     }
1048     myImages.Bind(aCs, aLSx);
1049   }
1050   //
1051   // 8. Compounds
1052   aType=myArgument.ShapeType();
1053   if (aType==TopAbs_COMPOUND) {
1054     FillImagesCompound(myArgument);
1055   }
1056 }
1057 //=======================================================================
1058 //function : FillImagesCompound
1059 //purpose  :
1060 //=======================================================================
1061 void GEOMAlgo_GetInPlace::FillImagesCompound(const TopoDS_Shape& aS)
1062 {
1063   TopAbs_ShapeEnum aType;
1064   TopoDS_Iterator aIt;
1065   TopTools_ListOfShape aLSx;
1066   TopTools_ListIteratorOfListOfShape aItLS;
1067   //
1068   aIt.Initialize(aS);
1069   for(; aIt.More(); aIt.Next()) {
1070     const TopoDS_Shape& aSx=aIt.Value();
1071     aType=aSx.ShapeType();
1072     //
1073     if (aType==TopAbs_COMPOUND) {
1074       FillImagesCompound(aSx);
1075     }
1076     //
1077     if (myImages.IsBound(aSx)) {
1078       const TopTools_ListOfShape& aLSi=myImages.Find(aSx);
1079       aItLS.Initialize(aLSi);
1080       for (; aItLS.More(); aItLS.Next()) {
1081         const TopoDS_Shape& aSi=aItLS.Value();
1082         aLSx.Append(aSi);
1083       }
1084     }
1085   }
1086   myImages.Bind(aS, aLSx);
1087 }
1088
1089 //=======================================================================
1090 //function : FillShapesIn
1091 //purpose  :
1092 //=======================================================================
1093 void GEOMAlgo_GetInPlace::FillShapesIn(const TopoDS_Shape& aS1,
1094                                        const TopoDS_Shape& aS2)
1095 {
1096   if (myShapesIn.IsBound(aS1)) {
1097     TopTools_MapOfShape& aMS=myShapesIn.ChangeFind(aS1);
1098     aMS.Add(aS2);
1099   }
1100   else {
1101     TopTools_MapOfShape aMS;
1102     //
1103     aMS.Add(aS2);
1104     myShapesIn.Bind(aS1, aMS);
1105   }
1106 }
1107 //=======================================================================
1108 //function : FillShapesOn
1109 //purpose  :
1110 //=======================================================================
1111 void GEOMAlgo_GetInPlace::FillShapesOn(const TopoDS_Shape& aS1,
1112                                        const TopoDS_Shape& aS2)
1113 {
1114   if (myShapesOn.IsBound(aS1)) {
1115     TopTools_MapOfShape& aMS=myShapesOn.ChangeFind(aS1);
1116     aMS.Add(aS2);
1117   }
1118   else {
1119     TopTools_MapOfShape aMS;
1120     //
1121     aMS.Add(aS2);
1122     myShapesOn.Bind(aS1, aMS);
1123   }
1124 }
1125 //=======================================================================
1126 //function : MapBRepShapes
1127 //purpose  :
1128 //=======================================================================
1129 void MapBRepShapes(const TopoDS_Shape& aS,
1130                    TopTools_IndexedMapOfShape& aM)
1131 {
1132   Standard_Boolean bDegenerated;
1133   TopAbs_ShapeEnum aType;
1134   TopoDS_Iterator aIt;
1135   //
1136   aType=aS.ShapeType();
1137   if (aType==TopAbs_VERTEX || aType==TopAbs_EDGE ||
1138       aType==TopAbs_FACE   || aType==TopAbs_SOLID) {
1139     bDegenerated=Standard_False;
1140     if (aType==TopAbs_EDGE) {
1141       TopoDS_Edge *pE=(TopoDS_Edge*)&aS;
1142       bDegenerated=BRep_Tool::Degenerated(*pE);
1143     }
1144     if (!bDegenerated) {
1145       aM.Add(aS);
1146     }
1147   }
1148   //
1149   aIt.Initialize(aS);
1150   for(; aIt.More(); aIt.Next()) {
1151     const TopoDS_Shape& aSx=aIt.Value();
1152     aType=aSx.ShapeType();
1153     MapBRepShapes(aSx, aM);
1154   }
1155 }