프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 16584d30

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

1 bca86986 gaqhf
using System;
2
using System.Collections.Generic;
3
using System.Linq;
4
using System.Text;
5
using System.Threading.Tasks;
6 f1c9dbaa gaqhf
using System.Data;
7 bca86986 gaqhf
using Converter.BaseModel;
8 bca81f4c gaqhf
using Converter.SPPID.Util;
9 bca86986 gaqhf
10 b8e2644e gaqhf
namespace Converter.SPPID.Model
11 bca86986 gaqhf
{
12
    public class SPPID_Document : Document
13
    {
14
        public SPPID_Document(string xmlPath) : base(xmlPath)
15
        {
16 f1c9dbaa gaqhf
            
17 bca86986 gaqhf
        }
18 88365b05 gaqhf
19 39a2a688 gaqhf
        public List<SymbolMapping> SymbolMappings;
20 4b4dbca9 gaqhf
        public List<ChildSymbolMapping> ChildSymbolMappings;
21 39a2a688 gaqhf
        public List<LineMapping> LineMappings;
22
        public List<LineNumberMapping> LineNumberMappings;
23 1efc25a3 gaqhf
        public List<AttributeMapping> AttributeMappings;
24 39a2a688 gaqhf
        public ETCSetting ETCSetting;
25 4d2571ab gaqhf
        public DataTable SymbolTable { get; set; }
26 39a2a688 gaqhf
27 f1c9dbaa gaqhf
        public List<Group> GROUPS = new List<Group>();
28 5dfb8a24 gaqhf
29 bca86986 gaqhf
        public string DrawingName { get; set; }
30
        public string DrawingNumber { get; set; }
31
        public string Unit { get; set; }
32 4314b3f3 gaqhf
        public string Template { get; set; }
33 f947c634 gaqhf
34
        public void SetSPPIDInfo()
35
        {
36
            foreach (var item in SYMBOLS)
37
            {
38 39a2a688 gaqhf
                if (item.SPPID == null)
39
                    item.SPPID = new SPPIDSymbolInfo();
40 4b4dbca9 gaqhf
41
                foreach (var childSymbol in item.ChildSymbols)
42
                {
43
                    if (childSymbol.SPPID == null)
44
                        childSymbol.SPPID = new SPPIDSymbolInfo();
45
                    SetChildSymbolSPPIDInfo(childSymbol);
46
                }
47 39a2a688 gaqhf
            }
48
49
            foreach (var item in LINES)
50
            {
51
                if (item.SPPID == null)
52
                    item.SPPID = new SPPIDLineInfo();
53 1ba9c671 gaqhf
            }
54
55
            foreach (var item in Equipments)
56
            {
57
                if (item.SPPID == null)
58
                    item.SPPID = new SPPIDSymbolInfo();
59
            }
60
61
            foreach (var item in EndBreaks)
62
            {
63
                if (item.SPPID == null)
64
                    item.SPPID = new SPPIDSymbolInfo();
65
            }
66
67 53c81765 gaqhf
            foreach (var item in SpecBreaks)
68
            {
69
                if (item.SPPID == null)
70
                    item.SPPID = new SPPIDSymbolInfo();
71
            }
72
73 1ba9c671 gaqhf
            foreach (var item in LINENUMBERS)
74
            {
75
                if (item.SPPID == null)
76
                    item.SPPID = new SPPIDSymbolInfo();
77
            }
78
79
            foreach (var item in TEXTINFOS)
80
            {
81
                if (item.SPPID == null)
82
                    item.SPPID = new SPPIDSymbolInfo();
83
            }
84
85
            foreach (var item in NOTES)
86
            {
87
                if (item.SPPID == null)
88
                    item.SPPID = new SPPIDSymbolInfo();
89
            }
90
        }
91
92
        public void SetSPPIDLocation(double SPPIDDocumentX, double SPPIDDocumentY)
93
        {
94
            foreach (var item in SYMBOLS)
95
            {
96
                double x = double.NaN;
97
                double y = double.NaN;
98
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
99
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
100 06b40010 gaqhf
101 1ba9c671 gaqhf
                item.SPPID.ORIGINAL_X = x;
102
                item.SPPID.ORIGINAL_Y = y;
103
            }
104
105
            foreach (var item in LINES)
106
            {
107 39a2a688 gaqhf
                double x = double.NaN;
108
                double y = double.NaN;
109
110
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
111 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
112 39a2a688 gaqhf
                item.SPPID.START_X = x;
113
                item.SPPID.START_Y = y;
114
115
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
116 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
117 39a2a688 gaqhf
                item.SPPID.END_X = x;
118
                item.SPPID.END_Y = y;
119
            }
120 809a7640 gaqhf
121
            foreach (var item in Equipments)
122
            {
123
                double x = double.NaN;
124
                double y = double.NaN;
125
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
126 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
127 06b40010 gaqhf
128 809a7640 gaqhf
                item.SPPID.ORIGINAL_X = x;
129
                item.SPPID.ORIGINAL_Y = y;
130
            }
131 3165c259 gaqhf
132
            foreach (var item in EndBreaks)
133
            {
134
                double x = double.NaN;
135
                double y = double.NaN;
136
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
137 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
138 3165c259 gaqhf
                item.SPPID.ORIGINAL_X = x;
139
                item.SPPID.ORIGINAL_Y = y;
140
            }
141 10872260 gaqhf
142 53c81765 gaqhf
            foreach (var item in SpecBreaks)
143
            {
144
                double x = double.NaN;
145
                double y = double.NaN;
146
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
147
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
148
149
                item.SPPID.ORIGINAL_X = x;
150
                item.SPPID.ORIGINAL_Y = y;
151
            }
152
153 10872260 gaqhf
            foreach (var item in LINENUMBERS)
154
            {
155
                double x = double.NaN;
156
                double y = double.NaN;
157
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
158 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
159 10872260 gaqhf
                item.SPPID.ORIGINAL_X = x;
160
                item.SPPID.ORIGINAL_Y = y;
161 1a3a74a8 gaqhf
162
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
163
                double x1 = item.X1;
164
                double y1 = item.Y1;
165
                double x2 = item.X2;
166
                double y2 = item.Y2;
167 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
168
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
169 1a3a74a8 gaqhf
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
170
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
171
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
172
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
173 10872260 gaqhf
            }
174 6b298450 gaqhf
175
            foreach (var item in TEXTINFOS)
176
            {
177
                double x = double.NaN;
178
                double y = double.NaN;
179
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
180 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
181 6b298450 gaqhf
                item.SPPID.ORIGINAL_X = x;
182
                item.SPPID.ORIGINAL_Y = y;
183 1a3a74a8 gaqhf
184
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
185
                double x1 = item.X1;
186
                double y1 = item.Y1;
187
                double x2 = item.X2;
188
                double y2 = item.Y2;
189 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
190
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
191 1a3a74a8 gaqhf
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
192
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
193
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
194
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
195 6b298450 gaqhf
            }
196
197
            foreach (var item in NOTES)
198
            {
199
                double x = double.NaN;
200
                double y = double.NaN;
201
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
202 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
203 6b298450 gaqhf
                item.SPPID.ORIGINAL_X = x;
204
                item.SPPID.ORIGINAL_Y = y;
205 1a3a74a8 gaqhf
206
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
207
                double x1 = item.X1;
208
                double y1 = item.Y1;
209
                double x2 = item.X2;
210
                double y2 = item.Y2;
211 1ba9c671 gaqhf
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
212
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
213 1a3a74a8 gaqhf
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
214
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
215
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
216
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
217 6b298450 gaqhf
            }
218 39a2a688 gaqhf
        }
219 4b4dbca9 gaqhf
220 c01ce90b gaqhf
        /// <summary>
221
        /// 좌표 보정
222
        /// </summary>
223
        public void CoordinateCorrection()
224
        {
225
            foreach (Symbol symbol in SYMBOLS)
226
            {
227
                if (!symbol.SPPID.IsCorrectionX)
228
                {
229
                    List<object> group = new List<object>();
230
                    group.Add(symbol);
231
                    FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.VERTICAL);
232
233
                    List<Symbol> groupSymbols = (from sym in @group
234
                                                 where sym.GetType() == typeof(Symbol)
235
                                                 select sym as Symbol).ToList();
236
237
                    // X 좌표만 보정
238
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionX);
239
                    double value = symbol.SPPID.ORIGINAL_X;
240
                    if (correctionSymbol == null)
241
                        SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value);
242
                    else
243
                        value = correctionSymbol.SPPID.ORIGINAL_X;
244
245
                    foreach (var item in groupSymbols)
246
                    {
247
                        item.SPPID.IsCorrectionX = true;
248
                        item.SPPID.ORIGINAL_X = value;
249
                    }
250
                }
251
252
                if (!symbol.SPPID.IsCorrectionY)
253
                {
254
                    List<object> group = new List<object>();
255
                    group.Add(symbol);
256
                    FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.HORIZONTAL);
257
258
                    List<Symbol> groupSymbols = (from sym in @group
259
                                                 where sym.GetType() == typeof(Symbol)
260
                                                 select sym as Symbol).ToList();
261
262
                    // Y 좌표만 보정
263
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionY);
264
                    double value = symbol.SPPID.ORIGINAL_Y;
265
                    if (correctionSymbol == null)
266
                        SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value);
267
                    else
268
                        value = correctionSymbol.SPPID.ORIGINAL_Y;
269
270
                    foreach (var item in groupSymbols)
271
                    {
272
                        item.SPPID.IsCorrectionY = true;
273
                        item.SPPID.ORIGINAL_Y = value;
274
                    }
275
                }
276
            }
277
        }
278
279
        private void FindGroupBySymbolAndSlopeType(Symbol symbol, List<object> group, SlopeType searchType)
280
        {
281
            foreach (var connector in symbol.CONNECTORS)
282
            {
283
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
284
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
285
                {
286
                    Symbol connSymbol = connectedItem as Symbol;
287
                    SlopeType slopeType = SPPIDUtil.CalcSlope(symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
288
                    if (slopeType == searchType)
289
                    {
290
                        if (!group.Contains(connSymbol))
291
                        {
292
                            group.Add(connSymbol);
293
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
294
                        }
295
                    }
296
                }
297
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
298
                {
299
                    Line connLine = connectedItem as Line;
300 02480ac1 gaqhf
301
                    double lineX = double.NaN;
302
                    double lineY = double.NaN;
303
                    // Symbol의 Connector ScenePoint
304
                    SPPIDUtil.ConvertPointBystring(connector.SCENECONNECTPOINT, ref lineX, ref lineY);
305
                    double symbolX = double.NaN;
306
                    double symbolY = double.NaN;
307
                    SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref symbolX, ref symbolY);
308
309
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
310 c01ce90b gaqhf
                    if (slopeType == searchType)
311
                    {
312
                        if (!group.Contains(connLine))
313
                        {
314
                            group.Add(connLine);
315
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
316
                        }
317
                    }
318
                }
319
            }
320
        }
321
322
        private void FindGroupByLineAndSlopeType(Line Line, List<object> group, SlopeType searchType)
323
        {
324
            foreach (var connector in Line.CONNECTORS)
325
            {
326
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
327
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
328
                {
329
                    Symbol connSymbol = connectedItem as Symbol;
330 02480ac1 gaqhf
331 c01ce90b gaqhf
                    double lineX = double.NaN;
332
                    double lineY = double.NaN;
333 02480ac1 gaqhf
                    // Line의 Connector ScenePoint
334 c01ce90b gaqhf
                    SPPIDUtil.ConvertPointBystring(connector.SCENECONNECTPOINT, ref lineX, ref lineY);
335
                    double symbolX = double.NaN;
336
                    double symbolY = double.NaN;
337
                    SPPIDUtil.ConvertPointBystring(connSymbol.ORIGINALPOINT, ref symbolX, ref symbolY);
338
339
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
340
                    if (slopeType == searchType)
341
                    {
342
                        if (!group.Contains(connSymbol))
343
                        {
344
                            group.Add(connSymbol);
345
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
346
                        }
347
                    }
348
                }
349
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
350
                {
351
                    Line connLine = connectedItem as Line;
352
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
353
                    if (slopeType == searchType)
354
                    {
355
                        if (!group.Contains(connLine))
356
                        {
357
                            group.Add(connLine);
358
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
359
                        }
360
                    }
361
                }
362
            }
363
        }
364
365 4b4dbca9 gaqhf
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
366
        {
367
            foreach (var childSymbol in item.ChildSymbols)
368
            {
369
                if (childSymbol.SPPID == null)
370
                    childSymbol.SPPID = new SPPIDSymbolInfo();
371
                SetChildSymbolSPPIDInfo(childSymbol);
372
            }
373
        }
374
      
375 39a2a688 gaqhf
        public bool SetSPPIDMapping()
376
        {
377
            foreach (var item in SYMBOLS)
378
            {
379
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
380
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
381
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
382
                    return false;
383 4b4dbca9 gaqhf
384
                foreach (var childSymbol in item.ChildSymbols)
385
                {
386
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
387
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
388
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
389
                        return false;
390
                }
391 39a2a688 gaqhf
            }
392
393
            foreach (var item in LINES)
394
            {
395
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
396
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
397
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
398
                    return false;
399 f947c634 gaqhf
            }
400
401 809a7640 gaqhf
            foreach (var item in Equipments)
402
            {
403
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
404
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
405
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
406
                    return false;
407
            }
408
409 3165c259 gaqhf
            foreach (var item in EndBreaks)
410
            {
411
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
412
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
413
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
414
                    return false;
415
            }
416
417 10872260 gaqhf
            foreach (var item in LINENUMBERS)
418
            {
419
                if (LineNumberMappings.Count > 0)
420
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
421
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
422
                    return false;
423
            }
424
425 6b298450 gaqhf
            ETCSetting etc = ETCSetting.GetInstance();
426
            foreach (var item in NOTES)
427
            {
428
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
429
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
430
                    return false;
431
            }
432
433
            foreach (var item in TEXTINFOS)
434
            {
435
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
436
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
437
                    return false;
438
            }
439 4b4dbca9 gaqhf
440 39a2a688 gaqhf
            return true;
441 f947c634 gaqhf
        }
442 5dfb8a24 gaqhf
443 4b4dbca9 gaqhf
        private bool SetChildSymbolMapping(ChildSymbol item)
444
        {
445
            foreach (var childSymbol in item.ChildSymbols)
446
            {
447
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
448
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
449
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
450
                    return false;
451
                else
452
                    return SetChildSymbolMapping(childSymbol);
453
            }
454
455
            return true;
456
        }
457 bca86986 gaqhf
    }
458
}
클립보드 이미지 추가 (최대 크기: 500 MB)