📄 zhongxinobj.cpp
字号:
#include "StdAfx.h"
#include ".\zhongxinobj.h"
#using <mscorlib.dll>
#include "visdrawview.h"
#include "visdrawdoc.h"
//#include <math.h>
IMPLEMENT_SERIAL(CZhongxinObj, CFigureObj, 0)
CZhongxinObj::CZhongxinObj(void)
{
}
CZhongxinObj::~CZhongxinObj(void)
{
}
CZhongxinObj::CZhongxinObj(DrawObj drawObj)
: CFigureObj(drawObj)
{
pToolObj = NULL;
}
CZhongxinObj::CZhongxinObj(const CRect& position)
: CFigureObj(position)
{
ASSERT_VALID(this);
// m_picID=0;
m_pointx = 0.0;
m_pointy = 0.0;
m_ltx=m_lty=m_rbx=m_rby=0.0;
}
void CZhongxinObj::Draw(CVisDrawView* pView,CDC* pDC)
{
ASSERT_VALID(this);
//CPoint nPoint;
//pView->WorldToClient(nPoint,m_pointx,m_pointy);
//把世界坐标转化为逻辑坐标
CPoint m_ltPoint, m_rbPoint;
CRect rect = CalcBounds(pView);
//nPoint.x=rect.TopLeft().x;
//nPoint.x=rect.TopLeft().y;
m_pic=pView->m_picIDjia;
bitmap.LoadBitmap(m_pic);
CDC dcComp;
dcComp.CreateCompatibleDC(pDC);
dcComp.SelectObject(&bitmap);
BITMAP bmInfo;
bitmap.GetObject(sizeof(bmInfo),&bmInfo);
pDC->BitBlt(rect.TopLeft().x,rect.TopLeft().y,bmInfo.bmWidth,bmInfo.bmHeight, &dcComp, 0,0,SRCCOPY);
//pDC->SelectObject()
//m_width=bmInfo.bmWidth;
//m_height=bmInfo.bmHeight;
/*
m_RectTracker.m_rect=m_RectLP;
pDC->LPtoDP(m_RectTracker.m_rect);
if(IsSelected())m_RectTracker.Draw(pDC);
*/
bitmap.DeleteObject();
}
void CZhongxinObj::Serialize(CArchive& ar)
{
ASSERT_VALID(this);
//调用基类串行化
CFigureObj::Serialize(ar);
if (ar.IsStoring())
{
ar << m_ltx << m_lty << m_rbx << m_rby;
}
else
{
ar >> m_ltx >> m_lty >> m_rbx >> m_rby;
}
}
//设定直线端点坐标,为世界坐标
void CZhongxinObj::SetPoint(int ptNumber, double x, double y)
{
ASSERT(ptNumber <=2);
switch(ptNumber)
{
case 1:
m_ltx = x;
m_lty = y;
break;
case 2:
m_rbx = x;
m_rby = y;
break;
}
}
//返回直线端点的世界坐标
void CZhongxinObj::GetPoint(int ptNumber, double& x, double& y)
{
ASSERT(ptNumber <=2);
switch(ptNumber)
{
case 1:
x = m_ltx;
y = m_lty;
break;
case 2:
x = m_rbx;
y = m_rby;
break;
}
}
/*
void CCheObj::SetPoint(double pointx, double pointy)
{
m_pointx = pointx;
m_pointy = pointy;
}
void CCheObj::GetPoint(double& pointx, double& pointy)
{
pointx = m_pointx;
pointy = m_pointy;
}
*/
/*//计算外接矩形,以逻辑坐标表示
CRect CCheObj::CalcBounds(CVisDrawView* pView)
{
CPoint nPoint;
pView->WorldToClient(nPoint,m_pointx,m_pointy);
rect.TopLeft()=nPoint;
rect.BottomRight().x=nPoint.x+m_width;
rect.BottomRight().y=nPoint.y+m_height;
//return rect;
//m_Rect.left = pt->x;
//m_Rect.top = pt->y;
//m_Rect.right = m_Rect.left +2000; //+100;
//m_Rect.bottom = m_Rect.top -1000; //+60;
//m_RectLP = rect;
//m_RectTracker.m_rect = rect;
//m_RectTracker.m_nStyle = CRectTracker::resizeOutside;
//m_RectTracker.Draw(pDC);
m_position = rect;
return m_position;
//}
}
*/
//计算外接矩形,以逻辑坐标表示
CRect CZhongxinObj::CalcBounds(CVisDrawView* pView)
{
CRect rect;
CPoint ltPoint, rbPoint;
pView->WorldToClient(ltPoint,m_ltx,m_lty);
pView->WorldToClient(rbPoint,m_rbx,m_rby);
rect.TopLeft() = ltPoint;
rect.BottomRight() = rbPoint;
m_position = rect;
return rect;
}
/*
double CCheObj::PointToLine(CPoint nStartPt,CPoint nEndPt, CPoint pt)
{
int A,B,C;
double distance;
//计算直线参数
A = nStartPt.y - nEndPt.y;
B = nEndPt.x - nStartPt.x;
C = nStartPt.x*nEndPt.y - nEndPt.x*nStartPt.y;
//计算点到直线距离
distance = (A*pt.x + B*pt.y + C)*(A*pt.x + B*pt.y + C)/(A*A + B*B);
distance = sqrt(distance);
return distance;
}
*/
BOOL CZhongxinObj::IsSelected(CVisDrawView* pView, const CPoint& point)
{
CPoint local, StartPt, EndPt;
//参数point是鼠标的逻辑坐标
int distance, nSelectDistance;
CRect rect = m_position;
//CPoint local;
local = point;
//鼠标点的设备坐标
pView->DocToClient(rect);
//识别精度值
nSelectDistance = pView->GetDocument()->GetSetectDistance()/2;
//鼠标点的设备坐标
pView->DocToClient(local);
//CPoint pt;
//把点的坐标转化为逻辑坐标
//pView->WorldToClient(pt, m_pointx, m_pointy);
//把点的坐标由逻辑坐标转化为设备坐标
//pView->DocToClient(pt);
//计算鼠标点point与点pt之间的像素距离
//第一条直线
distance = abs(local.y - rect.top);
if(distance < nSelectDistance) return true;
//第二条直线
distance = abs(local.x - rect.right);
if(distance < nSelectDistance) return true;
//第三条直线
distance = abs(local.y - rect.bottom);
if(distance < nSelectDistance) return true;
//第四条直线
distance = abs(local.x - rect.left);
if(distance < nSelectDistance) return true;
//根据拾取条件判断图元是否被拾取
//return (distance < nSelectDistance);
return false;
}
//返回手柄个数
int CZhongxinObj::GetHandleCount()
{
ASSERT_VALID(this);
return 9;
}
// 返回手柄中心逻辑坐标
CPoint CZhongxinObj::GetHandle(CVisDrawView* pView, int nHandle)
{
ASSERT_VALID(this);
return CFigureObj::GetHandle(pView, nHandle);
}
// delta为逻辑坐标
void CZhongxinObj::MoveTo(CPoint delta, CVisDrawView* pView)
{
ASSERT_VALID(this);
//把delta转化为世界坐标
double pointx,pointy;
pointx = pView->ClientToWorld(delta.x);
pointy = -pView->ClientToWorld(delta.y);
//修改矩形两顶点坐标
m_ltx = m_ltx + pointx;
m_lty = m_lty + pointy;
m_rbx = m_rbx + pointx;
m_rby = m_rby + pointy;
//重新计算边界矩形
CalcBounds(pView);
//修改文档标志
m_pDocument->SetModifiedFlag();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -