插件的开发方法2004-8-24一、创建插件接口1.1 头文件如:#ifndef CAAIAfrGeoCreationWkbAddin_h#define CAAIAfrGeoCreationWkbAddin_h// ApplicationFrame Framework#include <CA TIWorkbenchAddin.h>// Needed to derive from CATIWorkbenchAddin// Local Framework#include "CAAAfrGeoCreationWbench.h" // Needed to export the IID// Global Unique IDentifier defined in .cpp// exported by CAAAfrGeoCreationWbenchextern IID ExportedByCAAAfrGeoCreationWbench IID_CAAIAfrGeoCreationWkbAddin;class ExportedByCAAAfrGeoCreationWbench CAAIAfrGeoCreationWkbAddin : public CATIWorkbenchAddin {// Used in conjunction with CATImplementInterface in the .cpp fileCA TDeclareInterface;public:};#endif1.2 源文件1.2.1 组成1)接口标识符(IID)构造2)接口实现1.2.2 实例如:#include <CAAIAfrGeoCreationWkbAddin.h>// Use uuid_gen -C on UNIX or uuidgen -s on NT to generate the IIDIID IID_CAAIAfrGeoCreationWkbAddin = { /* a4188b88-d4c1-11d3-b7f5-0008c74fe8dd */0xa4188b88,0x11d3,{0xb7, 0xf5, 0x00, 0x08, 0xc7, 0x4f, 0xe8, 0xdd}};// Declares that CAAIAfrGeoCreationWkbAddin is an interface that// OM-derives from CATIWorkbenchAddinCATImplementInterface(CAAIAfrGeoCreationWkbAddin, CATIWorkbenchAddin);1.3 TIE文件1.3.1 内容头文件引用1.3.2 实例如:// Used by mkmk to create TIE_CAAIAfrGeoCreationWkbAddin.h#include <CAAIAfrGeoCreationWkbAddin.h>详见《接口开发》二、插件开发2.1 头文件2.1.1 结构#ifndef <插件类>_H#define <插件类>_H// System framework#include "CATBaseUnknown.h" // Needed to derive from CATBaseUnknown// ApplicationFrame framworkclass CATCmdContainer; // Needed by CreateToolbarsclass <插件类> : public CATBaseUnknown{// Used in conjunction with CATImplementClass in the .cpp fileCATDeclareClass;public:<插件类> (); //构造函数virtual ~<插件类> (); //析构函数// Instantiates the command headers for the commandsvoid CreateCommands(); //定义命令标签// Creates toolbars and arranges the commands insideCA TCmdContainer * CreateToolbars(); //创建菜单和工具条private:};#endif2.1.2 实例#ifndef CAAAfrGeoOperationAdn_H#define CAAAfrGeoOperationAdn_H// System framework#include "CA TBaseUnknown.h" // Needed to derive from CATBaseUnknown// ApplicationFrame framworkclass CATCmdContainer; // Needed by CreateToolbarsclass CAAAfrGeoOperationAdn : public CATBaseUnknown{// Used in conjunction with CATImplementClass in the .cpp fileCA TDeclareClass;public:CAAAfrGeoOperationAdn();virtual ~CAAAfrGeoOperationAdn();// Instantiates the command headers for the commandsvoid CreateCommands();// Creates toolbars and arranges the commands insideCA TCmdContainer * CreateToolbars();private:};#endif2.2 源文件2.2.1 定义命令标签类如:2.2.2 建立“联结(TIE)”对象指定插件插入的交互界面,如:1)界面#Include “TIE_CATIShapeDesignWorkshopAddin.h”;TIE_CATIShapeDesignWorkshopAddin(CAAEMmrCombinedCurveAdn);2)“零件设计(Part Design)”界面#include <TIE_CATIPrtWksAddin.h>TIE_CATIPrtWksAddin(CAAMmrDebugAdn);2.2.3 声明插件类CATImplementClass(CAAMmrDebugAdn, DataExtension, CATBaseUnknown,CAAMmrDebugAddin);2.2.4 更新接口字典文件2.2.4.1 字典文件名<框架>.dico2. 2.4.2 存放目录<>\CNext\Code\Dictionay2. 2.4.3 语句如插入如下结构的语句行:<接口实现类> <TIE接口类> <共享库名>如:CAAMmrCombinedCurveAddin CA TIShapeDesignWorkshopAddin libCAAMmrCombinedCurveAddIn其中:(1)<接口实现类>在CATImplementClass中指定,如CAAMmrCombinedCurveAddin:CATImplementClass ( CAAEMmrCombinedCurveAdn ,DataExtension ,CA TBaseUnknown ,CAAMmrCombinedCurveAddin );(2)<TIE接口类>TIE语句中所定义,如CATIShapeDesignWorkshopAddin:TIE_CATIShapeDesignWorkshopAddin(CAAEMmrCombinedCurveAdn);2.2.5 编制构造函数与析构函数2.2.6 定义命令标签(CreateCommands)和创建菜单/工具条(CreateToolbars)如:// Local Framework#include "CAAAfrGeoOperationAdn.h"// ApplicationFrame Framework#include <CA TCreateWorkshop.h>// Creates the CAAAfrGeoOperationAdnHeader command header class#include "CA TCommandHeader.h"MacDeclareHeader(CAAAfrGeoOperationAdnHeader);// To declare that the class// is a DataExtension of (late type) CAAAfrGeoOperationAddinCATImplementClass(CAAAfrGeoOperationAdn,DataExtension, CA TBaseUnknown,CAAAfrGeoOperationAddin(在接口字典中定义,见下句));// To create the TIE Object (即设置指向本插件的接口)(****)#include <TIE_CAAIAfrGeoCreationWkbAddin.h>TIE_CAAIAfrGeoCreationWkbAddin(CAAAfrGeoOperationAdn);// To declare that CAAAfrGeoOperationAddin implements CAAIAfrGeoCreationWkbAddin, insert// the following line in the interface dictionary: (???????功用)//CAAAfrGeoOperationAddin CAAIAfrGeoCreationWkbAddin libCAAAfrGeoCreationWkbAddin//---------------------------------------------------------------------------CAAAfrGeoOperationAdn::CAAAfrGeoOperationAdn(){}CAAAfrGeoOperationAdn::~CAAAfrGeoOperationAdn(){}void CAAAfrGeoOperationAdn::CreateCommands(){// Instantiation of the header class created by the macro MacDeclareHeader -// commands are always available and are represented by a push buttonnew CAAAfrGeoOperationAdnHeader("CAAAfrUnionHdr" ,"CommandLib","CommandName",(void *)NULL);new CAAAfrGeoOperationAdnHeader("CAAAfrSubstractHdr","CommandLib","CommandName",(void *)NULL);new CAAAfrGeoOperationAdnHeader("CAAAfrFilletHdr" ,"CommandLib","CommandName",(void *)NULL); }CATCmdContainer * CAAAfrGeoOperationAdn::CreateToolbars(){// CAAAfrOperationTlb ToolbarNewAccess(CATCmdContainer,pCAAAfrOperationTlb,CAAAfrOperationTlb);NewAccess(CATCmdStarter,pCAAAfrTUnionStr,CAAAfrTUnionStr);SetAccessCommand(pCAAAfrTUnionStr,"CAAAfrUnionHdr");SetAccessChild(pCAAAfrOperationTlb,pCAAAfrTUnionStr);NewAccess(CATCmdStarter,pCAAAfrTSubstractStr,CAAAfrTSubstractStr);SetAccessNext(pCAAAfrTUnionStr,pCAAAfrTSubstractStr);NewAccess(CATCmdStarter,pCAAAfrTFilletStr,CAAAfrTFilletStr);SetAccessCommand(pCAAAfrTFilletStr,"CAAAfrFilletHdr");SetAccessNext(pCAAAfrTSubstractStr,pCAAAfrTFilletStr);//----------------------// Menu bar (?????)NewAccess(CATCmdContainer,pCAAAfrOperationMbr,CAAAfrOperationMbr);// menu Tools with three new commandNewAccess(CATCmdContainer,pCAAAfrOperationToolsMnu,CA TAfrToolsMnu);SetAccessChild(pCAAAfrOperationMbr,pCAAAfrOperationToolsMnu);NewAccess(CATCmdSeparator,pCAAAfrOperationToolsSep,CAAAfrOperationToolsSep);SetAccessChild(pCAAAfrOperationToolsMnu,pCAAAfrOperationToolsSep);NewAccess(CATCmdStarter,pCAAAfrMUnionStr,CAAAfrMUnionStr);SetAccessCommand(pCAAAfrMUnionStr,"CAAAfrUnionHdr");SetAccessNext(pCAAAfrOperationToolsSep,pCAAAfrMUnionStr);NewAccess(CATCmdStarter,pCAAAfrMSubstractStr,CAAAfrMSubstractStr);SetAccessCommand(pCAAAfrMSubstractStr,"CAAAfrSubstractHdr");SetAccessNext(pCAAAfrMUnionStr,pCAAAfrMSubstractStr);NewAccess(CATCmdStarter,pCAAAfrMFilletStr,pCAAAfrMFilletStr);SetAccessCommand(pCAAAfrMFilletStr,"CAAAfrFilletHdr");SetAccessNext(pCAAAfrMSubstractStr,pCAAAfrMFilletStr);// Set the menu// pCAAAfrOperationTlb: Always the toolbar returned by the method// pCAAAfrOperationMbr: The container which contains all the menu's containersSetAddinMenu(pCAAAfrOperationTlb,pCAAAfrOperationMbr); (?????)// Invisible toolbarAddToolbarView(pCAAAfrOperationTlb,-1,Right);// Pointer of the first toolbar createdreturn pCAAAfrOperationTlb;}。