1 |
2cae7d1f
|
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.ComponentModel;
|
23 |
|
|
using System.Windows.Forms;
|
24 |
|
|
using Microsoft.Win32;
|
25 |
|
|
using Ingr.RAD2D;
|
26 |
b427ebf9
|
humkyung
|
using System.Reflection;
|
27 |
2cae7d1f
|
gaqhf
|
|
28 |
0a24b232
|
gaqhf
|
namespace Converter.SPPID.Wrapper
|
29 |
2cae7d1f
|
gaqhf
|
{
|
30 |
|
|
/// <summary>
|
31 |
|
|
/// This is the primary form.
|
32 |
|
|
/// This command may be built as an executable (EXE) or as a dynamic link
|
33 |
|
|
/// library (DLL).
|
34 |
|
|
///
|
35 |
|
|
/// When you implement the code that dismisses your form, e.g., an OK
|
36 |
|
|
/// button or a Stop Processing button, you should include the following:
|
37 |
|
|
///
|
38 |
|
|
/// Hide the form, for example
|
39 |
|
|
/// sPPIDConverterDialogBarWrapper.Hide
|
40 |
|
|
///
|
41 |
|
|
/// Set the Application's Interactive property to True, for example
|
42 |
|
|
/// commandControl.Application.Interactive = True
|
43 |
|
|
///
|
44 |
|
|
/// Set Intergraph Command Control Done property to True, for example
|
45 |
|
|
/// commandControl.Done = True
|
46 |
|
|
/// </summary>
|
47 |
e3e2d41f
|
gaqhf
|
public partial class SPPIDConverterWrapper : System.Windows.Forms.Form
|
48 |
2cae7d1f
|
gaqhf
|
{
|
49 |
|
|
const string DialogBarName = "Auto Converter";
|
50 |
e3e2d41f
|
gaqhf
|
public static string autoModelingDllPath = string.Empty;
|
51 |
2cae7d1f
|
gaqhf
|
|
52 |
|
|
/// <summary>
|
53 |
|
|
/// Constructor for the form.
|
54 |
|
|
/// </summary>
|
55 |
2f0955d4
|
gaqhf
|
public SPPIDConverterWrapper()
|
56 |
2cae7d1f
|
gaqhf
|
{
|
57 |
|
|
InitializeComponent();
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/// <summary>
|
61 |
|
|
/// Gets the tooltip of the command.
|
62 |
|
|
/// </summary>
|
63 |
|
|
/// <value>
|
64 |
|
|
/// The tooltip of the command as assigned in the resources file.
|
65 |
|
|
/// </value>
|
66 |
|
|
public string GetTooltip
|
67 |
|
|
{
|
68 |
|
|
get
|
69 |
|
|
{
|
70 |
|
|
return Properties.Resources.ResourceManager.GetString("Tooltip", System.Globalization.CultureInfo.CurrentCulture);
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
|
74 |
|
|
/// <summary>
|
75 |
|
|
/// Gets the toolbar image.
|
76 |
|
|
/// </summary>
|
77 |
|
|
/// <value>
|
78 |
|
|
/// The toolbar image of the command as assigned in the resources file.
|
79 |
|
|
/// </value>
|
80 |
|
|
public System.Drawing.Image ToolbarImage
|
81 |
|
|
{
|
82 |
|
|
get
|
83 |
|
|
{
|
84 |
|
|
return (System.Drawing.Image)Properties.Resources.ResourceManager.GetObject("ToolbarImage", System.Globalization.CultureInfo.CurrentCulture);
|
85 |
|
|
}
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/// <summary>
|
89 |
|
|
/// The Activate Event is where the command should show its form
|
90 |
|
|
/// if it should be displayed.
|
91 |
|
|
/// </summary>
|
92 |
|
|
/// <param name="sender">The sender of the event</param>
|
93 |
|
|
/// <param name="e">The event's arguments</param>
|
94 |
|
|
private void commandControl_Activate(object sender, EventArgs e)
|
95 |
|
|
{
|
96 |
|
|
|
97 |
|
|
}
|
98 |
|
|
|
99 |
|
|
/* The Deactivate event is where the command should hide its form if it
|
100 |
|
|
* was displayed. The command should not unload the form here.
|
101 |
|
|
* The command's form should be unloaded in the Class Module Terminate event.
|
102 |
|
|
*/
|
103 |
|
|
/// <summary>
|
104 |
|
|
///
|
105 |
|
|
/// </summary>
|
106 |
|
|
/// <param name="sender">The sender of the event</param>
|
107 |
|
|
/// <param name="e">The event's arguments</param>
|
108 |
|
|
private void commandControl_Deactivate(object sender, EventArgs e)
|
109 |
|
|
{
|
110 |
|
|
|
111 |
|
|
}
|
112 |
|
|
|
113 |
|
|
/// <summary>
|
114 |
|
|
/// The Initialize event is where the command should perform 1 time
|
115 |
|
|
/// initialization, for example it might save a reference to the
|
116 |
|
|
/// active document in private global data.
|
117 |
|
|
/// </summary>
|
118 |
|
|
/// <param name="sender">The sender of the event</param>
|
119 |
|
|
/// <param name="e">The event's arguments</param>
|
120 |
|
|
private void commandControl_Initialize(object sender, EventArgs e)
|
121 |
|
|
{
|
122 |
|
|
Ingr.RAD2D.Application application = commandControl.Application.RADApplication;
|
123 |
b33b0d0a
|
gaqhf
|
|
124 |
2cae7d1f
|
gaqhf
|
try
|
125 |
|
|
{
|
126 |
|
|
RegistryKey key = Registry.LocalMachine;
|
127 |
|
|
RegistryKey software = key.OpenSubKey("SOFTWARE");
|
128 |
|
|
RegistryKey DOFTECH = software.OpenSubKey("DOFTECH");
|
129 |
|
|
if (DOFTECH != null)
|
130 |
|
|
{
|
131 |
32205389
|
gaqhf
|
RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter");
|
132 |
|
|
if (SPPIDConverter != null)
|
133 |
2cae7d1f
|
gaqhf
|
{
|
134 |
32205389
|
gaqhf
|
autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
|
135 |
e62fd094
|
gaqhf
|
#if DEBUG
|
136 |
b427ebf9
|
humkyung
|
autoModelingDllPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) , "SPPIDConverter.dll");
|
137 |
e62fd094
|
gaqhf
|
#endif
|
138 |
42cf8c56
|
gaqhf
|
Log.Write("Path : " + autoModelingDllPath);
|
139 |
2cae7d1f
|
gaqhf
|
#region Set ToolBar and Menu
|
140 |
|
|
ToolBars toolBars = application.ToolBars;
|
141 |
8aa6f2db
|
gaqhf
|
//application.ActiveDocument.SelectSet.GetEnumerator();
|
142 |
2cae7d1f
|
gaqhf
|
bool find = true;
|
143 |
|
|
while (find)
|
144 |
|
|
{
|
145 |
|
|
find = false;
|
146 |
b33b0d0a
|
gaqhf
|
foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
|
147 |
2cae7d1f
|
gaqhf
|
{
|
148 |
b33b0d0a
|
gaqhf
|
if (toolBar.Name == "Main")
|
149 |
2cae7d1f
|
gaqhf
|
{
|
150 |
b33b0d0a
|
gaqhf
|
foreach (ToolbarControl item in toolBars["Main"].Controls)
|
151 |
|
|
{
|
152 |
6d12a734
|
gaqhf
|
if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
|
153 |
b33b0d0a
|
gaqhf
|
{
|
154 |
|
|
item.Delete();
|
155 |
|
|
find = true;
|
156 |
|
|
break;
|
157 |
|
|
}
|
158 |
|
|
}
|
159 |
2cae7d1f
|
gaqhf
|
break;
|
160 |
|
|
}
|
161 |
|
|
}
|
162 |
|
|
|
163 |
b33b0d0a
|
gaqhf
|
}
|
164 |
|
|
foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
|
165 |
|
|
{
|
166 |
|
|
if (toolBar.Name == "Main")
|
167 |
|
|
{
|
168 |
d19ae675
|
gaqhf
|
ToolbarControl toolBarControl = toolBars["Main"].Controls.AppendMacroCommand(autoModelingDllPath);
|
169 |
b33b0d0a
|
gaqhf
|
toolBarControl.ToolTipText = GetTooltip;
|
170 |
|
|
toolBarControl.Picture = ToolbarImage;
|
171 |
|
|
break;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
2cae7d1f
|
gaqhf
|
|
175 |
b33b0d0a
|
gaqhf
|
Menus menus = application.Menus;
|
176 |
2cae7d1f
|
gaqhf
|
find = true;
|
177 |
|
|
while (find)
|
178 |
|
|
{
|
179 |
|
|
find = false;
|
180 |
b33b0d0a
|
gaqhf
|
foreach (Ingr.RAD2D.Menu menu in menus)
|
181 |
2cae7d1f
|
gaqhf
|
{
|
182 |
b33b0d0a
|
gaqhf
|
if (menu.Name == "&Tools")
|
183 |
2cae7d1f
|
gaqhf
|
{
|
184 |
b33b0d0a
|
gaqhf
|
foreach (MenuControl item in menus["&Tools"].Controls)
|
185 |
|
|
{
|
186 |
|
|
if (item.Caption == GetTooltip)
|
187 |
|
|
{
|
188 |
|
|
item.Delete();
|
189 |
|
|
find = true;
|
190 |
|
|
break;
|
191 |
|
|
}
|
192 |
|
|
}
|
193 |
2cae7d1f
|
gaqhf
|
break;
|
194 |
|
|
}
|
195 |
|
|
}
|
196 |
b33b0d0a
|
gaqhf
|
}
|
197 |
|
|
foreach (Ingr.RAD2D.Menu menu in menus)
|
198 |
|
|
{
|
199 |
|
|
if (menu.Name == "&Tools")
|
200 |
|
|
{
|
201 |
d19ae675
|
gaqhf
|
MenuControl menuControl = application.Menus["&Tools"].Controls.AppendMacroCommand(GetTooltip, autoModelingDllPath);
|
202 |
b33b0d0a
|
gaqhf
|
menuControl.ToolTipText = GetTooltip;
|
203 |
|
|
}
|
204 |
2cae7d1f
|
gaqhf
|
}
|
205 |
|
|
|
206 |
|
|
#endregion
|
207 |
96a2080c
|
gaqhf
|
|
208 |
c4d079c4
|
gaqhf
|
#region Add Docking
|
209 |
e3e2d41f
|
gaqhf
|
try
|
210 |
|
|
{
|
211 |
|
|
bool bExist = false;
|
212 |
|
|
foreach (DialogBar dialogBar in application.DialogBars)
|
213 |
|
|
{
|
214 |
|
|
if (dialogBar.Name == DialogBarName)
|
215 |
|
|
{
|
216 |
|
|
bExist = true;
|
217 |
|
|
dialogBar.Delete();
|
218 |
|
|
break;
|
219 |
|
|
}
|
220 |
|
|
}
|
221 |
|
|
if (!bExist)
|
222 |
|
|
{
|
223 |
|
|
DialogBar dlgBar = application.DialogBars.Add(DialogBarName, DockingFlagsConstants.igDockableOnLeft, DockingLocationConstants.igDockOnLeft,
|
224 |
|
|
DialogBarStyleConstants.igDialogBarStyleShowCaption | DialogBarStyleConstants.igDialogBarStyleStretchToFitHorizontal | DialogBarStyleConstants.igDialogBarStyleStretchToFitVertical | DialogBarStyleConstants.igDialogBarStyleNoBorder, 0, 0);
|
225 |
6a7573b0
|
gaqhf
|
DialogbarControl dialogBarControl_UserControl = dlgBar.Controls.AddManaged(autoModelingDllPath, "Converter.SPPID.Wrapper.ConverterDocking", 200, 500);
|
226 |
e3e2d41f
|
gaqhf
|
}
|
227 |
|
|
}
|
228 |
|
|
catch (Exception ex)
|
229 |
|
|
{
|
230 |
d19ae675
|
gaqhf
|
MessageBox.Show("Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
231 |
e3e2d41f
|
gaqhf
|
}
|
232 |
c4d079c4
|
gaqhf
|
|
233 |
1ba9c671
|
gaqhf
|
if (application.ActiveDocument == null)
|
234 |
|
|
application.RunCommand(CommandConstants.igcmdFileNew);
|
235 |
|
|
|
236 |
c4d079c4
|
gaqhf
|
#endregion
|
237 |
2cae7d1f
|
gaqhf
|
}
|
238 |
|
|
}
|
239 |
|
|
else
|
240 |
|
|
{
|
241 |
|
|
MessageBox.Show("Please SetUp ID2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
242 |
|
|
}
|
243 |
|
|
}
|
244 |
|
|
catch (Exception ex)
|
245 |
|
|
{
|
246 |
|
|
MessageBox.Show(ex.Message);
|
247 |
|
|
}
|
248 |
b33b0d0a
|
gaqhf
|
finally
|
249 |
|
|
{
|
250 |
d19ae675
|
gaqhf
|
Close();
|
251 |
b33b0d0a
|
gaqhf
|
}
|
252 |
|
|
|
253 |
2cae7d1f
|
gaqhf
|
}
|
254 |
|
|
|
255 |
|
|
/// <summary>
|
256 |
|
|
/// The Terminate event is where the command can clean up any command
|
257 |
|
|
/// specific allocated resources.
|
258 |
|
|
/// </summary>
|
259 |
|
|
/// <param name="sender">The sender of the event</param>
|
260 |
|
|
/// <param name="e">The event's arguments</param>
|
261 |
|
|
public void commandControl_Terminate(object sender, EventArgs e)
|
262 |
|
|
{
|
263 |
|
|
|
264 |
|
|
}
|
265 |
|
|
|
266 |
|
|
/// <summary>
|
267 |
|
|
/// The primary form should not simply be unloaded. You should set
|
268 |
|
|
/// the Intergraph Command Control Done property to True when you
|
269 |
|
|
/// want the form to be unloaded. Then unload the form in the
|
270 |
|
|
/// dispose method.
|
271 |
|
|
/// </summary>
|
272 |
|
|
/// <param name="sender">The sender of the event</param>
|
273 |
|
|
/// <param name="e">The event's arguments</param>
|
274 |
|
|
private void SPPIDConverterDialogBarWrapper_FormClosing(object sender, FormClosingEventArgs e)
|
275 |
|
|
{
|
276 |
|
|
commandControl.Application.RADApplication.Interactive = true;
|
277 |
|
|
commandControl.Done = true;
|
278 |
|
|
}
|
279 |
|
|
|
280 |
|
|
}
|
281 |
|
|
} |