// MathOutWnd.cpp : implementation file // #include "stdafx.h" #include "math.h" #include "MathOutWnd.h" #include "MathDoc.h" #include "MathView.h" // Olectra Chart Includes #include "Axis.h" #include "AxisCollection.h" #include "Border.h" #include "Chart3DData.h" #include "ChartArea.h" #include "ChartGroup.h" #include "ChartGroupCollection.h" #include "CubeFont.h" #include "DerivedLong.h" #include "Font.h" #include "Interior.h" #include "Label.h" #include "Legend.h" #include "Location.h" #include "PlotCube.h" #include "Title.h" #include "View3d.h" #include "3dConst.h" #include "oc_color.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CMathOutWnd CMathOutWnd::CMathOutWnd() { m_IsModify = false; // the chart is currently NOT being modified m_OldRegion = oc3dRegionNone; // the mouse is currently NOT over the chart } CMathOutWnd::~CMathOutWnd() { // nothing to do! } BEGIN_MESSAGE_MAP(CMathOutWnd, CWnd) //{{AFX_MSG_MAP(CMathOutWnd) ON_WM_CREATE() ON_WM_SIZE() //}}AFX_MSG_MAP END_MESSAGE_MAP() // Get a pointer to the Chart via Member functions CChart3D *CMathOutWnd::GetChart() { return &m_chart; } // Helper function to update the footer void CMathOutWnd::UpdateFooter(long Row, long Col, long Region) { // Show the present value of this index in the footer. double Value; char charArr[MAX_STRING_LEN]; CLabel footTxt; // get the footer for convenience footTxt = m_chart.GetFooter().GetText(); // check where we are and update the footer text. if (Row > 0 && Col > 0) { Value = m_chart.GetChartGroups().GetItem(COleVariant(1L)).GetElevationData().GetValue(Row, Col); sprintf(charArr, "Closest Grid Index(%d, %d) = %.2f", Row, Col, Value); footTxt.SetText(charArr); } else if (Region == oc3dRegionInHeader) { footTxt.SetText("In the Header."); } else if (Region == oc3dRegionInFooter) { footTxt.SetText("In the Footer."); }else if (Region == oc3dRegionInLegend) { footTxt.SetText("In the Legend."); } else { footTxt.SetText("Nowhere."); } } // Helper function to initialize the chart void CMathOutWnd::InitialChartSetup(void) { CTitle header; CTitle footer; COleCurrency hFontSize; // set the border properties GetChart()->GetBorder().SetType(oc3dBorderPlain); GetChart()->GetBorder().SetWidth(1); // Add a border to the chart area GetChart()->GetChartArea().GetBorder().SetType(oc3dBorderShadow); GetChart()->GetChartArea().GetBorder().SetWidth(4); // Set the Control's Colors GetChart()->GetInterior().SetBackgroundColor(ocColorLightBlue); GetChart()->GetChartArea().GetInterior().SetBackgroundColor(ocColorHoneydew); GetChart()->GetChartArea().GetPlotCube().GetInterior().SetBackgroundColor(ocColorGray94); // Change the Legend Font GetChart()->GetLegend().GetFont().SetName("Courier New"); GetChart()->GetLegend().GetFont().SetBold(true); hFontSize.SetCurrency(10, 0); GetChart()->GetLegend().GetFont().SetSize(hFontSize); // Set the Control's Axis properties GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(1L)).GetTitle().SetText("X-Axis"); GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(2L)).GetTitle().SetText("Y-Axis"); hFontSize.SetCurrency(12, 0); GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(3L)).GetTitle().SetText("Z-Axis"); GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(1L)).GetTitleFont().SetSize(100); GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(1L)).GetAnnotationFont().GetTrueType().SetName("Arial"); GetChart()->GetChartArea().GetAxes().GetItem(COleVariant(1L)).GetAnnotationFont().GetTrueType().SetSize(hFontSize); // Set some initial Header Properties header = GetChart()->GetHeader(); header.GetText().SetText("f(x,y) = cos(sin(x*y)) + sin(cos(x/y))"); header.GetLocation().GetLeft().SetValue(25); header.GetLocation().GetTop().SetValue(15); header.GetFont().SetBold(true); header.GetFont().SetItalic(true); header.GetFont().SetName("Times New Roman"); hFontSize.SetCurrency(12, 0); header.GetFont().SetSize(hFontSize); // Set Some initial Footer Properties footer = GetChart()->GetFooter(); footer.GetText().SetText("Nowhere."); footer.GetLocation().GetLeft().SetValue(25); footer.GetFont().SetBold(true); footer.GetFont().SetName("Courier New"); hFontSize.SetCurrency(10, 0); footer.GetFont().SetSize(hFontSize); } // this is used to set a pointer to the Input View Window void CMathOutWnd::SetInWindow(CMathView* inWndView) { m_pInWndView = inWndView; } ///////////////////////////////////////////////////////////////////////////// // CMathOutWnd message handlers int CMathOutWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; // Create the chart if (!m_chart.Create(NULL, WS_VISIBLE, CRect(0, 0, 462, 356), this, 100)) { return -1; } // Setup the Chart With Initial Look Here InitialChartSetup(); return 0; } void CMathOutWnd::OnSize(UINT nType, int cx, int cy) { // Call parent's OnSize CWnd::OnSize(nType, cx, cy); // Streach/Squeeze the Chart's window to fit m_chart.MoveWindow(0, 0, cx, cy); // if we restored the output window if (nType == SIZE_RESTORED) { // check if the input window has been created if (::IsWindow(m_pInWndView->m_hWnd)) { // restore the input window m_pInWndView->GetParentFrame()->ShowWindow(SW_RESTORE); } } } BEGIN_EVENTSINK_MAP(CMathOutWnd, CWnd) //{{AFX_EVENTSINK_MAP(CMathOutWnd) ON_EVENT(CMathOutWnd, 100, -606 /* MouseMove */, OnMouseMoveChart3d1, VTS_I2 VTS_I2 VTS_I4 VTS_I4) ON_EVENT(CMathOutWnd, 100, 2 /* ModifyStart */, OnModifyStartChart3d1, VTS_PBOOL) ON_EVENT(CMathOutWnd, 100, 1 /* ModifyEnd */, OnModifyEndChart3d1, VTS_NONE) //}}AFX_EVENTSINK_MAP END_EVENTSINK_MAP() // ON_EVENT(CMathOutWnd, 100, 2 /* ModifyStart */, OnModifyStartChart3d1, VTS_PBOOL) // ON_EVENT(CMathOutWnd, IDC_CHART2D1, 1 /* ModifyEnd */, OnModifyEndChart3d1, VTS_NONE) void CMathOutWnd::OnMouseMoveChart3d1(short Button, short Shift, long X, long Y) { // When the mouse moves over the chart, update the footer at the bottom // with the index and value of the point the mouse is on. // User is modifying the chart, so get out of here if (m_IsModify) { return; } long px, py; long Row, Col; long Distance; long Region; // Convert to pixels px = X; py = Y; // See if the mouse is over the Chart Region = m_chart.GetChartGroups().GetItem(COleVariant(1L)).CoordToDataIndex(px, py, &Row, &Col, &Distance); if (Region != oc3dRegionInChartArea || Row <= 0 || Col <= 0 || Distance > 15) { // Not directly on any index, so force row and col to zero Row = Col = 0; } if ((Row != m_LastRow || Col != m_LastCol || Region != m_OldRegion) && Distance < 15) { // This is a different index than last time, so change the value shown in the footer // Keep the footer current UpdateFooter(Row, Col, Region); // Remember current grid selection m_LastRow = Row; m_LastCol = Col; m_OldRegion = Region; } } void CMathOutWnd::OnModifyStartChart3d1 (BOOL FAR* IsOK) { // Chart is being modified. m_IsModify = true; } void CMathOutWnd::OnModifyEndChart3d1 (void) { char XRot[MAX_STRING_LEN]; char YRot[MAX_STRING_LEN]; char ZRot[MAX_STRING_LEN]; // update rotation edit boxes sprintf(XRot, "%g", m_chart.GetChartArea().GetView3D().GetXRotation() ); sprintf(YRot, "%g", m_chart.GetChartArea().GetView3D().GetYRotation() ); sprintf(ZRot, "%g", m_chart.GetChartArea().GetView3D().GetZRotation() ); m_pInWndView->SetXYZAngleEdit(XRot, YRot, ZRot); // Chart is NO longer being modified. m_IsModify = false; }