一,
(1)使用的ObjectARX向导创建新工程用户交互
(2)编译,如果出现以下错误:
错误C2338:/ RTCc拒绝符合代码,因此C ++标准库不支持它。删除此编译器选项,或定义_ALLOW_RTCc_IN_STL以确认您已收到此警告。
解决方法:
(3)新建一个常见的过滤器:右键 - “添加筛选器
(4)在普通文件夹中新建相互作用文件夹
(5)在交互文件夹中新建一个CGetInputUtil,用于获取用户的输入
(6)此时,将的.cpp文件拖入到筛选器中即可
打开项目的文件夹,发现头文件和源文件都在同一层级上,所以拖入到筛选器文件夹中不影响它的层级关系,筛选器文件夹只是给开发者起到一种分类作用
(7)在其中新建一个成员函数GetPointReturnCode,指定基点的情况下提示用户拾取一个点,代码实现:
int CGetInputUtil::GetPointReturnCode(const AcGePoint3d &basePoint, const TCHAR* prompt, AcGePoint3d &point)
{
//将基点转换为UCS坐标
AcGePoint3d ucsBasePoint = CConvertUtil::WcsToUcsPoint(basePoint);
int nReturn = acedGetPoint(asDblArray(ucsBasePoint), prompt, asDblArray(point));
if (nReturn == RTNORM)
{
//acedGetPoint得到UCS坐标,转换为WCS
point = CConvertUtil::UcsToWcsPoint(point);
}
return nReturn;
}
(8)其中的CConvertUtil类:
在CConvertUtil类中添加成员函数:AcGePoint3d WcsToUcsPoint(const AcGePoint3d&point); 实现代码:
AcGePoint3d CConvertUtil::WcsToUcsPoint( const AcGePoint3d &point )
{
// 转换成世界坐标
AcGePoint3d pt;
struct resbuf rbFrom, rbTo;
rbFrom.restype = RTSHORT;
rbFrom.resval.rint = 0; // from WCS
rbTo.restype = RTSHORT;
rbTo.resval.rint = 1; // to UCS
acedTrans(asDblArray(point