프로젝트

일반

사용자정보

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

markus / MarkupToPDF / Controls / Etc / ImgControl.cs @ 036650a0

이력 | 보기 | 이력해설 | 다운로드 (14.3 KB)

1
using System;
2
using System.Net;
3
using System.Windows;
4
using System.Windows.Controls;
5
using System.Windows.Documents;
6
using System.Windows.Ink;
7
using System.Windows.Input;
8
using System.Windows.Media;
9
using System.Windows.Media.Animation;
10
using System.Windows.Shapes;
11
using System.Collections.Generic;
12
using System.ComponentModel;
13
using System.Linq;
14
using MarkupToPDF.Controls.Common;
15
using MarkupToPDF.Common;
16
using MarkupToPDF.Serialize.Core;
17
using MarkupToPDF.Serialize.S_Control;
18

    
19
namespace MarkupToPDF.Controls.Etc
20
{
21
    public class ImgControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IViewBox, IMarkupCommonData
22
    {
23
        #region 초기선언
24
        private const string PART_Image = "PART_Image";
25
        public Image Base_Image = null;
26
        #endregion
27

    
28
        static ImgControl()
29
        {
30
            DefaultStyleKeyProperty.OverrideMetadata(typeof(ImgControl), new FrameworkPropertyMetadata(typeof(ImgControl)));
31
            //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary);
32
            ResourceDictionary dictionary = new ResourceDictionary();
33
            dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute);
34
            Application.Current.Resources.MergedDictionaries.Add(dictionary);
35
             //System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count);
36
        }
37

    
38
        public ImgControl()
39
        {
40
            this.DefaultStyleKey = typeof(ImgControl);
41
        }
42

    
43
        public void Dispose()
44
        {
45
            GC.Collect();
46
            GC.SuppressFinalize(this);
47
        }
48
        public event PropertyChangedEventHandler PropertyChanged;
49
        protected void OnPropertyChanged(string propName)
50
        {
51
            if (PropertyChanged != null)
52
                PropertyChanged(this, new PropertyChangedEventArgs(propName));
53
        }
54

    
55
        public void ApplyOverViewData()
56
        {
57
            this.OverViewPathData = this.PathData;
58
        }
59

    
60
        #region Dependency Properties
61

    
62
        public static readonly DependencyProperty IsSelectedProperty =
63
            DependencyProperty.Register("IsSelected", typeof(bool), typeof(ImgControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
64

    
65
        public static readonly DependencyProperty ControlTypeProperty =
66
            DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ImgControl), new FrameworkPropertyMetadata(ControlType.ImgControl));
67

    
68
        public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register(
69
       "PathData", typeof(Geometry), typeof(ImgControl), null);
70
        public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register(
71
        "OverViewPathData", typeof(Geometry), typeof(ImgControl), null);
72

    
73
        public static readonly DependencyProperty ImageDataProperty = DependencyProperty.Register(
74
            "ImageData", typeof(ImageSource), typeof(ImgControl), new PropertyMetadata(null));
75
        public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
76
            "UserID", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
77
        public static readonly DependencyProperty FilePathProperty = DependencyProperty.Register(
78
            "FilePath", typeof(string), typeof(ImgControl), new PropertyMetadata(null));
79
        public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
80
            "StartPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
81
        public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
82
            "EndPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(100, 100), PointValueChanged));
83
        public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
84
            "PointSet", typeof(List<Point>), typeof(ImgControl), new PropertyMetadata(new List<Point>()));
85
        public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
86
             "TopRightPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
87
        public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
88
              "LeftBottomPoint", typeof(Point), typeof(ImgControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
89
        public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(ImgControl),
90
                        new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
91
        public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(ImgControl),
92
                        new PropertyMetadata((double)0, OnCenterXYChanged));
93
        public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(ImgControl),
94
                        new PropertyMetadata((double)0, OnCenterXYChanged));
95

    
96
        #endregion
97
        #region PropertyChanged Method
98

    
99
        public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
100
        {
101
            //var instance = (ImgControl)sender;
102

    
103
            //if (e.OldValue != e.NewValue && instance.Base_Image != null)
104
            //{
105

    
106
            //    instance.SetValue(e.Property, e.NewValue);
107

    
108
            //    if (instance.IsSelected)
109
            //    {
110
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Blue);
111
            //    }
112
            //    else
113
            //    {
114
            //        //instance.Base_Image.Stroke = new SolidColorBrush(Colors.Red);
115
            //    }
116
            //}
117
        }
118

    
119
        public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
120
        {
121
            var instance = (ImgControl)sender;
122
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
123
            {
124
                instance.SetValue(e.Property, e.NewValue);
125
                instance.SetImage();
126
            }
127
        }
128
        public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
129
        {
130
            var instance = (ImgControl)sender;
131
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
132
            {
133
                instance.SetValue(e.Property, e.NewValue);
134
                instance.SetImage();
135
            }
136
        }
137
        public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
138
        {
139
            var instance = (ImgControl)sender;
140
            if (e.OldValue != e.NewValue && instance.Base_Image != null)
141
            {
142
                instance.SetValue(e.Property, e.NewValue);
143
                instance.SetImage();
144
            }
145
        }
146
        #endregion
147
        #region Properties
148
        public double CenterX
149
        {
150
            get { return (double)GetValue(CenterXProperty); }
151
            set { SetValue(CenterXProperty, value); }
152
        }
153
        public string UserID
154
        {
155
            get { return (string)GetValue(UserIDProperty); }
156
            set
157
            {
158
                if (this.UserID != value)
159
                {
160
                    SetValue(UserIDProperty, value);
161
                    OnPropertyChanged("UserID");
162
                }
163
            }
164
        }
165
       
166
        public double CenterY
167
        {
168
            get { return (double)GetValue(CenterYProperty); }
169
            set { SetValue(CenterYProperty, value); }
170
        }
171
        public string FilePath
172
        {
173
            get { return (string)GetValue(FilePathProperty); }
174
            set { SetValue(FilePathProperty, value); }
175
        }
176
        public Point EndPoint
177
        {
178
            get { return (Point)GetValue(EndPointProperty); }
179
            set
180
            {
181
                if (this.EndPoint != value)
182
                {
183
                    SetValue(EndPointProperty, value);
184
                    OnPropertyChanged("EndPoint");
185
                }
186
            }
187
        }
188
        public List<Point> PointSet
189
        {
190
            get { return (List<Point>)GetValue(PointSetProperty); }
191
            set { SetValue(PointSetProperty, value); }
192
        }
193
        public Point StartPoint
194
        {
195
            get { return (Point)GetValue(StartPointProperty); }
196
            set
197
            {
198
                if (this.StartPoint != value)
199
                {
200
                    SetValue(StartPointProperty, value);
201
                    OnPropertyChanged("StartPoint");
202
                }
203
            }
204
        }
205
        public Point TopRightPoint
206
        {
207
            get { return (Point)GetValue(TopRightPointProperty); }
208
            set
209
            {
210
                SetValue(TopRightPointProperty, value);
211
                OnPropertyChanged("TopRightPoint");
212
            }
213
        }
214
        public Point LeftBottomPoint
215
        {
216
            get { return (Point)GetValue(LeftBottomPointProperty); }
217
            set
218
            {
219
                SetValue(LeftBottomPointProperty, value);
220
                OnPropertyChanged("LeftBottomPoint");
221
            }
222
        }
223
        public double Angle
224
        {
225
            get { return (double)GetValue(AngleProperty); }
226
            set
227
            {
228
                if (this.Angle != value)
229
                {
230
                    SetValue(AngleProperty, value);
231
                }
232
            }
233
        }
234
        public ImageSource ImageData
235
        {
236
            get { return (ImageSource)this.GetValue(ImageDataProperty); }
237
            set { this.SetValue(ImageDataProperty, value); }
238
        }
239

    
240
         public bool IsSelected
241
        {
242
            get
243
            {
244
                return (bool)GetValue(IsSelectedProperty);
245
            }
246
            set
247
            {
248
                SetValue(IsSelectedProperty, value);
249
                //OnPropertyChanged("IsSelected");
250
            }
251
        }
252

    
253
        override public ControlType ControlType
254
        {
255
            set
256
            {
257
                SetValue(ControlTypeProperty, value);
258
                OnPropertyChanged("ControlType");
259
            }
260
            get
261
            {
262
                return (ControlType)GetValue(ControlTypeProperty);
263
            }
264
        }
265

    
266
        public Geometry OverViewPathData
267
        {
268
            get { return (Geometry)GetValue(OverViewPathDataProperty); }
269
            set
270
            {
271
                SetValue(OverViewPathDataProperty, value);
272
                OnPropertyChanged("OverViewPathData");
273
            }
274
        }
275

    
276

    
277
        #endregion
278

    
279
        public override void OnApplyTemplate()
280
        {
281
            base.OnApplyTemplate();
282
            Base_Image = GetTemplateChild(PART_Image) as Image;
283
            Base_Image.Width = 0;
284
            Base_Image.Height = 0;
285
            SetImage();
286
        }
287
        public void SetImage()
288
        {
289
            this.ApplyTemplate();
290
            Point mid = MathSet.FindCentroid(new List<Point>()
291
            {
292
                this.StartPoint,
293
                this.LeftBottomPoint,
294
                this.EndPoint,
295
                this.TopRightPoint,                
296
            });
297
            double AngleData = this.Angle * -1;
298
            PathFigure pathFigure = new PathFigure();
299

    
300
            pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
301

    
302
            LineSegment lineSegment0 = new LineSegment();
303
            lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
304
            pathFigure.Segments.Add(lineSegment0);
305

    
306
            LineSegment lineSegment1 = new LineSegment();
307
            lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
308
            pathFigure.Segments.Add(lineSegment1);
309

    
310
            LineSegment lineSegment2 = new LineSegment();
311
            lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
312
            pathFigure.Segments.Add(lineSegment2);
313

    
314
            LineSegment lineSegment3 = new LineSegment();
315
            lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
316
            pathFigure.Segments.Add(lineSegment3);
317

    
318
            PathGeometry pathGeometry = new PathGeometry();
319
            pathGeometry.Figures = new PathFigureCollection();
320
            pathFigure.IsClosed = true;
321
            pathGeometry.Figures.Add(pathFigure);
322
            this.Base_Image.Width = pathGeometry.Bounds.Width;
323
            this.Base_Image.Height = pathGeometry.Bounds.Height;
324
             this.Tag = pathGeometry;
325

    
326
            Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2);
327
            Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2);
328

    
329
            this.PathData = pathGeometry;
330
            ApplyOverViewData();
331

    
332
        }
333
        public void updateControl()
334
        {
335
            this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
336
            this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
337
            this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
338
            this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
339
        }
340

    
341
        public double LineSize { get; set; }
342

    
343
        public Geometry PathData { get; set; }
344

    
345
        /// <summary>
346
        /// Serialize this
347
        /// </summary>
348
        /// <param name="sUserId"></param>
349
        /// <returns></returns>
350
        public override string Serialize()
351
        {
352
            using (S_ImgControl STemp = new S_ImgControl())
353
            {
354
                STemp.Angle = this.Angle;
355
                STemp.EndPoint = this.EndPoint;
356
                STemp.LB = this.LeftBottomPoint;
357
                STemp.Name = this.GetType().Name;
358
                STemp.PointSet = this.PointSet;
359
                STemp.StartPoint = this.StartPoint;
360
                STemp.UserID = this.UserID;
361
                STemp.Opac = this.Opacity;
362
                STemp.TR = this.TopRightPoint;
363
                STemp.ImagePath = this.FilePath;
364
                ///강인구 추가(2017.11.02)
365
                ///Memo 추가
366
                STemp.Memo = this.Memo;
367

    
368
                return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize()));
369
            }
370
        }
371
    }
372
}
클립보드 이미지 추가 (최대 크기: 500 MB)