Browse Source

mxg:上传忽略的文件

mengxiangge 5 years ago
parent
commit
d290dc923f

+ 0 - 1
.gitignore

@@ -18,6 +18,5 @@
 /FWindSoft/RevitBase/RevitVersion/bin/
 /FWindSoft/RevitBase/RevitVersion/bin/
 /FWindSoft/RevitBase/RevitVersion/obj/
 /FWindSoft/RevitBase/RevitVersion/obj/
 /FWindSoft/Test
 /FWindSoft/Test
-*.cs
 *.cache
 *.cache
 /FWindSoft/Saga.PlugIn/obj/
 /FWindSoft/Saga.PlugIn/obj/

+ 24 - 0
FWindSoft/Saga.PlugIn/CreateFacility/CreateFacilityConst.cs

@@ -0,0 +1,24 @@
+/* ==============================================================================
+ * 功能描述:CreateFacilityConst  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/23 10:50:02
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// CreateFacilityConst
+    /// </summary>
+    public class CreateFacilityConst
+    {
+        /// <summary>
+        /// 资产id
+        /// </summary>
+        public const string PropertyID = "PropertyID";
+    }
+}

+ 165 - 0
FWindSoft/Saga.PlugIn/CreateFacility/CreateFacilityRevitUtils.cs

@@ -0,0 +1,165 @@
+/* ==============================================================================
+ * 功能描述:CreateFacilityRevitUtils  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/23 10:24:09
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Text.RegularExpressions;
+using System.Threading.Tasks;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.UI;
+using Autodesk.Revit.DB.Structure;
+using Saga.PlugIn.ModelCheck;
+using SAGA.DotNetUtils.Others;
+using SAGA.RevitUtils.Extends;
+using SAGA.RevitUtils.Windows;
+using FWindSoft.Revit;
+using SAGA.DotNetUtils;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// CreateFacilityRevitUtils
+    /// </summary>
+    public class CreateFacilityRevitUtils
+    {
+        /// <summary>
+        /// 由资产id查找模型中的设备
+        /// </summary>
+        /// <param name="code"></param>
+        /// <param name="propertyId"></param>
+        /// <returns></returns>
+        public static string FindFacility(Document doc,string code, string propertyId)
+        {
+            var facilities = DocumentExtension.GetElements<FamilyInstance>(doc);
+            string id = null;
+            foreach (FamilyInstance facility in facilities)
+            {
+                var familyName = facility.GetFamilyName();
+                if (familyName.StartsWith(code))
+                {
+                    var parameter = ParameterExtend.GetParameterString(facility, CreateFacilityConst.PropertyID);
+                    if (parameter == propertyId)
+                    {
+                        id = facility.Id.ToString();
+                        break;
+                    }
+                }
+            }
+            return id;
+        }
+        /// <summary>
+        /// 定位模型
+        /// </summary>
+        /// <param name="id"></param>
+        public static void FocusFacility(string id)
+        {
+            RevitCore.UIApp.SetShowElements(new ElementId(id.ToInt()));
+        }
+        /// <summary>
+        /// 自动创建设备
+        /// </summary>
+        /// <param name="doc"></param>
+        /// <param name="code"></param>
+        /// <param name="location"></param>
+        /// <param name="propertyId"></param>
+        /// <returns></returns>
+        public static string CreateFacility(Document doc, MFacilityClass facilityClass, MXYZ location, string propertyId)
+        {
+            FamilyInstance fi = null;
+
+            using (Transaction trans = new Transaction(doc, "自动创建模型"))
+            {
+                trans.Start();
+                try
+                {
+                    FamilySymbol fs = GetFamilySymbol(doc, facilityClass.code);
+                    if (fs == null)
+                    {
+                        WinTipMissFamily win=new WinTipMissFamily($"{facilityClass.code}-{facilityClass.name}");
+                        win.ShowDialog();
+                        return null;
+                    }
+
+                    if (IsBasePointFamily(fs))
+                    {
+                        //使用BIMLocation中的坐标,mm转为英寸
+                        XYZ xyz = new XYZ(location.X.ToDouble().ToApi(), location.Y.ToDouble().ToApi(),
+                            location.Z.ToDouble().ToApi());
+                        xyz = xyz == null ? XYZ.Zero : xyz.ConvertToApi();
+                        var level = GetCurFloorLevel(doc);
+                        //传标高,z值设置为零
+                        xyz = xyz.NewZ(0);
+                        fi = doc.Create.NewFamilyInstance(xyz, fs, level, StructuralType.NonStructural);
+                        //假如定位点和中心点不一致,平移设备,将设备中心点移到定位点上
+                        doc.Regenerate();
+                        fi.SetSharedParameter(CreateFacilityConst.PropertyID, propertyId);
+                        XYZ centerXyz = FWindSoft.Revit.ElementExtension.GetLocationPoint(fi).NewZ(0);
+                        if (!centerXyz.IsEqual2(xyz))
+                        {
+                            XYZ vector = xyz - centerXyz;
+                            doc.MoveElement(fi.Id, vector);
+                        }
+
+                        trans.Commit();
+                    }
+                    else
+                    {
+                        MessageShowBase.Infomation("自动创建只能创建基于点的族,请查看族类型");
+                    }
+
+                }
+                catch (Exception e)
+                {
+                    trans.RollBack();
+                }
+            }
+
+            return fi?.Id.ToString();
+        }
+        /// <summary>
+        /// 判断是否为基于点的设备
+        /// </summary>
+        /// <param name="fs"></param>
+        /// <returns></returns>
+        private static bool IsBasePointFamily(FamilySymbol fs)
+        {
+            bool result = false;
+            Family fa = fs?.Family;
+            if (fa == null) return result;
+            result = fa.FamilyPlacementType == FamilyPlacementType.OneLevelBased;
+            return result;
+        }
+
+        private static Level GetCurFloorLevel(Document doc)
+        {
+            var view = DocumentExtension.GetElements<ViewPlan>(doc).FirstOrDefault(t => t.GenLevel?.Name != null && t.Name?.IndexOf("-saga") > -1 && t.ViewType == ViewType.FloorPlan);
+            Level level = view?.GenLevel ?? doc.GetLevels().FirstOrDefault();
+            return level;
+        }
+        /// <summary>
+        /// 由code获取FamilySymbol
+        /// </summary>
+        /// <param name="doc"></param>
+        /// <param name="code"></param>
+        /// <returns></returns>
+        public static FamilySymbol GetFamilySymbol(Document doc,string code)
+        {
+            Func<string, bool> filterFamily = (t) =>
+            {
+                return Regex.IsMatch(t, $@"{code}{ModelCheckConst.IsFamilyCode}");
+            };
+            List<Family> listFamily = doc.GetFamilys();
+            var fa = listFamily.FirstOrDefault(t => filterFamily(t.Name));
+            if (fa == null) return null;
+            List<FamilySymbol> symbolList = FamilyExtension.GetFamilySymbols(fa);
+            var fs = symbolList?.FirstOrDefault();
+            if (fs != null && !fs.IsActive)
+                fs.Activate();
+            return fs;
+        }
+    }
+}

+ 43 - 0
FWindSoft/Saga.PlugIn/CreateFacility/MFacilityTabCode.cs

@@ -0,0 +1,43 @@
+/* ==============================================================================
+ * 功能描述:MCreateFacility  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/22 17:33:04
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// MCreateFacility
+    /// </summary>
+    public class MFacilityTabCode
+    {
+        public string FloorName { get; set; }
+
+        public string BuildingName { get; set; }
+
+        public string Id { get; set; }
+
+        public MXYZ BIMLocation { get; set; }
+
+        public List<MFacilityClass> EquipClasses { get; set; }
+    }
+
+    public class MFacilityClass
+    {
+        public string code { get; set; }
+
+        public string name { get; set; }
+    }
+
+    public class MXYZ
+    {
+        public string X { get; set; }
+        public string Y { get; set; }
+        public string Z { get; set; }
+    }
+}

+ 31 - 0
FWindSoft/Saga.PlugIn/CreateFacility/ParseFacilityTabCode.cs

@@ -0,0 +1,31 @@
+/* ==============================================================================
+ * 功能描述:ParseFacilityTabCode  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/22 17:43:59
+ * ==============================================================================*/
+
+using System;
+using System.IO;
+using Newtonsoft.Json;
+using SAGA.DotNetUtils.Serializer;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// ParseFacilityTabCode
+    /// </summary>
+    public class ParseFacilityTabCode
+    {
+        public static MFacilityTabCode Parse(string json)
+        {
+            try
+            {
+                return JsonConvert.DeserializeObject<MFacilityTabCode>(json);
+            }
+            catch (Exception e)
+            {
+                return null;
+            }
+        }
+    }
+}

+ 173 - 0
FWindSoft/Saga.PlugIn/CreateFacility/VMCreateFacility.cs

@@ -0,0 +1,173 @@
+/* ==============================================================================
+ * 功能描述:VMCreateFacility  
+ * 创 建 者:Garrett
+ * 创建日期:2019/10/23 9:46:45
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using Autodesk.Revit.DB;
+using Saga.PlugIn.ModelCheck;
+using SAGA.DotNetUtils.Others;
+using SAGA.DotNetUtils.WPF;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// VMCreateFacility
+    /// </summary>
+    public class VMCreateFacility:BaseViewModelStub
+    {
+        public VMCreateFacility(Document doc)
+        {
+            m_Document = doc;
+            ModelFilePath = doc.PathName;
+        }
+
+        private Document m_Document;
+
+        private string m_TabCode;
+        /// <summary>
+        /// 标记码
+        /// </summary>
+
+        public string TabCode
+        {
+            get { return m_TabCode; }
+            set
+            {
+                m_TabCode = value;
+                NotifyPropertyChanged("TabCode");
+                MFacilityTabCode = ParseFacilityTabCode.Parse(value);
+            }
+        }
+
+        private MFacilityTabCode m_MFacilityTabCode;
+
+        public MFacilityTabCode MFacilityTabCode
+        {
+            get { return m_MFacilityTabCode; }
+            set
+            {
+                m_MFacilityTabCode = value;
+                FacilityLocated = $"{value?.BuildingName}-{value?.FloorName}";
+            }
+        }
+
+        private string m_FacilityLocated;
+        /// <summary>
+        /// 设备所在位置
+        /// </summary>
+        public string FacilityLocated
+        {
+            get { return m_FacilityLocated; }
+            set
+            {
+                m_FacilityLocated = value;
+                NotifyPropertyChanged("FacilityLocated");
+            }
+        }
+
+
+        private string m_ModelFilePath;
+        /// <summary>
+        /// 模型文件地址
+        /// </summary>
+        public string ModelFilePath
+        {
+            get { return m_ModelFilePath; }
+            set
+            {
+                m_ModelFilePath = value;
+                NotifyPropertyChanged("ModelFilePath");
+            }
+        }
+
+        #region command
+
+        [Command]
+        public void PasteTabCode(object param)
+        {
+            IDataObject iData = Clipboard.GetDataObject();
+            if (iData.GetDataPresent(DataFormats.Text))
+            {
+                TabCode = (String)iData.GetData(DataFormats.Text);
+            }
+        }
+        public bool CanPasteTabCode(object param)
+        {
+            return true;
+        }
+
+
+        [Command]
+        public void ClearTabCode(object param)
+        {
+            TabCode = null;
+        }
+        public bool CanClearTabCode(object param)
+        {
+            return true;
+        }
+
+        [Command]
+        public void Execute(object param)
+        {
+            if (string.IsNullOrEmpty(MFacilityTabCode.Id))
+            {
+                MessageShowBase.Infomation("粘贴设备类数据异常,请检查");
+                return;
+            }
+            //选择设备类
+            var facilityCodes = MFacilityTabCode.EquipClasses;
+            WinSelectDeviceClass win=new WinSelectDeviceClass(facilityCodes);
+            if (facilityCodes.Count > 1)
+            {
+                if(win.ShowDialog()!=true)
+                    return;
+            }
+
+            var facilityClass = win.SelectedCode;
+            if (facilityClass == null)
+            {
+                MessageShowBase.Infomation("粘贴设备类数据异常,请检查");
+                return;
+            }
+            //判断是否存在
+            var id = CreateFacilityRevitUtils.FindFacility(m_Document, facilityClass.code, MFacilityTabCode.Id);
+            if (!string.IsNullOrEmpty(id))
+            {
+                WinTipExisted winTipExisted=new WinTipExisted(id);
+                if (winTipExisted.ShowDialog() == true)
+                    TabCode = null;
+                return;
+            }
+            //创建
+            var winBase = param as Window;
+            if (winBase != null)
+            {
+                winBase.Close();
+                id = CreateFacilityRevitUtils.CreateFacility(m_Document, facilityClass, MFacilityTabCode.BIMLocation,
+                    MFacilityTabCode.Id);
+                if (!string.IsNullOrEmpty(id))
+                {
+                    WinTipCreateSuccess winTipCreateSuccess=new WinTipCreateSuccess(id);
+                    winTipCreateSuccess.ShowDialog();
+                }
+            }
+
+        }
+        public bool CanExecute(object param)
+        {
+            return MFacilityTabCode!=null;
+        }
+
+
+
+
+        #endregion
+    }
+}

+ 44 - 0
FWindSoft/Saga.PlugIn/CreateFacility/WinCreateFacility.xaml.cs

@@ -0,0 +1,44 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Windows;
+using Microsoft.Win32;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
+using System.Windows.Forms;
+using Saga.PlugIn.CreateFacility;
+
+namespace Saga.PlugIn.ModelCheck
+{
+    /// <summary>
+    /// WinModeCheckSetting.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinCreateFacility
+    {
+        public WinCreateFacility(VMCreateFacility viewmodel)
+        {
+            InitializeComponent();
+            this.DataContext = viewmodel;
+        }
+        
+
+        #region BindingProperty
+        #endregion
+
+
+        #region Action
+
+        private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
+        {
+            this.DialogResult = true;
+        }
+        
+        #endregion
+
+       
+    }
+}
+

+ 70 - 0
FWindSoft/Saga.PlugIn/CreateFacility/WinSelectDeviceClass.xaml.cs

@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Threading;
+using System.Windows;
+using Microsoft.Win32;
+using SAGA.DotNetUtils;
+using SAGA.DotNetUtils.Extend;
+using System.Windows.Forms;
+using Saga.PlugIn.CreateFacility;
+
+namespace Saga.PlugIn.ModelCheck
+{
+    /// <summary>
+    /// WinModeCheckSetting.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinSelectDeviceClass:INotifyPropertyChanged
+    {
+        public WinSelectDeviceClass(List<MFacilityClass> classCodes)
+        {
+            InitializeComponent();
+            ClassCodes = classCodes;
+            SelectedCode = classCodes.FirstOrDefault();
+            this.DataContext = this;
+        }
+
+
+        #region BindingProperty
+        private List<MFacilityClass> m_ClassCodes;
+
+        public List<MFacilityClass> ClassCodes
+        {
+            get { return m_ClassCodes; }
+            set
+            {
+                m_ClassCodes = value;
+            }
+        }
+
+        private MFacilityClass m_SelectedCode;
+
+        public event PropertyChangedEventHandler PropertyChanged;
+
+        public MFacilityClass SelectedCode
+        {
+            get { return m_SelectedCode; }
+            set
+            {
+                m_SelectedCode = value;
+                PropertyChanged?.Invoke(this,new PropertyChangedEventArgs("SelectedCode"));
+            }
+        }
+
+        #endregion
+
+
+        #region Action
+
+        private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
+        {
+            this.DialogResult = true;
+        }
+        
+        #endregion
+    }
+}
+

+ 42 - 0
FWindSoft/Saga.PlugIn/CreateFacility/WinTipCreateSuccess.xaml.cs

@@ -0,0 +1,42 @@
+using System.Windows;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// WinTipMissFamily.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinTipCreateSuccess
+    {
+
+        public WinTipCreateSuccess(string id)
+        {
+            InitializeComponent();
+            m_id = id;
+            Tip = $"BIMID:{id}";
+            this.DataContext = this;
+        }
+
+        private string m_id;
+        private string m_Tip;
+
+        public string Tip
+        {
+            get { return m_Tip; }
+            set { m_Tip = value; }
+        }
+
+        #region Action
+
+        private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
+        {
+            this.DialogResult = true;
+        }
+
+        private void ButtonCopy_OnClick(object sender, RoutedEventArgs e)
+        {
+            Clipboard.SetDataObject(m_id);
+        }
+        #endregion
+
+    }
+}

+ 47 - 0
FWindSoft/Saga.PlugIn/CreateFacility/WinTipExisted.xaml.cs

@@ -0,0 +1,47 @@
+using System.Windows;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// WinTipMissFamily.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinTipExisted
+    {
+
+        public WinTipExisted(string id)
+        {
+            InitializeComponent();
+            m_id = id;
+            Tip = $"BIMID:{id}";
+            this.DataContext = this;
+        }
+
+        private string m_id;
+        private string m_Tip;
+
+        public string Tip
+        {
+            get { return m_Tip; }
+            set { m_Tip = value; }
+        }
+
+        #region Action
+
+        private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
+        {
+            this.DialogResult = true;
+        }
+
+        private void ButtonCopy_OnClick(object sender, RoutedEventArgs e)
+        {
+            Clipboard.SetDataObject(m_id);
+        }
+
+        private void ButtonFocus_OnClick(object sender, RoutedEventArgs e)
+        {
+            CreateFacilityRevitUtils.FocusFacility(m_id);
+        }
+        #endregion
+
+    }
+}

+ 34 - 0
FWindSoft/Saga.PlugIn/CreateFacility/WinTipMissFamily.xaml.cs

@@ -0,0 +1,34 @@
+using System.Windows;
+
+namespace Saga.PlugIn.CreateFacility
+{
+    /// <summary>
+    /// WinTipMissFamily.xaml 的交互逻辑
+    /// </summary>
+    public partial class WinTipMissFamily
+    {
+        public WinTipMissFamily(string familyName)
+        {
+            InitializeComponent();
+            Tip = $"缺少族文件【{familyName}】,请手动载入族后重试";
+            this.DataContext = this;
+        }
+
+        private string m_Tip;
+
+        public string Tip
+        {
+            get { return m_Tip; }
+            set { m_Tip = value; }
+        }
+
+        #region Action
+
+        private void ButtonNext_OnClick(object sender, RoutedEventArgs e)
+        {
+            this.DialogResult = true;
+        }
+
+        #endregion
+    }
+}

+ 31 - 0
FWindSoft/Saga.PlugIn/CreateFacilityCommand.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using FWindSoft.Revit;
+using Autodesk.Revit.Attributes;
+using Autodesk.Revit.DB;
+using Autodesk.Revit.UI;
+using FWindSoft.Revit.ExtensibleStorage;
+using FWindSoft.Revit.Menu;
+using Saga.PlugIn.CreateFacility;
+using Saga.PlugIn.ModelCheck;
+
+namespace Saga.PlugIn
+{
+    [Transaction(TransactionMode.Manual)]
+    [Regeneration(RegenerationOption.Manual)]
+    [Button(ButtonName = "待建模设备", Index = -1)]
+    public class CreateFacilityCommand : ExternalCommand
+    {
+        public override Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
+        {
+            var doc = RevitCore.Doc;
+            VMCreateFacility viewModel=new VMCreateFacility(doc);
+            WinCreateFacility win=new WinCreateFacility(viewModel);
+            win.ShowDialog();
+            return Result.Succeeded;
+        }
+    }
+}

BIN
FWindSoft/Saga.PlugIn/ModelCheck/ExcelTemplate/模型检查结果输出格式-模版.xlsx