-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgtpy_pythonnode.h
More file actions
137 lines (111 loc) · 3.25 KB
/
gtpy_pythonnode.h
File metadata and controls
137 lines (111 loc) · 3.25 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* GTlab - Gas Turbine laboratory
* Source File: gtpy_pythonnode.h
*
* SPDX-License-Identifier: Apache-2.0
* SPDX-FileCopyrightText: 2024 German Aerospace Center (DLR)
*
* Created on: 22.03.2024
* Author: Jens Schmeink (AT-TWK)
*/
#ifndef GTPYPYTHONNODE_H
#define GTPYPYTHONNODE_H
#include <intelli/dynamicnode.h>
#include <intelli/data/bytearray.h>
#include "gt_stringproperty.h"
#include "gt_boolproperty.h"
class QPlainTextEdit;
class QSvgWidget;
namespace gt
{
namespace nodes
{
constexpr const char* script_init_content = R"(
################################################################################
# ...
################################################################################
#example imports
#import pandas as pd
#import numpy as np
#import matplotlib.pyplot as plt
#
# example value access:
# x_val is the Caption of the port (can be set in the property widget)
# x = x_val.value()
#
# compressorIn is the caption.
# The object() function only allows rea only access and should not be used
# for objects to set to output nodes
# compressor = compressorIn.object().clone()
#
)";
} // nodes
} // gt
namespace gt {
namespace nodes {
namespace python {
/**
* @brief deserializeToContext
* This function is often called multiple times.
* Make sure to call
* auto state = PyGILState_Ensure();
* before using this function and
* PyGILState_Release(state);
* afterwards to avoid problems with paralelism
*
* @param context
* @param pvd
*/
void deserializeToContext(int context, const intelli::ByteArrayData* pvd,
QString const& caption);
/**
* @brief serializeFromContextToVariant
* This function is often called multiple times.
* Make sure to call
* auto state = PyGILState_Ensure();
* before using this function and
* PyGILState_Release(state);
* afterwards to avoid problems with paralelism
*
* @param context
* @param pd
* @return
*/
QVariant serializeFromContextToVariant(int context,
const intelli::Node::PortInfo& pd);
} /// python
} /// nodes
} /// gt
/**
* @brief The GtpyPythonNode class
* Node for the flexible python scriot based evaluation of data
* The input and output information can be added via ports
*/
class GtpyPythonNode : public intelli::DynamicNode
{
Q_OBJECT
public:
Q_INVOKABLE GtpyPythonNode();
/**
* @brief script
* @return the script used for aevaluation
*/
QString script() const;
void setScript(const QString& scr);
void addInputPort(const QString& className, const QString& caption);
void addOutputPort(const QString& className, const QString& caption);
void eval() override;
private:
GtStringProperty m_script{"script", "script", {},
gt::nodes::script_init_content};
GtBoolProperty m_plot_active{"plot", "Plot enabled", "Plot enabled", false};
void deserializePythonData(int context);
void serealizePythonData(int context);
void showCustomContextMenu(const QPoint& pos, QPlainTextEdit* textEdit);
void loadPlaceHolder(QSvgWidget* w);
private slots:
void appendErrorMessage(QString string, int i, QString prefix);
signals:
void timePassed(int progress);
void onComputeChange(const QString& tmpPath);
};
#endif // GTPYPYTHONNODE_H