huangyhg 发表于 2003-10-31 21:43:00

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

#include
#include
#include
#include
#include
#include
#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={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 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;
}
页: [1]
查看完整版本: 为何例程ents可以这样声名函数?