📄 graphitedoc.cpp
字号:
//
// Graphite For WinCE(Pocket PC)
// Initially Written By Hyouck "Hawk" Kim, peakhunt@yahoo.com
// 2002, All Rights Reserved
//
// This is GPLed, open source based, software development project.
// For more question about GPL,
// visit http://www.gnu.org/licenses/gpl.txt
//
//
// Revision History
// Nov/30/2002, Initial Release hkim
//
//
// graphiteDoc.cpp : implementation of the CGraphiteDoc class
//
#include "stdafx.h"
#include "graphite.h"
#include "graphiteDoc.h"
#include "graphiteview.h"
#include "xyoptiondlg.h"
#include "mathinputdlg.h"
#include "stackmachine.h"
#include "mathlex.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGraphiteDoc
IMPLEMENT_DYNCREATE(CGraphiteDoc, CDocument)
BEGIN_MESSAGE_MAP(CGraphiteDoc, CDocument)
//{{AFX_MSG_MAP(CGraphiteDoc)
ON_COMMAND(ID_SCROLL_DOWN, OnScrollDown)
ON_COMMAND(ID_SCROLL_LEFT, OnScrollLeft)
ON_COMMAND(ID_SCROLL_RIGHT, OnScrollRight)
ON_COMMAND(ID_SCROLL_UP, OnScrollUp)
ON_COMMAND(ID_MENU_SET_RANGE, OnMenuSetRange)
ON_COMMAND(ID_MENU_MATH_INPUT, OnMenuMathInput)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGraphiteDoc construction/destruction
CGraphiteDoc::CGraphiteDoc()
{
// TODO: add one-time construction code here
m_maxX = 4.0;
m_minX = -4.0;
m_maxY = 4.0;
m_minY = -4.0;
m_deltaX = 0.1;
m_scrollX = 1.0;
m_scrollY = 1.0;
m_plotTitle = L"";
}
CGraphiteDoc::~CGraphiteDoc()
{
}
BOOL CGraphiteDoc::OnNewDocument()
{
if (!CDocument::OnNewDocument())
return FALSE;
// TODO: add reinitialization code here
// (SDI documents will reuse this document)
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CGraphiteDoc serialization
void CGraphiteDoc::Serialize(CArchive& ar)
{
if (ar.IsStoring())
{
// TODO: add storing code here
}
else
{
// TODO: add loading code here
}
}
/////////////////////////////////////////////////////////////////////////////
// CGraphiteDoc diagnostics
#ifdef _DEBUG
void CGraphiteDoc::AssertValid() const
{
CDocument::AssertValid();
}
void CGraphiteDoc::Dump(CDumpContext& dc) const
{
CDocument::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CGraphiteDoc commands
void CGraphiteDoc::OnScrollDown()
{
// TODO: Add your command handler code here
m_maxY -= m_scrollY;
m_minY -= m_scrollY;
UpdateView();
}
void CGraphiteDoc::OnScrollLeft()
{
// TODO: Add your command handler code here
m_maxX -= m_scrollX;
m_minX -= m_scrollX;
UpdateView();
}
void CGraphiteDoc::OnScrollRight()
{
// TODO: Add your command handler code here
m_maxX += m_scrollX;
m_minX += m_scrollX;
UpdateView();
}
void CGraphiteDoc::OnScrollUp()
{
// TODO: Add your command handler code here
m_maxY += m_scrollY;
m_minY += m_scrollY;
UpdateView();
}
void CGraphiteDoc::UpdateView()
{
POSITION pos = GetFirstViewPosition();
CGraphiteView* pView = (CGraphiteView*)GetNextView(pos);
pView->DrawXYTitle(NULL);
pView->DrawGraph(NULL);
pView->Invalidate(TRUE);
}
void CGraphiteDoc::OnMenuSetRange()
{
// TODO: Add your command handler code here
CXYOptionDlg dlg;
dlg.m_delta_x = m_deltaX;
dlg.m_max_x = m_maxX;
dlg.m_min_x = m_minX;
dlg.m_max_y = m_maxY;
dlg.m_min_y = m_minY;
dlg.m_scroll_x = m_scrollX;
dlg.m_scroll_y = m_scrollY;
if(dlg.DoModal() == IDOK)
{
m_deltaX = dlg.m_delta_x;
m_maxX = dlg.m_max_x;
m_minX = dlg.m_min_x;
m_maxY = dlg.m_max_y;
m_minY = dlg.m_min_y;
m_scrollX = dlg.m_scroll_x;
m_scrollY = dlg.m_scroll_y;
UpdateView();
}
}
double CGraphiteDoc::f(double x)
{
// just test
//return sin(2*x) + sin(4*x) + sin(8*x);
return m_sm.execute(x);
}
void CGraphiteDoc::OnMenuMathInput()
{
// TODO: Add your command handler code here
CMathInputDlg dlg;
dlg.m_math_input = m_plotTitle;
if(dlg.DoModal() == IDOK)
{
CTokenList* list;
list = new CTokenList();
CMathParser parser(dlg.m_math_input, list);
POSITION pos = GetFirstViewPosition();
CGraphiteView* pView =
(CGraphiteView*)GetNextView(pos);
if(parser.parse())
{
//pView->MessageBox(L"Parse Success\n" +
// dlg.m_math_input);
m_sm.changeFormula(list);
m_plotTitle = dlg.m_math_input;
UpdateView();
}
else
{
pView->MessageBox(L"Parse Fail\n" +
parser.m_errString);
delete list;
}
}
}
bool CGraphiteDoc::validDoc()
{
return m_sm.isValid();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -