• ObjectARX(CAD)_Step2_1


    Adding Commands using the ObjectARX Wizardk

    本章的目的是为了在我们通过 ObjectARX Wizard 构建的项目中,添加两个 CAD 命令

    1. Object Wizard 生成的 acrxEntryPoint.cpp 文件分析

    完整代码
    //-----------------------------------------------------------------------------
    //----- acrxEntryPoint.cpp
    //-----------------------------------------------------------------------------
    #include "StdAfx.h"
    #include "resource.h"
    
    //-----------------------------------------------------------------------------
    #define szRDS _RXST("asdk")
    
    //-----------------------------------------------------------------------------
    //----- ObjectARX EntryPoint, AutoCAD 传递信息地主要入口
    class CWizardInitionApp : public AcRxArxApp {
    
    public:
    	CWizardInitionApp () : AcRxArxApp () {}
    
    	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
    		// TODO: Load dependencies here
    
    		// You *must* call On_kInitAppMsg here
    		AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
    		
    		// TODO: Add your initialization code here
    
    		return (retCode) ;
    	}
    
    	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
    		// TODO: Add your code here
    
    		// You *must* call On_kUnloadAppMsg here
    		AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
    
    		// TODO: Unload dependencies here
    
    		return (retCode) ;
    	}
    
    	virtual void RegisterServerComponents () {
    	}
    	
    	// The ACED_ARXCOMMAND_ENTRY_AUTO macro can be applied to any static member 
    	// function of the CWizardInitionApp class.
    	// The function should take no arguments and return nothing.
    	//
    	// NOTE: ACED_ARXCOMMAND_ENTRY_AUTO has overloads where you can provide resourceid and
    	// have arguments to define context and command mechanism.
    	
    	// ACED_ARXCOMMAND_ENTRY_AUTO(classname, group, globCmd, locCmd, cmdFlags, UIContext)
    	// ACED_ARXCOMMAND_ENTRYBYID_AUTO(classname, group, globCmd, locCmdId, cmdFlags, UIContext)
    	// only differs that it creates a localized name using a string in the resource file
    	//   locCmdId - resource ID for localized command
    
    	// Modal Command with localized name
    	// ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL)
    	static void asdkMyGroupMyCommand () {
    		// Put your command code here
    
    	}
    
    	// Modal Command with pickfirst selection
    	// ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET)
    	static void asdkMyGroupMyPickFirst () {
    		ads_name result ;
    		int iRet =acedSSGet (ACRX_T("_I"), NULL, NULL, NULL, result) ;
    		if ( iRet == RTNORM )
    		{
    			// There are selected entities
    			// Put your command using pickfirst set code here
    		}
    		else
    		{
    			// There are no selected entities
    			// Put your command code here
    		}
    	}
    
    	// Application Session Command with localized name
    	// ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION)
    	static void asdkMyGroupMySessionCmd () {
    		// Put your command code here
    	}
    
    	// The ACED_ADSFUNCTION_ENTRY_AUTO / ACED_ADSCOMMAND_ENTRY_AUTO macros can be applied to any static member 
    	// function of the CWizardInitionApp class.
    	// The function may or may not take arguments and have to return RTNORM, RTERROR, RTCAN, RTFAIL, RTREJ to AutoCAD, but use
    	// acedRetNil, acedRetT, acedRetVoid, acedRetInt, acedRetReal, acedRetStr, acedRetPoint, acedRetName, acedRetList, acedRetVal to return
    	// a value to the Lisp interpreter.
    	//
    	// NOTE: ACED_ADSFUNCTION_ENTRY_AUTO / ACED_ADSCOMMAND_ENTRY_AUTO has overloads where you can provide resourceid.
    	
    	//- ACED_ADSFUNCTION_ENTRY_AUTO(classname, name, regFunc) - this example
    	//- ACED_ADSSYMBOL_ENTRYBYID_AUTO(classname, name, nameId, regFunc) - only differs that it creates a localized name using a string in the resource file
    	//- ACED_ADSCOMMAND_ENTRY_AUTO(classname, name, regFunc) - a Lisp command (prefix C:)
    	//- ACED_ADSCOMMAND_ENTRYBYID_AUTO(classname, name, nameId, regFunc) - only differs that it creates a localized name using a string in the resource file
    
    	// Lisp Function is similar to ARX Command but it creates a lisp 
    	// callable function. Many return types are supported not just string
    	// or integer.
    	// ACED_ADSFUNCTION_ENTRY_AUTO(CWizardInitionApp, MyLispFunction, false)
    	static int ads_MyLispFunction () {
    		//struct resbuf *args =acedGetArgs () ;
    		
    		// Put your command code here
    
    		//acutRelRb (args) ;
    		
    		// Return a value to the AutoCAD Lisp Interpreter
    		// acedRetNil, acedRetT, acedRetVoid, acedRetInt, acedRetReal, acedRetStr, acedRetPoint, acedRetName, acedRetList, acedRetVal
    
    		return (RTNORM) ;
    	}
    	
    } ;
    
    //-----------------------------------------------------------------------------
    IMPLEMENT_ARX_ENTRYPOINT(CWizardInitionApp)
    
    ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MyCommand, MyCommandLocal, ACRX_CMD_MODAL, NULL)
    ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MyPickFirst, MyPickFirstLocal, ACRX_CMD_MODAL | ACRX_CMD_USEPICKSET, NULL)
    ACED_ARXCOMMAND_ENTRY_AUTO(CWizardInitionApp, asdkMyGroup, MySessionCmd, MySessionCmdLocal, ACRX_CMD_MODAL | ACRX_CMD_SESSION, NULL)
    ACED_ADSSYMBOL_ENTRY_AUTO(CWizardInitionApp, MyLispFunction, false)
    

    2. 在 acrxEntryPoint.cpp 中实现两个方法 myInput & mySelect

    原始生成地代码有些目前我们不需要的部分, 我们通过一些简单的删改, 在代码中添加两个函数 AsdkStep02_myInput & AsdkStep02_mySelect

    • "MYINPUT" 命令用于演示 ObjectARX输入函数 的使用
      a. 要求用户输入一个整数值,限制这个值必须大于零;
      b. 要求用户输入一个真实值, 同时允许基于关键字的输入, 比如用户可以键入这三个值: (PI, A, B), 如果用户键入的是 <ENTER> 键, 则默认是输入 "C", "PI" 的值是一个双精度的 3.14, "A" 的值 是 10.0;
      c. 额外考虑, 如果用户在命令执行过程中, 使用 <ESC> 按键时的处理方法;
      d. 在 AutoCAD 命令提示符 处显示 整型变量 和 双精度变量 的值;
    图示
    • "MYSELECT" 命令用于演示 ObjectARX实体选择函数 的使用
      a. 要求用户选择一个实体(entity)
      b. 如果成功选择实体, 在命令提示行显示所选择实体的对象ID, 这是 ads_name 数据类型的第一个元素;
    图示
    完整代码
    
    //-----------------------------------------------------------------------------
    //----- ObjectARX EntryPoint
    class CStep02App : public AcRxArxApp {
    
    public:
    	CStep02App () : AcRxArxApp () {}
    
    	virtual AcRx::AppRetCode On_kInitAppMsg (void *pkt) {
    		AcRx::AppRetCode retCode =AcRxArxApp::On_kInitAppMsg (pkt) ;
    		// TODO: Add your initialization code here
    
    		return (retCode) ;
    	}
    
    	virtual AcRx::AppRetCode On_kUnloadAppMsg (void *pkt) {
    		AcRx::AppRetCode retCode =AcRxArxApp::On_kUnloadAppMsg (pkt) ;
    		// TODO: Add your code here
    
    		return (retCode) ;
    	}
    
    	virtual void RegisterServerComponents () 
    	{
    	}
    
    	// ----- AsdkStep02._myInput command (do not rename)
        /*
        * MYINPUT 命令, 主要用于演示 ObjectARX 输入函数的使用
        */
    	static void AsdkStep02_myInput(void)
    	{
    		// Add your code for command AsdkStep02._myInput here
    		int stat, iValue ;
    		double rValue ;
    		TCHAR kWord [133] ;
    
    		acedInitGet (RSG_NONEG | RSG_NOZERO, _T("")) ;
    
    		if ( acedGetInt (_T("\nEnter an integer value: "), &iValue) != RTNORM )
    			return ;
    
    		rValue =12.0 ;
    		acedInitGet (RSG_NOZERO, _T("PI A B C")) ;
    		stat =acedGetReal (_T("\nEnter a real value [PI/A/B/C] <C>: "), &rValue) ;
    		switch (stat) {
    			case RTCAN: // User termination
    				return ;
    			case RTKWORD: // Got a keyword
    				if ( acedGetInput (kWord) != RTNORM )
    					return ;
    				if ( !_tcscmp (_T("PI"), kWord) )
    					rValue =3.14 ;
    				else if ( !_tcscmp (_T("A"), kWord) )
    					rValue =10 ;
    				else if ( !_tcscmp (_T("B"), kWord) )
    					rValue =11 ;
    				else if ( !_tcscmp (_T("C"), kWord) )
    					rValue =12 ;
    				break ;
    			case RTNONE:
    				acutPrintf (_T("\nTake default rValue %lf"), rValue) ;
    				break ;
    			case RTNORM:
    				break ;
    			default:
    				return ;
    		}
    
    		acutPrintf (_T("\nInteger : %d"), iValue) ;
    		acutPrintf (_T("\nReal    : %lf"), rValue) ;
    	}
    
    	// ----- AsdkStep02._mySelect command (do not rename)
    	static void AsdkStep02_mySelect(void)
    	{
    		// Add your code for command AsdkStep02._mySelect here
    		ads_name en ;
    		ads_point pt ;
    
    		if ( acedEntSel (NULL, en, pt) != RTNORM )
    			return ;
    
    		acutPrintf (_T("\nYou selected entity ID: %ld"), en [0]) ;
    	}
    } ;
    
    //-----------------------------------------------------------------------------
    IMPLEMENT_ARX_ENTRYPOINT(CStep02App)
    
    ACED_ARXCOMMAND_ENTRY_AUTO(CStep02App, AsdkStep02, _mySelect, mySelect, ACRX_CMD_TRANSPARENT, NULL)
    ACED_ARXCOMMAND_ENTRY_AUTO(CStep02App, AsdkStep02, _myInput, myInput, ACRX_CMD_TRANSPARENT, NULL)
    
    
  • 相关阅读:
    烂泥:KVM使用NAT联网并为VM配置iptables端口转发
    烂泥:CentOS6.5挂载windows共享文件夹
    烂泥:KVM、kickstart与FTP集成
    js-浅显基础-正则表达式集
    小程序-轮播图案例
    小程序-TabBar点击切换
    js-禁止微信内置浏览器调整字体大小
    小程序-分享到群或好友
    小程序-提交信息(姓名,电话)
    js-在url后面添加时间戳清除浏览器打开页面的缓存
  • 原文地址:https://www.cnblogs.com/InfField/p/16039611.html
Copyright © 2020-2023  润新知