프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 58bf9dec

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