再谈拖动
www.dimcax.com
再谈拖动
继承 inherits entityjig 可以实现拖动, 继承 inherits drawjig 也可以实现。 以下代码是通过 继承inherits drawjig 实现
imports system
imports autodesk.autocad.runtime
imports autodesk.autocad.editorinput
imports autodesk.autocad.geometry
imports autodesk.autocad.databaseservices
imports autodesk.autocad.graphicsinterface
imports autodesk.autocad.applicationservices
'new class derrived from the drawjig class
public class jigexample
inherits drawjig
private previouscursorposition as point3d
private currentcursorposition as point3d
private entitytodrag as entity
dim ed as editor = application.documentmanager.mdiactivedocument.editor
<commandmethod("test")> _
public sub startjig()
'initialize cursor position
'use the geometry library to create a new 3d point object
previouscursorposition = new point3d(0, 0, 0)
entitytodrag = new circle(new point3d(0, 0, 0), new vector3d(0, 0, 1), 60)
application.documentmanager.mdiactivedocument.editor.drag(me)
end sub
'you must override this method
protected overloads overrides function sampler(byval prompts as jigprompts) as samplerstatus
'get the current cursor position
dim jigopts as new jigpromptpointoptions()
jigopts.userinputcontrols = (userinputcontrols.accept3dcoordinates or userinputcontrols.nozeroresponseaccepted or userinputcontrols.nonegativeresponseaccepted)
jigopts.message = "" & chr(10) & "enter insert point: "
dim userfeedback as promptpointresult = prompts.acquirepoint(jigopts)
currentcursorposition = userfeedback.value
if cursorhasmoved() then
'get the vector of the move
dim displacementvector as vector3d = currentcursorposition.getvectorto(previouscursorposition)
entitytodrag.transformby(matrix3d.displacement(displacementvector))
'save the cursor position
previouscursorposition = currentcursorposition
return samplerstatus.ok
else
return samplerstatus.nochange
end if
end function
dim jj as integer
'you must override this method
protected overloads overrides function worlddraw(byval draw as worlddraw) as boolean
draw.geometry.draw(entitytodrag)
return true
end function
private function cursorhasmoved() as boolean
return not (currentcursorposition = previouscursorposition)
end function
end class
复制代码
说的对,两种方法都行!我个人更喜欢inherits drawjig 。
两个类好像有差别,entityjig可用于自定义实体,文档上是这样说的!如下:
entityjig wraps the acedjig objectarx class. it may be implemented to provide on-screen editing capabilities for an application's custom entities. the entityjig object lets the user manipulate the graphical representation of a custom entity, and then applies the user's input to an actual instance of the entity.
而对drawjig :
drawjig lets the developer create a jig-based object that can be used to draw graphics and get user input independently of a custom entity.
是不是我说的意思,大家讨论讨论!?
.net暂时还不支持自定义实体。
c#最适合开发autocad,因为它拥有vb容易的特点,却具有vc++的强大功能。
恩,是呀,暂时不支持自定义实体,但我前段时间看了看cad dim displacementvector as vector3d = currentcursorposition.getvectorto(previouscursorposition) 这行代码少一个负号。
没有吧,负号放在哪?
用entityjig可以实现的拖动绘制同样可以由drawjig实现,但用drawjig实现的拖动绘制不一定能用entityjig实现。entityjig可以实现一个实体的拖动绘制,drawjig可以实现一个实体和其相关实体(附属子实体或者标注等等)的一并拖动绘制。