lixiaojun
昨天 531e3b2f09ebf2e6df44e6803e7fa06073ba2c3d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
namespace Yw.WpfUI.Hydro
{
    /// <summary>
    /// 绘制编辑辅助类
    /// </summary>
    internal class DrawEditHelper : IDisposable
    {
        /// <summary>
        /// 
        /// </summary>
        public DrawEditHelper
            (
                HelixViewport3D viewport,
                DrawInitialHelper initialHelper,
                DrawSelectionHelper selectionHelper
            )
        {
            _viewport = viewport;
            _initialHelper = initialHelper;
            _selectionHelper = selectionHelper;
            Attach();
        }
 
        #region 事件集合
 
        /// <summary>
        /// 编辑改变事件
        /// </summary>
        public event Action<List<VisualDraw3D>> EditChangedEvent;
 
        #endregion
 
        private readonly HelixViewport3D _viewport = null;//三维组件
        private readonly DrawInitialHelper _initialHelper = null;//初始化辅助类
        private readonly DrawSelectionHelper _selectionHelper = null;//选择辅助类
        private EditDraw3D _editer = null;//编辑器
 
        /// <summary>
        /// 是否初始化
        /// </summary>
        public bool Initialized
        {
            get { return _initialized; }
            private set { _initialized = value; }
        }
        private bool _initialized = false;
 
        //初始化
        private void Initialize()
        {
            _initialized = true;
        }
 
        //处理初始化完成
        private void OnInitialCompleted()
        {
            Initialize();
        }
 
        /// <summary>
        /// 开始
        /// </summary>
        public bool Start()
        {
            if (!Initialized)
            {
                return false;
            }
            _initialHelper.RegistDrawStatus(eDrawStatusL3d.Edit, End);
            if (_editer == null)
            {
                _editer = new EditDraw3D(_viewport, _initialHelper, _selectionHelper);
                _editer.EditChangedEvent += OnEditChanged;
                _editer.Initial(_selectionHelper.Selection);
                _viewport.Children.Add(_editer);
            }
            return true;
        }
 
        /// <summary>
        /// 结束
        /// </summary>
        public bool End()
        {
            if (!Initialized)
            {
                return false;
            }
            if (_editer != null)
            {
                _editer.EditChangedEvent -= OnEditChanged;
                _editer.Dispose();
                _viewport.Children.Remove(_editer);
                _editer = null;
            }
            _initialHelper.ResetDrawStatus();
            return true;
        }
 
        //处理编辑改变
        private void OnEditChanged(List<VisualDraw3D> list)
        {
            this.EditChangedEvent?.Invoke(list);
        }
 
        //附加
        private void Attach()
        {
            _initialHelper.InitialCompletedEvent += OnInitialCompleted;
        }
 
        //分离
        private void Detach()
        {
            _initialHelper.InitialCompletedEvent -= OnInitialCompleted;
        }
 
        /// <summary>
        /// 释放
        /// </summary>
        public void Dispose()
        {
            Detach();
        }
 
 
    }
 
}