home *** CD-ROM | disk | FTP | other *** search
- // ScrollView.cpp : implementation of the CMyScrollView class
- //
-
- #include "stdafx.h"
- #include "Scroll.h"
-
- #include "ScrollDoc.h"
- #include "ScrollView.h"
- #include "ctwxdef.h"
- #include <math.h>
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyScrollView
-
- IMPLEMENT_DYNCREATE(CMyScrollView, CFormView)
-
- BEGIN_MESSAGE_MAP(CMyScrollView, CFormView)
- //{{AFX_MSG_MAP(CMyScrollView)
- // 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()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyScrollView construction/destruction
-
- CMyScrollView::CMyScrollView()
- : CFormView(CMyScrollView::IDD)
- {
- //{{AFX_DATA_INIT(CMyScrollView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CMyScrollView::~CMyScrollView()
- {
- }
-
- void CMyScrollView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMyScrollView)
- DDX_Control(pDX, IDC_SCROLLXCTRL1, m_RTScroll1);
- DDX_Control(pDX, IDC_SCROLLXCTRL2, m_RTScroll2);
- DDX_Control(pDX, IDC_SCROLLXCTRL3, m_RTScroll3);
- DDX_Control(pDX, IDC_SCROLLXCTRL4, m_RTScroll4);
- DDX_Control(pDX, IDC_SCROLLXCTRL5, m_RTScroll5);
- //}}AFX_DATA_MAP
- }
-
- BOOL CMyScrollView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyScrollView printing
-
- BOOL CMyScrollView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CMyScrollView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CMyScrollView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- void CMyScrollView::OnPrint(CDC* pDC, CPrintInfo*)
- {
- // TODO: add code to print the controls
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyScrollView diagnostics
-
- #ifdef _DEBUG
- void CMyScrollView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CMyScrollView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CScrollDoc* CMyScrollView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScrollDoc)));
- return (CScrollDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CMyScrollView message handlers
-
- BEGIN_EVENTSINK_MAP(CMyScrollView, CFormView)
- //{{AFX_EVENTSINK_MAP(CMyScrollView)
- ON_EVENT(CMyScrollView, IDC_SCROLLXCTRL1, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl1, VTS_NONE)
- ON_EVENT(CMyScrollView, IDC_SCROLLXCTRL2, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl2, VTS_NONE)
- ON_EVENT(CMyScrollView, IDC_SCROLLXCTRL3, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl3, VTS_NONE)
- ON_EVENT(CMyScrollView, IDC_SCROLLXCTRL4, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl4, VTS_NONE)
- ON_EVENT(CMyScrollView, IDC_SCROLLXCTRL5, 1 /* OnInternalTimer */, OnInternalTimerScrollxctrl5, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
-
- void CMyScrollView::OnInternalTimerScrollxctrl1()
- {
-
- double rData[16];
- int i;
- static double rLastData[16];
- static BOOL bFirstDemoPass = FALSE;
-
- double rMin = min( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
- double rMax = max( m_RTScroll1.GetAxisMin (Y_AXIS1), m_RTScroll1.GetAxisMax (Y_AXIS1));
- double rCenter = (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- for (i=0; i < m_RTScroll1.GetSDataNumGroups (0); i++)
- {
- if (!bFirstDemoPass)
- rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData[i] = rLastData[i] + 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;
- rLastData[i] = rData[i];
- }
-
- bFirstDemoPass = TRUE;
- m_RTScroll1.UpdateDynData (0, rData);
- }
-
- void CMyScrollView::OnInternalTimerScrollxctrl2()
- {
- double rData[16], rData2[16];
- int i;
- static double rLastData[16], rLastData2[16];
- static BOOL bFirstDemoPass = FALSE;
-
- double rMin = min( m_RTScroll2.GetAxisMin (X_AXIS1), m_RTScroll2.GetAxisMax (X_AXIS1));
- double rMax = max( m_RTScroll2.GetAxisMin (X_AXIS1), m_RTScroll2.GetAxisMax (X_AXIS1));
- double rCenter = (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- for (i=0; i < m_RTScroll2.GetSDataNumGroups (0); i++)
- {
- if (!bFirstDemoPass)
- rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData[i] = rLastData[i] + 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;
- rLastData[i] = rData[i];
- }
-
- for (i=0; i < m_RTScroll2.GetSDataNumGroups (1); i++)
- {
- if (!bFirstDemoPass)
- rData2[i] = rCenter + rRange * 0.05 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData2[i] = rLastData2[i] + rRange * 0.2 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
-
- if (rData2[i] > rMax)
- rData2[i] = rMax;
- else
- if (rData2[i] < rMin)
- rData2[i] = rMin;
- rLastData2[i] = rData2[i];
- }
-
-
- bFirstDemoPass = TRUE;
- m_RTScroll2.UpdateDynData (0, rData);
- m_RTScroll2.UpdateDynData (0, rData2);
-
- }
-
- void CMyScrollView::OnInternalTimerScrollxctrl3()
- {
- double rData[16];
- int i;
- static double rLastData[16];
- static BOOL bFirstDemoPass = FALSE;
-
- double rMin = min( m_RTScroll3.GetAxisMin (Y_AXIS1), m_RTScroll3.GetAxisMax (Y_AXIS1));
- double rMax = max( m_RTScroll3.GetAxisMin (Y_AXIS1), m_RTScroll3.GetAxisMax (Y_AXIS1));
- double rCenter = (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- for (i=0; i < m_RTScroll3.GetSDataNumGroups(0); i++)
- {
- if (!bFirstDemoPass)
- rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData[i] = rLastData[i] + 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;
- rLastData[i] = rData[i];
- }
-
- bFirstDemoPass = TRUE;
- m_RTScroll3.UpdateDynData (0, rData);
-
- }
-
- void CMyScrollView::OnInternalTimerScrollxctrl4()
- {
- static nUpdateCounter=0;
-
- double rData[16];
- int i;
- static double rLastData[16];
- static BOOL bFirstDemoPass = FALSE;
-
- double rMin = min( m_RTScroll3.GetAxisMin (Y_AXIS1), m_RTScroll3.GetAxisMax (Y_AXIS1));
- double rMax = max( m_RTScroll3.GetAxisMin (Y_AXIS1), m_RTScroll3.GetAxisMax (Y_AXIS1));
- double rCenter = (rMax - rMin) /2;
- double rRange = (rMin - rMax);
-
- for (i=0; i < m_RTScroll4.GetSDataNumGroups(0); i++)
- {
- if (i < (m_RTScroll4.GetSDataNumGroups(0) -1))
- {
- if (!bFirstDemoPass)
- rData[i] = rCenter + rRange * 1.0 * ( 0.5 - ((double) rand() / (double) RAND_MAX));
- else
- rData[i] = rLastData[i] + 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;
- rLastData[i] = rData[i];
- } else
- {
- if ((nUpdateCounter / 20) % 2)
- rData[i] = 20.0 * ((double) rand() / (double) RAND_MAX);
- else
- rData[i] = 2.0 * ((double) rand() / (double) RAND_MAX);
- }
- }
- nUpdateCounter++;
- bFirstDemoPass = TRUE;
- m_RTScroll4.UpdateDynData (0, rData);
-
- }
-
- void CMyScrollView::OnInternalTimerScrollxctrl5()
- {
- static nUpdateCounter=0;
-
- double rData[16];
- double rMin = min( m_RTScroll5.GetAxisMin (Y_AXIS1), m_RTScroll5.GetAxisMax (Y_AXIS1));
- double rMax = max( m_RTScroll5.GetAxisMin (Y_AXIS1), m_RTScroll5.GetAxisMax (Y_AXIS1));
- double rRange = (rMin - rMax);
- double rUpdateValue;
- int i;
-
- int npp = m_RTScroll5.GetScrollXYNumPoints(0);
-
- int ng = m_RTScroll5.GetSDataNumGroups(0);
- for (i=0; i < m_RTScroll5.GetSDataNumGroups(0)/2; i++)
- {
- rUpdateValue = (double) nUpdateCounter / (m_RTScroll5.GetScrollXYNumPoints(0)/6.2);
- rData[i] = 0.95 * rRange * sin ( rUpdateValue ) / 2;
- rData[i+m_RTScroll5.GetSDataNumGroups(0)/2] = 0.95 * rRange *
- sin(rUpdateValue *1.1 + 0.5 + (double)i * rUpdateValue)/2;
- }
- nUpdateCounter++;
- m_RTScroll5.UpdateDynData (0, rData);
-
- }
-
-
-
-
- void CMyScrollView::BuildGraph1()
- {
- m_RTScroll1.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll1.SetSPlotType (0, SCROLLING_LINE_GRAPH);
- m_RTScroll1.SetSDataNumGroups (0, 4); // four channels of data
-
- //axis
- m_RTScroll1.SetAxisMax (X_AXIS1, 25.0); // x axis from 0 - 25
- m_RTScroll1.SetAxisEnable (X_AXIS2, TRUE); //enable the second x axis
- m_RTScroll1.SetAxisEnable (Y_AXIS2, TRUE); //enable the second x axis
- m_RTScroll1.SetAxisMajorTickInterval (X_AXIS1, 5.0); //label every 5 units
-
- //alarm updating
- m_RTScroll1.SetScrollAlarmMarksEnable (0, TRUE); //enable alarm marks
- m_RTScroll1.SetScrollLowAlarmEnable (0, TRUE); //enable lo alarm line
- m_RTScroll1.SetScrollHighAlarmEnable (0, TRUE); //enable hi alarm line
- m_RTScroll1.SetScrollSetpointEnable (0, TRUE); //enable set point line
-
- //title
- m_RTScroll1.SetTitleString (TITLE1,"Scroll Graph"); //graph title
-
- //window
- m_RTScroll1.SetWindowBackgroundColor (C_PALEBLUE); //background color
- m_RTScroll1.SetWindowBorderStyle (RC_HIGH);
-
- //use internal timer
- m_RTScroll1.SetEnableInternalTimer(TRUE);
-
- }
-
-
- void CMyScrollView::BuildGraph2()
- {
- m_RTScroll2.SetSPlotType (0, SWEEP_GRAPH); //<<constant needed for type
- m_RTScroll2.SetScrollDirection (0, OR_VERT); // vertical scrolling
- m_RTScroll2.SetScrollDirection (1, OR_VERT); // vertical scrolling
- m_RTScroll2.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll2.SetSDataNumGroups (0, 2); // two channels of data
- m_RTScroll2.SetSDataEnable (1, TRUE); // enable the 2ND data set
- m_RTScroll2.SetSDataNumGroups (1, 1); // one channels of data
-
- //axis attributes
- m_RTScroll2.SetAxisMax (Y_AXIS1, 25.0); // Y axis from 0 - 25
- m_RTScroll2.SetAxisMajorTickInterval (Y_AXIS1, 5.0);
-
- //font attributes for axis labels
- m_RTScroll2.SetAxisLabelFontStyle (X_AXIS1, TEXT_BOLD);
- m_RTScroll2.SetAxisLabelFontStyle (Y_AXIS1, TEXT_BOLD);
- m_RTScroll2.SetAxisLabelFontSize (X_AXIS1, 10);
- m_RTScroll2.SetAxisLabelFontSize (Y_AXIS1, 10);
- m_RTScroll2.SetAxisLabelColor (X_AXIS1, C_LIGHTBLUE);
- m_RTScroll2.SetAxisLabelColor (Y_AXIS1, C_LIGHTBLUE);
-
- m_RTScroll2.SetScrollSweepLineColor (0, C_LIGHTRED); // set color for sweep line
- m_RTScroll2.SetScrollLineColor (0, 0, C_YELLOW);
- m_RTScroll2.SetScrollLineColor (0, 1, C_WHITE);
- m_RTScroll2.SetScrollLineColor (1, 0, C_BLUE);
-
- //title
- m_RTScroll2.SetTitleString (TITLE1,"Sweep Graph");
- m_RTScroll2.SetTitleFontStyle (TITLE1, TEXT_BOLD);
- m_RTScroll2.SetTitleFontSize (TITLE1, 12);
-
- m_RTScroll2.SetAxisTitleString (X_AXIS1,"X Axis Title");
- m_RTScroll2.SetAxisTitleString (Y_AXIS1,"Y Axis Title");
-
- //colors
- m_RTScroll2.SetPlotBackgroundColor (RGB (128, 128, 255));
- m_RTScroll2.SetWindowBackgroundColor (C_PALEBLUE);
-
- //plotting area
- m_RTScroll2.SetRightPlotArea (0.92);
- m_RTScroll2.SetBottomPlotArea (0.8);
-
- //use internal timer
- m_RTScroll2.SetEnableInternalTimer(TRUE);
- }
-
-
- void CMyScrollView::BuildGraph3()
- {
- m_RTScroll3.SetSPlotType (0, SCROLLING_BAR_GRAPH ); //<<constant needed for type
- m_RTScroll3.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll3.SetScrollRelReset (0, 0.5); //reset to 1/2
-
- //axis
- m_RTScroll3.SetAxisMax (Y_AXIS1, 15.0); // y axis range -5 to 15
- m_RTScroll3.SetAxisMin (Y_AXIS1, -5.0);
- m_RTScroll3.SetAxisMajorTickInterval (Y_AXIS1, 5.0); //label every 5 units
- m_RTScroll3.SetAxisGridEnable (Y_AXIS1, TRUE);
-
- //colors
- m_RTScroll3.SetWindowBackgroundColor (C_PALEBLUE);
-
- //title
- m_RTScroll3.SetTitleFontStyle (TITLE1, TEXT_BOLD);
- m_RTScroll3.SetTitleString (TITLE1,"Scrolling Bar");
-
- //internal timer
- m_RTScroll3.SetEnableInternalTimer(TRUE);
-
- }
-
-
- void CMyScrollView::BuildGraph4()
- {
- CString sLegendStrings, CR = " ";
-
- m_RTScroll4.SetSPlotType (0, VARIABLE_SCROLLING_GRAPH); //<<constant
- m_RTScroll4.SetTitleString (TITLE1, "Variable Scrolling");
- m_RTScroll4.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll4.SetSDataNumGroups (0, 5); // Groups must = #channels + 1
- m_RTScroll4.SetAxisMax (X_AXIS1, 50.0); // x axis from 0 - 50
-
- m_RTScroll4.SetScrollLineColor(0, 0, C_GREEN);
- m_RTScroll4.SetScrollLineColor(0, 1, C_LIGHTMAGENTA);
- m_RTScroll4.SetScrollLineColor(0, 2, C_LIGHTRED);
- m_RTScroll4.SetScrollLineColor(0, 3, C_LIGHTBLUE);
-
- m_RTScroll4.SetLeftPlotArea (0.12);
- m_RTScroll4.SetTopPlotArea (0.3);
- m_RTScroll4.SetRightPlotArea (0.92);
- m_RTScroll4.SetBottomPlotArea (0.87);
-
- //legends
- CR.SetAt(0,(char) 13); // make CR a carriage return string;
- sLegendStrings = "Boston" + CR + "Chicago" + CR + "Los Angeles" + CR +"Dallas" + CR;
- m_RTScroll4.SetSLegendEnable (TRUE); //must enable to view!
- m_RTScroll4.SetSLegendLeft (0.05); //establish position
- m_RTScroll4.SetSLegendTop (0.08);
- m_RTScroll4.SetSLegendRight (0.95);
- m_RTScroll4.SetSLegendBottom(0.27);
- m_RTScroll4.SetSLegendOrientation (OR_HORZ); //horizontal
- m_RTScroll4.SetSLegendFontSize (8);
- m_RTScroll4.SetSLegendStrings(sLegendStrings);
-
- //colors
- m_RTScroll4.SetWindowBackgroundColor (C_PALEBLUE);
-
- //internal timer
- m_RTScroll4.SetEnableInternalTimer(TRUE);
-
- }
-
- void CMyScrollView::BuildGraph5()
- {
- m_RTScroll5.SetSPlotType (0, SCROLLING_XY_GRAPH); //<<constant needed for type
- m_RTScroll5.SetSDataNumGroups (0, 4); // groups must = #channels * 2
- m_RTScroll5.SetSDataEnable (0, TRUE); // enable the 1st data set
- m_RTScroll5.SetScrollXYNumPoints (0, 100); // 100 pts in the buffer
-
- //axis
- m_RTScroll5.SetAxisMin (X_AXIS1, -10.0); // x axis from -10 - 10
- m_RTScroll5.SetAxisMax (X_AXIS1, 10.0);
- m_RTScroll5.SetAxisMin (Y_AXIS1, -10.0); // x axis from -10 - 10
- m_RTScroll5.SetAxisMax (Y_AXIS1, 10.0);
-
- //color
- m_RTScroll5.SetWindowBackgroundColor (C_PALEBLUE);
-
- //title
- m_RTScroll5.SetTitleString (TITLE1,"XY Plot");
-
- //timer
- m_RTScroll5.SetEnableInternalTimer(TRUE);
- }
-
-
-
- void CMyScrollView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- BuildGraph1();
- BuildGraph2();
- BuildGraph3();
- BuildGraph4();
- BuildGraph5();
-
- }
-