现在的位置: 首页 > 综合 > 正文

(3)一步一步开发一个简单CAD之画线

2013年06月07日 ⁄ 综合 ⁄ 共 1528字 ⁄ 字号 评论关闭

(1)为了画线,则必需有一个存储实体的内存,同时为了实现捡选的功能,还必需存储一个捡选用的内存区

用以下两个模版类实现,做为文档类的成员函数

public://设定两个集合,选择集和实体集,同一个图形要么在选择集,要么在实体集
  CTypedPtrArray<CObArray, CSolid*>m_solid;
  CTypedPtrArray<CObArray, CSolid*>m_select;

 

各种命令实际上是对这两个类的操作

(2)为了画线,必需一个画线的命令类如下

 

class CCreateLine : public CComand
{
public:
 CCreateLine();
 virtual ~CCreateLine();
public:

    void OnLButtonDown(UINT nFlags,  CPosition pos);
    void OnMouseMove(UINT nFlags,  CPosition pos);
    void OnRButtonDown(UINT nFlags,  CPosition pos);

 
private:
    CPosition m_begin;
 CPosition m_end;
 CEraseLine m_erase_line;//这个是像皮筋类

};

 

CCreateLine::CCreateLine()
{
    m_nStep = 1;
 c_Refresh = g_Refresh;

}

CCreateLine::~CCreateLine()
{

}

void CCreateLine::OnLButtonDown(UINT nFlags,  CPosition pos)
{

 
   switch(m_nStep)
   {
 
   case 1://输出提示信息
   {
    
     CPosition center = pos;
      g_pDoc->DrawFlag(TRUE, pos, &center);//画标记,这个是为了实现捕捉功能
 
     m_end = m_begin = center;
 

    m_nStep++;
     m_erase_line.SetBegin(pos); //八个方向,并且如果在指定范围内,得到按下的点的坐标.实现像皮筋类
     break;
    
   }
    
    case 2:
   {

   CPosition center2 = pos;
    g_pDoc->DrawFlag(TRUE, pos, &center2);//画标记作用,画出矩形标记,center2取出替代值
   
   m_erase_line.SetBegin(pos);
         CDC *pDC = g_pView->GetDC();
       CLine *line = new CLine(m_begin, center2);
         line->DrawSolid(pDC, Normal);
         g_pDoc->m_solid.Add(line);
         m_nStep = 1;
       g_pView->ReleaseDC(pDC);

  }
   default:
      break;
  }
 
  
}

void CCreateLine::OnMouseMove(UINT nFlags,  CPosition pos)
{

    CPosition center2;
     g_pDoc->DrawFlag(TRUE, pos, &center2);
    m_erase_line.SetEnd(pos);

   
}

void CCreateLine::OnRButtonDown(UINT nFlags,  CPosition pos)
{

 m_erase_line.SetCancle(pos);//取消像皮筋
}

抱歉!评论已关闭.