프로젝트

일반

사용자정보

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

markus / KCOM / Events / UndoCommand.cs @ ab7fe8c0

이력 | 보기 | 이력해설 | 다운로드 (10.9 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
            Undo_data UndoData = new Undo_data()
53
            {
54
                IsUndo = false,
55
                Event = Event_Type.Thumb,
56
                EventTime = DateTime.Now,
57
                Markup_List = new List<Multi_Undo_data>(),
58
            };
59

    
60
            Multi_Undo_data multi_Undo_Data = new Multi_Undo_data();
61

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

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

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

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

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

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

    
99
            ViewerDataModel.Instance.UndoDataList.Add(UndoData);            
100
        }
101

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

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

    
114
            switch (undo.Event)
115
            {
116
                case (Event_Type.Create):
117
                    {
118
                        foreach (var item in undo.Markup_List)
119
                        {
120
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
121
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
122
                            null, Event_Type.Delete, item.Markup.CommentID, null);
123
                        }
124
                    }
125
                    break;
126
                case (Event_Type.Delete):
127
                    {
128
                        foreach (var item in undo.Markup_List)
129
                        {
130
                            //var markupitem = MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID);
131

    
132
                            //if (markupitem != null)
133
                            //{
134
                            //    IKCOM.MarkupItemEx markup = new IKCOM.MarkupItemEx
135
                            //    {
136
                            //        Data = markupitem.ConvertData,
137
                            //        Data_Type = markupitem.DATA_TYPE,
138
                            //        ID = markupitem.CommentID,
139
                            //        IsUpdate = false,
140
                            //        MarkupInfoID = App.Custom_ViewInfoId,
141
                            //        PageNumber = ViewerDataModel.Instance.PageNumber,
142
                            //        //Symbol_ID = p.Symbol_ID,
143
                            //        //Group_ID = p.Group_ID
144
                            //    };
145

    
146
                            //    ViewerDataModel.Instance.MyMarkupList.Add(markup);
147
                            //}
148

    
149
                            //ViewerDataModel.Instance.MarkupControls.Add(item.Markup);
150
                            item.Markup.Load();
151

    
152
                            ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup);
153
                            ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate(
154
                            MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null);
155
                        }
156
                    }
157
                    break;
158
                case (Event_Type.Thumb):
159
                    {
160
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
161

    
162
                        foreach (var item in undo.Markup_List)
163
                        {
164
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
165

    
166
                            if ((item.Markup as IViewBox) != null)
167
                            {
168
                                (item.Markup as IViewBox).CommentAngle = item.Angle;
169
                            }
170
                            if ((item.Markup as TextControl) != null)
171
                            {
172
                                (item.Markup as TextControl).CommentAngle = item.Angle;
173
                                Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X);
174
                                Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y);
175
                            }
176
                            else
177
                            {
178
                                (item.Markup as IPath).PointSet = item.PointSet;
179
                                (item.Markup as CommentUserInfo).UpdateControl();
180
                            }
181

    
182
                            comment.Add(item.Markup);
183
                        }
184
                        final = new AdornerFinal(comment);
185
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
186
                        SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu);
187
                    }
188
                    break;
189
                case (Event_Type.Select):
190
                    {
191
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
192

    
193
                        foreach (var item in undo.Markup_List)
194
                        {
195
                            ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup));
196

    
197
                            if ((item.Markup as IPath) != null)
198
                            {
199
                                (item.Markup as IPath).LineSize = item.LineSize;
200
                            }
201
                            if ((item.Markup as UIElement) != null)
202
                            {
203
                                (item.Markup as UIElement).Opacity = item.Opacity;
204
                            }
205
                            if ((item.Markup as IDashControl) != null)
206
                            {
207
                                (item.Markup as IDashControl).DashSize = item.DashSize;
208
                            }
209
                            if ((item.Markup as IShapeControl) != null)
210
                            {
211
                                (item.Markup as IShapeControl).Paint = item.paint;
212
                            }
213

    
214
                            comment.Add(item.Markup);
215
                        }
216

    
217
                        final = new AdornerFinal(comment);
218
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
219
                    }
220
                    break;
221
                case (Event_Type.Option):
222
                    {
223
                        List<CommentUserInfo> comment = new List<CommentUserInfo>();
224

    
225
                        foreach (var item in undo.Markup_List)
226
                        {
227
                            ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup);
228

    
229
                            if (undo.LineSize != 0 && item.Markup as IPath != null)
230
                            {
231
                                (item.Markup as IPath).LineSize = undo.LineSize;
232
                            }
233
                            else if (undo.Opacity != 0 && item.Markup as UIElement != null)
234
                            {
235
                                (item.Markup as UIElement).Opacity = undo.Opacity;
236
                            }
237
                            else if (undo.DashSize != null && item.Markup as IDashControl != null)
238
                            {
239
                                (item.Markup as IDashControl).DashSize = undo.DashSize;
240
                            }
241
                            else if (undo.Interval != 0 && item.Markup as LineControl != null)
242
                            {
243
                                (item.Markup as LineControl).Interval = undo.Interval;
244
                            }
245
                            else if (item.Markup as IShapeControl != null)
246
                            {
247
                                (item.Markup as IShapeControl).Paint = undo.paint;
248
                            }
249
                            comment.Add(item.Markup);
250
                        }
251
                        final = new AdornerFinal(comment);
252
                        Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
253
                    }
254
                    break;
255
            }
256
            ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList()
257
                .OrderByDescending(order => order.EventTime).ToList().ForEach(i =>
258
            {
259
                i.IsUndo = true;
260
            });
261
        }
262
    }
263
}
클립보드 이미지 추가 (최대 크기: 500 MB)