Zoom Extents in .Net

2024-06-10 11:32
文章标签 net zoom extents

本文主要是介绍Zoom Extents in .Net,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

原文:来自ADN

缩放模型空间到最合适屏幕,即Zoom E命令

public void SetViewportToExtents(Database db, ViewportTableRecord viewportTableRec) 
{ //lets update the database extents first//true gives the best fit but will take timedb.UpdateExt(true);//get the screen aspect ratio to calculate the height and widthdouble scrRatio = (viewportTableRec.Width / viewportTableRec.Height);//prepare Matrix for DCS to WCS transformationMatrix3d matWCS2DCS = Matrix3d.PlaneToWorld(viewportTableRec.ViewDirection);//for DCS target point is the originmatWCS2DCS = Matrix3d.Displacement(viewportTableRec.Target-Point3d.Origin) * matWCS2DCS; //WCS Xaxis is twisted by twist anglematWCS2DCS = Matrix3d.Rotation(-viewportTableRec.ViewTwist,viewportTableRec.ViewDirection,viewportTableRec.Target) * matWCS2DCS;matWCS2DCS = matWCS2DCS.Inverse();//tranform the extents to the DCS defined by the viewdirExtents3d extents = new Extents3d(db.Extmin, db.Extmax);extents.TransformBy(matWCS2DCS);//width of the extents in current viewdouble width = (extents.MaxPoint.X - extents.MinPoint.X);//height of the extents in current viewdouble height = (extents.MaxPoint.Y - extents.MinPoint.Y);//get the view center pointPoint2d center = new Point2d((extents.MaxPoint.X  + extents.MinPoint.X)*0.5, (extents.MaxPoint.Y  + extents.MinPoint.Y)*0.5);//check if the width 'fits' in current window//if not then get the new height as per the viewports aspect ratioif (width > (height * scrRatio)) height = width / scrRatio;viewportTableRec.Height = height; viewportTableRec.Width = height * scrRatio;viewportTableRec.CenterPoint = center;
}

[CommandMethod("ModelZoomExtents")]
public void ModelZoomExtents()
{Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;using (Transaction Tx = db.TransactionManager.StartTransaction()){ed.UpdateTiledViewportsInDatabase();ViewportTableRecord viewportTableRec = Tx.GetObject(ed.ActiveViewportId, OpenMode.ForWrite) as ViewportTableRecord;SetViewportToExtents(db, viewportTableRec);ed.UpdateTiledViewportsFromDatabase();Tx.Commit();}
}
[CommandMethod("PaperZoomExtents")]
static public void PaperZoomExtents()
{Document doc = Application.DocumentManager.MdiActiveDocument;Database db = doc.Database;Editor ed = doc.Editor;PromptEntityOptions peo = new PromptEntityOptions("\nSelect a viewport: ");peo.SetRejectMessage("\nMust be a viewport...");peo.AddAllowedClass(typeof(Viewport), true);PromptEntityResult per = ed.GetEntity(peo);if (per.Status != PromptStatus.OK) return;using (Transaction Tx = db.TransactionManager.StartTransaction()){Viewport vp = Tx.GetObject(per.ObjectId, OpenMode.ForWrite) as Viewport;db.UpdateExt(true);double scrRatio = (vp.Width / vp.Height);Matrix3d matWCS2DCS = Matrix3d.PlaneToWorld(vp.ViewDirection);matWCS2DCS = Matrix3d.Displacement(vp.ViewTarget-Point3d.Origin) * matWCS2DCS; matWCS2DCS = Matrix3d.Rotation(-vp.TwistAngle,vp.ViewDirection,vp.ViewTarget) * matWCS2DCS;matWCS2DCS = matWCS2DCS.Inverse();Extents3d extents = new Extents3d(db.Extmin, db.Extmax);extents.TransformBy(matWCS2DCS);double width = (extents.MaxPoint.X - extents.MinPoint.X);double height = (extents.MaxPoint.Y - extents.MinPoint.Y);Point2d center = new Point2d((extents.MaxPoint.X  + extents.MinPoint.X)*0.5, (extents.MaxPoint.Y  + extents.MinPoint.Y)*0.5);if (width > (height * scrRatio)) height = width / scrRatio;vp.ViewHeight = height;vp.ViewCenter = center;Tx.Commit();}
}



这篇关于Zoom Extents in .Net的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1048041

相关文章

C#使用Spire.Doc for .NET实现HTML转Word的高效方案

《C#使用Spire.Docfor.NET实现HTML转Word的高效方案》在Web开发中,HTML内容的生成与处理是高频需求,然而,当用户需要将HTML页面或动态生成的HTML字符串转换为Wor... 目录引言一、html转Word的典型场景与挑战二、用 Spire.Doc 实现 HTML 转 Word1

Go语言使用net/http构建一个RESTful API的示例代码

《Go语言使用net/http构建一个RESTfulAPI的示例代码》Go的标准库net/http提供了构建Web服务所需的强大功能,虽然众多第三方框架(如Gin、Echo)已经封装了很多功能,但... 目录引言一、什么是 RESTful API?二、实战目标:用户信息管理 API三、代码实现1. 用户数据

在ASP.NET项目中如何使用C#生成二维码

《在ASP.NET项目中如何使用C#生成二维码》二维码(QRCode)已广泛应用于网址分享,支付链接等场景,本文将以ASP.NET为示例,演示如何实现输入文本/URL,生成二维码,在线显示与下载的完整... 目录创建前端页面(Index.cshtml)后端二维码生成逻辑(Index.cshtml.cs)总结

解决hive启动时java.net.ConnectException:拒绝连接的问题

《解决hive启动时java.net.ConnectException:拒绝连接的问题》Hadoop集群连接被拒,需检查集群是否启动、关闭防火墙/SELinux、确认安全模式退出,若问题仍存,查看日志... 目录错误发生原因解决方式1.关闭防火墙2.关闭selinux3.启动集群4.检查集群是否正常启动5.

解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题

《解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘问题》:本文主要介绍解决未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4... 目录未解析的依赖项:‘net.sf.json-lib:json-lib:jar:2.4‘打开pom.XM

javax.net.ssl.SSLHandshakeException:异常原因及解决方案

《javax.net.ssl.SSLHandshakeException:异常原因及解决方案》javax.net.ssl.SSLHandshakeException是一个SSL握手异常,通常在建立SS... 目录报错原因在程序中绕过服务器的安全验证注意点最后多说一句报错原因一般出现这种问题是因为目标服务器

使用easy connect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题

《使用easyconnect之后,maven无法使用,原来需要配置-Djava.net.preferIPv4Stack=true问题》:本文主要介绍使用easyconnect之后,maven无法... 目录使用easGWowCy connect之后,maven无法使用,原来需要配置-DJava.net.pr

在.NET平台使用C#为PDF添加各种类型的表单域的方法

《在.NET平台使用C#为PDF添加各种类型的表单域的方法》在日常办公系统开发中,涉及PDF处理相关的开发时,生成可填写的PDF表单是一种常见需求,与静态PDF不同,带有**表单域的文档支持用户直接在... 目录引言使用 PdfTextBoxField 添加文本输入域使用 PdfComboBoxField

基于.NET编写工具类解决JSON乱码问题

《基于.NET编写工具类解决JSON乱码问题》在开发过程中,我们经常会遇到JSON数据处理的问题,尤其是在数据传输和解析过程中,很容易出现编码错误导致的乱码问题,下面我们就来编写一个.NET工具类来解... 目录问题背景核心原理工具类实现使用示例总结在开发过程中,我们经常会遇到jsON数据处理的问题,尤其是

Node.js net模块的使用示例

《Node.jsnet模块的使用示例》本文主要介绍了Node.jsnet模块的使用示例,net模块支持TCP通信,处理TCP连接和数据传输,具有一定的参考价值,感兴趣的可以了解一下... 目录简介引入 net 模块核心概念TCP (传输控制协议)Socket服务器TCP 服务器创建基本服务器服务器配置选项服