浏览代码

xls:空间管理相关数据

xulisong 6 年之前
父节点
当前提交
98ecd9e37c

+ 2 - 10
MBI/SAGA.GplotRelationComputerManage/ComputerPipes.cs

@@ -20,11 +20,8 @@ namespace SAGA.GplotRelationComputerManage
         public static void Computer()
         {
             //记录立管
-            //List<Pipe> verticalPipe = new List<Pipe>();
             Dictionary<Level, List<Pipe>> dicVerticalPipes = new Dictionary<Level, List<Pipe>>();
-            //打开所有楼层数据
-            // var fileInfos = RevitModelPath.GetAllRevitFiles();//.Where(t=>Regex.IsMatch(t, "Fl1101080003e883286bb63d11e8b92a092227bd993a"));//B2
-            var fileInfos = RevitModelPath.GetAllRevitFiles();//.Where(t=>Regex.IsMatch(t, "ee2c4"));//Test
+            var fileInfos = RevitModelPath.GetAllRevitFiles();
             foreach (var fileInfo in fileInfos)
             {
                 if (File.Exists(fileInfo))
@@ -54,12 +51,7 @@ namespace SAGA.GplotRelationComputerManage
                     //计算风管
                     DuctTerminalBll.DrawDuct();
                 }
-            }
-
-            
-            //计算立管
-            //if(ExternalDataWrapper.Current?.Doc==null)return;
-            //var levels =ExternalDataWrapper.Current.Doc.GetLevels();
+            }         
             var pipeComputer = new ComputerVerticalPipe();
             pipeComputer.Computer(dicVerticalPipes);
         }

+ 0 - 7
MBI/SAGA.GplotRelationComputerManage/ComputerVerticalPipe.cs

@@ -6,18 +6,11 @@
 
 using Autodesk.Revit.DB;
 using Autodesk.Revit.DB.Plumbing;
-
-using SAGA.GplotDrawData;
-using SAGA.MBI;
 using SAGA.Models;
 using SAGA.RevitUtils.Extends;
-
-using System;
 using System.Collections.Generic;
 using System.Linq;
-using System.Windows.Controls;
 using System.Windows.Media.Media3D;
-using Point = System.Windows.Point;
 namespace SAGA.GplotRelationComputerManage
 {
     public class ComputerVerticalPipe

+ 13 - 2
MBI/SAGA.MBI/RevitModelHandle/RevitParameterUpdate.cs

@@ -1,6 +1,7 @@
 using Autodesk.Revit.DB;
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -98,11 +99,21 @@ namespace SAGA.MBI
             var ids = bimId.Split(':');
             if (ids.Count() < 2)
                 return;
+            string floorId = ids[0];
             int elementID = ids[1].ToInt();
-            var doc = ExternalDataWrapper.Current.Doc;
+            var mFloor = DalProjectTree.GetFloorByFloorId(floorId);
+            if (mFloor == null)
+            {
+                return;
+            }            
+            if (!File.Exists(mFloor.FullPath))
+            {
+                return;
+            }
+            var doc = ExternalDataWrapper.Current.App.OpenDocumentFile(mFloor.FullPath);// ExternalDataWrapper.Current.Doc;
             if (doc == null)
                 return;
-            var element = ExternalDataWrapper.Current.Doc.GetElement(new ElementId(elementID));
+            var element = doc.GetElement(new ElementId(elementID));
             if (element == null)
                 return;
             UpdateNameAsync(element, name);

+ 3 - 2
MBI/SAGA.MBI/WinView/Space/FloorSpaceContext.cs

@@ -47,8 +47,9 @@ namespace SAGA.MBI.WinView
                     {
                         throw new Exception("无法找到相关模型文件!");
                     }
-                    var uiDoc = ExternalDataWrapper.Current.UiApp.OpenAndActivateDocument(filePath);
-                    m_Document = uiDoc.Document;
+                    //var uiDoc = ExternalDataWrapper.Current.UiApp.OpenAndActivateDocument(filePath);
+                    //var uiDoc = ExternalDataWrapper.Current.UiApp.OpenAndActivateDocument(filePath);
+                    m_Document = ExternalDataWrapper.Current.App.OpenDocumentFile(filePath);//uiDoc.Document;
                 }
                 return m_Document;
             }

+ 83 - 81
MBI/SAGA.MBI/WinView/Space/WinCreateSpace.xaml.cs

@@ -3,8 +3,6 @@ using System.Collections.Generic;
 using System.Collections.ObjectModel;
 using System.IO;
 using System.Linq;
-using System.Reflection;
-using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Input;
@@ -19,20 +17,12 @@ using Point = System.Windows.Point;
 using System.Windows.Media.Animation;
 using System.Windows.Threading;
 using Autodesk.Revit.UI;
-using Newtonsoft.Json.Linq;
-using SAGA.DotNetUtils.Logger;
-using SAGA.MBI.Common;
 using SAGA.MBI.DataArrange;
-using SAGA.MBI.JsonConvert;
 using SAGA.MBI.Model;
-using SAGA.MBI.RequestData;
-using SAGA.MBI.Tools;
 using SAGA.MBI.WinView.ModeInfoMaintenance;
 using SAGA.RevitUtils;
 using SAGA.RevitUtils.Windows;
 using Visibility = System.Windows.Visibility;
-using Path = System.IO.Path;
-using System.Threading.Tasks;
 
 //TODO:1.目前存在的问题,如果只选两个已有的端点画线不能实现
 //TODO:2.画图过程中,ESC可取消当前画图
@@ -574,7 +564,14 @@ namespace SAGA.MBI.WinView.Space
         private void btnSave_Click(object sender, RoutedEventArgs e)
         {
             SaveFloor();
-
+            ExecuteCmd.ExecuteCommandOnce(() =>
+            {
+                if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+                {
+                    InitFloor(floor);
+                }
+                return Result.Succeeded;
+            }, () => { return Result.Succeeded; });
         }
 
    
@@ -690,32 +687,44 @@ namespace SAGA.MBI.WinView.Space
         /// <param name="e"></param>
         private void Tv_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
         {
-            //检测是否有未保存的数据,数据分两部分:新建的空间分隔符,删除的空间分隔符
-            #region 切换前节点处理
-            if (DeletedPolylines.Count > 0 || this.canvas.Children.OfType<UIElement>().Any(el => (el is WPolyline line && line.Stroke == Brushes.Red)))
+            try
             {
-                WinConfirm confirm = new WinConfirm()
+                //检测是否有未保存的数据,数据分两部分:新建的空间分隔符,删除的空间分隔符
+                #region 切换前节点处理
+                if (DeletedPolylines.Count > 0 || this.canvas.Children.OfType<UIElement>().Any(el => (el is WPolyline line && line.Stroke == Brushes.Red)))
                 {
-                    ShowMessage = "尚未保存空间变化,确认放弃修改?",
-                    TTitle = "空间修改确认",
-                    BtnSure = "保存并更改模型",
-                    BtnCancel = "放弃修改",
-                    Owner=this
-                    
-                };
-                var result = confirm.ShowDialog();
-                if (result == true)
-                {
-                    SaveFloor();
-                    return;
+                    WinConfirm confirm = new WinConfirm()
+                    {
+                        ShowMessage = "尚未保存空间变化,确认放弃修改?",
+                        TTitle = "空间修改确认",
+                        BtnSure = "保存并更改模型",
+                        BtnCancel = "放弃修改",
+                        Owner = this
+                    };
+                    var result = confirm.ShowDialog();
+                    if (result == true)
+                    {
+                        SaveFloor();
+                        //return;
+                    }                
                 }
-                DeletedPolylines.Clear();
-            } 
-            #endregion
+                #endregion
+                //异步造成执行顺序混乱的情况,所以使用idling排队
+                ExecuteCmd.ExecuteCommandOnce(() =>
+                {                  
+                    if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+                    {
+                        InitFloor(floor);
+                    }
 
-            if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+                    return Result.Succeeded;
+                }, () => { return Result.Succeeded; });
+             
+            }
+            catch (Exception ex)
             {
-                InitFloor(floor);
+
+                MessageShow.Show(ex);
             }
         }
 
@@ -723,6 +732,7 @@ namespace SAGA.MBI.WinView.Space
         {
             try
             {
+                DeletedPolylines.Clear();
                 //关闭空间属性窗
                 WinModeInfoMaintenance.GetWindow().Hide();
                 this.canvas.Children.Clear();
@@ -813,15 +823,15 @@ namespace SAGA.MBI.WinView.Space
             m_isDraw = null;
             //需要保存的分隔符数据
             List<PointPair> saveDatas = GetPoints();
-            bool flagExecuteSuccess = true;//本应在回调函数里传值,目前代码不支持
+            bool flagExecuteSuccess = true; //本应在回调函数里传值,目前代码不支持
             ExecuteCmd.ExecuteCommandOnce(() =>
             {
                 #region 创建空间
                 CurrentContext.UpdateSpaceSeqaration(saveDatas
-                                .Select(points => new SpaceSeparation(points.RPoint[0], points.RPoint[1])).ToList(),
-                            DeletedPolylines);
+                        .Select(points => new SpaceSeparation(points.RPoint[0], points.RPoint[1])).ToList(),
+                    DeletedPolylines);
                 DeletedPolylines.Clear();
-                var createSuccess=CurrentContext.CreateSpaces();
+                var createSuccess = CurrentContext.CreateSpaces();
                 if (!createSuccess)
                 {
                     flagExecuteSuccess = false;
@@ -832,10 +842,9 @@ namespace SAGA.MBI.WinView.Space
                 #endregion
 
                 #region 初始化界面
-                this.canvas.IsEnabled = true;
-                btnOrigin_Click(null, null);
-                InitData();
-
+                //this.canvas.IsEnabled = true;
+                //btnOrigin_Click(null, null);
+                //InitData();
                 #endregion
 
                 #region 上传模型选择
@@ -851,45 +860,33 @@ namespace SAGA.MBI.WinView.Space
                     CanvasDefaultTips();
                     lbSpaces.ItemsSource = new ObservableCollection<MSpace>();
                     WinModeInfoMaintenance.GetWindow().Hide();
-
-                    #region 错误尝试
-                    //上传中的一些操作,不能发生在idling中
-
-                    //    Action<FloorSpaceContext> action = new Action<FloorSpaceContext>((context) =>
-                    //    {
-                    //        try
-                    //        {
-                    //             CurrentContext.Document.Save();
-                    //            SpaceManager.UploadModel(context.Document);
-                    //        }
-                    //        catch (Exception ex)
-                    //        {
-                    //            MessageShow.Show(ex);
-                    //        }
-                    //    });
-                    //    action.BeginInvoke(CurrentContext, null, null); 
-                    #endregion
                 }
+                else
+                {
+                    flagExecuteSuccess = false;
+                }
+
                 #endregion
+
                 return Result.Succeeded;
             }, () =>
             {
-                if (!flagExecuteSuccess)
-                {
-                    return Result.Succeeded;
-                }
                 try
                 {
                     var document = CurrentContext.Document;
                     document.Save();
-                   
+                    if (!flagExecuteSuccess)
+                    {
+                        return Result.Succeeded;
+                    }
                     SpaceManager.UploadModel(document);
                 }
                 catch (Exception ex)
                 {
                     MessageShow.Show(ex);
                 }
-                 return Result.Succeeded;
+
+                return Result.Succeeded;
             });
         }
 
@@ -984,29 +981,34 @@ namespace SAGA.MBI.WinView.Space
 
         private void lbSpaces_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-            if (lbSpaces.SelectedItems.Count == 0) return;
-            var space = lbSpaces.SelectedItems[0] as MSpace;
-
-
-
-            var bimId = space.BimID.Split(':')[1];
-
-            foreach (var polyline in this.canvas.Children.OfType<WPolyline>())
+            try
             {
-                if (polyline.Tag is Autodesk.Revit.DB.Mechanical.Space s)
+                #region 核心代码
+                if (lbSpaces.SelectedItems.Count == 0) return;
+                var space = lbSpaces.SelectedItems[0] as MSpace;
+                var bimId = space.BimID.Split(':')[1];
+                foreach (var polyline in this.canvas.Children.OfType<WPolyline>())
                 {
-                    if (s.Id.ToString() == (bimId))
+                    if (polyline.Tag is Autodesk.Revit.DB.Mechanical.Space s)
                     {
-                        polyline.Fill = Brushes.Aquamarine;
+                        if (s.Id.ToString() == (bimId))
+                        {
+                            polyline.Fill = Brushes.Aquamarine;
 
-                        //显示属性窗口
-                        ShowSpaceProperty(s);
-                    }
-                    else if (polyline.Fill == Brushes.Aquamarine)
-                    {
-                        polyline.Fill = Brushes.Transparent;
+                            //显示属性窗口
+                            ShowSpaceProperty(s);
+                        }
+                        else if (polyline.Fill == Brushes.Aquamarine)
+                        {
+                            polyline.Fill = Brushes.Transparent;
+                        }
                     }
                 }
+                #endregion
+            }
+            catch (Exception ex)
+            {
+                MessageShow.Show(ex);
             }
         }
 

+ 128 - 47
MBI/SAGA.MBI/WinView/Space/WinCreateSpaceWeb.xaml.cs

@@ -6,19 +6,18 @@ using System.Text;
 using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
-using System.Windows.Media;
-using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
+using Autodesk.Revit.DB;
 using Autodesk.Revit.UI;
+using Newtonsoft.Json.Linq;
+using SAGA.DotNetUtils;
 using SAGA.MBI.DataArrange;
 using SAGA.MBI.Model;
+using SAGA.MBI.RevitExport;
 using SAGA.MBI.WinView.ModeInfoMaintenance;
 using SAGA.RevitUtils;
+using SAGA.RevitUtils.Extends;
 using SAGA.RevitUtils.Windows;
+using Visibility = System.Windows.Visibility;
 
 namespace SAGA.MBI.WinView.Space
 {
@@ -48,26 +47,42 @@ namespace SAGA.MBI.WinView.Space
       
         private void Tv_OnSelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
         {
-            //检测是否有未保存的数据,数据分两部分:新建的空间分隔符,删除的空间分隔符
-            //删除空间分割的id和新建空间分割的线
-             var editData = GetEditData();
-            List<int> deletedIds = editData.DeletedIds;
-           var  newDatas = editData.NewDatas;
-            #region 切换前节点处理
-            if (deletedIds.Count > 0 || newDatas.Any())
+            try
             {
-                WinConfirm confirm = CreateSaveConfirm();
-                var result = confirm.ShowDialog();
-                if (result == true)
+                #region 核心代码
+                //检测是否有未保存的数据,数据分两部分:新建的空间分隔符,删除的空间分隔符
+                //删除空间分割的id和新建空间分割的线
+                var editData = GetEditData();
+                List<int> deletedIds = editData.DeletedIds;
+                var newDatas = editData.NewDatas;
+                #region 切换前节点处理
+                if (deletedIds.Count > 0 || newDatas.Any())
                 {
-                    SaveFloor(editData);
-                    return;
+                    WinConfirm confirm = CreateSaveConfirm();
+                    var result = confirm.ShowDialog();
+                    if (result == true)
+                    {
+                        SaveFloor(editData);
+                       // return;
+                    }
                 }
+                #endregion
+                //异步造成执行顺序混乱的情况,所以使用idling排队
+                ExecuteCmd.ExecuteCommandOnce(() =>
+                {
+                    if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+                    {
+                        InitFloor(floor);
+                    }
+
+                    return Result.Succeeded;
+                }, () => { return Result.Succeeded; });
+                #endregion
             }
-            #endregion
-            if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+            catch (Exception ex)
             {
-                InitFloor(floor);
+
+                MessageShow.Show(ex);
             }
         }
 
@@ -79,14 +94,35 @@ namespace SAGA.MBI.WinView.Space
 
         private void lbSpaces_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
-            if (lbSpaces.SelectedItems.Count == 0) return;
-            var space = lbSpaces.SelectedItems[0] as MSpace;
-            var bimId = space.BimID.Split(':')[1];
-            //发送js填充命令
-            var strJs = $"getData('{bimId.ToString()}')";
-            ucShowElement.ExecuteJsFun(strJs);
-            //显示空间属性窗格
-            //todo
+            try
+            {
+                if (lbSpaces.SelectedItems.Count == 0) return;
+                var space = lbSpaces.SelectedItems[0] as MSpace;
+                var bimId = space.BimID.Split(':')[1];
+                //发送js填充命令
+                var strJs = $"getData('{bimId.ToString()}')";
+                ucShowElement.ExecuteJsFun(strJs);
+                #region 显示属性窗格
+                var doc = CurrentContext.Document;
+                if (doc == null)
+                    return;
+                var revitSpace = doc.GetElement(new ElementId(bimId.ToInt()));
+                if (revitSpace == null)
+                    return;
+                MRevitEquipBase equipment = DalCommon.GetEquipmentQueryId(revitSpace);
+                if (equipment != null)
+                {
+                    var win = WinModeInfoMaintenanceForSpace.GetWindow();
+                    win.Topmost = true;
+                    win.Show(equipment);
+                    win.Visibility = Visibility.Visible;
+                }
+               #endregion
+            }
+            catch (Exception ex)
+            {
+                MessageShow.Show(ex);
+            }
         }
         #endregion
 
@@ -127,6 +163,29 @@ namespace SAGA.MBI.WinView.Space
         }
         #endregion
 
+        #region 界面信息相关处理
+        /// <summary>
+        /// 清理窗口显示的楼层相关数据
+        /// </summary>
+        private void ClearFloorData()
+        {
+            WinModeInfoMaintenance.GetWindow().Hide();
+            this.lbSpaces.ItemsSource = new ObservableCollection<MSpace>(); ;
+        }
+        /// <summary>
+        /// 设置窗口楼层相关数据
+        /// </summary>
+        public void SetFloorData(Document document)
+        {
+            var spaces = CurrentContext.Document.GetElements<SpatialElement>().Where(s => s is Autodesk.Revit.DB.Mechanical.Space && s.Area > 0).ToList();
+            var datas = CurrentContext.GetPhysicalSpaces(spaces.Select(t => t.Id.IntegerValue.ToString()).ToList());
+            var localSpace = spaces.Where(t => !datas.Any(s => s.BimID.Split(':')[1] == t.Id.ToString()))
+                .Select(t => new MSpace("", $"{Guid.NewGuid()}:{t.Id.ToString()}") { Name = t.Name});
+            datas.AddRange(localSpace);
+            lbSpaces.ItemsSource = new ObservableCollection<MSpace>(datas);
+        }
+
+        #endregion
 
         #region 空间管理相关逻辑
         public FloorSpaceContext CurrentContext;
@@ -134,9 +193,7 @@ namespace SAGA.MBI.WinView.Space
         {
             try
             {
-                //关闭空间属性窗
-                WinModeInfoMaintenance.GetWindow().Hide();
-                this.lbSpaces.ItemsSource = null;
+                ClearFloorData();
                 #region 数据整理
                 FloorSpaceContext context = new FloorSpaceContext(floor);
                 CurrentContext = context;
@@ -153,6 +210,7 @@ namespace SAGA.MBI.WinView.Space
                     #region 初始化界面
                     SetCanvasShow();
                     #endregion
+                    SetFloorData(doc);
                     return Result.Succeeded;
                 });
                 #endregion           
@@ -195,21 +253,24 @@ namespace SAGA.MBI.WinView.Space
                 {
                     //添加默认提示
                     SetEmptyTip();
-                    lbSpaces.ItemsSource = new ObservableCollection<MSpace>();
-                    WinModeInfoMaintenance.GetWindow().Hide();
+                    ClearFloorData();
+                }
+                else
+                {
+                    flagExecuteSuccess = false;
                 }
                 #endregion
                 return Result.Succeeded;
             }, () =>
             {
-                if (!flagExecuteSuccess)
-                {
-                    return Result.Succeeded;
-                }
                 try
                 {
                     var document = CurrentContext.Document;
                     document.Save();
+                    if (!flagExecuteSuccess)
+                    {
+                        return Result.Succeeded;
+                    }
                     SpaceManager.UploadModel(document);
                 }
                 catch (Exception ex)
@@ -238,17 +299,42 @@ namespace SAGA.MBI.WinView.Space
 
         public void SetCanvasShow()
         {
+            var jobject = GetModelDrawing();
+            
+        }
+        #endregion
+
+        #region js调用命令
+
+        public void Save()
+        {
 
+            var editData = GetEditData();
+            SaveFloor(editData);
+            ExecuteCmd.ExecuteCommandOnce(() =>
+            {
+                if (tv.SelectedItem is TreeNodeItem item && item.Item is MFloor floor)
+                {
+                    InitFloor(floor);
+                }
+                return Result.Succeeded;
+            }, () => { return Result.Succeeded; });
+            MessageBox.Show("Save");
         }
+
         #endregion
+
         /// <summary>
         /// 获取模型绘图数据
         /// </summary>
         /// <returns></returns>
-        private object GetModelDrawing()
+        private JObject GetModelDrawing()
         {
             //柱子,墙,虚拟墙,空间
-            return null;
+            Document linkDoc = CurrentContext.Document;
+            MbiElementManager manager = new MbiElementManager();
+            var exportDb = manager.ExportMbiEelemntDB(ExportDataBuilder.CreateExportData(linkDoc));
+            return exportDb.ToJsonObject();
         }
 
         private void Button_Click(object sender, RoutedEventArgs e)
@@ -264,12 +350,7 @@ namespace SAGA.MBI.WinView.Space
             ucShowElement.ExecuteJsFun(strJs);
         }
 
-        public void Save()
-        {
-         
-
-            MessageBox.Show("Save");
-        }
+       
 
         public void SaveStr(string path)
         {