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