void
removeEntryFromDict(const char* strDictKey, AcDbDictionary* pParent, 
            const char* strEmpKey) 
{
    AcDbObjectId idO;
    //see if our dictionary is there
    ARXOK(pParent->getAt(strDictKey,idO));
    //get it for write 
    AcDbObject* pO;
    ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite));
    //check if someone has else has created an entry with our name
    //that is not a dictionary. This should never happen as long as
    //I use the registered developer ID.
    AcDbDictionary* pEmployeeDict;
    if ((pEmployeeDict=AcDbDictionary::cast(pO))==NULL)
        throw Acad::eNotThatKindOfClass;
    //check if a record with this key isthere
    ARXOK(pEmployeeDict->getAt(strEmpKey,idO));
    //get it for write 
    ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite));
    //and erase it
    ARXOK(pO->erase());
    //erase dictionary if it has no more entries
    if (pParent->numEntries()==0)
        ARXOK(pParent->erase());

}
Esempio n. 2
0
static void AddLineType(CString lineTypeName)
{
	// 加载线型(两种方法)
	Acad::ErrorStatus es;
	//es = acdbHostApplicationServices()->workingDatabase()->loadLineTypeFile(_T("CENTER"), _T("acadiso.lin"));
	es = acdbLoadLineTypeFile(lineTypeName, _T("acadiso.lin"),acdbHostApplicationServices()->workingDatabase());
	// 创建新的AcDbMlineStyle对象
	AcDbMlineStyle *pMlStyle = new AcDbMlineStyle;
	pMlStyle->initMlineStyle();
	pMlStyle->setName(_T("NewStyle"));
	int index; // 多线样式中的元素索引
	//AcCmColor color; // 颜色
	AcDbObjectId linetypeId; // 线型的ID
	// 添加第一个元素(红色的中心线)
	//color.setColorIndex(1); // 红色
	GetLinetypeId(lineTypeName, linetypeId);
	//pMlStyle->addElement(index, 0, color, linetypeId);
	//// 添加第二个元素(蓝色的虚线)
	//color.setColorIndex(5); // 蓝色
	//GetLinetypeId("HIDDEN", linetypeId);
	//pMlStyle->addElement(index, 0.5, color, linetypeId);
	//// 添加第三个元素(蓝色的虚线)
	//pMlStyle->addElement(index, -0.5, color, linetypeId);
	//// 将多线样式添加到多线样式字典中
	AcDbDictionary *pDict;
	acdbHostApplicationServices()->workingDatabase()->getMLStyleDictionary(pDict, AcDb::kForWrite);
	AcDbObjectId mlStyleId;
	es = pDict->setAt(_T("NewStyle"), pMlStyle, mlStyleId);
	pDict->close();
	pMlStyle->close();
}
Esempio n. 3
0
// The listxrecord() functions gets the xrecord associated with the 
// key "ASDK_XREC1" and lists out its contents by passing the resbuf 
// list to the function printList().
// 
void
listXrecord()
{
    AcDbObject *pObj;
    AcDbXrecord *pXrec;
    AcDbObjectId dictObjId;
    AcDbDictionary *pDict;

    pObj = selectObject(AcDb::kForRead);
    if (pObj == NULL) {
        return;
    }
    // Get the object ID of the object's extension dictionary.
    //
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and get the xrecord
    // associated with the key ASDK_XREC1.
    // 
    acdbOpenObject(pDict, dictObjId, AcDb::kForRead);
    pDict->getAt("ASDK_XREC1", (AcDbObject*&)pXrec,
        AcDb::kForRead);
    pDict->close();

    // Get the xrecord's data list and then close the xrecord.
    //
    struct resbuf *pRbList;
    pXrec->rbChain(&pRbList);
    pXrec->close();

    printList(pRbList);
    acutRelRb(pRbList);
}
Esempio n. 4
0
static bool FindDictKey( const AcDbObjectId& dictId, const CString& key )
{
    AcDbDictionary* pDict = GetDictObject( dictId );
    if( pDict == 0 ) return false;

    bool ret = pDict->has( key );
    pDict->close();
    return ret;
}
Esempio n. 5
0
    //-------------------------------------------------------------------------------------------
    //
    //  功能: 将从AcDbObject派生数据库对象保存到实体的扩展词典中
    //
    //  作者:Qin H.X.
    //
    // 日期:200709
    //
    //  历史:
    //          2007.10.08 修改 by Qin H.X.
    //
    //----------------------------------------------------------------------------------------------
    // - CSCH081.AddAttribute command (do not rename)
    static void CSCH081AddAttribute(void)
    {
        AcDbObjectId dictObjId,eId, attId;
        AcDbDictionary* pDict;
        //选择管道(多义线)
        ads_name en;
        ads_point pt;
        if (  acedEntSel(_T("\n选择管道(多义线): "), en, pt)!= RTNORM)
        {
            acutPrintf(_T("\n选择失败,退出: "));
            return ;
        }
        // 打开对象
        acdbGetObjectId(eId, en);
        AcDbEntity * pEnt;
        acdbOpenObject(pEnt, eId,  AcDb::kForWrite);
        if(!pEnt->isKindOf (AcDbPolyline::desc ()))
        {
            acutPrintf(_T("\n选择的不是管道(多义线),退出: " ));
            return ;
        }

        // 判断实体的扩展词典是否创建,如果没有则创建
        dictObjId = pEnt->extensionDictionary();
        if(	dictObjId ==  AcDbObjectId::kNull )
        {
            pEnt->createExtensionDictionary();
        }

        // 获取实体的扩展词典
        dictObjId = pEnt->extensionDictionary();
        pEnt->close();

        // 	判断词典中的属性是否创建
        CPipeAttribute* pAttribute;
        acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
        pDict->getAt (_T("属性"),attId);
        if(attId!= AcDbObjectId::kNull )//如果已经创建则输出数据
        {
            acdbOpenObject(pAttribute, attId, AcDb::kForRead);
            acutPrintf(_T("\n管径:%4.2f " ),pAttribute->m_dRadius);
            acutPrintf(_T("\n壁厚:%4.2f " ),pAttribute->m_dThickness );
            acutPrintf(_T("\n埋深:%4.2f " ),pAttribute->m_dDeep );
            acutPrintf(_T("\n材质:%s " ),pAttribute->m_cMaterial  );
        }
        else
        {
            //没有则创建属性
            pAttribute = new CPipeAttribute();
            pDict->setAt(_T("属性"), pAttribute, attId);
        }
        //关闭对象
        pDict->close();
        pAttribute->close();

    }
Esempio n. 6
0
static void RemoveDictKey( const AcDbObjectId& dictId, const CString& key )
{
    AcDbDictionary* pDict = GetDictObject( dictId );
    if( pDict == 0 ) return;

    AcDbObjectId objId;
    pDict->remove( key, objId );
    ArxEntityHelper::EraseObject2( objId, true ); // 删除对象
    pDict->close();
}
Esempio n. 7
0
bool ArxDictTool::IsDictExist( const CString& dictName )
{
    AcDbDictionary* pNamedobj;
    acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary( pNamedobj, AcDb::kForRead );

    bool ret = pNamedobj->has( dictName );
    pNamedobj->close();

    return ret;
}
Esempio n. 8
0
// The createXrecord() functions creates an xrecord object, 
// adds data to it, and then adds the xrecord to the extension 
// dictionary of a user selected object.
// 
// THE FOLLOWING CODE APPEARS IN THE SDK DOCUMENT.
//
void
createXrecord()
{
    AcDbXrecord *pXrec = new AcDbXrecord;
    AcDbObject *pObj;
    AcDbObjectId dictObjId, xrecObjId;
    AcDbDictionary* pDict;

    pObj = selectObject(AcDb::kForWrite);
    if (pObj == NULL) {
        return;
    }

    // Try to create an extension dictionary for this
    // object.  If the extension dictionary already exists,
    // this will be a no-op.
    // 
    pObj->createExtensionDictionary();

    // Get the object ID of the extension dictionary for the
    // selected object.
    // 
    dictObjId = pObj->extensionDictionary();
    pObj->close();

    // Open the extension dictionary and add the new
    // xrecord to it.
    //
    acdbOpenObject(pDict, dictObjId, AcDb::kForWrite);
    pDict->setAt("ASDK_XREC1", pXrec, xrecObjId);
    pDict->close();

    // Create a resbuf list to add to the xrecord.
    //
    struct resbuf* head;
    ads_point testpt = {1.0, 2.0, 0.0};
    head = acutBuildList(AcDb::kDxfText,
        "This is a test Xrecord list",
        AcDb::kDxfXCoord, testpt,
        AcDb::kDxfReal, 3.14159,
        AcDb::kDxfAngle, 3.14159,
        AcDb::kDxfColor, 1,
        AcDb::kDxfInt16, 180,
        0);

    // Add the data list to the xrecord.  Notice that this
    // member function takes a reference to a resbuf NOT a
    // pointer to a resbuf, so you must dereference the
    // pointer before sending it.
    // 
    pXrec->setFromRbChain(*head);
    pXrec->close();
    acutRelRb(head);
}
void
ArxDbgAppEditorReactor::collectAllDictRecords(AcDbDatabase* db, AcDbObjectIdArray& objIds)
{
    AcDbDictionary* dict;
	Acad::ErrorStatus es;
	es = db->getNamedObjectsDictionary(dict, AcDb::kForRead);
    if (es == Acad::eOk) {
        searchOneDictionary(dict, objIds);
        dict->close();
    }
}
Esempio n. 10
0
bool ArxDictTool2::findEntry( const CString& key, AcDbObjectId& objId )
{
    AcDbDictionary* pDict = GetDictObject( m_dictId );
    if( pDict == 0 ) return false;

    bool ret = ( Acad::eOk == pDict->getAt( key, objId ) );
    //acutPrintf(_T("\nArxDitToll->Ret:%s"),ret?_T("Y"):_T("N"));
    pDict->close();

    return ret;
}
Esempio n. 11
0
void ArxDictTool2::getAllKeys( AcStringArray& keys )
{
    AcDbDictionary* pDict = GetDictObject( m_dictId );
    if( pDict == 0 ) return;

    AcDbDictionaryIterator* pIter = pDict->newIterator();
    for ( ; !pIter->done(); pIter->next() )
    {
        keys.append( pIter->name() );
    }
    delete pIter;
    pDict->close();
}
Esempio n. 12
0
void ArxDictTool2::getAllEntries( AcDbObjectIdArray& objIds )
{
    AcDbDictionary* pDict = GetDictObject( m_dictId );
    if( pDict == 0 ) return;

    AcDbDictionaryIterator* pIter = pDict->newIterator();
    for ( ; !pIter->done(); pIter->next() )
    {
        objIds.append( pIter->objectId() );
    }
    delete pIter;
    pDict->close();
}
Esempio n. 13
0
AcDbObjectId ArxDictTool::GetDict( const CString& dictName )
{
    AcDbDictionary* pNameObjDict;
    if( Acad::eOk != acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary( pNameObjDict, AcDb::kForRead ) )
    {
        return AcDbObjectId::kNull;
    }

    AcDbObjectId dictId;
    Acad::ErrorStatus es = pNameObjDict->getAt( dictName, dictId );
    pNameObjDict->close();

    return dictId;
}
Esempio n. 14
0
bool ArxDictTool2::removeEntry( const CString& key )
{
    AcDbDictionary* pDict = GetDictObject( m_dictId );
    if( pDict == 0 ) return false;

    AcDbObjectId objId;
    bool ret = ( Acad::eOk == pDict->remove( key, objId ) );
    pDict->close();

    if( ret )
    {
        ArxEntityHelper::EraseObject2( objId, true );
    }
    return ret;
}
Esempio n. 15
0
void 
addDictAndEntry(const char* strDictKey, AcDbDictionary* pParent, 
            const char* strEmpKey, AcDbObject* pEmployee) 
{
    AcDbObjectId idO;
    AcDbDictionary* pEmployeeDict;
    //unerase the dictionary if it was erased
    if (pParent->isErased())
        ARXOK(pParent->erase(Adesk::kFalse));
    //see if our dictionary is already there
    if (pParent->getAt(strDictKey,idO)==Acad::eKeyNotFound){
        //create it if not
        if ((pEmployeeDict=new AcDbDictionary)==NULL)
            throw Acad::eOutOfMemory;
        Acad::ErrorStatus es;
        pParent->upgradeOpen();
        if ((es=pParent->setAt(strDictKey,pEmployeeDict,idO))!=Acad::eOk){
            //make sure that we don't leak memory
            //a smart pointer would come handy but let's not confuse
            //everyone quite yet
            delete pEmployeeDict;
            throw es;
        }
        //this will ensure that the newly added object is properly 
        //committed to the db when the transaction ends
        actrTransactionManager->addNewlyCreatedDBRObject(pEmployeeDict);
    } else {
        //get it for write if it is already there
        AcDbObject* pO;
        ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite));
        //check if someone has else has created an entry with our name
        //that is not a dictionary. This should never happen as long as
        //I use the registered developer ID.
        if ((pEmployeeDict=AcDbDictionary::cast(pO))==NULL)
            throw Acad::eNotThatKindOfClass;
    }
    //check if a record with this key is already there
    Acad::ErrorStatus es;
    if ((es=pEmployeeDict->getAt(strEmpKey,idO))==Acad::eOk)
        throw Acad::eAlreadyInDb;
    if (es!=Acad::eKeyNotFound)
        throw es;
    ARXOK(pEmployeeDict->setAt(strEmpKey,pEmployee,idO));
    //this will ensure that the newly added object is properly 
    //committed to the db when the transaction ends
    actrTransactionManager->addNewlyCreatedDBRObject(pEmployee);
}
// The list tree function runs through all objects in the ASDK_DICT dictionary,
// follows their ownership trees, and lists out information
// on all objects in the tree.
//
void
listTree()
{
    AcDbDictionary *pNamedobj;
    AcDbDictionary *pDict;
    acdbHostApplicationServices()->workingDatabase()
        ->getNamedObjectsDictionary(pNamedobj, AcDb::kForWrite);

    // Get a pointer to the ASDK_DICT dictionary.
    //
    if (pNamedobj->getAt(_T("ASDK_DICT"), (AcDbObject*&) pDict,
        AcDb::kForRead) == Acad::eKeyNotFound)
	{
		pNamedobj->close();
		return ;
	}

    pNamedobj->close();

    // Run through the entries and list their backpointers.
    //
    AcDbDictionaryIterator *pDictItr = pDict->newIterator();
    for (; !pDictItr->done(); pDictItr->next()) {
        printOut(pDictItr->objectId());
    }
    delete pDictItr;

    pDict->close();
}
Esempio n. 17
0
Acad::ErrorStatus CTwArxDictionary::CreateSubDictionaryID( IN const AcDbObjectId& IdRoot, IN const CString& strKey, OUT AcDbObjectId& IdSubDic, IN AcRxClass* pRxObjType /*= AcDbDictionary::desc() */ ) const
{
	if( pRxObjType == NULL ) return Acad::eNullObjectPointer;

	Acad::ErrorStatus es = Acad::eOk;
	AcDbDictionary* pDicRoot = NULL;
	AcDbDatabase* pWdb = acdbCurDwg();

	if( IdRoot.isNull() )
		es = pWdb->getNamedObjectsDictionary( pDicRoot, AcDb::kForRead );
	else
		es = acdbOpenObject( pDicRoot, IdRoot, AcDb::kForRead );

	if( es != Acad::eOk ) return es;

	if( pDicRoot->has(strKey) )
	{
		pDicRoot->getAt( strKey, IdSubDic );
		pDicRoot->close();
		return es;
	}

	pDicRoot->upgradeOpen();
	AcDbObject* pObj = (AcDbObject*)pRxObjType->create();
	es = pDicRoot->setAt( strKey, pObj, IdSubDic );
	pObj->close();
	pDicRoot->close();

	return es;
}
Esempio n. 18
0
// Adds the reactor to the editor to monitor changes.
//
void
setup()
{
    acedEditor->addReactor(gpEdReac);
    acutPrintf("Added new command to Wblock.\n");

    // Now,  for this sample only,  we need to create a
    // new dictionary,  add it to the named object
    // dictionary using the key string specified by the
    // constant pointer kpDictionary.  Then we'll create
    // a couple of empty xrecords and put them into the
    // new dictionary.  All of this provides the objects
    // that our code will be cloning across.
    //
    AcDbDictionary *pNamedobj;
    acdbHostApplicationServices()->workingDatabase()
        ->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead);

    AcDbDictionary *pDict;
    // Search for the dictionary associated with the key
    // kpDictionary.  If it's not found,  then create it,
    // add it to the namedobjects dictionary,  and then
    // create and add a few xrecords to it.
    //
    // If it is found then do nothing because it's already
    // been done sometime previously.
    //
    if (!pNamedobj->has(kpDictionary))
    {
        if (pNamedobj->upgradeOpen() == Acad::eOk) {
            pDict = new AcDbDictionary;
            AcDbObjectId DictId;
            pNamedobj->setAt(kpDictionary, pDict, DictId);
            pNamedobj->close();

            AcDbXrecord *pObj1 = new AcDbXrecord(),
                        *pObj2 = new AcDbXrecord();

            AcDbObjectId rId1, rId2;
            pDict->setAt("OBJ1", pObj1, rId1);
            pDict->setAt("OBJ2", pObj2, rId2);

            pObj1->close();
            pObj2->close();
            pDict->close();
        } else
            pNamedobj->close();
    }
}
Esempio n. 19
0
bool ArxDictTool2::addEntry( const CString& key, AcDbObject* pObj )
{
    AcDbDictionary* pDict = GetDictObject( m_dictId );
    if( pDict == 0 ) return false;

    bool ret = false;
    if( !pDict->has( key ) )
    {
        AcDbObjectId objId;
        if( Acad::eOk == pDict->setAt( key, pObj, objId ) )
        {
            pObj->close();
            ret = true;
        }
    }
    pDict->close();

    return ret;
}
Esempio n. 20
0
Acad::ErrorStatus CTwArxDictionary::GetSubDictionaryID( IN const AcDbObjectId& IdRoot, IN const CString& strKey, AcDbObjectId& IdSub, AcDbDatabase* pCurDB ) const
{
	Acad::ErrorStatus es = Acad::eOk;
	AcDbDictionary* pDicRoot = NULL;
	AcDbDatabase* pWdb = pCurDB;
	if( pWdb == NULL )
		pWdb = acdbCurDwg();
	if( IdRoot.isNull() )
		es = pWdb->getNamedObjectsDictionary( pDicRoot, AcDb::kForRead );
	else
		es = acdbOpenObject( pDicRoot, IdRoot, AcDb::kForRead );
	if( pDicRoot == NULL ) return es;
	pDicRoot->close();
	
	es = pDicRoot->getAt( strKey, IdSub );

	return es;

}
AcDbObjectId
ArxDbgDbAdeskLogoStyle::getStandardStyle(AcDbDatabase* db, bool makeIfNotThere)
{
    Acad::ErrorStatus es;
    AcDbObjectId styleId;
    AcDbDictionary* dict;

	const char* standardStrPtr = acdbGetReservedString(AcDb::kStandard, false);
	ASSERT(standardStrPtr != NULL);
	
	dict = ArxDbgUtils::openDictionaryForRead(m_dictName, db);
    if (dict) {
        es = dict->getAt(standardStrPtr, styleId);
		dict->close();

		if (es == Acad::eOk)
			return styleId;

		if (makeIfNotThere == false)
			return AcDbObjectId::kNull;
	}

		// wasn't already there, so we need to make it
	dict = ArxDbgUtils::openDictionaryForWrite(m_dictName, true, db);
	if (dict) {
        ArxDbgDbAdeskLogoStyle* newRec = new ArxDbgDbAdeskLogoStyle;
        es = dict->setAt(standardStrPtr, newRec, styleId);
		dict->close();
        if (es == Acad::eOk) {
            newRec->close();
			return styleId;
        }
        else {
            acutPrintf("\nERROR: Could not add new ArxDbgDbAdeskLogoStyle (%s)", ArxDbgUtils::rxErrorStr(es));
            delete newRec;
        }
    }

	return AcDbObjectId::kNull;
}
Esempio n. 22
0
void ArxDictTool::RegDict( const CString& dictName )
{
    // 初始化工作,建立存储词典
    AcDbDictionary* pNamedobj;
    acdbHostApplicationServices()->workingDatabase()->getNamedObjectsDictionary( pNamedobj, AcDb::kForWrite );

    AcDbObject* pObj;
    Acad::ErrorStatus es = pNamedobj->getAt( dictName, pObj, AcDb::kForRead );
    if( Acad::eOk ==  es )
    {
        pObj->close();
    }
    else if( Acad::eKeyNotFound == es )
    {
        AcDbDictionary* pDict = new AcDbDictionary();
        AcDbObjectId dictId;
        if( Acad::eOk != pNamedobj->setAt( dictName, pDict, dictId ) )
        {
            delete pDict;
        }
        else
        {
            pDict->close();
        }
    }
    pNamedobj->close();
}
Esempio n. 23
0
static ArxXRecordManager* GetXRecordManager( const AcDbObjectId& dictId, const CString& key, bool createNewKey = false )
{
    //acutPrintf(_T("\n注册: %s"), dictName);

    AcDbDictionary* pDict = GetDictObject( dictId );
    if( pDict == 0 ) return 0;

    AcDbXrecord* pXrec = 0;
    // key不存在或者其它原因
    Acad::ErrorStatus es = pDict->getAt( key, ( AcDbObject*& ) pXrec, AcDb::kForWrite );
    if( Acad::eOk != es && Acad::eKeyNotFound != es )
    {
        pDict->close();
        return 0;
    }

    if( Acad::eKeyNotFound == es )
    {
        if( createNewKey )
        {
            pXrec = new AcDbXrecord();
            AcDbObjectId xrecObjId;
            pDict->setAt( key, pXrec, xrecObjId );
        }
        else
        {
            pDict->close();
            return 0;
        }
    }
    pDict->close();
    return new ArxXRecordManager( pXrec );
}
AcDbObjectId
ArxDbgUiTdcPersistentReactors::getPersistentEntReactor(AcDbDatabase* db, bool createIfNotFound)
{
	static LPCTSTR dictEntryName = _T("ARXDBG_PERSISTENT_ENT_REACTOR");

	AcDbObjectId prId;
    AcDbDictionary* prDict;

		// first see if its already there without "disturbing" anyone by opening them
		// for write.
    prDict = ArxDbgUtils::openDictionaryForRead(m_dictName, db);
    if (prDict != NULL) {
		if (prDict->getAt(dictEntryName, prId) == Acad::eOk) {
			prDict->close();
			return prId;
		}
		prDict->close();
	}

		// couldn't find it, bail if we aren't supposed to create it.
	if (createIfNotFound == false)
		return AcDbObjectId::kNull;

		// not here yet, so make an entry
    prDict = ArxDbgUtils::openDictionaryForWrite(m_dictName, true, db);
    if (prDict == NULL)
        return AcDbObjectId::kNull;

    Acad::ErrorStatus es;
    ArxDbgPersistentEntReactor* pr = new ArxDbgPersistentEntReactor;

    es = prDict->setAt(dictEntryName, pr, prId);
    if (es != Acad::eOk) {
        ArxDbgUtils::rxErrorMsg(es);
        ArxDbgUtils::alertBox(_T("ERROR: Could not add entry to dictionary."));
        delete pr;

		prDict->close();
		return AcDbObjectId::kNull;
    }
    else {
		pr->close();
		prDict->close();
		return prId;
    }
}
Esempio n. 25
0
Acad::ErrorStatus CZhfPalette::Wblock(AcDbDatabase*& pDbFrom, AcDbDatabase*& pDbTo, /*const AcGePoint3d& pt_3d_base,*/ const AcGeMatrix3d & xform)
{
	Acad::ErrorStatus es ;

	AcDbObjectIdArray objIdsOut;

	AcDbBlockTable* pBT = NULL ;
	pDbFrom->getBlockTable(pBT, AcDb::kForRead);
	AcDbBlockTableRecord* pBTR = NULL;
	es = pBT->getAt(ACDB_MODEL_SPACE, pBTR, AcDb::kForRead);
	pBT->close();

	AcDbBlockTableRecordIterator* pIT;
	es = pBTR->newIterator(pIT) ;
	for (; !pIT->done(); pIT->step()) 
	{ 
		AcDbEntity* pEnt = NULL ;
		if (Acad::eOk==pIT->getEntity(pEnt, AcDb::kForRead))
		{
// 			if (!pEnt->isKindOf(AcDbAttributeDefinition::desc()))
// 			{
				AcDbObjectId objId;
				if (Acad::eOk == pIT->getEntityId(objId))
				{
					objIdsOut.append(objId);
				}
// 			}
			pEnt->close() ;
		}
	}

	delete pIT;
	pBTR->close();

	if (!objIdsOut.isEmpty()) 
	{
		for (int i=0; i<objIdsOut.length(); i++)
		{
			AcDbObjectId objId = objIdsOut.at(i);
			AcDbEntity *pEnt = NULL ;
			if(Acad::eOk==acdbOpenAcDbEntity(pEnt,objId, AcDb::kForRead))
			{
				AcDbObjectId objIdDic ;
				if ((objIdDic = pEnt->extensionDictionary())!= AcDbObjectId::kNull)
				{
					AcDbDictionary *pDict = NULL;				
					if (Acad::eOk==acdbOpenObject(pDict, objIdDic, AcDb::kForWrite))
					{
						pDict->setTreatElementsAsHard(Adesk::kTrue);
						pDict->close();
					}
				}
				pEnt->close() ;
			}
		}

		AcDbDatabase *pTempDb ;
		es = pDbFrom->wblock( pTempDb, objIdsOut, AcGePoint3d::kOrigin ) ;
		if (Acad::eOk != es )
		{
			acedAlert( _T("wblock failed!") );
			return es ;
		}
		es = pDbTo->insert( xform, pTempDb ) ;
		if (Acad::eOk != es)
			acedAlert( _T("insert failed!" ));
		if (pTempDb)
		{
			delete pTempDb;
			pTempDb = NULL ;
		}
	}
	else
	{
		acutPrintf(_T("\nNo entities found in model space of DWG"));
	}

	return es ;
}
Esempio n. 26
0
void
mkraddobjects()
{
    AcGePoint3d pt;
    if (RTNORM != acedGetPoint( NULL, "\nEnter position:", asDblArray (pt) ))
        return;

    AsdkMkrEntity* pEnt = new AsdkMkrEntity;
    if (NULL == pEnt)
        return;

    pEnt->setPos( pt );
    if (!append( pEnt )) {
        delete pEnt;
        return;
    }

    AcDbObjectId objId;
    AsdkMkrObject *pObj = new AsdkMkrObject;
    if (NULL == pObj) {
        pEnt->erase();
        pEnt->close();
        return;
    }

#ifdef DIRECT
    acdbHostApplicationServices()->workingDatabase()
        ->addAcDbObject( objId, pObj );
    pObj->close();
#else
#ifdef NOD
    AcDbDictionary* pMyDict = getDict( /*NOXLATE*/"ASDK_MYDICT", AcDb::kForWrite );
    if (NULL != pMyDict)
        pMyDict->setMergeStyle(AcDb::kDrcMangleName);
#else
    AcDbDictionary* pMyDict = getExtDict( pEnt, /*NOXLATE*/"ASDK_MYDICT", AcDb::kForWrite );
#endif  // NOD
    if (NULL == pMyDict) {
        delete pObj;
        pEnt->erase();
        pEnt->close();
        return;
    }

    Acad::ErrorStatus es;
    if (pMyDict->has( /*NOXLATE*/"MYENTRY" ))
        es = pMyDict->setAt( "*", pObj, objId );
    else
        es = pMyDict->setAt( /*NOXLATE*/"MYENTRY", pObj, objId );
    pMyDict->close();
    if (Acad::eOk == es)
        pObj->close();
    else {
        delete pObj;
        pEnt->erase();
        pEnt->close();
        return;
    }

#endif  // DIRECT
    pEnt->setId( objId );
    pEnt->close();

    acutPrintf( "\nEv'rything OK\n" );
}
void
ArxDbgAppEditorReactor::insertCloneOwnerDict(const AcDbObjectId& dictId,
                            AcDbDatabase* destDb, AcDbIdMapping& idMap)
{
        // the dictionaries are dealt with as a whole when encountering the
        // first entry within them. Skip processing if we have already 
        // encountered this one before.
    if (m_didTheseDicts.contains(dictId))
        return;
    else
        m_didTheseDicts.append(dictId);

        // get the name of the dictionary to recreate
    CString dictName;
    if (!ArxDbgUtils::lookUpDictEntryName(dictId, dictName)) {
        ArxDbgUtils::stopAlertBox(_T("ERROR: Couldn't find old dictionary name during Insert!"));
        return;
    }
        // open the source dictionary to be inserted
    AcDbDictionary* srcDict;
    if (acdbOpenObject(srcDict, dictId, AcDb::kForRead) != Acad::eOk) {
        ASSERT(0);
        return;
    }
        // try to open the destiniation dictionary.  Since INSERT does
        // not clone the destination NamedObjects dictionary, we can
        // use getAt() on it since IDs are not inFlux
    Acad::ErrorStatus es;
    AcDbDictionary* destDict = ArxDbgUtils::openDictionaryForRead(dictName, destDb);
    if (destDict) {
        es = destDict->upgradeOpen();
        if (es == Acad::eOk)
            insertCloneMergeDicts(srcDict, destDict, idMap);
        else {
            ASSERT(0);
        }
        destDict->close();
    }
    else {
            // our dictionary doesn't yet exist in destination database.
            // Use deepClone to clone it and all of its contents to the 
            // root dictionary of the destination database.
        AcDbDictionary* rootDictDest;
		es = destDb->getNamedObjectsDictionary(rootDictDest, AcDb::kForWrite);
        if (es == Acad::eOk) {
            AcDbObject* pClone = NULL;
            srcDict->deepClone(rootDictDest, pClone, idMap);
            if (pClone != NULL) {
                AcDbObjectId tmpObjId;
                es = rootDictDest->setAt(dictName, pClone, tmpObjId);
                if (es != Acad::eOk) {
                    ArxDbgUtils::stopAlertBox(_T("ERROR: Could not clone destination dictionary!"));
                    ArxDbgUtils::rxErrorAlert(es);
                }
                pClone->close();
            }
            rootDictDest->close();
        }
    }
    srcDict->close();
}
Esempio n. 28
0
OarxEmployee *OarxEmployeeService::createEmployee (int id, AcGePoint3d location, int cubeNumber, char *strFirstName, char *strLastName) {
	OarxEmployee *p =NULL ;
	AcDbXrecord *pRec =NULL ;
	AcDbDictionary *pAppDict =NULL ;

	try {
		//----- Create the object
		p =new OarxEmployee ;
		if ( p == NULL )
			throw Acad::eOutOfMemory ;

		ARXOK ( p->setID (id) ) ;
		ARXOK ( p->setCubeNumber (cubeNumber) ) ;
		ARXOK ( p->setFirstName (strFirstName) ) ;
		ARXOK ( p->setLastName (strLastName) ) ;
		ARXOK ( p->setCenter (location) ) ;

		AcDbObjectId id0 ;
		ARXOK ( postToDatabase (p, id0) ) ;

		pRec =new AcDbXrecord ;
		if ( pRec == NULL )
			throw Acad::eOutOfMemory ;

		struct resbuf rb ;
		rb.restype =330 ; //----- SoftPointerId to the OarxEmployee entity
		rb.rbnext =NULL ;
		ARXOK ( acdbGetAdsName (rb.resval.rlname, id0) ) ;

		ARXOK ( pRec->setFromRbChain (rb) ) ;
		pRec->setXlateReferences (Adesk::kTrue) ;

		AcDbObjectId idDict =getAppDictionary () ;
		if ( idDict == AcDbObjectId::kNull )
			throw Acad::eNullObjectId ;
		ARXOK ( acdbOpenAcDbObject ((AcDbObject *&)pAppDict, idDict, AcDb::kForWrite) ) ;

		char buffer [33] ;
		sprintf (buffer, "%d", id) ;
		ARXOK ( pAppDict->setAt (buffer, pRec, id0) ) ;

		pRec->close () ;
		pAppDict->close () ;

		return (p) ;

	} catch (const Acad::ErrorStatus es) {
		if ( p != NULL && p->objectId () == AcDbObjectId::kNull )
			delete p ;
		else
			p->cancel () ;

		if ( pRec != NULL && pRec->objectId () == AcDbObjectId::kNull )
			delete pRec ;
		else
			pRec->cancel () ;

		if ( pAppDict != NULL )
			pAppDict->cancel () ;

		return (NULL) ;
	}
}
Esempio n. 29
0
void
createObjs()
{
    AcDbObjectId objIdA, objIdB, objIdC;
    AcDbDictionary *pNamedobj;
    AcDbDictionary *pDict = NULL;
    AcDbDatabase *pCurDwg = acdbHostApplicationServices()->workingDatabase();

    // Create object C with a dummy integer data value of 3.
    //
    AsdkOwnerDemo *pObjC = new AsdkOwnerDemo(3);

    // Append object C to database without setting an owner.
    //
    pCurDwg->addAcDbObject(objIdC, pObjC);

    pObjC->close();

    // Create object B with a dummy integer data value of 2.
    //
    AsdkOwnerDemo *pObjB = new AsdkOwnerDemo(2);

    // Append object B to the database without setting an owner.
    //
    pCurDwg->addAcDbObject(objIdB, pObjB);

    // Now set up ownership for object C.  The
    // AsdkOwnerDemo::setIdData() function takes the
    // objectId parameter and copies it into the
    // AcDbHardOwnershipId data member.  This places the
    // object ID in a position to be filed out/in via the
    // dwgInFields/dwgOutFields/dxfInFields/dxfOutFields
    // member functions.  This constitutes primary
    // "ownership."  The AsdkOwnerDemo::setIdData() function
    // also calls each owned object's setOwnerId() member
    // function to set the backpointer and establish the
    // full two-way ownership link.
    //
    pObjB->setIdData(objIdC);

    pObjB->close();

    // Create object A with a dummy integer data value of 1.
    //
    AsdkOwnerDemo *pObjA = new AsdkOwnerDemo(1);

    // Next, add objA to a dictionary in the named object
    // dictionary.  This will establish ownership for objA,
    // set the ownership backlink, and add it to the
    // database.
    //
    pCurDwg->getNamedObjectsDictionary(pNamedobj,
                                       AcDb::kForWrite);

    // Get a pointer to the ASDK_DICT dictionary.  If it
    // doesn't exist, then create it and add it to the
    // named object dictionary.
    //
    if (pNamedobj->getAt("ASDK_DICT", (AcDbObject*&) pDict,
                         AcDb::kForWrite) == Acad::eKeyNotFound)
    {
        pDict = new AcDbDictionary;
        AcDbObjectId DictId;
        pNamedobj->setAt("ASDK_DICT", pDict, DictId);
    }
    pNamedobj->close();

    // add object A to the ASDK_DICT dictionary
    //
    pDict->setAt("OBJA", pObjA, objIdA);
    pDict->close();

    // Now set up ownership for object B.
    //
    pObjA->setIdData(objIdB);

    pObjA->close();
}
Esempio n. 30
0
// AsdkNODEdReactor is derived from AcEditorReactor
//
void
AsdkNODEdReactor::beginDeepCloneXlation(
    AcDbIdMapping& idMap,
    Acad::ErrorStatus* pRetStat)
{
    Acad::ErrorStatus es;
    AcDbObjectId dictId;

    if (   idMap.deepCloneContext() != AcDb::kDcWblock
        && idMap.deepCloneContext() != AcDb::kDcInsert)
        return;

    // Get the "from" and "to" databases. 
    //
    AcDbDatabase *pFrom, *pTo;
    idMap.origDb(pFrom);
    idMap.destDb(pTo);

    // See if the "from" database has our dictionary, and
    // open it.  If it doesn't have one, we are done.
    //
    AcDbDictionary *pSrcNamedObjDict;
    pFrom->getNamedObjectsDictionary(pSrcNamedObjDict,
                                     AcDb::kForRead);

    es = pSrcNamedObjDict->getAt(kpDictionary, dictId);
    pSrcNamedObjDict->close();

    if (es == Acad::eKeyNotFound) 
        return;

    AcDbDictionary *pSrcDict;
    acdbOpenObject(pSrcDict, dictId, AcDb::kForRead);

    AcDbObject *pClone;
    switch (idMap.deepCloneContext()) {

    case AcDb::kDcWblock:

        // WBLOCK clones all, or part of a drawing into a
        // newly created drawing.  This means that the
        // NamedObject Dictionary is always cloned, and
        // its AcDbObjectIds are in flux.  Therefore, you
        // cannot use getAt() or setAt() on the dictionary
        // in the new database.  This is because the
        // cloned dictionary references all refer to the 
        // original objects.  During Deep Clone translation,
        // all cloned entries will be translated to the
        // new objects, and entries not cloned will be
        // "removed" by getting "translated" to NULL.
        //
        // The cloning of entries in our own dictionary are
        // not handled here.  If all are to be cloned, then
        // call setTreatElementsAsHard(Adesk::kTrue) on the
        // dictionary.  Otherwise, only those entries which
        // are refered to by hard references in other
        // wblocked objects, will have been cloned via
        // those references.

        // In this example, we will always write out all of
        // the records.  Since TreatElementsAsHard is not
        // currently persistent, we reset it here each time.
        //
        pSrcDict->upgradeOpen();
        pSrcDict->setTreatElementsAsHard(Adesk::kTrue);

        pClone = NULL;
        pSrcDict->wblockClone(pTo, pClone, idMap,
                              Adesk::kFalse);
        if (pClone != NULL) 
            pClone->close();
        break;

    case AcDb::kDcInsert:

        // In INSERT, an entire drawing is cloned, and
        // "merged" into a pre-existing drawing.  This
        // means that the destination drawing may already
        // have our dictionary - in which case we have to
        // merge our entries into the destination
        // dictionary.   So, first we must find out if
        // the destination NamedObjects dictionary has
        // our dictionary.
        //
        AcDbDictionary *pDestNamedDict;
        pTo->getNamedObjectsDictionary(pDestNamedDict,
                                       AcDb::kForWrite);

        // Since INSERT does not clone the destination
        // NamedObjects dictionary, we can use getAt()
        // on it.
        //
        es = pDestNamedDict->getAt(kpDictionary, dictId);

        // If our dictionary does not yet exist in the
        // NamedObjects dictionary, which is not itself
        // cloned, we have to both clone and add our
        // dictionary to it.  Since dictionary entries are
        // ownership references, all of our entries will
        // also be cloned at this point, so we are done.
        //
        if (es == Acad::eKeyNotFound) {

            pClone = NULL;
            pSrcDict->deepClone(pDestNamedDict,
                                pClone, idMap);

            // Unless we have overridden the deepClone
            // of our dictionary, we should expect it to
            // always be cloned here.
            //
            if (pClone == NULL) {
                *pRetStat = Acad::eNullObjectId;
                break;
            }

            pDestNamedDict->setAt(kpDictionary,
                                  pClone, dictId);
            pDestNamedDict->close();
            pClone->close();
            break;
        } 
        pDestNamedDict->close();

        // Our dictionary already exists in the destination
        // database, so now we must "merge" the entries
        // into it.  Since we have not cloned our
        // destination dictionary, its objectIds are not in
        // flux, and we can use getAt() and setAt() on it.
        //
        AcDbDictionary *pDestDict;
        acdbOpenObject(pDestDict, dictId, AcDb::kForWrite);

        AcDbObject *pObj, *pObjClone;
        AcDbDictionaryIterator* pIter;
        pIter = pSrcDict->newIterator();

        for (; !pIter->done(); pIter->next()) {

            const char *pName = pIter->name();
            pIter->getObject(pObj, AcDb::kForRead);

            // If the dictionary contains any references
            // and/or other objects have references to it,
            // you must either use deepClone() or put the
            // idPairs into the idMap here, so that they
            // will be in the map for translation.
            //
            pObjClone = NULL;
            pObj->deepClone(pDestDict, pObjClone, idMap);

            // INSERT usually uses a method of cloning
            // called CheapClone, where it "moves" objects
            // into the destination database instead of
            // actually cloning them.  When this happens,
            // pObj and pObjClone are pointers to the
            // same object.  We only want to close pObj
            // here if it really is a different object.
            // 
            if (pObj != pObjClone)
                pObj->close();

            if (pObjClone == NULL)
                continue;

            // If the name already exists in our
            // destination dictionary, it must be changed
            // to something unique.  In this example, the
            // name is changed to an annonymous entry. 
            // The setAt() method will automatically append
            // a unique identifier to each name beginning
            // with "*".  It will become something like,
            // "*S04".
            //
            if (   pDestDict->getAt(pName, dictId)
                == Acad::eKeyNotFound) 
                pDestDict->setAt(pName, pObjClone, dictId);
            else 
                pDestDict->setAt("*S", pObjClone, dictId);

            pObjClone->close();
        }
        delete pIter;
        pDestDict->close();
        break;

    default:
        break;
    }

    pSrcDict->close();
}