hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 0760d1ad
이력 | 보기 | 이력해설 | 다운로드 (26.7 KB)
1 | 23eb98bf | gaqhf | using System; |
---|---|---|---|
2 | using System.Collections.Generic; |
||
3 | using System.Linq; |
||
4 | using System.Text; |
||
5 | using System.Threading.Tasks; |
||
6 | using Newtonsoft.Json; |
||
7 | using System.IO; |
||
8 | b8e2644e | gaqhf | using Converter.SPPID.DB; |
9 | 23eb98bf | gaqhf | using Converter.BaseModel; |
10 | using System.Windows.Forms; |
||
11 | bca81f4c | gaqhf | using Converter.SPPID.Model; |
12 | 5dfb8a24 | gaqhf | using System.Drawing; |
13 | ea54adc8 | gaqhf | using Llama; |
14 | using System.Data; |
||
15 | using Plaice; |
||
16 | using Microsoft.VisualBasic; |
||
17 | 23eb98bf | gaqhf | |
18 | b8e2644e | gaqhf | namespace Converter.SPPID.Util |
19 | 23eb98bf | gaqhf | { |
20 | 5dfb8a24 | gaqhf | public enum SlopeType |
21 | { |
||
22 | d1eac84d | gaqhf | None, |
23 | 5dfb8a24 | gaqhf | Slope, |
24 | HORIZONTAL, |
||
25 | VERTICAL |
||
26 | } |
||
27 | 23eb98bf | gaqhf | public class SPPIDUtil |
28 | { |
||
29 | fab4f207 | gaqhf | public static bool ConvertToSPPIDInfo(string jsonString) |
30 | 23eb98bf | gaqhf | { |
31 | 2e1e3c12 | gaqhf | SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
32 | 23eb98bf | gaqhf | try |
33 | { |
||
34 | fab4f207 | gaqhf | SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString); |
35 | 23eb98bf | gaqhf | |
36 | _SPPIDInfo.DBType = jsonSPPIDInfo.DBType; |
||
37 | _SPPIDInfo.Service = jsonSPPIDInfo.Service; |
||
38 | _SPPIDInfo.Site = jsonSPPIDInfo.Site; |
||
39 | _SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP; |
||
40 | _SPPIDInfo.Port = jsonSPPIDInfo.Port; |
||
41 | _SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser; |
||
42 | _SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword; |
||
43 | _SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath; |
||
44 | _SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic; |
||
45 | _SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID; |
||
46 | _SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic; |
||
47 | _SPPIDInfo.Plant = jsonSPPIDInfo.Plant; |
||
48 | _SPPIDInfo.Enable = jsonSPPIDInfo.Enable; |
||
49 | _SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant; |
||
50 | _SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList; |
||
51 | |||
52 | } |
||
53 | catch (Exception ex) |
||
54 | { |
||
55 | fab4f207 | gaqhf | _SPPIDInfo.Enable = false; |
56 | 23eb98bf | gaqhf | return false; |
57 | } |
||
58 | return true; |
||
59 | } |
||
60 | 5dfb8a24 | gaqhf | |
61 | e00e891d | gaqhf | public static bool ConvertToETCSetting(string jsonString) |
62 | { |
||
63 | ETCSetting _ETCSetting = ETCSetting.GetInstance(); |
||
64 | try |
||
65 | { |
||
66 | ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString); |
||
67 | |||
68 | _ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath; |
||
69 | _ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath; |
||
70 | _ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize; |
||
71 | fbea6028 | gaqhf | _ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath; |
72 | 1a3a74a8 | gaqhf | _ETCSetting.TextLocation = jsonETCSetting.TextLocation; |
73 | _ETCSetting.NoteLocation = jsonETCSetting.NoteLocation; |
||
74 | _ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation; |
||
75 | b2d1c1aa | gaqhf | _ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath; |
76 | b7b123ba | gaqhf | _ETCSetting.BorderFilePath = jsonETCSetting.BorderFilePath; |
77 | e00e891d | gaqhf | } |
78 | catch (Exception ex) |
||
79 | { |
||
80 | return false; |
||
81 | } |
||
82 | return true; |
||
83 | } |
||
84 | bca81f4c | gaqhf | |
85 | 7cbb1038 | gaqhf | public static bool ConvertToGridSetting(string jsonString) |
86 | { |
||
87 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
88 | try |
||
89 | { |
||
90 | GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString); |
||
91 | |||
92 | _GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid; |
||
93 | _GridSetting.Density = jsonGridSetting.Density; |
||
94 | _GridSetting.Unit = jsonGridSetting.Unit; |
||
95 | f676f99a | gaqhf | _GridSetting.DrainValveCellCount = jsonGridSetting.DrainValveCellCount; |
96 | 7cbb1038 | gaqhf | } |
97 | catch (Exception ex) |
||
98 | { |
||
99 | return false; |
||
100 | } |
||
101 | return true; |
||
102 | } |
||
103 | |||
104 | 39a2a688 | gaqhf | public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
105 | { |
||
106 | try |
||
107 | { |
||
108 | string[] pointArr = sPoint.Split(new char[] { ',' }); |
||
109 | if (pointArr.Length == 2) |
||
110 | { |
||
111 | dX = Convert.ToDouble(pointArr[0]); |
||
112 | dY = Convert.ToDouble(pointArr[1]); |
||
113 | } |
||
114 | } |
||
115 | catch (Exception) |
||
116 | { |
||
117 | dX = 0; |
||
118 | dY = 0; |
||
119 | return false; |
||
120 | } |
||
121 | |||
122 | return true; |
||
123 | } |
||
124 | bca81f4c | gaqhf | |
125 | 39a2a688 | gaqhf | public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
126 | { |
||
127 | 1b261371 | gaqhf | decimal calcX = 0; |
128 | decimal calcY = 0; |
||
129 | decimal tempX = Convert.ToDecimal(dX); |
||
130 | decimal tempY = Convert.ToDecimal(dY); |
||
131 | decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
||
132 | decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
||
133 | decimal tempDwgX = Convert.ToDecimal(dDwgX); |
||
134 | decimal tempDwgY = Convert.ToDecimal(dDwgY); |
||
135 | |||
136 | calcX = (tempX * tempWidth) / tempDwgX; |
||
137 | calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
||
138 | c3d2e266 | gaqhf | dX = Convert.ToDouble(calcX); |
139 | dY = Convert.ToDouble(calcY); |
||
140 | 39a2a688 | gaqhf | } |
141 | bca81f4c | gaqhf | |
142 | 06b40010 | gaqhf | public static void ConvertGridPoint(ref double x, ref double y) |
143 | { |
||
144 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
145 | if (_GridSetting.UseSnapGrid) |
||
146 | { |
||
147 | if (_GridSetting.Unit == GridUnit.Inch) |
||
148 | { |
||
149 | double length = _GridSetting.Density * 0.0254; |
||
150 | double tempX = x; |
||
151 | double tempY = y; |
||
152 | x = Math.Round(tempX / length) * length; |
||
153 | y = Math.Round(tempY / length) * length; |
||
154 | b66a2996 | gaqhf | } |
155 | } |
||
156 | } |
||
157 | 4d2571ab | gaqhf | |
158 | b66a2996 | gaqhf | public static void ConvertGridPointOnlyOnePoint(ref double value) |
159 | { |
||
160 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
161 | if (_GridSetting.UseSnapGrid) |
||
162 | { |
||
163 | if (_GridSetting.Unit == GridUnit.Inch) |
||
164 | { |
||
165 | double temp = value; |
||
166 | d9794a6c | gaqhf | value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
167 | 06b40010 | gaqhf | } |
168 | } |
||
169 | } |
||
170 | a0e3dca4 | gaqhf | public static double ConvertGridPointOnlyOnePoint(double value) |
171 | { |
||
172 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
173 | if (_GridSetting.UseSnapGrid) |
||
174 | { |
||
175 | if (_GridSetting.Unit == GridUnit.Inch) |
||
176 | { |
||
177 | double temp = value; |
||
178 | value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
||
179 | } |
||
180 | } |
||
181 | |||
182 | return value; |
||
183 | } |
||
184 | 06b40010 | gaqhf | |
185 | c3e8fa8e | gaqhf | public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15) |
186 | 5dfb8a24 | gaqhf | { |
187 | if (x1 - x2 == 0) |
||
188 | { |
||
189 | return SlopeType.VERTICAL; |
||
190 | } |
||
191 | else |
||
192 | { |
||
193 | double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
||
194 | c3e8fa8e | gaqhf | if (angle <= degree) |
195 | 5dfb8a24 | gaqhf | return SlopeType.HORIZONTAL; |
196 | c3e8fa8e | gaqhf | else if (angle >= 90 - degree) |
197 | 5dfb8a24 | gaqhf | return SlopeType.VERTICAL; |
198 | else |
||
199 | return SlopeType.Slope; |
||
200 | } |
||
201 | } |
||
202 | 32205389 | gaqhf | public static double CalcAngle(double x1, double y1, double x2, double y2) |
203 | { |
||
204 | 60f4405d | gaqhf | double result = 90; |
205 | 32205389 | gaqhf | if (x1 - x2 != 0) |
206 | { |
||
207 | result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
||
208 | } |
||
209 | return result; |
||
210 | } |
||
211 | 5e6ecf05 | gaqhf | public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y) |
212 | { |
||
213 | |||
214 | double distance = 0; |
||
215 | if (lineX1 == lineX2) |
||
216 | distance = Math.Abs(x - lineX1); |
||
217 | else |
||
218 | { |
||
219 | double a; |
||
220 | double b; |
||
221 | double c; |
||
222 | |||
223 | a = (lineY2 - lineY1) / (lineX2 - lineX1); |
||
224 | b = -1; |
||
225 | c = -a * lineX1 + lineY1; |
||
226 | |||
227 | distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5); |
||
228 | } |
||
229 | return distance; |
||
230 | } |
||
231 | |||
232 | 56bc67e1 | gaqhf | public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) |
233 | { |
||
234 | double a1; |
||
235 | double a2; |
||
236 | double b1; |
||
237 | double b2; |
||
238 | |||
239 | if (x1 == x2) |
||
240 | a1 = 0; |
||
241 | else |
||
242 | a1 = (y2 - y1) / (x2 - x1); |
||
243 | if (x3 == x4) |
||
244 | a2 = 0; |
||
245 | else |
||
246 | a2 = (y4 - y3) / (x4 - x3); |
||
247 | |||
248 | b1 = -a1 * x1 + y1; |
||
249 | b2 = -a2 * x3 + y3; |
||
250 | |||
251 | 32205389 | gaqhf | if (x1 == x2 && x3 == x4) |
252 | 56bc67e1 | gaqhf | { |
253 | return null; |
||
254 | } |
||
255 | else if (x1 == x2) |
||
256 | { |
||
257 | return new double[] { x1, a2*x1 + b2 }; |
||
258 | } |
||
259 | else if (x3 == x4) |
||
260 | { |
||
261 | return new double[] { x3, a1 * x3 + b1 }; |
||
262 | } |
||
263 | else |
||
264 | { |
||
265 | 32205389 | gaqhf | return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 }; |
266 | } |
||
267 | } |
||
268 | |||
269 | public static double CalcGradient(double x1, double y1, double x2, double y2) |
||
270 | { |
||
271 | double result = double.NaN; |
||
272 | |||
273 | if (x1 != x2) |
||
274 | result = (y2 - y1) / (x2 - x1); |
||
275 | |||
276 | return result; |
||
277 | 56bc67e1 | gaqhf | } |
278 | d1eac84d | gaqhf | |
279 | 30a9ffce | gaqhf | public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
280 | { |
||
281 | return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
||
282 | } |
||
283 | |||
284 | bca81f4c | gaqhf | public static object FindObjectByUID(Document document, string UID) |
285 | { |
||
286 | d63050d6 | gaqhf | if (!string.IsNullOrEmpty(UID) && UID != "None") |
287 | bca81f4c | gaqhf | { |
288 | d63050d6 | gaqhf | foreach (Symbol item in document.SYMBOLS) |
289 | { |
||
290 | if (item.UID == UID) |
||
291 | return item; |
||
292 | } |
||
293 | bca81f4c | gaqhf | |
294 | d63050d6 | gaqhf | foreach (Line item in document.LINES) |
295 | { |
||
296 | if (item.UID == UID) |
||
297 | return item; |
||
298 | } |
||
299 | bca81f4c | gaqhf | |
300 | d63050d6 | gaqhf | foreach (Text item in document.TEXTINFOS) |
301 | { |
||
302 | if (item.UID == UID) |
||
303 | return item; |
||
304 | } |
||
305 | bca81f4c | gaqhf | |
306 | d63050d6 | gaqhf | foreach (Note item in document.NOTES) |
307 | { |
||
308 | if (item.UID == UID) |
||
309 | return item; |
||
310 | } |
||
311 | bca81f4c | gaqhf | |
312 | d63050d6 | gaqhf | foreach (LineNumber item in document.LINENUMBERS) |
313 | { |
||
314 | if (item.UID == UID) |
||
315 | return item; |
||
316 | } |
||
317 | bca81f4c | gaqhf | |
318 | d63050d6 | gaqhf | foreach (Equipment item in document.Equipments) |
319 | { |
||
320 | if (item.UID == UID) |
||
321 | return item; |
||
322 | } |
||
323 | 30ba9ae0 | gaqhf | |
324 | foreach (SpecBreak item in document.SpecBreaks) |
||
325 | { |
||
326 | if (item.UID == UID) |
||
327 | return item; |
||
328 | } |
||
329 | |||
330 | foreach (EndBreak item in document.EndBreaks) |
||
331 | { |
||
332 | if (item.UID == UID) |
||
333 | return item; |
||
334 | } |
||
335 | fb2d9638 | gaqhf | |
336 | foreach (VendorPackage item in document.VendorPackages) |
||
337 | { |
||
338 | if (item.UID == UID) |
||
339 | return item; |
||
340 | } |
||
341 | 809a7640 | gaqhf | } |
342 | |||
343 | bca81f4c | gaqhf | return null; |
344 | } |
||
345 | d1eac84d | gaqhf | |
346 | 335b7a24 | gaqhf | public static List<Line> FindLinesByModelId(Document document, string ModelItemId) |
347 | { |
||
348 | List<Line> lines = new List<Line>(); |
||
349 | foreach (Line item in document.LINES) |
||
350 | { |
||
351 | if (item.SPPID.ModelItemId == ModelItemId) |
||
352 | lines.Add(item); |
||
353 | } |
||
354 | |||
355 | return lines; |
||
356 | } |
||
357 | d1eac84d | gaqhf | |
358 | 4d2571ab | gaqhf | public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group) |
359 | b9cc9254 | gaqhf | { |
360 | f1a7faf9 | gaqhf | if (!group.Contains(symbol)) |
361 | group.Add(symbol); |
||
362 | |||
363 | 4d2571ab | gaqhf | foreach (var connector in symbol.CONNECTORS) |
364 | b9cc9254 | gaqhf | { |
365 | 4d2571ab | gaqhf | object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM); |
366 | if (connectedItem != null && connectedItem.GetType() == typeof(Symbol)) |
||
367 | b9cc9254 | gaqhf | { |
368 | 4d2571ab | gaqhf | Symbol connSymbol = connectedItem as Symbol; |
369 | if (!group.Contains(connSymbol)) |
||
370 | b9cc9254 | gaqhf | { |
371 | 4d2571ab | gaqhf | group.Add(connSymbol); |
372 | FindConnectedSymbolGroup(document, connSymbol, group); |
||
373 | b9cc9254 | gaqhf | } |
374 | } |
||
375 | } |
||
376 | } |
||
377 | |||
378 | 4d2571ab | gaqhf | public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group) |
379 | d1eac84d | gaqhf | { |
380 | 4d2571ab | gaqhf | Symbol result = null; |
381 | |||
382 | // Group의 가운데 찾기 |
||
383 | if (group.Count == 3) |
||
384 | d1eac84d | gaqhf | { |
385 | 4d2571ab | gaqhf | foreach (var symbol in group) |
386 | { |
||
387 | int count = 0; |
||
388 | foreach (var connector in symbol.CONNECTORS) |
||
389 | { |
||
390 | object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
||
391 | if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol)) |
||
392 | count++; |
||
393 | } |
||
394 | d1eac84d | gaqhf | |
395 | 4d2571ab | gaqhf | if (count == 2) |
396 | { |
||
397 | result = symbol; |
||
398 | break; |
||
399 | } |
||
400 | } |
||
401 | d1eac84d | gaqhf | } |
402 | |||
403 | 4d2571ab | gaqhf | return result; |
404 | d1eac84d | gaqhf | } |
405 | |||
406 | private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup) |
||
407 | { |
||
408 | foreach (Connector connector in symbol.CONNECTORS) |
||
409 | { |
||
410 | object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
||
411 | if (item != null && item.GetType() == typeof(Symbol)) |
||
412 | { |
||
413 | Symbol connSymbol = item as Symbol; |
||
414 | if (connSymbol != null && !symbolGroup.Contains(connSymbol)) |
||
415 | { |
||
416 | symbolGroup.Add(connSymbol); |
||
417 | GetConnectedSymbol(document, connSymbol, symbolGroup); |
||
418 | } |
||
419 | } |
||
420 | } |
||
421 | } |
||
422 | 2fdb56bf | gaqhf | |
423 | public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol) |
||
424 | { |
||
425 | foreach (var connector in targetSymbol.CONNECTORS) |
||
426 | { |
||
427 | if (connector.CONNECTEDITEM == uid) |
||
428 | { |
||
429 | return connector; |
||
430 | } |
||
431 | } |
||
432 | |||
433 | return null; |
||
434 | } |
||
435 | 71ba1ca3 | gaqhf | |
436 | public static Symbol FindSymbolByRepresentationID(Document document, string repID) |
||
437 | { |
||
438 | Symbol findSymbol = null; |
||
439 | foreach (var symbol in document.SYMBOLS) |
||
440 | { |
||
441 | if (symbol.SPPID.RepresentationId == repID) |
||
442 | { |
||
443 | findSymbol = symbol; |
||
444 | } |
||
445 | else |
||
446 | { |
||
447 | ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID); |
||
448 | if (childSymbol != null) |
||
449 | findSymbol = symbol; |
||
450 | } |
||
451 | |||
452 | if (findSymbol != null) |
||
453 | break; |
||
454 | } |
||
455 | |||
456 | return findSymbol; |
||
457 | } |
||
458 | |||
459 | public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID) |
||
460 | { |
||
461 | ChildSymbol childSymbol = null; |
||
462 | |||
463 | foreach (ChildSymbol loopChild in symbol.ChildSymbols) |
||
464 | { |
||
465 | if (loopChild.SPPID.RepresentationId == repID) |
||
466 | { |
||
467 | childSymbol = loopChild; |
||
468 | break; |
||
469 | } |
||
470 | else |
||
471 | { |
||
472 | childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild); |
||
473 | if (childSymbol != null) |
||
474 | break; |
||
475 | } |
||
476 | } |
||
477 | |||
478 | return childSymbol; |
||
479 | } |
||
480 | |||
481 | private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol) |
||
482 | { |
||
483 | ChildSymbol findChild = null; |
||
484 | |||
485 | foreach (var item in childSymbol.ChildSymbols) |
||
486 | { |
||
487 | if (item.SPPID.RepresentationId == repID) |
||
488 | { |
||
489 | findChild = item; |
||
490 | break; |
||
491 | } |
||
492 | else |
||
493 | { |
||
494 | findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item); |
||
495 | if (findChild != null) |
||
496 | break; |
||
497 | } |
||
498 | } |
||
499 | |||
500 | return findChild; |
||
501 | } |
||
502 | d9794a6c | gaqhf | |
503 | public static bool IsBranchLine(Line line1, Line line2) |
||
504 | { |
||
505 | bool result = true; |
||
506 | |||
507 | Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID); |
||
508 | Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID); |
||
509 | |||
510 | if (conn1 != null && conn2 != null) |
||
511 | result = false; |
||
512 | |||
513 | return result; |
||
514 | } |
||
515 | |||
516 | a0e3dca4 | gaqhf | public static bool IsBranchLine(Line line) |
517 | { |
||
518 | cf210438 | gaqhf | Connector connector = line.CONNECTORS.Find(x => |
519 | x.ConnectedObject != null && |
||
520 | x.ConnectedObject.GetType() == typeof(Line) && |
||
521 | a0e3dca4 | gaqhf | IsBranchLine(line, x.ConnectedObject as Line)); |
522 | return connector != null ? true : false; |
||
523 | } |
||
524 | cf210438 | gaqhf | |
525 | public static bool IsBranchedLine(Document document,Line line) |
||
526 | { |
||
527 | return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false; |
||
528 | } |
||
529 | |||
530 | 6d12a734 | gaqhf | public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY) |
531 | d9794a6c | gaqhf | { |
532 | if (range1[0] <= range2[2] && range1[2] >= range2[0]) |
||
533 | { |
||
534 | 6d12a734 | gaqhf | overlapX = true; |
535 | d9794a6c | gaqhf | x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0])); |
536 | } |
||
537 | |||
538 | if (range1[1] <= range2[3] && range1[3] >= range2[1]) |
||
539 | { |
||
540 | 6d12a734 | gaqhf | overlapY = true; |
541 | d9794a6c | gaqhf | y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1])); |
542 | } |
||
543 | } |
||
544 | |||
545 | 1299077b | gaqhf | public static bool IsOverlap(double[] range1, double[] range2) |
546 | { |
||
547 | if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1]) |
||
548 | return true; |
||
549 | else |
||
550 | return false; |
||
551 | } |
||
552 | |||
553 | d9794a6c | gaqhf | public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY) |
554 | { |
||
555 | SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y); |
||
556 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
557 | if (slopeType == SlopeType.HORIZONTAL) |
||
558 | { |
||
559 | double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length; |
||
560 | if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X) |
||
561 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length; |
||
562 | else |
||
563 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length; |
||
564 | } |
||
565 | else if (slopeType == SlopeType.VERTICAL) |
||
566 | { |
||
567 | double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length; |
||
568 | if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y) |
||
569 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length; |
||
570 | else |
||
571 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length; |
||
572 | } |
||
573 | } |
||
574 | a0e3dca4 | gaqhf | |
575 | b2064e69 | gaqhf | public static Line GetConnectedLine(Symbol symbol1, Symbol symbol2) |
576 | { |
||
577 | Line line = null; |
||
578 | Connector connector1 = symbol1.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && |
||
579 | ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol2) != null); |
||
580 | Connector connector2 = symbol2.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) && |
||
581 | ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol1) != null); |
||
582 | if (connector1 != null && connector2 != null) |
||
583 | line = connector1.ConnectedObject as Line; |
||
584 | |||
585 | return line; |
||
586 | } |
||
587 | |||
588 | public static int GetBranchLineCount(Document document, Line line) |
||
589 | { |
||
590 | return document.LINES.FindAll(x => IsBranchLine(line, x) && x.CONNECTORS.Find(y => y.ConnectedObject == line) != null).Count; |
||
591 | } |
||
592 | |||
593 | a0e3dca4 | gaqhf | public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y) |
594 | { |
||
595 | bool bStart = false; |
||
596 | int index = line.CONNECTORS.IndexOf(connector); |
||
597 | if (index == 0) |
||
598 | { |
||
599 | x = line.SPPID.START_X; |
||
600 | y = line.SPPID.START_Y; |
||
601 | bStart = true; |
||
602 | } |
||
603 | else |
||
604 | { |
||
605 | x = line.SPPID.END_X; |
||
606 | y = line.SPPID.END_Y; |
||
607 | } |
||
608 | return bStart; |
||
609 | } |
||
610 | dfac4553 | gaqhf | |
611 | d9fc7084 | gaqhf | public static bool IsSegment(Document document, Line line1, Line line2) |
612 | dfac4553 | gaqhf | { |
613 | bool result = false; |
||
614 | |||
615 | SpecBreak specBreak = document.SpecBreaks.Find(x => |
||
616 | d9fc7084 | gaqhf | (x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) || |
617 | (x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID)); |
||
618 | dfac4553 | gaqhf | |
619 | EndBreak endBreak = document.EndBreaks.Find(x => |
||
620 | d9fc7084 | gaqhf | (x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) || |
621 | (x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID)); |
||
622 | dfac4553 | gaqhf | |
623 | if (specBreak != null || endBreak != null) |
||
624 | result = true; |
||
625 | |||
626 | return result; |
||
627 | } |
||
628 | d23fe61b | gaqhf | |
629 | d9fc7084 | gaqhf | public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2) |
630 | 32205389 | gaqhf | { |
631 | bool result = false; |
||
632 | SpecBreak startSpecBreak = document.SpecBreaks.Find(x => |
||
633 | d9fc7084 | gaqhf | (x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) || |
634 | (x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID)); |
||
635 | 32205389 | gaqhf | |
636 | EndBreak startEndBreak = document.EndBreaks.Find(x => |
||
637 | d9fc7084 | gaqhf | (x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) || |
638 | (x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID)); |
||
639 | 32205389 | gaqhf | |
640 | if (startSpecBreak != null || startEndBreak != null) |
||
641 | result = true; |
||
642 | |||
643 | return result; |
||
644 | } |
||
645 | ea54adc8 | gaqhf | public static void test() |
646 | { |
||
647 | Placement placement = new Placement(); |
||
648 | LMADataSource dataSource = new LMADataSource(); |
||
649 | 518c7651 | gaqhf | LMSymbol symbol = dataSource.GetSymbol("BBAB475FA9AF4C01AACF4C51F56241F8"); |
650 | |||
651 | string[] array1 = new string[] { "", "Top" }; |
||
652 | string[] array2 = new string[] { "", "0.005" }; |
||
653 | placement.PIDApplyParameters(symbol.AsLMRepresentation(), array1, array2); |
||
654 | ea54adc8 | gaqhf | |
655 | ReleaseCOMObjects(dataSource); |
||
656 | } |
||
657 | public static DataTable GetUnitInfo() |
||
658 | { |
||
659 | LMADataSource dataSource = new LMADataSource(); |
||
660 | LMUnits units = new LMUnits(); |
||
661 | units.Collect(dataSource); |
||
662 | DataTable dt = new DataTable(); |
||
663 | dt.Columns.Add("LEVEL", typeof(string)); |
||
664 | dt.Columns.Add("SP_ID", typeof(string)); |
||
665 | dt.Columns.Add("PARENTID", typeof(string)); |
||
666 | dt.Columns.Add("NAME", typeof(string)); |
||
667 | foreach (LMUnit unit in units) |
||
668 | { |
||
669 | string dir = unit.get_Dir_Path(); |
||
670 | string[] array = dir.Split('\\'); |
||
671 | List<string> parents = new List<string>(); |
||
672 | string prevId = "-1"; |
||
673 | for (int i = 1; i < array.Length; i++) |
||
674 | { |
||
675 | string name = array[i]; |
||
676 | string uid = Guid.NewGuid().ToString(); |
||
677 | DataRow[] rows = dt.Select(string.Format("LEVEL = '{0}' AND NAME = '{1}' AND PARENTID = '{2}'", i, name, prevId)); |
||
678 | if (rows.Length == 0) |
||
679 | dt.Rows.Add(i, uid, prevId, name); |
||
680 | else |
||
681 | uid = rows[0]["SP_ID"].ToString(); |
||
682 | prevId = uid; |
||
683 | } |
||
684 | } |
||
685 | |||
686 | dt.Columns.Remove("LEVEL"); |
||
687 | |||
688 | ReleaseCOMObjects(units); |
||
689 | ReleaseCOMObjects(dataSource); |
||
690 | |||
691 | return dt; |
||
692 | } |
||
693 | public static string T_OPTIONSETTING_Value(string name) |
||
694 | { |
||
695 | string result = string.Empty; |
||
696 | LMADataSource dataSource = new LMADataSource(); |
||
697 | LMOptionSettings settings = new LMOptionSettings(); |
||
698 | |||
699 | LMAFilter filter = new LMAFilter(); |
||
700 | LMACriterion criterion = new LMACriterion(); |
||
701 | filter.ItemType = "OptionSetting"; |
||
702 | criterion.SourceAttributeName = "NAME"; |
||
703 | criterion.Operator = "="; |
||
704 | criterion.set_ValueAttribute(name); |
||
705 | filter.get_Criteria().Add(criterion); |
||
706 | settings.Collect(dataSource, Filter: filter); |
||
707 | |||
708 | foreach (LMOptionSetting item in settings) |
||
709 | { |
||
710 | result = item.get_Value(); |
||
711 | break; |
||
712 | } |
||
713 | |||
714 | ReleaseCOMObjects(criterion); |
||
715 | ReleaseCOMObjects(filter); |
||
716 | ReleaseCOMObjects(settings); |
||
717 | ReleaseCOMObjects(dataSource); |
||
718 | return result; |
||
719 | } |
||
720 | |||
721 | a80baec5 | gaqhf | public static string T_PLANTSETTING_Value(string name) |
722 | { |
||
723 | string result = string.Empty; |
||
724 | LMADataSource dataSource = new LMADataSource(); |
||
725 | LMPlantSettings settings = new LMPlantSettings(); |
||
726 | |||
727 | LMAFilter filter = new LMAFilter(); |
||
728 | LMACriterion criterion = new LMACriterion(); |
||
729 | filter.ItemType = "PlantSetting"; |
||
730 | criterion.SourceAttributeName = "NAME"; |
||
731 | criterion.Operator = "="; |
||
732 | criterion.set_ValueAttribute(name); |
||
733 | filter.get_Criteria().Add(criterion); |
||
734 | settings.Collect(dataSource, Filter: filter); |
||
735 | |||
736 | foreach (LMPlantSetting item in settings) |
||
737 | { |
||
738 | result = item.get_Value(); |
||
739 | break; |
||
740 | } |
||
741 | |||
742 | ReleaseCOMObjects(criterion); |
||
743 | ReleaseCOMObjects(filter); |
||
744 | ReleaseCOMObjects(settings); |
||
745 | ReleaseCOMObjects(dataSource); |
||
746 | return result; |
||
747 | } |
||
748 | |||
749 | ea54adc8 | gaqhf | public static void ReleaseCOMObjects(params object[] objVars) |
750 | { |
||
751 | int intNewRefCount = 0; |
||
752 | foreach (object obj in objVars) |
||
753 | { |
||
754 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
755 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
756 | } |
||
757 | } |
||
758 | 23eb98bf | gaqhf | } |
759 | } |