프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Model / SPPID_Document.cs @ 809a7640

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

1
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6
using System.Data;
7
using Converter.BaseModel;
8
using Converter.SPPID.Util;
9

    
10
namespace Converter.SPPID.Model
11
{
12
    public class SPPID_Document : Document
13
    {
14
        public SPPID_Document(string xmlPath) : base(xmlPath)
15
        {
16
            
17
        }
18

    
19
        private double testX = 0.855;
20
        private double testY = 0.55;
21

    
22
        public List<SymbolMapping> SymbolMappings;
23
        public List<LineMapping> LineMappings;
24
        public List<LineNumberMapping> LineNumberMappings;
25
        public List<AssociationMapping> AssociationMappings;
26
        public ETCSetting ETCSetting;
27

    
28
        public List<Group> GROUPS = new List<Group>();
29

    
30
        public string DrawingName { get; set; }
31
        public string DrawingNumber { get; set; }
32
        public string Unit { get; set; }
33
        public string Template { get; set; }
34

    
35
        public void SetSPPIDInfo()
36
        {
37
            foreach (var item in SYMBOLS)
38
            {
39
                if (item.SPPID == null)
40
                    item.SPPID = new SPPIDSymbolInfo();
41
                double x = double.NaN;
42
                double y = double.NaN;
43
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
44
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
45
                item.SPPID.ORIGINAL_X = x;
46
                item.SPPID.ORIGINAL_Y = y;
47
            }
48

    
49
            foreach (var item in LINES)
50
            {
51
                if (item.SPPID == null)
52
                    item.SPPID = new SPPIDLineInfo();
53
                double x = double.NaN;
54
                double y = double.NaN;
55

    
56
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
57
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
58
                item.SPPID.START_X = x;
59
                item.SPPID.START_Y = y;
60

    
61
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
62
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
63
                item.SPPID.END_X = x;
64
                item.SPPID.END_Y = y;
65
            }
66

    
67
            foreach (var item in Equipments)
68
            {
69
                if (item.SPPID == null)
70
                    item.SPPID = new SPPIDSymbolInfo();
71
                double x = double.NaN;
72
                double y = double.NaN;
73
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
74
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
75
                item.SPPID.ORIGINAL_X = x;
76
                item.SPPID.ORIGINAL_Y = y;
77
            }
78
        }
79
        
80
        public bool SetSPPIDMapping()
81
        {
82
            foreach (var item in SYMBOLS)
83
            {
84
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
85
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
86
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
87
                    return false;
88
            }
89

    
90
            foreach (var item in LINES)
91
            {
92
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
93
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
94
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
95
                    return false;
96
            }
97

    
98
            foreach (var item in Equipments)
99
            {
100
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
101
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
102
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
103
                    return false;
104
            }
105

    
106
            return true;
107
        }
108

    
109
        #region Grouping Source
110
        private bool SetGrouping()
111
        {
112
            try
113
            {
114
                // Line 기준으로 묶음
115
                foreach (Line item in LINES)
116
                    if (!item.SPPID.IsGroup)
117
                        SetGroupingByItem(item);
118
                // End
119

    
120
                // Symbol 기준으로 묶음
121
                foreach (Symbol item in SYMBOLS)
122
                    if (!item.SPPID.IsGroup)
123
                        SetGroupingByItem(item);
124
                // End
125
            }
126
            catch (Exception ex)
127
            {
128
                return false;
129
            }
130
            return true;
131
        }
132

    
133
        private void SetGroupingByItem(object item)
134
        {
135
            Group group = new Group();
136
            group.Items.Add(item);
137
            bool forward = true;
138
            SetGroupingByConnectedItem(item, group.Items, ref forward);
139

    
140
            GROUPS.Add(group);
141
        }
142

    
143
        private void SetGroupingByConnectedItem(object item, List<object> list, ref bool IsForward)
144
        {
145
            if (typeof(Line) == item.GetType())
146
            {
147
                Line line = item as Line;
148
                line.SPPID.IsGroup = true;
149
                SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, line.CONNECTORS);
150
            }
151
            else if (typeof(Symbol) == item.GetType())
152
            {
153
                Symbol symbol = item as Symbol;
154
                symbol.SPPID.IsGroup = true;
155
                // Symbol의 경우 BaseSymbol Connector가 2개 이하때 진행 / 나머지는 Grouping 종료
156
                int baseSymbolCount = 0;
157
                if (symbol.CONNECTORS.Count > 0)
158
                {
159
                    foreach (Connector symbolConnector in symbol.CONNECTORS)
160
                        if (symbolConnector.Index == 0)
161
                            baseSymbolCount++;
162

    
163
                    if (baseSymbolCount <= 2)
164
                        SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, symbol.CONNECTORS);
165
                }
166
            }
167
            IsForward = false;
168
        }
169

    
170
        private void SetGroupingByConnectedItem_ConnectorsLogic(object item, List<object> list, ref bool IsForward, List<Connector> connectors)
171
        {
172
            foreach (Connector connector in connectors)
173
            {
174
                object connItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
175
                if (connItem != null)
176
                {
177
                    bool result = false;
178
                    if (typeof(Line) == connItem.GetType())
179
                    {
180
                        Line connLine = connItem as Line;
181
                        // 연결되는 Item이 전부 Line일 경우 Branch, Line Type을 확인
182
                        if (item.GetType() == connLine.GetType())
183
                        {
184
                            Line line = item as Line;
185
                            if (SPPIDUtil.IsBranchLine(line.UID, connLine) || line.SPPID.MAPPINGNAME != connLine.SPPID.MAPPINGNAME)
186
                                continue;
187
                        }
188

    
189
                        result = true;
190
                    }
191
                    else if (typeof(Symbol) == connItem.GetType())
192
                    {
193
                        Symbol connSymbol = connItem as Symbol;
194
                        // 연결되는 Symbol의 Connector가 부가 심볼일 경우는 result = false
195
                        foreach (Connector symbolConnector in connSymbol.CONNECTORS)
196
                        {
197
                            string itemUID = item as Symbol != null ? ((Symbol)item).UID : ((Line)item).UID;
198

    
199
                            if (symbolConnector.CONNECTEDITEM == itemUID)
200
                            {
201
                                if (symbolConnector.Index == 0)
202
                                    result = true;
203
                                else
204
                                    result = false;
205
                                break;
206
                            }
207
                        }
208
                    }
209

    
210
                    if (!(connItem as Symbol != null ? ((Symbol)connItem).SPPID.IsGroup : ((Line)connItem).SPPID.IsGroup) && result)
211
                    {
212
                        if (IsForward)
213
                            list.Add(connItem);
214
                        else
215
                            list.Insert(0, connItem);
216
                        SetGroupingByConnectedItem(connItem, list, ref IsForward);
217
                    }
218
                }
219
            }
220
        }
221
        #endregion
222
    }
223
}
클립보드 이미지 추가 (최대 크기: 500 MB)