markus / KCOM / Events / UndoCommand.cs @ e5bd2147
이력 | 보기 | 이력해설 | 다운로드 (13.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, double dBeforeAngle = 0.0, List<Point> lstBeforePointSet = null) |
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 (lstBeforePointSet != null) |
79 |
// multi_Undo_Data.BeforePointSet = lstBeforePointSet; |
80 |
|
81 |
// if (comment is ArrowTextControl) |
82 |
// { |
83 |
// //multi_Undo_Data.Angle = dAngle = (comment as ArrowTextControl).CommentAngle; |
84 |
// multi_Undo_Data.Angle = dAngle; |
85 |
// multi_Undo_Data.BeforeAngle = dBeforeAngle; |
86 |
// } |
87 |
// else |
88 |
// { |
89 |
// multi_Undo_Data.Angle = dAngle; |
90 |
// multi_Undo_Data.BeforeAngle = dBeforeAngle; |
91 |
// } |
92 |
|
93 |
// multi_Undo_Data.Markup = comment; |
94 |
// UndoData.Markup_List.Add(multi_Undo_Data); |
95 |
// ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
96 |
// MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Thumb, null, null); |
97 |
|
98 |
// multi_Undo_Data = new Multi_Undo_data(); |
99 |
// } |
100 |
// ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i => |
101 |
// { |
102 |
// ViewerDataModel.Instance.UndoDataList.Remove(i); |
103 |
// }); |
104 |
|
105 |
// ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
106 |
//} |
107 |
|
108 |
public void Push(ICollection<CommentUserInfo> comments) |
109 |
{ |
110 |
Undo_data UndoData = new Undo_data() |
111 |
{ |
112 |
IsUndo = false, |
113 |
Event = Event_Type.Thumb, |
114 |
EventTime = DateTime.Now, |
115 |
Markup_List = new List<Multi_Undo_data>(), |
116 |
}; |
117 |
|
118 |
Multi_Undo_data multi_Undo_Data = new Multi_Undo_data(); |
119 |
|
120 |
foreach (var comment in comments) |
121 |
{ |
122 |
multi_Undo_Data.PointSet = new List<Point>(); |
123 |
var p_set = new List<Point>(); |
124 |
|
125 |
if (comment is TextControl) |
126 |
{ |
127 |
multi_Undo_Data.PointSet.Add((comment as TextControl).StartPoint); |
128 |
multi_Undo_Data.PointSet.Add((comment as TextControl).EndPoint); |
129 |
} |
130 |
|
131 |
foreach (var point in (comment as IPath).PointSet) |
132 |
{ |
133 |
multi_Undo_Data.PointSet.Add(point); |
134 |
} |
135 |
|
136 |
|
137 |
List<Point> points = new List<Point>(); |
138 |
foreach(var point in (comment as IPath).PointSet) |
139 |
{ |
140 |
points.Add(point); |
141 |
} |
142 |
multi_Undo_Data.BeforePointSet = points; |
143 |
|
144 |
if (comment is ArrowTextControl) |
145 |
{ |
146 |
//multi_Undo_Data.Angle = dAngle = (comment as ArrowTextControl).CommentAngle; |
147 |
multi_Undo_Data.Angle = comment.CommentAngle; |
148 |
} |
149 |
else |
150 |
{ |
151 |
multi_Undo_Data.Angle = comment.CommentAngle; |
152 |
} |
153 |
|
154 |
multi_Undo_Data.Markup = comment; |
155 |
UndoData.Markup_List.Add(multi_Undo_Data); |
156 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
157 |
MarkupParser.MarkupToString(multi_Undo_Data.Markup, App.ViewInfo.UserID), Event_Type.Thumb, null, null); |
158 |
|
159 |
multi_Undo_Data = new Multi_Undo_data(); |
160 |
} |
161 |
ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == true).ToList().ForEach(i => |
162 |
{ |
163 |
ViewerDataModel.Instance.UndoDataList.Remove(i); |
164 |
}); |
165 |
|
166 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
167 |
} |
168 |
|
169 |
/// <summary> |
170 |
/// undo |
171 |
/// </summary> |
172 |
public void Execute() |
173 |
{ |
174 |
AdornerFinal final; |
175 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
176 |
|
177 |
Undo_data undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList() |
178 |
.OrderByDescending(order => order.EventTime).FirstOrDefault(); |
179 |
if (undo == null) return; |
180 |
|
181 |
switch (undo.Event) |
182 |
{ |
183 |
case (Event_Type.Create): |
184 |
{ |
185 |
foreach (var item in undo.Markup_List) |
186 |
{ |
187 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
188 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
189 |
null, Event_Type.Delete, item.Markup.CommentID, null); |
190 |
} |
191 |
} |
192 |
break; |
193 |
case (Event_Type.Delete): |
194 |
{ |
195 |
foreach (var item in undo.Markup_List) |
196 |
{ |
197 |
//var markupitem = MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID); |
198 |
|
199 |
//if (markupitem != null) |
200 |
//{ |
201 |
// IKCOM.MarkupItemEx markup = new IKCOM.MarkupItemEx |
202 |
// { |
203 |
// Data = markupitem.ConvertData, |
204 |
// Data_Type = markupitem.DATA_TYPE, |
205 |
// ID = markupitem.CommentID, |
206 |
// IsUpdate = false, |
207 |
// MarkupInfoID = App.Custom_ViewInfoId, |
208 |
// PageNumber = ViewerDataModel.Instance.PageNumber, |
209 |
// //Symbol_ID = p.Symbol_ID, |
210 |
// //Group_ID = p.Group_ID |
211 |
// }; |
212 |
|
213 |
// ViewerDataModel.Instance.MyMarkupList.Add(markup); |
214 |
//} |
215 |
|
216 |
//ViewerDataModel.Instance.MarkupControls.Add(item.Markup); |
217 |
item.Markup.Load(); |
218 |
|
219 |
ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup); |
220 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
221 |
MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
222 |
} |
223 |
} |
224 |
break; |
225 |
case (Event_Type.Thumb): |
226 |
{ |
227 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
228 |
|
229 |
foreach (var item in undo.Markup_List) |
230 |
{ |
231 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
232 |
|
233 |
if ((item.Markup as IViewBox) != null) |
234 |
{ |
235 |
(item.Markup as IViewBox).CommentAngle = item.Angle; |
236 |
} |
237 |
if ((item.Markup as TextControl) != null) |
238 |
{ |
239 |
//(item.Markup as TextControl).CommentAngle = item.Angle; |
240 |
(item.Markup as TextControl).CommentAngle = item.BeforeAngle; |
241 |
Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X); |
242 |
Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y); |
243 |
} |
244 |
else |
245 |
{ |
246 |
(item.Markup).CommentAngle = item.BeforeAngle; |
247 |
//(item.Markup as IPath).PointSet = item.PointSet; |
248 |
(item.Markup as IPath).PointSet = item.BeforePointSet != null ? item.BeforePointSet : new List<Point>(); |
249 |
(item.Markup as CommentUserInfo).UpdateControl(); |
250 |
} |
251 |
|
252 |
comment.Add(item.Markup); |
253 |
} |
254 |
final = new AdornerFinal(comment); |
255 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
256 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
257 |
} |
258 |
break; |
259 |
case (Event_Type.Select): |
260 |
{ |
261 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
262 |
|
263 |
foreach (var item in undo.Markup_List) |
264 |
{ |
265 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
266 |
|
267 |
if ((item.Markup as IPath) != null) |
268 |
{ |
269 |
(item.Markup as IPath).LineSize = item.LineSize; |
270 |
} |
271 |
if ((item.Markup as UIElement) != null) |
272 |
{ |
273 |
(item.Markup as UIElement).Opacity = item.Opacity; |
274 |
} |
275 |
if ((item.Markup as IDashControl) != null) |
276 |
{ |
277 |
(item.Markup as IDashControl).DashSize = item.DashSize; |
278 |
} |
279 |
if ((item.Markup as IShapeControl) != null) |
280 |
{ |
281 |
(item.Markup as IShapeControl).Paint = item.paint; |
282 |
} |
283 |
|
284 |
comment.Add(item.Markup); |
285 |
} |
286 |
|
287 |
final = new AdornerFinal(comment); |
288 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
289 |
} |
290 |
break; |
291 |
case (Event_Type.Option): |
292 |
{ |
293 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
294 |
|
295 |
foreach (var item in undo.Markup_List) |
296 |
{ |
297 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup); |
298 |
|
299 |
if (undo.LineSize != 0 && item.Markup as IPath != null) |
300 |
{ |
301 |
(item.Markup as IPath).LineSize = undo.LineSize; |
302 |
} |
303 |
else if (undo.Opacity != 0 && item.Markup as UIElement != null) |
304 |
{ |
305 |
(item.Markup as UIElement).Opacity = undo.Opacity; |
306 |
} |
307 |
else if (undo.DashSize != null && item.Markup as IDashControl != null) |
308 |
{ |
309 |
(item.Markup as IDashControl).DashSize = undo.DashSize; |
310 |
} |
311 |
else if (undo.Interval != 0 && item.Markup as LineControl != null) |
312 |
{ |
313 |
(item.Markup as LineControl).Interval = undo.Interval; |
314 |
} |
315 |
else if (item.Markup as IShapeControl != null) |
316 |
{ |
317 |
(item.Markup as IShapeControl).Paint = undo.paint; |
318 |
} |
319 |
comment.Add(item.Markup); |
320 |
} |
321 |
final = new AdornerFinal(comment); |
322 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
323 |
} |
324 |
break; |
325 |
} |
326 |
ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList() |
327 |
.OrderByDescending(order => order.EventTime).ToList().ForEach(i => |
328 |
{ |
329 |
i.IsUndo = true; |
330 |
}); |
331 |
} |
332 |
} |
333 |
} |