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