프로젝트

일반

사용자정보

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

markus / KCOM / Common / SelectionSet.cs @ 8118ba81

이력 | 보기 | 이력해설 | 다운로드 (8.51 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
            selected.ForEach(x => mainMenu.Control_Style(x));
92

    
93
            selected.InsertRange(0, AlreadySelected);
94
            return new Controls.AdornerFinal(selected);
95
        }
96

    
97
        /// <summary>
98
        /// 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
            if (adornerSet.Any())
114
            {
115
                Controls.AdornerFinal final = new Controls.AdornerFinal(adornerSet);
116
                Common.ViewerDataModel.Instance.SystemMain.dzMainMenu.SelectLayer.Children.Add(final);
117
            }
118
        }
119

    
120
        /// <summary>
121
        /// 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
        public Controls.AdornerFinal SelectItemByRect(Rect rect, MainMenu mainMenu, bool Clear=true)
127
        {
128
            Controls.AdornerFinal selection = null;
129

    
130
            var selected = ViewerDataModel.Instance.MarkupControls_USER.Where(x => x.Visibility != Visibility.Hidden && rect.Contains(x.ItemRect)).ToList();
131
            if (selected.Any())
132
             {
133
                List<CommentUserInfo> AlreadySelected = !Clear ? SelectionSet.Instance.SelectedItems : new List<CommentUserInfo>();
134
                this.UnSelect(mainMenu);  /// unselect alreay selected items
135

    
136
                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

    
149
                selection = new Controls.AdornerFinal(selected);
150
                mainMenu.SelectLayer.Children.Add(selection);
151
            }
152

    
153
            return selection;
154
        }
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
                if (mainMenu.SelectLayer.Children.Count <= 0) return;
165

    
166
                foreach (var item in mainMenu.SelectLayer.Children)
167
                {
168
                    if (item.GetType().Name == "AdornerFinal") 
169
                    {
170
                        (item as AdornerFinal).UnRegister();
171

    
172
                        foreach (var InnerItem in (item as AdornerFinal).Members)
173
                        {
174
                            if (!ViewerDataModel.Instance.MarkupControls_USER.Contains(InnerItem.DrawingData))
175
                            {
176
                                if (InnerItem.DrawingData.GetType().Name == "PolygonControl")
177
                                {
178
                                    if ((InnerItem.DrawingData as PolygonControl).CommentID == null)
179
                                    {
180
                                        (InnerItem.DrawingData as PolygonControl).CommentID = Commons.ShortGuid();
181
                                    }
182
                                }
183

    
184
                                var control = InnerItem.DrawingData as CommentUserInfo;
185
                                #region ZIndex 설정
186
                                System.Windows.Controls.Canvas.SetZIndex(control, control.ZIndex);
187
                                #endregion
188

    
189
                                #region User 리스트에 기존 인덱스에 맞게 추가
190
                                if (control.Index >= 0 && control.Index <= ViewerDataModel.Instance.MarkupControls_USER.Count)
191
                                {
192
                                    ViewerDataModel.Instance.MarkupControls_USER.Insert(control.Index, control);
193
                                }
194
                                else
195
                                {
196
                                    ViewerDataModel.Instance.MarkupControls_USER.Add(control);
197
                                }
198
                                #endregion
199
                            }
200
                        }
201
                    }
202
                }
203
                mainMenu.SelectLayer.Children.Clear();
204
            }
205
            catch (Exception ex)
206
            {
207
                throw new InvalidOperationException(ex.Message);
208
            }
209
        }
210

    
211
        /// <summary>
212
        /// 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
    }
224
}
클립보드 이미지 추가 (최대 크기: 500 MB)