#12940 Add option to only parse in strict mode used from python

This commit is contained in:
Kristian Bendiksen committed 2026-01-21 08:41:09 +01:00
1 parent 89bfaa7fd9
commit 6a1c74bdfc
8 files changed
+102 -56

No files matched your search

@@ -63,8 +63,9 @@ public:
virtual void writeToField( QTextStream& inputStream,
caf::PdmObjectFactory* objectFactory,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) = 0;
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) = 0;
static QString helpString( const QString& existingTooltip, const QString& keyword );
@@ -43,7 +43,8 @@ using namespace caf;
void PdmFieldScriptingCapabilityIOHandler<QString>::writeToField( QString& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
fieldValue = "";
@@ -139,7 +140,8 @@ void PdmFieldScriptingCapabilityIOHandler<QString>::readFromField( const QString
void PdmFieldScriptingCapabilityIOHandler<bool>::writeToField( bool& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QString accumulatedFieldValue;
@@ -169,7 +171,7 @@ void PdmFieldScriptingCapabilityIOHandler<bool>::writeToField( bool&
formatString.arg( errorMessageContainer->currentArgument ).arg( errorMessageContainer->currentCommand );
errorMessageContainer->addError( errorMessage );
}
else
else if ( !allowExtraCharacters )
{
errorMessageContainer->checkForExtraCharactersAfterValue( inputStream );
}
@@ -194,7 +196,8 @@ void PdmFieldScriptingCapabilityIOHandler<bool>::readFromField( const bool& fie
void PdmFieldScriptingCapabilityIOHandler<double>::writeToField( double& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
inputStream >> fieldValue;
if ( inputStream.status() == QTextStream::ReadCorruptData )
@@ -205,7 +208,7 @@ void PdmFieldScriptingCapabilityIOHandler<double>::writeToField( double&
inputStream.setStatus( QTextStream::Ok );
}
else if ( inputStream.status() == QTextStream::Ok )
else if ( inputStream.status() == QTextStream::Ok && !allowExtraCharacters )
{
errorMessageContainer->checkForExtraCharactersAfterValue( inputStream );
}
@@ -228,7 +231,8 @@ void PdmFieldScriptingCapabilityIOHandler<double>::readFromField( const double&
void PdmFieldScriptingCapabilityIOHandler<int>::writeToField( int& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
inputStream >> fieldValue;
if ( inputStream.status() == QTextStream::ReadCorruptData )
@@ -239,7 +243,7 @@ void PdmFieldScriptingCapabilityIOHandler<int>::writeToField( int&
inputStream.setStatus( QTextStream::Ok );
}
else if ( inputStream.status() == QTextStream::Ok )
else if ( inputStream.status() == QTextStream::Ok && !allowExtraCharacters )
{
errorMessageContainer->checkForExtraCharactersAfterValue( inputStream );
}
@@ -206,7 +206,8 @@ struct PdmFieldScriptingCapabilityIOHandler
static void writeToField( DataType& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true )
bool stringsAreQuoted = true,
bool allowExtraCharacters = true )
{
inputStream >> fieldValue;
if ( inputStream.status() != QTextStream::Ok )
@@ -246,7 +247,8 @@ struct PdmFieldScriptingCapabilityIOHandler<QString>
static void writeToField( QString& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const QString& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -259,7 +261,8 @@ struct PdmFieldScriptingCapabilityIOHandler<bool>
static void writeToField( bool& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const bool& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -272,7 +275,8 @@ struct PdmFieldScriptingCapabilityIOHandler<double>
static void writeToField( double& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const double& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -285,7 +289,8 @@ struct PdmFieldScriptingCapabilityIOHandler<int>
static void writeToField( int& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const int& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -298,7 +303,8 @@ struct PdmFieldScriptingCapabilityIOHandler<AppEnum<T>>
static void writeToField( AppEnum<T>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true )
bool stringsAreQuoted = true,
bool allowExtraCharacters = true )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QString accumulatedFieldValue;
@@ -331,7 +337,7 @@ struct PdmFieldScriptingCapabilityIOHandler<AppEnum<T>>
"\" for the command: \"" + errorMessageContainer->currentCommand +
"\". Valid options are: " + validOptions.join( ", " ) );
}
else
else if ( !allowExtraCharacters )
{
errorMessageContainer->checkForExtraCharactersAfterValue( inputStream );
}
@@ -359,7 +365,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::optional<T>>
static void writeToField( std::optional<T>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true )
bool stringsAreQuoted = true,
bool allowExtraCharacters = true )
{
// Check if stream is empty (after skipping whitespace)
// Empty input for optional fields means "leave unset" - this is valid, not an error
@@ -376,7 +383,11 @@ struct PdmFieldScriptingCapabilityIOHandler<std::optional<T>>
// If so, we do not set the field value
auto incomingErrorCount = errorMessageContainer->m_messages.size();
PdmFieldScriptingCapabilityIOHandler<T>::writeToField( realValue, inputStream, errorMessageContainer, stringsAreQuoted );
PdmFieldScriptingCapabilityIOHandler<T>::writeToField( realValue,
inputStream,
errorMessageContainer,
stringsAreQuoted,
allowExtraCharacters );
if ( errorMessageContainer->m_messages.size() == incomingErrorCount )
{
@@ -407,7 +418,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::vector<T>>
static void writeToField( std::vector<T>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true )
bool stringsAreQuoted = true,
bool allowExtraCharacters = true )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar chr = errorMessageContainer->readCharWithLineNumberCount( inputStream );
@@ -445,7 +457,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::vector<T>>
PdmFieldScriptingCapabilityIOHandler<T>::writeToField( singleValue,
singleValueStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
fieldValue.push_back( singleValue );
}
}
@@ -481,7 +494,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::vector<T*>>
static void writeToField( std::vector<T*>& fieldValue,
const std::vector<T*>& allObjectsOfType,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer )
PdmScriptIOMessages* errorMessageContainer,
bool allowExtraCharacters = true )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar chr = errorMessageContainer->readCharWithLineNumberCount( inputStream );
@@ -519,7 +533,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::vector<T*>>
PdmFieldScriptingCapabilityIOHandler<T*>::writeToField( singleValue,
allObjectsOfType,
singleValueStream,
errorMessageContainer );
errorMessageContainer,
allowExtraCharacters );
fieldValue.push_back( singleValue );
}
}
@@ -555,7 +570,8 @@ struct PdmFieldScriptingCapabilityIOHandler<DataType*>
static void writeToField( DataType*& fieldValue,
const std::vector<DataType*>& allObjectsOfType,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer )
PdmScriptIOMessages* errorMessageContainer,
bool allowExtraCharacters = true )
{
fieldValue = nullptr; // Default initialized to nullptr
@@ -564,7 +580,8 @@ struct PdmFieldScriptingCapabilityIOHandler<DataType*>
PdmFieldScriptingCapabilityIOHandler<QString>::writeToField( fieldString,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
if ( inputStream.status() == QTextStream::ReadCorruptData )
{
@@ -634,14 +651,16 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
typename FieldType::FieldDataType value;
PdmFieldScriptingCapabilityIOHandler<typename FieldType::FieldDataType>::writeToField( value,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
if ( this->isIOWriteable() )
{
@@ -676,8 +695,9 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
std::vector<DataType*> allObjectsOfType = existingObjectsRoot->descendantsIncludingThisOfType<DataType>();
@@ -685,7 +705,8 @@ public:
PdmFieldScriptingCapabilityIOHandler<DataType*>::writeToField( object,
allObjectsOfType,
inputStream,
errorMessageContainer );
errorMessageContainer,
allowExtraCharacters );
if ( object && this->isIOWriteable() )
{
@@ -720,8 +741,9 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
std::vector<DataType*> allObjectsOfType = existingObjectsRoot->descendantsIncludingThisOfType<DataType>();
@@ -729,7 +751,8 @@ public:
PdmFieldScriptingCapabilityIOHandler<DataType*>::writeToField( object,
allObjectsOfType,
inputStream,
errorMessageContainer );
errorMessageContainer,
allowExtraCharacters );
if ( object && this->isIOWriteable() )
{
@@ -764,8 +787,9 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
std::vector<DataType*> allObjectsOfType = existingObjectsRoot->descendantsIncludingThisOfType<DataType>();
@@ -773,7 +797,8 @@ public:
PdmFieldScriptingCapabilityIOHandler<std::vector<DataType*>>::writeToField( objects,
allObjectsOfType,
inputStream,
errorMessageContainer );
errorMessageContainer,
allowExtraCharacters );
if ( this->isIOWriteable() )
{
@@ -808,8 +833,9 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
std::vector<DataType*> allObjectsOfType = existingObjectsRoot->descendantsIncludingThisOfType<DataType>();
@@ -817,7 +843,8 @@ public:
PdmFieldScriptingCapabilityIOHandler<std::vector<DataType*>>::writeToField( objects,
allObjectsOfType,
inputStream,
errorMessageContainer );
errorMessageContainer,
allowExtraCharacters );
if ( this->isIOWriteable() )
{
@@ -850,8 +877,9 @@ public:
void writeToField( QTextStream& inputStream,
PdmObjectFactory* objectFactory,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr ) override
bool stringsAreQuoted = true,
caf::PdmObjectHandle* existingObjectsRoot = nullptr,
bool allowExtraCharacters = true ) override
{
if ( this->isIOWriteable() )
{
@@ -860,7 +888,8 @@ public:
PdmFieldScriptingCapabilityIOHandler<caf::AppEnum<DataType>>::writeToField( value,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
m_field->setValue( value );
}
}
@@ -45,13 +45,15 @@ using namespace caf;
void PdmFieldScriptingCapabilityIOHandler<cvf::Color3f>::writeToField( cvf::Color3f& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
QString fieldStringValue;
PdmFieldScriptingCapabilityIOHandler<QString>::writeToField( fieldStringValue,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
QColor qColor( fieldStringValue );
if ( qColor.isValid() )
@@ -46,10 +46,11 @@ struct PdmFieldScriptingCapabilityIOHandler<cvf::Color3f>
static void writeToField( cvf::Color3f& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const cvf::Color3f& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
bool quoteNonBuiltins = false );
};
} // namespace caf
} // namespace caf
@@ -43,13 +43,15 @@ using namespace caf;
void PdmFieldScriptingCapabilityIOHandler<cvf::Vector3<double>>::writeToField( cvf::Vector3<double>& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
std::vector<double> fieldVectorValue;
PdmFieldScriptingCapabilityIOHandler<std::vector<double>>::writeToField( fieldVectorValue,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
if ( fieldVectorValue.size() == 3u )
{
for ( int i = 0; i < 3; ++i )
@@ -88,7 +90,8 @@ void PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>::wr
std::vector<cvf::Vector3<double>>& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
errorMessageContainer->skipWhiteSpaceWithLineNumberCount( inputStream );
QChar chr = errorMessageContainer->readCharWithLineNumberCount( inputStream );
@@ -101,7 +104,8 @@ void PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>::wr
PdmFieldScriptingCapabilityIOHandler<std::vector<double>>::writeToField( fieldVectorValue,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
if ( fieldVectorValue.size() == 3u )
{
fieldValue.push_back(
@@ -164,13 +168,15 @@ void PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>::re
void PdmFieldScriptingCapabilityIOHandler<cvf::Matrix4<double>>::writeToField( cvf::Matrix4<double>& fieldValue,
QTextStream& inputStream,
caf::PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted )
bool stringsAreQuoted,
bool allowExtraCharacters )
{
std::vector<double> fieldVectorValue;
PdmFieldScriptingCapabilityIOHandler<std::vector<double>>::writeToField( fieldVectorValue,
inputStream,
errorMessageContainer,
stringsAreQuoted );
stringsAreQuoted,
allowExtraCharacters );
if ( fieldVectorValue.size() == 16u )
{
for ( int row = 0; row < 4; ++row )
@@ -48,7 +48,8 @@ struct PdmFieldScriptingCapabilityIOHandler<cvf::Vector3<double>>
static void writeToField( cvf::Vector3<double>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const cvf::Vector3<double>& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -61,7 +62,8 @@ struct PdmFieldScriptingCapabilityIOHandler<std::vector<cvf::Vector3<double>>>
static void writeToField( std::vector<cvf::Vector3<double>>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const std::vector<cvf::Vector3<double>>& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
@@ -74,7 +76,8 @@ struct PdmFieldScriptingCapabilityIOHandler<cvf::Matrix4<double>>
static void writeToField( cvf::Matrix4<double>& fieldValue,
QTextStream& inputStream,
PdmScriptIOMessages* errorMessageContainer,
bool stringsAreQuoted = true );
bool stringsAreQuoted = true,
bool allowExtraCharacters = true );
static void readFromField( const cvf::Matrix4<double>& fieldValue,
QTextStream& outputStream,
bool quoteStrings = true,
+1 -1
View File
@@ -284,7 +284,7 @@ std::expected<void, QString> RiaGrpcServiceInterface::assignFieldValue( const QS
// Step 2: Parse and set new value
QTextStream stream( stringValue.toLatin1() );
scriptability->writeToField( stream, nullptr, messages, false, RimProject::current() );
scriptability->writeToField( stream, nullptr, messages, false, RimProject::current(), false );
// Step 3: Check for parsing errors (type mismatches)
if ( !messages->m_messages.empty() )