hytos / DTI_PID / SPPIDConverter / Model / SPPID_Document.cs @ 1efc25a3
이력 | 보기 | 이력해설 | 다운로드 (9.94 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 |
|
104 |
public bool SetSPPIDMapping() |
105 |
{ |
106 |
foreach (var item in SYMBOLS) |
107 |
{ |
108 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
109 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
110 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
111 |
return false; |
112 |
} |
113 |
|
114 |
foreach (var item in LINES) |
115 |
{ |
116 |
LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID); |
117 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
118 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
119 |
return false; |
120 |
} |
121 |
|
122 |
foreach (var item in Equipments) |
123 |
{ |
124 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
125 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
126 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
127 |
return false; |
128 |
} |
129 |
|
130 |
foreach (var item in EndBreaks) |
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 LINENUMBERS) |
139 |
{ |
140 |
if (LineNumberMappings.Count > 0) |
141 |
item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME; |
142 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
143 |
return false; |
144 |
} |
145 |
|
146 |
return true; |
147 |
} |
148 |
|
149 |
#region Grouping Source |
150 |
private bool SetGrouping() |
151 |
{ |
152 |
try |
153 |
{ |
154 |
// Line 기준으로 묶음 |
155 |
foreach (Line item in LINES) |
156 |
if (!item.SPPID.IsGroup) |
157 |
SetGroupingByItem(item); |
158 |
// End |
159 |
|
160 |
// Symbol 기준으로 묶음 |
161 |
foreach (Symbol item in SYMBOLS) |
162 |
if (!item.SPPID.IsGroup) |
163 |
SetGroupingByItem(item); |
164 |
// End |
165 |
} |
166 |
catch (Exception ex) |
167 |
{ |
168 |
return false; |
169 |
} |
170 |
return true; |
171 |
} |
172 |
|
173 |
private void SetGroupingByItem(object item) |
174 |
{ |
175 |
Group group = new Group(); |
176 |
group.Items.Add(item); |
177 |
bool forward = true; |
178 |
SetGroupingByConnectedItem(item, group.Items, ref forward); |
179 |
|
180 |
GROUPS.Add(group); |
181 |
} |
182 |
|
183 |
private void SetGroupingByConnectedItem(object item, List<object> list, ref bool IsForward) |
184 |
{ |
185 |
if (typeof(Line) == item.GetType()) |
186 |
{ |
187 |
Line line = item as Line; |
188 |
line.SPPID.IsGroup = true; |
189 |
SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, line.CONNECTORS); |
190 |
} |
191 |
else if (typeof(Symbol) == item.GetType()) |
192 |
{ |
193 |
Symbol symbol = item as Symbol; |
194 |
symbol.SPPID.IsGroup = true; |
195 |
// Symbol의 경우 BaseSymbol Connector가 2개 이하때 진행 / 나머지는 Grouping 종료 |
196 |
int baseSymbolCount = 0; |
197 |
if (symbol.CONNECTORS.Count > 0) |
198 |
{ |
199 |
foreach (Connector symbolConnector in symbol.CONNECTORS) |
200 |
if (symbolConnector.Index == 0) |
201 |
baseSymbolCount++; |
202 |
|
203 |
if (baseSymbolCount <= 2) |
204 |
SetGroupingByConnectedItem_ConnectorsLogic(item, list, ref IsForward, symbol.CONNECTORS); |
205 |
} |
206 |
} |
207 |
IsForward = false; |
208 |
} |
209 |
|
210 |
private void SetGroupingByConnectedItem_ConnectorsLogic(object item, List<object> list, ref bool IsForward, List<Connector> connectors) |
211 |
{ |
212 |
foreach (Connector connector in connectors) |
213 |
{ |
214 |
object connItem = SPPIDUtil.FindObjectByUID(this, connector.CONNECTEDITEM); |
215 |
if (connItem != null) |
216 |
{ |
217 |
bool result = false; |
218 |
if (typeof(Line) == connItem.GetType()) |
219 |
{ |
220 |
Line connLine = connItem as Line; |
221 |
// 연결되는 Item이 전부 Line일 경우 Branch, Line Type을 확인 |
222 |
if (item.GetType() == connLine.GetType()) |
223 |
{ |
224 |
Line line = item as Line; |
225 |
if (SPPIDUtil.IsBranchLine(line.UID, connLine) || line.SPPID.MAPPINGNAME != connLine.SPPID.MAPPINGNAME) |
226 |
continue; |
227 |
} |
228 |
|
229 |
result = true; |
230 |
} |
231 |
else if (typeof(Symbol) == connItem.GetType()) |
232 |
{ |
233 |
Symbol connSymbol = connItem as Symbol; |
234 |
// 연결되는 Symbol의 Connector가 부가 심볼일 경우는 result = false |
235 |
foreach (Connector symbolConnector in connSymbol.CONNECTORS) |
236 |
{ |
237 |
string itemUID = item as Symbol != null ? ((Symbol)item).UID : ((Line)item).UID; |
238 |
|
239 |
if (symbolConnector.CONNECTEDITEM == itemUID) |
240 |
{ |
241 |
if (symbolConnector.Index == 0) |
242 |
result = true; |
243 |
else |
244 |
result = false; |
245 |
break; |
246 |
} |
247 |
} |
248 |
} |
249 |
|
250 |
if (!(connItem as Symbol != null ? ((Symbol)connItem).SPPID.IsGroup : ((Line)connItem).SPPID.IsGroup) && result) |
251 |
{ |
252 |
if (IsForward) |
253 |
list.Add(connItem); |
254 |
else |
255 |
list.Insert(0, connItem); |
256 |
SetGroupingByConnectedItem(connItem, list, ref IsForward); |
257 |
} |
258 |
} |
259 |
} |
260 |
} |
261 |
#endregion |
262 |
} |
263 |
} |