diff --git a/uBIMEarthTools/Commands/Monitor/MonitorCommand.cs b/uBIMEarthTools/Commands/Monitor/MonitorCommand.cs new file mode 100644 index 0000000..99e78ff --- /dev/null +++ b/uBIMEarthTools/Commands/Monitor/MonitorCommand.cs @@ -0,0 +1,22 @@ +using Autodesk.Revit.Attributes; +using Autodesk.Revit.DB; +using Autodesk.Revit.UI; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace uBIMEarthTools.Commands.Monitor +{ + [Transaction(TransactionMode.Manual)] + public class MonitorCommand : IExternalCommand + { + Result IExternalCommand.Execute(ExternalCommandData commandData, ref string message, ElementSet elements) + { + MonitorWindow monitorWindow = new MonitorWindow(); + monitorWindow.Show(); + return Result.Succeeded; + } + } +} diff --git a/uBIMEarthTools/Commands/Monitor/MonitorViewModel.cs b/uBIMEarthTools/Commands/Monitor/MonitorViewModel.cs new file mode 100644 index 0000000..040c992 --- /dev/null +++ b/uBIMEarthTools/Commands/Monitor/MonitorViewModel.cs @@ -0,0 +1,206 @@ +using HelixToolkit.Wpf.SharpDX; +using SharpDX; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using System.Windows.Input; +using uBIMEarthTools.Core; +using uBIMEarthTools.Model; +using uBIMEarthTools.Utils; + +namespace uBIMEarthTools.Commands.Monitor +{ + internal class MonitorViewModel + { + public IEffectsManager EffectsManager { get; set; } + + public Camera Camera { get; set; } + public bool EnableSwapChainRendering { get; set; } + + public bool EnableD2DRendering { get; set; } + public ObservableElement3DCollection Models { get; set; } + public ICommand OpenCommand { get; set; } + + public MonitorViewModel() + { + this.Models = new ObservableElement3DCollection(); + + this.EffectsManager = new DefaultEffectsManager(); + this.Camera = new PerspectiveCamera() { NearPlaneDistance = 0.1, FarPlaneDistance = 10000000 }; + this.EnableSwapChainRendering = true; + this.EnableD2DRendering = false; + OpenCommand = new DelegateCommand() { ExecuteCommand = OpenXlsx }; + } + + private void OpenXlsx(object obj) + { + #region 数据读取 + + #region 数据文件读取路径 + string pathstring = string.Empty; + OpenFileDialog openFileDialog = new OpenFileDialog(); + openFileDialog.Title = "选择Excel文件…"; + openFileDialog.Filter = "Excel文件|*.xlsx"; + openFileDialog.RestoreDirectory = false; + openFileDialog.FilterIndex = 1; + if (openFileDialog.ShowDialog() == DialogResult.OK) + pathstring = openFileDialog.FileName; + else + return; + #endregion + + Stopwatch stopwatch2 = new Stopwatch(); + stopwatch2.Start(); + List boreholeList = ExcelHelper.GetDataFromExcel(pathstring); + stopwatch2.Stop(); + #endregion + + #region 数据有效性检测 + string abc = string.Empty; + foreach (var borehole in boreholeList) + { + for (int i = 0; i < borehole.ValueList.Count - 2; i++) + { + if (borehole.ValueList[i].Point.Z < borehole.ValueList[i + 1].Point.Z) + { + abc += borehole.Name + ","; + break; + } + } + } + if (!string.IsNullOrEmpty(abc)) + { + MessageBox.Show(abc); + } + #endregion + + #region 计算地质块 + List triIndexList = Common.Delaunay(boreholeList, 10000000 / 304.8); + List geologyBlocks = new List(); + foreach (int[] item in triIndexList) + { + List boreholes = new List() { + new Borehole(boreholeList.ElementAt(item[0])), + new Borehole(boreholeList.ElementAt(item[1])), + new Borehole(boreholeList.ElementAt(item[2])) + }; + + bool topToBottom = true; + while (boreholes[0].StartIndex != boreholes[0].EndIndex + || boreholes[1].StartIndex != boreholes[1].EndIndex + || boreholes[2].StartIndex != boreholes[2].EndIndex) + { + if (topToBottom) + { + boreholes[0].CurrentType = boreholes[0].StartIndex != boreholes[0].EndIndex ? boreholes[0].ValueList[boreholes[0].StartIndex + 1].Type : "Last1"; + boreholes[1].CurrentType = boreholes[1].StartIndex != boreholes[1].EndIndex ? boreholes[1].ValueList[boreholes[1].StartIndex + 1].Type : "Last2"; + boreholes[2].CurrentType = boreholes[2].StartIndex != boreholes[2].EndIndex ? boreholes[2].ValueList[boreholes[2].StartIndex + 1].Type : "Last3"; + boreholes = boreholes.OrderByDescending(x => x.ValueList[x.StartIndex].Point.Z).ToList(); + } + else + { + boreholes[0].CurrentType = boreholes[0].StartIndex != boreholes[0].EndIndex ? boreholes[0].ValueList[boreholes[0].EndIndex].Type : "Last1"; + boreholes[1].CurrentType = boreholes[1].StartIndex != boreholes[1].EndIndex ? boreholes[1].ValueList[boreholes[1].EndIndex].Type : "Last2"; + boreholes[2].CurrentType = boreholes[2].StartIndex != boreholes[2].EndIndex ? boreholes[2].ValueList[boreholes[2].EndIndex].Type : "Last3"; + boreholes = boreholes.OrderBy(x => x.ValueList[x.EndIndex].Point.Z).ToList(); + } + DataListSort(boreholes); + GeologyCompute.CreateGeologyBlock(boreholes, geologyBlocks, topToBottom); + topToBottom = !topToBottom; + } + } + #endregion + + + var colors = new Dictionary(); + Random random = new Random(); + + foreach (var item in geologyBlocks.Select(x => x.Type).Distinct()) + { + colors.Add(item, PhongMaterials.ToColor(random.Next(0, 255) / 255f, random.Next(0, 255) / 255f, random.Next(0, 255) / 255f)); + } + + foreach (var x in geologyBlocks) + { + List vector3s = new List(); + List indices = new List(); + vector3s.Add(new SharpDX.Vector3((float)x.FLeftUp.X, (float)x.FLeftUp.Z, -(float)x.FLeftUp.Y)); //0 + vector3s.Add(new SharpDX.Vector3((float)x.FLeftBottom.X, (float)x.FLeftBottom.Z, -(float)x.FLeftBottom.Y)); //1 + vector3s.Add(new SharpDX.Vector3((float)x.FRightUp.X, (float)x.FRightUp.Z, -(float)x.FRightUp.Y)); //2 + vector3s.Add(new SharpDX.Vector3((float)x.FRightBottom.X, (float)x.FRightBottom.Z, -(float)x.FRightBottom.Y)); //3 + vector3s.Add(new SharpDX.Vector3((float)x.ELeftUp.X, (float)x.ELeftUp.Z, -(float)x.ELeftUp.Y)); //4 + vector3s.Add(new SharpDX.Vector3((float)x.ELeftBottom.X, (float)x.ELeftBottom.Z, -(float)x.ELeftBottom.Y)); //5 + vector3s.Add(new SharpDX.Vector3((float)x.ERightUp.X, (float)x.ERightUp.Z, -(float)x.ERightUp.Y)); //6 + vector3s.Add(new SharpDX.Vector3((float)x.ERightBottom.X, (float)x.ERightBottom.Z, -(float)x.ERightBottom.Y)); //7 + + indices.Add(0); indices.Add(2); indices.Add(6); + indices.Add(0); indices.Add(6); indices.Add(4); + indices.Add(0); indices.Add(3); indices.Add(2); + indices.Add(3); indices.Add(0); indices.Add(1); + indices.Add(6); indices.Add(2); indices.Add(3); + indices.Add(6); indices.Add(3); indices.Add(7); + + indices.Add(0); indices.Add(4); indices.Add(1); + indices.Add(1); indices.Add(4); indices.Add(5); + indices.Add(4); indices.Add(6); indices.Add(7); + indices.Add(4); indices.Add(7); indices.Add(5); + indices.Add(5); indices.Add(7); indices.Add(1); + indices.Add(1); indices.Add(7); indices.Add(3); + + MeshGeometry3D me = new MeshGeometry3D(); + me.Positions = new Vector3Collection(vector3s); + me.Indices = new IntCollection(indices); + me.Normals = me.CalculateNormals(); + + Models.Add(new MeshGeometryModel3D() + { + Geometry = me, + FillMode = SharpDX.Direct3D11.FillMode.Solid, + Material = new PhongMaterial() + { + AmbientColor = colors[x.Type], + // SpecularColor = new SharpDX.Color4(0.0225f, 0.0225f, 0.0225f, 1.0f), + //EmissiveColor = new SharpDX.Color4(0.0f, 0.0f, 0.0f, 1.0f), + SpecularShininess = 12.8f, + // DiffuseColor = colors[x.Type], + } + }); + + } + + InitCamera(); + } + + + public void InitCamera() + { + if (Models.Any()) + { + var maxbox = Models.Select(x => x.Bounds).Aggregate(BoundingBox.Merge); + var size = maxbox.Size; + var maxLength = size.X > size.Y ? size.X > size.Z ? size.X : size.Z : size.Y > size.Z ? size.Y : size.Z; + var radius = Vector3.Distance(maxbox.Center, new Vector3(maxbox.Center.X + (maxLength / 2), maxbox.Center.Y + (maxLength / 2), maxbox.Center.Z + (maxLength / 2))); + var vec = (maxbox.Center + new Vector3(radius, radius, radius)); + this.Camera.Position = vec.ToPoint3D(); + this.Camera.LookDirection = (maxbox.Center - vec).ToVector3D(); + this.Camera.UpDirection = new Vector3(0, 1, 0).ToVector3D(); + //this.Camera.ZoomExtents(); + } + } + private static void DataListSort(List boreholes) + { + if (boreholes.First().CurrentType.Contains("Last")) + { + boreholes.Add(boreholes.First()); + boreholes.RemoveAt(0); + DataListSort(boreholes); + } + else + return; + } + } +} diff --git a/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml b/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml new file mode 100644 index 0000000..6217be5 --- /dev/null +++ b/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + diff --git a/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml.cs b/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml.cs new file mode 100644 index 0000000..9f51240 --- /dev/null +++ b/uBIMEarthTools/Commands/Monitor/MonitorWindow.xaml.cs @@ -0,0 +1,27 @@ +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.Shapes; + +namespace uBIMEarthTools.Commands.Monitor +{ + /// + /// MonitorWindow.xaml 的交互逻辑 + /// + public partial class MonitorWindow : Window + { + public MonitorWindow() + { + InitializeComponent(); + } + } +} diff --git a/uBIMEarthTools/MethodTimeLogger.cs b/uBIMEarthTools/MethodTimeLogger.cs index bee7791..4ff4ae2 100644 --- a/uBIMEarthTools/MethodTimeLogger.cs +++ b/uBIMEarthTools/MethodTimeLogger.cs @@ -2,7 +2,7 @@ using System.Diagnostics; using System.Reflection; -[assembly: MethodTimer.Time] +//[assembly: MethodTimer.Time] namespace uBIMEarthTools { public static class MethodTimeLogger @@ -16,7 +16,7 @@ namespace uBIMEarthTools FinishTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(), TimeSpan = elapsed.TotalMilliseconds }; - Trace.TraceInformation($"{methodBase.Name} : {elapsed.TotalSeconds}"); + // Trace.TraceInformation($"{methodBase.Name} : {elapsed.TotalSeconds}"); } } diff --git a/uBIMEarthTools/uBIMEarthTools.csproj b/uBIMEarthTools/uBIMEarthTools.csproj index 1b9b45f..01c2dd7 100644 --- a/uBIMEarthTools/uBIMEarthTools.csproj +++ b/uBIMEarthTools/uBIMEarthTools.csproj @@ -20,6 +20,7 @@ +