2017-06-29 04:48:26 -05:00
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//
|
|
|
|
// Copyright (C) 2017 Statoil ASA
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-06-29 04:48:26 -05:00
|
|
|
// ResInsight is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2017-06-29 04:48:26 -05:00
|
|
|
// ResInsight is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
// FITNESS FOR A PARTICULAR PURPOSE.
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
|
|
|
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
2017-06-29 04:48:26 -05:00
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "RicfFieldCapability.h"
|
2017-06-29 09:12:51 -05:00
|
|
|
#include "RicfMessages.h"
|
|
|
|
|
2019-06-10 13:42:20 -05:00
|
|
|
#include "RiaColorTools.h"
|
2017-06-29 04:48:26 -05:00
|
|
|
|
2019-06-10 13:42:20 -05:00
|
|
|
#include <QColor>
|
2017-06-29 04:48:26 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-06-29 04:48:26 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldReader<QString>::readFieldData( QString& fieldValue,
|
|
|
|
QTextStream& inputStream,
|
|
|
|
RicfMessages* errorMessageContainer,
|
|
|
|
bool stringsAreQuoted )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
fieldValue = "";
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
2017-06-29 04:48:26 -05:00
|
|
|
QString accumulatedFieldValue;
|
2019-09-06 03:40:57 -05:00
|
|
|
|
2017-06-29 04:48:26 -05:00
|
|
|
QChar currentChar;
|
2019-09-06 03:40:57 -05:00
|
|
|
bool validStringStart = !stringsAreQuoted;
|
|
|
|
bool validStringEnd = !stringsAreQuoted;
|
|
|
|
if ( stringsAreQuoted )
|
2019-07-30 02:21:43 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
|
|
|
if ( currentChar == QChar( '"' ) )
|
2019-07-30 02:21:43 -05:00
|
|
|
{
|
|
|
|
validStringStart = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( validStringStart )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
while ( !inputStream.atEnd() )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
|
|
|
if ( currentChar != QChar( '\\' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '"' ) ) // End Quote
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
// Reached end of string
|
2019-07-30 02:21:43 -05:00
|
|
|
validStringEnd = true;
|
2017-06-29 04:48:26 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
accumulatedFieldValue += currentChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
2017-06-29 04:48:26 -05:00
|
|
|
accumulatedFieldValue += currentChar;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !validStringStart )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
// Unexpected start of string, Missing '"'
|
|
|
|
// Error message
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError(
|
|
|
|
"String argument does not seem to be quoted. Missing the start '\"' in the \"" +
|
|
|
|
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
|
|
|
|
errorMessageContainer->currentCommand + "\"" );
|
2017-06-29 04:48:26 -05:00
|
|
|
// Could interpret as unquoted text
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( !validStringEnd )
|
2019-07-30 02:21:43 -05:00
|
|
|
{
|
|
|
|
// Unexpected end of string, Missing '"'
|
|
|
|
// Error message
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError( "String argument does not seem to be quoted. Missing the end '\"' in the \"" +
|
|
|
|
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
|
|
|
|
errorMessageContainer->currentCommand + "\"" );
|
2019-07-30 02:21:43 -05:00
|
|
|
// Could interpret as unquoted text
|
|
|
|
}
|
2017-06-29 04:48:26 -05:00
|
|
|
|
|
|
|
fieldValue = accumulatedFieldValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-06-29 04:48:26 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldWriter<QString>::writeFieldData( const QString& fieldValue, QTextStream& outputStream, bool quoteStrings )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
outputStream << "\"";
|
|
|
|
for ( int i = 0; i < fieldValue.size(); ++i )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( fieldValue[i] == QChar( '"' ) || fieldValue[i] == QChar( '\\' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
outputStream << "\\";
|
|
|
|
}
|
|
|
|
outputStream << fieldValue[i];
|
|
|
|
}
|
|
|
|
outputStream << "\"";
|
|
|
|
}
|
2018-09-19 02:25:27 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2018-09-19 02:25:27 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldReader<bool>::readFieldData( bool& fieldValue,
|
|
|
|
QTextStream& inputStream,
|
|
|
|
RicfMessages* errorMessageContainer,
|
|
|
|
bool stringsAreQuoted )
|
2018-09-19 02:25:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
2018-09-19 02:25:27 -05:00
|
|
|
QString accumulatedFieldValue;
|
2019-09-06 03:40:57 -05:00
|
|
|
QChar nextChar;
|
|
|
|
QChar currentChar;
|
|
|
|
while ( !inputStream.atEnd() )
|
2018-09-19 02:25:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
nextChar = errorMessageContainer->peekNextChar( inputStream );
|
|
|
|
if ( nextChar.isLetter() )
|
2018-09-19 02:25:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
2018-09-19 02:25:27 -05:00
|
|
|
accumulatedFieldValue += currentChar;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Accept TRUE or False in any case combination.
|
2019-09-06 03:40:57 -05:00
|
|
|
bool evaluatesToTrue = QString::compare( accumulatedFieldValue, QString( "true" ), Qt::CaseInsensitive ) == 0;
|
|
|
|
bool evaluatesToFalse = QString::compare( accumulatedFieldValue, QString( "false" ), Qt::CaseInsensitive ) == 0;
|
|
|
|
if ( evaluatesToTrue == evaluatesToFalse )
|
2018-09-19 02:25:27 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QString formatString(
|
|
|
|
"Boolean argument \"%1\" for the command \"%2\" does not evaluate to either true or false" );
|
2019-11-04 08:08:09 -06:00
|
|
|
QString errorMessage =
|
|
|
|
formatString.arg( errorMessageContainer->currentArgument ).arg( errorMessageContainer->currentCommand );
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError( errorMessage );
|
2018-09-19 02:25:27 -05:00
|
|
|
}
|
|
|
|
fieldValue = evaluatesToTrue;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldWriter<bool>::writeFieldData( const bool& fieldValue, QTextStream& outputStream, bool quoteStrings )
|
2018-09-19 02:25:27 -05:00
|
|
|
{
|
|
|
|
// Lower-case true/false is used in the documentation.
|
2019-09-06 03:40:57 -05:00
|
|
|
outputStream << ( fieldValue ? "true" : "false" );
|
2018-09-19 02:25:27 -05:00
|
|
|
}
|
2019-06-10 13:42:20 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldReader<cvf::Color3f>::readFieldData( cvf::Color3f& fieldValue,
|
|
|
|
QTextStream& inputStream,
|
|
|
|
RicfMessages* errorMessageContainer,
|
|
|
|
bool stringsAreQuoted )
|
2019-06-10 13:42:20 -05:00
|
|
|
{
|
|
|
|
QString fieldStringValue;
|
2019-09-06 03:40:57 -05:00
|
|
|
RicfFieldReader<QString>::readFieldData( fieldStringValue, inputStream, errorMessageContainer, stringsAreQuoted );
|
2019-06-10 13:42:20 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
QColor qColor( fieldStringValue );
|
|
|
|
if ( qColor.isValid() )
|
2019-06-10 13:42:20 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
fieldValue = RiaColorTools::fromQColorTo3f( qColor );
|
2019-06-10 13:42:20 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
///
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
void RicfFieldWriter<cvf::Color3f>::writeFieldData( const cvf::Color3f& fieldValue,
|
|
|
|
QTextStream& outputStream,
|
|
|
|
bool quoteStrings )
|
2019-06-10 13:42:20 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
QColor qColor = RiaColorTools::toQColor( fieldValue );
|
2019-06-10 13:42:20 -05:00
|
|
|
QString fieldStringValue = qColor.name();
|
2019-09-06 03:40:57 -05:00
|
|
|
RicfFieldWriter<QString>::writeFieldData( fieldStringValue, outputStream, quoteStrings );
|
2019-06-10 13:42:20 -05:00
|
|
|
}
|