#include "stdafx.h" #include "DicWav.h" #include "WavDoc.h" #include "WavView.h" #include "MainFrm.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CDicWavView IMPLEMENT_DYNCREATE(CDicWavView, CScrollView) BEGIN_MESSAGE_MAP(CDicWavView, CScrollView) //{{AFX_MSG_MAP(CDicWavView) ON_WM_CREATE() ON_COMMAND(ID_ALL_ERORRS, OnAllErorrs) ON_UPDATE_COMMAND_UI(ID_ALL_ERORRS, OnUpdateAllErorrs) ON_WM_LBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CDicWavView construction/destruction CDicWavView::CDicWavView() { m_bLoadedWaveform = FALSE; m_font.CreatePointFont (80, _T ("MS Sans Serif")); } CDicWavView::~CDicWavView() { } BOOL CDicWavView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs m_ClassName = AfxRegisterWndClass (CS_HREDRAW | CS_VREDRAW, ::LoadCursor(NULL, IDC_ARROW), (HBRUSH)::GetStockObject (BLACK_BRUSH), 0); cs.lpszClass = m_ClassName; return CScrollView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CDicWavView drawing void CDicWavView::OnDraw(CDC* pDC) { CDicWavDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); CSize size = GetTotalSize (); CBrush brush; brush.CreateStockObject (BLACK_BRUSH); CRect rcTop (0, 0, size.cx, size.cy); CPen pen (PS_SOLID, 0, RGB (50, 50, 50)); CPen* pOldPen = pDC->SelectObject (&pen); // Draw the grid int y; for (int i=0; iMoveTo (0, y); pDC->LineTo (size.cx, y); } int x ; for (int j=0; jMoveTo (x, 0); pDC->LineTo (x, size.cy); } pDC->SelectObject (pOldPen); if (m_bLoadedWaveform) { DrawWaveform(pDC , rcTop ); } } ///////////////////////////////////////////////////////////////////////////// // CDicWavView diagnostics #ifdef _DEBUG void CDicWavView::AssertValid() const { CScrollView::AssertValid(); } void CDicWavView::Dump(CDumpContext& dc) const { CScrollView::Dump(dc); } CDicWavDoc* CDicWavView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDicWavDoc))); return (CDicWavDoc*) m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CDicWavView message handlers int CDicWavView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CScrollView::OnCreate(lpCreateStruct) == -1) return -1; return 0; } void CDicWavView::OnAllErorrs() { LBase::DisplayErrorList(m_hWnd); } void CDicWavView::OnUpdateAllErorrs(CCmdUI* pCmdUI) { // TODO: Add your command update UI handler code here pCmdUI->Enable(LBase::GetErrorsNumber()); } void CDicWavView::OnInitialUpdate() { CScrollView::OnInitialUpdate(); CDC * pTempDC = GetDC(); m_nPageWidth = pTempDC->GetDeviceCaps(HORZRES); m_nPageHeight = pTempDC->GetDeviceCaps(VERTRES); m_nNumHorzPoints = HORIZONTAL_POINT_COUNT; m_nNumVerPoints = VERTICAL_POINT_COUNT; CClientDC dc (this); m_nCellWidth = (int)((double)m_nPageWidth/m_nNumHorzPoints); m_nCellHeight = (int)((double)m_nPageHeight/m_nNumVerPoints); m_nRibbonWidth = 0; SetScrollSizes (MM_TEXT, CSize (m_nPageWidth, m_nPageHeight)); } L_VOID CDicWavView::DrawWaveform(CDC* pDC ,CRect ViewRect) { CPen pen (PS_SOLID, 0, RGB (0, 255, 0)); CDicWavDoc* pDoc = GetDocument(); if (!pDoc) { return; } // Get number of channels L_UINT32 uChannelsCount = pDoc->m_CurWaveformGrp.GetNumberOfChannels(); if (uChannelsCount == 0) { return; } // How many samples do we have in a channel L_UINT32 uSamplesPerChannel = pDoc->m_CurWaveformGrp.GetNumberOfSamplesPerChannel(); if (uSamplesPerChannel == 0) { return; } L_INT32* pAllData = NULL; L_UINT32 uSampleIndex,uChannelIndex; L_INT32 iMaxVal, iMinVal; L_DOUBLE dExtent; L_DOUBLE dVertStep; CRect DrawTextRect; L_INT nViewRectHeight = (ViewRect.bottom - ViewRect.top) - FRAME_WIDTH; L_INT nViewRectWidth = (ViewRect.right - ViewRect.left); pDICOMCODESEQUENCEITEM pChannelSource ; CPen* pOldPen ; pDC->SetBkMode(TRANSPARENT); pDC->SetTextColor(RGB(255,0,0)); pOldPen = pDC->SelectObject (&pen); iMaxVal = -32768; iMinVal = 32767; //Find the minimum and maximum value for all the channels for (uChannelIndex = 0; uChannelIndex < uChannelsCount; uChannelIndex++) { pAllData = pDoc->m_CurWaveformGrp.GetChannel(uChannelIndex)->GetChannelSamples(&uSamplesPerChannel); for (uSampleIndex = 0; uSampleIndex < uSamplesPerChannel; uSampleIndex++) { if (pAllData[uSampleIndex] > iMaxVal) { iMaxVal = pAllData[uSampleIndex]; } else if (pAllData[uSampleIndex] < iMinVal) { iMinVal = pAllData[uSampleIndex]; } } dVertStep = nViewRectHeight / uChannelsCount; dExtent = ((iMaxVal - iMinVal) * 1.2)/ dVertStep; } int nIndex = 0 ; CString strText; pDICOMWAVEFORMANNOTATION pAnn; LONG lStartPoint; // Loop through the channels one by one for (uChannelIndex = 0; uChannelIndex < uChannelsCount; uChannelIndex++) { strText.Empty(); nIndex = uChannelsCount - uChannelIndex -1; //Get the data for this channel pAllData = pDoc->m_CurWaveformGrp.GetChannel(nIndex)->GetChannelSamples(&uSamplesPerChannel); lStartPoint = ((nViewRectHeight + (L_UINT32)((L_DOUBLE)((uChannelIndex) * -1 * (L_INT)dVertStep) - (pAllData[0] - iMinVal) / dExtent)))+FRAME_WIDTH/2; // Move to the first point of the channel pDC->MoveTo(FRAME_WIDTH, lStartPoint); //Get the channel source pChannelSource = pDoc->m_CurWaveformGrp.GetChannel(nIndex)->GetChannelSource(); DrawTextRect.top = lStartPoint; DrawTextRect.left = 5; DrawTextRect.bottom = DrawTextRect.top + (L_INT)dVertStep; DrawTextRect.right = FRAME_WIDTH; if(pChannelSource && pChannelSource->pszCodeMeaning) { // Display the channel source strText = pChannelSource->pszCodeMeaning; if(pDoc->m_CurWaveformGrp.GetChannel(nIndex)->GetAnnotationCount()) { // Display the channel annotation pAnn = pDoc->m_CurWaveformGrp.GetChannel(nIndex)->GetAnnotation(0); if(pAnn) { if(pAnn->pszUnformattedTextValue) { strText +=" ("; strText +=pAnn->pszUnformattedTextValue; strText +=")"; } else { if(pAnn->pCodedName && pAnn->pCodedName->pszCodeMeaning) { strText +=" ("; strText +=pAnn->pCodedName->pszCodeMeaning; strText +=")"; } } } } pDC->DrawText( strText, &DrawTextRect, DT_WORDBREAK); } L_INT32 nDiff; L_DOUBLE fRatio; L_INT32 nOffset; // Draw the points for this channel for (uSampleIndex = 1; uSampleIndex < uSamplesPerChannel; uSampleIndex++) { nDiff = pAllData[uSampleIndex] - iMinVal; fRatio = nDiff / dExtent; nOffset = FRAME_WIDTH/2; pDC->LineTo((uSampleIndex * nViewRectWidth / uSamplesPerChannel)+FRAME_WIDTH, ((nViewRectHeight + (L_UINT32)(( (L_DOUBLE)(uChannelIndex) * -1 * dVertStep) - fRatio)))+nOffset ); } } pDC->SelectObject (pOldPen); }