1 // Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // File: GEOMAlgo_Gluer2_3.cxx
24 // Author: Peter KURNEV
26 #include <GEOMAlgo_Gluer2.hxx>
28 #include <TopAbs_ShapeEnum.hxx>
30 #include <TopoDS_Shape.hxx>
31 #include <TopoDS_Edge.hxx>
33 #include <BRep_Tool.hxx>
36 #include <TopExp_Explorer.hxx>
38 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
39 #include <TopTools_DataMapOfShapeListOfShape.hxx>
40 #include <TopTools_ListOfShape.hxx>
41 #include <TopTools_MapOfShape.hxx>
42 #include <TopTools_MapIteratorOfMapOfShape.hxx>
43 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
44 #include <TopTools_ListIteratorOfListOfShape.hxx>
45 #include <TopTools_IndexedMapOfShape.hxx>
47 #include <GEOMAlgo_CoupleOfShapes.hxx>
48 #include <GEOMAlgo_ListOfCoupleOfShapes.hxx>
49 #include <GEOMAlgo_ListIteratorOfListOfCoupleOfShapes.hxx>
51 #include <GEOMAlgo_AlgoTools.hxx>
52 #include <GEOMAlgo_GlueDetector.hxx>
53 #include <GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
56 static void MapShapes1(const TopoDS_Shape& aS,
57 const TopAbs_ShapeEnum aType,
58 TopTools_IndexedMapOfShape& aM);
61 //=======================================================================
64 //=======================================================================
65 void GEOMAlgo_Gluer2::Detect()
67 Standard_Boolean bCheckGeometry;
68 Standard_Integer iErr;
69 TopTools_ListIteratorOfListOfShape aItLS;
70 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
75 myImagesDetected.Clear();
76 myOriginsDetected.Clear();
78 bCheckGeometry=Standard_True;
80 //modified by NIZNHY-PKV Tue Mar 13 13:33:35 2012f
82 myDetector.SetContext(myContext);
83 //modified by NIZNHY-PKV Tue Mar 13 13:33:38 2012t
84 myDetector.SetArgument(myArgument);
85 myDetector.SetTolerance(myTolerance);
86 myDetector.SetCheckGeometry(bCheckGeometry);
89 iErr=myDetector.ErrorStatus();
95 //modified by NIZNHY-PKV Tue Mar 13 13:40:36 2012f
96 iErr=myDetector.WarningStatus();
98 // Sticked shapes are detected
101 //modified by NIZNHY-PKV Tue Mar 13 13:40:39 2012t
103 const TopTools_DataMapOfShapeListOfShape& aImages=myDetector.Images();
104 aItDMSLS.Initialize(aImages);
105 for (; aItDMSLS.More(); aItDMSLS.Next()) {
106 const TopoDS_Shape& aSkey=aItDMSLS.Key();
107 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
108 myImagesDetected.Bind(aSkey, aLSD);
111 aItDMSLS.Initialize(myImagesDetected);
112 for (; aItDMSLS.More(); aItDMSLS.Next()) {
113 const TopoDS_Shape& aSkey=aItDMSLS.Key();
114 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
115 aItLS.Initialize(aLSD);
116 for (; aItLS.More(); aItLS.Next()) {
117 const TopoDS_Shape& aSx=aItLS.Value();
118 myOriginsDetected.Bind(aSx, aSkey);
123 //=======================================================================
124 //function : PerformShapesToWork
126 //=======================================================================
127 void GEOMAlgo_Gluer2::PerformShapesToWork()
129 Standard_Integer aNbSG, i, j, k, aNbC, aNb, aNbSD;
130 TopTools_ListIteratorOfListOfShape aItLS1, aItLS2;
131 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
132 GEOMAlgo_CoupleOfShapes aCS;
133 GEOMAlgo_ListOfCoupleOfShapes aLCS;
134 GEOMAlgo_ListIteratorOfListOfCoupleOfShapes aItCS;
139 myImagesToWork.Clear();
140 myOriginsToWork.Clear();
142 aNbSD=myImagesDetected.Extent();
143 if (!aNbSD) {// no shapes to glue detected
148 aNbSG=myShapesToGlue.Extent();
151 myImagesToWork=myImagesDetected;
153 aItDMSLS.Initialize(myImagesToWork);
154 for (; aItDMSLS.More(); aItDMSLS.Next()) {
155 const TopoDS_Shape& aSkey=aItDMSLS.Key();
156 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
157 aItLS1.Initialize(aLSD);
158 for (; aItLS1.More(); aItLS1.Next()) {
159 const TopoDS_Shape& aSx=aItLS1.Value();
160 myOriginsToWork.Bind(aSx, aSkey);
167 aItDMSLS.Initialize(myShapesToGlue);
168 for (k=0; aItDMSLS.More(); aItDMSLS.Next(), ++k) {
169 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
170 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
171 aItLS1.Initialize(aLSG);
172 for (i=0; aItLS1.More(); aItLS1.Next(), ++i) {
173 aItLS2.Initialize(aLSG);
174 for (j=0; aItLS2.More(); aItLS2.Next(), ++j) {
176 const TopoDS_Shape& aSG1=aItLS1.Value();
177 const TopoDS_Shape& aSG2=aItLS2.Value();
180 TreatPair(aCS, aLCS);
187 TopTools_ListOfShape aLSX;
188 GEOMAlgo_IndexedDataMapOfShapeIndexedMapOfShape aMC;
190 GEOMAlgo_AlgoTools::FindChains(aLCS, aMC);
192 // 3. myImagesToWork, myOriginsToWork
194 for (i=1; i<=aNbC; ++i) {
195 const TopoDS_Shape& aSkey=aMC.FindKey(i);
196 const TopTools_IndexedMapOfShape& aM=aMC(i);
199 for (j=1; j<=aNb; ++j) {
200 const TopoDS_Shape& aS=aM(j);
202 myOriginsToWork.Bind(aS, aSkey);
204 myImagesToWork.Bind(aSkey, aLSX);
208 //=======================================================================
209 //function : TreatPair
211 //=======================================================================
212 void GEOMAlgo_Gluer2::TreatPair(const GEOMAlgo_CoupleOfShapes& aCS,
213 GEOMAlgo_ListOfCoupleOfShapes& aLCS)
219 Standard_Integer i, aNbS1, aNbS2, aNbS;
220 TopAbs_ShapeEnum aType, aTypeS;
221 TopTools_ListIteratorOfListOfShape aItLS;
222 TopTools_IndexedMapOfShape aMS1, aMS2;
223 TopTools_DataMapOfShapeListOfShape aDMSLS;
224 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
225 GEOMAlgo_CoupleOfShapes aCSS;
227 // 1. Checking the pair on whether it can be glued at all
229 const TopoDS_Shape& aS1=aCS.Shape1();
230 if (!myOriginsDetected.IsBound(aS1)) {
234 const TopoDS_Shape& aSkey1=myOriginsDetected.Find(aS1);
236 const TopoDS_Shape& aS2=aCS.Shape2();
237 if (!myOriginsDetected.IsBound(aS2)) {
241 const TopoDS_Shape& aSkey2=myOriginsDetected.Find(aS2);
243 if (!aSkey1.IsSame(aSkey2)) {
248 // 2. Append the pair to the aLCS
251 // 3. Treatment the sub-shapes of the pair
252 aType=aS1.ShapeType();
253 if (aType==TopAbs_VERTEX) {
258 aTypeS=TopAbs_VERTEX;
261 MapShapes1(aS1, aTypeS, aMS1);
262 MapShapes1(aS2, aTypeS, aMS2);
272 for (i=1; i<=aNbS1; ++i) {
273 const TopoDS_Shape& aSS1=aMS1(i);
274 if (aMS2.Contains(aSS1)) {
278 if (!myOriginsDetected.IsBound(aSS1)) {
283 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS1);
284 if (aDMSLS.IsBound(aSkey)) {
285 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
289 TopTools_ListOfShape aLS;
292 aDMSLS.Bind(aSkey, aLS);
297 for (i=1; i<=aNbS2; ++i) {
298 const TopoDS_Shape& aSS2=aMS2(i);
299 if (aMS1.Contains(aSS2)) {
303 if (!myOriginsDetected.IsBound(aSS2)) {
308 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS2);
309 if (aDMSLS.IsBound(aSkey)) {
310 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
314 TopTools_ListOfShape aLS;
317 aDMSLS.Bind(aSkey, aLS);
322 aItDMSLS.Initialize(aDMSLS);
323 for (; aItDMSLS.More(); aItDMSLS.Next()) {
324 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
325 const TopTools_ListOfShape& aLS=aItDMSLS.Value();
332 const TopoDS_Shape& aSS1=aLS.First();
333 const TopoDS_Shape& aSS2=aLS.Last();
334 aCSS.SetShape1(aSS1);
335 aCSS.SetShape2(aSS2);
336 TreatPair(aCSS, aLCS);
340 //=======================================================================
341 //function : MapShapes1
343 //=======================================================================
344 void MapShapes1(const TopoDS_Shape& aS,
345 const TopAbs_ShapeEnum aType,
346 TopTools_IndexedMapOfShape& aM)
348 TopExp_Explorer aExp;
350 aExp.Init (aS, aType);
351 for ( ;aExp.More(); aExp.Next()) {
352 const TopoDS_Shape aSx=aExp.Current();
353 if (aType==TopAbs_EDGE) {
354 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
355 if (BRep_Tool::Degenerated(aEx)) {