Преглед на файлове

mxg:修改正则表达式的匹配模式

mengxiangge преди 6 години
родител
ревизия
36a54ab164

+ 4 - 5
MBI/SAGA.DotNetUtils/WPF/Converter/StringToImageConverter.cs

@@ -5,6 +5,7 @@
  * ==============================================================================*/
 using System;
 using System.Collections.Generic;
+using System.IO;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
@@ -12,6 +13,7 @@ using System.Windows.Data;
 using System.Windows.Media.Imaging;
 using System.Windows.Resources;
 using System.Windows;
+using System.Windows.Media;
 
 namespace SAGA.DotNetUtils.WPF.Converter
 {
@@ -24,14 +26,11 @@ namespace SAGA.DotNetUtils.WPF.Converter
         {
             BitmapImage img = new BitmapImage();
             if (value == null) return img;
-            //若要原始文件的站点,可以调用 Application 类的 GetRemoteStream 方法,同时传递标识原始文件的所需站点的 pack URI。 GetRemoteStream 将返回一个 StreamResourceInfo 对象,该对象将原始文件的该站点作为 Stream 公开,并描述其内容类型。
             try
             {
-                var uri = new Uri(value.ToString().Replace("%20", " "), UriKind.Relative);
-                StreamResourceInfo info = Application.GetRemoteStream(uri);
+                var bytes = File.ReadAllBytes(value.ToString());
                 img.BeginInit();
-                //img.UriSource = new Uri(value.ToString(), UriKind.Relative);
-                img.StreamSource = info.Stream;
+                img.StreamSource = new MemoryStream(bytes);
                 img.EndInit();
             }
             catch (Exception e)

+ 2 - 2
MBI/SAGA.DotNetUtils/WPF/UserControl/SelectPath_Start.xaml.cs

@@ -37,7 +37,7 @@ namespace SAGA.DotNetUtils.WPF.UserControl
             set { SetValue(BtnImageProperty, value); }
         }
 
-        public Action AttachAction;
+        public Action<System.Windows.Controls.UserControl,string> AttachAction;
 
         private void Button_Click(object sender, RoutedEventArgs e)
         {
@@ -48,7 +48,7 @@ namespace SAGA.DotNetUtils.WPF.UserControl
             {
                 string foldPath = dialog.SelectedPath;
                 Text = foldPath;
-                AttachAction?.Invoke();
+                AttachAction?.Invoke(this,foldPath);
             }
         }
 

+ 41 - 0
MBI/SAGA.MBI/Common/RegexConstPattern.cs

@@ -0,0 +1,41 @@
+/* ==============================================================================
+ * 功能描述:RegexPatten  
+ * 创 建 者:Garrett
+ * 创建日期:2019/5/29 14:12:17
+ * ==============================================================================*/
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.MBI.Common
+{
+    /// <summary>
+    /// RegexPatten
+    /// </summary>
+    class RegexConstPattern
+    {
+        public const string IsSpaceId = @"Si\S*";
+        public const string IsEquipId = @"Si\S*";
+        public const string IsEquipPartId = @"Si\S*";
+        public const string IsBeaconId = @"Si\S*";
+
+        public const string IsFamilyCode = @"\s*-\s*\S*";
+
+        public const string IsEquip = @"^[A-Z]{4}\s*-\s*\S*";
+        public const string IsEquipPart = @"^[A-Z]{6}\s*-\s*\S*";
+
+        public const string IsMBILevel = @"([BF][1-9]\d*M?\d?|RFM?\d?)";
+        public const string IsMBIView = @"^([BF][1-9]\d*M?\d?|RFM?\d?)-saga$";
+        public const string IsSandwich = @"([BF][1-9]\d*M\d?|RFM\d?)";
+
+        public const string IsRF = @"^RF(-saga)?$";
+        public const string IsRFM = @"RFM\d*";
+        public const string IsOnground = @"^B\s*";
+        public const string IsUnderground = @"^B\s*";
+
+        public const string IsPhoneNumber = @"^1[3|4|5|7|8][0-9]\d{8}$";
+
+    }
+}

+ 4 - 4
MBI/SAGA.MBI/DataArrange/DalCommon.cs

@@ -221,7 +221,7 @@ namespace SAGA.MBI.DataArrange
         public static bool Delete(string cloudId)
         {
             //空间
-            if (Regex.IsMatch(cloudId, @"Si\S*"))
+            if (Regex.IsMatch(cloudId, $"{RegexConstPattern.IsSpaceId}"))
             {
                 var rlt = new RltEquipInSpace(null, cloudId) { Operator = DocumentChangedOperator.Delete };
                 rlt.DelObject();
@@ -229,21 +229,21 @@ namespace SAGA.MBI.DataArrange
                 return SpaceConvert.DelSpace(cloudId);
             }
             //设备
-            if (Regex.IsMatch(cloudId, @"Eq\S*"))
+            if (Regex.IsMatch(cloudId, $"{RegexConstPattern.IsEquipId}"))
             {
                 var rlt = new RltEquipInSpace(cloudId, null) { Operator = DocumentChangedOperator.Delete };
                 rlt.DelObject();  //删除空间
                 return EquipmentConvert.DelEquipment(cloudId);
             }
             // 部件
-            if (Regex.IsMatch(cloudId, @"Ec\S*"))
+            if (Regex.IsMatch(cloudId, $"{RegexConstPattern.IsEquipPartId}"))
             {
                 var rlt = new RltEquipInSpace(cloudId, null) { Operator = DocumentChangedOperator.Delete };
                 rlt.DelObject();
                 return EquipmentPartConvert.DelEquipmentPart(cloudId);
             }
             //信标
-            if (Regex.IsMatch(cloudId, @"VOBc\S*"))
+            if (Regex.IsMatch(cloudId, $"{RegexConstPattern.IsBeaconId}"))
             {
                 var rltbeaconinsp = new RltBeaconinElementSp(cloudId, null) { Operator = DocumentChangedOperator.Delete };
                 rltbeaconinsp.DelObject();

+ 1 - 1
MBI/SAGA.MBI/Extend/DocExtend.cs

@@ -131,7 +131,7 @@ namespace SAGA.MBI.Tools
         {
             Func<string, bool> filterFamily = (t) =>
             {
-                return Regex.IsMatch(t, $@"{code}\s*-\s*\S*");
+                return Regex.IsMatch(t, $@"{code}{RegexConstPattern.IsFamilyCode}");
             };
             List<Family> listFamily = doc.GetFamilys();
             var fa = listFamily.FirstOrDefault(t => filterFamily(t.Name));

+ 4 - 7
MBI/SAGA.MBI/Extend/ElementExtend.cs

@@ -44,7 +44,7 @@ namespace SAGA.MBI.Tools
             if (element is FamilyInstance fi)
             {
                 var family = fi.GetFamilyName();
-                result = Regex.IsMatch(family, @"^[A-Z]{4}\s*-\s*\S*");
+                result = Regex.IsMatch(family, $"{RegexConstPattern.IsEquip}");
             }
 
             return result;
@@ -60,7 +60,7 @@ namespace SAGA.MBI.Tools
             if (element is FamilyInstance fi)
             {
                 var family = fi.GetFamilyName();
-                result = Regex.IsMatch(family, @"^[A-Z]{6}\s*-\s*\S*");
+                result = Regex.IsMatch(family, $"{RegexConstPattern.IsEquipPart}");
             }
 
             return result;
@@ -70,12 +70,9 @@ namespace SAGA.MBI.Tools
         /// </summary>
         /// <param name="family"></param>
         /// <returns></returns>
-        public static bool IsMbiEquipment(this Family family)
+        public static bool IsMbiEquipment(this Element element)
         {
-            var familyName = family.Name;
-            if (string.IsNullOrEmpty(familyName))
-                return false;
-            return Regex.IsMatch(familyName, @"^[A-Z]{4}\s*-\s*\S*") || Regex.IsMatch(familyName, @"^[A-Z]{6}\s*-\s*\S*");
+            return element.IsEquipment()||element.IsEquipmentPart();
         }
         /// <summary>
         /// 判断是否为信标

+ 1 - 1
MBI/SAGA.MBI/RevitExport/ParseElement/ParseEquipment.cs

@@ -28,7 +28,7 @@ namespace SAGA.MBI.RevitExport.ParseElement
                     return;
                 var family = equipment.GetFamily();
                 var name = family.Name;
-                if (!family.IsMbiEquipment())
+                if (!equipment.IsMbiEquipment())
                 {
                     return;
                 }

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

@@ -276,6 +276,7 @@
     <Compile Include="Common\MailLog.cs" />
     <Compile Include="Common\MessageManager.cs" />
     <Compile Include="Common\PhaseUtil.cs" />
+    <Compile Include="Common\RegexConstPattern.cs" />
     <Compile Include="Common\RevitBuiltInParameter.cs" />
     <Compile Include="Common\WaitingView.cs" />
     <Compile Include="DataArrange\DalInfoCode.cs" />

+ 1 - 1
MBI/SAGA.MBI/ToolsData/ModeCheck/DataCheckRule.cs

@@ -143,7 +143,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
             {
                 Regex regex = new Regex(@"^[A-Z]{4}");
                 list = str.Split(new[] { ',', ',' })
-                    .Where(t => Regex.IsMatch(t, @"^[A-Z]{4}\s*-\s*\S*"))
+                    .Where(t => Regex.IsMatch(t, $"{RegexConstPattern.IsEquip}"))
                     .Select(tt => regex.Match(tt).Value).ToList();
             }
 

+ 4 - 35
MBI/SAGA.MBI/ToolsData/ModeCheck/ElementRangeCheck.cs

@@ -18,6 +18,7 @@ using SAGA.MBI.ToolsData.CheckBase;
 using SAGA.RevitUtils.Extends;
 using NPOI.SS.Util;
 using NPOI.XSSF.UserModel;
+using SAGA.MBI.Common;
 
 namespace SAGA.MBI.ToolsData.ModeCheck
 {
@@ -127,8 +128,8 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                 //设置楼层底部高度
                 var curLevelName = result.RFloorName;
                 var levels = doc.GetLevels();
-                var mbiLevels = levels.Where(t => Regex.IsMatch(t.Name, @"([BF][1-9]\d*M?\d?|RFM?\d?)")).ToList();
-                Func<string, bool> isSandwichFunc = (str) => { return Regex.IsMatch(str, @"([BF][1-9]\d*M\d?|RFM?\d?)");};
+                var mbiLevels = levels.Where(t => Regex.IsMatch(t.Name, $"{RegexConstPattern.IsMBILevel}")).ToList();
+                Func<string, bool> isSandwichFunc = (str) => { return Regex.IsMatch(str, $"{RegexConstPattern.IsSandwich}");};
                 //设置楼层顶部高度
                 if (curLevelName == "RF")
                 {
@@ -149,39 +150,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                     }
                 }
 
-                //if (curLevelName == "RF" || curLevelName == "RFM")
-                //{
-                //    result.HTop = double.MaxValue;
-                //    result.HSamdwich = double.MaxValue;
-                //}
-                //else
-                //{
-                //    if (topLevel == null)
-                //    {
-                //        throw new Exception($"标高编码不合法:{curLevelName}不应该是顶层,缺少标高RF或标高RF标注的位置不正确");
-                //    }
-                //    double nextL = topLevel.Elevation;
-                //    string tempTopLevelName = topLevel.Name;
-                //    //如果是夹层,获取夹层的上一层
-                //    if (Regex.IsMatch(tempTopLevelName, @"([BF][1-9]\d*M|RFM)"))
-                //    {
-                //        result.HSamdwich = nextL;
-                //        topLevel = mbiLevels.FirstOrDefault(t => t.Elevation.IsThan(nextL));
-                //        if (topLevel == null)
-                //        {
-                //            throw new Exception($"标高编码不合法:{tempTopLevelName}不应该是顶层,缺少标高RF或标高RF标注的位置不正确");
-                //        }
-                //        else
-                //        {
-                //            result.HTop = topLevel.Elevation;
-                //        }
-                //    }
-                //    else
-                //    {
-                //        result.HSamdwich = nextL;
-                //        result.HTop = nextL;
-                //    }
-                //}
+           
             }
             catch (Exception e)
             {

+ 40 - 58
MBI/SAGA.MBI/ToolsData/ModeCheck/FloorMissCheck.cs

@@ -47,7 +47,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
             }
             //检查楼层顺序号
             IsRight = GetCheckResult();
-            Results.ForEach(t=>t.IsRight=IsRight);
+            Results.ForEach(t => t.IsRight = IsRight);
             RMessage = IsRight ? "" : "楼层平面图名称错误或缺失楼层,请检查";
             return IsRight;
         }
@@ -88,6 +88,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                         }
                     }
                 }
+
             }
             RBase.Results.ForEach(t => Results.Add(new FloorMissCheckResult { RBase = t }));
 
@@ -154,7 +155,7 @@ namespace SAGA.MBI.ToolsData.ModeCheck
 
     class SSCSComparerByFloorName : IComparer<SagaSignCheckResult>
     {
-        private static List<string> m_RuleFloorNames = new List<string> { "RF", "RFM", @"F\d*M?", @"B\d*M?" };
+        private static List<string> m_RuleFloorNames = new List<string> { RegexConstPattern.IsRF, RegexConstPattern.IsRFM, RegexConstPattern.IsOnground, RegexConstPattern.IsUnderground };
         public int Compare(SagaSignCheckResult x, SagaSignCheckResult y)
         {
             string floorName0 = x.RFloorName;
@@ -171,20 +172,10 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                 //分组组号对比
                 if (item0 == item1)
                 {
-                    int i0 = GetFloorNameIndex(floorName0);
-                    int i1 = GetFloorNameIndex(floorName1);
+                    double i0 = GetFloorNameIndex(floorName0);
+                    double i1 = GetFloorNameIndex(floorName1);
                     //楼层序号对比
-                    if (i0 == i1)
-                    {
-                        int j0 = IsSamdwich(floorName0);
-                        int j1 = IsSamdwich(floorName1);
-                        result = j0.CompareTo(j1);
-                    }
-                    else
-                    {
-                        //数字大的,大于数字小的
-                        result = i0.CompareTo(i1);
-                    }
+                    result = i0.CompareTo(i1);
                 }
                 else
                 {
@@ -192,74 +183,65 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                     result = item1.CompareTo(item0);
                 }
             }
-            return -1*result;
+            return -1 * result;
         }
         /// <summary>
-        /// 获取楼层名中的序号
+        /// 获取楼层名中的序号,夹层转化为点F1M1--1.1
         /// </summary>
         /// <param name="name"></param>
         /// <returns></returns>
-        private static int GetFloorNameIndex(string name)
+        private static double GetFloorNameIndex(string name)
         {
-            var str = Regex.Replace(name, @"[^0-9]+", "");
-            var i = str.ToInt();
+            var str = Regex.Replace(name.Replace('M', '.'), @"[^0-9|.]+", "");
+            var i = str.ToDouble();
             //如果是地下,序号为负
-            if (Regex.IsMatch(name, @"^B\s*"))
+            if (IsUnderground(name))
                 i = i * -1;
             return i;
         }
-        /// <summary>
-        /// 是否为夹层 是返回1,否返回0
-        /// </summary>
-        /// <returns></returns>
-        private static int IsSamdwich(string name)
+
+        private static bool IsRFoRFM(string name)
+        {
+            return (Regex.IsMatch(name, $"{RegexConstPattern.IsRF}")) ||
+                   (Regex.IsMatch(name, $"{RegexConstPattern.IsRFM}"));
+        }
+
+        private static bool IsUpground(string name)
         {
-            return Regex.IsMatch(name, @"\s*M") ? 1 : 0;
+            return (Regex.IsMatch(name, $"{RegexConstPattern.IsOnground}"));
+        }
+
+        private static bool IsUnderground(string name)
+        {
+            return (Regex.IsMatch(name, $"{RegexConstPattern.IsUnderground}"));
         }
         /// <summary>
-        /// 是否连续
+        /// 是否连续,x为上层,y为下层
         /// </summary>
         public static bool IsContinuous(SagaSignCheckResult x, SagaSignCheckResult y)
         {
             bool result = false;
             string floorName0 = x.RFloorName;
             string floorName1 = y.RFloorName;
-            if (floorName0 == floorName1)
-            {
+            double i0 = GetFloorNameIndex(floorName0);
+            double i1 = GetFloorNameIndex(floorName1);
+            //有一个RF或RFM,判断为连续
+            if (IsRFoRFM(floorName0) || IsRFoRFM(floorName0))
                 result = true;
-            }
-            else
+            var diff = i0 - i1;
+            if ((diff).IsThanEq(0))
             {
-                if (floorName0 == m_RuleFloorNames[0] || floorName0 == m_RuleFloorNames[1])
+                if (diff.IsThan(2))
                 {
-                    result = true;
+                    result = false;
+                }
+                else if (diff.IsEqual(2))
+                {
+                    result = IsUpground(floorName0) && IsUnderground(floorName1);
                 }
                 else
                 {
-                    int i0 = GetFloorNameIndex(floorName0);
-                    int i1 = GetFloorNameIndex(floorName1);
-                    int j0 = IsSamdwich(floorName0);
-                    int j1 = IsSamdwich(floorName1);
-
-                    if (j0 == 1)
-                    {           
-                        //顶部为夹层
-                        //底部不能为夹层,且楼层序号应该相同
-                        result = j1!=1&&i0 == i1;
-                    }
-                    else
-                    {
-                        if (i0 > 0 && i1 < 0)
-                        {
-                            //地上和地下连续,序号为1和-1
-                            result = i0 == 1 && i1 == -1;
-                        }
-                        else
-                        {
-                            //其它情况连续为序号差为1
-                            result = i0 - i1 == 1;
-                        }
-                    }
+                    result = true;
                 }
             }
 

+ 2 - 2
MBI/SAGA.MBI/ToolsData/ModeCheck/SagaSignCheck.cs

@@ -104,11 +104,11 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                     result.RPlanName = sagaPlanName;
                     result.HBase = sagaPlan.GenLevel.Elevation;
                     //打标记的楼层名称必需为指定格式;B1,B1M,F1,F1M,RFM,RF
-                    if (Regex.IsMatch(sagaPlanName, @"^([BF][1-9]\d*M?|RFM?)-saga$"))
+                    if (Regex.IsMatch(sagaPlanName, $"{RegexConstPattern.IsMBIView}"))
                     {
 
                         result.RSequence = mFloor.Sequence;
-                        var rfLevel = document.GetLevels().FirstOrDefault(t => System.Text.RegularExpressions.Regex.IsMatch(t.Name, @"^RF(-saga)?$"));
+                        var rfLevel = document.GetLevels().FirstOrDefault(t => System.Text.RegularExpressions.Regex.IsMatch(t.Name, $"{RegexConstPattern.IsRF}"));
                         if (rfLevel == null)
                         {
                             result.IsRight = false;

+ 3 - 1
MBI/SAGA.MBI/ToolsData/ModeCheck/WinModeCheckSetting.xaml.cs

@@ -219,7 +219,9 @@ namespace SAGA.MBI.ToolsData.ModeCheck
                 if (chk.IsChecked == true)
                 {
                     var checkItem = chk.DataContext as ModeCheckBase;
-                    if (checkItem.RIsNeedTwoMoreFloors)
+                    if (checkItem == null) return;
+                    var floors = DalProjectTree.GetSelectedFloors();
+                    if (checkItem.RIsNeedTwoMoreFloors&&floors.Count<2)
                     {
                         MessageBox.Show("请选择两个及以上楼层再检查此项");
                     }

+ 3 - 2
MBI/SAGA.MBI/ToolsData/VerticalPipeAlign.cs

@@ -14,6 +14,7 @@ using Autodesk.Revit.DB.Plumbing;
 using SAGA.DotNetUtils.Data;
 using SAGA.DotNetUtils.Extend;
 using SAGA.DotNetUtils.Others;
+using SAGA.MBI.Common;
 using SAGA.MBI.DataArrange;
 using SAGA.MBI.Model;
 using SAGA.MBI.Tools;
@@ -234,7 +235,7 @@ namespace SAGA.MBI.ToolsData
             else
             {
                 var levels = doc.GetLevels();
-                var mbiLevels = levels.Where(t => Regex.IsMatch(t.Name, @"([BF][1-9]\d*M?|RFM?)"));
+                var mbiLevels = levels.Where(t => Regex.IsMatch(t.Name, $"{RegexConstPattern.IsMBILevel}"));
                 var topLevel = mbiLevels.FirstOrDefault(t => t.Elevation.IsThan(hb));
                 if (topLevel == null)
                 {
@@ -244,7 +245,7 @@ namespace SAGA.MBI.ToolsData
                 double nextL = topLevel.Elevation;
                 string tempTopLevelName = topLevel.Name;
                 //如果是夹层,获取夹层的上一层
-                if (Regex.IsMatch(tempTopLevelName, @"([BF][1-9]\d*M|RFM)"))
+                if (Regex.IsMatch(tempTopLevelName, $"{RegexConstPattern.IsSandwich}"))
                 {
                     hj = nextL;
                     topLevel = mbiLevels.FirstOrDefault(t => t.Elevation.IsThan(nextL));

+ 1 - 1
MBI/SAGA.MBI/WinView/Login/WinLogin.xaml.cs

@@ -153,7 +153,7 @@ namespace SAGA.MBI.WinView.Login
         /// <returns></returns>
         public bool IsHandset(string str_handset)
         {
-            return System.Text.RegularExpressions.Regex.IsMatch(str_handset, @"^1[3|4|5|7|8][0-9]\d{8}$");
+            return System.Text.RegularExpressions.Regex.IsMatch(str_handset,$"{RegexConstPattern.IsPhoneNumber}");
         }
 
         private Timer timer = null;