EaBIM一直以来积极响应国家“十二五”推进建筑业信息化的号召,对建筑领域的信息技术开展深入技术交流和探讨!致力于打造“BIM-建筑师-生态技术”三位一体综合资源交流共享平台,希望为BIM与可持续设计理念及技术的普及做出微小的贡献!!!

EaBIM

 找回密码
 注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

搜索
查看: 988|回复: 14
打印 上一主题 下一主题

[即时预览] 在Jig中检测Shift和Control的按键状态

[复制链接]

1514

主题

7465

帖子

1万

积分

admin

Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10Rank: 10

积分
12404

社区QQ达人

跳转到指定楼层
楼主
发表于 2014-1-8 16:35:57 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
Detecting the use of the shift and control keys during an AutoCAD jig using .NET
Another interesting little problem, that of how to detect the use of  modifier keys during a jig operation (to indicate different jig behaviour). In this case the specific task was to detect the use of the Control and Shift keys, which – if held down during the jig – should cause our object to display differently.
I started with the code from this previous post which uses a DrawJig to place text in the plane of the screen during the jig operation. I initially thought I’d have to use a message filter (as shown in this previous post), but I eventually realised it wasn’t needed: it’s simply a matter of querying the state of System.Windows.Forms.Control.ModifierKeys at the appropriate moment during our WorldDraw().
Here’s the C# code
  • using Autodesk.AutoCAD.ApplicationServices;
  • using Autodesk.AutoCAD.Runtime;
  • using Autodesk.AutoCAD.EditorInput;
  • using Autodesk.AutoCAD.Geometry;
  • using Autodesk.AutoCAD.GraphicsInterface;
  • namespace JigTextPlanarToScreen
  • {
  • public class TextJig : DrawJig
  • {
  • private Point3d _position;
  • public Point3d Position
  • {
  • get { return _position; }
  • }
  • // We'll keep our styles alive rather than recreating them
  • private TextStyle _normal;
  • private TextStyle _highlight;
  • public TextJig()
  • {
  • _normal = new TextStyle();
  • _normal.Font =
  • new FontDescriptor("Calibri", false, true, 0, 0);
  • _normal.TextSize = 10;
  • _highlight = new TextStyle();
  • _highlight.Font =
  • new FontDescriptor("Calibri", true, false, 0, 0);
  • _highlight.TextSize = 14;
  • }
  • protected override SamplerStatus Sampler(JigPrompts prompts)
  • {
  • JigPromptPointOptions opts = new JigPromptPointOptions();
  • opts.UserInputControls =
  • UserInputControls.Accept3dCoordinates |
  • UserInputControls.AcceptMouseUpAsPoint |
  • UserInputControls.GovernedByUCSDetect;
  • opts.Message = "\nSelect point: ";
  • PromptPointResult res = prompts.AcquirePoint(opts);
  • Document doc =
  • Application.DocumentManager.MdiActiveDocument;
  • Editor ed = doc.Editor;
  • if (res.Status == PromptStatus.OK)
  • {
  • if (_position == res.Value)
  • {
  • return SamplerStatus.NoChange;
  • }
  • else
  • {
  • _position = res.Value;
  • return SamplerStatus.OK;
  • }
  • }
  • return SamplerStatus.Cancel;
  • }
  • protected override bool WorldDraw(WorldDraw draw)
  • {
  • // We make use of another interface to push our transforms
  • WorldGeometry wg = draw.Geometry as WorldGeometry;
  • if (wg != null)
  • {
  • // Push our transforms onto the stack
  • wg.PushOrientationTransform(
  • OrientationBehavior.Screen
  • );
  • wg.PushPositionTransform(
  • PositionBehavior.Screen,
  • new Point2d(30, 30)
  • );
  • System.Windows.Forms.Keys mods =
  • System.Windows.Forms.Control.ModifierKeys;
  • // Check whether the shift key is being pressed
  • bool shift =
  • (mods & System.Windows.Forms.Keys.Shift) > 0;
  • // Check whether the control key is being pressed
  • bool control =
  • (mods & System.Windows.Forms.Keys.Control) > 0;
  • // Draw our screen-fixed text
  • wg.Text(
  • new Point3d(0, 0, 0), // Position
  • new Vector3d(0, 0, 1), // Normal
  • new Vector3d(1, 0, 0), // Direction
  • _position.ToString(), // Text
  • true, // Rawness
  • (shift && // Textstyle
  • control ?
  • _highlight : // Highlight if Ctrl-Shift
  • _normal) // Normal, otherwise
  • );
  • // Remember to pop our transforms off the stack
  • wg.PopModelTransform();
  • wg.PopModelTransform();
  • }
  • return true;
  • }
  • [CommandMethod("SELPT")]
  • static public void SelectPointWithJig()
  • {
  • Document doc =
  • Application.DocumentManager.MdiActiveDocument;
  • Editor ed = doc.Editor;
  • TextJig jig = new TextJig();
  • PromptResult res = ed.Drag(jig);
  • if (res.Status == PromptStatus.OK)
  • {
  • ed.WriteMessage(
  • "\nPoint selected: {0}",
  • jig.Position
  • );
  • }
  • }
  • }
  • }

复制代码


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
收藏收藏 转播转播 分享分享 分享淘帖 支持支持 反对反对
工作时间:工作日的9:00-12:00/13:30-18:00,节假日不在线,请勿留言

31

主题

1019

帖子

1897

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1897
6F
发表于 2014-3-14 11:19:09 | 只看该作者
顶...... 楼下跟上.....

4

主题

864

帖子

1390

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1390
11F
发表于 2014-5-13 10:20:47 | 只看该作者
路过!!! 不发表意见……

5

主题

884

帖子

1541

积分

BIM经理

Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6Rank: 6

积分
1541
13F
发表于 2014-5-13 10:26:59 | 只看该作者
(*^__^*) 嘻嘻……
*滑块验证:
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|EaBIM网 ( 苏ICP备2020058923号-1  苏公网安备32011502011255号

GMT+8, 2024-11-23 17:10

Powered by Discuz! X3.2 Licensed

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表