From 56312d00346537756b791c14a5433310a3a4c2c0 Mon Sep 17 00:00:00 2001 From: Jeremy Hu Date: Mon, 18 Mar 2019 08:34:37 +0930 Subject: [PATCH] Implement more commands for Remote IO --- src/remoteioconnection.cpp | 234 +++++++++++++++++++++++++++++++++++++ src/remoteioconnection.h | 8 ++ 2 files changed, 242 insertions(+) diff --git a/src/remoteioconnection.cpp b/src/remoteioconnection.cpp index 509935e8..d12dd10d 100644 --- a/src/remoteioconnection.cpp +++ b/src/remoteioconnection.cpp @@ -1,6 +1,7 @@ #include #include #include "remoteioconnection.h" +#include "bonemark.h" RemoteIoConnection::RemoteIoConnection(QTcpSocket *tcpSocket) : m_tcpSocket(tcpSocket) @@ -21,6 +22,14 @@ RemoteIoConnection::RemoteIoConnection(QTcpSocket *tcpSocket) : m_commandHandlers["removeedge"] = &RemoteIoConnection::commandRemoveEdge; m_commandHandlers["removepart"] = &RemoteIoConnection::commandRemovePart; m_commandHandlers["addnode"] = &RemoteIoConnection::commandAddNode; + m_commandHandlers["scalenodebyaddradius"] = &RemoteIoConnection::commandScaleNodeByAddRadius; + m_commandHandlers["movenodeby"] = &RemoteIoConnection::commandMoveNodeBy; + m_commandHandlers["setnodeorigin"] = &RemoteIoConnection::commandSetNodeOrigin; + m_commandHandlers["setnoderadius"] = &RemoteIoConnection::commandSetNodeRadius; + m_commandHandlers["setnodebonemark"] = &RemoteIoConnection::commandSetNodeBoneMark; + m_commandHandlers["switchnodexz"] = &RemoteIoConnection::commandSwitchNodeXZ; + m_commandHandlers["moveoriginby"] = &RemoteIoConnection::commandMoveOriginBy; + m_commandHandlers["addedge"] = &RemoteIoConnection::commandAddEdge; if (!DocumentWindow::documentWindows().empty()) { connectDocumentWindow(DocumentWindow::documentWindows().begin()->first); @@ -579,3 +588,228 @@ QByteArray RemoteIoConnection::commandAddNode(const QByteArray ¶meters, QStr m_currentDocumentWindow->document()->addNode(x, y, z, radius, fromNodeId); return QByteArray(); } + +QByteArray RemoteIoConnection::commandScaleNodeByAddRadius(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId, float amount + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + auto amountString = nextParameter(parameters, &offset); + if (amountString.isEmpty()) { + *errorMessage = "Must specify amount parameter"; + return QByteArray(); + } + float amount = amountString.toFloat(); + + m_currentDocumentWindow->document()->scaleNodeByAddRadius(nodeId, amount); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandMoveNodeBy(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId, float x, float y, float z + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + auto xString = nextParameter(parameters, &offset); + if (xString.isEmpty()) { + *errorMessage = "Must specify x parameter"; + return QByteArray(); + } + float x = xString.toFloat(); + + auto yString = nextParameter(parameters, &offset); + if (yString.isEmpty()) { + *errorMessage = "Must specify y parameter"; + return QByteArray(); + } + float y = yString.toFloat(); + + auto zString = nextParameter(parameters, &offset); + if (zString.isEmpty()) { + *errorMessage = "Must specify z parameter"; + return QByteArray(); + } + float z = zString.toFloat(); + + m_currentDocumentWindow->document()->moveNodeBy(nodeId, x, y, z); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandSetNodeOrigin(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId, float x, float y, float z + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + auto xString = nextParameter(parameters, &offset); + if (xString.isEmpty()) { + *errorMessage = "Must specify x parameter"; + return QByteArray(); + } + float x = xString.toFloat(); + + auto yString = nextParameter(parameters, &offset); + if (yString.isEmpty()) { + *errorMessage = "Must specify y parameter"; + return QByteArray(); + } + float y = yString.toFloat(); + + auto zString = nextParameter(parameters, &offset); + if (zString.isEmpty()) { + *errorMessage = "Must specify z parameter"; + return QByteArray(); + } + float z = zString.toFloat(); + + m_currentDocumentWindow->document()->setNodeOrigin(nodeId, x, y, z); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandSetNodeRadius(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId, float radius + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + auto radiusString = nextParameter(parameters, &offset); + if (radiusString.isEmpty()) { + *errorMessage = "Must specify radius parameter"; + return QByteArray(); + } + float radius = radiusString.toFloat(); + + m_currentDocumentWindow->document()->setNodeRadius(nodeId, radius); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandSetNodeBoneMark(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId, BoneMark mark + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + auto boneMarkString = nextParameter(parameters, &offset); + auto boneMark = BoneMarkFromString(boneMarkString.toUtf8().constData()); + + m_currentDocumentWindow->document()->setNodeBoneMark(nodeId, boneMark); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandSwitchNodeXZ(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid nodeId + + int offset = 0; + + QUuid nodeId = QUuid(nextParameter(parameters, &offset)); + if (nodeId.isNull()) { + *errorMessage = "Must specify nodeId parameter"; + return QByteArray(); + } + + m_currentDocumentWindow->document()->switchNodeXZ(nodeId); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandMoveOriginBy(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // float x, float y, float z + + int offset = 0; + + auto xString = nextParameter(parameters, &offset); + if (xString.isEmpty()) { + *errorMessage = "Must specify x parameter"; + return QByteArray(); + } + float x = xString.toFloat(); + + auto yString = nextParameter(parameters, &offset); + if (yString.isEmpty()) { + *errorMessage = "Must specify y parameter"; + return QByteArray(); + } + float y = yString.toFloat(); + + auto zString = nextParameter(parameters, &offset); + if (zString.isEmpty()) { + *errorMessage = "Must specify z parameter"; + return QByteArray(); + } + float z = zString.toFloat(); + + m_currentDocumentWindow->document()->moveOriginBy(x, y, z); + return QByteArray(); +} + +QByteArray RemoteIoConnection::commandAddEdge(const QByteArray ¶meters, QString *errorMessage) +{ + COMMAND_PRECHECK(); + + // QUuid fromNodeId, QUuid toNodeId + + int offset = 0; + + QUuid fromNodeId = QUuid(nextParameter(parameters, &offset)); + if (fromNodeId.isNull()) { + *errorMessage = "Must specify fromNodeId parameter"; + return QByteArray(); + } + + QUuid toNodeId = QUuid(nextParameter(parameters, &offset)); + if (toNodeId.isNull()) { + *errorMessage = "Must specify toNodeId parameter"; + return QByteArray(); + } + + m_currentDocumentWindow->document()->addEdge(fromNodeId, toNodeId); + return QByteArray(); +} + diff --git a/src/remoteioconnection.h b/src/remoteioconnection.h index 9dd24bc0..7794cecd 100644 --- a/src/remoteioconnection.h +++ b/src/remoteioconnection.h @@ -48,6 +48,14 @@ private: QByteArray commandRemoveEdge(const QByteArray ¶meters, QString *errorMessage); QByteArray commandRemovePart(const QByteArray ¶meters, QString *errorMessage); QByteArray commandAddNode(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandScaleNodeByAddRadius(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandMoveNodeBy(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandSetNodeOrigin(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandSetNodeRadius(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandSetNodeBoneMark(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandSwitchNodeXZ(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandMoveOriginBy(const QByteArray ¶meters, QString *errorMessage); + QByteArray commandAddEdge(const QByteArray ¶meters, QString *errorMessage); }; #endif