markus / KCOM / Common / SelectionSet.cs @ 24da769b
이력 | 보기 | 이력해설 | 다운로드 (8.38 KB)
1 |
using KCOM.Common; |
---|---|
2 |
using KCOM.Controls; |
3 |
using KCOM.Views; |
4 |
using MarkupToPDF.Common; |
5 |
using MarkupToPDF.Controls.Parsing; |
6 |
using MarkupToPDF.Controls.Polygon; |
7 |
using Newtonsoft.Json; |
8 |
using Newtonsoft.Json.Converters; |
9 |
using Newtonsoft.Json.Linq; |
10 |
using Newtonsoft.Json.Serialization; |
11 |
using System; |
12 |
using System.Collections; |
13 |
using System.Collections.Generic; |
14 |
using System.ComponentModel; |
15 |
using System.Data; |
16 |
using System.IO; |
17 |
using System.Linq; |
18 |
using System.Reflection; |
19 |
using System.Runtime.Serialization.Formatters; |
20 |
using System.Runtime.Serialization.Formatters.Binary; |
21 |
using System.Runtime.Serialization.Json; |
22 |
using System.Text; |
23 |
using System.Windows; |
24 |
using System.Windows.Media; |
25 |
using System.Xml; |
26 |
using System.Xml.Serialization; |
27 |
|
28 |
namespace KCOM.Common |
29 |
{ |
30 |
public class SelectionSet |
31 |
{ |
32 |
private static readonly SelectionSet _instance = new SelectionSet(); |
33 |
|
34 |
// Explicit static constructor to tell C# compiler |
35 |
// not to mark type as beforefieldinit |
36 |
static SelectionSet() |
37 |
{ |
38 |
} |
39 |
|
40 |
private SelectionSet() |
41 |
{ |
42 |
} |
43 |
|
44 |
public static SelectionSet Instance |
45 |
{ |
46 |
get |
47 |
{ |
48 |
return _instance; |
49 |
} |
50 |
} |
51 |
|
52 |
/// <summary> |
53 |
/// 현재 선택된 아이템들을 리턴한다. |
54 |
/// </summary> |
55 |
public List<CommentUserInfo> SelectedItems |
56 |
{ |
57 |
get |
58 |
{ |
59 |
List<CommentUserInfo> res = new List<CommentUserInfo>(); |
60 |
foreach (var item in Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children) |
61 |
{ |
62 |
if (item.GetType().Name == "AdornerFinal") |
63 |
{ |
64 |
foreach (var InnerItem in (item as Controls.AdornerFinal).Members) |
65 |
{ |
66 |
res.Add(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo); |
67 |
} |
68 |
} |
69 |
} |
70 |
|
71 |
return res; |
72 |
} |
73 |
} |
74 |
|
75 |
/// <summary> |
76 |
/// select given item |
77 |
/// </summary> |
78 |
/// <param name="Clear">이전 SelectionSet을 제거할지 여부</param> |
79 |
/// <author>humkyung</author> |
80 |
public Controls.AdornerFinal SelectItem(CommentUserInfo comment, MainMenu mainMenu, bool Clear=true) |
81 |
{ |
82 |
List<CommentUserInfo> AlreadySelected = !Clear ? SelectionSet.Instance.SelectedItems : new List<CommentUserInfo>(); |
83 |
this.UnSelect(mainMenu); /// unselect alreay selected items |
84 |
|
85 |
List<CommentUserInfo> selected = new List<CommentUserInfo>() { comment }; |
86 |
if (!string.IsNullOrEmpty(comment.GroupID)) |
87 |
{ |
88 |
var group = ViewerDataModel.Instance.MarkupControls_USER.Where(x => !string.IsNullOrEmpty(x.GroupID) && x.GroupID.Equals(comment.GroupID) && !x.Equals(comment)); |
89 |
selected.AddRange(group); |
90 |
} |
91 |
|
92 |
selected.InsertRange(0, AlreadySelected); |
93 |
return new Controls.AdornerFinal(selected); |
94 |
} |
95 |
|
96 |
/// <summary> |
97 |
/// select all controls |
98 |
/// - unselect selected items |
99 |
/// - adornerset을 생성하고 SelectLayer에 추가한다 |
100 |
/// </summary> |
101 |
public void SelectAll() |
102 |
{ |
103 |
/// 선택된 어도너가 있을 시 취소하고 전체 선택 |
104 |
this.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
105 |
|
106 |
List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>(); |
107 |
var controls = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.GetType().Name != "" |
108 |
&& data.Visibility != Visibility.Hidden).ToList(); |
109 |
|
110 |
foreach (var item in controls) adornerSet.Add(item); |
111 |
|
112 |
if (adornerSet.Any()) |
113 |
{ |
114 |
Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
115 |
Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
116 |
} |
117 |
} |
118 |
|
119 |
/// <summary> |
120 |
/// select item which's bouding rectangle is inside of given rect |
121 |
/// </summary> |
122 |
/// <author>humkyung</author> |
123 |
/// <date>2018.06.14</date> |
124 |
/// <param name="rect"></param> |
125 |
public Controls.AdornerFinal SelectItemByRect(Rect rect, MainMenu mainMenu, bool Clear=true) |
126 |
{ |
127 |
Controls.AdornerFinal selection = null; |
128 |
|
129 |
var selected = ViewerDataModel.Instance.MarkupControls_USER.Where(x => x.Visibility != Visibility.Hidden && rect.Contains(x.ItemRect)).ToList(); |
130 |
if (selected.Any()) |
131 |
{ |
132 |
List<CommentUserInfo> AlreadySelected = !Clear ? SelectionSet.Instance.SelectedItems : new List<CommentUserInfo>(); |
133 |
this.UnSelect(mainMenu); /// unselect alreay selected items |
134 |
|
135 |
List<CommentUserInfo> groups = new List<CommentUserInfo>(); |
136 |
foreach (var comment in selected) |
137 |
{ |
138 |
if(!string.IsNullOrEmpty(comment.GroupID)) |
139 |
{ |
140 |
var group = ViewerDataModel.Instance.MarkupControls_USER.Where(x => !string.IsNullOrEmpty(x.GroupID) && x.GroupID.Equals(comment.GroupID) && !selected.Contains(x)); |
141 |
if(group.Any()) groups.AddRange(group); |
142 |
} |
143 |
} |
144 |
if(groups.Any()) selected.AddRange(groups); |
145 |
selected.InsertRange(0, AlreadySelected); |
146 |
|
147 |
selection = new Controls.AdornerFinal(selected); |
148 |
mainMenu.SelectLayer.Children.Add(selection); |
149 |
} |
150 |
|
151 |
return selection; |
152 |
} |
153 |
|
154 |
/// <summary> |
155 |
/// unselect selected items |
156 |
/// </summary> |
157 |
/// <param name="mainMenu"></param> |
158 |
public void UnSelect(MainMenu mainMenu) |
159 |
{ |
160 |
try |
161 |
{ |
162 |
if (mainMenu.SelectLayer.Children.Count <= 0) return; |
163 |
|
164 |
foreach (var item in mainMenu.SelectLayer.Children) |
165 |
{ |
166 |
if (item.GetType().Name == "AdornerFinal") |
167 |
{ |
168 |
(item as AdornerFinal).UnRegister(); |
169 |
|
170 |
foreach (var InnerItem in (item as AdornerFinal).Members) |
171 |
{ |
172 |
if (!ViewerDataModel.Instance.MarkupControls_USER.Contains(InnerItem.DrawingData)) |
173 |
{ |
174 |
if (InnerItem.DrawingData.GetType().Name == "PolygonControl") |
175 |
{ |
176 |
if ((InnerItem.DrawingData as PolygonControl).CommentID == null) |
177 |
{ |
178 |
(InnerItem.DrawingData as PolygonControl).CommentID = Commons.ShortGuid(); |
179 |
} |
180 |
} |
181 |
|
182 |
var control = InnerItem.DrawingData as CommentUserInfo; |
183 |
#region ZIndex 설정 |
184 |
System.Windows.Controls.Canvas.SetZIndex(control, control.ZIndex); |
185 |
#endregion |
186 |
|
187 |
#region User 리스트에 기존 인덱스에 맞게 추가 |
188 |
if (control.Index >= 0 && control.Index <= ViewerDataModel.Instance.MarkupControls_USER.Count) |
189 |
{ |
190 |
ViewerDataModel.Instance.MarkupControls_USER.Insert(control.Index, control); |
191 |
} |
192 |
else |
193 |
{ |
194 |
ViewerDataModel.Instance.MarkupControls_USER.Add(control); |
195 |
} |
196 |
#endregion |
197 |
} |
198 |
} |
199 |
} |
200 |
} |
201 |
mainMenu.SelectLayer.Children.Clear(); |
202 |
} |
203 |
catch (Exception ex) |
204 |
{ |
205 |
throw new InvalidOperationException(ex.Message); |
206 |
} |
207 |
} |
208 |
|
209 |
/// <summary> |
210 |
/// Control Select |
211 |
/// </summary> |
212 |
/// <author>humkyung</author> |
213 |
/// <date>2019.06.13</date> |
214 |
/// <param name="Control"></param> |
215 |
/// <param name="dragrect"></param> |
216 |
/// <returns></returns> |
217 |
public Boolean SelectControl(CommentUserInfo control, Rect dragrect) |
218 |
{ |
219 |
return dragrect.Contains(control.ItemRect); |
220 |
} |
221 |
} |
222 |
} |