프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Events / UndoCommand.cs @ 3908a575

이력 | 보기 | 이력해설 | 다운로드 (9.02 KB)

1 d128ceb2 humkyung
using MarkupToPDF.Common;
2
using MarkupToPDF.Controls.Common;
3
using MarkupToPDF.Controls.Line;
4
using MarkupToPDF.Controls.Polygon;
5
using MarkupToPDF.Controls.Shape;
6
using MarkupToPDF.Controls.Text;
7
using MarkupToPDF.Controls.Etc;
8
using System;
9
using System.Collections.Generic;
10
using System.Linq;
11
using System.Text;
12
using System.Windows;
13
using System.Windows.Controls;
14
using System.Windows.Media;
15
using MarkupToPDF.Controls.Cad;
16
using KCOM.Common;
17 f816dd63 humkyung
using KCOM.Controls;
18 d128ceb2 humkyung
19
namespace KCOM.Events
20
{
21
    public class UndoCommand
22
    {
23
        private static readonly UndoCommand _instance = new UndoCommand();
24
25
        // Explicit static constructor to tell C# compiler
26
        // not to mark type as beforefieldinit
27
        static UndoCommand()
28
        {
29
        }
30
31
        private UndoCommand()
32
        {
33
        }
34
35
        public static UndoCommand Instance
36
        {
37
            get
38
            {
39
                return _instance;
40
            }
41
        }
42
43
        /// <summary>
44
        /// push undo data
45
        /// </summary>
46
        /// <author>humkyung</author>
47
        /// <date>2019.06.14</date>
48
        /// <param name="comments"></param>
49 f816dd63 humkyung
        public void Push(ICollection<CommentUserInfo> comments, double dAngle)
50 d128ceb2 humkyung
        {
51
            List<Point> p_set = new List<Point>();
52
53
            Undo_data UndoData = new Undo_data()
54
            {
55
                IsUndo = false,
56
                Event = Event_Type.Thumb,
57
                EventTime = DateTime.Now,
58
                Markup_List = new List<Multi_Undo_data>(),
59
            };
60
61
            Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
62
63
            foreach (var comment in comments)
64
            {
65
                multi_Undo_Data.PointSet = new List<Point>();
66
                p_set = new List<Point>();
67
68
                if (comment is TextControl)
69
                {
70
                    multi_Undo_Data.PointSet.Add((comment as TextControl).StartPoint);
71
                    multi_Undo_Data.PointSet.Add((comment as TextControl).EndPoint);
72
                }
73
74
                foreach (var point in (comment as IPath).PointSet)
75
                {
76
                    multi_Undo_Data.PointSet.Add(point);
77
                }
78
79
                if (comment is ArrowTextControl)
80
                {
81
                    multi_Undo_Data.Angle = dAngle = (comment as ArrowTextControl).Angle;
82
                }
83
                else
84
                {
85
                    multi_Undo_Data.Angle = dAngle;
86
                }
87
88
                multi_Undo_Data.Markup = comment;
89
                UndoData.Markup_List.Add(multi_Undo_Data);
90
                multi_Undo_Data = new Multi_Undo_data();
91
            }
92
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
93
            {
94
                ViewerDataModel.Instance.UndoDataList.Remove(i);
95
            });
96
97
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);
98
        }
99 f816dd63 humkyung
100
        /// <summary>
101
        /// undo
102
        /// </summary>
103
        public void Execute()
104
        {
105
            AdornerFinal final;
106
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
107
108
            Undo_data undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList().OrderByDescending(order => order.EventTime).FirstOrDefault();
109
            if (undo == null) return;
110
111
            switch (undo.Event)
112
            {
113
                case (Event_Type.Create):
114
                    {
115
                        foreach (var item in undo.Markup_List)
116
                        {
117
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
118
                        }
119
                    }
120
                    break;
121
                case (Event_Type.Delete):
122
                    {
123
                        foreach (var item in undo.Markup_List)
124
                        {
125
                            ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup);
126
                        }
127
                    }
128
                    break;
129
                case (Event_Type.Thumb):
130
                    {
131
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
132
133
                        foreach (var item in undo.Markup_List)
134
                        {
135
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
136
137
                            if ((item.Markup as IViewBox) != null)
138
                            {
139
                                (item.Markup as IViewBox).Angle = item.Angle;
140
                            }
141
                            if ((item.Markup as TextControl) != null)
142
                            {
143
                                (item.Markup as TextControl).Angle = item.Angle;
144
                                Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X);
145
                                Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y);
146
                            }
147
                            else
148
                            {
149
                                (item.Markup as IPath).PointSet = item.PointSet;
150 0d00f9c8 humkyung
                                (item.Markup as CommentUserInfo).UpdateControl();
151 f816dd63 humkyung
                            }
152
153
                            comment.Add(item.Markup);
154
                        }
155
                        final = new AdornerFinal(comment);
156
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
157
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
158
                    }
159
                    break;
160
                case (Event_Type.Select):
161
                    {
162
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
163
164
                        foreach (var item in undo.Markup_List)
165
                        {
166
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
167
168
                            if ((item.Markup as IPath) != null)
169
                            {
170
                                (item.Markup as IPath).LineSize = item.LineSize;
171
                            }
172
                            if ((item.Markup as UIElement) != null)
173
                            {
174
                                (item.Markup as UIElement).Opacity = item.Opacity;
175
                            }
176
                            if ((item.Markup as IDashControl) != null)
177
                            {
178
                                (item.Markup as IDashControl).DashSize = item.DashSize;
179
                            }
180
                            if ((item.Markup as IShapeControl) != null)
181
                            {
182
                                (item.Markup as IShapeControl).Paint = item.paint;
183
                            }
184
185
                            comment.Add(item.Markup);
186
                        }
187
188
                        final = new AdornerFinal(comment);
189
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
190
                    }
191
                    break;
192
                case (Event_Type.Option):
193
                    {
194
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
195
196
                        foreach (var item in undo.Markup_List)
197
                        {
198
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
199
200
                            if (undo.LineSize != 0 && item.Markup as IPath != null)
201
                            {
202
                                (item.Markup as IPath).LineSize = undo.LineSize;
203
                            }
204
                            else if (undo.Opacity != 0 && item.Markup as UIElement != null)
205
                            {
206
                                (item.Markup as UIElement).Opacity = undo.Opacity;
207
                            }
208
                            else if (undo.DashSize != null && item.Markup as IDashControl != null)
209
                            {
210
                                (item.Markup as IDashControl).DashSize = undo.DashSize;
211
                            }
212
                            else if (undo.Interval != 0 && item.Markup as LineControl != null)
213
                            {
214
                                (item.Markup as LineControl).Interval = undo.Interval;
215
                            }
216
                            else if (item.Markup as IShapeControl != null)
217
                            {
218
                                (item.Markup as IShapeControl).Paint = undo.paint;
219
                            }
220
                            comment.Add(item.Markup);
221
                        }
222
                        final = new AdornerFinal(comment);
223
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
224
                    }
225
                    break;
226
            }
227
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList().OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
228
            {
229
                i.IsUndo = true;
230
            });
231
        }
232 d128ceb2 humkyung
    }
233
}
클립보드 이미지 추가 (최대 크기: 500 MB)