프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ c3e8fa8e

이력 | 보기 | 이력해설 | 다운로드 (39.8 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 f14b4e3b gaqhf
57
                if (!addEvent)
58
                {
59
                    application.EventObject.BeforeApplicationExit += ApplicationEvents_ApplicationExit;
60
                    addEvent = true;
61
                }
62 0db80f26 gaqhf
                RegisterHotKey(this.Handle, 0, (int)KeyModifier.Shift, Keys.A.GetHashCode());
63 6a7573b0 gaqhf
            }
64
            catch (Exception ex)
65
            {
66
                StringBuilder sb = new StringBuilder();
67
                sb.AppendLine(ex.Message);
68
                sb.AppendLine(ex.StackTrace);
69
                MessageBox.Show(sb.ToString());
70
            }
71 65881d60 gaqhf
        }
72 1b09fe17 gaqhf
        private void ApplicationEvents_ApplicationExit(out bool cancel)
73
        {
74
            cancel = false;
75
        }
76 5a9396ae humkyung
        /// <summary>
77
        /// 선택한 도면들을 읽어서 SPPID로 변환한다.
78
        /// </summary>
79
        /// <param name="sender"></param>
80
        /// <param name="e"></param>
81 e3e2d41f gaqhf
        private void btnConverter_Click(object sender, EventArgs e)
82 65881d60 gaqhf
        {
83 1ba9c671 gaqhf
            ConverterForm converterForm = new ConverterForm();
84
            if (converterForm.ShowDialog() == DialogResult.OK)
85 65881d60 gaqhf
            {
86 4941f5fe gaqhf
                //Ingr.RAD2D.Document doc = application.Documents.Add();
87
88 1ba9c671 gaqhf
                try
89
                {
90
                    CloseOPCForm.Run();
91 ca214bc3 gaqhf
92 d5ec4d0f gaqhf
                    for (int i = 0; i < converterForm.Documents.Count; i++)
93 1ba9c671 gaqhf
                    {
94 d5ec4d0f gaqhf
                        SPPID_Document document = converterForm.Documents[i];
95 1ba9c671 gaqhf
                        if (document.SetSPPIDMapping() && document.Enable)
96
                        {
97 bccacd6c gaqhf
                            using (AutoModeling modeling = new AutoModeling(document, converterForm.checkEditCloseDocument.Checked))
98 5a9396ae humkyung
                            {
99
                                modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
100
                                modeling.Run();
101
                            }
102 1ba9c671 gaqhf
                        }
103
                    }
104
                }
105
                catch (Exception ex)
106
                {
107
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
108
                }
109
                finally
110 d19ae675 gaqhf
                {
111 1ba9c671 gaqhf
                    CloseOPCForm.Stop();
112 4941f5fe gaqhf
113
                    //doc.SaveOnClose = false;
114
                    //doc.Close(false);
115
116
                    //dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
117
                    //dApplication.Drawings[1].CloseDrawing(false);
118
                    //ReleaseCOMObjects(dApplication);
119
                    //dApplication = null;
120 1ba9c671 gaqhf
                }
121
122
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
123
            }
124
        }
125
126 69b7387a gaqhf
        private void btnLinkOPC_Click(object sender, EventArgs e)
127
        {
128 154d8f43 gaqhf
            DataTable tOPCInfo = Project_DB.SelectOPCInfo();
129
            DataTable tOPCRelations = Project_DB.SelectOPCRelations();
130
            DataTable tDrawingInfo = Project_DB.SelectDrawingInfo();
131
            dynamic dApplication = Interaction.GetObject("", "PIDAutomation.Application");
132
133
            foreach (DataRow row in tOPCInfo.Rows)
134
            {
135
                if (!Convert.ToBoolean(row["PAIRED"]))
136
                {
137
                    string drawingUID = row["ID2_DRAWING_UID"].ToString();
138
                    string OPCUID = row["ID2_OPC_UID"].ToString();
139
                    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));
140 69b7387a gaqhf
141 154d8f43 gaqhf
                    if (rows.Length == 2)
142
                    {
143
                        string fromDrawingsUID1 = rows[0]["From_Drawings_UID"].ToString();
144
                        string fromDrawingsUID2 = rows[1]["From_Drawings_UID"].ToString();
145
                        string fromOPCUID1 = rows[0]["From_OPC_UID"].ToString();
146
                        string fromOPCUID2 = rows[1]["From_OPC_UID"].ToString();
147
                        string toDrawingsUID1 = rows[0]["To_Drawings_UID"].ToString();
148
                        string toDrawingsUID2 = rows[1]["To_Drawings_UID"].ToString();
149
                        string toOPCUID1 = rows[0]["To_OPC_UID"].ToString();
150
                        string toOPCUID2 = rows[1]["To_OPC_UID"].ToString();
151
152
                        DataRow[] fromDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", fromDrawingsUID1));
153
                        DataRow[] toDrawing = tDrawingInfo.Select(string.Format("ID2_DRAWING_UID = '{0}'", toDrawingsUID1));
154 58993ba9 gaqhf
                        DataRow[] fromOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", fromOPCUID1));
155
                        DataRow[] toOPCInfoRows = tOPCInfo.Select(string.Format("ID2_OPC_UID = '{0}'", toOPCUID1));
156 154d8f43 gaqhf
157 58993ba9 gaqhf
                        if (fromOPCUID1 == toOPCUID2 && fromOPCUID2 == toOPCUID1 && fromDrawing.Length == 1 && toDrawing.Length == 1 && fromOPCInfoRows.Length == 1 && toOPCInfoRows.Length == 1)
158 154d8f43 gaqhf
                        {
159 58993ba9 gaqhf
                            DataRow fromOPCInfoRow = fromOPCInfoRows[0];
160
                            DataRow toOPCInfoRow = toOPCInfoRows[0];
161 154d8f43 gaqhf
                            string fromOPCModelId = fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
162
                            string toOPCModelId = toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString();
163
                            string toDrawingName = toDrawing[0]["DRAWINGNAME"].ToString();
164 58993ba9 gaqhf
                            List<string[]> toOPCAttributes = JsonConvert.DeserializeObject<List<string[]>>(toOPCInfoRow["ATTRIBUTES"].ToString());
165 b7a29053 gaqhf
                            AutoModeling_OPC opc = new AutoModeling_OPC(dApplication, application, fromOPCModelId, toOPCModelId, toDrawingName, toOPCAttributes);
166 154d8f43 gaqhf
                            if (opc.Run())
167
                            {
168
                                fromOPCInfoRow["PAIRED"] = true;
169
                                toOPCInfoRow["PAIRED"] = true;
170
171
                                Project_DB.InsertOPCInfo(fromOPCInfoRow["ID2_OPC_UID"].ToString(), fromOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), fromOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
172
                                Project_DB.InsertOPCInfo(toOPCInfoRow["ID2_OPC_UID"].ToString(), toOPCInfoRow["SPPID_OPC_MODELITEM_ID"].ToString(), toOPCInfoRow["ID2_DRAWING_UID"].ToString(), true);
173
                            }
174
                        }
175
                    }
176
                }
177
            }
178
179
            tOPCInfo.Dispose();
180
            tOPCRelations.Dispose();
181
            tDrawingInfo.Dispose();
182
            ReleaseCOMObjects(dApplication);
183
            dApplication = null;
184 58993ba9 gaqhf
185
            MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
186 69b7387a gaqhf
        }
187
188 4fb0f8d5 gaqhf
        public void ReleaseCOMObjects(params object[] objVars)
189
        {
190
            int intNewRefCount = 0;
191
            foreach (object obj in objVars)
192
            {
193
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
194
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
195
            }
196
        }
197
198 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
199 1ba9c671 gaqhf
        {
200 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
201
            WrapperApplication wApp = new WrapperApplication(application.Application);
202
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
203
204 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
205 65881d60 gaqhf
            {
206 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
207
                if (line2D != null)
208 1ba9c671 gaqhf
                {
209 6a7573b0 gaqhf
                    double minX = 0;
210
                    double minY = 0;
211
                    double maxX = 0;
212
                    double maxY = 0;
213
                    line2D.Range(out minX, out minY, out maxX, out maxY);
214
215
                    Settings.Default.DrawingX = maxX - minX;
216
                    Settings.Default.DrawingY = maxY - minY;
217
                    Settings.Default.Save();
218
219
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
220
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
221 1ba9c671 gaqhf
                }
222 6a7573b0 gaqhf
                else
223
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
224 65881d60 gaqhf
            }
225 6a7573b0 gaqhf
            else
226
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
227
        }
228 7e4a64a3 gaqhf
229 82c7f66d gaqhf
        #region SPPID Utils
230
        private void btnSymmetry_Click(object sender, EventArgs e)
231
        {
232 c3e8fa8e gaqhf
            if (application.ActiveSelectSet.Count == 1 && application.ActiveSelectSet[0].GetType() == typeof(Symbol2d))
233
            {
234
                int symCount = (int)spinEditSymmetry.Value;
235
                Symbol2d symbol = application.ActiveSelectSet[0] as Symbol2d;
236
                double x, y;
237
                symbol.GetOrigin(out x, out y);
238
                string rep = GetRepresentationId(symbol);
239
                List<string> verticalRepID = new List<string>();
240
                List<string> horizontalRepID = new List<string>();
241
242
                if ((symbol.LinearName.Contains("Piping") ||
243
                    symbol.LinearName.Contains("Instrument")) &&
244
                    !string.IsNullOrEmpty(rep))
245
                {
246
                    Placement placement = new Placement();
247
                    LMADataSource dataSource = placement.PIDDataSource;
248
                    List<List<string>> datas = SetSymbol(dataSource, rep, x, y, symCount);
249
                    Dictionary<SymmetryArrow, List<string>> resultDatas = new Dictionary<SymmetryArrow, List<string>>();
250
                    if (datas.Count >= 2 && datas.Find(loop => loop.Count != symCount) == null)
251
                    {
252
                        SymmetryArrow arrow = SymmetryArrow.None;
253
                        foreach (var data in datas)
254
                        {
255
                            LMSymbol firstSymbol = dataSource.GetSymbol(data[0]);
256
                            double fX = firstSymbol.get_XCoordinate();
257
                            double fY = firstSymbol.get_YCoordinate();
258
259
                            SlopeType type = SPPIDUtil.CalcSlope(x, y, fX, fY, 1);
260
                            if (type == SlopeType.HORIZONTAL)
261
                            {
262
                                if (fX < x)
263
                                {
264
                                    arrow |= SymmetryArrow.Left;
265
                                    resultDatas.Add(SymmetryArrow.Left, data);
266
                                }
267
                                else
268
                                {
269
                                    arrow |= SymmetryArrow.Right;
270
                                    resultDatas.Add(SymmetryArrow.Right, data);
271
                                }
272
273
                            }
274
                            else if (type == SlopeType.VERTICAL)
275
                            {
276
                                if (fY < y)
277
                                {
278
                                    arrow |= SymmetryArrow.Down;
279
                                    resultDatas.Add(SymmetryArrow.Down, data);
280
                                }
281
                                else
282
                                {
283
                                    arrow |= SymmetryArrow.Up;
284
                                    resultDatas.Add(SymmetryArrow.Up, data);
285
                                }
286
                            }
287
288
                            ReleaseCOMObjects(firstSymbol);
289
                        }
290
291
                        SymmetryForm form = new SymmetryForm(arrow);
292
                        if (form.ShowDialog() == DialogResult.OK)
293
                        {
294
                            MoveByResult(dataSource, resultDatas, x, y, form.Result, rep);
295
                        }
296
                    }
297
                    else
298
                        MessageBox.Show("Check Symmetry Rules", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
299
                    ReleaseCOMObjects(dataSource);
300
                    ReleaseCOMObjects(placement);
301
                }
302
            }
303
304
            return;
305
306
            List<Symbol2d> symbols = new List<Symbol2d>();
307
            foreach (var item in application.ActiveSelectSet)
308
            {
309
                Type type = item.GetType();
310
                if (type == typeof(Symbol2d))
311
                {
312
                    Symbol2d symbol = item as Symbol2d;
313
                    if (symbol.LinearName.Contains("Piping") ||
314
                        symbol.LinearName.Contains("Instrument"))
315
                        symbols.Add(symbol);
316
                }
317
                //if (item.GetType() == typeof(Symbol2d) || item.GetType() == typeof(Point2d))
318
                //    items.Add(item);
319
            }
320
321
            List<Symbol2d> verticalSymbols = new List<Symbol2d>();
322
            List<Symbol2d> horizontalSymbols = new List<Symbol2d>();
323
            Symbol2d mainSymbol = null;
324
            for (int i = 0; i < symbols.Count - 1; i++)
325
            {
326
                Symbol2d symbol1 = symbols[i];
327
                for (int j = 1; j < symbols.Count; j++)
328
                {
329
                    Symbol2d symbol2 = symbols[j];
330
331
                    if (symbol1 != symbol2)
332
                    {
333
                        double x1, y1, x2, y2;
334
                        symbol1.GetOrigin(out x1, out y1);
335
                        symbol2.GetOrigin(out x2, out y2);
336
                        SlopeType slopeType = SPPIDUtil.CalcSlope(x1, y1, x2, y2, 1);
337
                        if (slopeType == SlopeType.HORIZONTAL)
338
                        {
339
                            if (!horizontalSymbols.Contains(symbol1))
340
                                horizontalSymbols.Add(symbol1);
341
                            if (!horizontalSymbols.Contains(symbol2))
342
                                horizontalSymbols.Add(symbol2);
343
344
                            if (verticalSymbols.Contains(symbol1))
345
                                mainSymbol = symbol1;
346
                            if (verticalSymbols.Contains(symbol2))
347
                                mainSymbol = symbol2;
348
                        }
349
                        else if (slopeType == SlopeType.VERTICAL)
350
                        {
351
                            if (!verticalSymbols.Contains(symbol1))
352
                                verticalSymbols.Add(symbol1);
353
                            if (!verticalSymbols.Contains(symbol2))
354
                                verticalSymbols.Add(symbol2);
355
356
                            if (horizontalSymbols.Contains(symbol1))
357
                                mainSymbol = symbol1;
358
                            if (horizontalSymbols.Contains(symbol2))
359
                                mainSymbol = symbol2;
360
                        }
361
                    }
362
                }
363
            }
364
365
            application.ActiveSelectSet.RemoveAll();
366
            foreach (var item in verticalSymbols)
367
                application.ActiveSelectSet.Add(item);
368
            foreach (var item in horizontalSymbols)
369
                application.ActiveSelectSet.Add(item);
370
                
371
372
            if (MessageBox.Show("Continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
373
            {
374
                application.ActiveSelectSet.RemoveAll();
375
376
            }
377
        }
378
        private void MoveByResult(LMADataSource dataSource,Dictionary<SymmetryArrow, List<string>> resultDatas, double x, double y, SymmetryArrow arrow, string centerRepID)
379
        {
380
            List<string> datas = resultDatas[arrow];
381
            foreach (var item in resultDatas)
382
            {
383
                if (item.Key != arrow)
384
                {
385
                    for (int i = 0; i < item.Value.Count; i++)
386
                    {
387
                        Symbol2d moveSymbol2d = GetSymbol2DByRepID(dataSource, item.Value[i]);
388
                        Symbol2d symbol2d = GetSymbol2DByRepID(dataSource, datas[i]);
389
390
                        double x1, y1, x2, y2;
391
                        symbol2d.GetOrigin(out x1, out y1);
392
                        moveSymbol2d.GetOrigin(out x2, out y2);
393
                        double distance = SPPIDUtil.CalcPointToPointdDistance(x, y, x1, y1);
394
395
                        List<Point2d> point2ds;
396
                        if (i == 0)
397
                            point2ds = FindAllPoint2d(dataSource, centerRepID, item.Value[i]);
398
                        else
399
                            point2ds = FindAllPoint2d(dataSource, item.Value[i - 1], item.Value[i]);
400
                        double moveX = 0;
401
                        double moveY = 0;
402
403
                        if (item.Key == SymmetryArrow.Left)
404
                            moveX = x - distance - x2;
405
                        else if (item.Key == SymmetryArrow.Right)
406
                            moveX = x + distance - x2;
407
                        else if (item.Key == SymmetryArrow.Down)
408
                            moveY = y - distance - y2;
409
                        else if (item.Key == SymmetryArrow.Up)
410
                            moveY = y + distance - y2;
411
412
                        moveSymbol2d.Move(0, 0, moveX, moveY);
413
                        MovePoint2d(dataSource, item.Value[i], arrow, moveX, moveY);
414
                        foreach (var point in point2ds)
415
                            point.Move(0, 0, moveX, moveY);
416
                    }
417
                }
418
            }
419
        }
420
        private string GetRepresentationId(Symbol2d symbol)
421
        {
422
            foreach (var attributes in symbol.AttributeSets)
423
            {
424
                foreach (var attribute in attributes)
425
                {
426
                    string name = attribute.Name;
427
                    object value = attribute.GetValue();
428
                    if (name == "DrawingID")
429
                    {
430
                        return value.ToString();  
431
                    }
432
                }
433
            }
434
            return null;
435
        }
436
        private List<List<string>> SetSymbol(LMADataSource dataSource, string rep, double x, double y, int count)
437
        {
438
            LMSymbol _LMSymbol = dataSource.GetSymbol(rep);
439
            List<List<string>> result = new List<List<string>>();
440
            List<string> oldIDs = new List<string>() { rep };
441
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
442
            {
443
                if (connector.get_ItemStatus() != "Active")
444
                    continue;
445
446
                string repID = connector.AsLMRepresentation().Id;
447
                string status = connector.get_ItemStatus();
448
                if (status == "Active" && !oldIDs.Contains(repID))
449
                {
450
                    List<string> symbols = new List<string>();
451
                    oldIDs.Add(repID);
452
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
453
                    result.Add(symbols);
454
                }
455
            }
456
457
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
458
            {
459
                if (connector.get_ItemStatus() != "Active")
460
                    continue;
461
462
                string repID = connector.AsLMRepresentation().Id;
463
                string status = connector.get_ItemStatus();
464
                if (status == "Active" && !oldIDs.Contains(repID))
465
                {
466
                    List<string> symbols = new List<string>();
467
                    oldIDs.Add(repID);
468
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
469
                    result.Add(symbols);
470
                }
471
            }
472
473
            ReleaseCOMObjects(_LMSymbol);
474
            return result;
475
        }
476
        private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMConnector connector, double x, double y, int count)
477
        {
478
            if (symbols.Count >= count)
479
                return;
480
481
            if (connector.ConnectItem1SymbolObject != null && !oldIDs.Contains(connector.ConnectItem1SymbolObject.AsLMRepresentation().Id))
482
            {
483
                string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
484
                oldIDs.Add(repID);
485
                if (connector.ConnectItem1SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
486
                {
487
                    double sX = connector.ConnectItem1SymbolObject.get_XCoordinate(), sY = connector.ConnectItem1SymbolObject.get_YCoordinate(); ;
488
                    SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1);
489
                    if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL)
490
                        symbols.Add(repID);
491
                }
492
493
                loop(dataSource, oldIDs, symbols, connector.ConnectItem1SymbolObject, x, y, count);
494
            }
495
496
            if (symbols.Count >= count)
497
                return;
498
499
            if (connector.ConnectItem2SymbolObject != null && !oldIDs.Contains(connector.ConnectItem2SymbolObject.AsLMRepresentation().Id))
500
            {
501
                string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
502
                oldIDs.Add(repID);
503
                if (connector.ConnectItem2SymbolObject.get_RepresentationType() != "Branch" && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
504
                {
505
                    double sX = connector.ConnectItem2SymbolObject.get_XCoordinate(), sY = connector.ConnectItem2SymbolObject.get_YCoordinate(); ;
506
                    SlopeType slopeType = SPPIDUtil.CalcSlope(x, y, sX, sY, 1);
507
                    if (slopeType == SlopeType.HORIZONTAL || slopeType == SlopeType.VERTICAL)
508
                        symbols.Add(repID);
509
                }
510
511
                loop(dataSource, oldIDs, symbols, connector.ConnectItem2SymbolObject, x, y, count);
512
            }
513
        }
514
        private void loop(LMADataSource dataSource, List<string> oldIDs, List<string> symbols, LMSymbol _LMSymbol, double x, double y, int count)
515
        {
516
            if (symbols.Count >= count)
517
                return;
518
519
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
520
            {
521
                if (connector.get_ItemStatus() != "Active")
522
                    continue;
523
524
                string repID = connector.AsLMRepresentation().Id;
525
                string status = connector.get_ItemStatus();
526
                if (status == "Active" && !oldIDs.Contains(repID))
527
                {
528
                    oldIDs.Add(repID);
529
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
530
                }
531
            }
532 82c7f66d gaqhf
533 c3e8fa8e gaqhf
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
534
            {
535
                if (connector.get_ItemStatus() != "Active")
536
                    continue;
537
538
                string repID = connector.AsLMRepresentation().Id;
539
                string status = connector.get_ItemStatus();
540
                if (status == "Active" && !oldIDs.Contains(repID))
541
                {
542
                    oldIDs.Add(repID);
543
                    loop(dataSource, oldIDs, symbols, connector, x, y, count);
544
                }
545
            }
546
        }
547
        private Symbol2d GetSymbol2DByRepID(LMADataSource dataSource, string repID)
548
        {
549
            LMSymbol _LMSymbol = dataSource.GetSymbol(repID);
550
            Symbol2d symbol2D = application.ActiveDocument.ActiveSheet.DrawingObjects[_LMSymbol.get_GraphicOID().ToString()];
551
            ReleaseCOMObjects(_LMSymbol);
552
            return symbol2D;
553 82c7f66d gaqhf
        }
554 c3e8fa8e gaqhf
        private void MovePoint2d(LMADataSource datasource, string repID, SymmetryArrow arrow, double moveX, double moveY)
555
        {
556
            LMSymbol _LMSymbol = datasource.GetSymbol(repID);
557
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
558
            {
559
                if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()))
560
                {
561
                    if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
562
                    {
563
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()];
564
                        point.X += moveX;
565
                        point.Y += moveY;
566
                    }
567
                    else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
568
                    {
569
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()];
570
                        point.X += moveX;
571
                        point.Y += moveY;
572
                    }
573
                }
574
            }
575
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
576
            {
577
                if (connector.get_ItemStatus() == "Active" && Convert.ToBoolean(connector.get_IsZeroLength()))
578
                {
579
                    if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
580
                    {
581
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem1SymbolObject.get_GraphicOID().ToString()];
582
                        point.X += moveX;
583
                        point.Y += moveY;
584
                    }
585
                    else if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
586
                    {
587
                        Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[connector.ConnectItem2SymbolObject.get_GraphicOID().ToString()];
588
                        point.X += moveX;
589
                        point.Y += moveY;
590
                    }
591
                }
592
            }
593
            ReleaseCOMObjects(_LMSymbol);
594
        }
595
596
        private List<Point2d> FindAllPoint2d(LMADataSource dataSource, string repID, string nextRepID)
597
        {
598
            LMSymbol _LMSymbol = dataSource.GetSymbol(repID);
599
            List<string> endIDs = new List<string>() { repID };
600
            List<string> graphicOIDs = new List<string>();
601
            List<Point2d> result = new List<Point2d>();
602
            FindPointsLoop(dataSource, _LMSymbol, endIDs, nextRepID, graphicOIDs);
603
            ReleaseCOMObjects(_LMSymbol);
604
            foreach (var item in graphicOIDs)
605
            {
606
                Point2d point = application.ActiveDocument.ActiveSheet.DrawingObjects[item] as Point2d;
607
                result.Add(point);
608
            }
609
            
610
            return result;
611
        }
612
613
        private bool FindPointsLoop(LMADataSource dataSource, LMSymbol _LMSymbol, List<string> endIDs, string targetRepID, List<string> graphicOIDs)
614
        {
615
            foreach (LMConnector connector in _LMSymbol.Connect1Connectors)
616
            {
617
                if (connector.get_ItemStatus() != "Active")
618
                    continue;
619
620
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
621
                {
622
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
623
                    if (!endIDs.Contains(repID))
624
                    {
625
                        endIDs.Add(repID);
626
                        if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
627
                        {
628
                            if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs))
629
                            {
630
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
631
                                    graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString());
632
                                return true;
633
                            }
634
                        }
635
                        else if (targetRepID == repID)
636
                        {
637
                            return true;
638
                        }
639
                    }
640
                }
641
                if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
642
                {
643
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
644
                    if (!endIDs.Contains(repID))
645
                    {
646
                        endIDs.Add(repID);
647
                        if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
648
                        {
649
                            if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs))
650
                            {
651
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
652
                                    graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString());
653
                                return true;
654
                            }
655
                        }
656
                        else if (targetRepID == repID)
657
                        {
658
                            return true;
659
                        }
660
                    }
661
                }
662
            }
663
            foreach (LMConnector connector in _LMSymbol.Connect2Connectors)
664
            {
665
                if (connector.get_ItemStatus() != "Active")
666
                    continue;
667
668
                if (connector.ConnectItem1SymbolObject != null && connector.ConnectItem1SymbolObject.get_ItemStatus() == "Active")
669
                {
670
                    string repID = connector.ConnectItem1SymbolObject.AsLMRepresentation().Id;
671
                    if (!endIDs.Contains(repID))
672
                    {
673
                        endIDs.Add(repID);
674
                        if (connector.ConnectItem1SymbolObject.get_RepresentationType() == "Branch")
675
                        {
676
                            if (FindPointsLoop(dataSource, connector.ConnectItem1SymbolObject, endIDs, targetRepID, graphicOIDs))
677
                            {
678
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
679
                                    graphicOIDs.Add(connector.ConnectItem1SymbolObject.get_GraphicOID().ToString());
680
                                return true;
681
                            }
682
                        }
683
                        else if (targetRepID == repID)
684
                        {
685
                            return true;
686
                        }
687
                    }
688
                }
689
                if (connector.ConnectItem2SymbolObject != null && connector.ConnectItem2SymbolObject.get_ItemStatus() == "Active")
690
                {
691
                    string repID = connector.ConnectItem2SymbolObject.AsLMRepresentation().Id;
692
                    if (!endIDs.Contains(repID))
693
                    {
694
                        endIDs.Add(repID);
695
                        if (connector.ConnectItem2SymbolObject.get_RepresentationType() == "Branch")
696
                        {
697
                            if (FindPointsLoop(dataSource, connector.ConnectItem2SymbolObject, endIDs, targetRepID, graphicOIDs))
698
                            {
699
                                if (!Convert.ToBoolean(connector.get_IsZeroLength()))
700
                                    graphicOIDs.Add(connector.ConnectItem2SymbolObject.get_GraphicOID().ToString());
701
                                return true;
702
                            }
703
                        }
704
                        else if (targetRepID == repID)
705
                        {
706
                            return true;
707
                        }
708
                    }
709
                }
710
            }
711
712
            return false;
713
        }
714
715
716
717 1b09fe17 gaqhf
        #region Hot Key
718 70b0b5d7 gaqhf
        [System.Runtime.InteropServices.DllImport("user32.dll")]
719
        private static extern bool RegisterHotKey(IntPtr hWnd, int id, int fsModifiers, int vk);
720
        [System.Runtime.InteropServices.DllImport("user32.dll")]
721
        private static extern bool UnregisterHotKey(IntPtr hWnd, int id);
722
        enum KeyModifier
723
        {
724
            None = 0,
725
            Alt = 1,
726
            Control = 2,
727
            Shift = 4,
728
            WinKey = 8
729
        }
730
        protected override void WndProc(ref Message m)
731
        {
732
            base.WndProc(ref m);
733
            if (m.Msg == 0x0312)
734
            {
735
                Keys key = (Keys)(((int)m.LParam >> 16) & 0xFFFF);
736
                KeyModifier modifier = (KeyModifier)((int)m.LParam & 0xFFFF);
737
                int id = m.WParam.ToInt32();
738
                application.RunCommand(CommandConstants.igcmdGridSnap);
739
            }
740
741
        }
742 1b09fe17 gaqhf
        #endregion
743 82c7f66d gaqhf
        #endregion
744 70b0b5d7 gaqhf
745 1b09fe17 gaqhf
        #region TEST
746 f14b4e3b gaqhf
747 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
748
        {
749 b7b123ba gaqhf
            Placement placement = new Placement();
750
            if (application.ActiveSelectSet.Count > 0)
751 d9fc7084 gaqhf
            {
752 b7b123ba gaqhf
                string modelItemId = null;
753
                Symbol2d symbol2D = application.ActiveSelectSet[0] as Symbol2d;
754
                DependencyObject dependency = application.ActiveSelectSet[0] as DependencyObject;
755
                application.ActiveSelectSet.RemoveAll();
756
                if (symbol2D != null)
757 d9fc7084 gaqhf
                {
758 b7b123ba gaqhf
                    return;
759
                    foreach (var attributes in symbol2D.AttributeSets)
760 90662b0b gaqhf
                    {
761 b7b123ba gaqhf
                        foreach (var attribute in attributes)
762
                        {
763
                            if (attribute.Name == "ModelID")
764
                                modelItemId = attribute.GetValue().ToString();
765
                        }
766 90662b0b gaqhf
                    }
767
768 b7b123ba gaqhf
                    if (modelItemId!=null)
769
                    {
770 e0828ff4 gaqhf
                        LMADataSource dataSource = new LMADataSource();
771 b7b123ba gaqhf
                        LMModelItem modelItem = dataSource.GetModelItem(modelItemId);
772
                        foreach (LMRepresentation item in modelItem.Representations)
773
                        {
774
                            if (item.ModelItemID == modelItemId)
775
                            {
776
                                dataSource = placement.PIDDataSource;
777
                                LMSymbol symbol = dataSource.GetSymbol(item.Id);
778
                                double oldx = symbol.get_XCoordinate();
779
                                double oldy = symbol.get_YCoordinate();
780
                                symbol2D.Move(0, 0, 0, GridSetting.GetInstance().Length);
781
782
                                dataSource = new LMADataSource();
783
                                //dataSource = placement.PIDDataSource;
784
                                symbol = dataSource.GetSymbol(item.Id);
785
                                double x = symbol.get_XCoordinate();
786
                                double y = symbol.get_YCoordinate();
787
                            }
788
                        }
789
                    }
790 4e865771 gaqhf
                }
791 b7b123ba gaqhf
                else if (dependency != null)
792 4e865771 gaqhf
                {
793 b7b123ba gaqhf
                    foreach (dynamic item in dependency.DrawingObjects)
794
                    {
795
                        item.Move(0, 0, 0, GridSetting.GetInstance().Length);
796
                    }
797 d9fc7084 gaqhf
                }
798
            }
799 4e865771 gaqhf
800 154d8f43 gaqhf
            return;
801 4941f5fe gaqhf
            Thread outThread = new Thread(func2 =>
802
            {
803
                for (int i = 100; i < 120; i++)
804
                {
805
                    Thread thread = new Thread(func =>
806
                    {
807
                        dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
808
                        //WrapperApplication wApp = new WrapperApplication(application.Application);
809
                        //Ingr.RAD2D.Application radApp = wApp.RADApplication;
810
                        dynamic drawing = application.Drawings.Add("Unit1", "D-Size.pid", i.ToString(), i.ToString());//application.Drawings.OpenDrawing("123");
811
812
                        Thread.Sleep(5000);
813
814
                        drawing.CloseDrawing(true);
815
816
                        //application.Quit();
817
                        ReleaseCOMObjects(application);
818
                        application = null;
819
                        ReleaseCOMObjects(drawing);
820
                        drawing = null;
821
                        Thread.Sleep(5000);
822
                    });
823
                    thread.Start();
824
                    thread.Join();
825
                }
826
            });
827
            outThread.Start();
828
            
829
            
830
831 32205389 gaqhf
832 ca6e0f51 gaqhf
833 4941f5fe gaqhf
            //radApp.Documents.Add(@"\\server70\DEVDOF1Site\GS\PLANT\PLANT1\Unit1\11111.pid");
834
835
            //radApp.ActiveDocument.Close(true);
836
            //drawing.CloseDrawing(true);
837
838
            //ReleaseCOMObjects(application);
839
            //ReleaseCOMObjects(drawing);
840
            //application = null;
841
            //wApp = null;
842
            //radApp = null;
843
            //drawing = null;
844 ca6e0f51 gaqhf
        }
845 4941f5fe gaqhf
846 ca6e0f51 gaqhf
        private void AutoJoinPipeRun()
847
        {
848 d4c3e39f gaqhf
            dynamic application = Interaction.GetObject("", "PIDAutomation.Application");
849
            WrapperApplication wApp = new WrapperApplication(application.Application);
850
            Ingr.RAD2D.Application radApp = wApp.RADApplication;
851
852 ca6e0f51 gaqhf
            string modelItemId = null;
853
            List<double[]> vertices = new List<double[]>();
854 a31a512e gaqhf
            if (radApp.ActiveSelectSet.Count == 0)
855
            {
856
                return;
857
            }
858 ca6e0f51 gaqhf
            dynamic OID = radApp.ActiveSelectSet[0].Key();
859
            DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
860
            foreach (var attributes in drawingObject.AttributeSets)
861 4ba01591 gaqhf
            {
862 ca6e0f51 gaqhf
                foreach (var attribute in attributes)
863 4ba01591 gaqhf
                {
864 ca6e0f51 gaqhf
                    if (attribute.Name == "ModelID")
865
                        modelItemId = attribute.GetValue().ToString();
866
                }
867
            }
868
            radApp.ActiveSelectSet.RemoveAll();
869 32205389 gaqhf
870 7e4a64a3 gaqhf
        }
871
        #endregion
872
873 7aee331b gaqhf
874 9628f54b gaqhf
        [DllImport("user32.dll")]
875
        public static extern int FindWindow(string lpClassName, string lpWindowName);
876 3734dcc5 gaqhf
877
        [DllImport("user32.dll", SetLastError = true)]
878
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
879
880 b427ebf9 humkyung
        private void ConverterDocking_Load(object sender, EventArgs e)
881
        {
882
#if DEBUG
883
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Always;
884
#else
885
            this.layoutControlItem2.Visibility = DevExpress.XtraLayout.Utils.LayoutVisibility.Never;
886
#endif
887
888
        }
889 0db80f26 gaqhf
890
        
891 65881d60 gaqhf
    }
892
}
클립보드 이미지 추가 (최대 크기: 500 MB)