프로젝트

일반

사용자정보

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

hytos / DTI_PID / APIDConverter / AutoModeling.cs @ ad3d070a

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

1 74a0c9d6 gaqhf
using System;
2
using System.Collections.Generic;
3 016701e5 gaqhf
using System.Collections;
4 74a0c9d6 gaqhf
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 1c5bd296 gaqhf
using AVEVA.PID.Components;
21
using AVEVA.PID.GUI;
22
using AVEVA.PID.Common;
23
using AVEVA.PID.DWGSelector;
24 495bb8f5 gaqhf
using AVEVA.PID.Utilities;
25 1c5bd296 gaqhf
26 14540282 gaqhf
using AVEVA.PID.CustomizationUtility.DB;
27
using AVEVA.PID.CustomizationUtility.Model;
28
using AVEVA.PID.CustomizationUtility.Properties;
29 74a0c9d6 gaqhf
30 aba318eb gaqhf
using DevExpress.XtraSplashScreen;
31
32 74a0c9d6 gaqhf
namespace AVEVA.PID.CustomizationUtility
33
{
34
    public class AutoModeling
35
    {
36 1c5bd296 gaqhf
        public static AutoModeling Running { get; set; }
37 14540282 gaqhf
        Model.Document document;
38 74a0c9d6 gaqhf
39 495bb8f5 gaqhf
        System.Data.DataTable AvevaSymbolTable = null;
40
41
        public AutoModeling(Model.Document document, System.Data.DataTable AvevaSymbolTable)
42 74a0c9d6 gaqhf
        {
43 14540282 gaqhf
            this.document = document;
44 495bb8f5 gaqhf
            this.AvevaSymbolTable = AvevaSymbolTable;
45 74a0c9d6 gaqhf
        }
46
47 1c5bd296 gaqhf
        public void CreateDrawing()
48 46756c13 gaqhf
        {
49 1c5bd296 gaqhf
            string outPath = Project_DB.GetDirectiveValue("DRGPTH");
50
            string tempPath = Path.GetTempPath();
51
            string selectedFullPath = Path.Combine(tempPath, document.AvevaTemplateName + ".DWT");
52
53
            DWTSelector.strDrawingNumber = document.AvevaDrawingNumber;
54
            DWTSelector.strSheetNumber = document.AvevaSheetNumber;
55
            DWTSelector.strCadFileName = document.AvevaDrawingNumber + document.AvevaSheetNumber;
56
            DWTSelector.strCadFilePath = outPath;
57
58
            try
59 46756c13 gaqhf
            {
60 1c5bd296 gaqhf
                string text = ReadWriteDrawingData.ReadTemplateData(document.AvevaTemplateName, document.AvevaTemplateID, selectedFullPath, false);
61
                Autodesk.AutoCAD.Interop.AcadApplication acadApplication = Autodesk.AutoCAD.ApplicationServices.Application.AcadApplication as Autodesk.AutoCAD.Interop.AcadApplication;
62
                Autodesk.AutoCAD.Interop.AcadDocument acadDocument = acadApplication.Documents.Add(text);
63
64
                Commands.addLatestPidvesrionToDictionary();
65
                AVVPropCmd.ActivateAcad();
66
67
                if (acadDocument != null)
68
                {
69
                    Running = this;
70
                    acadApplication.ActiveDocument = acadDocument;
71
                    acadDocument.SendCommand("QSAVE ");
72
                    acadDocument.SendCommand("APPIDRun ");
73 9dab7146 gaqhf
                    acadDocument.SendCommand("QSAVE ");
74 1c5bd296 gaqhf
                    Running = null;
75
                }
76 46756c13 gaqhf
            }
77 1c5bd296 gaqhf
            catch (System.Exception ex)
78
            {
79
                
80
            }
81
82
            GC.Collect();
83
        }
84
        public void Run()
85
        {
86 016701e5 gaqhf
            try
87
            {
88 aba318eb gaqhf
                SplashScreenManager.ShowForm(typeof(APIDSplashScreen), true, true);
89
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllStepCount, 2);
90
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetDocumentName, document.AvevaDrawingNumber + document.AvevaSheetNumber);
91
92 016701e5 gaqhf
                RunLineModeling();
93
                RunSymbolModeling();
94
            }
95
            catch (System.Exception ex)
96
            {
97
                System.Windows.Forms.MessageBox.Show(ex.Message + @"\n" + ex.StackTrace);
98
            }
99 aba318eb gaqhf
            finally
100
            {
101
                SplashScreenManager.CloseForm(false);
102
            }
103 46756c13 gaqhf
        }
104
105 9dab7146 gaqhf
        #region Run Method
106
        private void RunLineModeling()
107 74a0c9d6 gaqhf
        {
108 aba318eb gaqhf
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.LINES.Count);
109
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Line Modeling");
110 9dab7146 gaqhf
            foreach (var item in document.LINES)
111 74a0c9d6 gaqhf
            {
112 53344e2c gaqhf
                if (item.Aveva.Handle == 0)
113
                    LineModeling(item);
114 aba318eb gaqhf
115
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
116 74a0c9d6 gaqhf
            }
117 9dab7146 gaqhf
        }
118 016701e5 gaqhf
        private void RunSymbolModeling()
119
        {
120 aba318eb gaqhf
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetAllProgress, document.SYMBOLS.Count);
121
            SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.SetStep, "Symbol Modeling");
122 b90890eb gaqhf
            foreach (var item in document.SYMBOLS)
123
            {
124
                if (item.Aveva.Handle == 0)
125
                    SymbolModeling(item);
126 aba318eb gaqhf
                SplashScreenManager.Default.SendCommand(APIDSplashScreen.SplashScreenCommand.UpProgress, null);
127 b90890eb gaqhf
            }
128 016701e5 gaqhf
        }
129 9dab7146 gaqhf
        #endregion
130 74a0c9d6 gaqhf
131 9dab7146 gaqhf
        #region Modeling Method
132
        private void LineModeling(Model.Line line)
133
        {
134 53344e2c gaqhf
            List<Model.Line> groupLine = new List<Model.Line>();
135 9dab7146 gaqhf
            List<string> points = new List<string>();
136 016701e5 gaqhf
            GetConnectedGroupLine(line, groupLine, false);
137 53344e2c gaqhf
            GetGroupLinePoints(groupLine, points);
138 9dab7146 gaqhf
139 53344e2c gaqhf
            long handle = 0;
140 9dab7146 gaqhf
            if (line.Aveva.Type == Model.Type.Pipe)
141 53344e2c gaqhf
                handle = DrawPipe(line.Aveva.Name, points);
142 9dab7146 gaqhf
            else if (line.Aveva.Type == Model.Type.Signal)
143 53344e2c gaqhf
                handle = DrawSignal(line.Aveva.Name, points);
144
145
            foreach (var item in groupLine)
146
                item.Aveva.Handle = handle;
147 74a0c9d6 gaqhf
        }
148 b90890eb gaqhf
        private void SymbolModeling(Symbol symbol)
149
        {
150 495bb8f5 gaqhf
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
151
            if (allRows.Length == 1)
152 2d09df82 gaqhf
            {
153 495bb8f5 gaqhf
                DataRow symbolRow = allRows[0];
154
                bool bAngle = CheckAngle(symbolRow);
155
                bool bBalloon = CheckBalloon(symbol);
156
157
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
158
                if (handle != 0)
159 2d09df82 gaqhf
                {
160 495bb8f5 gaqhf
                    symbol.Aveva.Handle = handle;
161
162
                    if (!bAngle)
163
                    {
164
                        ObjectId objectId = GetObjectIdByHandle(handle);
165
                        if (objectId != ObjectId.Null)
166
                        {
167
                            SetBlockReferenceRotation(objectId, symbol.ANGLE);
168
                        }
169
                    }
170 2d09df82 gaqhf
                }
171
            }
172 b90890eb gaqhf
        }
173 9dab7146 gaqhf
        #endregion
174 74a0c9d6 gaqhf
175
        #region Drawing Method
176 9dab7146 gaqhf
        private long DrawPipe(string style, List<string> coordinates)
177 74a0c9d6 gaqhf
        {
178 9dab7146 gaqhf
            List<long> prevHandles = GetAllGroupHandles();
179 74a0c9d6 gaqhf
180 9dab7146 gaqhf
            GUIUtils.SetPipeStyle(style);
181 14540282 gaqhf
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
182 74a0c9d6 gaqhf
            Editor editor = acDoc.Editor;
183
            List<object> commandParam = new List<object>();
184
            //command name
185
            commandParam.Add("DRPIPE");
186
            //coordinate
187
            foreach (var item in coordinates)
188
                commandParam.Add(item);
189
            //enter
190
            commandParam.Add(null);
191
            //enter
192
            commandParam.Add(null);
193
194
            editor.Command(commandParam.ToArray());
195
196 9dab7146 gaqhf
            List<long> newHandles = GetAllGroupHandles();
197
            List<long> otherHandles = new List<long>();
198
            foreach (var item in newHandles)
199
                if (!prevHandles.Contains(item))
200
                    otherHandles.Add(item);
201 74a0c9d6 gaqhf
202 9dab7146 gaqhf
            if (otherHandles.Count == 1)
203
                return otherHandles[0];
204
            else
205
                return 0;
206 74a0c9d6 gaqhf
        }
207 9dab7146 gaqhf
        private long DrawPipe(string style, List<string> coordinates, ObjectId objectId)
208 74a0c9d6 gaqhf
        {
209 9dab7146 gaqhf
            List<long> prevHandles = GetAllGroupHandles();
210 14540282 gaqhf
            GUIUtils.SetPipeStyle(style);
211 74a0c9d6 gaqhf
212 14540282 gaqhf
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
213 74a0c9d6 gaqhf
            Editor editor = acDoc.Editor;
214
            List<object> commandParam = new List<object>();
215
            //command name
216
            commandParam.Add("DRPIPE");
217
            //coordinate
218
            foreach (var item in coordinates)
219
                commandParam.Add(item);
220
            //enter
221
            commandParam.Add(null);
222
223
            //Input Object ID
224
            commandParam.Add(objectId);
225
226
            //enter
227
            commandParam.Add(null);
228
229
            editor.Command(commandParam.ToArray());
230 9dab7146 gaqhf
231
            List<long> newHandles = GetAllGroupHandles();
232
            List<long> otherHandles = new List<long>();
233
            foreach (var item in newHandles)
234
                if (!prevHandles.Contains(item))
235
                    otherHandles.Add(item);
236
237
            if (otherHandles.Count == 1)
238
                return otherHandles[0];
239
            else
240
                return 0;
241
        }
242
        private long DrawSignal(string style, List<string> coordinates)
243
        {
244
            List<long> prevHandles = GetAllGroupHandles();
245
246
            GUIUtils.SetPipeStyle(style);
247
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
248
            Editor editor = acDoc.Editor;
249
            List<object> commandParam = new List<object>();
250
            //command name
251
            commandParam.Add("VPESIGNAL");
252
            //coordinate
253
            foreach (var item in coordinates)
254
                commandParam.Add(item);
255
            //enter
256
            commandParam.Add(null);
257
258
            editor.Command(commandParam.ToArray());
259
260
            List<long> newHandles = GetAllGroupHandles();
261
            List<long> otherHandles = new List<long>();
262
            foreach (var item in newHandles)
263
                if (!prevHandles.Contains(item))
264
                    otherHandles.Add(item);
265
266
            if (otherHandles.Count == 1)
267
                return otherHandles[0];
268
            else
269
                return 0;
270 74a0c9d6 gaqhf
        }
271 495bb8f5 gaqhf
        private long InsertSymbol(Symbol symbol, DataRow symbolRow, bool needAngle, bool needBalloon)
272 6b3cb476 gaqhf
        {
273 73152510 gaqhf
            long handle = 0;
274 6b3cb476 gaqhf
            try
275
            {
276 495bb8f5 gaqhf
                string insertSymbolName = symbol.Aveva.Name;
277
                double x = symbol.Aveva.X;
278
                double y = symbol.Aveva.Y;
279
280 73152510 gaqhf
                List<long> prevHandles = GetAllBlockHandlesByName(insertSymbolName);
281
282 6b3cb476 gaqhf
                AVEVA.PID.Utilities.DrawingData drawingData = new AVEVA.PID.Utilities.DrawingData();
283
                drawingData.InsertSymbolName = insertSymbolName;
284
                Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
285
                Editor editor = acDoc.Editor;
286
                List<object> commandParam = new List<object>();
287
                commandParam.Add("INSSYM");
288 495bb8f5 gaqhf
289
                // Insert Point
290 6b3cb476 gaqhf
                Point3d point = new Point3d(x, y, 0);
291
                commandParam.Add(point);
292 495bb8f5 gaqhf
293
                // Check Insert Point
294
                if (needAngle)
295
                    commandParam.Add(symbol.ANGLE);
296
297
                // Check Balloon
298
                if (needBalloon)
299
                {
300
                    point = new Point3d(x + 20, y + 20, 0);
301
                    commandParam.Add(point);
302
                    
303
                    // Check LeaderLine
304
                    if (GraphicalUtility.IsLeaderReqOnSymbolBalloons())
305
                        commandParam.Add(x + "," + y);
306
                }
307
308
                for (int i = 0; i < 8; i++)
309
                    commandParam.Add(null);
310 6b3cb476 gaqhf
311
                editor.Command(commandParam.ToArray());
312 73152510 gaqhf
313
                List<long> newHandles = GetAllBlockHandlesByName(insertSymbolName);
314
                List<long> otherHandles = new List<long>();
315
                foreach (var item in newHandles)
316
                    if (!prevHandles.Contains(item))
317
                        otherHandles.Add(item);
318
319
                if (otherHandles.Count == 1)
320
                    return otherHandles[0];
321
                else
322
                    return 0;
323 6b3cb476 gaqhf
            }
324
            catch (System.Exception ex)
325
            {
326 74a0c9d6 gaqhf
327 6b3cb476 gaqhf
            }
328 73152510 gaqhf
329
            return handle;
330 6b3cb476 gaqhf
        }
331 74a0c9d6 gaqhf
        #endregion
332
333 73152510 gaqhf
        #region Autocad Utils
334
        private List<long> GetAllBlockHandlesByName(string name)
335
        {
336
            List<long> handles = new List<long>();
337
338
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
339
            Database acCurDb = acDoc.Database;
340
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
341
            {
342
                BlockTable gd = (BlockTable)acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead);
343
                foreach (var entry in gd)
344
                {
345
                    BlockTableRecord blockTableRecord = acTrans.GetObject(entry, OpenMode.ForRead, true) as BlockTableRecord;
346
                    if (blockTableRecord != null)
347
                    {
348
                        IEnumerable<BlockReference> records = AcDbLinqExtensionMethods.GetBlockReferences(blockTableRecord);
349
                        foreach (var item in records)
350
                        {
351
                            if (item.Name == name)
352
                                handles.Add(item.Handle.Value);
353
                        }
354
                    }
355
                }
356
                    
357
                acTrans.Commit();
358
            }
359
            return handles;
360
        }
361 9dab7146 gaqhf
        private List<long> GetAllGroupHandles()
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
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
370
                foreach (var entry in gd)
371
                    handles.Add(entry.Value.Handle.Value);
372
                acTrans.Commit();
373
            }
374
            return handles;
375
        }
376
        private ObjectId GetFirstPolyLine(long groupHandle)
377
        {
378
            ObjectId result = ObjectId.Null;
379
380
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
381
            Database acCurDb = acDoc.Database;
382
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
383
            {
384
                DBDictionary gd = (DBDictionary)acTrans.GetObject(acCurDb.GroupDictionaryId, OpenMode.ForRead);
385
                foreach (var entry in gd)
386
                {
387
                    if (entry.Value.Handle.Value == groupHandle)
388
                    {
389
                        Autodesk.AutoCAD.DatabaseServices.Group group = acTrans.GetObject(entry.Value, OpenMode.ForRead) as Autodesk.AutoCAD.DatabaseServices.Group;
390
                        foreach (var item in group.GetAllEntityIds())
391
                        {
392
                            if (acTrans.GetObject(item, OpenMode.ForRead).GetType() == typeof(Autodesk.AutoCAD.DatabaseServices.Polyline))
393
                            {
394
                                result = item;
395
                                break;
396
                            }
397
                        }
398
                        break;
399
                    }
400
                }
401
                acTrans.Commit();
402
            }
403
404
            return result;
405
        }
406 2d09df82 gaqhf
        private ObjectId GetObjectIdByHandle(long lHandle)
407
        {
408
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
409
            Database acCurDb = acDoc.Database;
410
            Handle handle = new Handle(lHandle);
411
412
            return acCurDb.GetObjectId(false, handle, 0);
413
        }
414
        private void SetBlockReferenceRotation(ObjectId objectId, double rotation)
415
        {
416
            Autodesk.AutoCAD.ApplicationServices.Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
417
            Database acCurDb = acDoc.Database;
418
            Editor acDocEd = acDoc.Editor;
419
420
            using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
421
            {
422
                DBObject objDB = acTrans.GetObject(objectId, OpenMode.ForWrite);
423
                if (objDB != null)
424
                {
425
                    if (objDB.GetType() == typeof(BlockReference))
426
                    {
427
                        BlockReference block = objDB as BlockReference;
428
                        block.Rotation = rotation;
429
                    }
430
                }
431
                acTrans.Commit();
432
            }
433
        }
434 016701e5 gaqhf
        #endregion
435
436 73152510 gaqhf
        #region Modeling Utils
437 016701e5 gaqhf
        private void GetConnectedGroupLine(Model.Line line, List<Model.Line> group, bool isInsert)
438 53344e2c gaqhf
        {
439
            if (!group.Contains(line))
440
            {
441 016701e5 gaqhf
                if (isInsert)
442 53344e2c gaqhf
                    group.Insert(0, line);
443
                else
444
                    group.Add(line);
445
446 016701e5 gaqhf
                if (line.CONNECTORS[0].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[0].ConnectedObject))
447
                {
448
                    object connObj = line.CONNECTORS[0].ConnectedObject;
449
                    if (connObj.GetType() == typeof(Model.Line) &&
450
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
451
                        GetConnectedGroupLine(connObj as Model.Line, group, true);
452
                    else if (connObj.GetType() == typeof(Model.Symbol))
453
                    {
454
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
455
                        if (connLine != null)
456
                            GetConnectedGroupLine(connLine as Model.Line, group, true);
457
                    }
458
                }
459
                if (line.CONNECTORS[1].ConnectedObject != null && !IsExistEndBreak(line, line.CONNECTORS[1].ConnectedObject))
460
                {
461
                    object connObj = line.CONNECTORS[1].ConnectedObject;
462
                    if (connObj.GetType() == typeof(Model.Line) &&
463
                        APIDUtils.IsConnectedLine(connObj as Model.Line, line))
464
                        GetConnectedGroupLine(connObj as Model.Line, group, false);
465
                    else if (connObj.GetType() == typeof(Model.Symbol))
466
                    {
467
                        Model.Line connLine = FindOtherLineByRun(line, connObj as Symbol);
468
                        if (connLine != null)
469
                            GetConnectedGroupLine(connLine as Model.Line, group, false);
470
                    }
471
                }
472 53344e2c gaqhf
            }
473
        }
474
        private void GetGroupLinePoints(List<Model.Line> groupLine, List<string> points)
475
        {
476
            for (int i = 0; i < groupLine.Count; i++)
477
            {
478
                Model.Line line = groupLine[i];
479 016701e5 gaqhf
                if (i == 0)
480 f7e09e14 gaqhf
                {
481
                    object connObj = line.CONNECTORS[0].ConnectedObject;
482
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
483
                    {
484
                        Symbol connSymbol = connObj as Symbol;
485
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
486
487
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
488
                        if (slopeType == SlopeType.HORIZONTAL)
489 ad3d070a gaqhf
                            points.Add(connSymbol.Aveva.X + "," + line.Aveva.Start_Y);
490 f7e09e14 gaqhf
                        else if (slopeType == SlopeType.VERTICAL)
491 ad3d070a gaqhf
                            points.Add(line.Aveva.Start_X + "," + connSymbol.Aveva.Y);
492 f7e09e14 gaqhf
                        else
493
                            points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
494
                    }
495
                    else
496
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
497
                }
498 016701e5 gaqhf
                else
499
                {
500
                    Model.Line prevLine = groupLine[i - 1];
501
                    if (line.SlopeType == SlopeType.HORIZONTAL &&
502
                        prevLine.SlopeType == SlopeType.VERTICAL)
503
                        points.Add(prevLine.Aveva.End_X + "," + line.Aveva.Start_Y);
504
                    else if (line.SlopeType == SlopeType.VERTICAL &&
505
                        prevLine.SlopeType == SlopeType.HORIZONTAL)
506
                        points.Add(line.Aveva.Start_X + "," + prevLine.Aveva.End_Y);
507
                    else
508
                        points.Add(line.Aveva.Start_X + "," + line.Aveva.Start_Y);
509
                }
510
511 53344e2c gaqhf
                if (i == groupLine.Count - 1)
512 f7e09e14 gaqhf
                {
513
                    object connObj = line.CONNECTORS[1].ConnectedObject;
514
                    if (connObj != null && connObj.GetType() == typeof(Symbol))
515
                    {
516
                        Symbol connSymbol = connObj as Symbol;
517
                        Connector connector = connSymbol.CONNECTORS.Find(x => x.ConnectedObject == line);
518
519
                        SlopeType slopeType = APIDUtils.CalcSlope(connSymbol.X, connSymbol.Y, connector.X, connector.Y);
520
                        if (slopeType == SlopeType.HORIZONTAL)
521 ad3d070a gaqhf
                            points.Add(connSymbol.Aveva.X + "," + line.Aveva.End_Y);
522 f7e09e14 gaqhf
                        else if (slopeType == SlopeType.VERTICAL)
523 ad3d070a gaqhf
                            points.Add(line.Aveva.End_X + "," + connSymbol.Aveva.Y);
524 f7e09e14 gaqhf
                        else
525
                            points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
526
                    }
527
                    else
528
                        points.Add(line.Aveva.End_X + "," + line.Aveva.End_Y);
529
                }
530 53344e2c gaqhf
            }
531
        }
532 016701e5 gaqhf
        private bool IsExistEndBreak(object item1, object item2)
533
        {
534
            bool result = false;
535
            if (item1 != null && item2 != null)
536
            {
537
                EndBreak endBreak = document.EndBreaks.Find(x =>
538
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item1 &&
539
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item2) ||
540
            (APIDUtils.FindObjectByUID(document, x.OWNER) == item2 &&
541
            APIDUtils.FindObjectByUID(document, x.PROPERTIES.Find(y => y.ATTRIBUTE == "Connected Item").VALUE) == item1));
542
543
                if (endBreak != null)
544
                    result = true;
545
            }
546
547
            return result;
548
        }
549
        private LineRun FindLineRun(Model.Line line)
550
        {
551
            List<LineRun> allLineRun = new List<LineRun>();
552
            foreach (var item in document.LINENUMBERS)
553
                allLineRun.AddRange(item.RUNS);
554
            foreach (var item in document.TRIMLINES)
555
                allLineRun.AddRange(item.RUNS);
556
557
            return allLineRun.Find(x => x.RUNITEMS.Contains(line));
558
        }
559
        private Model.Line FindOtherLineByRun(Model.Line line, Symbol symbol)
560
        {
561
            Model.Line result = null;
562
            LineRun run = FindLineRun(line);
563
            Connector connector = symbol.CONNECTORS.Find(x =>
564
            x.ConnectedObject != null &&
565
            x.ConnectedObject != line &&
566
            run.RUNITEMS.Contains(x.ConnectedObject) &&
567
            x.ConnectedObject.GetType() == typeof(Model.Line));
568
569
            if (connector != null)
570
                result = connector.ConnectedObject as Model.Line;
571 2d09df82 gaqhf
            
572 016701e5 gaqhf
            return result;
573
        }
574 495bb8f5 gaqhf
        private bool CheckAngle(DataRow symbolRow)
575
        {
576
            return int.Parse(symbolRow["Insert_Points"].ToString()).Equals(2);
577
        }
578
        private bool CheckBalloon(Symbol symbol)
579
        {
580
            bool result = false;
581
582
            string text = string.Empty;
583
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
584
            if (symbolDefinitions.Count != 0)
585
            {
586
                text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
587
588
                if (text.Equals("VLP"))
589
                    text = "VPO";
590
                else if (text.Equals("IVP"))
591
                    text = "IPO";
592
593
                if (SymbolCategory.astrLabelBalloonBlockNames.Contains(text))
594
                    result = true;//dumbDwgUpgrade.addLabelBalloon(symbolForInsertion, objectId);
595
            }
596
597
            return result;
598
        }
599 53344e2c gaqhf
        #endregion
600 9dab7146 gaqhf
601 74a0c9d6 gaqhf
        #region Test Source
602
        public void test()
603
        {
604 14540282 gaqhf
            //InitGUI();
605 9dab7146 gaqhf
            //DrawSignal("SONIC", new List<string>() { "2,100", "100,100" });
606 74a0c9d6 gaqhf
607
            DrawPipe("Main Pipe", new List<string>() { "2,100", "100,100" });
608 495bb8f5 gaqhf
            Symbol symbol = new Symbol();
609
            symbol.Aveva = new AvevaSymbolInfo();
610
            symbol.Aveva.Name = "INVB";
611
            symbol.Aveva.X = 50;
612
            symbol.Aveva.Y = 100;
613
614
            DataRow[] allRows = AvevaSymbolTable.Select(string.Format("Symbol_Name = '{0}'", symbol.Aveva.Name));
615
            if (allRows.Length == 1)
616
            {
617
                DataRow symbolRow = allRows[0];
618
                bool bAngle = CheckAngle(symbolRow);
619
                bool bBalloon = CheckBalloon(symbol);
620
                bBalloon = false;
621
                long handle = InsertSymbol(symbol, symbolRow, bAngle, bBalloon);
622
            }
623
624
            Hashtable symbolDefinitions = GraphicsUtility.GetSymbolDefinitions(symbol.Aveva.Name);
625
            string text = symbolDefinitions[SymbolDefinition.symAflowType].ToString().ToUpper();
626
            if (int.Parse(symbolDefinitions[SymbolDefinition.symNoOfInsertPoints].ToString()).Equals(2))
627
            {
628
                bool bIsPromptRotate = true;
629
            }
630
            int num = int.Parse(symbolDefinitions[SymbolDefinition.symFixedOrUserDefined].ToString());
631
632
            AssociateSymbolType eAssosiateSym = AssociateSymbolType.None;
633
            bool bIsSymbolHasAssociation = GraphicalUtility.FindSymbolHasAssociation(text, ref eAssosiateSym);
634
            bool bPlaceSimpleBlocks = SymbolCategory.astrSimplePlacedBlocks.Contains(text);
635
636 9dab7146 gaqhf
            //DrawPipe("Main Pipe", new List<string>() { "2,200", "100,200" });
637 74a0c9d6 gaqhf
638 9dab7146 gaqhf
            //DrawPipe("Sub Pipe", new List<string>() { "50,100", "50,200" });
639 74a0c9d6 gaqhf
        }
640 9dab7146 gaqhf
        public static void TESTStatic()
641 74a0c9d6 gaqhf
        {
642 495bb8f5 gaqhf
            System.Data.DataTable avevaSymbolTable = Project_DB.SelectSymbolTable();
643
            AutoModeling auto = new AutoModeling(null, avevaSymbolTable);
644 74a0c9d6 gaqhf
            auto.test();
645
        }
646
        #endregion
647
    }
648 73152510 gaqhf
649
650
    public static class AcDbLinqExtensionMethods
651
    {
652
        /// <summary>
653
        /// Get all references to the given BlockTableRecord, including 
654
        /// references to anonymous dynamic BlockTableRecords.
655
        /// </summary>
656
657
        public static IEnumerable<BlockReference> GetBlockReferences(
658
           this BlockTableRecord btr,
659
           OpenMode mode = OpenMode.ForRead,
660
           bool directOnly = true)
661
        {
662
            if (btr == null)
663
                throw new ArgumentNullException("btr");
664
            var tr = btr.Database.TransactionManager.TopTransaction;
665
            if (tr == null)
666
                throw new InvalidOperationException("No transaction");
667
            var ids = btr.GetBlockReferenceIds(directOnly, true);
668
            int cnt = ids.Count;
669
            for (int i = 0; i < cnt; i++)
670
            {
671
                yield return (BlockReference)
672
                   tr.GetObject(ids[i], mode, false, false);
673
            }
674
            if (btr.IsDynamicBlock)
675
            {
676
                BlockTableRecord btr2 = null;
677
                var blockIds = btr.GetAnonymousBlockIds();
678
                cnt = blockIds.Count;
679
                for (int i = 0; i < cnt; i++)
680
                {
681
                    btr2 = (BlockTableRecord)tr.GetObject(blockIds[i],
682
                       OpenMode.ForRead, false, false);
683
                    ids = btr2.GetBlockReferenceIds(directOnly, true);
684
                    int cnt2 = ids.Count;
685
                    for (int j = 0; j < cnt2; j++)
686
                    {
687
                        yield return (BlockReference)
688
                           tr.GetObject(ids[j], mode, false, false);
689
                    }
690
                }
691
            }
692
        }
693
    }
694 74a0c9d6 gaqhf
}
클립보드 이미지 추가 (최대 크기: 500 MB)