+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;
+}
+