c#+CAD动态移动效果
public class MoveRotateScaleJig : DrawJig
{
public static List<Entity> entities = new List<Entity>();
private int step = ;
private int totalStepNum = ; public Point3d moveStartPnt;
public static Point3d moveEndPnt;
public Double rotateAngle;
public Double scaleFactor; public MoveRotateScaleJig(Point3d basePnt)
{
moveStartPnt = basePnt;
moveEndPnt = moveStartPnt;
rotateAngle = ;
scaleFactor = ;
} public Matrix3d Transformation
{
get
{
return Matrix3d.Scaling(scaleFactor, moveEndPnt).
PostMultiplyBy(Matrix3d.Rotation(rotateAngle, Vector3d.ZAxis, moveEndPnt)).
PostMultiplyBy(Matrix3d.Displacement(moveStartPnt.GetVectorTo(moveEndPnt)));
}
} public void AddEntity(Entity ent)
{
entities.Add(ent);
} public void TransformEntities()
{
Matrix3d mat = Transformation;
foreach (Entity ent in entities)
{
ent.TransformBy(mat);
}
} protected override bool WorldDraw(Autodesk.AutoCAD.GraphicsInterface.WorldDraw draw)
{
Matrix3d mat = Transformation; WorldGeometry geo = draw.Geometry;
if (geo != null)
{
geo.PushModelTransform(mat); foreach (Entity ent in entities)
{
geo.Draw(ent);
} geo.PopModelTransform();
} return true;
} protected override SamplerStatus Sampler(JigPrompts prompts)
{
switch (step)
{
case :
JigPromptPointOptions prOptions1 = new JigPromptPointOptions("\n目标点:");
prOptions1.UserInputControls = UserInputControls.GovernedByOrthoMode
| UserInputControls.GovernedByUCSDetect;
PromptPointResult prResult1 = prompts.AcquirePoint(prOptions1);
if (prResult1.Status != PromptStatus.OK)
return SamplerStatus.Cancel; if (prResult1.Value.Equals(moveEndPnt))
{
return SamplerStatus.NoChange;
}
else
{
moveEndPnt = prResult1.Value;
return SamplerStatus.OK;
} case :
JigPromptAngleOptions prOptions2 = new JigPromptAngleOptions("\nRotate:");
prOptions2.UseBasePoint = true;
prOptions2.BasePoint = moveEndPnt;
prOptions2.UserInputControls = UserInputControls.GovernedByOrthoMode
| UserInputControls.GovernedByUCSDetect;
PromptDoubleResult prResult2 = prompts.AcquireAngle(prOptions2);
if (prResult2.Status != PromptStatus.OK)
return SamplerStatus.Cancel; if (prResult2.Value.Equals(rotateAngle))
{
return SamplerStatus.NoChange;
}
else
{
rotateAngle = prResult2.Value;
return SamplerStatus.OK;
} case :
JigPromptDistanceOptions prOptions3 = new JigPromptDistanceOptions("\nScale:");
prOptions3.UseBasePoint = true;
prOptions3.BasePoint = moveEndPnt;
prOptions3.UserInputControls = UserInputControls.GovernedByOrthoMode
| UserInputControls.GovernedByUCSDetect;
PromptDoubleResult prResult3 = prompts.AcquireDistance(prOptions3);
if (prResult3.Status != PromptStatus.OK)
return SamplerStatus.Cancel; if (prResult3.Value.Equals(scaleFactor))
{
return SamplerStatus.NoChange;
}
else
{
scaleFactor = prResult3.Value;
return SamplerStatus.OK;
} default:
break;
} return SamplerStatus.OK;
} public static bool Jig()
{
try
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database; // 选择对象
PromptSelectionResult selRes = doc.Editor.GetSelection();
if (selRes.Status != PromptStatus.OK)
return false; // 指定起点
PromptPointResult ppr = doc.Editor.GetPoint("\nStart point:");
if (ppr.Status != PromptStatus.OK)
return false;
Point3d basePnt = ppr.Value;
basePnt = basePnt.TransformBy(doc.Editor.CurrentUserCoordinateSystem); // Draw Jig
MoveRotateScaleJig jig = new MoveRotateScaleJig(basePnt);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
foreach (ObjectId id in selRes.Value.GetObjectIds())
{
Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
jig.AddEntity(ent);
} // Draw Jig 交互
PromptResult pr;
do
{
pr = doc.Editor.Drag(jig);
if (pr.Status == PromptStatus.Keyword)
{
// Keyword handling code
}
else
{
jig.step++;
}
}
while (pr.Status == PromptStatus.OK
&& jig.step <= jig.totalStepNum); // 结果
if (pr.Status == PromptStatus.OK &&
jig.step == jig.totalStepNum + )
{
jig.TransformEntities();
}
else
{
return false;
} tr.Commit();
return true;
}
}
catch
{
return false;
}
} public static bool JigMove()
{
try
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database; //// 选择对象
//PromptSelectionResult selRes = doc.Editor.GetSelection();
//if (selRes.Status != PromptStatus.OK)
// return false; // 指定起点
PromptPointResult ppr = doc.Editor.GetPoint("\n指定起点:");
if (ppr.Status != PromptStatus.OK)
return false;
Point3d basePnt = ppr.Value;
basePnt = basePnt.TransformBy(doc.Editor.CurrentUserCoordinateSystem); // Draw Jig
MoveRotateScaleJig jig = new MoveRotateScaleJig(basePnt);
using (Transaction tr = db.TransactionManager.StartTransaction())
{
//foreach (ObjectId id in selRes.Value.GetObjectIds())
//{
// Entity ent = (Entity)tr.GetObject(id, OpenMode.ForWrite);
//} // Draw Jig 交互
PromptResult pr;
do
{
pr = doc.Editor.Drag(jig);
if (pr.Status == PromptStatus.Keyword)
{
// Keyword handling code
}
else
{
for (int i = ; i < entities.Count;i++ )
{
Entity ent = tr.GetObject(entities[i].ObjectId, OpenMode.ForWrite) as Entity;
AcEdPublicDll.CAcadEntity.Move(ent, basePnt, moveEndPnt);
ent.Dispose();
}
}
}
while (pr.Status != PromptStatus.OK);
tr.Commit();
return true;
}
}
catch
{
return false;
}
}
}
调用:MoveRotateScaleJig.Jig()
c#+CAD动态移动效果的更多相关文章
- Canvas之动态波浪效果_陈在真Sunny_chen_新浪博客
Canvas之动态波浪效果_陈在真Sunny_chen_新浪博客 Canvas之动态波浪效果 (2012-04-26 09:04:51) 转载▼
- Android SurfaceView实现静态于动态画图效果
本文是基于Android的SurfaceView的动态画图效果,实现静态和动态下的正弦波画图,可作为自己做图的简单参考,废话不多说,先上图, 静态效果: 动态效果: 比较简单,代码注释的也比较详细,易 ...
- 在WPF中使用PlaneProjection模拟动态3D效果
原文:在WPF中使用PlaneProjection模拟动态3D效果 虽然在WPF中也集成了3D呈现的功能,在简单的3D应用中,有时候并不需要真实光影的3D场景.毕竟使用3D引擎会消耗很多资源,有时候使 ...
- OpenGL 画出雷达动态扫描效果(二) 非底图
OpenGL 画出雷达动态扫描效果(一)中给出了已一张图片作为底图的雷达扫面程序 如果有漂亮的雷达底图的话,效果应该非常不错的,另外也可以直接手绘雷达框架 效果如下 雷达主体代码 glLineWidt ...
- Android自定义控件 -Canvas绘制折线图(实现动态报表效果)
有时候我们在项目中会遇到使用折线图等图形,Android的开源项目中为我们提供了很多插件,但是很多时候我们需要根据具体项目自定义这些图表,这一篇文章我们一起来看看如何在Android中使用Canvas ...
- 9种纯CSS3人物信息卡片动态展示效果
<!DOCTYPE html> <html lang="zh"> <head> <meta charset="UTF-8&quo ...
- JavaScript实现动态打字效果
废话不多说,上代码~~ <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...
- android优化中国风应用、完整NBA客户端、动态积分效果、文件传输、小说阅读器等源码
Android精选源码 android拖拽下拉关闭效果源码 一款优雅的中国风Android App源码 EasySignSeekBar一个漂亮而强大的自定义view15 android仿蘑菇街,蜜芽宝 ...
- 前端开发---ppt展示页面评论区支持动态交互效果
1. 工程地址:https://github.com/digitalClass/web_page 网站发布地址: http://115.28.30.25:8029/ 2. 用到的技术主要还是jquer ...
随机推荐
- D1——初读《Head First Java》
今天随便看了点<Head First Java>,发觉这本书的风格真是有趣.打算先把这本书踏踏实实的看了.学习切忌好高骛远.心浮气躁,尤其入门基础阶段更应该踏踏实实地学习知识.下面随便谈谈 ...
- python request 和requests 的区别
说明: 这里主要记录一下requests模块的如下几点: 1.requests模块的安装 2.requests模块发送get请求 3.requests模块发送post请求 4.requests模块上传 ...
- 测试那些事儿-软测必备的linux知识(五)
1.进程管理 1.1进程概述 在Linux中,每个执行的程序都称为一个进程,每个进程都分配一个ID号 每个进程,都会对应一个父进程,这个父进程可以复制多个子进程, 每个进程可能以两种方式存在,前台与后 ...
- Python:从入门到实践--第三章--列表简介--练习
#1.将一些朋友的姓名存储在一个列表中,并将其命名为friends.依次访问该列表中的每个元素,从而将每个朋友的姓名都打印出来. #2.继续使用1中的列表,为每人打印一条消息,每条消息包含相同的问候语 ...
- python 三种 安装包的方法
1.pycharm安装第三方库 然后点+搜索库安装. 注意 : 有时候点+会出现下图提示:Nothing to show,这就需要在点加号前点一下绿色圈圈的conda标志. 点+号出现下图的内容才是正 ...
- input date 赋值的坑及改变时如何获取 input date的值
- 《Java核心技术(卷一)》读书笔记——第六章:内部类
1. 内部类的概念? 类中类 2. 为什么要用内部类? 内部类的方法可以访问外部类的实例域 内部类对外部类的同一个包中的类实现了隐藏 匿名内部类在“想要定义一个回调函数却又不想编写 ...
- Python 限制线程的最大数量(Semaphore)
import threadingimport time sem = threading.Semaphore(4) # 限制线程的最大数量为4个 def gothread(): with sem: # ...
- Oracle Base64加解密
参考 http://blog.csdn.net/liuzhigang1237/article/details/7591439
- Yii2.0 RESTful API 基础配置教程
创建api应用 通过拷贝原有的应用,重命名得到新的应用 安装完 Composer,运行下面的命令来安装 Composer Asset 插件: php composer.phar global req ...