// UIDList.cpp : implementation file // #include "stdafx.h" #include "dclient.h" #include "UIDList.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif const WCHAR BASED_CODE _szLicString[] = LEAD_LICENSE_STRING; ///////////////////////////////////////////////////////////////////////////// // CUIDList dialog CUIDList::CUIDList(CWnd* pParent /*=NULL*/) : CDialog(CUIDList::IDD, pParent) { //{{AFX_DATA_INIT(CUIDList) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_pAbstractList=NULL; m_pLEADDicomDS = NULL; } void CUIDList::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CUIDList) DDX_Control(pDX, IDC_LIST, m_List); DDX_Control(pDX, IDC_TYPE, m_Type); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CUIDList, CDialog) //{{AFX_MSG_MAP(CUIDList) ON_NOTIFY(TVN_SELCHANGED, IDC_LIST, OnSelchangedList) ON_BN_CLICKED(IDC_INSERT, OnInsert) ON_BN_CLICKED(IDC_DELETE, OnDelete) ON_BN_CLICKED(IDC_DEFAULT, OnDefault) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CUIDList message handlers BOOL CUIDList::OnInitDialog() { CDialog::OnInitDialog(); HTREEITEM hItem; int nItem; short nRet; //******************************* 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 //************************** m_pLEADDicomDS->EnableMethodErrors = FALSE; nItem = m_Type.AddString("Other"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_OTHER); nItem = m_Type.AddString("Transfer Syntax - Uncompressed Image"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_TRANSFER1); nItem = m_Type.AddString("Transfer Syntax - Compressed Image"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_TRANSFER2); nItem = m_Type.AddString("SOP Class"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_CLASS); nItem = m_Type.AddString("Meta SOP Class"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_META_CLASS); nItem = m_Type.AddString("SOP Instance"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_INSTANCE); nItem = m_Type.AddString("Application Context Name"); m_Type.SetItemData(nItem, DICOM_UID_TYPE_APPLICATION); nRet = m_pLEADDicomDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SysFreeString(bstr); hItem = m_List.InsertItem(cs, TVI_ROOT, TVI_LAST); nRet = m_pLEADDicomDS->MoveNextUID(); } m_List.SelectItem(m_List.GetFirstVisibleItem()); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CUIDList::OnSelchangedList(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; CString szCode; short nRet; szCode = m_List.GetItemText(pNMTreeView->itemNew.hItem); //move to the selected UID BSTR bstr = szCode.AllocSysString(); nRet = m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) DisplayItem(); *pResult = 0; } void CUIDList::DisplayItem() { IDicomUIDItemPtr pCurrentUID = NULL;; //display the items information pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); if(pCurrentUID != NULL) { BSTR bstr1 = pCurrentUID->GetCode(); BSTR bstr2 = pCurrentUID->GetName(); CString cs = bstr1; SetDlgItemText(IDC_CODE, cs); cs = bstr1; SetDlgItemText(IDC_NAME, cs); SysFreeString(bstr1); SysFreeString(bstr2); m_Type.SetCurSel(pCurrentUID->GetType()); } } void CUIDList::OnInsert() { short nRet; HTREEITEM hItem=NULL; CString szCode; CString szName; GetDlgItemText(IDC_CODE, szCode); GetDlgItemText(IDC_NAME, szName); BSTR bstr = szCode.AllocSysString(); nRet = m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { MessageBox("Already Exists!", "Notice", MB_OK); return; } BSTR bstr1 = szCode.AllocSysString(); BSTR bstr2 = szName.AllocSysString(); nRet = m_pLEADDicomDS->InsertUID(bstr1, bstr2, m_Type.GetCurSel()); SysFreeString(bstr1); SysFreeString(bstr2); if(nRet != 0) { MessageBox("Error", "Error", MB_OK); return; } IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); pCurrentUID->Type = m_Type.GetCurSel(); DisplayItem(); //add item to the List hItem = m_List.InsertItem(szCode, TVI_ROOT, TVI_LAST); //also, insert it into the abstract list long nType; nType = pCurrentUID->GetType(); if((nType == DICOM_UID_TYPE_CLASS)||(nType == DICOM_UID_TYPE_META_CLASS))// Is it an Abstract Syntax? { BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SysFreeString(bstr); m_pAbstractList->AddString(cs); } m_List.RedrawWindow(); m_List.SelectItem(hItem); } void CUIDList::OnDelete() { CString szCode; short nRet; HTREEITEM hItem=NULL; hItem = m_List.GetSelectedItem(); if(hItem) { szCode = m_List.GetItemText(hItem); //move to the selected UID BSTR bstr = szCode.AllocSysString(); nRet = m_pLEADDicomDS->FindUID(bstr); SysFreeString(bstr); if(nRet == 0) { //delete it m_pLEADDicomDS->DeleteUID(); DisplayItem(); //remove it from the list view control m_List.DeleteItem(hItem); //remove it from the abstract list as well long nType; int index; IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); nType = pCurrentUID->GetType(); if((nType == DICOM_UID_TYPE_CLASS)||(nType == DICOM_UID_TYPE_META_CLASS))// Is it an Abstract Syntax? { BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SysFreeString(bstr); index = m_pAbstractList->FindStringExact(0, cs); if(index != LB_ERR) m_pAbstractList->DeleteString(index); } } else MessageBox("Error", "Error", MB_OK); } } void CUIDList::OnDefault() { HTREEITEM hItem; short nRet; m_List.DeleteAllItems(); m_pLEADDicomDS->DefaultUID(); nRet = m_pLEADDicomDS->MoveFirstUID(); while(nRet == 0) { IDicomUIDItemPtr pCurrentUID = m_pLEADDicomDS->GetCurrentUID(); BSTR bstr = pCurrentUID->GetCode(); CString cs = bstr; SysFreeString(bstr); hItem = m_List.InsertItem(cs, TVI_ROOT, TVI_LAST); nRet = m_pLEADDicomDS->MoveNextUID(); } m_List.SelectItem(m_List.GetFirstVisibleItem()); } void CUIDList::OnClose() { if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); m_pLEADDicomDS=NULL; CDialog::OnClose(); }