1 // Copyright (C) 2007-2012 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
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 <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;
81 //modified by NIZNHY-PKV Tue Mar 13 13:33:35 2012f
83 myDetector.SetContext(myContext);
84 //modified by NIZNHY-PKV Tue Mar 13 13:33:38 2012t
85 myDetector.SetArgument(myArgument);
86 myDetector.SetTolerance(myTolerance);
87 myDetector.SetCheckGeometry(bCheckGeometry);
90 iErr=myDetector.ErrorStatus();
96 //modified by NIZNHY-PKV Tue Mar 13 13:40:36 2012f
97 iErr=myDetector.WarningStatus();
99 // Sticked shapes are detected
102 //modified by NIZNHY-PKV Tue Mar 13 13:40:39 2012t
104 const TopTools_DataMapOfShapeListOfShape& aImages=myDetector.Images();
105 aItDMSLS.Initialize(aImages);
106 for (; aItDMSLS.More(); aItDMSLS.Next()) {
107 const TopoDS_Shape& aSkey=aItDMSLS.Key();
108 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
110 myImagesDetected.Bind(aSkey, aLSD);
113 aItDMSLS.Initialize(myImagesDetected);
114 for (; aItDMSLS.More(); aItDMSLS.Next()) {
115 const TopoDS_Shape& aSkey=aItDMSLS.Key();
116 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
117 aItLS.Initialize(aLSD);
118 for (; aItLS.More(); aItLS.Next()) {
119 const TopoDS_Shape& aSx=aItLS.Value();
120 myOriginsDetected.Bind(aSx, aSkey);
124 //=======================================================================
125 //function : PerformShapesToWork
127 //=======================================================================
128 void GEOMAlgo_Gluer2::PerformShapesToWork()
130 Standard_Integer aNbSG, i, j, k, aNbC, aNb, aNbSD;
131 TopTools_ListIteratorOfListOfShape aItLS1, aItLS2;
132 TopTools_DataMapIteratorOfDataMapOfShapeListOfShape aItDMSLS;
133 NMTTools_CoupleOfShape aCS;
134 NMTTools_ListOfCoupleOfShape aLCS;
135 NMTTools_ListIteratorOfListOfCoupleOfShape aItCS;
140 myImagesToWork.Clear();
141 myOriginsToWork.Clear();
143 aNbSD=myImagesDetected.Extent();
144 if (!aNbSD) {// no shapes to glue detected
149 aNbSG=myShapesToGlue.Extent();
152 myImagesToWork=myImagesDetected;
154 aItDMSLS.Initialize(myImagesToWork);
155 for (; aItDMSLS.More(); aItDMSLS.Next()) {
156 const TopoDS_Shape& aSkey=aItDMSLS.Key();
157 const TopTools_ListOfShape& aLSD=aItDMSLS.Value();
158 aItLS1.Initialize(aLSD);
159 for (; aItLS1.More(); aItLS1.Next()) {
160 const TopoDS_Shape& aSx=aItLS1.Value();
161 myOriginsToWork.Bind(aSx, aSkey);
168 aItDMSLS.Initialize(myShapesToGlue);
169 for (k=0; aItDMSLS.More(); aItDMSLS.Next(), ++k) {
170 //const TopoDS_Shape& aSkey=aItDMSLS.Key();
171 const TopTools_ListOfShape& aLSG=aItDMSLS.Value();
172 aItLS1.Initialize(aLSG);
173 for (i=0; aItLS1.More(); aItLS1.Next(), ++i) {
174 aItLS2.Initialize(aLSG);
175 for (j=0; aItLS2.More(); aItLS2.Next(), ++j) {
177 const TopoDS_Shape& aSG1=aItLS1.Value();
178 const TopoDS_Shape& aSG2=aItLS2.Value();
181 TreatPair(aCS, aLCS);
188 TopTools_ListOfShape aLSX;
189 NMTTools_IndexedDataMapOfShapeIndexedMapOfShape aMC;
191 NMTTools_Tools::FindChains(aLCS, aMC);
193 // 3. myImagesToWork, myOriginsToWork
195 for (i=1; i<=aNbC; ++i) {
196 const TopoDS_Shape& aSkey=aMC.FindKey(i);
197 const TopTools_IndexedMapOfShape& aM=aMC(i);
200 for (j=1; j<=aNb; ++j) {
201 const TopoDS_Shape& aS=aM(j);
203 myOriginsToWork.Bind(aS, aSkey);
205 myImagesToWork.Bind(aSkey, aLSX);
208 //=======================================================================
209 //function : TreatPair
211 //=======================================================================
212 void GEOMAlgo_Gluer2::TreatPair(const NMTTools_CoupleOfShape& aCS,
213 NMTTools_ListOfCoupleOfShape& 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 NMTTools_CoupleOfShape 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);
339 //=======================================================================
340 //function : MapShapes1
342 //=======================================================================
343 void MapShapes1(const TopoDS_Shape& aS,
344 const TopAbs_ShapeEnum aType,
345 TopTools_IndexedMapOfShape& aM)
347 TopExp_Explorer aExp;
349 aExp.Init (aS, aType);
350 for ( ;aExp.More(); aExp.Next()) {
351 const TopoDS_Shape aSx=aExp.Current();
352 if (aType==TopAbs_EDGE) {
353 const TopoDS_Edge& aEx=*((TopoDS_Edge*)&aSx);
354 if (BRep_Tool::Degenerated(aEx)) {