Example #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;
}
Example #2
0
// cmdcount_findfile: return int representing whether file was found (RTNORM)
//                    or not. Looks in the directory where .cfg/.ini files
//                    live. If it doesn't find the file there, it looks along
//                    the AutoCAD search path, according to acedFindFile().
int cmdcount_findfile (const char *fname, char *result)
{
	char statFilePath[MAX_PATH_LENGTH];
#ifdef OEM 
    // OEM doesn't support environment the "ACADCFG" env. variable. So, we'll look
    // in the exedir instead
    resbuf tmpResult;
	
    if (acedGetVar(/*NOXLATE*/"EXEDIR", &tmpResult) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    strcpy(statFilePath, tmpResult.resval.rstring);
#else 
	if (acedGetEnv(/*NOXLATE*/"ACADCFG", statFilePath) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
#endif  
    if (statFilePath[strlen(statFilePath) - 1] != '\\') 
		strcat(statFilePath, "\\");
	strcat(statFilePath, fname);
	if (fopen(statFilePath, /*NOXLATE*/"r") != NULL) {
		strcpy(result, statFilePath);
		return RTNORM;
	}
	else 
		return acedFindFile(fname, result);
}
Example #3
0
Adesk::Boolean
addMatchPoly()
{
    AcRxObject *pTemp;

    if (pTemp = acrxServiceDictionary->at("MatchProperties"))
    {
        acutPrintf ("MatchProperties is now available.\n"
                    "Now adding match prop protocol extension to AsdkPoly.\n");
        acedPostCommandPrompt();


        AcRxService *pSvc = AcRxService::cast(pTemp);

        if (pSvc == NULL)
            // something's terribly wrong so abort
            acrx_abort("\nProblem with service dictionary\n");

        // now to add the dependency to match.arx
        pSvc->addDependency();

        pMatchPoly = new AsdkPolyMatchProp;
        AsdkPoly::desc()->addX(AcDbMatchProperties::desc(), pMatchPoly);

        AppEventCatcher::thisAppLoaded = 1;

        return Adesk::kTrue;
    }

    return Adesk::kFalse;
}
Example #4
0
// GETcURtIME:  return double representing Julian Date, values of which
//              may be directly subtracted for elapsed time measurement.
double getCurTime()
{
    resbuf currentTime;

    if (acedGetVar(/*NOXLATE*/"DATE", &currentTime) != RTNORM) {
        // This should never happen.
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    return currentTime.resval.rreal;
}
Example #5
0
void printCurrentDateTime(FILE* statFile)
{
    resbuf tempRes;
    int jtd_day;
    double jtd_msec;
    int ctd_year, ctd_month, ctd_day, ctd_hour, ctd_minute, ctd_second;
    double rem;
    long t, j, y, d;

    // Get Julian date and convert it to calendar time and date
    // As in Calendar Time and Date, in case you were wondering what
    // the "ctd_" prefix used pervasively in this routine stands for.
    if (acedGetVar(/*NOXLATE*/"DATE", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 2",
                    PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    jtd_day = (int)tempRes.resval.rreal;
    jtd_msec = tempRes.resval.rreal - (int)tempRes.resval.rreal;
    j = jtd_day - 1721119L;
    t = 4 * j - 1;
    y = t / 146097L;
    j = t - 146097L * y;
    d = j / 4;
    j = (4 * d + 3) / 1461;
    d = (4 * d - 1461L * j + 7) / 4;
    ctd_month = (5 * d - 3) / 153;
    ctd_day = ((5 * d) - 3 - 153 * ctd_month + 5) / 5;
    ctd_year = (short)((100 * y) + j);
    if (ctd_month >= 10) {
        ctd_month -= 9;
        ctd_year++;
    } else
        ctd_month += 3;

    ctd_hour = (short)(jtd_msec * 24);
    rem = (jtd_msec * 24) - ctd_hour;
    ctd_minute = (short)(rem * 60);
    rem = (rem * 60) - ctd_minute;
    ctd_second = (short)(rem * 60);
    
    // print current date and time
    fprintf(statFile, "%0*d/%0*d/%0*d %0*d:%0*d:%0*d", 
            2, ctd_month,
            2, ctd_day,
            4, ctd_year,
            2, ctd_hour,
            2, ctd_minute,
            2, ctd_second);
}
static void
addAsdkShellSampObject()
{
    Acad::ErrorStatus es;
    AcDbBlockTable   *pBlockTable;
    es = acdbHostApplicationServices()->workingDatabase()
        ->getSymbolTable(pBlockTable, AcDb::kForRead);
    if (es != Acad::eOk)
        return;

    AcDbBlockTableRecord *pBlock;
    es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlock,
        AcDb::kForWrite);
    if (es != Acad::eOk)
        return;

    AcDbObjectId  objId;
    AsdkShellSamp *pNewObj = new AsdkShellSamp;
    es = pBlock->appendAcDbEntity(objId, pNewObj);
    if (es != Acad::eOk) {
        delete pNewObj;
        return;
    }

    es = pBlock->close();
    if (es != Acad::eOk)
        acrx_abort(_T("\nUnable to close block table record"));

    es = pBlockTable->close();
    if (es != Acad::eOk) 
        acrx_abort(_T("\nUnable to close block table"));

    es = pNewObj->close();
    if (es != Acad::eOk) 
        acrx_abort(_T("\nUnable to close new entity"));
}
Example #7
0
// cmdcount_findfile: Searches for the stat file as follows:
// 1. Searches the location of StatPath. 
// 2. If this key is not present it searches MyDocuments
// 3. It searches the AutoCAD search path.
// Note that MyDocuments and StatPath are mutually exclusive.
int cmdcount_findfile (const TCHAR *fname, TCHAR *result, bool returnDefault)
{
    TCHAR statFilePath[MAX_PATH_LENGTH] = "\0";
    TCHAR buf[512];
    _tcscpy(buf,acrxProductKey());
    _tcscat(buf,/*NOXLATE*/_T("\\Applications\\AcadCmdCount"));
    HKEY hKey;
    if (ERROR_SUCCESS==RegOpenKeyEx(HKEY_CURRENT_USER,buf,0,KEY_QUERY_VALUE,&hKey))
    {
        DWORD dwType = 0;
        DWORD dwDataSize = sizeof(buf);
        if (ERROR_SUCCESS == RegQueryValueEx(hKey, _T(/*MSG0*/"StatPath"), NULL, &dwType, (LPBYTE)buf, &dwDataSize))
        {
            _tcscpy(statFilePath,buf);
        }
        RegCloseKey(hKey);
    }
    if (statFilePath[0]==0)
    {
        resbuf rb;
        if (acedGetVar(/*NOXLATE*/"MYDOCUMENTSPREFIX", &rb) != RTNORM) {
            sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                    PRODUCTL, getProductName());
            acrx_abort(abort_msg);
        }
        _tcscpy(statFilePath,rb.resval.rstring);
        acdbFree(rb.resval.rstring);
    }
    if (statFilePath[strlen(statFilePath) - 1] != '\\') 
        strcat(statFilePath, "\\");
    strcat(statFilePath, fname);
    FILE* f;
    if ((f = fopen(statFilePath, /*NOXLATE*/"r")) != NULL) {
        fclose(f);
        strcpy(result, statFilePath);
        return RTNORM;
    }
    else 
    {
        int ret = acedFindFile(fname, result);
        if (ret!=RTNORM && returnDefault)
        {
            ret= RTNORM;
            strcpy(result,statFilePath);
        }
        return ret;
    }
}
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;

}
Example #9
0
Adesk::Boolean updateCumulativeStats()
{
    // If anything is going on in any document, now is NOT a good
    // time to accumulate stats, because each command/LISP expression
    // in progress has pointers into session stats.
    // This could be fixed with more recoding than I have time to do
    // now.  WCA 7/15/98
    for (int i = docData.length() - 1; i >= 0; i--) {
        // Make sure our info is up to date.
        if (docData[i].doc == curDocGlobals.doc)
            docData[i] = curDocGlobals;
        if ((docData[i].cmdIndex > 0) ||
            (docData[i].lispRcd != NULL))
            return Adesk::kFalse;
    }

    if (!readCumulativeStats()) {
        acutPrintf("\nWarning: Could not find Command Statistics file.\n");
        acutPrintf("Will try to create it.\n");
    }

    AcRxDictionaryIterator* iter;

    // Loop over current session stats, and merge them into cumulative stats.
    for (iter = sessionStats->newIterator(); !iter->done(); iter->next()) {
        AsdkCommandRecord* sessionCmdRcd = (AsdkCommandRecord*) iter->object();
        AsdkCommandRecord* cumulativeCmdRcd = (AsdkCommandRecord*)
                                          cumulativeStats->at(iter->key());
        if (!cumulativeCmdRcd)
            // First time, add it.
            cumulativeStats->atPut(iter->key(),
                                   new AsdkCommandRecord(sessionCmdRcd->count,
                                                     sessionCmdRcd->elapsedTime));
        else {
            // Not the first time, so bump it.
            cumulativeCmdRcd->count += sessionCmdRcd->count;
            cumulativeCmdRcd->elapsedTime += sessionCmdRcd->elapsedTime;
        }
    }

    delete iter;

    // Now that it has been added in, wipe out the current session Stats;
    delete sessionStats;
    sessionStats = initStatDictionary();

    // Open the cumulative stat file, creating it if necessary.
    char statFilePath[MAX_PATH_LENGTH];
    
    int ret = cmdcount_findfile(statFileName, statFilePath,true);
    assert(ret==RTNORM);//this should always succeed

    // Open the file
    FILE* statFile = fopen(statFilePath, /*NOXLATE*/"w");

    if (statFile == NULL) {
        // Bad permission in our chosen directory.  Give up.
        acedAlert("Warning: Could not create Command Statistics file.");
        return Adesk::kTrue;
    }

    // Print version number of STATFILE
    fprintf(statFile, "v%04.1f\n", STAT_FILENAME_VERSION);

    // Print create date of STATFILE
    if (!*createDate) {
        fprintf(statFile, "Created:               ");
        printCurrentDateTime(statFile);
        fprintf(statFile, "\n");
    } else
        fprintf(statFile, "%s\n", createDate);

    // Print date last modified for STATFILE
    fprintf(statFile, "Last Modified:         ");
    printCurrentDateTime(statFile);
    fprintf(statFile, "\n");
    
    resbuf tempRes;
    // Print LOGINNAME
    if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"LOGINNAME:             %s\n", tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;
    // Print ACAD serial number
    if (acedGetVar(/*NOXLATE*/"_PKSER", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"%.*s Serial Number: %s\n", PRODUCTL, getProductName(),
                            tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;

    // Print ACAD version
    if (acedGetVar(/*NOXLATE*/"_VERNUM", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    fprintf(statFile, /*NOXLATE*/"%.*s version:       %s\n", PRODUCTL, getProductName(),
                        tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;


    for (iter = cumulativeStats->newIterator(AcRx::kDictSorted); !iter->done(); iter->next()) {
        // Write out the command string.
        fprintf(statFile, "%s", iter->key());

        // Try for reasonable text alignment, such as allowing 24 chars
        // for the command name.  But have at least 1 space as a delimiter.
        int nbrOfSpaces = 24 - strlen(iter->key());
        do
            fprintf(statFile, " ");
        while (--nbrOfSpaces > 0);

        // Now the count and elapsed time in seconds (assume 1 billion seconds
        // maximum, which should exceed a typical beta survey period).
        fprintf(statFile, "%7i   %12.2f\n",
                ((AsdkCommandRecord*) iter->object())->count,
                ((AsdkCommandRecord*) iter->object())->elapsedTime);
    }

    fclose(statFile);

    delete iter;
    return Adesk::kTrue;
}
Example #10
0
// commandStats:  Print out current Session and Cumulative Stats
void initStats()
{
    cmdr   = new AsdkCommandReactor();
    statFileName[0] = EOS;

    // Define dictionary to delete all its entries when it is deleted.
    sessionStats = initStatDictionary();
    acedEditor->addReactor(cmdr);
    acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS",
                            /*NOXLATE*/"ASDK_CMDSTAT",
                            "CMDSTAT",
                            ACRX_CMD_MODAL,
                            &commandStats);
    acedRegCmds->addCommand(/*NOXLATE*/"ASDK_COMMAND_STATS",
                            /*NOXLATE*/"ASDK_CMDCOUNT",
                            "CMDCOUNT",
                            ACRX_CMD_MODAL,
                            &cmdCommandCount);

    bStatsFileUpdatePending = Adesk::kFalse;

    // Initialize Global struct array
    docData.setLogicalLength(0);

    // Fill array from existing documents
    AcApDocumentIterator* pDocIter = acDocManager->newAcApDocumentIterator();

    for (;!pDocIter->done(); pDocIter->step())
        // add an entry for the document, if some other notification hasn't
        // already done so.
        lookupDoc(pDocIter->document());

    delete pDocIter;

    // Establish current document, if there is one yet.
    if ((docData.length() > 0) && (acDocManager->curDocument() != NULL))
        curDocGlobals = docData[lookupDoc(acDocManager->curDocument())];
    else
        curDocGlobals.doc = NULL;

    pDocReactor = new AsdkDocReactor;
    acDocManager->addReactor(pDocReactor);


    resbuf tempRes;
    int i, j;
    // set the statFileName to be <LOGINNAME>.txt
    // remove blanks and tabs from LOGINNAME, so we have a more 
    // reasonable statFileName.
    if (acedGetVar(/*NOXLATE*/"LOGINNAME", &tempRes) != RTNORM) {
        sprintf(abort_msg, "%.*s Command\nStatistics Gatherer\nFailure 1",
                PRODUCTL, getProductName());
        acrx_abort(abort_msg);
    }
    strcpy(statFileName, tempRes.resval.rstring);
    acdbFree (tempRes.resval.rstring) ;
    for (i = 0, j = 0;
         (statFileName[i] != EOS) && (j < LOGINNAME_LENGTH);
         i++) {
        if ((statFileName[i] != ' ') && (statFileName[i] != '\t')) {
            statFileName[j] = statFileName[i];
            j++;
        }
    }
    statFileName[j] = EOS;
    strcat(statFileName, /*NOXLATE*/".txt");
}