CADDoc.cpp
上传用户:shangwu01
上传日期:2013-04-22
资源大小:707k
文件大小:7k
- // CADDoc.cpp : implementation of the CCADDoc class
- //
- #include "stdafx.h"
- #include "CAD.h"
- #include "CADDoc.h"
- #include "CADView.h"
- #include "MainFrm.h"
- #include "math.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCADDoc
- IMPLEMENT_DYNCREATE(CCADDoc, CDocument)
- BEGIN_MESSAGE_MAP(CCADDoc, CDocument)
- //{{AFX_MSG_MAP(CCADDoc)
- ON_COMMAND(IDR_DRAW_LINE, OnDrawLine)
- ON_UPDATE_COMMAND_UI(IDR_DRAW_LINE, OnUpdateDrawLine)
- ON_COMMAND(ID_DRAW_CIRCLE, OnDrawCircle)
- ON_UPDATE_COMMAND_UI(ID_DRAW_CIRCLE, OnUpdateDrawCircle)
- ON_COMMAND(ID_DRAW_ELLIPS, OnDrawEllips)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPS, OnUpdateDrawEllips)
- ON_COMMAND(ID_DRAW_MULTLINE, OnDrawMultline)
- ON_UPDATE_COMMAND_UI(ID_DRAW_MULTLINE, OnUpdateDrawMultline)
- ON_COMMAND(ID_DRAW_RECTANGE, OnDrawRectange)
- ON_UPDATE_COMMAND_UI(ID_DRAW_RECTANGE, OnUpdateDrawRectange)
- ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
- ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
- ON_UPDATE_COMMAND_UI(ID_MODE_D, OnUpdateModeD)
- ON_UPDATE_COMMAND_UI(ID_MODE_E, OnUpdateModeE)
- ON_COMMAND(ID_MODE_E, OnModeE)
- ON_COMMAND(ID_MODE_D, OnModeD)
- ON_COMMAND(ID_DRAW_ARC, OnDrawArc)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ARC, OnUpdateDrawArc)
- ON_COMMAND(IDM_wARC, OnwARC)
- ON_COMMAND(IDM_wCIRCLE, OnwCIRCLE)
- ON_COMMAND(IDM_wELLIPS, OnwELLIPS)
- ON_COMMAND(IDM_wLINE, OnwLINE)
- ON_COMMAND(IDM_wRECTANGE, OnwRECTANGE)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCADDoc construction/destruction
- CCADDoc::CCADDoc()
- {
- m_line_width=1;
- m_line_style=PS_SOLID;
- m_line_color=RGB(0,0,0);
- m_mode_flage=true;
- m_DrawType=1;
- /////////////////////////////////////////
- ///
- }
- CCADDoc::~CCADDoc()
- {
- }
- BOOL CCADDoc::OnNewDocument()
- {
- if (!CDocument::OnNewDocument())
- return FALSE;
- this->SetTitle("CAD");
- // TODO: add reinitialization code here
- // (SDI documents will reuse this document)
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCADDoc serialization
- void CCADDoc::Serialize(CArchive& ar)
- {
- if (ar.IsStoring())
- {
- // TODO: add storing code here
- }
- else
- {
- // TODO: add loading code here
- }
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCADDoc diagnostics
- #ifdef _DEBUG
- void CCADDoc::AssertValid() const
- {
- CDocument::AssertValid();
- }
- void CCADDoc::Dump(CDumpContext& dc) const
- {
- CDocument::Dump(dc);
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CCADDoc commands
- void CCADDoc::OnDrawLine()
- {
- if(m_mode_flage)
- m_DrawType=1;
-
-
- }
- void CCADDoc::OnUpdateDrawLine(CCmdUI* pCmdUI)
- {
- if(m_DrawType==1)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=1)
- pCmdUI->SetCheck(0);
-
-
- }
- void CCADDoc::OnDrawCircle()
- {
- if(m_mode_flage)
- m_DrawType=3;
-
-
- }
- void CCADDoc::OnUpdateDrawCircle(CCmdUI* pCmdUI)
- {
- if(m_DrawType==3)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=3)
- pCmdUI->SetCheck(0);
-
-
- }
- void CCADDoc::OnDrawEllips()
- {
- if(m_mode_flage)
- m_DrawType=5;
-
- }
- void CCADDoc::OnUpdateDrawEllips(CCmdUI* pCmdUI)
- {
- if(m_DrawType==5)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=5)
- pCmdUI->SetCheck(0);
-
-
- }
- void CCADDoc::OnDrawMultline()
- {
- if(m_mode_flage)
- m_DrawType=4;
-
- }
- void CCADDoc::OnUpdateDrawMultline(CCmdUI* pCmdUI)
- {
- if(m_DrawType==4)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=4)
- pCmdUI->SetCheck(0);
-
- }
- void CCADDoc::OnDrawRectange()
- {
- if(m_mode_flage)
- m_DrawType=2;
-
- }
- void CCADDoc::OnUpdateDrawRectange(CCmdUI* pCmdUI)
- {
- if(m_DrawType==2)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=2)
- pCmdUI->SetCheck(0);
-
- }
- void CCADDoc::OnDrawArc()
- {
- if(m_mode_flage)
- m_DrawType=7;
-
- }
- void CCADDoc::OnUpdateDrawArc(CCmdUI* pCmdUI)
- {
- if(m_DrawType==7)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=2)
- pCmdUI->SetCheck(0);
-
- }
- void CCADDoc::OnDrawText()
- {
- if(m_mode_flage)
- m_DrawType=6;
-
-
- }
- void CCADDoc::OnUpdateDrawText(CCmdUI* pCmdUI)
- {
- if(m_DrawType==6)
- pCmdUI->SetCheck(1);
- else if(m_DrawType!=6)
- pCmdUI->SetCheck(0);
-
- }
- void CCADDoc::OnUpdateModeD(CCmdUI* pCmdUI)
- {
- if(m_mode_flage)
- pCmdUI->SetCheck(1);
- else
- pCmdUI->SetCheck(0);
-
-
- }
- void CCADDoc::OnUpdateModeE(CCmdUI* pCmdUI)
- {
- if(!m_mode_flage)
- pCmdUI->SetCheck(1);
- else
- pCmdUI->SetCheck(0);
-
- }
- void CCADDoc::OnModeE()
- {
- m_mode_flage=false;
- m_DrawType=0;
- POSITION pos = GetFirstViewPosition();
- while (pos != NULL)
- {
- CCADView* pView = (CCADView*)GetNextView(pos);
- pView->UpdateWindow();//视图操作
- pView->catchcertre=false;
- pView->catchcross=false;
- pView->catchend=false;
- pView->catchmiddle=false;
- pView->catchcut=false;
- }
- CMainFrame* pFrm = (CMainFrame*) AfxGetMainWnd();
- pFrm->ShowControlBar(&pFrm->m_wndCatchTool,!pFrm->m_wndCatchTool.IsWindowVisible(),false);
-
-
- }
- void CCADDoc::OnModeD()
- {
- m_mode_flage=true;
- m_DrawType=1;
- CMainFrame* pFrm = (CMainFrame*) AfxGetMainWnd();
- pFrm->ShowControlBar(&pFrm->m_wndCatchTool,!pFrm->m_wndCatchTool.IsWindowVisible(),false);
- }
- void CCADDoc::OnwARC()
- {
- CLG_wARC dlg;
- if(dlg.DoModal()==IDOK)
- {
-
- CPoint certrepoint,startpoint,endpoint;
- certrepoint=CPoint(dlg.m_Xcertre,dlg.m_Ycertre);
- startpoint=CPoint(dlg.m_Xcertre+dlg.m_R*cos(dlg.m_ARC1*3.1415926/180),dlg.m_Ycertre-dlg.m_R*sin(dlg.m_ARC1*3.1415926/180));
- endpoint=CPoint(dlg.m_Xcertre+dlg.m_R*cos(dlg.m_ARC2*3.1415926/180),dlg.m_Ycertre-dlg.m_R*sin(dlg.m_ARC2*3.1415926/180));
-
- m_arc.arc_drawstore(certrepoint,startpoint,endpoint,m_line_style,m_line_width,m_line_color);
-
- }
- else
- return;
-
- }
- void CCADDoc::OnwCIRCLE()
- {
- CLG_wCIRCLE dlg;
- if(dlg.DoModal()==IDOK)
- {
- m_circle.circle_store(CPoint(dlg.m_Xcertre,dlg.m_Ycertre),
- CPoint(dlg.m_Xcertre+dlg.m_R,dlg.m_Ycertre),
- m_line_style,m_line_width,m_line_color);
-
- }
- else
- return;
-
-
- }
- void CCADDoc::OnwELLIPS()
- {
- CLG_wELLIPS dlg;
- if(dlg.DoModal()==IDOK)
- {
- m_ellips.ellips_store(CPoint(dlg.m_Xcertre,dlg.m_Ycertre),
- CPoint(dlg.m_Xcertre+dlg.m_Xlength/2,dlg.m_Ycertre+dlg.m_Ylength/2),
- m_line_style,m_line_width,m_line_color);
- }
- else
- return;
-
-
- }
- void CCADDoc::OnwLINE()
- {
- CLG_wLINE dlg;
- if(dlg.DoModal()==IDOK)
- {
- m_line.Line_store(CPoint(dlg.m_Xfirst,dlg.m_Yfirst),CPoint(dlg.m_Xsecond,dlg.m_Ysecond),
- m_line_style,m_line_width,m_line_color);
- }
- else
- return;
-
-
- }
- void CCADDoc::OnwRECTANGE()
- {
- CLG_wRECTANGE dlg;
- if(dlg.DoModal()==IDOK)
- {
- m_rectange.rectange_store(CPoint(dlg.m_Xtopleft,dlg.m_Ytopleft),CPoint(dlg.m_Xbottomright,dlg.m_Ybottomright),
- m_line_style,m_line_width,m_line_color);
- }
- else
- return;
-
-
- }