1
|
/*---------------------------------------------------------------------+\
|
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
|
using System.Reflection;
|
27
|
|
28
|
namespace Converter.SPPID.Wrapper
|
29
|
{
|
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
|
public partial class SPPIDConverterWrapper : System.Windows.Forms.Form
|
48
|
{
|
49
|
const string DialogBarName = "Auto Converter";
|
50
|
public static string autoModelingDllPath = string.Empty;
|
51
|
|
52
|
/// <summary>
|
53
|
/// Constructor for the form.
|
54
|
/// </summary>
|
55
|
public SPPIDConverterWrapper()
|
56
|
{
|
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
|
|
124
|
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
|
RegistryKey SPPIDConverter = DOFTECH.OpenSubKey("SPPIDConverter");
|
132
|
if (SPPIDConverter != null)
|
133
|
{
|
134
|
autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
|
135
|
#if DEBUG
|
136
|
autoModelingDllPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) , "SPPIDConverter.dll");
|
137
|
#endif
|
138
|
Log.Write("Path : " + autoModelingDllPath);
|
139
|
#region Set ToolBar and Menu
|
140
|
ToolBars toolBars = application.ToolBars;
|
141
|
//application.ActiveDocument.SelectSet.GetEnumerator();
|
142
|
bool find = true;
|
143
|
while (find)
|
144
|
{
|
145
|
find = false;
|
146
|
foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
|
147
|
{
|
148
|
if (toolBar.Name == "Main")
|
149
|
{
|
150
|
foreach (ToolbarControl item in toolBars["Main"].Controls)
|
151
|
{
|
152
|
if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
|
153
|
{
|
154
|
item.Delete();
|
155
|
find = true;
|
156
|
break;
|
157
|
}
|
158
|
}
|
159
|
break;
|
160
|
}
|
161
|
}
|
162
|
|
163
|
}
|
164
|
foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
|
165
|
{
|
166
|
if (toolBar.Name == "Main")
|
167
|
{
|
168
|
ToolbarControl toolBarControl = toolBars["Main"].Controls.AppendMacroCommand(autoModelingDllPath);
|
169
|
toolBarControl.ToolTipText = GetTooltip;
|
170
|
toolBarControl.Picture = ToolbarImage;
|
171
|
break;
|
172
|
}
|
173
|
}
|
174
|
|
175
|
Menus menus = application.Menus;
|
176
|
find = true;
|
177
|
while (find)
|
178
|
{
|
179
|
find = false;
|
180
|
foreach (Ingr.RAD2D.Menu menu in menus)
|
181
|
{
|
182
|
if (menu.Name == "&Tools")
|
183
|
{
|
184
|
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
|
break;
|
194
|
}
|
195
|
}
|
196
|
}
|
197
|
foreach (Ingr.RAD2D.Menu menu in menus)
|
198
|
{
|
199
|
if (menu.Name == "&Tools")
|
200
|
{
|
201
|
MenuControl menuControl = application.Menus["&Tools"].Controls.AppendMacroCommand(GetTooltip, autoModelingDllPath);
|
202
|
menuControl.ToolTipText = GetTooltip;
|
203
|
}
|
204
|
}
|
205
|
|
206
|
#endregion
|
207
|
|
208
|
#region Add Docking
|
209
|
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
|
DialogbarControl dialogBarControl_UserControl = dlgBar.Controls.AddManaged(autoModelingDllPath, "Converter.SPPID.Wrapper.ConverterDocking", 200, 500);
|
226
|
}
|
227
|
}
|
228
|
catch (Exception ex)
|
229
|
{
|
230
|
MessageBox.Show("Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
231
|
}
|
232
|
|
233
|
if (application.ActiveDocument == null)
|
234
|
application.RunCommand(CommandConstants.igcmdFileNew);
|
235
|
|
236
|
#endregion
|
237
|
}
|
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
|
finally
|
249
|
{
|
250
|
Close();
|
251
|
}
|
252
|
|
253
|
}
|
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
|
}
|