From c96876fdccb70401dee50f7b71db2934f5b9d728 Mon Sep 17 00:00:00 2001 From: ilgarlunin Date: Tue, 10 Mar 2020 17:00:43 +0300 Subject: [PATCH] launch window cmd --- src/constants.h | 3 +- src/main.cpp | 76 ++++++++++++++++++++++++++++++++++++++----------- src/utils.cpp | 10 +++++++ src/utils.h | 1 + 4 files changed, 73 insertions(+), 17 deletions(-) diff --git a/src/constants.h b/src/constants.h index b36d397..0698c14 100644 --- a/src/constants.h +++ b/src/constants.h @@ -1,7 +1,8 @@ #ifndef CONSTANTS_H #define CONSTANTS_H -static const char* WORKEPACE_CONTROL_NAME = "Rokoko Studio Live"; +static const char* WORKSPACE_CONTROL_NAME = "RSMLControl"; +static const char* WIDGET_TITLE = "Rokoko Studio Live"; static const int INITIAL_WINDOW_WIDTH = 400; static const int MINIMUM_WINDOW_WIDTH = 100; static const int INITIAL_WINDOW_HEIGHT = 800; diff --git a/src/main.cpp b/src/main.cpp index e1715f2..b3ca098 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,7 +4,9 @@ #include #include +#include +#include #include #include #include @@ -20,32 +22,74 @@ QPointer rsmlWidget; QPointer workspaceControl; -MStatus initializePlugin(MObject) { +class InvokeRSLM : MPxCommand { +public: + InvokeRSLM() {} + + ~InvokeRSLM() { + + } + + MStatus doIt(const MArgList &args) override + { + Q_UNUSED(args); + + MStatus result = MStatus::kSuccess; + + if(!rsmlWidget.isNull()) { + // do nothing if already visible + if(rsmlWidget->isVisible()) return MStatus::kFailure; + } + + + if(workspaceControl.isNull()) + { + MString cmd; + char sizeArgs[128]; + sprintf(sizeArgs, "-iw %d -mw %d -ih %d -mh %d", INITIAL_WINDOW_WIDTH, MINIMUM_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT, MINIMUM_WINDOW_HEIGHT); + cmd.format("workspaceControl -l \"^1s\" -fl true ^2s \"RSMLControl\";", WIDGET_TITLE, sizeArgs); + MGlobal::executeCommand(cmd); + } + + workspaceControl = MQtUtil::findControl(WORKSPACE_CONTROL_NAME); + rsmlScrollArea = new QScrollArea(workspaceControl); + rsmlWidget = new RootWidget(workspaceControl); + rsmlScrollArea->setWidget(rsmlWidget); + rsmlScrollArea->setWidgetResizable(true); + MQtUtil::addWidgetToMayaLayout(rsmlScrollArea, workspaceControl); + + return result; + } + + static void* creator() { + return new InvokeRSLM; + } +}; + + +MStatus initializePlugin(MObject obj) { MStatus result = MStatus::kSuccess; - MString cmd; - char sizeArgs[128]; - sprintf(sizeArgs, "-iw %d -mw %d -ih %d -mh %d", INITIAL_WINDOW_WIDTH, MINIMUM_WINDOW_WIDTH, INITIAL_WINDOW_HEIGHT, MINIMUM_WINDOW_HEIGHT); - cmd.format("workspaceControl -l \"^1s\" -fl true ^2s \"RSMLControl\"", WORKEPACE_CONTROL_NAME, sizeArgs); - MGlobal::executeCommand(cmd); - workspaceControl = MQtUtil::findControl("RSMLControl"); - rsmlScrollArea = new QScrollArea(workspaceControl); - rsmlWidget = new RootWidget(workspaceControl); - rsmlScrollArea->setWidget(rsmlWidget); - rsmlScrollArea->setWidgetResizable(true); - MQtUtil::addWidgetToMayaLayout(rsmlScrollArea, workspaceControl); + + const char* versionString = QString("v%1.%2.%3").arg(VERSION_MAJOR).arg(VERSION_MINOR).arg(VERSION_PATCH).toStdString().c_str(); + MFnPlugin plugin(obj, "Rokoko", versionString); + result = plugin.registerCommand("showRSLM", InvokeRSLM::creator); + return result; } -MStatus uninitializePlugin(MObject plugin) +MStatus uninitializePlugin(MObject obj) { MStatus result = MStatus::kSuccess; + MFnPlugin plugin(obj); + + plugin.deregisterCommand("showRSLM"); + if (!workspaceControl.isNull()) { - MGlobal::executeCommand("workspaceControl -e -close \"RSMLControl\""); - MGlobal::executeCommand("deleteUI -wnd \"RSMLControl\""); - workspaceControl.clear(); + // mel command will clear workspaceControl QPointer + Utils::removeMayaWSControl(); } if(!rsmlWidget.isNull()) { diff --git a/src/utils.cpp b/src/utils.cpp index 1cec9e0..0e56291 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -3,6 +3,7 @@ #include "mapping.h" #include "animations.h" #include "recorder.h" +#include "constants.h" #include #include @@ -54,6 +55,15 @@ void Utils::fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHashinstallCallbacks(); diff --git a/src/utils.h b/src/utils.h index 432ceae..f8b1f04 100644 --- a/src/utils.h +++ b/src/utils.h @@ -13,6 +13,7 @@ class Utils { static MVector rsToMaya(MVector); static MQuaternion rsToMaya(MQuaternion); static void fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash &map); + static void removeMayaWSControl(); static void RSLMInit(); static void RSLMShutdown(); };