프로젝트

일반

사용자정보

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

hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ f9cc5190

이력 | 보기 | 이력해설 | 다운로드 (11.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 65881d60 gaqhf
26
namespace Converter.SPPID.Wrapper
27
{
28
    public partial class ConverterDocking : UserControl
29
    {
30 e3e2d41f gaqhf
        Ingr.RAD2D.Application radApp;
31 d19ae675 gaqhf
        dynamic application;
32 65881d60 gaqhf
        public ConverterDocking()
33
        {
34
            InitializeComponent();
35 d19ae675 gaqhf
            application = Interaction.GetObject("", "PIDAutomation.Application");
36 e3e2d41f gaqhf
            WrapperApplication wApp = new WrapperApplication(application.Application);
37
            radApp = wApp.RADApplication;
38 1ba9c671 gaqhf
39 6a7573b0 gaqhf
            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 1ba9c671 gaqhf
#if DEBUG
53
            simpleButton1.Visible = true;
54 51ae61b9 gaqhf
55 4fb0f8d5 gaqhf
            
56 1ba9c671 gaqhf
#endif
57 65881d60 gaqhf
        }
58
59 e3e2d41f gaqhf
        private void btnConverter_Click(object sender, EventArgs e)
60 65881d60 gaqhf
        {
61 1ba9c671 gaqhf
            ConverterForm converterForm = new ConverterForm();
62
            if (converterForm.ShowDialog() == DialogResult.OK)
63 65881d60 gaqhf
            {
64 1ba9c671 gaqhf
                try
65
                {
66
                    CloseOPCForm.Run();
67 ca214bc3 gaqhf
68 d5ec4d0f gaqhf
                    for (int i = 0; i < converterForm.Documents.Count; i++)
69 1ba9c671 gaqhf
                    {
70 d5ec4d0f gaqhf
                        SPPID_Document document = converterForm.Documents[i];
71 1ba9c671 gaqhf
                        if (document.SetSPPIDMapping() && document.Enable)
72
                        {
73
                            AutoModeling modeling = new AutoModeling(document, application, radApp);
74 d5ec4d0f gaqhf
                            modeling.DocumentLabelText = string.Format("Drawing Name : {0} ({1}/{2})", document.DrawingName, i + 1, converterForm.Documents.Count);
75 1ba9c671 gaqhf
                            modeling.Run();
76
                        }
77
                    }
78
                }
79
                catch (Exception ex)
80
                {
81
                    MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
82
                }
83
                finally
84 d19ae675 gaqhf
                {
85 1ba9c671 gaqhf
                    CloseOPCForm.Stop();
86
                }
87
88
                MessageBox.Show(Msg.EndConvert, Msg.Information, MessageBoxButtons.OK, MessageBoxIcon.Information);
89
            }
90
        }
91
92 69b7387a gaqhf
        private void btnLinkOPC_Click(object sender, EventArgs e)
93
        {
94 4fb0f8d5 gaqhf
            LMADataSource dataSource = new LMADataSource();
95
            LMDrawings drawings = new LMDrawings();
96
97 88bac50c gaqhf
            //try
98 69b7387a gaqhf
            {
99 4fb0f8d5 gaqhf
                Project_Info _ProjectInfo = Project_Info.GetInstance();
100
                _ProjectInfo.DefaultPath = Settings.Default.LatestProjectPath;
101
                if (Project_DB.ConnTestAndCreateTable())
102
                {
103 224535bb gaqhf
                    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 69b7387a gaqhf
114 224535bb gaqhf
                        DataTable drawingTable = Project_DB.SelectDrawingInfo();
115
                        drawingTable.Columns.Add("EXIST", typeof(bool));
116
                        drawingTable.Columns.Add("SPPIDPATH", typeof(string));
117 e8536f2b gaqhf
118 224535bb gaqhf
                        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 69b7387a gaqhf
129 1ed39474 gaqhf
                        List<SPPID_Document> allDocuments = new List<SPPID_Document>();
130 224535bb gaqhf
                        foreach (DataRow row in drawingTable.Rows)
131 88bac50c gaqhf
                            allDocuments.Add((SPPID_Document)row["DOCUMENT"]);
132 1ed39474 gaqhf
133 88bac50c gaqhf
                        AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp);
134 1ed39474 gaqhf
                        opc.Run();
135 224535bb gaqhf
                    }
136 4fb0f8d5 gaqhf
                }
137
                else
138
                {
139
                    MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
140
                }
141 69b7387a gaqhf
            }
142 88bac50c gaqhf
            //catch (Exception ex)
143 69b7387a gaqhf
            {
144 88bac50c gaqhf
                //MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace);
145 69b7387a gaqhf
            }
146 88bac50c gaqhf
            //finally
147 4fb0f8d5 gaqhf
            {
148
                ReleaseCOMObjects(dataSource);
149
                ReleaseCOMObjects(drawings);
150
            }
151 69b7387a gaqhf
        }
152
153 4fb0f8d5 gaqhf
        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 6a7573b0 gaqhf
        private void btnGetDrawingSize_Click(object sender, EventArgs e)
164 1ba9c671 gaqhf
        {
165 6a7573b0 gaqhf
            if (radApp.ActiveSelectSet.Count > 0)
166 65881d60 gaqhf
            {
167 6a7573b0 gaqhf
                DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject;
168
                if (line2D != null)
169 1ba9c671 gaqhf
                {
170 6a7573b0 gaqhf
                    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 1ba9c671 gaqhf
                }
183 6a7573b0 gaqhf
                else
184
                    MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
185 65881d60 gaqhf
            }
186 6a7573b0 gaqhf
            else
187
                MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning);
188
        }
189 63fbf592 gaqhf
        bool first = true;
190
        LMDrawing currentDrawing;
191 6a7573b0 gaqhf
        private void simpleButton1_Click(object sender, EventArgs e)
192
        {
193 7aee331b gaqhf
            Placement _placement = new Placement();
194
            LMADataSource dataSource = _placement.PIDDataSource;//placement.PIDDataSource;
195 32205389 gaqhf
196
            LMModelItem modelitem = dataSource.GetModelItem("F462457D634C401B9D9FB425A2AC88EA");
197
            foreach (LMRepresentation item in modelitem.Representations)
198 4ba01591 gaqhf
            {
199 32205389 gaqhf
                LMSymbol symbol = dataSource.GetSymbol(item.Id);
200
                foreach (LMRelationship relationship in symbol.Relation1Relationships)
201 4ba01591 gaqhf
                {
202 32205389 gaqhf
                    if (relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.Id != symbol.Id)
203 4ba01591 gaqhf
                    {
204 32205389 gaqhf
205 4ba01591 gaqhf
                    }
206 32205389 gaqhf
                    else if (relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.Id != symbol.Id)
207
                    {
208 63fbf592 gaqhf
209 32205389 gaqhf
                    }
210
                }
211
                foreach (LMRelationship relationship in symbol.Relation2Relationships)
212 1ff0105e gaqhf
                {
213 32205389 gaqhf
                    if (relationship.Item1RepresentationObject != null && relationship.Item1RepresentationObject.Id != symbol.Id)
214 1ff0105e gaqhf
                    {
215
216
                    }
217 32205389 gaqhf
                    else if (relationship.Item2RepresentationObject != null && relationship.Item2RepresentationObject.Id != symbol.Id)
218
                    {
219 1ff0105e gaqhf
220 32205389 gaqhf
                    }
221 1ff0105e gaqhf
                }
222
            }
223 32205389 gaqhf
            
224
            
225
            //LMConnector connector = GetLMConnectorOnlyOne("E12B6DC30C224B51911F2AFFEFB8ED14");
226
            //if (connector != null)
227
            //{
228
            //    string mappingPath = @"\Piping\Labels - Piping Segments\Flow Direction.sym";
229
            //    List<double[]> vertices = GetConnectorVertices();
230
            //    vertices = vertices.FindAll(x => x[0] > 0 && x[1] > 0);
231
            //    double[] point = vertices[vertices.Count - 1];
232
            //    double[] temp = vertices[vertices.Count - 2];
233
            //    double angle = SPPIDUtil.CalcAngle(point[0], point[1], temp[0], temp[1]);
234
            //    Array array = new double[] { 0, point[0], point[1] };
235
            //    LMLabelPersist _LMLabelPersist = _placement.PIDPlaceLabel(mappingPath, ref array, LabeledItem: connector.AsLMRepresentation());
236
            //    if (_LMLabelPersist != null)
237
            //        ReleaseCOMObjects(_LMLabelPersist);
238
            //}
239 63fbf592 gaqhf
240 32205389 gaqhf
            //LMConnector GetLMConnectorOnlyOne(string modelItemID)
241 63fbf592 gaqhf
            //{
242 32205389 gaqhf
            //    LMConnector result = null;
243
            //    List<LMConnector> connectors = new List<LMConnector>();
244
            //    LMModelItem modelItem = dataSource.GetModelItem(modelItemID);
245
246
            //    if (modelItem != null)
247 63fbf592 gaqhf
            //    {
248 32205389 gaqhf
            //        foreach (LMRepresentation rep in modelItem.Representations)
249 63fbf592 gaqhf
            //        {
250 32205389 gaqhf
            //            if (rep.Attributes["RepresentationType"].get_Value() == "Connector" && rep.Attributes["ItemStatus"].get_Value() == "Active")
251
            //                connectors.Add(dataSource.GetConnector(rep.Id));
252 63fbf592 gaqhf
            //        }
253 32205389 gaqhf
254
            //        ReleaseCOMObjects(modelItem);
255 63fbf592 gaqhf
            //    }
256 a0e3dca4 gaqhf
257 32205389 gaqhf
            //    if (connectors.Count == 1)
258
            //        result = connectors[0];
259
            //    else
260
            //        foreach (var item in connectors)
261
            //            ReleaseCOMObjects(item);
262
263
            //    return result;
264 7aee331b gaqhf
            //}
265 32205389 gaqhf
266
            //List<double[]> GetConnectorVertices()
267 7aee331b gaqhf
            //{
268 32205389 gaqhf
            //    List<double[]> vertices = new List<double[]>();
269
            //    dynamic OID = radApp.ActiveSelectSet[0].Key();
270
            //    DependencyObject drawingObject = radApp.ActiveDocument.ActiveSheet.DrawingObjects[OID];
271
            //    Ingr.RAD2D.LineStringGeometry2d lineStringGeometry = drawingObject.GetGeometry() as Ingr.RAD2D.LineStringGeometry2d;
272
            //    int verticesCount = lineStringGeometry.VertexCount;
273
            //    double[] value = null;
274
            //    lineStringGeometry.GetVertices(ref verticesCount, ref value);
275
            //    for (int i = 0; i < verticesCount; i++)
276
            //    {
277
            //        double x = 0;
278
            //        double y = 0;
279
            //        lineStringGeometry.GetVertex(i + 1, ref x, ref y);
280
            //        vertices.Add(new double[] { x, y });
281
            //    }
282
            //    return vertices;
283 7aee331b gaqhf
            //}
284 65881d60 gaqhf
        }
285 7aee331b gaqhf
286 9628f54b gaqhf
        [DllImport("user32.dll")]
287
        public static extern int FindWindow(string lpClassName, string lpWindowName);
288 3734dcc5 gaqhf
289
        [DllImport("user32.dll", SetLastError = true)]
290
        static extern int GetWindowThreadProcessId(IntPtr hWnd, out int processId);
291
292 65881d60 gaqhf
    }
293
}
클립보드 이미지 추가 (최대 크기: 500 MB)