markus / MarkupToPDF / Controls / Etc / SignControl.cs @ 661b7416
이력 | 보기 | 이력해설 | 다운로드 (15.2 KB)
1 | 787a4489 | KangIngu | 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 | 036650a0 | humkyung | using MarkupToPDF.Serialize.Core; |
17 | using MarkupToPDF.Serialize.S_Control; |
||
18 | 661b7416 | humkyung | using System.Windows.Media.Imaging; |
19 | 787a4489 | KangIngu | |
20 | //강인구 추가 |
||
21 | namespace MarkupToPDF.Controls.Etc |
||
22 | { |
||
23 | [TemplatePart(Name = "PART_Image", Type = typeof(Image))] |
||
24 | public class SignControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IPath, IViewBox, IMarkupCommonData |
||
25 | { |
||
26 | #region 초기선언 |
||
27 | private const string PART_Image = "PART_Image"; |
||
28 | public Image Base_Image = null; |
||
29 | #endregion |
||
30 | |||
31 | static SignControl() |
||
32 | { |
||
33 | DefaultStyleKeyProperty.OverrideMetadata(typeof(SignControl), new FrameworkPropertyMetadata(typeof(SignControl))); |
||
34 | //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
||
35 | ResourceDictionary dictionary = new ResourceDictionary(); |
||
36 | dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
37 | Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
38 | System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
||
39 | } |
||
40 | |||
41 | public void Dispose() |
||
42 | { |
||
43 | GC.Collect(); |
||
44 | GC.SuppressFinalize(this); |
||
45 | } |
||
46 | #region Dependency Properties |
||
47 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
48 | "UserID", typeof(string), typeof(SignControl), new PropertyMetadata(null)); |
||
49 | public static readonly DependencyProperty SignImageProperty = DependencyProperty.Register( |
||
50 | "SignImage", typeof(ImageSource), typeof(SignControl), new PropertyMetadata(null)); |
||
51 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
52 | "StartPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
53 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
54 | "EndPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
55 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
56 | "PointSet", typeof(List<Point>), typeof(SignControl), new PropertyMetadata(new List<Point>())); |
||
57 | public static readonly DependencyProperty UserNubmerProperty = DependencyProperty.Register( |
||
58 | "UserNumber", typeof(string), typeof(SignControl), new PropertyMetadata(null)); |
||
59 | public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register( |
||
60 | "TopRightPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
61 | public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register( |
||
62 | "LeftBottomPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
63 | public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(SignControl), |
||
64 | new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
||
65 | public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(SignControl), |
||
66 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
67 | public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(SignControl), |
||
68 | new PropertyMetadata((double)0, OnCenterXYChanged)); |
||
69 | public static readonly DependencyProperty IsSelectedProperty = |
||
70 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(SignControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
71 | |||
72 | public static readonly DependencyProperty ControlTypeProperty = |
||
73 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(SignControl), new FrameworkPropertyMetadata(ControlType.Sign)); |
||
74 | #endregion |
||
75 | #region PropertyChanged Method |
||
76 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
77 | { |
||
78 | var instance = (SignControl)sender; |
||
79 | if (e.OldValue != e.NewValue && instance.Base_Image != null) |
||
80 | { |
||
81 | instance.SetValue(e.Property, e.NewValue); |
||
82 | instance.SetImage(); |
||
83 | } |
||
84 | } |
||
85 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
86 | { |
||
87 | |||
88 | } |
||
89 | public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
90 | { |
||
91 | var instance = (SignControl)sender; |
||
92 | if (e.OldValue != e.NewValue && instance.Base_Image != null) |
||
93 | { |
||
94 | instance.SetValue(e.Property, e.NewValue); |
||
95 | instance.SetImage(); |
||
96 | } |
||
97 | } |
||
98 | public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
99 | { |
||
100 | var instance = (SignControl)sender; |
||
101 | if (e.OldValue != e.NewValue && instance.Base_Image != null) |
||
102 | { |
||
103 | instance.SetValue(e.Property, e.NewValue); |
||
104 | instance.SetImage(); |
||
105 | } |
||
106 | } |
||
107 | #endregion |
||
108 | #region Properties |
||
109 | public string UserID |
||
110 | { |
||
111 | get { return (string)GetValue(UserIDProperty); } |
||
112 | set |
||
113 | { |
||
114 | if (this.UserID != value) |
||
115 | { |
||
116 | SetValue(UserIDProperty, value); |
||
117 | RaisePropertyChanged("UserID"); |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | public double CenterX |
||
122 | { |
||
123 | get { return (double)GetValue(CenterXProperty); } |
||
124 | set { SetValue(CenterXProperty, value); } |
||
125 | } |
||
126 | public double CenterY |
||
127 | { |
||
128 | get { return (double)GetValue(CenterYProperty); } |
||
129 | set { SetValue(CenterYProperty, value); } |
||
130 | } |
||
131 | public Point EndPoint |
||
132 | { |
||
133 | get { return (Point)GetValue(EndPointProperty); } |
||
134 | set |
||
135 | { |
||
136 | if (this.EndPoint != value) |
||
137 | { |
||
138 | SetValue(EndPointProperty, value); |
||
139 | RaisePropertyChanged("EndPoint"); |
||
140 | } |
||
141 | } |
||
142 | } |
||
143 | public List<Point> PointSet |
||
144 | { |
||
145 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
146 | set { SetValue(PointSetProperty, value); } |
||
147 | } |
||
148 | public Point StartPoint |
||
149 | { |
||
150 | get { return (Point)GetValue(StartPointProperty); } |
||
151 | set |
||
152 | { |
||
153 | if (this.StartPoint != value) |
||
154 | { |
||
155 | SetValue(StartPointProperty, value); |
||
156 | RaisePropertyChanged("StartPoint"); |
||
157 | } |
||
158 | } |
||
159 | } |
||
160 | public string UserNumber |
||
161 | { |
||
162 | get { return (string)GetValue(UserNubmerProperty); } |
||
163 | set |
||
164 | { |
||
165 | if (this.UserNumber != value) |
||
166 | { |
||
167 | SetValue(UserNubmerProperty, value); |
||
168 | RaisePropertyChanged("UserNumber"); |
||
169 | } |
||
170 | } |
||
171 | } |
||
172 | public Point TopRightPoint |
||
173 | { |
||
174 | get { return (Point)GetValue(TopRightPointProperty); } |
||
175 | set |
||
176 | { |
||
177 | SetValue(TopRightPointProperty, value); |
||
178 | RaisePropertyChanged("TopRightPoint"); |
||
179 | } |
||
180 | } |
||
181 | public Point LeftBottomPoint |
||
182 | { |
||
183 | get { return (Point)GetValue(LeftBottomPointProperty); } |
||
184 | set |
||
185 | { |
||
186 | SetValue(LeftBottomPointProperty, value); |
||
187 | RaisePropertyChanged("LeftBottomPoint"); |
||
188 | } |
||
189 | } |
||
190 | public double Angle |
||
191 | { |
||
192 | get { return (double)GetValue(AngleProperty); } |
||
193 | set |
||
194 | { |
||
195 | if (this.Angle != value) |
||
196 | { |
||
197 | SetValue(AngleProperty, value); |
||
198 | } |
||
199 | } |
||
200 | } |
||
201 | public ImageSource SignImage |
||
202 | { |
||
203 | get { return (ImageSource)this.GetValue(SignImageProperty); } |
||
204 | set { this.SetValue(SignImageProperty, value); } |
||
205 | } |
||
206 | |||
207 | public bool IsSelected |
||
208 | { |
||
209 | get |
||
210 | { |
||
211 | return (bool)GetValue(IsSelectedProperty); |
||
212 | } |
||
213 | set |
||
214 | { |
||
215 | SetValue(IsSelectedProperty, value); |
||
216 | } |
||
217 | } |
||
218 | |||
219 | 036650a0 | humkyung | override public ControlType ControlType |
220 | 787a4489 | KangIngu | { |
221 | set |
||
222 | { |
||
223 | SetValue(ControlTypeProperty, value); |
||
224 | } |
||
225 | get |
||
226 | { |
||
227 | return (ControlType)GetValue(ControlTypeProperty); |
||
228 | } |
||
229 | } |
||
230 | |||
231 | #endregion |
||
232 | public override void OnApplyTemplate() |
||
233 | { |
||
234 | base.OnApplyTemplate(); |
||
235 | Base_Image = GetTemplateChild(PART_Image) as Image; |
||
236 | SetImage(); |
||
237 | } |
||
238 | 661b7416 | humkyung | |
239 | private void SetImage() |
||
240 | 787a4489 | KangIngu | { |
241 | this.ApplyTemplate(); |
||
242 | |||
243 | Point mid = MathSet.FindCentroid(new List<Point>() |
||
244 | { |
||
245 | this.StartPoint, |
||
246 | this.LeftBottomPoint, |
||
247 | this.EndPoint, |
||
248 | this.TopRightPoint, |
||
249 | }); |
||
250 | |||
251 | double AngleData = this.Angle * -1; |
||
252 | |||
253 | PathFigure pathFigure = new PathFigure(); |
||
254 | pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
255 | |||
256 | LineSegment lineSegment0 = new LineSegment(); |
||
257 | lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData); |
||
258 | pathFigure.Segments.Add(lineSegment0); |
||
259 | |||
260 | LineSegment lineSegment1 = new LineSegment(); |
||
261 | lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData); |
||
262 | pathFigure.Segments.Add(lineSegment1); |
||
263 | |||
264 | LineSegment lineSegment2 = new LineSegment(); |
||
265 | lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData); |
||
266 | pathFigure.Segments.Add(lineSegment2); |
||
267 | |||
268 | LineSegment lineSegment3 = new LineSegment(); |
||
269 | lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData); |
||
270 | pathFigure.Segments.Add(lineSegment3); |
||
271 | |||
272 | PathGeometry pathGeometry = new PathGeometry(); |
||
273 | pathGeometry.Figures = new PathFigureCollection(); |
||
274 | pathFigure.IsClosed = true; |
||
275 | pathGeometry.Figures.Add(pathFigure); |
||
276 | this.Base_Image.Width = pathGeometry.Bounds.Width; |
||
277 | this.Base_Image.Height = pathGeometry.Bounds.Height; |
||
278 | this.Tag = pathGeometry; |
||
279 | |||
280 | Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2); |
||
281 | Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2); |
||
282 | } |
||
283 | public event PropertyChangedEventHandler PropertyChanged; |
||
284 | protected void RaisePropertyChanged(string propName) |
||
285 | { |
||
286 | if (PropertyChanged != null) |
||
287 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
||
288 | } |
||
289 | public void updateControl() |
||
290 | { |
||
291 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
292 | this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y); |
||
293 | this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
294 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
295 | } |
||
296 | 036650a0 | humkyung | |
297 | /// <summary> |
||
298 | /// Serialize this |
||
299 | /// </summary> |
||
300 | /// <param name="sUserId"></param> |
||
301 | /// <returns></returns> |
||
302 | public override string Serialize() |
||
303 | { |
||
304 | using (S_SignControl STemp = new S_SignControl()) |
||
305 | { |
||
306 | STemp.Angle = this.Angle; |
||
307 | STemp.EndPoint = this.EndPoint; |
||
308 | STemp.UserID = this.UserID; |
||
309 | STemp.LB = this.LeftBottomPoint; |
||
310 | STemp.Name = this.GetType().Name; |
||
311 | STemp.PointSet = this.PointSet; |
||
312 | STemp.StartPoint = this.StartPoint; |
||
313 | STemp.Opac = this.Opacity; |
||
314 | STemp.TR = this.TopRightPoint; |
||
315 | STemp.UserNumber = this.UserNumber == null ? this.UserID: this.UserNumber; |
||
316 | |||
317 | ///강인구 추가(2017.11.02) |
||
318 | ///Memo 추가 |
||
319 | STemp.Memo = this.Memo; |
||
320 | |||
321 | return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
||
322 | } |
||
323 | } |
||
324 | |||
325 | 661b7416 | humkyung | /// <summary> |
326 | /// create a signcontrol from given string |
||
327 | /// </summary> |
||
328 | /// <param name="str"></param> |
||
329 | /// <returns></returns> |
||
330 | public static SignControl FromString(string str, SolidColorBrush brush, string sProjectNo) |
||
331 | { |
||
332 | SignControl instance = null; |
||
333 | using (S_SignControl s = JsonSerializerHelper.JsonDeserialize<S_SignControl>(str)) |
||
334 | { |
||
335 | instance = new SignControl |
||
336 | { |
||
337 | Angle = s.Angle, |
||
338 | StartPoint = s.StartPoint, |
||
339 | TopRightPoint = s.TR, |
||
340 | EndPoint = s.EndPoint, |
||
341 | LeftBottomPoint = s.LB, |
||
342 | PointSet = s.PointSet, |
||
343 | Opacity = s.Opac, |
||
344 | SignImage = null, |
||
345 | UserID = s.UserID, |
||
346 | Memo = s.Memo |
||
347 | }; |
||
348 | |||
349 | if (s.UserNumber != null) |
||
350 | { |
||
351 | var _sign = GetUserSign.GetSign(s.UserNumber, sProjectNo); |
||
352 | if (_sign != null) |
||
353 | { |
||
354 | byte[] imageBytes = System.Convert.FromBase64String(_sign); |
||
355 | |||
356 | System.IO.MemoryStream stream = new System.IO.MemoryStream(); |
||
357 | stream.Write(imageBytes, 0, imageBytes.Length); |
||
358 | stream.Position = 0; |
||
359 | System.Drawing.Image img = System.Drawing.Image.FromStream(stream); |
||
360 | BitmapImage returnImage = new BitmapImage(); |
||
361 | returnImage.BeginInit(); |
||
362 | System.IO.MemoryStream ms = new System.IO.MemoryStream(); |
||
363 | img.Save(ms, System.Drawing.Imaging.ImageFormat.Png); |
||
364 | ms.Seek(0, System.IO.SeekOrigin.Begin); |
||
365 | returnImage.StreamSource = ms; |
||
366 | returnImage.EndInit(); |
||
367 | stream.Close(); |
||
368 | instance.SignImage = returnImage; |
||
369 | } |
||
370 | } |
||
371 | } |
||
372 | |||
373 | return instance; |
||
374 | } |
||
375 | |||
376 | public double LineSize |
||
377 | 787a4489 | KangIngu | { |
378 | get; |
||
379 | set; |
||
380 | } |
||
381 | public Geometry PathData |
||
382 | { |
||
383 | get; |
||
384 | set; |
||
385 | } |
||
386 | } |
||
387 | } |