/***************************************************************************** * * 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. */ // scatterView.cpp : implementation of the CScatterView class // #include //For OleCurrencyType #include #include #include #include "stdafx.h" #include "scatter.h" #include "scatterdoc.h" #include "scatterview.h" #include "Border.h" #include "Chart3DData.h" #include "ChartArea.h" #include "ChartGroup.h" #include "ChartGroupCollection.h" #include "Contour.h" #include "DataCoord.h" #include "DataCoordCollection.h" #include "DerivedLong.h" #include "Elevation.h" #include "Font.h" #include "Label.h" #include "LabelCollection.h" #include "Legend.h" #include "Location.h" #include "PlotCube.h" #include "CubeFont.h" #include "Title.h" #include "LineStyle.h" #include "3dconst.h" #include "oc_color.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CScatterView IMPLEMENT_DYNCREATE(CScatterView, CFormView) BEGIN_MESSAGE_MAP(CScatterView, CFormView) //{{AFX_MSG_MAP(CScatterView) ON_WM_CREATE() ON_WM_DESTROY() ON_WM_SIZE() ON_WM_TIMER() ON_COMMAND(ID_FONT_STROKE, OnFontStroke) ON_UPDATE_COMMAND_UI(ID_FONT_STROKE, OnUpdateFontStroke) ON_COMMAND(ID_FONT_TRUETYPE, OnFontTruetype) ON_UPDATE_COMMAND_UI(ID_FONT_TRUETYPE, OnUpdateFontTruetype) ON_COMMAND(ID_VIEW_2DSCATTER, OnView2dscatter) ON_UPDATE_COMMAND_UI(ID_VIEW_2DSCATTER, OnUpdateView2dscatter) ON_COMMAND(ID_VIEW_3DSCATTER, OnView3dscatter) ON_UPDATE_COMMAND_UI(ID_VIEW_3DSCATTER, OnUpdateView3dscatter) ON_COMMAND(ID_VIEW_DROPLINES, OnViewDroplines) ON_UPDATE_COMMAND_UI(ID_VIEW_DROPLINES, OnUpdateViewDroplines) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CScatterView construction/destruction CScatterView::CScatterView() : CFormView(CScatterView::IDD) { //{{AFX_DATA_INIT(CScatterView) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT m_View3D = TRUE; } CScatterView::~CScatterView() { } void CScatterView::DoDataExchange(CDataExchange* pDX) { CFormView::DoDataExchange(pDX); //{{AFX_DATA_MAP(CScatterView) DDX_Control(pDX, IDC_CHART3D, m_chart); //}}AFX_DATA_MAP } BOOL CScatterView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CFormView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CScatterView diagnostics #ifdef _DEBUG void CScatterView::AssertValid() const { CFormView::AssertValid(); } void CScatterView::Dump(CDumpContext& dc) const { CFormView::Dump(dc); } CScatterDoc* CScatterView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CScatterDoc))); return (CScatterDoc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CScatterView message handlers ///////////////////////////////////////////////////////////////////////////// // Do some eary setup ///////////////////////////////////////////////////////////////////////////// int CScatterView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CFormView::OnCreate(lpCreateStruct) == -1) return -1; m_PickSeries = 0; m_PickPoint = 0; m_IsModifying = false; return 0; } ///////////////////////////////////////////////////////////////////////////// // Setup the Form and the Chart ///////////////////////////////////////////////////////////////////////////// void CScatterView::OnInitialUpdate() { COleCurrency hFontSize; CFormView::OnInitialUpdate(); // Pre-Define some variables for easier reference later m_cGroup = m_chart.GetChartGroups().GetItem(COleVariant(short(1))); // Batch all the updates to the Chart m_chart.SetIsBatched(true); // Set the Chart type to scatter m_chart.GetChartGroups().GetItem(COleVariant((short)1)).SetChartType(oc3dTypeScatter); // Setup the ChartArea m_chart.GetChartArea().GetPlotCube().GetInterior().SetBackgroundColor(ocColorAliceBlue); // Setup the Data Group m_cGroup.GetElevationData().SetLayout(oc3dDataPoint); m_cGroup.GetElevationData().SetNumSeries(3); // Set up each scatter series CalculateScatterSeries(1, 10); CalculateScatterSeries(2, 5); CalculateScatterSeries(3, 8); // Setup the header m_chart.GetHeader().GetText().SetText("3D Scatter Chart!"); m_chart.GetHeader().GetFont().SetName("Arial"); hFontSize.SetCurrency(14, 0); m_chart.GetHeader().GetFont().SetSize(hFontSize); m_chart.GetHeader().GetFont().SetBold(true); // Setup the footer m_chart.GetFooter().GetText().SetText("Drag a point to change its Z value"); m_chart.GetFooter().GetFont().SetName("Arial"); hFontSize.SetCurrency(10, 0); m_chart.GetFooter().GetFont().SetSize(hFontSize); m_chart.GetFooter().GetBorder().SetType(oc3dBorderPlain); // Setup the legend m_chart.GetLegend().GetText().SetText("Sightings"); m_chart.GetLegend().GetBorder().SetType(oc3dBorderShadow); m_chart.GetLegend().GetBorder().SetWidth(4); m_chart.GetLegend().SetAnchor(oc3dAnchorNorthWest); m_chart.GetLegend().GetLabels().Add("Bats", COleVariant(short(1))); m_chart.GetLegend().GetLabels().Add("Bees", COleVariant(short(2))); m_chart.GetLegend().GetLabels().Add("Birds", COleVariant(short(3))); // Go back to normal Chart updates m_chart.SetIsBatched(false); } ///////////////////////////////////////////////////////////////////////////// // Release some variables before we exit the program ///////////////////////////////////////////////////////////////////////////// void CScatterView::OnDestroy() { CFormView::OnDestroy(); // Release the global variables m_cGroup.DetachDispatch(); } ///////////////////////////////////////////////////////////////////////////// // Obtain space for one series and calculate the 3d data points ///////////////////////////////////////////////////////////////////////////// void CScatterView::CalculateScatterSeries(int nSeries, int nNumPoints) { int j; double x, y, z; CDataCoordCollection m_DataSeries = m_cGroup.GetElevationData().PointSeries(nSeries); // Populate the series with some generic data for (j = 0; j < nNumPoints; j++) { // Scatter the data slightly if (j % 2) { x = j + j/(nSeries+1); y = nSeries + x/8; } else { x = j - j % 3; y = nSeries + 0.5 + x/8; } z = 7500 - (3*x*y + x*x*x + y*y*y); m_DataSeries.Add(x, y, z); } } BEGIN_EVENTSINK_MAP(CScatterView, CFormView) //{{AFX_EVENTSINK_MAP(CScatterView) ON_EVENT(CScatterView, IDC_CHART3D, -605 /* MouseDown */, Chart_OnMouseDown, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CScatterView, IDC_CHART3D, -606 /* MouseMove */, Chart_OnMouseMove, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CScatterView, IDC_CHART3D, -607 /* MouseUp */, Chart_OnMouseUp, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CScatterView, IDC_CHART3D, 1 /* ModifyEnd */, Chart_OnModifyEnd, VTS_NONE) ON_EVENT(CScatterView, IDC_CHART3D, 2 /* ModifyStart */, Chart_OnModifyStart, VTS_PBOOL) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() ///////////////////////////////////////////////////////////////////////////// // The user has pressed a Mouse-Button while over the Chart ///////////////////////////////////////////////////////////////////////////// void CScatterView::Chart_OnMouseDown(short Button, short Shift, long x, long y) { if (m_IsModifying) { return; } long Series, Point, Distance; if ((Button == 1) && (Shift == 0)) { m_Region = m_cGroup.CoordToDataIndex(x, y, &Series, &Point, &Distance); if ((m_Region == oc3dRegionInChartArea) && (Series > 0) && (Point > 0) && (Distance < 4)) { m_PickSeries = Series; m_PickPoint = Point; } } } ///////////////////////////////////////////////////////////////////////////// // The user is moving the mouse over the Chart ///////////////////////////////////////////////////////////////////////////// void CScatterView::Chart_OnMouseMove(short Button, short Shift, long x, long y) { if (m_IsModifying) { return; } double Value; // If we are dragging a point, update it if ((m_PickSeries != 0) && (m_PickPoint != 0)) { m_chart.SetIsBatched(true); m_cGroup.GetElevationData().SetIsBatched(true); Value = m_cGroup.DragZValue(m_PickSeries, m_PickPoint, x, y); /* Limit the range */ if (Value > 10000.0) { Value = 10000.0; } if (Value < 0.0) { Value = 0.0; } m_cGroup.GetElevationData().PointSeries(m_PickSeries).GetItem(COleVariant(short(m_PickPoint))).SetZ(Value); m_cGroup.GetElevationData().SetIsBatched(false); m_chart.SetIsBatched(false); } } ///////////////////////////////////////////////////////////////////////////// // The user has let the mouse button go while over the Chart ///////////////////////////////////////////////////////////////////////////// void CScatterView::Chart_OnMouseUp(short Button, short Shift, long x, long y) { m_PickSeries = 0; m_PickPoint = 0; } ///////////////////////////////////////////////////////////////////////////// // Let the Chart know it can be modified ///////////////////////////////////////////////////////////////////////////// void CScatterView::Chart_OnModifyEnd() { m_IsModifying = false; } ///////////////////////////////////////////////////////////////////////////// // Let the Chart know it can't be modified ///////////////////////////////////////////////////////////////////////////// void CScatterView::Chart_OnModifyStart(BOOL FAR* IsOK) { m_IsModifying = true; } ///////////////////////////////////////////////////////////////////////////// // Resize the Chart to the size of the window ///////////////////////////////////////////////////////////////////////////// void CScatterView::OnSize(UINT nType, int cx, int cy) { CFormView::OnSize(nType, cx, cy); // size the chart to fit the window if ((cx > 0) && (cy > 0)) { if (IsWindow(m_chart.m_hWnd)) { m_chart.MoveWindow(0, 0, cx, cy, true); } } } ///////////////////////////////////////////////////////////////////////////// // Respond to the Timer ///////////////////////////////////////////////////////////////////////////// void CScatterView::OnTimer(UINT nIDEvent) { CFormView::OnTimer(nIDEvent); } void CScatterView::OnFontStroke() { m_chart.SetUseTrueType(FALSE); } void CScatterView::OnUpdateFontStroke(CCmdUI* pCmdUI) { pCmdUI->SetCheck(!m_chart.GetUseTrueType()); } void CScatterView::OnFontTruetype() { m_chart.SetUseTrueType(TRUE); } void CScatterView::OnUpdateFontTruetype(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_chart.GetUseTrueType()); } void CScatterView::OnView2dscatter() { m_View3D = FALSE; // Turn off Shaded or Meshed to see 2D view m_cGroup.GetElevation().SetIsMeshed(m_View3D); m_cGroup.GetElevation().SetIsShaded(m_View3D); // Turn on Zoned or Contoured to see 2D effect m_cGroup.GetContour().SetIsContoured(TRUE); } void CScatterView::OnUpdateView2dscatter(CCmdUI* pCmdUI) { pCmdUI->SetCheck(!m_View3D); } void CScatterView::OnView3dscatter() { m_View3D = TRUE; m_cGroup.GetElevation().SetIsMeshed(TRUE); } void CScatterView::OnUpdateView3dscatter(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_View3D); } void CScatterView::OnViewDroplines() { m_cGroup.GetElevation().SetHasDropLines(!m_cGroup.GetElevation().GetHasDropLines()); } void CScatterView::OnUpdateViewDroplines(CCmdUI* pCmdUI) { pCmdUI->SetCheck(m_cGroup.GetElevation().GetHasDropLines()); }