📄 drawobj.cpp
字号:
{
ASSERT_VALID(this);
CDrawObj::Serialize(ar);
if (ar.IsStoring())
{
ar << (WORD) m_nShape;
//父对象的变量 ******************************
ar << m_position;
ar << m_bBrush;
ar << (WORD) m_DShape;
ar << m_sWellNO;
ar << m_sXCH;
ar << m_cSubList;
ar << m_PosIndex;
ar << m_sJoinPNO;
ar << m_sJoin2xch;
// ar << m_sSubXch;
ar << m_fontsize;
ar << m_text;
// ar << m_iArray;
// ar << m_iHorVer;
ar << m_bPen;
//ar << m_logpen;
//ar << m_logbrush;
ar << g_fZoom;
//******************************
m_ArrText.Serialize(ar);
//for(i=0;i<m_nTextSize;i++)
// ar << m_ArrText[i];
}
else
{
WORD wTemp;
CString sTemp;
ar >> wTemp; m_nShape = (Shape)wTemp;
//父对象的变量 ******************************
ar >> m_position;
ar >> m_bBrush;
ar >> wTemp; m_DShape = (DrawShape)wTemp;
ar >> m_sWellNO;
ar >> m_sXCH;
ar >> m_cSubList;
ar >> m_PosIndex;
ar >> m_sJoinPNO;
ar >> m_sJoin2xch;
// ar >> m_sSubXch;
ar >> m_fontsize;
ar >> m_text;
// ar >> m_iArray;
// ar >> m_iHorVer;
ar >> m_bPen;
//ar >> m_logpen;
//ar >> m_logbrush;
ar >> g_fZoom;
//******************************
m_ArrText.Serialize(ar);
}
/* if (ar.IsStoring())
{
ar << (WORD) m_nShape;
ar << m_roundness;
ar << m_fontsize;
ar << m_text;
m_ArrText.Serialize(ar);
ar << g_fZoom;
}
else
{
WORD wTemp;
CString sTemp;
ar >> wTemp; m_nShape = (Shape)wTemp;
ar >> m_roundness;
ar >> m_fontsize;
ar >> m_text;
m_ArrText.Serialize(ar);
ar >> g_fZoom;
}*/
}
void CDrawRect::Draw(CDC* pDC)
{
ASSERT_VALID(this);
// m_logpen.lopnWidth.x = 0;
// m_logpen.lopnWidth.y = 0;
CBrush brush;
if (!brush.CreateBrushIndirect(&m_logbrush))
return;
CPen pen;
if (!pen.CreatePenIndirect(&m_logpen))
return;
CBrush* pOldBrush;
CPen* pOldPen;
CFont* def_font;
CFont font;
VERIFY(font.CreateFont(
m_fontsize, // nHeight
0, // nWidth
0, // nEscapement
0, // nOrientation
FW_NORMAL, // nWeight
FALSE, // bItalic
FALSE, // bUnderline
0, // cStrikeOut
ANSI_CHARSET, // nCharSet
OUT_DEFAULT_PRECIS, // nOutPrecision
CLIP_DEFAULT_PRECIS, // nClipPrecision
DEFAULT_QUALITY, // nQuality
DEFAULT_PITCH | FF_SWISS, // nPitchAndFamily
"Arial")); // lpszFacename
if (m_bBrush)
pOldBrush = pDC->SelectObject(&brush);
else
pOldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH);
//m_bPen = FALSE;
if (m_bPen && recttext != m_nShape)
pOldPen = pDC->SelectObject(&pen);
else
pOldPen = (CPen*)pDC->SelectStockObject(NULL_PEN);
int itmp;
CRect rect = m_position;
switch (m_nShape)
{
case rectangle:
pDC->Rectangle(rect);
//pDC->TextOut(rect.left,rect.top,"RectTestWord");
break;
case roundRectangle:
pDC->RoundRect(rect, m_roundness);
break;
case ellipse:
pDC->Ellipse(rect);
break;
case fault_line:
case line:
if (rect.top > rect.bottom)
{
rect.top -= m_logpen.lopnWidth.y / 2;
rect.bottom += (m_logpen.lopnWidth.y + 1) / 2;
}
else
{
rect.top += (m_logpen.lopnWidth.y + 1) / 2;
rect.bottom -= m_logpen.lopnWidth.y / 2;
}
if (rect.left > rect.right)
{
rect.left -= m_logpen.lopnWidth.x / 2;
rect.right += (m_logpen.lopnWidth.x + 1) / 2;
}
else
{
rect.left += (m_logpen.lopnWidth.x + 1) / 2;
rect.right -= m_logpen.lopnWidth.x / 2;
}
pDC->MoveTo(rect.TopLeft());
pDC->LineTo(rect.BottomRight());
break;
case text: //hjq 2006-11
//pDC->GetTextMetrics(&TextM);
//nCharHeight = (unsigned short)TextM.tmHeight;
//nCharWidth = (unsigned short)TextM.tmAveCharWidth;
//itmp = m_text.GetLength();
//if (itmp <= 10) itmp=10;
//rect.right = rect.left+itmp*8;
//rect.bottom = rect.top + 15;
m_position = rect;
//itmp = rect.CenterPoint().x-15;
pDC->TextOut(rect.CenterPoint().x-25,rect.top +15, m_text);
break;
case vtext:
def_font = pDC->SelectObject(&font);
pDC->SetBkMode(TRANSPARENT);
pDC->DrawText(m_text,rect,DT_WORDBREAK);
pDC->SelectObject(def_font);
font.DeleteObject();
break;
case recttext:
// Do something with the font just created...
def_font = pDC->SelectObject(&font);
//pDC->Rectangle(rect.left,rect.top,rect.right+1,rect.bottom-2); //划层矩形框
pDC->SelectObject(&pen); //矩形不带线,下面再加上线
pDC->MoveTo(rect.left,rect.top);
pDC->LineTo(rect.right,rect.top);
pDC->MoveTo(rect.left,rect.bottom);
pDC->LineTo(rect.right,rect.bottom);
int itmp1; //临时变量
// int itmpx1,itmpx2; //划线用X1 X2
// itmpx1 = itmpx2 = rect.left + (int)(50*g_fZoom); //是垂直线
// pDC->MoveTo(itmpx1,rect.top); //
// pDC->LineTo(itmpx2,rect.bottom); //划线
//itmp = (int)((rect.bottom - rect.top)/2);
itmp = m_ArrText.GetSize();
itmp1 = (rect.bottom-rect.top);
//计算文字写的位置
TEXTMETRIC TextM;
pDC->GetTextMetrics(&TextM);
//字体高度 //字体平均宽度
int nCharHeight = (unsigned short)TextM.tmHeight;
//int nCharWidth=(unsigned short)TextM.tmAveCharWidth;
//if (abs(itmp1) >30*g_fZoom)
//itmp1 = rect.top + (rect.bottom+rect.top)/2;
itmp1 = (rect.bottom+rect.top+ nCharHeight )/2 ;
//else
// itmp1 = rect.top;
for(int i=0; i<itmp; i++)
{
pDC->SetBkMode(TRANSPARENT); //文字无背景
pDC->TextOut(rect.left + (int)(i*52*g_fZoom),itmp1 , m_ArrText[i]); //
}
pDC->SelectObject(def_font);
font.DeleteObject();
break;
}
pDC->SelectObject(pOldBrush);
pDC->SelectObject(pOldPen);
}
int CDrawRect::GetHandleCount()
{
ASSERT_VALID(this);
return m_nShape == line || m_nShape == fault_line ? 2 :
CDrawObj::GetHandleCount() + (m_nShape == roundRectangle);
}
// returns center of handle in logical coordinates
CPoint CDrawRect::GetHandle(int nHandle)
{
ASSERT_VALID(this);
if ((m_nShape == line || m_nShape == fault_line ) && nHandle == 2)
nHandle = 5;
else if (m_nShape == roundRectangle && nHandle == 9)
{
CRect rect = m_position;
rect.NormalizeRect();
CPoint point = rect.BottomRight();
point.x -= m_roundness.x / 2;
point.y -= m_roundness.y / 2;
return point;
}
return CDrawObj::GetHandle(nHandle);
}
HCURSOR CDrawRect::GetHandleCursor(int nHandle)
{
ASSERT_VALID(this);
if ((m_nShape == line || m_nShape == fault_line ) && nHandle == 2)
nHandle = 5;
else if (m_nShape == roundRectangle && nHandle == 9)
return AfxGetApp()->LoadStandardCursor(IDC_SIZEALL);
return CDrawObj::GetHandleCursor(nHandle);
}
// point is in logical coordinates
void CDrawRect::MoveHandleTo(int nHandle, CPoint point, CDrawView* pView)
{
ASSERT_VALID(this);
if ((m_nShape == line || m_nShape == fault_line) && nHandle == 2)
nHandle = 5;
else if (m_nShape == roundRectangle && nHandle == 9)
{
CRect rect = m_position;
rect.NormalizeRect();
if (point.x > rect.right - 1)
point.x = rect.right - 1;
else if (point.x < rect.left + rect.Width() / 2)
point.x = rect.left + rect.Width() / 2;
if (point.y > rect.bottom - 1)
point.y = rect.bottom - 1;
else if (point.y < rect.top + rect.Height() / 2)
point.y = rect.top + rect.Height() / 2;
m_roundness.x = 2 * (rect.right - point.x);
m_roundness.y = 2 * (rect.bottom - point.y);
m_pDocument->SetModifiedFlag();
if (pView == NULL)
Invalidate();
else
pView->InvalObj(this);
return;
}
CDrawObj::MoveHandleTo(nHandle, point, pView);
}
// rect must be in logical coordinates
BOOL CDrawRect::Intersects(const CRect& rect)
{
ASSERT_VALID(this);
CRect rectT = rect;
rectT.NormalizeRect();
CRect fixed = m_position;
fixed.NormalizeRect();
if (line != m_nShape && fault_line != m_nShape) //直线,其选择方式判断与其它的不一样
{
if ((rectT & fixed).IsRectEmpty())
return FALSE;
}
else
{
rectT.right += MIN_DISTANCE * 2;
rectT.bottom += MIN_DISTANCE * 2;
rectT.OffsetRect(-MIN_DISTANCE ,-MIN_DISTANCE );
if ((rectT & fixed).IsRectEmpty()) return FALSE;
CPoint po;
po.x = rect.left;
po.y = rect.top;
CPoint* points1 = new CPoint[2];
points1[0].x = m_position.left;
points1[0].y = m_position.top;
points1[1].x = m_position.right;
points1[1].y = m_position.bottom;
//return isVCrossAtLine(po,points1,2,*smin,*ipos,*x0,*y0);
return isVCrossAtLine(po,points1,2);
}
CRgn rgn;
switch (m_nShape)
{
case rectangle:
return TRUE;
case roundRectangle:
rgn.CreateRoundRectRgn(fixed.left, fixed.top, fixed.right, fixed.bottom,
m_roundness.x, m_roundness.y);
break;
case ellipse:
rgn.CreateEllipticRgnIndirect(fixed);
break;
/*
case line:
{
int x = (m_logpen.lopnWidth.x + 5) / 2;
int y = (m_logpen.lopnWidth.y + 5) / 2;
POINT points[4];
points[0].x = fixed.left;
points[0].y = fixed.top;
points[1].x = fixed.left;
points[1].y = fixed.top;
points[2].x = fixed.right;
points[2].y = fixed.bottom;
points[3].x = fixed.right;
points[3].y = fixed.bottom;
if (fixed.left < fixed.right)
{
points[0].x -= x;
points[1].x += x;
points[2].x += x;
points[3].x -= x;
}
else
{
points[0].x += x;
points[1].x -= x;
points[2].x -= x;
points[3].x += x;
}
if (fixed.top < fixed.bottom)
{
points[0].y -= y;
points[1].y += y;
points[2].y += y;
points[3].y -= y;
}
else
{
points[0].y += y;
points[1].y -= y;
points[2].y -= y;
points[3].y += y;
}
rgn.CreatePolygonRgn(points, 4, ALTERNATE);
}
break;
*/
case vtext:
case text: //hjq 2006-11
return FALSE;
//break;
case recttext:
return TRUE;
//break;
}
return rgn.RectInRegion(fixed);
}
CDrawObj* CDrawRect::Clone(CDrawDoc* pDoc)
{
ASSERT_VALID(this);
CDrawRect* pClone = new CDrawRect(m_position);
pClone->m_bPen = m_bPen;
pClone->m_logpen = m_logpen;
pClone->m_bBrush = m_bBrush;
pClone->m_logbrush = m_logbrush;
pClone->m_nShape = m_nShape;
pClone->m_roundness = m_roundness;
ASSERT_VALID(pClone);
if (pDoc != NULL)
pDoc->Add(pClone);
ASSERT_VALID(pClone);
return pClone;
}
////////////////////////////////////////////////////////////////////////////
// CDrawPoly
IMPLEMENT_SERIAL(CDrawPoly, CDrawObj, 0)
CDrawPoly::CDrawPoly()
{
m_points = NULL;
m_nPoints = 0;
m_nAllocPoints = 0;
}
CDrawPoly::CDrawPoly(const CRect& position)
: CDrawObj(position)
{
m_points = NULL;
m_nPoints = 0;
m_nAllocPoints = 0;
m_bPen = TRUE;
m_bBrush = FALSE;
}
CDrawPoly::CDrawPoly(DrawShape _Shape, const CRect &position, CString pWellNO)
: CDrawObj(position)
{
switch (_Shape)
{
case ::poly:
m_nShape = CDrawPoly::poly;
break;
case ::poly_line:
m_nShape = CDrawPoly::poly_line;
break;
case ::polyFault:
m_nShape = CDrawPoly::polyFault;
break;
case ::polylink:
m_nShape = CDrawPoly::polylink;
break;
default:
ASSERT(FALSE); // unsuported shape!
}
m_DShape = _Shape ;
m_points = NULL;
m_nPoints = 0;
m_nAllocPoints = 0;
m_bPen = TRUE;
m_bBrush = TRUE;
m_sWellNO = pWellNO;
m_bLinkPic = TRUE;
}
CDrawPoly::~CDrawPoly()
{
if (m_points != NULL)
delete[] m_points;
}
void CDrawPoly::Serialize( CArchive& ar )
{
int i;
CDrawObj::Serialize( ar );
if( ar.IsStoring() )
{
ar << (WORD) m_nShape;
ar << (WORD) m_nPoints;
ar << (WORD) m_nAllocPoints;
//父对象的变量 ******************************
ar << m_position;
ar << m_bBrush;
ar << (WORD) m_DShape;
ar << m_sWellNO;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -