前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >getRegularDictionaryId getSubDictionaryId collectDictionaryEntryNames和lookUpDictEntryName。

getRegularDictionaryId getSubDictionaryId collectDictionaryEntryNames和lookUpDictEntryName。

作者头像
用户3519280
发布2023-11-09 10:31:28
930
发布2023-11-09 10:31:28
举报
文章被收录于专栏:c++ 学习分享c++ 学习分享
代码语言:javascript
复制
/****************************************************************************
**
**	ArxDbgUtils::getRegularDictionaryId
**		get the id of a dictionary considered to be "regular" (one which is
**	underneath the RootNamedObjectDictionary.
**
**	**jma
**
*************************************/

AcDbObjectId
ArxDbgUtils::getRegularDictionaryId(LPCTSTR dictName, bool createIfNotFound, AcDbDatabase* db)
{
	ASSERT(db != NULL);

    AcDbObjectId dictId  = AcDbObjectId::kNull;

        // get the root dict for this database
    AcDbDictionary* rootDict;
	Acad::ErrorStatus es = db->getNamedObjectsDictionary(rootDict, AcDb::kForRead);
	if (es != Acad::eOk) {
		ArxDbgUtils::rxErrorMsg(es);
		return AcDbObjectId::kNull;
	}

        // try to first open for read and see if it is already there
    AcDbDictionary* dict;
    dict = openDictionaryForRead(dictName, rootDict);
    if (dict) {
        dictId = dict->objectId();
        dict->close();
    }
    else {    // the dictionary has not yet been created
        if (createIfNotFound) {
            es = rootDict->upgradeOpen();
            if ((es == Acad::eOk) || (es == Acad::eWasOpenForWrite)) {
                dict = openDictionaryForWrite(dictName, true, rootDict);
                if (dict) {
                    dictId = dict->objectId();
                    dict->close();
                }
            }
        }
    }
    rootDict->close();    // don't need it anymore!
    return dictId;
}

/****************************************************************************
**
**  ArxDbgUtils::getSubDictionaryId
**
**  **jma
**
*************************************/

AcDbObjectId
ArxDbgUtils::getSubDictionaryId(LPCTSTR dictName, bool createIfNotFound,
                                AcDbDictionary* parentDict)
{
    ASSERT(parentDict != NULL);

    AcDbObjectId dictId;

        // try to first see if it is already there
    Acad::ErrorStatus es = parentDict->getAt(dictName, dictId);
    if (es == Acad::eOk) {
        return dictId;
    }
    else if (es == Acad::eKeyNotFound) {
        if (createIfNotFound) {
                // upgrade parentDict to write if not already
            if (parentDict->isWriteEnabled() == Adesk::kFalse) {
                es = parentDict->upgradeOpen();
                if ((es != Acad::eOk) && (es != Acad::eWasOpenForWrite)) {
                    ArxDbgUtils::rxErrorAlert(es);
                    ASSERT(0);
                    return AcDbObjectId::kNull;
                }
            }
                // create this new dict
            AcDbDictionary* newDict = new AcDbDictionary;
            es = parentDict->setAt(dictName, newDict, dictId);
            if (es == Acad::eOk) {
                newDict->close();
                return dictId;
            }
            else {
                delete newDict;
                return AcDbObjectId::kNull;
            }
        }
        else
            return AcDbObjectId::kNull;
    }
    else {
        ArxDbgUtils::rxErrorAlert(es);
        ASSERT(0);
        return AcDbObjectId::kNull;
    }
}

这两个函数是ArxDbgUtils类中的成员函数,用于获取字典对象的ID。下面是对这两个函数的注释和分析:

// 获取一个字典对象的ID,如果字典不存在,则创建一个新的字典对象并返回其ID AcDbObjectId getRegularDictionaryId(LPCTSTR dictName, bool createIfNotFound = false, AcDbDatabase* db = nullptr);

// 获取一个字典对象的子对象的ID,如果字典或子对象不存在,则创建一个新的字典对象和子对象并返回其ID AcDbObjectId getSubDictionaryId(LPCTSTR dictName, bool createIfNotFound = false, AcDbDictionary* parentDict = nullptr); 这两个函数都接受一个字典对象的名称,以及一个可选的布尔值参数 createIfNotFound,用于指定是否在字典不存在时创建一个新的字典对象。如果字典对象已经存在,则返回其ID,否则创建一个新的字典对象并返回其ID。

getRegularDictionaryId 函数用于获取一个“常规”字典对象的ID。这个字典对象是指在 RootNamedObjectDictionary 之下的字典对象。该函数首先通过调用 getNamedObjectsDictionary 方法获取根字典对象的ID,然后尝试打开该字典对象以进行读取。如果打开成功,则尝试在该字典对象中查找指定名称的字典对象。如果找到,则返回字典对象的ID;否则,如果 createIfNotFound 参数为 true,则创建一个新的字典对象并返回其ID;否则,返回 AcDbObjectId::kNull。

getSubDictionaryId 函数用于获取一个字典对象的子对象的ID。该函数首先通过调用 getNamedObjectsDictionary 方法获取根字典对象的ID,然后尝试打开该字典对象以进行读取。如果打开成功,则尝试在该字典对象中查找指定名称的子字典对象。如果找到,则返回子字典对象的ID;否则,如果 createIfNotFound 参数为 true,则创建一个新的字典对象和子对象,并返回子对象的ID;否则,返回 `AcDbObjectId::kNull

代码语言:javascript
复制
Acad::ErrorStatus
ArxDbgUtils::collectDictionaryEntryNames(const AcDbObjectId& dictId, SdStrObjIdList& list, AcRxClass* classType)
{
    Acad::ErrorStatus ret = Acad::eInvalidInput;

    AcDbDictionary* dict;
	ret = acdbOpenObject(dict, dictId, AcDb::kForRead);
    if (ret == Acad::eOk) {
        Acad::ErrorStatus es;
        AcDbObject* obj;
        AcDbDictionaryIterator* dictIter = dict->newIterator();
        ASSERT(dictIter != NULL);
        if (dictIter != NULL) {
            for (; !dictIter->done(); dictIter->next()) {
                es = dictIter->getObject(obj, AcDb::kForRead);
                if (es == Acad::eOk) {
                    if (classType == NULL)
						list.AddAlpha(dictIter->name(), dictIter->objectId());
					else if (obj->isKindOf(classType))
                        list.AddAlpha(dictIter->name(), dictIter->objectId());
                    obj->close();
                }
            }
            delete dictIter;
            ret = Acad::eOk;
        }
        else
            ret = Acad::eInvalidInput;

        dict->close();
    }
    return ret;
}

/****************************************************************************
**
**	ArxDbgUtils::lookUpDictEntryName
**		given an entry Id in a dictionary, look up its parent dictionary
**	and then find out what the key value is for this entry in the dictionary.
**
**	**jma
**
*************************************/

bool
ArxDbgUtils::lookUpDictEntryName(const AcDbObjectId& objId, CString& entryName)
{
    bool retCode = FALSE;
    AcDbObject* obj;

    Acad::ErrorStatus es = acdbOpenAcDbObject(obj, objId, AcDb::kForRead);
    if (es == Acad::eOk) {
        AcDbDictionary* dict;
        es = acdbOpenObject(dict, obj->ownerId(), AcDb::kForRead);
        if (es == Acad::eOk) {
            TCHAR* name = NULL;
            if (dict->nameAt(objId, name) == Acad::eOk) {
                entryName = name;
                retCode = true;
                acutDelString(name);
            }
            dict->close();
        }
        obj->close();        
    }
    return retCode;
}

这段代码是ArxDbgUtils类中的两个成员函数:collectDictionaryEntryNames和lookUpDictEntryName。

collectDictionaryEntryNames函数的作用是收集指定字典对象中所有的字典条目名称,并将它们存储在一个AcRxClass类型的列表中。函数的输入参数包括字典对象的ID,一个SdrObjIdList对象用于存储收集到的字典条目名称,以及一个AcRxClass类型的指针,用于指定要收集的字典条目类型。函数返回一个Acad::ErrorStatus枚举值,表示函数执行的结果。

lookUpDictEntryName函数的作用是查找指定字典对象中的某个字典条目的名称。函数的输入参数包括字典对象的ID和一个CString对象,用于存储查找到的字典条目的名称。函数返回一个bool类型的值,表示查找是否成功。

在这两个函数中,Acad::eInvalidInput表示输入参数无效,Acad::eOk表示函数执行成功。函数中使用了AcDbObjectId、AcDbDictionary、AcDbObject和CString等类型。其中,AcDbObjectId用于表示一个对象的ID,AcDbDictionary用于表示一个字典对象,AcDbObject用于表示一个实体对象,CString用于表示一个字符串对象。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2023-11-08,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
对象存储
对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档