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