七、context command
context command是用来新建自己的工具,可以调用OPENGL,获取鼠标操作函数,在view窗口画自己想画的东西。(我是这麽理解的,可以以后再确定一下)
下面是一个context command的例子,通过例子来说明context command的代码怎么写,又怎么样来activate。
包含的头文件:
#include <maya/MIOStream.h>
#include <math.h>
#include <stdlib.h> #include <maya/MFnPlugin.h>
#include <maya/MString.h>
#include <maya/MGlobal.h>
#include <maya/M3dView.h>
#include <maya/MDagPath.h> #include <maya/MItSelectionList.h>
#include <maya/MSelectionList.h> #include <maya/MPxContextCommand.h>
#include <maya/MPxContext.h>
#include <maya/MEvent.h> #include <maya/MUIDrawManager.h>
#include <maya/MFrameContext.h>
#include <maya/MPoint.h>
#include <maya/MColor.h> #include <GL/gl.h>
#include <GL/glu.h>
1. 定义继承于MPxContext的类:
const char helpString[] =
"Click with left button or drag with middle button to select"; class marqueeContext : public MPxContext
{
public:
marqueeContext();
virtual void toolOnSetup( MEvent & event ); // Default viewport or hardware viewport methods override, will not be triggered in viewport 2.0.
virtual MStatus doPress( MEvent & event );
virtual MStatus doDrag( MEvent & event );
virtual MStatus doRelease( MEvent & event );
virtual MStatus doEnterRegion( MEvent & event ); // Viewport 2.0 methods, will only be triggered in viewport 2.0.
virtual MStatus doPress ( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context);
virtual MStatus doRelease( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context);
virtual MStatus doDrag ( MEvent & event, MHWRender::MUIDrawManager& drawMgr, const MHWRender::MFrameContext& context); private:
// Marquee draw method in default viewport or hardware viewport with immediate OpenGL call
void drawMarqueeGL();
// Common operation to handle when pressed
void doPressCommon( MEvent & event );
// Common operation to handle when released
void doReleaseCommon( MEvent & event ); short start_x, start_y;
short last_x, last_y; bool fsDrawn; MGlobal::ListAdjustment listAdjustment;
M3dView view;
};
其中doPress(), doRelease(), doDrag()函数,为函数重载,以方便不同版本的view进行绘制。
doPressCommon(), doReleaseCommon(), drawMarqueeGL()函数为上面三个函数不同版本之间的共同部分。以doDrag()为例子,具体参看document。
MStatus marqueeContext::doDrag( MEvent & event )
//
// Drag out the marquee (using OpenGL)
//
{
view.beginXorDrawing(); if (fsDrawn) {
// Redraw the marquee at its old position to erase it.
drawMarqueeGL();
} fsDrawn = true; // Get the marquee's new end position.
event.getPosition( last_x, last_y ); // Draw the marquee at its new position.
drawMarqueeGL(); view.endXorDrawing(); return MS::kSuccess;
}
void marqueeContext::drawMarqueeGL()
{
glBegin( GL_LINE_LOOP );
glVertex2i( start_x, start_y );
glVertex2i( last_x, start_y );
glVertex2i( last_x, last_y );
glVertex2i( start_x, last_y );
glEnd();
}
2. 编好自己的MPxContext之后,创建MPxContextCommand的子类来创建context 命令,该命令用来创建context工具。
class marqueeContextCmd : public MPxContextCommand
{
public:
marqueeContextCmd();
virtual MPxContext* makeObj();
static void* creator();
}; marqueeContextCmd::marqueeContextCmd() {} MPxContext* marqueeContextCmd::makeObj()
{
return new marqueeContext();
} void* marqueeContextCmd::creator()
{
return new marqueeContextCmd;
}
3. 最后通过MFnPlugin函数注册context command:
MStatus initializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj, PLUGIN_COMPANY, "12.0", "Any"); status = plugin.registerContextCommand( "marqueeToolContext",
marqueeContextCmd::creator );
return status;
} MStatus uninitializePlugin( MObject obj )
{
MStatus status;
MFnPlugin plugin( obj ); status = plugin.deregisterContextCommand( "marqueeToolContext" ); return status;
}
4. Adding a context command to the Maya shelf
There are two ways to "activate" or make your context the current context in Maya. The first is through the use of the setToolTo command. This command takes the name of a context (tool) and makes it the current context.
A second method is by making an icon to represent your context and putting it in the Maya tool shelf. The Maya tool shelf can store two kinds of buttons, command buttons and tool buttons. When the tool is activated, its icon is displayed next to the standard Maya tools in the toolbar.
The following is a set of MEL commands you can use to create a context and tool button for the context.
marqueeToolContext marqueeToolContext1;
setParent Shelf1; //注意这的shelf1应该用shelf子目录的名字代替,例如Custom
toolButton -cl toolCluster
-t marqueeToolContext1
-i1 "marqueeTool.xpm" marqueeTool1;
This MEL code instantiates an instance of the marqueeToolContext and adds it to the "Common" tools shelf.
marqueeTool.xpm, the icon for the tool, must be in the XBMLANGPATH to be found and added to the UI. If it is not found, a blank spot will appear on the shelf, but the tool will still be usable.
This code could either be sourced by hand from the MEL command window, or it could be invoked withMGlobal::sourceFile() in the initializePlugin() method of the plug-in.
七、context command的更多相关文章
- 八、MPxToolCommand, tool command
1. Tool Property Sheets: 是用来更改context属性的编辑框,类似于attribute editor.(property和attribute本质上是一个意思)作用于activ ...
- C#设计模式(15)——命令模式(Command Pattern)
一.前言 之前一直在忙于工作上的事情,关于设计模式系列一直没更新,最近项目中发现,对于设计模式的了解是必不可少的,当然对于设计模式的应用那更是重要,可以说是否懂得应用设计模式在项目中是衡量一个程序员的 ...
- .NET设计模式(17):命令模式(Command Pattern)(转)
概述 在软件系统中,“行为请求者”与“行为实现者”通常呈现一种“紧耦合”.但在某些场合,比如要对行为进行“记录.撤销/重做.事务”等处理,这种无法抵御变化的紧耦合是不合适的.在这种情况下,如何将“行为 ...
- NET设计模式 第二部分 行为型模式(16):命令模式(Command Pattern)
命令模式(Command Pattern) ——.NET设计模式系列之十七 TerryLee,2006年7月 概述 在软件系统中,“行为请求者”与“行为实现者”通常呈现一种“紧耦合”.但在某些场合,比 ...
- 【16】命令模式(Command Pattern)
一.前言 最近项目中发现,对于设计模式的了解是必不可少的,当然对于设计模式的应用那更是重要,可以说是否懂得应用设计模式在项目中是衡量一个程序员的技术水平,因为对于一个功能的实现,高级工程师和初级工程师 ...
- Docker Context基本原理
Docker Context基本原理 介绍 本指南介绍了上下文如何使单个Docker CLI轻松管理多个Swarm集群.多个Kubernetes集群和多个单独的Docker节点. 单个Docker C ...
- 美图DPOS以太坊教程(Docker版)
一.前言 最近,需要接触区块链项目的主链开发,在EOS.BTC.ethereum.超级账本这几种区块链技术当中,相互对比后,最终还是以go-ethereum为解决方案. 以ethereum为基准去找解 ...
- Linux操作系统的进程管理
Linux操作系统的进程管理 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.进程相关概念 1>.进程概述 内核的功用: 进程管理.文件系统.网络功能.内存管理.驱动程序. ...
- ps示例
博客PS示例 一显示指定真正用户名(RUID)或用户ID的进程 打开另外一个终端 [root@centos72 ~]# id wang uid=1000(wang) gid=1000(wang) gr ...
随机推荐
- python 程序构架
http://blog.csdn.net/heyabo/article/details/8806176
- ubuntu auto install update
sudo apt-get update sudo apt-get dist-upgrade 32bit mode sudo dpkg --add-architecture i386
- Swift语言—常量、变量、类型赋值
常量:常量在作用域内不能被赋值且不会发生改变,只读不写,每个常量都必须有唯一的名字和内存空间:关键字:let 变量:变量在作用区域内可以它的值可以被改变,可读可写可覆盖,每个常量都必须有唯一的名字 ...
- JVM-并发-Java 内存模型
Java内存模型 (1). 主内存与工作内存 Java内存模型规定了所有的变量都存储在主内存中. 每类线程的变量的主内存副本拷贝,线程对变量的所有操作(读操作,赋值操作等)都必须工作内存中进行,而不能 ...
- 在 Sublime Text 2 中使用 SFTP 插件快速编辑远程服务器文件
在 Sublime Text 2 中使用 SFTP 插件快速编辑远程服务器文件 开源程序 浏览:29555 2013年05月02日 文章目录[隐藏] 常见的工作流程 SFTP 安装和使用方法 第一步: ...
- 集合运算(A-B)U(B-A)
实质是两个数组的合并(顺序表最好是有序的) #include<iostream> using namespace std; //创建顺序表 void create(int A[],int ...
- leetcde37. Sudoku Solver
Write a program to solve a Sudoku puzzle by filling the empty cells. Empty cells are indicated by th ...
- 对于unallocated space的翻译 我想说几句话
在sqlserver中,当我们使用sp_spaceused查看数据库空间使用情况的时候 会看到属性unallocated space.所有的中文翻译都是“未保留供数据库对象使用的数据库空间”, 作为中 ...
- vs2010编译出的exe“应用程序无法正常启动(0xc0150002)”
今天编译出一个使用ogre1.6.5动态库的应用程序,启动时报"应用程序无法正常启动(0xc0150002)"的错误提示. 编译环境是Win10+VS2010.这个错误可以在Win ...
- curl的POST与GET方法
$url = '127.0.0.1/shang/bb.php'; $data = array('name'=>'赵猛','age'=>'23'); print_r(get($u ...