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

📄 fuzzyview.cpp

📁 自己用fuzzy實作開發之倒車入庫系統
💻 CPP
字号:
// fuzzyView.cpp : implementation of the CFuzzyView class
//

#include "stdafx.h"
#include "fuzzy.h"

#include "fuzzyDoc.h"
#include "fuzzyView.h"

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

#include <fstream.h>
#include <math.h>

/////////////////////////////////////////////////////////////////////////////
// CFuzzyView

IMPLEMENT_DYNCREATE(CFuzzyView, CFormView)

BEGIN_MESSAGE_MAP(CFuzzyView, CFormView)
	//{{AFX_MSG_MAP(CFuzzyView)
	ON_BN_CLICKED(IDC_RUN, OnRun)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CFuzzyView construction/destruction

CFuzzyView::CFuzzyView()
	: CFormView(CFuzzyView::IDD)
{
	//{{AFX_DATA_INIT(CFuzzyView)
	m_xy = _T("");
	m_angle = _T("");
	//}}AFX_DATA_INIT
	// TODO: add construction code here

	isRun = FALSE;
}

CFuzzyView::~CFuzzyView()
{
}

void CFuzzyView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CFuzzyView)
	DDX_Text(pDX, IDC_XYEDIT, m_xy);
	DDX_Text(pDX, IDC_ANGLEEDIT, m_angle);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CFuzzyView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

//	SetTimer(1, 500, NULL);

}

/////////////////////////////////////////////////////////////////////////////
// CFuzzyView printing

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

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

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

void CFuzzyView::OnPrint(CDC* pDC, CPrintInfo* /*pInfo*/)
{
	// TODO: add customized printing code here
}

/////////////////////////////////////////////////////////////////////////////
// CFuzzyView diagnostics

#ifdef _DEBUG
void CFuzzyView::AssertValid() const
{
	CFormView::AssertValid();
}

void CFuzzyView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CFuzzyView message handlers

void CFuzzyView::OnDraw(CDC* pDC) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(isRun)
	{
		DrawConvergence();
		ShowCar();
	}
}

void CFuzzyView::DrawConvergence()
{
	CDC* pDC;
	pDC = GetDC();
	
	ifstream fin("out.txt");

	int n;
	double x, y, phi;

	CPoint start(100, 400);
	int gridX = 30;
	int gridY = 20;
	
	pDC->TextOut(start.x+20, start.y+60, "Μ滥瓜");

	fin >> n >> x >> y >> phi;

	while(!fin.eof())
	{
		pDC->SetPixel(start.x + n, start.y - (int)x, RGB(0, 0, 255));
		pDC->SetPixel(start.x + n, start.y - (int)y, RGB(0, 255, 0));
		pDC->SetPixel(start.x + n, start.y, RGB(255, 255, 255)); 
		pDC->SetPixel(start.x , start.y - n, RGB(255, 255, 255)); 

		if((n%gridX) == 0)
		{
			CString str;
			str.Format("%d", n);
			pDC->TextOut(start.x + gridX*(n/gridX), start.y+20, str);
			pDC->MoveTo(start.x + gridX*(n/gridX), start.y);
			pDC->LineTo(start.x + gridX*(n/gridX), start.y-5);

		}

		if((n%gridY) == 0)
		{
			CString str;
			str.Format("%d", n);
			pDC->TextOut(start.x-50, start.y-gridY*(n/gridY), str);
			pDC->MoveTo(start.x, start.y-gridY*(n/gridY));
			pDC->LineTo(start.x+5, start.y-gridY*(n/gridY));

		}


		fin >> n >> x >> y >> phi;

	}
	fin.close();

	ReleaseDC(pDC);
}



void CFuzzyView::OnRun() 
{
	// TODO: Add your control notification handler code here
	car.Run();

	CString str;
	str.Format("(%d, %d)", car.initX, car.initY);
	m_xy = str;
	str.Format("%.3f", car.initPhi);
	m_angle = str;
	UpdateData(FALSE);

	DrawConvergence();
	ShowCar();
	isRun = TRUE;
	Invalidate(TRUE);

}


void CFuzzyView::ShowCar()
{
	CDC* pDC;
	pDC = GetDC();
	ifstream fin("out.txt");
	CPoint start(500, 500);

	pDC->TextOut(start.x+20, start.y+60, "ó

⌨️ 快捷键说明

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