示例#1
0
//
//  NAME: selectDocument        
//
//  REMARKS:  Simple utility to have the user choose an open document to
//            perform some action on.
//          
//          
// 
//  RETURNS:
//      void 
static AcApDocument* selectDocument()
{
    AcApDocument* documentArray[10];

    AcApDocument* pDoc;
    AcApDocumentIterator* pDocIter;
    int nDocs = 0;;

    pDocIter = acDocManager->newAcApDocumentIterator();

    for ( ; !pDocIter->done(); pDocIter->step(), nDocs++) {
        pDoc = pDocIter->document();
        documentArray[nDocs] = pDoc;
        acutPrintf("%d.  %s\n", nDocs + 1, pDoc->fileName());
    }
    delete pDocIter;

    acedInitGet(RSG_NOZERO | RSG_NONEG, NULL);
    int iSelection;
    int inputStatus = acedGetInt("Which document should this command execute in: ", &iSelection);
    if (inputStatus == RTNORM && iSelection <= nDocs) {
        return documentArray[iSelection - 1];
    } else {
        return NULL;
    }
}
示例#2
0
// Notification when a SAVE is complete Typical method to detect when
// a document has been renamed
void 
AsdkEditorReactor::saveComplete (AcDbDatabase*, const char* pActualName)
{
    AcApDocument* pDoc = acDocManager->curDocument();
    if (pDoc)
        acutPrintf("DOCUMENT: Save complete %s\n", pDoc->fileName());
}
示例#3
0
//  NAME: newSyncDoc()        
//
//  REMARKS:  Simple function which requests a NEW to be executed via the application context.
//
//
//              NOTEs: See explanation for inAppContext()
//  RETURNS:
//      void 
// 
void
newSyncDoc()
{
    static char pData[] = /*NOXLATE*/"acad.dwt";

    AcApDocument* pDoc = acDocManager->curDocument();
    if (pDoc) {
        acutPrintf("\nCurrently in Document context : %s, Switching to App.\n",pDoc->fileName());
        acDocManager->executeInApplicationContext(newSyncDocHelper, (void *)pData);
    }    

}
示例#4
0
//  NAME: newSyncDocHelper()        
//
//  REMARKS:  Simple callback function to be executed in the application context.
//              Demonstrates creating a new document synchronously to retain control
//              in caller function
//
//              NOTEs: See explanation for inAppContext()
//  RETURNS:
//      void 
// 
void 
newSyncDocHelper( void *pData)
{
    AcApDocument* pDoc = acDocManager->curDocument();
    if (acDocManager->isApplicationContext()) {
        acutPrintf("\nSucessfully Switched to App. Context\n");
        acDocManager->appContextNewDocument((const char *)pData);
        acutPrintf("\nOpened a new document synchronously.\n");
    } else
        acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName());

}
示例#5
0
//  NAME: appcontext()        
//
//  REMARKS:  Simple function which requests a routine to be executed via the application context.
//
//
//              NOTEs: See explanation for inAppContext()
//  RETURNS:
//      void 
// 
void
appContext()
{
    static char pData[] = "Test Param";

    AcApDocument* pDoc = acDocManager->curDocument();
    if (pDoc) {
        acutPrintf("\nCurrently in Document context : %s, Switching to App.\n",pDoc->fileName());
        acDocManager->executeInApplicationContext(inAppContext, (void *)pData);
    }    

}
示例#6
0
//  NAME: inAppContext()        
//
//  REMARKS:  Simple callback function to be executed in the application context.
//            
//              NOTES: The application context is unique from each document. It is the supervisor
//              that delegates between each document that is currently opened. Mode-less dialogs
//              and other floating dialogs execute in this domain. As such it is the only
//              context where a document can be created that will not be suspended when the new document
//              becomes active. In the previous OPEN and NEW APIs it was explained that once
//              suspended a line of code following those APIs would not be executed until that 
//              document is activated again. For advanced operations a developer may require the
//              ability to execute a routine from within the applciation context to overcome
//              this limitation. As such, executeInApplicationContext() and its companion funcitons
//              appContextOpenDocument() and appContextNewDocument() were provided.
//          
// 
//  RETURNS:
//      void 
// 
void 
inAppContext( void *pData)
{
    AcApDocument* pDoc = acDocManager->curDocument();
    if (acDocManager->isApplicationContext()) {
        acutPrintf("\nSucessfully Switched to App. Context\n");
        if (pData != NULL)
            acutPrintf("\nData: %s\n", (char *)pData);        
    } else
        acutPrintf("\nERROR: in Document context : %s\n",pDoc->fileName());

}
示例#7
0
void CMDITestDialog::OnIsquiescentButton() 
{
    AcApDocument *pDoc = acDocManager->curDocument();

    if(pDoc) {
        CString tempStr;
        tempStr.Format("Current Doc is %s\nlockMode() returned %s\nand myLockMode() returned %s.",
                        pDoc->isQuiescent() ? "Quiescent." : "NOT Quiescent.",
                        modeStr(pDoc->lockMode()),
                        modeStr(pDoc->myLockMode()) );
        AfxMessageBox( tempStr );
    }
}
示例#8
0
//
//  NAME: listDocuments        
//
//  REMARKS: Iterate over all the open documents. Very common piece of code
//           for MDI aware applications.
//          
// 
//  RETURNS:
//      void 
void
listDocuments()
{
    AcApDocument* pDoc;
    AcApDocumentIterator* pDocIter;

    pDocIter = acDocManager->newAcApDocumentIterator();

    for ( ; !pDocIter->done(); pDocIter->step()) {
        pDoc = pDocIter->document();
        acutPrintf("  %s\n", pDoc->fileName());
    }
    delete pDocIter;
}
void
ArxDbgUiTdcSysReactors::removeInputReactorFromAll()
{
    if (m_inputReactor) {
		AcApDocument* tmpDoc;
		AcDbVoidPtrArray docPtrs;
		ArxDbgUtils::getAllDocuments(docPtrs);

        acutPrintf(_T("\nRemoving Editor Input Reactor from all documents..."));

		int len = docPtrs.length();
		for (int i=0; i<len; i++) {
			tmpDoc = static_cast<AcApDocument*>(docPtrs[i]);
		    tmpDoc->inputPointManager()->removeInputContextReactor(m_inputReactor);
		}
	}
}
示例#10
0
//
//  NAME: send        
//
//  REMARKS:  Simple routine to exercise switching between documents and sending commands.
//            
//         NOTEs: The actual signature for sendStringToExecute is:
//                virtual Acad::ErrorStatus sendStringToExecute(
//                                       AcApDocument* pAcTargetDocument,
//                                       const char * pszExecute,
//                                       bool bActivate = true,
//                                       bool bWrapUpInactiveDoc = false) = 0;
//
//         By default this API activates the document you are sending the string to
//         to be executed to. The last parameter, bWrapUpInactiveDoc is only applicable
//         if bActivate == False. This special ability allows you to "clean up" 
//         a document you might have left with some dangling command when constructing
//         a command that spans documents. One scenario is you are in the middle of
//         a custom command whose implementation is designed to "follow" the user
//         as they move from one document to another. If you have registered a reactor
//         on documentToBeActivated(). When this reactor fires you wish to complete
//         your current command in the document that is being deactivated and start
//         a command in the document about to be activated. 
//         Given these conditions, you would possibly send a "return" to the old 
//         document and "execute my new command" string to the one about to activated.
//         The "return" you would want to process in the background so you would pass
//         bActivate = False and bWrapUpInactiveDoc = True. 
// 
//  RETURNS:
//      void 
// 
void
send()
{
    AcApDocument* pDoc = selectDocument();

    if (pDoc == NULL) {
        acutPrintf("No document selected.\n");
        return;
    } 

    acDocManager->sendStringToExecute(pDoc, /*NOXLATE*/"_Line\n");
    // The API inputPending() allows you to check to see if someone else has already
    // made a request via sendStringToExecute() to a target document.
    // You may not care if your command is autonomous and does not depend on the target
    // document being in a quiescent state. If not call both  isQuiescent() and inputPending()
    acutPrintf("\nSent String to Doc: %s Pending Input %d\n", pDoc->fileName(), acDocManager->inputPending(pDoc));

}
示例#11
0
// getDocFromFilename()
//  Passed a filename, it finds the corresponding document pointer
//  Returns true if successful
bool CMDITestDialog::getDocFromFilename(CString csFileName, AcApDocument* &pNewDocument)
{
    // Iterate over the open documents. We will match the filename if:
    //      The filename specified matches the fully qualified path
    //      name, as returned by AcApDocument::filename()
    //      -or-
    //      The filename specified matches the filename portion of the 
    //      document name

    AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator();
    AcApDocument* pThisDocument = NULL;
    CString csThisFilename;
    CString csThisFilenameShort;

    csFileName.MakeUpper(); // uppercase comparisons

    while(!iter->done()) {   // Tiptoe through the tulips
        pThisDocument = iter->document();
        csThisFilename = pThisDocument->docTitle();
        csThisFilename.MakeUpper();
        csThisFilenameShort = csThisFilename.Right(csThisFilename.GetLength() -
            csThisFilename.ReverseFind('\\') - 1);

        if(csFileName == csThisFilename ||       // Full path match
            csFileName == csThisFilenameShort || // Matches filename only
            csFileName == csThisFilenameShort.Left( // Filename less extension
                          csThisFilenameShort.GetLength() - 4)) 
        {
            pNewDocument = pThisDocument;
            if( iter )
                delete iter;
            return true;
        }
        iter->step();
    }

    pNewDocument = NULL;
    if( iter )
        delete iter;
    // no match found 
    return false;
}
示例#12
0
void CMDITestDialog::RebuildListBox()
{
    m_docListBox.ResetContent(); // start from an empty list box

    // at this moment, get all drawing names and add them to the list box.
    AcApDocumentIterator* iter = acDocManager->newAcApDocumentIterator();
    AcApDocument* pDoc = NULL;
    CString csFilename;

    while(!iter->done()) {   
        pDoc = iter->document();
        if(pDoc) {                     // #### make sure pDoc is not NULL ####
            csFilename = pDoc->docTitle(); 
            m_docListBox.AddString( csFilename );
        }
        iter->step();
    }
    if( iter )
        delete iter;
}
示例#13
0
bool append(AcDbEntity* pEntity)
{
    AcDbBlockTable *pBlockTable;

	AcApDocument* pDoc = acDocManager->curDocument();

	Acad::ErrorStatus es = acDocManager->lockDocument(pDoc);
    if (es != Acad::eOk) {
        acedAlert("Failed to lock the document...");
        return false;
    }

	AcDbDatabase* pDb = pDoc->database();
    
    es = pDb->getBlockTable(pBlockTable, AcDb::kForRead);
    if (es != Acad::eOk) {
        acedAlert("Failed to get block table...");
        return false;
    }

    AcDbBlockTableRecord *pBlockRec;
    es = pBlockTable->getAt(ACDB_MODEL_SPACE, pBlockRec, AcDb::kForWrite);
    if (es != Acad::eOk) {
        acedAlert("Failed to get block table record...");
        pBlockTable->close();
        return false;
    }

    es = pBlockRec->appendAcDbEntity(pEntity);
    if (es != Acad::eOk) {
        acedAlert("Failed to append entity...");
        pBlockTable->close();
        pBlockRec->close();
        delete pEntity;
        return false;
    }
    pBlockRec->close();
    pBlockTable->close();
    return true;

}
示例#14
0
LRESULT CMDITestDialog::onAcadUpdateDialog( WPARAM, LPARAM )
{
    // update elements of the dialog to reflect the current
    // state of the documents

    // get the current number of documents
    m_staticDocNum.SetWindowText( getDocCount() );

    // check/uncheck document activation
    m_activationCheck.SetCheck( acDocManager->isDocumentActivationEnabled() );

    // set the current document fields
    CString fName;
    AcApDocument *pCurrDoc = acDocManager->curDocument();
    if( pCurrDoc ) {
        fName = pCurrDoc->docTitle();
        m_staticCurrentDoc.SetWindowText(fName);
        m_staticToBeCurrDoc.SetWindowText(fName);
        m_staticCurDocLockStatus.SetWindowText( modeStr(pCurrDoc->lockMode()) );
        m_staticCurDocMyLockStatus.SetWindowText( modeStr(pCurrDoc->myLockMode()) );
    }
    else {
        m_staticCurrentDoc.SetWindowText(fName);
        m_staticToBeCurrDoc.SetWindowText("");
        m_staticCurDocLockStatus.SetWindowText("");
        m_staticCurDocMyLockStatus.SetWindowText("");
    }

    // set the active document data
    AcApDocument *pActDoc = acDocManager->mdiActiveDocument();

    if( pActDoc ) {
        // active document name
        fName = pActDoc->docTitle();
        m_staticActiveDoc.SetWindowText(fName);
        // active document lock modes
        m_staticActDocLockStatus.SetWindowText( modeStr(pActDoc->lockMode()) );
        m_staticActDocMyLockStatus.SetWindowText( modeStr(pActDoc->myLockMode()) );
    }
    else {
        m_staticActiveDoc.SetWindowText("");
        m_staticActDocLockStatus.SetWindowText("");
        m_staticActDocMyLockStatus.SetWindowText("");
    }

    // rebuild listbox
    RebuildListBox();
	return TRUE;
}
示例#15
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"));
	}
}