/***************************************************************************** * * 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 #include #pragma hdrstop #include "stack1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "OlectraChart2D_TLB" #pragma resource "*.dfm" const ocHugeValue = 1E+308; TfrmStack *frmStack; //--------------------------------------------------------------------------- __fastcall TfrmStack::TfrmStack(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TfrmStack::mnuExitClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::Chart2D1ModifyEnd(TObject *Sender) //Let other code know that the chart is back to normal. { int Code; int Value; ChartModify = False; //Update the 3D values now that the modify is complete Variant vCA = Chart2D1->ChartArea_; Variant vView3D = vCA.OlePropertyGet("View3D"); Value = vView3D.OlePropertyGet("Depth"); txtDepth->Text = IntToStr(Value); //Make sure that there is a depth, and if not, keep all values at 0 if (StrToInt(txtDepth->Text) > 0) { txtElevation->Text = IntToStr(vView3D.OlePropertyGet("Elevation")); txtRotation->Text = IntToStr(vView3D.OlePropertyGet("Rotation")); } else { txtElevation->Text = "0"; txtRotation->Text = "0"; vView3D.OlePropertySet("Elevation", StrToInt(txtElevation->Text)); vView3D.OlePropertySet("Rotation", StrToInt(txtRotation->Text)); } } //--------------------------------------------------------------------------- void __fastcall TfrmStack::Chart2D1ModifyStart(TObject *Sender, VARIANT_BOOL *IsOK) //Let other code know that the chart is being modified. { ChartModify = true; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::Chart2D1MouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) //If the user presses the left-mouse button then store the series and point // values for use when dragging the bar. { //Make sure we are not in being modified using the middle-mouse button if (ChartModify == true) return; long Series; long Point; long Distance; RegionConstants Region; Variant vValue; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item" ,1); if (Button == mbLeft) { //Region = (RegionConstants)(short)vCG1.OleFunction("CoordToDataIndex", (long)X, (long)Y, oc2dFocusXY, &Series, &Point, &Distance); vCG1.OleFunction("CoordToDataIndex", (long)X, (long)Y, oc2dFocusXY, &Series, &Point, &Distance); if (Series > 0) { SaveSeries = Series; SavePoint = Point; LeftMouseButton = True; } } } //--------------------------------------------------------------------------- void __fastcall TfrmStack::Chart2D1MouseMove(TObject *Sender, TShiftState Shift, int X, int Y) //Track the mouse movement and if over a bar, then make the markers visible on // the bar in the series and point that the mouse is currently over. //If the user has the left-mouse button pressed then change the value of the bar accordingly. { double vx; double vy; String HoldSeries; String HoldPoint; //Make sure we are not in being modified using the middle-mouse button if (ChartModify == true) return; long Series; long Point; long Distance; long HoldValue; RegionConstants Region; Variant vValue; char sBuffer[80]; Variant vFooter = Chart2D1->Footer; Variant vText = vFooter.OlePropertyGet("Text"); Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item" ,1); Variant vCG1Data = vCG1.OlePropertyGet("Data"); Variant vCA = Chart2D1->ChartArea_; Variant vMarkers = vCA.OlePropertyGet("Markers"); Variant vMarkerX = vMarkers.OlePropertyGet("Item", "X"); if (LeftMouseButton == false) { Region = (RegionConstants)(short)vCG1.OleFunction("CoordToDataIndex", (long)X, (long)Y, oc2dFocusXY, &Series, &Point, &Distance); if ((Distance <= 5) && (Region == oc2dRegionInChartArea)) { sprintf(sBuffer, "Series #%i Point #%i", Series, Point); vText.OlePropertySet("Text", sBuffer); Variant vIndex = vMarkerX.OlePropertyGet("Index"); HoldValue = vIndex.OlePropertyGet("Series"); if (HoldValue != Series) vIndex.OlePropertySet("Series", Series); HoldValue = vIndex.OlePropertyGet("Point"); if (HoldValue != Point) vIndex.OlePropertySet("Point", Point); HoldValue = vMarkerX.OlePropertyGet("IsShowing"); if (HoldValue != true) vMarkerX.OlePropertySet("IsShowing", true); } else { vMarkerX.OlePropertySet("IsShowing", false); vText.OlePropertySet("Text", "Nowhere"); } } //If the left button is being held else if (LeftMouseButton == true) { vCG1.OleFunction("CoordToDataCoord", (long)X, (long)Y, &vx, &vy); //Make sure the value we are at is a visible value (Hole values are invisible) if ((vy != ocHugeValue) && (SaveSeries > 0) && (SavePoint > 0)) { //Limit the drag value if (vy > 100) vy = 100; else if (vy < -100) vy = -100; vCG1Data.OlePropertySet("Y", SaveSeries, SavePoint, vy); //Set the new size of the bar } } } //--------------------------------------------------------------------------- void __fastcall TfrmStack::Chart2D1MouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) //Watch for the user to let go of the mouse button and reset the saved series and point values. { SaveSeries = 0; SavePoint = 0; LeftMouseButton = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::chkOutlinesClick(TObject *Sender) //Turn the black outlines on/off. { Variant vCA = Chart2D1->ChartArea_; vCA.OlePropertySet("IsShowingOutlines", chkOutlines->Checked); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::chkIs100PercentClick(TObject *Sender) //Set the Y-Axes to 100%. { Variant vCA = Chart2D1->ChartArea_; Variant vAxes = vCA.OlePropertyGet("Axes"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); vYAxis.OlePropertySet("Is100Percent", chkIs100Percent->Checked); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::chkReversedClick(TObject *Sender) //Re-order the legend based on the user's selection. { Variant vLegend = Chart2D1->Legend_; vLegend.OlePropertySet("IsReversed", chkReversed->Checked); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::FormCreate(TObject *Sender) //This is where it all begins! { //Setup the helpfile for the application to use //App.HelpFile = "OLCH-DMO.HLP" //Start with the form in the Top-Left Corner Top = 0; Left = 0; //Setup the marker style Variant vCA = Chart2D1->ChartArea_; Variant vMarkers = vCA.OlePropertyGet("Markers"); Variant vMarkerX = vMarkers.OlePropertyGet("Item", "X"); Variant vStyle = vMarkerX.OlePropertyGet("Style"); vStyle.OlePropertySet("Pattern", oc2dLineLongDash); vStyle.OlePropertySet("Color", (int)ocColorBlack); vStyle.OlePropertySet("Width", 6); vMarkerX.OlePropertySet("Method", oc2dMarkerDataIndex); //Set the attach method for the marker //The Chart is not currently being modified ChartModify = false; //Stack all applicable Chart Types Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("IsStacked", true); //Do some setup for the Legend Variant vLegend = Chart2D1->Legend_; Variant vText = vLegend.OlePropertyGet("Text"); vText.OlePropertySet("Text", "Series"); Variant vBorder = vLegend.OlePropertyGet("Border"); vBorder.OlePropertySet("Type", oc2dBorderEtchedIn); Variant vFont = vLegend.OlePropertyGet("Font"); vFont.OlePropertySet("Bold", true); //Setup the default 3D View Options Variant vView3D = vCA.OlePropertyGet("View3D"); vView3D.OlePropertySet("Depth", StrToInt(txtDepth->Text)); vView3D.OlePropertySet("Elevation", StrToInt(txtElevation->Text)); vView3D.OlePropertySet("Rotation", StrToInt(txtRotation->Text)); //Update the status of the frames based on the selected Chart Type rbTypePlotClick(rbTypePlot); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::FormResize(TObject *Sender) //The user has chosen to resize the form. { if (ClientWidth > 5) Chart2D1->Width = ClientWidth; else Chart2D1->Width = 5; if (ClientHeight > 100) //Using 94 pixels to compensate for the control being 94 pixels // from the top of the form Chart2D1->Height = ClientHeight - 94; else Chart2D1->Height = 5; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypePlotClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypePlot); gb3DView->Enabled = false; txtDepth->Enabled = false; txtElevation->Enabled = false; txtRotation->Enabled = false; gbOutlines->Enabled = false; chkOutlines->Enabled = false; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitDegrees); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypeBarClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypeStackingBar); gb3DView->Enabled = true; txtDepth->Enabled = true; txtElevation->Enabled = true; txtRotation->Enabled = true; gbOutlines->Enabled = true; chkOutlines->Enabled = true; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitDegrees); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypeAreaClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypeArea); gb3DView->Enabled = false; txtDepth->Enabled = false; txtElevation->Enabled = false; txtRotation->Enabled = false; gbOutlines->Enabled = true; chkOutlines->Enabled = true; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitDegrees); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypePolarClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypePolar); gb3DView->Enabled = false; txtDepth->Enabled = false; txtElevation->Enabled = false; txtRotation->Enabled = false; gbOutlines->Enabled = false; chkOutlines->Enabled = false; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitRadians); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypeRadarClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypeRadar); gb3DView->Enabled = false; txtDepth->Enabled = false; txtElevation->Enabled = false; txtRotation->Enabled = false; gbOutlines->Enabled = false; chkOutlines->Enabled = false; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitDegrees); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::rbTypeFilledRadarClick(TObject *Sender) //Change the Chart Type to reflect the choice of the user. { Chart2D1->IsBatched = true; Variant vCG = Chart2D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc2dTypeFilledRadar); gb3DView->Enabled = false; txtDepth->Enabled = false; txtElevation->Enabled = false; txtRotation->Enabled = false; gbOutlines->Enabled = true; chkOutlines->Enabled = true; Variant vCArea = Chart2D1->ChartArea_; vCArea.OlePropertySet("AngleUnit", oc2dAngleUnitDegrees); Chart2D1->IsBatched = false; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtDepthChange(TObject *Sender) //Update the Depth Value in the Chart. { Variant vCA = Chart2D1->ChartArea_; Variant vView3D = vCA.OlePropertyGet("View3D"); int Size = txtDepth->GetTextLen(); if (Size > 0) vView3D.OlePropertySet("Depth", StrToInt(txtDepth->Text)); else vView3D.OlePropertySet("Depth", 0); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtDepthExit(TObject *Sender) //Make sure there is always a value in the Textbox. { txtDepth->Text = Trim(txtDepth->Text); int Size = txtDepth->GetTextLen(); if (Size == 0) txtDepth->Text = "0"; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtDepthKeyPress(TObject *Sender, char &Key) //Only allow the numbers, minus sign, backspace, tab and enter keys to be entered. { if (((Key < 48) || (Key > 57)) && (Key != 45) && (Key != 8) && (Key != 9) && (Key != 13)) Key = 0; if (Key == 13) { Key = 0; txtElevation->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtElevationChange(TObject *Sender) //Update the Elevation Value in the Chart. { Variant vCA = Chart2D1->ChartArea_; Variant vView3D = vCA.OlePropertyGet("View3D"); int Size = txtElevation->GetTextLen(); if (Size > 0) vView3D.OlePropertySet("Elevation", StrToInt(txtElevation->Text)); else vView3D.OlePropertySet("Elevation", 0); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtElevationExit(TObject *Sender) //Make sure there is always a value in the Textbox. { txtElevation->Text = Trim(txtElevation->Text); int Size = txtElevation->GetTextLen(); if (Size == 0) txtElevation->Text = "0"; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtElevationKeyPress(TObject *Sender, char &Key) //Only allow the numbers, minus sign, backspace, tab and enter keys to be entered. { if (((Key < 48) || (Key > 57)) && (Key != 45) && (Key != 8) && (Key != 9) && (Key != 13)) Key = 0; if (Key == 13) { Key = 0; txtRotation->SetFocus(); } } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtRotationChange(TObject *Sender) //Update the Rotation Value in the Chart. { Variant vCA = Chart2D1->ChartArea_; Variant vView3D = vCA.OlePropertyGet("View3D"); int Size = txtRotation->GetTextLen(); if (Size > 0) vView3D.OlePropertySet("Rotation", StrToInt(txtRotation->Text)); else vView3D.OlePropertySet("Rotation", 0); } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtRotationExit(TObject *Sender) //Make sure there is always a value in the Textbox. { txtRotation->Text = Trim(txtRotation->Text); int Size = txtRotation->GetTextLen(); if (Size == 0) txtRotation->Text = "0"; } //--------------------------------------------------------------------------- void __fastcall TfrmStack::txtRotationKeyPress(TObject *Sender, char &Key) //Only allow the numbers, minus sign, backspace, tab and enter keys to be entered. { if (((Key < 48) || (Key > 57)) && (Key != 45) && (Key != 8) && (Key != 9) && (Key != 13)) Key = 0; if (Key == 13) { Key = 0; txtDepth->SetFocus(); } } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmStack::mnuAboutThisDemoClick(TObject *Sender) { Application->HelpContext(93); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmStack::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------