// MainFrm.cpp : implementation of the CMainFrame class // #include "stdafx.h" #include "Overlay.h" #include "MainFrm.h" #include "LeftPaneWnd.h" #include "RightPaneWnd.h" #include "OverlayAttribDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif #include "OverlayView.h" #ifndef RECTWIDTH #define RECTWIDTH(p) (((LPRECT) (p))->right - ((LPRECT) (p))->left) #endif #ifndef RECTHEIGHT /* ABS() is used because a PM rect top and bottom are reversed from Windows */ #define RECTHEIGHT(p) abs(((LPRECT) (p))->bottom - ((LPRECT) (p))->top) #endif extern COverlayApp theApp; ///////////////////////////////////////////////////////////////////////////// // CMainFrame IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd) BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ON_WM_CREATE() ON_COMMAND(ID_FILE_OPEN, OnFileOpen) ON_WM_SIZE() ON_COMMAND(ID_OVERLAYS_CHANGEOVERLAYCOLOR, OnOverlaysChangeOverlayColor) ON_COMMAND(ID_OVERLAYS_SAVEOVERLAY, OnOverlaysSaveOverlay) ON_COMMAND(ID_OVERLAYS_SHOWOVERLAYATTRIBUTES, OnOverlaysShowOverlayAttributes) ON_COMMAND(ID_OVERLAYS_SHOWOVERLAY, OnOverlaysShowOverlay) ON_UPDATE_COMMAND_UI(ID_OVERLAYS_SHOWOVERLAY, OnUpdateOverlaysShowOverlay) ON_COMMAND(ID_OVERLAYS_INSERTOVERLAY, OnOverlaysInsertOverlay) ON_UPDATE_COMMAND_UI(ID_OVERLAYS_INSERTOVERLAY, OnUpdateOverlaysInsertOverlay) ON_UPDATE_COMMAND_UI(ID_OVERLAYS_SHOWOVERLAYATTRIBUTES, OnUpdateOverlaysShowOverlayAttributes) ON_UPDATE_COMMAND_UI(ID_OVERLAYS_SAVEOVERLAY, OnUpdateOverlaysSaveOverlay) ON_UPDATE_COMMAND_UI(ID_OVERLAYS_CHANGEOVERLAYCOLOR, OnUpdateOverlaysChangeOverlayColor) ON_COMMAND(ID_FILE_SAVE_FILE, OnFileSaveFile) ON_UPDATE_COMMAND_UI(ID_FILE_SAVE_FILE, OnUpdateFileSaveFile) //}}AFX_MSG_MAP END_MESSAGE_MAP() static UINT indicators[] = { ID_SEPARATOR, // status line indicator ID_INDICATOR_CAPS, ID_INDICATOR_NUM, ID_INDICATOR_SCRL, }; ///////////////////////////////////////////////////////////////////////////// // CMainFrame construction/destruction CMainFrame::CMainFrame() { m_pLeftPaneWnd = NULL; m_pRightPaneWnd = NULL; m_hCtl = NULL; m_nSelItemIndex = 0; m_uCount = 0; m_bStatus = TRUE; memset (m_szFileName, 0, sizeof (m_szFileName)); } CMainFrame::~CMainFrame() { // m_DS.ResetDS(); } int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFrameWnd::OnCreate(lpCreateStruct) == -1) return -1; if (!m_wndStatusBar.Create(this) || !m_wndStatusBar.SetIndicators(indicators, sizeof(indicators)/sizeof(UINT))) { TRACE0("Failed to create status bar\n"); return -1; // fail to create } return 0; } BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext) { if (!m_wndSplitter.CreateStatic(this, 1, 2)) { TRACE0("Failed to create splitter window\n"); return FALSE; } CRect rect; GetClientRect(&rect); if (!m_wndSplitter.CreateView(0, 0, RUNTIME_CLASS(CLeftPaneWnd), CSize(180, 0), pContext)) { TRACE0("Failed to create left pane view\n"); return FALSE; } if (!m_wndSplitter.CreateView(0, 1, RUNTIME_CLASS(CRightPaneWnd), CSize(0, 0), pContext)) { TRACE0("Failed to create right pane frame\n"); return FALSE; } // Set the left pane as the active view m_pLeftPaneWnd = (CLeftPaneWnd *)m_wndSplitter.GetPane(0, 0); m_pRightPaneWnd = (CRightPaneWnd *)m_wndSplitter.GetPane(0, 1); SetActiveView((CView*) m_wndSplitter.GetPane(0, 0)); return TRUE; } BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs) { cs.style = WS_OVERLAPPEDWINDOW | WS_CAPTION; cs.lpszName = "Dicomovl COM Demo"; if( !CFrameWnd::PreCreateWindow(cs) ) return FALSE; // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return TRUE; } ///////////////////////////////////////////////////////////////////////////// // CMainFrame diagnostics #ifdef _DEBUG void CMainFrame::AssertValid() const { CFrameWnd::AssertValid(); } void CMainFrame::Dump(CDumpContext& dc) const { CFrameWnd::Dump(dc); } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CMainFrame message handlers void CMainFrame::OnFileOpen() { TCHAR szFilters[] =_T ("DICOM Files|*.dic;*.dcm|All files (*.*)|*.*||"); UNLOCKSUPPORT(m_pRightPaneWnd->m_RasterView.GetRaster()); CFileDialog dlg ( TRUE, _T ("dic"), _T ("*.dic"), OFN_FILEMUSTEXIST | OFN_HIDEREADONLY, szFilters); if (dlg.DoModal () != IDOK) { return; } strcpy (m_szFileName, (CHAR *)(LPCSTR)dlg.GetPathName()); int nRet = theApp.m_pLEADDicomDS->LoadDS((LPCTSTR)m_szFileName, 0); if (nRet != DICOM_SUCCESS) { MessageBox(TEXT("Error loading data set."), TEXT("Error"), MB_OK|MB_ICONERROR); return ; } if (m_pLeftPaneWnd->LoadOverlays () != 0) return; theApp.m_bShowOverlay = TRUE; /* Make the OVERLAY_AUTOPAINT flag always on to automaticaly paint the overlays over the original image */ UINT uFlags = OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_ORIGIN; UINT uAttFlags; for(int i = 0; i < (int)m_uCount; i++) { int nRet = theApp.m_pRasterProcess->GetOverlayAttributes(m_pRightPaneWnd->m_RasterView.GetRaster(), i, uFlags); if (!theApp.m_pRasterProcess->OverlayAttributes->Flags & OVERLAY_AUTOPAINT ) { uAttFlags = theApp.m_pRasterProcess->OverlayAttributes->Flags; uAttFlags |= OVERLAY_AUTOPAINT; theApp.m_pRasterProcess->OverlayAttributes->Flags = uAttFlags ; theApp.m_pRasterProcess->SetOverlayAttributes(m_pRightPaneWnd->m_RasterView.GetRaster(),i, uFlags); } } } void CMainFrame::OnSize(UINT nType, int cx, int cy) { CFrameWnd::OnSize(nType, cx, cy); RECT rcWin; if(m_pLeftPaneWnd) { m_pLeftPaneWnd->GetClientRect(&rcWin); m_pLeftPaneWnd->m_ImageListControl.MoveWindow(0, 0, RECTWIDTH(&rcWin), RECTHEIGHT(&rcWin), TRUE); } if(m_pRightPaneWnd) { m_pRightPaneWnd->GetClientRect(&rcWin); m_pRightPaneWnd->m_RasterView.MoveWindow(0, 0, RECTWIDTH(&rcWin), RECTHEIGHT(&rcWin), TRUE); } } void CMainFrame::OnOverlaysChangeOverlayColor() { int nRet; theApp.m_pRasterClrDlg->PutUIFlags( COLOR_SHOW_CONTEXTHELP | COLOR_SHOW_OLDCOLOR | COLOR_SHOW_NEWCOLOR | COLOR_SHOW_NAME | COLOR_COLORSPACE_SHOW_HUE | COLOR_COLORSPACE_SHOW_BRIGHTNESS | COLOR_COLORSPACE_SHOW_WHEEL | COLOR_COLORSPACE_SHOW_RGB | COLOR_COLORSPACE_SHOW_CMY | COLOR_COLORSPACE_SHOW_CMYK | COLOR_COLORSPACE_SHOW_LAB | COLOR_COLORMODEL_SHOW_RGB | COLOR_COLORMODEL_SHOW_HSB | COLOR_COLORMODEL_SHOW_HLS | COLOR_COLORMODEL_SHOW_CMY | COLOR_COLORMODEL_SHOW_CMYK | COLOR_COLORMODEL_SHOW_LAB ); if (theApp.m_pRasterClrDlg->ShowColorDlg((long)m_hWnd) != 0) return; nRet = theApp.m_pRasterProcess->GetOverlayAttributes(m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex, OVERLAYATTRIBUTES_COLOR); theApp.m_pRasterProcess->OverlayAttributes->Color = theApp.m_pRasterClrDlg->SelectedColor; nRet = theApp.m_pRasterProcess->SetOverlayAttributes(m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex, OVERLAYATTRIBUTES_COLOR); // Update the overlay preview with the new color nRet = theApp.m_pRasterProcess->GetOverlayBitmap(m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex, theApp.m_pRaster, OVERLAY_COPY); // Make the overlay preview looks clearer theApp.m_pRaster->BitmapPalette[1] = theApp.m_pRasterClrDlg->SelectedColor; theApp.m_pRasterProcess->Invert(theApp.m_pRaster); theApp.m_pRasterProcess->Size(theApp.m_pRaster,140, 140, RESIZE_FAVORBLACK); theApp.m_pRasterProcess->Invert(theApp.m_pRaster); CLEADRasterImageListItem item = m_pLeftPaneWnd->m_ImageListControl.Item(m_nSelItemIndex); item.SetBitmap(theApp.m_pRaster->GetBitmap()); m_pLeftPaneWnd->m_ImageListControl.EnsureVisible(m_nSelItemIndex); } void CMainFrame::OnUpdateOverlaysChangeOverlayColor(CCmdUI* pCmdUI) { pCmdUI->Enable (m_uCount > 0 ? TRUE : FALSE); } void CMainFrame::OnOverlaysSaveOverlay() { CHAR szSaveFileName[_MAX_PATH]; int nRet; CFileDialog SaveDlg( FALSE, "bmp", NULL, OFN_OVERWRITEPROMPT, "Windows Bitmap (*.bmp)|*.bmp|"); if (SaveDlg.DoModal()!=IDOK) return; memset (&szSaveFileName, 0, sizeof (&szSaveFileName)); strcpy (szSaveFileName, SaveDlg.GetPathName().GetBuffer(SaveDlg.GetPathName().GetLength())); nRet = theApp.m_pRasterProcess->GetOverlayBitmap(m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex,theApp.m_pRaster, OVERLAY_COPY); if(nRet == 0) { nRet = theApp.m_pRasterIO->Save(theApp.m_pRaster, (LPSTR)szSaveFileName, (RasterFileConstants)FILE_BMP, 1, (QFactorConstants)2, 0); if (nRet != 0) MessageBox ("Error saving overlay bitmap.", "Error", MB_OK|MB_ICONERROR); } else { MessageBox ("Error saving overlay bitmap.", "Error", MB_OK|MB_ICONERROR); } } void CMainFrame::OnUpdateOverlaysSaveOverlay(CCmdUI* pCmdUI) { pCmdUI->Enable (m_uCount > 0 ? TRUE : FALSE); } void CMainFrame::OnOverlaysShowOverlayAttributes() { COverlayAttribDlg* pOverlayAttribDlg = new COverlayAttribDlg(this); pOverlayAttribDlg->DoModal(); } void CMainFrame::OnUpdateOverlaysShowOverlayAttributes(CCmdUI* pCmdUI) { pCmdUI->Enable (m_uCount > 0 ? TRUE : FALSE); } void CMainFrame::OnOverlaysShowOverlay() { UINT uFlags = OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_ORIGIN; int nRet; UINT uAttFlags; theApp.m_bShowOverlay = !theApp.m_bShowOverlay; nRet = theApp.m_pRasterProcess->GetOverlayAttributes(m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex, uFlags); uAttFlags = theApp.m_pRasterProcess->OverlayAttributes->Flags; if (theApp.m_bShowOverlay) uAttFlags |= OVERLAY_AUTOPAINT; else uAttFlags &= ~OVERLAY_AUTOPAINT; theApp.m_pRasterProcess->OverlayAttributes->Flags = uAttFlags; theApp.m_pRasterProcess->SetOverlayAttributes (m_pRightPaneWnd->m_RasterView.GetRaster(), m_nSelItemIndex, uFlags); m_pRightPaneWnd->m_RasterView.ForceRepaint(); } void CMainFrame::OnUpdateOverlaysShowOverlay(CCmdUI* pCmdUI) { if (m_uCount > 0) { pCmdUI->Enable (TRUE); pCmdUI->SetCheck (theApp.m_bShowOverlay ? TRUE : FALSE); } else pCmdUI->Enable (FALSE); } void CMainFrame::OnOverlaysInsertOverlay() { LPSTR pszFilter = "All files(*.*)|*.*|"; CHAR szFileName[_MAX_PATH]; CHAR szItemText[20]; int nRet; memset (&szFileName, 0, sizeof (szFileName)); memset (&szItemText, 0, sizeof (szItemText)); CFileDialog OpenDlg( TRUE, NULL, NULL, OFN_FILEMUSTEXIST, pszFilter); if (OpenDlg.DoModal()!=IDOK) return; // Load the overlay bitmap strcpy (szFileName, OpenDlg.GetPathName().GetBuffer(OpenDlg.GetPathName().GetLength())); nRet = theApp.m_pRasterIO->Load(theApp.m_pRaster,szFileName, 1, 0,1); if(nRet != 0) { MessageBox ("Error inserting overlay bitmap.", "Error", MB_OK|MB_ICONERROR); return; } // Turn the OVERLAY_AUTOPAINT flag on. long AttFlags = theApp.m_pRasterProcess->OverlayAttributes->Flags; theApp.m_pRasterProcess->OverlayAttributes->PutOriginY(0); theApp.m_pRasterProcess->OverlayAttributes->PutOriginX(0); theApp.m_pRasterProcess->OverlayAttributes->PutColor(RGB(0xFF,0xFF,0xFF)); theApp.m_pRasterProcess->OverlayAttributes->PutRows((long)theApp.m_pRaster->GetBitmapHeight()); theApp.m_pRasterProcess->OverlayAttributes->PutColumns((long)theApp.m_pRaster->GetBitmapWidth()); theApp.m_pRasterProcess->OverlayAttributes->BitsAllocated = 1; theApp.m_pRasterProcess->OverlayAttributes->NumberFramesInOverlay = 1; theApp.m_pRasterProcess->OverlayAttributes->ImageFrameOrigin = 1; AttFlags |= OVERLAY_AUTOPAINT|OVERLAY_AUTOPROCESS; theApp.m_pRasterProcess->OverlayAttributes->Flags = AttFlags; theApp.m_pRasterProcess->OverlayAttributes->Type = "G"; nRet = theApp.m_pRasterProcess->SetOverlayAttributes( m_pRightPaneWnd->m_RasterView.GetRaster(), m_uCount, OVERLAYATTRIBUTES_FLAGS | OVERLAYATTRIBUTES_ORIGIN | OVERLAYATTRIBUTES_DICOM | OVERLAYATTRIBUTES_COLOR); if(nRet == 0) { nRet = theApp.m_pRasterProcess->SetOverlayBitmap(m_pRightPaneWnd->m_RasterView.GetRaster(), m_uCount, theApp.m_pRaster, OVERLAY_COPY); if(nRet != 0) { MessageBox ("Error setting overlay bitmap, maximum number allowed of overlays is 16.", "Error", MB_OK|MB_ICONERROR); theApp.m_pRaster->Free(); return; } } else { MessageBox ("Error setting overlay attributes", "Error", MB_OK|MB_ICONERROR); theApp.m_pRaster->Free(); return; } /* Remove selection from the selected image list item to select the new one that will be added */ m_pLeftPaneWnd->m_ImageListControl.Item(m_nSelItemIndex).SetSelected(FALSE); int old = m_nSelItemIndex; sprintf (szItemText, "Overlay %d", m_uCount); m_pLeftPaneWnd->m_ImageListControl.Insert(theApp.m_pRaster->GetBitmap(),szItemText, 1); m_pLeftPaneWnd->m_ImageListControl.EnsureVisible(m_pLeftPaneWnd->m_ImageListControl.GetCount()-1); m_nSelItemIndex = m_pLeftPaneWnd->m_ImageListControl.GetCount()-1; m_pLeftPaneWnd->m_ImageListControl.Item(m_nSelItemIndex).SetSelected(TRUE); if(theApp.m_bShowOverlay) { m_nSelItemIndex = old; OnOverlaysShowOverlay(); m_nSelItemIndex = m_pLeftPaneWnd->m_ImageListControl.GetCount()-1; OnOverlaysShowOverlay(); } else { m_pLeftPaneWnd->OverlaysShowOverlay(FALSE, m_nSelItemIndex, TRUE) ; } m_uCount++; } void CMainFrame::OnUpdateOverlaysInsertOverlay(CCmdUI* pCmdUI) { pCmdUI->Enable (m_uCount > 0 ? TRUE : FALSE); } void CMainFrame::OnFileSaveFile() { CHAR szSaveFileName[_MAX_PATH]; UINT uRet; TCHAR szFilters[] =_T ("DICOM Files (*.dic)|*.dic|All files (*.*)|*.*||"); CFileDialog dlg ( FALSE, _T ("dic"), _T ("*.dic"), OFN_OVERWRITEPROMPT, szFilters); // Get file name if (dlg.DoModal () != IDOK) { return; } memset (&szSaveFileName, 0, sizeof (&szSaveFileName)); IDicomImageInfoPtr pImageInfo=NULL; theApp.m_pLEADDicomDS->FindFirstElement(TAG_PIXEL_DATA, FALSE); theApp.m_pLEADDicomDS->GetImageInformation(0); pImageInfo = theApp.m_pLEADDicomDS->GetImageInfo(); strcpy (szSaveFileName, dlg.GetPathName()); theApp.m_pLEADDicomDS->put_Bitmap( m_pRightPaneWnd->m_RasterView.GetRaster().GetBitmap()); uRet = theApp.m_pLEADDicomDS->SetBitmapValue(pImageInfo->Compression , pImageInfo->Photometric , (short)pImageInfo->BitsPerPixel , 2, DICOM_SETIMAGE_AUTO_SAVE_OVERLAYS); if (uRet != DICOM_SUCCESS) { MessageBox ("Error saving overlay bitmap.", "Error", MB_OK|MB_ICONERROR); return; } uRet = theApp.m_pLEADDicomDS->SaveDS(szSaveFileName, 0); if (uRet != DICOM_SUCCESS) MessageBox ("Error saving data set.", "Error", MB_OK|MB_ICONERROR); } void CMainFrame::OnUpdateFileSaveFile(CCmdUI* pCmdUI) { pCmdUI->Enable (m_uCount > 0 ? TRUE : FALSE); }