Salome HOME
c95cc8034d3a338a12ff4ffcbab424853d528ac2
[modules/geom.git] / src / GEOMAlgo / GEOMAlgo_AlgoTools_1.cxx
1 // Copyright (C) 2007-2023  CEA, EDF, 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, or (at your option) any later version.
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_AlgoTools_2.cxx
23 //  Created :
24 //  Author  : Peter KURNEV
25
26 #include <GEOMAlgo_AlgoTools.hxx>
27
28 #include <GEOMAlgo_ListOfCoupleOfShapes.hxx>
29 #include <GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
30 #include <TopTools_IndexedMapOfShape.hxx>
31 #include <GEOMAlgo_CoupleOfShapes.hxx>
32 #include <TopoDS_Shape.hxx>
33 #include <TopTools_IndexedMapOfShape.hxx>
34
35
36
37 static
38   void ProcessBlock(const TopoDS_Shape& aF,
39                     const GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
40                     TopTools_IndexedMapOfShape& aProcessed,
41                     TopTools_IndexedMapOfShape& aChain);
42
43 //=======================================================================
44 // function: FindChains
45 // purpose :
46 //=======================================================================
47 void GEOMAlgo_AlgoTools::FindChains(const GEOMAlgo_ListOfCoupleOfShapes& aLCS,
48                                     GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
49 {
50   GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
51   GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape aMCV;
52   //
53   aItCS.Initialize(aLCS);
54   for (; aItCS.More(); aItCS.Next()) {
55     const GEOMAlgo_CoupleOfShapes& aCS=aItCS.Value();
56     //
57     const TopoDS_Shape& aF1=aCS.Shape1();
58     const TopoDS_Shape& aF2=aCS.Shape2();
59     //
60     //
61     if (aMCV.Contains(aF1)) {
62       TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF1);
63       aMV.Add(aF1);
64       aMV.Add(aF2);
65     }
66     else {
67       TopTools_IndexedMapOfShape aMV;
68       aMV.Add(aF1);
69       aMV.Add(aF2);
70       aMCV.Add(aF1, aMV);
71     }
72     //
73     if (aMCV.Contains(aF2)) {
74       TopTools_IndexedMapOfShape& aMV=aMCV.ChangeFromKey(aF2);
75       aMV.Add(aF1);
76       aMV.Add(aF2);
77     }
78     else {
79       TopTools_IndexedMapOfShape aMV;
80       aMV.Add(aF1);
81       aMV.Add(aF2);
82       aMCV.Add(aF2, aMV);
83     }
84   }
85   GEOMAlgo_AlgoTools::FindChains(aMCV, aMapChains);
86 }
87 //=======================================================================
88 // function: FindChains
89 // purpose :
90 //=======================================================================
91 void GEOMAlgo_AlgoTools::FindChains(const GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
92                                     GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape& aMapChains)
93 {
94   Standard_Integer  i, j, aNbCV, aNbV;
95   TopTools_IndexedMapOfShape aProcessed, aChain;
96   //
97   aNbCV=aMCV.Extent();
98   for (i=1; i<=aNbCV; ++i) {
99     const TopoDS_Shape& aF=aMCV.FindKey(i);
100     if (aProcessed.Contains(aF)) {
101       continue;
102     }
103     //
104     aProcessed.Add(aF);
105     aChain.Add(aF);
106     //
107     const TopTools_IndexedMapOfShape& aMV=aMCV(i);
108     aNbV=aMV.Extent();
109     for (j=1; j<=aNbV; ++j) {
110       const TopoDS_Shape& aFx=aMV(j);
111       ProcessBlock(aFx, aMCV, aProcessed, aChain);
112     }
113     aMapChains.Add(aF, aChain);
114     aChain.Clear();
115   }
116 }
117 //=======================================================================
118 // function: ProcessBlock
119 // purpose:
120 //=======================================================================
121 void ProcessBlock(const TopoDS_Shape& aF,
122                   const GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape& aMCV,
123                   TopTools_IndexedMapOfShape& aProcessed,
124                   TopTools_IndexedMapOfShape& aChain)
125 {
126   Standard_Integer j, aNbV;
127   //
128   if (aProcessed.Contains(aF)) {
129     return;
130   }
131   aProcessed.Add(aF);
132   aChain.Add(aF);
133   //
134   const TopTools_IndexedMapOfShape& aMV=aMCV.FindFromKey(aF);
135   aNbV=aMV.Extent();
136   for (j=1; j<=aNbV; ++j) {
137     const TopoDS_Shape& aFx=aMV(j);
138     ProcessBlock(aFx, aMCV, aProcessed, aChain);
139   }
140 }
141