// LeftView.cpp : implementation of the CLeftView class // #include "stdafx.h" #include "DICOMVid.h" #include "Document.h" #include "LeftView.h" #include "ModifyDE.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLeftView IMPLEMENT_DYNCREATE(CLeftView, CTreeView) BEGIN_MESSAGE_MAP(CLeftView, CTreeView) //{{AFX_MSG_MAP(CLeftView) ON_NOTIFY_REFLECT(NM_DBLCLK, OnDblclk) //}}AFX_MSG_MAP // Standard printing commands ON_COMMAND(ID_FILE_PRINT, CTreeView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, CTreeView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, CTreeView::OnFilePrintPreview) END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLeftView construction/destruction CLeftView::CLeftView() { // TODO: add construction code here } CLeftView::~CLeftView() { } BOOL CLeftView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CTreeView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CLeftView drawing void CLeftView::OnDraw(CDC* pDC) { CDicomVidDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here } ///////////////////////////////////////////////////////////////////////////// // CLeftView printing BOOL CLeftView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CLeftView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CLeftView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void CLeftView::OnInitialUpdate() { CTreeView::OnInitialUpdate(); int i; CBitmap Bitmap; CRect rcRect; // Set image list for our tree m_Icon.Create(16, 16, ILC_MASK, 0, sizeof(BITMAPLIST) / sizeof(BITMAPLIST[0])); for (i = 0; i < sizeof(BITMAPLIST) / sizeof(BITMAPLIST[0]); i++) { Bitmap.LoadBitmap(BITMAPLIST[i]); m_Icon.Add(&Bitmap, (COLORREF)0xFFFFFF); Bitmap.DeleteObject(); } GetTreeCtrl ().SetImageList(&m_Icon, TVSIL_NORMAL); // Change the style of the tree ::SetWindowLong( GetTreeCtrl (), GWL_STYLE, (GetWindowLong(GetTreeCtrl (),GWL_STYLE)) |TVS_HASLINES|TVS_LINESATROOT|TVS_HASBUTTONS); } //Populate our tree with dataset elements void CLeftView::FillDICOMElementsTree(HTREEITEM hParentTree, pDICOMELEMENT pParentElement) { CString strText; L_UINT32 nClass; LDicomDS *pDS = &(((CDicomVidDoc *)GetDocument()) ->GetActiveDS()); pDS->GetInfoDS(&nClass, NULL); if (nClass == CLASS_BASIC_DIRECTORY) return ; DoFillDICOMElementsTree(pDS, hParentTree, pParentElement); } //Get value for a certain element L_VOID CLeftView::GetElementValue(pDICOMELEMENT pElement,CString &strValue) { L_UINT32 nCount=0; L_UINT32 nLength; L_CHAR *pszValue; L_CHAR *pTemp1; L_CHAR *pTemp2; L_UINT32 i; LDicomDS *pDS = &(((CDicomVidDoc *)GetDocument()) ->GetActiveDS()); if((NULL == pElement) || (pDS->ExistsElement(pElement) == FALSE)) return; if (pElement->nTag == TAG_PIXEL_DATA) { strValue.Empty(); return; } nCount = pDS->GetCountValue(pElement); pDS->FreeValue(pElement); if (nCount == 0) { return; } strValue.Empty(); // call GetConvertValue and pass NULL in order to , // get the length of its value nLength = pDS->GetConvertValue(pElement, NULL); if (nLength == 0) { // Is this a date? if(pElement->nVR == VR_DA) { pVALUEDATE pDate=NULL; for (i = 0; i < nCount; i++) { pDate=pDS->GetDateValue(pElement, i, 1); if(pDate) { strValue.Format("%d/%d/%d", pDate->nDay, pDate->nMonth, pDate->nYear); } } } return; } //Allocate memory to hold the value of the element pszValue = (L_CHAR *)malloc(nLength); if (pszValue == NULL) { return; } //Get the value of this element nLength = pDS->GetConvertValue(pElement, pszValue); for (i = 0, pTemp1 = pszValue; i < nCount; i++) { if (nCount > 1) { pTemp2 = strchr(pTemp1, '\\'); if (pTemp2 != NULL) { *pTemp2 = 0; } } pTemp1 += strlen(pTemp1) + 1; } strValue = pszValue; free(pszValue); } // Insert a new item to the tree HTREEITEM CLeftView:: InsertElement(HTREEITEM hParentTree, pDICOMELEMENT pElement) { CString strName; pDICOMTAG pTag; HTREEITEM hItem; CString strValue; pTag = LDicomTag::Find(pElement->nTag); strName.Format("%04X:%04X - %s", GETGROUP(pElement->nTag), GETELEMENT(pElement->nTag), (pTag != NULL) ? pTag->pszName : "Unknown"); GetElementValue(pElement,strValue); strName = strName + " : "; if(strValue.GetLength() > 0 ) { strName = strName + strValue ; } if (pElement->nLength == ELEMENT_LENGTH_MAX) { hItem = GetTreeCtrl ().InsertItem( strName, GetImage(IDB_STORAGE_COLLAPSED), GetImage(IDB_STORAGE_COLLAPSED), hParentTree, TVI_SORT); } else { hItem = GetTreeCtrl ().InsertItem( strName, GetImage(IDB_STREAM), GetImage(IDB_STREAM), hParentTree, TVI_SORT); } if (hItem != NULL) { GetTreeCtrl ().SetItemData(hItem, (DWORD)pElement); } return hItem; } // void CLeftView:: DoFillDICOMElementsTree ( LDicomDS *pDS, HTREEITEM hParentTree, pDICOMELEMENT pParentElement ) { 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; 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 = GetTreeCtrl ().InsertItem( strName, GetImage(IDB_STORAGE_COLLAPSED), GetImage(IDB_STORAGE_COLLAPSED), TVI_ROOT, TVI_LAST); GetTreeCtrl ().SetItemState(hParentTree, TVIS_BOLD, TVIS_BOLD); for (j = 0; j < pModule->nCount; j++) { hItem = InsertElement(hParentTree, pModule->pElement[j]); if (pDS->GetChildElement(pModule->pElement[j], TRUE) != NULL) { DoFillDICOMElementsTree(pDS,hItem, pModule->pElement[j]); } } } } } else { pElement = pDS->GetChildElement(pParentElement, TRUE); while (pElement != NULL) { hItem = InsertElement(hParentTree, pElement); if ((pElement->nLength == ELEMENT_LENGTH_MAX) && (pDS->GetChildElement(pElement, TRUE) != NULL)) { if (pDS->GetChildElement(pElement, TRUE) != NULL) { DoFillDICOMElementsTree(pDS , hItem, pElement); } } pElement = pDS->GetNextElement(pElement, TRUE, TRUE); } } } int CLeftView::GetImage(UINT nBitmap) { int nImage; for (nImage = 0; nImage < sizeof(BITMAPLIST) / sizeof(BITMAPLIST[0]); nImage++) { if (BITMAPLIST[nImage] == nBitmap) { break; } } return nImage; } ///////////////////////////////////////////////////////////////////////////// // CLeftView diagnostics #ifdef _DEBUG void CLeftView::AssertValid() const { CTreeView::AssertValid(); } void CLeftView::Dump(CDumpContext& dc) const { CTreeView::Dump(dc); } CDicomVidDoc* CLeftView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDicomVidDoc))); return (CDicomVidDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CLeftView message handlers void CLeftView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) { GetTreeCtrl().DeleteAllItems(); FillDICOMElementsTree(TVI_ROOT, NULL); } // When the user double clicks an item in the tree we need to update its value if possible void CLeftView::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW *pNMTreeView = (NM_TREEVIEW*)pNMHDR; HTREEITEM hItem = GetTreeCtrl().GetSelectedItem(); if(hItem != NULL) { pDICOMELEMENT pElement = (pDICOMELEMENT)GetTreeCtrl().GetItemData(hItem); if ((pElement != NULL ) && (pElement->nTag != TAG_PIXEL_DATA)) { CString strName; pDICOMTAG pTag; CString strValue; CDicomModifyElementDlg dlg; pTag = LDicomTag::Find(pElement->nTag); if(NULL == pTag) { return ; } strName.Format("%s",(pTag != NULL) ? pTag->pszName : "Unknown"); GetElementValue(pElement,strValue); strName = strName + " : "; CDicomVidDoc* pDoc = GetDocument(); LDicomDS *pDS = &(((CDicomVidDoc *)GetDocument()) ->GetActiveDS()); if(pDoc) { dlg.m_pDicomIOD = LDicomIOD::Find(pDoc->GetIOD(), pElement->nTag, IOD_TYPE_ELEMENT , FALSE); dlg.m_pElement = pElement; dlg.m_strValue = strValue ; dlg.m_nCount = pDS->GetCountValue(pElement); if ((dlg.m_pDicomIOD ) && (dlg.DoModal() == IDOK)) { dlg.m_strValue.TrimLeft(); dlg.m_strValue.TrimRight(); pDS->FreeValue(dlg.m_pElement); pDS->SetConvertValue(dlg.m_pElement, (L_CHAR *)(LPCTSTR)dlg.m_strValue, dlg.m_nCount); strValue.Empty(); strValue.Format( "%04X:%04X - %s", GETGROUP(pElement->nTag), GETELEMENT(pElement->nTag), (pTag != NULL) ? pTag->pszName : "Unknown"); strValue = strValue + " : " + dlg.m_strValue; GetTreeCtrl().SetItemText(hItem,strValue); pDoc->SetModifiedFlag(TRUE); } } } } *pResult = 0; }