diff --git a/plugins/extensions/remotecontrol/kis_opcua_server.cpp b/plugins/extensions/remotecontrol/kis_opcua_server.cpp index 8a563242f7..a7d3564b44 100644 --- a/plugins/extensions/remotecontrol/kis_opcua_server.cpp +++ b/plugins/extensions/remotecontrol/kis_opcua_server.cpp @@ -1,196 +1,193 @@ /* * * 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-1301, USA. */ #include "kis_opcua_server.h" #include #include #include "open62541.h" QMap > m_variableMap; 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) { dataValue->hasValue = true; QString id = uaStringToQString(nodeid.identifier.string); if(!m_variableMap.contains(id)){ return UA_STATUSCODE_BADUNEXPECTEDERROR; } QPair property = m_variableMap[id]; QObject* object = property.first; QMetaProperty prop = object->metaObject()->property(property.second); QVariant value = prop.read(object); 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) { QString id = uaStringToQString(nodeid.identifier.string); if(!m_variableMap.contains(id)){ return UA_STATUSCODE_BADUNEXPECTEDERROR; } QPair property = m_variableMap[id]; - qDebug() << property.second; 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); return UA_STATUSCODE_GOOD; } KisOpcUaServer::KisOpcUaServer() { } 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(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; 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); - - qDebug() << QString("%1").arg(retval, 0, 16);; } objectIndex++; } UA_Server_run_startup(server); // if(retval != UA_STATUSCODE_GOOD) // { // UA_Server_delete(server); // nl.deleteMembers(&nl); // return; // } while(running) { UA_UInt16 timeout = UA_Server_run_iterate(server, false); struct timeval tv; tv.tv_sec = 0; tv.tv_usec = timeout * 1000; select(0, NULL, NULL, NULL, &tv); } UA_Server_run_shutdown(server); } void KisOpcUaServer::addObject(QObject *object) { m_objects.append(object); } diff --git a/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp b/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp index 3197ede9e8..c6e3651ce7 100644 --- a/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp +++ b/plugins/extensions/remotecontrol/kis_paintop_control_object.cpp @@ -1,50 +1,89 @@ /* * * 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-1301, USA. */ #include "kis_paintop_control_object.h" #include #include #include #include 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); } double KisPaintopControlObject::brushSize() { if(!m_view || !m_view->resourceProvider()) { return 0.0; } return m_view->resourceProvider()->currentPreset()->settings()->paintOpSize().width(); } + +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 --git a/plugins/extensions/remotecontrol/kis_paintop_control_object.h b/plugins/extensions/remotecontrol/kis_paintop_control_object.h index 9ca59e1aff..cd622bfd4b 100644 --- a/plugins/extensions/remotecontrol/kis_paintop_control_object.h +++ b/plugins/extensions/remotecontrol/kis_paintop_control_object.h @@ -1,42 +1,50 @@ /* * * 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-1301, USA. */ #ifndef KISPAINTOPCONTROLOBJECT_H #define KISPAINTOPCONTROLOBJECT_H #include class KisViewManager; class KisPaintopControlObject : public QObject { Q_OBJECT public: explicit KisPaintopControlObject(KisViewManager* view, QObject *parent = 0); Q_PROPERTY(double brushSize READ brushSize WRITE setBrushSize) + Q_PROPERTY(double opacity READ opacity WRITE setOpacity) + Q_PROPERTY(double flow READ flow WRITE setFlow) - void setBrushSize(double flow); + void setBrushSize(double size); double brushSize(); + void setOpacity(double opacity); + double opacity(); + + void setFlow(double flow); + double flow(); + private: KisViewManager* m_view; }; #endif // KISPAINTOPCONTROLOBJECT_H