home *** CD-ROM | disk | FTP | other *** search
- // BarsView.cpp : implementation of the CBarsView class
- //
-
- #include "stdafx.h"
- #include "Bars.h"
-
- #include "BarsDoc.h"
- #include "BarsView.h"
- #include "ctwxdef.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CBarsView
-
- IMPLEMENT_DYNCREATE(CBarsView, CFormView)
-
- BEGIN_MESSAGE_MAP(CBarsView, CFormView)
- //{{AFX_MSG_MAP(CBarsView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CBarsView construction/destruction
-
- CBarsView::CBarsView()
- : CFormView(CBarsView::IDD)
- {
- //{{AFX_DATA_INIT(CBarsView)
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CBarsView::~CBarsView()
- {
- }
-
- void CBarsView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CBarsView)
- DDX_Control(pDX, IDC_RTBARXCTRL1, m_Bar1);
- DDX_Control(pDX, IDC_RTBARXCTRL2, m_Bar2);
- //}}AFX_DATA_MAP
- }
-
- BOOL CBarsView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CBarsView printing
-
- BOOL CBarsView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CBarsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CBarsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- void CBarsView::OnPrint(CDC* pDC, CPrintInfo*)
- {
- // TODO: add code to print the controls
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CBarsView diagnostics
-
- #ifdef _DEBUG
- void CBarsView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CBarsView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CBarsDoc* CBarsView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CBarsDoc)));
- return (CBarsDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CBarsView message handlers
-
- void CBarsView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- BuildGraph1(); //build the first rt bargraph
- BuildGraph2(); //build the second rt bargraph
- }
-
-
- void CBarsView::BuildGraph1()
- {
- m_Bar1.SetBarNumChannels(8);
-
- //ALARM
- m_Bar1.SetBarAlarmMessageEnable(TRUE);
- m_Bar1.SetBarAlarmMarksEnable(TRUE);
- m_Bar1.SetBarHighAlarmValue (5.8);
- m_Bar1.SetBarLowAlarmValue (4.2);
- m_Bar1.SetBarHighAlarmString ("*HI*");
- m_Bar1.SetBarLowAlarmString ("*LO*");
- m_Bar1.SetBarNormalAlarmString ("ok");
-
- //DYN TEXT
- m_Bar1.SetBarDynTextEnable(TRUE);
-
- //SCALING AND CENTER POINT
- m_Bar1.SetBarScaleMin (4.0);
- m_Bar1.SetBarScaleMax (7.0);
- m_Bar1.SetBarScaleCenter (4.0);
- m_Bar1.SetBarTickSpace (1.0);
- m_Bar1.SetBarNumTicks (5);
-
- //AXIS LABEL PRECISION
- m_Bar1.SetBarLabelsPrecision (2);
-
- //COLORS
- m_Bar1.SetWindowBackgroundColor (RGB_WHITE);
-
- //TITLE
- m_Bar1.SetTitleString (TITLE1,"Vertical Bar Graph");
-
- //INTERNAL TIMER
- m_Bar1.SetEnableInternalTimer(TRUE);
-
- }
-
-
- void CBarsView::BuildGraph2()
- {
- m_Bar2.SetBarNumChannels(4);
- m_Bar2.SetBarType (OR_HORZ); //draw a horizontal bar graph
-
- //COLORS
- m_Bar2.SetWindowBackgroundColor(RGB (128, 128, 0));
- m_Bar2.SetPlotBackgroundColor(RGB (128, 64, 0));
-
- //ALARMS
- m_Bar2.SetBarAlarmMarksEnable(TRUE);
- m_Bar2.SetBarAlarmMessageEnable(TRUE);
- m_Bar2.SetBarHighAlarmValue (5.9);
- m_Bar2.SetBarLowAlarmValue (4.1);
- m_Bar2.SetBarNumTicks (9);
-
- //TAG NAMES
- m_Bar2.SetBarChannelTagName(0, "One");
- m_Bar2.SetBarChannelTagName(1, "Two");
- m_Bar2.SetBarChannelTagName(2, "Three");
- m_Bar2.SetBarChannelTagName(3, "Four");
-
- // BAR COLORS
- m_Bar2.SetBarChannelColor(0, RGB (0, 0, 128));
- m_Bar2.SetBarChannelColor(1, RGB (255, 255, 0));
- m_Bar2.SetBarChannelColor(2, RGB (255, 255, 255));
- m_Bar2.SetBarChannelColor(3, RGB (0, 0, 0));
-
- //TITLES
- m_Bar2.SetTitleString (TITLE1,"Horizontal Bar Graph");
-
- //INTERNAL TIMER
- m_Bar2.SetEnableInternalTimer(TRUE);
-
- }
-
- BEGIN_EVENTSINK_MAP(CBarsView, CFormView)
- //{{AFX_EVENTSINK_MAP(CBarsView)
- ON_EVENT(CBarsView, IDC_RTBARXCTRL1, 1 /* OnInternalTimer */, OnInternalTimerRtbarxctrl1, VTS_NONE)
- ON_EVENT(CBarsView, IDC_RTBARXCTRL2, 1 /* OnInternalTimer */, OnInternalTimerRtbarxctrl2, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CBarsView::OnInternalTimerRtbarxctrl1()
- {
- double rData[MAX_RTBARX_BARS];
- double rMin = min(m_Bar1.GetBarScaleMin (), m_Bar1.GetBarScaleMax ());
- double rMax = max(m_Bar1.GetBarScaleMin (), m_Bar1.GetBarScaleMax ());
- double rCenter = rMin + (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- int i;
- for (i=0; i < m_Bar1.GetBarNumChannels(); i++)
- {
- rData[i] = rCenter + rRange * 0.3 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- if (rData[i] > rMax)
- rData[i] = rMax;
- else
- if (rData[i] < rMin)
- rData[i] = rMin;
- }
- m_Bar1.UpdateDynData (rData);
-
- }
-
- void CBarsView::OnInternalTimerRtbarxctrl2()
- {
- double rData[MAX_RTBARX_BARS];
- double rMin = min(m_Bar2.GetBarScaleMin (), m_Bar2.GetBarScaleMax ());
- double rMax = max(m_Bar2.GetBarScaleMin (), m_Bar2.GetBarScaleMax ());
- double rCenter = rMin + (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- int i;
- for (i=0; i < m_Bar2.GetBarNumChannels(); i++)
- {
- rData[i] = rCenter + rRange * 0.2 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- if (rData[i] > rMax)
- rData[i] = rMax;
- else
- if (rData[i] < rMin)
- rData[i] = rMin;
- }
- m_Bar2.UpdateDynData (rData);
-
-
- }
-