프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 1ed39474

이력 | 보기 | 이력해설 | 다운로드 (18.7 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 1ed39474 gaqhf
                    Connector otherConnector = connLine.CONNECTORS.Find(x => x.CONNECTEDITEM != symbol.UID);
302
303 02480ac1 gaqhf
                    double lineX = double.NaN;
304
                    double lineY = double.NaN;
305
                    // Symbol의 Connector ScenePoint
306 1ed39474 gaqhf
                    SPPIDUtil.ConvertPointBystring(otherConnector.SCENECONNECTPOINT, ref lineX, ref lineY);
307 02480ac1 gaqhf
                    double symbolX = double.NaN;
308
                    double symbolY = double.NaN;
309
                    SPPIDUtil.ConvertPointBystring(symbol.ORIGINALPOINT, ref symbolX, ref symbolY);
310
311
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
312 c01ce90b gaqhf
                    if (slopeType == searchType)
313
                    {
314
                        if (!group.Contains(connLine))
315
                        {
316
                            group.Add(connLine);
317
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
318
                        }
319
                    }
320
                }
321
            }
322
        }
323
324
        private void FindGroupByLineAndSlopeType(Line Line, List<object> group, SlopeType searchType)
325
        {
326
            foreach (var connector in Line.CONNECTORS)
327
            {
328
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
329
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
330
                {
331
                    Symbol connSymbol = connectedItem as Symbol;
332 02480ac1 gaqhf
333 1ed39474 gaqhf
                    Connector otherConnector = Line.CONNECTORS.Find(x => x.CONNECTEDITEM != connSymbol.UID);
334
335 c01ce90b gaqhf
                    double lineX = double.NaN;
336
                    double lineY = double.NaN;
337 02480ac1 gaqhf
                    // Line의 Connector ScenePoint
338 1ed39474 gaqhf
                    SPPIDUtil.ConvertPointBystring(otherConnector.SCENECONNECTPOINT, ref lineX, ref lineY);
339 c01ce90b gaqhf
                    double symbolX = double.NaN;
340
                    double symbolY = double.NaN;
341
                    SPPIDUtil.ConvertPointBystring(connSymbol.ORIGINALPOINT, ref symbolX, ref symbolY);
342
343
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
344
                    if (slopeType == searchType)
345
                    {
346
                        if (!group.Contains(connSymbol))
347
                        {
348
                            group.Add(connSymbol);
349
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
350
                        }
351
                    }
352
                }
353
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
354
                {
355
                    Line connLine = connectedItem as Line;
356
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
357
                    if (slopeType == searchType)
358
                    {
359
                        if (!group.Contains(connLine))
360
                        {
361
                            group.Add(connLine);
362
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
363
                        }
364
                    }
365
                }
366
            }
367
        }
368
369 4b4dbca9 gaqhf
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
370
        {
371
            foreach (var childSymbol in item.ChildSymbols)
372
            {
373
                if (childSymbol.SPPID == null)
374
                    childSymbol.SPPID = new SPPIDSymbolInfo();
375
                SetChildSymbolSPPIDInfo(childSymbol);
376
            }
377
        }
378
      
379 39a2a688 gaqhf
        public bool SetSPPIDMapping()
380
        {
381
            foreach (var item in SYMBOLS)
382
            {
383
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
384
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
385
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
386
                    return false;
387 4b4dbca9 gaqhf
388
                foreach (var childSymbol in item.ChildSymbols)
389
                {
390
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
391
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
392
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
393
                        return false;
394
                }
395 39a2a688 gaqhf
            }
396
397
            foreach (var item in LINES)
398
            {
399
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
400
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
401
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
402
                    return false;
403 f947c634 gaqhf
            }
404
405 809a7640 gaqhf
            foreach (var item in Equipments)
406
            {
407
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
408
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
409
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
410
                    return false;
411
            }
412
413 3165c259 gaqhf
            foreach (var item in EndBreaks)
414
            {
415
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
416
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
417
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
418
                    return false;
419
            }
420
421 10872260 gaqhf
            foreach (var item in LINENUMBERS)
422
            {
423
                if (LineNumberMappings.Count > 0)
424
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
425
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
426
                    return false;
427
            }
428
429 6b298450 gaqhf
            ETCSetting etc = ETCSetting.GetInstance();
430
            foreach (var item in NOTES)
431
            {
432
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
433
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
434
                    return false;
435
            }
436
437
            foreach (var item in TEXTINFOS)
438
            {
439
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
440
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
441
                    return false;
442
            }
443 4b4dbca9 gaqhf
444 39a2a688 gaqhf
            return true;
445 f947c634 gaqhf
        }
446 5dfb8a24 gaqhf
447 4b4dbca9 gaqhf
        private bool SetChildSymbolMapping(ChildSymbol item)
448
        {
449
            foreach (var childSymbol in item.ChildSymbols)
450
            {
451
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
452
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
453
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
454
                    return false;
455
                else
456
                    return SetChildSymbolMapping(childSymbol);
457
            }
458
459
            return true;
460
        }
461 bca86986 gaqhf
    }
462
}
클립보드 이미지 추가 (최대 크기: 500 MB)