/***************************************************************************** * * 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 "actions1.h" #include "oc_color.h" //--------------------------------------------------------------------------- #pragma link "OlectraChart3D_TLB" #pragma resource "*.dfm" TfrmActions *frmActions; //--------------------------------------------------------------------------- __fastcall TfrmActions::TfrmActions(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- // End the program //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuExitClick(TObject *Sender) { exit(0); } //--------------------------------------------------------------------------- // Do some last minute Form and Chart setup //--------------------------------------------------------------------------- void __fastcall TfrmActions::FormActivate(TObject *Sender) { if (FirstPass) { //Clear all the currently defined Actions ClearEvents(); //Don't let the user make changes to the Chart Chart3D1->AllowUserChanges = false; int HoldHScroll; int HoldVScroll; //Setup the Horizontal Scrollbar Variant vCArea = Chart3D1->ChartArea_; Variant vLocation = vCArea.OlePropertyGet("Location"); Variant vLocationLeft = vLocation.OlePropertyGet("Left"); HoldHScroll = vLocationLeft.OlePropertyGet("Value"); HScroll->Min = HoldHScroll; Variant vLocationWidth = vLocation.OlePropertyGet("Width"); HoldHScroll = vLocationWidth.OlePropertyGet("Value"); HScroll->Max = HScroll->Min + HoldHScroll - 1; HScroll->Position = (HScroll->Max - HScroll->Min) / 2; HScroll->SmallChange = 5; HScroll->LargeChange = 30; HScrollValue = HScroll->Position; //Setup the Vertical Scrollbar Variant vLocationTop = vLocation.OlePropertyGet("Top"); HoldVScroll = vLocationTop.OlePropertyGet("Value"); VScroll->Min = HoldVScroll; Variant vLocationHeight = vLocation.OlePropertyGet("Height"); HoldVScroll = vLocationHeight.OlePropertyGet("Value"); VScroll->Max = VScroll->Min + HoldVScroll - 1; VScroll->Position = (VScroll->Max - VScroll->Min) / 2; VScroll->SmallChange = 5; VScroll->LargeChange = 30; VScrollValue = VScroll->Position; //Store the current Action CurrentAction = oc3dActionNone; //Apply the defaults rbNoneClick(rbNone); } } //--------------------------------------------------------------------------- // Setup the Form and the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::FormCreate(TObject *Sender) { FirstPass = true; //Start with the form in the top-left corner Top = 5; Left = 5; //Batch all the updates to the Chart so all the changes occur at once Chart3D1->IsBatched = true; //Setup the main border Variant vBorder = Chart3D1->Border_; vBorder.OlePropertySet("Type", oc3dBorderPlain); vBorder.OlePropertySet("Width", 1); //Setup the colors of the Chart Variant vInterior = Chart3D1->Interior_; vInterior.OlePropertySet("BackgroundColor", (int)ocColorLightGoldenrodYellow); vInterior.OlePropertySet("ForegroundColor", (int)ocColorBlack); Variant vCArea = Chart3D1->ChartArea_; Variant vPlotCube = vCArea.OlePropertyGet("PlotCube"); vInterior = vPlotCube.OlePropertyGet("Interior"); vInterior.OlePropertySet("BackgroundColor", (int)ocColorTan); //Set the Chart type to Bar Variant vCG = Chart3D1->ChartGroups; Variant vCG1 = vCG.OlePropertyGet("Item", 1); vCG1.OlePropertySet("ChartType", oc3dTypeBar); //Setup the amount of data to display Variant vCG1Data = vCG1.OlePropertyGet("ElevationData"); vCG1Data.OlePropertySet("RowCount", 3); vCG1Data.OlePropertySet("ColumnCount", 4); //Setup the data vCG1Data.OlePropertySet("RowOrigin", 1); vCG1Data.OlePropertySet("ColumnOrigin", 1); //Enter some data into the Chart vCG1Data.OlePropertySet("Value", 1, 1, 1.32608); vCG1Data.OlePropertySet("Value", 1, 2, 1.4186); vCG1Data.OlePropertySet("Value", 1, 3, 1.49956); vCG1Data.OlePropertySet("Value", 1, 4, 1.56597); vCG1Data.OlePropertySet("Value", 2, 1, 1.34446); vCG1Data.OlePropertySet("Value", 2, 2, 1.43709); vCG1Data.OlePropertySet("Value", 2, 3, 1.5124); vCG1Data.OlePropertySet("Value", 2, 4, 1.56768); vCG1Data.OlePropertySet("Value", 3, 1, 1.35423); vCG1Data.OlePropertySet("Value", 3, 2, 1.44188); vCG1Data.OlePropertySet("Value", 3, 3, 1.50643); vCG1Data.OlePropertySet("Value", 3, 4, 1.54619); //Turn on all the grid lines Variant vAxes = vCArea.OlePropertyGet("Axes"); Variant vXAxis = vAxes.OlePropertyGet("Item", "X"); Variant vXAxisMGrid = vXAxis.OlePropertyGet("MajorGrid"); Variant vYAxis = vAxes.OlePropertyGet("Item", "Y"); Variant vYAxisMGrid = vYAxis.OlePropertyGet("MajorGrid"); Variant vZAxis = vAxes.OlePropertyGet("Item", "Z"); Variant vZAxisMGrid = vZAxis.OlePropertyGet("MajorGrid"); vXAxisMGrid.OlePropertySet("IsOnXYPlane", true); vXAxisMGrid.OlePropertySet("IsOnXZPlane", true); vYAxisMGrid.OlePropertySet("IsOnXYPlane", true); vYAxisMGrid.OlePropertySet("IsOnYZPlane", true); vZAxisMGrid.OlePropertySet("IsOnXZPlane", true); vZAxisMGrid.OlePropertySet("IsOnYZPlane", true); //Set the scale vPlotCube.OlePropertySet("XScale", 180); vPlotCube.OlePropertySet("YScale", 180); //Setup the rotation Variant vView3D = vCArea.OlePropertyGet("View3D"); vView3D.OlePropertySet("XRotation", 36.5033); vView3D.OlePropertySet("YRotation", 0); vView3D.OlePropertySet("ZRotation", 42.7263); //Setup the Bar color Variant vElevation = vCG1.OlePropertyGet("Elevation"); vElevation.OlePropertySet("IsShaded", true); vElevation.OlePropertySet("ShadedTopColor", (int)ocColorCornsilk); //Resume regular updates to the Chart Chart3D1->IsBatched = false; } //--------------------------------------------------------------------------- // Clear any previously defined Actions //--------------------------------------------------------------------------- void TfrmActions::ClearEvents() { //Remove all the currently defined Action Maps Variant vActions = Chart3D1->ActionMaps; vActions.OleFunction("RemoveAll"); } //--------------------------------------------------------------------------- // Enable/Disable the Rotation Constraints GroupBox and contents //--------------------------------------------------------------------------- void TfrmActions::EnableRotationConstraints(bool Flag) { gbConstraint->Enabled = Flag; rbCXAxis->Enabled = Flag; rbCYAxis->Enabled = Flag; rbCZAxis->Enabled = Flag; rbCEyepoint->Enabled = Flag; rbCSpinTilt->Enabled = Flag; rbCNone->Enabled = Flag; } //--------------------------------------------------------------------------- // Reset the the Scrollbars //--------------------------------------------------------------------------- void TfrmActions::ResetScrollBars(bool hFlag, bool vFlag) { //Reset the Horizontal Scrollbar if (hFlag) { HScrollValue = (HScroll->Max - HScroll->Min) / 2; HScroll->Position = HScrollValue; HScroll->Enabled = hFlag; } else { HScroll->Enabled = hFlag; } //Reset the Vertical Scrollbar if (vFlag) { VScrollValue = (VScroll->Max - VScroll->Min) / 2; VScroll->Position = VScrollValue; VScroll->Enabled = vFlag; } else { VScroll->Enabled = vFlag; } } //--------------------------------------------------------------------------- // Check what restriction to impose on the Chart during a rotate //--------------------------------------------------------------------------- void __fastcall TfrmActions::Chart3D1View3DModify(TObject *Sender, double *XRotation, double *YRotation, double *ZRotation, VARIANT_BOOL *IsOK) { if (rbRotate->Checked) { if (rbCXAxis->Checked) { Chart3D1->CallAction(oc3dActionRotateXAxis, 0, 0); } if (rbCYAxis->Checked) { Chart3D1->CallAction(oc3dActionRotateYAxis, 0, 0); } if (rbCZAxis->Checked) { Chart3D1->CallAction(oc3dActionRotateZAxis, 0, 0); } if (rbCEyepoint->Checked) { Chart3D1->CallAction(oc3dActionRotateEye, 0, 0); } if (rbCSpinTilt->Checked) { YRotation = 0; if (*XRotation < 0) { *XRotation = 0; } if (*XRotation > 90) { *XRotation = 90; } } if (rbCNone->Checked) { Chart3D1->CallAction(oc3dActionRotateFree, 0, 0); } } } //--------------------------------------------------------------------------- // Reset the Chart back to its default //--------------------------------------------------------------------------- void __fastcall TfrmActions::cmdResetClick(TObject *Sender) { Chart3D1->CallAction(oc3dActionReset, 0, 0); ResetScrollBars(HScroll->Enabled, VScroll->Enabled); } //--------------------------------------------------------------------------- // Respond to a change of the Horizontal Scrollbar //--------------------------------------------------------------------------- void __fastcall TfrmActions::HScrollScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { //The user is using the Scrollbar to change the Chart if (HScroll->Position != HScrollValue) { if (HScrollStarted == false) { HScrollStarted = true; Chart3D1->PreviewMethod = oc3dPreviewFull; Chart3D1->CallAction(oc3dActionModifyStart, HScrollValue, VScroll->Position); Chart3D1->CallAction(CurrentAction, HScroll->Position, VScroll->Position); } Chart3D1->CallAction(oc3dActionModifyEnd, HScroll->Position, VScroll->Position); Chart3D1->PreviewMethod = oc3dPreviewCube; HScrollStarted = false; HScrollValue = HScroll->Position; } } //--------------------------------------------------------------------------- // Respond to a change of the Vertical Scrollbar //--------------------------------------------------------------------------- void __fastcall TfrmActions::VScrollScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { //The user is using the Scrollbar to change the Chart if (VScroll->Position != VScrollValue) { if (VScrollStarted == false) { VScrollStarted = true; Chart3D1->PreviewMethod = oc3dPreviewFull; Chart3D1->CallAction(oc3dActionModifyStart, HScroll->Position, VScrollValue); Chart3D1->CallAction(CurrentAction, HScroll->Position, VScroll->Position); } Chart3D1->CallAction(oc3dActionModifyEnd, HScroll->Position, VScroll->Position); Chart3D1->PreviewMethod = oc3dPreviewCube; VScrollStarted = false; VScrollValue = VScroll->Position; } } //--------------------------------------------------------------------------- // User has chosen to do nothing to the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbNoneClick(TObject *Sender) { if (rbNone->Checked) { ClearEvents(); EnableRotationConstraints(false); ResetScrollBars(false, false); CurrentAction = oc3dActionNone; } } //--------------------------------------------------------------------------- // The user has chosen to Move the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbMoveClick(TObject *Sender) { if (rbMove->Checked) { ClearEvents(); Variant vActions = Chart3D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc3dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc3dActionTranslate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc3dActionModifyEnd); vActions.OleFunction("Add", WM_KEYDOWN, MK_LBUTTON, VK_ESCAPE, oc3dActionModifyCancel); EnableRotationConstraints(false); ResetScrollBars(true, true); CurrentAction = oc3dActionTranslate; } } //--------------------------------------------------------------------------- // User has chosen to Scale the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbScaleClick(TObject *Sender) { if (rbScale->Checked) { ClearEvents(); Variant vActions = Chart3D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc3dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc3dActionScale); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc3dActionModifyEnd); vActions.OleFunction("Add", WM_KEYDOWN, MK_LBUTTON, VK_ESCAPE, oc3dActionModifyCancel); EnableRotationConstraints(false); ResetScrollBars(false, true); CurrentAction = oc3dActionScale; } } //--------------------------------------------------------------------------- // User has chosen to Zoom the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbZoomClick(TObject *Sender) { if (rbZoom->Checked) { ClearEvents(); Variant vActions = Chart3D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc3dActionZoomStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc3dActionZoomUpdate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc3dActionZoomEnd); vActions.OleFunction("Add", WM_KEYDOWN, MK_LBUTTON, VK_ESCAPE, oc3dActionZoomCancel); EnableRotationConstraints(false); ResetScrollBars(false, false); CurrentAction = oc3dActionZoomStart; } } //--------------------------------------------------------------------------- // User has chosen to Rotate the Chart //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbRotateClick(TObject *Sender) { if (rbRotate->Checked) { ClearEvents(); Variant vActions = Chart3D1->ActionMaps; vActions.OleFunction("Add", WM_LBUTTONDOWN, 0, 0, oc3dActionModifyStart); vActions.OleFunction("Add", WM_MOUSEMOVE, MK_LBUTTON, 0, oc3dActionRotate); vActions.OleFunction("Add", WM_LBUTTONUP, 0, 0, oc3dActionModifyEnd); vActions.OleFunction("Add", WM_KEYDOWN, MK_LBUTTON, VK_ESCAPE, oc3dActionModifyCancel); EnableRotationConstraints(true); ResetScrollBars(true, true); CurrentAction = oc3dActionRotate; } } //--------------------------------------------------------------------------- // If the Spin & Tilt option is selected, then impose some limits so that // the Chart always stays right side up //--------------------------------------------------------------------------- void __fastcall TfrmActions::rbCSpinTiltClick(TObject *Sender) { if (rbCSpinTilt->Checked) { double HoldXRotation; Variant vCArea = Chart3D1->ChartArea_; Variant vView3D = vCArea.OlePropertyGet("View3D"); HoldXRotation = vView3D.OlePropertyGet("XRotation"); if (HoldXRotation < 0) { vView3D.OlePropertySet("XRotation", 0); } if (HoldXRotation > 90) { vView3D.OlePropertySet("XRotation", 90); } vView3D.OlePropertySet("YRotation", 0); } } //--------------------------------------------------------------------------- // Show the 'About This Demo' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuAboutDemoClick(TObject *Sender) { Application->HelpContext(11); } //--------------------------------------------------------------------------- // Show the 'About Olectra Chart' Help Page //--------------------------------------------------------------------------- void __fastcall TfrmActions::mnuAboutOlectraChartClick(TObject *Sender) { Application->HelpContext(19); } //---------------------------------------------------------------------------