COScopeCtrl Class Reference From http://dev.drbio.cornell.edu/pl47/autocorrelator/html/class_c_o_scope_ctrl.html

COScopeCtrl Class Reference

#include <OScopeCtrl.h>

List of all members.


Detailed Description

This class describes a control that graphically displays numerical information similar to an oscilloscope.

This class is written by Mark C. Malburg. It is available under the Code Project Open License.

Definition at line 16 of file OScopeCtrl.h.



Public Member Functions

void  AppendMessage (const std::string &message)
  Appends a message onto display.
double  AppendPoint (double dNewPoint, ULONG count)
  Appends a new point with a counter.
double  AppendPoint (double dNewPoint)
  Appends a new point.
  COScopeCtrl ()
  Construction.
virtual BOOL  Create (DWORD dwStyle, const RECT &rect, CWnd *pParentWnd, UINT nID=NULL)
  Creates a Windows child window and attaches it to the CWnd object.
void  DrawPoint (ULONG)
void  DrawPoint ()
  Draws display point.
void  InvalidateCtrl ()
  Invalidates display region.
void  Reset ()
  Resets display.
void  SetBackgroundColor (COLORREF color)
  Sets display's background color.
void  SetGridColor (COLORREF color)
  Sets display's grid color.
void  SetPlotColor (COLORREF color)
  Sets display's plot color.
void  SetRange (double dLower, double dUpper, int nDecimalPlaces=1)
  Sets display range.
void  SetXUnits (CString string)
  Sets display x unit.
void  SetYUnits (CString string)
  Sets display y unit.
virtual  ~COScopeCtrl ()
  Destructor.

Public Attributes

COLORREF  m_crBackColor
  Background color.
COLORREF  m_crGridColor
  Grid color.
COLORREF  m_crPlotColor
  Data color.
double  m_dCurrentPosition
  Current position.
double  m_dPreviousPosition
  Previous position.
int  m_nShiftPixels
  Amount to shift with each new point.
int  m_nYDecimals
  Decimal range for Y values.
CString  m_strXUnitsString
  X units.
CString  m_strYUnitsString
  Y units.

Protected Member Functions

afx_msg void  OnPaint ()
  Called by framework to repaint window.
afx_msg void  OnSize (UINT nType, int cx, int cy)
  Called by framework after window's size has changed.

Protected Attributes

CBitmap  m_bitmapGrid
CBitmap  m_bitmapPlot
CBrush  m_brushBack
CDC  m_dcGrid
CDC  m_dcPlot
double  m_dLowerLimit
  Lower bounds.
double  m_dRange
double  m_dUpperLimit
  Upper bounds.
double  m_dVerticalFactor
int  m_nClientHeight
int  m_nClientWidth
int  m_nHalfShiftPixels
int  m_nPlotHeight
int  m_nPlotShiftPixels
int  m_nPlotWidth
CBitmap *  m_pbitmapOldGrid
CBitmap *  m_pbitmapOldPlot
CPen  m_penPlot
CRect  m_rectClient
CRect  m_rectPlot

Constructor & Destructor Documentation

COScopeCtrl::COScopeCtrl (
 ) 

Construction.

Definition at line 16 of file OScopeCtrl.cpp.

References m_brushBack, m_crBackColor, m_crGridColor, m_crPlotColor, m_dLowerLimit, m_dPreviousPosition, m_dRange, m_dUpperLimit, m_nHalfShiftPixels, m_nPlotShiftPixels, m_nShiftPixels, m_nYDecimals, m_pbitmapOldGrid, m_pbitmapOldPlot, m_penPlot, m_strXUnitsString, and m_strYUnitsString.

00017 {

00018     // since plotting is based on a LineTo for each new point

00019     // we need a starting point (i.e. a "previous" point)

00020     // use 0.0 as the default first point.

00021     // these are public member variables, and can be changed outside

00022     // (after construction).  Therefore m_perviousPosition could be set to

00023     // a more appropriate value prior to the first call to SetPosition.

00024     m_dPreviousPosition =   0.0 ;

00025 

00026     // public variable for the number of decimal places on the y axis

00027     m_nYDecimals = 3 ;

00028 

00029     // set some initial values for the scaling until "SetRange" is called.

00030     // these are protected varaibles and must be set with SetRange

00031     // in order to ensure that m_dRange is updated accordingly

00032     m_dLowerLimit = -10.0 ;

00033     m_dUpperLimit =  10.0 ;

00034     m_dRange      =  m_dUpperLimit - m_dLowerLimit ;   // protected member variable

00035 

00036     // m_nShiftPixels determines how much the plot shifts (in terms of pixels) 

00037     // with the addition of a new data point

00038     m_nShiftPixels     = 4 ;

00039     m_nHalfShiftPixels = m_nShiftPixels/2 ;                     // protected

00040     m_nPlotShiftPixels = m_nShiftPixels + m_nHalfShiftPixels ;  // protected

00041 

00042     // background, grid and data colors

00043     // these are public variables and can be set directly

00044     m_crBackColor  = RGB(  0,   0,   0) ;  // see also SetBackgroundColor

00045     m_crGridColor  = RGB(  0, 255, 255) ;  // see also SetGridColor

00046     m_crPlotColor  = RGB(255, 255, 255) ;  // see also SetPlotColor

00047 

00048     // protected variables

00049     m_penPlot.CreatePen(PS_SOLID, 0, m_crPlotColor) ;

00050     m_brushBack.CreateSolidBrush(m_crBackColor) ;

00051 

00052     // public member variables, can be set directly 

00053     m_strXUnitsString.Format(_T("Samples")) ;  // can also be set with SetXUnits

00054     m_strYUnitsString.Format(_T("Y units")) ;  // can also be set with SetYUnits

00055 

00056     // protected bitmaps to restore the memory DC's

00057     m_pbitmapOldGrid = NULL ;

00058     m_pbitmapOldPlot = NULL ;

00059 

00060 }  // COScopeCtrl

COScopeCtrl::~COScopeCtrl (
 )  [virtual]

Destructor.

Definition at line 63 of file OScopeCtrl.cpp.

References m_dcGrid, m_dcPlot, m_pbitmapOldGrid, and m_pbitmapOldPlot.

00064 {

00065     // just to be picky restore the bitmaps for the two memory dc's

00066     // (these dc's are being destroyed so there shouldn't be any leaks)

00067     if (m_pbitmapOldGrid != NULL)

00068         m_dcGrid.SelectObject(m_pbitmapOldGrid) ;  

00069     if (m_pbitmapOldPlot != NULL)

00070         m_dcPlot.SelectObject(m_pbitmapOldPlot) ;  

00071 

00072 } // ~COScopeCtrl


Member Function Documentation

void COScopeCtrl::AppendMessage ( const std::string &  message  ) 

Appends a message onto display.

Definition at line 548 of file OScopeCtrl.cpp.

References m_dcGrid, and m_dcPlot.

00549 {

00550 

00551     if (m_dcPlot.GetSafeHdc() != NULL)

00552     {

00553         CString csTemp( message.c_str() );

00554         m_dcGrid.TextOut( 530, 430, csTemp.GetBuffer() );

00555     }

00556 }

double COScopeCtrl::AppendPoint ( double  dNewPoint,


ULONG  count  

)


Appends a new point with a counter.

Definition at line 344 of file OScopeCtrl.cpp.

References DrawPoint(), and m_dCurrentPosition.

00345 {

00346     // append a data point to the plot

00347     // return the previous point

00348 

00349     double dPrevious ;

00350 

00351     dPrevious = m_dCurrentPosition ;

00352     m_dCurrentPosition = dNewPoint ;

00353     DrawPoint( counter ) ;

00354 

00355     Invalidate() ;

00356 

00357     return dPrevious ;

00358 

00359 } // AppendPoint

double COScopeCtrl::AppendPoint ( double  dNewPoint  ) 

Appends a new point.

Definition at line 325 of file OScopeCtrl.cpp.

References DrawPoint(), and m_dCurrentPosition.

Referenced by AutoCorrFormView::OnTimer().

00326 {

00327     // append a data point to the plot

00328     // return the previous point

00329 

00330     double dPrevious ;

00331 

00332     dPrevious = m_dCurrentPosition ;

00333     m_dCurrentPosition = dNewPoint ;

00334     DrawPoint() ;

00335 

00336     Invalidate() ;

00337 

00338     return dPrevious ;

00339 

00340 } // AppendPoint

BOOL COScopeCtrl::Create ( DWORD  dwStyle,


const RECT &  rect,


CWnd *  pParentWnd,


UINT  nID = NULL  

)

[virtual]

Creates a Windows child window and attaches it to the CWnd object.

Definition at line 88 of file OScopeCtrl.cpp.

References InvalidateCtrl().

Referenced by AutoCorrFormView::OnInitialUpdate().

00090 {

00091     BOOL result ;

00092     static CString className = AfxRegisterWndClass(CS_HREDRAW | CS_VREDRAW) ;

00093 

00094     result = CWnd::CreateEx(WS_EX_CLIENTEDGE | WS_EX_STATICEDGE, 

00095                           className, NULL, dwStyle, 

00096                           rect.left, rect.top, rect.right-rect.left, rect.bottom-rect.top,

00097                           pParentWnd->GetSafeHwnd(), (HMENU)nID) ;

00098     if (result != 0)

00099         InvalidateCtrl() ;

00100 

00101     return result ;

00102 

00103 } // Create

void COScopeCtrl::DrawPoint ( ULONG  counter  ) 

Definition at line 472 of file OScopeCtrl.cpp.

References m_brushBack, m_dcGrid, m_dcPlot, m_dCurrentPosition, m_dLowerLimit, m_dPreviousPosition, m_dVerticalFactor, m_nHalfShiftPixels, m_nPlotHeight, m_nPlotShiftPixels, m_nPlotWidth, m_nShiftPixels, m_penPlot, m_rectClient, and m_rectPlot.

00473 {

00474     // this does the work of "scrolling" the plot to the left

00475     // and appending a new data point all of the plotting is 

00476     // directed to the memory based bitmap associated with m_dcPlot

00477     // the will subsequently be BitBlt'd to the client in OnPaint

00478 

00479     int currX, prevX, currY, prevY ;

00480 

00481     CPen *oldPen ;

00482     CRect rectCleanUp ;

00483 

00484     if (m_dcPlot.GetSafeHdc() != NULL)

00485     {

00486         // shift the plot by BitBlt'ing it to itself 

00487         // note: the m_dcPlot covers the entire client

00488         //       but we only shift bitmap that is the size 

00489         //       of the plot rectangle

00490         // grab the right side of the plot (exluding m_nShiftPixels on the left)

00491         // move this grabbed bitmap to the left by m_nShiftPixels

00492 

00493         m_dcPlot.BitBlt(m_rectPlot.left, m_rectPlot.top+1, 

00494                         m_nPlotWidth, m_nPlotHeight, &m_dcPlot, 

00495                         m_rectPlot.left+m_nShiftPixels, m_rectPlot.top+1, 

00496                         SRCCOPY) ;

00497 

00498         // establish a rectangle over the right side of plot

00499         // which now needs to be cleaned up proir to adding the new point

00500         rectCleanUp = m_rectPlot ;

00501         rectCleanUp.left  = rectCleanUp.right - m_nShiftPixels ;

00502 

00503         // fill the cleanup area with the background

00504         m_dcPlot.FillRect(rectCleanUp, &m_brushBack) ;

00505 

00506         // draw the next line segement

00507 

00508         // grab the plotting pen

00509         oldPen = m_dcPlot.SelectObject(&m_penPlot) ;

00510 

00511         // move to the previous point

00512         prevX = m_rectPlot.right-m_nPlotShiftPixels ;

00513         prevY = m_rectPlot.bottom - 

00514                 (long)((m_dPreviousPosition - m_dLowerLimit) * m_dVerticalFactor) ;

00515         m_dcPlot.MoveTo (prevX, prevY) ;

00516 

00517         // draw to the current point

00518         currX = m_rectPlot.right-m_nHalfShiftPixels ;

00519         currY = m_rectPlot.bottom -

00520                 (long)((m_dCurrentPosition - m_dLowerLimit) * m_dVerticalFactor) ;

00521         m_dcPlot.LineTo (currX, currY) ;

00522 

00523         // restore the pen 

00524         m_dcPlot.SelectObject(oldPen) ;

00525 

00526         // if the data leaks over the upper or lower plot boundaries

00527         // fill the upper and lower leakage with the background

00528         // this will facilitate clipping on an as needed basis

00529         // as opposed to always calling IntersectClipRect

00530         if ((prevY <= m_rectPlot.top) || (currY <= m_rectPlot.top))

00531             m_dcPlot.FillRect(CRect(prevX, m_rectClient.top, currX+1, m_rectPlot.top+1), &m_brushBack) ;

00532 

00533         if ((prevY >= m_rectPlot.bottom) || (currY >= m_rectPlot.bottom))

00534             m_dcPlot.FillRect(CRect(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1), &m_brushBack) ;

00535 

00536         // store the current point for connection to the next point

00537         m_dPreviousPosition = m_dCurrentPosition ;

00538 

00539         CString csTemp;

00540         csTemp.Format(_T("Samples : %7d"), counter );

00541         m_dcGrid.TextOut( 530, 430, csTemp.GetBuffer() );

00542     }

00543 

00544 } // end DrawPoint

void COScopeCtrl::DrawPoint (
 ) 

Draws display point.

Definition at line 398 of file OScopeCtrl.cpp.

References m_brushBack, m_dcPlot, m_dCurrentPosition, m_dLowerLimit, m_dPreviousPosition, m_dVerticalFactor, m_nHalfShiftPixels, m_nPlotHeight, m_nPlotShiftPixels, m_nPlotWidth, m_nShiftPixels, m_penPlot, m_rectClient, and m_rectPlot.

Referenced by AppendPoint().

00399 {

00400     // this does the work of "scrolling" the plot to the left

00401     // and appending a new data point all of the plotting is 

00402     // directed to the memory based bitmap associated with m_dcPlot

00403     // the will subsequently be BitBlt'd to the client in OnPaint

00404 

00405     int currX, prevX, currY, prevY ;

00406 

00407     CPen *oldPen ;

00408     CRect rectCleanUp ;

00409 

00410     if (m_dcPlot.GetSafeHdc() != NULL)

00411     {

00412         // shift the plot by BitBlt'ing it to itself 

00413         // note: the m_dcPlot covers the entire client

00414         //       but we only shift bitmap that is the size 

00415         //       of the plot rectangle

00416         // grab the right side of the plot (exluding m_nShiftPixels on the left)

00417         // move this grabbed bitmap to the left by m_nShiftPixels

00418 

00419         m_dcPlot.BitBlt(m_rectPlot.left, m_rectPlot.top+1, 

00420                         m_nPlotWidth, m_nPlotHeight, &m_dcPlot, 

00421                         m_rectPlot.left+m_nShiftPixels, m_rectPlot.top+1, 

00422                         SRCCOPY) ;

00423 

00424         // establish a rectangle over the right side of plot

00425         // which now needs to be cleaned up proir to adding the new point

00426         rectCleanUp = m_rectPlot ;

00427         rectCleanUp.left  = rectCleanUp.right - m_nShiftPixels ;

00428 

00429         // fill the cleanup area with the background

00430         m_dcPlot.FillRect(rectCleanUp, &m_brushBack) ;

00431 

00432         // draw the next line segement

00433 

00434         // grab the plotting pen

00435         oldPen = m_dcPlot.SelectObject(&m_penPlot) ;

00436 

00437         // move to the previous point

00438         prevX = m_rectPlot.right-m_nPlotShiftPixels ;

00439         prevY = m_rectPlot.bottom - 

00440                 (long)((m_dPreviousPosition - m_dLowerLimit) * m_dVerticalFactor) ;

00441         m_dcPlot.MoveTo (prevX, prevY) ;

00442 

00443         // draw to the current point

00444         currX = m_rectPlot.right-m_nHalfShiftPixels ;

00445         currY = m_rectPlot.bottom -

00446                 (long)((m_dCurrentPosition - m_dLowerLimit) * m_dVerticalFactor) ;

00447         m_dcPlot.LineTo (currX, currY) ;

00448 

00449         // restore the pen 

00450         m_dcPlot.SelectObject(oldPen) ;

00451 

00452         // if the data leaks over the upper or lower plot boundaries

00453         // fill the upper and lower leakage with the background

00454         // this will facilitate clipping on an as needed basis

00455         // as opposed to always calling IntersectClipRect

00456         if ((prevY <= m_rectPlot.top) || (currY <= m_rectPlot.top))

00457             m_dcPlot.FillRect(CRect(prevX, m_rectClient.top, currX+1, m_rectPlot.top+1), &m_brushBack) ;

00458 

00459         if ((prevY >= m_rectPlot.bottom) || (currY >= m_rectPlot.bottom))

00460             m_dcPlot.FillRect(CRect(prevX, m_rectPlot.bottom+1, currX+1, m_rectClient.bottom+1), &m_brushBack) ;

00461 

00462         // store the current point for connection to the next point

00463         m_dPreviousPosition = m_dCurrentPosition ;

00464     }

00465 

00466 } // end DrawPoint

void COScopeCtrl::InvalidateCtrl (
 ) 

Invalidates display region.

Definition at line 181 of file OScopeCtrl.cpp.

References m_bitmapGrid, m_bitmapPlot, m_brushBack, m_crBackColor, m_crGridColor, m_dcGrid, m_dcPlot, m_dLowerLimit, m_dUpperLimit, m_nClientHeight, m_nClientWidth, m_nPlotHeight, m_nPlotWidth, m_nShiftPixels, m_nYDecimals, m_pbitmapOldGrid, m_pbitmapOldPlot, m_rectClient, m_rectPlot, m_strXUnitsString, and m_strYUnitsString.

Referenced by Create(), Reset(), SetBackgroundColor(), SetGridColor(), SetPlotColor(), SetRange(), SetXUnits(), and SetYUnits().

00182 {

00183     // There is a lot of drawing going on here - particularly in terms of 

00184     // drawing the grid.  Don't panic, this is all being drawn (only once)

00185     // to a bitmap.  The result is then BitBlt'd to the control whenever needed.

00186     int i ;

00187     int nCharacters ;

00188     int nTopGridPix, nMidGridPix, nBottomGridPix ;

00189 

00190     CPen *oldPen ;

00191     CPen solidPen(PS_SOLID, 0, m_crGridColor) ;

00192     CFont axisFont, yUnitFont, *oldFont ;

00193     CString strTemp ;

00194 

00195     // in case we haven't established the memory dc's

00196     CClientDC dc(this) ;  

00197 

00198     // if we don't have one yet, set up a memory dc for the grid

00199     if (m_dcGrid.GetSafeHdc() == NULL)

00200     {

00201         m_dcGrid.CreateCompatibleDC(&dc) ;

00202         m_bitmapGrid.CreateCompatibleBitmap(&dc, m_nClientWidth, m_nClientHeight) ;

00203         m_pbitmapOldGrid = m_dcGrid.SelectObject(&m_bitmapGrid) ;

00204     }

00205 

00206     m_dcGrid.SetBkColor (m_crBackColor) ;

00207 

00208     // fill the grid background

00209     m_dcGrid.FillRect(m_rectClient, &m_brushBack) ;

00210 

00211     // draw the plot rectangle:

00212     // determine how wide the y axis scaling values are

00213     nCharacters = abs((int)log10(fabs(m_dUpperLimit))) ;

00214     nCharacters = max(nCharacters, abs((int)log10(fabs(m_dLowerLimit)))) ;

00215 

00216     // add the units digit, decimal point and a minus sign, and an extra space

00217     // as well as the number of decimal places to display

00218     nCharacters = nCharacters + 4 + m_nYDecimals ;  

00219 

00220     // adjust the plot rectangle dimensions

00221     // assume 6 pixels per character (this may need to be adjusted)

00222     m_rectPlot.left = m_rectClient.left + 6*(nCharacters) ;

00223     m_nPlotWidth    = m_rectPlot.Width() ;

00224 

00225     // draw the plot rectangle

00226     oldPen = m_dcGrid.SelectObject (&solidPen) ; 

00227     m_dcGrid.MoveTo (m_rectPlot.left, m_rectPlot.top) ;

00228     m_dcGrid.LineTo (m_rectPlot.right+1, m_rectPlot.top) ;

00229     m_dcGrid.LineTo (m_rectPlot.right+1, m_rectPlot.bottom+1) ;

00230     m_dcGrid.LineTo (m_rectPlot.left, m_rectPlot.bottom+1) ;

00231     m_dcGrid.LineTo (m_rectPlot.left, m_rectPlot.top) ;

00232     m_dcGrid.SelectObject (oldPen) ; 

00233 

00234     // draw the dotted lines, 

00235     // use SetPixel instead of a dotted pen - this allows for a 

00236     // finer dotted line and a more "technical" look

00237     nMidGridPix    = (m_rectPlot.top + m_rectPlot.bottom)/2 ;

00238     nTopGridPix    = nMidGridPix - m_nPlotHeight/4 ;

00239     nBottomGridPix = nMidGridPix + m_nPlotHeight/4 ;

00240 

00241     for (i=m_rectPlot.left; i<m_rectPlot.right; i+=4)

00242     {

00243         m_dcGrid.SetPixel (i, nTopGridPix,    m_crGridColor) ;

00244         m_dcGrid.SetPixel (i, nMidGridPix,    m_crGridColor) ;

00245         m_dcGrid.SetPixel (i, nBottomGridPix, m_crGridColor) ;

00246     }

00247 

00248     // create some fonts (horizontal and vertical)

00249     // use a height of 14 pixels and 300 weight 

00250     // (these may need to be adjusted depending on the display)

00251     axisFont.CreateFont (14, 0, 0, 0, 300,

00252                        FALSE, FALSE, 0, ANSI_CHARSET,

00253                        OUT_DEFAULT_PRECIS, 

00254                        CLIP_DEFAULT_PRECIS,

00255                        DEFAULT_QUALITY, 

00256                        DEFAULT_PITCH|FF_SWISS, _T("Arial")) ;

00257     yUnitFont.CreateFont (14, 0, 900, 0, 300,

00258                        FALSE, FALSE, 0, ANSI_CHARSET,

00259                        OUT_DEFAULT_PRECIS, 

00260                        CLIP_DEFAULT_PRECIS,

00261                        DEFAULT_QUALITY, 

00262                        DEFAULT_PITCH|FF_SWISS, _T("Arial")) ;

00263 

00264     // grab the horizontal font

00265     oldFont = m_dcGrid.SelectObject(&axisFont) ;

00266 

00267     // y max

00268     m_dcGrid.SetTextColor (m_crGridColor) ;

00269     m_dcGrid.SetTextAlign (TA_RIGHT|TA_TOP) ;

00270     strTemp.Format (_T("%.*lf"), m_nYDecimals, m_dUpperLimit) ;

00271     m_dcGrid.TextOut (m_rectPlot.left-4, m_rectPlot.top, strTemp) ;

00272 

00273     // y min

00274     m_dcGrid.SetTextAlign (TA_RIGHT|TA_BASELINE) ;

00275     strTemp.Format (_T("%.*lf"), m_nYDecimals, m_dLowerLimit) ;

00276     m_dcGrid.TextOut (m_rectPlot.left-4, m_rectPlot.bottom, strTemp) ;

00277 

00278     // x min

00279     m_dcGrid.SetTextAlign (TA_LEFT|TA_TOP) ;

00280     m_dcGrid.TextOut (m_rectPlot.left, m_rectPlot.bottom+4, _T("0")) ;

00281 

00282     // x max

00283     m_dcGrid.SetTextAlign (TA_RIGHT|TA_TOP) ;

00284     strTemp.Format (_T("%d"), m_nPlotWidth/m_nShiftPixels) ; 

00285     m_dcGrid.TextOut (m_rectPlot.right, m_rectPlot.bottom+4, strTemp) ;

00286 

00287     // x units

00288     m_dcGrid.SetTextAlign (TA_CENTER|TA_TOP) ;

00289     m_dcGrid.TextOut ((m_rectPlot.left+m_rectPlot.right)/2, 

00290                     m_rectPlot.bottom+4, m_strXUnitsString) ;

00291 

00292 

00293     // restore the font

00294     m_dcGrid.SelectObject(oldFont) ;

00295 

00296     // y units

00297     oldFont = m_dcGrid.SelectObject(&yUnitFont) ;

00298     m_dcGrid.SetTextAlign (TA_CENTER|TA_BASELINE) ;

00299     m_dcGrid.TextOut ((m_rectClient.left+m_rectPlot.left)/2, 

00300                     (m_rectPlot.bottom+m_rectPlot.top)/2, m_strYUnitsString) ;

00301     m_dcGrid.SelectObject(oldFont) ;

00302 

00303     // at this point we are done filling the the grid bitmap, 

00304     // no more drawing to this bitmap is needed until the setting are changed

00305 

00306     // if we don't have one yet, set up a memory dc for the plot

00307     if (m_dcPlot.GetSafeHdc() == NULL)

00308     {

00309         m_dcPlot.CreateCompatibleDC(&dc) ;

00310         m_bitmapPlot.CreateCompatibleBitmap(&dc, m_nClientWidth, m_nClientHeight) ;

00311         m_pbitmapOldPlot = m_dcPlot.SelectObject(&m_bitmapPlot) ;

00312     }

00313 

00314     // make sure the plot bitmap is cleared

00315     m_dcPlot.SetBkColor (m_crBackColor) ;

00316     m_dcPlot.FillRect(m_rectClient, &m_brushBack) ;

00317 

00318     // finally, force the plot area to redraw

00319     InvalidateRect(m_rectClient) ;

00320 

00321 } // InvalidateCtrl

void COScopeCtrl::OnPaint (
 )  [protected]

Called by framework to repaint window.

Definition at line 363 of file OScopeCtrl.cpp.

References m_dcGrid, m_dcPlot, m_nClientHeight, and m_nClientWidth.

00364 {

00365     CPaintDC dc(this) ;  // device context for painting

00366     CDC memDC ;

00367     CBitmap memBitmap ;

00368     CBitmap* oldBitmap ; // bitmap originally found in CMemDC

00369 

00370     // no real plotting work is performed here, 

00371     // just putting the existing bitmaps on the client

00372 

00373     // to avoid flicker, establish a memory dc, draw to it 

00374     // and then BitBlt it to the client

00375     memDC.CreateCompatibleDC(&dc) ;

00376     memBitmap.CreateCompatibleBitmap(&dc, m_nClientWidth, m_nClientHeight) ;

00377     oldBitmap = (CBitmap *)memDC.SelectObject(&memBitmap) ;

00378 

00379     if (memDC.GetSafeHdc() != NULL)

00380     {

00381         // first drop the grid on the memory dc

00382         memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight, 

00383                      &m_dcGrid, 0, 0, SRCCOPY) ;

00384         // now add the plot on top as a "pattern" via SRCPAINT.

00385         // works well with dark background and a light plot

00386         memDC.BitBlt(0, 0, m_nClientWidth, m_nClientHeight, 

00387                      &m_dcPlot, 0, 0, SRCPAINT) ;  //SRCPAINT

00388         // finally send the result to the display

00389         dc.BitBlt(0, 0, m_nClientWidth, m_nClientHeight, 

00390                   &memDC, 0, 0, SRCCOPY) ;

00391     }

00392 

00393     memDC.SelectObject(oldBitmap) ;

00394 

00395 } // OnPaint

void COScopeCtrl::OnSize ( UINT  nType,


int  cx,


int  cy  

)

[protected]

Called by framework after window's size has changed.

Definition at line 561 of file OScopeCtrl.cpp.

References m_dRange, m_dVerticalFactor, m_nClientHeight, m_nClientWidth, m_nPlotHeight, m_nPlotWidth, m_rectClient, and m_rectPlot.

00562 {

00563     CWnd::OnSize(nType, cx, cy) ;

00564 

00565     // NOTE: OnSize automatically gets called during the setup of the control

00566 

00567     GetClientRect(m_rectClient) ;

00568 

00569     // set some member variables to avoid multiple function calls

00570     m_nClientHeight = m_rectClient.Height() ;

00571     m_nClientWidth  = m_rectClient.Width() ;

00572 

00573     // the "left" coordinate and "width" will be modified in 

00574     // InvalidateCtrl to be based on the width of the y axis scaling

00575     m_rectPlot.left   = 20 ;  

00576     m_rectPlot.top    = 10 ;

00577     m_rectPlot.right  = m_rectClient.right-10 ;

00578     m_rectPlot.bottom = m_rectClient.bottom-25 ;

00579 

00580     // set some member variables to avoid multiple function calls

00581     m_nPlotHeight = m_rectPlot.Height() ;

00582     m_nPlotWidth  = m_rectPlot.Width() ;

00583 

00584     // set the scaling factor for now, this can be adjusted 

00585     // in the SetRange functions

00586     m_dVerticalFactor = (double)m_nPlotHeight / m_dRange ; 

00587 

00588 } // OnSize

void COScopeCtrl::Reset (
 ) 

Resets display.

Definition at line 592 of file OScopeCtrl.cpp.

References InvalidateCtrl().

Referenced by AutoCorrFormView::OnBnClickedStartButton().

00593 {

00594     // to clear the existing data (in the form of a bitmap)

00595     // simply invalidate the entire control

00596     InvalidateCtrl() ;

00597 }

void COScopeCtrl::SetBackgroundColor ( COLORREF  color  ) 

Sets display's background color.

Definition at line 168 of file OScopeCtrl.cpp.

References InvalidateCtrl(), m_brushBack, and m_crBackColor.

Referenced by AutoCorrFormView::OnInitialUpdate().

00169 {

00170     m_crBackColor = color ;

00171 

00172     m_brushBack.DeleteObject() ;

00173     m_brushBack.CreateSolidBrush(m_crBackColor) ;

00174 

00175     // clear out the existing garbage, re-start with a clean plot

00176     InvalidateCtrl() ;

00177 

00178 }  // SetBackgroundColor

void COScopeCtrl::SetGridColor ( COLORREF  color  ) 

Sets display's grid color.

Definition at line 143 of file OScopeCtrl.cpp.

References InvalidateCtrl(), and m_crGridColor.

Referenced by AutoCorrFormView::OnInitialUpdate().

00144 {

00145     m_crGridColor = color ;

00146 

00147     // clear out the existing garbage, re-start with a clean plot

00148     InvalidateCtrl() ;

00149 

00150 }  // SetGridColor

void COScopeCtrl::SetPlotColor ( COLORREF  color  ) 

Sets display's plot color.

Definition at line 154 of file OScopeCtrl.cpp.

References InvalidateCtrl(), m_crPlotColor, and m_penPlot.

Referenced by AutoCorrFormView::OnInitialUpdate().

00155 {

00156     m_crPlotColor = color ;

00157 

00158     m_penPlot.DeleteObject() ;

00159     m_penPlot.CreatePen(PS_SOLID, 0, m_crPlotColor) ;

00160 

00161     // clear out the existing garbage, re-start with a clean plot

00162     InvalidateCtrl() ;

00163 

00164 }  // SetPlotColor

void COScopeCtrl::SetRange ( double  dLower,


double  dUpper,


int  nDecimalPlaces = 1  

)


Sets display range.

Definition at line 106 of file OScopeCtrl.cpp.

References InvalidateCtrl(), m_dLowerLimit, m_dRange, m_dUpperLimit, m_dVerticalFactor, m_nPlotHeight, and m_nYDecimals.

Referenced by AutoCorrFormView::OnInitialUpdate().

00107 {

00108     ASSERT(dUpper > dLower) ;

00109 

00110     m_dLowerLimit     = dLower ;

00111     m_dUpperLimit     = dUpper ;

00112     m_nYDecimals      = nDecimalPlaces ;

00113     m_dRange          = m_dUpperLimit - m_dLowerLimit ;

00114     m_dVerticalFactor = (double)m_nPlotHeight / m_dRange ; 

00115 

00116     // clear out the existing garbage, re-start with a clean plot

00117     InvalidateCtrl() ;

00118 

00119 }  // SetRange

void COScopeCtrl::SetXUnits ( CString  string  ) 

Sets display x unit.

Definition at line 123 of file OScopeCtrl.cpp.

References InvalidateCtrl(), and m_strXUnitsString.

Referenced by AutoCorrFormView::OnInitialUpdate().

00124 {

00125     m_strXUnitsString = string ;

00126 

00127     // clear out the existing garbage, re-start with a clean plot

00128     InvalidateCtrl() ;

00129 

00130 }  // SetXUnits

void COScopeCtrl::SetYUnits ( CString  string  ) 

Sets display y unit.

Definition at line 133 of file OScopeCtrl.cpp.

References InvalidateCtrl(), and m_strYUnitsString.

Referenced by AutoCorrFormView::OnInitialUpdate().

00134 {

00135     m_strYUnitsString = string ;

00136 

00137     // clear out the existing garbage, re-start with a clean plot

00138     InvalidateCtrl() ;

00139 

00140 }  // SetYUnits


Member Data Documentation

CBitmap COScopeCtrl::m_bitmapGrid [protected]

Definition at line 114 of file OScopeCtrl.h.

Referenced by InvalidateCtrl().

CBitmap COScopeCtrl::m_bitmapPlot [protected]

Definition at line 115 of file OScopeCtrl.h.

Referenced by InvalidateCtrl().

CBrush COScopeCtrl::m_brushBack [protected]

Definition at line 108 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), DrawPoint(), InvalidateCtrl(), and SetBackgroundColor().

COLORREF COScopeCtrl::m_crBackColor

Background color.

Definition at line 68 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetBackgroundColor().

COLORREF COScopeCtrl::m_crGridColor

Grid color.

Definition at line 70 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetGridColor().

COLORREF COScopeCtrl::m_crPlotColor

Data color.

Definition at line 72 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), and SetPlotColor().

CDC COScopeCtrl::m_dcGrid [protected]

Definition at line 110 of file OScopeCtrl.h.

Referenced by AppendMessage(), DrawPoint(), InvalidateCtrl(), OnPaint(), and ~COScopeCtrl().

CDC COScopeCtrl::m_dcPlot [protected]

Definition at line 111 of file OScopeCtrl.h.

Referenced by AppendMessage(), DrawPoint(), InvalidateCtrl(), OnPaint(), and ~COScopeCtrl().

double COScopeCtrl::m_dCurrentPosition

Current position.

Definition at line 74 of file OScopeCtrl.h.

Referenced by AppendPoint(), and DrawPoint().

double COScopeCtrl::m_dLowerLimit [protected]

Lower bounds.

Definition at line 99 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), DrawPoint(), InvalidateCtrl(), and SetRange().

double COScopeCtrl::m_dPreviousPosition

Previous position.

Definition at line 76 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), and DrawPoint().

double COScopeCtrl::m_dRange [protected]

Definition at line 102 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), OnSize(), and SetRange().

double COScopeCtrl::m_dUpperLimit [protected]

Upper bounds.

Definition at line 101 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetRange().

double COScopeCtrl::m_dVerticalFactor [protected]

Definition at line 103 of file OScopeCtrl.h.

Referenced by DrawPoint(), OnSize(), and SetRange().

int COScopeCtrl::m_nClientHeight [protected]

Definition at line 93 of file OScopeCtrl.h.

Referenced by InvalidateCtrl(), OnPaint(), and OnSize().

int COScopeCtrl::m_nClientWidth [protected]

Definition at line 94 of file OScopeCtrl.h.

Referenced by InvalidateCtrl(), OnPaint(), and OnSize().

int COScopeCtrl::m_nHalfShiftPixels [protected]

Definition at line 91 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), and DrawPoint().

int COScopeCtrl::m_nPlotHeight [protected]

Definition at line 95 of file OScopeCtrl.h.

Referenced by DrawPoint(), InvalidateCtrl(), OnSize(), and SetRange().

int COScopeCtrl::m_nPlotShiftPixels [protected]

Definition at line 92 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), and DrawPoint().

int COScopeCtrl::m_nPlotWidth [protected]

Definition at line 96 of file OScopeCtrl.h.

Referenced by DrawPoint(), InvalidateCtrl(), and OnSize().

int COScopeCtrl::m_nShiftPixels

Amount to shift with each new point.

Definition at line 60 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), DrawPoint(), and InvalidateCtrl().

int COScopeCtrl::m_nYDecimals

Decimal range for Y values.

Definition at line 62 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetRange().

CBitmap* COScopeCtrl::m_pbitmapOldGrid [protected]

Definition at line 112 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and ~COScopeCtrl().

CBitmap* COScopeCtrl::m_pbitmapOldPlot [protected]

Definition at line 113 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and ~COScopeCtrl().

CPen COScopeCtrl::m_penPlot [protected]

Definition at line 107 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), DrawPoint(), and SetPlotColor().

CRect COScopeCtrl::m_rectClient [protected]

Definition at line 105 of file OScopeCtrl.h.

Referenced by DrawPoint(), InvalidateCtrl(), and OnSize().

CRect COScopeCtrl::m_rectPlot [protected]

Definition at line 106 of file OScopeCtrl.h.

Referenced by DrawPoint(), InvalidateCtrl(), and OnSize().

CString COScopeCtrl::m_strXUnitsString

X units.

Definition at line 64 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetXUnits().

CString COScopeCtrl::m_strYUnitsString

Y units.

Definition at line 66 of file OScopeCtrl.h.

Referenced by COScopeCtrl(), InvalidateCtrl(), and SetYUnits().

你可能感兴趣的:(reference)