一,

(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), &rbFrom, &rbTo, Adesk::kFalse, asDblArray(pt));

return pt;

}

注意,是静态静成员函数:

static AcGePoint3d WcsToUcsPoint(const AcGePoint3d &point);

(9)在GetInputUtil.cpp中添加头文件

#include "ConvertUtil.h"

(10)在CConvertUtil类中添加静态成员函数UcsToWcsPoint(const AcGePoint3d&point)

UcsToWcsPoint函数声明:

static AcGePoint3d UcsToWcsPoint(const AcGePoint3d &point);

UcsToWcsPoint函数实现:

AcGePoint3d CConvertUtil::UcsToWcsPoint(const AcGePoint3d &point)

{

// 转换成世界坐标

AcGePoint3d pt;

struct resbuf rbFrom, rbTo;

rbFrom.restype = RTSHORT;

rbFrom.resval.rint = 1; // from UCS

rbTo.restype = RTSHORT;

rbTo.resval.rint = 0; // to WCS

acedTrans(asDblArray(point), &rbFrom, &rbTo, Adesk::kFalse, asDblArray(pt));

return pt;

}

(11)关于acedGetPoint函数:用于获取用户输入的一个点。

int acedGetPoint(

const ads_point pt,

const ACHAR * prompt,

ads_point result

);

二,在CGetInputUtil类中新建一个函数用GetPoint,返回值为布尔

(1)用GetPoint函数声明

static bool GetPoint(const AcGePoint3d &basePoint,

const TCHAR* prompt, AcGePoint3d &point);

(2)用GetPoint函数实现

bool CGetInputUtil::GetPoint(const AcGePoint3d &basePoint,

const TCHAR* prompt, AcGePoint3d &point)

{

return (GetPointReturnCode(basePoint, prompt, point) == RTNORM);

}

三,在CGetInputUtil类中添加一个函数Ge​​tPointReturnCode,在不提供基点的情况下提示用户拾取一个点:

(1)实现的代码:

int CGetInputUtil::GetPointReturnCode(const TCHAR* prompt, AcGePoint3d &point)

{

int nReturn = acedGetPoint(NULL, prompt, asDblArray(point));

if (nReturn == RTNORM)

{

point = CConvertUtil::UcsToWcsPoint(point);

}

return nReturn;

}

(2)asDblArray函数:

这个内联函数返回VEC作为两个双精度的数组。

四,添加一个简化返回值的封装函数用GetPoint

实现代码:

bool CGetInputUtil::GetPoint(const TCHAR* prompt, AcGePoint3d &point)

{

return (GetPointReturnCode(prompt, point) == RTNORM);

}

五,新建一个命令AddPolyBasic

(1)实现代码

static void AAAMyGroupAddPolyBasic() {

// Put your command code here

int index = 2; //当前输入点的次数

AcGePoint3d ptStart;

if (!CGetInputUtil::GetPoint(TEXT("\n输入第一点:"), ptStart))

{

return;

}

AcGePoint3d ptPrevious, ptCurrent;//前一个参考点,当前拾取点

ptPrevious = ptStart;

AcDbObjectId polyId; //多段线ID

while (CGetInputUtil::GetPoint(ptPrevious, TEXT("\n输入下一点:"), ptCurrent))

{

if (index == 2) //输入了第二个点,将多段线添加到模型空间

{

polyId = CPolylineUtil::Add(CConvertUtil::ToPoint2d(ptPrevious), CConvertUtil::ToPoint2d(ptCurrent));

}

else if (index > 2) //输入了更多的顶点,就向多段线添加一个顶点

{

AcDbPolyline *pPoly = NULL;

if (acdbOpenObject(pPolyId, AcDb::kForWrite) == Acad::eOk)

{

pPoly->addVertexAt(index - 1, CConvertUtil::ToPoint2d(ptCurrent));

pPoly->close();

}

}

ptPrevious = ptCurrent;

index++;

}

}

(2)添加一个类CPolylineUtil,

(3)添加2个成员函数

函数声明:

// 创建优化多段线

static AcDbObjectId Add(const AcGePoint2dArray &points, double width = 0);

static AcDbObjectId Add(const AcGePoint2d &ptStart, const AcGePoint2d &ptEnd,

double width = 0);

函数实现:

AcDbObjectId CPolylineUtil::Add(const AcGePoint2dArray &points, double width)

{

int numVertices = points.length();

AcDbPolyline *pPoly = new AcDbPolyline(numVertices);

for (int i = 0; i < numVertices; i++)

{

pPoly->addVertexAt(i, points.at(i), 0, width, width);

}

AcDbObjectId polyId;

polyId = CDwgDatabaseUtil::PostToModelSpace(pPoly);

return polyId;

}

AcDbObjectId CPolylineUtil::Add(const AcGePoint2d &ptStart, const AcGePoint2d &ptEnd, double width)

{

AcGePoint2dArray points;

points.append(ptStart);

points.append(ptEnd);

return Add(points, width);

}

(4)创建类CDwgDatabaseUtil,添加成员函数PostToModelSpace

实现代码:

static void AAAMyGroupAddPolyBasic() {

// Put your command code here

int index = 2; //当前输入点的次数

AcGePoint3d ptStart;

if (!CGetInputUtil::GetPoint(TEXT("\n输入第一点:"), ptStart))

{

return;

}

AcGePoint3d ptPrevious, ptCurrent;//前一个参考点,当前拾取点

ptPrevious = ptStart;

AcDbObjectId polyId; //多段线ID

while (CGetInputUtil::GetPoint(ptPrevious, TEXT("\n输入下一点:"), ptCurrent))

{

if (index == 2) //输入了第二个点,将多段线添加到模型空间

{

polyId = CPolylineUtil::Add(CConvertUtil::ToPoint2d(ptPrevious), CConvertUtil::ToPoint2d(ptCurrent));

}

else if (index > 2) //输入了更多的顶点,就向多段线添加一个顶点

{

AcDbPolyline *pPoly = NULL;

if (acdbOpenObject(pPoly,polyId, AcDb::kForWrite) == Acad::eOk)

{

pPoly->addVertexAt(index - 1, CConvertUtil::ToPoint2d(ptCurrent));

pPoly->close();

}

}

ptPrevious = ptCurrent;

index++;

}

}

(5)在PolylineUtil.cpp中添加头文件

#include "DwgDatabaseUtil.h"

(6)在类CConvertUtil中添加成员函数ToPoint2d

AcGePoint2d CConvertUtil::ToPoint2d( const AcGePoint3d &point3d )

{

return AcGePoint2d(point3d.x, point3d.y);

}

需要注意的是,我们整个项目中所添加的函数都是静态成员函数,在函数声明中添加静态

(7)在acrxEntryPoint.cpp中添加头文件

#include "GetInputUtil.h"

#include "PolylineUtil.h"

#include "ConvertUtil.h"

(8)此时不妨加载程序,在AutoCAD的中输入命令AddPolyBasic

可以正确运行,并绘制多段线。

六、注册新命令GetPointKeyword,用于实现在acedGetPoint函数中使用关键字的基本方法

(1)实现代码:

static void AAAMyGroupGetPointKeyword() {

// Put your command code here

int rc; //返回值

TCHAR kword[20]; //关键字

AcGePoint3d pt;

acedInitGet(RSG_NONULL, TEXT("K W"));

rc = CGetInputUtil::GetPointReturnCode(TEXT("\n输入一个点或[keyword1/keyword2]:"), pt);

switch (rc)

{

case RTKWORD://输入了关键字

if (acedGetInput(kword) != RTNORM)

{

return;

}

if (_tcscmp(kword, TEXT("K")) == 0)

{

acutPrintf(TEXT("\n选择的关键字是keyword1"));

}

else if (_tcscmp(kword, TEXT("W")) == 0)

{

acutPrintf(TEXT("\n选择的关键字是keyWord2!"));

}

break;

case RTNORM:

acutPrintf(TEXT("\n输入点的坐标是(%.2f,%.2f,%.2f)"),

pt.x, pt.y, pt.z);

break;

default:

break;

}

}

(2)acedInitGet(RSG_NONULL, TEXT("K W"))函数:

初始化下一个对用户输入函数的调用所使用的选项,如acedGetXxx()、acedDragGen()、acedEntSel()、acedNEntSelP()或acedNEntSel()。

参数RSG_NONULL:控制位,支持或禁用某些输入值和输入样式。RSG_NONULL表示不允许空输入

参数TEXT("K W"):用户输入函数接受的可选的关键字列表;

(3)_tcscmp(kword, TEXT("K")):

如果两个字符串是相同的则返回零。

七、在acrxEntryPoint.cpp文件的static void AAAMyGroupAddPolyBasic()命令函数前面创建一个函数GetWidth,

用于获取用户输入的线宽。(若你的编译器为VC6,则是在UserInteractionCommands.app文件中添加)

实现代码:

static ads_real GetWidth()

{

ads_real width = 0;

if (acedGetReal(TEXT("\n输入线宽:"), &width) == RTNORM)

{

return width;

}

else

{

return 0;

}

}

八、GetWidth函数后面添加一个函数GetColorIndex,用于提示输入颜色索引值。注意添加static。

static int GetColorIndex()

{

int colorIndex = 0;

if (acedGetInt(TEXT("\n输入颜色索引值(0~256):"), &colorIndex) != RTNORM)

{

return 0;

}

//处理颜色索引值无效的情况

while (colorIndex < 0 || colorIndex > 256)

{

acedPrompt(TEXT("\n输入了无效的颜色索引值."));

if (acedGetInt(TEXT("\n输入颜色索引值(0-256):"), &colorIndex) != RTNORM)

{

return 0;

}

}

return colorIndex;

}

九、注册一个新命令AddPoly,提示用户输入多段线的节点、线宽和颜色,完成多段线的创建。

实现代码为:

static void AAAMyGroupAddPoly() {

// Put your command code here

int colorIndex = 0; //颜色索引值

ads_real width = 0; //多段线的线宽

int index = 2; //当前输入点的次数

//提示用户输入起点

AcGePoint3d ptStart; //起点

if (!CGetInputUtil::GetPoint(TEXT("\n输入第一点:"), ptStart))

{

return;

}

AcGePoint3d ptPrevious, ptCurrent;//前一个参考点,当前拾取点

ptPrevious = ptStart;

AcDbObjectId polyId;//多段线的Id

//输入第二点

acedInitGet(NULL, TEXT("W C O"));

int rc = CGetInputUtil::GetPointReturnCode(ptPrevious,

TEXT("\n输入下一点[宽度(W)/颜色(C)]:"), ptCurrent);

while (rc == RTNORM || rc == RTKWORD)

{

if (rc == RTKWORD) //如果用户输入了关键字

{

TCHAR kword[20];

if (acedGetInput(kword) != RTNORM)

return;

if (_tcscmp(kword, TEXT("W")) == 0)

{

width = GetWidth();

}

else if (_tcscmp(kword, TEXT("C")) == 0)

{

colorIndex = GetColorIndex();

}

else if (_tcscmp(kword, TEXT("O")) == 0)

{

return;

}

else

{

acutPrintf(TEXT("\n无效的关键字."));

}

}

else if (rc == RTNORM)//用户输入了点

{

if (index == 2)

{

//创建多段线

polyId = CPolylineUtil::Add(CConvertUtil::ToPoint2d(ptPrevious), CConvertUtil::ToPoint2d(ptCurrent));

AcDbPolyline *pPoly = NULL;

if(acdbOpenObject(pPoly,polyId,AcDb::kForWrite) == Acad::eOk)

{

//修改多段线的颜色和线宽

pPoly->setConstantWidth(width);

pPoly->setColorIndex(colorIndex);

pPoly->close();

}

}

else if (index > 2)

{

//修改多段线,添加最后一个顶点

AcDbPolyline *pPoly = NULL;

if (acdbOpenObject(pPoly, polyId, AcDb::kForWrite) == Acad::eOk)

{

pPoly->addVertexAt(index - 1, CConvertUtil::ToPoint2d(ptCurrent));

//修改多段线的颜色和线宽

pPoly->setConstantWidth(width);

pPoly->setColorIndex(colorIndex);

pPoly->close();

}

}

ptPrevious = ptCurrent;

index++;

}

//提示用户输入新的节点

acedInitGet(NULL, TEXT("W C O"));

rc = CGetInputUtil::GetPointReturnCode(ptPrevious, TEXT("\n输入下一点[宽度(W)/颜色(C)]"), ptCurrent);

}

}

十、效果:

输入命令addpoly:

注意:宽度的关键字W 和 颜色关键字C 需要区分大小写

十一、项目UserIntereaction 的完整代码分享(开发环境:ObjectARX2018 + AutoCAD2018)

链接:https://pan.baidu.com/s/1qvbeEDP0-eMQb7vf4TncKQ 密码:osg6

参考资料:

《AutoCAD ObjectARX(VC)开发基础与实例教程》

objectarx用户交互_ObjectARX(C++)-ADSRX和用户交互-用户交互的实现(UserIntereaction)...相关推荐

  1. 移动端业务数据管理平台+健康管理平台+banner管理+图标管理+订单管理+门店内容管理+用户信息管理+版本更新管理Axure通用web端高保真交互app业务数据管理平台

    作品介绍:移动端业务数据管理平台+健康管理平台+banner管理+图标管理+订单管理+闪屏信息管理+门店内容管理+用户信息管理+版本更新管理Axure通用web端高保真交互app业务数据管理平台 ap ...

  2. 交互设计笔记(4)——理解用户:定性研究

    定性研究 只有定性的研究方法才能发掘更深层次的信息 定性研究与定量研究 定性研究的价值 与定量研究相比,定性研究是以一种更有用的更有用的方式帮助我们理解产品的问题领域.情景和约束条件. 他也能很快的帮 ...

  3. linux内核空间和用户空间的是怎样区别的,如何交互,如何从用户空间进入内核空间

    linux驱动程序一般工作在内核空间,但也可以工作在用户空间.下面我们将详细解析,什么是内核空间,什么是用户空间,以及如何判断他们. Linux简化了分段机制,使得虚拟地址与线性地址总是一致,因此,L ...

  4. 用户参与度与活跃度的区别_用户参与度突然下降

    用户参与度与活跃度的区别 disclaimer: I don't work for Yammer, this is a public data case study, I've written it ...

  5. 【用户运营】滴滴出行活动策划、用户成长体系、用户增长逻辑分析

    滴滴出行活动策划.用户成长体系.用户增长逻辑分析 1功能模块分析及产品介绍 1.1功能模块 1.2产品介绍 2活动策划(以愚人节为例) 2.1活动主题 2.2活动目的 2.3活动目标 2.4活动资源 ...

  6. 怎样做好软件用户体验测试,高效地测评软件的用户体验-51Testing.PDF

    高效地测评软件的用户体验-51Testing 高效地测评软件的用户体验-----------.-..-.-..-.--..-----.01 [搜狗测试]小明的测试故事系列----...-------- ...

  7. mysql管理用户数据库_MySQL 数据库管理(一)(用户与受权)

    前言 在企业信息化的过程当中,数据库中库和表都会大量存在,须要分配给管理者核实的权限进行操做 合理地分配权限,可使数据库管理井井有理,各个管理者只须要关注本身负责的内容,也可避免误操做对系统形成损失 ...

  8. 微信小程序云开发用户身份登录_微信小程序开发用户授权登录(下)

    如果开发者拥有多个移动应用.网站应用.和公众帐号(包括小程序),可通过 UnionID 来区分用户的唯一性,因为只要是同一个微信开放平台帐号下的移动应用.网站应用和公众帐号(包括小程序),用户的 Un ...

  9. 问题用户小米科技CEO雷军:千万别把用户当上帝

    查了好多资料,发现还是不全,干脆自己整理吧,至少保证在我的做法正确的,以免误导读者,也是给自己做个记录吧! 小米科技CEO雷军在2013寰球挪动互联网大会(GMIC)上说,"大家想一下我办一 ...

最新文章

  1. SQL 与oracle数据同步之 链接服务器
  2. java框架----commonmark的使用(一)
  3. 计算机粘贴功能不能用了,电脑复制粘贴不能用了【解决办法】
  4. HDU 3094 树上删边 NIM变形
  5. c语言输入字符时控制符%c前加空格的原因解释
  6. 手把手教你做用户画像:3种标签类型、8大系统模块
  7. 第二章 信息的表示和处理
  8. Android 性能优化工具
  9. 【算法】异或 偶数数组中找到一个唯一奇数
  10. 【Axure RP8.1】一款专业的快速原型设计工具
  11. #ifdef 支持Mac #ifndef 支持Windows #if defined (Q_OS_WIN) 应该可以再两个系统通用
  12. IsPostBack结论
  13. httpunit测试遭遇org.mozilla.javascript.NativeGlobal.constructError
  14. 代码自动删除QQ空间里的说说
  15. 数字排列问题(全排例)
  16. ‘数据分析实战’——战略分析案例(某购物商城分析案例)
  17. 封装原生javascript连缀
  18. SystemUI Q 移植到android studio开发
  19. 【操作系统】实验六 系统内存使用统计
  20. CdTe量子点及与牛血清蛋白的偶联/CdTe量子点与CLV3信号多肽片段偶联/GSH-CdTe量子点与溶菌酶的偶联

热门文章

  1. [ JS ] 如何把字符串类型的加减乘除转化成数学运算符?
  2. [操作系统学习笔记]Operating System(三)
  3. IOS 本地推送和远程推送
  4. 搜狗 workflow异步调度框架(二)HTTP客户端
  5. 喜讯:恭喜法大大、爱数、休恩、腾领等多家伙伴通过 SAP 集成方案认证
  6. FFmpeg+SoundTouch实现音频的变调变速
  7. 空间分辨率 密度分辨率 时间分辨率
  8. 颜色怎样搭配最好?网页颜色怎样搭配?
  9. 《Python语言程序设计》——序列习题练习
  10. 数据分析 | SQL基础查询语句+例题详解