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
23 // Author: Peter KURNEV
25 #include <GEOMAlgo_Gluer2.hxx>
27 #include <TopAbs_ShapeEnum.hxx>
29 #include <TopoDS_Shape.hxx>
30 #include <TopoDS_Edge.hxx>
32 #include <BRep_Tool.hxx>
35 #include <TopExp_Explorer.hxx>
37 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
38 #include <TopTools_DataMapOfShapeListOfShape.hxx>
39 #include <TopTools_ListOfShape.hxx>
40 #include <TopTools_MapOfShape.hxx>
41 #include <TopTools_MapIteratorOfMapOfShape.hxx>
42 #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
43 #include <TopTools_ListIteratorOfListOfShape.hxx>
44 #include <TopTools_IndexedMapOfShape.hxx>
46 #include <NMTTools_CoupleOfShape.hxx>
47 #include <NMTTools_ListOfCoupleOfShape.hxx>
48 #include <NMTTools_ListIteratorOfListOfCoupleOfShape.hxx>
49 #include <NMTTools_IndexedDataMapOfShapeIndexedMapOfShape.hxx>
50 #include <NMTTools_Tools.hxx>
52 #include <GEOMAlgo_GlueDetector.hxx>
56 void MapShapes1(const TopoDS_Shape& aS,
57 const TopAbs_ShapeEnum aType,
58 TopTools_IndexedMapOfShape& aM);
60 //=======================================================================
63 //=======================================================================
64 void GEOMAlgo_Gluer2::Detect()
66 Standard_Boolean bCheckGeometry;
67 Standard_Integer iErr, aNbSD;
68 TopTools_ListIteratorOfListOfShape aItLS;
69 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
70 //GEOMAlgo_GlueDetector aDetector;
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();
109 myImagesDetected.Bind(aSkey, aLSD);
112 aItDMSLS.Initialize(myImagesDetected);
113 for (; aItDMSLS.More(); aItDMSLS.Next()) {
114 const TopoDS_Shape& aSkey=aItDMSLS.Key();
115 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
116 aItLS.Initialize(aLSD);
117 for (; aItLS.More(); aItLS.Next()) {
118 const TopoDS_Shape& aSx=aItLS.Value();
119 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 NMTTools_CoupleOfShape aCS;
133 NMTTools_ListOfCoupleOfShape aLCS;
134 NMTTools_ListIteratorOfListOfCoupleOfShape 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 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
190 NMTTools_Tools::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);
207 //=======================================================================
208 //function : TreatPair
210 //=======================================================================
211 void GEOMAlgo_Gluer2::TreatPair(const NMTTools_CoupleOfShape& aCS,
212 NMTTools_ListOfCoupleOfShape& aLCS)
218 Standard_Integer i, aNbS1, aNbS2, aNbS;
219 TopAbs_ShapeEnum aType, aTypeS;
220 TopTools_ListIteratorOfListOfShape aItLS;
221 TopTools_IndexedMapOfShape aMS1, aMS2;
222 TopTools_DataMapOfShapeListOfShape aDMSLS;
223 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
224 NMTTools_CoupleOfShape aCSS;
226 // 1. Checking the pair on whether it can be glued at all
228 const TopoDS_Shape& aS1=aCS.Shape1();
229 if (!myOriginsDetected.IsBound(aS1)) {
233 const TopoDS_Shape& aSkey1=myOriginsDetected.Find(aS1);
235 const TopoDS_Shape& aS2=aCS.Shape2();
236 if (!myOriginsDetected.IsBound(aS2)) {
240 const TopoDS_Shape& aSkey2=myOriginsDetected.Find(aS2);
242 if (!aSkey1.IsSame(aSkey2)) {
247 // 2. Append the pair to the aLCS
250 // 3. Treatment the sub-shapes of the pair
251 aType=aS1.ShapeType();
252 if (aType==TopAbs_VERTEX) {
257 aTypeS=TopAbs_VERTEX;
260 MapShapes1(aS1, aTypeS, aMS1);
261 MapShapes1(aS2, aTypeS, aMS2);
271 for (i=1; i<=aNbS1; ++i) {
272 const TopoDS_Shape& aSS1=aMS1(i);
273 if (aMS2.Contains(aSS1)) {
277 if (!myOriginsDetected.IsBound(aSS1)) {
282 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS1);
283 if (aDMSLS.IsBound(aSkey)) {
284 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
288 TopTools_ListOfShape aLS;
291 aDMSLS.Bind(aSkey, aLS);
296 for (i=1; i<=aNbS2; ++i) {
297 const TopoDS_Shape& aSS2=aMS2(i);
298 if (aMS1.Contains(aSS2)) {
302 if (!myOriginsDetected.IsBound(aSS2)) {
307 const TopoDS_Shape& aSkey=myOriginsDetected.Find(aSS2);
308 if (aDMSLS.IsBound(aSkey)) {
309 TopTools_ListOfShape& aLS=aDMSLS.ChangeFind(aSkey);
313 TopTools_ListOfShape aLS;
316 aDMSLS.Bind(aSkey, aLS);
321 aItDMSLS.Initialize(aDMSLS);
322 for (; aItDMSLS.More(); aItDMSLS.Next()) {
323 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
324 const TopTools_ListOfShape& aLS=aItDMSLS.Value();
331 const TopoDS_Shape& aSS1=aLS.First();
332 const TopoDS_Shape& aSS2=aLS.Last();
333 aCSS.SetShape1(aSS1);
334 aCSS.SetShape2(aSS2);
335 TreatPair(aCSS, aLCS);
338 //=======================================================================
339 //function : MapShapes1
341 //=======================================================================
342 void MapShapes1(const TopoDS_Shape& aS,
343 const TopAbs_ShapeEnum aType,
344 TopTools_IndexedMapOfShape& aM)
346 TopExp_Explorer aExp;
348 aExp.Init (aS, aType);
349 for ( ;aExp.More(); aExp.Next()) {
350 const TopoDS_Shape aSx=aExp.Current();
351 if (aType==TopAbs_EDGE) {
352 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
353 if (BRep_Tool::Degenerated(aEx)) {