using DevExpress.XtraBars; using DevExpress.XtraEditors; using Hydro; using MathNet.Numerics; using MathNet.Numerics.LinearAlgebra.Double; using System.ComponentModel; using System.Data; using System.Drawing.Imaging; using System.Globalization; using System.IO; using System.Text; using Yw.WinFrmUI; using static Hydro.MapViewEnum; namespace PBS.WinFrmUI.Hydro { public partial class TemplateMgr : DocumentPage { public TemplateMgr() { this.PageTitle.Caption = "模板管理"; InitializeComponent(); this.treeList1.Columns.Add(new DevExpress.XtraTreeList.Columns.TreeListColumn { FieldName = "Name", Caption = "所有模板", Width = 170, VisibleIndex = 0 }); //this.propertyForm1.propertyGrid.OptionsBehavior.Editable = true; this.selectBackgroundImageCtrl1.CancleEvent += SelectBackgroundImageCtrl1_CancleEvent; this.selectBackgroundImageCtrl1.ApplyDataEvent += SelectBackgroundImageCtrl1_ApplyDataEvent; this.selectBackgroundImageCtrl1.ConfirmDataEvent += SelectBackgroundImageCtrl1_ConfirmDataEvent; InitTreeList(); } private void SelectBackgroundImageCtrl1_ConfirmDataEvent(object sender, SelectBackgroundImageCtrl e) { SetMapBackground(e.PicPath, e.BackGroundImgWidth, e.BackGroundImgHeight); //throw new NotImplementedException(); } private void SelectBackgroundImageCtrl1_ApplyDataEvent(object sender, SelectBackgroundImageCtrl e) { SetMapBackground(e.PicPath, e.BackGroundImgWidth, e.BackGroundImgHeight); //throw new NotImplementedException(); } private void SetMapBackground(string backgroundUrl, float width, float height) { map.mapOption.isShowPic = true; map.mapOption.isAutoBackgroundImage = true; var img = Image.FromFile(backgroundUrl); var imgWidth = img.Width; var imgHeight = img.Height; var w = imgWidth / width; var h = imgHeight / height; var zoom = w > h ? w : h; map.MapCenter = map.mapOption.Center = new PointF(width / 2, height / 2); map.zoom = map.mapOption.zoom = zoom; var temp = map._Template; File.Copy(backgroundUrl, temp.BackGroundImg_FullPath, true); temp.BackGroundImg_FullPath = temp.BackGroundImg_FullPath; temp.BackGroundImgWidth = width; temp.BackGroundImgHeight = height; temp.BackGroundImgRotaAngle = 0; temp.BackGroundPoint1 = new PointF(0, 0); map._Template = temp; //map.SetData(template); map.SetMapInvalidate(); } private void SelectBackgroundImageCtrl1_CancleEvent(object sender, EventArgs e) { this.dockPanel1.Visibility = DevExpress.XtraBars.Docking.DockVisibility.Hidden; } private List modelTemplates = new List(); private MapViewer map; private void InitTreeList() { var data = GetData(); modelTemplates = data; var ds = new List(); if (combobox_type.SelectedItem != null) { TemplateType selectedType = (TemplateType)Enum.Parse(typeof(TemplateType), combobox_type.SelectedItem.ToString()); ds = selectedType == TemplateType.全部 ? modelTemplates : modelTemplates.Where(c => c.TemplateType == (int)selectedType || c.ID == 0).ToList(); } else ds = data; this.treeList1.DataSource = ds; this.treeList1.RefreshDataSource(); } public override void RefreshData() { GlobalObject.PropertyForm = this.propertyForm1; GlobalObject.map = this.map; } private List GetData() { return Task.Run(async () => await new PBS.BLL.ModelTemplate().GetAll()).Result; } private void TemplateMgr_Load(object sender, EventArgs e) { map = new MapViewer(); map.Lock2DView = true; map.Location = new System.Drawing.Point(0, 0); map.Dock = DockStyle.Fill; splitContainerControl1.Panel1.Controls.Add(map); GlobalObject.PropertyForm = this.propertyForm1; GlobalObject.map = map; if (!TemplateList.Inited) TemplateList.Init(); var arrs = Enum.GetNames(typeof(TemplateType)); var arr = arrs.Where(c => c == TemplateType.楼层模板.ToString()).ToArray(); combobox_type.DataSource = arr; combobox_type.SelectedItem = TemplateType.楼层模板; //InitTreeList(); } /// /// 新增 /// /// /// private async void barButtonItem1_ItemClick(object sender, ItemClickEventArgs e) { using (var form = new TemplateEditForm(null)) { if (form.ShowDialog() == DialogResult.OK) { var model = new PBS.Vmo.ModelTemplateVmo() { Name = form.TemplateName, TemplateType = (int)form.Type, PlaceType = form.BuildType }; var id = await new PBS.BLL.ModelTemplate().Insert(model); var t = ModelConvertToTemplate(model); var filePath = "template\\" + form.Type.ToString() + "\\" + id.ToString() + ".inp"; var fullPath = Path.Combine(Directory.GetCurrentDirectory(), filePath); model.ID = id; t.ID = id.ToString(); if (!File.Exists(fullPath)) File.Create(fullPath).Close(); model.ModelPath = t.filePath = filePath; model.ModelInfo = Yw.JsonHelper.Object2Json(t); //model.FormJson = form.FormJson; await new PBS.BLL.ModelTemplate().Update(model); InitTreeList(); } } } private Template ModelConvertToTemplate(PBS.Vmo.ModelTemplateVmo model) { var jsonModel = Yw.JsonHelper.Json2Object