// IBDlg.cpp : implementation file // #include "stdafx.h" #include "cldprn32.h" #include "IBDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CImageBoxDlg dialog CImageBoxDlg::CImageBoxDlg(CImageBox& ImageBox, CTreeCtrl& PresentationLUTsTree, CTreeCtrl& OverlayBoxesTree, CWnd* pParent /*=NULL*/) : CDialog(CImageBoxDlg::IDD, pParent), m_ImageBox(ImageBox), m_PresentationLUTsTree(PresentationLUTsTree), m_OverlayBoxesTree(OverlayBoxesTree), m_bGrayscaleImageBox(TRUE), m_PolarityChkBox(IDC_COMBO_POLARITY), m_MagnificationTypeChkBox(IDC_COMBO_MAGNIFICATIONTYPE), m_SmoothingTypeChkBox(IDC_EDIT_SMOOTHINGTYPE), m_MinDensityChkBox(IDC_EDIT_MINDENSITY), m_MaxDensityChkBox(IDC_EDIT_MAXDENSITY), m_ConfigurationInformationChkBox(IDC_EDIT_CONFIGURATIONINFORMATION), m_RequestedImageSizeChkBox(IDC_EDIT_REQUESTEDIMAGESIZE), m_ReqDecimateCropBehaviorChkBox(IDC_COMBO_REQUESTEDDECIMATECROPBEHAVIOR), m_ReferencedPresentationLUTChkBox(IDC_COMBO_REFERENCEDPRESENTATIONLUT), m_ReferencedImageOverlayBoxChkBox(IDC_COMBO_REFERENCEDIMAGEOVERLAYBOX) { //{{AFX_DATA_INIT(CImageBoxDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void CImageBoxDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CImageBoxDlg) DDX_Control(pDX, IDC_COMBO_REFERENCEDIMAGEOVERLAYBOX, m_ReferencedImageOverlayBoxCombo); DDX_Control(pDX, IDC_COMBO_REFERENCEDPRESENTATIONLUT, m_ReferencedPresentationLUTCombo); DDX_Control(pDX, IDC_COMBO_REQUESTEDDECIMATECROPBEHAVIOR, m_ReqDecimateCropBehaviorCombo); DDX_Control(pDX, IDC_COMBO_MAGNIFICATIONTYPE, m_MagnificationTypeCombo); DDX_Control(pDX, IDC_COMBO_POLARITY, m_PolarityCombo); DDX_Control(pDX, IDC_CHECK_POLARITY, m_PolarityChkBox); DDX_Control(pDX, IDC_CHECK_MAGNIFICATIONTYPE, m_MagnificationTypeChkBox); DDX_Control(pDX, IDC_CHECK_SMOOTHINGTYPE, m_SmoothingTypeChkBox); DDX_Control(pDX, IDC_CHECK_MINDENSITY, m_MinDensityChkBox); DDX_Control(pDX, IDC_CHECK_MAXDENSITY, m_MaxDensityChkBox); DDX_Control(pDX, IDC_CHECK_CONFIGURATIONINFORMATION, m_ConfigurationInformationChkBox); DDX_Control(pDX, IDC_CHECK_REQUESTEDIMAGESIZE, m_RequestedImageSizeChkBox); DDX_Control(pDX, IDC_CHECK_REQUESTEDDECIMATECROPBEHAVIOR, m_ReqDecimateCropBehaviorChkBox); DDX_Control(pDX, IDC_CHECK_REFERENCEDPRESENTATIONLUT, m_ReferencedPresentationLUTChkBox); DDX_Control(pDX, IDC_CHECK_REFERENCEDIMAGEOVERLAYBOX, m_ReferencedImageOverlayBoxChkBox); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CImageBoxDlg, CDialog) //{{AFX_MSG_MAP(CImageBoxDlg) ON_CBN_SELCHANGE(IDC_COMBO_MAGNIFICATIONTYPE, OnSelChangeComboMagnificationType) ON_BN_CLICKED(IDC_BUTTON_NOIMAGE, OnButtonNoImage) ON_BN_CLICKED(IDC_BUTTON_UPDATE, OnButtonUpdate) ON_BN_CLICKED(IDC_BUTTON_SETIMAGE, OnButtonSetImage) ON_WM_DESTROY() //}}AFX_MSG_MAP END_MESSAGE_MAP() void CImageBoxDlg::InitializeFields() { // Image Position SetDlgItemInt(IDC_EDIT_IMAGEPOSITION, m_ImageBox.m_uImagePosition, FALSE); // Polarity m_PolarityCombo.AddString(TEXT("NORMAL")); m_PolarityCombo.AddString(TEXT("REVERSE")); m_PolarityCombo.SetCurSel(0); m_PolarityCombo.SelectString(-1, m_ImageBox.m_sPolarity); // Magnification Type m_MagnificationTypeCombo.AddString(TEXT("REPLICATE")); m_MagnificationTypeCombo.AddString(TEXT("BILINEAR")); m_MagnificationTypeCombo.AddString(TEXT("CUBIC")); m_MagnificationTypeCombo.AddString(TEXT("NONE")); m_MagnificationTypeCombo.SetCurSel(0); m_MagnificationTypeCombo.SelectString(-1, m_ImageBox.m_sMagnificationType); // Smoothing Type SetDlgItemText(IDC_EDIT_SMOOTHINGTYPE, m_ImageBox.m_sSmoothingType); UpdateSmoothingTypeControlsState(); // Min Density if (m_ImageBox.m_iMinDensity >= 0) { SetDlgItemInt(IDC_EDIT_MINDENSITY, m_ImageBox.m_iMinDensity, FALSE); } // Max Density if (m_ImageBox.m_iMaxDensity >= 0) { SetDlgItemInt(IDC_EDIT_MAXDENSITY, m_ImageBox.m_iMaxDensity, FALSE); } // Configuration Information SetDlgItemText(IDC_EDIT_CONFIGURATIONINFORMATION, m_ImageBox.m_sConfigurationInformation); // Requested Image Size if (m_ImageBox.m_dRequestedImageSize >= 0) { CString sRequestedImageSize; sRequestedImageSize.Format(TEXT("%g"), m_ImageBox.m_dRequestedImageSize); SetDlgItemText(IDC_EDIT_REQUESTEDIMAGESIZE, sRequestedImageSize); } // Req. Decimate/Crop Behavior m_ReqDecimateCropBehaviorCombo.AddString(TEXT("DECIMATE")); m_ReqDecimateCropBehaviorCombo.AddString(TEXT("CROP")); m_ReqDecimateCropBehaviorCombo.AddString(TEXT("FAIL")); m_ReqDecimateCropBehaviorCombo.SetCurSel(0); m_ReqDecimateCropBehaviorCombo.SelectString(-1, m_ImageBox.m_sRequestedDecimateCropBehavior); // Referenced Presentation LUT if (m_PresentationLUTsTree.GetCount() <= 0) { m_ReferencedPresentationLUTChkBox.m_bChecked = FALSE; m_ReferencedPresentationLUTChkBox.EnableWindow(FALSE); } else { int iIndex, iCurSel; LPCTSTR pszInstanceUID; CString sItemText; // If the Image Box references a Presentation LUT, then updating the Image Box while // specifying an empty string will remove that reference. iIndex = m_ReferencedPresentationLUTCombo.AddString(TEXT("")); m_ReferencedPresentationLUTCombo.SetItemData(iIndex, 0); iCurSel = 0; HTREEITEM hPresLUTItem = m_PresentationLUTsTree.GetRootItem(); while (hPresLUTItem) { sItemText = m_PresentationLUTsTree.GetItemText(hPresLUTItem); pszInstanceUID = (LPCTSTR) m_PresentationLUTsTree.GetItemData(hPresLUTItem); iIndex = m_ReferencedPresentationLUTCombo.AddString(sItemText); m_ReferencedPresentationLUTCombo.SetItemData(iIndex, DWORD(pszInstanceUID)); if (m_ImageBox.m_sRefPresLUTInstanceUID == pszInstanceUID) { iCurSel = iIndex; } hPresLUTItem = m_PresentationLUTsTree.GetNextItem(hPresLUTItem, TVGN_NEXT); } m_ReferencedPresentationLUTCombo.SetCurSel(iCurSel); } m_ReferencedPresentationLUTChkBox.Initialize(); // Referenced Image Overlay Box if (m_OverlayBoxesTree.GetCount() <= 0) { m_ReferencedImageOverlayBoxChkBox.m_bChecked = FALSE; m_ReferencedImageOverlayBoxChkBox.EnableWindow(FALSE); } else { int iIndex, iCurSel; LPCTSTR pszInstanceUID; CString sItemText; CImageOverlayBox* pImageOverlayBox; // If the Image Box references an Image Overlay Box, then updating the Image Box while // specifying an empty string will remove that reference. iIndex = m_ReferencedImageOverlayBoxCombo.AddString(TEXT("")); m_ReferencedImageOverlayBoxCombo.SetItemData(iIndex, 0); iCurSel = 0; HTREEITEM hOverlayBoxItem = m_OverlayBoxesTree.GetRootItem(); while (hOverlayBoxItem) { sItemText = m_OverlayBoxesTree.GetItemText(hOverlayBoxItem); pImageOverlayBox = (CImageOverlayBox*) m_OverlayBoxesTree.GetItemData(hOverlayBoxItem); if (pImageOverlayBox) { pszInstanceUID = pImageOverlayBox->m_sImageOverlayBoxInstanceUID; } else { pszInstanceUID = NULL; } iIndex = m_ReferencedImageOverlayBoxCombo.AddString(sItemText); m_ReferencedImageOverlayBoxCombo.SetItemData(iIndex, DWORD(pszInstanceUID)); if (m_ImageBox.m_sRefImageOverlayBoxInstanceUID == pszInstanceUID) { iCurSel = iIndex; } hOverlayBoxItem = m_OverlayBoxesTree.GetNextItem(hOverlayBoxItem, TVGN_NEXT); } m_ReferencedImageOverlayBoxCombo.SetCurSel(iCurSel); } m_ReferencedImageOverlayBoxChkBox.Initialize(); // Image m_sInitialImageFilename = m_ImageBox.m_sImageFilename; if (m_ImageBox.m_sImageFilename.GetLength()) { if (!DisplayImage((L_CHAR*)(LPCTSTR) m_ImageBox.m_sImageFilename)) { m_ImageBox.m_sImageFilename = TEXT(""); } } GetDlgItem(IDC_BUTTON_NOIMAGE)->EnableWindow(m_ImageBox.m_sImageFilename.GetLength()); } BOOL CImageBoxDlg::DisplayImage(L_CHAR* pszFilename) { L_INT iRet; // This is just to ensure that the file specified is really a DICOM file LDicomDS DataSet; iRet = DataSet.LoadDS(pszFilename, DS_LOAD_CLOSE); if (iRet != DICOM_SUCCESS) { return FALSE; } iRet = m_BitmapWindow.Load(pszFilename); if (iRet != SUCCESS) { return FALSE; } m_BitmapWindow.SetZoomMode(ZOOM_FIT); return TRUE; } void CImageBoxDlg::UpdateSmoothingTypeControlsState() { // The Smoothing Type is only valid for Magnification Type = CUBIC if (m_MagnificationTypeChkBox.GetCheck() == 1) { CString sValue; m_MagnificationTypeCombo.GetWindowText(sValue); m_SmoothingTypeChkBox.EnableWindow(sValue == TEXT("CUBIC")); } else { m_SmoothingTypeChkBox.EnableWindow(FALSE); } } ///////////////////////////////////////////////////////////////////////////// // CImageBoxDlg message handlers BOOL CImageBoxDlg::OnInitDialog() { CDialog::OnInitDialog(); m_PolarityChkBox.m_bChecked = m_ImageBox.m_bPolarityChecked; m_MagnificationTypeChkBox.m_bChecked = m_ImageBox.m_bMagnificationTypeChecked; m_SmoothingTypeChkBox.m_bChecked = m_ImageBox.m_bSmoothingTypeChecked; m_MinDensityChkBox.m_bChecked = m_ImageBox.m_bMinDensityChecked; m_MaxDensityChkBox.m_bChecked = m_ImageBox.m_bMaxDensityChecked; m_ConfigurationInformationChkBox.m_bChecked = m_ImageBox.m_bConfigurationInformationChecked; m_RequestedImageSizeChkBox.m_bChecked = m_ImageBox.m_bRequestedImageSizeChecked; m_ReqDecimateCropBehaviorChkBox.m_bChecked = m_ImageBox.m_bRequestedDecimateCropBehaviorChecked; m_ReferencedPresentationLUTChkBox.m_bChecked = m_ImageBox.m_bRefPresLUTInstanceUIDChecked; m_ReferencedImageOverlayBoxChkBox.m_bChecked = m_ImageBox.m_bRefImageOverlayBoxInstanceUIDChecked; m_PolarityChkBox.Initialize(); m_MagnificationTypeChkBox.Initialize(); m_SmoothingTypeChkBox.Initialize(); m_MinDensityChkBox.Initialize(); m_MaxDensityChkBox.Initialize(); m_ConfigurationInformationChkBox.Initialize(); m_RequestedImageSizeChkBox.Initialize(); m_ReqDecimateCropBehaviorChkBox.Initialize(); // Min Density, Max Density, Configuration Information, and Referenced Presentation LUT // Sequence are defined only for Grayscale Image Boxes m_MinDensityChkBox.EnableWindow(m_bGrayscaleImageBox); m_MaxDensityChkBox.EnableWindow(m_bGrayscaleImageBox); m_ConfigurationInformationChkBox.EnableWindow(m_bGrayscaleImageBox); m_ReferencedPresentationLUTChkBox.EnableWindow(m_bGrayscaleImageBox); m_BitmapWindow.SetWndHandle(GetDlgItem(IDC_STATIC_IMAGE)->m_hWnd); m_BitmapWindow.SetPatternBackColor(RGB(0, 0, 0)); InitializeFields(); LDialogBase::Initialize(0); return TRUE; } void CImageBoxDlg::OnDestroy() { CDialog::OnDestroy(); LDialogBase::Free(); } void CImageBoxDlg::OnButtonSetImage() { LDialogFile DialogFile; OPENFILENAME ofn; ZeroMemory(&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); ofn.lpstrFilter = TEXT("DICOM Files (*.dic; *.dcm)\0*.dic;*.dcm\0All Files (*.*)\0*.*\0"); ofn.nFilterIndex = 1; ofn.lpstrTitle = TEXT("Select Image"); DialogFile.SetOpenFileName(&ofn); OPENDLGPARAMS odp; ZeroMemory(&odp, sizeof(OPENDLGPARAMS)); odp.uStructSize = sizeof(OPENDLGPARAMS); odp.uDlgFlags = DLG_OPEN_SHOW_FILEINFO; odp.bPreviewEnabled = TRUE; DialogFile.SetOpenParams(&odp); DialogFile.EnablePreview(TRUE); if (DialogFile.DoModalOpen(m_hWnd) != SUCCESS_DLG_OK) { return; } L_CHAR szFilename[MAX_PATH]; DialogFile.GetFileName(szFilename, sizeof(szFilename)); if (!DisplayImage(szFilename)) { MessageBox(TEXT("Failed to open the specified file."), TEXT("Print SCU"), MB_ICONERROR); return; } m_ImageBox.m_sImageFilename = szFilename; GetDlgItem(IDC_BUTTON_NOIMAGE)->EnableWindow(TRUE); } void CImageBoxDlg::OnButtonNoImage() { m_BitmapWindow.SetHandle(NULL); m_BitmapWindow.Repaint(); m_ImageBox.m_sImageFilename = TEXT(""); GetDlgItem(IDC_BUTTON_NOIMAGE)->EnableWindow(FALSE); } void CImageBoxDlg::OnButtonUpdate() { CString sValue; // Polarity m_PolarityCombo.GetWindowText(m_ImageBox.m_sPolarity); m_ImageBox.m_bPolarityChecked = m_PolarityChkBox.m_bChecked; // Magnification Type m_MagnificationTypeCombo.GetWindowText(m_ImageBox.m_sMagnificationType); m_ImageBox.m_bMagnificationTypeChecked = m_MagnificationTypeChkBox.m_bChecked; // Smoothing Type GetDlgItemText(IDC_EDIT_SMOOTHINGTYPE, m_ImageBox.m_sSmoothingType); m_ImageBox.m_bSmoothingTypeChecked = m_SmoothingTypeChkBox.m_bChecked; // Min Density GetDlgItemText(IDC_EDIT_MINDENSITY, sValue); if (!m_MinDensityChkBox.m_bChecked && sValue.IsEmpty()) { m_ImageBox.m_iMinDensity = -1; } else { m_ImageBox.m_iMinDensity = atoi(sValue); } m_ImageBox.m_bMinDensityChecked = m_MinDensityChkBox.m_bChecked; // Max Density GetDlgItemText(IDC_EDIT_MAXDENSITY, sValue); if (!m_MaxDensityChkBox.m_bChecked && sValue.IsEmpty()) { m_ImageBox.m_iMaxDensity = -1; } else { m_ImageBox.m_iMaxDensity = atoi(sValue); } m_ImageBox.m_bMaxDensityChecked = m_MaxDensityChkBox.m_bChecked; // Configuration Information GetDlgItemText(IDC_EDIT_CONFIGURATIONINFORMATION, m_ImageBox.m_sConfigurationInformation); m_ImageBox.m_bConfigurationInformationChecked = m_ConfigurationInformationChkBox.m_bChecked; // Requested Image Size GetDlgItemText(IDC_EDIT_REQUESTEDIMAGESIZE, sValue); if (!m_RequestedImageSizeChkBox.m_bChecked && sValue.IsEmpty()) { m_ImageBox.m_dRequestedImageSize = -1; } else { m_ImageBox.m_dRequestedImageSize = atof(sValue); } m_ImageBox.m_bRequestedImageSizeChecked = m_RequestedImageSizeChkBox.m_bChecked; // Req. Decimate/Crop Behavior m_ReqDecimateCropBehaviorCombo.GetWindowText(m_ImageBox.m_sRequestedDecimateCropBehavior); m_ImageBox.m_bRequestedDecimateCropBehaviorChecked = m_ReqDecimateCropBehaviorChkBox.m_bChecked; LPCTSTR pszInstanceUID; int iCurSel; // Referenced Presentation LUT pszInstanceUID = NULL; iCurSel = m_ReferencedPresentationLUTCombo.GetCurSel(); if (iCurSel >= 0) { pszInstanceUID = (LPCTSTR) m_ReferencedPresentationLUTCombo.GetItemData(iCurSel); } m_ImageBox.m_sRefPresLUTInstanceUID = pszInstanceUID ? pszInstanceUID : TEXT(""); m_ImageBox.m_bRefPresLUTInstanceUIDChecked = m_ReferencedPresentationLUTChkBox.m_bChecked; // Referenced Image Overlay Box pszInstanceUID = NULL; iCurSel = m_ReferencedImageOverlayBoxCombo.GetCurSel(); if (iCurSel >= 0) { pszInstanceUID = (LPCTSTR) m_ReferencedImageOverlayBoxCombo.GetItemData(iCurSel); } m_ImageBox.m_sRefImageOverlayBoxInstanceUID = pszInstanceUID ? pszInstanceUID : TEXT(""); m_ImageBox.m_bRefImageOverlayBoxInstanceUIDChecked = m_ReferencedImageOverlayBoxChkBox.m_bChecked; CDialog::OnOK(); } void CImageBoxDlg::OnCancel() { m_ImageBox.m_sImageFilename = m_sInitialImageFilename; CDialog::OnCancel(); } BOOL CImageBoxDlg::OnCommand(WPARAM wParam, LPARAM lParam) { if (wParam == IDC_CHECK_MAGNIFICATIONTYPE) { UpdateSmoothingTypeControlsState(); } return CDialog::OnCommand(wParam, lParam); } void CImageBoxDlg::OnSelChangeComboMagnificationType() { UpdateSmoothingTypeControlsState(); }