Exemplo n.º 1
2
void addXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }
	// Get new XData.
	TCHAR appName[132] = {0};
	TCHAR resString[200] = {0};

    acedGetString(NULL, _T("\nEnter application name: "), appName);
    acedGetString(NULL, _T("\nEnter string to be added: "), resString);

    // XData
    resbuf *pRb = NULL;
	resbuf *pTemp = NULL;
    
    pRb = pObj->xData(appName);

    if (pRb != NULL)
	{
        for (pTemp = pRb; pTemp->rbnext != NULL; pTemp = pTemp->rbnext);
    }
	else
	{
        acdbRegApp(appName);
        pRb = acutNewRb(AcDb::kDxfRegAppName);
        pTemp = pRb;
        pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(appName) + 1) * sizeof(TCHAR));
        _tcscpy(pTemp->resval.rstring, appName);
    }

    pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
    pTemp = pTemp->rbnext;
    pTemp->resval.rstring = (TCHAR*)malloc((_tcslen(resString) + 1) * sizeof(TCHAR));
    _tcscpy(pTemp->resval.rstring, resString);

	// Set XData.
    pObj->upgradeOpen();
    pObj->setXData(pRb);
    
    pObj->close();
    acutRelRb(pRb);
}
Exemplo n.º 2
1
// Queries the user for Yes/No answer
//
static Adesk::Boolean
getYorN(const char* pStr)
{
    char yorn_str[132];

    // specific prompt.
    //
    acutPrintf("\n%s", pStr);

    acedInitGet(0, "No Yes");

    yorn_str[0] = 'Y';
    yorn_str[1] = '\0';

    switch (acedGetString(Adesk::kFalse, " -- No/<Yes>:  ",
        yorn_str))
    {
    case RTKWORD:
        acedGetInput(yorn_str);
        /* Deliberate fallthrough */
    default:
        break;
    }

    return (!((yorn_str[0] == 'N')
        || (yorn_str[0] == 'n')));
}
// Queries the user for Yes/No answer
//
static Adesk::Boolean
getYorN(const TCHAR* pStr)
{
    TCHAR yorn_str[132];

    // specific prompt.
    //
    acutPrintf(_T("\n%s"), pStr);

    acedInitGet(0, _T("No Yes"));

    yorn_str[0] = _T('Y');
    yorn_str[1] = _T('\0');

    switch (acedGetString(Adesk::kFalse, _T(" -- No/<Yes>:  "),
        yorn_str))
    {
    case RTKWORD:
        acedGetInput(yorn_str);
        /* Deliberate fallthrough */
    default:
        break;
    }

    return (!((yorn_str[0] == _T('N'))
        || (yorn_str[0] == _T('n'))));
}
Exemplo n.º 4
0
void CmdHelper::PostJsonDatasToRpc()
{
	TCHAR strFileName[MAX_PATH];
	if(acedGetString(0, _T("请指定数据文件名称:"), strFileName) != RTNORM) return;

	std::ifstream infile(W2C(strFileName));
	if(!infile) return;

	//有些请求可能需要传递给cad一些参数
	std::string input_datas = "{}";
	infile >> input_datas;

	//服务器生成的密钥
	std::string secret_key = "#";
	infile >> secret_key;
	infile.close();

	acutPrintf(_T("\n1:%s\n2:%s"), C2W(input_datas), C2W(secret_key));
	if(secret_key == "#") return;

	// 收集数据(根据input_datas的内容进行判断:input_datas是一个json数据)

	//发送rpc服务器进行缓存
	std::string out_datas = "{'name':'dlj'}";
	CbmClientHelper::PostJsonDatasFromCAD(secret_key, input_datas, out_datas);
}
Exemplo n.º 5
0
static Acad::ErrorStatus 
stylePoly(AsdkPoly* poly)
{
    Acad::ErrorStatus es = Acad::eOk;
    
    char nameBuf[133];
    int as;
    if ((as = acedGetString(Adesk::kTrue, "\nEnter new text style: ", 
        nameBuf)) == RTNORM) {
        // NULL string.
        if (strlen(nameBuf) == 0)
            return Acad::eOk;
        AcDbObjectId tsId;
        if ((es = rx_getTextStyleId(nameBuf, 
                acdbHostApplicationServices()->workingDatabase(), 
                tsId)) != Acad::eOk)
            return es;
        if ((es = poly->upgradeOpen()) != Acad::eOk) {
            return es;
        }
        if ((es = poly->setTextStyle(tsId)) != Acad::eOk) {
            poly->downgradeOpen();
            return es;
        }
        return poly->downgradeOpen();
    } else if (as == RTCAN)
        return Acad::eOk;
    else
        return Acad::eInvalidInput;
}
Exemplo n.º 6
0
// The selectObject() function prompts the user to select an 
// entity or enter an object's handle.  It then proceeds to 
// open the object/entity and return a pointer to it.
// 
AcDbObject*
selectObject(AcDb::OpenMode openMode)
{
    ads_name en;
    ads_point pt;
    char handleStr[132];
    AcDbObjectId eId;

    Acad::ErrorStatus retStat;
    int ss;

    // Allow user to either pick an entity,
    // or type in the object handle.
    //
    acedInitGet(RSG_OTHER, "_Handle Handle");
    ss = acedEntSel("\nSelect an Entity or enter"
        " 'H' to enter its handle:  ", en, pt);

    switch (ss) {
    case RTNORM:   // got it!
        break;
    case RTKWORD:
        if ((acedGetString(Adesk::kFalse,
            "Enter Valid Object Handle: ",
            handleStr) == RTNORM)
            && (acdbHandEnt(handleStr, en) == RTNORM))
        {
            break;
        }
    // Fall-through intentional
    //
    default:
        acutPrintf("Nothing Selected, Return Code==%d\n",
            ss);
        return NULL;
    }

    // Now, exchange the ads_name for the object Id...
    //
    retStat = acdbGetObjectId(eId, en);
    if (retStat != Acad::eOk) {
        acutPrintf("\nacdbGetObjectId failed");
        acutPrintf("\nen==(%lx,%lx), retStat==%d\n",
            en[0], en[1], eId);
        return NULL;
    }

    AcDbObject* pObj;

    if ((retStat = acdbOpenObject(pObj, eId, openMode))
        != Acad::eOk)
    {
        acutPrintf("acdbOpenEntity failed: ename:"
            "(%lx,%lx), mode:%d retStat:%d", en[0],
            en[1], openMode, retStat);
        return NULL;
    }
    return pObj;
}
Exemplo n.º 7
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)) ;
	}
}
Exemplo n.º 8
0
void printXData()
{
	// Get an Entity.
	ads_name mnEnt;
    ads_point ptSel;
    int nRet = acedEntSel(_T("\nSelect an Entity: "), mnEnt, ptSel);
	if (nRet != RTNORM)
		return;
	AcDbObjectId oid;
	
    Acad::ErrorStatus retStat;
    retStat = acdbGetObjectId(oid, mnEnt);
    if (retStat != Acad::eOk)
		return;

    AcDbObject* pObj = NULL;

    if ((retStat = acdbOpenObject(pObj, oid, AcDb::kForRead)) != Acad::eOk)
    {
        return;
    }

    // Get the application name for the xdata.
    //
	TCHAR appname[133] = {0};
    if (acedGetString(NULL, _T("\nEnter the Xdata application name: "), appname) != RTNORM)
    {
        return;
    }

    // Get the xdata for the application name.
    //
    resbuf *pRb = pObj->xData(appname);

    if (pRb != NULL)
	{
        printXDList(pRb);
        acutRelRb(pRb);
    }
	else
	{
        acutPrintf(_T("\nNo xdata for appname: %s."), appname);
    }
    pObj->close();
}
Exemplo n.º 9
0
static Acad::ErrorStatus 
namePoly(AsdkPoly* poly)
{
    Acad::ErrorStatus es = Acad::eOk;
    
    char nameBuf[133];
    if (acedGetString(Adesk::kTrue, "\nEnter new name: ", nameBuf) == RTNORM) {
        if ((es = poly->upgradeOpen()) != Acad::eOk) {
            return es;
        }
        if ((es = poly->setName(nameBuf)) != Acad::eOk) {
            poly->downgradeOpen();
            return es;
        }
        
        return poly->downgradeOpen();
    } else
        return Acad::eInvalidInput;
}
Exemplo n.º 10
0
bool printXData()
{
	CLogger::Print(_T("*Call: printxData()"));
	AcDbObject* pObj;
	
	//------------
	// Require to select an entity
	if (!(pObj = selectObject(AcDb::kForRead))) {
		CLogger::Print(_T("*Exit: printxData() - Object have not selected."));
		return false;
	}

	//------------
	// Require to enter xData application name
	ACHAR appname[133];
	if (RTNORM != acedGetString(NULL, ACRX_T("\nEnter the desired Xdata application name: "), appname)) 
	{
		CLogger::Print(_T("*Exit: printxData() - Fail to enter the application name!"));
		return false;
	}

	//------------
	// Read the xData that contained in object.
	// If application name is existing then print out its values.
	struct resbuf* pRb;
	pRb = pObj->xData(appname);
	pObj->close();
	if (pRb) {
		acutPrintf(ACRX_T("Inform: Application name '%s' is existing - The values are: "), appname);
		printList(pRb);
		acutRelRb(pRb); // release xData after using!
	} else {
		acutPrintf(ACRX_T("\n*Exit: printxData() - Application name '%s' is not existing."), appname);
		pObj->close();
		return false;
	}

	pObj->close();
	CLogger::Print(_T("*Exit: printxData()"));
	return true;
}
// This function calls the
// selectObject() function to allow the user to pick an
// object; then it accesses the xdata of the object and
// sends the list to the printList() function that lists the
// restype and resval values.
// 
void
printXdata()
{
    // Select and open an object.
    //
    AcDbObject *pObj;
    if ((pObj = selectObject(AcDb::kForRead)) == NULL) {
        return;
    }

    // Get the application name for the xdata.
    //
    TCHAR appname[133];
    if (acedGetString(NULL,
        _T("\nEnter the desired Xdata application name: "),
        appname) != RTNORM)
    {
        return;
    }

    // Get the xdata for the application name.
    //
    struct resbuf *pRb;
    pRb = pObj->xData(appname);

    if (pRb != NULL) {

        // Print the existing xdata if any is present.
        // Notice that there is no -3 group, as there is in
        // LISP. This is ONLY the xdata, so
        // the -3 xdata-start marker isn't needed.
        // 
        printList(pRb);
        acutRelRb(pRb);

    } else {
        acutPrintf(_T("\nNo xdata for this appname"));
    }
    pObj->close();
}
Exemplo n.º 12
0
void
printAll()
{
    int rc;
    char blkName[50];
    rc = acedGetString(Adesk::kTrue,
        "Enter Block Name <CR for current space>: ",
        blkName);

    if (rc != RTNORM)
        return;

    if (blkName[0] == '\0') {
        if (acdbHostApplicationServices()->workingDatabase()->tilemode() 
            == Adesk::kFalse) {
            struct resbuf rb;
            acedGetVar("cvport", &rb);
            if (rb.resval.rint == 1) {
                strcpy(blkName, ACDB_PAPER_SPACE);
            } else {
                strcpy(blkName, ACDB_MODEL_SPACE);
            }
        } else {
            strcpy(blkName, ACDB_MODEL_SPACE);
        }
    }
    AcDbBlockTable *pBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pBlockTableRecord;
    pBlockTable->getAt(blkName, pBlockTableRecord,
        AcDb::kForRead);
    pBlockTable->close();

    AcDbBlockTableRecordIterator *pBlockIterator;
    pBlockTableRecord->newIterator(pBlockIterator);

    for (; !pBlockIterator->done();
        pBlockIterator->step())
    {
        AcDbEntity *pEntity;
        pBlockIterator->getEntity(pEntity, AcDb::kForRead);

        AcDbHandle objHandle;
        pEntity->getAcDbHandle(objHandle);

        char handleStr[20];
        objHandle.getIntoAsciiBuffer(handleStr);
        const char *pCname = pEntity->isA()->name();

        acutPrintf("Object Id %lx, handle %s, class %s.\n",
            pEntity->objectId(), handleStr, pCname);

        pEntity->close();
    }
    delete pBlockIterator;
    pBlockTableRecord->close();

    acutPrintf("\n");
}
void 
addXdata() 
{
    AcDbObject* pObj = selectObject(AcDb::kForRead);
    if (!pObj) {
        acutPrintf(_T("Error selecting object\n"));
        return;
    }

    
    // Get the application name and string to be added to
    // xdata.
    //
    TCHAR appName[132], resString[200];
    appName[0] = resString[0] = _T('\0');

    acedGetString(NULL, _T("Enter application name: "),
        appName);
    acedGetString(NULL, _T("Enter string to be added: "),
        resString);

    
    struct  resbuf  *pRb, *pTemp;
    
    pRb = pObj->xData(appName);

    if (pRb != NULL) {

        // If xdata is present, then walk to the
        // end of the list.
        //
        for (pTemp = pRb; pTemp->rbnext != NULL;
                pTemp = pTemp->rbnext)
                { ; }
    } else {
        // If xdata is not present, register the application
        // and add appName to the first resbuf in the list.
        // Notice that there is no -3 group as there is in
        // AutoLISP. This is ONLY the xdata so
        // the -3 xdata-start marker isn't needed.
        // 
        acdbRegApp(appName);

        pRb = acutNewRb(AcDb::kDxfRegAppName);
        pTemp = pRb;
        const size_t nSize = _tcslen(appName) + 1;
        pTemp->resval.rstring
            = (TCHAR*) malloc(nSize * sizeof(TCHAR));
        errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, appName);
        assert(err == 0);
    }

    // Add user-specified string to the xdata.
    //
    pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
    pTemp = pTemp->rbnext;
    const size_t nSize = _tcslen(resString) + 1;
    pTemp->resval.rstring
        = (TCHAR*) malloc(nSize * sizeof(TCHAR));
    errno_t err = _tcscpy_s(pTemp->resval.rstring, nSize, resString);
    assert(err == 0);

    // The following code shows the use of upgradeOpen()
    // to change the entity from read to write.
    //
    pObj->upgradeOpen();
    pObj->setXData(pRb);
    
    pObj->close();
    acutRelRb(pRb);
}
// This function accepts a linked list of resbufs as it's
// argument and runs through the list printing out the
// restype and resval values one set per line.
// 
void
printList(struct resbuf* pRb)
{
    int rt, i;
    TCHAR buf[133];

    for (i = 0;pRb != NULL;i++, pRb = pRb->rbnext) {
        if (pRb->restype < 1010) {
            rt = RTSTR;
        } else if (pRb->restype < 1040) {
            rt = RT3DPOINT;
        } else if (pRb->restype < 1060) {
            rt = RTREAL;
        } else if (pRb->restype < 1071) {
            rt = RTSHORT;
        } else if (pRb->restype == 1071) {
            rt = RTLONG;
        } else {// restype is already RTSHORT, RTSTR,...
            rt = pRb->restype; // or else it is unknown.
        }

        switch (rt) {
        case RTSHORT:
            if (pRb->restype == RTSHORT) {
                acutPrintf(
                    _T("RTSHORT : %d\n"), pRb->resval.rint);
            } else {
                acutPrintf(_T("(%d . %d)\n"), pRb->restype,
                    pRb->resval.rint);
            };
            break;

        case RTREAL:
            if (pRb->restype == RTREAL) {
                acutPrintf(_T("RTREAL : %0.3f\n"),
                    pRb->resval.rreal);
            } else {
                acutPrintf(_T("(%d . %0.3f)\n"), pRb->restype,
                    pRb->resval.rreal);
            };
            break;

        case RTSTR:
            if (pRb->restype == RTSTR) {
                acutPrintf(_T("RTSTR : %s\n"),
                    pRb->resval.rstring);
            } else {
                acutPrintf(_T("(%d . \"%s\")\n"), pRb->restype,
                    pRb->resval.rstring);
            };
            break;

        case RT3DPOINT:
            if (pRb->restype == RT3DPOINT) {
                acutPrintf(
                    _T("RT3DPOINT : %0.3f, %0.3f, %0.3f\n"),
                    pRb->resval.rpoint[X],
                    pRb->resval.rpoint[Y],
                    pRb->resval.rpoint[Z]);
            } else {
                acutPrintf(_T("(%d %0.3f %0.3f %0.3f)\n"),
                    pRb->restype,
                    pRb->resval.rpoint[X],
                    pRb->resval.rpoint[Y],
                    pRb->resval.rpoint[Z]);
            }
            break;

        case RTLONG:
            acutPrintf(_T("RTLONG : %dl\n"), pRb->resval.rlong);
            break;
        }

        if ((i == 23) && (pRb->rbnext != NULL)) {
            i = 0;
            acedGetString(0,
                _T("Press <ENTER> to continue..."), buf);
        }
    }
}
Exemplo n.º 15
0
bool addXData()
{
	Acad::ErrorStatus es, esTmp;
	CLogger::Print(_T("*Call: addXData()"));

	//------------
	// Require to select an entity.
	AcDbObject* pObj = selectObject(AcDb::kForRead);
	if (!pObj) {
		CLogger::Print(_T("*Exit: addXData() - Khong chon duoc object!"));
		return false;
	}

	//------------
	// Require to enter the application name, then require to enter its string value.
	ACHAR appName[133], resString[133];
	appName[0] = resString[0] = L'\0';
	acedGetString(NULL, ACRX_T("\nEnter application name: "), appName);
	acedGetString(NULL, ACRX_T("\nEnter string to be added: "), resString);

	CLogger::Print(_T("Inform: Found out application name '%s'!"), appName);
	struct resbuf * pRb;
	struct resbuf * pTemp;
	pRb = pObj->xData(appName);

	if (pRb) {
		// If the appname is existing! Seek to the tail of resbuf link list.
		CLogger::Print(_T("Inform: Found out application name '%s' - Seek to the end of resbuf link list."), appName);
		for (pTemp = pRb; pTemp->rbnext; pTemp = pTemp->rbnext) {}
	} else {
		// If the appname is not existing! Register a new application name.
		CLogger::Print(_T("Inform: The application name %s is not existing, register this application name!"), appName);
		acdbRegApp(appName);

		// Then create new resbuf to copy the application name into it.
		pRb = acutNewRb(AcDb::kDxfRegAppName);
		pTemp = pRb;
		pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(appName) + 1) * sizeof(ACHAR));
		lstrcpy(pTemp->resval.rstring, appName);
	}

	//------------
	// Create new resbuf at the tail of the link list, then copy the value string into it.
	pTemp->rbnext = acutNewRb(AcDb::kDxfXdAsciiString);
	pTemp = pTemp->rbnext;
	pTemp->resval.rstring = (ACHAR*) malloc((lstrlen(resString) + 1) * sizeof(ACHAR));
	lstrcpy(pTemp->resval.rstring, resString);

	CLogger::Print(_T("Inform: Upgrade object opening!"));
	if (Acad::eOk != (es = pObj->upgradeOpen())) {
		CLogger::Print(_T("*Exit: addXData() - Fail to upgrade opening object!"));
		pObj->close();
		acutRelRb(pRb);
		return false;
	}

	//------------
	// Set object's xData.
	pObj->setXData(pRb);
	pObj->close();
	acutRelRb(pRb); // remember to release resbuf after using
	CLogger::Print(_T("*Exit: addXData()!"));
	return true;
}
Exemplo n.º 16
0
// input may either return RTNORM (from command line) or RTMODELESS (from OPM)
// if it is RTMODELSS, the entity already has that value set.
// if it not RTMODELSS, we process as before, setting the value on m_pPoly
void CPolyCommand::getInput()
{
    ads_point tmpc;
    char tmpBuf[133];
    if (!m_pPolyCmd->GotNumSides()) {
        int nSides;
        acedInitGet(INP_NNEG, "");
        if ((m_retval = acedGetInt("\nEnter number of sides: ", &nSides))
            == RTNORM)
        {
            if (nSides < 3) {
                acutPrintf("\nNeed at least 3 sides.");
                return;
            }
            m_pPoly->put_NumSides(nSides);
        }
    } else if (!m_pPolyCmd->GotCenter()) {
        if ((m_retval = acedGetPoint(NULL,
            "\nLocate center of polygon: ", tmpc)) == RTNORM)
        {
            AcAxPoint2d pt2d(tmpc[0],tmpc[1]);
            m_pPoly->put_Center(*pt2d.asVariantPtr());
        }
    } else if (!m_pPolyCmd->GotStartPoint()) {
        AcAxPoint2d pt2dCtr(0.0,0.0);
        VARIANT *pVar = pt2dCtr.asVariantPtr();
        m_pPoly->get_Center(pVar);
        pt2dCtr = pVar;
        ads_point cp = { pt2dCtr.x, pt2dCtr.y };
        if ((m_retval = acedGetPoint(cp,
            "\nLocate start point of polygon: ", tmpc)) == RTNORM)
        {
            AcAxPoint2d pt2d(tmpc[0],tmpc[1]);

            if (pt2dCtr == pt2d) {
                acutPrintf("\nPick a point different from the center.");
                return;
            }
            m_pPoly->put_StartPoint(*pt2d.asVariantPtr());
        }
    } else if (!m_pPolyCmd->GotTextString()) {
        if ((m_retval = acedGetString(Adesk::kTrue,
            "\nEnter polygon name: ",tmpBuf)) == RTNORM)
        {
            m_pPoly->put_TextString(_bstr_t(tmpBuf));
        }
    } else if (!m_pPolyCmd->GotTextStyleName()) {
        if ((m_retval = acedGetString(Adesk::kTrue,
            "\nEnter text style: ", tmpBuf)) == RTNORM)
        {
            AcDbObjectId tsId;
            if (tmpBuf[0] == '\0' ) {
                // Get default text style
                struct resbuf result ;
                if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
                    acutPrintf(
                "\nError while reading default AutoCAD text style setting");
                    fail();
                    return;
                }
                strcpy (tmpBuf, result.resval.rstring) ;
                acdbFree (result.resval.rstring) ;
            }
            if ( rx_getTextStyleId(tmpBuf, 
                     acdbHostApplicationServices()->workingDatabase(), 
                     tsId) != Acad::eOk)
            {
                acutPrintf("\nInvalid text style name");
                fail();
                return;
            }
            m_pPoly->put_TextStyleName(_bstr_t(tmpBuf));
        }
    } else
        m_bDone = true;
    if (m_retval != RTNORM && m_retval != RTMODELESS)
        fail();
}
Exemplo n.º 17
0
// Invoked by the command - DRAGPOLY
//
void 
dragPolyCommand()
{
    int nSides = 0;
    
    ads_point center, startPt, normal;
    
    if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM)
        return;
    
    char nameBuf[133];
    if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM)
        return;
    
    AcDbObjectId tsId = 0;
    char styleBuf[133], msg[133];
	// Get default text style
	struct resbuf result ;
	if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
		acutPrintf("\nError while reading default AutoCAD text style setting");
		return ;
	}
	strcpy (styleBuf, result.resval.rstring) ;
	sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ;
	acdbFree (result.resval.rstring) ;

    if (acedGetString(Adesk::kTrue, msg, styleBuf) != RTNORM)
        return;
    
    if ( styleBuf[0] == '\0' ) {
		// Get default text style
		struct resbuf result ;
		if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
			acutPrintf("\nError while reading default AutoCAD text style setting");
			return ;
		}
		strcpy (styleBuf, result.resval.rstring) ;
		acdbFree (result.resval.rstring) ;
	}

    if ( rx_getTextStyleId(styleBuf, 
                             acdbHostApplicationServices()->workingDatabase(), 
                             tsId) != Acad::eOk)
    {
        acutPrintf("\nInvalid text style name");
        return;
    }
    
    
    // Set the normal to the plane of the polygon to be the same as the
    // z direction of the current ucs, i.e. (0, 0, 1) since we also got the
    // center and start point in the current UCS. (acedGetPoint() returns in
    // the current UCS.)
    
    normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0;

    acdbUcs2Wcs(normal, normal, Adesk::kTrue);
    acdbUcs2Ecs(center, center, normal, Adesk::kFalse);
    acdbUcs2Ecs(startPt, startPt, normal, Adesk::kFalse);
    double elev = center[2];
    AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt);
    AcGeVector3d norm = asVec3d(normal);
    
    AsdkPolyJig* pJig = new AsdkPolyJig();
    pJig->acquire(cen, norm, nameBuf, tsId, elev);
    
    delete pJig;
}
Exemplo n.º 18
0
void LSS06()
{
	CLogger::Print(_T("-------------| START LOGGING LESSONS 06 |--------------"));

	//------------
	// Get the current DENKI project pointer, and number of files of project.
	if (!DenkiIsOpenProject()) {
		acutPrintf(ACRX_T("Denki project has not been opened yet!"));
		return;
	}

	ACHAR szMsg[256] = ACRX_T("\0");
	DenkiDwgProject* pCurProj = DenkiDwgProject::getCurrent();
	int nFileCount = pCurProj->count();
	if (nFileCount < 1) {
		CLogger::Print(_T("*Exit: There is no file within current project!"));
		return;
	}

	//------------
	// Get the 'Duplication Check Level' option of DENKI project.
	DenkiDuplicationCheckLevel CheckLvl = DenkiGetDuplicationCheckLevel(_T("NAME"));
	bool bChkInstNo = (CheckLvl == dclAsInstNumber) ? true : false;
	bool bChkBanNo = (CheckLvl == dclAsBanNumber) ? true : false;

	if (bChkInstNo) {
		bChkBanNo = true;
	}

	CLogger::Print(_T("> INS_NO: %s - BAN_NO: %s")
		, (bChkInstNo ? _T("Checked") : _T("Unchecked"))
		, (bChkBanNo ? _T("Checked") : _T("Unchecked")));

	//------------
	// Require to input BAN_NO, INST_NO, NAME keywords to search.
	ACHAR szNeedBanNo[256] = ACRX_T("\0");
	ACHAR szNeedInstNo[256] = ACRX_T("\0");
	ACHAR szNeedName[256] = ACRX_T("\0");

	if (bChkBanNo) {
		::LoadString(_hdllInstance, IDS_ASK_BANNO, szMsg, sizeof(szMsg)/sizeof(ACHAR));
		if (RTNORM != acedGetString(1, szMsg, szNeedBanNo)) {
			CLogger::Print(_T("*Exit: Fail to get the BAN_NO keyword."));
			return;
		}
	}

	if (bChkInstNo) {
		::LoadString(_hdllInstance, IDS_ASK_INSTNO, szMsg, sizeof(szMsg)/sizeof(ACHAR));
		if (RTNORM != acedGetString(1, szMsg, szNeedInstNo)) {
			CLogger::Print(_T("*Exit: Fail to get the INST_NO keyword."));
			return;
		}
	}

	::LoadString(_hdllInstance, IDS_ASK_NAME, szMsg, sizeof(szMsg)/sizeof(ACHAR));
	if (RTNORM != acedGetString(1, szMsg, szNeedName)) {
		CLogger::Print(_T("*Exit: Fail to get the NAME keyword."));
		return;
	}

	//------------
	// Steps through DENKI project's files.
	for (int nIndex = 0; nIndex < nFileCount; nIndex++) {
		CLogger::Print(_T("---- Index = %d ----"), nIndex);
		DenkiDwgProjectFile& file = pCurProj->getDwgAt(nIndex);
		if (!file.hasZuwaku()) {
			CLogger::Print(_T("Warn: File has not ZUWAKU. > Ignore"));
			continue;
		}

		// Get file path, and file name
		LPCASTR pszFileName = NULL;
		file.getFilePath(pszFileName);
		CLogger::Print(_T("> %s"), pszFileName);

		// Check whether or not file has got DENKI_ZUWAKU.
		DWORD dwFlags = 0;
		if (!file.getZuwakuFlags(dwFlags)) {
			CLogger::Print(_T("Warn: Fail to get the ZUWAKU flags > Ignore"));
			continue;
		}
		if (!(dwFlags & DENKI_ZUWAKU)) {
			CLogger::Print(_T("Warn: File has not DENKI_ZUWAKU. > Ignore"));
			continue;
		}

		// Get the current working database (Just to store).
		AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase();

		Acad::ErrorStatus esResult;
		AcApDocument* pDoc = NULL;
		AcDbDatabase* pDb = NULL;
		bool bFromProject = false;
		bool bReadMyseft = false;

		// Look up the required database from managed documents.
		if (pDoc = findDocument(pszFileName)) {
			CLogger::Print(_T("Inform: found out the database from managed documents."));
			pDb = pDoc->database();
		}

		if (!pDb) {
			// Look up the required database from current opening DENKI project!
			if (!DCMG::IsCacheRunning()) {
				CLogger::Print(_T("Inform: cache is not running > try to get database object."));
				if (pDb = DenkiGetProjectAcDbDatabase(pszFileName)) {
					CLogger::Print(_T("Inform: Database is got from DENKI project."));
				}
			}

			if (!pDb && DCMG::IsCacheRunning()) {
				CLogger::Print(_T("Inform: cache is running > try to open DWG file into DENKI project."));
				if (pDb = DenkiOpenProjectAcDbDatabase(pszFileName)) {
					CLogger::Print(_T("Inform: DWG file is opened into DENKI project. (Need to close it)"));
					bFromProject = true;
				}
			}

			// Open DWG file into an empty database object!
			if (!pDb) {
				pDb = new AcDbDatabase(false, true);
				esResult = pDb->readDwgFile(pszFileName, _SH_DENYNO);
				if (Acad::eOk == esResult) {
					CLogger::Print(_T("Inform: DWG file has been opened into an empty database object! (Need to delete it)"));
					bReadMyseft = true;
				} else {
					delete pDb;
					pDb = NULL;
				}
			}

			if (!pDb) {
				CLogger::Print(_T("Warn: Cannot open dwg file name: '%s' > Ignore"), pszFileName);
				acutPrintf(ACRX_T("Cannot open dwg file name: %s"), pszFileName);
				acdbHostApplicationServices()->setWorkingDatabase(pCurDb);
				continue;
			}
		}

		//------------
		// We have got the database pointer now!
		// Get all of its BlockReferences. Then steps through them.
		AcDbObjectIdArray idaAll;
		int nBlkRefCount = getBlockRefAll(pDb, idaAll);

		CLogger::Print(_T("Inform: Browse all of file's block reference! - Number: %d"), nBlkRefCount);
		for (int nIdx = 0; nIdx < nBlkRefCount; nIdx++) {

			// Get the BlockReference's information!
			DenkiSymbolSnapshot dss;
			if (!dss.open(idaAll[nIdx], ACRX_T("NAME, NAME#*, BAN_NO, INST_NO"))) {
				CLogger::Print(_T("Warn: Fail to open DenkSymbolSnapshot object. > Ignore"));
				continue;
			}

			LPASTR pszBanNo = NULL, pszInstNo = NULL, pszName = NULL;

			// Compare BlockReference's information with the required Keywords.
			switch (1)
			{
			case 1:
				if (bChkBanNo) {
					if (!dss.getBanNo(pszBanNo)) {
						CLogger::Print(_T("Warn: %d. Fail to get BAN_NO value!"), nIdx);
						break;
					}
					if (!acutWcMatchEx(pszBanNo, szNeedBanNo, true)) {
						break;
					}
				}

				if (bChkInstNo) {
					if (!dss.getInstNo(pszInstNo)) {
						CLogger::Print(_T("Warn: %d. Fail to get INST_NO value!"), nIdx);
						break;
					}
					if (!acutWcMatchEx(pszInstNo, szNeedInstNo, true)) {
						break;
					}
				}

				if (!dss.getExpandedValue(ACRX_T("NAME"), pszName)) {
					CLogger::Print(_T("Warn: %d. Fail to get NAME value!"), nIdx);
					break;
				}
				if (!acutWcMatchEx(pszName, szNeedName, true)) {
					break;
				}

			default: // Found out the match BlockReference.
				acutPrintf(ACRX_T("Found out %d. NAME = '%s', BAN_NO = '%s', INST_NO = '%s'")
					, nIdx, szNeedName, (bChkBanNo ? szNeedBanNo : L""), (bChkInstNo ? szNeedInstNo : L""));
				CLogger::Print(_T("Inform: Found out %d. NAME = '%s', BAN_NO = '%s', INST_NO = '%s'")
					, nIdx, szNeedName, (bChkBanNo ? szNeedBanNo : L""), (bChkInstNo ? szNeedInstNo : L""));
			}

			// Release BlockReference's information.
			if (pszBanNo)
				dss.freeString(pszBanNo);
			if (pszInstNo)
				dss.freeString(pszInstNo);
			if (pszName)
				dss.freeString(pszName);
			dss.close();
		}

		// Free memory to exit.
		if (bReadMyseft) {
			CLogger::Print(_T("Inform: DWG file has been opened into an empty database object!"));
			delete pDb;
		}
		if (bFromProject) {
			CLogger::Print(_T("Inform: DWG file has been opened into an DENKI project!"));
			DenkiCloseProjectAcDbDatabase(pDb);
		}

		acdbHostApplicationServices()->setWorkingDatabase(pCurDb);
		CLogger::Print(_T("*EXit"));
	}
}
Exemplo n.º 19
0
// Invoked by the command - POLY
//
void 
polyCommand()
{
    int nSides = 0;
    
    while (nSides < 3) {
        
        acedInitGet(INP_NNEG, "");
        switch (acedGetInt("\nEnter number of sides: ", &nSides)) {
            
        case RTNORM:
            if (nSides < 3)
                acutPrintf("\nNeed at least 3 sides.");
            break;
        default:
            return;
        }
    }
    
    ads_point center, startPt, normal;
    
    if (acedGetPoint(NULL, "\nLocate center of polygon: ", center) != RTNORM)
        return;
    
    startPt[0] = center[0]; startPt[1] = center[1]; startPt[2] = center[2];
    while (asPnt3d(startPt) == asPnt3d(center)) {
        switch (acedGetPoint(center, "\nLocate start point of polygon: ", 
            startPt)) {
        case RTNORM:
            if (asPnt3d(center) == asPnt3d(startPt))
                acutPrintf("\nPick a point different from the center.");
            break;
        default:
            return;
        }
    }
    
    char nameBuf[133];
    if (acedGetString(Adesk::kTrue, "\nEnter polygon name: ", nameBuf) != RTNORM)
        return;
    
    AcDbObjectId tsId = 0;
    char styleBuf[133], msg[133];
	// Get default text style
	struct resbuf result ;
	if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
		acutPrintf("\nError while reading default AutoCAD text style setting");
		return ;
	}
	strcpy (styleBuf, result.resval.rstring) ;
	sprintf (msg, "\nEnter text style <%s>: ", result.resval.rstring) ;
	acdbFree (result.resval.rstring) ;

    if (acedGetString(Adesk::kTrue, "\nEnter text style: ", styleBuf) != RTNORM)
        return;
    
    if ( styleBuf[0] == '\0' ) {
		// Get default text style
		struct resbuf result ;
		if ( acedGetVar ("TEXTSTYLE", &result) != RTNORM ) {
			acutPrintf("\nError while reading default AutoCAD text style setting");
			return ;
		}
		strcpy (styleBuf, result.resval.rstring) ;
		acdbFree (result.resval.rstring) ;
	}

    if ( rx_getTextStyleId(styleBuf, 
                         acdbHostApplicationServices()->workingDatabase(), 
                         tsId) != Acad::eOk)
	{
		acutPrintf("\nInvalid text style name");
		return;
	}
    
    
    // Set the normal to the plane of the polygon to be the same as the
    // z direction of the current ucs, i.e. (0, 0, 1) since we also got the
    // center and start point in the current UCS. (acedGetPoint() returns in
    // the current UCS.)
    
    normal[X] = 0.0; normal[Y] = 0.0; normal[Z] = 1.0;

    acdbUcs2Wcs(normal, normal, Adesk::kTrue);    
    acdbUcs2Ecs(center, center,normal, Adesk::kFalse);
    acdbUcs2Ecs(startPt, startPt,normal, Adesk::kFalse);
    double elev = center[2];
    AcGePoint2d cen = asPnt2d(center), start = asPnt2d(startPt);
    AcGeVector3d norm = asVec3d(normal);
    
    AsdkPoly* poly = new AsdkPoly;
    if (poly==NULL){
        acutPrintf("\nOut of memory.");
        return;
    }
    
    if (poly->set(cen, start, nSides, norm, nameBuf, tsId, elev)!=Acad::eOk){
        delete poly;
        acutPrintf("\nCannot create AsdkPoly with given parameters.");
        return;
    }
    
    poly->setDatabaseDefaults(acdbHostApplicationServices()->workingDatabase());
    postToDb(poly);
}
Exemplo n.º 20
0
// The printList() function takes a linked list of resbufs 
// as an argument.  Walks the list printing out the restypes 
// and resval values one set per line.
// 
void
printList(struct resbuf* pBuf)
{
    int rt, i;
    char buf[133];

    for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext) {
        if (pBuf->restype < 0)
            rt = pBuf->restype;
        else if (pBuf->restype < 10)
            rt = RTSTR;
        else if (pBuf->restype < 38)
            rt = RT3DPOINT;
        else if (pBuf->restype < 60)
            rt = RTREAL;
        else if (pBuf->restype < 80)
            rt = RTSHORT;
        else if (pBuf->restype < 100)
            rt = RTLONG;
        else if (pBuf->restype < 106)
            rt = RTSTR;
        else if (pBuf->restype < 148)
            rt = RTREAL;
        else if (pBuf->restype < 290)
            rt = RTSHORT;
        else if (pBuf->restype < 330)
            rt = RTSTR;
        else if (pBuf->restype < 370)
            rt = RTENAME;
        else if (pBuf->restype < 999)
            rt = RT3DPOINT;
        else
            rt = pBuf->restype;

        switch (rt) {
        case RTSHORT:
            if (pBuf->restype == RTSHORT)
                acutPrintf("RTSHORT : %d\n",
                    pBuf->resval.rint);
            else
                acutPrintf("(%d . %d)\n", pBuf->restype,
                    pBuf->resval.rint);
            break;
        case RTREAL:
            if (pBuf->restype == RTREAL)
                acutPrintf("RTREAL : %0.3f\n",
                    pBuf->resval.rreal);
            else
                acutPrintf("(%d . %0.3f)\n", pBuf->restype,
                    pBuf->resval.rreal);
            break;
        case RTSTR:
            if (pBuf->restype == RTSTR)
                acutPrintf("RTSTR : %s\n",
                   pBuf->resval.rstring);
            else
                acutPrintf("(%d . \"%s\")\n", pBuf->restype,
                    pBuf->resval.rstring);
            break;
        case RT3DPOINT:
            if (pBuf->restype == RT3DPOINT)
                acutPrintf(
                    "RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
                    pBuf->resval.rpoint[X],
                    pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            else
                acutPrintf(
                   "(%d %0.3f %0.3f %0.3f)\n",
                    pBuf->restype,
                    pBuf->resval.rpoint[X],
                    pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            break;
        case RTLONG:
            acutPrintf("RTLONG : %dl\n",
                pBuf->resval.rlong);
            break;
        case -1:
        case RTENAME:
            acutPrintf("(%d . <Entity name: %8lx>)\n",
                pBuf->restype, pBuf->resval.rlname[0]);
            break;
        case -3:
            acutPrintf("(-3)\n");
        }

        if ((i == 23) && (pBuf->rbnext != NULL)) {
            i = 0;
            acedGetString(0,
                "Press <ENTER> to continue...", buf);
        }
    }
    return;
}
Exemplo n.º 21
0
void
refEditApiExample()
{

    AcDbObjectId transId;
    AcDbDatabase* pDb;
    char *fname;
    struct resbuf *rb;

    // Get a dwg file from the user.
    //
    rb = acutNewRb(RTSTR);
    int stat = acedGetFileD("Pick a drawing", NULL, "dwg", 0, rb);
    
    if ((stat != RTNORM) || (rb == NULL)) {
        acutPrintf("\nYou must pick a drawing file.");
        return;
    }

    fname = (char*)acad_malloc(strlen(rb->resval.rstring) + 1);
    strcpy(fname, rb->resval.rstring);
    acutRelRb(rb);
    
    // Open the dwg file.
    //
    pDb = new AcDbDatabase(Adesk::kFalse);
    if (pDb->readDwgFile(fname) != Acad::eOk) {
        acutPrintf("\nSorry, that draing is probably already open.");
        return;
    }

    // Get the Block Table and then the model space record.
    //
    AcDbBlockTable *pBlockTable;
    pDb->getSymbolTable(pBlockTable, AcDb::kForRead);
    AcDbBlockTableRecord *pOtherMsBtr;
    pBlockTable->getAt(ACDB_MODEL_SPACE, pOtherMsBtr, AcDb::kForRead);
    pBlockTable->close();

    // Create an iterator.
    //
    AcDbBlockTableRecordIterator *pIter;
    pOtherMsBtr->newIterator(pIter);

    // Set up an object ID array.
    //
    AcDbObjectIdArray objIdArray;

    // Iterate over the model space BTR. Look specifically 
    // for lines and append their object ID to the array.
    //
    for (pIter->start(); !pIter->done(); pIter->step()) {
        AcDbEntity *pEntity;
        pIter->getEntity(pEntity, AcDb::kForRead);

        // Look for only AcDbLine objects and add them to the 
        // object ID array.
        //
        if (pEntity->isKindOf(AcDbLine::desc())) {
            objIdArray.append(pEntity->objectId());
        }
        pEntity->close();
    }
    delete pIter;
    pOtherMsBtr->close();

    if (objIdArray.isEmpty()) {
        acad_free(fname);
        acutPrintf("\nYou must pick a drawing file that contains lines.");
        return;
    }

    // Now get the current database and the object ID for the
    // current database's model space BTR.
    //
    AcDbBlockTable *pThisBlockTable;
    acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pThisBlockTable, AcDb::kForRead);

    AcDbBlockTableRecord *pThisMsBtr;
    pThisBlockTable->getAt(ACDB_MODEL_SPACE, pThisMsBtr, AcDb::kForWrite);
    pThisBlockTable->close();
    
    AcDbObjectId id = pThisMsBtr->objectId();
    pThisMsBtr->close();


    // Create the long transaction. This will check all the entities 
    // out of the external database.
    //
    AcDbIdMapping errorMap;
    acapLongTransactionManagerPtr()->checkOut(transId, objIdArray, id, errorMap);

    // Now modify the color of these entities.
    //
    int colorIndex;
    acedGetInt("\nEnter color number to change entities to: ", &colorIndex);
    AcDbObject* pObj;
    if (acdbOpenObject(pObj, transId, AcDb::kForRead) == Acad::eOk) {

        // Get a pointer to the transaction.
        //
        AcDbLongTransaction* pLongTrans = AcDbLongTransaction::cast(pObj);
        if (pLongTrans != NULL) {

            // Get a work set iterator.
            //
            AcDbLongTransWorkSetIterator* pWorkSetIter;
            pLongTrans->newWorkSetIterator(pWorkSetIter);

            // Iterate over the entities in the work set and change the color.
            //
            for (pWorkSetIter->start(); !pWorkSetIter->done(); pWorkSetIter->step()) {
                AcDbEntity *pEntity;
                acdbOpenAcDbEntity(pEntity, pWorkSetIter->objectId(), AcDb::kForWrite);
                pEntity->setColorIndex(colorIndex);
                pEntity->close();
            }
            delete pWorkSetIter;
        }
        pObj->close();
    }

    // Pause to see the change.
    //
    char str[132];
    acedGetString(0, "\nSee the new colors. Press return to check the object into the original database", str);

    // Check the entities back in to the original database.
    //
    acapLongTransactionManagerPtr()->checkIn(transId, errorMap);

    // Save the original database, since we have made changes.
    //
    pDb->saveAs(fname);

    // Close/Delete the database
    //
    delete pDb;
    pDb = NULL;

    acad_free(fname);
}
Exemplo n.º 22
0
// accepts a list of resbufs and prints out the values they contain
//
int
printList(struct resbuf* pBuf)
{
    int rt, i;
    char buf[133];     // should only need 1 byte for <return>, but
                       // play it safe since ads_getstring can accept
                       // up to 132 characters

    for (i = 0;pBuf != NULL;i++, pBuf = pBuf->rbnext)
    {
        if (pBuf->restype < 0)
            rt = pBuf->restype;           // Entity name (or other sentinel)
        else if (pBuf->restype < 10)
            rt = RTSTR;
        else if (pBuf->restype < 38)
            rt = RT3DPOINT;
        else if (pBuf->restype < 60)
            rt = RTREAL;
        else if (pBuf->restype < 80)
            rt = RTSHORT;
        else if (pBuf->restype < 100)
            rt = RTLONG;
        else if (pBuf->restype < 106)
            rt = RTSTR;
        else if (pBuf->restype < 148)
            rt = RTREAL;
        else if (pBuf->restype < 290)
            rt = RTSHORT;
        else if (pBuf->restype < 320)
            rt = RTSTR;
        else if (pBuf->restype < 370)
            rt = RTENAME;
        else if (pBuf->restype < 999)
            rt = RT3DPOINT;
        else                       // pBuf->restype is already RTSHORT, RTSTR,
            rt = pBuf->restype;      // etc. or else it is unknown.

        switch (rt) {
        case RTSHORT:
            if (pBuf->restype == RTSHORT)
                acutPrintf("RTSHORT : %d\n", pBuf->resval.rint);
            else
                acutPrintf("(%d . %d)\n", pBuf->restype, pBuf->resval.rint);
            break;
        case RTREAL:
            if (pBuf->restype == RTREAL)
                acutPrintf("RTREAL : %0.3f\n", pBuf->resval.rreal);
            else
                acutPrintf("(%d . %0.3f)\n", pBuf->restype, pBuf->resval.rreal);
            break;
        case RTSTR:
            if (pBuf->restype == RTSTR)
                acutPrintf("RTSTR : %s\n", pBuf->resval.rstring);
            else
                acutPrintf("(%d . \"%s\")\n", pBuf->restype, pBuf->resval.rstring);
            break;
        case RT3DPOINT:
            if (pBuf->restype == RT3DPOINT)
                acutPrintf("RT3DPOINT : %0.3f, %0.3f, %0.3f\n",
                pBuf->resval.rpoint[X],  pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            else
                acutPrintf("(%d %0.3f %0.3f %0.3f)\n", pBuf->restype,
                    pBuf->resval.rpoint[X], pBuf->resval.rpoint[Y],
                    pBuf->resval.rpoint[Z]);
            break;
        case RTLONG:
            acutPrintf("RTLONG : %dl\n", pBuf->resval.rlong);
            break;
        case -1:
        case RTENAME:                          // First block entity
            acutPrintf("(%d . <Entity name: %8lx>)\n", pBuf->restype,
                pBuf->resval.rlname[0]);
            break;
        case -3:                              // marks start of xdata
            acutPrintf("(-3)\n");
        }

        if ((i == 23) && (pBuf->rbnext != NULL)) {
            i = 0;
            acedGetString(0,"Press <ENTER> to continue...", buf);
        }
    }
    return RTNORM;
}
Exemplo n.º 23
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));
    }
}