Zoom Extents in .Net

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

本文主要是介绍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

相关文章

Windows中,.net framework 3.5安装

安装.net framework,目前已知2种方法,如下: 一、在MSDN下载对应的安装包,安装,这种可能无法安装成功,概率很大,不成功使用第二种方法,基本上没问题。 二、win8/8.1/10 下安装 .net framework 3.5.1: 1. 打开 win8/8.1/10 安装盘(这里指系统安装镜像文件),提取 sources\sxs 文件夹到 X:\sources\sxs (X代

ASP.Net.WebAPI和工具PostMan

1.WebAPI概述 1.1 WebAPI WebAPI 是一种传统的方式,用于构建和暴露 RESTUI风格的Web服务。它提供了丰富的功能和灵活性,可以处理各种HTTP请求,并支持各种数据格式,如JSON、XML等。 WebAPI使用控制器(Controllers)和动作方法(ActionMethods)的概念、通过路由配置将请求映射到相应的方法上。 开发人员可以使用各种属性和过滤器来处

【ASP.NET】 No 'Access-Control-Allow-Origin' header is present on the requested resource.

前端JS用XMLHttpRequest,请求后端数据。出现了No ‘Access-Control-Allow-Origin’ header is present on the requested resource. 我是使用的ASP.NET框架。 解决办法: 在Web.config文件相应地方添加: <?xml version="1.0" encoding="utf-8"?><confi

论文阅读--Efficient Hybrid Zoom using Camera Fusion on Mobile Phones

这是谷歌影像团队 2023 年发表在 Siggraph Asia 上的一篇文章,主要介绍的是利用多摄融合的思路进行变焦。 单反相机因为卓越的硬件性能,可以非常方便的实现光学变焦。不过目前的智能手机,受制于物理空间的限制,还不能做到像单反一样的光学变焦。目前主流的智能手机,都是采用多摄的设计,一般来说一个主摄搭配一个长焦,为了实现主摄与长焦之间的变焦,目前都是采用数字变焦的方式,数字变焦相比于光学

vue dist文件打开index.html报Failed to load resource: net::ERR_FILE_NOT_FOUND

本地正常。打包好的dist文件打开index.html报Failed to load resource: net::ERR_FILE_NOT_FOUND 解决办法: 在webpack.prod.conf.js 中output添加参数publicPath:’./’ 在webpack.base.conf.js里 publicPath: process.env.NODE_ENV === ‘pro

导入别人的net文件报红问题sdk

1. 使用cmd命令 dotnet --info 查看自己使用的SDK版本 2.直接找到项目中的 global.json 文件,右键打开,直接修改版本为本机的SDK版本,就可以用了

.net 面试题总结(工作经验2年半)

一、Ajax调用的时候,get、post有什么区别? 答:get和post都是向服务器发送一种请求,只是发送机制不同     1 GET请求会将参数跟在URL后进行传递,而POST请求则是作为HTTP消息的实体内容发送给WEB服务器。     2.首先是”GET方式提交的数据最多只能是1024字节”,Post传输的数据量大,可以达到2M。     3.get方式请求数据会被浏览器缓存起来,因此其

.Net Core 学习

1、.Net Core 环境搭建 安装.NET Core:     .NET Core 包括.NET Core Runtime 和 .NET Core SDK: NET Core = 应用运行依赖的 .NET Core RuntimeNET Core SDK = 使用.NET Core开发应用.NET Core Runtime 和 SDK+CLI(Software Developmen

ADO.NET 学习汇总

一、ADO.NET 概要 ADO.NET  是 .NET 框架中的重要组件,主要用于完成C# 应用程序访问数据库。   说明: Connection:连接  ,  Transaction :事务   , Parameters : 参数 Command : 命令  ,SelectCommand 查询命令,InsertCommand 插入命令,UpdateCommand 更新命令

.net平台下深拷贝和浅拷贝(实现ICloneable接口的基础上)

在.net类库中,对象克隆广泛存在于各种类型的实现中,凡是实现了ICloneable接口的类型都具备克隆其对象实例的能力。所以本文讲述的深拷贝和浅拷贝也是在实现ICloneable接口的基础上进行的。 基本概念: 浅拷贝:指对象的字段被拷贝,而字段引用的对象不会被拷贝,拷贝对象和原对象仅仅是引用名称有所不同,但是它们共用一份实体。对任何一个对象的改变,都会影响到另外一个对象。大部分的引用类型,