namespace Yw.WpfUI.Hydro
|
{
|
/// <summary>
|
/// 抽象管理器
|
/// </summary>
|
internal class LogicalManager
|
{
|
public LogicalManager(HelixViewport3D viewport)
|
{
|
_viewport = viewport;
|
_stateHelper = new LogicalStateHelper();
|
_materialHelper = new LogicalMaterialHelper();
|
_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 LogicalBillboardLeadLabelHelper(_viewport);
|
}
|
|
#region 事件集合
|
|
/// <summary>
|
/// 选择改变事件
|
/// </summary>
|
public event Action<List<VisualL3d>> SelectionChangedEvent;
|
|
#endregion
|
|
#region 固定资源
|
|
protected readonly HelixViewport3D _viewport = null;//三维组件
|
protected readonly LogicalStateHelper _stateHelper = null;//状态辅助类
|
protected readonly LogicalMaterialHelper _materialHelper = null;//材质辅助类
|
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 LogicalBillboardLeadLabelHelper _billboardTextHelper = null;//公告版文字辅助类
|
|
#endregion
|
|
#region 私有字段
|
|
protected NetworkL3d _nw = null;
|
protected Dictionary<string, VisualL3d> _allVisualL3dDict;
|
protected Dictionary<VisualL3d, LogicalVisual3D> _allVisualLogicalDict;
|
|
#endregion
|
|
#region 判断字段
|
|
/// <summary>
|
/// 是否启用缩放
|
/// </summary>
|
public virtual bool IsZoomEnabled
|
{
|
get { return _viewport.IsZoomEnabled; }
|
set { _viewport.IsZoomEnabled = value; }
|
}
|
|
/// <summary>
|
/// 是否启用平移
|
/// </summary>
|
public virtual bool IsPanEnabled
|
{
|
get { return _viewport.IsPanEnabled; }
|
set { _viewport.IsPanEnabled = value; }
|
}
|
|
/// <summary>
|
/// 是否启用旋转
|
/// </summary>
|
public virtual bool IsRotationEnabled
|
{
|
get { return _viewport.IsRotationEnabled; }
|
set { _viewport.IsRotationEnabled = value; }
|
}
|
|
/// <summary>
|
/// 是否启用高亮
|
/// </summary>
|
public virtual bool IsHighlightEnabled
|
{
|
get { return _isHighlightEnabled; }
|
set { _isHighlightEnabled = value; }
|
}
|
protected bool _isHighlightEnabled = true;
|
|
/// <summary>
|
/// 是否启用选择
|
/// </summary>
|
public virtual bool IsSelectionEnabled
|
{
|
get => _isSelectionEnabled;
|
set => _isSelectionEnabled = value;
|
}
|
protected bool _isSelectionEnabled = true;
|
|
/// <summary>
|
/// 是否启用缩放适应
|
/// </summary>
|
public virtual bool IsZoomExtentsEnabled
|
{
|
get => _isZoomExtentsEnabled;
|
set => _isZoomExtentsEnabled = value;
|
}
|
protected bool _isZoomExtentsEnabled = true;
|
|
#endregion
|
|
#region 初始化
|
|
/// <summary>
|
/// 是否初始化
|
/// </summary>
|
public virtual bool Initialized
|
{
|
get
|
{
|
if (_nw == null)
|
{
|
return false;
|
}
|
if (_allVisualL3dDict == null)
|
{
|
return false;
|
}
|
if (_allVisualLogicalDict == null)
|
{
|
return false;
|
}
|
return true;
|
}
|
}
|
|
/// <summary>
|
/// 初始化
|
/// </summary>
|
public virtual void Initial(NetworkL3d nw)
|
{
|
_nw = nw;
|
InitialNetwork();
|
InitialViewport();
|
RegisterEvents();
|
}
|
|
//加载管网
|
protected virtual void InitialNetwork()
|
{
|
if (_nw == null)
|
{
|
return;
|
}
|
_allVisualL3dDict = _nw.Visuals.ToDictionary(keySelector: x => x.Id);
|
_allVisualLogicalDict = new Dictionary<VisualL3d, LogicalVisual3D>();
|
_nw.Visuals?.ForEach(x =>
|
{
|
var logicalVisual = LogicalCreateHelper.Create(x, _stateHelper, _materialHelper, _overrideColorHelper, _overrideOpacityHelper, _overrideVisibleHelper);
|
if (logicalVisual != null)
|
{
|
_allVisualLogicalDict.Add(x, logicalVisual);
|
}
|
});
|
}
|
|
//初始化Vieport
|
protected virtual void InitialViewport()
|
{
|
InitialViewportInput();
|
InitialViewportCube();
|
InitialViewportData();
|
}
|
|
//初始化Viewport立方体
|
protected virtual void InitialViewportCube()
|
{
|
if (_viewport == null)
|
{
|
return;
|
}
|
_viewport.ViewCubeBackText = "后";
|
_viewport.ViewCubeBottomText = "下";
|
_viewport.ViewCubeFrontText = "前";
|
_viewport.ViewCubeLeftText = "左";
|
_viewport.ViewCubeRightText = "右";
|
_viewport.ViewCubeTopText = "上";
|
}
|
|
//初始化Viewport交互
|
protected virtual void InitialViewportInput()
|
{
|
if (_viewport == null)
|
{
|
return;
|
}
|
//当前操作不做任何处理,是为了避免鼠标操作冲突
|
}
|
|
//初始化Viewport数据
|
protected virtual void InitialViewportData()
|
{
|
if (_viewport == null)
|
{
|
return;
|
}
|
_viewport.Children.Clear();
|
_viewport.Children.Add(new SunLight());
|
_allVisualLogicalDict?.Values.ToList().ForEach(x => _viewport.Children.Add(x));
|
_viewport.ZoomExtents();
|
}
|
|
|
#endregion
|
|
#region 事件注册
|
|
//注册事件
|
protected virtual void RegisterEvents()
|
{
|
RegisterViewportEvents();
|
RegisterOperationEvents();
|
}
|
|
#region Viewport
|
|
//注册事件
|
protected virtual void RegisterViewportEvents()
|
{
|
if (_viewport == null)
|
{
|
return;
|
}
|
_viewport.MouseDown += Viewport_MouseDown;
|
_viewport.MouseUp += Viewport_MouseUp;
|
_viewport.MouseMove += Viewport_MouseMove;
|
_viewport.MouseWheel += Viewport_MouseWheel;
|
_viewport.MouseDoubleClick += Viewport_MouseDoubleClick;
|
_viewport.MouseLeftButtonDown += Viewport_MouseLeftButtonDown;
|
_viewport.PreviewMouseDown += _viewport_PreviewMouseDown;
|
}
|
|
private void _viewport_PreviewMouseDown(object sender, MouseButtonEventArgs e)
|
{
|
OnPreviewMouseDown(e);
|
}
|
|
//鼠标按下
|
private void Viewport_MouseDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
{
|
OnMouseDown(e);
|
}
|
|
//鼠标弹起
|
private void Viewport_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
|
{
|
OnMouseUp(e);
|
}
|
|
//鼠标移动
|
private void Viewport_MouseMove(object sender, System.Windows.Input.MouseEventArgs e)
|
{
|
OnMouseMove(e);
|
}
|
|
//鼠标滚轮
|
private void Viewport_MouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e)
|
{
|
OnMouseWheel(e);
|
}
|
|
//鼠标双击
|
private void Viewport_MouseDoubleClick(object sender, MouseButtonEventArgs e)
|
{
|
OnMouseDoubleClick(e);
|
}
|
|
//鼠标左键按下
|
private void Viewport_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
{
|
OnMouseLeftButtonDown(e);
|
}
|
|
//处理鼠标按下事件
|
protected virtual void OnMouseDown(System.Windows.Input.MouseButtonEventArgs e)
|
{
|
|
}
|
|
//处理鼠标弹起事件
|
protected virtual void OnMouseUp(System.Windows.Input.MouseButtonEventArgs e)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
if (this.IsSelectionEnabled)
|
{
|
_selectionHelper.HandleSingle(e.GetPosition(_viewport));
|
}
|
}
|
|
//处理鼠标移动事件
|
protected virtual void OnMouseMove(System.Windows.Input.MouseEventArgs e)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
if (this.IsHighlightEnabled)
|
{
|
_highlightHelper.Highlight(e.GetPosition(_viewport));
|
}
|
}
|
|
//处理鼠标滚轮事件
|
protected virtual void OnMouseWheel(System.Windows.Input.MouseWheelEventArgs e)
|
{
|
|
}
|
|
//处理鼠标双击事件
|
protected virtual void OnMouseDoubleClick(System.Windows.Input.MouseButtonEventArgs e)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
if (this.IsZoomExtentsEnabled)
|
{
|
_viewport.ZoomExtents();
|
}
|
}
|
|
//处理鼠标
|
protected virtual void OnMouseLeftButtonDown(MouseButtonEventArgs e)
|
{
|
|
}
|
|
protected virtual void OnPreviewMouseDown(MouseButtonEventArgs e)
|
{
|
|
}
|
|
#endregion
|
|
#region Operation
|
|
//注册操作事件
|
protected virtual void RegisterOperationEvents()
|
{
|
if (_highlightHelper != null)
|
{
|
_highlightHelper.StateChangedEvent += HighlightHelper_StateChangedEvent;
|
}
|
if (_selectionHelper != null)
|
{
|
_selectionHelper.StateChangedEvent += SelectionHelper_StateChangedEvent;
|
_selectionHelper.SelectionChangedEvent += SelectionHelper_SelectionChangedEvent;
|
}
|
}
|
|
//高亮状态改变事件
|
private void HighlightHelper_StateChangedEvent(LogicalVisual3D logicalVisual, bool operation)
|
{
|
if (logicalVisual == null)
|
{
|
return;
|
}
|
if (operation)
|
{
|
_stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Highlight);
|
}
|
else
|
{
|
_stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Highlight);
|
}
|
logicalVisual.UpdateVisual();
|
}
|
|
//选择状态改变事件
|
private void SelectionHelper_StateChangedEvent(LogicalVisual3D logicalVisual, bool operation)
|
{
|
if (logicalVisual == null)
|
{
|
return;
|
}
|
if (operation)
|
{
|
_stateHelper.LoadState(logicalVisual.Vmo, eLogicalState.Selection);
|
}
|
else
|
{
|
_stateHelper.UnloadState(logicalVisual.Vmo, eLogicalState.Selection);
|
}
|
logicalVisual.UpdateVisual();
|
}
|
|
//选择改变事件
|
private void SelectionHelper_SelectionChangedEvent(List<LogicalVisual3D> obj)
|
{
|
var visuals = obj?.Select(x => x.Vmo).ToList();
|
this.SelectionChangedEvent?.Invoke(visuals);
|
}
|
|
|
#endregion
|
|
#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);
|
}
|
|
#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 SetBillboardText(List<LogicalTextL3d> items)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
_billboardTextHelper.Set(items);
|
}
|
|
/// <summary>
|
/// 更新公告板文本
|
/// </summary>
|
public virtual void UpdateBillboardText(LogicalTextL3d item)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
_billboardTextHelper.Update(item);
|
}
|
|
/// <summary>
|
/// 更新公告板文本
|
/// </summary>
|
public virtual void UpdateBillboardText(List<LogicalTextL3d> items)
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
_billboardTextHelper.Update(items);
|
}
|
|
/// <summary>
|
/// 清理公告板文本
|
/// </summary>
|
public virtual void ClearBillboardText()
|
{
|
if (!Initialized)
|
{
|
return;
|
}
|
_billboardTextHelper.Clear();
|
}
|
|
|
#endregion
|
|
|
|
|
|
|
}
|
}
|