프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 53c81765

이력 | 보기 | 이력해설 | 다운로드 (18.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
        public List<SymbolMapping> SymbolMappings;
20
        public List<ChildSymbolMapping> ChildSymbolMappings;
21
        public List<LineMapping> LineMappings;
22
        public List<LineNumberMapping> LineNumberMappings;
23
        public List<AttributeMapping> AttributeMappings;
24
        public ETCSetting ETCSetting;
25
        public DataTable SymbolTable { get; set; }
26

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

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

    
34
        public void SetSPPIDInfo()
35
        {
36
            foreach (var item in SYMBOLS)
37
            {
38
                if (item.SPPID == null)
39
                    item.SPPID = new SPPIDSymbolInfo();
40

    
41
                foreach (var childSymbol in item.ChildSymbols)
42
                {
43
                    if (childSymbol.SPPID == null)
44
                        childSymbol.SPPID = new SPPIDSymbolInfo();
45
                    SetChildSymbolSPPIDInfo(childSymbol);
46
                }
47
            }
48

    
49
            foreach (var item in LINES)
50
            {
51
                if (item.SPPID == null)
52
                    item.SPPID = new SPPIDLineInfo();
53
            }
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
            foreach (var item in SpecBreaks)
68
            {
69
                if (item.SPPID == null)
70
                    item.SPPID = new SPPIDSymbolInfo();
71
            }
72

    
73
            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

    
101
                item.SPPID.ORIGINAL_X = x;
102
                item.SPPID.ORIGINAL_Y = y;
103
            }
104

    
105
            foreach (var item in LINES)
106
            {
107
                double x = double.NaN;
108
                double y = double.NaN;
109

    
110
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
111
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
112
                item.SPPID.START_X = x;
113
                item.SPPID.START_Y = y;
114

    
115
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
116
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
117
                item.SPPID.END_X = x;
118
                item.SPPID.END_Y = y;
119
            }
120

    
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
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
127

    
128
                item.SPPID.ORIGINAL_X = x;
129
                item.SPPID.ORIGINAL_Y = y;
130
            }
131

    
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
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
138
                item.SPPID.ORIGINAL_X = x;
139
                item.SPPID.ORIGINAL_Y = y;
140
            }
141

    
142
            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
            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
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
159
                item.SPPID.ORIGINAL_X = x;
160
                item.SPPID.ORIGINAL_Y = y;
161

    
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
                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
                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
            }
174

    
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
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
181
                item.SPPID.ORIGINAL_X = x;
182
                item.SPPID.ORIGINAL_Y = y;
183

    
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
                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
                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
            }
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
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
203
                item.SPPID.ORIGINAL_X = x;
204
                item.SPPID.ORIGINAL_Y = y;
205

    
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
                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
                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
            }
218
        }
219

    
220
        /// <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
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
301
                    if (slopeType == searchType)
302
                    {
303
                        if (!group.Contains(connLine))
304
                        {
305
                            group.Add(connLine);
306
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
307
                        }
308
                    }
309
                }
310
            }
311
        }
312

    
313
        private void FindGroupByLineAndSlopeType(Line Line, List<object> group, SlopeType searchType)
314
        {
315
            foreach (var connector in Line.CONNECTORS)
316
            {
317
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
318
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
319
                {
320
                    Symbol connSymbol = connectedItem as Symbol;
321
                    double lineX = double.NaN;
322
                    double lineY = double.NaN;
323
                    SPPIDUtil.ConvertPointBystring(connector.SCENECONNECTPOINT, ref lineX, ref lineY);
324
                    double symbolX = double.NaN;
325
                    double symbolY = double.NaN;
326
                    SPPIDUtil.ConvertPointBystring(connSymbol.ORIGINALPOINT, ref symbolX, ref symbolY);
327

    
328
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
329
                    if (slopeType == searchType)
330
                    {
331
                        if (!group.Contains(connSymbol))
332
                        {
333
                            group.Add(connSymbol);
334
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
335
                        }
336
                    }
337
                }
338
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
339
                {
340
                    Line connLine = connectedItem as Line;
341
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
342
                    if (slopeType == searchType)
343
                    {
344
                        if (!group.Contains(connLine))
345
                        {
346
                            group.Add(connLine);
347
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
348
                        }
349
                    }
350
                }
351
            }
352
        }
353

    
354
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
355
        {
356
            foreach (var childSymbol in item.ChildSymbols)
357
            {
358
                if (childSymbol.SPPID == null)
359
                    childSymbol.SPPID = new SPPIDSymbolInfo();
360
                SetChildSymbolSPPIDInfo(childSymbol);
361
            }
362
        }
363
      
364
        public bool SetSPPIDMapping()
365
        {
366
            foreach (var item in SYMBOLS)
367
            {
368
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
369
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
370
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
371
                    return false;
372

    
373
                foreach (var childSymbol in item.ChildSymbols)
374
                {
375
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
376
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
377
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
378
                        return false;
379
                }
380
            }
381

    
382
            foreach (var item in LINES)
383
            {
384
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
385
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
386
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
387
                    return false;
388
            }
389

    
390
            foreach (var item in Equipments)
391
            {
392
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
393
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
394
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
395
                    return false;
396
            }
397

    
398
            foreach (var item in EndBreaks)
399
            {
400
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
401
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
402
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
403
                    return false;
404
            }
405

    
406
            foreach (var item in SpecBreaks)
407
            {
408
                item.SPPID.MAPPINGNAME = @"\Piping\Segment Breaks\Piping Materials Class.sym";
409
            }
410

    
411
            foreach (var item in LINENUMBERS)
412
            {
413
                if (LineNumberMappings.Count > 0)
414
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
415
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
416
                    return false;
417
            }
418

    
419
            ETCSetting etc = ETCSetting.GetInstance();
420
            foreach (var item in NOTES)
421
            {
422
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
423
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
424
                    return false;
425
            }
426

    
427
            foreach (var item in TEXTINFOS)
428
            {
429
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
430
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
431
                    return false;
432
            }
433

    
434
            return true;
435
        }
436

    
437
        private bool SetChildSymbolMapping(ChildSymbol item)
438
        {
439
            foreach (var childSymbol in item.ChildSymbols)
440
            {
441
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
442
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
443
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
444
                    return false;
445
                else
446
                    return SetChildSymbolMapping(childSymbol);
447
            }
448

    
449
            return true;
450
        }
451
    }
452
}
클립보드 이미지 추가 (최대 크기: 500 MB)