markus / KCOM / Events / UndoCommand.cs @ 299f2c11
이력 | 보기 | 이력해설 | 다운로드 (5.99 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, 2024.04.26</date> |
49 |
/// <param name="comments"></param> |
50 |
public void Push(EventType _EventType, ICollection<CommentUserInfo> comments) |
51 |
{ |
52 |
UndoDataGroup UndoData = new UndoDataGroup() |
53 |
{ |
54 |
IsUndo = false, |
55 |
Event = _EventType, |
56 |
EventTime = DateTime.Now, |
57 |
MarkupDataColl = new List<UndoData>(), |
58 |
}; |
59 |
|
60 |
foreach (var comment in comments) |
61 |
{ |
62 |
UndoData _UndoData = new UndoData() |
63 |
{ |
64 |
Markup = comment |
65 |
}; |
66 |
_UndoData.Clone = comment.Clone(); |
67 |
UndoData.MarkupDataColl.Add(_UndoData); |
68 |
|
69 |
if (_EventType == EventType.Delete) |
70 |
{ |
71 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(comment); |
72 |
ViewerDataModel.Instance.MarkupControls.Remove(comment); |
73 |
|
74 |
var Item_ = ViewerDataModel.Instance.MyMarkupList.Find(d => d.ID == comment.CommentID); |
75 |
ViewerDataModel.Instance.MyMarkupList.Remove(Item_); |
76 |
|
77 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
78 |
null, EventType.Delete, MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID).CommentID, null); |
79 |
} |
80 |
else |
81 |
{ |
82 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
83 |
MarkupParser.MarkupToString(_UndoData.Markup, App.ViewInfo.UserID), EventType.Operation, null, null); |
84 |
} |
85 |
} |
86 |
|
87 |
ViewerDataModel.Instance.UndoDataList.Where(data => data.IsUndo).ToList().ForEach(i => |
88 |
{ |
89 |
ViewerDataModel.Instance.UndoDataList.Remove(i); |
90 |
}); |
91 |
ViewerDataModel.Instance.UndoDataList.Add(UndoData); |
92 |
} |
93 |
|
94 |
/// <summary> |
95 |
/// undo 실행 |
96 |
/// </summary> |
97 |
public void Execute() |
98 |
{ |
99 |
AdornerFinal final; |
100 |
SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
101 |
|
102 |
UndoDataGroup undo = ViewerDataModel.Instance.UndoDataList.Where(data => !data.IsUndo).ToList() |
103 |
.OrderByDescending(order => order.EventTime).FirstOrDefault(); |
104 |
if (undo == null) return; |
105 |
|
106 |
switch (undo.Event) |
107 |
{ |
108 |
case (EventType.Create): |
109 |
{ |
110 |
foreach (var item in undo.MarkupDataColl) |
111 |
{ |
112 |
ViewerDataModel.Instance.MarkupControls_USER.Remove((item.Markup)); |
113 |
|
114 |
ViewerDataModel.Instance.SystemMain.dzMainMenu.pageNavigator.MarkupListUpdate( |
115 |
null, EventType.Delete, item.Markup.CommentID, null); |
116 |
} |
117 |
} |
118 |
break; |
119 |
case (EventType.Delete): |
120 |
{ |
121 |
List<CommentUserInfo> comments = new List<CommentUserInfo>(); |
122 |
foreach (var item in undo.MarkupDataColl) |
123 |
{ |
124 |
item.Markup.Load(); |
125 |
item.Markup.UpdateControl(); |
126 |
comments.Add(item.Markup); |
127 |
} |
128 |
|
129 |
var adorner = new AdornerFinal(comments); |
130 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adorner); |
131 |
///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
132 |
} |
133 |
break; |
134 |
case (EventType.Operation): |
135 |
{ |
136 |
List<CommentUserInfo> comment = new List<CommentUserInfo>(); |
137 |
|
138 |
foreach (var item in undo.MarkupDataColl) |
139 |
{ |
140 |
ViewerDataModel.Instance.MarkupControls_USER.Remove(item.Markup); |
141 |
|
142 |
var tmp = item.Markup.Clone(); |
143 |
item.Markup.Copy(item.Clone); |
144 |
item.Clone.Copy(tmp); |
145 |
item.Markup.UpdateControl(); |
146 |
|
147 |
comment.Add(item.Markup); |
148 |
} |
149 |
var adoner = new AdornerFinal(comment); |
150 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(adoner); |
151 |
///SelectionSet.Instance.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
152 |
} |
153 |
break; |
154 |
} |
155 |
|
156 |
ViewerDataModel.Instance.UndoDataList.Where(data => data.EventTime == undo.EventTime).ToList() |
157 |
.OrderByDescending(order => order.EventTime).ToList().ForEach(i => |
158 |
{ |
159 |
i.IsUndo = true; |
160 |
}); |
161 |
} |
162 |
} |
163 |
} |