프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / ID2PSN / Object / Item.cs @ 0f07fa34

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

1
using DevExpress.XtraGrid.Views.Layout;
2
using System;
3
using System.Collections.Generic;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7

    
8
namespace ID2PSN
9
{
10
    public enum ItemType
11
    {
12
        None,
13
        Symbol,
14
        Line
15
    }
16
    public enum SubItemType
17
    {
18
        None,
19
        OPC,
20
        Header,
21
        Nozzle,
22
    }
23

    
24
    public class Item
25
    {
26
        public Item()
27
        {
28
            BranchItems = new List<Item>();
29
            Attributes = new List<Attribute>();
30
        }
31

    
32
        public string UID { get; set; }
33
        public string Type { get; set; }
34
        public string Name { get; set; }
35
        public string Owner { get; set; }
36
        public string Parent { get; set; }
37
        public string ANGLE { get; set; }
38
        public double[] POINT { get; set; }
39
        public List<Relation> Relations { get; set; }
40
        public List<Attribute> Attributes { get; set; }
41
        public ItemType ItemType { get; set; }
42
        public SubItemType SubItemType { get; set; }
43
        public List<Item> BranchItems { get; set; }
44
        public string TopologyData { get; set; }
45
        public string PSNPipeLineID { get; set; }
46
        public Topology Topology { get; set; }
47
        public LineNumber LineNumber { get; set; }
48
        public Equipment Equipment { get; set; }
49
    }
50

    
51
    public class Relation 
52
    { 
53
        public string UID { get; set; }
54
        public Item Item { get; set; }
55
        public double[] Point { get; set; }
56
    }
57
    public class Attribute
58
    {
59
        public string UID { get; set; }
60
        public string Name { get; set; }
61
        public string DisplayName { get; set; }
62
        public string Value { get; set; }
63
    }
64
    public class Equipment
65
    {
66
        public Equipment()
67
        {
68
            POINT = new List<double[]>();
69
            Nozzles = new List<Item>();
70
        }
71
        public string Name { get; set; }
72
        public string UID { get; set; }
73
        public List<double[]> POINT { get; set; }
74
        public List<Item> Nozzles { get; set; }
75
    }
76
    public class LineNumber
77
    {
78
        public LineNumber()
79
        {
80
            Attributes = new List<Attribute>();
81
        }
82
        public string UID { get; set; }
83
        public string Name { get; set; }
84
        public List<Attribute> Attributes { get; set; }
85
    }
86

    
87
    public class RunInfo 
88
    { 
89
        public RunInfo()
90
        {
91
            Items = new List<Item>();
92
        }
93
        public string UID { get; set; }
94
        public int Index { get; set; }
95
        public List<Item> Items { get; set; }
96
    }
97

    
98
    public class Group
99
    {
100
        public Group(Document document)
101
        {
102
            _Document = document;
103
        }
104
        public Group StartGroup { get; set; }
105
        public Group EndGroup { get; set; }
106
        public string UID { get; set; }
107
        public List<Item> Items { get; set; }
108
        private Document _Document;
109
        public Document Document { get { return _Document; } }
110
        public void SortItems()
111
        {
112
            List<Item> sorted = new List<Item>();
113
            Item line = Items.Find(x => x.ItemType == ItemType.Line);
114
            if (line != null)
115
            {
116
                sorted.Add(line);
117
                Item startItem = line.Relations[0].Item;
118
                if (startItem != null)
119
                {
120
                    Stack<Item> stacks = new Stack<Item>();
121
                    stacks.Push(startItem);
122
                    while (stacks.Count > 0)
123
                    {
124
                        Item stack = stacks.Pop();
125
                        if (sorted.Contains(stack))
126
                            continue;
127

    
128
                        if (Items.Contains(stack))
129
                        {
130
                            sorted.Insert(0, stack); 
131
                            foreach (var relation in stack.Relations)
132
                            {
133
                                if (relation.Item == null || !Items.Contains(relation.Item))
134
                                    continue;
135
                                stacks.Push(relation.Item);
136
                            }
137
                        }
138
                    }
139
                }
140
                Item endItem = line.Relations[1].Item;
141
                if (endItem != null)
142
                {
143
                    Stack<Item> stacks = new Stack<Item>();
144
                    stacks.Push(endItem);
145
                    while (stacks.Count > 0)
146
                    {
147
                        Item stack = stacks.Pop();
148
                        if (sorted.Contains(stack))
149
                            continue;
150

    
151
                        if (Items.Contains(stack))
152
                        {
153
                            sorted.Add(stack);
154
                            foreach (var relation in stack.Relations)
155
                            {
156
                                if (relation.Item == null || !Items.Contains(relation.Item))
157
                                    continue;
158
                                stacks.Push(relation.Item);
159
                            }
160
                        }
161
                    }
162
                }
163

    
164
                if (!sorted.Count.Equals(Items.Count))
165
                    throw new Exception("logic error");
166

    
167
                Items = sorted;
168
            }
169
            else
170
            {
171

    
172
            }
173
        }
174
    }
175

    
176
    public class Topology
177
    {
178
        public Topology()
179
        {
180
            Items = new List<Item>();
181
        }
182
        public string ID { get; set; }
183
        public string Type { get; set; }
184
        public string Index { get; set; }
185
        public string FullName { get { return ID + "-" + Type + Index; } }
186
        public List<Item> Items { get; set; }
187
    }
188
}