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 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();
    }
}



### Oracle `DBA_EXTENTS` 视图解析 #### 结构 `DBA_EXTENTS` 描述了数据库中所有表空间内段的扩展信息。此视图包含了多个字段,这些字段提供了关于各个段及其所在位置的具体细节[^1]。 - **TABLESPACE_NAME**: 表空间名称。 - **SEGMENT_NAME**: 段名。 - **OWNER**: 所有者用户名。 - **EXTENT_ID**: 扩展编号,在同一段内的唯一标识符。 - **FILE_ID**: 数据文件号。 - **BLOCK_ID**: 起始块号。 - **BYTES**: 占用字节数量。 - **BLOCKS**: 包含的数据块数量。 ```sql SELECT * FROM dba_extents WHERE rownum < 5; ``` 上述SQL语句可以用来查看前几条记录的内容,帮助理解该视图的实际布局和数据形式。 #### 用途 主要用于管理和监控Oracle数据库中的存储分配情况。通过查询这个视图,管理员能够获取有关特定对象(如表、索引等)所占用的空间分布的信息。这对于识别潜在的空间浪费以及优化磁盘利用率非常有用[^3]。 当涉及到具体的应用场景时: - 可以评估某个模式下的所有对象占用了多少物理空间; - 查找哪些大对象可能需要重新组织来释放未使用的空间; - 定位到具体的文件和块地址以便于更精细的操作,比如迁移或备份指定范围的数据。 需要注意的是,如果某些数据文件被设置为离线状态,则对应的记录不会出现在查询结果里,因为只有在线的数据文件才能提供有效的元数据访问。 #### 空间管理实践 由于直接查询 `DBA_EXTENTS` 的性能可能会比较低效[^4],因此建议采用一些策略提高效率并简化日常维护工作: - 使用合适的过滤条件缩小检索范围,减少不必要的扫描开销; - 创建辅助性的汇总统计表格定期更新,供快速查阅之用; - 利用分区技术将大型表分割成较小的部分处理,从而加快局部区域上的操作速度; 另外,还可以考虑利用其他相关联的动态性能视图(如 `V$SORT_SEGMENT`, `GV$TEMPORARY_LOBS`) 来补充和完善整体的空间分析视角。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值