Click here to Skip to main content
15,896,557 members
Articles / Desktop Programming / MFC

The Diffraction Grating Calculator

Rate me:
Please Sign up or sign in to vote.
4.40/5 (5 votes)
30 Oct 2010GPL38 min read 41.5K   678   6  
An MFC Windows program related to Concave Diffraction Gratings using VTK libraries.
#pragma once

#include "ChartCtrl.h"
#include "ColourPicker.h"
#include "ChartLineSerie.h"
#include "ChartLabel.h"
#include "ChartDragLineCursor.h"
#include "ChartMouseListener.h"
#include "ChartSeriesMouseListener.h"
#include "ChartCursor.h"
#include "Globals.h"
#include "ObjectList.h"

// Mouse & Cursor for the Chart

class CCustomMouseListener1 : public CChartSeriesMouseListener<SChartXYPoint>
{
public:
   CCustomMouseListener1() {}
   virtual ~CCustomMouseListener1() {}
   void OnMouseEventSeries(CChartMouseListener::MouseEvent mouseEvent, CPoint point,
      CChartSerieBase<SChartXYPoint>* pSerie, unsigned uPointIndex)
   {
      if (mouseEvent == CChartMouseListener::LButtonDoubleClick &&
         uPointIndex != INVALID_POINT)
      {
         TChartStringStream ssText;
         // SChartXYPoint Point = pSerie->GetPoint(uPointIndex);
         ssText << _T("Series : ") << pSerie->GetName();
         TChartString strText = ssText.str();
         MessageBox(NULL,strText.c_str(), _T("Info"), MB_OK);
      }
   }
};

class CCustomCursorListener1 : public CChartCursorListener
{
public:
   CCustomCursorListener1() {}
   virtual ~CCustomCursorListener1() {}
   void OnCursorMoved(CChartCursor *pCursor, double xValue, double yValue);
};

// CPlot2DFocalPlanes view

class CPlot2DFocalPlanes : public CView
{
	DECLARE_DYNCREATE(CPlot2DFocalPlanes)

protected:
	CPlot2DFocalPlanes();           // protected constructor used by dynamic creation
	virtual ~CPlot2DFocalPlanes();

   bool m_bInitCreate;
   bool m_bInitUpdate;

private:
   // ChartCtrl
   // default style flags: 0x50010000
   CChartCtrl m_PlotChart;

   // Vars for Chart definition
   // 1. Axis defs:
   double m_dBottomAxisMin;
   double m_dBottomAxisMax;
   double m_dLeftAxisMin;
   double m_dLeftAxisMax;
   double m_dTopAxisMin;
   double m_dTopAxisMax;
   double m_dRightAxisMin;
   double m_dRightAxisMax;
   TCHAR  m_czBottomAxisLabel[MAX_PATH];
   TCHAR  m_czLeftAxisLabel[MAX_PATH];
   TCHAR  m_czTopAxisLabel[MAX_PATH];
   TCHAR  m_czRightAxisLabel[MAX_PATH];
   bool   m_bBottomAxisGrid;
   bool   m_bLeftAxisGrid;
   bool   m_bTopAxisGrid;
   bool   m_bRightAxisGrid;

   // 2. Background Color
   COLORREF m_BackgroundColor;

   // 3. Title
   TCHAR  m_czPlotTitle[MAX_PATH];

   // 4. Series Properties
   int m_nSeriesType[MAX_SERIES_NO]; // 0) Line, 1) Points, 2) Surface
   COLORREF m_SeriesColour[MAX_SERIES_NO];
   int m_nLineWidth[MAX_SERIES_NO];
   int m_nPenStyle[MAX_SERIES_NO];
   int m_nPointsType[MAX_SERIES_NO];
   int m_nPointsWidth[MAX_SERIES_NO];
   int m_nPointsHeight[MAX_SERIES_NO];

   CCustomMouseListener1*  m_pMouseListener;
   CCustomCursorListener1* m_pCursorListener;
   CChartDragLineCursor*  m_pVertCursor;
   CChartDragLineCursor*  m_pHorzCursor;

protected:
   // Chart operations
   void SetChartDefaults(void);
   void InitPlotChart(void);
   void SetChartProperties(void);
   void AddSeriesToChart(int k, CObjectList* pList);
   void PlotDataToChart();

public:
   afx_msg void OnPlotData();
   afx_msg void OnPlotReset();
   afx_msg void OnPlotProp();
   afx_msg LRESULT OnPlot(WPARAM wP, LPARAM lP);

public:
	virtual void OnDraw(CDC* pDC);      // overridden to draw this view
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
	DECLARE_MESSAGE_MAP()
public:
   afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
   afx_msg void OnSize(UINT nType, int cx, int cy);
   virtual void OnInitialUpdate();
protected:
   virtual void OnBeginPrinting(CDC* pDC, CPrintInfo* pInfo);
   virtual void OnEndPrinting(CDC* pDC, CPrintInfo* pInfo);
   virtual BOOL OnPreparePrinting(CPrintInfo* pInfo);
   virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
public:
   afx_msg void OnFilePrint();
   afx_msg void OnFilePrintPreview();
};


By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)


Written By
Software Developer (Senior)
Italy Italy
Senior Software Developer in C/C++ and Oracle.
Ex-physicist holding a Ph.D. on x-ray lasers.

Comments and Discussions