要调用ObjectARX Reactors向导,请在解决方案资源管理器中的Step07项目上单击鼠标右键,然后选择Add-> New Item...。这将调用Add New Item对话框,在ObjectARX节点下选择“ Reactors Class Wizard template”。.
步骤7图1-使用Visual Studio
IDE的“添加类”对话框添加ObjectARX
Reactor类
-
这将调用ObjectARX /
DBX Reactors类向导。 键入类名称为AsdkEdEmployeeReactor,请注意文本框中已经存在RDS前缀Asdk。 选择基类为AcEditorReactor.
步骤7图2-使用ObjectARX /
DBX瞬态反应器类向导添加反应器类
-
实现基类AcEditorReactor的以下虚函数.
-
commandWillStart()
-
commandEnded()
要在派生类中实现基类方法,可以遍历所需基类中的方法以标识其方法签名。 然后,可以通过将签名复制到派生类来覆盖派生类中的方法。
要查看基类中可用于重写的各种虚拟方法,请在类视图中右键单击基类,然后选择“转到声明”。
步骤7图3-实现基类方法
然后,您将在基类中看到这些方法。 您可以将要覆盖的方法的方法签名复制到派生类。.
步骤7图4-基类中的虚拟方法
-
将代码添加到commandWillStart()中,以执行以下操作:
-
检查是否已启动命令“ MOVE”,“ ROTATE”,“ STRETCH”,“ SCALE”或“ GRIP_STRETCH”之一(使用字符串比较功能,例如strcmp(),正在使用的当前命令通过参数传递)。
- 如果它是受监视的命令之一,则设置m_editCommand
= true; 和m_doRepositioning = false; (使用DocVars.docData()。<此处为适当的变量>)。
- 将所有objectIds和位置信息(AcDbObjectIdArray
:: setLogicalLength())重置为零.
- 将代码添加到commandEnded()中,以执行以下操作:
-
如果所监视的命令不是上述命令列表中的受监视命令,则将m_editCommand =
false;设置为false。 然后简单地返回.
- 将m_editCommand重置为false.
-
将m_doRepositioning设置为true并开始重新定位移动的对象
- For every object in m_changedObjects (AcDbObjectIdArray::length())
do the following
- Open the entity (acdbOpenObject()).
- If the actual position is different from the stored position,
reposition the object (AcDbBlockReference::position(),
m_employeePositions.at(), AcDbBlockReference::setPosition()).
- Create an AsdkEdEmployeeReactor reactor instance.
- Create a global pointer to your editor reactor. Place this
reactor in the "acrxEntryPoint.cpp" file as
follows:
AsdkEdEmployeeReactor *pEdEmployeeReactor =
NULL; |
- Create an instance of the AsdkEdEmployeeReactor
editor reactor when the application loads, place this in the
On_kInitAppMsg() method of the CStep07App class in acrxEntryPoint.cpp.
pEdEmployeeReactor = new AsdkEdEmployeeReactor(true);//(true)
let the class handle addition and removal from the
acedEditor |
NOTE: Normally when working with transient reactors we
utilize the functions addReactor() and removeReactor()
to place/remove our transient reactors at the appropriate time
during the life of our application. In this particular case the AsdkEdEmployeeReactor
class was generated by the ObjectARX Wizard and the ObjectARX
Wizard delegates the responsibility of adding/removing the AsdkEdEmployeeReactor
to the constructor/destructor of the class respectively, provided
the constructor with the argument "true". See AsdkEdEmployeeReactor.cpp for details. Also
an editor reactor is added only when we load our application and
removed when we unload our application. It is extremely important
to remove your editor reactor if you unload your application.
Failing to do so can cause AutoCAD to crash.
- If the application unloads, delete the editor reactor. Place the
following in the On_kUnloadAppMsg() method of the CStep07App class in
acrxEntryPoint.cpp.
delete pEdEmployeeReactor; |
NOTE: Here we
create a single global instance of AsdkEmployeeReactor (an
AcDbObjectReactor object), as you will see later we attach this
instance to the EMPLOYEE block references. We could also have
created new instances of the AsdkEmployeeReactor and attached each
instance to each EMPLOYEE block reference found. We just want you to
be aware that an AcDbObjectReactor can be attached to more than one
object.
Try to implement all the above functions yourself. Dont forget the
ObjectARX online help for quick reference. If you get stuck, you can open
the Step07 solved project
and study the code in the AsdkEdEmployeeReactor.cpp &
AsdkEdEmployeeReactor.h files of Step07 project.
|