Browse Source

xls:MBI客户端,空间嵌套问题渲染

xulisong 5 years ago
parent
commit
ed51ad8531

+ 4 - 0
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -466,6 +466,10 @@
     <Compile Include="WPF\Converter\BoolToVisibilityConverter.cs" />
     <Compile Include="WPF\Converter\StringToImageConverter.cs" />
     <Compile Include="WPF\DataGridResource.cs" />
+    <Compile Include="WPF\Elements\AnnularElement.cs" />
+    <Compile Include="WPF\Elements\Element.cs" />
+    <Compile Include="WPF\Elements\ElementGeometryUtil.cs" />
+    <Compile Include="WPF\Elements\SpaceElement.cs" />
     <Compile Include="WPF\Extend\UIElementExtensions.cs" />
     <Compile Include="WPF\MVVM\BaseCommand.cs" />
     <Compile Include="WPF\MVVM\BasePropertyChanged.cs" />

+ 53 - 0
MBI/SAGA.DotNetUtils/WPF/Elements/AnnularElement.cs

@@ -0,0 +1,53 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:AnnularElement
+ * 作者:xulisong
+ * 创建时间: 2019/5/8 16:59:47
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public class AnnularElement: TElement
+    {
+        public AnnularElement(List<Point> outPoints)
+        {
+            if (outPoints.Count < 3)
+            {
+                throw new ArgumentNullException(nameof(outPoints));
+            }
+
+            OutPolygon = new PointCollection(outPoints);
+            InPolygons = new ObservableCollection<PointCollection>();
+            
+        }
+        public PointCollection OutPolygon { get; private set; }
+        public ObservableCollection<PointCollection> InPolygons
+        {
+            get;private set;
+        }
+
+        protected override System.Windows.Media.Geometry GetDefiningGeometry()
+        {
+            GeometryGroup group = new GeometryGroup();
+            PathGeometry geometry = ElementGeometryUtil.GetGeometry(OutPolygon);
+            group.Children.Add(geometry);
+            foreach (var  inPolygon in InPolygons)
+            {
+                group.Children.Add(ElementGeometryUtil.GetGeometry(inPolygon));
+            }
+            return group;
+        }
+
+     
+    }
+}

+ 66 - 0
MBI/SAGA.DotNetUtils/WPF/Elements/Element.cs

@@ -0,0 +1,66 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:Element
+ * 作者:xulisong
+ * 创建时间: 2019/5/8 15:29:43
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Shapes;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public class TElement : Shape
+    {
+        public TElement()
+        {
+            //ElementSelected.SetCanSelected(this, true);
+            //var beheaviors = Interaction.GetBehaviors(this);
+            //beheaviors.Add(new SelectedBehavior());
+            //this.SetValue(Interaction.beh)
+            //this.InheritanceBehavior
+        }
+        /// <summary>
+        /// 当前元素的id
+        /// </summary>
+        public int Id { get; internal set; }
+        protected override System.Windows.Media.Geometry DefiningGeometry
+        {
+            get { return GetDefiningGeometry(); }
+        }
+
+        protected virtual System.Windows.Media.Geometry GetDefiningGeometry()
+        {
+            return null;
+        }
+
+        protected override void OnRender(DrawingContext drawingContext)
+        {
+
+            drawingContext.DrawGeometry(this.Fill, new Pen(this.Stroke, this.StrokeThickness), this.DefiningGeometry);
+            //base.OnRender(drawingContext);
+        }
+        protected override void OnMouseEnter(MouseEventArgs e)
+        {
+            base.OnMouseEnter(e);
+            //ElementSelected.SetIsMouseOver(this, true);
+        }
+        protected override void OnMouseLeave(MouseEventArgs e)
+        {
+            base.OnMouseLeave(e);
+            //ElementSelected.SetIsMouseOver(this, false);
+        }
+        protected override void OnPreviewMouseLeftButtonUp(MouseButtonEventArgs e)
+        {
+            base.OnPreviewMouseLeftButtonUp(e);
+            //ElementSelected.SetIsSelected(this, !ElementSelected.GetIsSelected(this));
+        }
+       
+    }
+}

+ 34 - 0
MBI/SAGA.DotNetUtils/WPF/Elements/ElementGeometryUtil.cs

@@ -0,0 +1,34 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:ElementGeometryUtils
+ * 作者:xulisong
+ * 创建时间: 2019/5/8 17:41:29
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Media;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public static class ElementGeometryUtil
+    {
+        public static PathGeometry GetGeometry(IList<Point> points)
+        {
+            PathGeometry geometry = new PathGeometry();
+            PathFigure figure = new PathFigure();
+            figure.StartPoint = points[0];
+            var usePoints = points.ToList().GetRange(1, points.Count - 1);
+            usePoints.Add(points[0]);
+            figure.Segments = new PathSegmentCollection();
+            //参数的true或false,会影响边框是否显示
+            figure.Segments.Add(new PolyLineSegment(usePoints, true));
+            geometry.Figures.Add(figure);
+            return geometry;
+        }
+    }
+}

+ 24 - 0
MBI/SAGA.DotNetUtils/WPF/Elements/SpaceElement.cs

@@ -0,0 +1,24 @@
+/*-------------------------------------------------------------------------
+ * 功能描述:SpaceElement
+ * 作者:xulisong
+ * 创建时间: 2019/8/8 10:17:18
+ * 版本号:v1.0
+ *  -------------------------------------------------------------------------*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace SAGA.DotNetUtils.WPF
+{
+    public class SpaceElement: AnnularElement
+    {
+        public SpaceElement(List<Point> outPoints):base(outPoints)
+        {
+
+        }
+    }
+}

+ 38 - 32
MBI/SAGA.MBI/WinView/Space/WinCreateSpace.xaml.cs

@@ -5,6 +5,7 @@ using System.IO;
 using System.Linq;
 using System.Windows;
 using System.Windows.Controls;
+using System.Windows.Documents;
 using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Shapes;
@@ -16,6 +17,7 @@ using Point = System.Windows.Point;
 using System.Windows.Media.Animation;
 using System.Windows.Threading;
 using Autodesk.Revit.UI;
+using SAGA.DotNetUtils.WPF;
 using SAGA.MBI.DataArrange;
 using SAGA.MBI.Model;
 using SAGA.MBI.WinView.ModeInfoMaintenance;
@@ -1003,20 +1005,20 @@ namespace SAGA.MBI.WinView.Space
                 if (lbSpaces.SelectedItems.Count == 0) return;
                 var space = lbSpaces.SelectedItems[0] as MISpace;
                 var bimId = space.BimID.Split(':')[1];
-                foreach (var polyline in this.canvas.Children.OfType<WPolyline>())
+                foreach (var spaceELement in this.canvas.Children.OfType<SpaceElement>())
                 {
-                    if (polyline.Tag is Autodesk.Revit.DB.Mechanical.Space s)
+                    if (spaceELement.Tag is Autodesk.Revit.DB.Mechanical.Space s)
                     {
                         if (s.Id.ToString() == (bimId))
                         {
-                            polyline.Fill = Brushes.Aquamarine;
+                            spaceELement.Fill = Brushes.Aquamarine;
 
                             //显示属性窗口
                             ShowSpaceProperty(s);
                         }
-                        else if (polyline.Fill == Brushes.Aquamarine)
+                        else if (spaceELement.Fill == Brushes.Aquamarine)
                         {
-                            polyline.Fill = Brushes.Transparent;
+                            spaceELement.Fill = Brushes.Transparent;
                         }
                     }
                 }
@@ -1036,7 +1038,6 @@ namespace SAGA.MBI.WinView.Space
         {
             MRevitEquipBase equipment = DalCommon.GetEquipmentQueryId(space);
             ShowSpaceProperty(equipment);
-
         }
       
 
@@ -1072,22 +1073,37 @@ namespace SAGA.MBI.WinView.Space
             var seg = mySegments.FirstOrDefault();
             if (seg == null)
             {
-                MessageBox.Show(space.Id.IntegerValue + "");
                 return;
             }
+            SpaceElement spaceElement = null;
+            for (int i = 0; i < mySegments.Count; i++)
+            {
+                var useSeg = mySegments[i];
+                List<Point> datas = new List<Point>();
+                foreach (BoundarySegment segment in useSeg)
+                {
+                    datas.AddRange(segment.GetCurve().Tessellate().Select(xyz => xyz.ToW2DPoint()).ToList());
+                }
 
-
-            List<Point> datas = new List<Point>();
-            foreach (BoundarySegment segment in seg)
+                datas = datas.Select(p => { return MovePoint(new Point(p.X, p.Y)); }).ToList();
+                if (i == 0)
+                {
+                    spaceElement = new SpaceElement(datas);
+                }
+                else if (spaceElement!=null)
+                {
+                    spaceElement.InPolygons.Add(new PointCollection(datas));
+                }
+            }
+            //var polyLine = this.CreateDefaultPolyLine(datas, Brushes.Transparent);
+            if (spaceElement != null)
             {
-                datas.AddRange(segment.GetCurve().Tessellate().Select(xyz => xyz.ToW2DPoint()).ToList());
+                spaceElement.Tag = space;//此处比较重要,这个是判断曲线是否为轮廓线的关键
+                spaceElement.Fill = Brushes.Transparent;
+                spaceElement.MouseLeftButtonDown +=Space_MouseDown;
+                this.canvas.Children.Add(spaceElement);
             }
-
-            var polyLine = this.CreateDefaultPolyLine(datas, Brushes.Transparent);
-            polyLine.Tag = space;//此处比较重要,这个是判断曲线是否为轮廓线的关键
-            polyLine.Fill = Brushes.Transparent;
-
-            polyLine.MouseLeftButtonDown += PolyLine_MouseDown;
+           
         }
 
         /// <summary>
@@ -1095,19 +1111,17 @@ namespace SAGA.MBI.WinView.Space
         /// </summary>
         /// <param name="sender"></param>
         /// <param name="e"></param>
-        private void PolyLine_MouseDown(object sender, MouseButtonEventArgs e)
+        private void Space_MouseDown(object sender, MouseButtonEventArgs e)
         {
-            if ((sender is WPolyline line) && m_isDraw == null)
+            if ((sender is SpaceElement sapceElement) && m_isDraw == null)
             {
                 //找到已亮显的空间
-                var showSpaces = this.canvas.Children.OfType<WPolyline>().FirstOrDefault(t => t is WPolyline l && l.Fill == Brushes.Aquamarine);
+                var showSpaces = this.canvas.Children.OfType<SpaceElement>().FirstOrDefault(s => s.Fill == Brushes.Aquamarine);
 
                 //先清除
                 if (showSpaces != null) showSpaces.Fill = Brushes.Transparent;
-                line.Fill = Brushes.Aquamarine;
-                //MessageBox.Show(line.Tag+"");
-
-                if (line.Tag is Autodesk.Revit.DB.Mechanical.Space space)
+                sapceElement.Fill = Brushes.Aquamarine;
+                if (sapceElement.Tag is Autodesk.Revit.DB.Mechanical.Space space)
                 {
                     //反选右侧树
                     for (int i = 0; i < lbSpaces.Items.Count; i++)
@@ -1120,10 +1134,7 @@ namespace SAGA.MBI.WinView.Space
                             break;
                         }
                     }
-
                     //显示属性板
-
-
                     ShowSpaceProperty(space);
                 }
             }
@@ -1144,11 +1155,6 @@ namespace SAGA.MBI.WinView.Space
         {
             MoveElement(0.1, new Point());
         }
-
-        //创建定时器,以检测所有操作是否全部保存完成
-        private DispatcherTimer timer;
-
-       
         private void CanvasDefaultTips()
         {
             string tips = "请选择一个需要进行空间管理的楼层";