home *** CD-ROM | disk | FTP | other *** search
/ Delphi 5 for Professionals / DELPHI5.iso / AddOns / Components / RealTime Graphics ActiveX / DATA.3 / Examples / CPP / Bars / BarsView.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-10-21  |  6.1 KB  |  248 lines

  1. // BarsView.cpp : implementation of the CBarsView class
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "Bars.h"
  6.  
  7. #include "BarsDoc.h"
  8. #include "BarsView.h"
  9. #include "ctwxdef.h"
  10.  
  11. #ifdef _DEBUG
  12. #define new DEBUG_NEW
  13. #undef THIS_FILE
  14. static char THIS_FILE[] = __FILE__;
  15. #endif
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // CBarsView
  19.  
  20. IMPLEMENT_DYNCREATE(CBarsView, CFormView)
  21.  
  22. BEGIN_MESSAGE_MAP(CBarsView, CFormView)
  23.     //{{AFX_MSG_MAP(CBarsView)
  24.         // NOTE - the ClassWizard will add and remove mapping macros here.
  25.         //    DO NOT EDIT what you see in these blocks of generated code!
  26.     //}}AFX_MSG_MAP
  27.     // Standard printing commands
  28.     ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
  29.     ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
  30.     ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
  31. END_MESSAGE_MAP()
  32.  
  33. /////////////////////////////////////////////////////////////////////////////
  34. // CBarsView construction/destruction
  35.  
  36. CBarsView::CBarsView()
  37.     : CFormView(CBarsView::IDD)
  38. {
  39.     //{{AFX_DATA_INIT(CBarsView)
  40.     //}}AFX_DATA_INIT
  41.     // TODO: add construction code here
  42.  
  43. }
  44.  
  45. CBarsView::~CBarsView()
  46. {
  47. }
  48.  
  49. void CBarsView::DoDataExchange(CDataExchange* pDX)
  50. {
  51.     CFormView::DoDataExchange(pDX);
  52.     //{{AFX_DATA_MAP(CBarsView)
  53.     DDX_Control(pDX, IDC_RTBARXCTRL1, m_Bar1);
  54.     DDX_Control(pDX, IDC_RTBARXCTRL2, m_Bar2);
  55.     //}}AFX_DATA_MAP
  56. }
  57.  
  58. BOOL CBarsView::PreCreateWindow(CREATESTRUCT& cs)
  59. {
  60.     // TODO: Modify the Window class or styles here by modifying
  61.     //  the CREATESTRUCT cs
  62.  
  63.     return CFormView::PreCreateWindow(cs);
  64. }
  65.  
  66. /////////////////////////////////////////////////////////////////////////////
  67. // CBarsView printing
  68.  
  69. BOOL CBarsView::OnPreparePrinting(CPrintInfo* pInfo)
  70. {
  71.     // default preparation
  72.     return DoPreparePrinting(pInfo);
  73. }
  74.  
  75. void CBarsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  76. {
  77.     // TODO: add extra initialization before printing
  78. }
  79.  
  80. void CBarsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
  81. {
  82.     // TODO: add cleanup after printing
  83. }
  84.  
  85. void CBarsView::OnPrint(CDC* pDC, CPrintInfo*)
  86. {
  87.     // TODO: add code to print the controls
  88. }
  89.  
  90. /////////////////////////////////////////////////////////////////////////////
  91. // CBarsView diagnostics
  92.  
  93. #ifdef _DEBUG
  94. void CBarsView::AssertValid() const
  95. {
  96.     CFormView::AssertValid();
  97. }
  98.  
  99. void CBarsView::Dump(CDumpContext& dc) const
  100. {
  101.     CFormView::Dump(dc);
  102. }
  103.  
  104. CBarsDoc* CBarsView::GetDocument() // non-debug version is inline
  105. {
  106.     ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBarsDoc)));
  107.     return (CBarsDoc*)m_pDocument;
  108. }
  109. #endif //_DEBUG
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CBarsView message handlers
  113.  
  114. void CBarsView::OnInitialUpdate() 
  115. {
  116.     CFormView::OnInitialUpdate();
  117.     
  118.     BuildGraph1();  //build the first rt bargraph
  119.     BuildGraph2();  //build the second rt bargraph
  120. }
  121.  
  122.  
  123. void CBarsView::BuildGraph1()
  124. {
  125.     m_Bar1.SetBarNumChannels(8);
  126.     
  127.     //ALARM
  128.     m_Bar1.SetBarAlarmMessageEnable(TRUE);
  129.     m_Bar1.SetBarAlarmMarksEnable(TRUE);
  130.     m_Bar1.SetBarHighAlarmValue (5.8);
  131.     m_Bar1.SetBarLowAlarmValue (4.2);
  132.     m_Bar1.SetBarHighAlarmString ("*HI*");
  133.     m_Bar1.SetBarLowAlarmString ("*LO*");
  134.     m_Bar1.SetBarNormalAlarmString ("ok");
  135.     
  136.     //DYN TEXT
  137.     m_Bar1.SetBarDynTextEnable(TRUE);
  138.     
  139.     //SCALING AND CENTER POINT
  140.     m_Bar1.SetBarScaleMin (4.0);
  141.     m_Bar1.SetBarScaleMax (7.0);
  142.     m_Bar1.SetBarScaleCenter (4.0);
  143.     m_Bar1.SetBarTickSpace (1.0);
  144.     m_Bar1.SetBarNumTicks (5);
  145.     
  146.     //AXIS LABEL PRECISION
  147.     m_Bar1.SetBarLabelsPrecision (2);
  148.     
  149.     //COLORS
  150.     m_Bar1.SetWindowBackgroundColor (RGB_WHITE);
  151.     
  152.     //TITLE
  153.     m_Bar1.SetTitleString (TITLE1,"Vertical Bar Graph");
  154.  
  155.     //INTERNAL TIMER
  156.     m_Bar1.SetEnableInternalTimer(TRUE);
  157.  
  158. }
  159.  
  160.  
  161. void CBarsView::BuildGraph2()
  162. {
  163.     m_Bar2.SetBarNumChannels(4);
  164.     m_Bar2.SetBarType (OR_HORZ); //draw a horizontal bar graph
  165.     
  166.     //COLORS
  167.     m_Bar2.SetWindowBackgroundColor(RGB (128, 128, 0));
  168.     m_Bar2.SetPlotBackgroundColor(RGB (128, 64, 0)); 
  169.     
  170.     //ALARMS
  171.     m_Bar2.SetBarAlarmMarksEnable(TRUE);
  172.     m_Bar2.SetBarAlarmMessageEnable(TRUE);
  173.     m_Bar2.SetBarHighAlarmValue (5.9);
  174.     m_Bar2.SetBarLowAlarmValue (4.1);
  175.     m_Bar2.SetBarNumTicks (9);
  176.     
  177.     //TAG NAMES
  178.     m_Bar2.SetBarChannelTagName(0, "One");
  179.     m_Bar2.SetBarChannelTagName(1, "Two");
  180.     m_Bar2.SetBarChannelTagName(2, "Three");
  181.     m_Bar2.SetBarChannelTagName(3, "Four");
  182.  
  183.     // BAR COLORS
  184.     m_Bar2.SetBarChannelColor(0, RGB (0, 0, 128));
  185.     m_Bar2.SetBarChannelColor(1, RGB (255, 255, 0));
  186.     m_Bar2.SetBarChannelColor(2, RGB (255, 255, 255));
  187.     m_Bar2.SetBarChannelColor(3, RGB (0, 0, 0));
  188.     
  189.     //TITLES
  190.     m_Bar2.SetTitleString (TITLE1,"Horizontal Bar Graph");
  191.  
  192.     //INTERNAL TIMER
  193.     m_Bar2.SetEnableInternalTimer(TRUE);
  194.     
  195. }
  196.  
  197. BEGIN_EVENTSINK_MAP(CBarsView, CFormView)
  198.     //{{AFX_EVENTSINK_MAP(CBarsView)
  199.     ON_EVENT(CBarsView, IDC_RTBARXCTRL1, 1 /* OnInternalTimer */, OnInternalTimerRtbarxctrl1, VTS_NONE)
  200.     ON_EVENT(CBarsView, IDC_RTBARXCTRL2, 1 /* OnInternalTimer */, OnInternalTimerRtbarxctrl2, VTS_NONE)
  201.     //}}AFX_EVENTSINK_MAP
  202. END_EVENTSINK_MAP()
  203.  
  204. void CBarsView::OnInternalTimerRtbarxctrl1() 
  205. {
  206.     double rData[MAX_RTBARX_BARS];
  207.     double rMin = min(m_Bar1.GetBarScaleMin (), m_Bar1.GetBarScaleMax ());
  208.     double rMax = max(m_Bar1.GetBarScaleMin (), m_Bar1.GetBarScaleMax ());
  209.     double rCenter = rMin + (rMax - rMin) /2;
  210.     double rRange = (rMin - rMax);
  211.     
  212.     int i;
  213.     for (i=0; i < m_Bar1.GetBarNumChannels(); i++)
  214.     {
  215.         rData[i] = rCenter + rRange * 0.3 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
  216.         if (rData[i] > rMax)
  217.             rData[i] = rMax;
  218.         else
  219.             if (rData[i] < rMin) 
  220.                 rData[i] = rMin;
  221.     }
  222.     m_Bar1.UpdateDynData (rData);
  223.  
  224. }
  225.  
  226. void CBarsView::OnInternalTimerRtbarxctrl2() 
  227. {
  228.     double rData[MAX_RTBARX_BARS];
  229.     double rMin = min(m_Bar2.GetBarScaleMin (), m_Bar2.GetBarScaleMax ());
  230.     double rMax = max(m_Bar2.GetBarScaleMin (), m_Bar2.GetBarScaleMax ());
  231.     double rCenter = rMin + (rMax - rMin) /2;
  232.     double rRange = (rMin - rMax);
  233.     
  234.     int i;
  235.     for (i=0; i < m_Bar2.GetBarNumChannels(); i++)
  236.     {
  237.         rData[i] = rCenter + rRange * 0.2 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
  238.         if (rData[i] > rMax)
  239.             rData[i] = rMax;
  240.         else
  241.             if (rData[i] < rMin) 
  242.                 rData[i] = rMin;
  243.     }
  244.     m_Bar2.UpdateDynData (rData);
  245.  
  246.     
  247. }
  248.