프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 25c5df17

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

1
using System;
2
using System.Collections.Generic;
3
using System.ComponentModel;
4
using System.Drawing;
5
using System.Data;
6
using System.Linq;
7
using System.Text;
8
using System.Threading.Tasks;
9
using System.Windows.Forms;
10
using System.Threading;
11
using System.IO;
12
using Microsoft.VisualBasic;
13
using Ingr.RAD2D;
14
using Converter.BaseModel;
15
using Converter.SPPID.Properties;
16
using Converter.SPPID.DB;
17
using Converter.SPPID.Util;
18
using Converter.SPPID.Form;
19
using Converter.SPPID.Model;
20
using Plaice;
21
using Llama;
22
using DevExpress.XtraSplashScreen;
23
using Newtonsoft.Json;
24
using System.Runtime.InteropServices;
25
using System.Reflection;
26
using Converter.SPPID.OPC;
27

    
28
namespace Converter.SPPID.Wrapper
29
{
30
    public partial class ConverterDocking : UserControl
31
    {
32
        Ingr.RAD2D.Application application;
33
        static bool addEvent = false;
34
        public ConverterDocking()
35
        {
36
            InitializeComponent();
37
            spinEditSymmetry.Properties.Mask.EditMask = "f0";
38
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
39
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
40
            application = wApp.RADApplication;
41
            
42
            ReleaseCOMObjects(dApplication);
43
            dApplication = null;
44
            try
45
            {
46
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
47
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
48

    
49
                Project_Info _ProjectInfo = Project_Info.GetInstance();
50
                _ProjectInfo.DefaultPath = Settings.Default.ProjectPath;
51
                _ProjectInfo.DBType = (ID2DB_Type)Settings.Default.ProjectDBType;
52
                _ProjectInfo.ServerIP = Settings.Default.ProjectServerIP;
53
                _ProjectInfo.Port = Settings.Default.ProjectPort;
54
                _ProjectInfo.DBUser = Settings.Default.ProjectDBUser;
55
                _ProjectInfo.DBPassword = Settings.Default.ProjectDBPassword;
56
                if (Project_DB.ConnTestAndCreateTable())
57
                {
58
                    _ProjectInfo.Enable = true;
59
                    layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
60

    
61
                    DataTable dt = Project_DB.SelectSetting();
62
                    foreach (DataRow item in dt.Rows)
63
                    {
64
                        string settingType = item["SettingType"].ToString();
65
                        if (settingType == "ETCSetting")
66
                            SPPIDUtil.ConvertToETCSetting(item["JsonString"].ToString());
67
                        else if (settingType == "GridSetting")
68
                            SPPIDUtil.ConvertToGridSetting(item["JsonString"].ToString());
69
                    }
70
                }
71
                else
72
                {
73
                    layoutControlGroup3.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
74
                }
75

    
76
                if (!addEvent)
77
                {
78
                    application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit;
79
                    addEvent = true;
80
                }
81
                RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode());
82
            }
83
            catch (Exception ex)
84
            {
85
                StringBuilder sb = new StringBuilder();
86
                sb.AppendLine(ex.Message);
87
                sb.AppendLine(ex.StackTrace);
88
                MessageBox.Show(sb.ToString());
89
            }
90
        }
91
        private void ApplicationEvents_ApplicationExit(out bool cancel)
92
        {
93
            cancel = false;
94
        }
95
        /// <summary>
96
        /// 선택한 도면들을 읽어서 SPPID로 변환한다.
97
        /// </summary>
98
        /// <param name="sender"></param>
99
        /// <param name="e"></param>
100
        private void btnConverter_Click(object sender, EventArgs e)
101
        {
102
            ConverterForm converterForm = new ConverterForm();
103
            if (converterForm.ShowDialog() == DialogResult.OK)
104
            {
105
                //Ingr.RAD2D.Document doc = application.Documents.Add();
106

    
107
                try
108
                {
109
                    CloseOPCForm.Run();
110

    
111
                    for (int i = 0; i < converterForm.Documents.Count; i++)
112
                    {
113
                        SPPID_Document document = converterForm.Documents[i];
114
                        if (document.SetSPPIDMapping() && document.Enable)
115
                        {
116
                            using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked))
117
                            {
118
                                modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
119
                                modeling.Run();
120
                            }
121
                        }
122
                    }
123
                }
124
                catch (Exception ex)
125
                {
126
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
127
                }
128
                finally
129
                {
130
                    CloseOPCForm.Stop();
131

    
132
                    //doc.SaveOnClose = false;
133
                    //doc.Close(false);
134

    
135
                    //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
136
                    //dApplication.Drawings[1].CloseDrawing(false);
137
                    //ReleaseCOMObjects(dApplication);
138
                    //dApplication = null;
139
                }
140

    
141
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
142
            }
143
        }
144

    
145
        private void btnLinkOPC_Click(object sender, EventArgs e)
146
        {
147
            DataTable tOPCInfo = Project_DB.SelectOPCInfo();
148
            DataTable tOPCRelations = Project_DB.SelectOPCRelations();
149
            DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
150
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
151

    
152
            foreach (DataRow row in tOPCInfo.Rows)
153
            {
154
                if (!Convert.ToBoolean(row["PAIRED"]))
155
                {
156
                    string drawingUID = row["ID2_DRAWING_UID"].ToString();
157
                    string OPCUID = row["ID2_OPC_UID"].ToString();
158
                    DataRow[] rows = tOPCRelations.Select(string.Format("(From_Drawings_UID = '{0}' AND From_OPC_UID = '{1}') OR (To_Drawings_UID = '{0}' AND To_OPC_UID = '{1}')", drawingUID, OPCUID));
159

    
160
                    if (rows.Length == 2)
161
                    {
162
                        string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
163
                        string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
164
                        string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
165
                        string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
166
                        string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
167
                        string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
168
                        string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
169
                        string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
170

    
171
                        DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
172
                        DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
173
                        DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
174
                        DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
175

    
176
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
177
                        {
178
                            DataRow fromOPCInfoRow = fromOPCInfoRows[0];
179
                            DataRow toOPCInfoRow = toOPCInfoRows[0];
180
                            string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
181
                            string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
182
                            string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
183
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
184
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
185
                            if (opc.Run())
186
                            {
187
                                fromOPCInfoRow["PAIRED"] = true;
188
                                toOPCInfoRow["PAIRED"] = true;
189

    
190
                                Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
191
                                Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
192
                            }
193
                        }
194
                    }
195
                }
196
            }
197

    
198
            tOPCInfo.Dispose();
199
            tOPCRelations.Dispose();
200
            tDrawingInfo.Dispose();
201
            ReleaseCOMObjects(dApplication);
202
            dApplication = null;
203

    
204
            MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
205
        }
206

    
207
        public void ReleaseCOMObjects(params object[] objVars)
208
        {
209
            int intNewRefCount = 0;
210
            foreach (object obj in objVars)
211
            {
212
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
213
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
214
            }
215
        }
216

    
217
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
218
        {
219
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
220
            WrapperApplication wApp = new WrapperApplication(application.Application);
221
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
222

    
223
            if (radApp.ActiveSelectSet.Count > 0)
224
            {
225
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
226
                if (line2D != null)
227
                {
228
                    double minX = 0;
229
                    double minY = 0;
230
                    double maxX = 0;
231
                    double maxY = 0;
232
                    line2D.Range(out minX, out minY, out maxX, out maxY);
233

    
234
                    Settings.Default.DrawingX = maxX - minX;
235
                    Settings.Default.DrawingY = maxY - minY;
236
                    Settings.Default.Save();
237

    
238
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
239
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
240
                }
241
                else
242
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
243
            }
244
            else
245
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
246
        }
247

    
248
        #region SPPID Utils
249
        #region Symmetry
250
        private void btnSymmetry_Click(object sender, EventArgs e)
251
        {
252
            if (application.ActiveSelectSet.Count == 1 && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d))
253
            {
254
                int symCount = (int)spinEditSymmetry.Value;
255
                Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d;
256
                double x, y;
257
                symbol.GetOrigin(out x, out y);
258
                string rep = GetRepresentationId(symbol);
259
                List<string> verticalRepID = new List<string>();
260
                List<string> horizontalRepID = new List<string>();
261

    
262
                if ((symbol.LinearName.Contains("Piping") ||
263
                    symbol.LinearName.Contains("Instrument")) &&
264
                    !string.IsNullOrEmpty(rep))
265
                {
266
                    Placement placement = new Placement();
267
                    LMADataSource dataSource = placement.PIDDataSource;
268
                    List<List<string>> datas = SetSymbol(dataSource, rep, x, y, symCount);
269
                    Dictionary<SymmetryArrow, List<string>> resultDatas = new Dictionary<SymmetryArrow, List<string>>();
270
                    if (datas.Count >= 2 && datas.Find(loop => loop.Count != symCount) == null)
271
                    {
272
                        SymmetryArrow arrow = SymmetryArrow.None;
273
                        foreach (var data in datas)
274
                        {
275
                            LMSymbol firstSymbol = dataSource.GetSymbol(data[0]);
276
                            double fX = firstSymbol.get_XCoordinate();
277
                            double fY = firstSymbol.get_YCoordinate();
278

    
279
                            SlopeType type = SPPIDUtil.CalcSlope(x, y, fX, fY, 1);
280
                            if (type == SlopeType.HORIZONTAL)
281
                            {
282
                                if (fX < x)
283
                                {
284
                                    arrow |= SymmetryArrow.Left;
285
                                    resultDatas.Add(SymmetryArrow.Left, data);
286
                                }
287
                                else
288
                                {
289
                                    arrow |= SymmetryArrow.Right;
290
                                    resultDatas.Add(SymmetryArrow.Right, data);
291
                                }
292

    
293
                            }
294
                            else if (type == SlopeType.VERTICAL)
295
                            {
296
                                if (fY < y)
297
                                {
298
                                    arrow |= SymmetryArrow.Down;
299
                                    resultDatas.Add(SymmetryArrow.Down, data);
300
                                }
301
                                else
302
                                {
303
                                    arrow |= SymmetryArrow.Up;
304
                                    resultDatas.Add(SymmetryArrow.Up, data);
305
                                }
306
                            }
307

    
308
                            ReleaseCOMObjects(firstSymbol);
309
                        }
310

    
311
                        SymmetryForm form = new SymmetryForm(arrow);
312
                        if (form.ShowDialog() == DialogResult.OK)
313
                        {
314
                            MoveByResult(dataSource, resultDatas, x, y, form.Result, rep);
315
                        }
316
                    }
317
                    else
318
                        MessageBox.Show("Check Symmetry Rules", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
319
                    ReleaseCOMObjects(dataSource);
320
                    ReleaseCOMObjects(placement);
321
                }
322
            }
323

    
324
            return;
325

    
326
            List<Symbol2d> symbols = new List<Symbol2d>();
327
            foreach (var item in application.ActiveSelectSet)
328
            {
329
                Type type = item.GetType();
330
                if (type == typeof(Symbol2d))
331
                {
332
                    Symbol2d symbol = item as Symbol2d;
333
                    if (symbol.LinearName.Contains("Piping") ||
334
                        symbol.LinearName.Contains("Instrument"))
335
                        symbols.Add(symbol);
336
                }
337
                //if (item.GetType() == typeof(Symbol2d) || item.GetType() == typeof(Point2d))
338
                //    items.Add(item);
339
            }
340

    
341
            List<Symbol2d> verticalSymbols = new List<Symbol2d>();
342
            List<Symbol2d> horizontalSymbols = new List<Symbol2d>();
343
            Symbol2d mainSymbol = null;
344
            for (int i = 0; i < symbols.Count - 1; i++)
345
            {
346
                Symbol2d symbol1 = symbols[i];
347
                for (int j = 1; j < symbols.Count; j++)
348
                {
349
                    Symbol2d symbol2 = symbols[j];
350

    
351
                    if (symbol1 != symbol2)
352
                    {
353
                        double x1, y1, x2, y2;
354
                        symbol1.GetOrigin(out x1, out y1);
355
                        symbol2.GetOrigin(out x2, out y2);
356
                        SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 1);
357
                        if (slopeType == SlopeType.HORIZONTAL)
358
                        {
359
                            if (!horizontalSymbols.Contains(symbol1))
360
                                horizontalSymbols.Add(symbol1);
361
                            if (!horizontalSymbols.Contains(symbol2))
362
                                horizontalSymbols.Add(symbol2);
363

    
364
                            if (verticalSymbols.Contains(symbol1))
365
                                mainSymbol = symbol1;
366
                            if (verticalSymbols.Contains(symbol2))
367
                                mainSymbol = symbol2;
368
                        }
369
                        else if (slopeType == SlopeType.VERTICAL)
370
                        {
371
                            if (!verticalSymbols.Contains(symbol1))
372
                                verticalSymbols.Add(symbol1);
373
                            if (!verticalSymbols.Contains(symbol2))
374
                                verticalSymbols.Add(symbol2);
375

    
376
                            if (horizontalSymbols.Contains(symbol1))
377
                                mainSymbol = symbol1;
378
                            if (horizontalSymbols.Contains(symbol2))
379
                                mainSymbol = symbol2;
380
                        }
381
                    }
382
                }
383
            }
384

    
385
            application.ActiveSelectSet.RemoveAll();
386
            foreach (var item in verticalSymbols)
387
                application.ActiveSelectSet.Add(item);
388
            foreach (var item in horizontalSymbols)
389
                application.ActiveSelectSet.Add(item);
390
                
391

    
392
            if (MessageBox.Show("Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
393
            {
394
                application.ActiveSelectSet.RemoveAll();
395

    
396
            }
397
        }
398
        private void MoveByResult(LMADataSource dataSource,Dictionary<SymmetryArrow, List<string>> resultDatas, double x, double y, SymmetryArrow arrow, string centerRepID)
399
        {
400
            List<string> datas = resultDatas[arrow];
401
            foreach (var item in resultDatas)
402
            {
403
                if (item.Key != arrow)
404
                {
405
                    for (int i = 0; i < item.Value.Count; i++)
406
                    {
407
                        Symbol2d moveSymbol2d = GetSymbol2DByRepID(dataSource, item.Value[i]);
408
                        Symbol2d symbol2d = GetSymbol2DByRepID(dataSource, datas[i]);
409

    
410
                        double x1, y1, x2, y2;
411
                        symbol2d.GetOrigin(out x1, out y1);
412
                        moveSymbol2d.GetOrigin(out x2, out y2);
413
                        double distance = SPPIDUtil.CalcPointToPointdDistance(x, y, x1, y1);
414

    
415
                        string symbol1RepID;
416
                        string symbol2RepID;
417
                        List<Point2d> point2ds;
418
                        if (i == 0)
419
                        {
420
                            symbol1RepID = centerRepID;
421
                            symbol2RepID = item.Value[i];
422
                        }
423
                        else
424
                        {
425
                            symbol1RepID = item.Value[i - 1];
426
                            symbol2RepID = item.Value[i];
427
                        }
428
                        point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID);
429
                        double moveX = 0;
430
                        double moveY = 0;
431

    
432
                        if (item.Key == SymmetryArrow.Left)
433
                            moveX = x - distance - x2;
434
                        else if (item.Key == SymmetryArrow.Right)
435
                            moveX = x + distance - x2;
436
                        else if (item.Key == SymmetryArrow.Down)
437
                            moveY = y - distance - y2;
438
                        else if (item.Key == SymmetryArrow.Up)
439
                            moveY = y + distance - y2;
440

    
441
                        moveSymbol2d.Move(0, 0, moveX, moveY);
442
                        MovePoint2d(dataSource, item.Value[i], arrow, moveX, moveY);
443
                        foreach (var point in point2ds)
444
                        {
445
                            LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point));
446
                            LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID);
447
                            point.Move(0, 0, moveX, moveY);
448
                            if (connSymbol != null)
449
                            {
450
                                Symbol2d connSymbol2d = GetSymbol2DByRepID(dataSource, connSymbol.AsLMRepresentation().Id);
451
                                connSymbol2d.Move(0, 0, moveX, moveY);
452
                                ReleaseCOMObjects(connSymbol);
453
                            }
454
                            ReleaseCOMObjects(branch);
455
                        }
456
                            
457
                    }
458
                }
459
            }
460
        }
461
        private LMSymbol GetFirstSymbolBySlope(LMADataSource dataSource, LMSymbol branch, string symbol1RepID, string symbol2RepID)
462
        {
463
            LMSymbol result = null;
464
            foreach (LMConnector connector in branch.Connect1Connectors)
465
            {
466
                if (connector.ConnectItem1SymbolObject != null && 
467
                    connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" &&
468
                    connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
469
                {
470
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
471
                    if (repID != symbol1RepID && repID != symbol2RepID)
472
                        result = connector.ConnectItem1SymbolObject;
473
                }
474

    
475
                if (connector.ConnectItem2SymbolObject != null &&
476
                    connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" &&
477
                    connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
478
                {
479
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
480
                    if (repID != symbol1RepID && repID != symbol2RepID)
481
                        result = connector.ConnectItem2SymbolObject;
482
                }
483
            }
484

    
485
            foreach (LMConnector connector in branch.Connect2Connectors)
486
            {
487
                if (connector.ConnectItem1SymbolObject != null &&
488
                    connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active" &&
489
                    connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch")
490
                {
491
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
492
                    if (repID != symbol1RepID && repID != symbol2RepID)
493
                        result = connector.ConnectItem1SymbolObject;
494
                }
495

    
496
                if (connector.ConnectItem2SymbolObject != null &&
497
                    connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active" &&
498
                    connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch")
499
                {
500
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
501
                    if (repID != symbol1RepID && repID != symbol2RepID)
502
                        result = connector.ConnectItem2SymbolObject;
503
                }
504
            }
505

    
506

    
507
            return result;
508
        }
509
        private string GetRepresentationId(Symbol2d symbol)
510
        {
511
            foreach (var attributes in symbol.AttributeSets)
512
            {
513
                foreach (var attribute in attributes)
514
                {
515
                    string name = attribute.Name;
516
                    object value = attribute.GetValue();
517
                    if (name == "DrawingID")
518
                    {
519
                        return value.ToString();  
520
                    }
521
                }
522
            }
523
            return null;
524
        }
525
        private string GetRepresentationId(Point2d point2d)
526
        {
527
            foreach (var attributes in point2d.AttributeSets)
528
            {
529
                foreach (var attribute in attributes)
530
                {
531
                    string name = attribute.Name;
532
                    object value = attribute.GetValue();
533
                    if (name == "DrawingID")
534
                    {
535
                        return value.ToString();
536
                    }
537
                }
538
            }
539
            return null;
540
        }
541
        private List<List<string>> SetSymbol(LMADataSource dataSource, string rep, double x, double y, int count)
542
        {
543
            LMSymbol _LMSymbol = dataSource.GetSymbol(rep);
544
            List<List<string>> result = new List<List<string>>();
545
            List<string> oldIDs = new List<string>() { rep };
546
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
547
            {
548
                if (connector.get_ItemStatus() != "Active")
549
                    continue;
550

    
551
                string repID = connector.AsLMRepresentation().Id;
552
                string status = connector.get_ItemStatus();
553
                if (status == "Active" && !oldIDs.Contains(repID))
554
                {
555
                    List<string> symbols = new List<string>();
556
                    oldIDs.Add(repID);
557
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
558
                    result.Add(symbols);
559
                }
560
            }
561

    
562
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
563
            {
564
                if (connector.get_ItemStatus() != "Active")
565
                    continue;
566

    
567
                string repID = connector.AsLMRepresentation().Id;
568
                string status = connector.get_ItemStatus();
569
                if (status == "Active" && !oldIDs.Contains(repID))
570
                {
571
                    List<string> symbols = new List<string>();
572
                    oldIDs.Add(repID);
573
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
574
                    result.Add(symbols);
575
                }
576
            }
577

    
578
            ReleaseCOMObjects(_LMSymbol);
579
            return result;
580
        }
581
        private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMConnector connector, double x, double y, int count)
582
        {
583
            if (symbols.Count >= count)
584
                return;
585

    
586
            if (connector.ConnectItem1SymbolObject != null && !oldIDs.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id))
587
            {
588
                string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
589
                oldIDs.Add(repID);
590
                if (connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
591
                {
592
                    double sX = connector.ConnectItem1SymbolObject.get_XCoordinate(), sY = connector.ConnectItem1SymbolObject.get_YCoordinate(); ;
593
                    SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1);
594
                    if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL)
595
                        symbols.Add(repID);
596
                }
597

    
598
                loop(dataSource, oldIDs, symbols, connector.ConnectItem1SymbolObject, x, y, count);
599
            }
600

    
601
            if (symbols.Count >= count)
602
                return;
603

    
604
            if (connector.ConnectItem2SymbolObject != null && !oldIDs.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id))
605
            {
606
                string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
607
                oldIDs.Add(repID);
608
                if (connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
609
                {
610
                    double sX = connector.ConnectItem2SymbolObject.get_XCoordinate(), sY = connector.ConnectItem2SymbolObject.get_YCoordinate(); ;
611
                    SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1);
612
                    if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL)
613
                        symbols.Add(repID);
614
                }
615

    
616
                loop(dataSource, oldIDs, symbols, connector.ConnectItem2SymbolObject, x, y, count);
617
            }
618
        }
619
        private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMSymbol _LMSymbol, double x, double y, int count)
620
        {
621
            if (symbols.Count >= count)
622
                return;
623

    
624
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
625
            {
626
                if (connector.get_ItemStatus() != "Active")
627
                    continue;
628

    
629
                string repID = connector.AsLMRepresentation().Id;
630
                string status = connector.get_ItemStatus();
631
                if (status == "Active" && !oldIDs.Contains(repID))
632
                {
633
                    oldIDs.Add(repID);
634
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
635
                }
636
            }
637

    
638
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
639
            {
640
                if (connector.get_ItemStatus() != "Active")
641
                    continue;
642

    
643
                string repID = connector.AsLMRepresentation().Id;
644
                string status = connector.get_ItemStatus();
645
                if (status == "Active" && !oldIDs.Contains(repID))
646
                {
647
                    oldIDs.Add(repID);
648
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
649
                }
650
            }
651
        }
652
        private Symbol2d GetSymbol2DByRepID(LMADataSource dataSource, string repID)
653
        {
654
            LMSymbol _LMSymbol = dataSource.GetSymbol(repID);
655
            Symbol2d symbol2D = application.ActiveDocument.ActiveSheet.DrawingObjects[_LMSymbol.get_GraphicOID().ToString()];
656
            ReleaseCOMObjects(_LMSymbol);
657
            return symbol2D;
658
        }
659
        private void MovePoint2d(LMADataSource datasource, string repID, SymmetryArrow arrow, double moveX, double moveY)
660
        {
661
            LMSymbol _LMSymbol = datasource.GetSymbol(repID);
662
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
663
            {
664
                if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()))
665
                {
666
                    if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
667
                    {
668
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()];
669
                        point.X += moveX;
670
                        point.Y += moveY;
671
                    }
672
                    else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
673
                    {
674
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()];
675
                        point.X += moveX;
676
                        point.Y += moveY;
677
                    }
678
                }
679
            }
680
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
681
            {
682
                if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()))
683
                {
684
                    if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
685
                    {
686
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()];
687
                        point.X += moveX;
688
                        point.Y += moveY;
689
                    }
690
                    else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
691
                    {
692
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()];
693
                        point.X += moveX;
694
                        point.Y += moveY;
695
                    }
696
                }
697
            }
698
            ReleaseCOMObjects(_LMSymbol);
699
        }
700
        private List<Point2d> FindAllPoint2d(LMADataSource dataSource, string repID, string nextRepID)
701
        {
702
            LMSymbol _LMSymbol = dataSource.GetSymbol(repID);
703
            List<string> endIDs = new List<string>() { repID };
704
            List<string> graphicOIDs = new List<string>();
705
            List<Point2d> result = new List<Point2d>();
706
            FindPointsLoop(dataSource, _LMSymbol, endIDs, nextRepID, graphicOIDs);
707
            ReleaseCOMObjects(_LMSymbol);
708
            foreach (var item in graphicOIDs)
709
            {
710
                Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[item] as Point2d;
711
                result.Add(point);
712
            }
713
            
714
            return result;
715
        }
716
        private bool FindPointsLoop(LMADataSource dataSource, LMSymbol _LMSymbol, List<string> endIDs, string targetRepID, List<string> graphicOIDs)
717
        {
718
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
719
            {
720
                if (connector.get_ItemStatus() != "Active")
721
                    continue;
722

    
723
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
724
                {
725
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
726
                    if (!endIDs.Contains(repID))
727
                    {
728
                        endIDs.Add(repID);
729
                        if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
730
                        {
731
                            if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs))
732
                            {
733
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
734
                                    graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString());
735
                                return true;
736
                            }
737
                        }
738
                        else if (targetRepID == repID)
739
                        {
740
                            return true;
741
                        }
742
                    }
743
                }
744
                if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
745
                {
746
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
747
                    if (!endIDs.Contains(repID))
748
                    {
749
                        endIDs.Add(repID);
750
                        if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
751
                        {
752
                            if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs))
753
                            {
754
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
755
                                    graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString());
756
                                return true;
757
                            }
758
                        }
759
                        else if (targetRepID == repID)
760
                        {
761
                            return true;
762
                        }
763
                    }
764
                }
765
            }
766
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
767
            {
768
                if (connector.get_ItemStatus() != "Active")
769
                    continue;
770

    
771
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
772
                {
773
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
774
                    if (!endIDs.Contains(repID))
775
                    {
776
                        endIDs.Add(repID);
777
                        if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
778
                        {
779
                            if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs))
780
                            {
781
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
782
                                    graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString());
783
                                return true;
784
                            }
785
                        }
786
                        else if (targetRepID == repID)
787
                        {
788
                            return true;
789
                        }
790
                    }
791
                }
792
                if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
793
                {
794
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
795
                    if (!endIDs.Contains(repID))
796
                    {
797
                        endIDs.Add(repID);
798
                        if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
799
                        {
800
                            if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs))
801
                            {
802
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
803
                                    graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString());
804
                                return true;
805
                            }
806
                        }
807
                        else if (targetRepID == repID)
808
                        {
809
                            return true;
810
                        }
811
                    }
812
                }
813
            }
814

    
815
            return false;
816
        }
817
        #endregion
818
        #region SpecBreak
819
        private void btnSpecBreakRelocation_Click(object sender, EventArgs e)
820
        {
821
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
822
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
823
            application = wApp.RADApplication;
824

    
825
            int count = application.ActiveSelectSet.Count;
826
            int dependencyCount = 0;
827
            foreach (var item in application.ActiveSelectSet)
828
                if (item.GetType() == typeof(DependencyObject))
829
                    dependencyCount++;
830

    
831
            if (count > 0 && application.ActiveSelectSet[0].GetType() == typeof(DependencyObject))
832
            {
833
                MessageBox.Show("First selected item is DependencyObject!\r\nPlease move symbol", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
834
                return;
835
            }
836

    
837
            if ((count == 3 || count == 4) && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d) &&
838
                (dependencyCount == 2 || dependencyCount == 3))
839
            {
840
                Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d;
841

    
842
                if (!symbol.DefinitionName.Contains(@"Design\Annotation\Graphics\"))
843
                {
844
                    MessageBox.Show("Select SpecBreak!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
845
                    return;
846
                }
847

    
848
                DependencyObject dependency1 = application.ActiveSelectSet[1] as DependencyObject;
849
                DependencyObject dependency2 = application.ActiveSelectSet[2] as DependencyObject;
850
                DependencyObject dependency3 = null;
851
                if (count == 4)
852
                    dependency3 = application.ActiveSelectSet[3] as DependencyObject;
853

    
854
                application.ActiveSelectSet.RemoveAll();
855
                double angle = symbol.Angle;
856
                if (symbol.GetTransform().HasReflection)
857
                    angle += Math.PI;
858

    
859
                double degree = double.NaN;
860
                if (angle > -0.1 && angle < 0.1)
861
                    degree = 0;
862
                else if (angle > 1.56 && angle < 1.58)
863
                    degree = 90;
864
                else if (angle > 3.13 && angle < 3.15)
865
                    degree = 180;
866
                else if (angle > 4.7 && angle < 4.72)
867
                    degree = 270;
868
                else if (angle > 6.27 && angle < 6.29)
869
                    degree = 0;
870
                else if (angle > -1.58 && angle < -1.56)
871
                    degree = 270;
872
                else if (angle > -3.15 && angle < -3.13)
873
                    degree = 180;
874
                else
875
                    throw new Exception("Check Angle");
876

    
877

    
878
                double originX, originY;
879
                symbol.GetOrigin(out originX, out originY);
880

    
881
                double crossX = 0;
882
                double crossY = 0;
883
                double topX = 0;
884
                double topY = 0;
885
                foreach (var item in symbol.DrawingObjects)
886
                {
887
                    Line2d line2d = item as Line2d;
888
                    if (line2d != null)
889
                    {
890
                        double x1, y1, x2, y2;
891
                        line2d.GetStartPoint(out x1, out y1);
892
                        line2d.GetEndPoint(out x2, out y2);
893
                        SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 0.1);
894

    
895
                        if (slopeType == SlopeType.HORIZONTAL)
896
                        {
897
                            if (crossY == 0)
898
                                crossY = y1;
899
                            else
900
                                crossY = (crossY + y1) / 2;
901

    
902
                            switch (degree)
903
                            {
904
                                case 90:
905
                                    if (topX == 0)
906
                                        topX = Math.Min(x1, x2);
907
                                    else
908
                                        topX = Math.Min(topX, Math.Min(x1, x2));
909
                                    break;
910
                                case 270:
911
                                    if (topX == 0)
912
                                        topX = Math.Max(x1, x2);
913
                                    else
914
                                        topX = Math.Max(topX, Math.Max(x1, x2));
915
                                    break;
916
                                default:
917
                                    break;
918
                            }
919
                        }
920
                        else if (slopeType == SlopeType.VERTICAL)
921
                        {
922
                            if (crossX == 0)
923
                                crossX = x1;
924
                            else
925
                                crossX = (crossX + x1) / 2;
926

    
927
                            switch (degree)
928
                            {
929
                                case 0:
930
                                    if (topY == 0)
931
                                        topY = Math.Max(y1, y2);
932
                                    else
933
                                        topY = Math.Max(topY, Math.Max(y1, y2));
934
                                    break;
935
                                case 180:
936
                                    if (topY == 0)
937
                                        topY = Math.Min(y1, y2);
938
                                    else
939
                                        topY = Math.Min(topY, Math.Min(y1, y2));
940
                                    break;
941
                                default:
942
                                    break;
943
                            }
944
                        }
945
                    }
946
                }
947
                switch (degree)
948
                {
949
                    case 0:
950
                        crossX = originX;
951
                        topX = crossX;
952
                        break;
953
                    case 90:
954
                        crossY = originY;
955
                        topY = crossY;
956
                        break;
957
                    case 180:
958
                        crossX = originX;
959
                        topX = crossX;
960
                        break;
961
                    case 270:
962
                        crossY = originY;
963
                        topY = crossY;
964
                        break;
965
                    default:
966
                        break;
967
                }
968

    
969
                SpecBreakRelocation(degree, crossX, crossY, topX, topY, dependency1, dependency2, dependency3);
970
            }
971
            else
972
            {
973
                MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
974
            }
975
        }
976
        private void SpecBreakRelocation(double degree, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3)
977
        {
978
            double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2, d3X1 = 0, d3Y1 = 0, d3X2 = 0, d3Y2 = 0;
979
            
980
            FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2);
981
            FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2);
982
            if (dependency3 != null)
983
                FindRangeWithOutLineString2dAndTextBox(dependency3, out d3X1, out d3Y1, out d3X2, out d3Y2);
984

    
985
            GridSetting gridSetting = GridSetting.GetInstance();
986
            double move = gridSetting.Length / 2;
987
            switch (degree)
988
            {
989
                case 0:
990
                    MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY);
991
                    MoveDependency(dependency2, d2X1, d2Y2, crossX + move, crossY);
992
                    if (dependency3 != null)
993
                        MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y1, topX, topY);
994
                    break;
995
                case 90:
996
                    MoveDependency(dependency1, d1X1, d1Y2, crossX + move, crossY);
997
                    MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY);
998
                    if (dependency3 != null)
999
                        MoveDependency(dependency3, d3X2, (d3Y1 + d3Y2) / 2, topX, topY);
1000
                    break;
1001
                case 180:
1002
                    MoveDependency(dependency1, d1X2, d1Y1, crossX - move, crossY);
1003
                    MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY);
1004
                    if (dependency3 != null)
1005
                        MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y2, topX, topY);
1006
                    break;
1007
                case 270:
1008
                    MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY);
1009
                    MoveDependency(dependency2, d2X2, d2Y1, crossX - move, crossY);
1010
                    if (dependency3 != null)
1011
                        MoveDependency(dependency3, d3X1, (d3Y1 + d3Y2) / 2, topX, topY);
1012
                    break;
1013
                default:
1014
                    break;
1015
            }
1016
        }
1017
        private void MoveDependency(DependencyObject dependency, double xFrom, double yFrom, double xTo, double yTo)
1018
        {
1019
            application.ActiveSelectSet.Add(dependency);
1020

    
1021
            Transform transform = dependency.GetTransform();
1022
            transform.DefineByMove2d(xTo - xFrom, yTo - yFrom);
1023
            application.ActiveSelectSet.Transform(transform, false);
1024

    
1025
            application.ActiveSelectSet.RemoveAll();
1026
        }
1027
        private string GetDrawingItemType(DependencyObject dependency)
1028
        {
1029
            string result = string.Empty;
1030

    
1031
            foreach (var attributes in dependency.AttributeSets)
1032
            {
1033
                foreach (var attribute in attributes)
1034
                {
1035
                    if (attribute.Name == "DrawingItemType")
1036
                        return attribute.GetValue().ToString();
1037
                }
1038
            }
1039

    
1040
            return result;
1041
        }
1042
        private void FindRangeWithOutLineString2d(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2)
1043
        {
1044
            x1 = double.MaxValue;
1045
            y1 = double.MaxValue;
1046
            x2 = double.MinValue;
1047
            y2 = double.MinValue;
1048
            foreach (DrawingObjectBase item in dependency.DrawingObjects)
1049
            {
1050
                if (item.GetType() != typeof(LineString2d))
1051
                {
1052
                    double minX, minY, maxX, maxY;
1053
                    item.Range(out minX, out minY, out maxX, out maxY);
1054
                    if (x1 > minX)
1055
                        x1 = minX;
1056
                    if (y1 > minY)
1057
                        y1 = minY;
1058
                    if (x2 < maxX)
1059
                        x2 = maxX;
1060
                    if (y2 < maxY)
1061
                        y2 = maxY;
1062
                }
1063
            }
1064

    
1065
        }
1066

    
1067
        private void FindRangeWithOutLineString2dAndTextBox(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2)
1068
        {
1069
            x1 = double.MaxValue;
1070
            y1 = double.MaxValue;
1071
            x2 = double.MinValue;
1072
            y2 = double.MinValue;
1073
            foreach (DrawingObjectBase item in dependency.DrawingObjects)
1074
            {
1075
                if (item.GetType() != typeof(LineString2d) && item.GetType() != typeof(Ingr.RAD2D.TextBox))
1076
                {
1077
                    double minX, minY, maxX, maxY;
1078
                    item.Range(out minX, out minY, out maxX, out maxY);
1079
                    if (x1 > minX)
1080
                        x1 = minX;
1081
                    if (y1 > minY)
1082
                        y1 = minY;
1083
                    if (x2 < maxX)
1084
                        x2 = maxX;
1085
                    if (y2 < maxY)
1086
                        y2 = maxY;
1087
                }
1088
            }
1089

    
1090
        }
1091
        #endregion
1092
        #region Hot Key
1093
        [System.Runtime.InteropServices.DllImport("user32.dll")]
1094
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
1095
        [System.Runtime.InteropServices.DllImport("user32.dll")]
1096
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
1097
        enum KeyModifier
1098
        {
1099
            None = 0,
1100
            Alt = 1,
1101
            Control = 2,
1102
            Shift = 4,
1103
            WinKey = 8
1104
        }
1105
        protected override void WndProc(ref Message m)
1106
        {
1107
            base.WndProc(ref m);
1108
            if (m.Msg == 0x0312)
1109
            {
1110
                Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
1111
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
1112
                int id = m.WParam.ToInt32();
1113
                application.RunCommand(CommandConstants.igcmdGridSnap);
1114
            }
1115

    
1116
        }
1117
        #endregion
1118
        #endregion
1119

    
1120
        #region TEST
1121

    
1122
        private void simpleButton1_Click(object sender, EventArgs e)
1123
        {
1124
            //Placement placement = new Placement();
1125
            //LMADataSource dataSource = placement.PIDDataSource;
1126
            //string a = "0A509911F33441A2AF088BFBA78B770D";
1127
            //LMLabelPersist label = dataSource.GetLabelPersist(a);
1128
            //label.set_XCoordinate(0.4);
1129

    
1130
            Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d;
1131
            double minX = double.MaxValue;
1132
            int index = 0;
1133
            bool start = false;
1134
            Line2d tar = null;
1135
            double rx1 = 0, ry1 = 0, rx2 = 0, ry2 = 0;
1136
            if (symbol != null)
1137
            {
1138
                for (int i = 0; i < symbol.DrawingObjects.Count; i++)
1139
                {
1140
                    DrawingObjectBase drawingObj = symbol.DrawingObjects[i];
1141

    
1142
                    if (drawingObj.GetType() == typeof(Line2d))
1143
                    {
1144
                        Line2d line = drawingObj as Line2d;
1145
                        double x1, y1, x2, y2;
1146
                        line.GetStartPoint(out x1, out y1);
1147
                        line.GetEndPoint(out x2, out y2);
1148
                        if (x1 < minX)
1149
                        {
1150
                            minX = x1;
1151
                            index = i;
1152
                            start = true;
1153
                            tar = line;
1154

    
1155
                            rx1 = x1;
1156
                            rx2 = x2;
1157
                            ry1 = y1;
1158
                            ry2 = y2;
1159
                        }
1160

    
1161
                        if (x2 < minX)
1162
                        {
1163
                            minX = x2;
1164
                            index = i;
1165
                            start = false;
1166
                            tar = line;
1167

    
1168
                            rx1 = x1;
1169
                            rx2 = x2;
1170
                            ry1 = y1;
1171
                            ry2 = y2;
1172
                        }
1173
                    }
1174
                }
1175
            }
1176

    
1177
            if (start)
1178
            {
1179
                symbol.Symbol2dParameters[0].Value = 0.02;
1180
                //Ingr.RAD2D.Group group = symbol.Convert();
1181
                //group.
1182
            }
1183
            else
1184
            {
1185

    
1186
            }
1187
        }
1188

    
1189
        private void AutoJoinPipeRun()
1190
        {
1191
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
1192
            WrapperApplication wApp = new WrapperApplication(application.Application);
1193
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
1194

    
1195
            string modelItemId = null;
1196
            List<double[]> vertices = new List<double[]>();
1197
            if (radApp.ActiveSelectSet.Count == 0)
1198
            {
1199
                return;
1200
            }
1201
            dynamic OID = radApp.ActiveSelectSet[0].Key();
1202
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1203
            foreach (var attributes in drawingObject.AttributeSets)
1204
            {
1205
                foreach (var attribute in attributes)
1206
                {
1207
                    if (attribute.Name == "ModelID")
1208
                        modelItemId = attribute.GetValue().ToString();
1209
                }
1210
            }
1211
            radApp.ActiveSelectSet.RemoveAll();
1212

    
1213
        }
1214
        #endregion
1215

    
1216

    
1217
        [DllImport("user32.dll")]
1218
        public static extern int FindWindow(string lpClassName, string lpWindowName);
1219

    
1220
        [DllImport("user32.dll", SetLastError = true)]
1221
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
1222

    
1223
        private void ConverterDocking_Load(object sender, EventArgs e)
1224
        {
1225
#if DEBUG
1226
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
1227
#else
1228
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
1229
#endif
1230

    
1231
        }
1232

    
1233
        
1234
    }
1235
}
클립보드 이미지 추가 (최대 크기: 500 MB)