프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / AutoModeling.cs @ a19bd6e2

이력 | 보기 | 이력해설 | 다운로드 (28.9 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 && connObj.GetType() == typeof(Symbol))
510
                    {
511
                        Symbol connSymbol = connObj as Symbol;
512
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
513

    
514
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
515
                        if (slopeType == SlopeType.HORIZONTAL)
516
                            points.Add(connSymbol.Aveva.X + "," + line.Aveva.Start_Y);
517
                        else if (slopeType == SlopeType.VERTICAL)
518
                            points.Add(line.Aveva.Start_X + "," + connSymbol.Aveva.Y);
519
                        else
520
                            points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
521
                    }
522
                    else
523
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
524
                }
525
                else
526
                {
527
                    Model.Line prevLine = groupLine[i - 1];
528
                    if (line.SlopeType == SlopeType.HORIZONTAL &&
529
                        prevLine.SlopeType == SlopeType.VERTICAL)
530
                        points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y);
531
                    else if (line.SlopeType == SlopeType.VERTICAL &&
532
                        prevLine.SlopeType == SlopeType.HORIZONTAL)
533
                        points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y);
534
                    else
535
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
536
                }
537

    
538
                if (i == groupLine.Count - 1)
539
                {
540
                    object connObj = line.CONNECTORS[1].ConnectedObject;
541
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
542
                    {
543
                        Symbol connSymbol = connObj as Symbol;
544
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
545

    
546
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
547
                        if (slopeType == SlopeType.HORIZONTAL)
548
                            points.Add(connSymbol.Aveva.X + "," + line.Aveva.End_Y);
549
                        else if (slopeType == SlopeType.VERTICAL)
550
                            points.Add(line.Aveva.End_X + "," + connSymbol.Aveva.Y);
551
                        else
552
                            points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
553
                    }
554
                    else
555
                        points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
556
                }
557
            }
558
        }
559
        private bool IsExistEndBreak(object item1, object item2)
560
        {
561
            bool result = false;
562
            if (item1 != null && item2 != null)
563
            {
564
                EndBreak endBreak = document.EndBreaks.Find(x =>
565
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 &&
566
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) ||
567
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 &&
568
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1));
569

    
570
                if (endBreak != null)
571
                    result = true;
572
            }
573

    
574
            return result;
575
        }
576
        private LineRun FindLineRun(Model.Line line)
577
        {
578
            List<LineRun> allLineRun = new List<LineRun>();
579
            foreach (var item in document.LINENUMBERS)
580
                allLineRun.AddRange(item.RUNS);
581
            foreach (var item in document.TRIMLINES)
582
                allLineRun.AddRange(item.RUNS);
583

    
584
            return allLineRun.Find(x => x.RUNITEMS.Contains(line));
585
        }
586
        private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol)
587
        {
588
            Model.Line result = null;
589
            LineRun run = FindLineRun(line);
590
            Connector connector = symbol.CONNECTORS.Find(x =>
591
            x.ConnectedObject != null &&
592
            x.ConnectedObject != line &&
593
            run.RUNITEMS.Contains(x.ConnectedObject) &&
594
            x.ConnectedObject.GetType() == typeof(Model.Line));
595

    
596
            if (connector != null)
597
                result = connector.ConnectedObject as Model.Line;
598
            
599
            return result;
600
        }
601
        private bool CheckAngle(DataRow symbolRow)
602
        {
603
            return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2);
604
        }
605
        private bool CheckBalloon(Symbol symbol)
606
        {
607
            bool result = false;
608

    
609
            string text = string.Empty;
610
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
611
            if (symbolDefinitions.Count != 0)
612
            {
613
                text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
614

    
615
                if (text.Equals("VLP"))
616
                    text = "VPO";
617
                else if (text.Equals("IVP"))
618
                    text = "IPO";
619

    
620
                if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text))
621
                    result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId);
622
            }
623

    
624
            return result;
625
        }
626
        #endregion
627

    
628
        #region Test Source
629
        public void test()
630
        {
631
            //InitGUI();
632
            //DrawSignal("SONIC", new List<string>() { "2,100", "100,100" });
633

    
634
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
635
            Symbol symbol = new Symbol();
636
            symbol.Aveva = new AvevaSymbolInfo();
637
            symbol.Aveva.Name = "INVB";
638
            symbol.Aveva.X = 50;
639
            symbol.Aveva.Y = 100;
640

    
641
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
642
            if (allRows.Length == 1)
643
            {
644
                DataRow symbolRow = allRows[0];
645
                bool bAngle = CheckAngle(symbolRow);
646
                bool bBalloon = CheckBalloon(symbol);
647
                bBalloon = false;
648
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
649
            }
650

    
651
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
652
            string text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
653
            if (int.Parse(symbolDefinitions[SymbolDefinition.symNoOfInsertPoints].ToString()).Equals(2))
654
            {
655
                bool bIsPromptRotate = true;
656
            }
657
            int num = int.Parse(symbolDefinitions[SymbolDefinition.symFixedOrUserDefined].ToString());
658

    
659
            AssociateSymbolType eAssosiateSym = AssociateSymbolType.None;
660
            bool bIsSymbolHasAssociation = GraphicalUtility.FindSymbolHasAssociation(text, ref eAssosiateSym);
661
            bool bPlaceSimpleBlocks = SymbolCategory.astrSimplePlacedBlocks.Contains(text);
662

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

    
665
            //DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
666
        }
667
        public static void TESTStatic()
668
        {
669
            System.Data.DataTable avevaSymbolTable = Project_DB.SelectSymbolTable();
670
            AutoModeling auto = new AutoModeling(null, avevaSymbolTable);
671
            auto.test();
672
        }
673
        #endregion
674
    }
675

    
676

    
677
    public static class AcDbLinqExtensionMethods
678
    {
679
        /// <summary>
680
        /// Get all references to the given BlockTableRecord, including 
681
        /// references to anonymous dynamic BlockTableRecords.
682
        /// </summary>
683

    
684
        public static IEnumerable<BlockReference> GetBlockReferences(
685
           this BlockTableRecord btr,
686
           OpenMode mode = OpenMode.ForRead,
687
           bool directOnly = true)
688
        {
689
            if (btr == null)
690
                throw new ArgumentNullException("btr");
691
            var tr = btr.Database.TransactionManager.TopTransaction;
692
            if (tr == null)
693
                throw new InvalidOperationException("No transaction");
694
            var ids = btr.GetBlockReferenceIds(directOnly, true);
695
            int cnt = ids.Count;
696
            for (int i = 0; i < cnt; i++)
697
            {
698
                yield return (BlockReference)
699
                   tr.GetObject(ids[i], mode, false, false);
700
            }
701
            if (btr.IsDynamicBlock)
702
            {
703
                BlockTableRecord btr2 = null;
704
                var blockIds = btr.GetAnonymousBlockIds();
705
                cnt = blockIds.Count;
706
                for (int i = 0; i < cnt; i++)
707
                {
708
                    btr2 = (BlockTableRecord)tr.GetObject(blockIds[i],
709
                       OpenMode.ForRead, false, false);
710
                    ids = btr2.GetBlockReferenceIds(directOnly, true);
711
                    int cnt2 = ids.Count;
712
                    for (int j = 0; j < cnt2; j++)
713
                    {
714
                        yield return (BlockReference)
715
                           tr.GetObject(ids[j], mode, false, false);
716
                    }
717
                }
718
            }
719
        }
720
    }
721
}
클립보드 이미지 추가 (최대 크기: 500 MB)