Example #1
0
AcDbObjectId OarxEmployeeService::getAppDictionary () {
	AcDbDictionary *pNOD =NULL ;
	AcDbDictionary *pFirmDict =NULL ;
	AcDbDictionary *pAppDict =NULL ;

	try {
		//----- Get hold of the NOD
		ARXOK ( getNOD (pNOD, AcDb::kForRead) ) ;
		//----- Get our Firm Dictionary
		AcDbObjectId id0 ;
		if ( pNOD->getAt (OARX_FIRM_DICT, id0) == Acad::eKeyNotFound ) {
			//----- Then create it
			pFirmDict =new AcDbDictionary ;
			if ( pFirmDict == NULL )
				throw Acad::eOutOfMemory ;
			ARXOK ( pNOD->upgradeOpen () ) ;
			ARXOK ( pNOD->setAt (OARX_FIRM_DICT, pFirmDict, id0) ) ;
		} else {
			//----- Open the dictionary
			ARXOK ( acdbOpenAcDbObject ((AcDbObject *&)pFirmDict, id0, AcDb::kForRead) ) ;
		}
		//----- Get our App Dictionary
		if ( pFirmDict->getAt (OARX_APP_DICT, id0) == Acad::eKeyNotFound ) {
			//----- Then create it
			pAppDict =new AcDbDictionary ;
			if ( pAppDict == NULL )
				throw Acad::eOutOfMemory ;
            if ( pFirmDict->isWriteEnabled () == false )
			    ARXOK ( pFirmDict->upgradeOpen () ) ;
			ARXOK ( pFirmDict->setAt (OARX_APP_DICT, pAppDict, id0) ) ;
			id0 =pAppDict->objectId () ;
		}

		pNOD->close () ;
		pFirmDict->close () ;
		pAppDict->close () ;

		return (id0) ;

	} catch (const Acad::ErrorStatus es) {
		if ( pNOD != NULL )
			pNOD->cancel () ;

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

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

		return (AcDbObjectId::kNull) ;
	}
}
Example #2
0
//-----------------------------------------------------------------------------
//----- This is the AcRxService class Implementation
Adesk::Boolean OarxEmployeeService::isEmployeeExist (int id) {
	AcDbDictionary *pNOD =NULL ;
	AcDbDictionary *pFirmDict =NULL ;
	AcDbDictionary *pAppDict =NULL ;

	try {
		//----- Get hold of the NOD
		ARXOK ( getNOD (pNOD, AcDb::kForRead) ) ;
		//----- Get our Firm Dictionary
		AcDbObjectId id0 ;
		ARXOK ( pNOD->getAt (OARX_FIRM_DICT, id0) ) ;
		ARXOK ( acdbOpenAcDbObject ((AcDbObject *&)pFirmDict, id0, AcDb::kForRead) ) ;
		//----- Get our App Dictionary
		ARXOK ( pFirmDict->getAt (OARX_APP_DICT, id0) ) ;
		ARXOK ( acdbOpenAcDbObject ((AcDbObject *&)pAppDict, id0, AcDb::kForRead) ) ;
		//----- Check if that entry already exist
		char buffer [33] ;
		sprintf (buffer, "%d", id) ;
		Adesk::Boolean bRet =pAppDict->has (buffer) ;
		//----- Normally we should have open the associated XRecord, and check the validity of
		//----- the SoftPointerId which is supposed to point to an OarxEmployee entity... But
		//----- to simplify the sample we stop checking here!

		pNOD->close () ;
		pFirmDict->close () ;
		pAppDict->close () ;

		return (bRet) ;

	} catch (const Acad::ErrorStatus es) {
		if ( pNOD != NULL )
			pNOD->cancel () ;
		if ( pFirmDict != NULL )
			pFirmDict->cancel () ;
		if ( pAppDict != NULL )
			pAppDict->cancel () ;

		return (Adesk::kFalse) ;
	}
}
Example #3
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) ;
	}
}