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 [L= icense: GPL (v2+)] A +10 -1 plugins/extensions/remotecontrol/kis_opcua_server.h [Lic= ense: GPL (v2+)] A +3 -4 plugins/extensions/remotecontrol/kis_paintop_control_object.= cpp [License: GPL (v2+)] A +3 -3 plugins/extensions/remotecontrol/remotecontrol.cpp [Lice= nse: GPL (v2+)] A +0 -2 plugins/extensions/remotecontrol/remotecontrol.h [Licens= e: 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 + * + * 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-1= 301, USA. + */ + +#include "kis_opcua_server.h" + +#include +#include ++#include + - #include "open62541.h" + - QMap > m_variableMap; ++#include "open62541.h" + +QString uaStringToQString(const UA_String& uaString) +{ + int length =3D uaString.length; + char* cstring =3D new char[length+1]; + memcpy(cstring, uaString.data, length ); + cstring[length] =3D '\0'; + + QString result =3D QString(cstring); + + delete[] cstring; + return result; +} + - static UA_StatusCode readVariable(void *handle, const UA_NodeId nodeid, U= A_Boolean sourceTimeStamp, - const UA_NumericRange *range, UA_DataVal= ue *dataValue) { ++static UA_StatusCode readVariableCallback(void *handle, const UA_NodeId n= odeid, UA_Boolean sourceTimeStamp, ++ const UA_NumericRange *range, U= A_DataValue *dataValue) { + + dataValue->hasValue =3D true; + + QString id =3D uaStringToQString(nodeid.identifier.string); - = - if(!m_variableMap.contains(id)){ - return UA_STATUSCODE_BADUNEXPECTEDERROR; - } - QPair property =3D m_variableMap[id]; - = - QObject* object =3D property.first; - QMetaProperty prop =3D object->metaObject()->property(property.second= ); - = - QVariant value =3D prop.read(object); ++ = ++ QVariant value =3D KisOpcUaServer::instance()->readVariable(id); + + switch (value.type()) { + case QVariant::Int: + { + UA_Int32 intValue =3D value.toInt(); + UA_Variant_setScalarCopy(&dataValue->value, &intValue, &UA_TY= PES[UA_TYPES_INT32]); + break; + } + case QVariant::Double: + { + UA_Double doubleValue =3D 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_Numer= icRange *range) { ++static UA_StatusCode writeVariableCallback(void *handle, const UA_NodeId = nodeid, ++ const UA_Variant *data, const = UA_NumericRange *range) { + + + QString id =3D uaStringToQString(nodeid.identifier.string); + - if(!m_variableMap.contains(id)){ - return UA_STATUSCODE_BADUNEXPECTEDERROR; - } - QPair property =3D m_variableMap[id]; - = - QObject* object =3D property.first; - QMetaProperty prop =3D object->metaObject()->property(property.second= ); - = + QVariant value; + if(UA_Variant_isScalar(data) && data->data) { + if(data->type =3D=3D &UA_TYPES[UA_TYPES_INT32]) { + int intValue =3D *(UA_UInt32*)data->data; + value =3D QVariant(intValue); + + } + else if(data->type =3D=3D &UA_TYPES[UA_TYPES_DOUBLE]) { + double doubleValue =3D *(UA_Double*)data->data; + value =3D 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 =3D true; + + UA_ServerConfig config =3D UA_ServerConfig_standard; + UA_ServerNetworkLayer nl =3D UA_ServerNetworkLayerTCP(UA_ConnectionCo= nfig_standard, 16664); + config.networkLayers =3D &nl; + config.networkLayersSize =3D 1; + UA_Server *server =3D UA_Server_new(config); + + int objectIndex =3D 1000; + foreach(QObject* object, m_objects) { + + UA_ObjectAttributes object_attr; + UA_ObjectAttributes_init(&object_attr); + object_attr.description =3D UA_LOCALIZEDTEXT("en_US", ""); + object_attr.displayName =3D UA_LOCALIZEDTEXT("en_US", object->obj= ectName().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 =3D object->metaObject()->propertyCount(); + + for(int i =3D 0; i < propertyCount; i++) + { + QMetaProperty property =3D object->metaObject()->property(i); + + QString variableName =3D object->objectName() + '.' + QString= (property.name()); + m_variableMap[variableName] =3D QPair(object, = i); + + QString browseName =3D QString(property.name()); + + UA_NodeId variableNodeId =3D UA_NODEID_STRING(1, variableName= .toLatin1().data()); + UA_QualifiedName variableNodeName =3D UA_QUALIFIEDNAME(1, bro= wseName.toLatin1().data()); + + UA_DataSource dataSource; + dataSource.handle =3D 0; - dataSource.read =3D &readVariable; - dataSource.write =3D &writeVariable; ++ dataSource.read =3D &readVariableCallback; ++ dataSource.write =3D &writeVariableCallback; + + UA_VariableAttributes attr; + UA_VariableAttributes_init(&attr); + attr.description =3D UA_LOCALIZEDTEXT("en_US", variableName.t= oLatin1().data()); + attr.displayName =3D UA_LOCALIZEDTEXT("en_US", variableName.t= oLatin1().data()); + + UA_StatusCode retval =3D UA_Server_addDataSourceVariableNode(= server, variableNodeId, + UA_= NODEID_NUMERIC(1, objectIndex), + UA_= NODEID_NUMERIC(0, UA_NS0ID_ORGANIZES), + var= iableNodeName, UA_NODEID_NULL, attr, dataSource, NULL); + } + objectIndex++; + } + + UA_StatusCode retval =3D 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 property =3D m_variableMap[id]; ++ ++ QObject* object =3D property.first; ++ QMetaProperty prop =3D 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 property =3D m_variableMap[id]; ++ ++ QObject* object =3D property.first; ++ QMetaProperty prop =3D 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 + * + * 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-1= 301, USA. + */ + +#ifndef KISOPCUASERVER_H +#define KISOPCUASERVER_H + +#include +#include +#include +#include ++#include + +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 m_objects; ++ QMap > 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 + * + * 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-1= 301, USA. + */ + +#include "kis_paintop_control_object.h" +#include +#include +#include +#include + +KisPaintopControlObject::KisPaintopControlObject(KisViewManager* view, QO= bject *parent) : QObject(parent) +, m_view(view) +{ + setObjectName("PaintOp"); +} + +void KisPaintopControlObject::setBrushSize(double size) +{ + if(!m_view || !m_view->resourceProvider()) { + return; + } + = - qreal offset =3D size - m_view->resourceProvider()->currentPreset()->= settings()->paintOpSize().width(); - m_view->resourceProvider()->currentPreset()->settings()->changePaintO= pSize(offset, 0); ++ m_view->resourceProvider()->currentPreset()->settings()->setPaintOpSi= ze(size); + +} + +double KisPaintopControlObject::brushSize() +{ + if(!m_view || !m_view->resourceProvider()) { + return 0.0; + } - = - return m_view->resourceProvider()->currentPreset()->settings()->paint= OpSize().width(); ++ = ++ return m_view->resourceProvider()->currentPreset()->settings()->paint= OpSize(); +} + +double KisPaintopControlObject::flow() +{ + if(!m_view || !m_view->resourceProvider()) { + return 0.0; + } + + return m_view->resourceProvider()->currentPreset()->settings()->paint= OpFlow(); +} + +void KisPaintopControlObject::setFlow(double flow) +{ + if(!m_view || !m_view->resourceProvider()) { + return; + } + + m_view->resourceProvider()->currentPreset()->settings()->setPaintOpFl= ow(flow); +} + +double KisPaintopControlObject::opacity() +{ + if(!m_view || !m_view->resourceProvider()) { + return 0.0; + } + + return m_view->resourceProvider()->currentPreset()->settings()->paint= OpOpacity(); +} + +void KisPaintopControlObject::setOpacity(double opacity) +{ + if(!m_view || !m_view->resourceProvider()) { + return; + } + + m_view->resourceProvider()->currentPreset()->settings()->setPaintOpOp= acity(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 + * + * 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-1= 301, USA. + */ +#include "remotecontrol.h" + +#include +#include +#include + +#include "kis_paintop_control_object.h" +#include "kis_opcua_server.h" + +K_PLUGIN_FACTORY_WITH_JSON(RemoteControlFactory, "kritaremotecontrol.json= ", registerPlugin();) + +RemoteControl::RemoteControl(QObject *parent, const QVariantList &) + : KisViewPlugin(parent) +{ + m_paintOpControl =3D new KisPaintopControlObject(m_view, this); - m_server =3D new KisOpcUaServer(); ++ KisOpcUaServer* server =3D 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 + * + * 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-1= 301, USA. + */ +#ifndef REMOTECONTROL_H +#define REMOTECONTROL_H + +#include + +#include + +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