프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ 7e4a64a3

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

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

    
26
namespace Converter.SPPID.Wrapper
27
{
28
    public partial class ConverterDocking : UserControl
29
    {
30
        Ingr.RAD2D.Application radApp;
31
        dynamic application;
32
        public ConverterDocking()
33
        {
34
            InitializeComponent();
35
            application = Interaction.GetObject("", "PIDAutomation.Application");
36
            WrapperApplication wApp = new WrapperApplication(application.Application);
37
            radApp = wApp.RADApplication;
38

    
39
            try
40
            {
41
                textEditDrawingX.EditValue = Settings.Default.DrawingX;
42
                textEditDrawingY.EditValue = Settings.Default.DrawingY;
43
            }
44
            catch (Exception ex)
45
            {
46
                StringBuilder sb = new StringBuilder();
47
                sb.AppendLine(ex.Message);
48
                sb.AppendLine(ex.StackTrace);
49
                MessageBox.Show(sb.ToString());
50
            }
51

    
52
#if DEBUG
53
            simpleButton1.Visible = true;
54

    
55
            
56
#endif
57
        }
58

    
59
        private void btnConverter_Click(object sender, EventArgs e)
60
        {
61
            ConverterForm converterForm = new ConverterForm();
62
            if (converterForm.ShowDialog() == DialogResult.OK)
63
            {
64
                try
65
                {
66
                    CloseOPCForm.Run();
67

    
68
                    for (int i = 0; i < converterForm.Documents.Count; i++)
69
                    {
70
                        SPPID_Document document = converterForm.Documents[i];
71
                        if (document.SetSPPIDMapping() && document.Enable)
72
                        {
73
                            AutoModeling modeling = new AutoModeling(document, application, radApp);
74
                            modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
75
                            modeling.Run();
76
                        }
77
                    }
78
                }
79
                catch (Exception ex)
80
                {
81
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
82
                }
83
                finally
84
                {
85
                    CloseOPCForm.Stop();
86
                }
87

    
88
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
89
            }
90
        }
91

    
92
        private void btnLinkOPC_Click(object sender, EventArgs e)
93
        {
94
            LMADataSource dataSource = new LMADataSource();
95
            LMDrawings drawings = new LMDrawings();
96

    
97
            //try
98
            {
99
                Project_Info _ProjectInfo = Project_Info.GetInstance();
100
                _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
101
                if (Project_DB.ConnTestAndCreateTable())
102
                {
103
                    DataTable dt = Project_DB.SelectSPPID_DB_INFO();
104
                    if (dt.Columns.Count > 0 && dt.Rows.Count > 0)
105
                        SPPIDUtil.ConvertToSPPIDInfo(dt.Rows[0][0].ToString());
106
                    else
107
                        SPPID_DBInfo.Clear();
108

    
109
                    SPPID_DBInfo sPPID_DBInfo = SPPID_DBInfo.GetInstance();
110
                    if (sPPID_DBInfo.Enable)
111
                    {
112
                        drawings.Collect(dataSource);
113

    
114
                        DataTable drawingTable = Project_DB.SelectDrawingInfo();
115
                        drawingTable.Columns.Add("EXIST", typeof(bool));
116
                        drawingTable.Columns.Add("SPPIDPATH", typeof(string));
117

    
118
                        foreach (LMDrawing item in drawings)
119
                        {
120
                            DataRow[] rows = drawingTable.Select(string.Format("DRAWINGNUMBER = '{0}'", item.Attributes["DrawingNumber"].get_Value()));
121
                            foreach (DataRow row in rows)
122
                            {
123
                                row["EXIST"] = true;
124
                                row["DRAWINGNAME"] = item.Attributes["Name"].get_Value();
125
                                row["SPPIDPATH"] = item.get_Path();
126
                            }
127
                        }
128

    
129
                        List<SPPID_Document> allDocuments = new List<SPPID_Document>();
130
                        foreach (DataRow row in drawingTable.Rows)
131
                            allDocuments.Add((SPPID_Document)row["DOCUMENT"]);
132

    
133
                        AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp);
134
                        opc.Run();
135
                    }
136
                }
137
                else
138
                {
139
                    MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
140
                }
141
            }
142
            //catch (Exception ex)
143
            {
144
                //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
145
            }
146
            //finally
147
            {
148
                ReleaseCOMObjects(dataSource);
149
                ReleaseCOMObjects(drawings);
150
            }
151
        }
152

    
153
        public void ReleaseCOMObjects(params object[] objVars)
154
        {
155
            int intNewRefCount = 0;
156
            foreach (object obj in objVars)
157
            {
158
                if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj))
159
                    intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj);
160
            }
161
        }
162

    
163
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
164
        {
165
            if (radApp.ActiveSelectSet.Count > 0)
166
            {
167
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
168
                if (line2D != null)
169
                {
170
                    double minX = 0;
171
                    double minY = 0;
172
                    double maxX = 0;
173
                    double maxY = 0;
174
                    line2D.Range(out minX, out minY, out maxX, out maxY);
175

    
176
                    Settings.Default.DrawingX = maxX - minX;
177
                    Settings.Default.DrawingY = maxY - minY;
178
                    Settings.Default.Save();
179

    
180
                    textEditDrawingX.EditValue = Settings.Default.DrawingX;
181
                    textEditDrawingY.EditValue = Settings.Default.DrawingY;
182
                }
183
                else
184
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
185
            }
186
            else
187
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
188
        }
189

    
190
        #region TEST
191
        bool first = true;
192
        LMDrawing currentDrawing;
193
        private void simpleButton1_Click(object sender, EventArgs e)
194
        {
195
            Placement _placement = new Placement();
196
            LMADataSource dataSource = _placement.PIDDataSource;//placement.PIDDataSource;
197

    
198
            LMModelItem modelitem = dataSource.GetModelItem("F462457D634C401B9D9FB425A2AC88EA");
199
            foreach (LMRepresentation item in modelitem.Representations)
200
            {
201
                LMSymbol symbol = dataSource.GetSymbol(item.Id);
202
                foreach (LMRelationship relationship in symbol.Relation1Relationships)
203
                {
204
                    if (relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.Id != symbol.Id)
205
                    {
206

    
207
                    }
208
                    else if (relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.Id != symbol.Id)
209
                    {
210

    
211
                    }
212
                }
213
                foreach (LMRelationship relationship in symbol.Relation2Relationships)
214
                {
215
                    if (relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.Id != symbol.Id)
216
                    {
217

    
218
                    }
219
                    else if (relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.Id != symbol.Id)
220
                    {
221

    
222
                    }
223
                }
224
            }
225

    
226

    
227
            //LMConnector connector = GetLMConnectorOnlyOne("E12B6DC30C224B51911F2AFFEFB8ED14");
228
            //if (connector != null)
229
            //{
230
            //    string mappingPath = @"\Piping\Labels - Piping Segments\Flow Direction.sym";
231
            //    List<double[]> vertices = GetConnectorVertices();
232
            //    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
233
            //    double[] point = vertices[vertices.Count - 1];
234
            //    double[] temp = vertices[vertices.Count - 2];
235
            //    double angle = SPPIDUtil.CalcAngle(point[0], point[1], temp[0], temp[1]);
236
            //    Array array = new double[] { 0, point[0], point[1] };
237
            //    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
238
            //    if (_LMLabelPersist != null)
239
            //        ReleaseCOMObjects(_LMLabelPersist);
240
            //}
241

    
242
            //LMConnector GetLMConnectorOnlyOne(string modelItemID)
243
            //{
244
            //    LMConnector result = null;
245
            //    List<LMConnector> connectors = new List<LMConnector>();
246
            //    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
247

    
248
            //    if (modelItem != null)
249
            //    {
250
            //        foreach (LMRepresentation rep in modelItem.Representations)
251
            //        {
252
            //            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
253
            //                connectors.Add(dataSource.GetConnector(rep.Id));
254
            //        }
255

    
256
            //        ReleaseCOMObjects(modelItem);
257
            //    }
258

    
259
            //    if (connectors.Count == 1)
260
            //        result = connectors[0];
261
            //    else
262
            //        foreach (var item in connectors)
263
            //            ReleaseCOMObjects(item);
264

    
265
            //    return result;
266
            //}
267

    
268
            //List<double[]> GetConnectorVertices()
269
            //{
270
            //    List<double[]> vertices = new List<double[]>();
271
            //    dynamic OID = radApp.ActiveSelectSet[0].Key();
272
            //    DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
273
            //    Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
274
            //    int verticesCount = lineStringGeometry.VertexCount;
275
            //    double[] value = null;
276
            //    lineStringGeometry.GetVertices(ref verticesCount, ref value);
277
            //    for (int i = 0; i < verticesCount; i++)
278
            //    {
279
            //        double x = 0;
280
            //        double y = 0;
281
            //        lineStringGeometry.GetVertex(i + 1, ref x, ref y);
282
            //        vertices.Add(new double[] { x, y });
283
            //    }
284
            //    return vertices;
285
            //}
286
        }
287
        private void TESTLine()
288
        {
289
            Placement _placement = new Placement();
290
            LMADataSource dataSource = _placement.PIDDataSource;//placement.PIDDataSource;
291

    
292
            foreach (var attributes in radApp.ActiveSelectSet[0].AttributeSets)
293
            {
294
                foreach (var attribute in attributes)
295
                {
296
                    if (attribute.Name == "ModelID")
297
                    {
298
                        LMModelItem modelItem = dataSource.GetModelItem(attribute.GetValue().ToString());
299
                        foreach (LMRepresentation representation  in modelItem.Representations)
300
                        {
301
                            //representa
302
                        }
303
                    }
304
                }
305
            }
306
        }
307
        #endregion
308

    
309

    
310
        [DllImport("user32.dll")]
311
        public static extern int FindWindow(string lpClassName, string lpWindowName);
312

    
313
        [DllImport("user32.dll", SetLastError = true)]
314
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
315

    
316
    }
317
}
클립보드 이미지 추가 (최대 크기: 500 MB)