hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 0cab8feb
이력 | 보기 | 이력해설 | 다운로드 (21.2 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 | 23eb98bf | gaqhf | |
14 | b8e2644e | gaqhf | namespace Converter.SPPID.Util |
15 | 23eb98bf | gaqhf | { |
16 | 5dfb8a24 | gaqhf | public enum SlopeType |
17 | { |
||
18 | d1eac84d | gaqhf | None, |
19 | 5dfb8a24 | gaqhf | Slope, |
20 | HORIZONTAL, |
||
21 | VERTICAL |
||
22 | } |
||
23 | 23eb98bf | gaqhf | public class SPPIDUtil |
24 | { |
||
25 | fab4f207 | gaqhf | public static bool ConvertToSPPIDInfo(string jsonString) |
26 | 23eb98bf | gaqhf | { |
27 | 2e1e3c12 | gaqhf | SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance(); |
28 | 23eb98bf | gaqhf | try |
29 | { |
||
30 | fab4f207 | gaqhf | SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString); |
31 | 23eb98bf | gaqhf | |
32 | _SPPIDInfo.DBType = jsonSPPIDInfo.DBType; |
||
33 | _SPPIDInfo.Service = jsonSPPIDInfo.Service; |
||
34 | _SPPIDInfo.Site = jsonSPPIDInfo.Site; |
||
35 | _SPPIDInfo.ServerIP = jsonSPPIDInfo.ServerIP; |
||
36 | _SPPIDInfo.Port = jsonSPPIDInfo.Port; |
||
37 | _SPPIDInfo.DBUser = jsonSPPIDInfo.DBUser; |
||
38 | _SPPIDInfo.DBPassword = jsonSPPIDInfo.DBPassword; |
||
39 | _SPPIDInfo.PlantPath = jsonSPPIDInfo.PlantPath; |
||
40 | _SPPIDInfo.PlantDic = jsonSPPIDInfo.PlantDic; |
||
41 | _SPPIDInfo.PlantPID = jsonSPPIDInfo.PlantPID; |
||
42 | _SPPIDInfo.PlantPIDDic = jsonSPPIDInfo.PlantPIDDic; |
||
43 | _SPPIDInfo.Plant = jsonSPPIDInfo.Plant; |
||
44 | _SPPIDInfo.Enable = jsonSPPIDInfo.Enable; |
||
45 | _SPPIDInfo.SelectedPlant = jsonSPPIDInfo.SelectedPlant; |
||
46 | _SPPIDInfo.PlantList = jsonSPPIDInfo.PlantList; |
||
47 | |||
48 | } |
||
49 | catch (Exception ex) |
||
50 | { |
||
51 | fab4f207 | gaqhf | _SPPIDInfo.Enable = false; |
52 | 23eb98bf | gaqhf | return false; |
53 | } |
||
54 | return true; |
||
55 | } |
||
56 | 5dfb8a24 | gaqhf | |
57 | e00e891d | gaqhf | public static bool ConvertToETCSetting(string jsonString) |
58 | { |
||
59 | ETCSetting _ETCSetting = ETCSetting.GetInstance(); |
||
60 | try |
||
61 | { |
||
62 | ETCSetting jsonETCSetting = JsonConvert.DeserializeObject<ETCSetting>(jsonString); |
||
63 | |||
64 | _ETCSetting.NoteSymbolPath = jsonETCSetting.NoteSymbolPath; |
||
65 | _ETCSetting.TextSymbolPath = jsonETCSetting.TextSymbolPath; |
||
66 | _ETCSetting.DrainValveSize = jsonETCSetting.DrainValveSize; |
||
67 | fbea6028 | gaqhf | _ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath; |
68 | 1a3a74a8 | gaqhf | _ETCSetting.TextLocation = jsonETCSetting.TextLocation; |
69 | _ETCSetting.NoteLocation = jsonETCSetting.NoteLocation; |
||
70 | _ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation; |
||
71 | b2d1c1aa | gaqhf | _ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath; |
72 | e00e891d | gaqhf | } |
73 | catch (Exception ex) |
||
74 | { |
||
75 | return false; |
||
76 | } |
||
77 | return true; |
||
78 | } |
||
79 | bca81f4c | gaqhf | |
80 | 7cbb1038 | gaqhf | public static bool ConvertToGridSetting(string jsonString) |
81 | { |
||
82 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
83 | try |
||
84 | { |
||
85 | GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString); |
||
86 | |||
87 | _GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid; |
||
88 | _GridSetting.Density = jsonGridSetting.Density; |
||
89 | _GridSetting.Unit = jsonGridSetting.Unit; |
||
90 | } |
||
91 | catch (Exception ex) |
||
92 | { |
||
93 | return false; |
||
94 | } |
||
95 | return true; |
||
96 | } |
||
97 | |||
98 | 39a2a688 | gaqhf | public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY) |
99 | { |
||
100 | try |
||
101 | { |
||
102 | string[] pointArr = sPoint.Split(new char[] { ',' }); |
||
103 | if (pointArr.Length == 2) |
||
104 | { |
||
105 | dX = Convert.ToDouble(pointArr[0]); |
||
106 | dY = Convert.ToDouble(pointArr[1]); |
||
107 | } |
||
108 | } |
||
109 | catch (Exception) |
||
110 | { |
||
111 | dX = 0; |
||
112 | dY = 0; |
||
113 | return false; |
||
114 | } |
||
115 | |||
116 | return true; |
||
117 | } |
||
118 | bca81f4c | gaqhf | |
119 | 39a2a688 | gaqhf | public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height) |
120 | { |
||
121 | 1b261371 | gaqhf | decimal calcX = 0; |
122 | decimal calcY = 0; |
||
123 | decimal tempX = Convert.ToDecimal(dX); |
||
124 | decimal tempY = Convert.ToDecimal(dY); |
||
125 | decimal tempWidth = Convert.ToDecimal(SPPID_Width); |
||
126 | decimal tempHeight = Convert.ToDecimal(SPPID_Height); |
||
127 | decimal tempDwgX = Convert.ToDecimal(dDwgX); |
||
128 | decimal tempDwgY = Convert.ToDecimal(dDwgY); |
||
129 | |||
130 | calcX = (tempX * tempWidth) / tempDwgX; |
||
131 | calcY = tempHeight - ((tempY * tempHeight) / tempDwgY); |
||
132 | c3d2e266 | gaqhf | dX = Convert.ToDouble(calcX); |
133 | dY = Convert.ToDouble(calcY); |
||
134 | 39a2a688 | gaqhf | } |
135 | bca81f4c | gaqhf | |
136 | 06b40010 | gaqhf | public static void ConvertGridPoint(ref double x, ref double y) |
137 | { |
||
138 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
139 | if (_GridSetting.UseSnapGrid) |
||
140 | { |
||
141 | if (_GridSetting.Unit == GridUnit.Inch) |
||
142 | { |
||
143 | double length = _GridSetting.Density * 0.0254; |
||
144 | double tempX = x; |
||
145 | double tempY = y; |
||
146 | x = Math.Round(tempX / length) * length; |
||
147 | y = Math.Round(tempY / length) * length; |
||
148 | b66a2996 | gaqhf | } |
149 | } |
||
150 | } |
||
151 | 4d2571ab | gaqhf | |
152 | b66a2996 | gaqhf | public static void ConvertGridPointOnlyOnePoint(ref double value) |
153 | { |
||
154 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
155 | if (_GridSetting.UseSnapGrid) |
||
156 | { |
||
157 | if (_GridSetting.Unit == GridUnit.Inch) |
||
158 | { |
||
159 | double temp = value; |
||
160 | d9794a6c | gaqhf | value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
161 | 06b40010 | gaqhf | } |
162 | } |
||
163 | } |
||
164 | a0e3dca4 | gaqhf | public static double ConvertGridPointOnlyOnePoint(double value) |
165 | { |
||
166 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
167 | if (_GridSetting.UseSnapGrid) |
||
168 | { |
||
169 | if (_GridSetting.Unit == GridUnit.Inch) |
||
170 | { |
||
171 | double temp = value; |
||
172 | value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length; |
||
173 | } |
||
174 | } |
||
175 | |||
176 | return value; |
||
177 | } |
||
178 | 06b40010 | gaqhf | |
179 | 5dfb8a24 | gaqhf | public static SlopeType CalcSlope(double x1, double y1, double x2, double y2) |
180 | { |
||
181 | if (x1 - x2 == 0) |
||
182 | { |
||
183 | return SlopeType.VERTICAL; |
||
184 | } |
||
185 | else |
||
186 | { |
||
187 | double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
||
188 | d9794a6c | gaqhf | if (angle <= 15) |
189 | 5dfb8a24 | gaqhf | return SlopeType.HORIZONTAL; |
190 | d9794a6c | gaqhf | else if (angle >= 75) |
191 | 5dfb8a24 | gaqhf | return SlopeType.VERTICAL; |
192 | else |
||
193 | return SlopeType.Slope; |
||
194 | } |
||
195 | } |
||
196 | 32205389 | gaqhf | public static double CalcAngle(double x1, double y1, double x2, double y2) |
197 | { |
||
198 | 60f4405d | gaqhf | double result = 90; |
199 | 32205389 | gaqhf | if (x1 - x2 != 0) |
200 | { |
||
201 | result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI; |
||
202 | } |
||
203 | return result; |
||
204 | } |
||
205 | 5e6ecf05 | gaqhf | public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y) |
206 | { |
||
207 | |||
208 | double distance = 0; |
||
209 | if (lineX1 == lineX2) |
||
210 | distance = Math.Abs(x - lineX1); |
||
211 | else |
||
212 | { |
||
213 | double a; |
||
214 | double b; |
||
215 | double c; |
||
216 | |||
217 | a = (lineY2 - lineY1) / (lineX2 - lineX1); |
||
218 | b = -1; |
||
219 | c = -a * lineX1 + lineY1; |
||
220 | |||
221 | distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5); |
||
222 | } |
||
223 | return distance; |
||
224 | } |
||
225 | |||
226 | 56bc67e1 | gaqhf | public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) |
227 | { |
||
228 | double a1; |
||
229 | double a2; |
||
230 | double b1; |
||
231 | double b2; |
||
232 | |||
233 | if (x1 == x2) |
||
234 | a1 = 0; |
||
235 | else |
||
236 | a1 = (y2 - y1) / (x2 - x1); |
||
237 | if (x3 == x4) |
||
238 | a2 = 0; |
||
239 | else |
||
240 | a2 = (y4 - y3) / (x4 - x3); |
||
241 | |||
242 | b1 = -a1 * x1 + y1; |
||
243 | b2 = -a2 * x3 + y3; |
||
244 | |||
245 | 32205389 | gaqhf | if (x1 == x2 && x3 == x4) |
246 | 56bc67e1 | gaqhf | { |
247 | return null; |
||
248 | } |
||
249 | else if (x1 == x2) |
||
250 | { |
||
251 | return new double[] { x1, a2*x1 + b2 }; |
||
252 | } |
||
253 | else if (x3 == x4) |
||
254 | { |
||
255 | return new double[] { x3, a1 * x3 + b1 }; |
||
256 | } |
||
257 | else |
||
258 | { |
||
259 | 32205389 | gaqhf | return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 }; |
260 | } |
||
261 | } |
||
262 | |||
263 | public static double CalcGradient(double x1, double y1, double x2, double y2) |
||
264 | { |
||
265 | double result = double.NaN; |
||
266 | |||
267 | if (x1 != x2) |
||
268 | result = (y2 - y1) / (x2 - x1); |
||
269 | |||
270 | return result; |
||
271 | 56bc67e1 | gaqhf | } |
272 | d1eac84d | gaqhf | |
273 | 30a9ffce | gaqhf | public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2) |
274 | { |
||
275 | return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5); |
||
276 | } |
||
277 | |||
278 | bca81f4c | gaqhf | public static object FindObjectByUID(Document document, string UID) |
279 | { |
||
280 | d63050d6 | gaqhf | if (!string.IsNullOrEmpty(UID) && UID != "None") |
281 | bca81f4c | gaqhf | { |
282 | d63050d6 | gaqhf | foreach (Symbol item in document.SYMBOLS) |
283 | { |
||
284 | if (item.UID == UID) |
||
285 | return item; |
||
286 | } |
||
287 | bca81f4c | gaqhf | |
288 | d63050d6 | gaqhf | foreach (Line item in document.LINES) |
289 | { |
||
290 | if (item.UID == UID) |
||
291 | return item; |
||
292 | } |
||
293 | bca81f4c | gaqhf | |
294 | d63050d6 | gaqhf | foreach (Text item in document.TEXTINFOS) |
295 | { |
||
296 | if (item.UID == UID) |
||
297 | return item; |
||
298 | } |
||
299 | bca81f4c | gaqhf | |
300 | d63050d6 | gaqhf | foreach (Note item in document.NOTES) |
301 | { |
||
302 | if (item.UID == UID) |
||
303 | return item; |
||
304 | } |
||
305 | bca81f4c | gaqhf | |
306 | d63050d6 | gaqhf | foreach (LineNumber item in document.LINENUMBERS) |
307 | { |
||
308 | if (item.UID == UID) |
||
309 | return item; |
||
310 | } |
||
311 | bca81f4c | gaqhf | |
312 | d63050d6 | gaqhf | foreach (Equipment item in document.Equipments) |
313 | { |
||
314 | if (item.UID == UID) |
||
315 | return item; |
||
316 | } |
||
317 | 30ba9ae0 | gaqhf | |
318 | foreach (SpecBreak item in document.SpecBreaks) |
||
319 | { |
||
320 | if (item.UID == UID) |
||
321 | return item; |
||
322 | } |
||
323 | |||
324 | foreach (EndBreak item in document.EndBreaks) |
||
325 | { |
||
326 | if (item.UID == UID) |
||
327 | return item; |
||
328 | } |
||
329 | fb2d9638 | gaqhf | |
330 | foreach (VendorPackage item in document.VendorPackages) |
||
331 | { |
||
332 | if (item.UID == UID) |
||
333 | return item; |
||
334 | } |
||
335 | 809a7640 | gaqhf | } |
336 | |||
337 | bca81f4c | gaqhf | return null; |
338 | } |
||
339 | d1eac84d | gaqhf | |
340 | 335b7a24 | gaqhf | public static List<Line> FindLinesByModelId(Document document, string ModelItemId) |
341 | { |
||
342 | List<Line> lines = new List<Line>(); |
||
343 | foreach (Line item in document.LINES) |
||
344 | { |
||
345 | if (item.SPPID.ModelItemId == ModelItemId) |
||
346 | lines.Add(item); |
||
347 | } |
||
348 | |||
349 | return lines; |
||
350 | } |
||
351 | d1eac84d | gaqhf | |
352 | 4d2571ab | gaqhf | public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group) |
353 | b9cc9254 | gaqhf | { |
354 | f1a7faf9 | gaqhf | if (!group.Contains(symbol)) |
355 | group.Add(symbol); |
||
356 | |||
357 | 4d2571ab | gaqhf | foreach (var connector in symbol.CONNECTORS) |
358 | b9cc9254 | gaqhf | { |
359 | 4d2571ab | gaqhf | object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM); |
360 | if (connectedItem != null && connectedItem.GetType() == typeof(Symbol)) |
||
361 | b9cc9254 | gaqhf | { |
362 | 4d2571ab | gaqhf | Symbol connSymbol = connectedItem as Symbol; |
363 | if (!group.Contains(connSymbol)) |
||
364 | b9cc9254 | gaqhf | { |
365 | 4d2571ab | gaqhf | group.Add(connSymbol); |
366 | FindConnectedSymbolGroup(document, connSymbol, group); |
||
367 | b9cc9254 | gaqhf | } |
368 | } |
||
369 | } |
||
370 | } |
||
371 | |||
372 | 4d2571ab | gaqhf | public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group) |
373 | d1eac84d | gaqhf | { |
374 | 4d2571ab | gaqhf | Symbol result = null; |
375 | |||
376 | // Group의 가운데 찾기 |
||
377 | if (group.Count == 3) |
||
378 | d1eac84d | gaqhf | { |
379 | 4d2571ab | gaqhf | foreach (var symbol in group) |
380 | { |
||
381 | int count = 0; |
||
382 | foreach (var connector in symbol.CONNECTORS) |
||
383 | { |
||
384 | object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
||
385 | if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol)) |
||
386 | count++; |
||
387 | } |
||
388 | d1eac84d | gaqhf | |
389 | 4d2571ab | gaqhf | if (count == 2) |
390 | { |
||
391 | result = symbol; |
||
392 | break; |
||
393 | } |
||
394 | } |
||
395 | d1eac84d | gaqhf | } |
396 | |||
397 | 4d2571ab | gaqhf | return result; |
398 | d1eac84d | gaqhf | } |
399 | |||
400 | private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup) |
||
401 | { |
||
402 | foreach (Connector connector in symbol.CONNECTORS) |
||
403 | { |
||
404 | object item = FindObjectByUID(document, connector.CONNECTEDITEM); |
||
405 | if (item != null && item.GetType() == typeof(Symbol)) |
||
406 | { |
||
407 | Symbol connSymbol = item as Symbol; |
||
408 | if (connSymbol != null && !symbolGroup.Contains(connSymbol)) |
||
409 | { |
||
410 | symbolGroup.Add(connSymbol); |
||
411 | GetConnectedSymbol(document, connSymbol, symbolGroup); |
||
412 | } |
||
413 | } |
||
414 | } |
||
415 | } |
||
416 | 2fdb56bf | gaqhf | |
417 | public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol) |
||
418 | { |
||
419 | foreach (var connector in targetSymbol.CONNECTORS) |
||
420 | { |
||
421 | if (connector.CONNECTEDITEM == uid) |
||
422 | { |
||
423 | return connector; |
||
424 | } |
||
425 | } |
||
426 | |||
427 | return null; |
||
428 | } |
||
429 | 71ba1ca3 | gaqhf | |
430 | public static Symbol FindSymbolByRepresentationID(Document document, string repID) |
||
431 | { |
||
432 | Symbol findSymbol = null; |
||
433 | foreach (var symbol in document.SYMBOLS) |
||
434 | { |
||
435 | if (symbol.SPPID.RepresentationId == repID) |
||
436 | { |
||
437 | findSymbol = symbol; |
||
438 | } |
||
439 | else |
||
440 | { |
||
441 | ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID); |
||
442 | if (childSymbol != null) |
||
443 | findSymbol = symbol; |
||
444 | } |
||
445 | |||
446 | if (findSymbol != null) |
||
447 | break; |
||
448 | } |
||
449 | |||
450 | return findSymbol; |
||
451 | } |
||
452 | |||
453 | public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID) |
||
454 | { |
||
455 | ChildSymbol childSymbol = null; |
||
456 | |||
457 | foreach (ChildSymbol loopChild in symbol.ChildSymbols) |
||
458 | { |
||
459 | if (loopChild.SPPID.RepresentationId == repID) |
||
460 | { |
||
461 | childSymbol = loopChild; |
||
462 | break; |
||
463 | } |
||
464 | else |
||
465 | { |
||
466 | childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild); |
||
467 | if (childSymbol != null) |
||
468 | break; |
||
469 | } |
||
470 | } |
||
471 | |||
472 | return childSymbol; |
||
473 | } |
||
474 | |||
475 | private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol) |
||
476 | { |
||
477 | ChildSymbol findChild = null; |
||
478 | |||
479 | foreach (var item in childSymbol.ChildSymbols) |
||
480 | { |
||
481 | if (item.SPPID.RepresentationId == repID) |
||
482 | { |
||
483 | findChild = item; |
||
484 | break; |
||
485 | } |
||
486 | else |
||
487 | { |
||
488 | findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item); |
||
489 | if (findChild != null) |
||
490 | break; |
||
491 | } |
||
492 | } |
||
493 | |||
494 | return findChild; |
||
495 | } |
||
496 | d9794a6c | gaqhf | |
497 | public static bool IsBranchLine(Line line1, Line line2) |
||
498 | { |
||
499 | bool result = true; |
||
500 | |||
501 | Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID); |
||
502 | Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID); |
||
503 | |||
504 | if (conn1 != null && conn2 != null) |
||
505 | result = false; |
||
506 | |||
507 | return result; |
||
508 | } |
||
509 | |||
510 | a0e3dca4 | gaqhf | public static bool IsBranchLine(Line line) |
511 | { |
||
512 | cf210438 | gaqhf | Connector connector = line.CONNECTORS.Find(x => |
513 | x.ConnectedObject != null && |
||
514 | x.ConnectedObject.GetType() == typeof(Line) && |
||
515 | a0e3dca4 | gaqhf | IsBranchLine(line, x.ConnectedObject as Line)); |
516 | return connector != null ? true : false; |
||
517 | } |
||
518 | cf210438 | gaqhf | |
519 | public static bool IsBranchedLine(Document document,Line line) |
||
520 | { |
||
521 | return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false; |
||
522 | } |
||
523 | |||
524 | 6d12a734 | gaqhf | public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY) |
525 | d9794a6c | gaqhf | { |
526 | if (range1[0] <= range2[2] && range1[2] >= range2[0]) |
||
527 | { |
||
528 | 6d12a734 | gaqhf | overlapX = true; |
529 | d9794a6c | gaqhf | x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0])); |
530 | } |
||
531 | |||
532 | if (range1[1] <= range2[3] && range1[3] >= range2[1]) |
||
533 | { |
||
534 | 6d12a734 | gaqhf | overlapY = true; |
535 | d9794a6c | gaqhf | y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1])); |
536 | } |
||
537 | } |
||
538 | |||
539 | 1299077b | gaqhf | public static bool IsOverlap(double[] range1, double[] range2) |
540 | { |
||
541 | if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1]) |
||
542 | return true; |
||
543 | else |
||
544 | return false; |
||
545 | } |
||
546 | |||
547 | d9794a6c | gaqhf | public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY) |
548 | { |
||
549 | SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y); |
||
550 | GridSetting _GridSetting = GridSetting.GetInstance(); |
||
551 | if (slopeType == SlopeType.HORIZONTAL) |
||
552 | { |
||
553 | double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length; |
||
554 | if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X) |
||
555 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length; |
||
556 | else |
||
557 | symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length; |
||
558 | } |
||
559 | else if (slopeType == SlopeType.VERTICAL) |
||
560 | { |
||
561 | double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length; |
||
562 | if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y) |
||
563 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length; |
||
564 | else |
||
565 | symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length; |
||
566 | } |
||
567 | } |
||
568 | a0e3dca4 | gaqhf | |
569 | public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y) |
||
570 | { |
||
571 | bool bStart = false; |
||
572 | int index = line.CONNECTORS.IndexOf(connector); |
||
573 | if (index == 0) |
||
574 | { |
||
575 | x = line.SPPID.START_X; |
||
576 | y = line.SPPID.START_Y; |
||
577 | bStart = true; |
||
578 | } |
||
579 | else |
||
580 | { |
||
581 | x = line.SPPID.END_X; |
||
582 | y = line.SPPID.END_Y; |
||
583 | } |
||
584 | return bStart; |
||
585 | } |
||
586 | dfac4553 | gaqhf | |
587 | d9fc7084 | gaqhf | public static bool IsSegment(Document document, Line line1, Line line2) |
588 | dfac4553 | gaqhf | { |
589 | bool result = false; |
||
590 | |||
591 | SpecBreak specBreak = document.SpecBreaks.Find(x => |
||
592 | d9fc7084 | gaqhf | (x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) || |
593 | (x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID)); |
||
594 | dfac4553 | gaqhf | |
595 | EndBreak endBreak = document.EndBreaks.Find(x => |
||
596 | d9fc7084 | gaqhf | (x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) || |
597 | (x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID)); |
||
598 | dfac4553 | gaqhf | |
599 | if (specBreak != null || endBreak != null) |
||
600 | result = true; |
||
601 | |||
602 | return result; |
||
603 | } |
||
604 | d23fe61b | gaqhf | |
605 | d9fc7084 | gaqhf | public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2) |
606 | 32205389 | gaqhf | { |
607 | bool result = false; |
||
608 | SpecBreak startSpecBreak = document.SpecBreaks.Find(x => |
||
609 | d9fc7084 | gaqhf | (x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) || |
610 | (x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID)); |
||
611 | 32205389 | gaqhf | |
612 | EndBreak startEndBreak = document.EndBreaks.Find(x => |
||
613 | d9fc7084 | gaqhf | (x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) || |
614 | (x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID)); |
||
615 | 32205389 | gaqhf | |
616 | if (startSpecBreak != null || startEndBreak != null) |
||
617 | result = true; |
||
618 | |||
619 | return result; |
||
620 | } |
||
621 | 23eb98bf | gaqhf | } |
622 | } |