summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDominik Holland <dominik.holland@pelagicore.com>2018-10-16 11:25:33 +0200
committerDominik Holland <dominik.holland@pelagicore.com>2018-10-29 13:21:52 +0000
commit6760408aa2d78fb3dd1a471f787d3c2f4e53e00f (patch)
treebb10bf69f2c6cdea32f642e7713a7c2ae6e74d1f
parente65f8d9783de9b0f24719c8299bc69382c6e9a67 (diff)
downloadqtivi-6760408aa2d78fb3dd1a471f787d3c2f4e53e00f.tar.gz
ivigenerator: Add a simulation_data.json for the backend_simulator template
The simulation_data.json is generated from the 'config_simulator' annotation and added into a qrc file which gets compiled into the simulator plugin In the plugin the data is loaded using the loadSimulationData() function. Task-number: AUTOSUITE-629 Change-Id: Iac754b2bf2de65c3657f09126dc8542194777caa Reviewed-by: Robert Griebl <robert.griebl@pelagicore.com>
-rwxr-xr-xsrc/tools/ivigenerator/generate.py41
-rw-r--r--src/tools/ivigenerator/ivigenerator.pro4
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator.yaml4
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/data.qrc.tpl43
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl1
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/plugin.pri.tpl5
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/plugin.pro3
-rw-r--r--src/tools/ivigenerator/templates_backend_simulator/simulation_data.json.tpl40
8 files changed, 138 insertions, 3 deletions
diff --git a/src/tools/ivigenerator/generate.py b/src/tools/ivigenerator/generate.py
index 39bf994..a80ec7b 100755
--- a/src/tools/ivigenerator/generate.py
+++ b/src/tools/ivigenerator/generate.py
@@ -413,6 +413,46 @@ def json_domain(properties):
data[property.name][p] = property.tags['config_simulator'][p]
return json.dumps(data, separators=(',', ':'))
+def simulationData(module):
+# if type(module) is not Module:
+# return
+
+ found = False
+ data = {}
+ for interface in module.interfaces:
+ iData = {}
+ if 'config_simulator' in interface.tags:
+ iData = interface.tags['config_simulator']
+ for property in interface.properties:
+ if 'config_simulator' in property.tags:
+ for p in ['range', 'domain', 'minimum', 'maximum', 'default']:
+ if p in property.tags['config_simulator']:
+ if not property.name in iData:
+ iData[property.name] = {}
+ iData[property.name][p] = symbolToJson(property.tags['config_simulator'][p], property.type)
+ data[interface.name] = iData
+ return json.dumps(data, indent=' ')
+
+def symbolToJson(data, symbol):
+ if symbol.type.is_struct:
+ t = symbol.type
+ if not (isinstance(data, dict) or isinstance(data, list)):
+ return 'QFace Error: value in annotation is supposed to be a dict or list'
+ if len(data) != len(t.reference.fields):
+ return 'QFace Error: argument count in annotation and number of struct fields does not match'
+ newList = list(symbolToJson(property, list(t.reference.fields)[idx]) for idx, property in enumerate(data))
+ return { "type": symbol.type.name, "value": newList }
+ elif symbol.type.is_enum or symbol.type.is_flag:
+ module_name = symbol.type.reference.module.module_name
+ return { "type": "enum", "value": enum_value(data, module_name) }
+ elif symbol.type.is_list or symbol.type.is_model:
+ nested = symbol.type.nested
+ if nested.is_complex:
+ newList = []
+ for value in data:
+ newList.append(symbolToJson(value, nested))
+ return newList
+ return data
def jsonify(obj):
"""
@@ -645,6 +685,7 @@ def generate(tplconfig, moduleConfig, annotations, src, dst):
generator.register_filter("conf_sim_tag", conf_sim_tag)
generator.register_filter('jsonify', jsonify)
generator.register_filter('has_domains', has_domains)
+ generator.register_filter('simulationData', simulationData)
generator.register_filter('json_domain', json_domain)
generator.register_filter('qml_type', qml_type)
generator.register_filter('qml_control', qml_control)
diff --git a/src/tools/ivigenerator/ivigenerator.pro b/src/tools/ivigenerator/ivigenerator.pro
index 1690b83..8d02e5d 100644
--- a/src/tools/ivigenerator/ivigenerator.pro
+++ b/src/tools/ivigenerator/ivigenerator.pro
@@ -41,7 +41,9 @@ templates_backend_simulator.files += \
templates_backend_simulator/plugin.h.tpl \
templates_backend_simulator/plugin.json \
templates_backend_simulator/plugin.pri.tpl \
- templates_backend_simulator/plugin.pro
+ templates_backend_simulator/plugin.pro \
+ templates_backend_simulator/simulation_data.json.tpl \
+ templates_backend_simulator/data.qrc.tpl
templates_backend_simulator.path = $$[QT_HOST_BINS]/ivigenerator/templates_backend_simulator
templates_generation_validator.files += \
diff --git a/src/tools/ivigenerator/templates_backend_simulator.yaml b/src/tools/ivigenerator/templates_backend_simulator.yaml
index 0c3708d..9544372 100644
--- a/src/tools/ivigenerator/templates_backend_simulator.yaml
+++ b/src/tools/ivigenerator/templates_backend_simulator.yaml
@@ -6,6 +6,10 @@ generate_rules:
template_file: "plugin.cpp.tpl"
- dest_file: "{{module.module_name|lower}}.json"
template_file: "plugin.json"
+ - dest_file: "{{module.module_name|lower}}_simulation_data.json"
+ template_file: "simulation_data.json.tpl"
+ - dest_file: "{{module.module_name|lower}}.qrc"
+ template_file: "data.qrc.tpl"
- dest_file: "{{srcBase|lower}}.pri"
template_file: "plugin.pri.tpl"
interface_rules:
diff --git a/src/tools/ivigenerator/templates_backend_simulator/data.qrc.tpl b/src/tools/ivigenerator/templates_backend_simulator/data.qrc.tpl
new file mode 100644
index 0000000..cd3e510
--- /dev/null
+++ b/src/tools/ivigenerator/templates_backend_simulator/data.qrc.tpl
@@ -0,0 +1,43 @@
+{#
+# Copyright (C) 2018 Pelagicore AG
+# Contact: https://www.qt.io/licensing/
+#
+# This file is part of the QtIvi module of the Qt Toolkit.
+#
+# $QT_BEGIN_LICENSE:LGPL-QTAS$
+# Commercial License Usage
+# Licensees holding valid commercial Qt Automotive Suite licenses may use
+# this file in accordance with the commercial license agreement provided
+# with the Software or, alternatively, in accordance with the terms
+# contained in a written agreement between you and The Qt Company. For
+# licensing terms and conditions see https://www.qt.io/terms-conditions.
+# For further information use the contact form at https://www.qt.io/contact-us.
+#
+# GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+# General Public License version 3 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL3 included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 3 requirements
+# will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+#
+# GNU General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU
+# General Public License version 2.0 or (at your option) the GNU General
+# Public license version 3 or any later version approved by the KDE Free
+# Qt Foundation. The licenses are as published by the Free Software
+# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+# included in the packaging of this file. Please review the following
+# information to ensure the GNU General Public License requirements will
+# be met: https://www.gnu.org/licenses/gpl-2.0.html and
+# https://www.gnu.org/licenses/gpl-3.0.html.
+#
+# $QT_END_LICENSE$
+#
+# SPDX-License-Identifier: LGPL-3.0
+#}
+<RCC>
+ <qresource prefix="/simulation">
+ <file>{{module.module_name|lower}}_simulation_data.json</file>
+ </qresource>
+</RCC>
diff --git a/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl b/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl
index ae5c48f..0a421bb 100644
--- a/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl
+++ b/src/tools/ivigenerator/templates_backend_simulator/plugin.cpp.tpl
@@ -81,6 +81,7 @@ extern {{class}}::InterfaceBuilder {{module.tags.config.interfaceBuilder}};
{% else %}
{% set simulationFile = module.module_name|lower + '_simulation.qml' %}
{% endif %}
+ m_simulationEngine->loadSimulationData(QStringLiteral(":/simulation/{{module.module_name|lower}}_simulation_data.json"));
m_simulationEngine->loadSimulation(QStringLiteral("{{simulationFile}}"));
{% endif %}
}
diff --git a/src/tools/ivigenerator/templates_backend_simulator/plugin.pri.tpl b/src/tools/ivigenerator/templates_backend_simulator/plugin.pri.tpl
index 0e6b714..23c062d 100644
--- a/src/tools/ivigenerator/templates_backend_simulator/plugin.pri.tpl
+++ b/src/tools/ivigenerator/templates_backend_simulator/plugin.pri.tpl
@@ -57,5 +57,8 @@ SOURCES += \
{% endfor %}
$$PWD/{{module.module_name|lower}}plugin.cpp
+RESOURCES += $$PWD/{{module.module_name|lower}}.qrc
+
OTHER_FILES += \
- $$PWD/{{module.module_name|lower}}.json
+ $$PWD/{{module.module_name|lower}}.json \
+ $$PWD/{{module.module_name|lower}}_simulation_data.json
diff --git a/src/tools/ivigenerator/templates_backend_simulator/plugin.pro b/src/tools/ivigenerator/templates_backend_simulator/plugin.pro
index 1ca8ea2..897a4cf 100644
--- a/src/tools/ivigenerator/templates_backend_simulator/plugin.pro
+++ b/src/tools/ivigenerator/templates_backend_simulator/plugin.pro
@@ -60,4 +60,5 @@ HEADERS += {{module.module_name|lower}}plugin.h \
{% endif%}
{% endfor %}
-DISTFILES += {{module.module_name|lower}}_simulator.json
+DISTFILES += {{module.module_name|lower}}.json \
+ {{module.module_name|lower}}_simulation_data.json
diff --git a/src/tools/ivigenerator/templates_backend_simulator/simulation_data.json.tpl b/src/tools/ivigenerator/templates_backend_simulator/simulation_data.json.tpl
new file mode 100644
index 0000000..2335c59
--- /dev/null
+++ b/src/tools/ivigenerator/templates_backend_simulator/simulation_data.json.tpl
@@ -0,0 +1,40 @@
+{#
+# Copyright (C) 2017 Pelagicore AG
+# Contact: https://www.qt.io/licensing/
+#
+# This file is part of the QtIvi module of the Qt Toolkit.
+#
+# $QT_BEGIN_LICENSE:LGPL-QTAS$
+# Commercial License Usage
+# Licensees holding valid commercial Qt Automotive Suite licenses may use
+# this file in accordance with the commercial license agreement provided
+# with the Software or, alternatively, in accordance with the terms
+# contained in a written agreement between you and The Qt Company. For
+# licensing terms and conditions see https://www.qt.io/terms-conditions.
+# For further information use the contact form at https://www.qt.io/contact-us.
+#
+# GNU Lesser General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU Lesser
+# General Public License version 3 as published by the Free Software
+# Foundation and appearing in the file LICENSE.LGPL3 included in the
+# packaging of this file. Please review the following information to
+# ensure the GNU Lesser General Public License version 3 requirements
+# will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
+#
+# GNU General Public License Usage
+# Alternatively, this file may be used under the terms of the GNU
+# General Public License version 2.0 or (at your option) the GNU General
+# Public license version 3 or any later version approved by the KDE Free
+# Qt Foundation. The licenses are as published by the Free Software
+# Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
+# included in the packaging of this file. Please review the following
+# information to ensure the GNU General Public License requirements will
+# be met: https://www.gnu.org/licenses/gpl-2.0.html and
+# https://www.gnu.org/licenses/gpl-3.0.html.
+#
+# $QT_END_LICENSE$
+#
+# SPDX-License-Identifier: LGPL-3.0
+#}
+
+{{module|simulationData}}