2020-03-10 08:11:22 -05:00
|
|
|
//##################################################################################################
|
2017-06-29 04:48:26 -05:00
|
|
|
//
|
2020-03-10 08:11:22 -05:00
|
|
|
// Custom Visualization Core library
|
|
|
|
// Copyright (C) Ceetron Solutions AS
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2020-03-10 08:11:22 -05:00
|
|
|
// This library may be used under the terms of either the GNU General Public License or
|
|
|
|
// the GNU Lesser General Public License as follows:
|
2019-09-06 03:40:57 -05:00
|
|
|
//
|
2020-03-10 08:11:22 -05:00
|
|
|
// GNU General Public License Usage
|
|
|
|
// This library 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
|
|
|
//
|
2020-03-10 08:11:22 -05:00
|
|
|
// This library 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.
|
2017-06-29 04:48:26 -05:00
|
|
|
//
|
2020-03-10 08:11:22 -05:00
|
|
|
// See the GNU General Public License at <<http://www.gnu.org/licenses/gpl.html>>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
// GNU Lesser General Public License Usage
|
|
|
|
// This library is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Lesser General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This library 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 Lesser General Public License at <<http://www.gnu.org/licenses/lgpl-2.1.html>>
|
|
|
|
// for more details.
|
|
|
|
//
|
|
|
|
//##################################################################################################
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmObjectScriptingCapability.h"
|
2020-02-24 08:42:23 -06:00
|
|
|
|
2020-08-21 04:13:07 -05:00
|
|
|
#include "cafPdmAbstractFieldScriptingCapability.h"
|
2020-02-24 08:42:23 -06:00
|
|
|
#include "cafPdmObject.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafPdmObjectHandle.h"
|
2020-03-04 03:12:59 -06:00
|
|
|
#include "cafPdmScriptIOMessages.h"
|
2019-09-06 03:40:57 -05:00
|
|
|
#include "cafPdmXmlFieldHandle.h"
|
2020-02-24 08:42:23 -06:00
|
|
|
|
2019-09-06 03:40:57 -05:00
|
|
|
#include <QTextStream>
|
2017-06-29 04:48:26 -05:00
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
using namespace caf;
|
|
|
|
|
2017-06-29 04:48:26 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-06-29 04:48:26 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-08-21 04:13:07 -05:00
|
|
|
PdmObjectScriptingCapability::PdmObjectScriptingCapability( PdmObjectHandle* owner, bool giveOwnership )
|
2020-02-24 08:42:23 -06:00
|
|
|
: m_owner( owner )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
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
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-08-21 04:13:07 -05:00
|
|
|
PdmObjectScriptingCapability::~PdmObjectScriptingCapability()
|
2020-02-12 04:13:38 -06:00
|
|
|
{
|
|
|
|
}
|
2017-06-29 04:48:26 -05:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
2019-09-06 03:40:57 -05:00
|
|
|
///
|
2017-06-29 04:48:26 -05:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-08-21 04:13:07 -05:00
|
|
|
void PdmObjectScriptingCapability::readFields( QTextStream& inputStream,
|
|
|
|
PdmObjectFactory* objectFactory,
|
|
|
|
PdmScriptIOMessages* 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
|
|
|
|
2020-03-10 08:11:22 -05:00
|
|
|
PdmFieldHandle* fieldHandle = m_owner->findField( keyword );
|
2020-08-21 04:13:07 -05:00
|
|
|
if ( fieldHandle && fieldHandle->xmlCapability() &&
|
|
|
|
fieldHandle->capability<PdmAbstractFieldScriptingCapability>() )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2020-08-21 04:13:07 -05:00
|
|
|
PdmXmlFieldHandle* xmlFieldHandle = fieldHandle->xmlCapability();
|
|
|
|
PdmAbstractFieldScriptingCapability* scriptability =
|
|
|
|
fieldHandle->capability<PdmAbstractFieldScriptingCapability>();
|
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;
|
2020-03-10 08:11:22 -05:00
|
|
|
scriptability->writeToField( 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
|
|
|
//--------------------------------------------------------------------------------------------------
|
2020-08-21 04:13:07 -05:00
|
|
|
void PdmObjectScriptingCapability::writeFields( QTextStream& outputStream ) const
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
2020-03-10 08:11:22 -05:00
|
|
|
std::vector<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 )
|
|
|
|
{
|
2020-08-21 04:13:07 -05:00
|
|
|
const PdmXmlFieldHandle* xmlField = fields[it]->xmlCapability();
|
|
|
|
const PdmAbstractFieldScriptingCapability* scriptability =
|
|
|
|
fields[it]->capability<PdmAbstractFieldScriptingCapability>();
|
2020-03-10 08:11:22 -05:00
|
|
|
if ( scriptability && xmlField && xmlField->isIOWritable() )
|
2017-06-29 04:48:26 -05:00
|
|
|
{
|
|
|
|
QString keyword = xmlField->fieldHandle()->keyword();
|
2020-03-10 08:11:22 -05:00
|
|
|
CAF_ASSERT( PdmXmlObjectHandle::isValidXmlElementName( keyword ) );
|
2017-06-29 04:48:26 -05:00
|
|
|
|
|
|
|
if ( writtenFieldCount >= 1 )
|
|
|
|
{
|
|
|
|
outputStream << ", ";
|
|
|
|
}
|
|
|
|
|
|
|
|
outputStream << keyword << " = ";
|
2020-03-10 08:11:22 -05:00
|
|
|
scriptability->readFromField( outputStream );
|
2019-09-06 03:40:57 -05:00
|
|
|
|
2018-11-07 03:38:00 -06:00
|
|
|
writtenFieldCount++;
|
2017-06-29 04:48:26 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|