프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 1ecaaba8

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

1 65881d60 gaqhf
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 69b7387a gaqhf
using System.IO;
12 65881d60 gaqhf
using Microsoft.VisualBasic;
13 e3e2d41f gaqhf
using Ingr.RAD2D;
14 d19ae675 gaqhf
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 1ba9c671 gaqhf
using Plaice;
21
using Llama;
22 ca214bc3 gaqhf
using DevExpress.XtraSplashScreen;
23 224535bb gaqhf
using Newtonsoft.Json;
24 9628f54b gaqhf
using System.Runtime.InteropServices;
25 4941f5fe gaqhf
using System.Reflection;
26 154d8f43 gaqhf
using Converter.SPPID.OPC;
27 65881d60 gaqhf
28
namespace Converter.SPPID.Wrapper
29
{
30
    public partial class ConverterDocking : UserControl
31
    {
32 4941f5fe gaqhf
        Ingr.RAD2D.Application application;
33 f14b4e3b gaqhf
        static bool addEvent = false;
34 65881d60 gaqhf
        public ConverterDocking()
35
        {
36
            InitializeComponent();
37 c3e8fa8e gaqhf
            spinEditSymmetry.Properties.Mask.EditMask = "f0";
38 4941f5fe gaqhf
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
39
            WrapperApplication wApp = new WrapperApplication(dApplication.Application);
40
            application = wApp.RADApplication;
41 d4c3e39f gaqhf
            
42 4941f5fe gaqhf
            ReleaseCOMObjects(dApplication);
43
            dApplication = null;
44 6a7573b0 gaqhf
            try
45
            {
46
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
47
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
48 154d8f43 gaqhf
49
                Project_Info _ProjectInfo = Project_Info.GetInstance();
50 8847ea67 gaqhf
                _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 25c5df17 gaqhf
                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 f14b4e3b gaqhf
76
                if (!addEvent)
77
                {
78
                    application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit;
79
                    addEvent = true;
80
                }
81 0db80f26 gaqhf
                RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode());
82 6a7573b0 gaqhf
            }
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 65881d60 gaqhf
        }
91 1b09fe17 gaqhf
        private void ApplicationEvents_ApplicationExit(out bool cancel)
92
        {
93
            cancel = false;
94
        }
95 5a9396ae humkyung
        /// <summary>
96
        /// 선택한 도면들을 읽어서 SPPID로 변환한다.
97
        /// </summary>
98
        /// <param name="sender"></param>
99
        /// <param name="e"></param>
100 e3e2d41f gaqhf
        private void btnConverter_Click(object sender, EventArgs e)
101 65881d60 gaqhf
        {
102 1ba9c671 gaqhf
            ConverterForm converterForm = new ConverterForm();
103
            if (converterForm.ShowDialog() == DialogResult.OK)
104 65881d60 gaqhf
            {
105 4941f5fe gaqhf
                //Ingr.RAD2D.Document doc = application.Documents.Add();
106
107 1ba9c671 gaqhf
                try
108
                {
109
                    CloseOPCForm.Run();
110 ca214bc3 gaqhf
111 d5ec4d0f gaqhf
                    for (int i = 0; i < converterForm.Documents.Count; i++)
112 1ba9c671 gaqhf
                    {
113 d5ec4d0f gaqhf
                        SPPID_Document document = converterForm.Documents[i];
114 1ba9c671 gaqhf
                        if (document.SetSPPIDMapping() && document.Enable)
115
                        {
116 bccacd6c gaqhf
                            using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked))
117 5a9396ae humkyung
                            {
118
                                modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
119
                                modeling.Run();
120
                            }
121 1ba9c671 gaqhf
                        }
122
                    }
123
                }
124
                catch (Exception ex)
125
                {
126
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
127
                }
128
                finally
129 d19ae675 gaqhf
                {
130 1ba9c671 gaqhf
                    CloseOPCForm.Stop();
131 4941f5fe gaqhf
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 1ba9c671 gaqhf
                }
140
141
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
142
            }
143
        }
144
145 69b7387a gaqhf
        private void btnLinkOPC_Click(object sender, EventArgs e)
146
        {
147 154d8f43 gaqhf
            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 69b7387a gaqhf
160 154d8f43 gaqhf
                    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 58993ba9 gaqhf
                        DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
174
                        DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
175 154d8f43 gaqhf
176 58993ba9 gaqhf
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
177 154d8f43 gaqhf
                        {
178 58993ba9 gaqhf
                            DataRow fromOPCInfoRow = fromOPCInfoRows[0];
179
                            DataRow toOPCInfoRow = toOPCInfoRows[0];
180 154d8f43 gaqhf
                            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 58993ba9 gaqhf
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
184 b7a29053 gaqhf
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
185 154d8f43 gaqhf
                            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 58993ba9 gaqhf
204
            MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
205 69b7387a gaqhf
        }
206
207 4fb0f8d5 gaqhf
        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 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
218 1ba9c671 gaqhf
        {
219 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
220
            WrapperApplication wApp = new WrapperApplication(application.Application);
221
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
222
223 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
224 65881d60 gaqhf
            {
225 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
226
                if (line2D != null)
227 1ba9c671 gaqhf
                {
228 6a7573b0 gaqhf
                    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 1ba9c671 gaqhf
                }
241 6a7573b0 gaqhf
                else
242
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
243 65881d60 gaqhf
            }
244 6a7573b0 gaqhf
            else
245
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
246
        }
247 7e4a64a3 gaqhf
248 82c7f66d gaqhf
        #region SPPID Utils
249 29ac1959 gaqhf
        #region Symmetry
250 82c7f66d gaqhf
        private void btnSymmetry_Click(object sender, EventArgs e)
251
        {
252 c3e8fa8e gaqhf
            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 77d6e710 gaqhf
                        string symbol1RepID;
416
                        string symbol2RepID;
417 c3e8fa8e gaqhf
                        List<Point2d> point2ds;
418
                        if (i == 0)
419 77d6e710 gaqhf
                        {
420
                            symbol1RepID = centerRepID;
421
                            symbol2RepID = item.Value[i];
422
                        }
423 c3e8fa8e gaqhf
                        else
424 77d6e710 gaqhf
                        {
425
                            symbol1RepID = item.Value[i - 1];
426
                            symbol2RepID = item.Value[i];
427
                        }
428
                        point2ds = FindAllPoint2d(dataSource, symbol1RepID, symbol2RepID);
429 c3e8fa8e gaqhf
                        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 77d6e710 gaqhf
                        {
445
                            LMSymbol branch = dataSource.GetSymbol(GetRepresentationId(point));
446
                            LMSymbol connSymbol = GetFirstSymbolBySlope(dataSource, branch, symbol1RepID, symbol2RepID);
447 c3e8fa8e gaqhf
                            point.Move(0, 0, moveX, moveY);
448 77d6e710 gaqhf
                            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 c3e8fa8e gaqhf
                    }
458
                }
459
            }
460
        }
461 77d6e710 gaqhf
        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 c3e8fa8e gaqhf
        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 77d6e710 gaqhf
        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 c3e8fa8e gaqhf
        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 82c7f66d gaqhf
638 c3e8fa8e gaqhf
            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 82c7f66d gaqhf
        }
659 c3e8fa8e gaqhf
        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 29ac1959 gaqhf
        #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 979a91b9 gaqhf
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 29ac1959 gaqhf
            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 c3e8fa8e gaqhf
848 29ac1959 gaqhf
                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 30a774f6 gaqhf
                else if (angle > -3.15 && angle < -3.13)
873
                    degree = 180;
874 29ac1959 gaqhf
                else
875 30a774f6 gaqhf
                    throw new Exception("Check Angle");
876 c3e8fa8e gaqhf
877
878 29ac1959 gaqhf
                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 e7ea221d gaqhf
                SpecBreakRelocation(degree, originX, originY, crossX, crossY, topX, topY, dependency1, dependency2, dependency3);
970 29ac1959 gaqhf
            }
971
            else
972
            {
973
                MessageBox.Show("Check Rule!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
974
            }
975
        }
976 e7ea221d gaqhf
        private void SpecBreakRelocation(double degree, double originX, double originY, double crossX, double crossY, double topX, double topY, DependencyObject dependency1, DependencyObject dependency2, DependencyObject dependency3)
977 29ac1959 gaqhf
        {
978 519902b7 gaqhf
            double d1X1, d1Y1, d1X2, d1Y2, d2X1, d2Y1, d2X2, d2Y2, d3X1 = 0, d3Y1 = 0, d3X2 = 0, d3Y2 = 0;
979 30a774f6 gaqhf
            
980 54311b41 gaqhf
            FindRangeWithOutLineString2d(dependency1, out d1X1, out d1Y1, out d1X2, out d1Y2);
981
            FindRangeWithOutLineString2d(dependency2, out d2X1, out d2Y1, out d2X2, out d2Y2);
982 519902b7 gaqhf
            if (dependency3 != null)
983 cf520d0d gaqhf
                FindRangeWithOutLineString2dAndTextBox(dependency3, out d3X1, out d3Y1, out d3X2, out d3Y2);
984 29ac1959 gaqhf
985 25c5df17 gaqhf
            GridSetting gridSetting = GridSetting.GetInstance();
986
            double move = gridSetting.Length / 2;
987 29ac1959 gaqhf
            switch (degree)
988
            {
989
                case 0:
990 25c5df17 gaqhf
                    MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY);
991
                    MoveDependency(dependency2, d2X1, d2Y2, crossX + move, crossY);
992 519902b7 gaqhf
                    if (dependency3 != null)
993
                        MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y1, topX, topY);
994 29ac1959 gaqhf
                    break;
995
                case 90:
996 25c5df17 gaqhf
                    MoveDependency(dependency1, d1X1, d1Y2, crossX + move, crossY);
997
                    MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY);
998 519902b7 gaqhf
                    if (dependency3 != null)
999 e7ea221d gaqhf
                        MoveDependency(dependency3, d3X1, (d3Y1 + d3Y2) / 2, originX, originY);
1000 29ac1959 gaqhf
                    break;
1001
                case 180:
1002 25c5df17 gaqhf
                    MoveDependency(dependency1, d1X2, d1Y1, crossX - move, crossY);
1003
                    MoveDependency(dependency2, d2X1, d2Y1, crossX + move, crossY);
1004 519902b7 gaqhf
                    if (dependency3 != null)
1005
                        MoveDependency(dependency3, (d3X1 + d3X2) / 2, d3Y2, topX, topY);
1006 29ac1959 gaqhf
                    break;
1007
                case 270:
1008 25c5df17 gaqhf
                    MoveDependency(dependency1, d1X2, d1Y2, crossX - move, crossY);
1009
                    MoveDependency(dependency2, d2X2, d2Y1, crossX - move, crossY);
1010 519902b7 gaqhf
                    if (dependency3 != null)
1011 e7ea221d gaqhf
                        MoveDependency(dependency3, d3X2, (d3Y1 + d3Y2) / 2, originX, originY);
1012 29ac1959 gaqhf
                    break;
1013
                default:
1014
                    break;
1015
            }
1016
        }
1017 6a659fd9 gaqhf
        private void MoveDependency(DependencyObject dependency, double xFrom, double yFrom, double xTo, double yTo)
1018
        {
1019 54311b41 gaqhf
            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 6a659fd9 gaqhf
        }
1027 29ac1959 gaqhf
        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 54311b41 gaqhf
        private void FindRangeWithOutLineString2d(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2)
1043 29ac1959 gaqhf
        {
1044 54311b41 gaqhf
            x1 = double.MaxValue;
1045
            y1 = double.MaxValue;
1046
            x2 = double.MinValue;
1047
            y2 = double.MinValue;
1048
            foreach (DrawingObjectBase item in dependency.DrawingObjects)
1049 29ac1959 gaqhf
            {
1050 54311b41 gaqhf
                if (item.GetType() != typeof(LineString2d))
1051 29ac1959 gaqhf
                {
1052 54311b41 gaqhf
                    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 cf520d0d gaqhf
                    if (x2 < maxX)
1059
                        x2 = maxX;
1060
                    if (y2 < maxY)
1061
                        y2 = maxY;
1062
                }
1063
            }
1064
1065
        }
1066
        private void FindRangeWithOutLineString2dAndTextBox(DependencyObject dependency, out double x1, out double y1, out double x2, out double y2)
1067
        {
1068
            x1 = double.MaxValue;
1069
            y1 = double.MaxValue;
1070
            x2 = double.MinValue;
1071
            y2 = double.MinValue;
1072
            foreach (DrawingObjectBase item in dependency.DrawingObjects)
1073
            {
1074
                if (item.GetType() != typeof(LineString2d) && item.GetType() != typeof(Ingr.RAD2D.TextBox))
1075
                {
1076
                    double minX, minY, maxX, maxY;
1077
                    item.Range(out minX, out minY, out maxX, out maxY);
1078
                    if (x1 > minX)
1079
                        x1 = minX;
1080
                    if (y1 > minY)
1081
                        y1 = minY;
1082 54311b41 gaqhf
                    if (x2 < maxX)
1083
                        x2 = maxX;
1084
                    if (y2 < maxY)
1085
                        y2 = maxY;
1086 29ac1959 gaqhf
                }
1087
            }
1088
1089
        }
1090
        #endregion
1091 1b09fe17 gaqhf
        #region Hot Key
1092 70b0b5d7 gaqhf
        [System.Runtime.InteropServices.DllImport("user32.dll")]
1093
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
1094
        [System.Runtime.InteropServices.DllImport("user32.dll")]
1095
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
1096
        enum KeyModifier
1097
        {
1098
            None = 0,
1099
            Alt = 1,
1100
            Control = 2,
1101
            Shift = 4,
1102
            WinKey = 8
1103
        }
1104
        protected override void WndProc(ref Message m)
1105
        {
1106
            base.WndProc(ref m);
1107
            if (m.Msg == 0x0312)
1108
            {
1109
                Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
1110
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
1111
                int id = m.WParam.ToInt32();
1112
                application.RunCommand(CommandConstants.igcmdGridSnap);
1113
            }
1114
1115
        }
1116 1b09fe17 gaqhf
        #endregion
1117 82c7f66d gaqhf
        #endregion
1118 70b0b5d7 gaqhf
1119 1b09fe17 gaqhf
        #region TEST
1120 f14b4e3b gaqhf
1121 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
1122
        {
1123 54311b41 gaqhf
            //Placement placement = new Placement();
1124
            //LMADataSource dataSource = placement.PIDDataSource;
1125
            //string a = "0A509911F33441A2AF088BFBA78B770D";
1126
            //LMLabelPersist label = dataSource.GetLabelPersist(a);
1127
            //label.set_XCoordinate(0.4);
1128
1129 519902b7 gaqhf
            Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d;
1130
            double minX = double.MaxValue;
1131
            int index = 0;
1132
            bool start = false;
1133
            Line2d tar = null;
1134
            double rx1 = 0, ry1 = 0, rx2 = 0, ry2 = 0;
1135
            if (symbol != null)
1136 d9fc7084 gaqhf
            {
1137 519902b7 gaqhf
                for (int i = 0; i < symbol.DrawingObjects.Count; i++)
1138
                {
1139
                    DrawingObjectBase drawingObj = symbol.DrawingObjects[i];
1140
1141
                    if (drawingObj.GetType() == typeof(Line2d))
1142
                    {
1143
                        Line2d line = drawingObj as Line2d;
1144
                        double x1, y1, x2, y2;
1145
                        line.GetStartPoint(out x1, out y1);
1146
                        line.GetEndPoint(out x2, out y2);
1147
                        if (x1 < minX)
1148
                        {
1149
                            minX = x1;
1150
                            index = i;
1151
                            start = true;
1152
                            tar = line;
1153
1154
                            rx1 = x1;
1155
                            rx2 = x2;
1156
                            ry1 = y1;
1157
                            ry2 = y2;
1158
                        }
1159
1160
                        if (x2 < minX)
1161
                        {
1162
                            minX = x2;
1163
                            index = i;
1164
                            start = false;
1165
                            tar = line;
1166
1167
                            rx1 = x1;
1168
                            rx2 = x2;
1169
                            ry1 = y1;
1170
                            ry2 = y2;
1171
                        }
1172
                    }
1173
                }
1174
            }
1175
1176
            if (start)
1177
            {
1178
                symbol.Symbol2dParameters[0].Value = 0.02;
1179
                //Ingr.RAD2D.Group group = symbol.Convert();
1180
                //group.
1181
            }
1182
            else
1183
            {
1184
1185 d9fc7084 gaqhf
            }
1186 ca6e0f51 gaqhf
        }
1187 4941f5fe gaqhf
1188 ca6e0f51 gaqhf
        private void AutoJoinPipeRun()
1189
        {
1190 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
1191
            WrapperApplication wApp = new WrapperApplication(application.Application);
1192
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
1193
1194 ca6e0f51 gaqhf
            string modelItemId = null;
1195
            List<double[]> vertices = new List<double[]>();
1196 a31a512e gaqhf
            if (radApp.ActiveSelectSet.Count == 0)
1197
            {
1198
                return;
1199
            }
1200 ca6e0f51 gaqhf
            dynamic OID = radApp.ActiveSelectSet[0].Key();
1201
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
1202
            foreach (var attributes in drawingObject.AttributeSets)
1203 4ba01591 gaqhf
            {
1204 ca6e0f51 gaqhf
                foreach (var attribute in attributes)
1205 4ba01591 gaqhf
                {
1206 ca6e0f51 gaqhf
                    if (attribute.Name == "ModelID")
1207
                        modelItemId = attribute.GetValue().ToString();
1208
                }
1209
            }
1210
            radApp.ActiveSelectSet.RemoveAll();
1211 32205389 gaqhf
1212 7e4a64a3 gaqhf
        }
1213
        #endregion
1214
1215 7aee331b gaqhf
1216 9628f54b gaqhf
        [DllImport("user32.dll")]
1217
        public static extern int FindWindow(string lpClassName, string lpWindowName);
1218 3734dcc5 gaqhf
1219
        [DllImport("user32.dll", SetLastError = true)]
1220
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
1221
1222 b427ebf9 humkyung
        private void ConverterDocking_Load(object sender, EventArgs e)
1223
        {
1224
#if DEBUG
1225
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
1226
#else
1227
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
1228
#endif
1229
1230
        }
1231 0db80f26 gaqhf
1232
        
1233 65881d60 gaqhf
    }
1234
}
클립보드 이미지 추가 (최대 크기: 500 MB)