프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

markus / KCOM / Common / SelectionSet.cs @ 24da769b

이력 | 보기 | 이력해설 | 다운로드 (8.38 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
92
            selected.InsertRange(0, AlreadySelected);
93
            return new Controls.AdornerFinal(selected);
94
        }
95
96
        /// <summary>
97 b37ef4b3 humkyung
        /// 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 e1b36bc0 humkyung
            if (adornerSet.Any())
113 b37ef4b3 humkyung
            {
114
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
115
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
116
            }
117
        }
118
119
        /// <summary>
120 077896be humkyung
        /// 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 e1b36bc0 humkyung
        public Controls.AdornerFinal SelectItemByRect(Rect rect, MainMenu mainMenu, bool Clear=true)
126 077896be humkyung
        {
127 e1b36bc0 humkyung
            Controls.AdornerFinal selection = null;
128
129
            var selected = ViewerDataModel.Instance.MarkupControls_USER.Where(x => x.Visibility != Visibility.Hidden && rect.Contains(x.ItemRect)).ToList();
130 85132173 humkyung
            if (selected.Any())
131 4eb052e4 ljiyeon
             {
132 e1b36bc0 humkyung
                List<CommentUserInfo> AlreadySelected = !Clear ? SelectionSet.Instance.SelectedItems : new List<CommentUserInfo>();
133 077896be humkyung
                this.UnSelect(mainMenu);  /// unselect alreay selected items
134
135 e1b36bc0 humkyung
                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 077896be humkyung
147 e1b36bc0 humkyung
                selection = new Controls.AdornerFinal(selected);
148
                mainMenu.SelectLayer.Children.Add(selection);
149 077896be humkyung
            }
150 e1b36bc0 humkyung
151
            return selection;
152 077896be humkyung
        }
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 ef7ba61f humkyung
                if (mainMenu.SelectLayer.Children.Count <= 0) return;
163
164
                foreach (var item in mainMenu.SelectLayer.Children)
165 077896be humkyung
                {
166 ef7ba61f humkyung
                    if (item.GetType().Name == "AdornerFinal") 
167 077896be humkyung
                    {
168 ef7ba61f humkyung
                        (item as AdornerFinal).UnRegister();
169 077896be humkyung
170 ef7ba61f humkyung
                        foreach (var InnerItem in (item as AdornerFinal).Members)
171
                        {
172
                            if (!ViewerDataModel.Instance.MarkupControls_USER.Contains(InnerItem.DrawingData))
173 077896be humkyung
                            {
174 ef7ba61f humkyung
                                if (InnerItem.DrawingData.GetType().Name == "PolygonControl")
175 077896be humkyung
                                {
176 ef7ba61f humkyung
                                    if ((InnerItem.DrawingData as PolygonControl).CommentID == null)
177 077896be humkyung
                                    {
178 5a223b60 humkyung
                                        (InnerItem.DrawingData as PolygonControl).CommentID = Commons.ShortGuid();
179 077896be humkyung
                                    }
180
                                }
181 ef7ba61f humkyung
182
                                var control = InnerItem.DrawingData as CommentUserInfo;
183
                                #region ZIndex 설정
184
                                System.Windows.Controls.Canvas.SetZIndex(control, control.ZIndex);
185
                                #endregion
186 e1b36bc0 humkyung
187
                                #region User 리스트에 기존 인덱스에 맞게 추가
188
                                if (control.Index >= 0 && control.Index <= ViewerDataModel.Instance.MarkupControls_USER.Count)
189 5a223b60 humkyung
                                {
190
                                    ViewerDataModel.Instance.MarkupControls_USER.Insert(control.Index, control);
191
                                }
192
                                else
193
                                {
194
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(control);
195
                                }
196 e1b36bc0 humkyung
                                #endregion
197 077896be humkyung
                            }
198
                        }
199
                    }
200
                }
201 ef7ba61f humkyung
                mainMenu.SelectLayer.Children.Clear();
202 077896be humkyung
            }
203
            catch (Exception ex)
204
            {
205 b2d0f316 humkyung
                throw new InvalidOperationException(ex.Message);
206 077896be humkyung
            }
207
        }
208
209
        /// <summary>
210 91efe37a humkyung
        /// 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 959b3ef2 humkyung
    }
222
}
클립보드 이미지 추가 (최대 크기: 500 MB)