MyManageGraphObj.cpp
上传用户:netltd
上传日期:2013-02-12
资源大小:7234k
文件大小:42k
- #include "stdafx.h"
- #include "MyManageGraphObj.h"
- #include "math.h"
- #include "MyDefine.h"
- #include "resource.h"
- //被选择图形对象信息
- CSelectedObjectInfo::CSelectedObjectInfo(int type, int index)
- {
- m_type = type;
- m_index = index;
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- IMPLEMENT_DYNCREATE(CManageGraphObject, CObject)
- CManageGraphObject::CManageGraphObject()
- {
- Proportion = 1.0;
- LRepeatTimes = 0;
- RRepeatTimes = 0;
- }
- CManageGraphObject::~CManageGraphObject()
- {
- DelAllLine();
- DelAllRect();
- DelAllCircle();
- DelAllArc();
- }
- void CManageGraphObject::Initialize(SIZE size, int style, COLORREF color)
- {
- LogicSize = size;
- LineStyle = style;
- PenColor = color;
- GetObjectRange();
- }
- void CManageGraphObject::SetLogicSize(SIZE size)
- {
- LogicSize.cx = size.cx;
- LogicSize.cy = size.cy;
- }
- void CManageGraphObject::SetLineStyle(int style)
- {
- LineStyle = style;
- }
- void CManageGraphObject::SetPenColor(COLORREF color)
- {
- PenColor = color;
- }
- //获取命令堆栈指针
- void CManageGraphObject::GetCommandStack(CCommandStack* pStack)
- {
- pCommandStack = pStack;
- }
- void CManageGraphObject::SetCurrentLayerName(CString layername)
- {
- CurrentLayerName = layername;
- }
- void CManageGraphObject::GetDC(CDC* pClientDC)
- {
- ASSERT(pClientDC != NULL);
- pDC = pClientDC;
- }
- void CManageGraphObject::GetView(CView* view)
- {
- ASSERT(view != NULL);
- pView = view;
- }
- void CManageGraphObject::GetManageFileLayer(CManageFileLayer* pManage)
- {
- pManageLayer = pManage;
- }
- void CManageGraphObject::Serialize(CArchive& ar)
- {
- int index;
- CMyLine* pLine;
- CMyRect* pRect;
- CMyCircle* pCircle;
- CMyArc* pArc;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- if(ar.IsStoring())
- {
- m_LineArray.Serialize(ar);
- m_RectArray.Serialize(ar);
- m_CircleArray.Serialize(ar);
- m_ArcArray.Serialize(ar);
- }
- else
- {
- //注意当打开文件时,下面的Serialize()函数会自动创建CMyLine,CMyRect等对象
- m_LineArray.Serialize(ar);
- m_RectArray.Serialize(ar);
- m_CircleArray.Serialize(ar);
- m_ArcArray.Serialize(ar);
-
- //注意创建CGraphObjectInfo对象
- for(index = 0; index < m_LineArray.GetSize(); index++)
- {
- pLine = GetLine(index);
- pLineInfo = new CGraphObjectInfo();
- m_LineInfoArray.Add(pLineInfo);
- }
- for(index = 0; index < m_RectArray.GetSize(); index++)
- {
- pRect = GetRect(index);
- pRectInfo = new CGraphObjectInfo();
- m_RectInfoArray.Add(pRectInfo);
- }
- for(index = 0; index < m_CircleArray.GetSize(); index++)
- {
- pCircle = GetCircle(index);
- pCircleInfo = new CGraphObjectInfo();
- m_CircleInfoArray.Add(pCircleInfo);
- }
- for(index = 0; index < m_ArcArray.GetSize(); index++)
- {
- pArc = GetArc(index);
- pArcInfo = new CGraphObjectInfo();
- m_ArcInfoArray.Add(pArcInfo);
- }
- }
- }
- ///////////////////////////////////////////////////////////////////////////////////////////////
- //处理命令
- void CManageGraphObject::OnLButtonDown(UINT ID, CPoint point)
- {
- ASSERT(pDC != NULL);
- ASSERT(pCommandStack != NULL);
- UINT msg = MESSAGE_LBUTTONDOWN;
- switch(ID)
- {
- case DRAW_SELECT:
- SelectObject(pDC, point);
- break;
- case DRAW_LINE:
- OnDrawLine(msg, point);
- break;
- case DRAW_RECT:
- OnDrawRect(msg, point);
- break;
- case DRAW_CIRCLE:
- OnDrawCircle(msg, point);
- break;
- case DRAW_ARC:
- OnDrawArc(msg, point);
- break;
- case DRAW_TEXT:
- break;
- case MODIFY_DELETE:
- break;
- }
- }
- UINT CManageGraphObject::OnRButtonDown(UINT ID, CPoint point)
- {
- ASSERT(pDC != NULL);
- UINT msg = MESSAGE_RBUTTONDOWN;
- switch(ID)
- {
- case DRAW_SELECT:
- if(UnselectObject())
- pView->Invalidate();
- break;
- case DRAW_LINE:
- ID = OnDrawLine(msg, point);
- break;
- case DRAW_RECT:
- ID = OnDrawRect(msg, point);
- break;
- case DRAW_CIRCLE:
- ID = OnDrawCircle(msg, point);
- break;
- case DRAW_ARC:
- ID = OnDrawArc(msg, point);
- break;
- }
- return ID;
- }
- void CManageGraphObject::OnMouseMove(UINT ID, CPoint point)
- {
- ASSERT(pDC != NULL);
- UINT msg = MESSAGE_MOUSEMOVE;
- switch(ID)
- {
- case DRAW_SELECT:
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- break;
- case DRAW_LINE:
- OnDrawLine(msg, point);
- break;
- case DRAW_RECT:
- OnDrawRect(msg, point);
- break;
- case DRAW_CIRCLE:
- OnDrawCircle(msg, point);
- break;
- case DRAW_ARC:
- OnDrawArc(msg, point);
- break;
- }
- }
- void CManageGraphObject::OnScroll(UINT ID)
- {
- ASSERT(pDC != NULL);
-
- UINT msg = MESSAGE_SCROLL;
- switch(ID)
- {
- case DRAW_LINE:
- OnDrawLine(msg, NULL);
- break;
- case DRAW_RECT:
- OnDrawRect(msg, NULL);
- break;
- case DRAW_CIRCLE:
- OnDrawCircle(msg, NULL);
- break;
- case DRAW_ARC:
- OnDrawArc(msg, NULL);
- break;
- }
-
- }
- UINT CManageGraphObject::OnDrawLine(UINT msg, CPoint point)
- {
- int ObjectType;
- int ObjetcIndex;
-
- UINT command = DRAW_LINE;
- switch(msg)
- {
- case MESSAGE_LBUTTONDOWN:
- LRepeatTimes++;
- switch(LRepeatTimes)
- {
- case 1:
- StartPoint = point;
- m_DrawGrapObject.SetOnceFlag();
- break;
- case 2:
- EndPoint = point;
- m_DrawGrapObject.DrawLine(pDC, StartPoint, EndPoint, LineStyle, PenColor);
- AddLine(StartPoint, EndPoint, LineStyle, PenColor);
-
- ObjectType = OBJECT_LINE;
- ObjetcIndex = m_LineArray.GetUpperBound();
- //因为执行一项新操作后,将不再有可以Redo的命令
- pCommandStack->PushCommand(DRAW_LINE, 1, &ObjectType, &ObjetcIndex);
-
- LRepeatTimes--;
- StartPoint = EndPoint;
- oldEndPoint = StartPoint;
- break;
- }
- break;
- case MESSAGE_RBUTTONDOWN:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawLine(pDC, StartPoint, EndPoint);
- LRepeatTimes = 0;
- }
- else
- {
- command = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- LRepeatTimes = 0;
- }
- break;
- case MESSAGE_MOUSEMOVE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(LRepeatTimes == 1)
- {
- EndPoint = point;
- m_DrawGrapObject.DrawLineXOR(pDC, StartPoint, EndPoint, oldEndPoint);
- oldEndPoint = EndPoint;
- }
- break;
- case MESSAGE_SCROLL:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawLine(pDC, StartPoint, EndPoint);
- oldEndPoint = StartPoint;
- EndPoint = StartPoint;
- m_DrawGrapObject.SetOnceFlag();
- }
- break;
- }
- return command;
- }
- UINT CManageGraphObject::OnDrawRect(UINT msg, CPoint point)
- {
- int ObjectType;
- int ObjetcIndex;
- UINT command = DRAW_RECT;
- switch(msg)
- {
- case MESSAGE_LBUTTONDOWN:
- LRepeatTimes++;
- switch(LRepeatTimes)
- {
- case 1:
- StartPoint = point;
- m_DrawGrapObject.SetOnceFlag();
- break;
- case 2:
- EndPoint = point;
- m_DrawGrapObject.DrawRect(pDC, StartPoint, EndPoint, LineStyle, PenColor);
- AddRect(StartPoint, EndPoint, LineStyle, PenColor);
- ObjectType = OBJECT_RECT;
- ObjetcIndex = m_RectArray.GetUpperBound();
- pCommandStack->PushCommand(DRAW_RECT, 1, &ObjectType, &ObjetcIndex);
-
- LRepeatTimes = 0;
- break;
- }
- break;
- case MESSAGE_RBUTTONDOWN:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawRect(pDC, StartPoint, EndPoint);
- LRepeatTimes = 0;
- }
- else
- {
- command = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- LRepeatTimes = 0;
- }
- break;
- case MESSAGE_MOUSEMOVE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(LRepeatTimes == 1)
- {
- EndPoint = point;
- m_DrawGrapObject.DrawRectXOR(pDC, StartPoint, EndPoint, oldEndPoint);
- oldEndPoint = EndPoint;
- }
- break;
- case MESSAGE_SCROLL:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawRect(pDC, StartPoint, EndPoint);
- oldEndPoint = StartPoint;
- EndPoint = StartPoint;
- m_DrawGrapObject.SetOnceFlag();
- }
- break;
- }
- return command;
- }
- UINT CManageGraphObject::OnDrawCircle(UINT msg, CPoint point)
- {
- int ObjectType;
- int ObjetcIndex;
- UINT command = DRAW_CIRCLE;
- switch(msg)
- {
- case MESSAGE_LBUTTONDOWN:
- LRepeatTimes++;
- switch(LRepeatTimes)
- {
- case 1:
- StartPoint = point;
- m_DrawGrapObject.SetOnceFlag();
- break;
- case 2:
- EndPoint = point;
- m_DrawGrapObject.DrawCircle(pDC, StartPoint, EndPoint, LineStyle, PenColor);
- AddCircle(StartPoint, EndPoint, LineStyle, PenColor);
- ObjectType = OBJECT_CIRCLE;
- ObjetcIndex = m_CircleArray.GetUpperBound();
- pCommandStack->PushCommand(DRAW_CIRCLE, 1, &ObjectType, &ObjetcIndex);
- LRepeatTimes = 0;
- break;
- }
- break;
- case MESSAGE_RBUTTONDOWN:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawCircle(pDC, StartPoint, EndPoint);
- LRepeatTimes = 0;
- }
- else
- {
- command = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- LRepeatTimes = 0;
- }
- break;
- case MESSAGE_MOUSEMOVE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- if(LRepeatTimes == 1)
- {
- EndPoint = point;
- m_DrawGrapObject.DrawCircleXOR(pDC, StartPoint, EndPoint, oldEndPoint);
- oldEndPoint = EndPoint;
- }
- break;
- case MESSAGE_SCROLL:
- if(LRepeatTimes == 1)
- {
- m_DrawGrapObject.CancelDrawCircle(pDC, StartPoint, EndPoint);
- oldEndPoint = StartPoint;
- EndPoint = StartPoint;
- m_DrawGrapObject.SetOnceFlag();
- }
- break;
- }
- return command;
- }
- UINT CManageGraphObject::OnDrawArc(UINT msg, CPoint point)
- {
- int ObjectType;
- int ObjetcIndex;
- UINT command = DRAW_ARC;
- switch(msg)
- {
- case MESSAGE_LBUTTONDOWN:
- LRepeatTimes++;
- switch(LRepeatTimes)
- {
- case 1:
- StartPoint = point;
- m_DrawGrapObject.SetOnceFlag();
- break;
- case 2:
- MidPoint = point;
- m_DrawGrapObject.SetOnceFlag();
- break;
- case 3:
- EndPoint = point;
- m_DrawGrapObject.DrawArc(pDC, StartPoint, MidPoint, EndPoint,
- LineStyle, PenColor);
- AddArc(StartPoint, MidPoint, EndPoint, LineStyle, PenColor);
- ObjectType = OBJECT_ARC;
- ObjetcIndex = m_ArcArray.GetUpperBound();
- pCommandStack->PushCommand(DRAW_ARC, 1, &ObjectType, &ObjetcIndex);
-
- LRepeatTimes = 0;
- break;
- }
- break;
- case MESSAGE_RBUTTONDOWN:
- if(LRepeatTimes > 0)
- {
- m_DrawGrapObject.CancelDrawArc(pDC, StartPoint, MidPoint, EndPoint, LRepeatTimes);
- LRepeatTimes = 0;
- }
- else
- {
- command = DRAW_SELECT;
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR));
- LRepeatTimes = 0;
- }
- break;
- case MESSAGE_MOUSEMOVE:
- SetCursor(AfxGetApp()->LoadCursor(IDC_DRAWCUR));
- switch(LRepeatTimes)
- {
- case 1:
- MidPoint = point;
- m_DrawGrapObject.DrawArcXOR(pDC, StartPoint, MidPoint, oldMidPoint,
- EndPoint, oldEndPoint, LRepeatTimes);
- oldMidPoint = MidPoint;
- break;
- case 2:
- EndPoint = point;
- m_DrawGrapObject.DrawArcXOR(pDC, StartPoint, MidPoint, oldMidPoint,
- EndPoint, oldEndPoint, LRepeatTimes);
- oldEndPoint = EndPoint;
- break;
- }
- break;
- case MESSAGE_SCROLL:
- m_DrawGrapObject.CancelDrawArc(pDC, StartPoint, MidPoint, EndPoint, LRepeatTimes);
- if(LRepeatTimes == 1)
- {
- oldMidPoint = StartPoint;
- MidPoint = StartPoint;
- }
- if(LRepeatTimes == 2)
- {
- oldEndPoint = StartPoint;
- EndPoint = StartPoint;
- }
- m_DrawGrapObject.SetOnceFlag();
- break;
- }
- return command;
- }
- UINT CManageGraphObject::OnModifyDelete()
- {
- int* pObjectType;
- int* pObjetcIndex;
- int nIndex;
- int num;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- CSelectedObjectInfo* pSelObjectInfo;
- num = m_SelObjInfoArray.GetSize();
- //如果没有图形对象被选中则返回
- if(num == 0)
- {
- SetCursor(AfxGetApp()->LoadCursor(IDC_SELECTCUR1));
- return DRAW_SELECT;
- }
- pObjectType = new int[num];
- pObjetcIndex = new int[num];
- for(nIndex = 0; nIndex < num; nIndex++)
- {
- pSelObjectInfo = (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- switch(pSelObjectInfo->m_type)
- {
- case OBJECT_LINE:
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pSelObjectInfo->m_index);
- pLineInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJECT_LINE;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJECT_RECT:
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pSelObjectInfo->m_index);
- pRectInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJECT_RECT;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJECT_CIRCLE:
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pSelObjectInfo->m_index);
- pCircleInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJECT_CIRCLE;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- case OBJECT_ARC:
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pSelObjectInfo->m_index);
- pArcInfo->m_del = TRUE;
- pObjectType[nIndex] = OBJECT_ARC;
- pObjetcIndex[nIndex] = pSelObjectInfo->m_index;
- break;
- }
- }
- pCommandStack->PushCommand(MODIFY_DELETE, num, pObjectType, pObjetcIndex);
- UnselectObject();
- pView->Invalidate();
-
- delete pObjectType;
- delete pObjetcIndex;
- return DRAW_SELECT;
- }
- //实现“撤销”命令
- void CManageGraphObject::OnUndo()
- {
- CCommandStruct* pCommand;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- pCommand = (CCommandStruct*)pCommandStack->Undo();
- if(pCommand == NULL)
- return;
- switch(pCommand->m_command)
- {
- case DRAW_LINE:
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pCommand->m_index[0]);
- pLineInfo->m_del = TRUE;
- break;
- case DRAW_RECT:
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pCommand->m_index[0]);
- pRectInfo->m_del = TRUE;
- break;
- case DRAW_CIRCLE:
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pCommand->m_index[0]);
- pCircleInfo->m_del = TRUE;
- break;
- case DRAW_ARC:
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pCommand->m_index[0]);
- pArcInfo->m_del = TRUE;
- break;
- case MODIFY_DELETE:
- for(int index =0; index < pCommand->m_num; index++)
- {
- switch(pCommand->m_object[index])
- {
- case OBJECT_LINE:
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pCommand->m_index[index]);
- pLineInfo->m_del = FALSE;
- break;
- case OBJECT_RECT:
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pCommand->m_index[index]);
- pRectInfo->m_del = FALSE;
- break;
- case OBJECT_CIRCLE:
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pCommand->m_index[index]);
- pCircleInfo->m_del = FALSE;
- break;
- case OBJECT_ARC:
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pCommand->m_index[index]);
- pArcInfo->m_del = FALSE;
- break;
- }
- }
- break;
- }
- }
- //实现“重做”命令
- void CManageGraphObject::OnRedo()
- {
- CCommandStruct* pCommand;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- pCommand = (CCommandStruct*)pCommandStack->Redo();
- if(pCommand == NULL)
- return;
- switch(pCommand->m_command)
- {
- case DRAW_LINE:
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pCommand->m_index[0]);
- pLineInfo->m_del = FALSE;
- break;
- case DRAW_RECT:
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pCommand->m_index[0]);
- pRectInfo->m_del = FALSE;
- break;
- case DRAW_CIRCLE:
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pCommand->m_index[0]);
- pCircleInfo->m_del = FALSE;
- break;
- case DRAW_ARC:
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pCommand->m_index[0]);
- pArcInfo->m_del = FALSE;
- break;
- case MODIFY_DELETE:
- for(int index =0; index < pCommand->m_num; index++)
- {
- switch(pCommand->m_object[index])
- {
- case OBJECT_LINE:
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pCommand->m_index[index]);
- pLineInfo->m_del = TRUE;
- break;
- case OBJECT_RECT:
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pCommand->m_index[index]);
- pRectInfo->m_del = TRUE;
- break;
- case OBJECT_CIRCLE:
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pCommand->m_index[index]);
- pCircleInfo->m_del = TRUE;
- break;
- case OBJECT_ARC:
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pCommand->m_index[index]);
- pArcInfo->m_del = TRUE;
- break;
- }
- }
- break;
- }
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- POINT CManageGraphObject::DrawingToLogic(FPOINT fpoint)
- {
- POINT point;
- point.x = long(fpoint.x * Proportion) + EXTRA_WIDTH;
- point.y = LogicSize.cy - (long)(fpoint.y * Proportion) - EXTRA_HIGTH;
- return point;
- }
- long CManageGraphObject::DrawingToLogic(float fdistance)
- {
- long distance;
- distance = (long)(fdistance * Proportion);
- return distance;
- }
- FPOINT CManageGraphObject::LogicToDrawing(POINT point)
- {
- FPOINT fpoint;
- fpoint.x = (float)(point.x - EXTRA_WIDTH) / Proportion;
- fpoint.y = (float)(LogicSize.cy - point.y - EXTRA_HIGTH) / Proportion;
- return fpoint;
- }
- float CManageGraphObject::LogicToDrawing(long distance)
- {
- float fdistance;
- fdistance = (float)distance / Proportion;
- return fdistance;
- }
- void CManageGraphObject::GetObjectRange()
- {
- int index;
- // int n;
- CMyLine* pLine;
- CMyRect* pRect;
- CMyCircle* pCircle;
- CMyArc* pArc;
- CGraphObjectInfo* pLineInfo;
- CGraphObjectInfo* pRectInfo;
- CGraphObjectInfo* pCircleInfo;
- CGraphObjectInfo* pArcInfo;
- // n = m_LineArray.GetSize();
- // n = m_LineInfoArray.GetSize();
- for(index = 0; index < m_LineInfoArray.GetSize(); index++)
- {
-
- pLine = GetLine(index);
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(index);
- pLineInfo->Initialize(GetLineRange(2, pLine), FALSE, FALSE);
- }
- for(index = 0; index < m_RectInfoArray.GetSize(); index++)
- {
- pRect = GetRect(index);
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(index);
- pRectInfo->Initialize(GetRectRange(2, pRect), FALSE, FALSE);
- }
- for(index = 0; index < m_CircleInfoArray.GetSize(); index++)
- {
- pCircle = GetCircle(index);
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(index);
- pCircleInfo->Initialize(GetCircleRange(2, pCircle), FALSE, FALSE);
- }
- for(index = 0; index < m_ArcInfoArray.GetSize(); index++)
- {
- pArc = GetArc(index);
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(index);
- pArcInfo->Initialize(GetArcRange(2, pArc), FALSE, FALSE);
- }
- }
- void CManageGraphObject::SetEffectRect(CRect rect)
- {
- EffectRect = rect;
- }
- CRect CManageGraphObject::GetLogicClientRect()
- {
- CRect rect;
- ASSERT(pView != NULL);
- ASSERT(pDC != NULL);
- pView->GetClientRect(&rect);
- pDC->DPtoLP(&rect);
- return rect;
- }
- BOOL CManageGraphObject::IsInLogicClientRect(CRect rect)
- {
- CRect clientrect = GetLogicClientRect();
- CRect temp = clientrect & rect;
- if(temp.IsRectEmpty())
- return FALSE;
- else
- return TRUE;
- }
- CRect CManageGraphObject::GetRedrawRect(CRect effectRect, CRect clientRect)
- {
- CRect rect;
- rect = effectRect & clientRect;
- return rect;
- }
- BOOL CManageGraphObject::IsRedraw(CRect redrawRect, CRect objRect)
- {
- CRect rect;
-
- rect = redrawRect & objRect;
- if(rect.IsRectEmpty())
- return FALSE;
- else
- return TRUE;
- }
- ////////////////////////////////////////////////////////////////////////////////////////////////
- void CManageGraphObject::RedrawAllObject(CDC* pDC)
- {
- LogicClientRect = GetLogicClientRect();
- RedrawLine(pDC);
- RedrawRect(pDC);
- RedrawCircle(pDC);
- RedrawArc(pDC);
- }
- void CManageGraphObject::SelectObject(CDC* pDC, CPoint point)
- {
- SelectLine(pDC, point);
- SelectRect(pDC, point);
- SelectCircle(pDC, point);
- SelectArc(pDC, point);
- }
- BOOL CManageGraphObject::UnselectObject()
- {
- BOOL flag = FALSE;
- int nIndex;
-
- if(UnselectLine())
- flag = TRUE;
- if(UnselectRect())
- flag = TRUE;
- if(UnselectCircle())
- flag = TRUE;
- if(UnselectArc())
- flag = TRUE;
-
- nIndex = m_SelObjInfoArray.GetSize();
- while(nIndex--)
- delete (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- m_SelObjInfoArray.RemoveAll();
- return flag;
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- CRect CManageGraphObject::GetLineRange(long ExtraRange, CMyLine* pLine)
- {
- CRect rect;
- POINT start;
- POINT end;
- start = DrawingToLogic(pLine->m_start);
- end = DrawingToLogic(pLine->m_end);
- rect.left = start.x;
- rect.top = start.y;
- rect.right = end.x;
- rect.bottom = end.y;
- //注意必须对矩形规格化
- rect.NormalizeRect();
- rect.left -= ExtraRange;
- rect.top -= ExtraRange;
- rect.right += ExtraRange;
- rect.bottom += ExtraRange;
-
- return rect;
- }
- void CManageGraphObject::RedrawLine(CDC* pDC)
- {
- int index;
- CRect rect;
- CMyLine* pLine;
- CGraphObjectInfo* pLineInfo;
- index = m_LineArray.GetSize();
- while(index--)
- {
- pLine = (CMyLine*)m_LineArray.GetAt(index);
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(index);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pLine->m_layer);
- if(!pLayer->IsShow())
- continue;
- //判断直线对象是否需要重画
- if(!IsRedraw(GetRedrawRect(EffectRect, LogicClientRect), pLineInfo->m_rect))
- continue;
- if(pLineInfo->m_del == TRUE)
- continue;
- if(pLineInfo->m_selected == TRUE)
- {
- m_DrawGrapObject.DrawSelLine(pDC, DrawingToLogic(pLine->m_start), DrawingToLogic(pLine->m_end),
- pLine->m_style, pLine->m_color);
- continue;
- }
-
- m_DrawGrapObject.DrawLine(pDC, DrawingToLogic(pLine->m_start), DrawingToLogic(pLine->m_end),
- pLine->m_style, pLine->m_color);
- }
- }
- void CManageGraphObject::SelectLine(CDC* pDC, CPoint point)
- {
- int nIndex;
- long distance;
- CRect rect;
-
- CGraphObjectInfo* pLineInfo;
- CSelectedObjectInfo* pSelObjInfo;
- CMyLine* pLine;
- for(nIndex = 0; nIndex < m_LineInfoArray.GetSize(); nIndex++)
- {
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(nIndex);
- pLine = (CMyLine*)m_LineArray.GetAt(nIndex);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pLine->m_layer);
- if(!pLayer->IsShow())
- continue;
- if(pLineInfo ->m_del == TRUE || pLineInfo ->m_selected ==TRUE)
- continue;
-
- //判断选取点是否在图形对象所占据的选取逻辑区域内
- CRect region = pLineInfo->m_rect;
- region.InflateRect(SELECT_RANGE, SELECT_RANGE);
- if(!region.PtInRect(point))
- continue;
- rect.left = DrawingToLogic(pLine->m_start).x;
- rect.top = DrawingToLogic(pLine->m_start).y;
- rect.right = DrawingToLogic(pLine->m_end).x;
- rect.bottom = DrawingToLogic(pLine->m_end).y;
- if( (point.x >= min(rect.left, rect.right) - SELECT_RANGE) && (point.x <= max(rect.left, rect.right) + SELECT_RANGE) &&
- (point.y >= min(rect.top, rect.bottom) - SELECT_RANGE) && (point.y <= max(rect.top, rect.bottom) + SELECT_RANGE) )
- {
- distance = (long)( abs( (rect.bottom - rect.top) * point.x - (rect.right - rect.left) * point.y + rect.top * (rect.right - rect.left) - rect.left * (rect.bottom - rect.top) )
- / sqrt( (rect.right - rect.left) * (rect.right - rect.left) + (rect.bottom - rect.top) * (rect.bottom - rect.top) ) );
- if(distance <= SELECT_RANGE)
- {
- m_DrawGrapObject.DrawSelLine(pDC, DrawingToLogic(pLine->m_start), DrawingToLogic(pLine->m_end),
- pLine->m_style, pLine->m_color);
- pLineInfo->m_selected = TRUE;
- pSelObjInfo = new CSelectedObjectInfo(OBJECT_LINE, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- }
- BOOL CManageGraphObject::UnselectLine()
- {
- BOOL flag = FALSE;
- int nIndex;
- CSelectedObjectInfo* pSelObjInfo;
- CGraphObjectInfo* pLineInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJECT_LINE)
- {
- pLineInfo = (CGraphObjectInfo*)m_LineInfoArray.GetAt(pSelObjInfo->m_index);
- pLineInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CManageGraphObject::AddLine(POINT SPoint, POINT EPoint, int Style, COLORREF Color)
- {
- FPOINT start;
- FPOINT end;
- start = LogicToDrawing(SPoint);
- end = LogicToDrawing(EPoint);
- CMyLine* pLine = new CMyLine(CurrentLayerName, start, end, Style, Color);
- m_LineArray.Add(pLine);
- CGraphObjectInfo* pLineInfo = new CGraphObjectInfo(GetLineRange(0, pLine), FALSE, FALSE);
- m_LineInfoArray.Add(pLineInfo);
- }
- CMyLine* CManageGraphObject::GetLine(int index)
- {
- ASSERT(index >= 0 && index <= m_LineArray.GetUpperBound());
- return (CMyLine*)m_LineArray.GetAt(index);
- }
- void CManageGraphObject::DelLine(int index)
- {
- ASSERT(index >= 0 && index <= m_LineArray.GetUpperBound());
- delete (CMyLine*)m_LineArray.GetAt(index);
- m_LineArray.RemoveAt(index);
- delete (CGraphObjectInfo*)m_LineInfoArray.GetAt(index);
- m_LineInfoArray.RemoveAt(index);
- }
- void CManageGraphObject::DelAllLine()
- {
- int index;
- index = m_LineArray.GetSize();
- while(index--)
- delete (CMyLine*)m_LineArray.GetAt(index);
- m_LineArray.RemoveAll();
-
- index = m_LineInfoArray.GetSize();
- while(index--)
- delete (CGraphObjectInfo*)m_LineInfoArray.GetAt(index);
- m_LineInfoArray.RemoveAll();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- CRect CManageGraphObject::GetRectRange(long ExtraRange, CMyRect* pRect)
- {
- CRect rect;
- POINT start;
- POINT end;
- start = DrawingToLogic(pRect->m_start);
- end = DrawingToLogic(pRect->m_end);
- rect.left = start.x;
- rect.top = start.y;
- rect.right = end.x;
- rect.bottom = end.y;
- //注意必须对矩形规格化
- rect.NormalizeRect();
- rect.left -= ExtraRange;
- rect.top -= ExtraRange;
- rect.right += ExtraRange;
- rect.bottom += ExtraRange;
- return rect;
- }
- void CManageGraphObject::RedrawRect(CDC* pDC)
- {
- int index;
- CMyRect* pRect;
- CGraphObjectInfo* pRectInfo;
- index = m_RectArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pRect = (CMyRect*)m_RectArray.GetAt(index);
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(index);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pRect->m_layer);
- if(!pLayer->IsShow())
- continue;
- //判断矩形对象是否需要重画
- if(!IsRedraw(GetRedrawRect(EffectRect, LogicClientRect), pRectInfo->m_rect))
- continue;
- if(pRectInfo->m_del == TRUE)
- continue;
- if(pRectInfo->m_selected == TRUE)
- {
- m_DrawGrapObject.DrawSelRect(pDC, DrawingToLogic(pRect->m_start), DrawingToLogic(pRect->m_end),
- pRect->m_style, pRect->m_color);
- continue;
- }
- m_DrawGrapObject.DrawRect(pDC, DrawingToLogic(pRect->m_start), DrawingToLogic(pRect->m_end),
- pRect->m_style, pRect->m_color);
-
- }
- }
- void CManageGraphObject::SelectRect(CDC* pDC, CPoint point)
- {
- int nIndex;
- CRect rect;
- CGraphObjectInfo* pRectInfo;
- CSelectedObjectInfo* pSelObjInfo;
- CMyRect* pRect;
- for(nIndex = 0; nIndex < m_RectInfoArray.GetSize(); nIndex++)
- {
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(nIndex);
- pRect = (CMyRect*)m_RectArray.GetAt(nIndex);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pRect->m_layer);
- if(!pLayer->IsShow())
- continue;
- if(pRectInfo ->m_del == TRUE || pRectInfo ->m_selected ==TRUE)
- continue;
- //判断选取点是否在图形对象所占据的选取逻辑区域内
- CRect region = pRectInfo->m_rect;
- region.InflateRect(SELECT_RANGE, SELECT_RANGE);
- if(!region.PtInRect(point))
- continue;
-
- rect.left = DrawingToLogic(pRect->m_start).x;
- rect.top = DrawingToLogic(pRect->m_start).y;
- rect.right = DrawingToLogic(pRect->m_end).x;
- rect.bottom = DrawingToLogic(pRect->m_end).y;
- if( ( (point.x >= min(rect.left, rect.right) - SELECT_RANGE) && (point.x <= max(rect.left, rect.right) + SELECT_RANGE) &&
- (point.y >= min(rect.top, rect.bottom) - SELECT_RANGE) && (point.y <= max(rect.top, rect.bottom) + SELECT_RANGE) ) &&
- ( (point.x <= min(rect.left, rect.right) + SELECT_RANGE) || (point.x >= max(rect.left, rect.right) - SELECT_RANGE) ||
- (point.y <= min(rect.top, rect.bottom) + SELECT_RANGE) || (point.y >= max(rect.top, rect.bottom) - SELECT_RANGE) ) )
- {
- m_DrawGrapObject.DrawSelRect(pDC, rect.TopLeft(), rect.BottomRight(),
- pRect->m_style, pRect->m_color);
- pRectInfo->m_selected = TRUE;
- pSelObjInfo = new CSelectedObjectInfo(OBJECT_RECT, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CManageGraphObject::UnselectRect()
- {
- BOOL flag = FALSE;
- int nIndex;
- CSelectedObjectInfo* pSelObjInfo;
- CGraphObjectInfo* pRectInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJECT_RECT)
- {
- pRectInfo = (CGraphObjectInfo*)m_RectInfoArray.GetAt(pSelObjInfo->m_index);
- pRectInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CManageGraphObject::AddRect(POINT SPoint, POINT EPoint, int Style, COLORREF Color)
- {
- FPOINT start;
- FPOINT end;
-
- start = LogicToDrawing(SPoint);
- end = LogicToDrawing(EPoint);
-
- CMyRect* pRect = new CMyRect(CurrentLayerName, start, end, Style, Color);
- m_RectArray.Add(pRect);
- CGraphObjectInfo * pRectInfo = new CGraphObjectInfo(GetRectRange(0, pRect), FALSE, FALSE);
- m_RectInfoArray.Add(pRectInfo);
- }
- CMyRect* CManageGraphObject::GetRect(int index)
- {
- ASSERT(index >= 0 && index <= m_RectArray.GetUpperBound());
- return (CMyRect*)m_RectArray.GetAt(index);
- }
- void CManageGraphObject::DelRect(int index)
- {
- ASSERT(index >= 0 && index <= m_RectArray.GetUpperBound());
- delete (CMyRect*)m_RectArray.GetAt(index);
- m_RectArray.RemoveAt(index);
- delete (CGraphObjectInfo*)m_RectInfoArray.GetAt(index);
- m_RectInfoArray.RemoveAt(index);
- }
- void CManageGraphObject::DelAllRect()
- {
- int index;
- index = m_RectArray.GetSize();
- while(index--)
- delete (CMyRect*)m_RectArray.GetAt(index);
- m_RectArray.RemoveAll();
- index = m_RectInfoArray.GetSize();
- while(index--)
- delete (CGraphObjectInfo*)m_RectInfoArray.GetAt(index);
- m_RectInfoArray.RemoveAll();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- CRect CManageGraphObject::GetCircleRange(long ExtraRange, CMyCircle* pCircle)
- {
- CRect rect;
- POINT origin;
- long Radius;
- origin = DrawingToLogic(pCircle->m_origin);
- Radius = DrawingToLogic(pCircle->m_radius);
- rect.left = origin.x - Radius - ExtraRange;
- rect.top = origin.y - Radius - ExtraRange;
- rect.right = origin.x + Radius + ExtraRange;
- rect.bottom = origin.y + Radius + ExtraRange;
- rect.NormalizeRect();
- return rect;
- }
- void CManageGraphObject::RedrawCircle(CDC* pDC)
- {
- int index;
- CMyCircle* pCircle;
- CGraphObjectInfo* pCircleInfo;
- index = m_CircleArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pCircle = (CMyCircle*)m_CircleArray.GetAt(index);
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(index);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pCircle->m_layer);
- if(!pLayer->IsShow())
- continue;
- //判断圆对象是否需要重画
- if(!IsRedraw(GetRedrawRect(EffectRect, LogicClientRect), pCircleInfo->m_rect))
- continue;
- if(pCircleInfo->m_del == TRUE)
- continue;
- if(pCircleInfo->m_selected == TRUE)
- {
- m_DrawGrapObject.DrawSelCircle(pDC, DrawingToLogic(pCircle->m_origin), DrawingToLogic(pCircle->m_radius),
- pCircle->m_style, pCircle->m_color);
- continue;
- }
- m_DrawGrapObject.DrawCircle(pDC, DrawingToLogic(pCircle->m_origin), DrawingToLogic(pCircle->m_radius),
- pCircle->m_style, pCircle->m_color);
- }
- }
- void CManageGraphObject::SelectCircle(CDC* pDC, CPoint point)
- {
- int nIndex;
- POINT origin;
- long r;
- long distance;
- CGraphObjectInfo* pCircleInfo;
- CSelectedObjectInfo* pSelObjInfo;
- CMyCircle* pCircle;
- for(nIndex = 0; nIndex < m_CircleInfoArray.GetSize(); nIndex++)
- {
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(nIndex);
- pCircle = (CMyCircle*)m_CircleArray.GetAt(nIndex);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pCircle->m_layer);
- if(!pLayer->IsShow())
- continue;
- if(pCircleInfo ->m_del == TRUE || pCircleInfo ->m_selected ==TRUE)
- continue;
- //判断选取点是否在图形对象所占据的选取逻辑区域内
- CRect region = pCircleInfo->m_rect;
- region.InflateRect(SELECT_RANGE, SELECT_RANGE);
- if(!region.PtInRect(point))
- continue;
- origin = DrawingToLogic(pCircle->m_origin);
- r = DrawingToLogic(pCircle->m_radius);
- distance = (long)sqrt( (origin.x - point.x) * (origin.x - point.x) + (origin.y - point.y) * (origin.y - point.y) );
- if(distance <= r + SELECT_RANGE && distance >= r - SELECT_RANGE)
- {
- m_DrawGrapObject.DrawSelCircle(pDC, DrawingToLogic(pCircle->m_origin), DrawingToLogic(pCircle->m_radius),
- pCircle->m_style, pCircle->m_color);
- pCircleInfo->m_selected = TRUE;
- pSelObjInfo = new CSelectedObjectInfo(OBJECT_CIRCLE, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CManageGraphObject::UnselectCircle()
- {
- BOOL flag = FALSE;
- int nIndex;
- CSelectedObjectInfo* pSelObjInfo;
- CGraphObjectInfo* pCircleInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJECT_CIRCLE)
- {
- pCircleInfo = (CGraphObjectInfo*)m_CircleInfoArray.GetAt(pSelObjInfo->m_index);
- pCircleInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CManageGraphObject::AddCircle(POINT SPoint, POINT EPoint, int Style, COLORREF Color)
- {
- FPOINT start;
- FPOINT end;
- float r;
-
- start = LogicToDrawing(SPoint);
- end = LogicToDrawing(EPoint);
- r = (float)sqrt(pow(start.x - end.x, 2) + pow(start.y - end.y, 2));
- CMyCircle* pCircle = new CMyCircle(CurrentLayerName, start, r, Style, Color);
- m_CircleArray.Add(pCircle);
- CGraphObjectInfo* pCircleInfo = new CGraphObjectInfo(GetCircleRange(0, pCircle), FALSE, FALSE);
- m_CircleInfoArray.Add(pCircleInfo);
- }
- CMyCircle* CManageGraphObject::GetCircle(int index)
- {
- ASSERT(index >= 0 && index <= m_CircleArray.GetUpperBound());
- return (CMyCircle*)m_CircleArray.GetAt(index);
- }
- void CManageGraphObject::DelCircle(int index)
- {
- ASSERT(index >= 0 && index <= m_CircleArray.GetUpperBound());
- delete (CMyCircle*)m_CircleArray.GetAt(index);
- m_CircleArray.RemoveAt(index);
- delete (CGraphObjectInfo*)m_CircleInfoArray.GetAt(index);
- m_CircleInfoArray.RemoveAt(index);
- }
- void CManageGraphObject::DelAllCircle()
- {
- int index;
- index = m_CircleArray.GetSize();
- while(index--)
- delete (CMyCircle*)m_CircleArray.GetAt(index);
- m_CircleArray.RemoveAll();
- index = m_CircleInfoArray.GetSize();
- while(index--)
- delete (CGraphObjectInfo*)m_CircleInfoArray.GetAt(index);
- m_CircleInfoArray.RemoveAll();
- }
- //////////////////////////////////////////////////////////////////////////////////////////////
- CRect CManageGraphObject::GetArcRange(long ExtraRange, CMyArc* pArc)
- {
- CRect rect;
- POINT origin;
- long Radius;
- origin = DrawingToLogic(pArc->m_origin);
- Radius = DrawingToLogic(pArc->m_radius);
- rect.left = origin.x - Radius - ExtraRange;
- rect.top = origin.y - Radius - ExtraRange;
- rect.right = origin.x + Radius + ExtraRange;
- rect.bottom = origin.y + Radius + ExtraRange;
- rect.NormalizeRect();
- return rect;
- }
- void CManageGraphObject::RedrawArc(CDC* pDC)
- {
- int index;
- CMyArc* pArc;
- CGraphObjectInfo* pArcInfo;
- index = m_ArcArray.GetSize();
- //设置不填充状态
- pDC->SelectStockObject(NULL_BRUSH);
- while(index--)
- {
- pArc = (CMyArc*)m_ArcArray.GetAt(index);
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(index);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pArc->m_layer);
- if(!pLayer->IsShow())
- continue;
- //判断圆弧对象是否需要重画
- if(!IsRedraw(GetRedrawRect(EffectRect, LogicClientRect), pArcInfo->m_rect))
- continue;
- if(pArcInfo->m_del == TRUE)
- continue;
- if(pArcInfo->m_selected == TRUE)
- {
- m_DrawGrapObject.DrawSelArc(pDC, DrawingToLogic(pArc->m_origin), DrawingToLogic(pArc->m_start),
- DrawingToLogic(pArc->m_end),
- DrawingToLogic(pArc->m_radius), LineStyle, PenColor);
- continue;
- }
-
-
- m_DrawGrapObject.DrawArc(pDC, DrawingToLogic(pArc->m_origin),
- DrawingToLogic(pArc->m_start), DrawingToLogic(pArc->m_end),
- DrawingToLogic(pArc->m_radius), pArc->m_style, pArc->m_color);
- }
- }
- void CManageGraphObject::SelectArc(CDC* pDC, CPoint point)
- {
- int nIndex;
- POINT origin;
- long r;
- long distance;
- CPoint start;
- CPoint end;
- CGraphObjectInfo* pArcInfo;
- CSelectedObjectInfo* pSelObjInfo;
- CMyArc* pArc;
- for(nIndex = 0; nIndex < m_ArcInfoArray.GetSize(); nIndex++)
- {
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(nIndex);
- pArc = (CMyArc*)m_ArcArray.GetAt(nIndex);
- //判断图形对象所在层是否被隐藏
- CFileLayer* pLayer = pManageLayer->GetLayer(pArc->m_layer);
- if(!pLayer->IsShow())
- continue;
- if(pArcInfo ->m_del == TRUE || pArcInfo ->m_selected ==TRUE)
- continue;
- //判断选取点是否在图形对象所占据的选取逻辑区域内
- CRect region = pArcInfo->m_rect;
- region.InflateRect(SELECT_RANGE, SELECT_RANGE);
- if(!region.PtInRect(point))
- continue;
- origin = DrawingToLogic(pArc->m_origin);
- start = DrawingToLogic(pArc->m_start);
- end = DrawingToLogic(pArc->m_end);
- r = DrawingToLogic(pArc->m_radius);
- distance = (long)sqrt( (origin.x - point.x) * (origin.x - point.x) + (origin.y - point.y) * (origin.y - point.y) );
- if(distance <= r + SELECT_RANGE && distance >= r - SELECT_RANGE)
- {
- m_DrawGrapObject.DrawSelArc(pDC, origin, start, end, r, pArc->m_style, pArc->m_color);
- pArcInfo->m_selected = TRUE;
- pSelObjInfo = new CSelectedObjectInfo(OBJECT_ARC, nIndex);
- m_SelObjInfoArray.Add(pSelObjInfo);
- }
- }
- }
- BOOL CManageGraphObject::UnselectArc()
- {
- BOOL flag = FALSE;
- int nIndex;
- CSelectedObjectInfo* pSelObjInfo;
- CGraphObjectInfo* pArcInfo;
- for(nIndex = 0; nIndex < m_SelObjInfoArray.GetSize(); nIndex++)
- {
- pSelObjInfo = (CSelectedObjectInfo*)m_SelObjInfoArray.GetAt(nIndex);
- if(pSelObjInfo->m_type ==OBJECT_ARC)
- {
- pArcInfo = (CGraphObjectInfo*)m_ArcInfoArray.GetAt(pSelObjInfo->m_index);
- pArcInfo->m_selected = FALSE;
- flag = TRUE;
- }
- }
- return flag;
- }
- void CManageGraphObject::AddArc(POINT SPoint, POINT MPoint, POINT EPoint, int Style, COLORREF Color)
- {
- long x1, y1, x2, y2;
- double originX;
- double originY;
- double k1;
- double k2;
- double mid1X;
- double mid1Y;
- double mid2X;
- double mid2Y;
- POINT OPoint;
- long Radius;
- CMyArc* pArc;
-
- if(SPoint.y == MPoint.y)
- k1 = 1000000.0;
- else
- k1 = (- (double)(SPoint.x - MPoint.x) / (double)(SPoint.y - MPoint.y));
- if(EPoint.y == MPoint.y)
- k2 = 1000000.0;
- else
- k2 = (- (double)(EPoint.x - MPoint.x) / (double)(EPoint.y - MPoint.y));
- mid1X = (double)(SPoint.x + MPoint.x) / 2.0;
- mid1Y = (double)(SPoint.y + MPoint.y) / 2.0;
- mid2X = (double)(EPoint.x + MPoint.x) / 2.0;
- mid2Y = (double)(EPoint.y + MPoint.y) / 2.0;
- if(k1 == k2)
- return;
-
- if(k1 == 1000000.0)
- {
- originX = mid1X;
- originY = k2 * (originX - mid2X) + mid2Y;
- }
- else
- if(k2 == 1000000.0)
- {
- originX = mid2X;
- originY = k1 * (originX - mid1X) + mid1Y;
- }
- else
- {
- originX = ((k2 * mid2X - k1 * mid1X) - (mid2Y - mid1Y)) / (k2 - k1);
- originY = k2 * (originX - mid2X) + mid2Y;
- }
- Radius = (long)sqrt(pow((double)(originX - SPoint.x), 2) + pow((double)(originY - SPoint.y), 2));
- OPoint.x = (long)originX;
- OPoint.y = (long)originY ;
- x1 = MidPoint.x - SPoint.x;
- y1 = MPoint.y - SPoint.y;
- x2 = EPoint.x - SPoint.x;
- y2 = EPoint.y - SPoint.y;
- if(x1*y2 - x2*y1 < 0)
- pArc = new CMyArc(CurrentLayerName, LogicToDrawing(OPoint),
- LogicToDrawing(SPoint), LogicToDrawing(EPoint),
- LogicToDrawing(Radius), LineStyle, PenColor);
- else
- pArc = new CMyArc(CurrentLayerName, LogicToDrawing(OPoint),
- LogicToDrawing(EPoint), LogicToDrawing(SPoint),
- LogicToDrawing(Radius), LineStyle, PenColor);
-
- m_ArcArray.Add(pArc);
- CGraphObjectInfo* pArcInfo = new CGraphObjectInfo(GetArcRange(0, pArc), FALSE, FALSE);
- m_ArcInfoArray.Add(pArcInfo);
- }
- CMyArc* CManageGraphObject::GetArc(int index)
- {
- ASSERT(index >= 0 && index <= m_ArcArray.GetUpperBound());
- return (CMyArc*)m_ArcArray.GetAt(index);
- }
- void CManageGraphObject::DelArc(int index)
- {
- ASSERT(index >= 0 && index <= m_ArcArray.GetUpperBound());
- delete (CMyArc*)m_ArcArray.GetAt(index);
- m_ArcArray.RemoveAt(index);
- delete (CGraphObjectInfo*)m_ArcInfoArray.GetAt(index);
- m_ArcInfoArray.RemoveAt(index);
- }
- void CManageGraphObject::DelAllArc()
- {
- int index;
- index = m_ArcArray.GetSize();
- while(index--)
- delete (CMyArc*)m_ArcArray.GetAt(index);
- m_ArcArray.RemoveAll();
- index = m_ArcInfoArray.GetSize();
- while(index--)
- delete (CGraphObjectInfo*)m_ArcInfoArray.GetAt(index);
- m_ArcInfoArray.RemoveAll();
- }