Bentley二次开发教程27-交互窗口-案例实战1-可视化矩形梁生成工具

server/2024/9/25 11:51:06/

为了展现在MicroStation二次开发中使用WinForm界面控件与MicroStation内的数据交互,这里我们使用三个案例进行展示,分别为可视化矩形梁生成工具,EC属性赋值工具与文件选择复制工具。
在这里插入图片描述

可视化矩形梁生成工具

该工具会根据用户输入的数据实时在Panel中的用户控件中对截面信息进行预览,确定截面信息无误后点击确认会启动交互式工具,根据用户输入的信息生成矩形梁截面,通过交互式工具用户点击的位置确认矩形梁的起点与终点。
该工具涉及到的WinForm控件有:Label,TextBox,Button,Panel,UserControl(用户自定义控件)。
在这里插入图片描述
在这里插入图片描述

using Bentley.DgnPlatformNET;class CreateDimensionCallbacks : DimensionCreateData{private DimensionStyle m_dimStyle;private DgnTextStyle m_textStyle;private Symbology m_symbology;private LevelId m_levelId;private DirectionFormatter m_directionFormatter;public CreateDimensionCallbacks(DimensionStyle dimStyle, DgnTextStyle textStyle, Symbology symb, LevelId levelId, DirectionFormatter formatter){m_dimStyle = dimStyle;m_textStyle = textStyle;m_symbology = symb;m_levelId = levelId;m_directionFormatter = formatter;}public override DimensionStyle GetDimensionStyle(){return m_dimStyle;}public override DgnTextStyle GetTextStyle(){return m_textStyle;}public override Symbology GetSymbology(){return m_symbology;}public override LevelId GetLevelId(){return m_levelId;}public override int GetViewNumber(){return 0;}//此函数返回的旋转矩阵与GetViewRotation返回的旋转矩阵共同声明了尺寸标注元素的方向public override DMatrix3d GetDimensionRotation(){return DMatrix3d.Identity;}public override DMatrix3d GetViewRotation(){return DMatrix3d.Identity;}//用于从数字方向值构造字符串。public override DirectionFormatter GetDirectionFormatter(){return m_directionFormatter;}}
}
namespace WinformUIIntroduction.UI// // textBox2// this.textBox2.Location = new System.Drawing.Point(62, 47);this.textBox2.Name = "textBox2";this.textBox2.Size = new System.Drawing.Size(100, 20);this.textBox2.TabIndex = 2;this.textBox2.Text = "500";this.textBox2.TextChanged += new System.EventHandler(this.textBox2_TextChanged);this.textBox2.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.textBox2_KeyPress);// // button1// this.button1.Font = new System.Drawing.Font("Microsoft YaHei UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));this.button1.Location = new System.Drawing.Point(41, 210);this.button1.Name = "button1";this.button1.Size = new System.Drawing.Size(75, 23);this.button1.TabIndex = 3;this.button1.Text = "确认";this.button1.UseVisualStyleBackColor = true;this.button1.Click += new System.EventHandler(this.button1_Click);// // BeamCreateMenu// this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;this.ClientSize = new System.Drawing.Size(397, 261);this.Controls.Add(this.button1);this.Controls.Add(this.textBox2);this.Controls.Add(this.textBox1);this.Controls.Add(this.label2);this.Controls.Add(this.label1);this.Controls.Add(this.panel_view);this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;this.MaximizeBox = false;this.Name = "BeamCreateMenu";this.ShowIcon = false;this.Text = "BeamCreateMenu";this.TopMost = true;this.ResumeLayout(false);this.PerformLayout();}#endregionprivate System.Windows.Forms.Panel panel_view;private System.Windows.Forms.Label label1;private System.Windows.Forms.Label label2;private System.Windows.Forms.TextBox textBox1;private System.Windows.Forms.TextBox textBox2;private System.Windows.Forms.Button button1;}
}
extern alias dgnDisplayAlias;
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using dgnDisplayAlias::Bentley.DgnPlatform;namespace WinformUIIntroduction.UI
{public partial class PreviewPanel : UserControl{private readonly dgnDisplayAlias::Bentley.DgnPlatform.PreviewControl mPreviewControl;public PreviewPanel(Bentley.DgnPlatformNET.DgnModelRef modelRef){InitializeComponent();unsafe{this.mPreviewControl =new dgnDisplayAlias::Bentley.DgnPlatform.PreviewControl((dgnDisplayAlias::Bentley.DgnPlatform.DgnModel*)modelRef.GetDgnModel().GetNative());}this.mPreviewControl.ActivatePanTool();this.mPreviewControl.PreviewControlOptions.IsFitToolVisible = true;this.mPreviewControl.PreviewControlOptions.IsPanToolVisible = true;this.mPreviewControl.PreviewControlOptions.IsViewingToolsVisible = true;this.mPreviewControl.PreviewControlOptions.IsZoomToolsVisible = true;this.mPreviewControl.PreviewControlOptions.IsRotationToolVisible = true;this.mPreviewControl.IsEnabled = true;this.mPreviewControl.IsManipulationEnabled = true;this.mPreviewControl.PreviewControlOptions.RotationMode = RotationMode.Top;this.mPreviewControl.PreviewControlOptions.RenderMode = RenderMode.FilledVisibleEdge;ElementHost elementHost = new ElementHost();elementHost.Dock = DockStyle.Fill;elementHost.Child = this.mPreviewControl;this.Controls.Add(elementHost);}public void ShowPreview(Bentley.DgnPlatformNET.Elements.Element ele){Bentley.DgnPlatformNET.ElementAgenda agenda = new Bentley.DgnPlatformNET.ElementAgenda();if (ele != null){agenda.Insert(ele, true);}this.mPreviewControl.ShowPreview(agenda);}}
}
using Bentley.DgnPlatformNET;else{EndDynamics();//关闭动态绘制m_pos.Clear();//清空列表                }return true;}protected override void OnDynamicFrame(DgnButtonEvent ev)//动态绘制时触发{ShapeElement m_beamProfile = CreateBeamProfile(m_pos[0]);//创建形元素用于确定梁截面Element element = CreateSolidElement(m_pos[0], ev.Point,m_beamProfile);//创建梁实体元素if (null == element)//若未成功生成梁实体元素return;//返回DynamicDrawElems(element);//动态绘制元素            }private ShapeElement CreateBeamProfile(DPoint3d startPo)//创建用于表达梁截面的形元素{DPoint3d[] pos ={new DPoint3d(startPo.X-0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z),new DPoint3d(startPo.X-0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z-1*UI.BeamCreateMenu.m_height*m_uorPerMilliMeter),new DPoint3d(startPo.X+0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z-1*UI.BeamCreateMenu.m_height*m_uorPerMilliMeter),new DPoint3d(startPo.X+0.5*UI.BeamCreateMenu.m_width*m_uorPerMilliMeter,startPo.Y,startPo.Z)};//确定梁截面端点坐标集ShapeElement beamProfile = new ShapeElement(m_dgnModel,null,pos);//创建表达梁截面的形元素return beamProfile;//返回梁截面的形元素}private void DynamicDrawElems(Element element){RedrawElems redrawElems = new RedrawElems();//使用元素用于动态绘制redrawElems.SetDynamicsViewsFromActiveViewSet(Session.GetActiveViewport());//设置视角redrawElems.DrawMode = DgnDrawMode.TempDraw;//设置绘制模式redrawElems.DrawPurpose = DrawPurpose.Dynamics;//设置绘制目标redrawElems.DoRedraw(element);//使用元素用于动态绘制}private Element CreateSolidElement(DPoint3d startPo, DPoint3d endPo, ShapeElement beamProfile){DVector3d vector = new DVector3d(startPo, endPo);//声明梁方向向量if (vector == DVector3d.Zero)//判断是否成功获取{return null;//返回空}           TransformInfo trans = new TransformInfo(DTransform3d.FromRotationAroundLine(startPo, DVector3d.UnitZ, vector.Rotate90CCWXY().AngleXY));//声明变换信息beamProfile.ApplyTransform(trans);//对形元素施加变换Element solid = SolidElement.CreateProjectionElement(m_dgnModel, null, beamProfile, startPo, vector, DTransform3d.Identity, true);//创建拉伸实体return solid;//返回拉伸实体}private void CreateBeamElem(){ShapeElement beamProfile= CreateBeamProfile(m_pos[0]);//创建表达梁截面的形元素Element element = CreateSolidElement(m_pos[0], m_pos[1], beamProfile);//创建拉伸元素element.AddToModel();//将拉伸元素写入模型}}
}

在这里插入图片描述


http://www.ppmy.cn/server/22247.html

相关文章

《Fundamentals of Power Electronics》——Buck、Boost、Buck-Boost三个电路的CCM-DCM工作特性总结

Buck、Boost、Buck-Boost这三个电路的CCM-DCM工作特性总结如下表所示: Buck、Boost、Buck-Boost这三个电路工作在DCM模式下电压传输比的对比图如下所示: 由上图可知,Buck-Boost电路的工作特性是一条斜率为的直线,Buck电路和Boost电…

ArcGIS Pro3.0软件破解版安装教程

软件名称:ArcGIS Pro 3.0 安装环境:Windows 软件大小:7.3GB 硬件要求:CPU2GHz,内存4G(或更高) 百度云下载链接 : https://pan.baidu.com/s/1CXy1MSwdQXdVnJoV2X422A 提 取 码 :r0w1 教学内…

Pandas 2.2 中文官方教程和指南(二十五·一)

原文:pandas.pydata.org/docs/ 食谱 原文:pandas.pydata.org/docs/user_guide/cookbook.html 这是一个简短而精炼的示例和链接存储库,包含有用的 pandas 示例。我们鼓励用户为此文档添加内容。 在这一部分添加有趣的链接和/或内联示例是一个…

分布式与一致性协议之Raft算法(一)

Raft算法 概述 Raft算法属于Multi-Paxos算法,它在兰伯特Multi-Paxos思想的基础上做了一些简化和限制,比如日志必须是连续的,只支持领导者(Leader)、跟随者(Follwer)和候选人(Candidate)3种状态。在理解和算法实现上,Raft算法相对…

(十)Servlet教程——HttpServletRequest接口

1. 知识准备 HttpServletRequest对象 浏览器访问网页的时候通过HTTP协议访问服务器上的静态资源或者接口服务,Servlet可以充当接口服务。当Servlet接收到来自浏览器的请求后会生成HttpServletRequest和HttpServletResponse来处理该请求。 公共接口类HttpServletReq…

MySql: 可视化工具监测管理数据库

Navicat 官网 Navicat 也可以从网盘中下载 链接: https://pan.baidu.com/s/1gawJN5d4_eBSQiZaFeNMSA 提取码: 33bd

Django之搭配内网穿透

一,安装coplar 二,开启8087的内网穿透 三,setting.py中加入如下配置: ALLOWED_HOSTS [*]CSRF_TRUSTED_ORIGINS ["https://localhost:8087", "http://localhost:8087"]四,启动项目 五&#xff…

【并行计算】【《云计算与分布式系统·从并行处理到物联网》笔记】第一章:分布式系统模型和关键技术

文章目录 [toc]1.1|互联网之上的可扩展计算互联网计算的时代高性能计算高吞吐量计算三种新的计算范式 可扩展性计算趋势和新的范式并行度 物联网和CPS物联网信息物理融合系统CPS 个人主页:丷从心 系列专栏:计算机网络 1.1|互联网之上的可扩展计算 互联…