xulisong 6 лет назад
Родитель
Сommit
a12a8aa7ce

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/PumpEnd/DrawEnd.cs

@@ -9,6 +9,7 @@ using System.Collections.Generic;
 using System.Drawing;
 using System.Drawing.Drawing2D;
 using System.Linq;
+using System.Runtime.Caching;
 using System.Text.RegularExpressions;
 using System.Windows;
 using System.Windows.Media.Media3D;
@@ -569,7 +570,6 @@ namespace SAGA.GplotRelationComputerManage.PumpEnd
                             foreach (var sgSpace in levelSpaces.EndPoints)
                             {
                                 #region 点在区域内判断
-
                                 GraphicsPath myGraphicsPath = new GraphicsPath();
                                 Region myRegion = new Region();
                                 myGraphicsPath.Reset();

+ 1 - 1
MBI/SAGA.GplotRelationComputerManage/PumpEnd/DuctTerminalBll.cs

@@ -46,7 +46,7 @@ namespace SAGA.GplotRelationComputerManage.PumpEnd
         /// <summary>
         /// 计算风管
         /// </summary>
-        /// <param name="datas"></param>
+    
         public static void DrawDuct()
         {
             var doc = ExternalDataWrapper.Current.Doc;

+ 2 - 0
MBI/SAGA.GplotRelationComputerManage/SAGA.GplotRelationComputerManage.csproj

@@ -64,6 +64,7 @@
     <Reference Include="System.Core" />
     <Reference Include="System.Drawing" />
     <Reference Include="System.IO.Compression" />
+    <Reference Include="System.Runtime.Caching" />
     <Reference Include="System.Runtime.Serialization" />
     <Reference Include="System.ServiceModel" />
     <Reference Include="System.Transactions" />
@@ -113,6 +114,7 @@
     <Compile Include="SpaceRelation\SpaceComputerContext.cs" />
     <Compile Include="SpaceRelation\SpaceComputerHandler.cs" />
     <Compile Include="SpaceRelation\SpaceComputerManager.cs" />
+    <Compile Include="SystemRelation\Common\SystemCalcUtil.cs" />
   </ItemGroup>
   <ItemGroup>
     <ProjectReference Include="..\SAGA.GplotDrawData\SAGA.GplotDrawData.csproj">

+ 29 - 0
MBI/SAGA.GplotRelationComputerManage/SystemRelation/Common/SystemCalcUtil.cs

@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SystemCalcUtil
+ * 作者:xulisong
+ * 创建时间: 2019/1/2 17:55:55
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.DB;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using SAGA.RevitUtils.Extends;
+
+namespace SAGA.GplotRelationComputerManage.SystemRelation.Common
+{
+    /// <summary>
+    /// 系统计算相关
+    /// </summary>
+    public class SystemCalcUtil
+    {
+        public bool IsStart(Element element)
+        {
+           // if(element is Mepcu)
+            return element.GetParameterString(BuiltInParameter.ALL_MODEL_INSTANCE_COMMENTS) == "start";
+        }
+    }
+}

+ 1 - 0
MBI/SAGA.MBI/SAGA.MBI.csproj

@@ -629,6 +629,7 @@
       <DependentUpon>WinBeacon.xaml</DependentUpon>
     </Compile>
     <Compile Include="DataArrange\DalUploadFloor.cs" />
+    <Compile Include="WinView\Space\ExternalEventHandler.cs" />
     <Compile Include="WinView\Space\FloorSpaceContext.cs" />
     <Compile Include="WinView\Space\GeometryHelper.cs" />
     <Compile Include="WinView\Space\ServerSpace.cs" />

+ 67 - 0
MBI/SAGA.MBI/WinView/Space/ExternalEventHandler.cs

@@ -0,0 +1,67 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ExternalEventHandler
+ * 作者:xulisong
+ * 创建时间: 2019/1/4 10:59:50
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using Autodesk.Revit.UI;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.WinView.Space
+{
+    /// <summary>
+    /// 为了在外部事件中打开OpenAndActiveDocument
+    /// </summary>
+    public class ExternalEventHandler : IExternalEventHandler
+    {
+        public ExternalEventHandler(Action<UIApplication> handler)
+        {
+            m_Execute = handler;
+        }
+        private Action<UIApplication> m_Execute;
+        // 事件处理函数
+        public void Execute(UIApplication app)
+        {
+            if (m_Execute != null)
+            {
+                m_Execute(app);
+            }
+        }
+        // 事件处理函数的名称
+        public string GetName()
+        {
+            return "上传";
+        }
+    }
+
+    public class EventCommand
+    {
+        private ExternalEventHandler m_Handler;
+        public EventCommand(ExternalEventHandler handler)
+        {
+            m_Handler = handler;
+        }
+        public ExternalEvent Event { get; private set; }
+        public void Register()
+        {
+            if (m_Handler != null&& Event==null)
+            {
+                Event = ExternalEvent.Create(m_Handler);
+            }         
+        }
+
+        public void Raise()
+        {
+            if (Event == null)
+            {
+                Register();
+            }
+            Event?.Raise();
+        }
+    }
+}

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

@@ -109,9 +109,13 @@ namespace SAGA.MBI.WinView
                     #endregion
 
                     #region 冲突处理代码
-                    spacePreprocessor.SetOperate(false);
+                    FailureHandlingOptions fhoDe = tran.GetFailureHandlingOptions();
+                    fhoDe.SetFailuresPreprocessor(new SpaceFailuresPreprocessor(false) );
+                    tran.SetFailureHandlingOptions(fhoDe);
+                    //spacePreprocessor.SetOperate(false);
                     tran.Start();
-                    SpaceManager.DealSpaceFailuresPreprocessor(document,spacePreprocessor.Items,this);
+                    //返回值临时使用
+                    flag=SpaceManager.DealSpaceFailuresPreprocessor(document,spacePreprocessor.Items,this);
                     tran.Commit();
 
                     #endregion

+ 5 - 1
MBI/SAGA.MBI/WinView/Space/SpaceManager.cs

@@ -143,8 +143,10 @@ namespace SAGA.MBI.WinView
         /// <param name="doc"></param>
         /// <param name="failItems"></param>
         /// <param name="context">楼层上下文</param>
-        public static void DealSpaceFailuresPreprocessor(Document doc, List<FailItem> failItems,FloorSpaceContext context)
+        /// <returns>ture表示处理完成,false表示存在没处理的空间【冲突空间可能未处理】</returns>
+        public static bool DealSpaceFailuresPreprocessor(Document doc, List<FailItem> failItems,FloorSpaceContext context)
         {
+            bool flag = true;
             #region 处理逻辑
             /*
              * 1、根据条件过滤,满足自动处理的自动处理。
@@ -287,8 +289,10 @@ namespace SAGA.MBI.WinView
                 else
                 {
                     //没处理会有什么操作
+                    flag = false;
                 }
             }
+            return flag;
         }
 
         /// <summary>

+ 76 - 52
MBI/SAGA.MBI/WinView/Space/WinCreateSpace.xaml.cs

@@ -573,9 +573,6 @@ namespace SAGA.MBI.WinView.Space
                 return Result.Succeeded;
             }, () => { return Result.Succeeded; });
         }
-
-   
-
         /// <summary>
         /// 离开画布,改变鼠标样式
         /// </summary>
@@ -585,7 +582,6 @@ namespace SAGA.MBI.WinView.Space
         {
             this.Cursor = Cursors.Arrow;
         }
-
         /// <summary>
         /// 鼠标进入画布,改变鼠标样式
         /// </summary>
@@ -716,7 +712,6 @@ namespace SAGA.MBI.WinView.Space
                     {
                         InitFloor(floor);
                     }
-
                     return Result.Succeeded;
                 }, () => { return Result.Succeeded; });
              
@@ -732,6 +727,8 @@ namespace SAGA.MBI.WinView.Space
         {
             try
             {
+                //保存按钮不可用
+                this.btnSave.IsEnabled = false;
                 DeletedPolylines.Clear();
                 //关闭空间属性窗
                 WinModeInfoMaintenance.GetWindow().Hide();
@@ -824,60 +821,16 @@ namespace SAGA.MBI.WinView.Space
             //需要保存的分隔符数据
             List<PointPair> saveDatas = GetPoints();
             bool flagExecuteSuccess = true; //本应在回调函数里传值,目前代码不支持
-            ExecuteCmd.ExecuteCommandOnce(() =>
-            {
-                #region 创建空间
-                CurrentContext.UpdateSpaceSeqaration(saveDatas
-                        .Select(points => new SpaceSeparation(points.RPoint[0], points.RPoint[1])).ToList(),
-                    DeletedPolylines);
-                DeletedPolylines.Clear();
-                var createSuccess = CurrentContext.CreateSpaces();
-                if (!createSuccess)
-                {
-                    flagExecuteSuccess = false;
-                    MessageShow.Infomation("保存楼层空间失败");
-                    return Result.Succeeded;
-                }
+            #region 扩展事件处理相关
 
-                #endregion
-
-                #region 初始化界面
-                //this.canvas.IsEnabled = true;
-                //btnOrigin_Click(null, null);
-                //InitData();
-                #endregion
-
-                #region 上传模型选择
-                Window confirm = GetUploadConfirm();
-                var result = confirm.ShowDialog();
-                //选择以后界面可用
-                this.IsEnabled = true;
-                if (result == true)
-                {
-                    // 由于上传需要关闭所有模型,所以这里需要对所有数据进行清空
-                    this.canvas.Children.Clear();
-                    //添加默认提示
-                    CanvasDefaultTips();
-                    lbSpaces.ItemsSource = new ObservableCollection<MSpace>();
-                    WinModeInfoMaintenance.GetWindow().Hide();
-                }
-                else
-                {
-                    flagExecuteSuccess = false;
-                }
-
-                #endregion
-
-                return Result.Succeeded;
-            }, () =>
-            {
+            EventCommand updateCommand = new EventCommand(new ExternalEventHandler((app) => {
                 try
                 {
                     var document = CurrentContext.Document;
                     document.Save();
                     if (!flagExecuteSuccess)
                     {
-                        return Result.Succeeded;
+                        return;
                     }
                     SpaceManager.UploadModel(document);
                 }
@@ -885,7 +838,78 @@ namespace SAGA.MBI.WinView.Space
                 {
                     MessageShow.Show(ex);
                 }
+            }));
+            #endregion
+            ExecuteCmd.ExecuteCommandOnce(() =>
+            {
+                try
+                {
+                    updateCommand.Register();
+                    #region 创建空间
+                    using (TransactionGroup group = new TransactionGroup(CurrentContext.Document, "保存空间修改"))
+                    {
+                        group.Start();
+                        CurrentContext.UpdateSpaceSeqaration(saveDatas
+                                .Select(points => new SpaceSeparation(points.RPoint[0], points.RPoint[1])).ToList(),
+                            DeletedPolylines);
+                        DeletedPolylines.Clear();
+                        var createSuccess = CurrentContext.CreateSpaces();
+                        if (!createSuccess)
+                        {
+                            flagExecuteSuccess = false;
+                            group.RollBack();
+                            MessageShow.Infomation("保存楼层空间失败");                       
+                            return Result.Succeeded;
+                        }
+                        group.Assimilate();
+                    }
+                    #endregion
 
+                    #region 上传模型选择
+                    Window confirm = GetUploadConfirm();
+                    var result = confirm.ShowDialog();
+                    //选择以后界面可用
+                    this.IsEnabled = true;
+                    if (result == true)
+                    {
+                        // 由于上传需要关闭所有模型,所以这里需要对所有数据进行清空
+                        this.canvas.Children.Clear();
+                        //添加默认提示
+                        CanvasDefaultTips();
+                        lbSpaces.ItemsSource = new ObservableCollection<MSpace>();
+                        WinModeInfoMaintenance.GetWindow().Hide();
+                    }
+                    else
+                    {
+                        flagExecuteSuccess = false;
+                    }
+                    #endregion
+                }
+                finally
+                {
+                    this.IsEnabled = true;
+                }
+
+                return Result.Succeeded;
+            }, () =>
+            {
+                #region 代码中包含事务,不能再回调线程中使用
+                //try
+                //{
+                //    var document = CurrentContext.Document;
+                //    document.Save();
+                //    if (!flagExecuteSuccess)
+                //    {
+                //        return Result.Succeeded;
+                //    }
+                //    SpaceManager.UploadModel(document);
+                //}
+                //catch (Exception ex)
+                //{
+                //    MessageShow.Show(ex);
+                //}
+                #endregion
+                updateCommand.Raise();
                 return Result.Succeeded;
             });
         }

+ 15 - 6
MBI/SAGA.MBI/WinView/Space/WinCreateSpaceWeb.xaml.cs

@@ -232,14 +232,23 @@ namespace SAGA.MBI.WinView.Space
             {
                 #region 创建空间
                 var seqs = saveDatas.Select(points => new SpaceSeparation(points.RPoint[0], points.RPoint[1])).ToList();
-                CurrentContext.UpdateSpaceSeqaration(seqs,deletedIds);
-                var createSuccess = CurrentContext.CreateSpaces();
-                if (!createSuccess)
+                using (TransactionGroup group = new TransactionGroup(CurrentContext.Document, "保存空间修改"))
                 {
-                    flagExecuteSuccess = false;
-                    MessageShow.Infomation("保存楼层空间失败");
-                    return Result.Succeeded;
+                    group.Start();
+                    CurrentContext.UpdateSpaceSeqaration(seqs, deletedIds);
+                    var createSuccess = CurrentContext.CreateSpaces();
+                    if (!createSuccess)
+                    {
+                        flagExecuteSuccess = false;
+                        group.RollBack();
+                        MessageShow.Infomation("保存楼层空间失败");
+                        return Result.Succeeded;
+                    }
+
+                    group.Assimilate();
                 }
+
+              
                 #endregion
                 #region 初始化界面
                 SetCanvasShow();