markus / MarkupToPDF / Controls / Shape / TriControl.cs @ f6cecf63
이력 | 보기 | 이력해설 | 다운로드 (16.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.ComponentModel; |
12 |
using System.Collections.Generic; |
13 |
using MarkupToPDF.Controls.Common; |
14 |
using MarkupToPDF.Common; |
15 |
using MarkupToPDF.Serialize.Core; |
16 |
using MarkupToPDF.Serialize.S_Control; |
17 |
|
18 |
namespace MarkupToPDF.Controls.Shape |
19 |
{ |
20 |
//[TemplatePart(Name = "PART_TriPath", Type = typeof(Path))] |
21 |
public class TriControl : CommentUserInfo, IDisposable, INotifyPropertyChanged, IPath, IMarkupCommonData, IShapeControl, IDashControl |
22 |
{ |
23 |
public Path Base_TriPath { get; set; } |
24 |
//public enum PaintSet { None, Fill, Hatch }; |
25 |
private const string PART_TriPath = "PART_TriPath"; |
26 |
|
27 |
//public Path Base_TriPath = null; |
28 |
|
29 |
static TriControl() |
30 |
{ |
31 |
DefaultStyleKeyProperty.OverrideMetadata(typeof(TriControl), new FrameworkPropertyMetadata(typeof(TriControl))); |
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 |
} |
36 |
|
37 |
#region Dependency Properties |
38 |
|
39 |
public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
40 |
"OverViewPathData", typeof(Geometry), typeof(TriControl), new PropertyMetadata(null)); |
41 |
|
42 |
public static readonly DependencyProperty IsSelectedProperty = |
43 |
DependencyProperty.Register("IsSelected", typeof(bool), typeof(TriControl), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
44 |
|
45 |
public static readonly DependencyProperty ControlTypeProperty = |
46 |
DependencyProperty.Register("ControlType", typeof(ControlType), typeof(TriControl), new FrameworkPropertyMetadata(ControlType.Triangle)); |
47 |
|
48 |
public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
49 |
"LineSize", typeof(double), typeof(TriControl), new PropertyMetadata((Double)3)); |
50 |
public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
51 |
"UserID", typeof(string), typeof(TriControl), new PropertyMetadata(null)); |
52 |
//강인구 추가 |
53 |
public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
54 |
"DashSize", typeof(DoubleCollection), typeof(TriControl), new PropertyMetadata(new DoubleCollection { 1, 1 }, PointValueChanged)); |
55 |
public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
56 |
"PathData", typeof(Geometry), typeof(TriControl), null); |
57 |
public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
58 |
"StrokeColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
59 |
public static readonly DependencyProperty FillColorProperty = DependencyProperty.Register( |
60 |
"FillColor", typeof(SolidColorBrush), typeof(TriControl), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
61 |
public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
62 |
"EndPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
63 |
public static readonly DependencyProperty MidPointProperty = DependencyProperty.Register( |
64 |
"MidPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
65 |
public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
66 |
"StartPoint", typeof(Point), typeof(TriControl), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
67 |
//강인구 추가 |
68 |
public static readonly DependencyProperty PaintProperty = DependencyProperty.Register( |
69 |
"Paint", typeof(PaintSet), typeof(TriControl), new PropertyMetadata(PaintSet.None, PointValueChanged)); |
70 |
|
71 |
public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
72 |
"PointSet", typeof(List<Point>), typeof(TriControl), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
73 |
public static readonly DependencyProperty AngleProperty = DependencyProperty.Register("Angle", typeof(double), typeof(TriControl), new |
74 |
PropertyMetadata((double)0.0, new PropertyChangedCallback(AngleValueChanged))); |
75 |
public static readonly DependencyProperty CenterXProperty = DependencyProperty.Register("CenterX", typeof(double), typeof(TriControl), |
76 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
77 |
|
78 |
public static readonly DependencyProperty CenterYProperty = DependencyProperty.Register("CenterY", typeof(double), typeof(TriControl), |
79 |
new PropertyMetadata((double)0, OnCenterXYChanged)); |
80 |
|
81 |
#endregion |
82 |
#region PropertyChanged Method |
83 |
|
84 |
public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
85 |
{ |
86 |
//var instance = (TriControl)sender; |
87 |
|
88 |
//if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
89 |
//{ |
90 |
|
91 |
// instance.SetValue(e.Property, e.NewValue); |
92 |
|
93 |
// if (instance.IsSelected) |
94 |
// { |
95 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue); |
96 |
// } |
97 |
// else |
98 |
// { |
99 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red); |
100 |
// } |
101 |
//} |
102 |
} |
103 |
|
104 |
public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
105 |
{ |
106 |
var instance = (TriControl)sender; |
107 |
|
108 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
109 |
{ |
110 |
instance.SetValue(e.Property, e.NewValue); |
111 |
instance.SetTri(); |
112 |
} |
113 |
} |
114 |
|
115 |
|
116 |
public static void OnCenterXYChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
117 |
{ |
118 |
var instance = (TriControl)sender; |
119 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
120 |
{ |
121 |
instance.SetValue(e.Property, e.NewValue); |
122 |
instance.SetTri(); |
123 |
} |
124 |
} |
125 |
public static void AngleValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
126 |
{ |
127 |
var instance = (TriControl)sender; |
128 |
if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
129 |
{ |
130 |
instance.SetValue(e.Property, e.NewValue); |
131 |
instance.SetTri(); |
132 |
} |
133 |
} |
134 |
#endregion |
135 |
#region Properties |
136 |
|
137 |
public Double LineSize |
138 |
{ |
139 |
get { return (Double)GetValue(LineSizeProperty); } |
140 |
set |
141 |
{ |
142 |
if (this.LineSize != value) |
143 |
{ |
144 |
SetValue(LineSizeProperty, value); |
145 |
} |
146 |
} |
147 |
} |
148 |
public string UserID |
149 |
{ |
150 |
get { return (string)GetValue(UserIDProperty); } |
151 |
set |
152 |
{ |
153 |
if (this.UserID != value) |
154 |
{ |
155 |
SetValue(UserIDProperty, value); |
156 |
OnPropertyChanged("UserID"); |
157 |
} |
158 |
} |
159 |
} |
160 |
public SolidColorBrush FillColor |
161 |
{ |
162 |
get { return (SolidColorBrush)GetValue(FillColorProperty); } |
163 |
set |
164 |
{ |
165 |
if (this.FillColor != value) |
166 |
{ |
167 |
SetValue(FillColorProperty, value); |
168 |
} |
169 |
} |
170 |
} |
171 |
public DoubleCollection DashSize |
172 |
{ |
173 |
get { return (DoubleCollection)GetValue(DashSizeProperty); } |
174 |
set |
175 |
{ |
176 |
if (this.DashSize != value) |
177 |
{ |
178 |
SetValue(DashSizeProperty, value); |
179 |
} |
180 |
} |
181 |
} |
182 |
public PaintSet Paint |
183 |
{ |
184 |
get { return (PaintSet)GetValue(PaintProperty); } |
185 |
set |
186 |
{ |
187 |
if (this.Paint != value) |
188 |
{ |
189 |
SetValue(PaintProperty, value); |
190 |
} |
191 |
} |
192 |
} |
193 |
|
194 |
|
195 |
public SolidColorBrush StrokeColor |
196 |
{ |
197 |
get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
198 |
set |
199 |
{ |
200 |
if (this.StrokeColor != value) |
201 |
{ |
202 |
SetValue(StrokeColorProperty, value); |
203 |
} |
204 |
} |
205 |
} |
206 |
public Geometry OverViewPathData |
207 |
{ |
208 |
get |
209 |
{ |
210 |
return (Geometry)GetValue(OverViewPathDataProperty); |
211 |
} |
212 |
set |
213 |
{ |
214 |
SetValue(OverViewPathDataProperty, value); |
215 |
OnPropertyChanged("OverViewPathData"); |
216 |
} |
217 |
} |
218 |
public Geometry PathData |
219 |
{ |
220 |
get { return (Geometry)GetValue(PathDataProperty); } |
221 |
set { SetValue(PathDataProperty, value); } |
222 |
} |
223 |
public Point EndPoint |
224 |
{ |
225 |
get { return (Point)GetValue(EndPointProperty); } |
226 |
set { SetValue(EndPointProperty, value); } |
227 |
} |
228 |
public Point StartPoint |
229 |
{ |
230 |
get { return (Point)GetValue(StartPointProperty); } |
231 |
set { SetValue(StartPointProperty, value); } |
232 |
} |
233 |
public Point MidPoint |
234 |
{ |
235 |
get { return (Point)GetValue(MidPointProperty); } |
236 |
set { SetValue(MidPointProperty, value); } |
237 |
} |
238 |
public List<Point> PointSet |
239 |
{ |
240 |
get { return (List<Point>)GetValue(PointSetProperty); } |
241 |
set { SetValue(PointSetProperty, value); } |
242 |
} |
243 |
|
244 |
public bool IsSelected |
245 |
{ |
246 |
get |
247 |
{ |
248 |
return (bool)GetValue(IsSelectedProperty); |
249 |
} |
250 |
set |
251 |
{ |
252 |
SetValue(IsSelectedProperty, value); |
253 |
} |
254 |
} |
255 |
|
256 |
override public ControlType ControlType |
257 |
{ |
258 |
get |
259 |
{ |
260 |
return (ControlType)GetValue(ControlTypeProperty); |
261 |
} |
262 |
set |
263 |
{ |
264 |
SetValue(ControlTypeProperty, value); |
265 |
} |
266 |
} |
267 |
|
268 |
|
269 |
public double Angle |
270 |
{ |
271 |
get { return (double)GetValue(AngleProperty); } |
272 |
set |
273 |
{ |
274 |
if (this.Angle != value) |
275 |
{ |
276 |
SetValue(AngleProperty, value); |
277 |
} |
278 |
} |
279 |
} |
280 |
public double CenterX |
281 |
{ |
282 |
get { return (double)GetValue(CenterXProperty); } |
283 |
set { SetValue(CenterXProperty, value); } |
284 |
} |
285 |
public double CenterY |
286 |
{ |
287 |
get { return (double)GetValue(CenterYProperty); } |
288 |
set { SetValue(CenterYProperty, value); } |
289 |
} |
290 |
#endregion |
291 |
|
292 |
#region Dependency PropertyChanged |
293 |
//public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
294 |
//{ |
295 |
// var instance = (TriControl)sender; |
296 |
|
297 |
// if (e.OldValue != e.NewValue && instance.Base_TriPath != null) |
298 |
// { |
299 |
|
300 |
// instance.SetValue(e.Property, e.NewValue); |
301 |
|
302 |
// if (instance.IsSelected) |
303 |
// { |
304 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Blue); |
305 |
// } |
306 |
// else |
307 |
// { |
308 |
// instance.Base_TriPath.Stroke = new SolidColorBrush(Colors.Red); |
309 |
// } |
310 |
// } |
311 |
//} |
312 |
|
313 |
#endregion Dependency PropertyChanged |
314 |
|
315 |
public override void OnApplyTemplate() |
316 |
{ |
317 |
base.OnApplyTemplate(); |
318 |
Base_TriPath = GetTemplateChild(PART_TriPath) as Path; |
319 |
|
320 |
if (Base_TriPath == null) |
321 |
{ |
322 |
return; |
323 |
} |
324 |
|
325 |
this.SetTri(); |
326 |
} |
327 |
|
328 |
public void SetTri() |
329 |
{ |
330 |
this.ApplyTemplate(); |
331 |
Base_TriPath.StrokeDashArray.Clear(); |
332 |
foreach (var item in this.DashSize) |
333 |
{ |
334 |
Base_TriPath.StrokeDashArray.Add(item); |
335 |
} |
336 |
Base_TriPath.StrokeDashCap = PenLineCap.Square; |
337 |
PathFigure pathFigure = new PathFigure(); |
338 |
|
339 |
//this.FillColor = this.StrokeColor; |
340 |
////Base_TriPath.Fill = this.FillColor; |
341 |
//Base_TriPath.Fill = Brushes.Red; |
342 |
//pathFigure.IsFilled = true; |
343 |
|
344 |
switch (this.Paint) |
345 |
{ |
346 |
case PaintSet.None: |
347 |
this.FillColor = null; |
348 |
pathFigure.IsFilled = false; |
349 |
break; |
350 |
case PaintSet.Fill: |
351 |
this.FillColor = this.StrokeColor; |
352 |
Base_TriPath.Fill = this.FillColor; |
353 |
pathFigure.IsFilled = true; |
354 |
break; |
355 |
case PaintSet.Hatch: |
356 |
Base_TriPath.Fill = HatchMake.CreateHatchBrush(this.StrokeColor); |
357 |
pathFigure.IsFilled = true; |
358 |
break; |
359 |
default: |
360 |
break; |
361 |
} |
362 |
pathFigure.StartPoint = this.StartPoint; |
363 |
|
364 |
List<Point> points = new List<Point>() { this.StartPoint }; |
365 |
if (MidPoint.X != 0 && MidPoint.Y != 0) points.Add(this.MidPoint); |
366 |
points.Add(this.EndPoint); |
367 |
|
368 |
PolyLineSegment polyline = new PolyLineSegment(points , true); |
369 |
pathFigure.Segments.Add(polyline); |
370 |
|
371 |
PathGeometry pathGeometry = new PathGeometry(); |
372 |
pathGeometry.Figures = new PathFigureCollection(); |
373 |
pathFigure.IsClosed = true; |
374 |
pathGeometry.Figures.Add(pathFigure); |
375 |
|
376 |
this.PathData = pathGeometry; |
377 |
ApplyOverViewData(); |
378 |
|
379 |
} |
380 |
public void Dispose() |
381 |
{ |
382 |
GC.Collect(); |
383 |
GC.SuppressFinalize(this); |
384 |
} |
385 |
public event PropertyChangedEventHandler PropertyChanged; |
386 |
protected void OnPropertyChanged(string propName) |
387 |
{ |
388 |
if (PropertyChanged != null) |
389 |
PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
390 |
} |
391 |
|
392 |
public void ApplyOverViewData() |
393 |
{ |
394 |
this.OverViewPathData = this.PathData; |
395 |
} |
396 |
|
397 |
public void updateControl() |
398 |
{ |
399 |
this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
400 |
this.MidPoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
401 |
this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
402 |
} |
403 |
|
404 |
/// <summary> |
405 |
/// Serialize this |
406 |
/// </summary> |
407 |
/// <param name="sUserId"></param> |
408 |
/// <returns></returns> |
409 |
public override string Serialize() |
410 |
{ |
411 |
using (S_TriControl STemp = new S_TriControl()) |
412 |
{ |
413 |
STemp.TransformPoint = "0|0"; |
414 |
STemp.Paint = this.Paint; |
415 |
STemp.SizeSet = String.Format("{0}", this.LineSize); |
416 |
//STemp.StrokeColor = "#FF00FF00"; |
417 |
STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
418 |
if (this.FillColor != null) |
419 |
{ |
420 |
STemp.FillColor = this.FillColor.Color.ToString(); |
421 |
} |
422 |
STemp.StartPoint = this.StartPoint; |
423 |
STemp.EndPoint = this.EndPoint; |
424 |
STemp.MidPoint = this.MidPoint; |
425 |
STemp.Opac = this.Opacity; |
426 |
STemp.UserID = this.UserID; |
427 |
STemp.PointSet = this.PointSet; |
428 |
STemp.Angle = this.Angle; |
429 |
STemp.DashSize = this.DashSize; |
430 |
STemp.Name = this.GetType().Name.ToString(); |
431 |
///강인구 추가(2017.11.02) |
432 |
///Memo 추가 |
433 |
STemp.Memo = this.Memo; |
434 |
|
435 |
return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
436 |
} |
437 |
} |
438 |
|
439 |
//public void ChangePaint(PaintSet state) |
440 |
//{ |
441 |
// this.Paint = state; |
442 |
// this.SetTri(); |
443 |
//} |
444 |
} |
445 |
} |