mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
#4526 enable setting flow diagnostics results through Python
This commit is contained in:
parent
979101fe96
commit
f61df01694
@ -23,19 +23,29 @@
|
|||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
|
||||||
{
|
{
|
||||||
fieldValue = "";
|
fieldValue = "";
|
||||||
|
|
||||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
QString accumulatedFieldValue;
|
QString accumulatedFieldValue;
|
||||||
|
|
||||||
QChar currentChar;
|
QChar currentChar;
|
||||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
bool validStringStart = !stringsAreQuoted;
|
||||||
if ( currentChar == QChar('"') )
|
bool validStringEnd = !stringsAreQuoted;
|
||||||
|
if (stringsAreQuoted)
|
||||||
|
{
|
||||||
|
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||||
|
if (currentChar == QChar('"'))
|
||||||
|
{
|
||||||
|
validStringStart = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (validStringStart)
|
||||||
{
|
{
|
||||||
while ( !inputStream.atEnd() )
|
while ( !inputStream.atEnd() )
|
||||||
{
|
{
|
||||||
@ -45,6 +55,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
|||||||
if ( currentChar == QChar('"') ) // End Quote
|
if ( currentChar == QChar('"') ) // End Quote
|
||||||
{
|
{
|
||||||
// Reached end of string
|
// Reached end of string
|
||||||
|
validStringEnd = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -59,7 +70,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
if (!validStringStart)
|
||||||
{
|
{
|
||||||
// Unexpected start of string, Missing '"'
|
// Unexpected start of string, Missing '"'
|
||||||
// Error message
|
// Error message
|
||||||
@ -68,6 +79,15 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
|||||||
+ errorMessageContainer->currentCommand + "\"" );
|
+ errorMessageContainer->currentCommand + "\"" );
|
||||||
// Could interpret as unquoted text
|
// Could interpret as unquoted text
|
||||||
}
|
}
|
||||||
|
else if (!validStringEnd)
|
||||||
|
{
|
||||||
|
// Unexpected end of string, Missing '"'
|
||||||
|
// Error message
|
||||||
|
errorMessageContainer->addError("String argument does not seem to be quoted. Missing the end '\"' in the \"" +
|
||||||
|
errorMessageContainer->currentArgument + "\" argument of the command: \"" +
|
||||||
|
errorMessageContainer->currentCommand + "\"");
|
||||||
|
// Could interpret as unquoted text
|
||||||
|
}
|
||||||
|
|
||||||
fieldValue = accumulatedFieldValue;
|
fieldValue = accumulatedFieldValue;
|
||||||
}
|
}
|
||||||
@ -75,7 +95,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextStream& outputStream)
|
void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextStream& outputStream, bool quoteStrings)
|
||||||
{
|
{
|
||||||
outputStream << "\"";
|
outputStream << "\"";
|
||||||
for ( int i = 0; i < fieldValue.size(); ++i )
|
for ( int i = 0; i < fieldValue.size(); ++i )
|
||||||
@ -92,7 +112,7 @@ void RicfFieldWriter<QString>::writeFieldData(const QString& fieldValue, QTextSt
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
|
||||||
{
|
{
|
||||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
QString accumulatedFieldValue;
|
QString accumulatedFieldValue;
|
||||||
@ -127,7 +147,7 @@ void RicfFieldReader<bool>::readFieldData(bool& fieldValue, QTextStream& inputSt
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldWriter<bool>::writeFieldData(const bool& fieldValue, QTextStream& outputStream)
|
void RicfFieldWriter<bool>::writeFieldData(const bool& fieldValue, QTextStream& outputStream, bool quoteStrings)
|
||||||
{
|
{
|
||||||
// Lower-case true/false is used in the documentation.
|
// Lower-case true/false is used in the documentation.
|
||||||
outputStream << (fieldValue ? "true" : "false");
|
outputStream << (fieldValue ? "true" : "false");
|
||||||
@ -136,10 +156,10 @@ void RicfFieldWriter<bool>::writeFieldData(const bool& fieldValue, QTextStream&
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldReader<cvf::Color3f>::readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
void RicfFieldReader<cvf::Color3f>::readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
|
||||||
{
|
{
|
||||||
QString fieldStringValue;
|
QString fieldStringValue;
|
||||||
RicfFieldReader<QString>::readFieldData(fieldStringValue, inputStream, errorMessageContainer);
|
RicfFieldReader<QString>::readFieldData(fieldStringValue, inputStream, errorMessageContainer, stringsAreQuoted);
|
||||||
|
|
||||||
QColor qColor(fieldStringValue);
|
QColor qColor(fieldStringValue);
|
||||||
if (qColor.isValid())
|
if (qColor.isValid())
|
||||||
@ -151,9 +171,9 @@ void RicfFieldReader<cvf::Color3f>::readFieldData(cvf::Color3f& fieldValue, QTex
|
|||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
///
|
///
|
||||||
//--------------------------------------------------------------------------------------------------
|
//--------------------------------------------------------------------------------------------------
|
||||||
void RicfFieldWriter<cvf::Color3f>::writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream)
|
void RicfFieldWriter<cvf::Color3f>::writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream, bool quoteStrings)
|
||||||
{
|
{
|
||||||
QColor qColor = RiaColorTools::toQColor(fieldValue);
|
QColor qColor = RiaColorTools::toQColor(fieldValue);
|
||||||
QString fieldStringValue = qColor.name();
|
QString fieldStringValue = qColor.name();
|
||||||
RicfFieldWriter<QString>::writeFieldData(fieldStringValue, outputStream);
|
RicfFieldWriter<QString>::writeFieldData(fieldStringValue, outputStream, quoteStrings);
|
||||||
}
|
}
|
@ -32,7 +32,7 @@
|
|||||||
template <typename DataType>
|
template <typename DataType>
|
||||||
struct RicfFieldReader
|
struct RicfFieldReader
|
||||||
{
|
{
|
||||||
static void readFieldData(DataType & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
static void readFieldData(DataType & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
|
||||||
{
|
{
|
||||||
inputStream >> fieldValue;
|
inputStream >> fieldValue;
|
||||||
if (inputStream.status() == QTextStream::ReadCorruptData)
|
if (inputStream.status() == QTextStream::ReadCorruptData)
|
||||||
@ -49,7 +49,7 @@ struct RicfFieldReader
|
|||||||
template <typename DataType>
|
template <typename DataType>
|
||||||
struct RicfFieldWriter
|
struct RicfFieldWriter
|
||||||
{
|
{
|
||||||
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream)
|
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream, bool quoteStrings = true)
|
||||||
{
|
{
|
||||||
outputStream << fieldValue;
|
outputStream << fieldValue;
|
||||||
}
|
}
|
||||||
@ -58,43 +58,43 @@ struct RicfFieldWriter
|
|||||||
template <>
|
template <>
|
||||||
struct RicfFieldReader<QString>
|
struct RicfFieldReader<QString>
|
||||||
{
|
{
|
||||||
static void readFieldData(QString & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer);
|
static void readFieldData(QString & fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct RicfFieldWriter<QString>
|
struct RicfFieldWriter<QString>
|
||||||
{
|
{
|
||||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream, bool quoteStrings = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct RicfFieldReader<bool>
|
struct RicfFieldReader<bool>
|
||||||
{
|
{
|
||||||
static void readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer);
|
static void readFieldData(bool& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <>
|
template <>
|
||||||
struct RicfFieldWriter<bool>
|
struct RicfFieldWriter<bool>
|
||||||
{
|
{
|
||||||
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream);
|
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream, bool quoteStrings = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct RicfFieldReader<cvf::Color3f>
|
struct RicfFieldReader<cvf::Color3f>
|
||||||
{
|
{
|
||||||
static void readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer);
|
static void readFieldData(cvf::Color3f& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct RicfFieldWriter<cvf::Color3f>
|
struct RicfFieldWriter<cvf::Color3f>
|
||||||
{
|
{
|
||||||
static void writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream);
|
static void writeFieldData(const cvf::Color3f& fieldValue, QTextStream& outputStream, bool quoteStrings = true);
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
struct RicfFieldReader< caf::AppEnum<T> >
|
struct RicfFieldReader< caf::AppEnum<T> >
|
||||||
{
|
{
|
||||||
static void readFieldData(caf::AppEnum<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
static void readFieldData(caf::AppEnum<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
|
||||||
{
|
{
|
||||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
QString accumulatedFieldValue;
|
QString accumulatedFieldValue;
|
||||||
@ -127,7 +127,7 @@ struct RicfFieldReader< caf::AppEnum<T> >
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct RicfFieldWriter< caf::AppEnum<T> >
|
struct RicfFieldWriter< caf::AppEnum<T> >
|
||||||
{
|
{
|
||||||
static void writeFieldData(const caf::AppEnum<T>& fieldValue, QTextStream& outputStream)
|
static void writeFieldData(const caf::AppEnum<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true)
|
||||||
{
|
{
|
||||||
outputStream << fieldValue;
|
outputStream << fieldValue;
|
||||||
}
|
}
|
||||||
@ -136,7 +136,7 @@ struct RicfFieldWriter< caf::AppEnum<T> >
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct RicfFieldReader< std::vector<T> >
|
struct RicfFieldReader< std::vector<T> >
|
||||||
{
|
{
|
||||||
static void readFieldData(std::vector<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
static void readFieldData(std::vector<T>& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true)
|
||||||
{
|
{
|
||||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||||
QChar chr = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
QChar chr = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||||
@ -157,7 +157,7 @@ struct RicfFieldReader< std::vector<T> >
|
|||||||
}
|
}
|
||||||
|
|
||||||
T value;
|
T value;
|
||||||
RicfFieldReader<T>::readFieldData(value, inputStream, errorMessageContainer);
|
RicfFieldReader<T>::readFieldData(value, inputStream, errorMessageContainer, true);
|
||||||
fieldValue.push_back(value);
|
fieldValue.push_back(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,7 +172,7 @@ struct RicfFieldReader< std::vector<T> >
|
|||||||
template <typename T>
|
template <typename T>
|
||||||
struct RicfFieldWriter< std::vector<T> >
|
struct RicfFieldWriter< std::vector<T> >
|
||||||
{
|
{
|
||||||
static void writeFieldData(const std::vector<T>& fieldValue, QTextStream& outputStream)
|
static void writeFieldData(const std::vector<T>& fieldValue, QTextStream& outputStream, bool quoteStrings = true)
|
||||||
{
|
{
|
||||||
outputStream << "[";
|
outputStream << "[";
|
||||||
for (size_t i = 0; i < fieldValue.size(); ++i)
|
for (size_t i = 0; i < fieldValue.size(); ++i)
|
||||||
@ -202,10 +202,10 @@ public:
|
|||||||
|
|
||||||
// Xml Serializing
|
// Xml Serializing
|
||||||
public:
|
public:
|
||||||
void readFieldData (QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer) override
|
void readFieldData (QTextStream& inputStream, caf::PdmObjectFactory* objectFactory, RicfMessages* errorMessageContainer, bool stringsAreQuoted = true) override
|
||||||
{
|
{
|
||||||
typename FieldType::FieldDataType value;
|
typename FieldType::FieldDataType value;
|
||||||
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream, errorMessageContainer);
|
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream, errorMessageContainer, stringsAreQuoted);
|
||||||
|
|
||||||
if (this->isIOWriteable())
|
if (this->isIOWriteable())
|
||||||
{
|
{
|
||||||
@ -213,9 +213,9 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void writeFieldData(QTextStream& outputStream) const override
|
void writeFieldData(QTextStream& outputStream, bool quoteStrings = true) const override
|
||||||
{
|
{
|
||||||
RicfFieldWriter<typename FieldType::FieldDataType>::writeFieldData(m_field->value(), outputStream);
|
RicfFieldWriter<typename FieldType::FieldDataType>::writeFieldData(m_field->value(), outputStream, quoteStrings);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -19,6 +19,8 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "cafPdmFieldCapability.h"
|
#include "cafPdmFieldCapability.h"
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
namespace caf
|
namespace caf
|
||||||
{
|
{
|
||||||
class PdmObjectFactory;
|
class PdmObjectFactory;
|
||||||
@ -52,8 +54,9 @@ public:
|
|||||||
|
|
||||||
virtual void readFieldData (QTextStream& inputStream,
|
virtual void readFieldData (QTextStream& inputStream,
|
||||||
caf::PdmObjectFactory* objectFactory,
|
caf::PdmObjectFactory* objectFactory,
|
||||||
RicfMessages* errorMessageContainer ) = 0;
|
RicfMessages* errorMessageContainer,
|
||||||
virtual void writeFieldData(QTextStream& outputStream) const = 0;
|
bool stringsAreQuoted = true) = 0;
|
||||||
|
virtual void writeFieldData(QTextStream& outputStream, bool quoteStrings = true) const = 0;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
caf::PdmFieldHandle* m_owner;
|
caf::PdmFieldHandle* m_owner;
|
||||||
|
@ -56,8 +56,6 @@ class PdmObject:
|
|||||||
for val in value:
|
for val in value:
|
||||||
listofstrings.append(self.__fromValue(val))
|
listofstrings.append(self.__fromValue(val))
|
||||||
return "[" + ", ".join(listofstrings) + "]"
|
return "[" + ", ".join(listofstrings) + "]"
|
||||||
elif isinstance(value, str):
|
|
||||||
return "\"" + str(value) + "\""
|
|
||||||
else:
|
else:
|
||||||
return str(value)
|
return str(value)
|
||||||
|
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
import rips
|
||||||
|
|
||||||
|
resInsight = rips.Instance.find()
|
||||||
|
|
||||||
|
view = resInsight.project.view(0)
|
||||||
|
|
||||||
|
cellResult = view.cellResult()
|
||||||
|
|
||||||
|
cellResult.printObjectInfo()
|
||||||
|
|
||||||
|
cellResult.setValue("ResultType", "FLOW_DIAGNOSTICS")
|
||||||
|
cellResult.setValue("ResultVariable", "TOF")
|
||||||
|
|
||||||
|
cellResult.update()
|
@ -85,7 +85,7 @@ void RiaGrpcServiceInterface::copyPdmObjectFromCafToRips(const caf::PdmObject* s
|
|||||||
{
|
{
|
||||||
QString text;
|
QString text;
|
||||||
QTextStream outStream(&text);
|
QTextStream outStream(&text);
|
||||||
ricfHandle->writeFieldData(outStream);
|
ricfHandle->writeFieldData(outStream, false);
|
||||||
(*parametersMap)[keyword.toStdString()] = text.toStdString();
|
(*parametersMap)[keyword.toStdString()] = text.toStdString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -127,7 +127,7 @@ void RiaGrpcServiceInterface::assignFieldValue(const QString& stringValue, caf::
|
|||||||
{
|
{
|
||||||
QTextStream stream(stringValue.toLatin1());
|
QTextStream stream(stringValue.toLatin1());
|
||||||
RicfMessages messages;
|
RicfMessages messages;
|
||||||
ricfHandle->readFieldData(stream, nullptr, &messages);
|
ricfHandle->readFieldData(stream, nullptr, &messages, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user