프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 9a554a33

이력 | 보기 | 이력해설 | 다운로드 (27.1 KB)

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