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>
|
||||
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
///
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer)
|
||||
void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& inputStream, RicfMessages* errorMessageContainer, bool stringsAreQuoted)
|
||||
{
|
||||
fieldValue = "";
|
||||
|
||||
errorMessageContainer->skipWhiteSpaceWithLineNumberCount(inputStream);
|
||||
QString accumulatedFieldValue;
|
||||
|
||||
QChar currentChar;
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if ( currentChar == QChar('"') )
|
||||
bool validStringStart = !stringsAreQuoted;
|
||||
bool validStringEnd = !stringsAreQuoted;
|
||||
if (stringsAreQuoted)
|
||||
{
|
||||
currentChar = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
if (currentChar == QChar('"'))
|
||||
{
|
||||
validStringStart = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (validStringStart)
|
||||
{
|
||||
while ( !inputStream.atEnd() )
|
||||
{
|
||||
@ -45,6 +55,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
||||
if ( currentChar == QChar('"') ) // End Quote
|
||||
{
|
||||
// Reached end of string
|
||||
validStringEnd = true;
|
||||
break;
|
||||
}
|
||||
else
|
||||
@ -59,7 +70,7 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
if (!validStringStart)
|
||||
{
|
||||
// Unexpected start of string, Missing '"'
|
||||
// Error message
|
||||
@ -68,6 +79,15 @@ void RicfFieldReader<QString>::readFieldData(QString& fieldValue, QTextStream& i
|
||||
+ errorMessageContainer->currentCommand + "\"" );
|
||||
// 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;
|
||||
}
|
||||
@ -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 << "\"";
|
||||
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);
|
||||
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.
|
||||
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;
|
||||
RicfFieldReader<QString>::readFieldData(fieldStringValue, inputStream, errorMessageContainer);
|
||||
RicfFieldReader<QString>::readFieldData(fieldStringValue, inputStream, errorMessageContainer, stringsAreQuoted);
|
||||
|
||||
QColor qColor(fieldStringValue);
|
||||
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);
|
||||
QString fieldStringValue = qColor.name();
|
||||
RicfFieldWriter<QString>::writeFieldData(fieldStringValue, outputStream);
|
||||
RicfFieldWriter<QString>::writeFieldData(fieldStringValue, outputStream, quoteStrings);
|
||||
}
|
@ -32,7 +32,7 @@
|
||||
template <typename DataType>
|
||||
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;
|
||||
if (inputStream.status() == QTextStream::ReadCorruptData)
|
||||
@ -49,7 +49,7 @@ struct RicfFieldReader
|
||||
template <typename DataType>
|
||||
struct RicfFieldWriter
|
||||
{
|
||||
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream)
|
||||
static void writeFieldData(const DataType & fieldValue, QTextStream& outputStream, bool quoteStrings = true)
|
||||
{
|
||||
outputStream << fieldValue;
|
||||
}
|
||||
@ -58,43 +58,43 @@ struct RicfFieldWriter
|
||||
template <>
|
||||
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 <>
|
||||
struct RicfFieldWriter<QString>
|
||||
{
|
||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream);
|
||||
static void writeFieldData(const QString & fieldValue, QTextStream& outputStream, bool quoteStrings = true);
|
||||
};
|
||||
|
||||
template <>
|
||||
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 <>
|
||||
struct RicfFieldWriter<bool>
|
||||
{
|
||||
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream);
|
||||
static void writeFieldData(const bool& fieldValue, QTextStream& outputStream, bool quoteStrings = true);
|
||||
};
|
||||
|
||||
template<>
|
||||
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<>
|
||||
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>
|
||||
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);
|
||||
QString accumulatedFieldValue;
|
||||
@ -127,7 +127,7 @@ struct RicfFieldReader< caf::AppEnum<T> >
|
||||
template <typename 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;
|
||||
}
|
||||
@ -136,7 +136,7 @@ struct RicfFieldWriter< caf::AppEnum<T> >
|
||||
template <typename 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);
|
||||
QChar chr = errorMessageContainer->readCharWithLineNumberCount(inputStream);
|
||||
@ -157,7 +157,7 @@ struct RicfFieldReader< std::vector<T> >
|
||||
}
|
||||
|
||||
T value;
|
||||
RicfFieldReader<T>::readFieldData(value, inputStream, errorMessageContainer);
|
||||
RicfFieldReader<T>::readFieldData(value, inputStream, errorMessageContainer, true);
|
||||
fieldValue.push_back(value);
|
||||
}
|
||||
}
|
||||
@ -172,7 +172,7 @@ struct RicfFieldReader< std::vector<T> >
|
||||
template <typename 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 << "[";
|
||||
for (size_t i = 0; i < fieldValue.size(); ++i)
|
||||
@ -202,10 +202,10 @@ public:
|
||||
|
||||
// Xml Serializing
|
||||
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;
|
||||
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream, errorMessageContainer);
|
||||
RicfFieldReader<typename FieldType::FieldDataType>::readFieldData(value, inputStream, errorMessageContainer, stringsAreQuoted);
|
||||
|
||||
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:
|
||||
|
@ -19,6 +19,8 @@
|
||||
#pragma once
|
||||
#include "cafPdmFieldCapability.h"
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace caf
|
||||
{
|
||||
class PdmObjectFactory;
|
||||
@ -52,8 +54,9 @@ public:
|
||||
|
||||
virtual void readFieldData (QTextStream& inputStream,
|
||||
caf::PdmObjectFactory* objectFactory,
|
||||
RicfMessages* errorMessageContainer ) = 0;
|
||||
virtual void writeFieldData(QTextStream& outputStream) const = 0;
|
||||
RicfMessages* errorMessageContainer,
|
||||
bool stringsAreQuoted = true) = 0;
|
||||
virtual void writeFieldData(QTextStream& outputStream, bool quoteStrings = true) const = 0;
|
||||
|
||||
private:
|
||||
caf::PdmFieldHandle* m_owner;
|
||||
|
@ -56,8 +56,6 @@ class PdmObject:
|
||||
for val in value:
|
||||
listofstrings.append(self.__fromValue(val))
|
||||
return "[" + ", ".join(listofstrings) + "]"
|
||||
elif isinstance(value, str):
|
||||
return "\"" + str(value) + "\""
|
||||
else:
|
||||
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;
|
||||
QTextStream outStream(&text);
|
||||
ricfHandle->writeFieldData(outStream);
|
||||
ricfHandle->writeFieldData(outStream, false);
|
||||
(*parametersMap)[keyword.toStdString()] = text.toStdString();
|
||||
}
|
||||
}
|
||||
@ -127,7 +127,7 @@ void RiaGrpcServiceInterface::assignFieldValue(const QString& stringValue, caf::
|
||||
{
|
||||
QTextStream stream(stringValue.toLatin1());
|
||||
RicfMessages messages;
|
||||
ricfHandle->readFieldData(stream, nullptr, &messages);
|
||||
ricfHandle->readFieldData(stream, nullptr, &messages, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user