插件的开发方法
2004-8-24
一、创建插件接口
1.1 头文件
如:
#ifndef CAAIAfrGeoCreationWkbAddin_h
#define CAAIAfrGeoCreationWkbAddin_h
// ApplicationFrame Framework
#include <CATIWorkbenchAddin.h>// Needed to derive from CATIWorkbenchAddin
// Local Framework
#include "CAAAfrGeoCreationWbench.h"  // Needed to export the IID
// Global Unique IDentifier defined in .cpp
// exported by CAAAfrGeoCreationWbench
extern IID ExportedByCAAAfrGeoCreationWbench IID_CAAIAfrGeoCreationWkbAddin;
class ExportedByCAAAfrGeoCreationWbench CAAIAfrGeoCreationWkbAddin : public CATIWorkbenchAddin
{
  // Used in conjunction with CATImplementInterface in the .cpp file
  CATDeclareInterface;
  public:
};
#endif
1.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 IID
IID IID_CAAIAfrGeoCreationWkbAddin = { /* a4188b88-d4c1-11d3-b7f5-0008c74fe8dd */
    0xa4188b88,
    0xd4c1,
    0x11d3,
    {0xb7, 0xf5, 0x00, 0x08, 0xc7, 0x4f, 0xe8, 0xdd}
  };
// Declares that CAAIAfrGeoCreationWkbAddin is an interface that
// OM-derives from CATIWorkbenchAddin
CATImplementInterface(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 framwork
class CATCmdContainer;      // Needed by CreateToolbars
class <插件类> : public CATBaseUnknown
{
  // Used in conjunction with CATImplementClass in the .cpp file
  CATDeclareClass;
  public:
    <插件类> (); //构造函数
    virtual ~<插件类> (); //析构函数
    // Instantiates the command headers for the commands
    void CreateCommands(); //定义命令标签
    // Creates toolbars and arranges the commands inside
    CATCmdContainer * CreateToolbars(); //创建菜单和工具条
 
  private:
};
#endif
2.1.2 实例
#ifndef CAAAfrGeoOperationAdn_H
#define CAAAfrGeoOperationAdn_H
// System framework
#include "CATBaseUnknown.h"  // Needed to derive from CATBaseUnknown
// ApplicationFrame framwork
class CATCmdContainer;      // Needed by CreateToolbars
class CAAAfrGeoOperationAdn : public CATBaseUnknown
{
  // Used in conjunction with CATImplementClass in the .cpp file
  CATDeclareClass;
  public:
    CAAAfrGeoOperationAdn();
    virtual ~CAAAfrGeoOperationAdn();
    // Instantiates the command headers for the commands
system的头文件    void CreateCommands();
    // Creates toolbars and arranges the commands inside
    CATCmdContainer * CreateToolbars();
 
  private:
};
#endif
2.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 字典文件名
<框架>.dico
2. 2.4.2 存放目录
        <>\CNext\Code\Dictionay
2. 2.4.3 语句
如插入如下结构的语句行:
        <接口实现类> <TIE接口类> <共享库名>
如:
    CAAMmrCombinedCurveAddin      CATIShapeDesignWorkshopAddin    libCAAMmrCombinedCurveAddIn
其中:
(1)<接口实现类>
在CATImplementClass中指定,如CAAMmrCombinedCurveAddin
CATImplementClass ( CAAEMmrCombinedCurveAdn  ,
                    DataExtension          ,
                    CATBaseUnknown          ,
                    CAAMmrCombinedCurveAddin );
(2)<TIE接口类>
    TIE语句中所定义,如CATIShapeDesignWorkshopAddin:
TIE_CATIShapeDesignWorkshopAddin(CAAEMmrCombinedCurveAdn);
2.2.5 编制构造函数与析构函数
2.2.6 定义命令标签(CreateCommands)和创建菜单/工具条(CreateToolbars)
详见《菜单与工具条的开发方法》
如:
// Local Framework
#include "CAAAfrGeoOperationAdn.h"
// ApplicationFrame Framework
#include <CATCreateWorkshop.h>   
// Creates the CAAAfrGeoOperationAdnHeader command header class
#include "CATCommandHeader.h"
MacDeclareHeader(CAAAfrGeoOperationAdnHeader); 
// To declare that the class
// is a DataExtension of (late type) CAAAfrGeoOperationAddin
CATImplementClass(CAAAfrGeoOperationAdn,
DataExtension, CATBaseUnknown,
CAAAfrGeoOperationAddin(在接口字典中定义,见下句));
// To create the TIE Object (即设置指向本插件的接口)(****)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。