[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [krita/langkamp/remotecontrol] plugins/extensions: Adapt remote control to hud changes
From: Sven Langkamp <sven.langkamp () gmail ! com>
Date: 2016-08-26 16:41:53
Message-ID: E1bdKCX-0007bP-2I () code ! kde ! org
[Download RAW message or body]
Git commit 28acba828c186d8fed8b0edaed777a9e93bcc0db by Sven Langkamp.
Committed on 26/08/2016 at 16:41.
Pushed by langkamp into branch 'langkamp/remotecontrol'.
Adapt remote control to hud changes
M +1 -0 plugins/extensions/CMakeLists.txt
A +55 -28 plugins/extensions/remotecontrol/kis_opcua_server.cpp [License: \
GPL (v2+)] A +10 -1 plugins/extensions/remotecontrol/kis_opcua_server.h \
[License: GPL (v2+)] A +3 -4 \
plugins/extensions/remotecontrol/kis_paintop_control_object.cpp [License: GPL \
(v2+)] A +3 -3 plugins/extensions/remotecontrol/remotecontrol.cpp \
[License: GPL (v2+)] A +0 -2 plugins/extensions/remotecontrol/remotecontrol.h \
[License: GPL (v2+)]
http://commits.kde.org/krita/28acba828c186d8fed8b0edaed777a9e93bcc0db
diff --cc plugins/extensions/CMakeLists.txt
index c0f0eea,e09bd6e..5055705
--- a/plugins/extensions/CMakeLists.txt
+++ b/plugins/extensions/CMakeLists.txt
@@@ -14,7 -14,7 +14,8 @@@ add_subdirectory( shearimage
add_subdirectory( layergroupswitcher )
add_subdirectory( resourcemanager )
add_subdirectory( layersplit )
+add_subdirectory( remotecontrol )
+ add_subdirectory( waveletdecompose )
# Allow to skip building GMIC plugin
option(WITH_GMIC "Build the G'Mic plugin" ON)
diff --cc plugins/extensions/remotecontrol/kis_opcua_server.cpp
index 4f190a5,0000000..fc0025d
mode 100644,000000..100644
--- a/plugins/extensions/remotecontrol/kis_opcua_server.cpp
+++ b/plugins/extensions/remotecontrol/kis_opcua_server.cpp
@@@ -1,181 -1,0 +1,208 @@@
+/*
+ *
+ * Copyright (c) 2016 Sven Langkamp <sven.langkamp@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_opcua_server.h"
+
+#include <QMetaProperty>
+#include <QDebug>
++#include <QMetaObject>
+
- #include "open62541.h"
+
- QMap<QString, QPair<QObject*, int> > m_variableMap;
++#include "open62541.h"
+
+QString uaStringToQString(const UA_String& uaString)
+{
+ int length = uaString.length;
+ char* cstring = new char[length+1];
+ memcpy(cstring, uaString.data, length );
+ cstring[length] = '\0';
+
+ QString result = QString(cstring);
+
+ delete[] cstring;
+ return result;
+}
+
- static UA_StatusCode readVariable(void *handle, const UA_NodeId nodeid, UA_Boolean \
sourceTimeStamp,
- const UA_NumericRange *range, UA_DataValue \
*dataValue) { ++static UA_StatusCode readVariableCallback(void *handle, const \
UA_NodeId nodeid, UA_Boolean sourceTimeStamp, ++ \
const UA_NumericRange *range, UA_DataValue *dataValue) { +
+ dataValue->hasValue = true;
+
+ QString id = uaStringToQString(nodeid.identifier.string);
-
- if(!m_variableMap.contains(id)){
- return UA_STATUSCODE_BADUNEXPECTEDERROR;
- }
- QPair<QObject*, int> property = m_variableMap[id];
-
- QObject* object = property.first;
- QMetaProperty prop = object->metaObject()->property(property.second);
-
- QVariant value = prop.read(object);
++
++ QVariant value = KisOpcUaServer::instance()->readVariable(id);
+
+ switch (value.type()) {
+ case QVariant::Int:
+ {
+ UA_Int32 intValue = value.toInt();
+ UA_Variant_setScalarCopy(&dataValue->value, &intValue, \
&UA_TYPES[UA_TYPES_INT32]); + break;
+ }
+ case QVariant::Double:
+ {
+ UA_Double doubleValue = value.toDouble();
+ UA_Variant_setScalarCopy(&dataValue->value, &doubleValue, \
&UA_TYPES[UA_TYPES_DOUBLE]); + break;
+ }
+ default:
+ break;
+ }
+
+ return UA_STATUSCODE_GOOD;
+}
+
- static UA_StatusCode writeVariable(void *handle, const UA_NodeId nodeid,
- const UA_Variant *data, const UA_NumericRange \
*range) { ++static UA_StatusCode writeVariableCallback(void *handle, const UA_NodeId \
nodeid, ++ const UA_Variant *data, const \
UA_NumericRange *range) { +
+
+ QString id = uaStringToQString(nodeid.identifier.string);
+
- if(!m_variableMap.contains(id)){
- return UA_STATUSCODE_BADUNEXPECTEDERROR;
- }
- QPair<QObject*, int> property = m_variableMap[id];
-
- QObject* object = property.first;
- QMetaProperty prop = object->metaObject()->property(property.second);
-
+ QVariant value;
+ if(UA_Variant_isScalar(data) && data->data) {
+ if(data->type == &UA_TYPES[UA_TYPES_INT32]) {
+ int intValue = *(UA_UInt32*)data->data;
+ value = QVariant(intValue);
+
+ }
+ else if(data->type == &UA_TYPES[UA_TYPES_DOUBLE]) {
+ double doubleValue = *(UA_Double*)data->data;
+ value = QVariant(doubleValue);
+ } else {
+ return UA_STATUSCODE_BADUNEXPECTEDERROR;
+ }
+ }
-
- prop.write(object, value);
++
++ bool result;
++ QMetaObject::invokeMethod(KisOpcUaServer::instance(), "writeVariable",
++ Qt::BlockingQueuedConnection,
++ Q_RETURN_ARG(bool, result),
++ Q_ARG(QString, id),
++ Q_ARG(QVariant, value));
++ if(!result)
++ return UA_STATUSCODE_BADUNEXPECTEDERROR;
+
+ return UA_STATUSCODE_GOOD;
+}
+
++Q_GLOBAL_STATIC(KisOpcUaServer, s_instance)
++
+KisOpcUaServer::KisOpcUaServer()
+{
+
+}
+
++KisOpcUaServer* KisOpcUaServer::instance()
++{
++ return s_instance;
++}
++
+void KisOpcUaServer::run()
+{
+ bool running = true;
+
+ UA_ServerConfig config = UA_ServerConfig_standard;
+ UA_ServerNetworkLayer nl = \
UA_ServerNetworkLayerTCP(UA_ConnectionConfig_standard, 16664); + \
config.networkLayers = &nl; + config.networkLayersSize = 1;
+ UA_Server *server = UA_Server_new(config);
+
+ int objectIndex = 1000;
+ foreach(QObject* object, m_objects) {
+
+ UA_ObjectAttributes object_attr;
+ UA_ObjectAttributes_init(&object_attr);
+ object_attr.description = UA_LOCALIZEDTEXT("en_US", "");
+ object_attr.displayName = UA_LOCALIZEDTEXT("en_US", \
object->objectName().toLatin1().data()); + UA_Server_addObjectNode(server, \
UA_NODEID_NUMERIC(1, objectIndex), + UA_NODEID_NUMERIC(0, \
UA_NS0ID_OBJECTSFOLDER), + UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), \
UA_QUALIFIEDNAME(1, object->objectName().toLatin1().data()), + \
UA_NODEID_NUMERIC(0, UA_NS0ID_FOLDERTYPE), object_attr, NULL, NULL); +
+ int propertyCount = object->metaObject()->propertyCount();
+
+ for(int i = 0; i < propertyCount; i++)
+ {
+ QMetaProperty property = object->metaObject()->property(i);
+
+ QString variableName = object->objectName() + '.' + \
QString(property.name()); + m_variableMap[variableName] = QPair<QObject*, \
int>(object, i); +
+ QString browseName = QString(property.name());
+
+ UA_NodeId variableNodeId = UA_NODEID_STRING(1, \
variableName.toLatin1().data()); + UA_QualifiedName variableNodeName = \
UA_QUALIFIEDNAME(1, browseName.toLatin1().data()); +
+ UA_DataSource dataSource;
+ dataSource.handle = 0;
- dataSource.read = &readVariable;
- dataSource.write = &writeVariable;
++ dataSource.read = &readVariableCallback;
++ dataSource.write = &writeVariableCallback;
+
+ UA_VariableAttributes attr;
+ UA_VariableAttributes_init(&attr);
+ attr.description = UA_LOCALIZEDTEXT("en_US", \
variableName.toLatin1().data()); + attr.displayName = \
UA_LOCALIZEDTEXT("en_US", variableName.toLatin1().data()); +
+ UA_StatusCode retval = UA_Server_addDataSourceVariableNode(server, \
variableNodeId, + \
UA_NODEID_NUMERIC(1, objectIndex), + \
UA_NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), + \
variableNodeName, UA_NODEID_NULL, attr, dataSource, NULL); + }
+ objectIndex++;
+ }
+
+ UA_StatusCode retval = UA_Server_run(server, &running);
+ UA_Server_delete(server);
+ nl.deleteMembers(&nl);
+}
+
+void KisOpcUaServer::addObject(QObject *object)
+{
+ m_objects.append(object);
+}
+
++bool KisOpcUaServer::writeVariable(const QString& id, QVariant value)
++{
++ if(!m_variableMap.contains(id)){
++ return false;
++ }
++ QPair<QObject*, int> property = m_variableMap[id];
++
++ QObject* object = property.first;
++ QMetaProperty prop = object->metaObject()->property(property.second);
++
++ prop.write(object, value);
++
++ return true;
++}
++
++QVariant KisOpcUaServer::readVariable(const QString& id)
++{
++ if(!m_variableMap.contains(id)){
++ return QVariant();
++ }
++ QPair<QObject*, int> property = m_variableMap[id];
++
++ QObject* object = property.first;
++ QMetaProperty prop = object->metaObject()->property(property.second);
++
++ return prop.read(object);
++}
++
++
diff --cc plugins/extensions/remotecontrol/kis_opcua_server.h
index a172e95,0000000..fcfc432
mode 100644,000000..100644
--- a/plugins/extensions/remotecontrol/kis_opcua_server.h
+++ b/plugins/extensions/remotecontrol/kis_opcua_server.h
@@@ -1,42 -1,0 +1,51 @@@
+/*
+ *
+ * Copyright (c) 2016 Sven Langkamp <sven.langkamp@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#ifndef KISOPCUASERVER_H
+#define KISOPCUASERVER_H
+
+#include <QThread>
+#include <QVector>
+#include <QMap>
+#include <QPair>
++#include <QVariant>
+
+class KisOpcUaServer : public QThread
+{
++ Q_OBJECT
+public:
++ static KisOpcUaServer *instance();
++
+ KisOpcUaServer();
+
+ void run();
+
+ void addObject(QObject* object);
+
-
++public Q_SLOTS:
++ bool writeVariable(const QString& id, QVariant value);
++
++ QVariant readVariable(const QString& id);
++
+private:
+ QVector<QObject*> m_objects;
++ QMap<QString, QPair<QObject*, int> > m_variableMap;
+};
+
+#endif // KISOPCUASERVER_H
diff --cc plugins/extensions/remotecontrol/kis_paintop_control_object.cpp
index c6e3651c,0000000..19de7eb
mode 100644,000000..100644
--- a/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp
+++ b/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp
@@@ -1,89 -1,0 +1,88 @@@
+/*
+ *
+ * Copyright (c) 2016 Sven Langkamp <sven.langkamp@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_paintop_control_object.h"
+#include <KisViewManager.h>
+#include <kis_canvas_resource_provider.h>
+#include <kis_paintop_preset.h>
+#include <kis_paintop_settings.h>
+
+KisPaintopControlObject::KisPaintopControlObject(KisViewManager* view, QObject \
*parent) : QObject(parent) +, m_view(view)
+{
+ setObjectName("PaintOp");
+}
+
+void KisPaintopControlObject::setBrushSize(double size)
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return;
+ }
+
- qreal offset = size - \
m_view->resourceProvider()->currentPreset()->settings()->paintOpSize().width();
- m_view->resourceProvider()->currentPreset()->settings()->changePaintOpSize(offset, \
0); ++ m_view->resourceProvider()->currentPreset()->settings()->setPaintOpSize(size);
+
+}
+
+double KisPaintopControlObject::brushSize()
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return 0.0;
+ }
-
- return m_view->resourceProvider()->currentPreset()->settings()->paintOpSize().width();
++
++ return m_view->resourceProvider()->currentPreset()->settings()->paintOpSize();
+}
+
+double KisPaintopControlObject::flow()
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return 0.0;
+ }
+
+ return m_view->resourceProvider()->currentPreset()->settings()->paintOpFlow();
+}
+
+void KisPaintopControlObject::setFlow(double flow)
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return;
+ }
+
+ m_view->resourceProvider()->currentPreset()->settings()->setPaintOpFlow(flow);
+}
+
+double KisPaintopControlObject::opacity()
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return 0.0;
+ }
+
+ return m_view->resourceProvider()->currentPreset()->settings()->paintOpOpacity();
+}
+
+void KisPaintopControlObject::setOpacity(double opacity)
+{
+ if(!m_view || !m_view->resourceProvider()) {
+ return;
+ }
+
+ m_view->resourceProvider()->currentPreset()->settings()->setPaintOpOpacity(opacity);
+}
+
+
+
diff --cc plugins/extensions/remotecontrol/remotecontrol.cpp
index bea67e9,0000000..0986263
mode 100644,000000..100644
--- a/plugins/extensions/remotecontrol/remotecontrol.cpp
+++ b/plugins/extensions/remotecontrol/remotecontrol.cpp
@@@ -1,44 -1,0 +1,44 @@@
+/*
+ *
+ * Copyright (c) 2016 Sven Langkamp <sven.langkamp@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#include "remotecontrol.h"
+
+#include <klocalizedstring.h>
+#include <kis_debug.h>
+#include <kpluginfactory.h>
+
+#include "kis_paintop_control_object.h"
+#include "kis_opcua_server.h"
+
+K_PLUGIN_FACTORY_WITH_JSON(RemoteControlFactory, "kritaremotecontrol.json", \
registerPlugin<RemoteControl>();) +
+RemoteControl::RemoteControl(QObject *parent, const QVariantList &)
+ : KisViewPlugin(parent)
+{
+ m_paintOpControl = new KisPaintopControlObject(m_view, this);
- m_server = new KisOpcUaServer();
++ KisOpcUaServer* server = KisOpcUaServer::instance();
+
- m_server->addObject(m_paintOpControl);
- m_server->start();
++ server->addObject(m_paintOpControl);
++ server->start();
+}
+
+RemoteControl::~RemoteControl()
+{
+}
+
+#include "remotecontrol.moc"
diff --cc plugins/extensions/remotecontrol/remotecontrol.h
index 34bcb2d,0000000..8ac1b3f
mode 100644,000000..100644
--- a/plugins/extensions/remotecontrol/remotecontrol.h
+++ b/plugins/extensions/remotecontrol/remotecontrol.h
@@@ -1,43 -1,0 +1,41 @@@
+/*
+ *
+ *
+ * Copyright (c) 2016 Sven Langkamp <sven.langkamp@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+#ifndef REMOTECONTROL_H
+#define REMOTECONTROL_H
+
+#include <QVariant>
+
+#include <kis_view_plugin.h>
+
+class KisPaintopControlObject;
- class KisOpcUaServer;
+
+class RemoteControl : public KisViewPlugin
+{
+ Q_OBJECT
+public:
+ RemoteControl(QObject *parent, const QVariantList &);
+ virtual ~RemoteControl();
+
+private:
+ KisPaintopControlObject* m_paintOpControl;
- KisOpcUaServer* m_server;
+
+};
+
+#endif // REMOTECONTROL_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic