Salome HOME
20.01.2014. Fix for case 1 object + limiting contour.
[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   TCollection_AsciiString aNam("Faces_");
121   for( int anIndex = 1, aLength = theObjectList.Length(); anIndex <= aLength; anIndex++ )
122   {
123     Handle(HYDROData_Object) aGeomObj = 
124       Handle(HYDROData_Object)::DownCast( theObjectList.Value( anIndex ) );
125     if( aGeomObj.IsNull() )
126       continue;
127
128     TopoDS_Shape aShape = aGeomObj->GetTopShape();
129     if ( aShape.IsNull() )
130       continue;  
131    //TCollection_AsciiString aName = aNam + anIndex + ".brep";
132    //BRepTools::Write(aShape, aName.ToCString());
133
134     if ( aShape.ShapeType() == TopAbs_COMPOUND ) {
135       // Create split data for each face contained in the compound
136       TopExp_Explorer anExp( aShape, TopAbs_FACE );
137       for ( ; anExp.More(); anExp.Next() ) {
138         const TopoDS_Face& aFace = TopoDS::Face( anExp.Current() );
139         if ( !aFace.IsNull() ) {
140           SplitData aSplitData( SplitData::Data_Zone, aFace, aGeomObj->GetName() );
141           anInputSplitDataList.append( aSplitData );
142         }
143       }
144     } else {
145       SplitData aSplitData( SplitData::Data_Zone, aShape, aGeomObj->GetName() );
146       anInputSplitDataList.append( aSplitData );
147     }
148   }
149   //
150   SplitDataList anInputGroupList;
151   for( int anIndex = 1; anIndex <= theGroupsList.Length(); anIndex++ )
152   {
153     Handle(HYDROData_ShapesGroup) aGeomGroup = 
154       Handle(HYDROData_ShapesGroup)::DownCast( theGroupsList.Value( anIndex ) );
155     if( aGeomGroup.IsNull() )
156       continue;
157       
158     TopTools_SequenceOfShape aGroupShapes;
159     aGeomGroup->GetShapes( aGroupShapes );
160     for( int i = 1, aNbShapes = aGroupShapes.Length(); i <= aNbShapes; i++ ) {
161       const TopoDS_Shape& aGroupShape = aGroupShapes.Value( i );
162       if ( aGroupShape.IsNull() )
163         continue;  
164
165       if ( aGroupShape.ShapeType() == TopAbs_COMPOUND ) {    
166         TopExp_Explorer anExp( aGroupShape, TopAbs_EDGE );
167         for ( ; anExp.More(); anExp.Next() ) {
168           const TopoDS_Edge& anEdge = TopoDS::Edge( anExp.Current() );
169           if ( !anEdge.IsNull() ) {
170             SplitData aSplitData( SplitData::Data_Edge, anEdge, aGeomGroup->GetName() );
171             anInputGroupList.append( aSplitData );
172           }
173           }
174       } else {
175         SplitData aSplitData( SplitData::Data_Edge, aGroupShape, aGeomGroup->GetName() );
176         anInputGroupList.append( aSplitData );
177       }
178     }
179   }
180   // If only one shape is given we don't split it 
181   // algorithm just returns the unpacked input data
182   bool limplus1Object(false);
183   if(theObjectList.Size() == 1 )  {
184         if(thePolyline.IsNull()) {
185           anOutputSplitDataList.append(anInputSplitDataList); 
186           if(!theGroupsList.IsEmpty() ) 
187             anOutputSplitDataList.append(anInputGroupList);     
188       return anOutputSplitDataList;
189         } else
190                 limplus1Object = true;// size =1 && hasLimits
191   }
192   HYDROData_DataMapOfShapeListOfString aDM3;
193   if(!anInputGroupList.isEmpty()) {// Old edge ==> List_Of_Names
194     QStringList aListOfNames;
195     for (int i=0;i < anInputGroupList.size() ;i++) {
196       const TopoDS_Shape& aSh = anInputGroupList.at(i).Shape;
197       aDM3.Bind(aSh, anInputGroupList.at(i).ObjectNames);
198     }
199   }
200   // Step 1. Prepare Partition structures. 
201   TopoDS_Shape aResult;
202   BOPCol_ListOfShape aLS;  
203   QStringList aListOfNames;
204   TopoDS_Compound aCmp;
205   BRep_Builder aBB;
206   aBB.MakeCompound(aCmp);
207   for (int i=0;i < anInputSplitDataList.size() ;i++) {
208     const TopoDS_Shape& aSh = anInputSplitDataList.at(i).Shape;
209     aDM3.Bind(aSh, anInputSplitDataList.at(i).ObjectNames);
210     aLS.Append(aSh);
211         aBB.Add(aCmp,aSh);
212     //TCollection_AsciiString aName = aNam + i + ".brep";
213     //BRepTools::Write(aSh, aName.ToCString());
214   }
215 #ifdef DEB_SPLIT_TO_ZONES_CHECK_PARTITION
216   TCollection_AsciiString aNameBefore = fileNameBefore + ".brep";
217   BRepTools::Write(aCmp, aNameBefore.ToCString());
218 #endif
219
220   HYDROData_DataMapOfShapeListOfShape aDM1;
221   if(anInputSplitDataList.size() > 1) {
222   HYDROData_Transform splitTool; 
223   const Standard_Integer anErr = SplitFaces(aCmp, splitTool);    
224   if(anErr)
225     return anOutputSplitDataList;
226   aResult = splitTool.Shape();
227   if (aResult.IsNull()) 
228     return anOutputSplitDataList;
229   BRepCheck_Analyzer aCheck (aResult);
230   if(!aCheck.IsValid()) {
231 #ifdef DEB_SPLIT_TO_ZONES
232     cout << "result is not valid" <<endl;
233     BRepTools::Write(aResult, "SplitFacesNV.brep");  
234 #endif
235     return anOutputSplitDataList;
236   }
237 #ifdef DEB_SPLIT_TO_ZONES
238   BRepTools::Write(aResult, "SplitFacesV.brep");
239 #endif
240   
241   // Step 3. Collect history  
242   //HYDROData_DataMapOfShapeListOfShape aDM1;
243   BOPCol_ListIteratorOfListOfShape anIt(aLS); 
244   TCollection_AsciiString aNamM ("EdgM_");
245   TCollection_AsciiString aNamG ("EdgG_");
246   for (int i =1;anIt.More();anIt.Next(),i++) {
247         Standard_Boolean foundF(Standard_False);
248     const TopTools_ListOfShape& aListOfNew = splitTool.Modified(anIt.Value());
249         if(!aListOfNew.IsEmpty())
250           foundF = Standard_True;
251     TopTools_ListOfShape aList;
252     TopTools_ListIteratorOfListOfShape it(aListOfNew);
253     for(;it.More();it.Next())       
254       aList.Append(it.Value());
255     // Bug in History: partition should give only modified entities! => temporary solution is used
256     const TopTools_ListOfShape& aListOfGen = splitTool.Generated(anIt.Value());
257         if(!aListOfGen.IsEmpty())
258           foundF = Standard_True;
259         it.Initialize(aListOfGen);    
260         for(;it.More();it.Next())     
261           aList.Append(it.Value());
262     if(!foundF) // face is not modified
263           aList.Append (anIt.Value());
264         aDM1.Bind(anIt.Value(), aList);
265 #ifdef DEB_SPLIT_TO_ZONES
266         TCollection_AsciiString aName;
267 #endif
268         if(!anInputGroupList.isEmpty() ) { // 1
269       aList.Clear();
270           TopExp_Explorer exp (anIt.Value(), TopAbs_EDGE);
271           for (int j =1;exp.More();exp.Next(),j++) {
272             Standard_Boolean foundE(Standard_False);
273             const TopTools_ListOfShape& aListM = splitTool.Modified(exp.Current());     
274                 //cout << "NB_EDGE_M = " << aListM.Extent() <<endl;
275                 if(aListM.Extent()) foundE = Standard_True;
276                 it.Initialize(aListM);    
277                 for(int k=1;it.More();it.Next(),k++) {    
278               aList.Append(it.Value());
279                   //aName = aNamM + i + j +k +".brep";
280                   //BRepTools::Write(it.Value(),aName.ToCString());
281                 }
282                 const TopTools_ListOfShape& aListG = splitTool.Generated(exp.Current());
283                 if(aListG.Extent()) foundE = Standard_True;
284                 it.Initialize(aListG);    
285                 for(int k=1;it.More();it.Next(),k++)   {  
286               aList.Append(it.Value());
287                   //aName = aNamG + i + j +k +".brep";
288                   //BRepTools::Write(it.Value(),aName.ToCString());
289                 }
290                 //cout << "NB_EDGE = " << aList.Extent() <<endl;
291                 if(!foundE) {
292                   aList.Append (exp.Current());
293 #ifdef DEB_SPLIT_TO_ZONES
294                   aName = aNamG + i + j +".brep";
295                   //BRepTools::Write(exp.Current(),aName.ToCString());
296                   cout << aName.ToCString()<< " = " << exp.Current().TShape() <<endl;
297 #endif
298                 }
299                 aDM1.Bind(exp.Current(), aList);
300           }      
301         }
302   }
303   } else 
304           aResult = anInputSplitDataList.at(0).Shape; // get single input shape
305   // aDM2: NewShape ==> ListOfOldShapes
306   HYDROData_DataMapOfShapeListOfShape aDM2;
307   // make limiting face
308   HYDROData_DataMapOfShapeListOfShape aDM4;
309   Standard_Boolean hasLimits(Standard_False);
310   if (! thePolyline.IsNull()) {
311     //const TopoDS_Shape aShape = thePolyline->GetShape();      
312     const TopoDS_Wire aBndWire = TopoDS::Wire(thePolyline->GetShape());
313     if(!aBndWire.IsNull()) {
314       TopoDS_Face limFace;        
315           if(buildLimFace(aBndWire, limFace)) {
316                 TopoDS_Shape aComResult;
317             BRepAlgoAPI_Common mkCom(aResult, limFace);
318                 if(mkCom.IsDone()) {
319               aComResult = mkCom.Shape();
320                   BRepCheck_Analyzer aCheck (aComResult);
321           if(aCheck.IsValid()) {
322 #ifdef DEB_SPLIT_TO_ZONES
323                     BRepTools::Write(aComResult,"CommonV.brep");
324 #endif  
325
326                     hasLimits = Standard_True; // DM2 should be filled here
327                     HYDROData_MapOfShape aView;
328                     TopExp_Explorer exp (aResult, TopAbs_FACE);
329                         for (int i =1;exp.More();exp.Next(),i++) {
330               const TopoDS_Shape& aFace = exp.Current();
331                       if(!aFace.IsNull()) {
332                         const TopTools_ListOfShape& aListOfNew = mkCom.Modified(aFace);
333                           //cout << "Modified: " << aListOfNew.Extent() <<endl;                 
334                 const TopTools_ListOfShape& aListOfGen = mkCom.Generated(aFace);                        
335                             if(!aListOfNew.IsEmpty()) {
336                       aDM4.Bind(aFace, aListOfNew);
337                               //TCollection_AsciiString aName = aNam + i + ".brep";
338                                   //BRepTools::Write(aListOfNew.Last(), aName.ToCString());                             
339                                 }
340                                 else {
341                               if(!mkCom.IsDeleted(aFace)) {
342                                     if(!aListOfGen.IsEmpty()) {
343                           aDM4.Bind(aFace, aListOfGen);                        
344                                       //TCollection_AsciiString aName = aNam + i + "g.brep";
345                                       //BRepTools::Write(aListOfGen.Last(), aName.ToCString());
346                                         }
347                                          else {
348                                     TopTools_ListOfShape aList; 
349                                         aList.Append(aFace);
350                                         aDM4.Bind(aFace, aList); //the same face - not modified
351                                          }
352                                   }
353                          }
354                          TopExp_Explorer exp2 (aFace, TopAbs_EDGE);
355                          for (int j =1;exp2.More();exp2.Next(),j++) {
356                            const TopoDS_Shape& anEdge = exp2.Current();
357                            if(!anEdge.IsNull()) {
358                                  if(aView.Contains(anEdge)) continue;
359                                  aView.Add(anEdge);
360                                  const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
361                                  const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
362                  if(!aListOfNewEd.IsEmpty())
363                        aDM4.Bind(anEdge, aListOfNewEd);
364                                  else {
365                                    if(!mkCom.IsDeleted(anEdge)) {
366                                          if(!aListOfGenEd.IsEmpty()) {
367                                            aDM4.Bind(anEdge, aListOfGenEd);
368                                          } else {
369                                            TopTools_ListOfShape aList; 
370                                        aList.Append(anEdge);
371                                        aDM4.Bind(anEdge, aList);//the same edge - not modified
372                                          }
373                                    }
374                                  }
375                            }
376                          }
377                         }
378                   } //end DM4 filling (phase 1)
379                     //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
380                  // phase 2 (from tool)
381          TopExp_Explorer expt (limFace, TopAbs_EDGE);
382                  for(;expt.More();expt.Next()) {
383                    const TopoDS_Shape& anEdge = expt.Current();
384                    if(!anEdge.IsNull()) {
385              const TopTools_ListOfShape& aListOfNewEd = mkCom.Modified(anEdge);
386                          const TopTools_ListOfShape& aListOfGenEd = mkCom.Generated(anEdge);
387              if(!aListOfNewEd.IsEmpty())
388                    aDM4.Bind(anEdge, aListOfNewEd);
389                          else {
390                            if(!mkCom.IsDeleted(anEdge)) {
391                                  if(!aListOfGenEd.IsEmpty()) {
392                                    aDM4.Bind(anEdge, aListOfGenEd);
393                                  } else {
394                                    TopTools_ListOfShape aList; 
395                                aList.Append(anEdge);
396                                aDM4.Bind(anEdge, aList);//the same edge - not modified
397                                  }
398                            }
399                          }
400                    }
401                  }
402                  //cout << "DM4 Ext = " <<aDM4.Extent() <<endl;
403                  if(limplus1Object) {
404                    // fill DM1 (old - new) and DM2 (new - old)
405                    HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape mIt(aDM4);
406            for(;mIt.More();mIt.Next()) {
407                          const TopoDS_Shape& aKey = mIt.Key();//old
408                          TopTools_ListOfShape aList;
409                          aList.Append(aKey);
410                          const TopTools_ListOfShape& aListOfNew = mIt.Value();
411                          aDM1.Bind(aKey, aListOfNew);
412                          TopTools_ListIteratorOfListOfShape it(aListOfNew);
413                          for(;it.More();it.Next()) {
414                            if(!aDM2.IsBound(it.Value()))
415                                  aDM2.Bind(it.Value(), aList);
416                            else {
417                                  TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
418                                  aList.Prepend(aKey);
419                            }
420                          }
421                    }
422                  } else {
423          HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1); 
424                  //DM4 contains Old - New after common op. DM1: old - new after Split op.
425                  for(;aMIt.More();aMIt.Next()) {
426            const TopoDS_Shape& aKey = aMIt.Key();
427            TopTools_ListOfShape aList;
428            aList.Append(aKey);
429            const TopTools_ListOfShape& aListOfNew = aMIt.Value();
430            TopTools_ListIteratorOfListOfShape it(aListOfNew);
431            for(;it.More();it.Next()) {// iterate new: b1, b2, b3...
432                          if(!aDM4.IsBound(it.Value())) // bi - is deleted
433                continue; // go to the next bi
434                          else {
435                                 const TopTools_ListOfShape& aListOfNew4 = aDM4.Find(it.Value());
436                             TopTools_ListIteratorOfListOfShape it4(aListOfNew4); // {c1, c2, c3,...}
437                 for(;it4.More();it4.Next()) {
438                                   if(!aDM2.IsBound(it4.Value()))
439                     aDM2.Bind(it4.Value(), aList);
440                               else {
441                     TopTools_ListOfShape& aList = aDM2.ChangeFind(it4.Value());
442                     aList.Prepend(aKey);
443                                   }
444                                 }
445                          }
446                    }//
447                  }
448                  }
449                  } else {
450                          hasLimits = Standard_False;
451 #ifdef DEB_SPLIT_TO_ZONES
452                      BRepTools::Write(aComResult,"CommonNV.brep");
453 #endif  
454                   }
455            }
456           }
457         }
458   }// end limits processing
459   if(!hasLimits) {
460     HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM1);
461     for(;aMIt.More();aMIt.Next()) {
462       const TopoDS_Shape& aKey = aMIt.Key();
463       TopTools_ListOfShape aList;
464       aList.Append(aKey);
465       const TopTools_ListOfShape& aListOfNew = aMIt.Value();
466       TopTools_ListIteratorOfListOfShape it(aListOfNew);
467       for(;it.More();it.Next()) {
468         if(!aDM2.IsBound(it.Value()))
469           aDM2.Bind(it.Value(), aList);
470         else {
471           TopTools_ListOfShape& aList = aDM2.ChangeFind(it.Value());
472           aList.Prepend(aKey);
473                 }
474           }
475         }
476   }
477   // Step 4. Fill output structure.
478 #ifdef DEB_SPLIT_TO_ZONES
479   TCollection_AsciiString aNam4 ("SC_");
480 #endif  
481   HYDROData_DataMapIteratorOfDataMapOfShapeListOfShape aMIt(aDM2);
482   for(int i =1;aMIt.More();aMIt.Next(),i++) {
483     SplitData aDestSplitData;
484     const TopoDS_Shape& aKey = aMIt.Key(); //new
485     aDestSplitData.Shape = aKey;
486     if(aKey.ShapeType() == TopAbs_FACE)
487       aDestSplitData.Type = SplitData::Data_Zone;
488         else {
489       aDestSplitData.Type = SplitData::Data_Edge;
490 #ifdef DEB_SPLIT_TO_ZONES
491           TCollection_AsciiString aName = aNam4 + i + ".brep";
492           BRepTools::Write(aKey,aName.ToCString());
493 #endif  
494         }
495
496     QStringList aListOfNames; // names processing
497     const TopTools_ListOfShape& aListOfOld = aMIt.Value();
498     TopTools_ListIteratorOfListOfShape it(aListOfOld);
499         for(;it.More();it.Next()) {     
500           const TopoDS_Shape& aSh = it.Value(); //old
501           if(aDM3.IsBound(aSh)) {
502             const QStringList& ObjectNames = aDM3.Find(aSh);
503                 aListOfNames.append(ObjectNames);
504 #ifdef DEB_SPLIT_TO_ZONES
505
506                 for ( int k = 1;k <= ObjectNames.length(); ++k ) {
507                         QString aStr = ObjectNames.last(); 
508                         cout << "Indx = " << i<< " k = " << k << " size = " <<ObjectNames.size() << " Name = "<<aStr.toStdString() <<endl;   
509                 }       
510 #endif  
511           }      
512         }
513
514         aDestSplitData.ObjectNames = aListOfNames;  
515         anOutputSplitDataList.append(aDestSplitData);
516   }
517  
518   return anOutputSplitDataList;
519 }
520
521 bool HYDROData_SplitToZonesTool::SplitTwoData( const SplitData& theData1,
522                                                const SplitData& theData2,
523                                                SplitData& theData1Subtracted,
524                                                SplitData& theData2Subtracted,
525                                                SplitData& theDataIntersected )
526 {
527   const TopoDS_Shape& aShape1 = theData1.Shape;
528   const TopoDS_Shape& aShape2 = theData2.Shape;
529
530   const QStringList& anObjectNames1 = theData1.ObjectNames;
531   const QStringList& anObjectNames2 = theData2.ObjectNames;
532
533   BRepAlgoAPI_Common aCommon( aShape1, aShape2 );
534   TopoDS_Shape aCommonShape = aCommon.Shape();
535   if( aCommonShape.IsNull() )
536   {
537     theData1Subtracted = theData1;
538     theData2Subtracted = theData2;
539     return false;
540   }
541
542   BRepAlgoAPI_Cut aCut1( aShape1, aShape2 );
543   TopoDS_Shape aCut1Shape = aCut1.Shape();
544
545   BRepAlgoAPI_Cut aCut2( aShape2, aShape1 );
546   TopoDS_Shape aCut2Shape = aCut2.Shape();
547
548   theData1Subtracted = SplitData( SplitData::Data_Zone, aCut1Shape, anObjectNames1 );
549   theData2Subtracted = SplitData( SplitData::Data_Zone, aCut2Shape, anObjectNames2 );
550   theDataIntersected = SplitData( SplitData::Data_Zone, aCommonShape, anObjectNames1 + anObjectNames2 );
551
552   return true;
553 }
554
555 HYDROData_SplitToZonesTool::SplitDataList
556 HYDROData_SplitToZonesTool::ExtractSeparateData( const SplitData& theData )
557 {
558   SplitDataList aSplitDataList;
559   TopExp_Explorer anExp( theData.Shape, TopAbs_FACE );
560   for( ; anExp.More(); anExp.Next() )
561   {
562     TopoDS_Shape aShape = anExp.Current();
563     if( aShape.ShapeType() == TopAbs_FACE )
564     {
565       TopoDS_Face aFace = TopoDS::Face( aShape );
566       if( !aFace.IsNull() )
567       {
568         SplitData aSplitData( SplitData::Data_Zone, aFace, theData.ObjectNames );
569         aSplitDataList.append( aSplitData );
570       }
571     }
572   }
573   return aSplitDataList;
574 }