Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
中国BDN社区
  • Welcome to Bentley Communities
  • Bentley's Communities
  • 中国BDN社区
  • Cancel
中国BDN社区
中国BDN社区-威客 如何在视窗内添加自定义装饰
    • Sign In
    • 中国BDN社区-威客
    • -iTwin.js编程
      • iModel.js Front-End简介
      • iModel.js 样例项目配置与运行
      • iModel.js.UI开发基本介绍
      • iModel.js前端统一选择一致性机制
      • iModel.js基本查询
      • iModel.js若干前端功能开发样例
      • imodel图形显示简单介绍
      • iModel文件的合并等操作
      • Redux基本使用
      • simple-viewer-app源码简单分析
      • TypeScript基本介绍及环境配置
      • 下载视口截图
      • 关于imodel测量单位的转换
      • 关于如何导入与导出imodel中schema文件
      • 基于PresentationRules个性化显示iModel的内容
      • 如何在视窗内添加自定义装饰
      • 如何将2个bim中的图形模型显示在一个视图中
      • 用户选择保存感兴趣的视图
    • +MicroStation CONNECT版SDK的新变化
    • +MicroStation编程技巧
    • +OpenRoads中国版平台开发指南
    • +ORD SDK二次开发编程
    • +一步步学习ABD-CE开发
    • +一步步学习MicroStation CE Addin开发
    • 一步步学习MicroStation CE MDL开发
    • +一步步学习ProjectWise编程
    • 中国优先社区二次开发精华帖汇总
    • +学习Microstation交互式工具开发
    • +过期帖,留存仅供参考
    • +非Bentley社区分享的文章
    • C#、C/C++相关的编程知识汇总

     
     Questions about this article, topic, or product? Click here. 

    如何在视窗内添加自定义装饰

    如何在视窗内添加自定义装饰

    基本使用

    Imodel.js可以在前端视窗内添加/删除用户自定义装饰(Decorator)。其类层次如下所示:

    其中AccuSnap,HyperModelingDecorator是imodel.js系统预定义的装饰(Decorator),CustomDecorator是用户自定义装饰(Decorator),也就说用户至少需要实现接口Decorator中的decorate(context: DecorateContext): void方法即可实现自己的装饰(Decorator)。然后创建CustomDecorator的实例customDecorator,并调用:IModelApp.viewManager.addDecorator(customDecorator);即可将自定义装饰(Decorator)显示在视窗上,同时调用IModelApp.viewManager.dropDecorator(d)可将自定义装饰(Decorator)从视窗上删除。

    示例

    希望在视窗上显示一个用户自定义三角形,效果如下所示:

    使用以下代码即可实现:

    class CustomDecorator implements Decorator {
      public decorate(context: DecorateContext) {
        // draw semi-transparent polyline from top left to bottom right of vp
        const overlayBuilder = context.createGraphicBuilder(
          GraphicType.ViewOverlay
        );
        const polylineColor = ColorDef.from(0, 255, 0, 128);
        overlayBuilder.setSymbology(polylineColor, polylineColor, 10);
        const ps: Point3d[] = [
          new Point3d(100, 0, 0),
          new Point3d(100, 500, 0),
          new Point3d(500, 500, 0),
          new Point3d(100, 0, 0),
        ];
        overlayBuilder.addShape(ps);
        context.addDecorationFromBuilder(overlayBuilder);
      }
    }
    
    const cd = new CustomDecorator();
    //添加装饰
    IModelApp.viewManager.addDecorator(cd);
    //删除装饰
    IModelApp.viewManager.dropDecorator(cd);

    原理

    IModelApp.viewManager维护着一个Decorator[]数组,每当显式调用:IModelApp.viewManager.addDecorator或IModelApp.viewManager.dropDecorator的时候遍历标记所有viewport中的_decorationsValid为无效(异常情况下不会触发此标记),然后主动调用IModelApp.requestNextAnimation()以更新帧,因为此时_decorationsValid已经被标记为无效,所以会将IModelApp.viewManager维护者的Decorator[]数组中的所有内容更新到窗口上。注意,通过IModelApp.viewManager.addDecorator添加的装饰(Decorator)会在所有的ViewState的视窗上出现。

    其大概流程如下所示:

    • Share
    • History
    • More
    • Cancel
    • Devin Liu Created by Devin Liu
    • When: Wed, Sep 2 2020 5:20 AM
    • Devin Liu Last revision by Devin Liu
    • When: Fri, Sep 4 2020 12:00 AM
    • Revisions: 6
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies