projView.cpp
上传用户:ywlong9188
上传日期:2022-05-31
资源大小:2656k
文件大小:33k
- // ProjView.cpp : implementation of the CProjView class
- //
- #include "stdafx.h"
- #include <afxpriv.h>
- #include "Proj.h"
- #include "ProjDoc.h"
- #include "drawobj.h"
- #include "splitdlg.h"
- #include "ProjView.h"
- #include "drawobj.h"
- #include "drawtool.h"
- #include "palettebar.h"
- #include "mainfrm.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CProjView
- IMPLEMENT_DYNCREATE(CProjView, CScrollView)
- BEGIN_MESSAGE_MAP(CProjView, CScrollView)
- //{{AFX_MSG_MAP(CProjView)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONDBLCLK()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_VIEW_GRID, OnViewGrid)
- ON_COMMAND(ID_CANCEL_EDIT, OnCancelEdit)
- ON_UPDATE_COMMAND_UI(ID_VIEW_GRID, OnUpdateViewGrid)
- ON_COMMAND(ID_OBJECT_MOVETOFRONT, OnObjectMovetofront)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOFRONT, OnUpdateObjectMovetofront)
- ON_COMMAND(ID_OBJECT_MOVETOBACK, OnObjectMovetoback)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVETOBACK, OnUpdateObjectMovetoback)
- ON_COMMAND(ID_OBJECT_MOVEFORWARD, OnObjectMoveforward)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEFORWARD, OnUpdateObjectMoveforward)
- ON_COMMAND(ID_OBJECT_LINECOLOR, OnObjectLinecolor)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_LINECOLOR, OnUpdateObjectLinecolor)
- ON_COMMAND(ID_OBJECT_FILL_COLOR, OnObjectFillColor)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_FILL_COLOR, OnUpdateObjectFillColor)
- ON_COMMAND(ID_EDIT_SELECT_ALL, OnEditSelectAll)
- ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CLEAR, OnUpdateAnySelect)
- ON_UPDATE_COMMAND_UI(ID_EDIT_SELECT_ALL, OnUpdateEditSelectAll)
- ON_COMMAND(ID_EDIT_PROPERTIES, OnEditProperties)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PROPERTIES, OnUpdateEditProperties)
- ON_COMMAND(ID_EDIT_PASTE, OnEditPaste)
- ON_UPDATE_COMMAND_UI(ID_EDIT_PASTE, OnUpdateEditPaste)
- ON_COMMAND(ID_EDIT_CUT, OnEditCut)
- ON_UPDATE_COMMAND_UI(ID_EDIT_CUT, OnUpdateEditCut)
- ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
- ON_UPDATE_COMMAND_UI(ID_EDIT_COPY, OnUpdateEditCopy)
- ON_COMMAND(ID_DRAW_SELECTION, OnDrawSelection)
- ON_UPDATE_COMMAND_UI(ID_DRAW_SELECTION, OnUpdateDrawSelection)
- ON_COMMAND(ID_DRAW_RECT, OnDrawRect)
- ON_UPDATE_COMMAND_UI(ID_DRAW_RECT, OnUpdateDrawRect)
- ON_COMMAND(ID_DRAW_POLYGON, OnDrawPolygon)
- ON_UPDATE_COMMAND_UI(ID_DRAW_POLYGON, OnUpdateDrawPolygon)
- ON_COMMAND(ID_DRAW_LINE, OnDrawLine)
- ON_UPDATE_COMMAND_UI(ID_DRAW_LINE, OnUpdateDrawLine)
- ON_COMMAND(ID_DRAW_ELLIPSE, OnDrawEllipse)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ELLIPSE, OnUpdateDrawEllipse)
- ON_COMMAND(ID_OBJECT_MOVEBACK, OnObjectMoveback)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_MOVEBACK, OnUpdateObjectMoveback)
- ON_WM_ERASEBKGND()
- ON_WM_SIZE()
- ON_COMMAND(ID_DRAW_TEXT, OnDrawText)
- ON_UPDATE_COMMAND_UI(ID_DRAW_TEXT, OnUpdateDrawText)
- ON_COMMAND(ID_DRAW_BAR_GRAPH, OnDrawBarGraph)
- ON_UPDATE_COMMAND_UI(ID_DRAW_BAR_GRAPH, OnUpdateDrawBarGraph)
- ON_COMMAND(ID_DRAW_CLOCK, OnDrawClock)
- ON_UPDATE_COMMAND_UI(ID_DRAW_CLOCK, OnUpdateDrawClock)
- ON_WM_TIMER()
- ON_WM_CREATE()
- ON_COMMAND(ID_DRAW_ANIMATE_TAG, OnDrawAnimateTag)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ANIMATE_TAG, OnUpdateDrawAnimateTag)
- ON_UPDATE_COMMAND_UI(ID_DRAW_CURSOR, OnUpdateDrawCursor)
- ON_COMMAND(ID_DRAW_CURSOR, OnDrawCursor)
- ON_COMMAND(ID_RUN_RUN, OnRunRun)
- ON_UPDATE_COMMAND_UI(ID_RUN_RUN, OnUpdateRunRun)
- ON_COMMAND(ID_RUN_STOP, OnRunStop)
- ON_UPDATE_COMMAND_UI(ID_RUN_STOP, OnUpdateRunStop)
- ON_WM_SETCURSOR()
- ON_WM_RBUTTONDOWN()
- ON_COMMAND(ID_DRAW_ISA, OnDrawIsa)
- ON_UPDATE_COMMAND_UI(ID_DRAW_ISA, OnUpdateDrawIsa)
- ON_COMMAND(ID_DRAW_LOOP, OnDrawLoop)
- ON_UPDATE_COMMAND_UI(ID_DRAW_LOOP, OnUpdateDrawLoop)
- ON_COMMAND(ID_OBJECT_MERGE, OnObjectMerge)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_MERGE, OnUpdateObjectMerge)
- ON_COMMAND(ID_OBJECT_LIB, OnObjectLib)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_LIB, OnUpdateObjectLib)
- ON_COMMAND(ID_DRAW_LIB, OnDrawLib)
- ON_UPDATE_COMMAND_UI(ID_DRAW_LIB, OnUpdateDrawLib)
- ON_WM_CHAR()
- ON_WM_KEYDOWN()
- ON_COMMAND(ID_OBJECT_SPLIT, OnObjectSplit)
- ON_UPDATE_COMMAND_UI(ID_OBJECT_SPLIT, OnUpdateObjectSplit)
- ON_COMMAND(ID_EDIT_CLEAR, OnEditClear)
- ON_COMMAND(ID_DRAW_BUTTON, OnDrawButton)
- ON_UPDATE_COMMAND_UI(ID_DRAW_BUTTON, OnUpdateDrawButton)
- //}}AFX_MSG_MAP
- ON_COMMAND(ID_EDIT_ROTATE, OnEditRotate)
- ON_UPDATE_COMMAND_UI(ID_EDIT_ROTATE, OnUpdateEditRotate)
- ON_COMMAND_RANGE(ID_EDIT_LEFT,ID_EDIT_BOTTOM,OnAlign)
- ON_UPDATE_COMMAND_UI_RANGE(ID_EDIT_LEFT,ID_EDIT_BOTTOM,OnUpdateAlign)
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CProjView construction/destruction
- CProjView::CProjView() :m_tracker(CRect(0,0,10,10),CRectTracker::solidLine|CRectTracker::resizeInside)
- //,CScrollView(CProjView::IDD)
- {
- m_bGrid = FALSE;
- m_gridColor = RGB(0, 0, 128);
- m_bActive = FALSE;
- nTemp = 0;
- m_bRun = FALSE;
- m_bCursor = FALSE;
-
- }
- CProjView::~CProjView()
- {
- while( m_backup.GetHeadPosition() != NULL )
- delete m_backup.RemoveHead();
- }
- BOOL CProjView::PreCreateWindow(CREATESTRUCT& cs)
- {
- ASSERT(cs.style & WS_CHILD);
- if (cs.lpszClass == NULL)
- cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
- return TRUE;
- }
- /////////////////////////////////////////////////////////////////////////////
- // CProjView drawing
- void CProjView::OnDraw(CDC* pDC)
- {
- CProjDoc* pDoc = GetDocument();
- ASSERT_VALID(pDoc);
- CDC dc;
- CDC* pDrawDC = pDC;
- CBitmap bitmap;
- CBitmap* pOldBitmap;
- // only paint the rect that needs repainting
- CRect client;
- pDC->GetClipBox(client);
- CRect rect = client;
- DocToClient(rect);
- // draw to offscreen bitmap for fast looking repaints
- if (dc.CreateCompatibleDC(pDC))
- {
- if (bitmap.CreateCompatibleBitmap(pDC, rect.Width(), rect.Height()))
- {
- OnPrepareDC(&dc, NULL);
- pDrawDC = &dc;
- // offset origin more because bitmap is just piece of the whole drawing
- dc.OffsetViewportOrg(-rect.left, -rect.top);
- pOldBitmap = dc.SelectObject(&bitmap);
- dc.SetBrushOrg(rect.left % 8, rect.top % 8);
- // might as well clip to the same rectangle
- dc.IntersectClipRect(client);
- }
- }
-
- // paint background
- CBrush brush;
-
- if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
- return;
- brush.UnrealizeObject();
- pDrawDC->FillRect(client, &brush);
- pDoc->Draw(pDrawDC, this);
- if (!pDC->IsPrinting() && m_bGrid)
- DrawGrid(pDrawDC);
- if (pDrawDC != pDC)
- {
- pDC->SetViewportOrg(0, 0);
- pDC->SetWindowOrg(0,0);
- pDC->SetMapMode(MM_TEXT);
- dc.SetViewportOrg(0, 0);
- dc.SetWindowOrg(0,0);
- dc.SetMapMode(MM_TEXT);
- pDC->BitBlt(rect.left, rect.top, rect.Width(), rect.Height(),
- &dc, 0, 0, SRCCOPY);
- dc.SelectObject(pOldBitmap);
- bitmap.DeleteObject();
- brush.DeleteObject();
- }
- }
- void CProjView::OnInitialUpdate()
- {
- CSize size = GetDocument()->GetSize();
- CClientDC dc(NULL);
- size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
- size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
- SetScrollSizes(MM_TEXT, size);
- m_selection.RemoveAll();
-
- OnUpdate(NULL,HINT_UPDATE_WINDOW,NULL);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CProjView diagnostics
- #ifdef _DEBUG
- void CProjView::AssertValid() const
- {
- CScrollView::AssertValid();
- }
- void CProjView::Dump(CDumpContext& dc) const
- {
- CScrollView::Dump(dc);
- }
- CProjDoc* CProjView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CProjDoc)));
- return (CProjDoc*)m_pDocument;
- }
- #endif //_DEBUG
- /////////////////////////////////////////////////////////////////////////////
- // CProjView message handlers
- void CProjView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- if (!m_bActive)
- return;
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnLButtonDown(this, nFlags, point);
- }
- void CProjView::OnLButtonDblClk(UINT nFlags, CPoint point)
- {
- if (!m_bActive)
- return;
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnLButtonDblClk(this, nFlags, point);
- }
- void CProjView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- if (!m_bActive)
- return;
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnLButtonUp(this, nFlags, point);
- }
- void CProjView::OnMouseMove(UINT nFlags, CPoint point)
- {
-
- if (!m_bActive)
- return;
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnMouseMove(this, nFlags, point);
- CPoint temp = point;
- ClientToDoc(temp);
- CPoint tempPoint ;
- tempPoint.x = temp.x;
- tempPoint.y = -temp.y;
- char text[100];
- CStatusBar* pStatus = (CStatusBar* )AfxGetApp()->m_pMainWnd->
- GetDescendantWindow(AFX_IDW_STATUS_BAR);
-
- wsprintf(text,"x = %d",tempPoint.x);
- pStatus->SetPaneText(0,text);
- wsprintf(text,"y = %d",tempPoint.y);
- pStatus->SetPaneText(1,text);
-
- /* CClientDC dc(this);
-
- int old = dc.SetROP2(R2_NOT);
-
-
- CRect rc;
- GetClientRect(rc);
- dc.MoveTo(m_prePoint.x,rc.top);
- dc.LineTo(m_prePoint.x,rc.bottom);
- dc.MoveTo(rc.left,m_prePoint.y);
- dc.LineTo(rc.right,m_prePoint.y);
- dc.MoveTo(point.x,rc.top);
- dc.LineTo(point.x,rc.bottom);
- dc.MoveTo(rc.left,point.y);
- dc.LineTo(rc.right,point.y);
- dc.SetROP2(old);
- m_prePoint = point;*/
- }
- void CProjView::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- GetParentFrame()->ActivateFrame();
- CPoint local = point;
- ScreenToClient(&local);
- ClientToDoc(local);
- CDrawObj* pObj;
- pObj = GetDocument()->ObjectAt(local);
- if(pObj != NULL)
- {
- if(!IsSelected(pObj))
- Select( pObj, FALSE ); // reselect item if appropriate
- UpdateWindow();
- CMenu menu;
- if (menu.LoadMenu(ID_POPUP_MENU))
- {
- CMenu* pPopup = menu.GetSubMenu(0);
- ASSERT(pPopup != NULL);
- pPopup->TrackPopupMenu(TPM_RIGHTBUTTON | TPM_LEFTALIGN,
- point.x, point.y,
- AfxGetMainWnd()); // route commands through main window
- }
- }
-
- }
-
-
- void CProjView::OnViewGrid()
- {
- m_bGrid = !m_bGrid;
- Invalidate(FALSE);
- }
-
- void CProjView::OnUpdateViewGrid(CCmdUI* pCmdUI)
- {
- pCmdUI->SetCheck(m_bGrid);
- }
-
- void CProjView::OnObjectMovetofront()
- {
- CProjDoc* pDoc = GetDocument();
- CDrawObj* pObj = m_selection.GetHead();
- CDrawObjList* pObjects = pDoc->GetObjects();
- POSITION pos = pObjects->Find(pObj);
- ASSERT(pos != NULL);
- pObjects->RemoveAt(pos);
- pObjects->AddTail(pObj);
- InvalObj(pObj);
- }
-
- void CProjView::OnUpdateObjectMovetofront(CCmdUI* pCmdUI)
- {
-
- pCmdUI -> Enable(!m_selection.IsEmpty());
-
- }
- void CProjView::OnObjectMovetoback()
- {
- CProjDoc* pDoc = GetDocument();
- CDrawObj* pObj = m_selection.GetHead();
- CDrawObjList* pObjects = pDoc->GetObjects();
- POSITION pos = pObjects->Find(pObj);
- ASSERT(pos != NULL);
- pObjects->RemoveAt(pos);
- pObjects->AddHead(pObj);
- InvalObj(pObj);
- }
-
- void CProjView::OnUpdateObjectMovetoback(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(!m_selection.IsEmpty());
-
- }
- void CProjView::OnObjectMoveforward()
- {
- CProjDoc* pDoc = GetDocument();
- if(m_selection.IsEmpty())
- return;
- CDrawObj* pObj = m_selection.GetHead();
- CDrawObjList* pObjects = pDoc->GetObjects();
- POSITION pos = pObjects->Find(pObj);
- ASSERT(pos != NULL);
- if (pos != pObjects->GetTailPosition())
- {
- POSITION posNext = pos;
- pObjects->GetNext(posNext);
- pObjects->RemoveAt(pos);
- pObjects->InsertAfter(posNext, pObj);
- InvalObj(pObj);
- }
- }
-
- void CProjView::OnUpdateObjectMoveforward(CCmdUI* pCmdUI)
- {
- pCmdUI -> Enable(!m_selection.IsEmpty());
- }
- void CProjView::OnObjectLinecolor()
- {
- CColorDialog dlg;
- if (dlg.DoModal() != IDOK)
- return;
- COLORREF color = dlg.GetColor();
- POSITION pos = m_selection.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- pObj->SetLineColor(color);
- }
- }
-
- void CProjView::OnUpdateObjectLinecolor(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CProjView::OnObjectFillColor()
- {
- CColorDialog dlg;
- if (dlg.DoModal() != IDOK)
- return;
- COLORREF color = dlg.GetColor();
- POSITION pos = m_selection.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- pObj->SetFillColor(color);
- }
- }
-
- void CProjView::OnUpdateObjectFillColor(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
-
- }
- void CProjView::OnEditSelectAll()
- {
- CDrawObjList* pObList = GetDocument()->GetObjects();
- POSITION pos = pObList->GetHeadPosition();
- while (pos != NULL)
- Select(pObList->GetNext(pos), TRUE);
- }
- void CProjView::OnEditProperties()
- {
- if (m_selection.GetCount() == 1 && CDrawTool::c_drawShape == selection)
- {
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- ASSERT(pTool != NULL);
- pTool->OnEditProperties(this);
- }
- }
-
- void CProjView::OnUpdateEditProperties(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_selection.GetCount() == 1 &&
- CDrawTool::c_drawShape == selection);
- }
- void CProjView::OnEditPaste()
- {
- POSITION pos = m_backup.GetHeadPosition();
- while( pos != NULL ){
- CDrawObj* pTemp = m_backup.GetNext(pos);
- //pTemp = pTemp->Clone( NULL);
- pTemp = pTemp->Clone(GetDocument());
- CRect rect = pTemp->m_position;
- rect.OffsetRect(30,-30);
- pTemp->MoveTo(rect,this);
- // pTemp->m_position.OffsetRect(30,-30);
- // pTemp->ReConsist();
- // GetDocument()->Add( pTemp );
- //pTemp->ReConsist();
- //Select( pTemp ,TRUE);
- }
- GetDocument()->SetModifiedFlag();
- Invalidate();
- }
- void CProjView::OnUpdateEditPaste(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_backup.IsEmpty());
- }
- void CProjView::OnEditCut()
- {
- OnEditCopy();
- OnEditClear();
- }
- void CProjView::OnUpdateEditCut(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_selection.IsEmpty());
- }
- void CProjView::OnEditCopy()
- {
- if(!m_backup.IsEmpty())
- {
- while( m_backup.GetHeadPosition() != NULL )
- delete m_backup.RemoveHead();
- }
- POSITION pos = m_selection.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- CDrawObj* pTemp = pObj->Clone( NULL );
- m_backup.AddTail( pTemp );
- }
-
- }
- void CProjView::OnUpdateEditCopy(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_selection.IsEmpty());
- }
-
- void CProjView::OnDrawSelection()
- {
- CDrawTool::c_drawShape = selection;
- }
- void CProjView::OnUpdateDrawSelection(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == selection);
- }
- void CProjView::OnDrawRect()
- {
- CDrawTool::c_drawShape = rect;
- }
- void CProjView::OnUpdateDrawRect(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == rect);
- }
- void CProjView::OnDrawPolygon()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = poly;
-
- }
- void CProjView::OnUpdateDrawPolygon(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == poly);
- }
-
- void CProjView::OnDrawLine()
- {
- CDrawTool::c_drawShape = line;
- }
- void CProjView::OnUpdateDrawLine(CCmdUI* pCmdUI)
- {
-
- pCmdUI->SetRadio(CDrawTool::c_drawShape == line);
-
- }
- void CProjView::OnDrawEllipse()
- {
- CDrawTool::c_drawShape = ellipse;
- }
- void CProjView::OnUpdateDrawEllipse(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == ellipse);
-
- }
- void CProjView::OnObjectMoveback()
- {
- CProjDoc* pDoc = GetDocument();
- CDrawObj* pObj = m_selection.GetHead();
- CDrawObjList* pObjects = pDoc->GetObjects();
- POSITION pos = pObjects->Find(pObj);
- ASSERT(pos != NULL);
- if (pos != pObjects->GetHeadPosition())
- {
- POSITION posPrev = pos;
- pObjects->GetPrev(posPrev);
- pObjects->RemoveAt(pos);
- pObjects->InsertBefore(posPrev, pObj);
- InvalObj(pObj);
- }
- }
- void CProjView::OnUpdateObjectMoveback(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(m_selection.GetCount() == 1);
- }
-
- BOOL CProjView::OnEraseBkgnd(CDC* pDC)
- {
- CProjDoc* pDoc = GetDocument();
- CBrush brush;
- CRect rect;
- GetClientRect(rect);
-
- if (!brush.CreateSolidBrush(pDoc->GetPaperColor()))
- return TRUE;
- brush.UnrealizeObject();
- pDC->FillRect(rect,&brush);
- return FALSE;
- }
- void CProjView::OnSize(UINT nType, int cx, int cy)
- {
- CScrollView::OnSize(nType, cx, cy);
-
- }
- void CProjView::OnUpdateEditSelectAll(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(GetDocument()->GetObjects()->GetCount() != 0);
- }
- void CProjView::OnEditClear()
- {
- // update all the views before the selection goes away
- //GetDocument()->UpdateAllViews(NULL, HINT_DELETE_SELECTION, &m_selection); // Comment the two lines for test;
- //OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
- // now remove the selection from the document
- POSITION pos = m_selection.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- GetDocument()->Remove(pObj);
- pObj->Remove();
- }
- m_selection.RemoveAll();
- Invalidate();// Add this line for test!
- }
-
- BOOL CProjView::IsSelected(const CObject* pDocItem) const
- {
- CDrawObj* pDrawObj = (CDrawObj*)pDocItem;
- return m_selection.Find(pDrawObj) != NULL;
- }
- void CProjView::CloneSelection()
- {
- POSITION pos = m_selection.GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- pObj->Clone(pObj->m_pDocument);
- // copies object and adds it to the document
- }
- }
- void CProjView::Deselect(CDrawObj* pObj)
- {
- POSITION pos = m_selection.Find(pObj);
- if (pos != NULL)
- {
- InvalObj(pObj);
- m_selection.RemoveAt(pos);
- }
- }
- void CProjView::SelectWithinRect(CRect rect, BOOL bAdd)
- {
- if (!bAdd)
- Select(NULL);
- ClientToDoc(rect);
- CDrawObjList* pObList = GetDocument()->GetObjects();
- POSITION posObj = pObList->GetHeadPosition();
- while (posObj != NULL)
- {
- CDrawObj* pObj = pObList->GetNext(posObj);
- if( pObj != NULL )
- if (pObj->Intersects(rect))
- Select(pObj, TRUE);
- }
- }
- CRect CProjView::GetInitialPosition()
- {
- CRect rect(10, 10, 10, 10);
- ClientToDoc(rect);
- return rect;
- }
- void CProjView::ClientToDoc(CPoint& point)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc, NULL);
- dc.DPtoLP(&point);
- }
- void CProjView::ClientToDoc(CRect& rect)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc, NULL);
- dc.DPtoLP(rect);
- ASSERT(rect.left <= rect.right);
- ASSERT(rect.bottom <= rect.top);
- }
- void CProjView::DocToClient(CPoint& point)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc, NULL);
- dc.LPtoDP(&point);
- }
- void CProjView::DocToClient(CRect& rect)
- {
- CClientDC dc(this);
- OnPrepareDC(&dc, NULL);
- dc.LPtoDP(rect);
- rect.NormalizeRect();
- }
- void CProjView::Select(CDrawObj* pObj, BOOL bAdd)
- {
- if (!bAdd)
- {
- OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
- m_selection.RemoveAll();
- }
- if (pObj == NULL || IsSelected(pObj))
- return;
- m_selection.AddTail(pObj);
- InvalObj(pObj);
- }
- void CProjView::OnCancelEdit()
- {
- ReleaseCapture();
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnCancel(this);
- CDrawTool::c_drawShape = selection;
- }
- void CProjView::SetPageSize(CSize size)
- {
- CClientDC dc(NULL);
- size.cx = MulDiv(size.cx, dc.GetDeviceCaps(LOGPIXELSX), 100);
- size.cy = MulDiv(size.cy, dc.GetDeviceCaps(LOGPIXELSY), 100);
- SetScrollSizes(MM_TEXT, size);
- GetDocument()->UpdateAllViews(NULL, HINT_UPDATE_WINDOW, NULL);
- }
- void CProjView::DrawGrid(CDC* pDC)
- {
- CProjDoc* pDoc = GetDocument();
- COLORREF oldBkColor = pDC->SetBkColor(pDoc->GetPaperColor());
- CRect rect;
- rect.left = 0;
- rect.top = 0;
- rect.right = pDoc->GetSize().cx;
- rect.bottom = -pDoc->GetSize().cy;
- // Center lines
- int old = pDC->SetROP2(R2_NOTXORPEN);
- int old1 = pDC->SetBkMode(TRANSPARENT);
- CPen penDash;
- penDash.CreatePen(PS_DASH, 1, m_gridColor);
- CPen* pOldPen = pDC->SelectObject(&penDash);
- pDC->MoveTo(0, rect.top);
- pDC->LineTo(0, rect.bottom);
- pDC->MoveTo(rect.left, 0);
- pDC->LineTo(rect.right, 0);
- //for(int i = rect.top/20*20;i<rect.bottom;i+=20)
- //{
- // pDC->Ellipse(CRect(-1,i-1,1,i+1));
- //}
-
- // Major unit lines
- CPen penDot;
- penDot.CreatePen(PS_DOT, 1, m_gridColor);
- pDC->SelectObject(&penDot);
- for (int x = rect.left / 100 * 100; x < rect.right; x += 100)
- {
- if (x != 0)
- {
- pDC->MoveTo(x, rect.top);
- pDC->LineTo(x, rect.bottom);
- /*for (int y = rect.top / 20 * 20; y < rect.bottom; y += 20)
- {
- if (y != 0)
- {
- pDC->MoveTo(x, rect.top);
- pDC->LineTo(x, rect.bottom);
- pDC->Ellipse(CRect(x-1,y-1,x+1,y+1));
- }
- }*/
- }
- }
- for (int y = rect.top / 100 * 100; y >rect.bottom; y -= 100)
- {
- if (y != 0)
- {
- pDC->MoveTo(rect.left, y);
- pDC->LineTo(rect.right, y);
- }
- }
- // Outlines
- CPen penSolid;
- penSolid.CreatePen(PS_SOLID, 1, m_gridColor);
- pDC->SelectObject(&penSolid);
- pDC->MoveTo(rect.left, rect.top);
- pDC->LineTo(rect.right, rect.top);
- pDC->LineTo(rect.right, rect.bottom);
- pDC->LineTo(rect.left, rect.bottom);
- pDC->LineTo(rect.left, rect.top);
-
- pDC->SetROP2(old);
- pDC->SetBkMode(old1);
- pDC->SelectObject(pOldPen);
- pDC->SetBkColor(oldBkColor);
- }
- void CProjView::Remove(CDrawObj* pObj)
- {
- POSITION pos = m_selection.Find(pObj);
- CRect rect;
- GetClientRect(rect);
- if (pos != NULL)
- m_selection.RemoveAt(pos);
- InvalidateRect(rect,FALSE);
- }
- void CProjView::OnPrepareDC(CDC* pDC, CPrintInfo* pInfo)
- {
- CScrollView::OnPrepareDC(pDC, pInfo);
- // mapping mode is MM_ANISOTROPIC
- // these extents setup a mode similar to MM_LOENGLISH
- // MM_LOENGLISH is in .01 physical inches
- // these extents provide .01 logical inches
- pDC->SetMapMode(MM_ANISOTROPIC);
- pDC->SetViewportExt(pDC->GetDeviceCaps(LOGPIXELSX),
- pDC->GetDeviceCaps(LOGPIXELSY));
- int n = pDC->GetDeviceCaps(LOGPIXELSX);//for debug
- int m = pDC->GetDeviceCaps(LOGPIXELSY);//for debug
- //pDC->SetWindowExt(100, -100);
- pDC->SetWindowExt(100, -100);
- // set the origin of the coordinate system to the center of the page
- CPoint ptOrg;
- ptOrg.x = GetDocument()->GetSize().cx / 2;
- ptOrg.y = GetDocument()->GetSize().cy / 2;
- // ptOrg is in logical coordinates
- // pDC->OffsetWindowOrg(-ptOrg.x,ptOrg.y);
- //pDC->OffsetViewportOrg(ptOrg.x,ptOrg.y);
- pDC->OffsetViewportOrg(0,0);
- }
- void CProjView::InvalObj(CDrawObj* pObj)
- {
- CRect rect = pObj->m_position;
- DocToClient(rect);
- if (m_bActive && IsSelected(pObj))
- {
- rect.left -= 40;
- rect.top -= 50;
- rect.right += 50;
- rect.bottom += 40;
- }
- rect.InflateRect(1, 1); // handles CDrawOleObj objects
- //rect.InflateRect(5, 5);//For debug
- InvalidateRect(rect, FALSE);
- }
- void CProjView::OnUpdate(CView* , LPARAM lHint, CObject* pHint)
- {
- switch (lHint)
- {
- case HINT_UPDATE_WINDOW: // redraw entire window
- Invalidate(FALSE);
- break;
- case HINT_UPDATE_DRAWOBJ: // a single object has changed
- InvalObj((CDrawObj*)pHint);
- break;
- case HINT_UPDATE_SELECTION: // an entire selection has changed
- {
- CDrawObjList* pList = pHint != NULL ?
- (CDrawObjList*)pHint : &m_selection;
- POSITION pos = pList->GetHeadPosition();
- while (pos != NULL)
- InvalObj(pList->GetNext(pos));
- }
- break;
- case HINT_DELETE_SELECTION: // an entire selection has been removed
- if (pHint != &m_selection)
- {
- CDrawObjList* pList = (CDrawObjList*)pHint;
- POSITION pos = pList->GetHeadPosition();
- while (pos != NULL)
- {
- CDrawObj* pObj = pList->GetNext(pos);
- InvalObj(pObj);
- Remove(pObj); // remove it from this view's selection
- }
- }
- break;
-
- default:
- ASSERT(FALSE);
- break;
- }
- Invalidate(FALSE);
- }
- BOOL CProjView::DestroyWindow()
- {
- // TODO: Add your specialized code here and/or call the base class
-
- return CScrollView::DestroyWindow();
- }
- void CProjView::OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView)
- {
- CView::OnActivateView(bActivate, pActivateView, pDeactiveView);
- // invalidate selections when active status changes
- if (m_bActive != bActivate)
- {
- if (bActivate) // if becoming active update as if active
- m_bActive = bActivate;
- if (!m_selection.IsEmpty())
- OnUpdate(NULL, HINT_UPDATE_SELECTION, NULL);
- m_bActive = bActivate;
- }
- }
- void CProjView::OnUpdateAnySelect(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable(!m_selection.IsEmpty());
- }
- void CProjView::OnDrawText()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = text;
- }
- void CProjView::OnUpdateDrawText(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == text);
- }
- void CProjView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- TRACE("Into OnCharn");
- if (!m_bActive)
- return;
- CDrawTool* pTool = CDrawTool::FindTool(CDrawTool::c_drawShape);
- if (pTool != NULL)
- pTool->OnChar(this, nFlags, nChar);
- CScrollView::OnChar(nChar, nRepCnt, nFlags);
- }
- void CProjView::OnDrawBarGraph()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = barGraph;
-
- }
- void CProjView::OnUpdateDrawBarGraph(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == barGraph);
- }
- void CProjView::OnDrawClock()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = clockGraph;
- }
- void CProjView::OnUpdateDrawClock(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == clockGraph);
- }
- void CProjView::LoopSearch(CDrawObjList& list,int nTemp)
- {
- CDrawObjList tempList;
- POSITION pos = list.GetHeadPosition();
- while(pos!=NULL)
- {
- if(list.GetNext(pos)->GetActiveObj(tempList))
- {
- POSITION pos1 = tempList.GetHeadPosition();
- while( pos1 != NULL )
- {
- (tempList.GetNext( pos1 ))->SendData( nTemp );
- }
- }
- else
- {
- LoopSearch(tempList,nTemp);
- }
- }
- }
- void CProjView::OnTimer(UINT nIDEvent)
- {
- nTemp += 10;
- if(nTemp >100 )
- nTemp = 0;
- if( m_bRun )
-
- LoopSearch(GetDocument()->m_objects,nTemp);
-
- }
- int CProjView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollView::OnCreate(lpCreateStruct) == -1)
- return -1;
- int nRes = SetTimer( 1, 500, NULL);
- // TODO: Add your specialized creation code here
-
- return 0;
- }
- void CProjView::OnDrawAnimateTag()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = animateTag;
- }
- void CProjView::OnUpdateDrawAnimateTag(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == animateTag);
- }
- void CProjView::OnUpdateDrawCursor(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == cursor);
- }
- void CProjView::OnDrawCursor()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = cursor;
- }
- void CProjView::OnRunRun()
- {
- // TODO: Add your command handler code here
- m_bRun = TRUE;
-
- }
- void CProjView::OnUpdateRunRun(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable( !m_bRun && !(GetDocument()->m_objects).IsEmpty() );
-
- }
- void CProjView::OnRunStop()
- {
- // TODO: Add your command handler code here
- m_bRun = FALSE;
-
- }
- void CProjView::OnUpdateRunStop(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->Enable( m_bRun );
-
- }
- void CProjView::OnAlign( UINT nID )
- {
- POSITION pos = m_selection.GetHeadPosition();
- CRect rect = m_selection.GetNext(pos)->m_position;
- switch( nID )
- {
- case ID_EDIT_TOP:
- while( pos != NULL )
- m_selection.GetNext(pos)->AlignToTop( rect );
-
- break;
- case ID_EDIT_RIGHT:
- while( pos != NULL )
- m_selection.GetNext(pos)->AlignToRight( rect );
-
- break;
- case ID_EDIT_LEFT:
- while( pos != NULL )
- m_selection.GetNext(pos)->AlignToLeft( rect );
-
- break;
- case ID_EDIT_BOTTOM:
- while( pos != NULL )
- m_selection.GetNext(pos)->AlignToBottom( rect );
-
- break;
- default:
- ASSERT( FALSE );
- }
- Invalidate();
- }
- void CProjView::OnUpdateAlign( CCmdUI* pCmdUI)
- {
- pCmdUI->Enable( m_selection.GetCount() >= 2);
- }
- // End of the implemention
- BOOL CProjView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
- {
- if( m_bCursor )
- return m_tracker.SetCursor( pWnd,nHitTest );
- else
- return CScrollView::OnSetCursor(pWnd, nHitTest, message);
- }
- void CProjView::OnRButtonDown(UINT nFlags, CPoint point)
- {
- OnCancelEdit();
- }
- void CProjView::OnDrawIsa()
- {
- CDrawTool::c_drawShape = isa;
- }
- void CProjView::OnUpdateDrawIsa(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == isa);
- }
- void CProjView::OnDrawLoop()
- {
- CDrawTool::c_drawShape = loop;
-
- }
- void CProjView::OnUpdateDrawLoop(CCmdUI* pCmdUI)
- {
-
- pCmdUI->SetRadio(CDrawTool::c_drawShape == loop);
- }
- void CProjView::OnObjectMerge()
- {
- BeginWaitCursor();
- POSITION pos = m_selection.GetHeadPosition();
- CRect rect = (m_selection.GetNext(pos))->m_position;
- while( pos!=NULL)
- {
- rect.NormalizeRect();
- CRect temp = (m_selection.GetNext(pos))->m_position;
- temp.NormalizeRect();
- rect |= temp;
- }
- CMergeObj* pMerge = new CMergeObj(rect);
- pMerge->SetList(m_selection);
- CRect rect1 = pMerge->m_position;
- pMerge->RightRect(rect1);
- pMerge->m_position = rect1;
-
- GetDocument()->Add(pMerge);
- pos = m_selection.GetHeadPosition();
- while( pos!=NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- GetDocument()->Remove(pObj);
- }
- m_selection.RemoveAll();
- Invalidate();
- EndWaitCursor();
- }
- void CProjView::OnUpdateObjectMerge(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable( m_selection.GetCount() >= 2);
- }
- void CProjView::OnObjectLib()
- {
- CProjDoc* pDoc = (CProjDoc* )GetDocument();
- ASSERT_VALID(pDoc);
- if(!pDoc->IsExist())
- {
- if(!pDoc->CreateLib())
- return;
- }
- pDoc->LoadFromLib();
- pDoc->AddToList((m_selection.GetHead())->Clone(NULL));
- pDoc->StoreToLib();
- }
- void CProjView::OnUpdateObjectLib(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable( m_selection.GetCount() == 1
- && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CMergeObj)));
- }
- void CProjView::OnDrawLib()
- {
- // TODO: Add your command handler code here
- CDrawTool::c_drawShape = custom;
- }
- void CProjView::OnUpdateDrawLib(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetRadio(CDrawTool::c_drawShape == custom);
- }
- void CProjView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
- {
- // TODO: Add your message handler code here and/or call default
- if(nChar == VK_DELETE && !m_selection.IsEmpty())
- OnEditClear();
- if(nChar == VK_F5)
- Invalidate(FALSE);
- if(!m_selection.IsEmpty())
- {
- CRect rect;
- int nStep = 5;
- if(::GetKeyState(VK_CONTROL)<0)
- nStep = 1;
- POSITION pos = m_selection.GetHeadPosition();
- while(pos != NULL)
- {
- CDrawObj* pObj = m_selection.GetNext(pos);
- ASSERT_VALID(pObj);
- rect = pObj->m_position;
- switch(nChar)
- {
- case VK_RIGHT:
- rect.OffsetRect(nStep,0);
- //pObj->m_position = rect;
- break;
- case VK_LEFT:
- rect.OffsetRect(-nStep,0);
- //pObj->m_position = rect;
- break;
- case VK_UP:
- rect.OffsetRect(0,nStep);
- //pObj->m_position = rect;
- break;
- case VK_DOWN:
- rect.OffsetRect(0,-nStep);
-
- break;
- default:
- break;
- }
- pObj->MoveTo(rect);
- }
- Invalidate(FALSE);
- }
- CScrollView::OnKeyDown(nChar, nRepCnt, nFlags);
- }
- void CProjView::OnObjectSplit()
- {
- CDrawObj* pSplit;
- CMergeObj* pObj = (CMergeObj* )m_selection.GetHead();
- CSplitDlg dlg;
- POSITION pos = (pObj->m_consist).GetHeadPosition();
- while(pos!=NULL)
- {
- dlg.m_list.AddTail(((pObj->m_consist).GetNext(pos))->m_name);
- }
- if(dlg.DoModal()!=IDOK)
- return;
- if(dlg.m_index >= 0){
- pos = (pObj->m_consist).FindIndex(dlg.m_index);
- pSplit = (pObj->m_consist).GetAt(pos);
- (pObj->m_consist).RemoveAt(pos);
-
- /*if((pObj->m_consist).IsEmpty())
- {
- GetDocument()->Remove(pObj);
- pObj->Remove();
- }*/
- if((pObj->m_consist).GetCount() == 1)
- {
- GetDocument()->Remove(pObj);
- GetDocument()->Add((pObj->m_consist).RemoveHead());
- pObj->Remove();
- }
- else{
- pObj->ReRect();
- }
- GetDocument()->Add(pSplit);
- }
-
- Invalidate();
- GetDocument()->SetModifiedFlag();
- }
- void CProjView::OnUpdateObjectSplit(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable( m_selection.GetCount() == 1
- && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CMergeObj)));
- }
- void CProjView::OnDrawButton()
- {
- CDrawTool::c_drawShape = button;
-
- }
- void CProjView::OnUpdateDrawButton(CCmdUI* pCmdUI)
- {
- pCmdUI->SetRadio(CDrawTool::c_drawShape == button);
-
- }
- void CProjView::OnEditRotate()
- {
- CDrawISA* pObj = (CDrawISA* )m_selection.GetHead();
- if((++(pObj->m_nRotate))>3)
- pObj->m_nRotate = 0;
- Invalidate(FALSE);
- }
- void CProjView::OnUpdateEditRotate(CCmdUI* pCmdUI)
- {
- pCmdUI->Enable((m_selection.GetCount()==1)
- && (m_selection.GetHead())->IsKindOf(RUNTIME_CLASS(CDrawISA)));
- }