narrowPolyViewerCmd.cpp
#include "narrowPolyViewerCmd.h"
#include <maya/MItDag.h>
#include <maya/MGlobal.h>
#include <maya/MSyntax.h>
#include <maya/MArgParser.h>
#include <maya/MArgList.h>
#include <maya/MSelectionList.h>
#include <maya/MFnCamera.h>
#include <maya/MIOStream.h>
narrowPolyViewerCmd::narrowPolyViewerCmd()
: MPxModelEditorCommand()
{
}
narrowPolyViewerCmd::~narrowPolyViewerCmd()
{
}
void* narrowPolyViewerCmd::creator()
{
return new narrowPolyViewerCmd();
}
MStatus narrowPolyViewerCmd::appendSyntax()
{
MStatus ReturnStatus;
MSyntax theSyntax = syntax(&ReturnStatus);
if (MS::kSuccess != ReturnStatus) {
MGlobal::displayError("Could not get the parent's syntax");
return ReturnStatus;
}
theSyntax.addFlag(kInitFlag,
kInitFlagLong);
theSyntax.addFlag(kResultsFlag,
kResultsFlagLong);
theSyntax.addFlag(kClearFlag,
kClearFlagLong);
theSyntax.addFlag(kToleranceFlag,
kToleranceFlagLong,
MSyntax::kDouble);
return ReturnStatus;
}
MStatus narrowPolyViewerCmd::doEditFlags()
{
MStatus ReturnStatus = MS::kSuccess;
MPx3dModelView *user3dModelView = modelView();
if (NULL == user3dModelView) {
MGlobal::displayError("NULL == user3dModelView!");
return MS::kFailure;
}
if (user3dModelView->viewType() != "narrowPolyViewer") {
MGlobal::displayError("This view is not a narrowPolyViewer");
return MS::kFailure;
}
narrowPolyViewer *mpView = (narrowPolyViewer *)user3dModelView;
MArgParser argData = parser();
if (argData.isFlagSet(kInitFlag)) {
return initTests(*mpView);
} else if (argData.isFlagSet(kResultsFlag)) {
return testResults(*mpView);
} else if (argData.isFlagSet(kClearFlag)) {
return clearResults(*mpView);
} else if (argData.isFlagSet(kToleranceFlag)) {
double tol;
argData.getFlagArgument(kToleranceFlag, 0, tol);
mpView->tol = tol;
mpView->refresh(true, true);
} else {
return MS::kUnknownParameter;
}
return ReturnStatus;
}
MStatus narrowPolyViewerCmd::doQueryFlags()
{
return ParentClass::doQueryFlags();
}
MStatus narrowPolyViewerCmd::clearResults(narrowPolyViewer &view)
{
view.removeAllCameras();
fCameraList.clear();
return MS::kSuccess;
}
MStatus narrowPolyViewerCmd::initTests(narrowPolyViewer &view)
{
MGlobal::displayInfo("narrowPolyViewerCmd::initTests");
clearResults(view);
MDagPath cameraPath;
MStatus status = MS::kSuccess;
MItDag dagIterator(MItDag::kDepthFirst, MFn::kCamera);
for (; !dagIterator.isDone(); dagIterator.next()) {
if (!dagIterator.getPath(cameraPath)) {
continue;
}
MFnCamera camera(cameraPath, &status);
if (MS::kSuccess != status) {
continue;
}
MGlobal::displayInfo(camera.fullPathName());
fCameraList.append(cameraPath);
}
if (MS::kSuccess !=
view.setCameraList(fCameraList)) {
MGlobal::displayError("Could not set the list of cameras");
return MS::kFailure;
} else {
view.refresh();
}
return MS::kSuccess;
}
MStatus narrowPolyViewerCmd::testResults(narrowPolyViewer &view)
{
cout << "fCameraList.length() = " << fCameraList.length() << endl;
cout << "fCameraList = " << fCameraList << endl;
cout << "view.fTestCameraList.length() = " << view.fTestCameraList.length() << endl;
cout << "view.fTestCameraList = " << view.fTestCameraList << endl;
return MS::kSuccess;
}