mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#1666 Add CommandFileInterface system
This commit is contained in:
@@ -46,6 +46,7 @@ include_directories(
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/GridBox
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ModelVisualization/Intersections
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/UserInterface
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/CommandFileInterface/Core
|
||||
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/ProjectDataModel/Completions
|
||||
@@ -122,6 +123,8 @@ list( APPEND REFERENCED_CMAKE_FILES
|
||||
Commands/ViewLink/CMakeLists_files.cmake
|
||||
Commands/WellLogCommands/CMakeLists_files.cmake
|
||||
Commands/WellPathCommands/CMakeLists_files.cmake
|
||||
|
||||
CommandFileInterface/Core/CMakeLists_files.cmake
|
||||
)
|
||||
|
||||
option (RESINSIGHT_INCLUDE_APPLICATION_UNIT_TESTS "Include ApplicationCode Unit Tests" OFF)
|
||||
|
@@ -0,0 +1,26 @@
|
||||
|
||||
set (SOURCE_GROUP_HEADER_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifcCommandFileReader.h
|
||||
)
|
||||
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfCommandObject.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldCapability.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfFieldHandle.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RicfObjectCapability.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/RifcCommandFileReader.cpp
|
||||
)
|
||||
|
||||
list(APPEND CODE_HEADER_FILES
|
||||
${SOURCE_GROUP_HEADER_FILES}
|
||||
)
|
||||
|
||||
list(APPEND CODE_SOURCE_FILES
|
||||
${SOURCE_GROUP_SOURCE_FILES}
|
||||
)
|
||||
|
||||
source_group( "CommandFileInterface\\Core" FILES ${SOURCE_GROUP_HEADER_FILES} ${SOURCE_GROUP_SOURCE_FILES} ${CMAKE_CURRENT_LIST_DIR}/CMakeLists_files.cmake )
|
@@ -0,0 +1,37 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCommandObject::RicfCommandObject(): RicfObjectCapability(this, false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfCommandObject::~RicfCommandObject()
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,43 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
#include "cafPdmObject.h"
|
||||
#include "RicfObjectCapability.h"
|
||||
#include "RicfFieldCapability.h"
|
||||
|
||||
#define RICF_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis) \
|
||||
CAF_PDM_InitField(field, keyword, default, uiName, iconResourceName, toolTip, whatsThis); \
|
||||
AddRicfCapabilityToField(field)
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandObject : public caf::PdmObject, public RicfObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfCommandObject();
|
||||
~RicfCommandObject();
|
||||
|
||||
virtual void execute() = 0;
|
||||
};
|
||||
|
||||
|
@@ -0,0 +1,85 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfFieldCapability.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream)
|
||||
{
|
||||
fieldValue = "";
|
||||
|
||||
inputStream.skipWhiteSpace();
|
||||
QString accumulatedFieldValue;
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
if ( currentChar == QChar('"') )
|
||||
{
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
if ( currentChar != QChar('\\') )
|
||||
{
|
||||
if ( currentChar == QChar('"') ) // End Quote
|
||||
{
|
||||
// Reached end of string
|
||||
// Read and eat , or ) ?
|
||||
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
accumulatedFieldValue += currentChar;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
accumulatedFieldValue += currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unexpected start of string, Missing '"'
|
||||
// Error message
|
||||
// Could interpret as unquoted text
|
||||
}
|
||||
|
||||
fieldValue = accumulatedFieldValue;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextStream& outputStream)
|
||||
{
|
||||
outputStream << "\"";
|
||||
for ( int i = 0; i < fieldValue.size(); ++i )
|
||||
{
|
||||
if ( fieldValue[i] == QChar('"') || fieldValue[i] == QChar('\\') )
|
||||
{
|
||||
outputStream << "\\";
|
||||
}
|
||||
outputStream << fieldValue[i];
|
||||
}
|
||||
outputStream << "\"";
|
||||
}
|
@@ -0,0 +1,99 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "RicfFieldHandle.h"
|
||||
|
||||
#include <QTextStream>
|
||||
#include <QString>
|
||||
|
||||
template <typename DataType>
|
||||
struct RicfFieldReader
|
||||
{
|
||||
static void readFieldData(DataType & fieldValue, QTextStream& inputStream)
|
||||
{
|
||||
inputStream >> fieldValue;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename DataType>
|
||||
struct RicfFieldWriter
|
||||
{
|
||||
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream)
|
||||
{
|
||||
outputStream << fieldValue;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RicfFieldReader<QString>
|
||||
{
|
||||
static void readFieldData(QString & fieldValue, QTextStream& inputStream);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct RicfFieldWriter<QString>
|
||||
{
|
||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
||||
};
|
||||
|
||||
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
template < typename FieldType>
|
||||
class RicfFieldCapability : public RicfFieldHandle
|
||||
{
|
||||
public:
|
||||
RicfFieldCapability(FieldType* field, bool giveOwnership) : RicfFieldHandle(field, giveOwnership) { m_field = field; }
|
||||
|
||||
// Xml Serializing
|
||||
public:
|
||||
virtual void readFieldData (QTextStream& inputStream, caf::PdmObjectFactory* objectFactory) override
|
||||
{
|
||||
//m_field->xmlCapability()->assertValid();
|
||||
typename FieldType::FieldDataType value;
|
||||
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream);
|
||||
m_field->setValue(value);
|
||||
}
|
||||
|
||||
virtual void writeFieldData(QTextStream& outputStream) const override
|
||||
{
|
||||
//m_field->xmlCapability()->assertValid();
|
||||
RicfFieldWriter<typename FieldType::FieldDataType>::writeFieldData(m_field->value(), outputStream);
|
||||
}
|
||||
|
||||
private:
|
||||
FieldType* m_field;
|
||||
};
|
||||
|
||||
|
||||
template<typename FieldType>
|
||||
void AddRicfCapabilityToField(FieldType* field)
|
||||
{
|
||||
if(field->template capability< RicfFieldCapability<FieldType> >() == NULL)
|
||||
{
|
||||
new RicfFieldCapability<FieldType>(field, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -0,0 +1,39 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfFieldHandle.h"
|
||||
#include "cafPdmFieldHandle.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfFieldHandle::RicfFieldHandle(caf::PdmFieldHandle* owner, bool giveOwnership)
|
||||
{
|
||||
m_owner = owner;
|
||||
owner->addCapability(this, giveOwnership);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfFieldHandle::~RicfFieldHandle()
|
||||
{
|
||||
|
||||
}
|
51
ApplicationCode/CommandFileInterface/Core/RicfFieldHandle.h
Normal file
51
ApplicationCode/CommandFileInterface/Core/RicfFieldHandle.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
#include "cafPdmFieldCapability.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectFactory;
|
||||
class PdmFieldHandle;
|
||||
}
|
||||
|
||||
class QTextStream;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfFieldHandle : public caf::PdmFieldCapability
|
||||
{
|
||||
public:
|
||||
RicfFieldHandle(caf::PdmFieldHandle* owner , bool giveOwnership);
|
||||
|
||||
virtual ~RicfFieldHandle();
|
||||
|
||||
virtual void readFieldData (QTextStream& inputStream, caf::PdmObjectFactory* objectFactory) = 0;
|
||||
virtual void writeFieldData(QTextStream& outputStream) const = 0;
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* m_owner;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
@@ -0,0 +1,163 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RicfObjectCapability.h"
|
||||
#include "cafPdmObjectHandle.h"
|
||||
#include <QTextStream>
|
||||
#include "RicfFieldHandle.h"
|
||||
#include "cafPdmXmlFieldHandle.h"
|
||||
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfObjectCapability::RicfObjectCapability(caf::PdmObjectHandle* owner, bool giveOwnership)
|
||||
{
|
||||
m_owner = owner;
|
||||
m_owner->addCapability(this, giveOwnership);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
RicfObjectCapability::~RicfObjectCapability()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::readFields(QTextStream& inputStream, caf::PdmObjectFactory* objectFactory)
|
||||
{
|
||||
std::set<QString> readFields;
|
||||
bool readLastArgument = false;
|
||||
while ( !inputStream.atEnd() && !readLastArgument )
|
||||
{
|
||||
// Read field keyword
|
||||
|
||||
QString keyword;
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
if ( currentChar.isSpace() || currentChar == QChar('=') )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
keyword += currentChar;
|
||||
}
|
||||
|
||||
if ( readFields.count(keyword) )
|
||||
{
|
||||
// Warning message: Referenced the same argument several times
|
||||
}
|
||||
}
|
||||
|
||||
// Make field read its data
|
||||
|
||||
caf::PdmFieldHandle* fieldHandle = m_owner->findField(keyword);
|
||||
if ( fieldHandle && fieldHandle->xmlCapability() && fieldHandle->capability<RicfFieldHandle>() )
|
||||
{
|
||||
caf::PdmXmlFieldHandle* xmlFieldHandle = fieldHandle->xmlCapability();
|
||||
RicfFieldHandle* rcfField = fieldHandle->capability<RicfFieldHandle>();
|
||||
|
||||
if ( xmlFieldHandle->isIOReadable() )
|
||||
{
|
||||
rcfField->readFieldData(inputStream, objectFactory);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// Error message: Unknown argument name
|
||||
}
|
||||
|
||||
// Skip to end of argument ',' or end of call ')'
|
||||
{
|
||||
QChar currentChar;
|
||||
bool isOutsideQuotes = true;
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
if ( isOutsideQuotes )
|
||||
{
|
||||
if ( currentChar == QChar(',') )
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if ( currentChar == QChar(')') )
|
||||
{
|
||||
readLastArgument = true;
|
||||
break;
|
||||
}
|
||||
if ( currentChar == QChar('\"') )
|
||||
{
|
||||
isOutsideQuotes = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( currentChar == QChar('\"') )
|
||||
{
|
||||
isOutsideQuotes = true;
|
||||
}
|
||||
|
||||
if ( currentChar == QChar('\\') )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfObjectCapability::writeFields(QTextStream& outputStream) const
|
||||
{
|
||||
std::vector<caf::PdmFieldHandle*> fields;
|
||||
m_owner->fields(fields);
|
||||
int writtenFieldCount = 0;
|
||||
for ( size_t it = 0; it < fields.size(); ++it )
|
||||
{
|
||||
const caf::PdmXmlFieldHandle* xmlField = fields[it]->xmlCapability();
|
||||
const RicfFieldHandle* rcfField = fields[it]->capability<RicfFieldHandle>();
|
||||
if ( rcfField && xmlField && xmlField->isIOWritable() )
|
||||
{
|
||||
QString keyword = xmlField->fieldHandle()->keyword();
|
||||
CAF_ASSERT(caf::PdmXmlObjectHandle::isValidXmlElementName(keyword));
|
||||
|
||||
if ( writtenFieldCount >= 1 )
|
||||
{
|
||||
outputStream << ", ";
|
||||
++writtenFieldCount;
|
||||
}
|
||||
|
||||
outputStream << keyword << " = ";
|
||||
rcfField->writeFieldData(outputStream);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#pragma once
|
||||
#include "cafPdmObjectCapability.h"
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectHandle;
|
||||
class PdmObjectFactory;
|
||||
}
|
||||
|
||||
class QTextStream;
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfObjectCapability : public caf::PdmObjectCapability
|
||||
{
|
||||
public:
|
||||
RicfObjectCapability(caf::PdmObjectHandle* owner, bool giveOwnership);
|
||||
|
||||
virtual ~RicfObjectCapability();
|
||||
|
||||
void readFields(QTextStream& inputStream, caf::PdmObjectFactory* objectFactory);
|
||||
void writeFields(QTextStream& outputStream) const;
|
||||
|
||||
private:
|
||||
caf::PdmObjectHandle* m_owner;
|
||||
};
|
||||
|
||||
|
||||
|
@@ -0,0 +1,124 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RifcCommandFileReader.h"
|
||||
|
||||
#include "RicfCommandObject.h"
|
||||
#include "RicfObjectCapability.h"
|
||||
|
||||
#include "cafPdmObjectFactory.h"
|
||||
|
||||
#include <QTextStream>
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
std::vector<RicfCommandObject*> RicfCommandFileReader::readCommands(QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory)
|
||||
{
|
||||
std::vector<RicfCommandObject*> readCommands;
|
||||
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
|
||||
// Read command name
|
||||
QString commandName;
|
||||
bool foundStartBracet = false;
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
QChar currentChar;
|
||||
inputStream >> currentChar;
|
||||
if ( currentChar.isSpace() )
|
||||
{
|
||||
inputStream.skipWhiteSpace();
|
||||
QChar isBracket('a');
|
||||
inputStream >> isBracket;
|
||||
if ( isBracket != QChar('(') )
|
||||
{
|
||||
// Error, could not find start bracket for command
|
||||
return readCommands;
|
||||
}
|
||||
break;
|
||||
}
|
||||
else if ( currentChar == QChar('(') )
|
||||
{
|
||||
break;
|
||||
}
|
||||
commandName += currentChar;
|
||||
}
|
||||
}
|
||||
|
||||
CAF_ASSERT(objectFactory);
|
||||
caf::PdmObjectHandle* obj = objectFactory->create(commandName);
|
||||
RicfCommandObject* cObj = dynamic_cast<RicfCommandObject*>(obj);
|
||||
|
||||
if ( cObj == nullptr )
|
||||
{
|
||||
// Error: Unknown command
|
||||
// Skip to end of command
|
||||
QChar currentChar;
|
||||
bool isOutsideQuotes = true;
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
if ( isOutsideQuotes )
|
||||
{
|
||||
if ( currentChar == QChar(')') )
|
||||
{
|
||||
break;
|
||||
}
|
||||
if ( currentChar == QChar('\"') )
|
||||
{
|
||||
isOutsideQuotes = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( currentChar == QChar('\"') )
|
||||
{
|
||||
isOutsideQuotes = true;
|
||||
}
|
||||
|
||||
if ( currentChar == QChar('\\') )
|
||||
{
|
||||
inputStream >> currentChar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
readCommands.push_back(cObj);
|
||||
auto rcfCap = cObj->capability<RicfObjectCapability>();
|
||||
rcfCap->readFields(inputStream, objectFactory);
|
||||
}
|
||||
}
|
||||
|
||||
return readCommands;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfCommandFileReader::writeCommands(QTextStream& outputStream, const std::vector<RicfCommandObject*>& commandsToWrite)
|
||||
{
|
||||
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Copyright (C) 2017 Statoil ASA
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// See the GNU General Public License at <http://www.gnu.org/licenses/gpl.html>
|
||||
// for more details.
|
||||
//
|
||||
/////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class RicfCommandObject;
|
||||
class QTextStream;
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectFactory;
|
||||
}
|
||||
|
||||
//==================================================================================================
|
||||
//
|
||||
//
|
||||
//
|
||||
//==================================================================================================
|
||||
class RicfCommandFileReader
|
||||
{
|
||||
public:
|
||||
static std::vector<RicfCommandObject*> readCommands(QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory);
|
||||
static void writeCommands(QTextStream& outputStream,
|
||||
const std::vector<RicfCommandObject*>& commandsToWrite);
|
||||
};
|
@@ -10,6 +10,7 @@ set (SOURCE_GROUP_HEADER_FILES
|
||||
set (SOURCE_GROUP_SOURCE_FILES
|
||||
${CEE_CURRENT_LIST_DIR}cvfGeometryTools-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}Ert-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifcCommandCore-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifEclipseInputFileTools-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseOutput-Test.cpp
|
||||
${CEE_CURRENT_LIST_DIR}RifReaderEclipseSummary-Test.cpp
|
||||
|
70
ApplicationCode/UnitTests/RifcCommandCore-Test.cpp
Normal file
70
ApplicationCode/UnitTests/RifcCommandCore-Test.cpp
Normal file
@@ -0,0 +1,70 @@
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "RifcCommandFileReader.h"
|
||||
#include "RicfCommandObject.h"
|
||||
#include "cafPdmField.h"
|
||||
|
||||
class TestCommand1: public RicfCommandObject
|
||||
{
|
||||
CAF_PDM_HEADER_INIT;
|
||||
public:
|
||||
TestCommand1()
|
||||
{
|
||||
RICF_InitField(&m_textArgument, "TextArgument", QString(), "TextArgument", "", "", "");
|
||||
RICF_InitField(&m_doubleArgument, "DoubleArgument", 0.0, "DoubleArgument", "", "", "");
|
||||
RICF_InitField(&m_intArgument, "IntArgument", 0, "IntArgument", "", "", "");
|
||||
}
|
||||
|
||||
virtual void execute() override { std::cout << "TestCommand1::execute(" << "\"" << m_textArgument().toStdString() << "\", "
|
||||
<< m_doubleArgument() << ", "
|
||||
<< m_intArgument << ");" << std::endl; }
|
||||
|
||||
caf::PdmField<QString> m_textArgument;
|
||||
caf::PdmField<double> m_doubleArgument;
|
||||
caf::PdmField<int> m_intArgument;
|
||||
};
|
||||
|
||||
CAF_PDM_SOURCE_INIT(TestCommand1, "TestCommand1");
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
TEST(RicfCommands, Test1)
|
||||
{
|
||||
TestCommand1* tc = new TestCommand1;
|
||||
tc->m_textArgument = "textValue";
|
||||
tc->execute();
|
||||
delete tc;
|
||||
|
||||
QString commandString("TestCommand1(IntArgument=3, TextArgument=\"Dette er en tekst, \\\"og\\\" jeg er: (happy)\", DoubleArgument=5.0e3) \n"
|
||||
"TestCommand1 ( IntArgument = 4 , \n TextArgument = \"Dette er en tekst, \\\"og\\\" jeg er: (happy)\", \n DoubleArgument = 5.0e-3 ) \n"
|
||||
" TestCommand1(TextArgument=\"Litt kortere tekst.\") \n");
|
||||
std::cout << commandString.toStdString() << std::endl;
|
||||
QTextStream inputStream(&commandString);
|
||||
|
||||
auto objects = RicfCommandFileReader::readCommands(inputStream, caf::PdmDefaultObjectFactory::instance());
|
||||
EXPECT_EQ(3, objects.size());
|
||||
|
||||
auto tc2 = dynamic_cast<TestCommand1*>(objects[0]);
|
||||
EXPECT_EQ(39, tc2->m_textArgument().size());
|
||||
EXPECT_EQ(5.0e3, tc2->m_doubleArgument());
|
||||
|
||||
tc2 = dynamic_cast<TestCommand1*>(objects[1]);
|
||||
EXPECT_EQ(37, tc2->m_textArgument().size());
|
||||
EXPECT_EQ(5e-3, tc2->m_doubleArgument());
|
||||
|
||||
tc2 = dynamic_cast<TestCommand1*>(objects[2]);
|
||||
EXPECT_EQ(19, tc2->m_textArgument().size());
|
||||
EXPECT_EQ(0.0, tc2->m_doubleArgument());
|
||||
|
||||
for (auto obj: objects)
|
||||
{
|
||||
obj->execute();
|
||||
}
|
||||
|
||||
for (auto obj: objects)
|
||||
{
|
||||
delete(obj);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user