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