/***************************************************************************** * * Copyright (c) 1999, KL GROUP INC. All Rights Reserved. * http://www.klgroup.com * * This file is provided for demonstration and educational uses only. * Permission to use, copy, modify and distribute this file for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of KL Group not be used in advertising * or publicity pertaining to this material without the specific, * prior written permission of an authorized representative of * KL Group. * * KL GROUP MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR * PURPOSE, OR NON-INFRINGEMENT. KL GROUP SHALL NOT BE LIABLE FOR ANY * DAMAGES SUFFERED BY USERS AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. * *****************************************************************************/ //--------------------------------------------------------------------------- #include #pragma hdrstop #include "stripper1.h" #include #include //--------------------------------------------------------------------------- #pragma link "OlectraChart2D_TLB" #pragma resource "*.dfm" TfrmStripper *frmStripper; const float Pi = 3.1415926535; const float XIncr = 0.0025; //--------------------------------------------------------------------------- __fastcall TfrmStripper::TfrmStripper(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- // Tell the Chart it is not ok to be modified //--------------------------------------------------------------------------- void __fastcall TfrmStripper::Chart2D1ModifyStart(TObject *Sender, VARIANT_BOOL *IsOK) { *IsOK = false; } //--------------------------------------------------------------------------- // End the program //--------------------------------------------------------------------------- void __fastcall TfrmStripper::mnuExitClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- // Do some preliminary setup //--------------------------------------------------------------------------- void __fastcall TfrmStripper::FormCreate(TObject *Sender) { //Don't let the end user make changes to the Chart Chart2D1->AllowUserChanges = false; FirstPass = true; //Start with the form in the top-left corner Top = 5; Left = 5; //Set the Timer so it doesn't do anything Timer1->Interval = 0; } //--------------------------------------------------------------------------- // Setup the Chart //--------------------------------------------------------------------------- void __fastcall TfrmStripper::FormActivate(TObject *Sender) { if (FirstPass == true) { FirstPass = false; //Setup the starting values scrUpdatesPerSecChange(scrUpdatesPerSec); EachTime = scrPointsPerInt->Position; ArraySize = scrNumPoints->Position; ShiftSize = ArraySize - (ArraySize * (scrScrollBack->Position / 100.0)); NextX = 0; //Store a reference to the data object for use throughout the program Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1Data = vCG1.OlePropertyGet("Data"); //Batch all the updates to the Chart so all the changes occur at once Chart2D1->IsBatched = true; //Setup the Axes Variant vCArea = Chart2D1->ChartArea_; Variant vAxes = vCArea.OlePropertyGet("Axes"); vXAxis = vAxes.OlePropertyGet("Item", "X"); vXAxis.OlePropertySet("Min", 0); vXAxis.OlePropertySet("Max", (ArraySize - 1) * XIncr); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); vYAxis.OlePropertySet("Min", -6); vYAxis.OlePropertySet("Max", 6); //Setup the Data vCG1Data.OlePropertySet("IsBatched", true); vCG1Data.OlePropertySet("Layout", oc2dDataArray); vCG1Data.OlePropertySet("NumSeries", 1); vCG1Data.OlePropertySet("NumPoints", 1, ArraySize); vCG1Data.OlePropertySet("FirstSeries", 1); vCG1Data.OlePropertySet("LastSeries", 1); vCG1Data.OlePropertySet("FirstPoint", 1, 1); vCG1Data.OlePropertySet("LastPoint", 1, 0); vCG1Data.OlePropertySet("IsBatched", false); //Resume regular updates to the Chart Chart2D1->IsBatched = false; } } //--------------------------------------------------------------------------- // Release some global variables before exiting //--------------------------------------------------------------------------- void __fastcall TfrmStripper::FormDestroy(TObject *Sender) { //Release the Variants to give the memory back when the program exits vCG1Data.Clear(); vXAxis.Clear(); } //--------------------------------------------------------------------------- // Respond to the user changing the number of updates desired //--------------------------------------------------------------------------- void __fastcall TfrmStripper::scrUpdatesPerSecChange(TObject *Sender) { //Change the Timer frequency based on the Scrollbar value Timer1->Interval = (int)(1000.0 / scrUpdatesPerSec->Position); lblUpdateValue->Caption = scrUpdatesPerSec->Position; } //--------------------------------------------------------------------------- // Respond to the user changing the amount of scroll back desired //--------------------------------------------------------------------------- void __fastcall TfrmStripper::scrScrollBackScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { //Change the amount of scrollback based on the Scrollbar value lblScrollPercent->Caption = scrScrollBack->Position; ShiftSize = ArraySize - (ArraySize * (scrScrollBack->Position / 100.0)); } //--------------------------------------------------------------------------- // Respond the the user changing the number of points to draw //--------------------------------------------------------------------------- void __fastcall TfrmStripper::scrNumPointsScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { int tHold; //Batch all the updates to the Chart so all the changes occur at once Chart2D1->IsBatched = true; lblArraySize->Caption = scrNumPoints->Position; ArraySize = scrNumPoints->Position; ShiftSize = ArraySize - (ArraySize * (scrScrollBack->Position / 100.0)); //Store the current Timer interval and stop the Timer tHold = Timer1->Interval; Timer1->Interval = 0; Timer1->Enabled = false; NextX = 0; vXAxis.OlePropertySet("Min", 0); vXAxis.OlePropertySet("Max", (ArraySize - 1) * XIncr); //Setup the Data object vCG1Data.OlePropertySet("IsBatched", true); vCG1Data.OlePropertySet("Layout", oc2dDataArray); vCG1Data.OlePropertySet("NumSeries", 1); vCG1Data.OlePropertySet("NumPoints", 1, ArraySize); vCG1Data.OlePropertySet("FirstSeries", 1); vCG1Data.OlePropertySet("LastSeries", 1); vCG1Data.OlePropertySet("FirstPoint", 1, 1); vCG1Data.OlePropertySet("LastPoint", 1, 0); vCG1Data.OlePropertySet("IsBatched", false); //Restart the Timer Timer1->Interval = tHold; Timer1->Enabled = true; //Resume regular updates to the Chart Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- // Respond the the user changing the number of points per interval to draw //--------------------------------------------------------------------------- void __fastcall TfrmStripper::scrPointsPerIntScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { //Set the number of points to draw per interval lblNumPoints->Caption = scrPointsPerInt->Position; if (scrPointsPerInt->Position > ArraySize) { scrPointsPerInt->Position = ArraySize; } EachTime = scrPointsPerInt->Position; lblNumPoints->Caption = scrPointsPerInt->Position; } //--------------------------------------------------------------------------- // Turn the data flow on //--------------------------------------------------------------------------- void __fastcall TfrmStripper::rbFlowONClick(TObject *Sender) { //User wants to have data drawn so start the Timer Timer1->Enabled = true; } //--------------------------------------------------------------------------- // Turn the data flow off //--------------------------------------------------------------------------- void __fastcall TfrmStripper::rbFlowOffClick(TObject *Sender) { //User wants to stop drawing data so stop the Timer Timer1->Enabled = false; } //--------------------------------------------------------------------------- // Update the Chart each Time the Timer fires //--------------------------------------------------------------------------- void __fastcall TfrmStripper::Timer1Timer(TObject *Sender) { //Every time the Timer fires, generate the User selected number of points // and add them to the Chart as fast as possible using the FastUpdate // methods provided in Olectra Chart randomize(); int ThisTime; int nHold; int nPoints; int lPoint; float AxisMin; double Value; //Test to see if the new data will fit nPoints = vCG1Data.OlePropertyGet("NumPoints", 1); lPoint = vCG1Data.OlePropertyGet("LastPoint", 1); //New points won't fit, so shift the points down if (lPoint >= nPoints) { //Batch all the updates to the Chart so all the changes occur at once Chart2D1->IsBatched = true; if (ShiftSize != 0) { vCG1Data.OleFunction("ShiftPoints", 1, ShiftSize, 1, ArraySize - ShiftSize + 1); } NextPoint = ShiftSize + 1; //Calculate the X-Axis AxisMin = vXAxis.OlePropertyGet("Min"); vXAxis.OlePropertySet("Min", AxisMin + ((ArraySize - ShiftSize) * XIncr)); AxisMin = vXAxis.OlePropertyGet("Min"); vXAxis.OlePropertySet("Max", AxisMin + ((ArraySize - 1) * XIncr)); vCG1Data.OlePropertySet("LastPoint", 1, ShiftSize); lPoint = vCG1Data.OlePropertyGet("LastPoint", 1); //Resume regular updates to the Chart Chart2D1->IsBatched = false; } else { NextPoint = lPoint + 1; } //Finish drawing the rest of the points so we can do a shift the next time around ThisTime = EachTime; if ((lPoint + ThisTime) > nPoints) { ThisTime = nPoints - lPoint; } //Calculate the value for the next point and add it to the queue to be drawn nHold = random(3) + 1; for (int i = 1; i <= ThisTime; i++) { Value = (NextX * XIncr); vCG1Data.OlePropertySet("X", 1, NextPoint, Value); Value = (2.0 * sin(2.0 * Pi * (NextX * XIncr)) * sin(5.0 * nHold * (NextX * XIncr)) * nHold); vCG1Data.OlePropertySet("Y", 1, NextPoint, Value); NextX = NextX + 1; NextPoint = NextPoint + 1; } //Count how many of the points were drawn using the FastUpdate Method vCG1Data.OleFunction("DrawNewPoints", 1, ThisTime); } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmStripper::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(10); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmStripper::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------