프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ c01ce90b

이력 | 보기 | 이력해설 | 다운로드 (17.4 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

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

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

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

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

    
48
            foreach (var item in LINES)
49
            {
50
                if (item.SPPID == null)
51
                    item.SPPID = new SPPIDLineInfo();
52
            }
53

    
54
            foreach (var item in Equipments)
55
            {
56
                if (item.SPPID == null)
57
                    item.SPPID = new SPPIDSymbolInfo();
58
            }
59

    
60
            foreach (var item in EndBreaks)
61
            {
62
                if (item.SPPID == null)
63
                    item.SPPID = new SPPIDSymbolInfo();
64
            }
65

    
66
            foreach (var item in LINENUMBERS)
67
            {
68
                if (item.SPPID == null)
69
                    item.SPPID = new SPPIDSymbolInfo();
70
            }
71

    
72
            foreach (var item in TEXTINFOS)
73
            {
74
                if (item.SPPID == null)
75
                    item.SPPID = new SPPIDSymbolInfo();
76
            }
77

    
78
            foreach (var item in NOTES)
79
            {
80
                if (item.SPPID == null)
81
                    item.SPPID = new SPPIDSymbolInfo();
82
            }
83
        }
84

    
85
        public void SetSPPIDLocation(double SPPIDDocumentX, double SPPIDDocumentY)
86
        {
87
            foreach (var item in SYMBOLS)
88
            {
89
                double x = double.NaN;
90
                double y = double.NaN;
91
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
92
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
93

    
94
                item.SPPID.ORIGINAL_X = x;
95
                item.SPPID.ORIGINAL_Y = y;
96
            }
97

    
98
            foreach (var item in LINES)
99
            {
100
                double x = double.NaN;
101
                double y = double.NaN;
102

    
103
                SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y);
104
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
105
                item.SPPID.START_X = x;
106
                item.SPPID.START_Y = y;
107

    
108
                SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y);
109
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
110
                item.SPPID.END_X = x;
111
                item.SPPID.END_Y = y;
112
            }
113

    
114
            foreach (var item in Equipments)
115
            {
116
                double x = double.NaN;
117
                double y = double.NaN;
118
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
119
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
120

    
121
                item.SPPID.ORIGINAL_X = x;
122
                item.SPPID.ORIGINAL_Y = y;
123
            }
124

    
125
            foreach (var item in EndBreaks)
126
            {
127
                double x = double.NaN;
128
                double y = double.NaN;
129
                SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y);
130
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
131
                item.SPPID.ORIGINAL_X = x;
132
                item.SPPID.ORIGINAL_Y = y;
133
            }
134

    
135
            foreach (var item in LINENUMBERS)
136
            {
137
                double x = double.NaN;
138
                double y = double.NaN;
139
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
140
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
141
                item.SPPID.ORIGINAL_X = x;
142
                item.SPPID.ORIGINAL_Y = y;
143

    
144
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
145
                double x1 = item.X1;
146
                double y1 = item.Y1;
147
                double x2 = item.X2;
148
                double y2 = item.Y2;
149
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
150
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
151
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
152
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
153
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
154
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
155
            }
156

    
157
            foreach (var item in TEXTINFOS)
158
            {
159
                double x = double.NaN;
160
                double y = double.NaN;
161
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
162
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
163
                item.SPPID.ORIGINAL_X = x;
164
                item.SPPID.ORIGINAL_Y = y;
165

    
166
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
167
                double x1 = item.X1;
168
                double y1 = item.Y1;
169
                double x2 = item.X2;
170
                double y2 = item.Y2;
171
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
172
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
173
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
174
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
175
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
176
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
177
            }
178

    
179
            foreach (var item in NOTES)
180
            {
181
                double x = double.NaN;
182
                double y = double.NaN;
183
                SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y);
184
                SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
185
                item.SPPID.ORIGINAL_X = x;
186
                item.SPPID.ORIGINAL_Y = y;
187

    
188
                item.SPPIDLabelLocation = new SPPIDLabelLocationInfo();
189
                double x1 = item.X1;
190
                double y1 = item.Y1;
191
                double x2 = item.X2;
192
                double y2 = item.Y2;
193
                SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
194
                SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY);
195
                item.SPPIDLabelLocation.X1 = Math.Min(x1, x2);
196
                item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2);
197
                item.SPPIDLabelLocation.X2 = Math.Max(x1, x2);
198
                item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2);
199
            }
200
        }
201

    
202
        /// <summary>
203
        /// 좌표 보정
204
        /// </summary>
205
        public void CoordinateCorrection()
206
        {
207
            foreach (Symbol symbol in SYMBOLS)
208
            {
209
                if (!symbol.SPPID.IsCorrectionX)
210
                {
211
                    List<object> group = new List<object>();
212
                    group.Add(symbol);
213
                    FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.VERTICAL);
214

    
215
                    List<Symbol> groupSymbols = (from sym in @group
216
                                                 where sym.GetType() == typeof(Symbol)
217
                                                 select sym as Symbol).ToList();
218

    
219
                    // X 좌표만 보정
220
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionX);
221
                    double value = symbol.SPPID.ORIGINAL_X;
222
                    if (correctionSymbol == null)
223
                        SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value);
224
                    else
225
                        value = correctionSymbol.SPPID.ORIGINAL_X;
226

    
227
                    foreach (var item in groupSymbols)
228
                    {
229
                        item.SPPID.IsCorrectionX = true;
230
                        item.SPPID.ORIGINAL_X = value;
231
                    }
232
                }
233

    
234
                if (!symbol.SPPID.IsCorrectionY)
235
                {
236
                    List<object> group = new List<object>();
237
                    group.Add(symbol);
238
                    FindGroupBySymbolAndSlopeType(symbol, group, SlopeType.HORIZONTAL);
239

    
240
                    List<Symbol> groupSymbols = (from sym in @group
241
                                                 where sym.GetType() == typeof(Symbol)
242
                                                 select sym as Symbol).ToList();
243

    
244
                    // Y 좌표만 보정
245
                    Symbol correctionSymbol = groupSymbols.Find(x => x.SPPID.IsCorrectionY);
246
                    double value = symbol.SPPID.ORIGINAL_Y;
247
                    if (correctionSymbol == null)
248
                        SPPIDUtil.ConvertGridPointOnlyOnePoint(ref value);
249
                    else
250
                        value = correctionSymbol.SPPID.ORIGINAL_Y;
251

    
252
                    foreach (var item in groupSymbols)
253
                    {
254
                        item.SPPID.IsCorrectionY = true;
255
                        item.SPPID.ORIGINAL_Y = value;
256
                    }
257
                }
258
            }
259
        }
260

    
261
        private void FindGroupBySymbolAndSlopeType(Symbol symbol, List<object> group, SlopeType searchType)
262
        {
263
            foreach (var connector in symbol.CONNECTORS)
264
            {
265
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
266
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
267
                {
268
                    Symbol connSymbol = connectedItem as Symbol;
269
                    SlopeType slopeType = SPPIDUtil.CalcSlope(symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y, connSymbol.SPPID.ORIGINAL_X, connSymbol.SPPID.ORIGINAL_Y);
270
                    if (slopeType == searchType)
271
                    {
272
                        if (!group.Contains(connSymbol))
273
                        {
274
                            group.Add(connSymbol);
275
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
276
                        }
277
                    }
278
                }
279
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
280
                {
281
                    Line connLine = connectedItem as Line;
282
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
283
                    if (slopeType == searchType)
284
                    {
285
                        if (!group.Contains(connLine))
286
                        {
287
                            group.Add(connLine);
288
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
289
                        }
290
                    }
291
                }
292
            }
293
        }
294

    
295
        private void FindGroupByLineAndSlopeType(Line Line, List<object> group, SlopeType searchType)
296
        {
297
            foreach (var connector in Line.CONNECTORS)
298
            {
299
                object connectedItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM);
300
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
301
                {
302
                    Symbol connSymbol = connectedItem as Symbol;
303
                    double lineX = double.NaN;
304
                    double lineY = double.NaN;
305
                    SPPIDUtil.ConvertPointBystring(connector.SCENECONNECTPOINT, ref lineX, ref lineY);
306
                    double symbolX = double.NaN;
307
                    double symbolY = double.NaN;
308
                    SPPIDUtil.ConvertPointBystring(connSymbol.ORIGINALPOINT, ref symbolX, ref symbolY);
309

    
310
                    SlopeType slopeType = SPPIDUtil.CalcSlope(lineX, lineY, symbolX, symbolY);
311
                    if (slopeType == searchType)
312
                    {
313
                        if (!group.Contains(connSymbol))
314
                        {
315
                            group.Add(connSymbol);
316
                            FindGroupBySymbolAndSlopeType(connSymbol, group, searchType);
317
                        }
318
                    }
319
                }
320
                else if (connectedItem != null && connectedItem.GetType() == typeof(Line))
321
                {
322
                    Line connLine = connectedItem as Line;
323
                    SlopeType slopeType = SPPIDUtil.CalcSlope(connLine.SPPID.START_X, connLine.SPPID.START_Y, connLine.SPPID.END_X, connLine.SPPID.END_Y);
324
                    if (slopeType == searchType)
325
                    {
326
                        if (!group.Contains(connLine))
327
                        {
328
                            group.Add(connLine);
329
                            FindGroupByLineAndSlopeType(connLine, group, searchType);
330
                        }
331
                    }
332
                }
333
            }
334
        }
335

    
336
        private void SetChildSymbolSPPIDInfo(ChildSymbol item)
337
        {
338
            foreach (var childSymbol in item.ChildSymbols)
339
            {
340
                if (childSymbol.SPPID == null)
341
                    childSymbol.SPPID = new SPPIDSymbolInfo();
342
                SetChildSymbolSPPIDInfo(childSymbol);
343
            }
344
        }
345
      
346
        public bool SetSPPIDMapping()
347
        {
348
            foreach (var item in SYMBOLS)
349
            {
350
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
351
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
352
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
353
                    return false;
354

    
355
                foreach (var childSymbol in item.ChildSymbols)
356
                {
357
                    ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
358
                    childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
359
                    if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol))
360
                        return false;
361
                }
362
            }
363

    
364
            foreach (var item in LINES)
365
            {
366
                LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID);
367
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
368
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
369
                    return false;
370
            }
371

    
372
            foreach (var item in Equipments)
373
            {
374
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
375
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
376
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
377
                    return false;
378
            }
379

    
380
            foreach (var item in EndBreaks)
381
            {
382
                SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID);
383
                item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null;
384
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
385
                    return false;
386
            }
387

    
388
            foreach (var item in LINENUMBERS)
389
            {
390
                if (LineNumberMappings.Count > 0)
391
                    item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME;
392
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
393
                    return false;
394
            }
395

    
396
            ETCSetting etc = ETCSetting.GetInstance();
397
            foreach (var item in NOTES)
398
            {
399
                item.SPPID.MAPPINGNAME = etc.NoteSymbolPath;
400
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
401
                    return false;
402
            }
403

    
404
            foreach (var item in TEXTINFOS)
405
            {
406
                item.SPPID.MAPPINGNAME = etc.TextSymbolPath;
407
                if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME))
408
                    return false;
409
            }
410

    
411
            return true;
412
        }
413

    
414
        private bool SetChildSymbolMapping(ChildSymbol item)
415
        {
416
            foreach (var childSymbol in item.ChildSymbols)
417
            {
418
                ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME);
419
                childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null;
420
                if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME))
421
                    return false;
422
                else
423
                    return SetChildSymbolMapping(childSymbol);
424
            }
425

    
426
            return true;
427
        }
428
    }
429
}
클립보드 이미지 추가 (최대 크기: 500 MB)