프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Util / SPPIDUtil.cs @ 20f9fa83

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