프로젝트

일반

사용자정보

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

markus / KCOM / Events / UndoCommand.cs @ 285635d3

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

1
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
using KCOM.Controls;
18
using MarkupToPDF.Controls.Parsing;
19

    
20
namespace KCOM.Events
21
{
22
    public class UndoCommand
23
    {
24
        private static readonly UndoCommand _instance = new UndoCommand();
25

    
26
        // Explicit static constructor to tell C# compiler
27
        // not to mark type as beforefieldinit
28
        static UndoCommand()
29
        {
30
        }
31

    
32
        private UndoCommand()
33
        {
34
        }
35

    
36
        public static UndoCommand Instance
37
        {
38
            get
39
            {
40
                return _instance;
41
            }
42
        }
43

    
44
        /// <summary>
45
        /// push undo data
46
        /// </summary>
47
        /// <author>humkyung</author>
48
        /// <date>2019.06.14</date>
49
        /// <param name="comments"></param>
50
        public void Push(ICollection<CommentUserInfo> comments, double dAngle)
51
        {
52
            List<Point> p_set = new List<Point>();
53

    
54
            Undo_data UndoData = new Undo_data()
55
            {
56
                IsUndo = false,
57
                Event = Event_Type.Thumb,
58
                EventTime = DateTime.Now,
59
                Markup_List = new List<Multi_Undo_data>(),
60
            };
61

    
62
            Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
63

    
64
            foreach (var comment in comments)
65
            {
66
                multi_Undo_Data.PointSet = new List<Point>();
67
                p_set = new List<Point>();
68

    
69
                if (comment is TextControl)
70
                {
71
                    multi_Undo_Data.PointSet.Add((comment as TextControl).StartPoint);
72
                    multi_Undo_Data.PointSet.Add((comment as TextControl).EndPoint);
73
                }
74

    
75
                foreach (var point in (comment as IPath).PointSet)
76
                {
77
                    multi_Undo_Data.PointSet.Add(point);
78
                }
79

    
80
                if (comment is ArrowTextControl)
81
                {
82
                    multi_Undo_Data.Angle = dAngle = (comment as ArrowTextControl).CommentAngle;
83
                }
84
                else
85
                {
86
                    multi_Undo_Data.Angle = dAngle;
87
                }
88

    
89
                multi_Undo_Data.Markup = comment;
90
                UndoData.Markup_List.Add(multi_Undo_Data);
91
                ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
92
                            MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Thumb, null, null);
93

    
94
                multi_Undo_Data = new Multi_Undo_data();                
95
            }
96
            ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i =>
97
            {
98
                ViewerDataModel.Instance.UndoDataList.Remove(i);
99
            });
100

    
101
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);            
102
        }
103

    
104
        /// <summary>
105
        /// undo
106
        /// </summary>
107
        public void Execute()
108
        {
109
            AdornerFinal final;
110
            SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
111

    
112
            Undo_data undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList().OrderByDescending(order => order.EventTime).FirstOrDefault();
113
            if (undo == null) return;
114

    
115
            switch (undo.Event)
116
            {
117
                case (Event_Type.Create):
118
                    {
119
                        foreach (var item in undo.Markup_List)
120
                        {
121
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
122
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
123
                            null, Event_Type.Delete, item.Markup.CommentID, null);
124
                        }
125
                    }
126
                    break;
127
                case (Event_Type.Delete):
128
                    {
129
                        foreach (var item in undo.Markup_List)
130
                        {
131
                            ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup);
132
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
133
                            MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
134
                        }
135
                    }
136
                    break;
137
                case (Event_Type.Thumb):
138
                    {
139
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
140

    
141
                        foreach (var item in undo.Markup_List)
142
                        {
143
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
144

    
145
                            if ((item.Markup as IViewBox) != null)
146
                            {
147
                                (item.Markup as IViewBox).CommentAngle = item.Angle;
148
                            }
149
                            if ((item.Markup as TextControl) != null)
150
                            {
151
                                (item.Markup as TextControl).CommentAngle = item.Angle;
152
                                Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X);
153
                                Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y);
154
                            }
155
                            else
156
                            {
157
                                (item.Markup as IPath).PointSet = item.PointSet;
158
                                (item.Markup as CommentUserInfo).UpdateControl();
159
                            }
160

    
161
                            comment.Add(item.Markup);
162
                        }
163
                        final = new AdornerFinal(comment);
164
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
165
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
166
                    }
167
                    break;
168
                case (Event_Type.Select):
169
                    {
170
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
171

    
172
                        foreach (var item in undo.Markup_List)
173
                        {
174
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
175

    
176
                            if ((item.Markup as IPath) != null)
177
                            {
178
                                (item.Markup as IPath).LineSize = item.LineSize;
179
                            }
180
                            if ((item.Markup as UIElement) != null)
181
                            {
182
                                (item.Markup as UIElement).Opacity = item.Opacity;
183
                            }
184
                            if ((item.Markup as IDashControl) != null)
185
                            {
186
                                (item.Markup as IDashControl).DashSize = item.DashSize;
187
                            }
188
                            if ((item.Markup as IShapeControl) != null)
189
                            {
190
                                (item.Markup as IShapeControl).Paint = item.paint;
191
                            }
192

    
193
                            comment.Add(item.Markup);
194
                        }
195

    
196
                        final = new AdornerFinal(comment);
197
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
198
                    }
199
                    break;
200
                case (Event_Type.Option):
201
                    {
202
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
203

    
204
                        foreach (var item in undo.Markup_List)
205
                        {
206
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
207

    
208
                            if (undo.LineSize != 0 && item.Markup as IPath != null)
209
                            {
210
                                (item.Markup as IPath).LineSize = undo.LineSize;
211
                            }
212
                            else if (undo.Opacity != 0 && item.Markup as UIElement != null)
213
                            {
214
                                (item.Markup as UIElement).Opacity = undo.Opacity;
215
                            }
216
                            else if (undo.DashSize != null && item.Markup as IDashControl != null)
217
                            {
218
                                (item.Markup as IDashControl).DashSize = undo.DashSize;
219
                            }
220
                            else if (undo.Interval != 0 && item.Markup as LineControl != null)
221
                            {
222
                                (item.Markup as LineControl).Interval = undo.Interval;
223
                            }
224
                            else if (item.Markup as IShapeControl != null)
225
                            {
226
                                (item.Markup as IShapeControl).Paint = undo.paint;
227
                            }
228
                            comment.Add(item.Markup);
229
                        }
230
                        final = new AdornerFinal(comment);
231
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
232
                    }
233
                    break;
234
            }
235
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList().OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
236
            {
237
                i.IsUndo = true;
238
            });
239
        }
240
    }
241
}
클립보드 이미지 추가 (최대 크기: 500 MB)