hytos / DTI_PID / SPPIDConverter / ConverterDocking.cs @ fc0a8c33
이력 | 보기 | 이력해설 | 다운로드 (8.05 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 | 65881d60 | gaqhf | |
25 | namespace Converter.SPPID.Wrapper |
||
26 | { |
||
27 | public partial class ConverterDocking : UserControl |
||
28 | { |
||
29 | e3e2d41f | gaqhf | Ingr.RAD2D.Application radApp; |
30 | d19ae675 | gaqhf | dynamic application; |
31 | 65881d60 | gaqhf | public ConverterDocking() |
32 | { |
||
33 | InitializeComponent(); |
||
34 | d19ae675 | gaqhf | application = Interaction.GetObject("", "PIDAutomation.Application"); |
35 | e3e2d41f | gaqhf | WrapperApplication wApp = new WrapperApplication(application.Application); |
36 | radApp = wApp.RADApplication; |
||
37 | 1ba9c671 | gaqhf | |
38 | 6a7573b0 | gaqhf | try |
39 | { |
||
40 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
41 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
42 | } |
||
43 | catch (Exception ex) |
||
44 | { |
||
45 | StringBuilder sb = new StringBuilder(); |
||
46 | sb.AppendLine(ex.Message); |
||
47 | sb.AppendLine(ex.StackTrace); |
||
48 | MessageBox.Show(sb.ToString()); |
||
49 | } |
||
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 | 69b7387a | gaqhf | try |
98 | { |
||
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 | { |
||
132 | SPPID_Document document = JsonConvert.DeserializeObject<SPPID_Document>(row["DOCUMENT"].ToString()); |
||
133 | 1ed39474 | gaqhf | allDocuments.Add(document); |
134 | 224535bb | gaqhf | } |
135 | 1ed39474 | gaqhf | |
136 | 71ba1ca3 | gaqhf | AutoModeling_OPC opc = new AutoModeling_OPC(allDocuments, application, radApp, drawingTable); |
137 | 1ed39474 | gaqhf | opc.Run(); |
138 | 224535bb | gaqhf | //dynamic doc = application.Drawings.OpenDrawing(drawingTable.Rows[0]["DRAWINGNAME"]); |
139 | e8536f2b | gaqhf | |
140 | 224535bb | gaqhf | //doc.CloseDrawing(true); |
141 | |||
142 | |||
143 | |||
144 | //radApp.Documents.Open(sPPID_DBInfo.PlantPath + @"\" + drawingTable.Rows[0]["SPPIDPATH"].ToString()); |
||
145 | } |
||
146 | 4fb0f8d5 | gaqhf | } |
147 | else |
||
148 | { |
||
149 | MessageBox.Show(Msg.ConnectionFail, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
150 | } |
||
151 | 69b7387a | gaqhf | } |
152 | catch (Exception ex) |
||
153 | { |
||
154 | MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); |
||
155 | } |
||
156 | 4fb0f8d5 | gaqhf | finally |
157 | { |
||
158 | ReleaseCOMObjects(dataSource); |
||
159 | ReleaseCOMObjects(drawings); |
||
160 | } |
||
161 | 69b7387a | gaqhf | } |
162 | |||
163 | 4fb0f8d5 | gaqhf | public void ReleaseCOMObjects(params object[] objVars) |
164 | { |
||
165 | int intNewRefCount = 0; |
||
166 | foreach (object obj in objVars) |
||
167 | { |
||
168 | if (!Information.IsNothing(obj) && System.Runtime.InteropServices.Marshal.IsComObject(obj)) |
||
169 | intNewRefCount = intNewRefCount + System.Runtime.InteropServices.Marshal.FinalReleaseComObject(obj); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | |||
174 | 6a7573b0 | gaqhf | private void btnGetDrawingSize_Click(object sender, EventArgs e) |
175 | 1ba9c671 | gaqhf | { |
176 | 6a7573b0 | gaqhf | if (radApp.ActiveSelectSet.Count > 0) |
177 | 65881d60 | gaqhf | { |
178 | 6a7573b0 | gaqhf | DependencyObject line2D = radApp.ActiveSelectSet[0] as DependencyObject; |
179 | if (line2D != null) |
||
180 | 1ba9c671 | gaqhf | { |
181 | 6a7573b0 | gaqhf | double minX = 0; |
182 | double minY = 0; |
||
183 | double maxX = 0; |
||
184 | double maxY = 0; |
||
185 | line2D.Range(out minX, out minY, out maxX, out maxY); |
||
186 | |||
187 | Settings.Default.DrawingX = maxX - minX; |
||
188 | Settings.Default.DrawingY = maxY - minY; |
||
189 | Settings.Default.Save(); |
||
190 | |||
191 | textEditDrawingX.EditValue = Settings.Default.DrawingX; |
||
192 | textEditDrawingY.EditValue = Settings.Default.DrawingY; |
||
193 | 1ba9c671 | gaqhf | } |
194 | 6a7573b0 | gaqhf | else |
195 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
196 | 65881d60 | gaqhf | } |
197 | 6a7573b0 | gaqhf | else |
198 | MessageBox.Show(Msg.SelectLine, Msg.Warning, MessageBoxButtons.OK, MessageBoxIcon.Warning); |
||
199 | } |
||
200 | |||
201 | 02480ac1 | gaqhf | static Command command; |
202 | int CmdID; |
||
203 | string CmdCLSID; |
||
204 | bool isActiveInPlace; |
||
205 | CommandTypeConstants CommandTypeConstants; |
||
206 | string argList; |
||
207 | string DLLName; |
||
208 | string HelpFile; |
||
209 | |||
210 | 6a7573b0 | gaqhf | private void simpleButton1_Click(object sender, EventArgs e) |
211 | { |
||
212 | 1ab9a205 | gaqhf | Placement _placement = new Placement(); |
213 | 6a7573b0 | gaqhf | LMADataSource dataSource = new LMADataSource();//placement.PIDDataSource; |
214 | |||
215 | 1ed39474 | gaqhf | LMConnector connector = dataSource.GetConnector(""); |
216 | |||
217 | LMSymbol symbol1 = connector.ConnectItem1SymbolObject; |
||
218 | LMSymbol symbol2 = connector.ConnectItem2SymbolObject; |
||
219 | 224535bb | gaqhf | |
220 | 65881d60 | gaqhf | } |
221 | 6a7573b0 | gaqhf | |
222 | |||
223 | 65881d60 | gaqhf | } |
224 | } |