프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / APIDConverter / AutoModeling.cs @ f7e09e14

이력 | 보기 | 이력해설 | 다운로드 (26.7 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
namespace AVEVA.PID.CustomizationUtility
31
{
32
    public class AutoModeling
33
    {
34
        public static AutoModeling Running { get; set; }
35
        Model.Document document;
36

    
37
        System.Data.DataTable AvevaSymbolTable = null;
38

    
39
        public AutoModeling(Model.Document document, System.Data.DataTable AvevaSymbolTable)
40
        {
41
            this.document = document;
42
            this.AvevaSymbolTable = AvevaSymbolTable;
43
        }
44

    
45
        public void CreateDrawing()
46
        {
47
            string outPath = Project_DB.GetDirectiveValue("DRGPTH");
48
            string tempPath = Path.GetTempPath();
49
            string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT");
50

    
51
            DWTSelector.strDrawingNumber = document.AvevaDrawingNumber;
52
            DWTSelector.strSheetNumber = document.AvevaSheetNumber;
53
            DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber;
54
            DWTSelector.strCadFilePath = outPath;
55

    
56
            try
57
            {
58
                string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false);
59
                Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
60
                Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text);
61

    
62
                Commands.addLatestPidvesrionToDictionary();
63
                AVVPropCmd.ActivateAcad();
64

    
65
                if (acadDocument != null)
66
                {
67
                    Running = this;
68
                    acadApplication.ActiveDocument = acadDocument;
69
                    acadDocument.SendCommand("QSAVE ");
70
                    acadDocument.SendCommand("APPIDRun ");
71
                    acadDocument.SendCommand("QSAVE ");
72
                    Running = null;
73
                }
74
            }
75
            catch (System.Exception ex)
76
            {
77
                
78
            }
79

    
80
            GC.Collect();
81
        }
82
        public void Run()
83
        {
84
            try
85
            {
86
                RunLineModeling();
87
                RunSymbolModeling();
88
            }
89
            catch (System.Exception ex)
90
            {
91
                System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace);
92
            }
93
        }
94

    
95
        #region Run Method
96
        private void RunLineModeling()
97
        {
98
            foreach (var item in document.LINES)
99
            {
100
                if (item.Aveva.Handle == 0)
101
                    LineModeling(item);
102
            }
103
        }
104
        private void RunSymbolModeling()
105
        {
106
            foreach (var item in document.SYMBOLS)
107
            {
108
                if (item.Aveva.Handle == 0)
109
                    SymbolModeling(item);
110
            }
111
        }
112
        #endregion
113

    
114
        #region Modeling Method
115
        private void LineModeling(Model.Line line)
116
        {
117
            List<Model.Line> groupLine = new List<Model.Line>();
118
            List<string> points = new List<string>();
119
            GetConnectedGroupLine(line, groupLine, false);
120
            GetGroupLinePoints(groupLine, points);
121

    
122
            long handle = 0;
123
            if (line.Aveva.Type == Model.Type.Pipe)
124
                handle = DrawPipe(line.Aveva.Name, points);
125
            else if (line.Aveva.Type == Model.Type.Signal)
126
                handle = DrawSignal(line.Aveva.Name, points);
127

    
128
            foreach (var item in groupLine)
129
                item.Aveva.Handle = handle;
130
        }
131
        private void SymbolModeling(Symbol symbol)
132
        {
133
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
134
            if (allRows.Length == 1)
135
            {
136
                DataRow symbolRow = allRows[0];
137
                bool bAngle = CheckAngle(symbolRow);
138
                bool bBalloon = CheckBalloon(symbol);
139

    
140
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
141
                if (handle != 0)
142
                {
143
                    symbol.Aveva.Handle = handle;
144

    
145
                    if (!bAngle)
146
                    {
147
                        ObjectId objectId = GetObjectIdByHandle(handle);
148
                        if (objectId != ObjectId.Null)
149
                        {
150
                            SetBlockReferenceRotation(objectId, symbol.ANGLE);
151
                        }
152
                    }
153
                }
154
            }
155
        }
156
        #endregion
157

    
158
        #region Drawing Method
159
        private long DrawPipe(string style, List<string> coordinates)
160
        {
161
            List<long> prevHandles = GetAllGroupHandles();
162

    
163
            GUIUtils.SetPipeStyle(style);
164
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
165
            Editor editor = acDoc.Editor;
166
            List<object> commandParam = new List<object>();
167
            //command name
168
            commandParam.Add("DRPIPE");
169
            //coordinate
170
            foreach (var item in coordinates)
171
                commandParam.Add(item);
172
            //enter
173
            commandParam.Add(null);
174
            //enter
175
            commandParam.Add(null);
176

    
177
            editor.Command(commandParam.ToArray());
178

    
179
            List<long> newHandles = GetAllGroupHandles();
180
            List<long> otherHandles = new List<long>();
181
            foreach (var item in newHandles)
182
                if (!prevHandles.Contains(item))
183
                    otherHandles.Add(item);
184

    
185
            if (otherHandles.Count == 1)
186
                return otherHandles[0];
187
            else
188
                return 0;
189
        }
190
        private long DrawPipe(string style, List<string> coordinates, ObjectId objectId)
191
        {
192
            List<long> prevHandles = GetAllGroupHandles();
193
            GUIUtils.SetPipeStyle(style);
194

    
195
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
196
            Editor editor = acDoc.Editor;
197
            List<object> commandParam = new List<object>();
198
            //command name
199
            commandParam.Add("DRPIPE");
200
            //coordinate
201
            foreach (var item in coordinates)
202
                commandParam.Add(item);
203
            //enter
204
            commandParam.Add(null);
205

    
206
            //Input Object ID
207
            commandParam.Add(objectId);
208

    
209
            //enter
210
            commandParam.Add(null);
211

    
212
            editor.Command(commandParam.ToArray());
213

    
214
            List<long> newHandles = GetAllGroupHandles();
215
            List<long> otherHandles = new List<long>();
216
            foreach (var item in newHandles)
217
                if (!prevHandles.Contains(item))
218
                    otherHandles.Add(item);
219

    
220
            if (otherHandles.Count == 1)
221
                return otherHandles[0];
222
            else
223
                return 0;
224
        }
225
        private long DrawSignal(string style, List<string> coordinates)
226
        {
227
            List<long> prevHandles = GetAllGroupHandles();
228

    
229
            GUIUtils.SetPipeStyle(style);
230
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
231
            Editor editor = acDoc.Editor;
232
            List<object> commandParam = new List<object>();
233
            //command name
234
            commandParam.Add("VPESIGNAL");
235
            //coordinate
236
            foreach (var item in coordinates)
237
                commandParam.Add(item);
238
            //enter
239
            commandParam.Add(null);
240

    
241
            editor.Command(commandParam.ToArray());
242

    
243
            List<long> newHandles = GetAllGroupHandles();
244
            List<long> otherHandles = new List<long>();
245
            foreach (var item in newHandles)
246
                if (!prevHandles.Contains(item))
247
                    otherHandles.Add(item);
248

    
249
            if (otherHandles.Count == 1)
250
                return otherHandles[0];
251
            else
252
                return 0;
253
        }
254
        private long InsertSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon)
255
        {
256
            long handle = 0;
257
            try
258
            {
259
                string insertSymbolName = symbol.Aveva.Name;
260
                double x = symbol.Aveva.X;
261
                double y = symbol.Aveva.Y;
262

    
263
                List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName);
264

    
265
                AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData();
266
                drawingData.InsertSymbolName = insertSymbolName;
267
                Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
268
                Editor editor = acDoc.Editor;
269
                List<object> commandParam = new List<object>();
270
                commandParam.Add("INSSYM");
271

    
272
                // Insert Point
273
                Point3d point = new Point3d(x, y, 0);
274
                commandParam.Add(point);
275

    
276
                // Check Insert Point
277
                if (needAngle)
278
                    commandParam.Add(symbol.ANGLE);
279

    
280
                // Check Balloon
281
                if (needBalloon)
282
                {
283
                    point = new Point3d(x + 20, y + 20, 0);
284
                    commandParam.Add(point);
285
                    
286
                    // Check LeaderLine
287
                    if (GraphicalUtility.IsLeaderReqOnSymbolBalloons())
288
                        commandParam.Add(x + "," + y);
289
                }
290

    
291
                for (int i = 0; i < 8; i++)
292
                    commandParam.Add(null);
293

    
294
                editor.Command(commandParam.ToArray());
295

    
296
                List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName);
297
                List<long> otherHandles = new List<long>();
298
                foreach (var item in newHandles)
299
                    if (!prevHandles.Contains(item))
300
                        otherHandles.Add(item);
301

    
302
                if (otherHandles.Count == 1)
303
                    return otherHandles[0];
304
                else
305
                    return 0;
306
            }
307
            catch (System.Exception ex)
308
            {
309

    
310
            }
311

    
312
            return handle;
313
        }
314
        #endregion
315

    
316
        #region Autocad Utils
317
        private List<long> GetAllBlockHandlesByName(string name)
318
        {
319
            List<long> handles = new List<long>();
320

    
321
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
322
            Database acCurDb = acDoc.Database;
323
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
324
            {
325
                BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
326
                foreach (var entry in gd)
327
                {
328
                    BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord;
329
                    if (blockTableRecord != null)
330
                    {
331
                        IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord);
332
                        foreach (var item in records)
333
                        {
334
                            if (item.Name == name)
335
                                handles.Add(item.Handle.Value);
336
                        }
337
                    }
338
                }
339
                    
340
                acTrans.Commit();
341
            }
342
            return handles;
343
        }
344
        private List<long> GetAllGroupHandles()
345
        {
346
            List<long> handles = new List<long>();
347

    
348
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
349
            Database acCurDb = acDoc.Database;
350
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
351
            {
352
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
353
                foreach (var entry in gd)
354
                    handles.Add(entry.Value.Handle.Value);
355
                acTrans.Commit();
356
            }
357
            return handles;
358
        }
359
        private ObjectId GetFirstPolyLine(long groupHandle)
360
        {
361
            ObjectId result = ObjectId.Null;
362

    
363
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
364
            Database acCurDb = acDoc.Database;
365
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
366
            {
367
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
368
                foreach (var entry in gd)
369
                {
370
                    if (entry.Value.Handle.Value == groupHandle)
371
                    {
372
                        Autodesk.AutoCAD.DatabaseServices.Group group = acTrans.GetObject(entry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Group;
373
                        foreach (var item in group.GetAllEntityIds())
374
                        {
375
                            if (acTrans.GetObject(item, OpenMode.ForRead).GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Polyline))
376
                            {
377
                                result = item;
378
                                break;
379
                            }
380
                        }
381
                        break;
382
                    }
383
                }
384
                acTrans.Commit();
385
            }
386

    
387
            return result;
388
        }
389
        private ObjectId GetObjectIdByHandle(long lHandle)
390
        {
391
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
392
            Database acCurDb = acDoc.Database;
393
            Handle handle = new Handle(lHandle);
394

    
395
            return acCurDb.GetObjectId(false, handle, 0);
396
        }
397
        private void SetBlockReferenceRotation(ObjectId objectId, double rotation)
398
        {
399
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
400
            Database acCurDb = acDoc.Database;
401
            Editor acDocEd = acDoc.Editor;
402

    
403
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
404
            {
405
                DBObject objDB = acTrans.GetObject(objectId, OpenMode.ForWrite);
406
                if (objDB != null)
407
                {
408
                    if (objDB.GetType() == typeof(BlockReference))
409
                    {
410
                        BlockReference block = objDB as BlockReference;
411
                        block.Rotation = rotation;
412
                    }
413
                }
414
                acTrans.Commit();
415
            }
416
        }
417
        #endregion
418

    
419
        #region Modeling Utils
420
        private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert)
421
        {
422
            if (!group.Contains(line))
423
            {
424
                if (isInsert)
425
                    group.Insert(0, line);
426
                else
427
                    group.Add(line);
428

    
429
                if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject))
430
                {
431
                    object connObj = line.CONNECTORS[0].ConnectedObject;
432
                    if (connObj.GetType() == typeof(Model.Line) &&
433
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
434
                        GetConnectedGroupLine(connObj as Model.Line, group, true);
435
                    else if (connObj.GetType() == typeof(Model.Symbol))
436
                    {
437
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
438
                        if (connLine != null)
439
                            GetConnectedGroupLine(connLine as Model.Line, group, true);
440
                    }
441
                }
442
                if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject))
443
                {
444
                    object connObj = line.CONNECTORS[1].ConnectedObject;
445
                    if (connObj.GetType() == typeof(Model.Line) &&
446
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
447
                        GetConnectedGroupLine(connObj as Model.Line, group, false);
448
                    else if (connObj.GetType() == typeof(Model.Symbol))
449
                    {
450
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
451
                        if (connLine != null)
452
                            GetConnectedGroupLine(connLine as Model.Line, group, false);
453
                    }
454
                }
455
            }
456
        }
457
        private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points)
458
        {
459
            for (int i = 0; i < groupLine.Count; i++)
460
            {
461
                Model.Line line = groupLine[i];
462
                if (i == 0)
463
                {
464
                    object connObj = line.CONNECTORS[0].ConnectedObject;
465
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
466
                    {
467
                        Symbol connSymbol = connObj as Symbol;
468
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
469

    
470
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
471
                        if (slopeType == SlopeType.HORIZONTAL)
472
                            points.Add(connSymbol.X + "," + line.Aveva.Start_Y);
473
                        else if (slopeType == SlopeType.VERTICAL)
474
                            points.Add(line.Aveva.Start_X + "," + connSymbol.Y);
475
                        else
476
                            points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
477
                    }
478
                    else
479
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
480
                }
481
                else
482
                {
483
                    Model.Line prevLine = groupLine[i - 1];
484
                    if (line.SlopeType == SlopeType.HORIZONTAL &&
485
                        prevLine.SlopeType == SlopeType.VERTICAL)
486
                        points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y);
487
                    else if (line.SlopeType == SlopeType.VERTICAL &&
488
                        prevLine.SlopeType == SlopeType.HORIZONTAL)
489
                        points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y);
490
                    else
491
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
492
                }
493

    
494
                if (i == groupLine.Count - 1)
495
                {
496
                    object connObj = line.CONNECTORS[1].ConnectedObject;
497
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
498
                    {
499
                        Symbol connSymbol = connObj as Symbol;
500
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
501

    
502
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
503
                        if (slopeType == SlopeType.HORIZONTAL)
504
                            points.Add(connSymbol.X + "," + line.Aveva.End_Y);
505
                        else if (slopeType == SlopeType.VERTICAL)
506
                            points.Add(line.Aveva.End_X + "," + connSymbol.Y);
507
                        else
508
                            points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
509
                    }
510
                    else
511
                        points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
512
                }
513
            }
514
        }
515
        private bool IsExistEndBreak(object item1, object item2)
516
        {
517
            bool result = false;
518
            if (item1 != null && item2 != null)
519
            {
520
                EndBreak endBreak = document.EndBreaks.Find(x =>
521
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 &&
522
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) ||
523
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 &&
524
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1));
525

    
526
                if (endBreak != null)
527
                    result = true;
528
            }
529

    
530
            return result;
531
        }
532
        private LineRun FindLineRun(Model.Line line)
533
        {
534
            List<LineRun> allLineRun = new List<LineRun>();
535
            foreach (var item in document.LINENUMBERS)
536
                allLineRun.AddRange(item.RUNS);
537
            foreach (var item in document.TRIMLINES)
538
                allLineRun.AddRange(item.RUNS);
539

    
540
            return allLineRun.Find(x => x.RUNITEMS.Contains(line));
541
        }
542
        private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol)
543
        {
544
            Model.Line result = null;
545
            LineRun run = FindLineRun(line);
546
            Connector connector = symbol.CONNECTORS.Find(x =>
547
            x.ConnectedObject != null &&
548
            x.ConnectedObject != line &&
549
            run.RUNITEMS.Contains(x.ConnectedObject) &&
550
            x.ConnectedObject.GetType() == typeof(Model.Line));
551

    
552
            if (connector != null)
553
                result = connector.ConnectedObject as Model.Line;
554
            
555
            return result;
556
        }
557
        private bool CheckAngle(DataRow symbolRow)
558
        {
559
            return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2);
560
        }
561
        private bool CheckBalloon(Symbol symbol)
562
        {
563
            bool result = false;
564

    
565
            string text = string.Empty;
566
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
567
            if (symbolDefinitions.Count != 0)
568
            {
569
                text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
570

    
571
                if (text.Equals("VLP"))
572
                    text = "VPO";
573
                else if (text.Equals("IVP"))
574
                    text = "IPO";
575

    
576
                if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text))
577
                    result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId);
578
            }
579

    
580
            return result;
581
        }
582
        #endregion
583

    
584
        #region Test Source
585
        public void test()
586
        {
587
            //InitGUI();
588
            //DrawSignal("SONIC", new List<string>() { "2,100", "100,100" });
589

    
590
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
591
            Symbol symbol = new Symbol();
592
            symbol.Aveva = new AvevaSymbolInfo();
593
            symbol.Aveva.Name = "INVB";
594
            symbol.Aveva.X = 50;
595
            symbol.Aveva.Y = 100;
596

    
597
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
598
            if (allRows.Length == 1)
599
            {
600
                DataRow symbolRow = allRows[0];
601
                bool bAngle = CheckAngle(symbolRow);
602
                bool bBalloon = CheckBalloon(symbol);
603
                bBalloon = false;
604
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
605
            }
606

    
607
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
608
            string text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
609
            if (int.Parse(symbolDefinitions[SymbolDefinition.symNoOfInsertPoints].ToString()).Equals(2))
610
            {
611
                bool bIsPromptRotate = true;
612
            }
613
            int num = int.Parse(symbolDefinitions[SymbolDefinition.symFixedOrUserDefined].ToString());
614

    
615
            AssociateSymbolType eAssosiateSym = AssociateSymbolType.None;
616
            bool bIsSymbolHasAssociation = GraphicalUtility.FindSymbolHasAssociation(text, ref eAssosiateSym);
617
            bool bPlaceSimpleBlocks = SymbolCategory.astrSimplePlacedBlocks.Contains(text);
618

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

    
621
            //DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
622
        }
623
        public static void TESTStatic()
624
        {
625
            System.Data.DataTable avevaSymbolTable = Project_DB.SelectSymbolTable();
626
            AutoModeling auto = new AutoModeling(null, avevaSymbolTable);
627
            auto.test();
628
        }
629
        #endregion
630
    }
631

    
632

    
633
    public static class AcDbLinqExtensionMethods
634
    {
635
        /// <summary>
636
        /// Get all references to the given BlockTableRecord, including 
637
        /// references to anonymous dynamic BlockTableRecords.
638
        /// </summary>
639

    
640
        public static IEnumerable<BlockReference> GetBlockReferences(
641
           this BlockTableRecord btr,
642
           OpenMode mode = OpenMode.ForRead,
643
           bool directOnly = true)
644
        {
645
            if (btr == null)
646
                throw new ArgumentNullException("btr");
647
            var tr = btr.Database.TransactionManager.TopTransaction;
648
            if (tr == null)
649
                throw new InvalidOperationException("No transaction");
650
            var ids = btr.GetBlockReferenceIds(directOnly, true);
651
            int cnt = ids.Count;
652
            for (int i = 0; i < cnt; i++)
653
            {
654
                yield return (BlockReference)
655
                   tr.GetObject(ids[i], mode, false, false);
656
            }
657
            if (btr.IsDynamicBlock)
658
            {
659
                BlockTableRecord btr2 = null;
660
                var blockIds = btr.GetAnonymousBlockIds();
661
                cnt = blockIds.Count;
662
                for (int i = 0; i < cnt; i++)
663
                {
664
                    btr2 = (BlockTableRecord)tr.GetObject(blockIds[i],
665
                       OpenMode.ForRead, false, false);
666
                    ids = btr2.GetBlockReferenceIds(directOnly, true);
667
                    int cnt2 = ids.Count;
668
                    for (int j = 0; j < cnt2; j++)
669
                    {
670
                        yield return (BlockReference)
671
                           tr.GetObject(ids[j], mode, false, false);
672
                    }
673
                }
674
            }
675
        }
676
    }
677
}
클립보드 이미지 추가 (최대 크기: 500 MB)