markus / MarkupToPDF / Controls / Line / ArrowControl_Multi.cs @ a5b465dc
이력 | 보기 | 이력해설 | 다운로드 (16.5 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 | 036650a0 | humkyung | using MarkupToPDF.Serialize.S_Control; |
16 | using MarkupToPDF.Serialize.Core; |
||
17 | 661b7416 | humkyung | using System.Linq; |
18 | 787a4489 | KangIngu | |
19 | namespace MarkupToPDF.Controls.Line |
||
20 | { |
||
21 | |||
22 | public class ArrowControl_Multi : CommentUserInfo, IDisposable, INotifyPropertyChanged, IMarkupCommonData, IDashControl |
||
23 | { |
||
24 | |||
25 | public event PropertyChangedEventHandler PropertyChanged; |
||
26 | private const string PART_ArrowMultiPath = "PART_ArrowMultiPath"; |
||
27 | public Path Base_ArrowMultiPath = null; |
||
28 | |||
29 | static ArrowControl_Multi() |
||
30 | { |
||
31 | DefaultStyleKeyProperty.OverrideMetadata(typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(typeof(ArrowControl_Multi))); |
||
32 | //Application.Current.Resources.MergedDictionaries.Add(Application.LoadComponent(new Uri("/MarkupToPDF;Component/Themes/generic.xaml")) as ResourceDictionary); |
||
33 | ResourceDictionary dictionary = new ResourceDictionary(); |
||
34 | dictionary.Source = new Uri("/MarkupToPDF;component/themes/generic.xaml", UriKind.RelativeOrAbsolute); |
||
35 | Application.Current.Resources.MergedDictionaries.Add(dictionary); |
||
36 | System.Diagnostics.Debug.WriteLine("resource Count :" + Application.Current.Resources.MergedDictionaries.Count); |
||
37 | } |
||
38 | |||
39 | public ArrowControl_Multi() |
||
40 | { |
||
41 | this.DefaultStyleKey = typeof(ArrowControl_Multi); |
||
42 | } |
||
43 | |||
44 | #region Dependency Properties |
||
45 | |||
46 | public static readonly DependencyProperty IsSelectedProperty = |
||
47 | DependencyProperty.Register("IsSelected", typeof(bool), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(false, IsSelectedChanged)); |
||
48 | |||
49 | public static readonly DependencyProperty ControlTypeProperty = |
||
50 | DependencyProperty.Register("ControlType", typeof(ControlType), typeof(ArrowControl_Multi), new FrameworkPropertyMetadata(ControlType.ArrowMultiLine)); |
||
51 | |||
52 | public static readonly DependencyProperty OverViewPathDataProperty = DependencyProperty.Register( |
||
53 | "OverViewPathData", typeof(Geometry), typeof(ArrowControl_Multi), new PropertyMetadata(null)); |
||
54 | |||
55 | public static readonly DependencyProperty UserIDProperty = DependencyProperty.Register( |
||
56 | "UserID", typeof(string), typeof(ArrowControl_Multi), new PropertyMetadata(null)); |
||
57 | |||
58 | public static readonly DependencyProperty LineSizeProperty = DependencyProperty.Register( |
||
59 | b3fb7321 | ljiyeon | "LineSize", typeof(double), typeof(ArrowControl_Multi), new PropertyMetadata((Double)3, PointValueChanged)); |
60 | 787a4489 | KangIngu | |
61 | public static readonly DependencyProperty DashSizeProperty = DependencyProperty.Register( |
||
62 | "DashSize", typeof(DoubleCollection), typeof(ArrowControl_Multi), new PropertyMetadata(new DoubleCollection { 99999099 }, PointValueChanged)); |
||
63 | |||
64 | public static readonly DependencyProperty StrokeColorProperty = DependencyProperty.Register( |
||
65 | "StrokeColor", typeof(SolidColorBrush), typeof(ArrowControl_Multi), new PropertyMetadata(new SolidColorBrush(Colors.Red))); |
||
66 | |||
67 | public static readonly DependencyProperty PathDataProperty = DependencyProperty.Register( |
||
68 | "PathData", typeof(Geometry), typeof(ArrowControl_Multi), null); |
||
69 | |||
70 | public static readonly DependencyProperty StartPointProperty = DependencyProperty.Register( |
||
71 | "StartPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
72 | |||
73 | public static readonly DependencyProperty EndPointProperty = DependencyProperty.Register( |
||
74 | "EndPoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(100, 100), PointValueChanged)); |
||
75 | public static readonly DependencyProperty MiddlePointProperty = DependencyProperty.Register( |
||
76 | "MiddlePoint", typeof(Point), typeof(ArrowControl_Multi), new PropertyMetadata(new Point(0, 0), PointValueChanged)); |
||
77 | |||
78 | public static readonly DependencyProperty PointSetProperty = DependencyProperty.Register( |
||
79 | "PointSet", typeof(List<Point>), typeof(ArrowControl_Multi), new PropertyMetadata(new List<Point>(), PointValueChanged)); |
||
80 | #endregion |
||
81 | #region PropertyChanged Method |
||
82 | |||
83 | public static void IsSelectedChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
84 | { |
||
85 | //var instance = (ArrowControl_Multi)sender; |
||
86 | |||
87 | //if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null) |
||
88 | //{ |
||
89 | |||
90 | // instance.SetValue(e.Property, e.NewValue); |
||
91 | |||
92 | // if (instance.IsSelected) |
||
93 | // { |
||
94 | // instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue); |
||
95 | // } |
||
96 | // else |
||
97 | // { |
||
98 | // instance.Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red); |
||
99 | // } |
||
100 | //} |
||
101 | } |
||
102 | |||
103 | |||
104 | public static void PointValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) |
||
105 | { |
||
106 | var instance = (ArrowControl_Multi)sender; |
||
107 | if (e.OldValue != e.NewValue && instance.Base_ArrowMultiPath != null) |
||
108 | { |
||
109 | instance.SetValue(e.Property, e.NewValue); |
||
110 | instance.SetArrowMultiPath(); |
||
111 | } |
||
112 | } |
||
113 | #endregion |
||
114 | #region Properties |
||
115 | public string UserID |
||
116 | { |
||
117 | get { return (string)GetValue(UserIDProperty); } |
||
118 | set |
||
119 | { |
||
120 | if (this.UserID != value) |
||
121 | { |
||
122 | SetValue(UserIDProperty, value); |
||
123 | OnPropertyChanged("UserID"); |
||
124 | } |
||
125 | } |
||
126 | } |
||
127 | public Double LineSize |
||
128 | { |
||
129 | get { return (Double)GetValue(LineSizeProperty); } |
||
130 | set |
||
131 | { |
||
132 | if (this.LineSize != value) |
||
133 | { |
||
134 | SetValue(LineSizeProperty, value); |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | public Geometry OverViewPathData |
||
140 | { |
||
141 | get |
||
142 | { |
||
143 | return (Geometry)GetValue(OverViewPathDataProperty); |
||
144 | } |
||
145 | set |
||
146 | { |
||
147 | SetValue(OverViewPathDataProperty, value); |
||
148 | OnPropertyChanged("OverViewPathData"); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | 959b3ef2 | humkyung | public override bool IsSelected |
153 | 787a4489 | KangIngu | { |
154 | get |
||
155 | { |
||
156 | return (bool)GetValue(IsSelectedProperty); |
||
157 | } |
||
158 | set |
||
159 | { |
||
160 | SetValue(IsSelectedProperty, value); |
||
161 | } |
||
162 | } |
||
163 | |||
164 | 5529d2a2 | humkyung | public override ControlType ControlType |
165 | 787a4489 | KangIngu | { |
166 | get |
||
167 | { |
||
168 | return (ControlType)GetValue(ControlTypeProperty); |
||
169 | } |
||
170 | set |
||
171 | { |
||
172 | SetValue(ControlTypeProperty, value); |
||
173 | } |
||
174 | } |
||
175 | |||
176 | |||
177 | public DoubleCollection DashSize |
||
178 | { |
||
179 | get { return (DoubleCollection)GetValue(DashSizeProperty); } |
||
180 | set |
||
181 | { |
||
182 | if (this.DashSize != value) |
||
183 | { |
||
184 | SetValue(DashSizeProperty, value); |
||
185 | } |
||
186 | } |
||
187 | } |
||
188 | public List<Point> PointSet |
||
189 | { |
||
190 | get { return (List<Point>)GetValue(PointSetProperty); } |
||
191 | set { SetValue(PointSetProperty, value); } |
||
192 | } |
||
193 | public SolidColorBrush StrokeColor |
||
194 | { |
||
195 | get { return (SolidColorBrush)GetValue(StrokeColorProperty); } |
||
196 | set |
||
197 | { |
||
198 | if (this.StrokeColor != value) |
||
199 | { |
||
200 | SetValue(StrokeColorProperty, value); |
||
201 | } |
||
202 | } |
||
203 | } |
||
204 | public Geometry PathData |
||
205 | { |
||
206 | get { return (Geometry)GetValue(PathDataProperty); } |
||
207 | set { SetValue(PathDataProperty, value); } |
||
208 | } |
||
209 | public Point EndPoint |
||
210 | { |
||
211 | get { return (Point)GetValue(EndPointProperty); } |
||
212 | set { SetValue(EndPointProperty, value); } |
||
213 | } |
||
214 | public Point StartPoint |
||
215 | { |
||
216 | get { return (Point)GetValue(StartPointProperty); } |
||
217 | set { SetValue(StartPointProperty, value); } |
||
218 | } |
||
219 | public Point MiddlePoint |
||
220 | { |
||
221 | get { return (Point)GetValue(MiddlePointProperty); } |
||
222 | set |
||
223 | { |
||
224 | SetValue(MiddlePointProperty, value); |
||
225 | OnPropertyChanged("MiddlePoint"); |
||
226 | } |
||
227 | } |
||
228 | #endregion |
||
229 | #region Object & Variable |
||
230 | GeometryGroup instanceGroup = new GeometryGroup(); |
||
231 | #endregion |
||
232 | public override void OnApplyTemplate() |
||
233 | { |
||
234 | base.OnApplyTemplate(); |
||
235 | Base_ArrowMultiPath = GetTemplateChild(PART_ArrowMultiPath) as Path; |
||
236 | SetArrowMultiPath(); |
||
237 | } |
||
238 | |||
239 | public void ApplyOverViewData() |
||
240 | { |
||
241 | this.OverViewPathData = this.PathData; |
||
242 | } |
||
243 | |||
244 | public void SetArrowMultiPath() |
||
245 | { |
||
246 | |||
247 | |||
248 | Base_ArrowMultiPath.StrokeDashArray.Clear(); |
||
249 | foreach (var item in this.DashSize) |
||
250 | { |
||
251 | Base_ArrowMultiPath.StrokeDashArray.Add(item); |
||
252 | } |
||
253 | Base_ArrowMultiPath.StrokeDashCap = PenLineCap.Square; |
||
254 | instanceGroup.Children.Clear(); |
||
255 | PathFigure pathFigure = new PathFigure(); |
||
256 | |||
257 | pathFigure.StartPoint = this.StartPoint; |
||
258 | LineSegment lineSegment0 = new LineSegment(); |
||
259 | lineSegment0.Point = this.StartPoint; |
||
260 | pathFigure.Segments.Add(lineSegment0); |
||
261 | |||
262 | |||
263 | |||
264 | //if (this.EndPoint == this.MiddlePoint) |
||
265 | if (this.MiddlePoint == new Point(0,0)) |
||
266 | { |
||
267 | //instanceGroup.Children.Add(SingleAllow(this.StartPoint, this.MiddlePoint, this.LineSize)); |
||
268 | d251456f | humkyung | instanceGroup.Children.Add(DrawSet.DrawArrow(this.StartPoint, this.EndPoint, this.LineSize)); |
269 | 787a4489 | KangIngu | } |
270 | else |
||
271 | { |
||
272 | d251456f | humkyung | instanceGroup.Children.Add(DrawSet.DrawArrow(this.MiddlePoint, this.EndPoint, this.LineSize)); |
273 | 787a4489 | KangIngu | LineSegment lineSegment1 = new LineSegment(); |
274 | lineSegment1.Point = this.MiddlePoint; |
||
275 | pathFigure.Segments.Add(lineSegment1); |
||
276 | } |
||
277 | |||
278 | LineSegment lineSegment2 = new LineSegment(); |
||
279 | lineSegment2.Point = this.EndPoint; |
||
280 | pathFigure.Segments.Add(lineSegment2); |
||
281 | |||
282 | PathGeometry pathGeometry = new PathGeometry(); |
||
283 | pathGeometry.Figures.Add(pathFigure); |
||
284 | pathFigure.IsFilled = false; |
||
285 | instanceGroup.Children.Add(pathGeometry); |
||
286 | //this.Base_ArrowMultiPath.Stroke = this.StrokeColor; |
||
287 | |||
288 | //if (this.IsSelected) |
||
289 | //{ |
||
290 | // Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Blue); |
||
291 | //} |
||
292 | //else |
||
293 | //{ |
||
294 | // Base_ArrowMultiPath.Stroke = new SolidColorBrush(Colors.Red); |
||
295 | //} |
||
296 | |||
297 | this.PathData = instanceGroup; |
||
298 | OverViewPathData = PathData; |
||
299 | } |
||
300 | //public static PathGeometry SingleAllow(Point p2, Point p1, double lineSize) |
||
301 | //{ |
||
302 | // double theta = Math.Atan2((p2.Y - p1.Y), (p2.X - p1.X)) * 180 / Math.PI; |
||
303 | // PathGeometry pathGeometry = new PathGeometry(); |
||
304 | // PathFigure pathFigure = new PathFigure(); |
||
305 | // pathFigure.StartPoint = p1; |
||
306 | |||
307 | // Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6); |
||
308 | // Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6); |
||
309 | |||
310 | // //Point lpoint = new Point(p1.X + lineSize, p1.Y + lineSize * 4); |
||
311 | // //Point rpoint = new Point(p1.X - lineSize, p1.Y + lineSize * 4); |
||
312 | |||
313 | // //Point lpoint = new Point(p1.X + lineSize * 3, p1.Y + lineSize * 6); |
||
314 | // //Point rpoint = new Point(p1.X - lineSize * 3, p1.Y + lineSize * 6); |
||
315 | |||
316 | // LineSegment seg1 = new LineSegment(); |
||
317 | // seg1.Point = lpoint; |
||
318 | // pathFigure.Segments.Add(seg1); |
||
319 | |||
320 | // LineSegment seg2 = new LineSegment(); |
||
321 | // seg2.Point = rpoint; |
||
322 | // pathFigure.Segments.Add(seg2); |
||
323 | |||
324 | // LineSegment seg3 = new LineSegment(); |
||
325 | // seg3.Point = p1; |
||
326 | // pathFigure.Segments.Add(seg3); |
||
327 | |||
328 | // pathFigure.IsClosed = true; |
||
329 | // pathFigure.IsFilled = true; |
||
330 | |||
331 | // pathGeometry.Figures.Add(pathFigure); |
||
332 | // pathGeometry.FillRule = FillRule.Nonzero; |
||
333 | // RotateTransform transform = new RotateTransform(); |
||
334 | // transform.Angle = theta - 90; |
||
335 | // transform.CenterX = p1.X; |
||
336 | // transform.CenterY = p1.Y; |
||
337 | // pathGeometry.Transform = transform; |
||
338 | // return pathGeometry; |
||
339 | //} |
||
340 | |||
341 | protected void OnPropertyChanged(string propName) |
||
342 | { |
||
343 | if (PropertyChanged != null) |
||
344 | PropertyChanged(this, new PropertyChangedEventArgs(propName)); |
||
345 | } |
||
346 | public void updateControl() |
||
347 | { |
||
348 | this.StartPoint = new Point(this.PointSet[0].X, this.PointSet[0].Y); |
||
349 | this.MiddlePoint = new Point(this.PointSet[1].X, this.PointSet[1].Y); |
||
350 | this.EndPoint = new Point(this.PointSet[2].X, this.PointSet[2].Y); |
||
351 | } |
||
352 | 036650a0 | humkyung | |
353 | /// <summary> |
||
354 | a5b465dc | humkyung | /// return ArrowControl_Multi's area |
355 | /// </summary> |
||
356 | /// <author>humkyung</author> |
||
357 | /// <date>2019.06.13</date> |
||
358 | public override Rect ItemRect |
||
359 | { |
||
360 | get |
||
361 | { |
||
362 | double dMinX = Math.Min(this.StartPoint.X, this.EndPoint.X); |
||
363 | dMinX = Math.Min(this.MiddlePoint.X, dMinX); |
||
364 | double dMinY = Math.Min(this.StartPoint.Y, this.EndPoint.Y); |
||
365 | dMinY = Math.Min(this.MiddlePoint.Y, dMinY); |
||
366 | double dMaxX = Math.Max(this.StartPoint.X, this.EndPoint.X); |
||
367 | dMaxX = Math.Max(this.MiddlePoint.X, dMaxX); |
||
368 | double dMaxY = Math.Max(this.StartPoint.Y, this.EndPoint.Y); |
||
369 | dMaxY = Math.Max(this.MiddlePoint.Y, dMaxY); |
||
370 | |||
371 | return new Rect(new Point(dMinX, dMinY), new Point(dMaxX, dMaxY)); |
||
372 | } |
||
373 | } |
||
374 | |||
375 | /// <summary> |
||
376 | 036650a0 | humkyung | /// Serialize this |
377 | /// </summary> |
||
378 | /// <param name="sUserId"></param> |
||
379 | /// <returns></returns> |
||
380 | public override string Serialize() |
||
381 | { |
||
382 | using (S_ArrowControl_Multi STemp = new S_ArrowControl_Multi()) |
||
383 | { |
||
384 | STemp.TransformPoint = "0|0"; |
||
385 | STemp.PointSet = this.PointSet; |
||
386 | STemp.SizeSet = String.Format("{0}", this.LineSize); |
||
387 | STemp.StrokeColor = this.StrokeColor.Color.ToString(); |
||
388 | STemp.StartPoint = this.StartPoint; |
||
389 | STemp.EndPoint = this.EndPoint; |
||
390 | STemp.UserID = this.UserID; |
||
391 | STemp.Opac = this.Opacity; |
||
392 | STemp.DashSize = this.DashSize; |
||
393 | STemp.MidPoint = this.MiddlePoint; |
||
394 | STemp.Name = this.GetType().Name.ToString(); |
||
395 | |||
396 | ///강인구 추가(2017.11.02) |
||
397 | ///Memo 추가 |
||
398 | STemp.Memo = this.Memo; |
||
399 | |||
400 | return "|DZ|" + JsonSerializerHelper.CompressString((STemp.JsonSerialize())); |
||
401 | }; |
||
402 | } |
||
403 | |||
404 | 661b7416 | humkyung | /// <summary> |
405 | /// create a arrowcontrol_multi from given string |
||
406 | /// </summary> |
||
407 | /// <param name="str"></param> |
||
408 | /// <returns></returns> |
||
409 | public static ArrowControl_Multi FromString(string str, SolidColorBrush brush, string sProjectNo) |
||
410 | { |
||
411 | ArrowControl_Multi instance = null; |
||
412 | using (S_ArrowControl_Multi s = JsonSerializerHelper.JsonDeserialize<S_ArrowControl_Multi>(str)) |
||
413 | { |
||
414 | string[] data2 = s.SizeSet.Split(delimiterChars2, StringSplitOptions.RemoveEmptyEntries); |
||
415 | instance = new ArrowControl_Multi |
||
416 | { |
||
417 | LineSize = Convert.ToDouble(data2.First()), |
||
418 | StartPoint = s.StartPoint, |
||
419 | MiddlePoint = s.MidPoint, |
||
420 | DashSize = s.DashSize, |
||
421 | EndPoint = s.EndPoint, |
||
422 | PointSet = s.PointSet, |
||
423 | Opacity = s.Opac, |
||
424 | StrokeColor = brush, |
||
425 | UserID = s.UserID, |
||
426 | Memo = s.Memo |
||
427 | }; |
||
428 | } |
||
429 | |||
430 | return instance; |
||
431 | } |
||
432 | |||
433 | 787a4489 | KangIngu | public void Dispose() |
434 | { |
||
435 | GC.Collect(); |
||
436 | GC.SuppressFinalize(this); |
||
437 | } |
||
438 | } |
||
439 | } |