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