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 "RicfObjectCapability.h"
|
|
|
|
#include "RicfFieldHandle.h"
|
2017-06-29 09:12:51 -05:00
|
|
|
#include "RicfMessages.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafPdmObjectHandle.h"
|
|
|
|
#include "cafPdmXmlFieldHandle.h"
|
|
|
|
#include <QTextStream>
|
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
|
|
|
RicfObjectCapability::RicfObjectCapability( caf::PdmObjectHandle* owner, bool giveOwnership )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
m_owner = owner;
|
2019-09-06 03:40:57 -05:00
|
|
|
m_owner->addCapability( this, giveOwnership );
|
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
|
|
|
RicfObjectCapability::~RicfObjectCapability() {}
|
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 RicfObjectCapability::readFields( QTextStream& inputStream,
|
|
|
|
caf::PdmObjectFactory* objectFactory,
|
|
|
|
RicfMessages* errorMessageContainer )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
std::set<QString> readFields;
|
2019-09-06 03:40:57 -05:00
|
|
|
bool isLastArgumentRead = false;
|
2017-06-29 09:12:51 -05:00
|
|
|
while ( !inputStream.atEnd() && !isLastArgumentRead )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
// Read field keyword
|
2019-09-06 03:40:57 -05:00
|
|
|
bool fieldDataFound = false;
|
|
|
|
bool isEndOfArgumentFound = false;
|
2017-06-29 04:48:26 -05:00
|
|
|
QString keyword;
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
QChar currentChar;
|
2019-09-06 03:40:57 -05:00
|
|
|
while ( !inputStream.atEnd() )
|
2017-06-29 06:18:19 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
2017-06-29 06:18:19 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '=' ) || currentChar == QChar( ')' ) || currentChar == QChar( ',' ) ||
|
|
|
|
currentChar.isSpace() )
|
2017-06-29 06:18:19 -05:00
|
|
|
{
|
2017-08-04 06:58:32 -05:00
|
|
|
break;
|
2017-06-29 06:18:19 -05:00
|
|
|
}
|
2017-08-04 06:58:32 -05:00
|
|
|
else
|
|
|
|
{
|
|
|
|
keyword += currentChar;
|
|
|
|
}
|
2017-06-29 06:18:19 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar.isSpace() )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
|
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '=' ) )
|
2017-08-04 06:58:32 -05:00
|
|
|
{
|
|
|
|
fieldDataFound = true;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( currentChar == QChar( ')' ) )
|
2017-08-04 06:58:32 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( !keyword.isNull() )
|
2017-08-04 06:58:32 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError(
|
|
|
|
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
|
|
|
|
.arg( keyword )
|
|
|
|
.arg( errorMessageContainer->currentCommand ) );
|
2017-08-04 06:58:32 -05:00
|
|
|
}
|
|
|
|
isLastArgumentRead = true;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
else if ( currentChar == QChar( ',' ) )
|
2017-08-04 06:58:32 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError(
|
|
|
|
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
|
|
|
|
.arg( keyword )
|
|
|
|
.arg( errorMessageContainer->currentCommand ) );
|
2017-08-04 06:58:32 -05:00
|
|
|
isEndOfArgumentFound = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addError(
|
|
|
|
QString( "Can't find the '=' after the argument named '%1' in the command '%2'" )
|
|
|
|
.arg( keyword )
|
|
|
|
.arg( errorMessageContainer->currentCommand ) );
|
2017-08-04 06:58:32 -05:00
|
|
|
}
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( readFields.count( keyword ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
// Warning message: Referenced the same argument several times
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addWarning( "The argument: \"" + keyword +
|
|
|
|
"\" is referenced several times in the command: \"" +
|
|
|
|
errorMessageContainer->currentCommand + "\"" );
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( fieldDataFound )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2017-06-29 09:12:51 -05:00
|
|
|
// Make field read its data
|
2017-06-29 04:48:26 -05:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
caf::PdmFieldHandle* fieldHandle = m_owner->findField( keyword );
|
2017-06-29 09:12:51 -05:00
|
|
|
if ( fieldHandle && fieldHandle->xmlCapability() && fieldHandle->capability<RicfFieldHandle>() )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2017-06-29 09:12:51 -05:00
|
|
|
caf::PdmXmlFieldHandle* xmlFieldHandle = fieldHandle->xmlCapability();
|
2019-09-06 03:40:57 -05:00
|
|
|
RicfFieldHandle* rcfField = fieldHandle->capability<RicfFieldHandle>();
|
2017-06-29 04:48:26 -05:00
|
|
|
|
2017-06-29 09:12:51 -05:00
|
|
|
if ( xmlFieldHandle->isIOReadable() )
|
|
|
|
{
|
2017-06-29 09:29:50 -05:00
|
|
|
errorMessageContainer->currentArgument = keyword;
|
2019-09-06 03:40:57 -05:00
|
|
|
rcfField->readFieldData( inputStream, objectFactory, errorMessageContainer );
|
2017-06-29 09:29:50 -05:00
|
|
|
errorMessageContainer->currentArgument = keyword;
|
2017-06-29 09:12:51 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Error message: Unknown argument name
|
2019-09-06 03:40:57 -05:00
|
|
|
errorMessageContainer->addWarning( "The argument: \"" + keyword + "\" does not exist in the command: \"" +
|
|
|
|
errorMessageContainer->currentCommand + "\"" );
|
2017-06-29 09:12:51 -05:00
|
|
|
}
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
// Skip to end of argument ',' or end of call ')'
|
|
|
|
if ( !( isLastArgumentRead || isEndOfArgumentFound ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
QChar currentChar;
|
2019-09-06 03:40:57 -05:00
|
|
|
bool isOutsideQuotes = true;
|
2017-06-29 04:48:26 -05:00
|
|
|
while ( !inputStream.atEnd() )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
2017-06-29 04:48:26 -05:00
|
|
|
if ( isOutsideQuotes )
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( ',' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( ')' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2017-06-29 09:12:51 -05:00
|
|
|
isLastArgumentRead = true;
|
2017-06-29 04:48:26 -05:00
|
|
|
break;
|
|
|
|
}
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '\"' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
isOutsideQuotes = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '\"' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
isOutsideQuotes = true;
|
|
|
|
}
|
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
if ( currentChar == QChar( '\\' ) )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2019-09-06 03:40:57 -05:00
|
|
|
currentChar = errorMessageContainer->readCharWithLineNumberCount( inputStream );
|
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 RicfObjectCapability::writeFields( QTextStream& outputStream ) const
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
std::vector<caf::PdmFieldHandle*> fields;
|
2019-09-06 03:40:57 -05:00
|
|
|
m_owner->fields( fields );
|
2017-06-29 04:48:26 -05:00
|
|
|
int writtenFieldCount = 0;
|
|
|
|
for ( size_t it = 0; it < fields.size(); ++it )
|
|
|
|
{
|
|
|
|
const caf::PdmXmlFieldHandle* xmlField = fields[it]->xmlCapability();
|
2019-09-06 03:40:57 -05:00
|
|
|
const RicfFieldHandle* rcfField = fields[it]->capability<RicfFieldHandle>();
|
2017-06-29 04:48:26 -05:00
|
|
|
if ( rcfField && xmlField && xmlField->isIOWritable() )
|
|
|
|
{
|
|
|
|
QString keyword = xmlField->fieldHandle()->keyword();
|
2019-09-06 03:40:57 -05:00
|
|
|
CAF_ASSERT( caf::PdmXmlObjectHandle::isValidXmlElementName( keyword ) );
|
2017-06-29 04:48:26 -05:00
|
|
|
|
|
|
|
if ( writtenFieldCount >= 1 )
|
|
|
|
{
|
|
|
|
outputStream << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
outputStream << keyword << " = ";
|
2019-09-06 03:40:57 -05:00
|
|
|
rcfField->writeFieldData( outputStream );
|
|
|
|
|
2018-11-07 03:38:00 -06:00
|
|
|
writtenFieldCount++;
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|