hytos / DTI_PID / SPPIDConverter / SPPIDModel / SPPID_Document.cs @ 20972c61
이력 | 보기 | 이력해설 | 다운로드 (12.5 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 |
private void SetChildSymbolSPPIDInfo(ChildSymbol item) |
203 |
{ |
204 |
foreach (var childSymbol in item.ChildSymbols) |
205 |
{ |
206 |
if (childSymbol.SPPID == null) |
207 |
childSymbol.SPPID = new SPPIDSymbolInfo(); |
208 |
SetChildSymbolSPPIDInfo(childSymbol); |
209 |
} |
210 |
} |
211 |
|
212 |
public bool SetSPPIDMapping() |
213 |
{ |
214 |
foreach (var item in SYMBOLS) |
215 |
{ |
216 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
217 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
218 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
219 |
return false; |
220 |
|
221 |
foreach (var childSymbol in item.ChildSymbols) |
222 |
{ |
223 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
224 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
225 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME) || !SetChildSymbolMapping(childSymbol)) |
226 |
return false; |
227 |
} |
228 |
} |
229 |
|
230 |
foreach (var item in LINES) |
231 |
{ |
232 |
LineMapping mapping = LineMappings.Find(x => x.UID == item.TYPEUID); |
233 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
234 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
235 |
return false; |
236 |
} |
237 |
|
238 |
foreach (var item in Equipments) |
239 |
{ |
240 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
241 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
242 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
243 |
return false; |
244 |
} |
245 |
|
246 |
foreach (var item in EndBreaks) |
247 |
{ |
248 |
SymbolMapping mapping = SymbolMappings.Find(x => x.UID == item.DBUID); |
249 |
item.SPPID.MAPPINGNAME = mapping != null ? mapping.SPPIDSYMBOLNAME : null; |
250 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
251 |
return false; |
252 |
} |
253 |
|
254 |
foreach (var item in LINENUMBERS) |
255 |
{ |
256 |
if (LineNumberMappings.Count > 0) |
257 |
item.SPPID.MAPPINGNAME = LineNumberMappings[0].SPPIDSYMBOLNAME; |
258 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
259 |
return false; |
260 |
} |
261 |
|
262 |
ETCSetting etc = ETCSetting.GetInstance(); |
263 |
foreach (var item in NOTES) |
264 |
{ |
265 |
item.SPPID.MAPPINGNAME = etc.NoteSymbolPath; |
266 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
267 |
return false; |
268 |
} |
269 |
|
270 |
foreach (var item in TEXTINFOS) |
271 |
{ |
272 |
item.SPPID.MAPPINGNAME = etc.TextSymbolPath; |
273 |
if (string.IsNullOrEmpty(item.SPPID.MAPPINGNAME)) |
274 |
return false; |
275 |
} |
276 |
|
277 |
return true; |
278 |
} |
279 |
|
280 |
public void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
281 |
{ |
282 |
decimal calcX = 0; |
283 |
decimal calcY = 0; |
284 |
decimal tempX = Convert.ToDecimal(dX); |
285 |
decimal tempY = Convert.ToDecimal(dY); |
286 |
decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
287 |
decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
288 |
decimal tempDwgX = Convert.ToDecimal(dDwgX); |
289 |
decimal tempDwgY = Convert.ToDecimal(dDwgY); |
290 |
|
291 |
//calcX = (tempX * tempWidth) / tempDwgX; |
292 |
//calcX = Math.Truncate(calcX * 1000) / 1000; |
293 |
//calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
294 |
//calcY = Math.Truncate(calcY * 1000) / 1000; |
295 |
//dX = Math.Round(Convert.ToDouble(calcX), 10); |
296 |
//dY = Math.Round(Convert.ToDouble(calcY), 10); |
297 |
|
298 |
calcX = (tempX * tempWidth) / tempDwgX; |
299 |
calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
300 |
dX = Convert.ToDouble(calcX); |
301 |
dY = Convert.ToDouble(calcY); |
302 |
} |
303 |
|
304 |
private bool SetChildSymbolMapping(ChildSymbol item) |
305 |
{ |
306 |
foreach (var childSymbol in item.ChildSymbols) |
307 |
{ |
308 |
ChildSymbolMapping childMapping = ChildSymbolMappings.Find(x => x.UID == childSymbol.NAME); |
309 |
childSymbol.SPPID.MAPPINGNAME = childMapping != null ? childMapping.SPPIDSYMBOLNAME : null; |
310 |
if (string.IsNullOrEmpty(childSymbol.SPPID.MAPPINGNAME)) |
311 |
return false; |
312 |
else |
313 |
return SetChildSymbolMapping(childSymbol); |
314 |
} |
315 |
|
316 |
return true; |
317 |
} |
318 |
} |
319 |
} |