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