-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevicedrivercore.h
More file actions
179 lines (144 loc) · 6.62 KB
/
devicedrivercore.h
File metadata and controls
179 lines (144 loc) · 6.62 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
// SPDX-FileCopyrightText: 2025 Marius Dege <marius.dege@basyskom.com>
// SPDX-FileCopyrightText: 2024 Marius Dege <marius.dege@basyskom.com>
// SPDX-FileCopyrightText: 2024 basysKom GmbH
// SPDX-License-Identifier: LGPL-3.0-or-later
#ifndef DEVICEDRIVERCORE_H
#define DEVICEDRIVERCORE_H
#include "childitemfiltermodel.h"
#include "mustache.hpp"
#include "rootnodefiltermodel.h"
#include "treemodel.h"
#include "uanodesetparser.h"
#include <QDir>
#include <QFileInfoList>
#include <QStringList>
#ifdef WASM_BUILD
#include <emscripten.h>
#include <emscripten/bind.h>
#include <emscripten/val.h>
#endif
#include <unordered_map>
#include <vector>
using namespace kainjow;
class DeviceDriverCore : public QObject
{
Q_OBJECT
Q_PROPERTY(TreeModel* deviceTypesModel READ deviceTypesModel CONSTANT)
Q_PROPERTY(TreeModel* selectionModel READ selectionModel NOTIFY selectionModelChanged)
Q_PROPERTY(ChildItemFilterModel* childItemFilterModel READ childItemFilterModel NOTIFY
childItemFilterModelChanged)
Q_PROPERTY(RootNodeFilterModel* rootNodeFilterModel READ rootNodeFilterModel NOTIFY
rootNodeFilterModelChanged)
Q_PROPERTY(QString nodeSetPath READ nodeSetPath WRITE setNodeSetPath NOTIFY selectionModelChanged)
Q_PROPERTY(QString projectName READ projectName WRITE setProjectName NOTIFY projectNameChanged)
Q_PROPERTY(QString projectFilePath READ projectFilePath WRITE setProjectFilePath NOTIFY
projectFilePathChanged)
Q_PROPERTY(QString existingFilePath READ existingFilePath WRITE setExistingFilePath NOTIFY
existingFilePathChanged)
Q_PROPERTY(QString outputFilePath READ outputFilePath WRITE setOutputFilePath NOTIFY
outputFilePathChanged)
public:
DeviceDriverCore();
~DeviceDriverCore();
Q_INVOKABLE void selectNodeSetXML(const QString& nodeSetDir);
Q_INVOKABLE void addRootNodeToSelectionModel(
const QString& namespaceString, const QString& nodeId);
Q_INVOKABLE void removeRootNodeFromSelection(const int index);
Q_INVOKABLE void generateCode(bool includeCmake, bool includeJson);
Q_INVOKABLE void saveToJson(const QString& fileName, const QJsonDocument& content);
Q_INVOKABLE void loadState(const QString& filePath);
Q_INVOKABLE void saveProject();
Q_INVOKABLE QString appendProjectNameToPath(const QString& basePath);
TreeModel* deviceTypesModel() const;
std::shared_ptr<UANode> findNodeById(const QString& namespaceString, const QString& nodeId) const;
void setNodeSetPath(const QString& newNodeSetPath);
void setMustacheTemplatePath(const QString& newMustacheTemplatePath);
void setCmakeMustacheTemplatePath(const QString& newCmakeMustacheTemplatePath);
TreeModel* selectionModel() const;
ChildItemFilterModel* childItemFilterModel() const;
void setExistingFilePath(const QString& newexistingFilePath);
void setOutputFilePath(const QString& newOutputFilePath);
QString nodeSetPath() const;
RootNodeFilterModel* rootNodeFilterModel() const;
void printMustacheData(const QJsonDocument& jsonDoc);
QString projectName() const;
void setProjectName(const QString& newProjectName);
QString generatedCFilePath() const;
void setGeneratedCFilePath(const QString& newGeneratedCFilePath);
QString projectFilePath() const;
void setProjectFilePath(const QString& newProjectFilePath);
QString outputFilePath() const;
QString existingFilePath() const;
QString readMeMustacheTemplatePath() const;
void setReadMeMustacheTemplatePath(const QString& newReadMeMustacheTemplatePath);
signals:
void selectionModelChanged();
void childItemFilterModelChanged();
void rootNodeFilterModelChanged();
void setupFinished();
void projectNameChanged();
void generatedCFilePathChanged();
void projectFilePathChanged();
void outputFilePathChanged();
void existingFilePathChanged();
void openProjectReturned(const bool& success);
void generateCodeFinished();
private:
TreeModel* m_deviceTypesModel = nullptr;
TreeModel* m_selectionModel = nullptr;
ChildItemFilterModel* m_childItemFilterModel = nullptr;
UaNodeSetParser m_parser;
QMap<QString, std::shared_ptr<UANodeSet>> m_nodeSets;
QString m_nodeSetPath;
QString m_mustacheTemplatePath;
QString m_cmakeMustacheTemplatePath;
QString m_existingFilePath;
QString m_projectFilePath;
QString m_readMeMustacheTemplatePath;
QString m_outputFilePath;
QString m_selectedModelUri;
QString m_currentNodeSetDir;
QString m_projectName;
QStringList findRequiredModels(const QString& fileName);
QStringList findRequiredFiles(const QStringList& models, bool xmlOnly = true);
QStringList getAllNodesetFiles(const QString& dir);
QString getNodeSetXmlFile(const QString& dir);
QString ensureUniqueDirectory(const QString& path);
void parseNodeSets(const QString& nodeSetDir);
void resolveNodeReferences(
std::shared_ptr<UANode> node, QSet<std::shared_ptr<UANode>>& visitedNodes);
void resolveParentNode();
void resolveReferences();
void resolveDataTypes();
void resolveMethods();
QString parentReferenceNodeId(std::shared_ptr<UANode> node);
QList<TreeItem*> getSelectedItems();
void travereseTreeModel(
const QAbstractItemModel* model,
QList<TreeItem*>& items,
const QModelIndex& parent = QModelIndex());
std::pair<std::unordered_map<std::string, mustache::data>, QJsonDocument> getMustacheData();
std::pair<mustache::data, QJsonDocument> getCMakeMustacheData();
std::unordered_map<std::string, mustache::data> createNodeMap(
int index, TreeItem* item, const QMap<int, QString>& namespaceMap, QJsonObject& jsonNodeMap);
void getVariableAsMustacheArray(
TreeItem* item,
std::unordered_map<std::string, mustache::data>& nodeMap,
QJsonObject& jsonObj);
void getMethodAsMustacheArray(
TreeItem* item,
std::unordered_map<std::string, mustache::data>& nodeMap,
QJsonObject& jsonObj);
void getArgumentsAsMustacheArray(
int index,
std::shared_ptr<UAVariable> var,
std::unordered_map<std::string, mustache::data>& argMap,
QJsonObject& jsonArgMap);
std::string loadTemplateFile(const QString& filePath);
void saveToFile(const QString& filePath, const std::string& data);
void downloadFile(const QString& fileName, const QByteArray& fileContent);
QString getUserCodeSegment(
const QString& fileName, const QString& startMarker, const QString& endMarker);
RootNodeFilterModel* m_rootNodeFilterModel = nullptr;
};
#endif // DEVICEDRIVERCORE_H