📄 inspectorbar.cpp
字号:
if ( hItem )
hChild =mpTree->GetNextItem (hItem, TVGN_CHILD) ;
else
hChild =mpTree->GetRootItem () ;
while ( hChild ) {
DWORD dw =mpTree->GetItemData (hChild) ;
if ( dw == data )
break ;
if ( bRecurs && mpTree->ItemHasChildren (hChild) ) {
HTREEITEM hResult =FindItemPosition (hChild, data, TRUE) ;
if ( hResult )
return (hResult) ;
}
hChild =mpTree->GetNextItem (hChild, TVGN_NEXT) ;
}
return (hChild) ;
}
HTREEITEM CInspectorBar::FindItemPosition (AcRxObject *pObj) {
AcDbObjectIdArray array ;
if ( !pObj->isKindOf (AcDbObject::desc ()) )
return (FindItemPosition (NULL, (DWORD)pObj, TRUE)) ;
try {
USES_OKEYS ;
AcDbObjectId id ;
AcDbObject *p =(AcDbObject *)pObj ;
array.append (p->objectId ()) ;
while ( (id =p->ownerId ()) != AcDbObjectId::kNull ) {
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)p, id, AcDb::kForRead, Adesk::kTrue) ) ;
array.append (id) ;
}
AcDbDatabase *pDwg =((AcDbObject *)pObj)->database () ;
HTREEITEM pos =FindItemPosition (NULL, (DWORD)pDwg, FALSE) ;
if ( !pos )
throw "" ;
for ( int i =array.logicalLength () - 1 ; i >= 0 ; i-- )
if ( (pos =FindItemPosition (pos, (DWORD)array [i].asOldId (), FALSE)) == NULL )
break ;
return (pos) ;
} catch (const char *szMsg) {
return (NULL) ;
}
}
HTREEITEM CInspectorBar::FindParentPosition (AcDbObject *pObj) {
AcDbObjectIdArray array ;
try {
USES_OKEYS ;
AcDbObjectId id ;
AcDbObject *p =pObj ;
while ( (id =p->ownerId ()) != AcDbObjectId::kNull ) {
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)p, id, AcDb::kForRead, Adesk::kTrue) ) ;
array.append (id) ;
}
AcDbDatabase *pDwg =pObj->database () ;
HTREEITEM pos =FindItemPosition (NULL, (DWORD)pDwg, FALSE) ;
if ( !pos )
throw "" ;
for ( int i =array.logicalLength () - 1 ; i >= 0 ; i-- )
if ( (pos =FindItemPosition (pos, (DWORD)array [i].asOldId (), FALSE)) == NULL )
throw "" ;
return (pos) ;
} catch (const char *szMsg) {
return (NULL) ;
}
}
HTREEITEM CInspectorBar::FindPreviousSubEntity (AcDbEntity *pObj) {
HTREEITEM hItem =TVI_FIRST ;
AcDbObjectIterator *pi =NULL ;
try {
USES_OKEYS ;
AcDbObjectId id =pObj->objectId () ;
AcDbObjectId idParent =pObj->ownerId () ;
HTREEITEM hParent =FindParentPosition (pObj) ;
if ( pObj->isKindOf (AcDb2dVertex::desc ()) ) {
AcDb2dPolyline *pParent ;
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)pParent, idParent, AcDb::kForRead, Adesk::kTrue) ) ;
ARXNULL ( pi =pParent->vertexIterator () ) ;
} else if ( pObj->isKindOf (AcDb3dPolylineVertex::desc ()) ) {
AcDb3dPolyline *pParent ;
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)pParent, idParent, AcDb::kForRead, Adesk::kTrue) ) ;
ARXNULL ( pi =pParent->vertexIterator () ) ;
} else if ( pObj->isKindOf (AcDbAttribute::desc ()) ) {
AcDbBlockReference *pParent ;
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)pParent, idParent, AcDb::kForRead, Adesk::kTrue) ) ;
ARXNULL ( pi =pParent->attributeIterator () ) ;
}// else if ( p->isKindOf (AcDbFace::desc ()) ) {
//}
//else if ( p->isKindOf (AcDbPolyFaceMesh::desc ()) ) {
//}
//else if ( p->isKindOf (AcDbPolygonMesh::desc ()) ) {
//}
pi->setPosition (id) ;
while ( !pi->done () ) {
pi->step (Adesk::kTrue, Adesk::kTrue) ;
if ( !pi->done () ) {
if ( (hItem =FindItemPosition (hParent, pi->objectId ().asOldId (), FALSE)) )
break ;
}
hItem =TVI_FIRST ;
}
delete pi ;
return (hItem) ;
} catch (const char *szMsg) {
delete pi ;
return (NULL) ;
}
}
HTREEITEM CInspectorBar::FindPreviousEntity (AcDbEntity *pObj) {
HTREEITEM hItem =TVI_FIRST ;
HTREEITEM hParent =FindParentPosition (pObj) ;
AcDbBlockTableRecordIterator *pi =NULL ;
try {
USES_OKEYS ;
if ( pObj->isKindOf (AcDb2dVertex::desc ()) || pObj->isKindOf (AcDbAttribute::desc ()) )
return (FindPreviousSubEntity (pObj)) ;
AcDbObjectId id =pObj->objectId () ;
AcDbObjectId idParent =pObj->ownerId () ;
AcDbBlockTableRecord *pParent ;
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)pParent, idParent, AcDb::kForRead, Adesk::kTrue) ) ;
ARXOK ( pParent->newIterator (pi, Adesk::kTrue, Adesk::kFalse) ) ;
//----- seek() does not work on erased entities
if ( pi->seek (id) != Acad::eOk ) {
while ( !pi->done () ) {
AcDbObjectId iid ;
ARXOK ( pi->getEntityId (iid) ) ;
if ( iid == id )
break ;
pi->step (Adesk::kTrue, Adesk::kFalse) ;
}
}
while ( !pi->done () ) {
pi->step (Adesk::kFalse, Adesk::kFalse) ;
if ( !pi->done () ) {
AcDbObjectId idp ;
ARXOK ( pi->getEntityId (idp) ) ;
if ( (hItem =FindItemPosition (hParent, idp.asOldId (), FALSE)) )
break ;
}
hItem =TVI_FIRST ;
}
delete pi ;
if ( hItem == TVI_FIRST ) {
//----- Because a AcDbBlockTableRecord has a AcDbBlockBegin object prior any
//----- entity, we must move one step to be at the correct position in
//----- the list
hItem =mpTree->GetNextItem (hParent, TVGN_CHILD) ;
}
return (hItem) ;
} catch (const char *szMsg) {
delete pi ;
return (NULL) ;
}
}
void CInspectorBar::OnNewObj (AcRxObject *p) {
if ( p->isKindOf (AcDbDatabase::desc ()) ) {
Scan ((AcDbDatabase *)p) ;
return ;
}
if ( p->isKindOf (AcDbObject::desc ()) ) {
if ( actrTransactionManager->topTransaction () == NULL ) {
mbFlag =TRUE ;
actrTransactionManager->startTransaction () ;
}
//----- Find parent in the tree
HTREEITEM hParent =FindParentPosition ((AcDbObject *)p) ;
if ( hParent ) {
//---- Determines position in the list
HTREEITEM hPrevChild =TVI_LAST ;
if ( p->isKindOf (AcDbVertex::desc ()) || p->isKindOf (AcDbAttribute::desc ()) )
hPrevChild =FindPreviousSubEntity ((AcDbEntity *)p) ;
else if ( p->isKindOf (AcDbEntity::desc ()) )
hPrevChild =FindPreviousEntity ((AcDbEntity *)p) ;
//----- Create the item
CreateItem (GetName (p), hParent, hPrevChild, p) ;
}
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
}
}
void CInspectorBar::OnUpdObj (AcRxObject *p) {
if ( p->isKindOf (AcDbObject::desc ()) ) {
if ( actrTransactionManager->topTransaction () == NULL ) {
mbFlag =TRUE ;
actrTransactionManager->startTransaction () ;
}
//----- Mark the Database modified if not yet done!
HTREEITEM hDb =FindItemPosition (((AcDbObject *)p)->database ()) ;
mpTree->SetItemColor (hDb, MODIFIED_COLOR) ;
mpTree->SetItemImage (hDb, (int)(mImgMap [_T(/*NOXLATE*/"AcDbDatabase")]) + MODIFIED, (int)(mImgMap [_T(/*NOXLATE*/"AcDbDatabase")]) + MODIFIED) ;
HTREEITEM hItem =FindItemPosition (p) ;
if ( hItem ) {
//----- Visibility
if ( ((AcDbObject *)p)->isErased () && !mbSeeErasedObjects ) {
mpTree->DeleteItem (hItem) ;
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
return ;
}
//----- State
mpTree->SetItemState (hItem, ((AcDbObject *)p)->isErased () ? 0 : TVIS_BOLD, TVIS_BOLD) ;
if ( ((AcDbObject *)p)->isModified () )
mpTree->SetItemColor (hItem, MODIFIED_COLOR) ;
else
mpTree->ResetItemProperty (hItem) ;
//----- Image
int index =0 ;
if ( ((AcDbObject *)p)->isErased () )
index++ ;
if ( ((AcDbObject *)p)->isModified () )
index +=2 ;
index +=GetImage (p) ;
mpTree->SetItemImage (hItem, index, index) ;
} else if ( !((AcDbObject *)p)->isErased () || mbSeeErasedObjects ) {
//----- Find parent in the tree
HTREEITEM hParent =FindParentPosition ((AcDbObject *)p) ;
if ( !hParent ) {
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
return ;
}
//---- Determines position in the list
HTREEITEM hPrevChild =TVI_LAST ;
if ( p->isKindOf (AcDbVertex::desc ()) || p->isKindOf (AcDbAttribute::desc ()) )
hPrevChild =FindPreviousSubEntity ((AcDbEntity *)p) ;
else if ( p->isKindOf (AcDbEntity::desc ()) )
hPrevChild =FindPreviousEntity ((AcDbEntity *)p) ;
//----- Create the item
hItem =CreateItem (GetName (p), hParent, hPrevChild, p) ;
ScanSubObjects (hItem, (AcDbObject *)p) ;
//----- State
mpTree->SetItemState (hItem, ((AcDbObject *)p)->isErased () ? 0 : TVIS_BOLD, TVIS_BOLD) ;
if ( ((AcDbObject *)p)->isModified () )
mpTree->SetItemColor (hItem, MODIFIED_COLOR) ;
else
mpTree->ResetItemProperty (hItem) ;
//----- Image
int index =0 ;
if ( ((AcDbObject *)p)->isErased () )
index++ ;
if ( ((AcDbObject *)p)->isModified () )
index +=2 ;
index +=GetImage (p) ;
mpTree->SetItemImage (hItem, index, index) ;
}
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
}
}
void CInspectorBar::OnDelObj (AcRxObject *p) {
if ( !::IsWindow (m_hWnd) )
return ;
if ( actrTransactionManager->topTransaction () == NULL ) {
mbFlag =TRUE ;
actrTransactionManager->startTransaction () ;
}
HTREEITEM hItem =FindItemPosition (p) ;
if ( hItem )
mpTree->DeleteItem (hItem) ;
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
}
//-----------------------------------------------------------------------------
void OnSaved (TTreeCtrl *pTree, HTREEITEM hItem) {
pTree->ResetItemProperty (hItem) ;
int index, i ;
pTree->GetItemImage (hItem, index, i) ;
if ( index % 4 == MODIFIED || index %4 == ER_AND_MD ) {
index -=MODIFIED ;
pTree->SetItemImage (hItem, index, i) ;
}
}
void CInspectorBar::Saved (AcDbDatabase *pDb) {
if ( actrTransactionManager->topTransaction () == NULL ) {
mbFlag =TRUE ;
actrTransactionManager->startTransaction () ;
}
HTREEITEM hItem =FindItemPosition (pDb) ;
if ( hItem ) {
mpTree->SetItemText (hItem, acDocManager->document (pDb)->fileName ()) ;
mpTree->ApplyToAll (hItem, OnSaved) ;
}
if ( mbFlag ) {
mbFlag =FALSE ;
actrTransactionManager->endTransaction () ;
}
}
//-----------------------------------------------------------------------------
//----- Scan Database
HTREEITEM CInspectorBar::Scan (AcDbDatabase *pDb) {
HTREEITEM hItem =NULL ;
CString name =acDocManager->document (pDb)->fileName () ;
try {
USES_OKEYS ;
actrTransactionManager->startTransaction () ;
//----- Database
hItem =CreateItem (name, TVI_ROOT, TVI_LAST, pDb) ;
//----- Scan Block Table
SmartPtr<AcDbBlockTable> pBlockTable ;
ARXOK ( pDb->getBlockTable (*pBlockTable, AcDb::kForRead) ) ;
Scan (hItem, pBlockTable) ;
//----- Scan Dimension Style Table
SmartPtr<AcDbDimStyleTable> pDimStyleTable ;
ARXOK ( pDb->getDimStyleTable (*pDimStyleTable, AcDb::kForRead) ) ;
Scan (hItem, pDimStyleTable) ;
//----- Scan Layer Table
SmartPtr<AcDbLayerTable> pLayerTable ;
ARXOK ( pDb->getLayerTable (*pLayerTable, AcDb::kForRead) ) ;
Scan (hItem, pLayerTable) ;
//----- Scan Linetype Table
SmartPtr<AcDbLinetypeTable> pLinetypeTable ;
ARXOK ( pDb->getLinetypeTable (*pLinetypeTable, AcDb::kForRead) ) ;
Scan (hItem, pLinetypeTable) ;
//----- Named Object Dictionary
SmartPtr<AcDbDictionary> pNOD ;
ARXOK ( pDb->getNamedObjectsDictionary (*pNOD, AcDb::kForRead) ) ;
Scan (hItem, pNOD) ;
//----- Scan Registered Application Table
SmartPtr<AcDbRegAppTable> pRegAppTable ;
ARXOK ( pDb->getRegAppTable (*pRegAppTable, AcDb::kForRead) ) ;
Scan (hItem, pRegAppTable) ;
//----- Scan Text Style Table
SmartPtr<AcDbTextStyleTable> pTextStyleTable ;
ARXOK ( pDb->getTextStyleTable (*pTextStyleTable, AcDb::kForRead) ) ;
Scan (hItem, pTextStyleTable) ;
//----- Scan User Coordinate System Table
SmartPtr<AcDbUCSTable> pUCSTable ;
ARXOK ( pDb->getUCSTable (*pUCSTable, AcDb::kForRead) ) ;
Scan (hItem, pUCSTable) ;
//----- Scan View Table
SmartPtr<AcDbViewTable> pViewTable ;
ARXOK ( pDb->getViewTable (*pViewTable, AcDb::kForRead) ) ;
Scan (hItem, pViewTable) ;
//----- Scan Viewport Table
SmartPtr<AcDbViewportTable> pViewportTable ;
ARXOK ( pDb->getViewportTable (*pViewportTable, AcDb::kForRead) ) ;
Scan (hItem, pViewportTable) ;
actrTransactionManager->endTransaction () ;
return (hItem) ;
} catch (const char *szMsg) {
if ( hItem != NULL && mpTree->ItemHasChildren (hItem) ) {
HTREEITEM hChildItem ;
while ( (hChildItem =mpTree->GetChildItem (hItem)) != NULL )
mpTree->DeleteItem (hChildItem) ;
}
actrTransactionManager->endTransaction () ; //----- Do not call abortTransaction() here
return (NULL) ;
}
}
HTREEITEM CInspectorBar::Scan (HTREEITEM hParent, AcDbSymbolTable *p) {
HTREEITEM hItem =NULL ;
AcDbSymbolTableIterator *pi =NULL ;
try {
USES_OKEYS ;
hItem =CreateItem (GetName (p), hParent, TVI_LAST, p) ;
ScanSubObjects (hItem, p) ;
ARXOK ( p->newIterator (pi, Adesk::kTrue, Adesk::kTrue) ) ;
while ( !pi->done () ) {
AcDbObjectId id ;
ARXOK ( pi->getRecordId (id) ) ;
AcDbSymbolTableRecord *pr ;
ARXOK ( actrTransactionManager->topTransaction ()->getObject ((AcDbObject *&)pr, id, AcDb::kForRead, Adesk::kTrue) ) ;
Scan (hItem, pr) ;
pi->step (Adesk::kTrue, Adesk::kTrue) ;
}
delete pi ;
return (hItem) ;
} catch (const char *szMsg) {
delete pi ;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -