Salome HOME
ImportFromFile()
[modules/hydro.git] / src / HYDROData / HYDROData_Tool.cxx
index 48b9340f1593568871997f6892d3ea3375a6bc2a..7d1339241db68abd290f6b348fa52791943294ba 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
-#include "HYDROData_Tool.h"
-
-#include "HYDROData_ArtificialObject.h"
-#include "HYDROData_Image.h"
-#include "HYDROData_Iterator.h"
-#include "HYDROData_NaturalObject.h"
-#include "HYDROData_ShapesGroup.h"
-
+#include <HYDROData_Tool.h>
+#include <HYDROData_ArtificialObject.h>
+#include <HYDROData_Document.h>
+#include <HYDROData_Entity.h>
+#include <HYDROData_Iterator.h>
+#include <HYDROData_NaturalObject.h>
+#include <HYDROData_ShapesGroup.h>
+#include <QColor>
 #include <QFile>
 #include <QStringList>
 #include <QTextStream>
-
-#include <limits>
-#include <gp_Pnt.hxx>
-#include <gp_Pln.hxx>
-#include <ElSLib.hxx>
-#include <TopAbs_State.hxx>
+#include <BRep_Tool.hxx>
 #include <BRepAdaptor_Surface.hxx>
 #include <BRepTopAdaptor_FClass2d.hxx>
-#include <BRep_Tool.hxx>
+#include <ElSLib.hxx>
 #include <Geom_Curve.hxx>
+#include <gp_Pln.hxx>
+#include <Quantity_Color.hxx>
+#include <TopExp_Explorer.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Face.hxx>
+#include <TopoDS_Shape.hxx>
 #include <TopoDS_Wire.hxx>
-#include <TopExp_Explorer.hxx>
+#include <limits>
+#include <math.h>
 
 static int aMaxNameId = std::numeric_limits<int>::max();
 
@@ -58,38 +59,6 @@ void HYDROData_Tool::WriteStringsToFile( QFile&             theFile,
   anOutStream << aWriteStr << theSep << theSep;
 }
 
-void HYDROData_Tool::SetMustBeUpdatedObjects(
-  const Handle(HYDROData_Document)& theDoc  )
-{
-  bool anIsChanged = true;
-
-  // iterate until there is no changes because objects on all level of dependency must be updated
-  while ( anIsChanged )
-  {
-    anIsChanged = false;
-
-    HYDROData_Iterator anIter( theDoc );
-    for ( ; anIter.More(); anIter.Next() )
-    {
-      Handle(HYDROData_Entity) anObject = anIter.Current();
-      if ( anObject.IsNull() || anObject->IsMustBeUpdated() )
-        continue;
-
-      HYDROData_SequenceOfObjects aRefSeq = anObject->GetAllReferenceObjects();
-      for ( int i = 1, n = aRefSeq.Length(); i <= n; ++i )
-      {
-        Handle(HYDROData_Entity) aRefObject = aRefSeq.Value( i );
-        if ( aRefObject.IsNull() || !aRefObject->IsMustBeUpdated() )
-          continue;
-
-        anObject->SetToUpdate( true );
-        anIsChanged = true;
-        break;
-      }
-    }
-  }
-}
-
 QString HYDROData_Tool::GenerateObjectName( const Handle(HYDROData_Document)& theDoc,
                                             const QString&                    thePrefix,
                                             const QStringList&                theUsedNames,
@@ -304,3 +273,77 @@ QString HYDROData_Tool::toQString( const TCollection_ExtendedString& theStr )
 {
   return QString( (QChar*)theStr.ToExtString(), theStr.Length() );
 }
+
+Quantity_Color HYDROData_Tool::toOccColor( const QColor& theColor )
+{
+  double r = theColor.red() / 255.0;
+  double g = theColor.green() / 255.0;
+  double b = theColor.blue() / 255.0;
+
+  return Quantity_Color( r, g, b, Quantity_TOC_RGB );
+}
+
+QColor HYDROData_Tool::toQtColor( const Quantity_Color& theColor )
+{
+  int r = 255 * theColor.Red();
+  int g = 255 * theColor.Green();
+  int b = 255 * theColor.Blue();
+  return QColor( r, g, b );
+}
+
+bool HYDROData_Tool::IsNan( double theValue )
+{
+#ifdef WIN32
+  return _isnan( theValue );
+#else
+  return isnan( theValue );
+#endif
+}
+
+bool HYDROData_Tool::IsInf( double theValue )
+{
+#ifdef WIN32
+  return (!_finite( theValue  ) );
+#else
+  return isinf( theValue );
+#endif  
+}
+
+std::ostream& operator<<( std::ostream& theStream, const QString& theText )
+{
+  theStream << theText.toStdString();
+  return theStream;
+}
+
+std::ostream& operator<<( std::ostream& theStream, const QColor& theColor )
+{
+  theStream << "[" << theColor.red() << ", " << theColor.green() << ", " << theColor.blue() << "]";
+  return theStream;
+}
+
+std::ostream& operator<<( std::ostream& theStream, const TopoDS_Shape& theShape )
+{
+  theStream << "[" << theShape.TShape().operator->() << "]";
+  return theStream;
+}
+
+std::ostream& operator<<( std::ostream& theStream, const TopoDS_Face& theFace )
+{
+  theStream << "[" << theFace.TShape().operator->() << "]";
+  return theStream;
+}
+
+std::ostream& operator<<( std::ostream& theStream, const gp_XY& theXY )
+{
+  theStream << "(" << theXY.X() << "; " << theXY.Y() << ")";
+  return theStream;
+}
+
+bool operator == ( const gp_XY& thePoint1, const gp_XY& thePoint2 )
+{
+  const double EPS = 1E-3;
+  return
+    fabs( thePoint1.X() - thePoint2.X() ) < EPS &&
+    fabs( thePoint1.Y() - thePoint2.Y() ) < EPS;
+
+}