프로젝트

일반

사용자정보

통계
| 브랜치(Branch): | 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ e3bab6e7

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