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

📄 bsplinesetdlg.cpp

📁 B3次样条拟合
💻 CPP
字号:
// BSplineSetDlg.cpp : implementation file
//

#include "stdafx.h"
#include "BSpline.h"
#include "BSplineSetDlg.h"
#include "BSplineDoc.h"
#include "BSplineView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CBSplineSetDlg dialog


CBSplineSetDlg::CBSplineSetDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CBSplineSetDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CBSplineSetDlg)
	m_degree = 3;
	m_length = 0.01;
	//}}AFX_DATA_INIT
	m_type = 2;
	m_subtype = 1;
}


void CBSplineSetDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CBSplineSetDlg)
	DDX_Control(pDX, IDC_TYPE1, m_Section1);
	DDX_Control(pDX, IDC_SUBTYPE1, m_Section2);
	DDX_Text(pDX, IDC_DGR, m_degree);
	DDV_MinMaxInt(pDX, m_degree, 0, 15);
	DDX_Text(pDX, IDC_LTH, m_length);
	DDV_MinMaxDouble(pDX, m_length, 0., 0.5);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CBSplineSetDlg, CDialog)
	//{{AFX_MSG_MAP(CBSplineSetDlg)
	ON_BN_CLICKED(IDC_TYPE1, OnType1)
	ON_BN_CLICKED(IDC_TYPE2, OnType2)
	ON_BN_CLICKED(IDC_TYPE3, OnType3)
	ON_BN_CLICKED(IDC_TYPE4, OnType4)
	ON_BN_CLICKED(IDC_SUBTYPE1, OnSubtype1)
	ON_BN_CLICKED(IDC_SUBTYPE2, OnSubtype2)
	ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
	ON_WM_PAINT()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CBSplineSetDlg message handlers

void CBSplineSetDlg::OnType1() 
{
	// TODO: Add your control notification handler code here
	m_type = 1;
	HideSection2();
}

void CBSplineSetDlg::OnType2() 
{
	// TODO: Add your control notification handler code here
	m_type = 2;
	HideSection2();
}

void CBSplineSetDlg::OnType3() 
{
	// TODO: Add your control notification handler code here
	m_type = 3;
	HideSection2();
}

void CBSplineSetDlg::OnType4() 
{
	// TODO: Add your control notification handler code here
	m_type = 4;
	ShowSection2();
}

void CBSplineSetDlg::OnSubtype1() 
{
	// TODO: Add your control notification handler code here
	m_subtype = 1;
}

void CBSplineSetDlg::OnSubtype2() 
{
	// TODO: Add your control notification handler code here
	m_subtype = 2;
}

BOOL CBSplineSetDlg::OnInitDialog() 
{
	// TODO: Add extra initialization here
	CDialog::OnInitDialog();
	HideSection2();
	Invalidate();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CBSplineSetDlg::HideSection2()
{
	GetDlgItem(IDC_STATIC2)->EnableWindow(FALSE);
	GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_SUBTYPE1)->EnableWindow(FALSE);
	GetDlgItem(IDC_SUBTYPE1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_SUBTYPE2)->EnableWindow(FALSE);
	GetDlgItem(IDC_SUBTYPE2)->ShowWindow(SW_SHOW);
}

void CBSplineSetDlg::OnOK() 
{
	// TODO: Add extra validation here

    //调用文档类数据
	CBSplineView *pViewWnd = (CBSplineView *)GetParent()->GetWindow(GW_CHILD);
	CBSplineDoc* pDoc = pViewWnd->GetDocument();
	ASSERT_VALID(pDoc);

	UpdateData(TRUE);	
	if(pDoc->m_ptArray.GetUpperBound() < m_degree)
	{
		MessageBox("控制点数一定要大于曲线次数!");
		return;
	}

	if(m_type == 3 && pDoc->m_ptArray.GetUpperBound() % m_degree != 0)
	{
		MessageBox("选择分段贝奇尔曲线时,控制点数减1应该能够整除曲线次数!");
		return;
	}
	UpdateData(TRUE);
	pDoc->m_degree = m_degree;
	pDoc->m_length = m_length;
	pDoc->m_subtype = m_subtype;
	pDoc->m_type = m_type;
	pDoc->UpdateData();
	pDoc->UpdateAllViews(NULL);

	CDialog::OnOK();
}

void CBSplineSetDlg::OnRefresh() 
{
	// TODO: Add your control notification handler code here
	//调用文档类数据
	CBSplineView *pViewWnd = (CBSplineView *)GetParent()->GetWindow(GW_CHILD);
	CBSplineDoc* pDoc = pViewWnd->GetDocument();
	ASSERT_VALID(pDoc);
	m_degree = pDoc->m_degree = 3;
	m_length = pDoc->m_length = 0.01;
	m_type = pDoc->m_type = 2;
	m_subtype = pDoc->m_subtype = 1;
	HideSection2();
	Invalidate();
}

void CBSplineSetDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here

	//调用文档类数据
	CBSplineView *pViewWnd = (CBSplineView *)GetParent()->GetWindow(GW_CHILD);
	CBSplineDoc* pDoc = pViewWnd->GetDocument();
	ASSERT_VALID(pDoc);
		
	m_degree = pDoc->m_degree;
	m_length = pDoc->m_length;
	UpdateData(FALSE);

	switch(pDoc->m_type) {
	case 1:
		((CButton *)GetDlgItem(IDC_TYPE1))->SetCheck(1);
		((CButton *)GetDlgItem(IDC_TYPE2))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE3))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE4))->SetCheck(0);
		break;
	case 2:
		((CButton *)GetDlgItem(IDC_TYPE1))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE2))->SetCheck(1);
		((CButton *)GetDlgItem(IDC_TYPE3))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE4))->SetCheck(0);
		break;
	case 3:
		((CButton *)GetDlgItem(IDC_TYPE1))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE2))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE3))->SetCheck(1);
		((CButton *)GetDlgItem(IDC_TYPE4))->SetCheck(0);
		break;
	case 4:
		((CButton *)GetDlgItem(IDC_TYPE1))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE2))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE3))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_TYPE4))->SetCheck(1);
		ShowSection2();
		break;
	default:
		break;
	}
	
	switch(pDoc->m_subtype) {
	case 1:
		((CButton *)GetDlgItem(IDC_SUBTYPE1))->SetCheck(1);	
		((CButton *)GetDlgItem(IDC_SUBTYPE2))->SetCheck(0);
		break;
	case 2:
		((CButton *)GetDlgItem(IDC_SUBTYPE1))->SetCheck(0);
		((CButton *)GetDlgItem(IDC_SUBTYPE2))->SetCheck(1);
		break;
	default:
		break;
	}
	// Do not call CDialog::OnPaint() for painting messages
}

void CBSplineSetDlg::ShowSection2()
{
	GetDlgItem(IDC_STATIC2)->EnableWindow(TRUE);
	GetDlgItem(IDC_STATIC2)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_SUBTYPE1)->EnableWindow(TRUE);
	GetDlgItem(IDC_SUBTYPE1)->ShowWindow(SW_SHOW);
	GetDlgItem(IDC_SUBTYPE2)->EnableWindow(TRUE);
	GetDlgItem(IDC_SUBTYPE2)->ShowWindow(SW_SHOW);
}





















⌨️ 快捷键说明

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