markus / KCOM / Common / SelectionSet.cs @ 8118ba81
이력 | 보기 | 이력해설 | 다운로드 (8.51 KB)
1 | 959b3ef2 | humkyung | using KCOM.Common; |
---|---|---|---|
2 | using KCOM.Controls; |
||
3 | using KCOM.Views; |
||
4 | using MarkupToPDF.Common; |
||
5 | using MarkupToPDF.Controls.Parsing; |
||
6 | 077896be | humkyung | using MarkupToPDF.Controls.Polygon; |
7 | 959b3ef2 | humkyung | 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 | d62c0439 | humkyung | namespace KCOM.Common |
29 | 959b3ef2 | humkyung | { |
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 | 91efe37a | humkyung | |
52 | e1b36bc0 | humkyung | /// <summary> |
53 | /// 현재 선택된 아이템들을 리턴한다. |
||
54 | /// </summary> |
||
55 | d62c0439 | humkyung | 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 | e1b36bc0 | humkyung | foreach (var InnerItem in (item as Controls.AdornerFinal).Members) |
65 | d62c0439 | humkyung | { |
66 | res.Add(InnerItem.DrawingData as MarkupToPDF.Common.CommentUserInfo); |
||
67 | } |
||
68 | } |
||
69 | } |
||
70 | |||
71 | return res; |
||
72 | } |
||
73 | } |
||
74 | |||
75 | 91efe37a | humkyung | /// <summary> |
76 | e1b36bc0 | humkyung | /// 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 | selected.ForEach(x => mainMenu.Control_Style(x)); |
||
92 | |||
93 | selected.InsertRange(0, AlreadySelected); |
||
94 | return new Controls.AdornerFinal(selected); |
||
95 | } |
||
96 | |||
97 | /// <summary> |
||
98 | b37ef4b3 | humkyung | /// select all controls |
99 | /// - unselect selected items |
||
100 | /// - adornerset을 생성하고 SelectLayer에 추가한다 |
||
101 | /// </summary> |
||
102 | public void SelectAll() |
||
103 | { |
||
104 | /// 선택된 어도너가 있을 시 취소하고 전체 선택 |
||
105 | this.UnSelect(Common.ViewerDataModel.Instance.SystemMain.dzMainMenu); |
||
106 | |||
107 | List<MarkupToPDF.Common.CommentUserInfo> adornerSet = new List<MarkupToPDF.Common.CommentUserInfo>(); |
||
108 | var controls = ViewerDataModel.Instance.MarkupControls_USER.Where(data => data.GetType().Name != "" |
||
109 | && data.Visibility != Visibility.Hidden).ToList(); |
||
110 | |||
111 | foreach (var item in controls) adornerSet.Add(item); |
||
112 | |||
113 | e1b36bc0 | humkyung | if (adornerSet.Any()) |
114 | b37ef4b3 | humkyung | { |
115 | Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet); |
||
116 | Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final); |
||
117 | } |
||
118 | } |
||
119 | |||
120 | /// <summary> |
||
121 | 077896be | humkyung | /// select item which's bouding rectangle is inside of given rect |
122 | /// </summary> |
||
123 | /// <author>humkyung</author> |
||
124 | /// <date>2018.06.14</date> |
||
125 | /// <param name="rect"></param> |
||
126 | e1b36bc0 | humkyung | public Controls.AdornerFinal SelectItemByRect(Rect rect, MainMenu mainMenu, bool Clear=true) |
127 | 077896be | humkyung | { |
128 | e1b36bc0 | humkyung | Controls.AdornerFinal selection = null; |
129 | |||
130 | var selected = ViewerDataModel.Instance.MarkupControls_USER.Where(x => x.Visibility != Visibility.Hidden && rect.Contains(x.ItemRect)).ToList(); |
||
131 | 85132173 | humkyung | if (selected.Any()) |
132 | 4eb052e4 | ljiyeon | { |
133 | e1b36bc0 | humkyung | List<CommentUserInfo> AlreadySelected = !Clear ? SelectionSet.Instance.SelectedItems : new List<CommentUserInfo>(); |
134 | 077896be | humkyung | this.UnSelect(mainMenu); /// unselect alreay selected items |
135 | |||
136 | e1b36bc0 | humkyung | List<CommentUserInfo> groups = new List<CommentUserInfo>(); |
137 | foreach (var comment in selected) |
||
138 | { |
||
139 | if(!string.IsNullOrEmpty(comment.GroupID)) |
||
140 | { |
||
141 | var group = ViewerDataModel.Instance.MarkupControls_USER.Where(x => !string.IsNullOrEmpty(x.GroupID) && x.GroupID.Equals(comment.GroupID) && !selected.Contains(x)); |
||
142 | if(group.Any()) groups.AddRange(group); |
||
143 | } |
||
144 | } |
||
145 | if(groups.Any()) selected.AddRange(groups); |
||
146 | selected.ForEach(x => mainMenu.Control_Style(x)); |
||
147 | selected.InsertRange(0, AlreadySelected); |
||
148 | 077896be | humkyung | |
149 | e1b36bc0 | humkyung | selection = new Controls.AdornerFinal(selected); |
150 | mainMenu.SelectLayer.Children.Add(selection); |
||
151 | 077896be | humkyung | } |
152 | e1b36bc0 | humkyung | |
153 | return selection; |
||
154 | 077896be | humkyung | } |
155 | |||
156 | /// <summary> |
||
157 | /// unselect selected items |
||
158 | /// </summary> |
||
159 | /// <param name="mainMenu"></param> |
||
160 | public void UnSelect(MainMenu mainMenu) |
||
161 | { |
||
162 | try |
||
163 | { |
||
164 | ef7ba61f | humkyung | if (mainMenu.SelectLayer.Children.Count <= 0) return; |
165 | |||
166 | foreach (var item in mainMenu.SelectLayer.Children) |
||
167 | 077896be | humkyung | { |
168 | ef7ba61f | humkyung | if (item.GetType().Name == "AdornerFinal") |
169 | 077896be | humkyung | { |
170 | ef7ba61f | humkyung | (item as AdornerFinal).UnRegister(); |
171 | 077896be | humkyung | |
172 | ef7ba61f | humkyung | foreach (var InnerItem in (item as AdornerFinal).Members) |
173 | { |
||
174 | if (!ViewerDataModel.Instance.MarkupControls_USER.Contains(InnerItem.DrawingData)) |
||
175 | 077896be | humkyung | { |
176 | ef7ba61f | humkyung | if (InnerItem.DrawingData.GetType().Name == "PolygonControl") |
177 | 077896be | humkyung | { |
178 | ef7ba61f | humkyung | if ((InnerItem.DrawingData as PolygonControl).CommentID == null) |
179 | 077896be | humkyung | { |
180 | 5a223b60 | humkyung | (InnerItem.DrawingData as PolygonControl).CommentID = Commons.ShortGuid(); |
181 | 077896be | humkyung | } |
182 | } |
||
183 | ef7ba61f | humkyung | |
184 | var control = InnerItem.DrawingData as CommentUserInfo; |
||
185 | #region ZIndex 설정 |
||
186 | System.Windows.Controls.Canvas.SetZIndex(control, control.ZIndex); |
||
187 | #endregion |
||
188 | e1b36bc0 | humkyung | |
189 | #region User 리스트에 기존 인덱스에 맞게 추가 |
||
190 | if (control.Index >= 0 && control.Index <= ViewerDataModel.Instance.MarkupControls_USER.Count) |
||
191 | 5a223b60 | humkyung | { |
192 | ViewerDataModel.Instance.MarkupControls_USER.Insert(control.Index, control); |
||
193 | } |
||
194 | else |
||
195 | { |
||
196 | ViewerDataModel.Instance.MarkupControls_USER.Add(control); |
||
197 | } |
||
198 | e1b36bc0 | humkyung | #endregion |
199 | 077896be | humkyung | } |
200 | } |
||
201 | } |
||
202 | } |
||
203 | ef7ba61f | humkyung | mainMenu.SelectLayer.Children.Clear(); |
204 | 077896be | humkyung | } |
205 | catch (Exception ex) |
||
206 | { |
||
207 | b2d0f316 | humkyung | throw new InvalidOperationException(ex.Message); |
208 | 077896be | humkyung | } |
209 | } |
||
210 | |||
211 | /// <summary> |
||
212 | 91efe37a | humkyung | /// Control Select |
213 | /// </summary> |
||
214 | /// <author>humkyung</author> |
||
215 | /// <date>2019.06.13</date> |
||
216 | /// <param name="Control"></param> |
||
217 | /// <param name="dragrect"></param> |
||
218 | /// <returns></returns> |
||
219 | public Boolean SelectControl(CommentUserInfo control, Rect dragrect) |
||
220 | { |
||
221 | return dragrect.Contains(control.ItemRect); |
||
222 | } |
||
223 | 959b3ef2 | humkyung | } |
224 | } |