프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / Model / PlantItem / Document.cs @ 7a8645c9

이력 | 보기 | 이력해설 | 다운로드 (37.1 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
        }
449

    
450
        private void SetSpecBreakAttribute(SpecBreak specBreak)
451
        {
452
            string upStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "UpStream").VALUE;
453
            string downStream = specBreak.ATTRIBUTES.Find(x => x.ATTRIBUTE == "DownStream").VALUE;
454

    
455
            specBreak.UpStreamUID = upStream;
456
            specBreak.DownStreamUID = downStream;
457
        }
458

    
459
        private void SetLineNumberRuns(XElement node, List<LineRun> lineNumberRuns)
460
        {
461
            foreach (XElement item in node.Elements("RUN"))
462
            {
463
                LineRun run = new LineRun()
464
                {
465
                    TYPE = item.Attribute("TYPE").Value
466
                };
467

    
468
                foreach (XElement element in item.Elements())
469
                {
470
                    if (element.Name == "SYMBOL")
471
                    {
472
                        Symbol symbol = GetSymbolByUID(element.Element("UID").Value);
473
                        Equipment equipment = GetEquipmentByUID(element.Element("UID").Value);
474
                        if (symbol == null && equipment == null)
475
                        {
476
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
477
                            validationStringBuilder.AppendLine();
478
                            validationResult = true;
479
                        }
480
                        if (symbol != null)
481
                            run.RUNITEMS.Add(symbol);
482
                        else if (equipment != null)
483
                            run.RUNITEMS.Add(equipment);
484
                    }
485
                    else if (element.Name == "LINE")
486
                    {
487
                        Line line = GetLineByUID(element.Element("UID").Value);
488
                        if (line == null)
489
                        {
490
                            validationStringBuilder.AppendLine("Missing Item!" + "\r\nUID : " + element.Element("UID").Value);
491
                            validationStringBuilder.AppendLine();
492
                            validationResult = true;
493
                        }
494
                        run.RUNITEMS.Add(line);
495
                    }
496
                }
497
                lineNumberRuns.Add(run);
498
            }
499
        }
500

    
501
        private void SetChildSymbol(Symbol symbol)
502
        {
503
            List<ChildSymbol> childList = new List<ChildSymbol>();
504
            if (!string.IsNullOrEmpty(symbol.CHILD) && symbol.CHILD != "None")
505
            {
506
                string[] childArray = symbol.CHILD.Split(new char[] { '/' });
507
                foreach (string sChild in childArray)
508
                {
509
                    string[] sChildInfo = sChild.Split(new char[] { ',' });
510
                    childList.Add(new ChildSymbol()
511
                    {
512
                        ParentAt = Convert.ToInt32(sChildInfo[0]),
513
                        Direction = sChildInfo[1],
514
                        NAME = sChildInfo[2]
515
                    });
516
                }
517

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

    
544
        private void SetText(XElement node)
545
        {
546
            foreach (XElement item in node.Elements("ATTRIBUTE"))
547
            {
548
                Text text = new Text()
549
                {
550
                    UID = item.Element("UID").Value,
551
                    OWNER = item.Element("OWNER").Value,
552
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
553
                    NAME = item.Element("NAME").Value,
554
                    LOCATION = item.Element("LOCATION").Value,
555
                    VALUE = item.Element("VALUE").Value,
556
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
557
                    WIDTH = item.Element("WIDTH").Value,
558
                    HEIGHT = item.Element("HEIGHT").Value,
559
                    AREA = item.Element("AREA").Value,
560
                    SCENE = item.Element("SCENE").Value
561
                };
562

    
563
                Texts.Add(text);
564
            }
565
        }
566

    
567
        private void SetNote(XElement node)
568
        {
569
            foreach (XElement item in node.Elements("ATTRIBUTE"))
570
            {
571
                Note note = new Note()
572
                {
573
                    UID = item.Element("UID").Value,
574
                    ATTRIBUTEVALUE = item.Element("ATTRIBUTEVALUE").Value,
575
                    NAME = item.Element("NAME").Value,
576
                    LOCATION = item.Element("LOCATION").Value,
577
                    VALUE = item.Element("VALUE").Value,
578
                    ANGLE = Convert.ToDouble(item.Element("ANGLE").Value),
579
                    WIDTH = item.Element("WIDTH").Value,
580
                    HEIGHT = item.Element("HEIGHT").Value,
581
                    AREA = item.Element("AREA").Value,
582
                    SCENE = item.Element("SCENE").Value,
583
                    OWNER = item.Element("OWNER").Value
584
                };
585

    
586
                Notes.Add(note);
587
            }
588
        }
589
        #endregion
590

    
591
        public void SetAllConnectors()
592
        {
593
            foreach (var item in SYMBOLS)
594
                foreach (var connector in item.CONNECTORS)
595
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
596

    
597
            foreach (var item in OPCs)
598
                foreach (var connector in item.CONNECTORS)
599
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
600

    
601
            foreach (var item in LINES)
602
                foreach (var connector in item.CONNECTORS)
603
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
604

    
605
            foreach (var item in Equipments)
606
                foreach (var connector in item.CONNECTORS)
607
                    connector.ConnectedObject = APIDUtils.FindObjectByUID(this, connector.CONNECTEDITEM);
608
        }
609

    
610
        public Symbol GetSymbolByUID(string uid)
611
        {
612
            return SYMBOLS.Find(x => x.UID == uid);
613
        }
614

    
615
        public Equipment GetEquipmentByUID(string uid)
616
        {
617
            return Equipments.Find(x => x.UID == uid);
618
        }
619

    
620
        public Line GetLineByUID(string uid)
621
        {
622
            return LINES.Find(x => x.UID == uid);
623
        }
624

    
625
        #region For Aveva
626
        
627
        public bool SetAvevaInfo(DataTable symbolMappingTable, DataTable lineMappingTable, DataTable opcMappingTable)
628
        {
629
            bool result = true;
630
            foreach (var item in LINES)
631
            {
632
                DataRow[] rows = lineMappingTable.Select(string.Format("UID = '{0}'", item.TYPEUID));
633
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"]))
634
                {
635
                    item.Aveva = new AvevaLineInfo();
636
                    item.Aveva.Name = (string)rows[0]["APID_SYMBOL"];
637
                    double startX = item.Start_X;
638
                    double startY = SIZE_HEIGHT - item.Start_Y;
639
                    double endX = item.End_X;
640
                    double endY = SIZE_HEIGHT - item.End_Y;
641

    
642
                    ConvertAvevaPoint(ref startX, ref startY);
643
                    ConvertAvevaPoint(ref endX, ref endY);
644

    
645
                    item.Aveva.Start_X = startX;
646
                    item.Aveva.Start_Y = startY;
647
                    item.Aveva.End_X = endX;
648
                    item.Aveva.End_Y = endY;
649

    
650
                    if (!DBNull.Value.Equals(rows[0]["DATA1"]))
651
                    {
652
                        if (rows[0]["DATA1"].ToString() == "PIPE")
653
                            item.Aveva.Type = Type.Pipe;
654
                        else if (rows[0]["DATA1"].ToString() == "SIGNAL")
655
                            item.Aveva.Type = Type.Signal;
656
                    }
657
                }
658
                else
659
                    result = false;
660
            }
661
            foreach (var item in SYMBOLS)
662
            {
663
                DataRow[] rows = symbolMappingTable.Select(string.Format("UID = '{0}'", item.DBUID));
664
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["APID_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["APID_SYMBOL"]))
665
                {
666
                    item.Aveva = new AvevaSymbolInfo();
667
                    double x = item.X;
668
                    double y = SIZE_HEIGHT - item.Y;
669

    
670
                    ConvertAvevaPoint(ref x, ref y);
671

    
672
                    item.Aveva.X = x;
673
                    item.Aveva.Y = y;
674

    
675
                    item.Aveva.FullName = (string)rows[0]["APID_SYMBOL"];
676
                    string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
677
                    item.Aveva.Name = split[split.Length - 1];
678
                }
679
                else
680
                    result = false;
681
            }
682
            foreach (var item in OPCs)
683
            {
684
                DataRow[] rows = opcMappingTable.Select(string.Format("UID = '{0}'", item.DBUID));
685
                if (rows.Length == 1 && !DBNull.Value.Equals(rows[0]["IN_SYMBOL"]) && !string.IsNullOrEmpty((string)rows[0]["OUT_SYMBOL"]))
686
                {
687
                    item.Aveva = new AvevaSymbolInfo();
688
                    double x = item.X;
689
                    double y = SIZE_HEIGHT - item.Y;
690

    
691
                    ConvertAvevaPoint(ref x, ref y);
692

    
693
                    item.Aveva.X = x;
694
                    item.Aveva.Y = y;
695

    
696
                    if (item.TYPE == "Piping OPC's")
697
                        item.OPCType = OPCType.Pipe;
698
                    else if (item.TYPE == "Instrument OPC's")
699
                        item.OPCType = OPCType.Signal;
700

    
701
                    Connector connector = item.CONNECTORS.Find(loop =>
702
                    APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM) != null &&
703
                    APIDUtils.FindObjectByUID(this, loop.CONNECTEDITEM).GetType() == typeof(Line));
704
                    if (connector != null)
705
                    {
706
                        // out
707
                        if (item.CONNECTORS.IndexOf(connector) == 0)
708
                        {
709
                            item.Aveva.FullName = (string)rows[0]["OUT_SYMBOL"];
710
                            string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
711
                            item.Aveva.Name = split[split.Length - 1];
712
                            item.FlowType = FlowType.Out;
713
                        }
714
                        // in
715
                        else
716
                        {
717
                            item.Aveva.FullName = (string)rows[0]["IN_SYMBOL"];
718
                            string[] split = item.Aveva.FullName.Split(new char[] { '\\' });
719
                            item.Aveva.Name = split[split.Length - 1];
720
                            item.FlowType = FlowType.In;
721
                        }
722
                    }
723
                    else
724
                        result = false;
725
                }
726
                else
727
                    result = false;
728
            }
729
            foreach (var item in LINENUMBERS)
730
            {
731
                item.Aveva = new AvevaLabelInfo();
732
                double x = (item.X1 + item.X2) / 2;
733
                double y = SIZE_HEIGHT - (item.Y1 + item.Y2) / 2;
734

    
735
                ConvertAvevaPoint(ref x, ref y);
736

    
737
                item.Aveva.X = x;
738
                item.Aveva.Y = y;
739
                item.Aveva.LabelType = LabelType.LineNumber;
740
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
741
            }
742

    
743
            foreach (var item in Texts)
744
            {
745
                item.Aveva = new AvevaLabelInfo();
746

    
747
                double x = item.X1;
748
                double y = SIZE_HEIGHT - item.Y2;
749
                ConvertAvevaPoint(ref x, ref y);
750
                item.Aveva.X = x;
751
                item.Aveva.Y = y;
752

    
753
                if (item.TextAngle == TextAngle.Degree0 || item.TextAngle == TextAngle.Degree180)
754
                {
755
                    double height = Math.Abs(item.Y1 - item.Y2);
756
                    ConvertAvevaPointY(ref height);
757
                    item.Aveva.Height = height;
758
                }
759
                else if (item.TextAngle == TextAngle.Degree90 || item.TextAngle == TextAngle.Degree270)
760
                {
761
                    double height = Math.Abs(item.X1 - item.X2);
762
                    ConvertAvevaPointX(ref height);
763
                    item.Aveva.Height = height;
764
                }
765

    
766
                if (item.VALUE.Contains("\n"))
767
                {
768
                    item.Aveva.LabelType = LabelType.MultiText;
769
                    int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1;
770
                    item.Aveva.Height = item.Aveva.Height / count;
771
                }
772
                else
773
                    item.Aveva.LabelType = LabelType.SingleText;
774

    
775
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
776
            }
777
            foreach (var item in Notes)
778
            {
779
                item.Aveva = new AvevaLabelInfo();
780

    
781
                double x = item.X1;
782
                double y = SIZE_HEIGHT - item.Y2;
783
                ConvertAvevaPoint(ref x, ref y);
784
                item.Aveva.X = x;
785
                item.Aveva.Y = y;
786

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

    
800
                if (item.VALUE.Contains(@"\n"))
801
                {
802
                    item.Aveva.LabelType = LabelType.MultiNote;
803
                    int count = item.VALUE.Length - item.VALUE.Replace("\n", "").Length + 1;
804
                    item.Aveva.Height = item.Aveva.Height / count;
805
                }
806
                else
807
                    item.Aveva.LabelType = LabelType.SingleNote;
808

    
809
                item.Aveva.Angle = RadianToDegree(item.ANGLE);
810
            }
811

    
812
            return result;
813
        }
814

    
815
        public void ConvertAvevaPoint(ref double x, ref double y)
816
        {
817
            decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX);
818
            decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY);
819
            decimal id2Width = Convert.ToDecimal(SIZE_WIDTH);
820
            decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT);
821

    
822
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
823
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
824
        }
825
        public void ConvertAvevaPointX(ref double x)
826
        {
827
            decimal drawingSizeWidth = Convert.ToDecimal(Properties.Settings.Default.DrawingX);
828
            decimal id2Width = Convert.ToDecimal(SIZE_WIDTH);
829

    
830
            x = Convert.ToDouble(drawingSizeWidth / id2Width * Convert.ToDecimal(x));
831
        }
832
        public void ConvertAvevaPointY(ref double y)
833
        {
834
            decimal drawingSizeHeight = Convert.ToDecimal(Properties.Settings.Default.DrawingY);
835
            decimal id2Height = Convert.ToDecimal(SIZE_HEIGHT);
836

    
837
            y = Convert.ToDouble(drawingSizeHeight / id2Height * Convert.ToDecimal(y));
838
        }
839

    
840
        private double RadianToDegree(double angle)
841
        {
842
            return angle * (180.0 / Math.PI);
843
        }
844

    
845
        #endregion
846
    }
847
}
클립보드 이미지 추가 (최대 크기: 500 MB)