标题: [用户交互] 关键字设置 [打印本页] 作者: 萧闫子 时间: 2014-1-8 16:36 标题: [用户交互] 关键字设置 This post extends the polyline-creation jig shown in the previous entry to support the use of keywords both for arc segments and for undo.
A few notes:
I removed the use of a separate vertex list, as it proved to be less necessary than needed
This implementation supports Undo, and the toggling between Line segment and Arc segment entry
Arc segments have a fixed bulge of 1.0, which is actually quite useful if drawing a cloud, but not really useful for much else. Generally the bulge should be adjusted according to the position of the cursor relative to the previous point, which may be something I attempt in a future post
I've also streamlined some of the other parts of code (such as using the basepoint in the jig - which we don't actually need, as we allow the polyline to draw itself)
The code has become quite a bit more complex, and could probably do with some additional performance tuning, but it should allow you to get the idea of what can be done (and one way of approaching it). I should also say that - and this holds true for any of the code samples posted in this blog - it should be thoroughly tested before being integrated into your own application. Hopefully that goes without saying...
Here's the C# code:
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.EditorInput;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.Geometry;
namespace MyPlineApp
{
public class MyPlineCmds
{
class PlineJig : EntityJig
{
// Use a separate variable for the most recent point...
// Again, not strictly necessary, but easier to reference
Point3d m_tempPoint;
Plane m_plane;
bool m_isArcSeg = false;
bool m_isUndoing = false;
// At this stage, weour arc segments will
// have a fixed bulge of 1.0...
// Later we may update the routine to determine
// the bulge based on the relative location
// of the cursor
const double kBulge = 1.0;
public PlineJig(Matrix3d ucs)
: base(new Polyline())
{
// Create a temporary plane, to help with calcs
Point3d origin = new Point3d(0, 0, 0);
Vector3d normal = new Vector3d(0, 0, 1);
normal = normal.TransformBy(ucs);
m_plane = new Plane(origin, normal);
// Create polyline, set defaults, add dummy vertex