⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xiuhuaview.cpp

📁 本程序用于读取电脑绣花机的数据
💻 CPP
字号:
// xiuhuaView.cpp : implementation of the CXiuhuaView class
//

#include "stdafx.h"
#include "xiuhua.h"

#include "xiuhuaDoc.h"
#include "xiuhuaView.h"
#include "dialog1.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView

IMPLEMENT_DYNCREATE(CXiuhuaView, CView)

BEGIN_MESSAGE_MAP(CXiuhuaView, CView)
	//{{AFX_MSG_MAP(CXiuhuaView)
		// NOTE - the ClassWizard will add and remove mapping macros here.
		//    DO NOT EDIT what you see in these blocks of generated code!
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_MENU_MODFIY_FLOWER_PARAMETER, OnMenuModfiyFlowerParameter)
	ON_COMMAND(ID_MENU_BEGIN_EMBROEDER, OnMenuBeginEmbroeder)
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView construction/destruction

CXiuhuaView::CXiuhuaView()
{
	// TODO: add construction code here
	V_Flower_coordinate_x=300;
	V_Flower_coordinate_y=300;
	V_Flower_begin=34;
	V_Flower_over=37150;
	V_Flower_Speed=1;
	V_Flower_Scale=5;

  

}

CXiuhuaView::~CXiuhuaView()
{
}

BOOL CXiuhuaView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView drawing

void CXiuhuaView::OnDraw(CDC* pDC)
{
	CXiuhuaDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here


}

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView printing

BOOL CXiuhuaView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CXiuhuaView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CXiuhuaView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView diagnostics

#ifdef _DEBUG
void CXiuhuaView::AssertValid() const
{
	CView::AssertValid();
}

void CXiuhuaView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CXiuhuaDoc* CXiuhuaView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CXiuhuaDoc)));
	return (CXiuhuaDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CXiuhuaView message handlers
void CXiuhuaView::OnMenuModfiyFlowerParameter() 
{
	// TODO: Add your command handler code here
	dialog1   dlg;
 	dlg.m_Flower_coordinate_x=V_Flower_coordinate_x;
	dlg.m_Flower_coordinate_y=V_Flower_coordinate_y;
	dlg.m_Flower_begin=V_Flower_begin;
	dlg.m_Flower_over=V_Flower_over;
	dlg.m_Flower_Speed=V_Flower_Speed;
	dlg.m_Flower_Scale=	V_Flower_Scale;
	
	
	if  (dlg.DoModal()==IDOK)//调用dialog1 对话框
	{
	V_Flower_coordinate_x=dlg.m_Flower_coordinate_x;
	V_Flower_coordinate_y=dlg.m_Flower_coordinate_y;
	V_Flower_begin=dlg.m_Flower_begin;
	V_Flower_over=dlg.m_Flower_over;
	V_Flower_Speed=dlg.m_Flower_Speed;
	V_Flower_Scale=dlg.m_Flower_Scale;	
	
	if (V_Flower_Scale<1)
	{V_Flower_Scale=1;}

	}
}

void CXiuhuaView::OnMenuBeginEmbroeder() 
{





//下面是几个全局数据
//	CFile* m_pHexFile;
//	CXiuhuaDoc* pDoc =GetDocument();

//	long	V_Flower_coordinate_x;图形在屏幕中的位置
//	long	V_Flower_coordinate_y;
//	long	V_Flower_begin;文件的开始位置;
//	long	V_Flower_over;文件结束位置
//	int		V_Flower_Speed; 花速绣度
//	int		V_Flower_Scale; 图形比例

	
	int		VV_Flower_Speed;//绣花速度
	int		VV_Flower_Scale;//图形比例

	long	V_Flower_coordinate_xx;//图形位置
	long	V_Flower_coordinate_yy;

	long	V_Flower_coordinate_xx1;//图形放大/速小时使用
	long	V_Flower_coordinate_xx2;
	long	V_Flower_coordinate_yy1;
	long	V_Flower_coordinate_yy2;
	long	V_Flower_coordinate_xxxx;//画线时用于保存
	long	V_Flower_coordinate_yyyy;


	long    lpBufPtr_file;//用于读文件操作时,保存原有指针
	long	Flower_over;//文件结束位置
	
	long    coordinate_xy;//用于读取文件
	int     coordinate_x=0;//用于读点的坐标
	int     coordinate_y=0;
	
	long  coordinate_1;//转换长坐标数据临时使用
	long  coordinate_2;

//****************数据初始化
   //全局数据
	CXiuhuaDoc* pDoc = GetDocument();//获取文档指针
	ASSERT_VALID(pDoc);
	if	(pDoc->m_pHexFile==NULL)// 文件是否打开
		{AfxMessageBox("文件没有打开");
		return ;
		}	
	
	VV_Flower_Speed=V_Flower_Speed;//绣花速度
	VV_Flower_Scale=V_Flower_Scale;//图形比例

	
	Flower_over=V_Flower_over;//文件结束位置
	lpBufPtr_file=V_Flower_begin;//文件的开始位置;
 
	V_Flower_coordinate_xx=V_Flower_coordinate_x;//图形位置
	V_Flower_coordinate_yy=V_Flower_coordinate_y;

//*************************************************************


	V_Flower_coordinate_xxxx=V_Flower_coordinate_xx;//图形位置,作为最初的点的坐标
	V_Flower_coordinate_yyyy=V_Flower_coordinate_yy;

	V_Flower_coordinate_xx1=V_Flower_coordinate_xx;
    V_Flower_coordinate_yy1=V_Flower_coordinate_yy;
  	
	V_Flower_coordinate_xx2=V_Flower_coordinate_xx;
    V_Flower_coordinate_yy2=V_Flower_coordinate_yy;

    CClientDC   dc(this);
 	dc.MoveTo(V_Flower_coordinate_xx,V_Flower_coordinate_yy);

//*******************	//绣花循环
	while ( lpBufPtr_file<Flower_over)//绣花循环
	{
		coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);
		if(coordinate_xy>127)//正副数转换
			{coordinate_xy=-(256-coordinate_xy);}
			coordinate_x=coordinate_xy;//点的坐标x
			lpBufPtr_file++;
 			coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);
		if(coordinate_xy>127)
			{coordinate_xy=-(256-coordinate_xy);}
			coordinate_y=coordinate_xy;//点的坐标y
			lpBufPtr_file++;
//*********************//坐标差值较大,使用两个字节表示坐标值
			//标志值82H,82H,之后是坐标差值,用字表示,低位在前,高位在后,
			//一个坐标差值占ZB_x,2个个字节,ZB_Y,2个字节,标志位占2位

if ((coordinate_x==-126)&&(coordinate_y==-126))//遇到超长坐标,标志位
{
	  coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);//读坐标第一值
	  lpBufPtr_file++;
	  coordinate_1=coordinate_xy;
	  coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);
	  lpBufPtr_file++;
	  coordinate_2=coordinate_xy;
	  if (coordinate_1>127)//数据转化,原始数据不分正副数
			{coordinate_x=-(65536-(coordinate_1*256+coordinate_2));
			}
	  else
			{coordinate_x=coordinate_1*256+coordinate_2;
			}
	
	  coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);//读坐标第二值
	  lpBufPtr_file++;
	  coordinate_1=coordinate_xy;
	  coordinate_xy=pDoc->ReadFileAndProcess(lpBufPtr_file);
	  lpBufPtr_file++;
	  coordinate_2=coordinate_xy;
	  if (coordinate_1>127)
		 {coordinate_y=-(65536-(coordinate_1*256+coordinate_2));
			}
	  else
		{coordinate_y=coordinate_1*256+coordinate_2;
		}
	

 
  
 }
//***************************//遇到超长坐标,标志位,程序结束
//遇到换线标志,81h, 81h,不绣,
 if((coordinate_x==-127)&&(coordinate_y==-127))//换线
 {}
 else
 {
//*******************************

	V_Flower_coordinate_xx2=V_Flower_coordinate_xx1+coordinate_x;//计算坐标,终点
	V_Flower_coordinate_yy2=V_Flower_coordinate_yy1+coordinate_y;

	V_Flower_coordinate_xxxx=V_Flower_coordinate_xx2;//保存终点
	V_Flower_coordinate_yyyy=V_Flower_coordinate_yy2;

//按比例速放,400用于将图形上下到相
	V_Flower_coordinate_xx1=int(V_Flower_coordinate_xx1/VV_Flower_Scale)+V_Flower_coordinate_xx;
	V_Flower_coordinate_yy1=400-(int(V_Flower_coordinate_yy1/VV_Flower_Scale)+V_Flower_coordinate_yy);

	V_Flower_coordinate_xx2=int(V_Flower_coordinate_xx2/VV_Flower_Scale)+V_Flower_coordinate_xx;
	V_Flower_coordinate_yy2=400-(int(V_Flower_coordinate_yy2/VV_Flower_Scale)+V_Flower_coordinate_yy);

	dc.MoveTo(V_Flower_coordinate_xx1,V_Flower_coordinate_yy1);//画图
	dc.LineTo(V_Flower_coordinate_xx2,V_Flower_coordinate_yy2);	 

	V_Flower_coordinate_xx1=V_Flower_coordinate_xxxx;//保存下一根线的起点
    V_Flower_coordinate_yy1=V_Flower_coordinate_yyyy;
}//换线结束
}//绣花循环结束



}//命令结束

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -