Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/module/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ set(HEADERS
wizards/gtpy_wizardgeometryitem.h
wizards/python_task/gtpy_taskwizardpage.h
wizards/script_calculator/gtpy_scriptcalculatorwizardpage.h
utilities/gtpy_moduleupgrader.h
)

set(SOURCES
Expand Down Expand Up @@ -162,6 +163,7 @@ set(SOURCES
wizards/gtpy_wizardgeometryitem.cpp
wizards/python_task/gtpy_taskwizardpage.cpp
wizards/script_calculator/gtpy_scriptcalculatorwizardpage.cpp
utilities/gtpy_moduleupgrader.cpp
)

set(MODULE_ID "Python Module (Python ${Python3_VERSION_MAJOR}.${Python3_VERSION_MINOR})")
Expand Down
15 changes: 15 additions & 0 deletions src/module/gt_python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,11 @@
#include "gt_accessdataconnection.h"

#include "gtpy_scriptcollectionsettings.h"
#include "gtpy_moduleupgrader.h"

#include "gt_python.h"


#if GT_VERSION >= 0x010700
GtVersionNumber
GtPythonModule::version()
Expand Down Expand Up @@ -327,6 +329,18 @@ QList<gt::SharedFunction> GtPythonModule::sharedFunctions() const
}
#endif

QList<gt::VersionUpgradeRoutine>
GtPythonModule::upgradeRoutines() const
{
return {
#if GT_VERSION >= GT_VERSION_CHECK(2, 1, 0)
gt::VersionUpgradeRoutine {GtVersionNumber(2, 0, 0),
&gtpy::module_upgrader::to_2_0_0::run}
#endif
};
}


namespace PythonExecution
{

Expand All @@ -350,6 +364,7 @@ parseScriptFile(QFile& file)
return out.readAll();
}


int
runPythonInterpreter(const QStringList& args)
{
Expand Down
3 changes: 3 additions & 0 deletions src/module/gt_python.h
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@ class GtPythonModule: public QObject, public GtModuleInterface,
QList<GtCommandLineFunction> commandLineFunctions() const override;

QList<gt::SharedFunction> sharedFunctions() const override;

/** We are providing routines to upgrade the datamodel */
QList<gt::VersionUpgradeRoutine> upgradeRoutines() const override;
#endif

private:
Expand Down
29 changes: 18 additions & 11 deletions src/module/processcomponents/gtpy_abstractscriptcomponent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,14 @@ setStructContainerValue(GtPropertyStructContainer& con, const QString& argName,
{
auto entry = std::find_if(con.begin(), con.end(),
[&argName](const GtPropertyStructInstance& entry){
#if GT_VERSION >= GT_VERSION_CHECK(2, 1, 0)
return entry.ident() == argName;
#elif GT_VERSION >= GT_VERSION_CHECK(2, 0, 0)
return entry.getMemberVal<QString>("name") == argName;
#endif
});

if (entry == con.end())
{
return false;
}
if (entry == con.end()) return false;

return entry->setMemberVal("value", value);
}
Expand All @@ -57,13 +58,15 @@ structContainerValue(const GtPropertyStructContainer& con, const QString& argNam
{
auto entry = std::find_if(con.begin(), con.end(),
[&argName](const GtPropertyStructInstance& entry){
#if GT_VERSION >= GT_VERSION_CHECK(2, 1, 0)
return entry.ident() == argName;
#elif GT_VERSION >= GT_VERSION_CHECK(2, 0, 0)
return entry.getMemberVal<QString>("name") == argName;
#endif

});

if (entry == con.end())
{
return {};
}
if (entry == con.end()) return {};

return entry->getMemberValToVariant("value");
}
Expand Down Expand Up @@ -92,9 +95,11 @@ GtpyAbstractScriptComponent::GtpyAbstractScriptComponent() :
m_pyThreadId{-1},
m_replaceTabBySpaces{"replaceTab", "Replace tab by spaces"},
m_tabSize{"tabSize", "Tab size"},
m_script{"script", "Script"}
#if GT_VERSION >= GT_VERSION_CHECK(2, 0, 0)
,
m_script{"script", "Script"},
#if GT_VERSION >= GT_VERSION_CHECK(2, 1, 0)
m_inputArgs{"input_args", GtPropertyStructContainer::Associative},
m_outputArgs{"output_args", GtPropertyStructContainer::Associative}
#elif GT_VERSION >= GT_VERSION_CHECK(2, 0, 0)
m_inputArgs{"input_args"},
m_outputArgs{"output_args"}
#endif
Expand All @@ -104,7 +109,9 @@ GtpyAbstractScriptComponent::GtpyAbstractScriptComponent() :
auto createStructDef =
[](const QString& typeName, gt::PropertyFactoryFunction f){
GtPropertyStructDefinition structDef(typeName);
#if GT_VERSION < GT_VERSION_CHECK(2, 1, 0)
structDef.defineMember("name", gt::makeStringProperty());
#endif // GT_VERSION < GT_VERSION_CHECK(2, 1, 0)
structDef.defineMember("value", f);
return structDef;
};
Expand Down
82 changes: 81 additions & 1 deletion src/module/utilities/gtpy_decorator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,58 @@ GtpyDecorator::getPropertyContainerVal(GtObject* obj, QString const& id,
return structCon.getMemberValToVariant(memberId);
}

QVariant
GtpyDecorator::getPropertyContainerVal(GtObject* obj,
const QString& id,
const QString& entryId,
const QString& memberId)
{
GtPropertyStructContainer* s = structContainerOfObject(obj, id);

if (!s)
{
gtError() << __func__ << " -> PropertyStruct container of "
"object not found!";
return {};
}

GtPropertyStructContainer::const_iterator it = s->findEntry(entryId);

if (it != s->end())
{
return it->getMemberValToVariant(memberId);
}

gtError() << __func__ << tr("-> Cannot get parameter %1 of entry %2"
"in container %3").arg(memberId, entryId, id);

return {};
}

QStringList
GtpyDecorator::getPropertyContainerEntryIds(GtObject* obj,
const QString& containerId)
{
GtPropertyStructContainer* s = structContainerOfObject(obj, containerId);

if (!s)
{
gtError() << __func__ << " -> PropertyStruct container of "
"object not found!";
return {};
}

QStringList retVal;

std::transform(s->begin(), s->end(), std::back_inserter(retVal),
[](const auto& v)
{
return v.ident();
});

return retVal;
}

bool
GtpyDecorator::setPropertyContainerVal(GtObject* obj, const QString& id,
int index, const QString& memberId,
Expand All @@ -1059,11 +1111,39 @@ GtpyDecorator::setPropertyContainerVal(GtObject* obj, const QString& id,
return false;
}


GtPropertyStructInstance& structCon = s->at(index);

return structCon.setMemberVal(memberId, val);
}

bool
GtpyDecorator::setPropertyContainerVal(GtObject* obj, const QString& id,
const QString& entryId,
const QString& memberId,
const QVariant& val)
{
GtPropertyStructContainer* s = structContainerOfObject(obj, id);

if (!s)
{
gtError() << __func__ << " -> PropertyStruct container of "
"object not found!";
return false;
}

GtPropertyStructContainer::iterator it = s->findEntry(entryId);

if (it != s->end())
{
return it->setMemberVal(memberId, val);
}

gtError() << __func__ << tr("-> Cannot set parameter %1 of entry %2"
"in container %3").arg(memberId, entryId, id);

return false;
}

#endif
QList<GtAbstractProperty*>
GtpyDecorator::findGtProperties(GtObject* obj)
Expand Down
47 changes: 44 additions & 3 deletions src/module/utilities/gtpy_decorator.h
Original file line number Diff line number Diff line change
Expand Up @@ -423,13 +423,40 @@ public slots:
* @param id of the property struct container
* @param index of the element of the items of the container
* @param memberId of the property to call
* @return the value as a variant
*
* @return the value as a variant - empty for invalid inputs
* Example call in python:
* task.getPropertyContainerVal("args_input", 0, "name")
*/
QVariant getPropertyContainerVal (GtObject* obj, const QString& id,
int index, const QString& memberId);
int index, const QString& memberId);

/**
* @brief Find a struct container property and return a value of
* a defined property. This function uses the id string of the
* container element.
*
* @param obj - parent object of the struct propety
* @param id of the property struct container
* @param entryId - id of the entry to read the value from.
* @param memberId of the property to call
* @return the value as a variant - empty for invalid inputs
* Example call in python:
* task.getPropertyContainerVal("constraints", "minEta", "value")
*/
QVariant getPropertyContainerVal(GtObject* obj, const QString& id,
const QString& entryId,
const QString& memberId);

/**
* @brief getPropertyContainerEntryIds
Comment thread
jensschmeink marked this conversation as resolved.
* Returns a list with all property entry ids of a given container element
* The container element is specified by its containerId
* @param obj - object which has the property container
* @param containerId - Id of the property container to evaluate
* @return a ist of all ids of the contained properties
*/
QStringList getPropertyContainerEntryIds(GtObject* obj,
const QString& containerId);

/**
* @brief setPropertyContainerVal
Expand All @@ -444,6 +471,20 @@ public slots:
*/
bool setPropertyContainerVal(GtObject* obj, QString const& id, int index,
QString const& memberId, const QVariant& val);

Comment thread
jensschmeink marked this conversation as resolved.
/**
* @brief Find a struct container property and sets a value of
* a defined propety
* @param obj - parent object of the struct propety
* @param id of the property struct container
* @param entryId - Id of the container element to modify.
* @param memberId of the property to call
* @param val - value to set
* @return true in case of success, else false
*/
bool setPropertyContainerVal(GtObject* obj, QString const& id,
const QString& entryId,
QString const& memberId, const QVariant& val);
#endif
/**
* @brief findGtProperties returns all properties of a GtObject
Expand Down
Loading