Salome HOME
SIP: HYDROData_ObstacleAltitude is included.
[modules/hydro.git] / src / HYDROData / HYDROData_Image.cxx
index 0d1d5bcb07dfcd3c8dc070e856bc69071fdd90bb..e1ea0bfbf4bd824948fff0994649989a830e78e7 100644 (file)
@@ -17,6 +17,9 @@
 #include <ImageComposer_MetaTypes.h>
 
 #include <QStringList>
+#include <QFile>
+
+#include <boost/math/special_functions/fpclassify.hpp>
 
 static const Standard_GUID GUID_SELF_SPLITTED("997995aa-5c19-40bf-9a60-ab4b70ad04d8");
 static const Standard_GUID GUID_HAS_LOCAL_POINTS("FD8841AA-FC44-42fa-B6A7-0F682CCC6F27");
@@ -598,6 +601,80 @@ bool HYDROData_Image::GetGlobalPoints( TransformationMode& theMode,
   return true;
 }
 
+bool HYDROData_Image::SetGlobalPointsFromFile( const QString& theFileName )
+{
+  bool aRes = false;
+
+  // Try to open the file
+  QFile aFile( theFileName );
+  if ( !aFile.exists() || !aFile.open( QIODevice::ReadOnly ) ) {
+    return aRes;
+  }
+
+  QPointF aPointA, aPointB;
+  double aXmin, anYmin, aXmax, anYmax;
+  aXmin = anYmin = aXmax = anYmax = -1;
+
+  while ( !aFile.atEnd() && 
+          ( aXmin < 0 || anYmin < 0 || aXmax < 0 || anYmax < 0 ) ) {
+    // Read line
+    QString aLine = aFile.readLine().simplified();
+    aLine.replace( " ", "" );
+    if ( aLine.isEmpty() ) {
+      continue;
+    }
+
+    // Try to read double value after ":"
+    bool isDoubleOk = false;
+    double aDoubleValue = -1;
+    QStringList aValues = aLine.split( ":", QString::SkipEmptyParts );
+    if ( aValues.count() == 2 ) {
+      aDoubleValue = aValues.last().toDouble( &isDoubleOk );
+    }
+
+    // Check the result
+    if ( !isDoubleOk ||
+         boost::math::isnan( aDoubleValue ) ||
+         boost::math::isinf( aDoubleValue ) ) {
+      continue;
+    }
+
+    // Set the value
+    if ( aLine.startsWith( "Xminimum" ) ) {
+      aXmin = aDoubleValue;    
+    } 
+    else if ( aLine.startsWith( "Yminimum" ) ) {
+      anYmin = aDoubleValue; 
+    }
+    else if ( aLine.startsWith( "Xmaximum" ) ) {
+      aXmax = aDoubleValue;
+    }
+    else if ( aLine.startsWith( "Ymaximum" ) ) {
+      anYmax = aDoubleValue;  
+    }
+  }
+
+  // Close the file
+  aFile.close();
+
+  if ( aXmin >= 0 && anYmin >= 0 ) {
+    aPointA.setX( aXmin );
+    aPointA.setY( anYmin );
+  }
+    
+  if ( aXmax >= 0 && anYmax >= 0 ) {
+    aPointB.setX( aXmax );
+    aPointB.setY( anYmax );
+  }
+
+  if ( !aPointA.isNull() && !aPointB.isNull() ) {
+    SetGlobalPoints( ManualCartesian, aPointA, aPointB );
+    aRes = true;
+  }
+
+  return aRes;
+}
+
 bool HYDROData_Image::HasGlobalPoints() const
 {
   TDF_Label aLabel = myLab.FindChild( DataTag_TrsfPoints, false );