Skip to content

Commit

Permalink
launch window cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
IlgarLunin committed Mar 10, 2020
1 parent ec1b55e commit c96876f
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 17 deletions.
3 changes: 2 additions & 1 deletion src/constants.h
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
76 changes: 60 additions & 16 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

#include <QPointer>
#include <QScrollArea>
#include <QString>

#include <maya/MPxCommand.h>
#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MObject.h>
Expand All @@ -20,32 +22,74 @@ QPointer<RootWidget> rsmlWidget;
QPointer<QWidget> 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()) {
Expand Down
10 changes: 10 additions & 0 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "mapping.h"
#include "animations.h"
#include "recorder.h"
#include "constants.h"

#include <QString>
#include <QHash>
Expand Down Expand Up @@ -54,6 +55,15 @@ void Utils::fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash<QString,
}
}

void Utils::removeMayaWSControl()
{
QString closeCmd = QString("if (`window -ex \"%1\"`); workspaceControl -e -close \"%1\";").arg(WORKSPACE_CONTROL_NAME);
QString deleteCmd = QString("if (`window -ex \"%1\"`); deleteUI -wnd \"%1\";").arg(WORKSPACE_CONTROL_NAME);

MGlobal::executeCommand(closeCmd.toStdString().c_str());
MGlobal::executeCommand(deleteCmd.toStdString().c_str());
}

void Utils::RSLMInit()
{
Mapping::get()->installCallbacks();
Expand Down
1 change: 1 addition & 0 deletions src/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Utils {
static MVector rsToMaya(MVector);
static MQuaternion rsToMaya(MQuaternion);
static void fillFaceWeightsMap(const MFnBlendShapeDeformer &bsFn, QHash<QString, MPlug> &map);
static void removeMayaWSControl();
static void RSLMInit();
static void RSLMShutdown();
};
Expand Down

0 comments on commit c96876f

Please sign in to comment.