www.pudn.com > roll.rar > CURVE2DW.CPP


// Curve2DW.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "roll.h" 
#include "curve2d.h" 
#include "Curve2DW.h" 
#include "comnfun.h" 
#include "inputstring.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCurve2DW 
COLORREF CCurve2DW::crColor[13]={ 
	0x00000000, 
	0x00ff0000,0x0000ff00,0x000000ff, 
	0x00ff00ff,0x00ffff00,0x0000ffff, 
	0x00800000,0x00008000,0x00000080, 
	0x00808000,0x00800080,0x00008080, 
}; 
 
CCurve2DW::CCurve2DW() 
{ 
	nx=4; 
	ny=3; 
	type=1; 
	IsMarked=TRUE; 
	strHorz=CString("长度(单位:mm)"); 
	strVert=CString("刚度(单位:N/mm/mm)"); 
	memset(&logfont, 0, sizeof logfont); 
    logfont.lfHeight = 12; 
    lstrcpy(logfont.lfFaceName, _T("Arial")); 
    logfont.lfOutPrecision = OUT_TT_PRECIS; 
    logfont.lfClipPrecision = CLIP_DEFAULT_PRECIS; 
    logfont.lfQuality = PROOF_QUALITY; 
    logfont.lfPitchAndFamily = FF_SWISS | VARIABLE_PITCH; 
} 
 
CCurve2DW::~CCurve2DW() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CCurve2DW, CWnd) 
	//{{AFX_MSG_MAP(CCurve2DW) 
	ON_WM_PAINT() 
	ON_WM_RBUTTONUP() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
extern CCurve2D My_Curve; 
 
///////////////////////////////////////////////////////////////////////////// 
// CCurve2DW message handlers 
 
void CCurve2DW::DrawCoordinate(CDC *dc,double xmin,double xmax,double ymin,double ymax, 
							   double x,double y,double xi,double yi,int nx,int ny,int Type) 
{ 
	char buf[30]; 
	POINT pt; 
	pt.x=INT(-x*xi); 
	pt.y=INT(-y*yi); 
	CRect rect; 
	UINT TextAlign; 
	GetClientRect(&rect); 
	dc->DPtoLP(&rect); 
	LONG xl,xr,yt,yb,si; 
	xl=INT(xi*(xmin-x)); 
	xr=INT(xi*(xmax-x)); 
	yt=INT(yi*(ymin-y)); 
	yb=INT(yi*(ymax-y)); 
 
	CFont fontHorz,fontVert; 
 
	logfont.lfEscapement=0; 
	fontHorz.CreateFontIndirect(&logfont); 
	CFont *pOldFont=(CFont *)dc->SelectObject(&fontHorz); 
	TextAlign=dc->SetTextAlign(TA_CENTER|TA_TOP); 
	dc->TextOut(0,pt.y-2,strHorz); 
 
	logfont.lfEscapement=2700; 
	fontVert.CreateFontIndirect(&logfont); 
	dc->SelectObject(&fontVert); 
	dc->SetTextAlign(TA_CENTER|TA_BOTTOM); 
	dc->TextOut(pt.x,0,strVert); 
 
	dc->SelectObject(pOldFont); 
	dc->SetTextAlign(TextAlign); 
	if(Type==0) { 
		sprintf(buf,"0,0"); 
		dc->TextOut(pt.x+1,pt.y,buf); 
		TextAlign=dc->SetTextAlign(TA_LEFT|TA_BOTTOM); 
		sprintf(buf,"%7.2f",ymax); 
		dc->TextOut(pt.x+1,yb,buf); 
 
		dc->MoveTo(pt.x,yb); 
		dc->LineTo(pt.x+5,yb); 
		dc->MoveTo(pt.x,0); 
		dc->LineTo(pt.x+5,0); 
 
		dc->MoveTo(0,pt.y); 
		dc->LineTo(0,pt.y+5); 
		dc->MoveTo(xr,pt.y); 
		dc->LineTo(xr,pt.y+5); 
 
		dc->SetTextAlign(TA_RIGHT|TA_TOP); 
		sprintf(buf,"%7.2f",xmax); 
		dc->TextOut(xr,pt.y,buf); 
		dc->SetTextAlign(TextAlign); 
		dc->MoveTo(rect.left+5,pt.y); 
		dc->LineTo(rect.right-7,pt.y); 
		dc->MoveTo(pt.x,rect.top-7); 
		dc->LineTo(pt.x,rect.bottom+5); 
		DrawHArrow(dc,rect.right-7,pt.y); 
		DrawVArrow(dc,pt.x,rect.top-7); 
	} 
	else { 
		double s; 
		dc->Rectangle(xl,yt,xr,yb); 
		CPen pen(PS_DASH,1,RGB(0,0,0)); 
		CPen* pOldPen=(CPen *)dc->SelectObject(&pen); 
		s=yi*(ymax-ymin)/ny; 
		for(si=1;siMoveTo(xl,yt+LONG(si*s+0.5)); 
			dc->LineTo(xr,yt+LONG(si*s+0.5)); 
		} 
		s=xi*(xmax-xmin)/nx; 
		for(si=1;siMoveTo(xl+LONG(si*s+0.5),yt); 
			dc->LineTo(xl+LONG(si*s+0.5),yb); 
		} 
		dc->SelectObject(pOldPen); 
		sprintf(buf,"%9.3e,%9.3e",xmin,ymin); 
		dc->TextOut(xl,yt,buf); 
		TextAlign=dc->SetTextAlign(TA_RIGHT|TA_BOTTOM); 
		sprintf(buf,"%9.3e,%9.3e",xmax,ymax); 
		dc->TextOut(xr,yb,buf); 
		dc->SetTextAlign(TextAlign); 
	} 
} 
 
void CCurve2DW::OnPaint()  
{ 
	CRect rect; 
	CPaintDC hdc(this); 
	GetClientRect(&rect); 
	if(My_Curve.Curve==NULL) { 
		hdc.DrawText("No curve defined !",-1,&rect, 
			DT_SINGLELINE|DT_CENTER|DT_VCENTER); 
		return; 
	} 
	hdc.SetMapMode(MM_ISOTROPIC); 
	hdc.SetWindowExt(1,1); 
	hdc.SetViewportExt(1,-1); 
	hdc.SetViewportOrg(rect.right/2,rect.bottom/2); 
	double x,y,xi,yi,xr,yr; 
	long lth; 
	double& xmin=My_Curve.xmin; 
	double& ymin=My_Curve.ymin; 
	double& xmax=My_Curve.xmax; 
	double& ymax=My_Curve.ymax; 
	x=0.5*(xmax+xmin); 
	y=0.5*(ymax+ymin); 
	lth=rect.right-40; 
	if(lth<0) lth=rect.right; 
	xi=lth/(My_Curve.xmax-xmin); 
	lth=rect.bottom-40; 
	if(lth<0) lth=rect.bottom; 
	yi=lth/(My_Curve.ymax-ymin); 
	_Global_Ratio=1.0; 
	DrawCoordinate(&hdc,xmin,xmax,ymin,ymax,x,y,xi,yi,nx,ny,type); 
	for(short si=0;siPolyline(pt,4); 
		break; 
	case 2: 
		x=int(xp+0.5); 
		y=int(yp+0.5); 
		pt[4].x=pt[0].x=x-2; 
		pt[4].y=pt[0].y=y-2; 
		pt[1].x=x+2; 
		pt[1].y=y-2; 
		pt[2].x=x+2; 
		pt[2].y=y+2; 
		pt[3].x=x-2; 
		pt[3].y=y+2; 
		dc->Polyline(pt,5); 
		break; 
	} 
} 
 
void CCurve2DW::OnRButtonUp(UINT nFlags, CPoint point)  
{ 
	CMenu menu; 
	menu.CreatePopupMenu( ); 
	if(type==1) { 
		menu.AppendMenu(MF_ENABLED,1,"Change the horz lattice number"); 
		menu.AppendMenu(MF_ENABLED,2,"Change the vert lattice number"); 
	} 
	menu.AppendMenu(MF_ENABLED,3,"Change corrdinate system type"); 
	if(IsMarked) 
		menu.AppendMenu(MF_ENABLED,4,"NEED NOT marked points"); 
	else 
		menu.AppendMenu(MF_ENABLED,4,"MUST TO marked points"); 
	menu.AppendMenu(MF_ENABLED,5,"Modify Horz characters"); 
	menu.AppendMenu(MF_ENABLED,6,"Modify Vert characters"); 
	menu.AppendMenu(MF_ENABLED,7,"Change Horz && Vert Font"); 
	menu.TrackPopupMenu(TPM_CENTERALIGN|TPM_LEFTBUTTON,point.x,point.y,this); 
	 
	CWnd::OnRButtonUp(nFlags, point); 
} 
 
BOOL CCurve2DW::OnCommand(WPARAM wParam, LPARAM lParam)  
{ 
	if(wParam==1) { 
		CString string="Input the horz lattice number:"; 
		CInputString Input(string); 
		if(Input.DoModal()==IDCANCEL) goto ret; 
		if(Input.m_String.IsEmpty()) goto ret; 
		nx=atoi(Input.m_String); 
		if(nx<1) nx=1; 
	} 
	else if(wParam==2) { 
		CString string="Input the vert lattice number:"; 
		CInputString Input(string); 
		if(Input.DoModal()==IDCANCEL) goto ret; 
		if(Input.m_String.IsEmpty()) goto ret; 
		ny=atoi(Input.m_String); 
		if(ny<1) ny=1; 
	} 
	else if(wParam==3) 
		type = !type; 
	else if(wParam==4) 
		IsMarked = !IsMarked; 
	else if(wParam==5) { 
		CString string="Input the Horz Characters:"; 
		CInputString Input(string); 
		Input.m_String=strHorz; 
		if(Input.DoModal()==IDCANCEL) goto ret; 
		strHorz=Input.m_String; 
	} 
	else if(wParam==6) { 
		CString string="Input the Vert Characters:"; 
		CInputString Input(string); 
		Input.m_String=strVert; 
		if(Input.DoModal()==IDCANCEL) goto ret; 
		strVert=Input.m_String; 
	} 
	else if(wParam==7) { 
		CFontDialog fontDlg(&logfont); 
		fontDlg.DoModal(); 
	} 
	InvalidateRect(NULL); 
ret: 
	return CWnd::OnCommand(wParam, lParam); 
}