Exemplo n.º 1
1
Acad::ErrorStatus createCircle(AcDbObjectId & idCircle)
{
	CLogger::Print(L"*Call: createCircle()");
	Acad::ErrorStatus es, esTmp;

	AcDbBlockTable* pBlockTable = NULL;
	es = acdbHostApplicationServices()->workingDatabase()
				->getSymbolTable(pBlockTable, AcDb::kForRead);
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to get the BlockTable.");
		return es;
	}

	AcDbBlockTableRecord* pModelSpace = NULL;
	es = pBlockTable->getAt(ACDB_MODEL_SPACE, pModelSpace, AcDb::kForWrite);
	if (Acad::eOk != (esTmp =  pBlockTable->close())) {
		CLogger::Print(L"Warn: Fail to close the BlockTable!");
		acrx_abort(ACRX_T("\nThere is an error occured when close the BlockTable. Message: %s")
									, acadErrorStatusText(esTmp));
	}
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to get the Model Space! Error: %s", acadErrorStatusText(es));
		return es;
	}

	idCircle = AcDbObjectId::kNull;
	AcGePoint3d pt3Center(9.0, 3.0, 0.0);
	AcGeVector3d vt3Normal(0.0, 0.0, 1.0);
	AcDbCircle* pCircle = new AcDbCircle(pt3Center, vt3Normal, 10.0);

	if (!pCircle) {
		if (Acad::eOk != (esTmp = pModelSpace->close())) {
			CLogger::Print(L"Warn: Fail to create new circle object!");
			acrx_abort(ACRX_T("\nThere is an error occured. Error: %s")
											, acadErrorStatusText(esTmp));
		}
		return Acad::eOutOfMemory;
	}

	es = pModelSpace->appendAcDbEntity(idCircle, pCircle);
	if (Acad::eOk != (esTmp = pModelSpace->close())) {
		CLogger::Print(L"Warn: Fail to close the Model Space!");
		acrx_abort(ACRX_T("\nThere is an error occured when close the Model Space! Error: %s")
										, acadErrorStatusText(esTmp));
	}
	if (Acad::eOk != es) {
		CLogger::Print(L"*Exit: createCircle() - Fail to append new circle in to Model Space!");
		delete pCircle;
		return es;
	}

	if (Acad::eOk != (esTmp = pCircle->close())) {
		CLogger::Print(L"Warn: Fail to close the circle object.");
		acrx_abort(ACRX_T("\nFail to close the circle entity!, Error: %s")
										, acadErrorStatusText(esTmp));
	}

	CLogger::Print(L"*Exit: createCircle()");
	return Acad::eOk;
}
Exemplo n.º 2
0
void create()
{
	Acad::ErrorStatus es;
	AcDbObjectId layerId;

	// create a new layer named "USER"
	// createLayer returns the object ID of the newly created layer
	// This is good ARX programming practice, though it is not used
	// subsequently in this lab

	es = createLayer("USER", layerId);
	if (es != Acad::eOk)
	{
		acutPrintf("\nERROR:  %s\nCouldn't create layer record.", acadErrorStatusText(es));
	}

	es = createBlockRecord("EMPLOYEE");
	if (es != Acad::eOk)
	{
		if(es == Acad::eDuplicateKey)
			acutPrintf("Block already defined.\n");
		else
			acutPrintf("\nERROR:  %s\nCouldn't create block record.", acadErrorStatusText(es));
	}
	else
	{
		acutPrintf("\nBlock EMPLOYEE successfully created.");
	}
}
Exemplo n.º 3
0
void jig3d()
{
    
    try
    {
        struct resbuf rb;
        acedGetVar("cvport", &rb);
        if (rb.resval.rint==1)
            throw CmdException("3djig cannot be used in layout mode");
        ads_name ename;
        ads_point pt;
		int rt;
        if ((rt = acedEntSel("Select object:",ename,pt))==RTCAN)
			return;
		if (rt!=RTNORM)
			throw CmdException(Acad::eInvalidInput,"Invalid selection. Try again!");
        AcDbObjectId id;
        acdbGetObjectId(id,ename);

        Jig3d jig;
        jig.init(id, asPnt3d(pt), rb.resval.rint);
        jig.engage();
    }
    catch(CmdException e)
    {
        const char* strDesc = e.description();
        if (strDesc == NULL)
            strDesc = "No description.";
        acutPrintf("ERROR:%s (es=%s)",strDesc,acadErrorStatusText(e.errorStatus()));
    }
}
Exemplo n.º 4
0
void LSS10()
{
	CLogger::Print(_T("-------------| START LOGGING LESSONS 10 |--------------"));
	AcDbObjectId idCircle;
	Acad::ErrorStatus es;
	if (Acad::eOk != (es = createCircle(idCircle))) {
		acutPrintf(ACRX_T("Fail to call createCircle() function - Error: %s")
									, acadErrorStatusText(es));
	}
}
Exemplo n.º 5
0
//-----------------------------------------------------------------------------
//----- This is used as the key for our custom
//----- dictionary. Note the registered developer id 'OARX'
//----- at the beginning
void lab9Command () {
	OarxEmployee *p =NULL ;

	try {
		//----- Start transaction for the db operations in this command
		actrTransactionManager->startTransaction () ;
		//----- Prompt the use for the an id
		int id ;
		ADSOK ( acedGetInt ("Enter employee's ID:", &id) ) ;
		//----- Before continuing, we should verify if that Employee is already registered
		if ( EmployeeService->isEmployeeExist (id) != Adesk::kTrue ) {
			//----- Continue data acquisition
			int cubeNumber ;
			char strFirstName [133] ;
			char strLastName [133] ;
			AcGePoint3d position ;

			ADSOK ( acedGetInt ("Enter cube number:", &cubeNumber) ) ;
			ADSOK ( acedGetString (0, "Enter employee's first name:", strFirstName) ) ;
			ADSOK ( acedGetString (0, "Enter employee's last name:", strLastName) ) ;
			ADSOK ( acedGetPoint (asDblArray (position), NULL, asDblArray (position)) ) ;

			p =EmployeeService->createEmployee (id, position, cubeNumber,strFirstName, strLastName) ;
			if ( p == NULL )
				throw Acad::eOutOfMemory ;
		}
		//----- Stop transaction
        actrTransactionManager->endTransaction () ;

	} catch (const Acad::ErrorStatus es) {
		if ( p != NULL && p->objectId () == AcDbObjectId::kNull )
			delete p ;
		//----- Abort, rollback all db operations
		actrTransactionManager->abortTransaction () ;
		//----- Check if the user has cancelled us, then we don't report anything
		if ( es != Acad::eUserBreak )
			acutPrintf ("***Error: %s\n", acadErrorStatusText (es)) ;
	}
}
void
errorReport(AcBr::ErrorStatus errorCode)
{
    switch (errorCode) {
	case(AcBr::eBrepChanged):
		acutPrintf(ACRX_T(" Brep Changed\n"));
		break;        
    case(AcBr::eUnsuitableTopology):
		acutPrintf(ACRX_T(" Unsuitable Topology\n"));
		break;        
    case(AcBr::eDegenerateTopology):
		acutPrintf(ACRX_T(" Degenerate Topology\n"));
		break;        
    case(AcBr::eUninitialisedObject):
		acutPrintf(ACRX_T(" Uninitialised Object\n"));
		break;        
	default: 
		acutPrintf(ACRX_T(" AutoCAD Error Code: %d\n"), errorCode);
		acadErrorStatusText((Acad::ErrorStatus)errorCode);
		break;    
	}

	return;
}
Exemplo n.º 7
0
void setInsertLayer()
{
	// Iterate through Model Space to find every instance of the EMPLOYEE block
	// When found, change its layer to "USER"
	
	Acad::ErrorStatus es;
	AcDbBlockTable* pBlockTbl;
	AcDbBlockTableRecord* pMS;

	if ((es = acdbCurDwg()->getBlockTable(pBlockTbl, AcDb::kForRead)) == Acad::eOk)
	{
	//Get the Model Space record and open it for read.
        if ((es = pBlockTbl->getAt(ACDB_MODEL_SPACE, pMS, AcDb::kForWrite)) != Acad::eOk)
		{
			acrx_abort("\nCouldn't get Model Space! Drawing corrupt.\n");
		}
	    pBlockTbl->close();
    }

	// declare the appropriate iterator
	// get the iterator from the object to be iterated through

	// in this case, the Model Space block table record will provide the iterator
	// start at the beginning of the record and skip deleted entities

	AcDbBlockTableRecordIterator* pBtrIter;
	if ((es = pMS->newIterator(pBtrIter)) != Acad::eOk)
	{
		acutPrintf("\nCouldn't create Model Space iterator: %s", acadErrorStatusText(es));
		return;
	}

	char* blockName;  
	AcDbEntity* pEnt;
	AcDbBlockTableRecord* pCurEntBlock;
	AcDbObjectId blockId;

	for (pBtrIter->start(); !pBtrIter->done(); pBtrIter->step())
	{
		// first open each entity for read, just to check its class
		// if it's what we want, we can upgrade open later
		// Don't bother with erased entities
		if ((es = pBtrIter->getEntity(pEnt, AcDb::kForRead)) != Acad::eOk)
		{
			acutPrintf("\nCouldn't open entity:  %s", acadErrorStatusText(es));
			continue;
		}

		// check isf the entity is an instance of type AcDbBlockReference
		if (pEnt->isA() != AcDbBlockReference::desc())
		{
			pEnt->close();
			continue;
		}
		
		// get the insert's block table record and compare its name
		// to make sure we've got the right block.  If so, set the layer
		blockId = (AcDbBlockReference::cast(pEnt))->blockTableRecord();
		if (acdbOpenObject((AcDbObject*&)pCurEntBlock, blockId, AcDb::kForRead) == Acad::eOk)
		{
			pCurEntBlock->getName(blockName);
			if (strcmp(blockName, "EMPLOYEE") == 0)
			{
				if (pEnt->upgradeOpen() == Acad::eOk)
					// setLayer also has an overload that takes a layer ID
					// but to avoid global variables we specify the layer name
					pEnt->setLayer("USER");
			}
			pCurEntBlock->close();
			acdbFree ( blockName );
		}
		pEnt->close();
	}

	// delete, rather than close, the iterator object
	delete pBtrIter;
    pMS->close();
	return;

}
Exemplo n.º 8
0
void 
polyeditCommand()
{
	Adesk::Boolean interrupted = Adesk::kFalse;
	Adesk::Boolean	    done;
    Acad::ErrorStatus es = Acad::eOk;
    AcDbFullSubentPath nullSub;
	AcGePoint2d   savedCenter;
	AcGePoint2d   savedStartPoint;
	int	     savedNumSides;
	AcGeVector3d  savedNormal;
	char	     savedName[133];
    double savedElevation;
    
    // Select an AsdkPoly entity.
    
    AsdkPoly	 *poly = NULL;
    AcDb3dSolid  *solid = NULL;
    AcDbObjectId  objId;
    
    ads_name	  ename;
    ads_point     ptres;

    AcDbEntity* ent;

	ads_name ss ;
	if ( acedSSGet ("_I", NULL, NULL, NULL, ss) == RTNORM ) {
		long n ;
		acedSSLength (ss, &n) ;
		switch ( n ) {
			case 0:
				//----- Not possible, but ?
				break ;
			case 1:
				acedSSName (ss, 0, ename) ;

				AOK(acdbGetObjectId(objId, ename));
        
				AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
				assert(ent != NULL);
        
				poly = AsdkPoly::cast(ent);
				if (poly == NULL) {
					acutPrintf("\nNot a polygon.");
					AOK(ent->close());
				}
				break ;
			default:
				//----- If more than one entity selected, fallback in standard selection mode
				break ;
		}
		acedSSFree (ss) ;
	}

	while ( poly == NULL ) {

		switch (acedEntSel("\nSelect a poly: ", ename, ptres)) {
        
		case RTNORM:
        
			AOK(acdbGetObjectId(objId, ename));
        
			AOK(acdbOpenAcDbEntity(ent, objId, AcDb::kForRead));
			assert(ent != NULL);
        
			poly = AsdkPoly::cast(ent);
			if (poly == NULL) {
				acutPrintf("\nNot a polygon.");
				AOK(ent->close());
				continue;
			}
        
			break;
        
		case RTNONE:
		case RTCAN:
			return;
		default:
			continue;
		}
		break;
	}

    // Now we have a polygon. Start editing it.
    
    char option[256];
    
    done = Adesk::kFalse;
    interrupted = Adesk::kFalse;
    
    while (!done && !interrupted) {
        
        AOK(getEditOption(option,interrupted));
        
        if (strcmp(option, "Grow") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(growPoly(poly));
            
        } else if (strcmp(option, "Shrink") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(shrinkPoly(poly));
            
        } else if (strcmp(option, "More") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(morePoly(poly));
            
        } else if (strcmp(option, "Less") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(lessPoly(poly));
            
        } else if (strcmp(option, "Thicken") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(thickenPoly(poly, ent, savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            solid = AcDb3dSolid::cast(ent);
            assert(solid != NULL);
            poly = NULL;
            
            
            solid->draw();
            
        } else if (strcmp(option, "Flatten") == 0) {
            
            if (!ent->isKindOf(AcDb3dSolid::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            AOK(flattenPoly(solid,ent,savedCenter,savedStartPoint, savedNumSides,savedNormal,savedName,savedElevation));
            
            poly = AsdkPoly::cast(ent);
            assert(poly != NULL);
            solid = NULL;
            
            
        } else if (strcmp(option, "Name") == 0) {
            
            if (!ent->isKindOf(AsdkPoly::desc())) {
                acutPrintf("\nNot Applicable");
                continue;
            }
            Acad::ErrorStatus es;
            if ((es = namePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's name. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
            if ((es = stylePoly(poly)) != Acad::eOk) {
                acutPrintf("\nError setting Poly's text style. Error: %s",
                    acadErrorStatusText(es));
                done = Adesk::kTrue;
                continue;
            }
        } else if (strcmp(option, "EXit") == 0) {
            done = Adesk::kTrue;
        } else {
            done = Adesk::kTrue;
        }
        
    }
    
    // Close the entity corresponding to the open for read right
    // after selection.
    
    AOK(ent->close());
}
Exemplo n.º 9
0
void addEmpCommand()
{ 
    AcDbDictionary* pEmployeeDict=NULL;
    EmployeeDetails* pEmployeeDetails=NULL;
    EmployeeEntry* pEmployeeEntry=NULL;
    //this cannot really happen but...
    if (acdbHostApplicationServices()->workingDatabase()==NULL)
        return;
    try
    {
        //start transaction for the db operations in this command
        actrTransactionManager->startTransaction();

        //get the data from the user
        ads_name ename;
        ads_point pt;
        ADSOK(acedEntSel("Select employee:",ename,pt));

        //do a quick check
        //a more comprehensive check could include 
        //a check to see if we already have the detail object on this candidate
        AcDbObjectId idO;
        ARXOK(acdbGetObjectId(idO,ename));
        AcDbObject* pO;
        ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite));
        if (!pO->isKindOf(AcDbBlockReference::desc()))
            throw Acad::eNotThatKindOfClass;

        //go on getting user input
        int id;
        ADSOK(acedGetInt("Enter employee ID:",&id));

        int cubeNumber;
        ADSOK(acedGetInt("Enter cube number:",&cubeNumber));

        char strFirstName[133];
        ADSOK(acedGetString(0,"Enter employee first name:",strFirstName));

        char strLastName[133];
        ADSOK(acedGetString(0,"Enter employee last name:",strLastName));
        
        //create an EmployeeDetails object and set its fields
        if ((pEmployeeDetails= new EmployeeDetails)==NULL)
            throw Acad::eOutOfMemory;
        ARXOK(pEmployeeDetails->setID(id));
        ARXOK(pEmployeeDetails->setCubeNumber(cubeNumber));
        ARXOK(pEmployeeDetails->setFirstName(strFirstName));
        ARXOK(pEmployeeDetails->setLastName(strLastName));

        //get hold of the extension dictionary
        if ((idO = pO->extensionDictionary())==AcDbObjectId::kNull){
            ARXOK(pO->createExtensionDictionary());
            idO = pO->extensionDictionary();
        }
        AcDbDictionary* pExtDict;
        //make sure you open erased extension dictionaries
        //you may need to unerase them
        ARXOK(actrTransactionManager->getObject((AcDbObject*&)pExtDict,idO,AcDb::kForWrite,Adesk::kTrue));
        
        //add the EmployeeDetails to the extension dictionary
        addDictAndEntry(DICT,pExtDict,DETAILS,pEmployeeDetails);
        
        //create the EmployeeEntry and set the id it holds to
        //point to the corresponding EmployeeDetails
        if ((pEmployeeEntry= new EmployeeEntry)==NULL)
            throw Acad::eOutOfMemory;
        ARXOK(pEmployeeEntry->setEmployee(pEmployeeDetails->objectId()));

        //get hold of the NOD
        AcDbDictionary* pNOD;
		ARXOK(getNOD(pNOD,AcDb::kForWrite));
        
        //create string key from the employee id
        char strID[33];
        sprintf(strID,"%d",id);

        //set the EmployeeEntry to the NOD
        addDictAndEntry(DICT,pNOD,strID,pEmployeeEntry);

        actrTransactionManager->endTransaction();
    }
    catch (const Acad::ErrorStatus es)
    {
        //we have run into some error
        //do the proper cleanup. a smart pointer could check these in its
        //destructor and then we wouldn't need this but we I don't want to
        //complicate the picture with that yet.
        if (pEmployeeDict!=NULL && 
            pEmployeeDict->objectId()==AcDbObjectId::kNull)
            delete pEmployeeDict;
        if (pEmployeeDetails!=NULL && 
            pEmployeeDetails->objectId()==AcDbObjectId::kNull)
            delete pEmployeeDetails;
        if (pEmployeeEntry!=NULL && 
            pEmployeeEntry->objectId()==AcDbObjectId::kNull)
            delete pEmployeeEntry;
        //abort, rollback all db operations
        actrTransactionManager->abortTransaction();
        //check if the user has cancelled us, then we don't report
        //anything
        if (es!=Acad::eUserBreak)
            acutPrintf("***Error: %s\n",acadErrorStatusText(es));
    }
}
Exemplo n.º 10
0
void listEmpsCommand()
{
    //this cannot really happen but...
    if (acdbHostApplicationServices()->workingDatabase()==NULL)
        return;
    AcDbDictionaryIterator* pIter=NULL;
    try
    {
        //start transaction for the db operations in this command
        actrTransactionManager->startTransaction();
        
        
        //get the named object dictionary
        AcDbDictionary* pNOD;
        ARXOK(getNOD(pNOD,AcDb::kForRead));

        //see if our dictionary is there
        AcDbObjectId idO;
        ARXOK(pNOD->getAt(DICT,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=NULL;
        if ((pEmployeeDict=AcDbDictionary::cast(pO))==NULL)
            throw Acad::eNotThatKindOfClass;

        if ((pIter = pEmployeeDict->newIterator(AcRx::kDictCollated))!=NULL){
            for (;!pIter->done();pIter->next()){
                //get the object
                ARXOK(actrTransactionManager->getObject(pO,pIter->objectId(),AcDb::kForRead));

                //check if it is the right one
                EmployeeEntry* pEmployeeEntry;
                if ((pEmployeeEntry=EmployeeEntry::cast(pO))==NULL)
                    throw Acad::eNotThatKindOfClass;

                //get the corresponding EmployeeDetail object
                ARXOK(actrTransactionManager->getObject(pO,pEmployeeEntry->employee(),AcDb::kForRead));
                EmployeeDetails* pEmployeeDetails;
                if ((pEmployeeDetails=EmployeeDetails::cast(pO))==NULL)
                    throw Acad::eNotThatKindOfClass;

                //print the details now
                acutPrintf("*Employee's ID:%d\n",pEmployeeDetails->ID());
                acutPrintf("*Employee's cube number:%d\n",pEmployeeDetails->cubeNumber());
                acutPrintf("*Employee's first name:%s\n",pEmployeeDetails->firstName());
                acutPrintf("*Employee's last name:%s\n",pEmployeeDetails->lastName());

                //this will ease memory burden when implemented
                ARXOK(actrTransactionManager->markObjectPageable(pO));
            }
            //shouldn't forget this
            delete pIter;
            pIter=NULL;
        }

        actrTransactionManager->endTransaction();
    }
    catch (const Acad::ErrorStatus es)
    {
        if (pIter!=NULL)
            delete pIter;
        //abort, rollback all db operations
        actrTransactionManager->abortTransaction();
        //check if the user has cancelled us, then we don't report
        //anything
        if (es!=Acad::eUserBreak)
            acutPrintf("***Error: %s\n",acadErrorStatusText(es));
    }
}
Exemplo n.º 11
0
void removeEmpCommand()
{ 
    //this cannot really happen but...
    if (acdbHostApplicationServices()->workingDatabase()==NULL)
        return;
    try
    {
        //start transaction for the db operations in this command
        actrTransactionManager->startTransaction();

        //get you extension dictionary
        AcDbDictionary* pExtDict = NULL;
        getExtDictOfObject(pExtDict);
        
        //get the id from the EmployeeDetails object
        //see if our dictionary is there
        AcDbObjectId idO;
        ARXOK(pExtDict->getAt(DICT,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=NULL;
        if ((pEmployeeDict=AcDbDictionary::cast(pO))==NULL)
            throw Acad::eNotThatKindOfClass;

        //check if a record with this key is there
        ARXOK(pEmployeeDict->getAt(DETAILS,idO));

        //get it for write 
        ARXOK(actrTransactionManager->getObject(pO,idO,AcDb::kForWrite));
        
        EmployeeDetails* pEmployeeDetails;
        if ((pEmployeeDetails=EmployeeDetails::cast(pO))==NULL)
            throw Acad::eNotThatKindOfClass;

        //create string key from the employee id
        char strID[33];
        sprintf(strID,"%d",pEmployeeDetails->ID());

        //and then erase it
        ARXOK(pO->erase());

        //get hold of the NOD
        AcDbDictionary* pNOD;
        ARXOK(getNOD(pNOD,AcDb::kForWrite));
        
        //remove the EmployeeEntry from NOD
        removeEntryFromDict(DICT,pNOD,strID);

        actrTransactionManager->endTransaction();
    }
    catch (const Acad::ErrorStatus es)
    {
        //abort, rollback all db operations
        actrTransactionManager->abortTransaction();
        //check if the user has cancelled us, then we don't report
        //anything
        if (es!=Acad::eUserBreak)
            acutPrintf("***Error: %s\n",acadErrorStatusText(es));
    }
}