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