markus / KCOM / Events / UndoCommand.cs @ fd452a01
이력 | 보기 | 이력해설 | 다운로드 (11.5 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 |
/// <summary> |
109 |
/// undo |
110 |
/// </summary> |
111 |
public void Execute() |
112 |
{ |
113 |
AdornerFinal final; |
114 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
115 |
|
116 |
Undo_data undo = ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo == false).ToList() |
117 |
.OrderByDescending(order => order.EventTime).FirstOrDefault(); |
118 |
if (undo == null) return; |
119 |
|
120 |
switch (undo.Event) |
121 |
{ |
122 |
case (Event_Type.Create): |
123 |
{ |
124 |
foreach (var item in undo.Markup_List) |
125 |
{ |
126 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
127 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
128 |
null, Event_Type.Delete, item.Markup.CommentID, null); |
129 |
} |
130 |
} |
131 |
break; |
132 |
case (Event_Type.Delete): |
133 |
{ |
134 |
foreach (var item in undo.Markup_List) |
135 |
{ |
136 |
//var markupitem = MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID); |
137 |
|
138 |
//if (markupitem != null) |
139 |
//{ |
140 |
// IKCOM.MarkupItemEx markup = new IKCOM.MarkupItemEx |
141 |
// { |
142 |
// Data = markupitem.ConvertData, |
143 |
// Data_Type = markupitem.DATA_TYPE, |
144 |
// ID = markupitem.CommentID, |
145 |
// IsUpdate = false, |
146 |
// MarkupInfoID = App.Custom_ViewInfoId, |
147 |
// PageNumber = ViewerDataModel.Instance.PageNumber, |
148 |
// //Symbol_ID = p.Symbol_ID, |
149 |
// //Group_ID = p.Group_ID |
150 |
// }; |
151 |
|
152 |
// ViewerDataModel.Instance.MyMarkupList.Add(markup); |
153 |
//} |
154 |
|
155 |
//ViewerDataModel.Instance.MarkupControls.Add(item.Markup); |
156 |
item.Markup.Load(); |
157 |
|
158 |
ViewerDataModel.Instance.MarkupControls_USER.Add(item.Markup); |
159 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
160 |
MarkupParser.MarkupToString(item.Markup, App.ViewInfo.UserID), Event_Type.Create, null, null); |
161 |
} |
162 |
} |
163 |
break; |
164 |
case (Event_Type.Thumb): |
165 |
{ |
166 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
167 |
|
168 |
foreach (var item in undo.Markup_List) |
169 |
{ |
170 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
171 |
|
172 |
if ((item.Markup as IViewBox) != null) |
173 |
{ |
174 |
(item.Markup as IViewBox).CommentAngle = item.Angle; |
175 |
} |
176 |
if ((item.Markup as TextControl) != null) |
177 |
{ |
178 |
//(item.Markup as TextControl).CommentAngle = item.Angle; |
179 |
(item.Markup as TextControl).CommentAngle = item.BeforeAngle; |
180 |
Canvas.SetLeft((item.Markup as TextControl), item.PointSet[0].X); |
181 |
Canvas.SetTop((item.Markup as TextControl), item.PointSet[0].Y); |
182 |
} |
183 |
else |
184 |
{ |
185 |
(item.Markup).CommentAngle = item.BeforeAngle; |
186 |
//(item.Markup as IPath).PointSet = item.PointSet; |
187 |
(item.Markup as IPath).PointSet = item.BeforePointSet != null ? item.BeforePointSet : new List<Point>(); |
188 |
(item.Markup as CommentUserInfo).UpdateControl(); |
189 |
} |
190 |
|
191 |
comment.Add(item.Markup); |
192 |
} |
193 |
final = new AdornerFinal(comment); |
194 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
195 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
196 |
} |
197 |
break; |
198 |
case (Event_Type.Select): |
199 |
{ |
200 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
201 |
|
202 |
foreach (var item in undo.Markup_List) |
203 |
{ |
204 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
205 |
|
206 |
if ((item.Markup as IPath) != null) |
207 |
{ |
208 |
(item.Markup as IPath).LineSize = item.LineSize; |
209 |
} |
210 |
if ((item.Markup as UIElement) != null) |
211 |
{ |
212 |
(item.Markup as UIElement).Opacity = item.Opacity; |
213 |
} |
214 |
if ((item.Markup as IDashControl) != null) |
215 |
{ |
216 |
(item.Markup as IDashControl).DashSize = item.DashSize; |
217 |
} |
218 |
if ((item.Markup as IShapeControl) != null) |
219 |
{ |
220 |
(item.Markup as IShapeControl).Paint = item.paint; |
221 |
} |
222 |
|
223 |
comment.Add(item.Markup); |
224 |
} |
225 |
|
226 |
final = new AdornerFinal(comment); |
227 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
228 |
} |
229 |
break; |
230 |
case (Event_Type.Option): |
231 |
{ |
232 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
233 |
|
234 |
foreach (var item in undo.Markup_List) |
235 |
{ |
236 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup); |
237 |
|
238 |
if (undo.LineSize != 0 && item.Markup as IPath != null) |
239 |
{ |
240 |
(item.Markup as IPath).LineSize = undo.LineSize; |
241 |
} |
242 |
else if (undo.Opacity != 0 && item.Markup as UIElement != null) |
243 |
{ |
244 |
(item.Markup as UIElement).Opacity = undo.Opacity; |
245 |
} |
246 |
else if (undo.DashSize != null && item.Markup as IDashControl != null) |
247 |
{ |
248 |
(item.Markup as IDashControl).DashSize = undo.DashSize; |
249 |
} |
250 |
else if (undo.Interval != 0 && item.Markup as LineControl != null) |
251 |
{ |
252 |
(item.Markup as LineControl).Interval = undo.Interval; |
253 |
} |
254 |
else if (item.Markup as IShapeControl != null) |
255 |
{ |
256 |
(item.Markup as IShapeControl).Paint = undo.paint; |
257 |
} |
258 |
comment.Add(item.Markup); |
259 |
} |
260 |
final = new AdornerFinal(comment); |
261 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
262 |
} |
263 |
break; |
264 |
} |
265 |
ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList() |
266 |
.OrderByDescending(order => order.EventTime).ToList().ForEach(i => |
267 |
{ |
268 |
i.IsUndo = true; |
269 |
}); |
270 |
} |
271 |
} |
272 |
} |