lixiaojun
2024-08-15 11bfb11f3f352315fe64104509adda13d9f870d0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Xml.Linq;
 
namespace Eventech.DynPicture.Model
{
    /// <summary>
    /// 默认参数
    /// </summary>
    public class ConfigInfo
    {
        #region 点
        /// <summary>
        /// 牟定方式
        /// </summary>
        public ePointAnchor PointAnchor { get; set; }
        #endregion
        #region 字体
 
        /// <summary>
        /// 字体名称
        /// </summary>
        public string FontName
        {
            get { return _fontName; }
            set { _fontName = value; }
        }
        private string _fontName = "宋体";
 
        /// <summary>
        /// 字体大小
        /// </summary>
        public float FontSize
        {
            get { return _fontSize; }
            set { _fontSize = value; }
        }
        private float _fontSize = 9f;
 
        /// <summary>
        /// 字体颜色
        /// </summary>
        public Color FontColor
        {
            get { return _fontColor; }
            set { _fontColor = value; }
        }
        private Color _fontColor = Color.Black;
 
        /// <summary>
        /// 是否粗体
        /// </summary>
        public bool IsBold
        {
            get { return _isBold; }
            set { _isBold = value; }
        }
        private bool _isBold = false;
 
        /// <summary>
        /// 是否斜体
        /// </summary>
        public bool IsItalic
        {
            get { return _isItalic; }
            set { _isItalic = value; }
        }
        private bool _isItalic = false;
 
        /// <summary>
        /// 旋转角度
        /// </summary>
        public float TextAngle
        {
            get { return _textAngle; }
            set { _textAngle = value; }
        }
        private float _textAngle = 0;
 
        #endregion
 
        #region 文本框
 
        /// <summary>
        /// 文本边框宽度
        /// </summary>
        public float TextBoxBorderWidth
        {
            get { return _textBoxBorderWidth; }
            set { _textBoxBorderWidth = value; }
        }
        private float _textBoxBorderWidth = 1f;
 
        /// <summary>
        /// 文本框颜色
        /// </summary>
        public Color TextBoxBorderColor
        {
            get { return _textBoxBorderColor; }
            set { _textBoxBorderColor = value; }
        }
        private Color _textBoxBorderColor = Color.Black;
 
        /// <summary>
        /// 背景颜色是否透明
        /// </summary>
        public bool TextBoxBackgroundTransparent
        {
            get { return _textBoxBackgroundTransparent; }
            set { _textBoxBackgroundTransparent = value; }
        }
        private bool _textBoxBackgroundTransparent = true;
 
        /// <summary>
        /// 背景颜色
        /// </summary>
        public Color TextBoxBackgroundColor
        {
            get { return _textBoxBackgroundColor; }
            set { _textBoxBackgroundColor = value; }
        }
        private Color _textBoxBackgroundColor = Color.White;
 
        /// <summary>
        /// 文本框宽度
        /// </summary>
        public float TextBoxWidth
        {
            get { return _textBoxWidth; }
            set { _textBoxWidth = value; }
        }
        private float _textBoxWidth = 100;
 
        /// <summary>
        /// 文本框高度
        /// </summary>
        public float TextBoxHeight
        {
            get { return _textBoxHeight; }
            set { _textBoxHeight = value; }
        }
        private float _textBoxHeight = 30;
 
        /// <summary>
        /// 文本水平对齐方式
        /// </summary>
        public StringAlignment TextHAlignment
        {
            get { return _textHAlignment; }
            set { _textHAlignment = value; }
        }
        private StringAlignment _textHAlignment = StringAlignment.Center;
 
        /// <summary>
        /// 文本垂直对齐方式
        /// </summary>
        public StringAlignment TextVAlignment
        {
            get { return _textVAlignment; }
            set { _textVAlignment = value; }
        }
        private StringAlignment _textVAlignment = StringAlignment.Center;
        
 
        #endregion
 
        #region 线
 
        /// <summary>
        /// 线宽
        /// </summary>
        public float LineWidth
        {
            get { return _lineWidth; }
            set { _lineWidth = value; }
        }
        private float _lineWidth = 1;
 
        /// <summary>
        /// 线颜色
        /// </summary>
        public Color LineColor
        {
            get { return _lineColor; }
            set { _lineColor = value; }
        }
        private Color _lineColor = Color.Black;
 
        /// <summary>
        /// 线影响区域
        /// </summary>
        public float LineShadow
        {
            get { return _lineShadow; }
            set { _lineShadow = value; }
        }
        private float _lineShadow = 5f;
 
        /// <summary>
        /// 线延申长度
        /// </summary>
        public float LineExtendLength
        {
            get { return _lineExtendLength; }
            set { _lineExtendLength = value; }
        }
        private float _lineExtendLength = 10f;
 
        
 
        
        #endregion
 
        #region 箭头
 
        /// <summary>
        /// 箭头长度
        /// </summary>
        public float ArrowLength
        {
            get { return _arrowLength; }
            set { _arrowLength = value; }
        }
        private float _arrowLength = 15f;
 
        /// <summary>
        /// 箭头宽度
        /// </summary>
        public float ArrowWidth
        {
            get { return _arrowWidth; }
            set { _arrowWidth = value; }
        }
        private float _arrowWidth = 10f;
 
        /// <summary>
        /// 箭头颜色
        /// </summary>
        public Color ArrowColor
        {
            get { return _arrowColor; }
            set { _arrowColor = value; }
        }
        private Color _arrowColor = Color.Black;
 
        /// <summary>
        /// 箭头方向
        /// </summary>
        public eArrowDirection ArrowDirection
        {
            get { return _arrowDirection; }
            set { _arrowDirection = value; }
        }
        private eArrowDirection _arrowDirection =eArrowDirection.Inner;
 
        
        #endregion
 
        #region Highlight
        /// <summary>
        /// 高亮边框颜色
        /// </summary>
        public Color HighlightBorderColor
        {
            get { return _highlightBorderColor; }
            set { _highlightBorderColor = value; }
        }
        private Color _highlightBorderColor = Color.Red;
 
        /// <summary>
        /// 高亮边框宽度
        /// </summary>
        public float HighlightBorderWidth
        {
            get { return _highlightBorderWidth; }
            set { _highlightBorderWidth = value; }
        }
        private float _highlightBorderWidth = 1f;
 
        
        #endregion
 
        
        /// <summary>
        /// 转化为XElement
        /// </summary>
        /// <returns></returns>
        public XElement ToXElement()
        {
            var xele = new XElement("Root");
 
            #region 点
            var pointXele = new XElement("Point");
            pointXele.SetAttributeValue("PointAnchor", (int)this.PointAnchor);
            xele.Add(pointXele); 
            #endregion
 
            #region Font
            var fontXele = new XElement("Font");
            fontXele.SetAttributeValue("FontName", this.FontName);
            fontXele.SetAttributeValue("FontSize", this.FontSize);
            fontXele.SetAttributeValue("FontColor", ColorTranslator.ToHtml(this.FontColor));
            fontXele.SetAttributeValue("IsBold", this.IsBold ? 1 : 0);
            fontXele.SetAttributeValue("IsItalic", this.IsItalic ? 1 : 0);
            fontXele.SetAttributeValue("TextAngle", this.TextAngle);
            xele.Add(fontXele);
            #endregion
 
            #region TextBox
            var textBoxXele = new XElement("TextBox");
            textBoxXele.SetAttributeValue("TextBoxBorderWidth", this.TextBoxBorderWidth);
            textBoxXele.SetAttributeValue("TextBoxBorderColor", ColorTranslator.ToHtml(this.TextBoxBorderColor));
            textBoxXele.SetAttributeValue("TextBoxBackgroundTransparent", this.TextBoxBackgroundTransparent ? 1 : 0);
            textBoxXele.SetAttributeValue("TextBoxBackgroundColor", ColorTranslator.ToHtml(this.TextBoxBackgroundColor));
            textBoxXele.SetAttributeValue("TextBoxWidth", this.TextBoxWidth);
            textBoxXele.SetAttributeValue("TextBoxHeight", this.TextBoxHeight);
            textBoxXele.SetAttributeValue("TextHAlignment", (int)this.TextHAlignment);
            textBoxXele.SetAttributeValue("TextVAlignment", (int)this.TextVAlignment);
            xele.Add(textBoxXele);
            #endregion
 
            #region Line
            var lineXele = new XElement("Line");
            lineXele.SetAttributeValue("LineWidth", this.LineWidth);
            lineXele.SetAttributeValue("LineColor", ColorTranslator.ToHtml(this.LineColor));
            lineXele.SetAttributeValue("LineShadow", this.LineShadow);
            lineXele.SetAttributeValue("LineExtendLength", this.LineExtendLength);
            xele.Add(lineXele);
            #endregion
 
            #region Arrow
            var arrowXele = new XElement("Arrow");
            arrowXele.SetAttributeValue("ArrowLength", this.ArrowLength);
            arrowXele.SetAttributeValue("ArrowWidth", this.ArrowWidth);
            arrowXele.SetAttributeValue("ArrowColor", ColorTranslator.ToHtml(this.ArrowColor));
            arrowXele.SetAttributeValue("ArrowDirection", (int)this.ArrowDirection);
            xele.Add(arrowXele);
            #endregion
 
            #region Highlight
            var highlightXele = new XElement("Highlight");
            highlightXele.SetAttributeValue("HighlightBorderColor",ColorTranslator.ToHtml(this.HighlightBorderColor));
            highlightXele.SetAttributeValue("HighlightBorderWidth",this.HighlightBorderWidth);
            #endregion
 
            return xele;
        }
 
        public static ConfigInfo GetConfigInfo(XElement xele)
        {
            try
            {
                var defaltParas = new ConfigInfo();
 
                #region 点
                var pointXele = xele.Element("Point");
                defaltParas.PointAnchor = (ePointAnchor)int.Parse(pointXele.Attribute("PointAnchor").Value);
                xele.Add(pointXele);
                #endregion
 
                #region font
                var fontXele = xele.Element("Font");
                defaltParas.FontName = fontXele.Attribute("FontName").Value;
                defaltParas.FontSize = float.Parse(fontXele.Attribute("FontSize").Value);
                defaltParas.FontColor = ColorTranslator.FromHtml(fontXele.Attribute("FontColor").Value);
                defaltParas.IsBold = Convert.ToInt32(fontXele.Attribute("IsBold").Value) == 1 ? true : false;
                defaltParas.IsItalic = Convert.ToInt32(fontXele.Attribute("IsItalic").Value) == 1 ? true : false;
                defaltParas.TextAngle = float.Parse(fontXele.Attribute("TextAngle").Value);
                #endregion
 
                #region textBox
                var textBoxXele = xele.Element("TextBox");
                defaltParas.TextBoxBorderWidth = float.Parse(textBoxXele.Attribute("TextBoxBorderWidth").Value);
                defaltParas.TextBoxBorderColor = ColorTranslator.FromHtml(textBoxXele.Attribute("TextBoxBorderColor").Value);
                defaltParas.TextBoxBackgroundTransparent = Convert.ToInt32(textBoxXele.Attribute("TextBoxBackgroundTransparent").Value) == 1 ? true : false;
                defaltParas.TextBoxBackgroundColor = ColorTranslator.FromHtml(textBoxXele.Attribute("TextBoxBackgroundColor").Value);
                defaltParas.TextBoxWidth = float.Parse(textBoxXele.Attribute("TextBoxWidth").Value);
                defaltParas.TextBoxHeight = float.Parse(textBoxXele.Attribute("TextBoxHeight").Value);
                defaltParas.TextHAlignment = (StringAlignment)int.Parse(textBoxXele.Attribute("TextHAlignment").Value);
                defaltParas.TextVAlignment= (StringAlignment)int.Parse(textBoxXele.Attribute("TextVAlignment").Value);
                #endregion
 
                #region line
                var lineXele = xele.Element("Line");
                defaltParas.LineWidth = float.Parse(lineXele.Attribute("LineWidth").Value);
                defaltParas.LineColor = ColorTranslator.FromHtml(lineXele.Attribute("LineColor").Value);
                defaltParas.LineShadow = float.Parse(lineXele.Attribute("LineShadow").Value);
                defaltParas.LineExtendLength = float.Parse(lineXele.Attribute("LineExtendLength").Value);
                #endregion
 
                #region arrow
                var arrowXele = xele.Element("Arrow");
                defaltParas.ArrowLength = float.Parse(arrowXele.Attribute("ArrowLength").Value);
                defaltParas.ArrowWidth = float.Parse(arrowXele.Attribute("ArrowWidth").Value);
                defaltParas.ArrowColor = ColorTranslator.FromHtml(arrowXele.Attribute("ArrowColor").Value);
                defaltParas.ArrowDirection = (eArrowDirection)int.Parse(arrowXele.Attribute("ArrowDirection").Value);
                #endregion
 
                #region Highlight
                var highlightXele = xele.Element("Highlight");
                defaltParas.HighlightBorderColor = ColorTranslator.FromHtml(highlightXele.Attribute("HighlightBorderColor").Value);
                defaltParas.HighlightBorderWidth = float.Parse(highlightXele.Attribute("HighlightBorderWidth").Value);
                #endregion
 
                return defaltParas;
            }
            catch
            {
                return new ConfigInfo();
            }
        }
 
 
    }
}