Zoom Extents in .Net

翻译 2013年12月06日 17:04:33

原文:来自ADN

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

public void SetViewportToExtents(Database db, ViewportTableRecord viewportTableRec) 
{ 
    //lets update the database extents first
    //true gives the best fit but will take time
    db.UpdateExt(true);

    //get the screen aspect ratio to calculate the height and width
    double scrRatio = (viewportTableRec.Width / viewportTableRec.Height);

    //prepare Matrix for DCS to WCS transformation
    Matrix3d matWCS2DCS = Matrix3d.PlaneToWorld(viewportTableRec.ViewDirection);
    
    //for DCS target point is the origin
    matWCS2DCS = Matrix3d.Displacement(viewportTableRec.Target-Point3d.Origin) * matWCS2DCS; 
    
    //WCS Xaxis is twisted by twist angle
    matWCS2DCS = Matrix3d.Rotation(-viewportTableRec.ViewTwist,
                                    viewportTableRec.ViewDirection,
                                    viewportTableRec.Target) 
                                    * matWCS2DCS;
        
    matWCS2DCS = matWCS2DCS.Inverse();

    //tranform the extents to the DCS defined by the viewdir
    Extents3d extents = new Extents3d(db.Extmin, db.Extmax);
    extents.TransformBy(matWCS2DCS);

    //width of the extents in current view
    double width = (extents.MaxPoint.X - extents.MinPoint.X);

    //height of the extents in current view
    double height = (extents.MaxPoint.Y - extents.MinPoint.Y);

    //get the view center point
    Point2d 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 ratio
    if (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();
    }
}



相关文章推荐

[转]推荐net开发cad入门阅读代码片段

原文:http://www.cnblogs.com/cadlife/articles/2668158.html using System; using System.Collections.Gene...

Windows Phone 7 - Image加上Zoom in/out功能 缩放功能

Windows Phone 7 - Image加上Zoom in/out功能   最近不小心迷上用手機看漫畫這件事,所以想說寫一個自己的漫畫程式,這樣可以選擇自己覺得 取得圖像資料比較快且穩定的...

AngryBird简单开发实现(二),zoom in/out的实现以及镜头跟随效果

上一篇简单的实现了AngryBird的发射和碰撞检测功能,下面着手解决屏幕的缩放功能以及小鸟发射后镜头跟随的效果。 先上成品截图: 1.zoom in状态 2.zoom out状态 3...

Controlling text size in Safari for iOS without disabling user zoom

The default viewport settings – the size and scale of the viewport – in Mobile Safari/Safari for i...

Angularjs2+ASP.NET MVC Core in Visual Studio 2015开发环境安装说明

安装准备首先安装asp.net mvc core项目模板,没有安装之前创建项目的时候看到的是这个样子 点击确定即可开始下载安装包,写此文章的时候自动下载的版本是 DotNetCore.1.0.1-...

ASP.NET MVC 3: New @model keyword in Razor

使用Razor的@model指令,获取后台实体、集合  New @model directive Let’s now look at a new feature we added with the...

hive启动报错 java.net.URISyntaxException: Relative path in absolute URI: ${system:java.io.tmpdir%7D/$%7B

启动hive报错: [root@master conf]# hive Logging initialized using configuration in file:/usr/local/hi...

Using WebSocket in .NET 4.5 (Part 1)

In this serial of articles, I will share some knowledge I leart recently in using WebSocket in .NET ...
  • pkudzy
  • pkudzy
  • 2013-07-08 15:54
  • 2177

创建联动的 DropdownList in ASP.net MVC 3 and jQuery (2)

1. AjaxBindDropdownlistController.cs using System; using System.Collections.Generic; using Syst...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:深度学习:神经网络中的前向传播和反向传播算法推导
举报原因:
原因补充:

(最多只允许输入30个字)