// IOTabDlg.cpp : implementation file // #include "stdafx.h" // #include "DICOM.h" // #include "IOTabDlg.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."; ///////////////////////////////////////////////////////////////////////////// // CIODTableDlg dialog CIODTableDlg::CIODTableDlg(CWnd* pParent /*=NULL*/) : CDialog(CIODTableDlg::IDD, pParent) { //{{AFX_DATA_INIT(CIODTableDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CIODTableDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CIODTableDlg) DDX_Control(pDX, IDC_EDIT7, m_Text7); 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_DESCTEXT, m_DescText); DDX_Control(pDX, IDC_TREE1, m_TreeView1); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CIODTableDlg, CDialog) //{{AFX_MSG_MAP(CIODTableDlg) 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_BN_CLICKED(IDC_BUTTON6, OnButton6) ON_NOTIFY(TVN_SELCHANGED, IDC_TREE1, OnSelchangedTree1) ON_BN_CLICKED(IDC_FIRST, OnFirst) ON_BN_CLICKED(IDC_LAST, OnLast) ON_BN_CLICKED(IDC_NEXT, OnNext) ON_BN_CLICKED(IDC_PARENT, OnParent) ON_BN_CLICKED(IDC_CHILD, OnChild) ON_BN_CLICKED(IDC_PREV, OnPrev) ON_BN_CLICKED(IDC_ROOT, OnRoot) ON_WM_CLOSE() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CIODTableDlg message handlers BOOL CIODTableDlg::OnInitDialog() { CDialog::OnInitDialog(); 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; FillTree(); DisplayNode(); m_TreeView1.SetFocus(); return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE } void CIODTableDlg::FillTree() { //move to root of tree m_pLEADDicomDS->MoveFirstIOD(FALSE); //move to first IOD in tree m_pLEADDicomDS->MoveRootIOD(); //get the root of this IOD //now, add the IOD items FillSubTree(NULL); m_hSelectedItem = m_TreeView1.GetRootItem(); } void CIODTableDlg::FillSubTree(HTREEITEM hParent) { short nRet; HTREEITEM hItem=NULL; CString szText; //add the node to the tree IDicomIODItemPtr pCurrentIOD=NULL; pCurrentIOD = m_pLEADDicomDS->GetCurrentIOD(); szText = (LPCSTR)pCurrentIOD->GetName(); if(hParent) hItem = m_TreeView1.InsertItem(szText, hParent); else hItem = m_TreeView1.InsertItem(szText); m_TreeView1.SetItemData(hItem, pCurrentIOD->GethIOD()); nRet = m_pLEADDicomDS->MoveChildIOD(); //does this node have a child? if(nRet == 0) FillSubTree(hItem); //move to next node in same level (if one) nRet = m_pLEADDicomDS->MoveNextIOD(TRUE); if(nRet == 0) FillSubTree(hParent); else { //move back to parent m_pLEADDicomDS->MoveParentIOD(); } } void CIODTableDlg::DisplayNode() { IDicomIODItemPtr pCurrentIOD=NULL; CString szDisplay; pCurrentIOD = m_pLEADDicomDS->GetCurrentIOD(); szDisplay.Format("%ld", pCurrentIOD->GetCode()); m_Text1.SetWindowText(szDisplay); szDisplay = (LPCSTR)pCurrentIOD->GetName(); m_Text2.SetWindowText(szDisplay); szDisplay.Format("%d", pCurrentIOD->GetType()); m_Text3.SetWindowText(szDisplay); szDisplay.Format("%d", pCurrentIOD->GetUsage()); m_Text4.SetWindowText(szDisplay); szDisplay = (LPCSTR)pCurrentIOD->GetDescription(); m_Text5.SetWindowText(szDisplay); m_DescText.SetWindowText(szDisplay); } void CIODTableDlg::OnButton1() { short nRet; HCURSOR hOldCursor=NULL; nRet = MessageBox("This may take a few seconds, are you sure?","", MB_YESNO); if(nRet == IDYES) { m_TreeView1.DeleteAllItems(); hOldCursor = SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT))); m_pLEADDicomDS->DefaultIOD(); FillTree(); SetCursor(hOldCursor); DisplayNode(); } } void CIODTableDlg::OnButton2() { m_TreeView1.DeleteAllItems(); //clear all IOD items m_pLEADDicomDS->ResetIOD(); } void CIODTableDlg::OnButton3() { if(m_TreeView1.GetCount() == 0) return; HTREEITEM hItem=NULL; HTREEITEM hParent=NULL; BOOL bChild; BOOL bInsert; long lCode; short nType; short nUsage; long hIOD; short nRet; CString szCode; CString szType; CString szName; CString szUsage; CString szDesc; IDicomIODItemPtr pCurrentIOD=NULL; bInsert = FALSE; bChild = IsDlgButtonChecked(IDC_CHECK1); hParent = m_TreeView1.GetSelectedItem(); m_Text1.GetWindowText(szCode); lCode = atoi(szCode); m_Text2.GetWindowText(szName); m_Text3.GetWindowText(szType); nType = atoi(szType); m_Text4.GetWindowText(szUsage); nUsage = atoi(szUsage); m_Text5.GetWindowText(szDesc); pCurrentIOD = m_pLEADDicomDS->GetCurrentIOD(); hIOD = pCurrentIOD->GethIOD(); if(nType == DICOM_IOD_TYPE_CLASS) { hParent = NULL; bChild = FALSE; } //does an IOD already exist on that level? if(bChild) { //if the selected item has a child, move to that level nRet = m_pLEADDicomDS->MoveChildIOD(); if(nRet != 0) bInsert = TRUE; else //check this level to see if IOD already exists { m_pLEADDicomDS->MoveFirstIOD(TRUE); nRet = m_pLEADDicomDS->FindIOD(lCode, nType, TRUE); if(nRet != 0) bInsert = TRUE; //move back to parent level m_pLEADDicomDS->MoveParentIOD(); } } else { m_pLEADDicomDS->MoveFirstIOD(TRUE); nRet = m_pLEADDicomDS->FindIOD(lCode, nType, TRUE); if(nRet != 0) bInsert = TRUE; m_pLEADDicomDS->SetCurrentIOD(hIOD); } //allow user to insert item at the same level as the current or as child if(bInsert) { BSTR bstr1 = szName.AllocSysString(); BSTR bstr2 = szDesc.AllocSysString(); m_pLEADDicomDS->InsertIOD(bChild, nType, lCode, bstr1, nUsage, bstr2); SysFreeString(bstr1); SysFreeString(bstr2); pCurrentIOD = m_pLEADDicomDS->GetCurrentIOD(); CString szText; szText = (LPCSTR)pCurrentIOD->GetName(); //add the node to the tree if(bChild) hItem = m_TreeView1.InsertItem(szText ,hParent); else hItem = m_TreeView1.InsertItem(szText ,m_TreeView1.GetParentItem(hParent)); m_TreeView1.SetItemData(hItem, pCurrentIOD->GethIOD()); } else AfxMessageBox("Already exists"); } void CIODTableDlg::OnButton4() { if(m_TreeView1.GetCount() == 0) return; m_pLEADDicomDS->SetCurrentIOD((long)m_TreeView1.GetItemData(m_hSelectedItem)); m_pLEADDicomDS->DeleteIOD(); DisplayNode(); //remove it from the list view control m_TreeView1.DeleteItem(m_hSelectedItem); m_hSelectedItem = m_TreeView1.GetSelectedItem(); } void CIODTableDlg::OnButton5() { if(m_TreeView1.GetCount() == 0) return; CString szName; IDicomIODItemPtr pCurrentIOD=NULL; m_pLEADDicomDS->SetCurrentIOD((long)m_TreeView1.GetItemData(m_hSelectedItem)); //change the name m_Text6.GetWindowText(szName); BSTR bstr = szName.AllocSysString(); m_pLEADDicomDS->SetIODName(bstr); SysFreeString(bstr); pCurrentIOD = m_pLEADDicomDS->GetCurrentIOD(); //update it in the tree view control CString cs = (LPCSTR)pCurrentIOD->GetName(); m_TreeView1.SetItemText(m_hSelectedItem, cs); DisplayNode(); } void CIODTableDlg::OnButton6() { if(m_TreeView1.GetCount() == 0) return; CString szDesc; m_pLEADDicomDS->SetCurrentIOD((long)m_TreeView1.GetItemData(m_hSelectedItem)); //change the name m_Text7.GetWindowText(szDesc); BSTR bstr = szDesc.AllocSysString(); m_pLEADDicomDS->SetIODDescription(bstr); SysFreeString(bstr); DisplayNode(); } void CIODTableDlg::OnSelchangedTree1(NMHDR* pNMHDR, LRESULT* pResult) { NM_TREEVIEW* pNMTreeView = (NM_TREEVIEW*)pNMHDR; long hIOD = 0; hIOD = m_TreeView1.GetItemData(pNMTreeView->itemNew.hItem); m_hSelectedItem = m_TreeView1.GetSelectedItem(); m_pLEADDicomDS->SetCurrentIOD(hIOD); if(hIOD) DisplayNode(); *pResult = 0; } void CIODTableDlg::OnFirst() { HTREEITEM hTemp; hTemp = m_TreeView1.GetPrevSiblingItem(m_hSelectedItem); while (hTemp != NULL) { m_hSelectedItem = hTemp; hTemp = m_TreeView1.GetPrevSiblingItem(m_hSelectedItem); } if (m_hSelectedItem) { m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnLast() { HTREEITEM hTemp; hTemp = m_TreeView1.GetNextSiblingItem(m_hSelectedItem); while (hTemp != NULL) { m_hSelectedItem = hTemp; hTemp = m_TreeView1.GetNextSiblingItem(m_hSelectedItem); } if (m_hSelectedItem) { m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnNext() { HTREEITEM hTemp; hTemp = m_TreeView1.GetNextSiblingItem(m_hSelectedItem); if (hTemp) { m_hSelectedItem = hTemp; m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnParent() { HTREEITEM hTemp; hTemp = m_TreeView1.GetParentItem(m_hSelectedItem); if (hTemp) { m_hSelectedItem = hTemp; m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnChild() { HTREEITEM hTemp; hTemp = m_TreeView1.GetChildItem(m_hSelectedItem); if (hTemp) { m_hSelectedItem = hTemp; m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnPrev() { HTREEITEM hTemp; hTemp = m_TreeView1.GetPrevSiblingItem(m_hSelectedItem); if (hTemp) { m_hSelectedItem = hTemp; m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnRoot() { HTREEITEM hTemp; hTemp = m_TreeView1.GetParentItem(m_hSelectedItem); while (hTemp != NULL) { m_hSelectedItem = hTemp; hTemp = m_TreeView1.GetParentItem(m_hSelectedItem); } if (m_hSelectedItem) { m_TreeView1.EnsureVisible(m_hSelectedItem); m_TreeView1.SelectItem(m_hSelectedItem); } m_TreeView1.SetFocus(); } void CIODTableDlg::OnClose() { if(m_pLEADDicomDS) m_pLEADDicomDS->Release(); CDialog::OnClose(); }