明经CAD社区

 找回密码
 注册

QQ登录

只需一步,快速开始

搜索
查看: 1394|回复: 0

为何例程ents可以这样声名函数?

[复制链接]
发表于 2003-10-31 21:43:00 | 显示全部楼层 |阅读模式
#include <string.h>
#include <aced.h>
#include <dbents.h>
#include <dbsymtb.h>
#include <dbgroup.h>
#include <dbapserv.h>
#include "dbfcf.h"

AcDbObjectId createLine();
AcDbObjectId createCircle();
void createNewLayer();
void createGroup();                             //问一:为何例程可以这样声名函数?
//而下面的函数体这样实现?带两个参数都不报错?
//void createGroup(AcDbObjectIdArray& objIds, char* pGroupName)
AcDbObjectId createFcf();
Acad::ErrorStatus changeColor(AcDbObjectId, Adesk::UInt16);

AcDbObjectId createFcf()
{
//        double point[3]={9.0, 3.0, 0.0};
//        AcDbFcf *pLine;
        AcGePoint3d center(90, 3.0, 0.0);
AcDbFcf *pLine = new AcDbFcf();
pLine->setText("{\\Fgdt;a}%%v0.1%%v%%v%%v%%v");
pLine->setLocation(center);
        AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
        AcDb::kForWrite);
    pBlockTable->close();

    AcDbObjectId lineId;
    pBlockTableRecord->appendAcDbEntity(lineId, pLine);

    pBlockTableRecord->close();
    pLine->close();

return lineId;       
}
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
AcDbObjectId
createLine()
{
    AcGePoint3d startPt(4.0, 2.0, 0.0);
    AcGePoint3d endPt(10.0, 7.0, 0.0);
    AcDbLine *pLine = new AcDbLine(startPt, endPt);

    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
        AcDb::kForWrite);
    pBlockTable->close();

    AcDbObjectId lineId;
    pBlockTableRecord->appendAcDbEntity(lineId, pLine);

    pBlockTableRecord->close();
    pLine->close();

    return lineId;
}

AcDbObjectId
createCircle()
{
    AcGePoint3d center(9.0, 3.0, 0.0);
    AcGeVector3d normal(0.0, 0.0, 1.0);
    AcDbCircle *pCirc = new AcDbCircle(center, normal, 2.0);

    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockTableRecord,
        AcDb::kForWrite);
    pBlockTable->close();

    AcDbObjectId circleId;
    pBlockTableRecord->appendAcDbEntity(circleId, pCirc);

    pBlockTableRecord->close();
    pCirc->close();

    return circleId;
}

void
createNewLayer()
{
    AcDbLayerTable *pLayerTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pLayerTable, AcDb::kForWrite);

    AcDbLayerTableRecord *pLayerTableRecord =
        new AcDbLayerTableRecord;
    pLayerTableRecord->setName("ASDK_MYLAYER");

        // Defaults are used for other properties of
        // the layer if they are not otherwise specified.

        pLayerTable->add(pLayerTableRecord);
    pLayerTable->close();
    pLayerTableRecord->close();
}
Acad::ErrorStatus
changeColor(AcDbObjectId entId, Adesk::UInt16 newColor)
{
    AcDbEntity *pEntity;
    acdbOpenObject(pEntity, entId,
        AcDb::kForWrite);

    pEntity->setColorIndex(newColor);
    pEntity->close();

    return Acad::eOk;
}
void
createGroup(AcDbObjectIdArray& objIds, char* pGroupName)
{
    AcDbGroup *pGroup = new AcDbGroup(pGroupName);

    for (int i = 0; i < objIds.length(); i++) {
        pGroup->append(objIds);
    }

    // Put the group in the group dictionary which resides
    // in the named object dictionary.
    //
    AcDbDictionary *pGroupDict;
    acdbHostApplicationServices()->workingDatabase()
        ->getGroupDictionary(pGroupDict, AcDb::kForWrite);

    AcDbObjectId pGroupId;
    pGroupDict->setAt(pGroupName, pGroup, pGroupId);
    pGroupDict->close();
    pGroup->close();
}


// END CODE APPEARING IN SDK DOCUMENT.

void
runIt()
{
    createNewLayer();

    AcDbObjectIdArray idArr;

    // create a line and circle and add them to the objectId
    // array
    //
    idArr.append(createLine());
    idArr.append(createCircle());
        idArr.append(createFcf());
    // change circle color to red
    //
    changeColor(idArr.last(), 1);

  
    createGroup(idArr, "ASDK_TEST_GROUP");
}

void initApp()
{
    acedRegCmds->addCommand("ASDK_MAKE_ENTS",
                            "ASDK_MKENTS",
                            "MKENTS",
                            ACRX_CMD_MODAL,
                            runIt);
}

void unloadApp()
{
        acedRegCmds->removeGroup("ASDK_MAKE_ENTS");
}

extern "C" AcRx::AppRetCode
acrxEntryPoint(AcRx::AppMsgCode msg, void* appId)
{
        switch (msg) {
        case AcRx::kInitAppMsg:
                       acrxDynamicLinker->unlockApplication(appId);
                                acrxDynamicLinker->registerAppMDIAware(appId);

                initApp();
                break;
        case AcRx::kUnloadAppMsg:
                unloadApp();
        }
        return AcRx::kRetOK;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

小黑屋|手机版|CAD论坛|CAD教程|CAD下载|联系我们|关于明经|明经通道 ( 粤ICP备05003914号 )  
©2000-2023 明经通道 版权所有 本站代码,在未取得本站及作者授权的情况下,不得用于商业用途

GMT+8, 2024-11-25 20:51 , Processed in 0.155354 second(s), 23 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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