프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / AutoModeling.cs @ ff4941b2

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

1
using System;
2
using System.Collections.Generic;
3
using System.Collections;
4
using System.Configuration;
5
using System.Data;
6
using System.Data.Common;
7
using System.Data.SqlClient;
8
using System.IO;
9

    
10
using Autodesk.AutoCAD.ApplicationServices;
11
using Autodesk.AutoCAD.ApplicationServices.Core;
12
using Autodesk.AutoCAD.DatabaseServices;
13
using Autodesk.AutoCAD.EditorInput;
14
using Autodesk.AutoCAD.Geometry;
15
using Autodesk.AutoCAD.Interop;
16
using Autodesk.AutoCAD.Interop.Common;
17
using Autodesk.AutoCAD.Runtime;
18
using Autodesk.AutoCAD.Windows;
19

    
20
using AVEVA.PID.Components;
21
using AVEVA.PID.GUI;
22
using AVEVA.PID.Common;
23
using AVEVA.PID.DWGSelector;
24
using AVEVA.PID.Utilities;
25

    
26
using AVEVA.PID.CustomizationUtility.DB;
27
using AVEVA.PID.CustomizationUtility.Model;
28
using AVEVA.PID.CustomizationUtility.Properties;
29

    
30
using DevExpress.XtraSplashScreen;
31

    
32
namespace AVEVA.PID.CustomizationUtility
33
{
34
    public class AutoModeling
35
    {
36
        public static AutoModeling Running { get; set; }
37
        Model.Document document;
38

    
39
        System.Data.DataTable AvevaSymbolTable = null;
40

    
41
        private void SetConvertRule()
42
        {
43
            #region OPC Setting
44
            document.OPCs.Sort(SortOPC);
45
            int SortOPC(OPC a, OPC b)
46
            {
47
                if (a.FlowType == FlowType.In)
48
                    return 1;
49
                else
50
                    return 0;
51
            }
52
            #endregion
53
        }
54

    
55
        public AutoModeling(Model.Document document, System.Data.DataTable AvevaSymbolTable)
56
        {
57
            this.document = document;
58
            this.AvevaSymbolTable = AvevaSymbolTable;
59
        }
60

    
61
        public void CreateDrawing()
62
        {
63
            string outPath = Project_DB.GetDirectiveValue("DRGPTH");
64
            string tempPath = Path.GetTempPath();
65
            string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT");
66

    
67
            DWTSelector.strDrawingNumber = document.AvevaDrawingNumber;
68
            DWTSelector.strSheetNumber = document.AvevaSheetNumber;
69
            DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber;
70
            DWTSelector.strCadFilePath = outPath;
71

    
72
            try
73
            {
74
                string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false);
75
                Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
76
                Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text);
77

    
78
                Commands.addLatestPidvesrionToDictionary();
79
                AVVPropCmd.ActivateAcad();
80

    
81
                if (acadDocument != null)
82
                {
83
                    Running = this;
84
                    acadApplication.ActiveDocument = acadDocument;
85
                    acadDocument.SendCommand("QSAVE ");
86
                    acadDocument.SendCommand("APPIDRun ");
87
                    acadDocument.SendCommand("QSAVE ");
88
                    Running = null;
89
                }
90
            }
91
            catch (System.Exception ex)
92
            {
93
                
94
            }
95

    
96
            GC.Collect();
97
        }
98
        public void Run()
99
        {
100
            try
101
            {
102
                SplashScreenManager.ShowForm(typeof(APIDSplashScreen), true, true);
103
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 2);
104
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetDocumentName, document.AvevaDrawingNumber + document.AvevaSheetNumber);
105
                SetConvertRule();
106

    
107
                RunLineModeling();
108
                RunOPCModeling();
109
                RunSymbolModeling();
110
            }
111
            catch (System.Exception ex)
112
            {
113
                System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace);
114
            }
115
            finally
116
            {
117
                SplashScreenManager.CloseForm(false);
118
            }
119
        }
120

    
121
        #region Run Method
122
        private void RunLineModeling()
123
        {
124
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
125
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling");
126
            foreach (var item in document.LINES)
127
            {
128
                if (item.Aveva.Handle == 0)
129
                    LineModeling(item);
130

    
131
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
132
            }
133
        }
134
        private void RunOPCModeling()
135
        {
136
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.OPCs.Count);
137
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "OPC Modeling");
138
            foreach (var item in document.OPCs)
139
            {
140
                if (item.Aveva.Handle == 0)
141
                    SymbolModeling(item);
142
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
143
            }
144
        }
145
        private void RunSymbolModeling()
146
        {
147
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
148
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
149
            foreach (var item in document.SYMBOLS)
150
            {
151
                if (item.Aveva.Handle == 0)
152
                    SymbolModeling(item);
153
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
154
            }
155
        }
156
        #endregion
157

    
158
        #region Modeling Method
159
        private void LineModeling(Model.Line line)
160
        {
161
            List<Model.Line> groupLine = new List<Model.Line>();
162
            List<string> points = new List<string>();
163
            GetConnectedGroupLine(line, groupLine, false);
164
            GetGroupLinePoints(groupLine, points);
165

    
166
            long handle = 0;
167
            if (line.Aveva.Type == Model.Type.Pipe)
168
                handle = DrawPipe(line.Aveva.Name, points);
169
            else if (line.Aveva.Type == Model.Type.Signal)
170
                handle = DrawSignal(line.Aveva.Name, points);
171

    
172
            foreach (var item in groupLine)
173
                item.Aveva.Handle = handle;
174
        }
175
        private void SymbolModeling(Symbol symbol)
176
        {
177
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
178
            if (allRows.Length == 1)
179
            {
180
                DataRow symbolRow = allRows[0];
181
                bool bAngle = CheckAngle(symbolRow);
182
                bool bBalloon = CheckBalloon(symbol);
183

    
184
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
185
                if (handle != 0)
186
                {
187
                    symbol.Aveva.Handle = handle;
188

    
189
                    if (!bAngle)
190
                    {
191
                        ObjectId objectId = GetObjectIdByHandle(handle);
192
                        if (objectId != ObjectId.Null)
193
                        {
194
                            SetBlockReferenceRotation(objectId, symbol.ANGLE);
195
                        }
196
                    }
197
                }
198
            }
199
        }
200
        #endregion
201

    
202
        #region Drawing Method
203
        private long DrawPipe(string style, List<string> coordinates)
204
        {
205
            List<long> prevHandles = GetAllGroupHandles();
206

    
207
            GUIUtils.SetPipeStyle(style);
208
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
209
            Editor editor = acDoc.Editor;
210
            List<object> commandParam = new List<object>();
211
            //command name
212
            commandParam.Add("DRPIPE");
213
            //coordinate
214
            foreach (var item in coordinates)
215
                commandParam.Add(item);
216
            //enter
217
            commandParam.Add(null);
218
            //enter
219
            commandParam.Add(null);
220

    
221
            editor.Command(commandParam.ToArray());
222

    
223
            List<long> newHandles = GetAllGroupHandles();
224
            List<long> otherHandles = new List<long>();
225
            foreach (var item in newHandles)
226
                if (!prevHandles.Contains(item))
227
                    otherHandles.Add(item);
228

    
229
            if (otherHandles.Count == 1)
230
                return otherHandles[0];
231
            else
232
                return 0;
233
        }
234
        private long DrawPipe(string style, List<string> coordinates, ObjectId objectId)
235
        {
236
            List<long> prevHandles = GetAllGroupHandles();
237
            GUIUtils.SetPipeStyle(style);
238

    
239
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
240
            Editor editor = acDoc.Editor;
241
            List<object> commandParam = new List<object>();
242
            //command name
243
            commandParam.Add("DRPIPE");
244
            //coordinate
245
            foreach (var item in coordinates)
246
                commandParam.Add(item);
247
            //enter
248
            commandParam.Add(null);
249

    
250
            //Input Object ID
251
            commandParam.Add(objectId);
252

    
253
            //enter
254
            commandParam.Add(null);
255

    
256
            editor.Command(commandParam.ToArray());
257

    
258
            List<long> newHandles = GetAllGroupHandles();
259
            List<long> otherHandles = new List<long>();
260
            foreach (var item in newHandles)
261
                if (!prevHandles.Contains(item))
262
                    otherHandles.Add(item);
263

    
264
            if (otherHandles.Count == 1)
265
                return otherHandles[0];
266
            else
267
                return 0;
268
        }
269
        private long DrawSignal(string style, List<string> coordinates)
270
        {
271
            List<long> prevHandles = GetAllGroupHandles();
272

    
273
            GUIUtils.SetPipeStyle(style);
274
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
275
            Editor editor = acDoc.Editor;
276
            List<object> commandParam = new List<object>();
277
            //command name
278
            commandParam.Add("VPESIGNAL");
279
            //coordinate
280
            foreach (var item in coordinates)
281
                commandParam.Add(item);
282
            //enter
283
            commandParam.Add(null);
284

    
285
            editor.Command(commandParam.ToArray());
286

    
287
            List<long> newHandles = GetAllGroupHandles();
288
            List<long> otherHandles = new List<long>();
289
            foreach (var item in newHandles)
290
                if (!prevHandles.Contains(item))
291
                    otherHandles.Add(item);
292

    
293
            if (otherHandles.Count == 1)
294
                return otherHandles[0];
295
            else
296
                return 0;
297
        }
298
        private long InsertSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon)
299
        {
300
            long handle = 0;
301
            try
302
            {
303
                string insertSymbolName = symbol.Aveva.Name;
304
                double x = symbol.Aveva.X;
305
                double y = symbol.Aveva.Y;
306

    
307
                List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName);
308

    
309
                AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData();
310
                drawingData.InsertSymbolName = insertSymbolName;
311
                Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
312
                Editor editor = acDoc.Editor;
313
                List<object> commandParam = new List<object>();
314
                commandParam.Add("INSSYM");
315

    
316
                // Insert Point
317
                Point3d point = new Point3d(x, y, 0);
318
                commandParam.Add(point);
319

    
320
                // Check Insert Point
321
                if (needAngle)
322
                    commandParam.Add(symbol.ANGLE);
323

    
324
                // Check Balloon
325
                if (needBalloon)
326
                {
327
                    point = new Point3d(x + 20, y + 20, 0);
328
                    commandParam.Add(point);
329
                    
330
                    // Check LeaderLine
331
                    if (GraphicalUtility.IsLeaderReqOnSymbolBalloons())
332
                        commandParam.Add(x + "," + y);
333
                }
334

    
335
                for (int i = 0; i < 8; i++)
336
                    commandParam.Add(null);
337

    
338
                editor.Command(commandParam.ToArray());
339

    
340
                List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName);
341
                List<long> otherHandles = new List<long>();
342
                foreach (var item in newHandles)
343
                    if (!prevHandles.Contains(item))
344
                        otherHandles.Add(item);
345

    
346
                if (otherHandles.Count == 1)
347
                    return otherHandles[0];
348
                else
349
                    return 0;
350
            }
351
            catch (System.Exception ex)
352
            {
353

    
354
            }
355

    
356
            return handle;
357
        }
358
        #endregion
359

    
360
        #region Autocad Utils
361
        private List<long> GetAllBlockHandlesByName(string name)
362
        {
363
            List<long> handles = new List<long>();
364

    
365
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
366
            Database acCurDb = acDoc.Database;
367
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
368
            {
369
                BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
370
                foreach (var entry in gd)
371
                {
372
                    BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord;
373
                    if (blockTableRecord != null)
374
                    {
375
                        IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord);
376
                        foreach (var item in records)
377
                        {
378
                            if (item.Name == name)
379
                                handles.Add(item.Handle.Value);
380
                        }
381
                    }
382
                }
383
                    
384
                acTrans.Commit();
385
            }
386
            return handles;
387
        }
388
        private List<long> GetAllGroupHandles()
389
        {
390
            List<long> handles = new List<long>();
391

    
392
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
393
            Database acCurDb = acDoc.Database;
394
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
395
            {
396
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
397
                foreach (var entry in gd)
398
                    handles.Add(entry.Value.Handle.Value);
399
                acTrans.Commit();
400
            }
401
            return handles;
402
        }
403
        private ObjectId GetFirstPolyLine(long groupHandle)
404
        {
405
            ObjectId result = ObjectId.Null;
406

    
407
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
408
            Database acCurDb = acDoc.Database;
409
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
410
            {
411
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
412
                foreach (var entry in gd)
413
                {
414
                    if (entry.Value.Handle.Value == groupHandle)
415
                    {
416
                        Autodesk.AutoCAD.DatabaseServices.Group group = acTrans.GetObject(entry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Group;
417
                        foreach (var item in group.GetAllEntityIds())
418
                        {
419
                            if (acTrans.GetObject(item, OpenMode.ForRead).GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Polyline))
420
                            {
421
                                result = item;
422
                                break;
423
                            }
424
                        }
425
                        break;
426
                    }
427
                }
428
                acTrans.Commit();
429
            }
430

    
431
            return result;
432
        }
433
        private ObjectId GetObjectIdByHandle(long lHandle)
434
        {
435
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
436
            Database acCurDb = acDoc.Database;
437
            Handle handle = new Handle(lHandle);
438

    
439
            return acCurDb.GetObjectId(false, handle, 0);
440
        }
441
        private void SetBlockReferenceRotation(ObjectId objectId, double rotation)
442
        {
443
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
444
            Database acCurDb = acDoc.Database;
445
            Editor acDocEd = acDoc.Editor;
446

    
447
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
448
            {
449
                DBObject objDB = acTrans.GetObject(objectId, OpenMode.ForWrite);
450
                if (objDB != null)
451
                {
452
                    if (objDB.GetType() == typeof(BlockReference))
453
                    {
454
                        BlockReference block = objDB as BlockReference;
455
                        block.Rotation = rotation;
456
                    }
457
                }
458
                acTrans.Commit();
459
            }
460
        }
461
        #endregion
462

    
463
        #region Modeling Utils
464
        private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert)
465
        {
466
            if (!group.Contains(line))
467
            {
468
                if (isInsert)
469
                    group.Insert(0, line);
470
                else
471
                    group.Add(line);
472

    
473
                if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject))
474
                {
475
                    object connObj = line.CONNECTORS[0].ConnectedObject;
476
                    if (connObj.GetType() == typeof(Model.Line) &&
477
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
478
                        GetConnectedGroupLine(connObj as Model.Line, group, true);
479
                    else if (connObj.GetType() == typeof(Model.Symbol))
480
                    {
481
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
482
                        if (connLine != null)
483
                            GetConnectedGroupLine(connLine as Model.Line, group, true);
484
                    }
485
                }
486
                if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject))
487
                {
488
                    object connObj = line.CONNECTORS[1].ConnectedObject;
489
                    if (connObj.GetType() == typeof(Model.Line) &&
490
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
491
                        GetConnectedGroupLine(connObj as Model.Line, group, false);
492
                    else if (connObj.GetType() == typeof(Model.Symbol))
493
                    {
494
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
495
                        if (connLine != null)
496
                            GetConnectedGroupLine(connLine as Model.Line, group, false);
497
                    }
498
                }
499
            }
500
        }
501
        private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points)
502
        {
503
            for (int i = 0; i < groupLine.Count; i++)
504
            {
505
                Model.Line line = groupLine[i];
506
                if (i == 0)
507
                {
508
                    object connObj = line.CONNECTORS[0].ConnectedObject;
509
                    if (connObj != null)
510
                    {
511
                        string point = GetPointByConnectedItem(connObj, line, true);
512
                        if (string.IsNullOrEmpty(point))
513
                            points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
514
                        else
515
                            points.Add(point);
516
                    }
517
                    else
518
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
519
                }
520
                else
521
                {
522
                    Model.Line prevLine = groupLine[i - 1];
523
                    if (line.SlopeType == SlopeType.HORIZONTAL &&
524
                        prevLine.SlopeType == SlopeType.VERTICAL)
525
                        points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y);
526
                    else if (line.SlopeType == SlopeType.VERTICAL &&
527
                        prevLine.SlopeType == SlopeType.HORIZONTAL)
528
                        points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y);
529
                    else
530
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
531
                }
532

    
533
                if (i == groupLine.Count - 1)
534
                {
535
                    object connObj = line.CONNECTORS[1].ConnectedObject;
536
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
537
                    {
538
                        string point = GetPointByConnectedItem(connObj, line, false);
539
                        if (string.IsNullOrEmpty(point))
540
                            points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
541
                        else
542
                            points.Add(point);
543
                    }
544
                    else
545
                        points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
546
                }
547
            }
548
        }
549
        private string GetPointByConnectedItem(object connObj, Model.Line line, bool isStart)
550
        {
551
            string result = string.Empty;
552
            double x;
553
            double y;
554
            if (isStart)
555
            {
556
                x = line.Aveva.Start_X;
557
                y = line.Aveva.Start_Y;
558
            }
559
            else
560
            {
561
                x = line.Aveva.End_X;
562
                y = line.Aveva.End_Y;
563
            }
564

    
565
            if (connObj.GetType() == typeof(Symbol))
566
            {
567
                Symbol connSymbol = connObj as Symbol;
568
                Connector connector = connSymbol.CONNECTORS.Find(loop => loop.ConnectedObject == line);
569

    
570
                SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
571
                if (slopeType == SlopeType.HORIZONTAL)
572
                    result = connSymbol.Aveva.X + "," + y;
573
                else if (slopeType == SlopeType.VERTICAL)
574
                    result = x + "," + connSymbol.Aveva.Y;
575
                else
576
                    result = x + "," + y;
577
            }
578
            else if (connObj.GetType() == typeof(OPC))
579
            {
580
                OPC connOPC = connObj as OPC;
581
                Connector connector = connOPC.CONNECTORS.Find(loop => loop.ConnectedObject == line);
582

    
583
                double locX = 0, locY = 0, sizeWidth = 0, sizeHeight = 0, aX = 0, aY = 0;
584
                APIDUtils.ConvertPointBystring(connOPC.LOCATION, ref locX, ref locY);
585
                APIDUtils.ConvertPointBystring(connOPC.SIZE, ref sizeWidth, ref sizeHeight);
586
                locX = locX + sizeWidth / 2;
587
                locY = locY + sizeHeight / 2;
588
                aX = locX;
589
                aY = locY;
590
                document.ConvertAvevaPoint(ref aX, ref aY);
591

    
592
                SlopeType slopeType = APIDUtils.CalcSlope(locX, locY, connector.X, connector.Y);
593
                if (slopeType == SlopeType.HORIZONTAL)
594
                    result = aX + "," + y;
595
                else if (slopeType == SlopeType.VERTICAL)
596
                    result = x + "," + aY;
597
                else
598
                    result = x + "," + y;
599
            }
600
            
601
            return result;
602
        }
603
        private bool IsExistEndBreak(object item1, object item2)
604
        {
605
            bool result = false;
606
            if (item1 != null && item2 != null)
607
            {
608
                EndBreak endBreak = document.EndBreaks.Find(x =>
609
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 &&
610
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) ||
611
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 &&
612
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1));
613

    
614
                if (endBreak != null)
615
                    result = true;
616
            }
617

    
618
            return result;
619
        }
620
        private LineRun FindLineRun(Model.Line line)
621
        {
622
            List<LineRun> allLineRun = new List<LineRun>();
623
            foreach (var item in document.LINENUMBERS)
624
                allLineRun.AddRange(item.RUNS);
625
            foreach (var item in document.TRIMLINES)
626
                allLineRun.AddRange(item.RUNS);
627

    
628
            return allLineRun.Find(x => x.RUNITEMS.Contains(line));
629
        }
630
        private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol)
631
        {
632
            Model.Line result = null;
633
            LineRun run = FindLineRun(line);
634
            Connector connector = symbol.CONNECTORS.Find(x =>
635
            x.ConnectedObject != null &&
636
            x.ConnectedObject != line &&
637
            run.RUNITEMS.Contains(x.ConnectedObject) &&
638
            x.ConnectedObject.GetType() == typeof(Model.Line));
639

    
640
            if (connector != null)
641
                result = connector.ConnectedObject as Model.Line;
642
            
643
            return result;
644
        }
645
        private bool CheckAngle(DataRow symbolRow)
646
        {
647
            return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2);
648
        }
649
        private bool CheckBalloon(Symbol symbol)
650
        {
651
            bool result = false;
652

    
653
            string text = string.Empty;
654
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
655
            if (symbolDefinitions.Count != 0)
656
            {
657
                text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
658

    
659
                if (text.Equals("VLP"))
660
                    text = "VPO";
661
                else if (text.Equals("IVP"))
662
                    text = "IPO";
663

    
664
                if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text))
665
                    result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId);
666
            }
667

    
668
            return result;
669
        }
670
        #endregion
671

    
672
        #region Test Source
673
        public void test()
674
        {
675
            //InitGUI();
676
            //DrawSignal("SONIC", new List<string>() { "2,100", "100,100" });
677

    
678
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
679
            Symbol symbol = new Symbol();
680
            symbol.Aveva = new AvevaSymbolInfo();
681
            symbol.Aveva.Name = "INVB";
682
            symbol.Aveva.X = 50;
683
            symbol.Aveva.Y = 100;
684

    
685
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
686
            if (allRows.Length == 1)
687
            {
688
                DataRow symbolRow = allRows[0];
689
                bool bAngle = CheckAngle(symbolRow);
690
                bool bBalloon = CheckBalloon(symbol);
691
                bBalloon = false;
692
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
693
            }
694

    
695
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
696
            string text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
697
            if (int.Parse(symbolDefinitions[SymbolDefinition.symNoOfInsertPoints].ToString()).Equals(2))
698
            {
699
                bool bIsPromptRotate = true;
700
            }
701
            int num = int.Parse(symbolDefinitions[SymbolDefinition.symFixedOrUserDefined].ToString());
702

    
703
            AssociateSymbolType eAssosiateSym = AssociateSymbolType.None;
704
            bool bIsSymbolHasAssociation = GraphicalUtility.FindSymbolHasAssociation(text, ref eAssosiateSym);
705
            bool bPlaceSimpleBlocks = SymbolCategory.astrSimplePlacedBlocks.Contains(text);
706

    
707
            //DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" });
708

    
709
            //DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
710
        }
711
        public static void TESTStatic()
712
        {
713
            System.Data.DataTable avevaSymbolTable = Project_DB.SelectSymbolTable();
714
            AutoModeling auto = new AutoModeling(null, avevaSymbolTable);
715
            auto.test();
716
        }
717
        #endregion
718
    }
719

    
720

    
721
    public static class AcDbLinqExtensionMethods
722
    {
723
        /// <summary>
724
        /// Get all references to the given BlockTableRecord, including 
725
        /// references to anonymous dynamic BlockTableRecords.
726
        /// </summary>
727

    
728
        public static IEnumerable<BlockReference> GetBlockReferences(
729
           this BlockTableRecord btr,
730
           OpenMode mode = OpenMode.ForRead,
731
           bool directOnly = true)
732
        {
733
            if (btr == null)
734
                throw new ArgumentNullException("btr");
735
            var tr = btr.Database.TransactionManager.TopTransaction;
736
            if (tr == null)
737
                throw new InvalidOperationException("No transaction");
738
            var ids = btr.GetBlockReferenceIds(directOnly, true);
739
            int cnt = ids.Count;
740
            for (int i = 0; i < cnt; i++)
741
            {
742
                yield return (BlockReference)
743
                   tr.GetObject(ids[i], mode, false, false);
744
            }
745
            if (btr.IsDynamicBlock)
746
            {
747
                BlockTableRecord btr2 = null;
748
                var blockIds = btr.GetAnonymousBlockIds();
749
                cnt = blockIds.Count;
750
                for (int i = 0; i < cnt; i++)
751
                {
752
                    btr2 = (BlockTableRecord)tr.GetObject(blockIds[i],
753
                       OpenMode.ForRead, false, false);
754
                    ids = btr2.GetBlockReferenceIds(directOnly, true);
755
                    int cnt2 = ids.Count;
756
                    for (int j = 0; j < cnt2; j++)
757
                    {
758
                        yield return (BlockReference)
759
                           tr.GetObject(ids[j], mode, false, false);
760
                    }
761
                }
762
            }
763
        }
764
    }
765
}
클립보드 이미지 추가 (최대 크기: 500 MB)