프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / Model / PlantItem / Document.cs @ 6adc617c

이력 | 보기 | 이력해설 | 다운로드 (38.9 KB)

1
using System;
2
using System.Collections.Generic;
3
using System.Text;
4
using System.Linq;
5
using System.Threading.Tasks;
6
using System.Xml.Linq;
7
using System.IO;
8
using System.Data;
9
using System.Windows.Forms;
10

    
11
namespace AVEVA.PID.CustomizationUtility.Model
12
{
13
    public class Document
14
    {
15
        private string _DWGNAME;
16
        private string _SIZE;
17
        private double _SIZE_WIDTH;
18
        private double _SIZE_HEIGHT;
19
        private string _UID;
20
        private List<Symbol> _SYMBOLS = new List<Symbol>();
21
        private List<Line> _LINES = new List<Line>();
22
        private List<LineNumber> _LINENUMBERS = new List<LineNumber>();
23
        private List<TrimLine> _TRIMLINES = new List<TrimLine>();
24
        private List<EndBreak> _EndBreaks = new List<EndBreak>();
25
        private List<SpecBreak> _SpecBreaks = new List<SpecBreak>();
26
        private List<Equipment> _Equipments = new List<Equipment>();
27
        private List<Text> _Texts = new List<Text>();
28
        private List<Note> _Notes = new List<Note>();
29
        private List<OPC> _OPCs = new List<OPC>();
30
        private bool _Enable;
31
        private bool _Validation;
32
        private bool _MappingValidation;
33
        private string _ValidationMessage = string.Empty;
34
        bool validationResult = false;
35
        private DataTable ID2SymbolTypeDT;
36

    
37
        public string AvevaDrawingNumber { get; set; }
38
        public string AvevaSheetNumber { get; set; }
39
        public string AvevaTemplateID { get; set; }
40
        public string AvevaTemplateName { get; set; }
41

    
42
        public string ValidationMessage { get => _ValidationMessage; set => _ValidationMessage = value; }
43

    
44
        public List<Symbol> SYMBOLS { get => _SYMBOLS; set => _SYMBOLS = value; }
45
        public List<Line> LINES { get => _LINES; set => _LINES = value; }
46
        public List<LineNumber> LINENUMBERS { get => _LINENUMBERS; set => _LINENUMBERS = value; }
47
        public List<EndBreak> EndBreaks { get => _EndBreaks; set => _EndBreaks = value; }
48
        public List<SpecBreak> SpecBreaks { get => _SpecBreaks; set => _SpecBreaks = value; }
49
        public List<Equipment> Equipments { get => _Equipments; set => _Equipments = value; }
50
        public string DWGNAME { get => _DWGNAME; set => _DWGNAME = value; }
51
        public string SIZE
52
        {
53
            get
54
            {
55
                return _SIZE;
56
            }
57
            set
58
            {
59
                _SIZE = value;
60
                string[] pointArr = _SIZE.Split(new char[] { ',' });
61
                if (pointArr.Length == 2)
62
                {
63
                    _SIZE_WIDTH = Convert.ToDouble(pointArr[0]);
64
                    _SIZE_HEIGHT = Convert.ToDouble(pointArr[1]);
65
                }
66
            }
67
        }
68
        public double SIZE_WIDTH { get => _SIZE_WIDTH; }
69
        public double SIZE_HEIGHT { get => _SIZE_HEIGHT; }
70
        public List<TrimLine> TRIMLINES { get => _TRIMLINES; set => _TRIMLINES = value; }
71
        public string PATH { get; set; }
72
        public bool Enable { get => _Enable; set => _Enable = value; }
73
        public bool Validation { get => _Validation; set => _Validation = value; }
74
        public bool MappingValidation { get => _MappingValidation; set => _MappingValidation = value; }
75
        public string UID { get => _UID; set => _UID = value; }
76
        public List<OPC> OPCs { get => _OPCs; set => _OPCs = value; }
77
        public List<Text> Texts { get => _Texts; set => _Texts = value; }
78
        public List<Note> Notes { get => _Notes; set => _Notes = value; }
79

    
80
        StringBuilder validationStringBuilder = new StringBuilder();
81

    
82
        public List<PlantItem> PlantItems = new List<PlantItem>();
83

    
84
        public Document(string xmlPath, DataTable ID2SymbolTypeDT)
85
        {
86
            this.ID2SymbolTypeDT = ID2SymbolTypeDT;
87
            validationStringBuilder.AppendLine("Document Path : " + xmlPath);
88
            validationStringBuilder.AppendLine("");
89
            try
90
            {
91
                if (xmlPath != null)
92
                {
93
                    PATH = xmlPath;
94
                    XElement xml = XElement.Load(xmlPath);
95
                    DWGNAME = xml.Element("DWGNAME").Value;
96
                    SIZE = xml.Element("SIZE").Value;
97

    
98
                    validationStringBuilder.AppendLine("Drawing Name : " + DWGNAME);
99
                    validationStringBuilder.AppendLine("");
100

    
101
                    SetText(xml.Element("TEXTINFOS"));
102
                    SetNote(xml.Element("NOTES"));
103
                    SetSymbol(xml.Element("SYMBOLS"));
104
                    SetLine(xml.Element("LINEINFOS"));
105
                    SetLineNumber(xml.Element("LINENOS"));
106
                    SetTrimLine(xml.Element("TRIMLINENOS"));
107

    
108
                    SetAllConnectors();
109
                    Enable = true;
110
                }
111
            }
112
            catch (Exception ex)
113
            {
114
                Enable = false;
115
                MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
116
            }
117
        }
118

    
119
        #region READ XML
120
        private void SetSymbol(XElement node)
121
        {
122
            foreach (XElement item in node.Elements("SYMBOL"))
123
            {
124
                string sType = item.Element("TYPE").Value;
125

    
126
                DataRow[] rows = ID2SymbolTypeDT.Select(string.Format("Type = '{0}'", sType.Replace("'", "''")));
127
                string sCategory = rows[0]["Category"].ToString();
128

    
129
                if (sType == "Segment Breaks")
130
                {
131
                    SpecBreak specBreak = new SpecBreak()
132
                    {
133
                        UID = item.Element("UID").Value,
134
                        DBUID = item.Element("DBUID").Value,
135
                        NAME = item.Element("NAME").Value,
136
                        TYPE = item.Element("TYPE").Value,
137
                        OWNER = item.Element("OWNER").Value,
138
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
139
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
140
                        LOCATION = item.Element("LOCATION").Value,
141
                        SIZE = item.Element("SIZE").Value,
142
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
143
                        PARENT = item.Element("PARENT").Value,
144
                        CHILD = item.Element("CHILD").Value,
145
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
146
                        AREA = item.Element("AREA").Value,
147
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
148
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
149
                    };
150
                    SetAssociations(item.Element("ASSOCIATIONS"), specBreak.ASSOCIATIONS);
151
                    SetSymbolConnectors(item.Element("CONNECTORS"), specBreak.CONNECTORS, specBreak.CONNECTIONPOINT);
152
                    SetProperties(item.Element("PROPERTIES"), specBreak.PROPERTIES);
153
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), specBreak.ATTRIBUTES);
154
                    SetSpecBreakAttribute(specBreak);
155

    
156
                    SpecBreaks.Add(specBreak);
157
                }
158
                else if (sType == "End Break")
159
                {
160
                    EndBreak endBreak = new EndBreak()
161
                    {
162
                        UID = item.Element("UID").Value,
163
                        DBUID = item.Element("DBUID").Value,
164
                        NAME = item.Element("NAME").Value,
165
                        TYPE = item.Element("TYPE").Value,
166
                        OWNER = item.Element("OWNER").Value,
167
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
168
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
169
                        LOCATION = item.Element("LOCATION").Value,
170
                        SIZE = item.Element("SIZE").Value,
171
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
172
                        PARENT = item.Element("PARENT").Value,
173
                        CHILD = item.Element("CHILD").Value,
174
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
175
                        AREA = item.Element("AREA").Value,
176
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
177
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
178
                    };
179
                    SetAssociations(item.Element("ASSOCIATIONS"), endBreak.ASSOCIATIONS);
180
                    SetSymbolConnectors(item.Element("CONNECTORS"), endBreak.CONNECTORS, endBreak.CONNECTIONPOINT);
181
                    SetProperties(item.Element("PROPERTIES"), endBreak.PROPERTIES);
182
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), endBreak.ATTRIBUTES);
183

    
184
                    EndBreaks.Add(endBreak);
185
                }
186
                else if (sCategory == "Equipment" ||
187
                    sCategory == "Equipment Components")
188
                {
189
                    Equipment equipment = new Equipment()
190
                    {
191
                        UID = item.Element("UID").Value,
192
                        DBUID = item.Element("DBUID").Value,
193
                        NAME = item.Element("NAME").Value,
194
                        TYPE = item.Element("TYPE").Value,
195
                        OWNER = item.Element("OWNER").Value,
196
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
197
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
198
                        LOCATION = item.Element("LOCATION").Value,
199
                        SIZE = item.Element("SIZE").Value,
200
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
201
                        PARENT = item.Element("PARENT").Value,
202
                        CHILD = item.Element("CHILD").Value,
203
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
204
                        AREA = item.Element("AREA").Value,
205
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
206
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
207
                    };
208
                    SetAssociations(item.Element("ASSOCIATIONS"), equipment.ASSOCIATIONS);
209
                    SetSymbolConnectors(item.Element("CONNECTORS"), equipment.CONNECTORS, equipment.CONNECTIONPOINT);
210
                    SetProperties(item.Element("PROPERTIES"), equipment.PROPERTIES);
211
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), equipment.ATTRIBUTES);
212

    
213
                    Equipments.Add(equipment);
214
                }
215
                else if (sType == "Piping OPC's" || sType == "Instrument OPC's")
216
                {
217
                    OPC opc = new OPC()
218
                    {
219
                        UID = item.Element("UID").Value,
220
                        DBUID = item.Element("DBUID").Value,
221
                        NAME = item.Element("NAME").Value,
222
                        TYPE = item.Element("TYPE").Value,
223
                        OWNER = item.Element("OWNER").Value,
224
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
225
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
226
                        LOCATION = item.Element("LOCATION").Value,
227
                        SIZE = item.Element("SIZE").Value,
228
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
229
                        PARENT = item.Element("PARENT").Value,
230
                        CHILD = item.Element("CHILD").Value,
231
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
232
                        AREA = item.Element("AREA").Value,
233
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
234
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
235
                    };
236

    
237
                    SetAssociations(item.Element("ASSOCIATIONS"), opc.ASSOCIATIONS);
238
                    SetSymbolConnectors(item.Element("CONNECTORS"), opc.CONNECTORS, opc.CONNECTIONPOINT);
239
                    SetProperties(item.Element("PROPERTIES"), opc.PROPERTIES);
240
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), opc.ATTRIBUTES);
241
                    SetChildSymbol(opc);
242

    
243
                    if (sType == "Piping OPC's")
244
                        opc.OPCType = OPCType.Pipe;
245
                    else if (sType == "Instrument OPC's")
246
                        opc.OPCType = OPCType.Signal;
247

    
248
                    OPCs.Add(opc);
249
                }
250
                else
251
                {
252
                    Symbol symbol = new Symbol()
253
                    {
254
                        UID = item.Element("UID").Value,
255
                        DBUID = item.Element("DBUID").Value,
256
                        NAME = item.Element("NAME").Value,
257
                        TYPE = item.Element("TYPE").Value,
258
                        OWNER = item.Element("OWNER").Value,
259
                        ORIGINALPOINT = item.Element("ORIGINALPOINT").Value,
260
                        CONNECTIONPOINT = item.Element("CONNECTIONPOINT").Value,
261
                        LOCATION = item.Element("LOCATION").Value,
262
                        SIZE = item.Element("SIZE").Value,
263
                        ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
264
                        PARENT = item.Element("PARENT").Value,
265
                        CHILD = item.Element("CHILD").Value,
266
                        HASINSTRUMENTLABEL = item.Element("HASINSTRUMENTLABEL").Value,
267
                        AREA = item.Element("AREA").Value,
268
                        FLIP = Convert.ToInt32(item.Element("FLIP").Value),
269
                        CURRENTPOINTMODEINDEX = Convert.ToInt32(item.Element("CURRENTPOINTMODEINDEX").Value)
270
                    };
271

    
272
                    SetAssociations(item.Element("ASSOCIATIONS"), symbol.ASSOCIATIONS);
273
                    SetSymbolConnectors(item.Element("CONNECTORS"), symbol.CONNECTORS, symbol.CONNECTIONPOINT);
274
                    SetProperties(item.Element("PROPERTIES"), symbol.PROPERTIES);
275
                    SetAttributes(item.Element("SYMBOLATTRIBUTES"), symbol.ATTRIBUTES);
276
                    SetChildSymbol(symbol);
277

    
278
                    SYMBOLS.Add(symbol);
279
                }
280
            }
281

    
282
            PlantItems.AddRange(SpecBreaks);
283
            PlantItems.AddRange(EndBreaks);
284
            PlantItems.AddRange(Equipments);
285
            PlantItems.AddRange(SYMBOLS);
286
            PlantItems.AddRange(OPCs);
287
        }
288

    
289
        private void SetLine(XElement node)
290
        {
291
            foreach (XElement item in node.Elements("LINE"))
292
            {
293
                Line line = new Line()
294
                {
295
                    OWNER = item.Attribute("OWNER").Value,
296
                    UID = item.Element("UID").Value,
297
                    STARTPOINT = item.Element("STARTPOINT").Value,
298
                    ENDPOINT = item.Element("ENDPOINT").Value,
299
                    TYPE = item.Element("TYPE").Value,
300
                    TYPEUID = item.Element("TYPE").Attribute("TYPEUID").Value,
301
                    AREA = item.Element("AREA").Value,
302
                    THICKNESS = item.Element("THICKNESS").Value,
303
                };
304
                int flowMarkPercent = 0;
305
                if (int.TryParse(item.Element("FLOWMARK").Value, out flowMarkPercent))
306
                {
307
                    line.FLOWMARK = true;
308
                    line.FLOWMARK_PERCENT = flowMarkPercent;
309
                }
310
                else
311
                    line.FLOWMARK = false;
312

    
313
                SetAssociations(item.Element("ASSOCIATIONS"), line.ASSOCIATIONS);
314
                SetConnectors(item.Element("CONNECTORS"), line.CONNECTORS);
315
                SetAttributes(item.Element("SYMBOLATTRIBUTES"), line.ATTRIBUTES);
316
                line.SetSlopeType();
317
                LINES.Add(line);
318
            }
319
            PlantItems.AddRange(LINES);
320
        }
321

    
322
        private void SetLineNumber(XElement node)
323
        {
324
            foreach (XElement item in node.Elements("LINE_NO"))
325
            {
326
                LineNumber lineNumber = new LineNumber()
327
                {
328
                    UID = item.Element("UID").Value,
329
                    TEXT = item.Element("TEXT").Value,
330
                    LOCATION = item.Element("LOCATION").Value,
331
                    WIDTH = item.Element("WIDTH").Value,
332
                    HEIGHT = item.Element("HEIGHT").Value,
333
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
334
                    AREA = item.Element("AREA").Value,
335
                    SCENE = item.Element("SCENE").Value
336
                };
337
                if (item.Element("CONNLINE") != null)
338
                    lineNumber.CONNLINE = item.Element("CONNLINE").Value;
339
                else
340
                {
341
                    validationStringBuilder.AppendLine("Not exist CONNLINE!" + "\r\nLineNumber UID : " + lineNumber.UID);
342
                    validationStringBuilder.AppendLine();
343
                    validationResult = true;
344
                }
345

    
346
                SetLineNumberRuns(item, lineNumber.RUNS);
347
                SetProperties(item.Element("PROPERTIES"), lineNumber.PROPERTIES);
348
                SetAttributes(item, lineNumber.ATTRIBUTES);
349
                LINENUMBERS.Add(lineNumber);
350
            }
351
            PlantItems.AddRange(LINENUMBERS);
352
        }
353

    
354
        private void SetTrimLine(XElement node)
355
        {
356
            foreach (XElement item in node.Elements("TRIM_LINE_NO"))
357
            {
358
                TrimLine trimLine = new TrimLine()
359
                {
360
                    UID = item.Element("UID").Value,
361
                };
362
                SetLineNumberRuns(item, trimLine.RUNS);
363
                TRIMLINES.Add(trimLine);
364
            }
365
            PlantItems.AddRange(TRIMLINES);
366
        }
367

    
368
        private void SetAssociations(XElement node, List<Association> associations)
369
        {
370
            foreach (XElement item in node.Elements("ASSOCIATION"))
371
            {
372
                Association association = new Association()
373
                {
374
                    TYPE = item.Attribute("TYPE").Value,
375
                    VALUE = item.Value
376
                };
377

    
378
                associations.Add(association);
379
            }
380
        }
381

    
382
        private void SetConnectors(XElement node, List<Connector> connectors)
383
        {
384
            foreach (XElement item in node.Elements("CONNECTOR"))
385
            {
386
                connectors.Add(new Connector()
387
                {
388
                    UID = item.Attribute("UID").Value,
389
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
390
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
391
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
392
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
393
                });
394
            }
395
        }
396

    
397
        private void SetSymbolConnectors(XElement node, List<Connector> connectors, string CONNECTIONPOINT)
398
        {
399
            foreach (XElement item in node.Elements("CONNECTOR"))
400
            {
401
                connectors.Add(new Connector()
402
                {
403
                    UID = item.Attribute("UID").Value,
404
                    CONNECTED_AT = Convert.ToInt32(item.Attribute("CONNECTED_AT").Value),
405
                    CONNECTEDITEM = item.Element("CONNECTEDITEM").Value,
406
                    CONNECTPOINT = item.Element("CONNECTPOINT").Value,
407
                    SCENECONNECTPOINT = item.Element("SCENECONNECTPOINT").Value,
408
                });
409
            }
410
        }
411

    
412
        private void SetProperties(XElement node, List<Property> properties)
413
        {
414
            foreach (XElement item in node.Elements("PROPERTY"))
415
            {
416
                properties.Add(new Property()
417
                {
418
                    UID = item.Attribute("UID").Value,
419
                    LENGTH = item.Attribute("Length").Value,
420
                    EXPRESSION = item.Attribute("Expression").Value,
421
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
422
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
423
                    ATTRIBUTE = item.Attribute("Attribute").Value,
424
                    VALUE = item.Value
425
                });
426
            }
427
        }
428

    
429
        private void SetAttributes(XElement node, List<Attribute> attributes)
430
        {
431
            foreach (XElement item in node.Elements("ATTRIBUTE"))
432
            {
433
                Attribute attribute = new Attribute()
434
                {
435
                    UID = item.Attribute("UID").Value,
436
                    LENGTH = item.Attribute("Length").Value,
437
                    EXPRESSION = item.Attribute("Expression").Value,
438
                    DISPLAYATTRIBUTE = item.Attribute("DisplayAttribute").Value,
439
                    ATTRIBUTETYPE = item.Attribute("AttributeType").Value,
440
                    ATTRIBUTE = item.Attribute("Attribute").Value,
441
                    ATTRAT = item.Attribute("AttrAt").Value,
442
                    ASSOCITEM = item.Attribute("AssocItem").Value,
443
                    VALUE = item.Value
444
                };
445

    
446
                attributes.Add(attribute);
447

    
448
                if (!string.IsNullOrEmpty(attribute.ASSOCITEM) && attribute.ASSOCITEM != "None")
449
                {
450
                    Text text = Texts.Find(x => x.UID == attribute.ASSOCITEM);
451
                    if (text != null)
452
                        text.ASSOCIATION = true;
453
                }
454
            }
455
        }
456

    
457
        private void SetSpecBreakAttribute(SpecBreak specBreak)
458
        {
459
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
460
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
461

    
462
            specBreak.UpStreamUID = upStream;
463
            specBreak.DownStreamUID = downStream;
464
        }
465

    
466
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
467
        {
468
            foreach (XElement item in node.Elements("RUN"))
469
            {
470
                LineRun run = new LineRun()
471
                {
472
                    TYPE = item.Attribute("TYPE").Value
473
                };
474

    
475
                foreach (XElement element in item.Elements())
476
                {
477
                    if (element.Name == "SYMBOL")
478
                    {
479
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
480
                        Equipment equipment = GetEquipmentByUID(element.Element("UID").Value);
481
                        OPC opc = GetOPCByUID(element.Element("UID").Value);
482
                        if (symbol == null && equipment == null && opc == null)
483
                        {
484
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
485
                            validationStringBuilder.AppendLine();
486
                            validationResult = true;
487
                        }
488
                        if (symbol != null)
489
                            run.RUNITEMS.Add(symbol);
490
                        else if (equipment != null)
491
                            run.RUNITEMS.Add(equipment);
492
                        else if (opc != null)
493
                            run.RUNITEMS.Add(opc);
494
                    }
495
                    else if (element.Name == "LINE")
496
                    {
497
                        Line line = GetLineByUID(element.Element("UID").Value);
498
                        if (line == null)
499
                        {
500
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
501
                            validationStringBuilder.AppendLine();
502
                            validationResult = true;
503
                        }
504
                        run.RUNITEMS.Add(line);
505
                    }
506
                }
507
                lineNumberRuns.Add(run);
508
            }
509
        }
510

    
511
        private void SetChildSymbol(Symbol symbol)
512
        {
513
            List<ChildSymbol> childList = new List<ChildSymbol>();
514
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
515
            {
516
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
517
                foreach (string sChild in childArray)
518
                {
519
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
520
                    childList.Add(new ChildSymbol()
521
                    {
522
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
523
                        Direction = sChildInfo[1],
524
                        NAME = sChildInfo[2]
525
                    });
526
                }
527

    
528
                foreach (ChildSymbol child in childList)
529
                {
530
                    if (child.ParentAt == 0)
531
                        symbol.ChildSymbols.Add(child);
532
                    else
533
                        childList[child.ParentAt - 1].ChildSymbols.Add(child);
534
                }
535
            }
536
            if (!string.IsNullOrEmpty(symbol.CONNECTIONPOINT) && symbol.CONNECTIONPOINT != "None")
537
            {
538
                // 현재 부모 Symbol에 자식 Connector까지 들어가 있음
539
                string[] connectionArray = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
540
                string[] array = symbol.CONNECTIONPOINT.Split(new char[] { '/' });
541
                for (int i = 0; i < array.Length; i++)
542
                {
543
                    string[] arrConn = array[i].Split(new char[] { ',' });
544
                    int connIndex = Convert.ToInt32(arrConn[3]);
545
                    if (connIndex != 0)
546
                    {
547
                        childList[connIndex - 1].Connectors.Add(symbol.CONNECTORS[i]);
548
                        symbol.CONNECTORS[i].Index = connIndex;
549
                    }
550
                }
551
            }
552
        }
553

    
554
        private void SetText(XElement node)
555
        {
556
            foreach (XElement item in node.Elements("ATTRIBUTE"))
557
            {
558
                Text text = new Text()
559
                {
560
                    UID = item.Element("UID").Value,
561
                    OWNER = item.Element("OWNER").Value,
562
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
563
                    NAME = item.Element("NAME").Value,
564
                    LOCATION = item.Element("LOCATION").Value,
565
                    VALUE = item.Element("VALUE").Value,
566
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
567
                    WIDTH = item.Element("WIDTH").Value,
568
                    HEIGHT = item.Element("HEIGHT").Value,
569
                    AREA = item.Element("AREA").Value,
570
                    SCENE = item.Element("SCENE").Value
571
                };
572

    
573
                Texts.Add(text);
574
            }
575
        }
576

    
577
        private void SetNote(XElement node)
578
        {
579
            foreach (XElement item in node.Elements("ATTRIBUTE"))
580
            {
581
                Note note = new Note()
582
                {
583
                    UID = item.Element("UID").Value,
584
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
585
                    NAME = item.Element("NAME").Value,
586
                    LOCATION = item.Element("LOCATION").Value,
587
                    VALUE = item.Element("VALUE").Value,
588
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
589
                    WIDTH = item.Element("WIDTH").Value,
590
                    HEIGHT = item.Element("HEIGHT").Value,
591
                    AREA = item.Element("AREA").Value,
592
                    SCENE = item.Element("SCENE").Value,
593
                    OWNER = item.Element("OWNER").Value
594
                };
595

    
596
                Notes.Add(note);
597
            }
598
        }
599
        #endregion
600

    
601
        public void SetAllConnectors()
602
        {
603
            foreach (var item in SYMBOLS)
604
                foreach (var connector in item.CONNECTORS)
605
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
606

    
607
            foreach (var item in OPCs)
608
                foreach (var connector in item.CONNECTORS)
609
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
610

    
611
            foreach (var item in LINES)
612
                foreach (var connector in item.CONNECTORS)
613
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
614

    
615
            foreach (var item in Equipments)
616
                foreach (var connector in item.CONNECTORS)
617
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
618
        }
619

    
620
        public Symbol GetSymbolByUID(string uid)
621
        {
622
            return SYMBOLS.Find(x => x.UID == uid);
623
        }
624

    
625
        public OPC GetOPCByUID(string uid)
626
        {
627
            return OPCs.Find(x => x.UID == uid);
628
        }
629

    
630
        public Equipment GetEquipmentByUID(string uid)
631
        {
632
            return Equipments.Find(x => x.UID == uid);
633
        }
634

    
635
        public Line GetLineByUID(string uid)
636
        {
637
            return LINES.Find(x => x.UID == uid);
638
        }
639

    
640
        #region For Aveva
641
        
642
        public bool SetAvevaInfo(DataTable symbolMappingTable, DataTable lineMappingTable, DataTable opcMappingTable)
643
        {
644
            bool result = true;
645
            foreach (var item in LINES)
646
            {
647
                DataRow[] rows = lineMappingTable.Select(string.Format("UID = '{0}'", item.TYPEUID));
648
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"]))
649
                {
650
                    item.Aveva = new AvevaLineInfo();
651
                    item.Aveva.Name = (string)rows[0]["APID_SYMBOL"];
652
                    double startX = item.Start_X;
653
                    double startY = SIZE_HEIGHT - item.Start_Y;
654
                    double endX = item.End_X;
655
                    double endY = SIZE_HEIGHT - item.End_Y;
656

    
657
                    ConvertAvevaPoint(ref startX, ref startY);
658
                    ConvertAvevaPoint(ref endX, ref endY);
659

    
660
                    item.Aveva.Start_X = startX;
661
                    item.Aveva.Start_Y = startY;
662
                    item.Aveva.End_X = endX;
663
                    item.Aveva.End_Y = endY;
664

    
665
                    if (item.SlopeType == SlopeType.HORIZONTAL)
666
                        item.Aveva.End_Y = item.Aveva.Start_Y;
667
                    else if (item.SlopeType == SlopeType.VERTICAL)
668
                        item.Aveva.End_X = item.Aveva.Start_X;
669

    
670
                    if (!DBNull.Value.Equals(rows[0]["DATA1"]))
671
                    {
672
                        if (rows[0]["DATA1"].ToString() == "PIPE")
673
                            item.Aveva.Type = Type.Pipe;
674
                        else if (rows[0]["DATA1"].ToString() == "SIGNAL")
675
                            item.Aveva.Type = Type.Signal;
676
                    }
677

    
678
                    item.Aveva.Start_X = Math.Round(item.Aveva.Start_X);
679
                    item.Aveva.Start_Y = Math.Round(item.Aveva.Start_Y);
680
                    item.Aveva.End_X = Math.Round(item.Aveva.End_X);
681
                    item.Aveva.End_Y = Math.Round(item.Aveva.End_Y);
682
                }
683
                else
684
                {
685
                    validationStringBuilder.AppendLine(string.Format("Need Mapping Line : {0}", item.TYPE));
686
                    result = false;
687
                }
688
            }
689
            foreach (var item in SYMBOLS)
690
            {
691
                DataRow[] rows = symbolMappingTable.Select(string.Format("UID = '{0}'", item.DBUID));
692
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"]))
693
                {
694
                    item.Aveva = new AvevaSymbolInfo();
695
                    double x = item.X;
696
                    double y = SIZE_HEIGHT - item.Y;
697

    
698
                    ConvertAvevaPoint(ref x, ref y);
699

    
700
                    item.Aveva.X = Math.Round(x);
701
                    item.Aveva.Y = Math.Round(y);
702

    
703
                    item.Aveva.FullName = (string)rows[0]["APID_SYMBOL"];
704
                    string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
705
                    item.Aveva.Name = split[split.Length - 1];
706
                }
707
                else
708
                {
709
                    validationStringBuilder.AppendLine(string.Format("Need Mapping Symbol : {0}", item.NAME));
710
                    result = false;
711
                }
712
            }
713
            foreach (var item in OPCs)
714
            {
715
                DataRow[] rows = opcMappingTable.Select(string.Format("UID = '{0}'", item.DBUID));
716
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["IN_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["OUT_SYMBOL"]))
717
                {
718
                    item.Aveva = new AvevaSymbolInfo();
719
                    double x = item.X;
720
                    double y = SIZE_HEIGHT - item.Y;
721

    
722
                    ConvertAvevaPoint(ref x, ref y);
723

    
724
                    item.Aveva.X = Math.Round(x);
725
                    item.Aveva.Y = Math.Round(y);
726

    
727
                    if (item.TYPE == "Piping OPC's")
728
                        item.OPCType = OPCType.Pipe;
729
                    else if (item.TYPE == "Instrument OPC's")
730
                        item.OPCType = OPCType.Signal;
731

    
732
                    Connector connector = item.CONNECTORS.Find(loop =>
733
                    APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM) != null &&
734
                    APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM).GetType() == typeof(Line));
735
                    if (connector != null)
736
                    {
737
                        // out
738
                        if (item.CONNECTORS.IndexOf(connector) == 0)
739
                        {
740
                            item.Aveva.FullName = (string)rows[0]["OUT_SYMBOL"];
741
                            string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
742
                            item.Aveva.Name = split[split.Length - 1];
743
                            item.FlowType = FlowType.Out;
744
                        }
745
                        // in
746
                        else
747
                        {
748
                            item.Aveva.FullName = (string)rows[0]["IN_SYMBOL"];
749
                            string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
750
                            item.Aveva.Name = split[split.Length - 1];
751
                            item.FlowType = FlowType.In;
752
                        }
753
                    }
754
                    else
755
                    {
756
                        validationStringBuilder.AppendLine(string.Format("Check OPC's Connector : {0}", item.UID));
757
                        result = false;
758
                    }
759
                }
760
                else
761
                {
762
                    validationStringBuilder.AppendLine(string.Format("Need Mapping Symbol : {0}", item.NAME));
763
                    result = false;
764
                }
765
            }
766
            foreach (var item in LINENUMBERS)
767
            {
768
                item.Aveva = new AvevaLabelInfo();
769
                double x = (item.X1 + item.X2) / 2;
770
                double y = SIZE_HEIGHT - (item.Y1 + item.Y2) / 2;
771

    
772
                ConvertAvevaPoint(ref x, ref y);
773

    
774
                item.Aveva.X = Math.Round(x);
775
                item.Aveva.Y = Math.Round(y);
776
                item.Aveva.LabelType = LabelType.LineNumber;
777
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
778
            }
779

    
780
            foreach (var item in Texts)
781
            {
782
                item.Aveva = new AvevaLabelInfo();
783

    
784
                double x = item.X1;
785
                double y = SIZE_HEIGHT - item.Y2;
786
                ConvertAvevaPoint(ref x, ref y);
787
                item.Aveva.X = Math.Round(x);
788
                item.Aveva.Y = Math.Round(y);
789

    
790
                if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
791
                {
792
                    double height = Math.Abs(item.Y1 - item.Y2);
793
                    ConvertAvevaPointY(ref height);
794
                    item.Aveva.Height = height;
795
                }
796
                else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
797
                {
798
                    double height = Math.Abs(item.X1 - item.X2);
799
                    ConvertAvevaPointX(ref height);
800
                    item.Aveva.Height = height;
801
                }
802

    
803
                if (item.VALUE.Contains("\n"))
804
                {
805
                    item.Aveva.LabelType = LabelType.MultiText;
806
                    int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1;
807
                    item.Aveva.Height = item.Aveva.Height / count;
808
                }
809
                else
810
                    item.Aveva.LabelType = LabelType.SingleText;
811

    
812
                item.Aveva.Angle = item.ANGLE;
813
            }
814
            foreach (var item in Notes)
815
            {
816
                item.Aveva = new AvevaLabelInfo();
817

    
818
                double x = item.X1;
819
                double y = SIZE_HEIGHT - item.Y2;
820
                ConvertAvevaPoint(ref x, ref y);
821
                item.Aveva.X = Math.Round(x);
822
                item.Aveva.Y = Math.Round(y);
823

    
824
                if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
825
                {
826
                    double height = Math.Abs(item.Y1 - item.Y2);
827
                    ConvertAvevaPointY(ref height);
828
                    item.Aveva.Height = height;
829
                }
830
                else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
831
                {
832
                    double height = Math.Abs(item.X1 - item.X2);
833
                    ConvertAvevaPointX(ref height);
834
                    item.Aveva.Height = height;
835
                }
836

    
837
                if (item.VALUE.Contains(@"\n"))
838
                {
839
                    item.Aveva.LabelType = LabelType.MultiNote;
840
                    int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1;
841
                    item.Aveva.Height = item.Aveva.Height / count;
842
                }
843
                else
844
                    item.Aveva.LabelType = LabelType.SingleNote;
845

    
846
                item.Aveva.Angle = item.ANGLE;
847
            }
848

    
849
            if (!result)
850
                ValidationMessage = validationStringBuilder.ToString();
851

    
852
            return result;
853
        }
854

    
855
        public void ConvertAvevaPoint(ref double x, ref double y)
856
        {
857
            decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX);
858
            decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY);
859
            decimal id2Width = Convert.ToDecimal(SIZE_WIDTH);
860
            decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT);
861

    
862
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
863
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
864
        }
865
        public void ConvertAvevaPointX(ref double x)
866
        {
867
            decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX);
868
            decimal id2Width = Convert.ToDecimal(SIZE_WIDTH);
869

    
870
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
871
        }
872
        public void ConvertAvevaPointY(ref double y)
873
        {
874
            decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY);
875
            decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT);
876

    
877
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
878
        }
879

    
880
        private double RadianToDegree(double angle)
881
        {
882
            return angle * (180.0 / Math.PI);
883
        }
884

    
885
        #endregion
886
    }
887
}
클립보드 이미지 추가 (최대 크기: 500 MB)