프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 04133d37

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

1
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
using Converter.SPPID.DB;
9
using Converter.BaseModel;
10
using System.Windows.Forms;
11
using Converter.SPPID.Model;
12
using System.Drawing;
13
using Llama;
14
using System.Data;
15
using Plaice;
16
using Microsoft.VisualBasic;
17

    
18
namespace Converter.SPPID.Util
19
{
20
    public enum SlopeType
21
    {
22
        None,
23
        Slope,
24
        HORIZONTAL,
25
        VERTICAL
26
    }
27
    public class SPPIDUtil
28
    {
29
        public static bool ConvertToSPPIDInfo(string jsonString)
30
        {
31
            SPPID_DBInfo _SPPIDInfo = SPPID_DBInfo.GetInstance();
32
            try
33
            {
34
                SPPID_DBInfo jsonSPPIDInfo = JsonConvert.DeserializeObject<SPPID_DBInfo>(jsonString);
35

    
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
                _SPPIDInfo.SQLSERVER_DBNAME = jsonSPPIDInfo.SQLSERVER_DBNAME;
52
                _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

    
57
            }
58
            catch (Exception ex)
59
            {
60
                _SPPIDInfo.Enable = false;
61
                return false;
62
            }
63
            return true;
64
        }
65

    
66
        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
                _ETCSetting.VendorPackageSymbolPath = jsonETCSetting.VendorPackageSymbolPath;
77
                _ETCSetting.TextLocation = jsonETCSetting.TextLocation;
78
                _ETCSetting.NoteLocation = jsonETCSetting.NoteLocation;
79
                _ETCSetting.LineNumberLocation = jsonETCSetting.LineNumberLocation;
80
                _ETCSetting.FlowMarkSymbolPath = jsonETCSetting.FlowMarkSymbolPath;
81
                _ETCSetting.BorderFilePath = jsonETCSetting.BorderFilePath;
82
            }
83
            catch (Exception ex)
84
            {
85
                return false;
86
            }
87
            return true;
88
        }
89

    
90
        public static bool ConvertToGridSetting(string jsonString)
91
        {
92
            GridSetting _GridSetting = GridSetting.GetInstance();
93
            try
94
            {
95
                GridSetting jsonGridSetting = JsonConvert.DeserializeObject<GridSetting>(jsonString);
96

    
97
                _GridSetting.UseSnapGrid = jsonGridSetting.UseSnapGrid;
98
                _GridSetting.Density = jsonGridSetting.Density;
99
                _GridSetting.Unit = jsonGridSetting.Unit;
100
                _GridSetting.DrainValveCellCount = jsonGridSetting.DrainValveCellCount;
101
            }
102
            catch (Exception ex)
103
            {
104
                return false;
105
            }
106
            return true;
107
        }
108

    
109
        public static bool ConvertPointBystring(string sPoint, ref double dX, ref double dY)
110
        {
111
            try
112
            {
113
                string[] pointArr = sPoint.Split(new char[] { ',' });
114
                if (pointArr.Length == 2)
115
                {
116
                    dX = Convert.ToDouble(pointArr[0]);
117
                    dY = Convert.ToDouble(pointArr[1]);
118
                }
119
            }
120
            catch (Exception)
121
            {
122
                dX = 0;
123
                dY = 0;
124
                return false;
125
            }
126

    
127
            return true;
128
        }
129

    
130
        public static void ConvertSPPIDPoint(ref double dX, ref double dY, double dDwgX, double dDwgY, double SPPID_Width, double SPPID_Height)
131
        {
132
            decimal calcX = 0;
133
            decimal calcY = 0;
134
            decimal tempX = Convert.ToDecimal(dX);
135
            decimal tempY = Convert.ToDecimal(dY);
136
            decimal tempWidth = Convert.ToDecimal(SPPID_Width);
137
            decimal tempHeight = Convert.ToDecimal(SPPID_Height);
138
            decimal tempDwgX = Convert.ToDecimal(dDwgX);
139
            decimal tempDwgY = Convert.ToDecimal(dDwgY);
140

    
141
            calcX = (tempX * tempWidth) / tempDwgX;
142
            calcY = tempHeight - ((tempY * tempHeight) / tempDwgY);
143
            dX = Convert.ToDouble(calcX);
144
            dY = Convert.ToDouble(calcY);
145
        }
146

    
147
        public static void ConvertGridPoint(ref double x, ref double y)
148
        {
149
            GridSetting _GridSetting = GridSetting.GetInstance();
150
            if (_GridSetting.UseSnapGrid)
151
            {
152
                if (_GridSetting.Unit == GridUnit.Inch)
153
                {
154
                    double length = _GridSetting.Density * 0.0254;
155
                    double tempX = x;
156
                    double tempY = y;
157
                    x = Math.Round(tempX / length) * length;
158
                    y = Math.Round(tempY / length) * length;
159
                }
160
            }
161
        }
162

    
163
        public static void ConvertGridPointOnlyOnePoint(ref 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
        public static double ConvertGridPointOnlyOnePoint(double value)
176
        {
177
            GridSetting _GridSetting = GridSetting.GetInstance();
178
            if (_GridSetting.UseSnapGrid)
179
            {
180
                if (_GridSetting.Unit == GridUnit.Inch)
181
                {
182
                    double temp = value;
183
                    value = Math.Round(value / _GridSetting.Length) * _GridSetting.Length;
184
                }
185
            }
186

    
187
            return value;
188
        }
189

    
190
        public static SlopeType CalcSlope(double x1, double y1, double x2, double y2, double degree = 15)
191
        {
192
            if (x1 - x2 == 0)
193
            {
194
                return SlopeType.VERTICAL;
195
            }
196
            else
197
            {
198
                double angle = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
199
                if (angle <= degree)
200
                    return SlopeType.HORIZONTAL;
201
                else if (angle >= 90 - degree)
202
                    return SlopeType.VERTICAL;
203
                else
204
                    return SlopeType.Slope;
205
            }
206
        }
207
        public static double CalcAngle(double x1, double y1, double x2, double y2)
208
        {
209
            double result = 90;
210
            if (x1 - x2 != 0)
211
            {
212
                result = Math.Atan(Math.Abs(y2 - y1) / Math.Abs(x2 - x1)) * 180 / Math.PI;
213
            }
214
            return result;
215
        }
216
        public static double CalcLineToPointDistance(double lineX1, double lineY1, double lineX2, double lineY2, double x, double y)
217
        {
218

    
219
            double distance = 0;
220
            if (lineX1 == lineX2)
221
                distance = Math.Abs(x - lineX1);
222
            else
223
            {
224
                double a;
225
                double b;
226
                double c;
227

    
228
                a = (lineY2 - lineY1) / (lineX2 - lineX1);
229
                b = -1;
230
                c = -a * lineX1 + lineY1;
231

    
232
                distance = Math.Abs(a * x + b * y + c) / Math.Pow(a * a + b * b, 0.5);
233
            }
234
            return distance;
235
        }
236

    
237
        public static double[] CalcLineCrossingPoint(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
238
        {
239
            double a1;
240
            double a2;
241
            double b1;
242
            double b2;
243

    
244
            if (x1 == x2)
245
                a1 = 0;
246
            else
247
                a1 = (y2 - y1) / (x2 - x1);
248
            if (x3 == x4)
249
                a2 = 0;
250
            else
251
                a2 = (y4 - y3) / (x4 - x3);
252

    
253
            b1 = -a1 * x1 + y1;
254
            b2 = -a2 * x3 + y3;
255

    
256
            if (x1 == x2 && x3 == x4)
257
            {
258
                return null;
259
            }
260
            else if (x1 == x2)
261
            {
262
                return new double[] { x1, a2*x1 + b2 };
263
            }
264
            else if (x3 == x4)
265
            {
266
                return new double[] { x3, a1 * x3 + b1 };
267
            }
268
            else
269
            {
270
                return new double[] { -(b1 - b2) / (a1 - a2), a1 * -(b1 - b2) / (a1 - a2) + b1 };
271
            }            
272
        }
273

    
274
        public static double CalcGradient(double x1, double y1, double x2, double y2)
275
        {
276
            double result = double.NaN;
277

    
278
            if (x1 != x2)
279
                result = (y2 - y1) / (x2 - x1);
280

    
281
            return result;
282
        }
283

    
284
        public static double CalcPointToPointdDistance(double x1, double y1, double x2, double y2)
285
        {
286
            return Math.Pow(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2), 0.5);
287
        }
288

    
289
        public static object FindObjectByUID(Document document, string UID)
290
        {
291
            if (!string.IsNullOrEmpty(UID) && UID != "None")
292
            {
293
                foreach (Symbol item in document.SYMBOLS)
294
                {
295
                    if (item.UID == UID)
296
                        return item;
297
                }
298

    
299
                foreach (Line item in document.LINES)
300
                {
301
                    if (item.UID == UID)
302
                        return item;
303
                }
304

    
305
                foreach (Text item in document.TEXTINFOS)
306
                {
307
                    if (item.UID == UID)
308
                        return item;
309
                }
310

    
311
                foreach (Note item in document.NOTES)
312
                {
313
                    if (item.UID == UID)
314
                        return item;
315
                }
316

    
317
                foreach (LineNumber item in document.LINENUMBERS)
318
                {
319
                    if (item.UID == UID)
320
                        return item;
321
                }
322

    
323
                foreach (Equipment item in document.Equipments)
324
                {
325
                    if (item.UID == UID)
326
                        return item;
327
                }
328

    
329
                foreach (SpecBreak item in document.SpecBreaks)
330
                {
331
                    if (item.UID == UID)
332
                        return item;
333
                }
334

    
335
                foreach (EndBreak item in document.EndBreaks)
336
                {
337
                    if (item.UID == UID)
338
                        return item;
339
                }
340

    
341
                foreach (VendorPackage item in document.VendorPackages)
342
                {
343
                    if (item.UID == UID)
344
                        return item;
345
                }
346
            }
347

    
348
            return null;
349
        }
350

    
351
        public static List<Line> FindLinesByModelId(Document document, string ModelItemId)
352
        {
353
            List<Line> lines = new List<Line>();
354
            foreach (Line item in document.LINES)
355
            {
356
                if (item.SPPID.ModelItemId == ModelItemId)
357
                    lines.Add(item);
358
            }
359

    
360
            return lines;
361
        }
362

    
363
        public static void FindConnectedSymbolGroup(Document document, Symbol symbol, List<Symbol> group)
364
        {
365
            if (!group.Contains(symbol))
366
                group.Add(symbol);
367

    
368
            foreach (var connector in symbol.CONNECTORS)
369
            {
370
                object connectedItem = FindObjectByUID(document, connector.CONNECTEDITEM);
371
                if (connectedItem != null && connectedItem.GetType() == typeof(Symbol))
372
                {
373
                    Symbol connSymbol = connectedItem as Symbol;
374
                    if (!group.Contains(connSymbol))
375
                    {
376
                        group.Add(connSymbol);
377
                        FindConnectedSymbolGroup(document, connSymbol, group);
378
                    }
379
                }
380
            }
381
        }
382

    
383
        public static Symbol FindCenterAtThreeSymbols(Document document, List<Symbol> group)
384
        {
385
            Symbol result = null;
386

    
387
            // Group의 가운데 찾기
388
            if (group.Count == 3)
389
            {
390
                foreach (var symbol in group)
391
                {
392
                    int count = 0;
393
                    foreach (var connector in symbol.CONNECTORS)
394
                    {
395
                        object item = FindObjectByUID(document, connector.CONNECTEDITEM);
396
                        if (item != null && item.GetType() == typeof(Symbol) && group.Contains(item as Symbol))
397
                            count++;
398
                    }
399

    
400
                    if (count == 2)
401
                    {
402
                        result = symbol;
403
                        break;
404
                    }
405
                }
406
            }
407

    
408
            return result;
409
        }
410

    
411
        private static void GetConnectedSymbol(Document document, Symbol symbol, List<Symbol> symbolGroup)
412
        {
413
            foreach (Connector connector in symbol.CONNECTORS)
414
            {
415
                object item = FindObjectByUID(document, connector.CONNECTEDITEM);
416
                if (item != null && item.GetType() == typeof(Symbol))
417
                {
418
                    Symbol connSymbol = item as Symbol;
419
                    if (connSymbol != null && !symbolGroup.Contains(connSymbol))
420
                    {
421
                        symbolGroup.Add(connSymbol);
422
                        GetConnectedSymbol(document, connSymbol, symbolGroup);
423
                    }
424
                }
425
            }
426
        }
427

    
428
        public static Connector FindSymbolConnectorByUID(Document document, string uid, Symbol targetSymbol)
429
        {
430
            foreach (var connector in targetSymbol.CONNECTORS)
431
            {
432
                if (connector.CONNECTEDITEM == uid)
433
                {
434
                    return connector;
435
                }
436
            }
437

    
438
            return null;
439
        }
440

    
441
        public static Symbol FindSymbolByRepresentationID(Document document, string repID)
442
        {
443
            Symbol findSymbol = null;
444
            foreach (var symbol in document.SYMBOLS)
445
            {
446
                if (symbol.SPPID.RepresentationId == repID)
447
                {
448
                    findSymbol = symbol;
449
                }
450
                else
451
                {
452
                    ChildSymbol childSymbol = FindChildSymbolByRepresentationID(document, symbol, repID);
453
                    if (childSymbol != null)
454
                        findSymbol = symbol;
455
                }
456

    
457
                if (findSymbol != null)
458
                    break;
459
            }
460

    
461
            return findSymbol;
462
        }
463

    
464
        public static ChildSymbol FindChildSymbolByRepresentationID(Document document, Symbol symbol, string repID)
465
        {
466
            ChildSymbol childSymbol = null;
467

    
468
            foreach (ChildSymbol loopChild in symbol.ChildSymbols)
469
            {
470
                if (loopChild.SPPID.RepresentationId == repID)
471
                {
472
                    childSymbol = loopChild;
473
                    break;
474
                }
475
                else
476
                {
477
                    childSymbol = FindChildSymbolByRepresentationIDLoop(document, repID, loopChild);
478
                    if (childSymbol != null)
479
                        break;
480
                }
481
            }
482

    
483
            return childSymbol;
484
        }
485

    
486
        private static ChildSymbol FindChildSymbolByRepresentationIDLoop(Document document, string repID, ChildSymbol childSymbol)
487
        {
488
            ChildSymbol findChild = null;
489

    
490
            foreach (var item in childSymbol.ChildSymbols)
491
            {
492
                if (item.SPPID.RepresentationId == repID)
493
                {
494
                    findChild = item;
495
                    break;
496
                }
497
                else
498
                {
499
                    findChild = FindChildSymbolByRepresentationIDLoop(document, repID, item);
500
                    if (findChild != null)
501
                        break;
502
                }
503
            }
504

    
505
            return findChild;
506
        }
507

    
508
        public static bool IsBranchLine(Line line1, Line line2)
509
        {
510
            bool result = true;
511

    
512
            Connector conn1 = line1.CONNECTORS.Find(x => x.CONNECTEDITEM == line2.UID);
513
            Connector conn2 = line2.CONNECTORS.Find(x => x.CONNECTEDITEM == line1.UID);
514

    
515
            if (conn1 != null && conn2 != null)
516
                result = false;
517

    
518
            return result;
519
        }
520

    
521
        public static bool IsBranchLine(Line line)
522
        {
523
            Connector connector = line.CONNECTORS.Find(x =>
524
            x.ConnectedObject != null &&
525
            x.ConnectedObject.GetType() == typeof(Line) &&
526
            IsBranchLine(line, x.ConnectedObject as Line));
527
            return connector != null ? true : false;
528
        }
529

    
530
        public static bool IsBranchedLine(Document document,Line line)
531
        {
532
            return document.LINES.Find(x => x.CONNECTORS.Find(y => y.CONNECTEDITEM == line.UID && IsBranchLine(x, y.ConnectedObject as Line)) != null) != null ? true : false;
533
        }
534

    
535
        public static void CalcOverlap(double[] range1, double[] range2, ref double x, ref double y, ref bool overlapX, ref bool overlapY)
536
        {
537
            if (range1[0] <= range2[2] && range1[2] >= range2[0])
538
            {
539
                overlapX = true;
540
                x = Math.Min(Math.Abs(range1[0] - range2[2]), Math.Abs(range1[2] - range2[0]));
541
            }
542

    
543
            if (range1[1] <= range2[3] && range1[3] >= range2[1])
544
            {
545
                overlapY = true;
546
                y = Math.Min(Math.Abs(range1[1] - range2[3]), Math.Abs(range1[3] - range2[1]));
547
            }
548
        }
549

    
550
        public static bool IsOverlap(double[] range1, double[] range2)
551
        {
552
            if (range1[0] <= range2[2] && range1[2] >= range2[0] && range1[1] <= range2[3] && range1[3] >= range2[1])
553
                return true;
554
            else
555
                return false;
556
        }
557

    
558
        public static void CalcNewCoordinateForSymbol(Symbol symbol, Symbol prevSymbol, double distanceX, double distanceY)
559
        {
560
            SlopeType slopeType = SPPIDUtil.CalcSlope(prevSymbol.SPPID.ORIGINAL_X, prevSymbol.SPPID.ORIGINAL_Y, symbol.SPPID.ORIGINAL_X, symbol.SPPID.ORIGINAL_Y);
561
            GridSetting _GridSetting = GridSetting.GetInstance();
562
            if (slopeType == SlopeType.HORIZONTAL)
563
            {
564
                double length = (Math.Ceiling(distanceX / _GridSetting.Length) + 1) * _GridSetting.Length;
565
                if (prevSymbol.SPPID.ORIGINAL_X < symbol.SPPID.ORIGINAL_X)
566
                    symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X + length;
567
                else
568
                    symbol.SPPID.ORIGINAL_X = symbol.SPPID.ORIGINAL_X - length;
569
            }
570
            else if (slopeType == SlopeType.VERTICAL)
571
            {
572
                double length = (Math.Ceiling(distanceY / _GridSetting.Length) + 1) * _GridSetting.Length;
573
                if (prevSymbol.SPPID.ORIGINAL_Y < symbol.SPPID.ORIGINAL_Y)
574
                    symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y + length;
575
                else
576
                    symbol.SPPID.ORIGINAL_Y = symbol.SPPID.ORIGINAL_Y - length;
577
            }
578
        }
579

    
580
        public static Line GetConnectedLine(Symbol symbol1, Symbol symbol2)
581
        {
582
            Line line = null;
583
            Connector connector1 = symbol1.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
584
            ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol2) != null);
585
            Connector connector2 = symbol2.CONNECTORS.Find(x => x.ConnectedObject != null && x.ConnectedObject.GetType() == typeof(Line) &&
586
            ((Line)x.ConnectedObject).CONNECTORS.Find(y => y.ConnectedObject == symbol1) != null);
587
            if (connector1 != null && connector2 != null)
588
                line = connector1.ConnectedObject as Line;
589

    
590
            return line;
591
        }
592

    
593
        public static int GetBranchLineCount(Document document, Line line)
594
        {
595
            return document.LINES.FindAll(x => IsBranchLine(line, x) && x.CONNECTORS.Find(y => y.ConnectedObject == line) != null).Count;
596
        }
597

    
598
        public static bool GetLineConnectorPoint(Line line, Connector connector, ref double x, ref double y)
599
        {
600
            bool bStart = false;
601
            int index = line.CONNECTORS.IndexOf(connector);
602
            if (index == 0)
603
            {
604
                x = line.SPPID.START_X;
605
                y = line.SPPID.START_Y;
606
                bStart = true;
607
            }
608
            else
609
            {
610
                x = line.SPPID.END_X;
611
                y = line.SPPID.END_Y;
612
            }
613
            return bStart;
614
        }
615

    
616
        public static bool IsSegment(Document document, Line line1, Line line2)
617
        {
618
            bool result = false;
619

    
620
            SpecBreak specBreak = document.SpecBreaks.Find(x =>
621
                (x.DownStreamUID == line1.UID && x.UpStreamUID == line2.UID) || 
622
                (x.DownStreamUID == line2.UID && x.UpStreamUID == line1.UID));
623

    
624
            EndBreak endBreak = document.EndBreaks.Find(x =>
625
            (x.OWNER == line1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line2.UID) ||
626
            (x.OWNER == line2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == line1.UID));
627

    
628
            if (specBreak != null || endBreak != null)
629
                result = true;
630

    
631
            return result;
632
        }
633

    
634
        public static bool IsSegment(Document document, Symbol symbol1, Symbol symbol2)
635
        {
636
            bool result = false;
637
            SpecBreak startSpecBreak = document.SpecBreaks.Find(x =>
638
            (x.DownStreamUID == symbol1.UID && x.UpStreamUID == symbol2.UID) ||
639
            (x.DownStreamUID == symbol2.UID && x.UpStreamUID == symbol1.UID));
640

    
641
            EndBreak startEndBreak = document.EndBreaks.Find(x =>
642
            (x.OWNER == symbol1.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol2.UID) ||
643
            (x.OWNER == symbol2.UID && x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE == symbol1.UID));
644

    
645
            if (startSpecBreak != null || startEndBreak != null)
646
                result = true;
647

    
648
            return result;
649
        }
650
        public static void test()
651
        {
652
            Placement placement = new Placement();
653
            LMADataSource dataSource = new LMADataSource();
654
            LMSymbol symbol = dataSource.GetSymbol("BBAB475FA9AF4C01AACF4C51F56241F8");
655

    
656
            string[] array1 = new string[] { "", "Top" };
657
            string[] array2 = new string[] { "", "0.005" };
658
            placement.PIDApplyParameters(symbol.AsLMRepresentation(), array1, array2);
659

    
660
            ReleaseCOMObjects(dataSource);
661
        }
662
        public static DataTable GetUnitInfo()
663
        {
664
            LMADataSource dataSource = new LMADataSource();
665
            LMUnits units = new LMUnits();
666
            units.Collect(dataSource);
667
            DataTable dt = new DataTable();
668
            dt.Columns.Add("LEVEL", typeof(string));
669
            dt.Columns.Add("SP_ID", typeof(string));
670
            dt.Columns.Add("PARENTID", typeof(string));
671
            dt.Columns.Add("NAME", typeof(string));
672
            foreach (LMUnit unit in units)
673
            {
674
                string dir = unit.get_Dir_Path();
675
                string[] array = dir.Split('\\');
676
                List<string> parents = new List<string>();
677
                string prevId = "-1";
678
                for (int i = 1; i < array.Length; i++)
679
                {
680
                    string name = array[i];
681
                    string uid = Guid.NewGuid().ToString();
682
                    DataRow[] rows = dt.Select(string.Format("LEVEL = '{0}' AND NAME = '{1}' AND PARENTID = '{2}'", i, name, prevId));
683
                    if (rows.Length == 0)
684
                        dt.Rows.Add(i, uid, prevId, name);
685
                    else
686
                        uid = rows[0]["SP_ID"].ToString();
687
                    prevId = uid;
688
                }
689
            }
690

    
691
            dt.Columns.Remove("LEVEL");
692

    
693
            ReleaseCOMObjects(units);
694
            ReleaseCOMObjects(dataSource);
695

    
696
            return dt;
697
        }
698
        public static string T_OPTIONSETTING_Value(string name)
699
        {
700
            string result = string.Empty;
701
            LMADataSource dataSource = new LMADataSource();
702
            LMOptionSettings settings = new LMOptionSettings();
703

    
704
            LMAFilter filter = new LMAFilter();
705
            LMACriterion criterion = new LMACriterion();
706
            filter.ItemType = "OptionSetting";
707
            criterion.SourceAttributeName = "NAME";
708
            criterion.Operator = "=";
709
            criterion.set_ValueAttribute(name);
710
            filter.get_Criteria().Add(criterion);
711
            settings.Collect(dataSource, Filter: filter);
712

    
713
            foreach (LMOptionSetting item in settings)
714
            {
715
                result = item.get_Value();
716
                break;
717
            }
718

    
719
            ReleaseCOMObjects(criterion);
720
            ReleaseCOMObjects(filter);
721
            ReleaseCOMObjects(settings);
722
            ReleaseCOMObjects(dataSource);
723
            return result;
724
        }
725

    
726
        public static string T_PLANTSETTING_Value(string name)
727
        {
728
            string result = string.Empty;
729
            LMADataSource dataSource = new LMADataSource();
730
            LMPlantSettings settings = new LMPlantSettings();
731

    
732
            LMAFilter filter = new LMAFilter();
733
            LMACriterion criterion = new LMACriterion();
734
            filter.ItemType = "PlantSetting";
735
            criterion.SourceAttributeName = "NAME";
736
            criterion.Operator = "=";
737
            criterion.set_ValueAttribute(name);
738
            filter.get_Criteria().Add(criterion);
739
            settings.Collect(dataSource, Filter: filter);
740

    
741
            foreach (LMPlantSetting item in settings)
742
            {
743
                result = item.get_Value();
744
                break;
745
            }
746

    
747
            ReleaseCOMObjects(criterion);
748
            ReleaseCOMObjects(filter);
749
            ReleaseCOMObjects(settings);
750
            ReleaseCOMObjects(dataSource);
751
            return result;
752
        }
753

    
754
        public static void ReleaseCOMObjects(params object[] objVars)
755
        {
756
            int intNewRefCount = 0;
757
            foreach (object obj in objVars)
758
            {
759
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
760
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
761
            }
762
        }
763
    }
764
}
클립보드 이미지 추가 (최대 크기: 500 MB)