hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 06b40010
이력 | 보기 | 이력해설 | 다운로드 (12.6 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 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
95 |
|
96 |
item.SPPID.ORIGINAL_X = x; |
97 |
item.SPPID.ORIGINAL_Y = y; |
98 |
} |
99 |
|
100 |
foreach (var item in LINES) |
101 |
{ |
102 |
double x = double.NaN; |
103 |
double y = double.NaN; |
104 |
|
105 |
SPPIDUtil.ConvertPointBystring(item.STARTPOINT, ref x, ref y); |
106 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
107 |
item.SPPID.START_X = x; |
108 |
item.SPPID.START_Y = y; |
109 |
|
110 |
SPPIDUtil.ConvertPointBystring(item.ENDPOINT, ref x, ref y); |
111 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
112 |
item.SPPID.END_X = x; |
113 |
item.SPPID.END_Y = y; |
114 |
} |
115 |
|
116 |
foreach (var item in Equipments) |
117 |
{ |
118 |
double x = double.NaN; |
119 |
double y = double.NaN; |
120 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
121 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
122 |
|
123 |
SPPIDUtil.ConvertGridPoint(ref x, ref y); |
124 |
|
125 |
item.SPPID.ORIGINAL_X = x; |
126 |
item.SPPID.ORIGINAL_Y = y; |
127 |
} |
128 |
|
129 |
foreach (var item in EndBreaks) |
130 |
{ |
131 |
double x = double.NaN; |
132 |
double y = double.NaN; |
133 |
SPPIDUtil.ConvertPointBystring(item.ORIGINALPOINT, ref x, ref y); |
134 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
135 |
item.SPPID.ORIGINAL_X = x; |
136 |
item.SPPID.ORIGINAL_Y = y; |
137 |
} |
138 |
|
139 |
foreach (var item in LINENUMBERS) |
140 |
{ |
141 |
double x = double.NaN; |
142 |
double y = double.NaN; |
143 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
144 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
145 |
item.SPPID.ORIGINAL_X = x; |
146 |
item.SPPID.ORIGINAL_Y = y; |
147 |
|
148 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
149 |
double x1 = item.X1; |
150 |
double y1 = item.Y1; |
151 |
double x2 = item.X2; |
152 |
double y2 = item.Y2; |
153 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
154 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
155 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
156 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
157 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
158 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
159 |
} |
160 |
|
161 |
foreach (var item in TEXTINFOS) |
162 |
{ |
163 |
double x = double.NaN; |
164 |
double y = double.NaN; |
165 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
166 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
167 |
item.SPPID.ORIGINAL_X = x; |
168 |
item.SPPID.ORIGINAL_Y = y; |
169 |
|
170 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
171 |
double x1 = item.X1; |
172 |
double y1 = item.Y1; |
173 |
double x2 = item.X2; |
174 |
double y2 = item.Y2; |
175 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
176 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
177 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
178 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
179 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
180 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
181 |
} |
182 |
|
183 |
foreach (var item in NOTES) |
184 |
{ |
185 |
double x = double.NaN; |
186 |
double y = double.NaN; |
187 |
SPPIDUtil.ConvertPointBystring(item.LOCATION, ref x, ref y); |
188 |
SPPIDUtil.ConvertSPPIDPoint(ref x, ref y, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
189 |
item.SPPID.ORIGINAL_X = x; |
190 |
item.SPPID.ORIGINAL_Y = y; |
191 |
|
192 |
item.SPPIDLabelLocation = new SPPIDLabelLocationInfo(); |
193 |
double x1 = item.X1; |
194 |
double y1 = item.Y1; |
195 |
double x2 = item.X2; |
196 |
double y2 = item.Y2; |
197 |
SPPIDUtil.ConvertSPPIDPoint(ref x1, ref y1, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
198 |
SPPIDUtil.ConvertSPPIDPoint(ref x2, ref y2, SIZE_WIDTH, SIZE_HEIGHT, SPPIDDocumentX, SPPIDDocumentY); |
199 |
item.SPPIDLabelLocation.X1 = Math.Min(x1, x2); |
200 |
item.SPPIDLabelLocation.Y1 = Math.Min(y1, y2); |
201 |
item.SPPIDLabelLocation.X2 = Math.Max(x1, x2); |
202 |
item.SPPIDLabelLocation.Y2 = Math.Max(y1, y2); |
203 |
} |
204 |
} |
205 |
|
206 |
private void SetChildSymbolSPPIDInfo(ChildSymbol item) |
207 |
{ |
208 |
foreach (var childSymbol in item.ChildSymbols) |
209 |
{ |
210 |
if (childSymbol.SPPID == null) |
211 |
childSymbol.SPPID = new SPPIDSymbolInfo(); |
212 |
SetChildSymbolSPPIDInfo(childSymbol); |
213 |
} |
214 |
} |
215 |
|
216 |
public bool SetSPPIDMapping() |
217 |
{ |
218 |
foreach (var item in SYMBOLS) |
219 |
{ |
220 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
221 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
222 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
223 |
return false; |
224 |
|
225 |
foreach (var childSymbol in item.ChildSymbols) |
226 |
{ |
227 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
228 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
229 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol)) |
230 |
return false; |
231 |
} |
232 |
} |
233 |
|
234 |
foreach (var item in LINES) |
235 |
{ |
236 |
LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID); |
237 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
238 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
239 |
return false; |
240 |
} |
241 |
|
242 |
foreach (var item in Equipments) |
243 |
{ |
244 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
245 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
246 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
247 |
return false; |
248 |
} |
249 |
|
250 |
foreach (var item in EndBreaks) |
251 |
{ |
252 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
253 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
254 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
255 |
return false; |
256 |
} |
257 |
|
258 |
foreach (var item in LINENUMBERS) |
259 |
{ |
260 |
if (LineNumberMappings.Count > 0) |
261 |
item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME; |
262 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
263 |
return false; |
264 |
} |
265 |
|
266 |
ETCSetting etc = ETCSetting.GetInstance(); |
267 |
foreach (var item in NOTES) |
268 |
{ |
269 |
item.SPPID.MAPPINGNAME = etc.NoteSymbolPath; |
270 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
271 |
return false; |
272 |
} |
273 |
|
274 |
foreach (var item in TEXTINFOS) |
275 |
{ |
276 |
item.SPPID.MAPPINGNAME = etc.TextSymbolPath; |
277 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
278 |
return false; |
279 |
} |
280 |
|
281 |
return true; |
282 |
} |
283 |
|
284 |
public void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
285 |
{ |
286 |
decimal calcX = 0; |
287 |
decimal calcY = 0; |
288 |
decimal tempX = Convert.ToDecimal(dX); |
289 |
decimal tempY = Convert.ToDecimal(dY); |
290 |
decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
291 |
decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
292 |
decimal tempDwgX = Convert.ToDecimal(dDwgX); |
293 |
decimal tempDwgY = Convert.ToDecimal(dDwgY); |
294 |
|
295 |
//calcX = (tempX * tempWidth) / tempDwgX; |
296 |
//calcX = Math.Truncate(calcX * 1000) / 1000; |
297 |
//calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
298 |
//calcY = Math.Truncate(calcY * 1000) / 1000; |
299 |
//dX = Math.Round(Convert.ToDouble(calcX), 10); |
300 |
//dY = Math.Round(Convert.ToDouble(calcY), 10); |
301 |
|
302 |
calcX = (tempX * tempWidth) / tempDwgX; |
303 |
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
304 |
dX = Convert.ToDouble(calcX); |
305 |
dY = Convert.ToDouble(calcY); |
306 |
} |
307 |
|
308 |
private bool SetChildSymbolMapping(ChildSymbol item) |
309 |
{ |
310 |
foreach (var childSymbol in item.ChildSymbols) |
311 |
{ |
312 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
313 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
314 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME)) |
315 |
return false; |
316 |
else |
317 |
return SetChildSymbolMapping(childSymbol); |
318 |
} |
319 |
|
320 |
return true; |
321 |
} |
322 |
} |
323 |
} |