// VRTabDlg.cpp : implementation file // #include "stdafx.h" // #include "DICOM.h" // #include "VRTabDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const WCHAR BASED_CODE _szLicString[] = L"LEADTOOLS OCX Copyright (c) 1991-2004 LEAD Technologies, Inc."; ///////////////////////////////////////////////////////////////////////////// // CVRTableDlg dialog CVRTableDlg::CVRTableDlg(CWnd* pParent /*=NULL*/) : CDialog(CVRTableDlg::IDD, pParent) { //{{AFX_DATA_INIT(CVRTableDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CVRTableDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CVRTableDlg) DDX_Control(pDX, IDC_EDIT6, m_Text6); DDX_Control(pDX, IDC_EDIT5, m_Text5); DDX_Control(pDX, IDC_EDIT4, m_Text4); DDX_Control(pDX, IDC_EDIT3, m_Text3); DDX_Control(pDX, IDC_EDIT2, m_Text2); DDX_Control(pDX, IDC_EDIT1, m_Text1); DDX_Control(pDX, IDC_LIST1, m_ListView1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CVRTableDlg, CDialog) //{{AFX_MSG_MAP(CVRTableDlg) ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1) ON_BN_CLICKED(IDC_FIRST, OnFirst) ON_BN_CLICKED(IDC_NEXT, OnNext) ON_BN_CLICKED(IDC_PREV, OnPrev) ON_BN_CLICKED(IDC_LAST, OnLast) ON_BN_CLICKED(IDC_BUTTON1, OnButton1) ON_BN_CLICKED(IDC_BUTTON2, OnButton2) ON_BN_CLICKED(IDC_BUTTON3, OnButton3) ON_BN_CLICKED(IDC_BUTTON4, OnButton4) ON_BN_CLICKED(IDC_BUTTON5, OnButton5) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CVRTableDlg message handlers BOOL CVRTableDlg::OnInitDialog() { CDialog::OnInitDialog(); m_ListView1.InsertColumn( 1, "Code", LVCFMT_LEFT, 60); m_ListView1.InsertColumn( 2, "Name", LVCFMT_LEFT, 120); m_ListView1.InsertColumn( 3, "Length", LVCFMT_LEFT, 60); m_ListView1.InsertColumn( 4, "Restrict", LVCFMT_LEFT, 60); m_ListView1.InsertColumn( 5, "UnitSize", LVCFMT_LEFT, 60); BSTR lpLic = SysAllocString(_szLicString); ILEADDicomFactory *pFactory=NULL; CoCreateInstance(CLSID_LEADDicomFactory, NULL, CLSCTX_ALL, IID_ILEADDicomFactory, (void**)&pFactory); #if _MSC_VER < 1200 m_pLEADDicomDS = (ILEADDicomDS*)pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); #else ILEADDicomDSPtr spLEADDicomDS=NULL; spLEADDicomDS = pFactory->CreateObject("LEADDicomDS.LEADDicomDS", lpLic); m_pLEADDicomDS = spLEADDicomDS; m_pLEADDicomDS->AddRef();//because when spLEADDicomDS goes out of scope, it will auto Release()! #endif pFactory->Release(); SysFreeString(lpLic); m_pLEADDicomDS->EnableMethodErrors = FALSE; FillList(); DisplayItem(); m_ListView1.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CVRTableDlg::FillList() { long lCount; long nIndex=-1; IDicomVRItemPtr pCurrentVR=NULL; CString szItem; short nRet; //get the VR Item count lCount = m_pLEADDicomDS->GetVRCount(); //get the first VR Item nRet = m_pLEADDicomDS->MoveFirstVR(); while(nRet == 0) { //add item to the ListView control pCurrentVR = m_pLEADDicomDS->GetCurrentVR(); szItem.Format("%ld", pCurrentVR->GetCode()); nIndex = m_ListView1.InsertItem(nIndex+1, szItem); szItem = (LPCSTR)pCurrentVR->GetName(); m_ListView1.SetItemText(nIndex, 1, szItem); szItem.Format("%ld", pCurrentVR->GetLength()); m_ListView1.SetItemText(nIndex, 2, szItem); szItem.Format("%d", pCurrentVR->GetRestrict()); m_ListView1.SetItemText(nIndex, 3, szItem); szItem.Format("%d", pCurrentVR->GetUnitSize()); m_ListView1.SetItemText(nIndex, 4, szItem); nRet = m_pLEADDicomDS->MoveNextVR(); } m_ListView1.SetItemState( 0, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.SetFocus(); m_ListView1.Update(0); m_nSelectedItem = 0; } void CVRTableDlg::DisplayItem() { short nRestrict; CString szOut; IDicomVRItemPtr pCurrentVR=NULL; pCurrentVR = m_pLEADDicomDS->GetCurrentVR(); if(pCurrentVR == NULL) { return; } //display the items information switch(pCurrentVR->GetCode()) { case VR_AE: m_Text1.SetWindowText("AE"); break; case VR_AS: m_Text1.SetWindowText("AS"); break; case VR_AT: m_Text1.SetWindowText("AT"); break; case VR_CS: m_Text1.SetWindowText("CS"); break; case VR_DA: m_Text1.SetWindowText("DA"); break; case VR_DS: m_Text1.SetWindowText("DS"); break; case VR_DT: m_Text1.SetWindowText("DT"); break; case VR_FD: m_Text1.SetWindowText("FD"); break; case VR_FL: m_Text1.SetWindowText("FL"); break; case VR_IS: m_Text1.SetWindowText("IS"); break; case VR_LO: m_Text1.SetWindowText("LO"); break; case VR_LT: m_Text1.SetWindowText("LT"); break; case VR_OB: m_Text1.SetWindowText("OB"); break; case VR_OW: m_Text1.SetWindowText("OW"); break; case VR_PN: m_Text1.SetWindowText("PN"); break; case VR_SH: m_Text1.SetWindowText("SH"); break; case VR_SL: m_Text1.SetWindowText("SL"); break; case VR_SQ: m_Text1.SetWindowText("SQ"); break; case VR_SS: m_Text1.SetWindowText("SS"); break; case VR_ST: m_Text1.SetWindowText("ST"); break; case VR_TM: m_Text1.SetWindowText("TM"); break; case VR_UI: m_Text1.SetWindowText("UI"); break; case VR_UL: m_Text1.SetWindowText("UL"); break; case VR_UN: m_Text1.SetWindowText("UN"); break; case VR_US: m_Text1.SetWindowText("US"); break; case VR_UT: m_Text1.SetWindowText("UT"); break; default: szOut.Format("%d", pCurrentVR->GetCode()); m_Text1.SetWindowText(szOut); break; } m_Text2.SetWindowText(pCurrentVR->GetName()); szOut.Format("%d", pCurrentVR->GetLength()); m_Text3.SetWindowText(szOut); nRestrict = pCurrentVR->GetRestrict(); nRestrict &= ~DICOM_VR_BINARY; nRestrict &= ~DICOM_VR_STRING; nRestrict &= ~DICOM_VR_TEXT; switch(nRestrict) { case DICOM_VR_FIXED: m_Text4.SetWindowText("Fixed"); break; case DICOM_VR_MAXIMUM: m_Text4.SetWindowText("Maximum"); break; case DICOM_VR_MAXIMUM_GROUP: m_Text4.SetWindowText("Maximum Group"); break; case DICOM_VR_ANY: m_Text4.SetWindowText("Any Length"); break; case DICOM_VR_NOT_APPLICABLE: m_Text4.SetWindowText("Not Applicable"); break; case DICOM_VR_MAX: m_Text4.SetWindowText("Max"); break; default: szOut.Format("%d", pCurrentVR->GetRestrict()); m_Text4.SetWindowText(szOut); break; } szOut.Format("%d", pCurrentVR->GetUnitSize()); m_Text5.SetWindowText(szOut); } void CVRTableDlg::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; short nCode; CString szCode; if((pNMListView->uNewState & LVIS_SELECTED)==LVIS_SELECTED) { m_nSelectedItem = pNMListView->iItem; szCode = m_ListView1.GetItemText(pNMListView->iItem, 0); nCode = atoi(szCode); //move to the selected VR m_pLEADDicomDS->FindVR(nCode); DisplayItem(); } *pResult = 0; } void CVRTableDlg::OnFirst() { if(m_pLEADDicomDS->MoveFirstVR()==0) { UpdateList(); DisplayItem(); } } void CVRTableDlg::OnNext() { if(m_pLEADDicomDS->MoveNextVR()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CVRTableDlg::OnPrev() { if(m_pLEADDicomDS->MovePrevVR()==0) { UpdateList(); DisplayItem(); } m_ListView1.SetFocus(); } void CVRTableDlg::OnLast() { if(m_pLEADDicomDS->MoveLastVR()==0) { UpdateList(); DisplayItem(); } } void CVRTableDlg::UpdateList() { LV_FINDINFO lvfind; CString szCode; IDicomVRItemPtr pCurrentVR=NULL; int nIndex; pCurrentVR = m_pLEADDicomDS->GetCurrentVR(); szCode.Format("%d", pCurrentVR->GetCode()); memset(&lvfind, 0, sizeof(LV_FINDINFO)); lvfind.flags = LVFI_STRING; lvfind.psz = szCode; nIndex = m_ListView1.FindItem(&lvfind, -1); if(nIndex >= 0) { m_ListView1.SetItemState( nIndex, LVIS_SELECTED | LVIS_FOCUSED, LVIS_SELECTED | LVIS_FOCUSED ); m_ListView1.Update(nIndex); m_ListView1.EnsureVisible(nIndex, FALSE); m_nSelectedItem = nIndex; m_ListView1.SetFocus(); } } void CVRTableDlg::OnButton1() { HCURSOR hOldCursor=NULL; m_ListView1.DeleteAllItems(); hOldCursor = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS->DefaultVR(); FillList(); SetCursor(hOldCursor); DisplayItem(); } void CVRTableDlg::OnButton2() { m_ListView1.DeleteAllItems(); //Clear all items from the VR Table m_pLEADDicomDS->ResetVR(); } void CVRTableDlg::OnButton3() { short nRet; short nCode; short nRestrict; CString szCode; CString szRestrict; CString szName; CString szLength; CString szUnitSize; long lLength; short nUnitSize; IDicomVRItemPtr pCurrentVR=NULL; int nIndex; CString szItem; m_Text1.GetWindowText(szCode); nCode = GetVRCode(szCode); nRet = m_pLEADDicomDS->FindVR(nCode); if(nRet == 0) { AfxMessageBox("Already Exists!"); return; } m_Text2.GetWindowText(szName); m_Text3.GetWindowText(szLength); lLength = atoi(szLength); m_Text4.GetWindowText(szRestrict); nRestrict = GetRestrict(szRestrict); m_Text5.GetWindowText(szUnitSize); nUnitSize = atoi(szUnitSize); BSTR bstr = szName.AllocSysString(); nRet = m_pLEADDicomDS->InsertVR(nCode, bstr, lLength, nRestrict, nUnitSize); SysFreeString(bstr); if(nRet != 0) { AfxMessageBox("Error"); return; } //add item to the ListView control pCurrentVR = m_pLEADDicomDS->GetCurrentVR(); szItem.Format("%ld", pCurrentVR->GetCode()); nIndex = m_ListView1.InsertItem(m_ListView1.GetItemCount(), szItem); szItem = (LPCSTR)pCurrentVR->GetName(); m_ListView1.SetItemText(nIndex, 1, szItem); szItem.Format("%ld", pCurrentVR->GetLength()); m_ListView1.SetItemText(nIndex, 2, szItem); szItem.Format("%d", pCurrentVR->GetRestrict()); m_ListView1.SetItemText(nIndex, 3, szItem); szItem.Format("%d", pCurrentVR->GetUnitSize()); m_ListView1.SetItemText(nIndex, 4, szItem); DisplayItem(); m_ListView1.SetItemState(nIndex, LVIS_SELECTED, LVIF_STATE); m_ListView1.Update(nIndex); m_nSelectedItem = nIndex; } void CVRTableDlg::OnButton4() { short nCode; CString szCode; short nRet; szCode = m_ListView1.GetItemText(m_nSelectedItem, 0); nCode = atoi(szCode); //move to the selected VR m_pLEADDicomDS->FindVR(nCode); //delete it nRet = m_pLEADDicomDS->DeleteVR(); if(nRet != 0) { AfxMessageBox("Error"); return; } //remove it from the list view control m_ListView1.DeleteItem(m_nSelectedItem); if(m_nSelectedItem>0) m_nSelectedItem--; else m_nSelectedItem++; m_ListView1.SetItemState(m_nSelectedItem, LVIS_SELECTED, LVIF_STATE); m_ListView1.Update(m_nSelectedItem); } short CVRTableDlg::GetRestrict(CString szRestrict) { if(szRestrict == "Fixed") return(DICOM_VR_FIXED); else if(szRestrict == "Maximum") return(DICOM_VR_MAXIMUM); else if(szRestrict == "Maximum Group") return(DICOM_VR_MAXIMUM_GROUP); else if(szRestrict == "Any Length") return(DICOM_VR_ANY); else if(szRestrict == "Not Applicable") return(DICOM_VR_NOT_APPLICABLE); else if(szRestrict == "Max") return(DICOM_VR_MAX); else return(atoi(szRestrict)); return 0; } short CVRTableDlg::GetVRCode(CString szCode) { if(szCode == "AE") return(VR_AE); else if(szCode == "AS") return(VR_AS); else if(szCode == "AT") return(VR_AT); else if(szCode == "CS") return(VR_CS); else if(szCode == "DA") return(VR_DA); else if(szCode == "DS") return(VR_DS); else if(szCode == "DT") return(VR_DT); else if(szCode == "FD") return(VR_FD); else if(szCode == "FL") return(VR_FL); else if(szCode == "IS") return(VR_IS); else if(szCode == "LO") return(VR_LO); else if(szCode == "LT") return(VR_LT); else if(szCode == "OB") return(VR_OB); else if(szCode == "OW") return(VR_OW); else if(szCode == "PN") return(VR_PN); else if(szCode == "SH") return(VR_SH); else if(szCode == "SL") return(VR_SL); else if(szCode == "SQ") return(VR_SQ); else if(szCode == "SS") return(VR_SS); else if(szCode == "ST") return(VR_ST); else if(szCode == "TM") return(VR_TM); else if(szCode == "UI") return(VR_UI); else if(szCode == "UL") return(VR_UL); else if(szCode == "UN") return(VR_UN); else if(szCode == "US") return(VR_US); else if(szCode == "UT") return(VR_UT); else return(atoi(szCode)); return(0); } void CVRTableDlg::OnButton5() { CString szName; IDicomVRItemPtr pCurrentVR=NULL; //move to the selected VR m_pLEADDicomDS->FindIndexVR(m_nSelectedItem); //change the name m_Text6.GetWindowText(szName); BSTR bstr=szName.AllocSysString(); m_pLEADDicomDS->SetVRName(bstr); SysFreeString(bstr); pCurrentVR = m_pLEADDicomDS->GetCurrentVR(); if(pCurrentVR) { DisplayItem(); m_ListView1.SetItemText(m_nSelectedItem, 1, pCurrentVR->GetName()); } //update it in the list view control } void CVRTableDlg::OnClose() { if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); CDialog::OnClose(); }