1 // Copyright (C) 2007-2011 CEA/DEN, EDF R&D, 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.
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
22 // 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 <NMTTools_CoupleOfShape.hxx>
48 #include <NMTTools_ListOfCoupleOfShape.hxx>
49 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
50 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
51 #include <NMTTools_Tools.hxx>
53 #include <GEOMAlgo_GlueDetector.hxx>
57 void MapShapes1(const TopoDS_Shape& aS,
58 const TopAbs_ShapeEnum aType,
59 TopTools_IndexedMapOfShape& aM);
61 //=======================================================================
64 //=======================================================================
65 void GEOMAlgo_Gluer2::Detect()
67 Standard_Boolean bCheckGeometry;
68 Standard_Integer iErr, aNbSD;
69 TopTools_ListIteratorOfListOfShape aItLS;
70 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
71 GEOMAlgo_GlueDetector aDetector;
76 myImagesDetected.Clear();
77 myOriginsDetected.Clear();
79 bCheckGeometry=Standard_True;
80 aDetector.SetArgument(myArgument);
81 aDetector.SetTolerance(myTolerance);
82 aDetector.SetCheckGeometry(bCheckGeometry);
85 iErr=aDetector.ErrorStatus();
87 myErrorStatus=11;// Detector failed
91 const TopTools_DataMapOfShapeListOfShape& aImages=aDetector.Images();
92 aItDMSLS.Initialize(aImages);
93 for (; aItDMSLS.More(); aItDMSLS.Next()) {
94 const TopoDS_Shape& aSkey=aItDMSLS.Key();
95 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
97 myImagesDetected.Bind(aSkey, aLSD);
100 aItDMSLS.Initialize(myImagesDetected);
101 for (; aItDMSLS.More(); aItDMSLS.Next()) {
102 const TopoDS_Shape& aSkey=aItDMSLS.Key();
103 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
104 aItLS.Initialize(aLSD);
105 for (; aItLS.More(); aItLS.Next()) {
106 const TopoDS_Shape& aSx=aItLS.Value();
107 myOriginsDetected.Bind(aSx, aSkey);
111 //=======================================================================
112 //function : PerformShapesToWork
114 //=======================================================================
115 void GEOMAlgo_Gluer2::PerformShapesToWork()
117 Standard_Integer aNbSG, i, j, aNbC, aNb, aNbSD;
118 TopTools_ListIteratorOfListOfShape aItLS1, aItLS2;
119 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
120 NMTTools_CoupleOfShape aCS;
121 NMTTools_ListOfCoupleOfShape aLCS;
122 NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
127 myImagesToWork.Clear();
128 myOriginsToWork.Clear();
130 aNbSD=myImagesDetected.Extent();
131 if (!aNbSD) {// no shapes to glue detected
136 aNbSG=myShapesToGlue.Extent();
139 myImagesToWork=myImagesDetected;
141 aItDMSLS.Initialize(myImagesToWork);
142 for (; aItDMSLS.More(); aItDMSLS.Next()) {
143 const TopoDS_Shape& aSkey=aItDMSLS.Key();
144 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
145 aItLS1.Initialize(aLSD);
146 for (; aItLS1.More(); aItLS1.Next()) {
147 const TopoDS_Shape& aSx=aItLS1.Value();
148 myOriginsToWork.Bind(aSx, aSkey);
155 aItDMSLS.Initialize(myShapesToGlue);
156 for (; aItDMSLS.More(); aItDMSLS.Next()) {
157 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
158 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
159 aItLS1.Initialize(aLSG);
160 for (i=0; aItLS1.More(); aItLS1.Next(), ++i) {
161 aItLS2.Initialize(aLSG);
162 for (j=0; aItLS2.More(); aItLS2.Next(), ++j) {
164 const TopoDS_Shape& aSG1=aItLS1.Value();
165 const TopoDS_Shape& aSG2=aItLS2.Value();
168 TreatPair(aCS, aLCS);
175 TopTools_ListOfShape aLSX;
176 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
178 NMTTools_Tools::FindChains(aLCS, aMC);
180 // 3. myImagesToWork, myOriginsToWork
182 for (i=1; i<=aNbC; ++i) {
183 const TopoDS_Shape& aSkey=aMC.FindKey(i);
184 const TopTools_IndexedMapOfShape& aM=aMC(i);
187 for (j=1; j<=aNb; ++j) {
188 const TopoDS_Shape& aS=aM(j);
190 myOriginsToWork.Bind(aS, aSkey);
192 myImagesToWork.Bind(aSkey, aLSX);
195 //=======================================================================
196 //function : TreatPair
198 //=======================================================================
199 void GEOMAlgo_Gluer2::TreatPair(const NMTTools_CoupleOfShape& aCS,
200 NMTTools_ListOfCoupleOfShape& aLCS)
206 Standard_Integer i, aNbS1, aNbS2, aNbS;
207 TopAbs_ShapeEnum aType, aTypeS;
208 TopTools_ListIteratorOfListOfShape aItLS;
209 TopTools_IndexedMapOfShape aMS1, aMS2;
210 TopTools_DataMapOfShapeListOfShape aDMSLS;
211 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
212 NMTTools_CoupleOfShape aCSS;
214 // 1. Checking the pair on whether it can be glued at all
216 const TopoDS_Shape& aS1=aCS.Shape1();
217 if (!myOriginsDetected.IsBound(aS1)) {
221 const TopoDS_Shape& aSkey1=myOriginsDetected.Find(aS1);
223 const TopoDS_Shape& aS2=aCS.Shape2();
224 if (!myOriginsDetected.IsBound(aS2)) {
228 const TopoDS_Shape& aSkey2=myOriginsDetected.Find(aS2);
230 if (!aSkey1.IsSame(aSkey2)) {
235 // 2. Append the pair to the aLCS
238 // 3. Treatment the subshapes of the pair
239 aType=aS1.ShapeType();
240 if (aType==TopAbs_VERTEX) {
245 aTypeS=TopAbs_VERTEX;
248 MapShapes1(aS1, aTypeS, aMS1);
249 MapShapes1(aS2, aTypeS, aMS2);
259 for (i=1; i<=aNbS1; ++i) {
260 const TopoDS_Shape& aSS1=aMS1(i);
261 if (aMS2.Contains(aSS1)) {
265 if (!myOriginsDetected.IsBound(aSS1)) {
270 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS1);
271 if (aDMSLS.IsBound(aSkey)) {
272 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
276 TopTools_ListOfShape aLS;
279 aDMSLS.Bind(aSkey, aLS);
284 for (i=1; i<=aNbS2; ++i) {
285 const TopoDS_Shape& aSS2=aMS2(i);
286 if (aMS1.Contains(aSS2)) {
290 if (!myOriginsDetected.IsBound(aSS2)) {
295 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS2);
296 if (aDMSLS.IsBound(aSkey)) {
297 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
301 TopTools_ListOfShape aLS;
304 aDMSLS.Bind(aSkey, aLS);
309 aItDMSLS.Initialize(aDMSLS);
310 for (; aItDMSLS.More(); aItDMSLS.Next()) {
311 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
312 const TopTools_ListOfShape& aLS=aItDMSLS.Value();
319 const TopoDS_Shape& aSS1=aLS.First();
320 const TopoDS_Shape& aSS2=aLS.Last();
321 aCSS.SetShape1(aSS1);
322 aCSS.SetShape2(aSS2);
323 TreatPair(aCSS, aLCS);
326 //=======================================================================
327 //function : MapShapes1
329 //=======================================================================
330 void MapShapes1(const TopoDS_Shape& aS,
331 const TopAbs_ShapeEnum aType,
332 TopTools_IndexedMapOfShape& aM)
334 TopExp_Explorer aExp;
336 aExp.Init (aS, aType);
337 for ( ;aExp.More(); aExp.Next()) {
338 const TopoDS_Shape aSx=aExp.Current();
339 if (aType==TopAbs_EDGE) {
340 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
341 if (BRep_Tool::Degenerated(aEx)) {
349 //=======================================================================
350 //function : MapShapes1
352 //=======================================================================
353 void MapShapes1(const TopoDS_Shape& aS,
354 const TopAbs_ShapeEnum aType,
355 TopTools_IndexedMapOfShape& aM)
357 TopExp_Explorer aExp (aS, aType);
358 while (aExp.More()) {
359 const TopoDS_Shape aSx=aExp.Current();
360 if (aType==TopAbs_EDGE) {
361 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
362 if (BRep_Tool::Degenerated(aEx)) {