以梦为马,不负韶华

搜索
查看: 1189|回复: 0
收起左侧

CAD控件:自定义实体的实现

[复制链接]
发表于 2015-5-8 15:30:44 显示全部楼层 |阅读模式

软件名称:: 梦  。。。。。。。想。。。。。。。。CAD。。。。。。。。控。。。。件。。。。。。。
1         自定义实体        3
1.1        说明        3
1.2        类的类型信息        3
1.3        worldDraw        4
1.4        getGripPoints        4
1.5        moveGripPointsAt        5
1.6        getGeomExtents        6
1.7        getOsnapPoints        6
1.8        explode        7
1.9        dwgInFields        8
1.10        dwgOutFields        9
1.11        控件例程说明        9
1 、 自定义实体1.1 说明
控件支持自定义实体功能,可以从McDbEntity继承自己的实体,在自定体实体类中,实现相关虚函数来实现实体的自定义功能。
1.2 类的类型信息
使用MCRX_DECLARE_MEMBERS宏定义类的类型信息函数,宏的第一个参数是类的类名。使用例如:
MCRX_DECLARE_MEMBERS(CLinkLine);
使用 ACRX_DXF_DEFINE_MEMBERS 宏实现类的类型信息函数。宏定义参数使用如下:
ACRX_DXF_DEFINE_MEMBERS(CLinkLine, McDbEntity,
                                                AcDb::kDHL_CURRENT, AcDb::kMReleaseCurrent,
                                                AcDbProxyEntity::kAllAllowedBits, _T("LinkLine"),
                                                _T("MxDrawObj Test Custom Entity") );
CLinkLine                                自定义实体的类名
McDbEnity                                自定义实体的基类
AcDb::kDHL_CURRENT                当前文件版本
AcDb::kMReleaseCurrent                当前控件版本
AcDbProxyEntity::kAllAllowedBits 代理实体处理标志
_T("LinkLine")                          Dfx0组码对应值
_T("MxDrawObj Test Custom Entity") 类说明

在程序启动的时候,调用rxInit函数,自定义实体的类型信息注册到系统中,使用例如:
BOOL CCustomEntityApp::InitInstance()
{
…..
// 注册自定义实体类信息。
        CLinkBlock::rxInit();
        CLinkLine::rxInit();

1.3 worldDraw
重载该虚函数,绘制自定义实体的显示效果
VC接口:
Adesk::Boolean  worldDraw       (AcGiWorldDraw * wd);;
参数:
Wd  显示绘制的上下文对象
参考例程:
Adesk::Boolean  CLinkLine::worldDraw       (AcGiWorldDraw * wd)
{
        assertReadEnabled();
        wd->geometry().line(m_start,m_end);

        std::auto_ptr<AcDbText> spText(GetDimText() );
        spText->worldDraw(wd);

        return Adesk::kTrue;
}
1.4 getGripPoints
重载该虚函数,返回自定义的编辑夹点
VC接口:
virtual Acad::ErrorStatus   getGripPoints(
                AcGePoint3dArray&  gripPoints,
                AcGeIntArray&  osnapModes,
                AcGeIntArray&  geomIds) const;
参数:
gripPoints          返回夹点
osnapModes    暂没有使用
geomIds             暂没有使用
参考例程:
Acad::ErrorStatus   CLinkLine::getGripPoints(
        AcGePoint3dArray&  gripPoints,
        AcGeIntArray&  osnapModes,
        AcGeIntArray&  geomIds) const
{
        assertReadEnabled();

        gripPoints.append(m_start);                // 返回开始点夹点
        gripPoints.append(m_end);                        // 返回结束点夹点
        gripPoints.append(m_start + (m_end - m_start) / 2.0);        // 返回中点夹点。

        return Acad::eOk;
}

1.5 moveGripPointsAt
重载该虚函数,处理夹点编辑结果。
VC接口:
virtual Acad::ErrorStatus moveGripPointsAt(
const AcGeIntArray& indices,
                const AcGeVector3d& offset);
参数:
indices              indices [0]参数是传入被编辑的夹点索引, 其它数组元素暂没有使用。
offset         夹点编辑的偏移量
参考例程:

Acad::ErrorStatus CLinkLine::moveGripPointsAt(const AcGeIntArray& indices,
                                                                                                          const AcGeVector3d& offset)
{
        assertWriteEnabled();
        int iIndex = indices[0];
        switch(iIndex)
        {
        case 0:
                m_start = m_start + offset;                // 开始点被编辑
                break;
        case 1:
                m_end = m_end + offset;                        // 结束点被编辑
                break;
        case 2:
                m_start = m_start + offset;                // 中点被编辑
                m_end = m_end + offset;                        // 中点被编辑
                break;
        }
        return Mcad::eOk;
}
1.6 getGeomExtents
重载该虚函数,返回自定义实体的外包矩形框
VC接口:
virtual Acad::ErrorStatus   getGeomExtents(
AcDbExtents& extents) const;
参数:
extents             返回自定义实体外包矩形框。
参考例程:
Acad::ErrorStatus   CLinkLine::getGeomExtents(AcDbExtents& extents) const
{
        assertReadEnabled();
        extents.set(m_start,m_end);
        return Mcad::eOk;
}
1.7 getOsnapPoints
重载该虚函数,返回自定义实体的捕捉点
VC接口:
virtual Acad::ErrorStatus   getOsnapPoints(
                AcDb::OsnapMode     osnapMode,
                int                 gsSelectionMark,
                const AcGePoint3d&  pickPoint,
                const AcGePoint3d&  lastPoint,
                const AcGeMatrix3d& viewXform,
                AcGePoint3dArray&   snapPoints,
                AcDbIntArray&       geomIds) const;
参数:
osnapMode                       捕捉点类型,通过该变量可以确定需要返回什么类型的捕捉点
gsSelectionMark          暂没有使用
pickPoint            当前输入点
lastPoint            上一次的输入点
viewXform            暂没有使用
snapPoints           返回捕捉点
geomIds              暂没有使用
参考例程:

Acad::ErrorStatus   CLinkLine::getOsnapPoints(
        AcDb::OsnapMode     osnapMode,
        int                 gsSelectionMark,
        const AcGePoint3d&  pickPoint,
        const AcGePoint3d&  lastPoint,
        const AcGeMatrix3d& viewXform,
        AcGePoint3dArray&   snapPoints,
        AcDbIntArray&       geomIds) const
{
        assertReadEnabled();

        if(osnapMode == McDb::kOsModeEnd)
        {
                // 返端点。
                snapPoints.append(m_start);
                snapPoints.append(m_end);
        }
        else if(osnapMode == McDb::kOsModeMid)
        {
                // 返回的是中点。
                snapPoints.append(m_start + (m_end - m_start) / 2.0);
        }
        return Mcad::eOk;
}

1.8 explode
重载该虚函数,返回自定义实体打碎后的实体,在控件中,自定义实体保存在到dwg图中时,使用是块引用来保存,控件使用该函数得到自定义实体在块引用中的实体数据。

VC接口:
virtual Acad::ErrorStatus   explode(
AcDbVoidPtrArray& entitySet) const;
参数:
entitySet                     返回打碎后的基本实体。实体指针内存控件释放。

参考例程:

Acad::ErrorStatus   CLinkLine::explode(AcDbVoidPtrArray& entitySet) const
{
        assertReadEnabled();
        AcDbLine* pLine = new AcDbLine(m_start,m_end);
        entitySet.append(pLine);
        entitySet.append(GetDimText() );

        return Acad::eOk;
}

1.9 dwgInFields
重载该虚函数,响应控件系统,读取自定义实体数据,在从文件读取实体,复制实体等地方都会调用该函数。

VC接口:
virtual Acad::ErrorStatus dwgInFields (AcDbDwgFiler* pFiler);
参数:
pFiler                     数据归档对象,在这个函数,使用该对象读取数据。

参考例程:

Acad::ErrorStatus CLinkLine::dwgInFields (AcDbDwgFiler* pFiler)
{
        assertWriteEnabled();
        if(pFiler->filerType() != McDb::kCustomEntityFileFiler)
        {
                Mcad::ErrorStatus es;
                if ((es = McDbEntity::dwgInFields(pFiler)) != Mcad::eOk)
                {
                        return es;
                }
        }

        int lVar = 1;
        pFiler->readInt(&lVar);

        pFiler->readPoint3d(&m_start);
        pFiler->readPoint3d(&m_end);

        return Mcad::eOk;
}
1.10 dwgOutFields
重载该虚函数,响应控件系统,写入自定义实体数据,在把实体写入文件时,复制实体等地方都会调用该函数。

VC接口:
virtual Acad::ErrorStatus dwgOutFields(AcDbDwgFiler* pFiler) const;
参数:
pFiler                     数据归档对象,在这个函数,使用该对象写入数据。

参考例程:
Acad::ErrorStatus CLinkLine::dwgOutFields(AcDbDwgFiler* pFiler) const
{
        assertReadEnabled();

        if(pFiler->filerType() != McDb::kCustomEntityFileFiler)
        {
                Mcad::ErrorStatus es;
                if ((es = McDbEntity::dwgOutFields(pFiler)) != Mcad::eOk)
                {
                        return es;
                }
        }

        pFiler->writeInt(LINKLINE_VERSION);
        pFiler->writePoint3d(m_start);
        pFiler->writePoint3d(m_end);

        return Mcad::eOk;
}
1.11 控件例程说明
在控件安装目录下的samples\CustomEntity\ CustomEntity.sln例程,演示了自定义实体现。在例程实现连接块CLinkBlock自定义实体,CLinkLine自定义实体,
CLinkBlock类显示通过块引用显示,绘图捕捉点通过块记录中的块属性定义文本来确定,当该实体被编辑后,会自动移动与该实体连接的连接线,实现个连动效果。
CLinkLine 类实现一个线段实体功能,并带有长度标注功能。
不想打字就选择快捷回复吧
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|以梦为马,不负韶华

GMT+8, 2025-4-10 16:38

Powered by 以梦为马,不负韶华

© 2024-2099 Meng.Horse

快速回复 返回顶部 返回列表