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 |
|
|
|
17 |
|
|
//강인구 추가
|
18 |
|
|
namespace MarkupToPDF.Controls.Etc
|
19 |
|
|
{
|
20 |
|
|
[TemplatePart(Name = "PART_Image", Type = typeof(Image))]
|
21 |
|
|
public class SignControl : CommentUserInfo, IDisposable, INormal, INotifyPropertyChanged, IPath, IViewBox, IMarkupCommonData
|
22 |
|
|
{
|
23 |
|
|
#region 초기선언
|
24 |
|
|
private const string PART_Image = "PART_Image";
|
25 |
|
|
public Image Base_Image = null;
|
26 |
|
|
#endregion
|
27 |
|
|
|
28 |
|
|
static SignControl()
|
29 |
|
|
{
|
30 |
|
|
DefaultStyleKeyProperty.OverrideMetadata(typeof(SignControl), new FrameworkPropertyMetadata(typeof(SignControl)));
|
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 void Dispose()
|
39 |
|
|
{
|
40 |
|
|
GC.Collect();
|
41 |
|
|
GC.SuppressFinalize(this);
|
42 |
|
|
}
|
43 |
|
|
#region Dependency Properties
|
44 |
|
|
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register(
|
45 |
|
|
"UserID", typeof(string), typeof(SignControl), new PropertyMetadata(null));
|
46 |
|
|
public static readonly DependencyProperty SignImageProperty = DependencyProperty.Register(
|
47 |
|
|
"SignImage", typeof(ImageSource), typeof(SignControl), new PropertyMetadata(null));
|
48 |
|
|
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register(
|
49 |
|
|
"StartPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
50 |
|
|
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register(
|
51 |
|
|
"EndPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
52 |
|
|
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register(
|
53 |
|
|
"PointSet", typeof(List<Point>), typeof(SignControl), new PropertyMetadata(new List<Point>()));
|
54 |
|
|
public static readonly DependencyProperty UserNubmerProperty = DependencyProperty.Register(
|
55 |
|
|
"UserNumber", typeof(string), typeof(SignControl), new PropertyMetadata(null));
|
56 |
|
|
public static readonly DependencyProperty TopRightPointProperty = DependencyProperty.Register(
|
57 |
|
|
"TopRightPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
58 |
|
|
public static readonly DependencyProperty LeftBottomPointProperty = DependencyProperty.Register(
|
59 |
|
|
"LeftBottomPoint", typeof(Point), typeof(SignControl), new PropertyMetadata(new Point(0, 0), PointValueChanged));
|
60 |
|
|
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(SignControl),
|
61 |
|
|
new PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged)));
|
62 |
|
|
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(SignControl),
|
63 |
|
|
new PropertyMetadata((double)0, OnCenterXYChanged));
|
64 |
|
|
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(SignControl),
|
65 |
|
|
new PropertyMetadata((double)0, OnCenterXYChanged));
|
66 |
|
|
public static readonly DependencyProperty IsSelectedProperty =
|
67 |
|
|
DependencyProperty.Register("IsSelected", typeof(bool), typeof(SignControl), new FrameworkPropertyMetadata(false, IsSelectedChanged));
|
68 |
|
|
|
69 |
|
|
public static readonly DependencyProperty ControlTypeProperty =
|
70 |
|
|
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(SignControl), new FrameworkPropertyMetadata(ControlType.Sign));
|
71 |
|
|
#endregion
|
72 |
|
|
#region PropertyChanged Method
|
73 |
|
|
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
74 |
|
|
{
|
75 |
|
|
var instance = (SignControl)sender;
|
76 |
|
|
if (e.OldValue != e.NewValue && instance.Base_Image != null)
|
77 |
|
|
{
|
78 |
|
|
instance.SetValue(e.Property, e.NewValue);
|
79 |
|
|
instance.SetImage();
|
80 |
|
|
}
|
81 |
|
|
}
|
82 |
|
|
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
83 |
|
|
{
|
84 |
|
|
|
85 |
|
|
}
|
86 |
|
|
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
87 |
|
|
{
|
88 |
|
|
var instance = (SignControl)sender;
|
89 |
|
|
if (e.OldValue != e.NewValue && instance.Base_Image != null)
|
90 |
|
|
{
|
91 |
|
|
instance.SetValue(e.Property, e.NewValue);
|
92 |
|
|
instance.SetImage();
|
93 |
|
|
}
|
94 |
|
|
}
|
95 |
|
|
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
|
96 |
|
|
{
|
97 |
|
|
var instance = (SignControl)sender;
|
98 |
|
|
if (e.OldValue != e.NewValue && instance.Base_Image != null)
|
99 |
|
|
{
|
100 |
|
|
instance.SetValue(e.Property, e.NewValue);
|
101 |
|
|
instance.SetImage();
|
102 |
|
|
}
|
103 |
|
|
}
|
104 |
|
|
#endregion
|
105 |
|
|
#region Properties
|
106 |
|
|
public string UserID
|
107 |
|
|
{
|
108 |
|
|
get { return (string)GetValue(UserIDProperty); }
|
109 |
|
|
set
|
110 |
|
|
{
|
111 |
|
|
if (this.UserID != value)
|
112 |
|
|
{
|
113 |
|
|
SetValue(UserIDProperty, value);
|
114 |
|
|
RaisePropertyChanged("UserID");
|
115 |
|
|
}
|
116 |
|
|
}
|
117 |
|
|
}
|
118 |
|
|
public double CenterX
|
119 |
|
|
{
|
120 |
|
|
get { return (double)GetValue(CenterXProperty); }
|
121 |
|
|
set { SetValue(CenterXProperty, value); }
|
122 |
|
|
}
|
123 |
|
|
public double CenterY
|
124 |
|
|
{
|
125 |
|
|
get { return (double)GetValue(CenterYProperty); }
|
126 |
|
|
set { SetValue(CenterYProperty, value); }
|
127 |
|
|
}
|
128 |
|
|
public Point EndPoint
|
129 |
|
|
{
|
130 |
|
|
get { return (Point)GetValue(EndPointProperty); }
|
131 |
|
|
set
|
132 |
|
|
{
|
133 |
|
|
if (this.EndPoint != value)
|
134 |
|
|
{
|
135 |
|
|
SetValue(EndPointProperty, value);
|
136 |
|
|
RaisePropertyChanged("EndPoint");
|
137 |
|
|
}
|
138 |
|
|
}
|
139 |
|
|
}
|
140 |
|
|
public List<Point> PointSet
|
141 |
|
|
{
|
142 |
|
|
get { return (List<Point>)GetValue(PointSetProperty); }
|
143 |
|
|
set { SetValue(PointSetProperty, value); }
|
144 |
|
|
}
|
145 |
|
|
public Point StartPoint
|
146 |
|
|
{
|
147 |
|
|
get { return (Point)GetValue(StartPointProperty); }
|
148 |
|
|
set
|
149 |
|
|
{
|
150 |
|
|
if (this.StartPoint != value)
|
151 |
|
|
{
|
152 |
|
|
SetValue(StartPointProperty, value);
|
153 |
|
|
RaisePropertyChanged("StartPoint");
|
154 |
|
|
}
|
155 |
|
|
}
|
156 |
|
|
}
|
157 |
|
|
public string UserNumber
|
158 |
|
|
{
|
159 |
|
|
get { return (string)GetValue(UserNubmerProperty); }
|
160 |
|
|
set
|
161 |
|
|
{
|
162 |
|
|
if (this.UserNumber != value)
|
163 |
|
|
{
|
164 |
|
|
SetValue(UserNubmerProperty, value);
|
165 |
|
|
RaisePropertyChanged("UserNumber");
|
166 |
|
|
}
|
167 |
|
|
}
|
168 |
|
|
}
|
169 |
|
|
public Point TopRightPoint
|
170 |
|
|
{
|
171 |
|
|
get { return (Point)GetValue(TopRightPointProperty); }
|
172 |
|
|
set
|
173 |
|
|
{
|
174 |
|
|
SetValue(TopRightPointProperty, value);
|
175 |
|
|
RaisePropertyChanged("TopRightPoint");
|
176 |
|
|
}
|
177 |
|
|
}
|
178 |
|
|
public Point LeftBottomPoint
|
179 |
|
|
{
|
180 |
|
|
get { return (Point)GetValue(LeftBottomPointProperty); }
|
181 |
|
|
set
|
182 |
|
|
{
|
183 |
|
|
SetValue(LeftBottomPointProperty, value);
|
184 |
|
|
RaisePropertyChanged("LeftBottomPoint");
|
185 |
|
|
}
|
186 |
|
|
}
|
187 |
|
|
public double Angle
|
188 |
|
|
{
|
189 |
|
|
get { return (double)GetValue(AngleProperty); }
|
190 |
|
|
set
|
191 |
|
|
{
|
192 |
|
|
if (this.Angle != value)
|
193 |
|
|
{
|
194 |
|
|
SetValue(AngleProperty, value);
|
195 |
|
|
}
|
196 |
|
|
}
|
197 |
|
|
}
|
198 |
|
|
public ImageSource SignImage
|
199 |
|
|
{
|
200 |
|
|
get { return (ImageSource)this.GetValue(SignImageProperty); }
|
201 |
|
|
set { this.SetValue(SignImageProperty, value); }
|
202 |
|
|
}
|
203 |
|
|
|
204 |
|
|
public bool IsSelected
|
205 |
|
|
{
|
206 |
|
|
get
|
207 |
|
|
{
|
208 |
|
|
return (bool)GetValue(IsSelectedProperty);
|
209 |
|
|
}
|
210 |
|
|
set
|
211 |
|
|
{
|
212 |
|
|
SetValue(IsSelectedProperty, value);
|
213 |
|
|
}
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
public ControlType ControlType
|
217 |
|
|
{
|
218 |
|
|
set
|
219 |
|
|
{
|
220 |
|
|
SetValue(ControlTypeProperty, value);
|
221 |
|
|
}
|
222 |
|
|
get
|
223 |
|
|
{
|
224 |
|
|
return (ControlType)GetValue(ControlTypeProperty);
|
225 |
|
|
}
|
226 |
|
|
}
|
227 |
|
|
|
228 |
|
|
#endregion
|
229 |
|
|
public override void OnApplyTemplate()
|
230 |
|
|
{
|
231 |
|
|
base.OnApplyTemplate();
|
232 |
|
|
Base_Image = GetTemplateChild(PART_Image) as Image;
|
233 |
|
|
SetImage();
|
234 |
|
|
}
|
235 |
|
|
public void SetImage()
|
236 |
|
|
{
|
237 |
|
|
this.ApplyTemplate();
|
238 |
|
|
|
239 |
|
|
Point mid = MathSet.FindCentroid(new List<Point>()
|
240 |
|
|
{
|
241 |
|
|
this.StartPoint,
|
242 |
|
|
this.LeftBottomPoint,
|
243 |
|
|
this.EndPoint,
|
244 |
|
|
this.TopRightPoint,
|
245 |
|
|
});
|
246 |
|
|
|
247 |
|
|
double AngleData = this.Angle * -1;
|
248 |
|
|
|
249 |
|
|
PathFigure pathFigure = new PathFigure();
|
250 |
|
|
pathFigure.StartPoint = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
|
251 |
|
|
|
252 |
|
|
LineSegment lineSegment0 = new LineSegment();
|
253 |
|
|
lineSegment0.Point = MathSet.RotateAbout(mid, this.StartPoint, AngleData);
|
254 |
|
|
pathFigure.Segments.Add(lineSegment0);
|
255 |
|
|
|
256 |
|
|
LineSegment lineSegment1 = new LineSegment();
|
257 |
|
|
lineSegment1.Point = MathSet.RotateAbout(mid, this.LeftBottomPoint, AngleData);
|
258 |
|
|
pathFigure.Segments.Add(lineSegment1);
|
259 |
|
|
|
260 |
|
|
LineSegment lineSegment2 = new LineSegment();
|
261 |
|
|
lineSegment2.Point = MathSet.RotateAbout(mid, this.EndPoint, AngleData);
|
262 |
|
|
pathFigure.Segments.Add(lineSegment2);
|
263 |
|
|
|
264 |
|
|
LineSegment lineSegment3 = new LineSegment();
|
265 |
|
|
lineSegment3.Point = MathSet.RotateAbout(mid, this.TopRightPoint, AngleData);
|
266 |
|
|
pathFigure.Segments.Add(lineSegment3);
|
267 |
|
|
|
268 |
|
|
PathGeometry pathGeometry = new PathGeometry();
|
269 |
|
|
pathGeometry.Figures = new PathFigureCollection();
|
270 |
|
|
pathFigure.IsClosed = true;
|
271 |
|
|
pathGeometry.Figures.Add(pathFigure);
|
272 |
|
|
this.Base_Image.Width = pathGeometry.Bounds.Width;
|
273 |
|
|
this.Base_Image.Height = pathGeometry.Bounds.Height;
|
274 |
|
|
this.Tag = pathGeometry;
|
275 |
|
|
|
276 |
|
|
Canvas.SetLeft(this, MathSet.RotateAbout(mid, mid, AngleData).X - this.Base_Image.Width / 2);
|
277 |
|
|
Canvas.SetTop(this, MathSet.RotateAbout(mid, mid, AngleData).Y - this.Base_Image.Height / 2);
|
278 |
|
|
}
|
279 |
|
|
public event PropertyChangedEventHandler PropertyChanged;
|
280 |
|
|
protected void RaisePropertyChanged(string propName)
|
281 |
|
|
{
|
282 |
|
|
if (PropertyChanged != null)
|
283 |
|
|
PropertyChanged(this, new PropertyChangedEventArgs(propName));
|
284 |
|
|
}
|
285 |
|
|
public void updateControl()
|
286 |
|
|
{
|
287 |
|
|
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y);
|
288 |
|
|
this.TopRightPoint = new Point(this.PointSet[3].X, this.PointSet[3].Y);
|
289 |
|
|
this.LeftBottomPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y);
|
290 |
|
|
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y);
|
291 |
|
|
}
|
292 |
|
|
public double LineSize
|
293 |
|
|
{
|
294 |
|
|
get;
|
295 |
|
|
set;
|
296 |
|
|
}
|
297 |
|
|
public Geometry PathData
|
298 |
|
|
{
|
299 |
|
|
get;
|
300 |
|
|
set;
|
301 |
|
|
}
|
302 |
|
|
}
|
303 |
|
|
} |