浏览代码

mxg:添加坐标箭头

mengxiangge 6 年之前
父节点
当前提交
6f2e9be213

二进制
MBI/MBIResource/Family/坐标箭头.rfa


+ 1 - 2
MBI/SAGA.DotNetUtils/Geometry/Geometry2d.cs

@@ -745,8 +745,7 @@ namespace SAGA.DotNetUtils.Geometry
             int c = 0, i, n;
             LineSeg l1 = new LineSeg(), l2 = new LineSeg();
             l1.Start = q;
-            l1.End = q;
-            l1.End.X = INFCONST;
+            l1.End = new PointD(INFCONST,q.Y);
             n = vcount;
             for (i = 0; i < vcount; i++)
             {

+ 79 - 76
MBI/SAGA.MBI/TestCommand.cs

@@ -46,95 +46,98 @@ namespace SAGA.MBI
         {
             try
             {
-                var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
-                var space = fi.GetReferenceSpace();
-                string str = "";
-                while (true)
-                {
-                    if (space != null)
-                    {
-                        List<XYZ> spaceVertex = space.GetBoundaryVertexes().FirstOrDefault();
-                        if (spaceVertex == null)
-                        {
-                            str = "Boundary 为Null";
-                            break;
-                        }
+                //var fi = ExternalDataWrapper.Current.UiApp.GetSelectedElement() as FamilyInstance;
+                //var space = fi.GetReferenceSpace();
+                //string str = "",str2="";
+                //while (true)
+                //{
+                //    if (space != null)
+                //    {
+                //        List<XYZ> spaceVertex = space.GetBoundaryVertexes().FirstOrDefault();
+                //        if (spaceVertex == null)
+                //        {
+                //            str = "Boundary 为Null";
+                //            break;
+                //        }
 
-                        var xyz = fi.GetLocationPointMBIXYZ();
-                        str = "Geometry Intersection Result" + xyz.PointInPolygonByRay(spaceVertex);
+                //        var xyz = fi.GetLocationPointMBIXYZ();
+                //        str = "Geometry Intersection Result" + xyz.PointInPolygonByRay(spaceVertex);
 
+                //        str2 = "Geometry2D Intersection Result:" + Geometry2D.InSidePolygon(spaceVertex.Count,
+                //                   spaceVertex.Select(t => t.ToPointD()).ToArray(), xyz.ToPointD());
 
-                            break;
 
-                    }
 
-                }
-                MessageShowBase.Infomation($"{str}");
-
-                //var doc = commandData.View.Document;
-                //var spaces = doc.GetSpaces().Where(t => t.IsValidObject).ToList();
-                //var fis = doc.GetFamilyInstances().Where(t=>t.IsEquipmentPart()||t.IsEquipment());
-                //List<List<List<XYZ>>> spaceVertexes = spaces.Select(t => t.GetBoundaryVertexes()).ToList();
-                //List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs = fis.Select(t => new KeyValuePair<FamilyInstance,XYZ>(t,t.GetLocationPointMBIXYZ())).ToList();
-                //List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs_bak = new List<KeyValuePair<FamilyInstance, XYZ>>();
-                //long rtime = 0,gtime = 0;
-                //int rcount = 0, gcount = 0;
-                //Stopwatch watch = new Stopwatch();
-                //#region 使用Revit计算
-                //watch.Start();
-                //foreach (var pair in keyValuePairs)
-                //{
-                //    FamilyInstance fi = pair.Key;
-                //    var space=fi.GetReferenceSpace(spaces);
-                //    if (space != null)
-                //    {
-                //        rcount++;
-                //        keyValuePairs_bak.Add(pair);
                 //    }
+                //    break;
+
                 //}
-                //watch.Stop();
-                //rtime = watch.ElapsedMilliseconds;
+                //MessageShowBase.Infomation($"{str}"+"\r\n"+$"{str2}");
+
+                var doc = commandData.View.Document;
+                var spaces = doc.GetSpaces().Where(t => t.IsValidObject).ToList();
+                var fis = doc.GetFamilyInstances().Where(t => t.IsEquipmentPart() || t.IsEquipment());
+                List<List<List<XYZ>>> spaceVertexes = spaces.Select(t => t.GetBoundaryVertexes()).ToList();
+                List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs = fis.Select(t => new KeyValuePair<FamilyInstance, XYZ>(t, t.GetLocationPointMBIXYZ())).ToList();
+                List<KeyValuePair<FamilyInstance, XYZ>> keyValuePairs_bak = new List<KeyValuePair<FamilyInstance, XYZ>>();
+                long rtime = 0, gtime = 0;
+                int rcount = 0, gcount = 0;
+                Stopwatch watch = new Stopwatch();
+                #region 使用Revit计算
+                watch.Start();
+                foreach (var pair in keyValuePairs)
+                {
+                    FamilyInstance fi = pair.Key;
+                    var space = fi.GetReferenceSpace(spaces);
+                    if (space != null)
+                    {
+                        rcount++;
+                        keyValuePairs_bak.Add(pair);
+                    }
+                }
+                watch.Stop();
+                rtime = watch.ElapsedMilliseconds;
 
-                //#endregion
+                #endregion
 
-                //#region 使用Geomety计算
+                #region 使用Geomety计算
 
-                //List<List<XYZ>> spaceBorderVertexes = spaceVertexes.Select(t => t.FirstOrDefault()).ToList();
-                //watch.Reset();
-                //watch.Start();
+                List<List<XYZ>> spaceBorderVertexes = spaceVertexes.Select(t => t.FirstOrDefault()).ToList();
+                watch.Reset();
+                watch.Start();
 
-                //foreach (var pair in keyValuePairs)
-                //{
-                //    XYZ xyz = pair.Value;
-                //    double z = xyz.Z;
-                //    var point = xyz.ToPointD();
-                //    foreach (var spaceVertex in spaceBorderVertexes)
-                //    {
-                //        if(spaceVertex==null)continue;
-                        
-                //        double minz = spaceVertex.Min(t => t.Z);
-                //        double maxz = spaceVertex.Max(t => t.Z);
-                //        //if (z.IsBetween(minz, maxz))
-                //        {
-                //            //if(Geometry2D.InSidePolygon(spaceVertex.Count,spaceVertex.Select(t=>t.ToPointD()).ToArray(),point)==1)
-                //            if (xyz.PointInPolygonByRay(spaceVertex) != -1)
-                //            {
-                //                gcount++;
-                                
-                //                keyValuePairs_bak.Remove(pair);
-                //                break;
-                //            }
-                //        }
-                //    }
-                //}
-                //watch.Stop();
-                //gtime = watch.ElapsedMilliseconds;
+                foreach (var pair in keyValuePairs)
+                {
+                    XYZ xyz = pair.Value;
+                    double z = xyz.Z;
+                    var point = xyz.ToPointD();
+                    foreach (var spaceVertex in spaceBorderVertexes)
+                    {
+                        if (spaceVertex == null) continue;
+
+                        double minz = spaceVertex.Min(t => t.Z);
+                        double maxz = spaceVertex.Max(t => t.Z);
+                        //if (z.IsBetween(minz, maxz))
+                        {
+                            if(Geometry2D.InSidePolygon(spaceVertex.Count,spaceVertex.Select(t=>t.ToPointD()).ToArray(),point)!=2)
+                            //if (xyz.PointInPolygonByRay(spaceVertex) != -1)
+                            {
+                                gcount++;
+
+                                keyValuePairs_bak.Remove(pair);
+                                break;
+                            }
+                        }
+                    }
+                }
+                watch.Stop();
+                gtime = watch.ElapsedMilliseconds;
 
-                //#endregion
+                #endregion
 
-                //MessageShow.Infomation($"Revit计算耗时{rtime},共识别出{rcount}个空间" + "\r\n" +
-                //                       $"Geometry计算耗时{gtime},共识别出{gcount}个空间"+"\r\n"+
-                //                       $"{string.Join(",",keyValuePairs_bak.Select(t=>t.Key.Id))}");
+                MessageShow.Infomation($"Revit计算耗时{rtime},共识别出{rcount}个空间" + "\r\n" +
+                                       $"Geometry计算耗时{gtime},共识别出{gcount}个空间" + "\r\n" +
+                                       $"{string.Join(",", keyValuePairs_bak.Select(t => t.Key.Id))}");
             }
             catch (Exception e)
             {

+ 10 - 2
MBI/SAGA.RevitUtils/Extends/XYZExtend.cs

@@ -1680,7 +1680,11 @@ namespace SAGA.RevitUtils.Extends
         /// </summary>
         /// <param name="inputPoint"></param>
         /// <param name="lines"></param>
-        /// <returns></returns>
+        /// <returns>
+        ///  如果点在多边形内:   返回1 
+        ///  如果点在多边形边上: 返回0
+        ///  如果点在多边形外:	返回-1
+        /// </returns>
         public static int PointInPolygonByRay(this XYZ inputPoint, List<Line> lines)
         {
             #region 描述
@@ -1802,7 +1806,11 @@ namespace SAGA.RevitUtils.Extends
         /// </summary>
         /// <param name="inputPoint"></param>
         /// <param name="points"></param>
-        /// <returns></returns>
+        /// <returns>
+        ///  如果点在多边形内:   返回1 
+        ///  如果点在多边形边上: 返回0
+        ///  如果点在多边形外:	返回-1
+        /// </returns>
         public static int PointInPolygonByRay(this XYZ inputPoint, List<XYZ> points)
         {
             List<Line> lines = new List<Line>();

+ 33 - 19
MBI/ToolCommand/Command.cs

@@ -54,7 +54,7 @@ namespace ToolCommand
                 var tip = MessageShow.Question("确定要导出所有的族类别?");
                 if (tip)
                 {
-                    ExportAllCategory export=new ExportAllCategory();
+                    ExportAllCategory export = new ExportAllCategory();
                     export.Operate();
                 }
             }
@@ -76,7 +76,7 @@ namespace ToolCommand
             return true;
         }
     }
-    
+
     #region 浏览坐标
     [Transaction(TransactionMode.Manual)]
     [Regeneration(RegenerationOption.Manual)]
@@ -87,28 +87,40 @@ namespace ToolCommand
             var uiApp = commandData.Application;
             var uiDoc = uiApp.ActiveUIDocument;
             var doc = uiDoc.Document;
-          
-        WinLocation win=new WinLocation();
-            if (win.ShowDialog() == true)
+
+            do
             {
-                string location = win.Location;
-                if (ObjectExtend.IsNotNullEmpty(location))
+                WinLocation win = new WinLocation();
+                if (win.ShowDialog() == true)
                 {
-
-                    XYZ xyz= ConvertToXyz(location);
-                    PlaceHolder(doc, xyz.ConvertToApi());
+                    string location = win.Location;
+                    if (ObjectExtend.IsNotNullEmpty(location))
+                    {
+                        XYZ xyz = ConvertToXyz(location);
+                        if (xyz == null)
+                        {
+                            MessageShow.Infomation("Location格式异常");
+                            break;
+                        }
+                        if (win.IsMetricSystem)
+                        {
+                            xyz = xyz.ConvertToApi();
+                        }
+                        PlaceHolder(doc, xyz);
+                    }
                 }
-            }
+            } while (false);
+            
             return Result.Succeeded;
         }
-        
+
         private XYZ ConvertToXyz(string str)
         {
             XYZ xyz = null;
-            var strs = str.Split(',');
+            var strs = str.Replace('(',' ').Replace(')',' ').SplitRemoveEmpty(",");
             if (strs.Length == 3)
             {
-                xyz=new XYZ(strs[0].ToDouble(), strs[1].ToDouble(), strs[2].ToDouble());
+                xyz = new XYZ(strs[0].ToDouble(), strs[1].ToDouble(), strs[2].ToDouble());
             }
 
             return xyz;
@@ -118,28 +130,30 @@ namespace ToolCommand
         /// </summary>
         /// <param name="doc"></param>
         /// <param name="xyz"></param>
-        private void PlaceHolder(Document doc,XYZ xyz)
+        private void PlaceHolder(Document doc, XYZ xyz)
         {
             using (Transaction trans = new Transaction(doc, "创建信标"))
             {
                 trans.Start();
                 try
                 {
-                    string familyFile = Path.Combine(AppBaseInfo.FamilyPath, "占位符.rfa");
+                    string familyFile = Path.Combine(AppBaseInfo.FamilyPath, "坐标箭头.rfa");
                     FamilySymbol fs = doc.GetFamilySymbol(familyFile, BuiltInCategory.OST_GenericModel);
                     var fi = doc.Create.NewFamilyInstance(xyz, fs, StructuralType.NonStructural);
-                    ExternalDataWrapper.Current.UiApp.SetShowElements(fi);
+                    doc.Regenerate();
                     trans.Commit();
+                    ExternalDataWrapper.Current.UiApp.SetShowElements(fi);
                 }
                 catch (Exception e)
                 {
                     trans.RollBack();
+                    MessageShow.Show(e);
                 }
             }
         }
 
-#endregion
+        #endregion
+
 
-  
     }
 }

+ 5 - 4
MBI/ToolCommand/WinLocation.xaml

@@ -3,13 +3,14 @@
              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"
-        mc:Ignorable="d" Title="获取坐标"
-        Width="400" Height="80">
+        mc:Ignorable="d" Title="请输入坐标"
+        Width="308.212" Height="100">
     <Grid>
         <Canvas>
             <TextBox Text="" Height="24" Width="300" Name="txtLocation"></TextBox>
-            <Button Canvas.Left="300" Content="确定" Height="24" Width="80" Click="ButtonBase_OnClick"></Button>
+            <Button Canvas.Left="50" Content="公制" Height="24" Width="80" Click="ButtonBase_OnClick" Tag="0" Canvas.Top="25"></Button>
+            <Button Canvas.Right="50" Content="英制" Height="24" Width="80" Click="ButtonBase_OnClick" Tag="1" Canvas.Top="25"></Button>
         </Canvas>
     </Grid>
-    
+
 </Window>

+ 7 - 1
MBI/ToolCommand/WinLocation.xaml.cs

@@ -1,11 +1,13 @@
 using System.Windows;
+using System.Windows.Controls;
+using SAGA.DotNetUtils;
 
 namespace ToolCommand
 {
     /// <summary>
     /// WinLocation.xaml 的交互逻辑
     /// </summary>
-    public partial class WinLocation 
+    public partial class WinLocation
     {
         public WinLocation()
         {
@@ -19,8 +21,12 @@ namespace ToolCommand
                 return txtLocation.Text;
             }
         }
+        public bool IsMetricSystem { get; set; }
         private void ButtonBase_OnClick(object sender, RoutedEventArgs e)
         {
+            var button = sender as Button;
+            if (button != null)
+                IsMetricSystem = button.Tag.ToInt() == 0;
             this.DialogResult = true;
         }
     }