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

📄 myexam07dlg.cpp

📁 ARX/CAD二次开发
💻 CPP
字号:
// MyExam07Dlg.cpp : implementation file
//

#include "stdafx.h"
#include "MyExam07Dlg.h"
#include "exam07.h"

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

/////////////////////////////////////////////////////////////////////////////
// MyExam07Dlg dialog


MyExam07Dlg::MyExam07Dlg(CWnd* pParent /*=NULL*/)
	: CAcUiDialog(MyExam07Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(MyExam07Dlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void MyExam07Dlg::DoDataExchange(CDataExchange* pDX)
{
	CAcUiDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(MyExam07Dlg)
	DDX_Control(pDX, IDC_COMBO_REGAPPS, m_ctrlRegAppComboBox);
	DDX_Control(pDX, IDC_LIST_BLOCKS, m_ctrlBlockListBox);
	DDX_Control(pDX, IDC_EDIT_ZPT, m_ctrlZPtEdit);
	DDX_Control(pDX, IDC_EDIT_YPT, m_ctrlYPtEdit);
	DDX_Control(pDX, IDC_EDIT_XPT, m_ctrlXPtEdit);
	DDX_Control(pDX, IDC_EDIT_ANGLE, m_ctrlAngleEdit);
	DDX_Control(pDX, IDC_BUTTON_POINT, m_ctrlPickButton);
	DDX_Control(pDX, IDC_BUTTON_ANGLE, m_ctrlAngleButton);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(MyExam07Dlg, CAcUiDialog)
	//{{AFX_MSG_MAP(MyExam07Dlg)
	ON_BN_CLICKED(IDC_BUTTON_ANGLE, OnButtonAngle)
	ON_BN_CLICKED(IDC_BUTTON_POINT, OnButtonPoint)
	ON_CBN_KILLFOCUS(IDC_COMBO_REGAPPS, OnKillfocusComboRegapps)
	ON_EN_KILLFOCUS(IDC_EDIT_ANGLE, OnKillfocusEditAngle)
	ON_EN_KILLFOCUS(IDC_EDIT_XPT, OnKillfocusEditXpt)
	ON_EN_KILLFOCUS(IDC_EDIT_YPT, OnKillfocusEditYpt)
	ON_EN_KILLFOCUS(IDC_EDIT_ZPT, OnKillfocusEditZpt)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// MyExam07Dlg message handlers

BOOL MyExam07Dlg::OnInitDialog()
{

	SetDialogName("exam07:MyExam07Dlg");
	CAcUiDialog::OnInitDialog();
	DLGCTLINFO dlgSizeInfo[]= {
		{ IDC_STATIC_GROUP1, ELASTICX, 20 },
		{ IDC_STATIC_GROUP1, ELASTICY, 100 },
		{ IDC_EDIT_XPT,ELASTICX, 20 },
		{ IDC_EDIT_YPT,ELASTICX, 20 },
		{ IDC_EDIT_ZPT,ELASTICX, 20 },
		{ IDC_EDIT_ANGLE, ELASTICX, 20 },
		{ IDC_STATIC_GROUP2, MOVEX, 20 },
		{ IDC_STATIC_GROUP2, ELASTICY, 100 },
		{ IDC_STATIC_GROUP2, ELASTICX, 80 },
		{ IDC_LIST_BLOCKS, MOVEX, 20 },
		{ IDC_LIST_BLOCKS, ELASTICY, 100 },
		{ IDC_STATIC_TEXT2,MOVEX, 20 },
		{ IDC_STATIC_TEXT2,MOVEY, 100 },
		{ IDC_LIST_BLOCKS, ELASTICX, 80 },
		{ IDC_STATIC_TEXT2,ELASTICX, 80 },
		{ IDC_STATIC_GROUP3, MOVEY, 100 },
		{ IDC_STATIC_GROUP3, ELASTICX, 20 },
		{ IDC_COMBO_REGAPPS, MOVEY, 100 },
		{ IDC_COMBO_REGAPPS, ELASTICX, 20 },
		{ IDC_STATIC_TEXT3,MOVEY, 100 },
		{ IDC_STATIC_TEXT3,ELASTICX, 20 },
		{ IDOK,MOVEX, 100 },
		{ IDCANCEL, MOVEX, 100 },
	};

	const DWORD numberofentries =
		sizeof dlgSizeInfo / sizeof DLGCTLINFO;
	SetControlProperty(dlgSizeInfo, numberofentries);

	m_ctrlXPtEdit.SetRange(-50.0, 50.0);
	m_ctrlYPtEdit.SetRange(-50.0, 50.0);
	m_ctrlZPtEdit.SetRange(-50.0, 50.0);
	
	m_ctrlAngleEdit.SetRange(0.0, 90.0 /*(PI/2.0)*/);
	
	SetWindowText("AcUiDialog Sample");
	
	m_ctrlPickButton.AutoLoad();
	m_ctrlAngleButton.AutoLoad();
	
	if (!GetDialogData("ANGLE", m_strAngle))
		m_strAngle = "0.0";
	if (!GetDialogData("POINTX", m_strXPt))
		m_strXPt = "0.0";
	if (!GetDialogData("POINTY", m_strYPt))
		m_strYPt = "0.0";
	if (!GetDialogData("POINTZ", m_strZPt))
		m_strZPt = "0.0";
	DisplayPoint();
	DisplayAngle();
	DisplayBlocks();
	DisplayRegApps();
	return TRUE;
}

void MyExam07Dlg::DisplayPoint()
{
	m_ctrlXPtEdit.SetWindowText(m_strXPt);
	m_ctrlXPtEdit.Convert();
	m_ctrlYPtEdit.SetWindowText(m_strYPt);
	m_ctrlYPtEdit.Convert();
	m_ctrlZPtEdit.SetWindowText(m_strZPt);
	m_ctrlZPtEdit.Convert();
}

bool MyExam07Dlg::ValidatePoint()
{
	if (!m_ctrlXPtEdit.Validate())
		return false;
	if (!m_ctrlYPtEdit.Validate())
		return false;
	if (!m_ctrlZPtEdit.Validate())
		return false;
	return true;
}

void MyExam07Dlg::DisplayAngle()
{
	m_ctrlAngleEdit.SetWindowText(m_strAngle);
	m_ctrlAngleEdit.Convert();
}

bool MyExam07Dlg::ValidateAngle()
{
	if (!m_ctrlAngleEdit.Validate())
		return false;
	return true;
}

void MyExam07Dlg::DisplayBlocks()
{
	AcDbBlockTable *pBlockTable;
	acdbHostApplicationServices()->workingDatabase()
		->getSymbolTable(pBlockTable, AcDb::kForRead);

	char *pName;
	AcDbBlockTableIterator *pBTItr;
	if (pBlockTable->newIterator(pBTItr) == Acad::eOk) 
	{
		while (!pBTItr->done()) 
		{
			AcDbBlockTableRecord *pRecord;
			if (pBTItr->getRecord(pRecord, AcDb::kForRead)
				== Acad::eOk) 
			{
				pRecord->getName(pName);
				m_ctrlBlockListBox.InsertString(-1, pName);
				pRecord->close();
			}
			pBTItr->step();
		}
	}
	pBlockTable->close();
}

void MyExam07Dlg::DisplayRegApps()
{
	AcDbRegAppTable *pRegAppTable;
	acdbHostApplicationServices()->workingDatabase()
		->getSymbolTable(pRegAppTable, AcDb::kForRead);

	char *pName;
	AcDbRegAppTableIterator *pItr;
	if (pRegAppTable->newIterator(pItr) == Acad::eOk) 
	{
		while (!pItr->done()) 
		{
			AcDbRegAppTableRecord *pRecord;
			if (pItr->getRecord(pRecord, AcDb::kForRead)
				== Acad::eOk) 
			{
				pRecord->getName(pName);
				m_ctrlRegAppComboBox.InsertString(-1, pName);
				pRecord->close();
			}
			pItr->step();
		}
	}
	pRegAppTable->close();
}

void MyExam07Dlg::OnButtonAngle()
{
	BeginEditorCommand();

	ads_point pt;
	acdbDisToF(m_strXPt, -1, &pt[X]);
	acdbDisToF(m_strYPt, -1, &pt[Y]);
	acdbDisToF(m_strZPt, -1, &pt[Z]);
	double angle;
	
	if (acedGetAngle(pt, "\nPick an angle: ", &angle) == RTNORM) {
	
		CompleteEditorCommand();
		
		m_strAngle.Format("%g", angle*(180.0/PI));
		DisplayAngle();
	} 
	else 
	{
		CancelEditorCommand();
	}
}

void MyExam07Dlg::OnButtonPoint() 
{

	BeginEditorCommand();
	ads_point pt;
	
	if (acedGetPoint(NULL, "\nPick a point: ", pt) == RTNORM) {
		CompleteEditorCommand();
		m_strXPt.Format("%g", pt[X]);
		m_strYPt.Format("%g", pt[Y]);
		m_strZPt.Format("%g", pt[Z]);
		DisplayPoint();
	} 
	else 
	{
		CancelEditorCommand();
	}
}

void MyExam07Dlg::OnKillfocusEditAngle()
{
	m_ctrlAngleEdit.Convert();
	m_ctrlAngleEdit.GetWindowText(m_strAngle);
}

void MyExam07Dlg::OnKillfocusEditXpt()
{
	m_ctrlXPtEdit.Convert();
	m_ctrlXPtEdit.GetWindowText(m_strXPt);
}

void MyExam07Dlg::OnKillfocusEditYpt()
{
	m_ctrlYPtEdit.Convert();
	m_ctrlYPtEdit.GetWindowText(m_strYPt);
}

void MyExam07Dlg::OnKillfocusEditZpt()
{
	m_ctrlZPtEdit.Convert();
	m_ctrlZPtEdit.GetWindowText(m_strZPt);
}

void MyExam07Dlg::OnKillfocusComboRegapps()
{
	CString strFromEdit;
	m_ctrlRegAppComboBox.GetWindowText(strFromEdit);
	if (m_ctrlRegAppComboBox.FindString(-1, strFromEdit) == CB_ERR)
		if (acdbRegApp(strFromEdit) == RTNORM)
			m_ctrlRegAppComboBox.AddString(strFromEdit);
}

void MyExam07Dlg::OnOK()
{
	if (!ValidatePoint()) 
	{
		AfxMessageBox("Sorry, Point out of desired range.");
		m_ctrlXPtEdit.SetFocus();
		return;
	}
	if (!ValidateAngle()) 
	{
		AfxMessageBox("Sorry, Angle out of desired range.");
		m_ctrlAngleEdit.SetFocus();
		return;
	}

	SetDialogData("ANGLE", m_strAngle);
	SetDialogData("POINTX", m_strXPt);
	SetDialogData("POINTY", m_strYPt);
	SetDialogData("POINTZ", m_strZPt);
	CAcUiDialog::OnOK();
}

⌨️ 快捷键说明

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