Пример #1
0
void
toggleActivate()
{

    if (getYorN("Enable Multiple Document Activation")) {
		if( !(acDocManager->isDocumentActivationEnabled()) ) {
			Acad::ErrorStatus st = acDocManager->enableDocumentActivation();
			if ( st == Acad::eOk )
				acutPrintf(/*NOXLATE*/"==== Acad::eOk ====\n");
			else if ( st == Acad::eInvalidContext )
				acutPrintf(/*NOXLATE*/" ==== Acad::eInvalidContext ====\n");
			else
				acutPrintf(" ==== I have no clue what's going on.... ====\n");
		} else {
			acutPrintf("*******  Activation is already on.*******\n");
			return;
		}

        acutPrintf("*******  Activation ON.*******\n");
    } else {
        acDocManager->disableDocumentActivation();
        acutPrintf("*******  Activation OFF.*******\n");
    }

}
Пример #2
0
//
//  NAME: watchDocuments        
//
//  REMARKS:  Turn on all reactor notifications
//          
//          
// 
//  RETURNS:
//      void 
void
watchDocuments()
{
    if (getYorN("Start watching Documents")) {
        acDocManager->addReactor(gpDocReactor);
        acedEditor->addReactor(gpEditReactor);
        acutPrintf("  Added reactor to the Document Manager.\n");
    } else {
        acedEditor->removeReactor(gpEditReactor);
        acDocManager->removeReactor(gpDocReactor);
        acutPrintf("  Removed reactor from the Document Manager.\n");
    }
}
Пример #3
0
// Main logic of the threading, file reading and calculation;
// adopts a one-ahead technique where parameters are calculated one time step ahead, before transmitted in the next time step
// calculations are based on information from the file and from information one time step before
int multiDevFileThreading(vector<DXMotorSystem*>& allSys, const string& filename, bool& runFlag, int delayTime)
{
    int numDXSystem = allSys.size();

    queue<vector<int> > allPosInstr;
    getInstructions(allPosInstr, filename);
    vector<vector<int> > allPrevPos, allCalcPos, allGoalPos, allCurrentPos, allPrevFilePos, allCurrentFilePos, allFilePos;
    vector<WriteData> allCalcData, allGoalData;

    int timestep = 0;
    try{
        unsigned int sumMotors = 0;
        vector<unsigned int> allNumMotor;
        for (unsigned int ii = 0; ii < allSys.size(); ii++)
        {
            int numMotors = (*(allSys[ii])).getNumMotors();
            allNumMotor.push_back(numMotors);
            sumMotors += numMotors;
            allCurrentPos.push_back((*(allSys[ii])).getAllPosition());
            WriteData wd;
            wd.setSpeed = false;
            wd.setPID = false;
            wd.setCompliance = false;
            allCalcData.push_back(wd);
        }
        if (allPosInstr.front().size() != sumMotors)
        {
            cout << "Number of columns in instructions does not tally with number of motors. Continue?";
            if(!getYorN())
                return 1;
        }
        allCalcPos = allCurrentPos;
        allFilePos = allCurrentPos;
        allCurrentFilePos = allFilePos;

        while(!allPosInstr.empty() && runFlag)
        {
            allPrevPos = allCurrentPos;
            allGoalPos = allCalcPos;
            allPrevFilePos = allCurrentFilePos;
            allCurrentFilePos = allFilePos;
            allGoalData = allCalcData;

            int idx = 0;
            vector<int> data = allPosInstr.front();
            allPosInstr.pop();
            allPosInstr.push(data);
            for (unsigned int ii = 0; ii < allSys.size(); ii++)
            {
                vector<int> filePos;
                for (unsigned int jj = 0; jj < allNumMotor[ii]; jj++)
                {
                    filePos.push_back(data[idx++]);
                }
                allFilePos[ii] = filePos;
            }

            thread calcThread(multiDevFileCalc, ref(allSys), timestep, ref(allPrevPos), ref(allPrevFilePos), ref(allFilePos), ref(allCalcPos), ref(allCalcData));
            thread fdt[numDXSystem];
            for (int ii = 0; ii < numDXSystem; ii++)
            {
                fdt[ii] = thread(multiDevFileSet,ref(*(allSys[ii])),ref(allGoalPos[ii]),ref(allGoalData[ii]),ref(allCurrentPos[ii]));
            }

            timestepDelay(delayTime);

            calcThread.join();
            for (int ii = 0; ii < numDXSystem; ii++)
            {
                fdt[ii].join();
            }
            timestep++;
        }
    } catch(runtime_error e)
    {
        cout << e.what() << endl;
        cout << "Exit?";
        if (getYorN())
            goto EXITTHREADFN;
    }

    EXITTHREADFN:
    return 0;
}
Пример #4
0
HRESULT 
AsdkSheetSet::create(char* name,		
					 char* path,		
					 char* description,
					 char* templPath,
					 char* defSheetLoc)
{
	BOOL  bAlwaysCreate = TRUE;
	CComBSTR bstrSSName(name);	 // Sheet set name
	HRESULT hr;
	
	// If sheet set manager doesnt exist, create one
	if(!m_pSSetMgr.p)
	{
		if (FAILED(m_pSSetMgr.CoCreateInstance(CLSID_AcSmSheetSetMgr)))
		{
			acutPrintf("\n Error Cannot get sheet set manager!!");	
			return E_FAIL;
		}
	}
	 
	char fullPath[255];
	strcpy(fullPath, path);

	// If no trailing backslash entered, add it
	if (strcmp("\\" , &fullPath[strlen(fullPath)-1]) != 0)
		strcat(fullPath, "\\");

	// check if folder exists
	if(_access(fullPath,0))
	{
		acutPrintf("\n Error: Folder does not exist. Specify another folder!!!");
		return E_FAIL;
	}

	if(!strstr(name,".dst"))
		strcat(name, ".dst");	

	strcat(fullPath, name);
	
	CComBSTR bstrPath(fullPath);
	AcSmLockStatus lockStatus;
	
	// check if file exists 
	// If so, ask the user whether to overwrite or open existing
	if(!_access(fullPath,0))
	{
	   if(!getYorN("\n File exists!! Overwrite existing?"))
	   {
	    	// Don't overwrite existing
			// Just open the file
			// 2nd parameter = FALSE means don't fail if already open
			if(FAILED(m_pSSetMgr->OpenDatabase(bstrPath, FALSE, &m_pDb)))
			{
				acutPrintf("\n Error: Cannot open database!!");
				return E_FAIL;
			}
			
			// get the sheet set from the database.
			if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
			{  
				acutPrintf("\n Error: Cannot get sheet set");
				return E_FAIL;
			}
			
			return E_ABORT;
		}
	}  
	
	// create the database for the sheet set
	// bAlwaysCreate lets you override the existing file if it's set to true
	if (FAILED(hr = m_pSSetMgr->CreateDatabase(bstrPath, NULL, bAlwaysCreate, &m_pDb)))
	{
		acutPrintf("\nError: Cannot create database!");
		if (E_INVALIDARG == hr)
			acutPrintf("\n File name invalid!");		
		return E_FAIL;
	}

	
	 // lock the the database first before doing any operation on it
    if (FAILED(LockDatabase()))
	{
		acutPrintf("\n Error: Database lock failed!");
        return E_FAIL;
	}

	CComBSTR bstrDesc(description);
	
	// set the sheet set db name, description = sheet set name, description
	 if (FAILED(m_pDb->SetName(bstrSSName)))
	 {
		acutPrintf("\n Error: Cannot set database name");
		return E_FAIL;
	 }
	 
	 if (FAILED(m_pDb->SetDesc(bstrDesc)))
	 {
		acutPrintf("\nError: Cannot set database description!");
		return E_FAIL;
	 }
	
	    // get the sheet set from the database.
    if (FAILED(m_pDb->GetSheetSet(&m_pSheetSet)))
	{  
		acutPrintf("\n Error: Cannot get sheet set");
        return E_FAIL;
	}

	// set the name and description to the sheet set
	if (FAILED(m_pSheetSet->SetName(bstrSSName)))
	{
		acutPrintf("\nError: Cannot set name!");
        return E_FAIL;
	}


    if (FAILED(m_pSheetSet->SetDesc(bstrDesc)))
	{
		acutPrintf("\nError: Cannot set description!");
        return E_FAIL;
	}

	if(isValid(templPath))
	{
		// set default template for layout at sheet set level
		overrideDefaultDWTLayout(templPath, m_pSheetSet);
	}

	if(isValid(defSheetLoc))
	{
		// set default sheet location
		setNewSheetLocation(defSheetLoc, m_pSheetSet);
	}

	if (FAILED(UnlockDatabase())) 
	{
		acutPrintf("\n Cannot unlock database");
        return E_FAIL;
	}
    else
		acutPrintf("\n Sheet set %s created", fullPath);
	
	return S_OK;

}
// AsdkEdReactor is derived from AcEditorReactor
//
void
AsdkEdReactor::beginDeepCloneXlation(AcDbIdMapping& idMap,
    Acad::ErrorStatus* es)
{
    if (idMap.deepCloneContext() == AcDb::kDcWblock
        && getYorN(_T("Wblock all Text Styles")))
    {
        AcDbDatabase *pOrigDb, *pDestDb;
        if (idMap.origDb(pOrigDb) != Acad::eOk)
            return;
        *es = idMap.destDb(pDestDb);
        if (*es != Acad::eOk)
            return;

        AcDbTextStyleTable *pTsTable;
        *es = pOrigDb->getSymbolTable(pTsTable,
            AcDb::kForRead);
        if (*es != Acad::eOk)
            return;

        AcDbTextStyleTableIterator *pTsIter;
        *es = pTsTable->newIterator(pTsIter);
        if (*es != Acad::eOk) {
            pTsTable->close();
            return;
        }
        AcDbTextStyleTableRecord *pTsRecord;
        AcDbObject *pClonedObj;
        for (; !pTsIter->done(); pTsIter->step()) {
            *es = pTsIter->getRecord(pTsRecord,
                AcDb::kForRead);
            if (*es != Acad::eOk) {
                delete pTsIter;
                pTsTable->close();
                return;
            }
            // We don't need to check for already cloned
            // Records.  If the Text Style is already
            // cloned, wblockClone will return Acad::eOk
            // and pCloneObj will be NULL.
            //
            pClonedObj = NULL;
            *es = pTsRecord->wblockClone(pDestDb,
                pClonedObj, idMap, Adesk::kFalse);
            if (*es != Acad::eOk) {
                pTsRecord->close();
                delete pTsIter;
                pTsTable->close();
                return;
            }
            *es = pTsRecord->close();
            if (*es != Acad::eOk) {
                delete pTsIter;
                pTsTable->close();
                return;
            }
            if (pClonedObj != NULL) {
                *es = pClonedObj->close();
                if (*es != Acad::eOk) {
                    delete pTsIter;
                    pTsTable->close();
                    return;
                }
            }
        }
        delete pTsIter;
        *es = pTsTable->close();
    }
}