| | |
| | | using System.Windows.Controls; |
| | | using System.Windows.Media.Media3D; |
| | | |
| | | namespace Yw.WpfUI.Hydro |
| | | namespace Yw.WpfUI.Hydro |
| | | { |
| | | /// <summary> |
| | | /// 抽象管理器 |
| | |
| | | _overrideColorHelper = new LogicalOverrideColorHelper(); |
| | | _overrideOpacityHelper = new LogicalOverrideOpacityHelper(); |
| | | _overrideVisibleHelper = new LogicalOverrideVisibleHelper(); |
| | | _backgroundHelper = new LogicalBackgroudHelper(_viewport); |
| | | _gridLinesHelper = new LogicalGridLineHelper(_viewport); |
| | | _highlightHelper = new LogicalHighlightHelper(_viewport); |
| | | _selectionHelper = new LogicalSelectionHelper(_viewport); |
| | | _zoomHelper = new LogicalZoomHelper(_viewport); |
| | | _billboardTextHelper = new LogicalBillboardTextHelper(_viewport); |
| | | _cameraHelper = new LogicalCameraHelper(_viewport); |
| | | _flowDirectionHelper = new LogicalFlowDirectionHelper(_viewport, _materialHelper); |
| | | } |
| | | |
| | | #region 事件集合 |
| | |
| | | protected readonly LogicalOverrideColorHelper _overrideColorHelper = null;//覆盖颜色辅助类 |
| | | protected readonly LogicalOverrideOpacityHelper _overrideOpacityHelper = null;//覆盖透明度辅助类 |
| | | protected readonly LogicalOverrideVisibleHelper _overrideVisibleHelper = null;//覆盖可见性辅助类 |
| | | protected readonly LogicalBackgroudHelper _backgroundHelper = null;//背景辅助类 |
| | | protected readonly LogicalGridLineHelper _gridLinesHelper = null;//网格线辅助类 |
| | | protected readonly LogicalHighlightHelper _highlightHelper = null;//高亮辅助类 |
| | | protected readonly LogicalSelectionHelper _selectionHelper = null;//选择辅助类 |
| | | protected readonly LogicalZoomHelper _zoomHelper = null;//缩放辅助类 |
| | | protected readonly LogicalBillboardTextHelper _billboardTextHelper = null;//公告版文字辅助类 |
| | | protected readonly LogicalCameraHelper _cameraHelper = null;//相机辅助类 |
| | | protected readonly LogicalFlowDirectionHelper _flowDirectionHelper = null;//水流方向辅助类 |
| | | |
| | | #endregion |
| | | |
| | |
| | | return; |
| | | } |
| | | _viewport.Children.Clear(); |
| | | _viewport.Children.Add(new DefaultLights()); |
| | | _viewport.Children.Add(new SunLight()); |
| | | _allVisualLogicalDict?.Values.ToList().ForEach(x => _viewport.Children.Add(x)); |
| | | _viewport.ZoomExtents(); |
| | | if (_nw.DefaultCamera != null) |
| | | { |
| | | _cameraHelper.SetDefault(_nw.DefaultCamera); |
| | | _cameraHelper.ApplyDefault(); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | _selectionHelper.StateChangedEvent += SelectionHelper_StateChangedEvent; |
| | | _selectionHelper.SelectionChangedEvent += SelectionHelper_SelectionChangedEvent; |
| | | } |
| | | if (_cameraHelper != null) |
| | | { |
| | | _cameraHelper.SaveDefaultCameraEvent += CameraHelper_SaveDefaultCameraEvent; |
| | | } |
| | | } |
| | | |
| | | //高亮状态改变事件 |
| | | private void HighlightHelper_StateChangedEvent(LogicalVisual3D logicalVisual, eLogicalHighlight highlightType) |
| | | private void HighlightHelper_StateChangedEvent(LogicalVisual3D logicalVisual, bool operation) |
| | | { |
| | | if (logicalVisual == null) |
| | | { |
| | | return; |
| | | } |
| | | switch (highlightType) |
| | | if (operation) |
| | | { |
| | | case eLogicalHighlight.Load: |
| | | { |
| | | _stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Highlight); |
| | | } |
| | | break; |
| | | case eLogicalHighlight.Unload: |
| | | { |
| | | _stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Highlight); |
| | | } |
| | | break; |
| | | default: break; |
| | | _stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Highlight); |
| | | } |
| | | else |
| | | { |
| | | _stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Highlight); |
| | | } |
| | | logicalVisual.UpdateVisual(); |
| | | } |
| | | |
| | | //选择状态改变事件 |
| | | private void SelectionHelper_StateChangedEvent(LogicalVisual3D logicalVisual, eLogicalSelection selectionType) |
| | | private void SelectionHelper_StateChangedEvent(LogicalVisual3D logicalVisual, bool operation) |
| | | { |
| | | if (logicalVisual == null) |
| | | { |
| | | return; |
| | | } |
| | | switch (selectionType) |
| | | if (operation) |
| | | { |
| | | case eLogicalSelection.Load: |
| | | { |
| | | _stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Selection); |
| | | } |
| | | break; |
| | | case eLogicalSelection.Unload: |
| | | { |
| | | _stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Selection); |
| | | } |
| | | break; |
| | | default: break; |
| | | _stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Selection); |
| | | } |
| | | else |
| | | { |
| | | _stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Selection); |
| | | } |
| | | logicalVisual.UpdateVisual(); |
| | | } |
| | |
| | | this.SelectionChangedEvent?.Invoke(visuals); |
| | | } |
| | | |
| | | //默认相机保存事件 |
| | | private void CameraHelper_SaveDefaultCameraEvent(LogicalCamera3D logicalCamera) |
| | | { |
| | | var camera = logicalCamera.ToCameraL3d(); |
| | | _nw.DefaultCamera = camera; |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | | #region 快捷方法 |
| | | |
| | | //获取Visual3D |
| | | protected virtual LogicalVisual3D GetVisual3D(string Id) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return default; |
| | | } |
| | | var id = Id?.Trim(); |
| | | if (string.IsNullOrEmpty(id)) |
| | | { |
| | | return default; |
| | | } |
| | | if (_allVisualL3dDict.ContainsKey(id)) |
| | | { |
| | | var visual = _allVisualL3dDict[Id]; |
| | | if (_allVisualLogicalDict.ContainsKey(visual)) |
| | | { |
| | | var visual3d = _allVisualLogicalDict[visual]; |
| | | return visual3d; |
| | | } |
| | | } |
| | | return default; |
| | | } |
| | | |
| | | //获取Visual3D |
| | | protected virtual List<LogicalVisual3D> GetVisual3D(List<string> Ids) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return default; |
| | | } |
| | | var list = Ids?.Select(x => GetVisual3D(x)).Where(x => x != null).ToList(); |
| | | return list; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 视角 |
| | | |
| | | /// <summary> |
| | | /// 设置上视图 |
| | | /// </summary> |
| | | public virtual void SetTopView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(0, 0, -1); // 向下看 |
| | | var upDirection = new Vector3D(0, 1, 0);// Y轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置下视图 |
| | | /// </summary> |
| | | public virtual void SetBottomView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(0, 0, 1); // 向上看 |
| | | var upDirection = new Vector3D(0, 1, 0);// Y轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置左视图 |
| | | /// </summary> |
| | | public virtual void SetLeftView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(1, 0, 0); // 向右看 |
| | | var upDirection = new Vector3D(0, 0, 1);// Z轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置右视图 |
| | | /// </summary> |
| | | public virtual void SetRightView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(-1, 0, 0); // 向左看 |
| | | var upDirection = new Vector3D(0, 0, 1);// Z轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置前视图 |
| | | /// </summary> |
| | | public virtual void SetFrontView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(0, 1, 0); // 向后看 |
| | | var upDirection = new Vector3D(0, 0, 1);// Z轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置后视图 |
| | | /// </summary> |
| | | public virtual void SetBackView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(0, -1, 0); // 向前看 |
| | | var upDirection = new Vector3D(0, 0, 1);// Z轴朝上 |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 西南视角 |
| | | /// 从物体的左前下方观察 |
| | | /// </summary> |
| | | public virtual void SetSouthWestView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(1, 1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 东南视角 |
| | | /// 从物体的右前下方观察 |
| | | /// </summary> |
| | | public virtual void SetSouthEastView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(-1, 1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 东北视角 |
| | | /// 从物体的右后上方观察 |
| | | /// </summary> |
| | | public virtual void SetNorthEastView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(-1, -1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 西北视角 |
| | | /// 从物体的左后上方观察 |
| | | /// </summary> |
| | | public virtual void SetNorthWestView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(1, -1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 背景 |
| | | |
| | | /// <summary> |
| | | /// 显示背景 |
| | | /// </summary> |
| | | public virtual void ShowBackgroud() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _backgroundHelper.Show(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 隐藏背景 |
| | | /// </summary> |
| | | public virtual void HideBackgroud() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _backgroundHelper.Hide(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 背景可见性 |
| | | /// </summary> |
| | | public virtual bool BackgroudVisible |
| | | { |
| | | get |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return false; |
| | | } |
| | | return _backgroundHelper.Visible; |
| | | } |
| | | set |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _backgroundHelper.Visible = value; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置背景 |
| | | /// </summary> |
| | | public virtual void SetBackgroud(string url) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _backgroundHelper.Set(url); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置背景 |
| | | /// </summary> |
| | | public virtual void SetBackgroud(string url, double width, double height) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _backgroundHelper.Set(url, width, height); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 网格线 |
| | | |
| | | /// <summary> |
| | | /// 显示网格线 |
| | | /// </summary> |
| | | public virtual void ShowGridLines() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _gridLinesHelper.Show(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 隐藏网格线 |
| | | /// </summary> |
| | | public virtual void HideGridLines() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _gridLinesHelper.Hide(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网格线可见性 |
| | | /// </summary> |
| | | public virtual bool GridLinesVisible |
| | | { |
| | | get |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return false; |
| | | } |
| | | return _gridLinesHelper.Visible; |
| | | } |
| | | set |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _gridLinesHelper.Visible = value; |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 缩放 |
| | | |
| | | /// <summary> |
| | | /// 缩放至可见构件 |
| | | /// </summary> |
| | | public virtual void ZoomToVisual(string Id) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3d = GetVisual3D(Id); |
| | | if (visual3d != null) |
| | | { |
| | | _zoomHelper.ZoomToVisual(visual3d); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 缩放至可见构件 |
| | | /// </summary> |
| | | public virtual void ZoomToVisual(List<string> Ids) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3ds = GetVisual3D(Ids); |
| | | if (visual3ds != null && visual3ds.Count > 0) |
| | | { |
| | | _zoomHelper.ZoomToVisual(visual3ds); |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 选择 |
| | | |
| | | /// <summary> |
| | | /// 选择可见构件 |
| | | /// </summary> |
| | | public virtual void SelectVisual(string Id) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3d = GetVisual3D(Id); |
| | | _selectionHelper.SelectVisual(visual3d); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 选择可见构件 |
| | | /// </summary> |
| | | public virtual void SelectVisual(List<string> Ids) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3ds = GetVisual3D(Ids); |
| | | _selectionHelper.SelectVisual(visual3ds); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 缩放并选择 |
| | | |
| | | /// <summary> |
| | | /// 缩放并选择可见构件 |
| | | /// </summary> |
| | | public virtual void ZoomAndSelectVisual(string Id) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3d = GetVisual3D(Id); |
| | | _zoomHelper.ZoomToVisual(visual3d); |
| | | _selectionHelper.SelectVisual(visual3d); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 缩放并选择可见构件 |
| | | /// </summary> |
| | | public virtual void ZoomAndSelectVisual(List<string> Ids) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var visual3ds = GetVisual3D(Ids); |
| | | _zoomHelper.ZoomToVisual(visual3ds); |
| | | _selectionHelper.SelectVisual(visual3ds); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 公告板文本 |
| | | |
| | | /// <summary> |
| | | /// 设置公告板文本 |
| | | /// </summary> |
| | | public virtual void SetBillboardText(List<TextL3d> items) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _billboardTextHelper.Set(items); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新公告板文本 |
| | | /// </summary> |
| | | public virtual void UpdateBillboardText(TextL3d item) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _billboardTextHelper.Update(item); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 更新公告板文本 |
| | | /// </summary> |
| | | public virtual void UpdateBillboardText(List<TextL3d> items) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _billboardTextHelper.Update(items); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清理公告板文本 |
| | | /// </summary> |
| | | public virtual void ClearBillboardText() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _billboardTextHelper.Clear(); |
| | | } |
| | | |
| | | |
| | | #endregion |
| | | |
| | | #region 相机 |
| | | |
| | | /// <summary> |
| | | /// 保存默认相机 |
| | | /// </summary> |
| | | public void SaveDefaultCamera() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _cameraHelper.SaveDefault(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 应用默认相机 |
| | | /// </summary> |
| | | public void ApplyDefaultCamera() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _cameraHelper.ApplyDefault(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 水流方向 |
| | | |
| | | /// <summary> |
| | | /// 显示水流方向 |
| | | /// </summary> |
| | | public void ShowFlowDirection() |
| | | { |
| | | var allLinkList = _allVisualLogicalDict.Values.Where(x => x is LogicalLink3D).Select(x => x as LogicalLink3D).ToList(); |
| | | _flowDirectionHelper.Set(allLinkList); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置水流方向 |
| | | /// </summary> |
| | | public void SetFlowDirection(List<FlowDirectionL3d> list) |
| | | { |
| | | var dict = new Dictionary<LogicalLink3D, bool>(); |
| | | list?.ForEach(x => |
| | | { |
| | | if (_allVisualL3dDict.ContainsKey(x.Id)) |
| | | { |
| | | var visual = _allVisualL3dDict[x.Id]; |
| | | if (_allVisualLogicalDict.ContainsKey(visual)) |
| | | { |
| | | var visual3d = _allVisualLogicalDict[visual]; |
| | | if (visual3d is LogicalLink3D link3d) |
| | | { |
| | | dict.Add(link3d, x.Positive); |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | _flowDirectionHelper.Set(dict); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 清除水流方向 |
| | | /// </summary> |
| | | public void ClearFlowDirection() |
| | | { |
| | | _flowDirectionHelper.Clear(); |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | |
| | | } |