Преглед изворни кода

mxg:添加参数复制命令

mengxiangge пре 6 година
родитељ
комит
80e3f9a457

+ 5 - 5
MBI/Menu/MBITool.xml

@@ -136,13 +136,13 @@
       <Modules>MBITool</Modules>
     </Button>
     <Button ButtonStyles="Stacked">
-      <ButtonName>SAGA.MBI.CopyLocalIdCommand</ButtonName>
-      <ButtonText>复制设备编号的值</ButtonText>
+      <ButtonName>SAGA.MBI.CopyParameterValueCommand</ButtonName>
+      <ButtonText>复制指定参数A的值到指定参数B中</ButtonText>
       <ImageName>1、打开楼层模型</ImageName>
       <DllName>..\OutputDll\SAGA.MBI.exe</DllName>
-      <ClassName>SAGA.MBI.CopyLocalIdCommand</ClassName>
-      <ToolTip>将设备编号的值复制到设备本地编码中。</ToolTip>
-      <LongDescription>将设备编号的值复制到设备本地编码中,结果将列出本层复制失败的对象的id,如果本层都复制成功则没有提示。</LongDescription>
+      <ClassName>SAGA.MBI.CopyParameterValueCommand</ClassName>
+      <ToolTip>复制指定参数A的值到指定参数B中。</ToolTip>
+      <LongDescription>复制指定参数A的值到指定参数B中,在设置中选择需要复制的值名称。</LongDescription>
       <ToolTipImage></ToolTipImage>
       <MenuTab>MBITool_W</MenuTab>
       <Modules>MBITool</Modules>

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

@@ -328,12 +328,15 @@
     <Compile Include="RevitModelHandle\RevitParameterUpdate.cs" />
     <Compile Include="RevitReference\RVTNoModeDutyOperate.cs" />
     <Compile Include="Service\InputService.cs" />
+    <Compile Include="Test\CopyParameterValue.cs" />
     <Compile Include="Test\CopyWallLocalName.cs" />
+    <Compile Include="Test\WinParameterDic.xaml.cs">
+      <DependentUpon>WinParameterDic.xaml</DependentUpon>
+    </Compile>
     <Compile Include="ToolsData\DataCheck\DutyModeCodeDiffCheck.cs" />
     <Compile Include="ToolsData\DataCheck\DutyModeCodeDiffCheckResult.cs" />
     <Compile Include="ToolsData\DataCheck\SpaceEquipFloorCheck.cs" />
     <Compile Include="ToolsData\DataCheck\SpaceEquipFloorCheckResult.cs" />
-    <Compile Include="ToolsData\CopyLocalNameValue.cs" />
     <Compile Include="ToolsData\DelZeroSpace.cs" />
     <Compile Include="ToolsData\CheckBase\CheckOperation.cs" />
     <Compile Include="ToolsData\CheckBase\CheckType.cs" />
@@ -753,6 +756,10 @@
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>
     </Page>
+    <Page Include="Test\WinParameterDic.xaml">
+      <SubType>Designer</SubType>
+      <Generator>MSBuild:Compile</Generator>
+    </Page>
     <Page Include="ToolsData\CheckBase\WinDataCheckProgressBar.xaml">
       <Generator>MSBuild:Compile</Generator>
       <SubType>Designer</SubType>

+ 96 - 0
MBI/SAGA.MBI/Test/CopyParameterValue.cs

@@ -0,0 +1,96 @@
+/* ==============================================================================
+ * 功能描述:同步幕墙的本地名称、本地编码到幕墙嵌板中?
+ * 创 建 者:Garrett
+ * 创建日期:2018/7/11 14:34:26
+ * ==============================================================================*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using Autodesk.Revit.DB;
+using Microsoft.Win32;
+using NPOI.OpenXmlFormats.Dml.Diagram;
+using NPOI.SS.UserModel;
+using NPOI.XSSF.UserModel;
+using SAGA.DotNetUtils.Data;
+using SAGA.DotNetUtils.Extend;
+using SAGA.DotNetUtils.Logger;
+using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Calc;
+using SAGA.MBI.DataArrange;
+using SAGA.MBI.Model;
+using SAGA.MBI.Tools;
+using SAGA.MBI.ToolsData;
+using SAGA.MBI.WinView.Upload;
+using SAGA.Models;
+using SAGA.RevitUtils.Extends;
+using ICell = NPOI.SS.UserModel.ICell;
+using CellType = NPOI.SS.UserModel.CellType;
+
+namespace SAGA.MBI.Test
+{
+    /// <summary>
+    /// CheckEquipInSpace
+    /// </summary>
+    public class CopyParameterValue : IDataCorrect
+    {
+        private Dictionary<string, string> m_parameterDic;
+        public void SetCopyParameterDic(Dictionary<string, string> dic)
+        {
+            m_parameterDic = dic;
+        }
+
+        public string Execute(MFloor floor)
+        {
+            try
+            {
+                string fullPah = floor.FullPath;
+                Document doc = ExternalDataWrapper.Current.UiApp.Application.OpenDocumentFile(fullPah);
+                OperateFloor(doc);
+                doc.Save();
+            }
+            catch (Exception e)
+            {
+                MessageShowBase.Show(e);
+            }
+            return null;
+        }
+
+        public string ExecuteAll()
+        {
+            var floors = DalProjectTree.GetAllFloors(false);
+            List<CalcContext> contexts = new List<CalcContext>();
+            foreach (MFloor floor in floors)
+            {
+                Execute(floor);
+            }
+
+            return null;
+        }
+
+        private void OperateFloor(Document doc)
+        {
+            using (Transaction trans = new Transaction(doc, "复制属性"))
+            {
+                trans.Start();
+                var elements = doc.GetMbiElements();
+                foreach (Element element in elements)
+                {
+                    if (element.GetFamilyCode() == "GMMP")
+                        foreach (var pair in m_parameterDic)
+                        {
+                            string origin = pair.Key;
+                            string target = pair.Value;
+                            if (origin.IsNotNullEmpty() && target.IsNotNullEmpty())
+                            {
+                                element.SetParameterValue(target, element.GetParameterString(origin));
+                            }
+                        }
+                }
+
+                trans.Commit();
+            }
+        }
+    }
+}

+ 44 - 0
MBI/SAGA.MBI/Test/WinParameterDic.xaml

@@ -0,0 +1,44 @@
+<Window x:Class="SAGA.MBI.Test.WinParameterDic"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:SAGA.MBI.Test"
+             mc:Ignorable="d" Title="配置参数" WindowStartupLocation="CenterScreen"
+             Height="300" Width="400">
+    <Window.Resources>
+        <Style  TargetType="TextBox">
+            <Setter Property="HorizontalContentAlignment" Value="Center"></Setter>
+            <Setter Property="VerticalContentAlignment" Value="Center"></Setter>
+            <Setter Property="Height" Value="24"></Setter>
+        </Style>
+    </Window.Resources>
+    <Grid Margin="5">
+        <Grid.RowDefinitions>
+            <RowDefinition Height="20"></RowDefinition>
+            <RowDefinition></RowDefinition>
+            <RowDefinition Height="50"></RowDefinition>
+        </Grid.RowDefinitions>
+        <Grid Grid.Row="1">
+            <Grid.ColumnDefinitions>
+                <ColumnDefinition></ColumnDefinition>
+                <ColumnDefinition></ColumnDefinition>
+                <ColumnDefinition Width="30"></ColumnDefinition>
+            </Grid.ColumnDefinitions>
+            <StackPanel Grid.Column="0">
+                <Label Height="25" Content="源参数名称(旧)" HorizontalContentAlignment="Center" Background="LightGray"></Label>
+                <TextBox Name="txt00" Text="车位编号"></TextBox>
+                <TextBox Name="txt10"></TextBox>
+            </StackPanel>
+            <StackPanel Grid.Column="1">
+                <Label Height="25" Content="目标参数名称(新)" HorizontalContentAlignment="Center" Background="LightGray"></Label>
+                <TextBox  Name="txt01" Text="设备本地编码"></TextBox>
+                <TextBox  Name="txt11"></TextBox>
+            </StackPanel>
+        </Grid>
+        <WrapPanel Grid.Row="2" HorizontalAlignment="Center" VerticalAlignment="Center">
+            <Button Height="24" Width="100" Content="执行" Margin="10,0" IsDefault="True" Click="ButtonBase_OnClick"></Button>
+            <Button Height="24" Width="100" Content="取消" Margin="10,0" IsCancel="True"></Button>
+        </WrapPanel>
+    </Grid>
+</Window>

+ 45 - 0
MBI/SAGA.MBI/Test/WinParameterDic.xaml.cs

@@ -0,0 +1,45 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+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 Exception = System.Exception;
+
+namespace SAGA.MBI.Test
+{
+    /// <summary>
+    /// WinParameterDic.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinParameterDic
+    {
+        public WinParameterDic()
+        {
+            InitializeComponent();
+        }
+        public Dictionary<string,string> ParameterDic { get; set; }
+        private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
+        {
+            ParameterDic=new System.Collections.Generic.Dictionary<string, string>();
+            try
+            {
+                ParameterDic.Add(txt00.Text,txt01.Text);
+                ParameterDic.Add(txt10.Text,txt11.Text);
+            }
+            catch (Exception exception)
+            {
+                Console.WriteLine(exception);
+                
+            }
+            this.DialogResult = true;
+        }
+    }
+}

+ 26 - 15
MBI/SAGA.MBI/ToolCommand.cs

@@ -16,12 +16,14 @@ using Autodesk.Revit.DB.Plumbing;
 using Autodesk.Revit.UI;
 using FWindSoft.DataFramework;
 using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Data;
 using SAGA.DotNetUtils.Geometry;
 using SAGA.DotNetUtils.Logger;
 using SAGA.DotNetUtils.Others;
 using SAGA.MBI.Common;
 using SAGA.MBI.DataArrange;
 using SAGA.MBI.Model;
+using SAGA.MBI.Test;
 using SAGA.MBI.Tools;
 using SAGA.MBI.ToolsData;
 using SAGA.MBI.ToolsData.CheckBase;
@@ -133,7 +135,7 @@ namespace SAGA.MBI
 
                 //外点 ==2
                 var testPoint = new Geometry2D.PointD(-100, 200);
-                int flag = Geometry2D.InSidePolygon( newPoints.ToArray(),testPoint ); 
+                int flag = Geometry2D.InSidePolygon(newPoints.ToArray(), testPoint);
                 //==0
                 var testPoint2 = new Geometry2D.PointD(50, 200);
                 int flag2 = Geometry2D.InSidePolygon(newPoints.ToArray(), testPoint2);
@@ -227,30 +229,39 @@ namespace SAGA.MBI
     }
 
     /// <summary>
-    /// 将设备编号的值复制到设备本地编码
+    /// 复制指定参数A的值到指定参数B
     /// </summary>
     [Transaction(TransactionMode.Manual)]
     [Regeneration(RegenerationOption.Manual)]
-    public class CopyLocalIdCommand : ExternalCommand
+    public class CopyParameterValueCommand : ExternalCommand
     {
         public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
         {
             try
             {
-                int count = 0;
-                var tip = MessageShowBase.Question2($"确定复制设备编号中的值到{RevitBuiltInParameter.EquipLocalID}中?\r\n是:修正全部楼层\r\n否:修正当前楼层\r\n取消:取消修正。");
-                switch (tip)
+                var tip = MessageShowBase.Question2("确定要复制参数\r\n是:全部楼层\r\n否:当前楼层\r\n取消:取消。");
+                if (tip == DialogResult.No || tip == DialogResult.Yes)
                 {
-                    case DialogResult.Yes:
-                        count = CopyLocalNameValue.OperateAll();
-                        break;
-                    case DialogResult.No:
-                        count = CopyLocalNameValue.OperateCurFloor();
-                        break;
-                    default:
-                        break;
+                    WinParameterDic win = new WinParameterDic();
+
+                    if (win.ShowDialog() == true)
+                    {
+                        SingleInstance<CopyParameterValue>.Instance.SetCopyParameterDic(win.ParameterDic);
+                        switch (tip)
+                        {
+                            case DialogResult.Yes:
+                                SingleInstance<CopyParameterValue>.Instance.ExecuteAll();
+                                break;
+                            case DialogResult.No:
+                                MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
+                                if (floor != null)
+                                    SingleInstance<CopyParameterValue>.Instance.Execute(floor);
+                                break;
+                        }
+                        MessageShowBase.Infomation("信息点的值复制完成");
+                    }
                 }
-                MessageShowBase.Infomation("信息点的值复制完成");
+
             }
             catch (Exception e)
             {

+ 0 - 153
MBI/SAGA.MBI/ToolsData/CopyLocalNameValue.cs

@@ -1,153 +0,0 @@
-/* ==============================================================================
- * 功能描述:复制本地名称或本地编码的值
- * 创 建 者:Garrett
- * 创建日期:2018/7/12 14:25:17
- * ==============================================================================*/
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using SAGA.DotNetUtils.Others;
-using SAGA.MBI.Calc;
-using SAGA.MBI.Model;
-using SAGA.MBI.RequestData;
-using SAGA.MBI.WinView.Upload;
-using Autodesk.Revit.DB;
-using Autodesk.Revit.DB.Mechanical;
-using SAGA.DotNetUtils;
-using SAGA.DotNetUtils.Logger;
-using SAGA.MBI.Common;
-using SAGA.MBI.DataArrange;
-using SAGA.MBI.Tools;
-using SAGA.RevitUtils.Extends;
-
-namespace SAGA.MBI.ToolsData
-{
-    /// <summary>
-    /// CheckEquipCategory
-    /// </summary>
-    public class CopyLocalNameValue
-    {
-        /// <summary>
-        /// 检查并处理所有楼层
-        /// </summary>
-        public static int OperateAll()
-        {
-            int count = 0;
-            var floors = DalUploadFloor.GetHasFileFloors();
-            foreach (UploadFloor floor in floors)
-            {
-                count += Operate(floor.MFloor);
-            }
-            return count;
-        }
-        /// <summary>
-        /// 只处理当前楼层
-        /// </summary>
-        public static int OperateCurFloor()
-        {
-            int count = 0;
-            MFloor floor = ExternalDataWrapper.Current.Doc.GetCurMFloor();
-            if (floor != null)
-                count = Operate(floor);
-            return count;
-        }
-        /// <summary>
-        /// 检查并处理
-        /// </summary>
-        /// <param name="floor"></param>
-        /// <returns>失败的个数</returns>
-        private static int Operate(MFloor floor)
-        {
-            List<string> errorids = new List<string>();
-            var context = new CalcContext(floor);
-            try
-            {
-                context.OpenDocument();
-                var doc = context.RevitDoc;
-                using (Transaction trans = new Transaction(doc, "复制本地名称,本地编码的值"))
-                {
-                    trans.Start();
-                    try
-                    {
-                        var fis = doc.GetMbiElements();
-                        foreach (var fi in fis)
-                        {
-                            if (fi.IsEquipment() || fi.IsEquipmentPart())
-                                if (!CopyProperty(fi))
-                                    errorids.Add(fi.Id.ToString());
-                        }
-                        trans.Commit();
-                    }
-                    catch (Exception)
-                    {
-                        trans.RollBack();
-                    }
-                }
-            }
-            catch (Exception e)
-            {
-                MessageShowBase.Show(e);
-            }
-            finally
-            {
-                context.RevitDoc.CloseDoc();
-            }
-            //if (errorids.Count > 0)
-            //    MessageShowBase.Infomation($"楼层 {floor} 下列对象的参数复制失败,请检查!\r\n" + string.Join(",", errorids));
-            return errorids.Count;
-        }
-
-        /// <summary>
-        /// 复制值:
-        /// 从设备本地名称到设备本地名称2
-        /// 从设备本地编码到设备本地编码2
-        /// 从设备编号到设备本地编码
-        /// </summary>
-        /// <param name="fi"></param>
-        /// <returns>True成功,False失败</returns>
-        private static bool CopyProperty(Element fi, bool isBackupValue = false)
-        {
-            bool result = false;
-            try
-            {
-                Parameter localIdParameter = fi.GetParameter(RevitBuiltInParameter.EquipLocalID);
-                Parameter numParameter = fi.GetParameter("设备编号");
-                if (localIdParameter != null)
-                {
-                    if (isBackupValue)
-                    {
-                        Parameter localNameParameter = fi.GetParameter(RevitBuiltInParameter.EquipLocalName);
-                        Parameter localNameParameter2 = fi.GetParameter("设备本地名称2");
-                        Parameter localIdParameter2 = fi.GetParameter("设备本地编码2");
-                        if (localNameParameter != null)
-                        {
-                            if (localIdParameter2 != null && localNameParameter2 != null)
-                            {
-                                localIdParameter2.SetValueString(localIdParameter.GetParameterString());
-                                localNameParameter2.SetValueString(localNameParameter.GetParameterString());
-                            }
-                        }
-                    }
-
-                    if (numParameter != null)
-                    {
-                        string originValue = localIdParameter.GetParameterString();
-                        string numvalue = numParameter.GetParameterString();
-                        if (originValue.IsNullOrEmpty()&& numvalue.IsNotNullEmpty())
-                            result = localIdParameter.Set(numvalue);
-                    }
-
-                }
-            }
-            catch (Exception e)
-            {
-                Console.WriteLine(e);
-                return false;
-            }
-
-            return result;
-        }
-    }
-}

+ 2 - 1
MBI/SAGA.MBI/ToolsData/ExportAllDuty.cs

@@ -79,6 +79,7 @@ namespace SAGA.MBI.ToolsData
         {
             SaveFileDialog sflg = new SaveFileDialog();
             sflg.Filter = "Excel(*.xlsx)|*.xlsx";
+            sflg.FileName = $"{MBIControl.ProjectCur}岗位汇总表";
             if (sflg.ShowDialog() != true) return;
             ExportToExcel(contexts, sflg.FileName, sflg.FilterIndex);
         }
@@ -131,7 +132,7 @@ namespace SAGA.MBI.ToolsData
 
                     Action<MRevitEquipBase, string> action = (equip, type) =>
                      {
-                         var family = equip.EquipClassCode;
+                         string family = equip.EquipClassCode+"-"+equip.Family?.Name;
                          var id = equip.Id;
                          var bimid = equip.BimID.GetBIMID();
                          index++;