| | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | | public DrawCameraHelper(HelixViewport3D viewport) |
| | | public DrawCameraHelper |
| | | ( |
| | | HelixViewport3D viewport, |
| | | DrawInitialHelper initialHelper |
| | | ) |
| | | { |
| | | _viewport = viewport; |
| | | _initialHelper = initialHelper; |
| | | Attach(); |
| | | } |
| | | |
| | | private readonly HelixViewport3D _viewport = null;//三维组件 |
| | | private readonly DrawInitialHelper _initialHelper = null;//初始化辅助类 |
| | | |
| | | /// <summary> |
| | | /// 是否启用 |
| | | /// </summary> |
| | | public bool Enabled |
| | | { |
| | | get { return _enabled; } |
| | | set { _enabled = value; } |
| | | } |
| | | private bool _enabled = true; |
| | | |
| | | /// <summary> |
| | | /// 是否初始化 |
| | | /// </summary> |
| | | public bool Initialized |
| | | { |
| | | get { return _initialized; } |
| | | private set { _initialized = value; } |
| | | } |
| | | private bool _initialized = false; |
| | | |
| | | //初始化 |
| | | private void Initialize() |
| | | { |
| | | if (!_initialHelper.Initialized) |
| | | { |
| | | return; |
| | | } |
| | | _initialized = true; |
| | | } |
| | | |
| | | //处理初始化完成 |
| | | private void OnInitialCompleted() |
| | | { |
| | | Initialize(); |
| | | } |
| | | |
| | | #region 视图操作 |
| | | |
| | | /// <summary> |
| | | /// 获取视图 |
| | | /// </summary> |
| | | public CameraSettingL3d GetView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return default; |
| | | } |
| | | var cameraSetting = new CameraSetting(_viewport.Camera); |
| | | return cameraSetting.ToCameraSettingL3d(); |
| | | } |
| | |
| | | /// </summary> |
| | | public void SetView(CameraSettingL3d cameraSetting) |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | if (cameraSetting == null) |
| | | { |
| | | return; |
| | |
| | | } |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 六视图 |
| | | |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public 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> |
| | | public 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> |
| | | public 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> |
| | | public 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> |
| | | public 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> |
| | | public 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> |
| | | public void SetSouthWestView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(1, 1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | |
| | | /// </summary> |
| | | public void SetSouthEastView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(-1, 1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | |
| | | /// </summary> |
| | | public void SetNorthEastView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return; |
| | | } |
| | | var lookDirection = new Vector3D(-1, -1, -1); |
| | | var upDirection = new Vector3D(0, 0, 1); |
| | | _viewport.FitView(lookDirection, upDirection); |
| | |
| | | /// </summary> |
| | | public 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 bool ShowDefaultView() |
| | | { |
| | | if (!Initialized) |
| | | { |
| | | return false; |
| | | } |
| | | var cameraSetting = _initialHelper.GetDefaultCameraSetting(); |
| | | if (cameraSetting == null) |
| | | { |
| | | return false; |
| | | } |
| | | SetView(cameraSetting); |
| | | return true; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | //处理鼠标双击事件 |
| | | private void OnMouseDoubleClick(object sender, MouseButtonEventArgs e) |
| | | { |
| | | if (e.ChangedButton != MouseButton.Left) |
| | | { |
| | | return; |
| | | } |
| | | if (!Enabled) |
| | | { |
| | | return; |
| | | } |
| | | var bol = ShowDefaultView(); |
| | | if (bol) |
| | | { |
| | | return; |
| | | } |
| | | SetSouthWestView(); |
| | | } |
| | | |
| | | //附加 |
| | | private void Attach() |
| | | { |
| | | _viewport.MouseDoubleClick += OnMouseDoubleClick; |
| | | _initialHelper.InitialCompletedEvent += OnInitialCompleted; |
| | | } |
| | | |
| | | //分离 |
| | | private void Detach() |
| | | { |
| | | _viewport.MouseDoubleClick -= OnMouseDoubleClick; |
| | | _initialHelper.InitialCompletedEvent -= OnInitialCompleted; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 释放 |
| | | /// </summary> |
| | | public void Dispose() |
| | | { |
| | | |
| | | Detach(); |
| | | } |
| | | |
| | | } |