- UID
- 658062
- 积分
- 2147
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2008-10-22
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
选择时增加一个覆盖区域的透明色块
http://spiderinnet1.typepad.com/ ... er-window-pick.html
- #region Namespaces
- using System;
- using Application = Autodesk.AutoCAD.ApplicationServices.Core .Application ;
- using Autodesk.AutoCAD.DatabaseServices;
- using Autodesk.AutoCAD.EditorInput;
- using Autodesk.AutoCAD.Geometry;
- using Autodesk.AutoCAD.GraphicsInterface;
- #endregion
- namespace AcadNetAddinWizard_Namespace
- {
- public class PointCollector2 : IDisposable
- {
- public enum Shape
- {
- Window,
- Fence,
- Polygon,
- RegularPolygon,
- Circle,
- Box,
- }
- private readonly Shape _mShape;
- private Hatch _mTempHatch;
- private readonly short _mHatchColorIndex = 119;
- private byte mHatchTransparency = 50;
- private readonly TransientDrawingMode _mHatchDrawMode;
- private Autodesk.AutoCAD.DatabaseServices.Polyline _mTempPline;
- private short mBoundaryColorIndex = 7;
- private readonly TransientDrawingMode _mBoundaryDrawMode;
- private Point3d _m1StPoint;
- public Point3dCollection CollectedPoints { get; private set; }
- public PromptStatus SelectionStatus { get; private set; }
- public PointCollector2(Shape shape, bool isCrossing)
- {
- _mShape = shape;
- _mTempPline = new Autodesk.AutoCAD.DatabaseServices.Polyline();
- _mTempPline.SetDatabaseDefaults();
- _mTempPline.ColorIndex = mBoundaryColorIndex;
- _mTempHatch = new Hatch();
- _mTempHatch.SetDatabaseDefaults();
- _mTempHatch.ColorIndex = _mHatchColorIndex;
- _mTempHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
- _mTempHatch.Transparency = new Autodesk.AutoCAD.Colors.Transparency(mHatchTransparency);
- _mHatchDrawMode = TransientDrawingMode.Main;
- if (isCrossing)
- {
- _mHatchColorIndex = 119;
- _mBoundaryDrawMode = TransientDrawingMode.Highlight;
- }
- else
- {
- _mHatchColorIndex = 172;
- _mBoundaryDrawMode = TransientDrawingMode.DirectTopmost;
- }
-
- CollectedPoints = new Point3dCollection();
- SelectionStatus = PromptStatus.OK;
- }
- private void Editor_PointMonitor(object sender, PointMonitorEventArgs e)
- {
- Cleanup();
- _mTempPline = new Autodesk.AutoCAD.DatabaseServices.Polyline();
- _mTempPline.SetDatabaseDefaults();
- _mTempPline.ColorIndex = mBoundaryColorIndex;
- _mTempHatch = new Hatch();
- _mTempHatch.SetDatabaseDefaults();
- _mTempHatch.ColorIndex = _mHatchColorIndex;
- _mTempHatch.SetHatchPattern(HatchPatternType.PreDefined, "SOLID");
- _mTempHatch.Transparency = new Autodesk.AutoCAD.Colors.Transparency(mHatchTransparency);
- Point3d compPt = e.Context.ComputedPoint.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem.Inverse());
- if (_mShape == Shape.Window)
- {
- BuildupWindowVertices(_m1StPoint, compPt);
- }
- _mTempPline.TransformBy(Application.DocumentManager.MdiActiveDocument.Editor.CurrentUserCoordinateSystem);
- _mTempHatch.Normal = _mTempPline.Normal;
- HatchLoop loop = new HatchLoop(HatchLoopTypes.Default);
- for (int i = 0; i < _mTempPline.NumberOfVertices; i++)
- {
- loop.Curves.Add(_mTempPline.GetLineSegment2dAt(i));
- }
- _mTempHatch.AppendLoop(loop);
- _mTempHatch.EvaluateHatch(true);
- TransientManager.CurrentTransientManager.AddTransient(_mTempPline, _mBoundaryDrawMode, 0, new IntegerCollection());
- TransientManager.CurrentTransientManager.AddTransient(_mTempHatch, _mHatchDrawMode, 0, new IntegerCollection());
- }
- public Point3dCollection Collect()
- {
- if (_mShape == Shape.Window)
- {
- CollectWindowPoints();
- }
- return CollectedPoints;
- }
- private void CollectWindowPoints()
- {
- PromptPointResult prPntRes1 = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nSpecify first corner");
- if (prPntRes1.Status != PromptStatus.OK)
- {
- SelectionStatus = prPntRes1.Status;
- return;
- }
- _m1StPoint = prPntRes1.Value;
- CollectedPoints.Add(_m1StPoint);
- BuildupWindowVertices(_m1StPoint, _m1StPoint);
- Application.DocumentManager.MdiActiveDocument.Editor.PointMonitor += Editor_PointMonitor;
- PromptPointResult prPntRes2 = Application.DocumentManager.MdiActiveDocument.Editor.GetPoint("\nSpecify opposite corner");
- if (prPntRes2.Status != PromptStatus.OK)
- {
- SelectionStatus = prPntRes2.Status;
- Application.DocumentManager.MdiActiveDocument.Editor.PointMonitor -= Editor_PointMonitor;
- return;
- }
- CollectedPoints.Add(prPntRes2.Value);
- Application.DocumentManager.MdiActiveDocument.Editor.PointMonitor -= Editor_PointMonitor;
- }
- private void BuildupWindowVertices(Point3d corner1, Point3d corner2)
- {
- _mTempPline.Closed = true;
- _mTempPline.AddVertexAt(_mTempPline.NumberOfVertices, new Point2d(corner1.X, corner1.Y), 0, 1, 1);
- _mTempPline.AddVertexAt(_mTempPline.NumberOfVertices, new Point2d(corner2.X, corner1.Y), 0, 1, 1);
- _mTempPline.AddVertexAt(_mTempPline.NumberOfVertices, new Point2d(corner2.X, corner2.Y), 0, 1, 1);
- _mTempPline.AddVertexAt(_mTempPline.NumberOfVertices, new Point2d(corner1.X, corner2.Y), 0, 1, 1);
- }
- public void Dispose()
- {
- Application.DocumentManager.MdiActiveDocument.Editor.PointMonitor -= Editor_PointMonitor;
- Cleanup();
- CollectedPoints.Dispose();
- }
- private void Cleanup()
- {
- if (_mTempPline != null && !_mTempPline.IsDisposed)
- {
- TransientManager.CurrentTransientManager.EraseTransient(_mTempPline, new IntegerCollection());
- _mTempPline.Dispose();
- _mTempPline = null;
- }
- if (_mTempHatch != null && !_mTempHatch.IsDisposed)
- {
- TransientManager.CurrentTransientManager.EraseTransient(_mTempHatch, new IntegerCollection());
- _mTempHatch.Dispose();
- _mTempHatch = null;
- }
- }
- }
- }
测试代码
- [CommandMethod("SelectWindow2", CommandFlags.Modal | CommandFlags.Redraw)]
- public static void SelectWindow2_Method()
- {
- Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
- try
- {
- using (var pc = new PointCollector2(PointCollector2.Shape.Window, false))
- {
- Point3dCollection points = pc.Collect();
- if (pc.SelectionStatus == PromptStatus.OK)
- {
- PromptSelectionResult prSelRes = ed.SelectWindow(points[0], points[1]);
- if (prSelRes.Status == PromptStatus.OK)
- {
- using (SelectionSet ss = prSelRes.Value)
- {
- if (ss != null && ss.Count > 0)
- {
- ed.SetImpliedSelection(ss.GetObjectIds().ToArray());
- }
- }
- }
- }
- }
- }
- catch (System.Exception ex)
- {
- ed.WriteMessage(Environment.NewLine + ex.ToString());
- }
- }
|
|