프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / Model / SPPID_Document.cs @ 4b4dbca9

이력 | 보기 | 이력해설 | 다운로드 (13.2 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<ChildSymbolMapping> ChildSymbolMappings;
24
        public List<LineMapping> LineMappings;
25
        public List<LineNumberMapping> LineNumberMappings;
26
        public List<AttributeMapping> AttributeMappings;
27
        public ETCSetting ETCSetting;
28

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

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

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

    
50
                foreach (var childSymbol in item.ChildSymbols)
51
                {
52
                    if (childSymbol.SPPID == null)
53
                        childSymbol.SPPID = new SPPIDSymbolInfo();
54
                    SetChildSymbolSPPIDInfo(childSymbol);
55
                }
56
            }
57

    
58
            foreach (var item in LINES)
59
            {
60
                if (item.SPPID == null)
61
                    item.SPPID = new SPPIDLineInfo();
62
                double x = double.NaN;
63
                double y = double.NaN;
64

    
65
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
66
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
67
                item.SPPID.START_X = x;
68
                item.SPPID.START_Y = y;
69

    
70
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
71
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
72
                item.SPPID.END_X = x;
73
                item.SPPID.END_Y = y;
74
            }
75

    
76
            foreach (var item in Equipments)
77
            {
78
                if (item.SPPID == null)
79
                    item.SPPID = new SPPIDSymbolInfo();
80
                double x = double.NaN;
81
                double y = double.NaN;
82
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
83
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
84
                item.SPPID.ORIGINAL_X = x;
85
                item.SPPID.ORIGINAL_Y = y;
86
            }
87

    
88
            foreach (var item in EndBreaks)
89
            {
90
                if (item.SPPID == null)
91
                    item.SPPID = new SPPIDSymbolInfo();
92
                double x = double.NaN;
93
                double y = double.NaN;
94
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
95
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
96
                item.SPPID.ORIGINAL_X = x;
97
                item.SPPID.ORIGINAL_Y = y;
98
            }
99

    
100
            foreach (var item in LINENUMBERS)
101
            {
102
                if (item.SPPID == null)
103
                    item.SPPID = new SPPIDSymbolInfo();
104
                double x = double.NaN;
105
                double y = double.NaN;
106
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
107
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
108
                item.SPPID.ORIGINAL_X = x;
109
                item.SPPID.ORIGINAL_Y = y;
110
            }
111

    
112
            foreach (var item in TEXTINFOS)
113
            {
114
                if (item.SPPID == null)
115
                    item.SPPID = new SPPIDSymbolInfo();
116
                double x = double.NaN;
117
                double y = double.NaN;
118
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
119
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
120
                item.SPPID.ORIGINAL_X = x;
121
                item.SPPID.ORIGINAL_Y = y;
122
            }
123

    
124
            foreach (var item in NOTES)
125
            {
126
                if (item.SPPID == null)
127
                    item.SPPID = new SPPIDSymbolInfo();
128
                double x = double.NaN;
129
                double y = double.NaN;
130
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
131
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY);
132
                item.SPPID.ORIGINAL_X = x;
133
                item.SPPID.ORIGINAL_Y = y;
134
            }
135
        }
136

    
137
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
138
        {
139
            foreach (var childSymbol in item.ChildSymbols)
140
            {
141
                if (childSymbol.SPPID == null)
142
                    childSymbol.SPPID = new SPPIDSymbolInfo();
143
                SetChildSymbolSPPIDInfo(childSymbol);
144
            }
145
        }
146
      
147
        public bool SetSPPIDMapping()
148
        {
149
            foreach (var item in SYMBOLS)
150
            {
151
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
152
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
153
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
154
                    return false;
155

    
156
                foreach (var childSymbol in item.ChildSymbols)
157
                {
158
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
159
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
160
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
161
                        return false;
162
                }
163
            }
164

    
165
            foreach (var item in LINES)
166
            {
167
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
168
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
169
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
170
                    return false;
171
            }
172

    
173
            foreach (var item in Equipments)
174
            {
175
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
176
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
177
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
178
                    return false;
179
            }
180

    
181
            foreach (var item in EndBreaks)
182
            {
183
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
184
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
185
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
186
                    return false;
187
            }
188

    
189
            foreach (var item in LINENUMBERS)
190
            {
191
                if (LineNumberMappings.Count > 0)
192
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
193
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
194
                    return false;
195
            }
196

    
197
            ETCSetting etc = ETCSetting.GetInstance();
198
            foreach (var item in NOTES)
199
            {
200
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
201
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
202
                    return false;
203
            }
204

    
205
            foreach (var item in TEXTINFOS)
206
            {
207
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
208
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
209
                    return false;
210
            }
211

    
212
            return true;
213
        }
214

    
215
        private bool SetChildSymbolMapping(ChildSymbol item)
216
        {
217
            foreach (var childSymbol in item.ChildSymbols)
218
            {
219
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
220
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
221
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
222
                    return false;
223
                else
224
                    return SetChildSymbolMapping(childSymbol);
225
            }
226

    
227
            return true;
228
        }
229
        #region Grouping Source
230
        private bool SetGrouping()
231
        {
232
            try
233
            {
234
                // Line 기준으로 묶음
235
                foreach (Line item in LINES)
236
                    if (!item.SPPID.IsGroup)
237
                        SetGroupingByItem(item);
238
                // End
239

    
240
                // Symbol 기준으로 묶음
241
                foreach (Symbol item in SYMBOLS)
242
                    if (!item.SPPID.IsGroup)
243
                        SetGroupingByItem(item);
244
                // End
245
            }
246
            catch (Exception ex)
247
            {
248
                return false;
249
            }
250
            return true;
251
        }
252

    
253
        private void SetGroupingByItem(object item)
254
        {
255
            Group group = new Group();
256
            group.Items.Add(item);
257
            bool forward = true;
258
            SetGroupingByConnectedItem(item, group.Items, ref forward);
259

    
260
            GROUPS.Add(group);
261
        }
262

    
263
        private void SetGroupingByConnectedItem(object item, List<object> list, ref bool IsForward)
264
        {
265
            if (typeof(Line) == item.GetType())
266
            {
267
                Line line = item as Line;
268
                line.SPPID.IsGroup = true;
269
                SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, line.CONNECTORS);
270
            }
271
            else if (typeof(Symbol) == item.GetType())
272
            {
273
                Symbol symbol = item as Symbol;
274
                symbol.SPPID.IsGroup = true;
275
                // Symbol의 경우 BaseSymbol Connector가 2개 이하때 진행 / 나머지는 Grouping 종료
276
                int baseSymbolCount = 0;
277
                if (symbol.CONNECTORS.Count > 0)
278
                {
279
                    foreach (Connector symbolConnector in symbol.CONNECTORS)
280
                        if (symbolConnector.Index == 0)
281
                            baseSymbolCount++;
282

    
283
                    if (baseSymbolCount <= 2)
284
                        SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, symbol.CONNECTORS);
285
                }
286
            }
287
            IsForward = false;
288
        }
289

    
290
        private void SetGroupingByConnectedItem_ConnectorsLogic(object item, List<object> list, ref bool IsForward, List<Connector> connectors)
291
        {
292
            foreach (Connector connector in connectors)
293
            {
294
                object connItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
295
                if (connItem != null)
296
                {
297
                    bool result = false;
298
                    if (typeof(Line) == connItem.GetType())
299
                    {
300
                        Line connLine = connItem as Line;
301
                        // 연결되는 Item이 전부 Line일 경우 Branch, Line Type을 확인
302
                        if (item.GetType() == connLine.GetType())
303
                        {
304
                            Line line = item as Line;
305
                            if (SPPIDUtil.IsBranchLine(line.UID, connLine) || line.SPPID.MAPPINGNAME != connLine.SPPID.MAPPINGNAME)
306
                                continue;
307
                        }
308

    
309
                        result = true;
310
                    }
311
                    else if (typeof(Symbol) == connItem.GetType())
312
                    {
313
                        Symbol connSymbol = connItem as Symbol;
314
                        // 연결되는 Symbol의 Connector가 부가 심볼일 경우는 result = false
315
                        foreach (Connector symbolConnector in connSymbol.CONNECTORS)
316
                        {
317
                            string itemUID = item as Symbol != null ? ((Symbol)item).UID : ((Line)item).UID;
318

    
319
                            if (symbolConnector.CONNECTEDITEM == itemUID)
320
                            {
321
                                if (symbolConnector.Index == 0)
322
                                    result = true;
323
                                else
324
                                    result = false;
325
                                break;
326
                            }
327
                        }
328
                    }
329

    
330
                    if (!(connItem as Symbol != null ? ((Symbol)connItem).SPPID.IsGroup : ((Line)connItem).SPPID.IsGroup) && result)
331
                    {
332
                        if (IsForward)
333
                            list.Add(connItem);
334
                        else
335
                            list.Insert(0, connItem);
336
                        SetGroupingByConnectedItem(connItem, list, ref IsForward);
337
                    }
338
                }
339
            }
340
        }
341
        #endregion
342
    }
343
}
클립보드 이미지 추가 (최대 크기: 500 MB)