]> SALOME platform Git repositories - modules/hydro.git/blob - src/HYDROData/HYDROData_Tool.cxx
Salome HOME
Merge branch 'BR_H2018_2' of https://codev-tuleap.cea.fr/plugins/git/salome/hydro...
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
1 // Copyright (C) 2014-2015  EDF-R&D
2 // This library is free software; you can redistribute it and/or
3 // modify it under the terms of the GNU Lesser General Public
4 // License as published by the Free Software Foundation; either
5 // version 2.1 of the License, or (at your option) any later version.
6 //
7 // This library is distributed in the hope that it will be useful,
8 // but WITHOUT ANY WARRANTY; without even the implied warranty of
9 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
10 // Lesser General Public License for more details.
11 //
12 // You should have received a copy of the GNU Lesser General Public
13 // License along with this library; if not, write to the Free Software
14 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
15 //
16 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
17 //
18
19 #include <HYDROData_Tool.h>
20 #include <HYDROData_ArtificialObject.h>
21 #include <HYDROData_Document.h>
22 #include <HYDROData_Entity.h>
23 #include <HYDROData_Iterator.h>
24 #include <HYDROData_NaturalObject.h>
25 #include <HYDROData_ShapesGroup.h>
26 #include <HYDROData_PolylineXY.h>
27 #include <QColor>
28 #include <QFile>
29 #include <QStringList>
30 #include <QTextStream>
31 #include <QSet>
32 #include <BRep_Tool.hxx>
33 #include <BRepAdaptor_Surface.hxx>
34 #include <BRepTopAdaptor_FClass2d.hxx>
35 #include <ElSLib.hxx>
36 #include <Geom_Curve.hxx>
37 #include <gp_Pln.hxx>
38 #include <Quantity_Color.hxx>
39 #include <TopExp_Explorer.hxx>
40 #include <TopoDS.hxx>
41 #include <TopoDS_Face.hxx>
42 #include <TopoDS_Shape.hxx>
43 #include <TopoDS_Wire.hxx>
44 #include <limits>
45 #include <math.h>
46
47
48 #include <BRepTools.hxx>
49 #include <NCollection_Map.hxx>
50 #include <TopTools_ShapeMapHasher.hxx>
51 #include <BRep_Builder.hxx>
52 #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
53 #include <TopExp.hxx>
54 #include <NCollection_List.hxx>
55 #include <TopTools_ListIteratorOfListOfShape.hxx>
56
57 #include <BRepBuilderAPI_MakeFace.hxx>
58
59 #include <TopExp_Explorer.hxx>
60 #include <TopTools_ListIteratorOfListOfShape.hxx>
61 #include <TopTools_HSequenceOfShape.hxx>
62
63 #include <BRep_Builder.hxx>
64 #include <BRepAlgo_FaceRestrictor.hxx>
65 #include <BRepCheck_Analyzer.hxx>
66
67 #include <ShapeAnalysis.hxx>
68 #include <ShapeAnalysis_FreeBounds.hxx>
69
70
71 HYDROData_Tool::ExecStatus HYDROData_Tool::myTriangulationStatus = ExecStatus::None;
72
73 static int aMaxNameId = INT_MAX;
74 static int aMaxColorNb = 92000;
75 void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
76                                          const QStringList& theStrings,
77                                          const QString&     theSep )
78 {
79   if ( !theFile.isOpen() || theStrings.isEmpty() )
80     return;
81   
82   QString aWriteStr = theStrings.join( theSep );
83   if ( aWriteStr.isEmpty() )
84     return;
85
86   QTextStream anOutStream( &theFile );
87   anOutStream << aWriteStr.toUtf8() << theSep << theSep;
88 }
89
90 bool HYDROData_Tool::ExtractGeneratedObjectName(const QString& theName, int& outValue, QString& thePrefName)
91 {
92   QStringList aLs = theName.split('_');
93   bool ok = false;
94   QString last = aLs.last();
95   outValue = last.toInt(&ok);
96   if (!ok)
97     return false;
98   int last_len = last.length();
99   int total_len = theName.length();
100   thePrefName = theName.left(total_len-last_len-1);
101   return true;
102 }
103
104 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
105                                             const QString&                    thePrefix,
106                                             const QStringList&                theUsedNames,
107                                             const bool                        theIsTryToUsePurePrefix )
108 {
109   QStringList aNamesList( theUsedNames );
110
111   // Collect all used names in the document
112   HYDROData_Iterator anIter( theDoc );
113   for( ; anIter.More(); anIter.Next() )
114   {
115     Handle(HYDROData_Entity) anObject = anIter.Current();
116     if( anObject.IsNull() )
117       continue;
118
119     QString anObjName = anObject->GetName();
120     if ( anObjName.isEmpty() )
121       continue;
122
123     aNamesList.append( anObjName );
124   }
125
126   QString aName;
127
128   if ( theIsTryToUsePurePrefix && !aNamesList.contains( thePrefix ) ) {
129     aName = thePrefix;
130   } else {
131     int anId = 1;
132     while( anId < aMaxNameId )
133     {
134       aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
135
136       // check that there are no other objects with the same name in the document
137       if ( !aNamesList.contains( aName ) )
138         break;
139     }
140   }
141
142   return aName;
143 }
144
145 bool HYDROData_Tool::IsGeometryObject( const Handle(HYDROData_Entity)& theObject )
146 {
147   if ( theObject.IsNull() )
148     return false;
149   
150   return theObject->IsKind( STANDARD_TYPE(HYDROData_ArtificialObject) ) ||
151          theObject->IsKind( STANDARD_TYPE(HYDROData_NaturalObject) );
152 }
153
154 void HYDROData_Tool::UpdateChildObjectName( const QString&                  theOldStr,
155                                             const QString&                  theNewStr,
156                                             const Handle(HYDROData_Entity)& theObject )
157 {
158   if ( theObject.IsNull() )
159     return;
160
161   QString anObjName = theObject->GetName();
162   if ( theOldStr.isEmpty() )
163   {
164     while ( anObjName.startsWith( '_' ) )
165       anObjName.remove( 0, 1 );
166
167     anObjName.prepend( theNewStr + "_" );
168   }
169   else if ( anObjName.startsWith( theOldStr ) )
170   {
171     anObjName.replace( 0, theOldStr.length(), theNewStr );
172   }
173   else
174     return;
175
176   theObject->SetName( anObjName );
177 }
178
179 QString HYDROData_Tool::GenerateNameForPython( const MapOfTreatedObjects& theTreatedObjects,
180                                                const QString&             thePrefix )
181 {
182   QString aName = thePrefix;
183   if ( !theTreatedObjects.contains( aName ) )
184     return aName;
185
186   int anId = 1;
187   while( anId < aMaxNameId )
188   {
189     aName = QString( "%1_%2" ).arg( thePrefix ).arg( QString::number( anId++ ) );
190
191     // check that there are no other objects with the same name
192     if ( !theTreatedObjects.contains( aName ) )
193       break;
194   }
195
196   return aName;
197 }
198 //======================================================================================================
199 TopAbs_State HYDROData_Tool::ComputePointState( const gp_XY& theXY, const TopoDS_Face& theFace )
200 {
201   TopAbs_State aState(TopAbs_UNKNOWN);
202   if(theFace.IsNull()) return aState;  
203   Standard_Real aTol = BRep_Tool::Tolerance(theFace);
204   BRepAdaptor_Surface Ads ( theFace, Standard_False );
205   Standard_Real toluv = Min ( Ads.UResolution(aTol), Ads.VResolution(aTol) ); 
206   if (toluv < 0.01)
207     toluv = 0.01; // there is no need to be more precise than 1cm a any case ! 
208                   // another solution could be to compute a tolerance related to the distance between the border nodes 
209   const gp_Pln& aPlane = Ads.Surface().Plane();
210   gp_Pnt aPnt(theXY.X(), theXY.Y(), 0.);
211   Standard_Real aU1, aV1;
212   ElSLib::Parameters(aPlane,aPnt, aU1, aV1);
213   BRepTopAdaptor_FClass2d aClassifier( theFace, toluv ); 
214   aState = aClassifier.Perform( gp_Pnt2d(aU1, aV1), Standard_False );
215   return aState;
216 }
217
218 double HYDROData_Tool::GetAltitudeForEdge( const TopoDS_Edge& theEdge,
219                                            const gp_XY& thePoint,
220                                            double theParameterTolerance,
221                                            double theSquareDistanceTolerance,
222                                            double theInvalidAltitude )
223 {
224   double aFirst, aLast;
225   Handle(Geom_Curve) aCurve = BRep_Tool::Curve( theEdge, aFirst, aLast );
226   if( aCurve.IsNull() )
227     return theInvalidAltitude;
228
229   gp_Pnt aFirstPnt, aLastPnt;
230
231   aCurve->D0( aFirst, aFirstPnt );
232   aCurve->D0( aLast, aLastPnt );
233
234   gp_Pnt2d aFirstPnt2d( aFirstPnt.X(), aFirstPnt.Y() );
235   gp_Pnt2d aLastPnt2d( aLastPnt.X(), aLastPnt.Y() );
236
237   double aFirstDist = 0;
238   double aLastDist = aFirstPnt2d.SquareDistance( aLastPnt2d );
239   double aNecDist = aFirstPnt2d.SquareDistance( thePoint );
240
241   while( fabs( aLast - aFirst ) > theParameterTolerance )
242   {
243     double aMid = ( aFirst + aLast ) / 2;
244     gp_Pnt aMidPnt;
245     aCurve->D0( aMid, aMidPnt );
246     double aDist = aFirstPnt2d.SquareDistance( gp_Pnt2d( aMidPnt.X(), aMidPnt.Y() ) );
247
248     if( aDist < aNecDist )
249       aFirst = aMid;
250     else
251       aLast = aMid;
252   }
253
254   double aMid = ( aFirst + aLast ) / 2;
255   gp_Pnt aMidPnt;
256   aCurve->D0( aMid, aMidPnt );
257
258   gp_Pnt2d aMidPnt2d( aMidPnt.X(), aMidPnt.Y() );
259   if( aMidPnt2d.SquareDistance( thePoint ) < theSquareDistanceTolerance )
260     return aMidPnt.Z();
261   else
262     return theInvalidAltitude;
263 }
264
265 double HYDROData_Tool::GetAltitudeForWire( const TopoDS_Wire& theWire,
266                                            const gp_XY& thePoint,
267                                            double theParameterTolerance,
268                                            double theSquareDistanceTolerance,
269                                            double theInvalidAltitude )
270 {
271   TopExp_Explorer anExp( theWire, TopAbs_EDGE );
272   for( ; anExp.More(); anExp.Next() )
273   {
274     double anAltitude = GetAltitudeForEdge( TopoDS::Edge( anExp.Current() ), thePoint,
275       theParameterTolerance, theSquareDistanceTolerance, theInvalidAltitude );
276     if( anAltitude != theInvalidAltitude )
277       return anAltitude;
278   }
279   return theInvalidAltitude;
280 }
281
282 TopoDS_Shape HYDROData_Tool::getFirstShapeFromGroup( const HYDROData_SequenceOfObjects& theGroups,
283                                                      const int                          theGroupId )
284 {
285   TopoDS_Shape aResShape;
286   if ( theGroupId < 1 || theGroupId > theGroups.Length() )
287     return aResShape;
288
289   Handle(HYDROData_ShapesGroup) aGroup =
290     Handle(HYDROData_ShapesGroup)::DownCast( theGroups.Value( theGroupId ) );
291   if ( aGroup.IsNull() )
292     return aResShape;
293
294   TopTools_SequenceOfShape aGroupShapes;
295   aGroup->GetShapes( aGroupShapes );
296
297   if ( !aGroupShapes.IsEmpty() )
298     aResShape = aGroupShapes.First();
299
300   return aResShape;
301 }
302
303 TCollection_ExtendedString HYDROData_Tool::toExtString( const QString& theStr )
304 {
305   TCollection_ExtendedString aRes;
306   if( !theStr.isEmpty() )
307   {
308           Standard_ExtString extStr = new Standard_ExtCharacter[ ( theStr.length() + 1 ) * 2 ];
309           memcpy( (void*)extStr, theStr.unicode(), theStr.length() * 2 );
310           ((short*)extStr)[theStr.length()] = '\0';
311     aRes = TCollection_ExtendedString( extStr );
312           delete [] extStr;
313   }
314   return aRes;
315 }
316
317 QString HYDROData_Tool::toQString( const TCollection_ExtendedString& theStr )
318 {
319   return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
320 }
321
322 Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor )
323 {
324   double r = theColor.red() / 255.0;
325   double g = theColor.green() / 255.0;
326   double b = theColor.blue() / 255.0;
327
328   return Quantity_Color( r, g, b, Quantity_TOC_RGB );
329 }
330
331 QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor )
332 {
333   int r = 255 * theColor.Red();
334   int g = 255 * theColor.Green();
335   int b = 255 * theColor.Blue();
336   return QColor( r, g, b );
337 }
338
339 QColor HYDROData_Tool::GenerateRandColor()
340 {
341   float aHue = ( rand()%1000 ) * 0.001f;
342
343   QColor aColor;
344   aColor.setHsl( (int)(aHue*255.), 200, 128 );
345   int r = aColor.red();
346   int g = aColor.green();
347   int b = aColor.blue();
348   return ( aColor.isValid() ? aColor : Qt::darkBlue );
349 }
350
351 void HYDROData_Tool::GenerateRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
352 {
353   for (int i = 1; i <= nbColorsToGen; i++)
354     theColors.append(HYDROData_Tool::GenerateRandColor());
355 }
356
357 bool HYDROData_Tool::GenerateNonRepeatableRandColors(int nbColorsToGen, QVector<QColor>& theColors)
358 {
359   if (nbColorsToGen > aMaxColorNb)
360     return false;
361   QSet<int> Codes;
362   float aHue;
363   theColors.clear();
364   do 
365   {
366     QColor aColor;
367     int H = rand()%360;
368     int S = rand()%256;
369     int Code = H*256+S;
370     if (Codes.contains(Code))
371       continue;
372     aColor.setHsl( H, S, 128 );
373     if (aColor.isValid())
374     {
375       theColors.append(aColor);
376       Codes.insert(Code);
377     }
378   } while (theColors.size() <= nbColorsToGen);
379   return true;
380 }
381
382
383 bool HYDROData_Tool::IsNan( double theValue )
384 {
385 #ifdef WIN32
386   return _isnan( theValue );
387 #else
388   return isnan( theValue );
389 #endif
390 }
391
392 bool HYDROData_Tool::IsInf( double theValue )
393 {
394 #ifdef WIN32
395   return (!_finite( theValue  ) );
396 #else
397   return isinf( theValue );
398 #endif  
399 }
400
401 static void MakeShellG(const NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>& FG,
402   TopoDS_Shape& outSh)
403 {
404   BRep_Builder bb;
405   NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>::Iterator itFG(FG);
406   if (FG.Extent() > 1)
407   {
408     //face nb > 1 => make shell
409     TopoDS_Shell outShell;
410     bb.MakeShell(outShell);
411     for (;itFG.More();itFG.Next())
412       bb.Add(outShell, itFG.Value());
413     outSh = outShell;
414   }
415   else if (FG.Extent() == 1)
416   {
417     outSh = itFG.Value(); //one face
418   }
419 }
420
421 TopoDS_Shape HYDROData_Tool::RebuildCmp(const TopoDS_Shape& in)
422 {
423   TopTools_IndexedDataMapOfShapeListOfShape mE2LF;
424   TopExp::MapShapesAndAncestors(in, TopAbs_EDGE, TopAbs_FACE, mE2LF);
425   if (mE2LF.IsEmpty())
426     return TopoDS_Shape();
427   NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> dfm;
428   //TopExp::MapShapes(aFuseShape, TopAbs_FACE, dfm);
429   TopExp_Explorer expf(in, TopAbs_FACE);
430   for (;expf.More(); expf.Next())
431     dfm.Add(TopoDS::Face(expf.Current()));
432
433   int nbF = dfm.Extent();
434   TopExp_Explorer exp_f(in, TopAbs_FACE);
435   const TopoDS_Face& FF = TopoDS::Face(exp_f.Current());
436   NCollection_List<TopoDS_Face> CurrFS;
437   NCollection_List<TopoDS_Face> NeighFS;
438   NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> PrF;
439   CurrFS.Append(FF);
440   NCollection_List<NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>> GL_F;
441   NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher> OneGr;
442   bool end = false;
443   while (!end)
444   {
445     NCollection_List<TopoDS_Face>::Iterator it_currfs(CurrFS);
446     NeighFS.Clear();
447     for (;it_currfs.More();it_currfs.Next())
448     {
449       const TopoDS_Face& CF = it_currfs.Value();
450       TopExp_Explorer exp_edge(CF, TopAbs_EDGE);
451       for (;exp_edge.More();exp_edge.Next())
452       {
453         const TopoDS_Shape& CE = exp_edge.Current();
454         const TopTools_ListOfShape& lsf = mE2LF.FindFromKey(CE);
455         TopTools_ListIteratorOfListOfShape ls_it(lsf); //always one face (since all faces are planar)
456         for (;ls_it.More();ls_it.Next())
457         {
458           const TopoDS_Face& F = TopoDS::Face(ls_it.Value());
459           if (F.IsSame(CF))
460             continue;
461           if (!PrF.Contains(F))
462           {
463             OneGr.Add(F);
464             NeighFS.Append(F);
465             PrF.Add(F);
466           }
467         }
468       }
469       OneGr.Add(CF);
470       PrF.Add(CF);
471     }
472     if (NeighFS.IsEmpty())
473     {
474       GL_F.Append(OneGr);
475       OneGr.Clear();
476       dfm.Subtract(PrF);
477       if (dfm.IsEmpty())
478         end = true;
479       else
480       {
481         NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>::Iterator itDm(dfm);
482         const TopoDS_Face& nsh = itDm.Key();
483         NeighFS.Append(nsh);
484       }
485     }
486     CurrFS = NeighFS;
487   }
488
489   TopoDS_Shape sh;
490
491   if (GL_F.Extent() > 1)
492   {
493     TopoDS_Compound cmp;
494     NCollection_List<NCollection_Map<TopoDS_Face, TopTools_ShapeMapHasher>>::Iterator itGL_F(GL_F);  
495     BRep_Builder bb;
496     bb.MakeCompound(cmp);
497     for (;itGL_F.More();itGL_F.Next())
498     {
499       MakeShellG(itGL_F.Value(), sh);
500       if (!sh.IsNull())
501         bb.Add(cmp, sh);
502     }
503     return  cmp;
504   }
505   else if (GL_F.Extent() == 1)
506   {
507     MakeShellG(GL_F.First(), sh);
508     return sh;
509   }
510   
511 }
512
513 TopoDS_Shape HYDROData_Tool::PolyXY2Face( const Handle(HYDROData_PolylineXY)& aPolyline )
514 {
515   //DEBTRACE("generateTopShape");
516   TopoDS_Face aResultFace = TopoDS_Face(); // --- result: default = null face
517
518   if (!aPolyline.IsNull())
519     {
520       TopoDS_Shape aPolylineShape = aPolyline->GetShape();
521 #ifdef DEB_IMZ
522       std::string brepName = "imz.brep";
523       BRepTools::Write(aPolylineShape, brepName.c_str());
524 #endif
525       TopTools_ListOfShape aWiresList;
526
527       if (!aPolylineShape.IsNull() && aPolylineShape.ShapeType() == TopAbs_WIRE)
528         {
529           // --- only one wire: try to make a face
530           //DEBTRACE("one wire: try to build a face");
531           const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aPolylineShape);
532           if (!aPolylineWire.IsNull())
533             {
534               BRepBuilderAPI_MakeFace aMakeFace(aPolylineWire, Standard_True);
535               aMakeFace.Build();
536               if (aMakeFace.IsDone())
537                 {
538                   //DEBTRACE(" a face with the only wire given");
539                   aResultFace = aMakeFace.Face();
540                 }
541             }
542         }
543       else
544         {
545           // --- a list of wires ? inventory of wires and edges
546           Handle(TopTools_HSequenceOfShape) aSeqWires = new TopTools_HSequenceOfShape;
547           Handle(TopTools_HSequenceOfShape) aSeqEdges = new TopTools_HSequenceOfShape;
548           TopExp_Explorer anExp(aPolylineShape, TopAbs_WIRE);
549           //DEBTRACE("list of wires ?");
550           for (; anExp.More(); anExp.Next())
551             {
552               if (!anExp.Current().IsNull())
553                 {
554                   const TopoDS_Wire& aWire = TopoDS::Wire(anExp.Current());
555                   aWiresList.Append(aWire);
556                   //DEBTRACE("  append wire");
557                   TopExp_Explorer it2(aWire, TopAbs_EDGE);
558                   for (; it2.More(); it2.Next())
559                     aSeqEdges->Append(it2.Current());
560                 }
561             }
562           if (aWiresList.IsEmpty())
563             return aResultFace; // --- no wires: null result
564
565           if (aSeqEdges->Length() > 1)
566             {
567               //DEBTRACE("try to connect all the edges together, build a unique wire and a face");
568               // --- try to create one wire by connecting edges with a distance tolerance (no necessity of sharing points)
569               ShapeAnalysis_FreeBounds::ConnectEdgesToWires(aSeqEdges, 1E-5, Standard_False, aSeqWires);
570
571               if (aSeqWires->Length() == 1)
572                 {
573                   // --- one wire: try to make a face
574                   const TopoDS_Wire& aPolylineWire = TopoDS::Wire(aSeqWires->Value(1));
575                   if (!aPolylineWire.IsNull())
576                     {
577                       BRepBuilderAPI_MakeFace aMakeFace(aPolylineWire, Standard_True);
578                       aMakeFace.Build();
579                       if (aMakeFace.IsDone())
580                         {
581                           //DEBTRACE("  a face from all the wires connected");
582                           aResultFace = aMakeFace.Face();
583                         }
584                     }
585                 }
586             }
587
588           if (aResultFace.IsNull())
589             {
590               //DEBTRACE("try to make a face with the first wire of the list and other wires as restrictions");
591               // --- try to make a face with the first wire of the list and other wires as restrictions
592               BRepAlgo_FaceRestrictor aFR;
593               TopoDS_Face aRefFace;
594               TopoDS_Shape aS = aWiresList.First();
595               BRepBuilderAPI_MakeFace aMakeFace(TopoDS::Wire(aWiresList.First()), Standard_True);
596               aMakeFace.Build();
597               if (aMakeFace.IsDone())
598                 {
599                   //DEBTRACE("  a face with first wire");
600                   aRefFace = aMakeFace.Face();
601                 }
602               if (!aRefFace.IsNull())
603                 {
604                   aFR.Init(aRefFace, Standard_False, Standard_True);
605                   TopTools_ListIteratorOfListOfShape anIt(aWiresList);
606                   for (; anIt.More(); anIt.Next())
607                     {
608                       TopoDS_Wire& aWire = TopoDS::Wire(anIt.Value());
609                       if (aWire.IsNull())
610                         continue;
611                       aFR.Add(aWire);
612                     }
613                   aFR.Perform();
614                   if (aFR.IsDone())
615                     {
616                       for (; aFR.More(); aFR.Next())
617                         {
618                           //DEBTRACE("  a restricted face");
619                           aResultFace = aFR.Current();
620                           break;
621                         }
622                     }
623                 }
624             }
625         }
626     }
627
628   if (aResultFace.IsNull())
629     return aResultFace;
630
631   //DEBTRACE("check the face");
632   BRepCheck_Analyzer anAnalyzer(aResultFace);
633   if (anAnalyzer.IsValid() && aResultFace.ShapeType() == TopAbs_FACE)
634   {
635     //DEBTRACE("face OK");
636     return aResultFace;
637   }
638   else
639   {
640     //DEBTRACE("bad face");
641   }
642   return TopoDS_Face();
643 }
644
645 void HYDROData_Tool::SetSIProgress(const Handle(Message_ProgressIndicator)& thePI)
646 {
647   StricklerInterpolationProgress() = thePI;
648 }
649   
650 const Handle(Message_ProgressIndicator)& HYDROData_Tool::GetSIProgress()
651 {
652   return StricklerInterpolationProgress();
653 }
654
655 Handle(Message_ProgressIndicator)& HYDROData_Tool::StricklerInterpolationProgress()
656 {
657   static Handle(Message_ProgressIndicator) aPI = NULL;
658   return aPI;
659 }
660
661 void HYDROData_Tool::SetZIProgress(const Handle(Message_ProgressIndicator)& thePI)
662 {
663   BathymetryInterpolationProgress() = thePI;
664 }
665   
666 const Handle(Message_ProgressIndicator)& HYDROData_Tool::GetZIProgress()
667 {
668   return BathymetryInterpolationProgress();
669 }
670
671 Handle(Message_ProgressIndicator)& HYDROData_Tool::BathymetryInterpolationProgress()
672 {
673   static Handle(Message_ProgressIndicator) aPI = NULL;
674   return aPI;
675 }
676
677 void HYDROData_Tool::SetTriangulationStatus(const ExecStatus& theStatus)
678 {
679   myTriangulationStatus = theStatus;
680 }
681
682 const HYDROData_Tool::ExecStatus& HYDROData_Tool::GetTriangulationStatus()
683 {
684   return myTriangulationStatus;
685 }
686
687 std::ostream& operator<<( std::ostream& theStream, const QString& theText )
688 {
689   theStream << theText.toStdString();
690   return theStream;
691 }
692
693 std::ostream& operator<<( std::ostream& theStream, const QColor& theColor )
694 {
695   theStream << "[" << theColor.red() << ", " << theColor.green() << ", " << theColor.blue() << "]";
696   return theStream;
697 }
698
699 std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape )
700 {
701   theStream << "[" << theShape.TShape().operator->() << "]";
702   return theStream;
703 }
704
705 std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace )
706 {
707   theStream << "[" << theFace.TShape().operator->() << "]";
708   return theStream;
709 }
710
711 std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY )
712 {
713   theStream << "(" << theXY.X() << "; " << theXY.Y() << ")";
714   return theStream;
715 }
716
717 bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 )
718 {
719   const double EPS = 1E-3;
720   return
721     fabs( thePoint1.X() - thePoint2.X() ) < EPS &&
722     fabs( thePoint1.Y() - thePoint2.Y() ) < EPS;
723
724 }