프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 32da6a8a

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