// MyTreeCtrl.cpp : implementation file // #include "stdafx.h" #include "DicomMWL.h" #include "MyTreeCtrl.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMyTreeCtrl // CMyTreeCtrl::CMyTreeCtrl() { m_pMyListCtrl = NULL; m_pIODClass = NULL; } CMyTreeCtrl::~CMyTreeCtrl() { } BEGIN_MESSAGE_MAP(CMyTreeCtrl, CTreeCtrl) //{{AFX_MSG_MAP(CMyTreeCtrl) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CMyTreeCtrl message handlers HTREEITEM CMyTreeCtrl::InsertItem(LPCTSTR lpszItem, HTREEITEM hParent, HTREEITEM hInsertAfter, LPCTSTR lpszValue, int nCount, pDICOMIOD pDicomIOD, pDICOMELEMENT pElement) { HTREEITEM hItem; hItem = CTreeCtrl::InsertItem(lpszItem,hParent, hInsertAfter); if (pElement) if (pElement->nLength == ELEMENT_LENGTH_MAX) SetItemImage(hItem, CGlobals::m_nIconSequence,CGlobals::m_nIconSequence); if (hItem != NULL) { CMyTreeData *pMyTreeData = new CMyTreeData(); if (pMyTreeData) { if (!lpszValue) pMyTreeData->m_strValue = ""; else pMyTreeData->m_strValue = lpszValue; pMyTreeData->m_pElement = pElement; pMyTreeData->m_strName = lpszItem; pMyTreeData->m_pDicomIOD = pDicomIOD; pMyTreeData->m_nCount = nCount; SetItemData(hItem, (DWORD)pMyTreeData); } } return hItem; } HTREEITEM CMyTreeCtrl::InsertElement(HTREEITEM hParentTree, pDICOMELEMENT pElement, pDICOMIOD pDicomIOD, LDicomDS *pDS) { if (!pElement) return NULL; CString strName; pDICOMTAG pTag; HTREEITEM hItem; int bTag = TRUE; char *pszValue; pTag = LDicomTag::Find(pElement->nTag); if (bTag == FALSE) { strName = (pTag != NULL) ? pTag->pszName : "Unknown"; } else { strName.Format("%04X:%04X - %s", GETGROUP(pElement->nTag), GETELEMENT(pElement->nTag), (pTag != NULL) ? pTag->pszName : "Unknown"); } int nLength = 0; if (pElement->nLength > 0) nLength = pDS->GetConvertValue(pElement, NULL); if (nLength == 0) { pszValue = NULL; hItem = InsertItem( strName, hParentTree, TVI_LAST, pszValue, 0, pDicomIOD, pElement); // If this is not NULL, populate the ListCtrl with empty type1 elements if ((m_pMyListCtrl) && (pElement->nLength != ELEMENT_LENGTH_MAX)) { // Is it type 1? pDICOMIOD pIOD = LDicomIOD::Find(m_pIODClass, pElement->nTag, IOD_TYPE_ELEMENT, FALSE); if ((pIOD) && ((pIOD->nUsage == IOD_USAGE_1) || (pIOD->nUsage == IOD_USAGE_1C))) { CString strTag; strTag.Format("%04X:%04X", GETGROUP(pElement->nTag), GETELEMENT(pElement->nTag)); int nIndex = m_pMyListCtrl->AppendItem((LPSTR)(LPCSTR)strTag, pIOD->pszName, "", hItem); SetItemImage(hItem, CGlobals::m_nIconMissing, CGlobals::m_nIconMissing); UpdateListIndex(hItem, nIndex); } } } else { int nCount = 0; if (pElement->nTag == TAG_PIXEL_DATA) { pszValue = NULL; } else { pszValue = (L_CHAR *)malloc(nLength); if (pszValue != NULL) { pDS->GetConvertValue(pElement, pszValue); nCount = pDS->GetCountValue(pElement); } } hItem = InsertItem( strName, hParentTree, TVI_LAST, pszValue, nCount, pDicomIOD, pElement); } if (pszValue) free(pszValue); return hItem; } L_VOID CMyTreeCtrl::DisplayCommandSet(LDicomDS *pDS, HTREEITEM hRoot, HTREEITEM hParentTree, pDICOMELEMENT pParentElement ) { if (!pDS) return; L_UINT32 i; L_UINT32 j; L_UINT32 nCount; L_UINT32 nClass; L_UINT16 nFlags; pDICOMMODULE pModule; pDICOMELEMENT pElement; pDICOMIOD pIOD; HTREEITEM hItem; CString strName; int bVolatile = TRUE; if (pParentElement == NULL) { pDS->GetInfoDS(&nClass, &nFlags); nCount = pDS->GetCountModule(); for (i = 0; i < nCount; i++) { pModule = pDS->FindIndexModule(i); if (pModule != NULL) { pIOD = LDicomIOD::FindModule(nClass, pModule->nModule); if (pIOD != NULL) { strName = pIOD->pszName; } else { strName = "Unknown"; } hParentTree = InsertItem( strName, hRoot, TVI_LAST, NULL, 0, NULL, NULL); SetItemState(hParentTree, TVIS_BOLD, TVIS_BOLD); SetItemImage(hParentTree, CGlobals::m_nIconFolder, CGlobals::m_nIconFolder); for (j = 0; j < pModule->nCount; j++) { pDICOMIOD pElementIOD = LDicomIOD::Find(NULL /*pDicomIOD*/, pModule->pElement[j]->nTag, IOD_TYPE_ELEMENT , FALSE); // Insert Element hItem = InsertElement(hParentTree, pModule->pElement[j], pElementIOD, pDS); if (pDS->GetChildElement(pModule->pElement[j], bVolatile) != NULL) { DisplayCommandSet(pDS, hItem, hItem, pModule->pElement[j]); } } } } } else { pElement = pDS->GetChildElement(pParentElement, bVolatile); while (pElement != NULL) { // Insert Element pDICOMIOD pElementIOD = LDicomIOD::Find(NULL /*pDicomIOD*/, pElement->nTag, IOD_TYPE_ELEMENT , FALSE); hItem = InsertElement(hParentTree, pElement, pElementIOD, pDS); if ((pElement->nLength == ELEMENT_LENGTH_MAX) && (pDS->GetChildElement(pElement, bVolatile) != NULL)) { if (pDS->GetChildElement(pElement, bVolatile) != NULL) { //DisplayCommandSet(pDS, hItem, pElement); DisplayCommandSet(pDS, hItem, hItem, pElement); } } pElement = pDS->GetNextElement(pElement, TRUE, bVolatile); } } } L_VOID CMyTreeCtrl::AddMWLItem(LDicomDS *pDS, int nCountDS) { HTREEITEM hItem; CString strMsg = ""; if (pDS) { hItem = InsertItem((LPSTR)(LPCSTR)strMsg, TVI_ROOT, TVI_LAST,NULL, 0, NULL, NULL); SetItemImage(hItem, CGlobals::m_nIconWorklist,CGlobals::m_nIconWorklist); CMyTreeData *pMyTreeData = (CMyTreeData *)GetItemData(hItem); if (pMyTreeData) { pMyTreeData->SetDS(pDS); strMsg.Format("%03d Modality Work List - %s ", nCountDS, pMyTreeData->m_pDS->GetModality()); SetItemText(hItem, (LPSTR)(LPCSTR)strMsg); } DisplayCommandSet(pDS, hItem, NULL, NULL); } } /* CString CMyTreeCtrl::GetValue(LDicomDS *pDS, pDICOMELEMENT pElement) { int nCount; int nLength; CString strRet; char *pszValue, *p, *q; int i; if (!pElement) return strRet; nCount = pDS->GetCountValue(pElement); pDS->FreeValue(pElement); if (nCount == 0) { return strRet; } //nLength = pDS->GetConvertValue(pElement, NULL); nLength = 0; if (pElement->nLength > 0) nLength = pDS->GetConvertValue(pElement, NULL); if (nLength == 0) { return strRet; } pszValue = (L_CHAR *)malloc(nLength); if (pszValue == NULL) { return strRet; } nLength = pDS->GetConvertValue(pElement, pszValue); for (i = 0, p = pszValue; i < nCount; i++) { if (nCount > 1) { q = strchr(p, '\\'); if (q != NULL) { *q = 0; } } strRet = strRet + p + "\r\n"; p += strlen(p) + 1; } free(pszValue); return strRet; } */ void CMyTreeCtrl::TraverseFreeTree(HTREEITEM hRoot) { if (hRoot == NULL) return; // Free memory for children HTREEITEM hItem = GetChildItem(hRoot); while (NULL != hItem) { CMyTreeData *pMyTreeData = (CMyTreeData *)GetItemData(hItem); if (pMyTreeData) { delete pMyTreeData; SetItemData(hItem, NULL); } // Recursively print TraverseFreeTree(hItem); // Move on to next sibling hItem = GetNextSiblingItem(hItem); } } BOOL CMyTreeCtrl::DeleteAllItems() { TraverseFreeTree(TVI_ROOT); return CTreeCtrl::DeleteAllItems(); } void CMyTreeCtrl::OnDestroy() { TraverseFreeTree(TVI_ROOT); CTreeCtrl::OnDestroy(); // TODO: Add your message handler code here } //hItem == NULL: Returns root of treeview //hItem != NULL: Returns root of hItem HTREEITEM CMyTreeCtrl::GetRootOfItem(HTREEITEM hItem) { if (hItem == NULL) return GetRootItem(); HTREEITEM hParent = GetParentItem(hItem); if (hParent == NULL) return hItem; else return GetRootOfItem(hParent); } LDicomDS * CMyTreeCtrl::GetDS(HTREEITEM hItem) { LDicomDS *pDS = NULL; CMyTreeData *pMyTreeData = NULL; HTREEITEM hRoot = GetRootOfItem(hItem); if (hRoot) { pMyTreeData = (CMyTreeData*)GetItemData(hRoot); if (pMyTreeData) pDS = pMyTreeData->m_pDS; } return pDS; } BOOL CMyTreeCtrl::Create(DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID) { // TODO: Add your specialized code here and/or call the base class BOOL bRet = CTreeCtrl::Create( dwStyle, rect, pParentWnd, nID); if (bRet) SetImageList(&CGlobals::m_ImageList, TVSIL_NORMAL); return bRet; } void CMyTreeCtrl::UpdateListIndex(HTREEITEM hItem, int nIndex) { CMyTreeData *pData = (CMyTreeData *)GetItemData(hItem); if (hItem) pData->m_nListIndex = nIndex; }