You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
158 lines
3.1 KiB
C++
158 lines
3.1 KiB
C++
#include "StdAfx.h"
|
|
#include "itembkgrid.h"
|
|
#include "SigmaDoc.h"
|
|
#include "SigmaView.h"
|
|
|
|
CItemBkGrid::CItemBkGrid(CSigmaDoc* ppDoc)
|
|
: CItem(ppDoc)
|
|
{
|
|
this->SetType(ITEM_BK_GRID);
|
|
}
|
|
|
|
CItemBkGrid::~CItemBkGrid(void)
|
|
{
|
|
}
|
|
|
|
double CItemBkGrid::GetGridRX(long x)
|
|
{
|
|
double stepX = GetView()->GridStepX;
|
|
double dd = GetDC()->GetRX(x);
|
|
if(AfxGetPublicFunction()->IsZero(stepX)) return dd;
|
|
|
|
double m;
|
|
|
|
if(dd > 0)
|
|
dd += stepX*0.5;
|
|
else if(dd < 0)
|
|
dd-= stepX*0.5;
|
|
m=fmod(dd,stepX);
|
|
return dd-m;
|
|
}
|
|
|
|
double CItemBkGrid::GetGridRY(long y)
|
|
{
|
|
double stepY = GetView()->GridStepY;
|
|
double dd = GetDC()->GetRY(y);
|
|
if(AfxGetPublicFunction()->IsZero(stepY)) return dd;
|
|
|
|
double n;
|
|
if(dd > 0) dd += stepY*0.5;
|
|
else if(dd < 0) dd-= stepY*0.5;
|
|
n=fmod(dd,stepY);
|
|
return dd-n;
|
|
}
|
|
|
|
void CItemBkGrid::GetGridPoint(CPoint &point)
|
|
{
|
|
if(point.x==0 && point.y==0) return;
|
|
|
|
double stepX = GetView()->GridStepX;
|
|
double stepY = GetView()->GridStepY;
|
|
|
|
if(AfxGetPublicFunction()->IsZero(stepX) || AfxGetPublicFunction()->IsZero(stepY)) return;
|
|
|
|
double x = GetDC()->GetRX(point.x);
|
|
double y = GetDC()->GetRY(point.y);
|
|
|
|
double v;
|
|
if(point.x != 0)
|
|
{
|
|
if(x > 0) x += stepX*0.5;
|
|
else if(x < 0) x-= stepX*0.5;
|
|
v=fmod(x,stepX);
|
|
v=x-v;
|
|
point.x = GetDC()->GetSX(v);
|
|
}
|
|
if(point.y != 0)
|
|
{
|
|
if(y > 0) y += stepY*0.5;
|
|
else if(y < 0) y-= stepY*0.5;
|
|
v=fmod(y,stepY);
|
|
v=y-v;
|
|
point.y = GetDC()->GetSY(v);
|
|
}
|
|
}
|
|
|
|
void CItemBkGrid::DrawGrid(double stepX, double stepY, BOOL nSel)
|
|
{
|
|
if(AfxGetPublicFunction()->IsZero(stepX) || AfxGetPublicFunction()->IsZero(stepY)) return;
|
|
|
|
CSigmaView* pView =GetView();
|
|
if(pView==NULL) return;
|
|
|
|
CXyDC* pDC=GetDC();
|
|
CRect rect;
|
|
rect = pView->GetClientRect(); //¿ÉÄÜ»á³ö´í
|
|
CRect8 rt=pDC->GetReal(rect);
|
|
rt.NormalizeRect();
|
|
|
|
// Major unit lines
|
|
int old=0;
|
|
if(nSel) old = pDC->GetDC()->SetROP2(R2_NOTXORPEN);
|
|
COLORREF color=0;
|
|
|
|
double m, n;
|
|
m=fmod(rt.left,stepX);
|
|
m=rt.left-m;
|
|
n=fmod(rt.bottom,stepY);
|
|
n=rt.bottom-n;
|
|
|
|
int sx=pDC->GetScreenWidth(stepX);
|
|
int sy=pDC->GetScreenHeight(stepY);
|
|
if( sx>100.0 || sy>100.0 )
|
|
{
|
|
CPen pen;
|
|
pen.CreatePen(PS_DASHDOTDOT, 1, color);
|
|
CPen* pOldPen = pDC->GetDC()->SelectObject(&pen);
|
|
//»´¹Ö±·½ÏòµÄÍø¸ñ
|
|
for (double x=m; x<rt.right; x+=stepX)
|
|
{
|
|
pDC->MoveTo(x, rt.bottom);
|
|
pDC->LineTo(x, rt.top);
|
|
}
|
|
//»Ë®Æ½·½ÏòµÄÍø¸ñ
|
|
for (double y=n; y<rt.top; y+=stepY)
|
|
{
|
|
pDC->MoveTo(rt.left, y);
|
|
pDC->LineTo(rt.right, y);
|
|
}
|
|
pDC->GetDC()->SelectObject(pOldPen);
|
|
}
|
|
else if(sx>4 || sy>4) //»µã»òÊ®×Ö²æ
|
|
{
|
|
BOOL bIsPoint=TRUE;
|
|
if( sx>40 || sy>40 ) bIsPoint=FALSE;
|
|
|
|
CPen pen;
|
|
CPen* pOldPen=NULL;
|
|
if(!bIsPoint)
|
|
{
|
|
pen.CreatePen(PS_SOLID, 1, color);
|
|
pOldPen=pDC->GetDC()->SelectObject(&pen);
|
|
}
|
|
|
|
int width=2;
|
|
int sx,sy;
|
|
for (double x=m; x<rt.right; x+=stepX)
|
|
{
|
|
for (double y=n; y<rt.top; y+=stepY)
|
|
{
|
|
sx=pDC->GetSX(x);
|
|
sy=pDC->GetSY(y);
|
|
if(bIsPoint)
|
|
pDC->GetDC()->SetPixel(sx,sy,color);
|
|
else
|
|
{
|
|
pDC->GetDC()->MoveTo(sx,sy-width);
|
|
pDC->GetDC()->LineTo(sx,sy+width+1);
|
|
pDC->GetDC()->MoveTo(sx-width,sy);
|
|
pDC->GetDC()->LineTo(sx+width+1,sy);
|
|
}
|
|
}
|
|
}
|
|
if(pOldPen) pDC->GetDC()->SelectObject(pOldPen);
|
|
}
|
|
|
|
if(nSel) pDC->GetDC()->SetROP2(old);
|
|
}
|