hytos / DTI_PID / SPPIDConverter / Model / SPPID_Document.cs @ 6b298450
이력 | 보기 | 이력해설 | 다운로드 (11.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 |
private double testX = 0.855; |
20 |
private double testY = 0.55; |
21 |
|
22 |
public List<SymbolMapping> SymbolMappings; |
23 |
public List<LineMapping> LineMappings; |
24 |
public List<LineNumberMapping> LineNumberMappings; |
25 |
public List<AttributeMapping> AttributeMappings; |
26 |
public ETCSetting ETCSetting; |
27 |
|
28 |
public List<Group> GROUPS = new List<Group>(); |
29 |
|
30 |
public string DrawingName { get; set; } |
31 |
public string DrawingNumber { get; set; } |
32 |
public string Unit { get; set; } |
33 |
public string Template { get; set; } |
34 |
|
35 |
public void SetSPPIDInfo() |
36 |
{ |
37 |
foreach (var item in SYMBOLS) |
38 |
{ |
39 |
if (item.SPPID == null) |
40 |
item.SPPID = new SPPIDSymbolInfo(); |
41 |
double x = double.NaN; |
42 |
double y = double.NaN; |
43 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
44 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
45 |
item.SPPID.ORIGINAL_X = x; |
46 |
item.SPPID.ORIGINAL_Y = y; |
47 |
} |
48 |
|
49 |
foreach (var item in LINES) |
50 |
{ |
51 |
if (item.SPPID == null) |
52 |
item.SPPID = new SPPIDLineInfo(); |
53 |
double x = double.NaN; |
54 |
double y = double.NaN; |
55 |
|
56 |
SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y); |
57 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
58 |
item.SPPID.START_X = x; |
59 |
item.SPPID.START_Y = y; |
60 |
|
61 |
SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y); |
62 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
63 |
item.SPPID.END_X = x; |
64 |
item.SPPID.END_Y = y; |
65 |
} |
66 |
|
67 |
foreach (var item in Equipments) |
68 |
{ |
69 |
if (item.SPPID == null) |
70 |
item.SPPID = new SPPIDSymbolInfo(); |
71 |
double x = double.NaN; |
72 |
double y = double.NaN; |
73 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
74 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
75 |
item.SPPID.ORIGINAL_X = x; |
76 |
item.SPPID.ORIGINAL_Y = y; |
77 |
} |
78 |
|
79 |
foreach (var item in EndBreaks) |
80 |
{ |
81 |
if (item.SPPID == null) |
82 |
item.SPPID = new SPPIDSymbolInfo(); |
83 |
double x = double.NaN; |
84 |
double y = double.NaN; |
85 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
86 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
87 |
item.SPPID.ORIGINAL_X = x; |
88 |
item.SPPID.ORIGINAL_Y = y; |
89 |
} |
90 |
|
91 |
foreach (var item in LINENUMBERS) |
92 |
{ |
93 |
if (item.SPPID == null) |
94 |
item.SPPID = new SPPIDSymbolInfo(); |
95 |
double x = double.NaN; |
96 |
double y = double.NaN; |
97 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
98 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
99 |
item.SPPID.ORIGINAL_X = x; |
100 |
item.SPPID.ORIGINAL_Y = y; |
101 |
} |
102 |
|
103 |
foreach (var item in TEXTINFOS) |
104 |
{ |
105 |
if (item.SPPID == null) |
106 |
item.SPPID = new SPPIDSymbolInfo(); |
107 |
double x = double.NaN; |
108 |
double y = double.NaN; |
109 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
110 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
111 |
item.SPPID.ORIGINAL_X = x; |
112 |
item.SPPID.ORIGINAL_Y = y; |
113 |
} |
114 |
|
115 |
foreach (var item in NOTES) |
116 |
{ |
117 |
if (item.SPPID == null) |
118 |
item.SPPID = new SPPIDSymbolInfo(); |
119 |
double x = double.NaN; |
120 |
double y = double.NaN; |
121 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
122 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, testX, testY); |
123 |
item.SPPID.ORIGINAL_X = x; |
124 |
item.SPPID.ORIGINAL_Y = y; |
125 |
} |
126 |
} |
127 |
|
128 |
public bool SetSPPIDMapping() |
129 |
{ |
130 |
foreach (var item in SYMBOLS) |
131 |
{ |
132 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
133 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
134 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
135 |
return false; |
136 |
} |
137 |
|
138 |
foreach (var item in LINES) |
139 |
{ |
140 |
LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID); |
141 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
142 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
143 |
return false; |
144 |
} |
145 |
|
146 |
foreach (var item in Equipments) |
147 |
{ |
148 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
149 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
150 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
151 |
return false; |
152 |
} |
153 |
|
154 |
foreach (var item in EndBreaks) |
155 |
{ |
156 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
157 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
158 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
159 |
return false; |
160 |
} |
161 |
|
162 |
foreach (var item in LINENUMBERS) |
163 |
{ |
164 |
if (LineNumberMappings.Count > 0) |
165 |
item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME; |
166 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
167 |
return false; |
168 |
} |
169 |
|
170 |
ETCSetting etc = ETCSetting.GetInstance(); |
171 |
foreach (var item in NOTES) |
172 |
{ |
173 |
item.SPPID.MAPPINGNAME = etc.NoteSymbolPath; |
174 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
175 |
return false; |
176 |
} |
177 |
|
178 |
foreach (var item in TEXTINFOS) |
179 |
{ |
180 |
item.SPPID.MAPPINGNAME = etc.TextSymbolPath; |
181 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
182 |
return false; |
183 |
} |
184 |
return true; |
185 |
} |
186 |
|
187 |
#region Grouping Source |
188 |
private bool SetGrouping() |
189 |
{ |
190 |
try |
191 |
{ |
192 |
// Line 기준으로 묶음 |
193 |
foreach (Line item in LINES) |
194 |
if (!item.SPPID.IsGroup) |
195 |
SetGroupingByItem(item); |
196 |
// End |
197 |
|
198 |
// Symbol 기준으로 묶음 |
199 |
foreach (Symbol item in SYMBOLS) |
200 |
if (!item.SPPID.IsGroup) |
201 |
SetGroupingByItem(item); |
202 |
// End |
203 |
} |
204 |
catch (Exception ex) |
205 |
{ |
206 |
return false; |
207 |
} |
208 |
return true; |
209 |
} |
210 |
|
211 |
private void SetGroupingByItem(object item) |
212 |
{ |
213 |
Group group = new Group(); |
214 |
group.Items.Add(item); |
215 |
bool forward = true; |
216 |
SetGroupingByConnectedItem(item, group.Items, ref forward); |
217 |
|
218 |
GROUPS.Add(group); |
219 |
} |
220 |
|
221 |
private void SetGroupingByConnectedItem(object item, List<object> list, ref bool IsForward) |
222 |
{ |
223 |
if (typeof(Line) == item.GetType()) |
224 |
{ |
225 |
Line line = item as Line; |
226 |
line.SPPID.IsGroup = true; |
227 |
SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, line.CONNECTORS); |
228 |
} |
229 |
else if (typeof(Symbol) == item.GetType()) |
230 |
{ |
231 |
Symbol symbol = item as Symbol; |
232 |
symbol.SPPID.IsGroup = true; |
233 |
// Symbol의 경우 BaseSymbol Connector가 2개 이하때 진행 / 나머지는 Grouping 종료 |
234 |
int baseSymbolCount = 0; |
235 |
if (symbol.CONNECTORS.Count > 0) |
236 |
{ |
237 |
foreach (Connector symbolConnector in symbol.CONNECTORS) |
238 |
if (symbolConnector.Index == 0) |
239 |
baseSymbolCount++; |
240 |
|
241 |
if (baseSymbolCount <= 2) |
242 |
SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, symbol.CONNECTORS); |
243 |
} |
244 |
} |
245 |
IsForward = false; |
246 |
} |
247 |
|
248 |
private void SetGroupingByConnectedItem_ConnectorsLogic(object item, List<object> list, ref bool IsForward, List<Connector> connectors) |
249 |
{ |
250 |
foreach (Connector connector in connectors) |
251 |
{ |
252 |
object connItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM); |
253 |
if (connItem != null) |
254 |
{ |
255 |
bool result = false; |
256 |
if (typeof(Line) == connItem.GetType()) |
257 |
{ |
258 |
Line connLine = connItem as Line; |
259 |
// 연결되는 Item이 전부 Line일 경우 Branch, Line Type을 확인 |
260 |
if (item.GetType() == connLine.GetType()) |
261 |
{ |
262 |
Line line = item as Line; |
263 |
if (SPPIDUtil.IsBranchLine(line.UID, connLine) || line.SPPID.MAPPINGNAME != connLine.SPPID.MAPPINGNAME) |
264 |
continue; |
265 |
} |
266 |
|
267 |
result = true; |
268 |
} |
269 |
else if (typeof(Symbol) == connItem.GetType()) |
270 |
{ |
271 |
Symbol connSymbol = connItem as Symbol; |
272 |
// 연결되는 Symbol의 Connector가 부가 심볼일 경우는 result = false |
273 |
foreach (Connector symbolConnector in connSymbol.CONNECTORS) |
274 |
{ |
275 |
string itemUID = item as Symbol != null ? ((Symbol)item).UID : ((Line)item).UID; |
276 |
|
277 |
if (symbolConnector.CONNECTEDITEM == itemUID) |
278 |
{ |
279 |
if (symbolConnector.Index == 0) |
280 |
result = true; |
281 |
else |
282 |
result = false; |
283 |
break; |
284 |
} |
285 |
} |
286 |
} |
287 |
|
288 |
if (!(connItem as Symbol != null ? ((Symbol)connItem).SPPID.IsGroup : ((Line)connItem).SPPID.IsGroup) && result) |
289 |
{ |
290 |
if (IsForward) |
291 |
list.Add(connItem); |
292 |
else |
293 |
list.Insert(0, connItem); |
294 |
SetGroupingByConnectedItem(connItem, list, ref IsForward); |
295 |
} |
296 |
} |
297 |
} |
298 |
} |
299 |
#endregion |
300 |
} |
301 |
} |