Salome HOME
16062cf5b19877fd96cb7f8a74be1b6e9aa15890
[modules/hydro.git] / src / HYDROData / HYDROData_SplitToZonesTool.cxx
1
2 #include "HYDROData_SplitToZonesTool.h"
3
4 #include "HYDROData_PolylineXY.h"
5 #include "HYDROData_ShapesGroup.h"
6 #include <HYDROData_Transform.h>
7 #include <BRepAlgoAPI_Cut.hxx>
8 #include <BRepAlgoAPI_Common.hxx>
9 #include <BRepBuilderAPI_MakeFace.hxx>
10 #include <BRep_Builder.hxx>
11 #include <TopExp_Explorer.hxx>
12 #include <TopoDS.hxx>
13 #include <TopoDS_Shape.hxx>
14 #include <TopoDS_Compound.hxx>
15 #include <TopoDS_Wire.hxx>
16 #include <TopoDS_Edge.hxx>
17 #include <BRepCheck_Analyzer.hxx>
18 #include <TopTools_ListOfShape.hxx>
19 #include <TopTools_ListIteratorOfListOfShape.hxx>
20 #include <gp_Pln.hxx>
21 #include <BRepGProp.hxx>
22 #include <GProp_GProps.hxx>
23 #include <Geom_Plane.hxx>
24 #include <BRepBuilderAPI_FindPlane.hxx>
25
26 //#define DEB_SPLIT_TO_ZONES 1
27 //#define DEB_SPLIT_TO_ZONES_CHECK_PARTITION 1
28 #if (defined (DEB_SPLIT_TO_ZONES) || defined(DEB_SPLIT_TO_ZONES_CHECK_PARTITION))
29 #include <BRepTools.hxx>
30 static TCollection_AsciiString fileNameBefore("BeforeTranslation");
31 #endif
32
33 TopoDS_Face HYDROData_SplitToZonesTool::SplitData::Face() const
34 {
35   TopoDS_Face aResFace;
36
37   if( !Shape.IsNull() )
38   {
39     if ( Shape.ShapeType() == TopAbs_FACE )
40     {
41       aResFace = TopoDS::Face( Shape );
42     }
43     else if ( Shape.ShapeType() == TopAbs_WIRE )
44     {
45       BRepBuilderAPI_MakeFace aMakeFace( TopoDS::Wire( Shape ), Standard_True );
46       aMakeFace.Build();
47       if( aMakeFace.IsDone() )
48         aResFace = aMakeFace.Face();
49     }
50   }
51
52   return aResFace;
53 }
54
55 Standard_Boolean buildLimFace(const TopoDS_Wire& theBndWire, TopoDS_Face& outFace) 
56 {
57   GProp_GProps G;
58   BRepGProp::LinearProperties(theBndWire,G);
59   const gp_Pnt& aCPnt = G.CentreOfMass();
60   gp_Pln aPln;
61   BRepBuilderAPI_FindPlane fndPlane (theBndWire, Precision::Confusion());  
62   if(fndPlane.Found())
63     aPln = fndPlane.Plane()->Pln();
64   else
65     aPln = gp_Pln(aCPnt, gp::OZ().Direction());
66   BRepBuilderAPI_MakeFace  aMkFace(aPln, theBndWire);
67   if(aMkFace.IsDone()) {
68     outFace = aMkFace.Face();      
69     if(!outFace.IsNull()) {
70 #ifdef DEB_SPLIT_TO_ZONES
71 //      BRepTools::Write(limFace,"FL.brep");
72 #endif
73       return Standard_True;
74     }
75   }
76   return Standard_False;
77 }
78 //======================================================================================
79
80 void HYDROData_SplitToZonesTool::SetFileNames(const QString& theNameBefore, const QString& theNameAfter)
81 {
82 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
83   if(!theNameBefore.isNull() && !theNameBefore.isEmpty())
84   {
85     TCollection_AsciiString aName (theNameBefore.toStdString().data());
86     fileNameBefore = aName;
87   }
88   if(!theNameAfter.isNull() && !theNameAfter.isEmpty())
89   {
90     TCollection_AsciiString aName (theNameAfter.toStdString().data());
91     HYDROData_Transform::SetFileName (aName);
92   }
93 #endif
94 }
95 //======================================================================================
96 Standard_Integer HYDROData_SplitToZonesTool::SplitFaces(const TopoDS_Compound& theComp, 
97                                                         HYDROData_Transform& theTool)
98 {
99   theTool.Clear();
100   theTool.SetArgument(theComp);
101   theTool.Detect();
102   const Standard_Boolean bToTransform = theTool.ToTransform();  
103   theTool.SetToTransform(bToTransform);  
104   theTool.Perform();
105   Standard_Integer anErr = theTool.ErrorStatus();
106   return anErr;
107 }
108
109 //======================================================================================
110 HYDROData_SplitToZonesTool::SplitDataList
111   HYDROData_SplitToZonesTool::Split( const HYDROData_SequenceOfObjects&  theObjectList,
112                                      const HYDROData_SequenceOfObjects&  theGroupsList,
113                                      const Handle(HYDROData_PolylineXY)& thePolyline )
114 {
115   SplitDataList anOutputSplitDataList;
116   if(theObjectList.IsEmpty()) return anOutputSplitDataList;
117   // Preparation. 
118   // Collect the object shapes to split. InputDataList will contain elements which will hold shape & name_of_shape.
119   SplitDataList anInputSplitDataList;
120 #ifdef DEB_SPLIT_TO_ZONES
121   TCollection_AsciiString aNam("Faces_");
122 #endif
123   for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
124   {
125     Handle(HYDROData_Object) aGeomObj = 
126       Handle(HYDROData_Object)::DownCast( theObjectList.Value( anIndex ) );
127     if( aGeomObj.IsNull() )
128       continue;
129
130     TopoDS_Shape aShape = aGeomObj->GetTopShape();
131     if ( aShape.IsNull() )
132       continue;  
133 #ifdef DEB_SPLIT_TO_ZONES
134    TCollection_AsciiString aName = aNam + anIndex + ".brep";
135    BRepTools::Write(aShape, aName.ToCString());
136 #endif
137     if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
138       // Create split data for each face contained in the compound
139       TopExp_Explorer anExp( aShape, TopAbs_FACE );
140       for ( ; anExp.More(); anExp.Next() ) {
141         const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
142         if ( !aFace.IsNull() ) {
143           SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() );
144           anInputSplitDataList.append( aSplitData );
145         }
146       }
147     } else {
148       SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() );
149       anInputSplitDataList.append( aSplitData );
150     }
151   }
152   //
153   SplitDataList anInputGroupList;
154   for( int anIndex = 1, aLength = theGroupsList.Length(); anIndex <=aLength; anIndex++ )
155   {
156     Handle(HYDROData_ShapesGroup) aGeomGroup = 
157       Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
158     if( aGeomGroup.IsNull() )
159       continue;
160       
161     TopTools_SequenceOfShape aGroupShapes;
162     aGeomGroup->GetShapes( aGroupShapes );
163     for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
164       const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
165       if ( aGroupShape.IsNull() )
166         continue;  
167
168       if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {    
169         TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
170         for ( ; anExp.More(); anExp.Next() ) {
171           const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
172           if ( !anEdge.IsNull() ) {
173             SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
174             anInputGroupList.append( aSplitData );
175           }
176         }
177       } else {
178         SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
179         anInputGroupList.append( aSplitData );
180 #ifdef DEB_SPLIT_TO_ZONES
181         QString aStr = aSplitData.ObjectNames.join(" "); 
182         cout << "Group# = " <<anIndex <<" Nmb in grp = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aSplitData.ObjectNames.size() <<endl;   
183 #endif
184       }
185     }
186   }
187   // If only one shape is given we don't split it 
188   // algorithm just returns the unpacked input data
189   bool limplus1Object(false);
190   if(theObjectList.Size() == 1 )  {
191     if(thePolyline.IsNull()) {
192       anOutputSplitDataList.append(anInputSplitDataList); 
193       if(!theGroupsList.IsEmpty() ) 
194         anOutputSplitDataList.append(anInputGroupList);
195       return anOutputSplitDataList;
196     } else
197         limplus1Object = true;// size =1 && hasLimits
198   }
199   HYDROData_DataMapOfShapeListOfString aDM3;
200   if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
201     QStringList aListOfNames;
202     for (int i=0;i < anInputGroupList.size() ;i++) {
203       const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
204       aDM3.Bind(aSh, anInputGroupList.at(i).ObjectNames);
205     }
206   }
207
208   // Step 1. Prepare Partition structures. 
209   TopoDS_Shape aResult;
210   BOPCol_ListOfShape aLS;  
211   QStringList aListOfNames;
212   TopoDS_Compound aCmp;
213   BRep_Builder aBB;
214   aBB.MakeCompound(aCmp);
215   for (int i=0;i < anInputSplitDataList.size() ;i++) {
216     const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
217     aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames);
218     aLS.Append(aSh);
219     aBB.Add(aCmp,aSh);
220 #ifdef DEB_SPLIT_TO_ZONES
221     //TCollection_AsciiString aName = aNam + i + ".brep";
222     //BRepTools::Write(aSh, aName.ToCString());
223 #endif
224   }
225 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
226   TCollection_AsciiString aNameBefore = fileNameBefore + ".brep";
227   BRepTools::Write(aCmp, aNameBefore.ToCString());
228 #endif
229
230   HYDROData_DataMapOfShapeListOfShape aDM1;
231   if(anInputSplitDataList.size() > 1) {
232     HYDROData_Transform splitTool; 
233     const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
234     if(anErr)
235       return anOutputSplitDataList;
236     aResult = splitTool.Shape();
237     if (aResult.IsNull()) 
238       return anOutputSplitDataList;
239     BRepCheck_Analyzer aCheck (aResult);
240     if(!aCheck.IsValid()) {
241   #ifdef DEB_SPLIT_TO_ZONES
242       cout << "result is not valid" <<endl;
243       BRepTools::Write(aResult, "SplitFacesNV.brep");  
244   #endif
245       return anOutputSplitDataList;
246     }
247   #ifdef DEB_SPLIT_TO_ZONES
248     BRepTools::Write(aResult, "SplitFacesV.brep");
249   #endif
250     
251     // Step 3. Collect history  
252     //HYDROData_DataMapOfShapeListOfShape aDM1;
253     BOPCol_ListIteratorOfListOfShape anIt(aLS); 
254   #ifdef DEB_SPLIT_TO_ZONES
255     TCollection_AsciiString aNamM ("EdgM_");
256     TCollection_AsciiString aNamG ("EdgG_");
257   #endif
258     for (int i =1;anIt.More();anIt.Next(),i++) {
259       Standard_Boolean foundF(Standard_False);
260       const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
261       if(!aListOfNew.IsEmpty())
262         foundF = Standard_True;
263
264       TopTools_ListOfShape aList;
265
266       TopTools_ListIteratorOfListOfShape it(aListOfNew);
267       for(;it.More();it.Next())       
268         aList.Append(it.Value());
269       // Bug in History: partition should give only modified entities! => temporary solution is used
270       const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
271       if(!aListOfGen.IsEmpty())
272         foundF = Standard_True;
273       it.Initialize(aListOfGen);    
274       for(;it.More();it.Next())     
275         aList.Append(it.Value());
276       if(!foundF) // face is not modified
277         aList.Append (anIt.Value());
278       aDM1.Bind(anIt.Value(), aList);
279   #ifdef DEB_SPLIT_TO_ZONES
280       TCollection_AsciiString aName;
281   #endif
282       if(!anInputGroupList.isEmpty() ) { // 1
283         TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
284         for (int j =1;exp.More();exp.Next(),j++) {
285           aList.Clear();
286           Standard_Boolean foundE(Standard_False);
287           const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());    
288           //cout << "NB_EDGE_M = " << aListM.Extent() <<endl;
289           if(aListM.Extent()) foundE = Standard_True;
290           it.Initialize(aListM);    
291           for(int k=1;it.More();it.Next(),k++) {    
292             aList.Append(it.Value());
293   #ifdef DEB_SPLIT_TO_ZONES
294             //aName = aNamM + i + j +k +".brep";
295             //BRepTools::Write(it.Value(),aName.ToCString());
296   #endif
297           }
298           const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
299           if(aListG.Extent()) foundE = Standard_True;
300           it.Initialize(aListG);    
301           for(int k=1;it.More();it.Next(),k++)
302             aList.Append(it.Value());
303           //cout << "NB_EDGE = " << aList.Extent() <<endl;
304           if(!foundE) {
305             aList.Append (exp.Current());
306   #ifdef DEB_SPLIT_TO_ZONES
307             aName = aNamG + i + j +".brep";
308             BRepTools::Write(exp.Current(),aName.ToCString());
309             cout << aName.ToCString()<< " = " << exp.Current().TShape() <<endl;
310   #endif
311           }
312           aDM1.Bind(exp.Current(), aList);
313         }
314       }
315     }
316   } else {
317       aResult = anInputSplitDataList.at(0).Shape; // get single input shape
318   }
319
320   // aDM2: NewShape ==> ListOfOldShapes
321   HYDROData_DataMapOfShapeListOfShape aDM2;
322   // make limiting face
323   HYDROData_DataMapOfShapeListOfShape aDM4;
324   Standard_Boolean hasLimits(Standard_False);
325   QString aBndName;
326   HYDROData_MapOfShape aBndView;
327   if (! thePolyline.IsNull()) {    
328     const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape());
329     if(!aBndWire.IsNull()) {
330       TopoDS_Face limFace;       
331       if(buildLimFace(aBndWire, limFace)) {
332         TopoDS_Shape aComResult;
333         BRepAlgoAPI_Common mkCom(aResult, limFace);
334         if(mkCom.IsDone()) {
335           aComResult = mkCom.Shape();
336           BRepCheck_Analyzer aCheck (aComResult);
337           if(aCheck.IsValid()) {
338 #ifdef DEB_SPLIT_TO_ZONES
339             BRepTools::Write(aComResult,"CommonV.brep");
340             BRepTools::Write(limFace,"limFace.brep");
341 #endif    
342             aBndName = thePolyline->GetName();
343             hasLimits = Standard_True; // DM2 should be filled here
344             TopExp_Explorer exp (limFace, TopAbs_EDGE);
345             for (int i =1;exp.More();exp.Next(),i++) {
346               const TopoDS_Shape& anEdge = exp.Current();
347               if(anEdge.IsNull()) continue;
348               aBndView.Add(anEdge);
349               QStringList aListOfNames;
350               aListOfNames.append(aBndName);
351               aDM3.Bind(anEdge, aListOfNames);
352               TopTools_ListOfShape aList;
353               aList.Append(anEdge);
354               aDM1.Bind(anEdge,aList);
355             }
356             HYDROData_MapOfShape aView;
357             exp.Init (aResult, TopAbs_FACE);
358             for (int i =1;exp.More();exp.Next(),i++) {
359               const TopoDS_Shape& aFace = exp.Current();
360               if(!aFace.IsNull()) {
361                 const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
362                 //cout << "Modified: " << aListOfNew.Extent() <<endl;                                    
363                 if(!aListOfNew.IsEmpty()) {
364                   aDM4.Bind(aFace, aListOfNew);
365 #ifdef DEB_SPLIT_TO_ZONES
366                   //TCollection_AsciiString aName = aNam + i + ".brep";
367                   //BRepTools::Write(aListOfNew.Last(), aName.ToCString());                
368 #endif
369                 }
370                 else {
371                     if(!mkCom.IsDeleted(aFace)) {
372                       const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);    
373                       if(!aListOfGen.IsEmpty()) {
374                         aDM4.Bind(aFace, aListOfGen);    
375 #ifdef DEB_SPLIT_TO_ZONES
376                         //TCollection_AsciiString aName = aNam + i + "g.brep";
377                         //BRepTools::Write(aListOfGen.Last(), aName.ToCString());
378 #endif
379                       }
380                        else {
381                         TopTools_ListOfShape aList; 
382                         aList.Append(aFace);
383                         aDM4.Bind(aFace, aList); //the same face - not modified
384                        }
385                     }
386              }
387              TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
388              for (int j =1;exp2.More();exp2.Next(),j++) {
389                const TopoDS_Shape& anEdge = exp2.Current();
390                if(!anEdge.IsNull()) {
391                  if(aView.Contains(anEdge)) continue;
392                  aView.Add(anEdge);
393                  const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);                 
394                  if(!aListOfNewEd.IsEmpty())
395                    aDM4.Bind(anEdge, aListOfNewEd);
396                  else {
397                    if(!mkCom.IsDeleted(anEdge)) {
398                      const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
399                      if(!aListOfGenEd.IsEmpty()) {
400                        aDM4.Bind(anEdge, aListOfGenEd);
401                      } else {
402                        TopTools_ListOfShape aList; 
403                        aList.Append(anEdge);
404                        aDM4.Bind(anEdge, aList);//the same edge - not modified
405                      }
406                    }
407                  }
408                }
409              }
410             }
411             } //end DM4 filling (phase 1)
412             //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
413          // phase 2 (from tool)
414 #ifdef DEB_SPLIT_TO_ZONES
415          TCollection_AsciiString aNam("BndEd_");
416 #endif
417          TopExp_Explorer expt (limFace, TopAbs_EDGE);
418          for(int i =1;expt.More();expt.Next(),i++) {
419            const TopoDS_Shape& anEdge = expt.Current();
420            if(!anEdge.IsNull()) {
421              const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);    
422 #ifdef DEB_SPLIT_TO_ZONES
423              TopTools_ListIteratorOfListOfShape itl(aListOfNewEd);
424              for(int j=1;itl.More();itl.Next(),j++) {
425                TCollection_AsciiString aName = aNam + i + "_" + j + ".brep";
426                BRepTools::Write(itl.Value(), aName.ToCString());
427                cout <<aName.ToCString()<<" = "<< itl.Value().TShape() <<endl;
428              }
429 #endif
430              if(!aListOfNewEd.IsEmpty())
431                aDM4.Bind(anEdge, aListOfNewEd);
432              else {
433                if(!mkCom.IsDeleted(anEdge)) {
434                  const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
435                  if(!aListOfGenEd.IsEmpty()) {
436                    aDM4.Bind(anEdge, aListOfGenEd);
437                  } else {
438                    TopTools_ListOfShape aList; 
439                    aList.Append(anEdge);
440                    aDM4.Bind(anEdge, aList);//the same edge - not modified
441                  }
442                }
443              }
444            }
445          }
446          //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
447          if(limplus1Object) {
448            // fill DM1 (old - new) and DM2 (new - old)
449            HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
450            for(;mIt.More();mIt.Next()) {
451              const TopoDS_Shape& aKey = mIt.Key();//old
452              TopTools_ListOfShape aList;
453              aList.Append(aKey);
454              const TopTools_ListOfShape& aListOfNew = mIt.Value();
455              aDM1.Bind(aKey, aListOfNew);
456              TopTools_ListIteratorOfListOfShape it(aListOfNew);
457              for(;it.More();it.Next()) {
458                if(!aDM2.IsBound(it.Value()))
459                  aDM2.Bind(it.Value(), aList);
460                else {
461                  TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
462                  aList.Prepend(aKey);
463                }
464              }
465            }
466          } else {
467            HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); 
468            //DM4 contains Old - New after common op. DM1: old - new after Split op.
469            for(;aMIt.More();aMIt.Next()) {
470              const TopoDS_Shape& aKey = aMIt.Key();
471              TopTools_ListOfShape aList;
472              aList.Append(aKey);
473              const TopTools_ListOfShape& aListOfNew = aMIt.Value();
474              TopTools_ListIteratorOfListOfShape it(aListOfNew);
475              for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
476                if(!aDM4.IsBound(it.Value())) // bi - is deleted
477                  continue; // go to the next bi
478                else {
479                   const TopTools_ListOfShape& aListOfNew4 = aDM4.Find(it.Value());
480                   TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
481                   for(;it4.More();it4.Next()) {
482                     if(!aDM2.IsBound(it4.Value()))
483                       aDM2.Bind(it4.Value(), aList);
484                     else {
485                       TopTools_ListOfShape& aList = aDM2.ChangeFind(it4.Value());
486                       aList.Prepend(aKey);
487                     }
488                   }
489                }
490              }
491            }
492          }
493          } else {
494              hasLimits = Standard_False;
495 #ifdef DEB_SPLIT_TO_ZONES
496              BRepTools::Write(aComResult,"CommonNV.brep");
497 #endif    
498           }
499        }
500       }
501     }
502   }// end limits processing
503   if(!hasLimits) {
504     HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
505     for(;aMIt.More();aMIt.Next()) {
506       const TopoDS_Shape& aKey = aMIt.Key();
507       TopTools_ListOfShape aList;
508       aList.Append(aKey);
509       const TopTools_ListOfShape& aListOfNew = aMIt.Value();
510       TopTools_ListIteratorOfListOfShape it(aListOfNew);
511       for(;it.More();it.Next()) {
512         if(!aDM2.IsBound(it.Value()))
513           aDM2.Bind(it.Value(), aList);
514         else {
515           TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
516           aList.Prepend(aKey);
517         }
518       }
519     }
520   }
521   // Step 4. Fill output structure.
522 #ifdef DEB_SPLIT_TO_ZONES
523   TCollection_AsciiString aNam4 ("SC_");
524 #endif  
525   HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
526   for(int i =1;aMIt.More();aMIt.Next(),i++) {
527     SplitData aDestSplitData;
528     const TopoDS_Shape& aKey = aMIt.Key(); //new
529     aDestSplitData.Shape = aKey;
530     if(aKey.ShapeType() == TopAbs_FACE)
531       aDestSplitData.Type = SplitData::Data_Zone;
532     else {
533       aDestSplitData.Type = SplitData::Data_Edge;
534 #ifdef DEB_SPLIT_TO_ZONES
535       TCollection_AsciiString aName = aNam4 + i + ".brep";
536       BRepTools::Write(aKey,aName.ToCString());
537 #endif    
538     }
539
540     QStringList aListOfNames; // names processing
541     const TopTools_ListOfShape& aListOfOld = aMIt.Value();
542     TopTools_ListIteratorOfListOfShape it(aListOfOld);
543     for(int j =1;it.More();it.Next(),j++) {    
544       const TopoDS_Shape& aSh = it.Value(); //old
545       if(aDM3.IsBound(aSh)) {
546         const QStringList& ObjectNames = aDM3.Find(aSh);    
547         aListOfNames.append(ObjectNames);
548 #ifdef DEB_SPLIT_TO_ZONES
549         TCollection_AsciiString aName = aNam4 + i +"_" + j + ".brep";
550         BRepTools::Write(aSh ,aName.ToCString());        
551 #endif    
552       }    else {
553 #ifdef DEB_SPLIT_TO_ZONES
554         TCollection_AsciiString aName = aNam4 +"__" + i +"_" + j + ".brep";
555         BRepTools::Write(aSh ,aName.ToCString());        
556         cout <<aName.ToCString()<<" = "<< aSh.TShape() <<endl;
557 #endif
558           if(aBndView.Contains(aSh) && hasLimits) {            
559             aListOfNames.append(aBndName);
560 #ifdef DEB_SPLIT_TO_ZONES
561             cout << " BndName = "<<aBndName.toStdString() <<endl; 
562 #endif
563           }
564       }
565     }
566
567     aDestSplitData.ObjectNames = aListOfNames;  
568     anOutputSplitDataList.append(aDestSplitData);    
569 #ifdef DEB_SPLIT_TO_ZONES
570     QString aStr = aDestSplitData.ObjectNames.join(" "); 
571     cout << "New# = " << i<< " Names = "<<aStr.toStdString() << " size = " <<aDestSplitData.ObjectNames.size() <<endl; 
572 #endif
573   }
574
575   return anOutputSplitDataList;
576 }
577