hytos / DTI_PID / SPPIDConverter_CustomCommand / ConverterForm.cs @ 7da8145f
이력 | 보기 | 이력해설 | 다운로드 (11.8 KB)
1 | d57a5303 | gaqhf | /*---------------------------------------------------------------------+\ |
---|---|---|---|
2 | | | |
||
3 | | Copyright 2016 Intergraph Corporation | |
||
4 | | All Rights Reserved | |
||
5 | | | |
||
6 | | Including software, file formats, and audio-visual displays; | |
||
7 | | may only be used pursuant to applicable software license | |
||
8 | | agreement; contains confidential and proprietary information of| |
||
9 | | Intergraph and/or third parties which is protected by copyright| |
||
10 | | and trade secret law and may not be provided or otherwise made | |
||
11 | | available without proper authorization. | |
||
12 | | | |
||
13 | | Unpublished -- rights reserved under the Copyright Laws of the | |
||
14 | | United States. | |
||
15 | | | |
||
16 | | Intergraph Corporation | |
||
17 | | Huntsville, Alabama 35894-0001 | |
||
18 | | | |
||
19 | \+---------------------------------------------------------------------*/ |
||
20 | |||
21 | using System; |
||
22 | using System.Windows.Forms; |
||
23 | using Ingr.RAD2D; |
||
24 | 022cae08 | gaqhf | using System.Runtime.InteropServices; |
25 | using System.Drawing; |
||
26 | d57a5303 | gaqhf | using SPPID.Modeling; |
27 | using SPPID.Utill; |
||
28 | using SPPID.Model; |
||
29 | |||
30 | namespace CustomCommand |
||
31 | { |
||
32 | /// <summary> |
||
33 | /// This is the primary form. The form is shown as modal. |
||
34 | /// This command may be built as an executable (EXE) or as a dynamic link |
||
35 | /// library (DLL). |
||
36 | /// |
||
37 | /// When you implement the code that dismisses your form, e.g., an OK |
||
38 | /// button or a Stop Processing button, you should include the following: |
||
39 | /// |
||
40 | /// Hide the form, for example |
||
41 | /// converterForm.Hide |
||
42 | /// |
||
43 | /// Set the Application's Interactive property to True, for example |
||
44 | /// commandControl.Application.Interactive = True |
||
45 | /// |
||
46 | /// Set Intergraph Command Control Done property to True, for example |
||
47 | /// commandControl.Done = True |
||
48 | /// </summary> |
||
49 | public partial class ConverterForm : Form |
||
50 | { |
||
51 | #region Default CustomCommand |
||
52 | /// <summary> |
||
53 | /// Constructs and initializes the form. |
||
54 | /// </summary> |
||
55 | public ConverterForm() |
||
56 | { |
||
57 | InitializeComponent(); |
||
58 | } |
||
59 | |||
60 | /// <summary> |
||
61 | /// The OK Click Event is used to dismiss the form. |
||
62 | /// </summary> |
||
63 | /// <param name="sender">The sender of the event</param> |
||
64 | /// <param name="e">Arguments passed during event</param> |
||
65 | //private void cmdOK_Click(object sender, EventArgs e) |
||
66 | //{ |
||
67 | // commandControl.Application.RADApplication.Interactive = true; |
||
68 | // Hide(); |
||
69 | // commandControl.Done = true; |
||
70 | //} |
||
71 | |||
72 | /// <summary> |
||
73 | /// The Activate Event is where the command should show its form |
||
74 | /// if it should be displayed. |
||
75 | /// </summary> |
||
76 | /// <param name="sender">The sender of the event</param> |
||
77 | /// <param name="e">Arguments passed during event</param> |
||
78 | private void commandControl_Activate(object sender, EventArgs e) |
||
79 | { |
||
80 | ShowDialog(); |
||
81 | } |
||
82 | |||
83 | /// <summary> |
||
84 | /// The Deactivate event is where the command should hide its form if it |
||
85 | /// was displayed. The command should not unload the form here. |
||
86 | /// The command's form should be unloaded in the Class Module Terminate event. |
||
87 | /// </summary> |
||
88 | /// <param name="sender">The sender of the event</param> |
||
89 | /// <param name="e">Arguments passed during event</param> |
||
90 | private void commandControl_Deactivate(object sender, EventArgs e) |
||
91 | { |
||
92 | Hide(); |
||
93 | } |
||
94 | |||
95 | /// <summary> |
||
96 | /// The Initialize event is where the command should perform 1 time |
||
97 | /// initialization, for example it might save a reference to the |
||
98 | /// active document in private global data. |
||
99 | /// </summary> |
||
100 | /// <param name="sender">The sender of the event</param> |
||
101 | /// <param name="e">Arguments passed during event</param> |
||
102 | private void commandControl_Initialize(object sender, EventArgs e) |
||
103 | { |
||
104 | 022cae08 | gaqhf | |
105 | d57a5303 | gaqhf | } |
106 | |||
107 | /// <summary> |
||
108 | /// The Terminate event is where the command can clean up any command |
||
109 | /// specific allocated resources. |
||
110 | /// </summary> |
||
111 | /// <param name="sender">The sender of the event</param> |
||
112 | /// <param name="e">Arguments passed during event</param> |
||
113 | public void commandControl_Terminate(object sender, EventArgs e) |
||
114 | { |
||
115 | |||
116 | } |
||
117 | |||
118 | /// <summary> |
||
119 | /// The primary form should not simply be unloaded. You should set the |
||
120 | /// Intergraph Command Control Done property to True when you want the |
||
121 | /// form to be unloaded. Then unload the form in the dispose method. |
||
122 | /// </summary> |
||
123 | /// <param name="sender">The sender of the event</param> |
||
124 | /// <param name="e">Arguments passed during event</param> |
||
125 | private void ConverterForm_FormClosing(object sender, FormClosingEventArgs e) |
||
126 | { |
||
127 | commandControl.Application.RADApplication.Interactive = true; // Add by kyouho |
||
128 | Hide(); |
||
129 | commandControl.Done = true; |
||
130 | e.Cancel = true; //Do not let C# close out the form ... Let RAD close it. |
||
131 | } |
||
132 | 022cae08 | gaqhf | #endregion |
133 | |||
134 | |||
135 | |||
136 | |||
137 | |||
138 | |||
139 | |||
140 | |||
141 | |||
142 | |||
143 | |||
144 | |||
145 | d57a5303 | gaqhf | |
146 | private void button1_Click(object sender, EventArgs e) |
||
147 | { |
||
148 | OpenFileDialog dia = new OpenFileDialog(); |
||
149 | dia.Multiselect = false; |
||
150 | dia.Filter = "Xml(*.xml)|*.xml"; |
||
151 | if (dia.ShowDialog() == DialogResult.OK) |
||
152 | { |
||
153 | Log.WriteLine("--------------------------------START--------------------------------"); |
||
154 | SPPID.Model.Document document = SPPID.Model.Document.Load(dia.FileName); |
||
155 | AutoModeling auto = new AutoModeling(document); |
||
156 | auto.Run(); |
||
157 | } |
||
158 | } |
||
159 | 022cae08 | gaqhf | |
160 | #region ?? CustomCommand Source ???? |
||
161 | |||
162 | private void openDocumentsToolStripMenuItem_Click(object sender, EventArgs e) |
||
163 | { |
||
164 | OpenFileDialog dia = new OpenFileDialog(); |
||
165 | dia.Multiselect = true; |
||
166 | dia.Filter = "Xml(*.xml)|*.xml"; |
||
167 | if (dia.ShowDialog() == DialogResult.OK) |
||
168 | { |
||
169 | foreach (string fileName in dia.FileNames) |
||
170 | { |
||
171 | SetDrawingTreeNode(fileName); |
||
172 | } |
||
173 | treeViewDrawing.Nodes[0].Expand(); |
||
174 | } |
||
175 | } |
||
176 | |||
177 | private void itemMappingToolStripMenuItem_Click(object sender, EventArgs e) |
||
178 | { |
||
179 | |||
180 | } |
||
181 | |||
182 | private void importToolStripMenuItem_Click(object sender, EventArgs e) |
||
183 | { |
||
184 | |||
185 | } |
||
186 | private void convertToolStripMenuItem_Click(object sender, EventArgs e) |
||
187 | { |
||
188 | |||
189 | } |
||
190 | |||
191 | private void stopToolStripMenuItem_Click(object sender, EventArgs e) |
||
192 | { |
||
193 | |||
194 | } |
||
195 | |||
196 | |||
197 | #region TreeNode |
||
198 | #region Hide TreeNode CheckBox |
||
199 | private const int TVIF_STATE = 0x8; |
||
200 | private const int TVIS_STATEIMAGEMASK = 0xF000; |
||
201 | private const int TV_FIRST = 0x1100; |
||
202 | private const int TVM_SETITEM = TV_FIRST + 63; |
||
203 | |||
204 | [StructLayout(LayoutKind.Sequential, Pack = 8, CharSet = CharSet.Auto)] |
||
205 | private struct TVITEM |
||
206 | { |
||
207 | public int mask; |
||
208 | public IntPtr hItem; |
||
209 | public int state; |
||
210 | public int stateMask; |
||
211 | [MarshalAs(UnmanagedType.LPTStr)] |
||
212 | public string lpszText; |
||
213 | public int cchTextMax; |
||
214 | public int iImage; |
||
215 | public int iSelectedImage; |
||
216 | public int cChildren; |
||
217 | public IntPtr lParam; |
||
218 | } |
||
219 | |||
220 | [DllImport("user32.dll", CharSet = CharSet.Auto)] |
||
221 | private static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, |
||
222 | ref TVITEM lParam); |
||
223 | |||
224 | /// <summary> |
||
225 | /// Hides the checkbox for the specified node on a TreeView control. |
||
226 | /// </summary> |
||
227 | private void HideCheckBox(TreeView tvw, TreeNode node) |
||
228 | { |
||
229 | TVITEM tvi = new TVITEM(); |
||
230 | tvi.hItem = node.Handle; |
||
231 | tvi.mask = TVIF_STATE; |
||
232 | tvi.stateMask = TVIS_STATEIMAGEMASK; |
||
233 | tvi.state = 0; |
||
234 | SendMessage(tvw.Handle, TVM_SETITEM, IntPtr.Zero, ref tvi); |
||
235 | } |
||
236 | #endregion |
||
237 | |||
238 | private void SetDrawingTreeNode(string fileName) |
||
239 | { |
||
240 | SPPID.Model.Document document = SPPID.Model.Document.Load(fileName); |
||
241 | TreeNode drawingNode = new TreeNode(); |
||
242 | if (document == null) |
||
243 | { |
||
244 | drawingNode.Text = fileName; |
||
245 | drawingNode.Name = fileName; |
||
246 | drawingNode.ForeColor = Color.Red; |
||
247 | treeViewDrawing.Nodes[0].Nodes.Add(drawingNode); |
||
248 | } |
||
249 | else |
||
250 | { |
||
251 | drawingNode.Text = document.DWGNAME; |
||
252 | drawingNode.Name = document.DWGNAME; |
||
253 | drawingNode.Tag = document; |
||
254 | treeViewDrawing.Nodes[0].Nodes.Add(drawingNode); |
||
255 | } |
||
256 | |||
257 | SetItemTreeNode(drawingNode); |
||
258 | } |
||
259 | |||
260 | private void SetItemTreeNode(TreeNode drawingNode) |
||
261 | { |
||
262 | SPPID.Model.Document document = drawingNode.Tag as SPPID.Model.Document; |
||
263 | if (document != null) |
||
264 | { |
||
265 | foreach (LineNumber item in document.LINENUMBERS) |
||
266 | { |
||
267 | TreeNode node = new TreeNode(); |
||
268 | node.Name = item.UID; |
||
269 | node.Text = item.TEXT; |
||
270 | if (string.IsNullOrEmpty(item.SPPIDMAPPINGNAME)) |
||
271 | node.ForeColor = Color.Red; |
||
272 | else |
||
273 | node.ForeColor = Color.Gray; |
||
274 | drawingNode.Nodes.Add(node); |
||
275 | HideCheckBox(treeViewDrawing, node); |
||
276 | } |
||
277 | |||
278 | foreach (Symbol item in document.SYMBOLS) |
||
279 | { |
||
280 | TreeNode node = new TreeNode(); |
||
281 | node.Name = item.UID; |
||
282 | node.Text = item.NAME; |
||
283 | if (string.IsNullOrEmpty(item.SPPIDMAPPINGNAME)) |
||
284 | node.ForeColor = Color.Red; |
||
285 | else |
||
286 | node.ForeColor = Color.Gray; |
||
287 | drawingNode.Nodes.Add(node); |
||
288 | HideCheckBox(treeViewDrawing, node); |
||
289 | } |
||
290 | |||
291 | foreach (Line item in document.LINES) |
||
292 | { |
||
293 | TreeNode node = new TreeNode(); |
||
294 | node.Name = item.UID; |
||
295 | node.Text = item.TYPE; |
||
296 | if (string.IsNullOrEmpty(item.SPPIDMAPPINGNAME)) |
||
297 | node.ForeColor = Color.Red; |
||
298 | else |
||
299 | node.ForeColor = Color.Gray; |
||
300 | drawingNode.Nodes.Add(node); |
||
301 | HideCheckBox(treeViewDrawing, node); |
||
302 | } |
||
303 | |||
304 | foreach (Text item in document.TEXTS) |
||
305 | { |
||
306 | TreeNode node = new TreeNode(); |
||
307 | node.Name = item.UID; |
||
308 | node.Text = item.NAME; |
||
309 | if (string.IsNullOrEmpty(item.SPPIDMAPPINGNAME)) |
||
310 | node.ForeColor = Color.Red; |
||
311 | else |
||
312 | node.ForeColor = Color.Gray; |
||
313 | drawingNode.Nodes.Add(node); |
||
314 | HideCheckBox(treeViewDrawing, node); |
||
315 | } |
||
316 | } |
||
317 | } |
||
318 | |||
319 | private bool DrawingValidationCheck(SPPID.Model.Document document) |
||
320 | { |
||
321 | bool result = false; |
||
322 | |||
323 | |||
324 | |||
325 | return result; |
||
326 | } |
||
327 | |||
328 | |||
329 | #endregion |
||
330 | |||
331 | d57a5303 | gaqhf | #endregion |
332 | 022cae08 | gaqhf | |
333 | d57a5303 | gaqhf | } |
334 | } |