-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtpy_task.cpp
More file actions
95 lines (76 loc) · 2.24 KB
/
gtpy_task.cpp
File metadata and controls
95 lines (76 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/* GTlab - Gas Turbine laboratory
* Source File: gtpy_task.cpp
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
*
* Created on: 12.08.2019
* Author: Marvin Noethen (DLR AT-TWK)
*/
#include "gt_package.h"
#include "gt_objectpathproperty.h"
#include "gt_processdata.h"
#include "gtpy_contextmanager.h"
#include "gtpy_wizardgeometries.h"
#include "gtpy_task.h"
GtpyTask::GtpyTask()
{
setObjectName("Python Task");
#if GT_VERSION >= GT_VERSION_CHECK(2, 0, 0)
registerPropertyStructContainer(m_inputArgs);
registerMonitoringPropertyStructContainer(m_outputArgs);
#endif
registerProperty(m_script);
registerProperty(m_replaceTabBySpaces);
registerProperty(m_tabSize);
for (auto* pathProp : qAsConst(m_dynamicPathProps))
{
registerProperty(*pathProp);
}
connect(this, SIGNAL(stateChanged(GtProcessComponent::STATE)), this,
SLOT(onStateChanged(GtProcessComponent::STATE)));
connect(this, SIGNAL(deletedFromDatamodel(QString)),
GtpyWizardGeometries::instance(),
SLOT(processElementDeleted(QString)));
}
GtpyTask::~GtpyTask()
{
if (this->findParent<GtProcessData*>())
{
emit deletedFromDatamodel(this->uuid());
}
}
bool
GtpyTask::runIteration()
{
int contextId = GtpyContextManager::instance()->createNewContext(
GtpyContextManager::TaskRunContext, true);
GtpyContextManager::instance()->setLoggingPrefix(contextId, objectName());
///Initialize context with data model objects
GtpyContextManager::instance()->addTaskValue(contextId, this);
auto success = evalScript(contextId);
emit transferMonitoringProperties();
return success;
}
bool
GtpyTask::childAccepted(GtObject* /*child*/)
{
#if GT_VERSION >= 0x020000
return qobject_cast<GtTaskGroup*>(this->parent()) == nullptr;
#else
return qobject_cast<GtProcessData*>(this->parent()) == nullptr;
#endif
}
GtPackage*
GtpyTask::dataPackage(const GtObjectPath& pkgPath)
{
return data<GtPackage*>(pkgPath);
}
void
GtpyTask::onStateChanged(STATE state) const
{
if (m_pyThreadId >= 0 && state == GtProcessComponent::TERMINATION_REQUESTED)
{
GtpyContextManager::instance()->interruptPyThread(m_pyThreadId);
}
}