프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Wrapper / SPPIDConverterWrapper.cs @ f9c90c9b

이력 | 보기 | 이력해설 | 다운로드 (12.5 KB)

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
using DOFTECH;
28

    
29
namespace Converter.SPPID.Wrapper
30
{
31
    /// <summary>
32
    /// This is the primary form.
33
    /// This command may be built as an executable (EXE) or as a dynamic link 
34
    /// library (DLL).
35
    /// 
36
    /// When you implement the code that dismisses your form, e.g., an OK
37
    /// button or a Stop Processing button, you should include the following:
38
    /// 
39
    ///     Hide the form, for example
40
    ///         sPPIDConverterDialogBarWrapper.Hide
41
    ///         
42
    ///     Set the Application's Interactive property to True, for example
43
    ///         commandControl.Application.Interactive = True
44
    ///         
45
    ///     Set Intergraph Command Control Done property to True, for example
46
    ///         commandControl.Done = True
47
    /// </summary>
48
    public partial class SPPIDConverterWrapper : System.Windows.Forms.Form
49
    {
50
        const string DialogBarName = "Auto Converter";
51
        public static string autoModelingDllPath = string.Empty;
52

    
53
        /// <summary>
54
        /// Constructor for the form.
55
        /// </summary>
56
        public SPPIDConverterWrapper()
57
        {
58
            InitializeComponent();
59
        }
60

    
61
        /// <summary>
62
        /// Gets the tooltip of the command.
63
        /// </summary>
64
        /// <value>
65
        /// The tooltip of the command as assigned in the resources file.
66
        /// </value>
67
        public string GetTooltip
68
        {
69
            get
70
            {
71
                return Properties.Resources.ResourceManager.GetString("Tooltip", System.Globalization.CultureInfo.CurrentCulture);
72
            }
73
        }
74

    
75
        /// <summary>
76
        /// Gets the toolbar image.
77
        /// </summary>
78
        /// <value>
79
        /// The toolbar image of the command as assigned in the resources file.
80
        /// </value>
81
        public System.Drawing.Image ToolbarImage
82
        {
83
            get
84
            {
85
                return (System.Drawing.Image)Properties.Resources.ResourceManager.GetObject("ToolbarImage", System.Globalization.CultureInfo.CurrentCulture);
86
            }
87
        }
88

    
89
        /// <summary>
90
        /// The Activate Event is where the command should show its form
91
        /// if it should be displayed.
92
        /// </summary>
93
        /// <param name="sender">The sender of the event</param>
94
        /// <param name="e">The event's arguments</param>
95
        private void commandControl_Activate(object sender, EventArgs e)
96
        {
97

    
98
        }
99

    
100
        /* The Deactivate event is where the command should hide its form if it
101
         * was displayed.  The command should not unload the form here.
102
         * The command's form should be unloaded in the Class Module Terminate event.
103
         */
104
        /// <summary>
105
        /// 
106
        /// </summary>
107
        /// <param name="sender">The sender of the event</param>
108
        /// <param name="e">The event's arguments</param>
109
        private void commandControl_Deactivate(object sender, EventArgs e)
110
        {
111

    
112
        }
113

    
114
        /// <summary>
115
        /// The Initialize event is where the command should perform 1 time 
116
        /// initialization, for example it might save a reference to the 
117
        /// active document in private global data.
118
        /// </summary>
119
        /// <param name="sender">The sender of the event</param>
120
        /// <param name="e">The event's arguments</param>
121
        private void commandControl_Initialize(object sender, EventArgs e)
122
        {
123
            Ingr.RAD2D.Application application = commandControl.Application.RADApplication;
124

    
125
            try
126
            {
127
                RegistryKey key = Registry.LocalMachine;
128
                RegistryKey software = key.OpenSubKey("SOFTWARE");
129
                RegistryKey Doftech = software.OpenSubKey("DOFTECH");
130
                if (Doftech != null)
131
                {
132
                    RegistryKey SPPIDConverter = Doftech.OpenSubKey("SPPIDConverter");
133
                    if (SPPIDConverter != null)
134
                    {
135
                        if (!DOFTECH.License.License.IsEnabled())
136
                        {
137
                            MessageBox.Show("Check License!", "SPPID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
138
                            return;
139
                        }
140

    
141
                        autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
142
#if DEBUG
143
                        autoModelingDllPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) , "SPPIDConverter.dll");
144
#endif
145
                        Log.Write("Path : " + autoModelingDllPath);
146
                        #region Set ToolBar and Menu
147
                        ToolBars toolBars = application.ToolBars;
148
                        //application.ActiveDocument.SelectSet.GetEnumerator();
149
                        bool find = true;
150
                        while (find)
151
                        {
152
                            find = false;
153
                            foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
154
                            {
155
                                if (toolBar.Name == "Main")
156
                                {
157
                                    foreach (ToolbarControl item in toolBars["Main"].Controls)
158
                                    {
159
                                        if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
160
                                        {
161
                                            item.Delete();
162
                                            find = true;
163
                                            break;
164
                                        }
165
                                    }
166
                                    break;
167
                                }
168
                            }
169

    
170
                        }
171
                        foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
172
                        {
173
                            if (toolBar.Name == "Main")
174
                            {
175
                                ToolbarControl toolBarControl = toolBars["Main"].Controls.AppendMacroCommand(autoModelingDllPath);
176
                                toolBarControl.ToolTipText = GetTooltip;
177
                                toolBarControl.Picture = ToolbarImage;
178
                                break;
179
                            }
180
                        }
181

    
182
                        Menus menus = application.Menus;
183
                        find = true;
184
                        while (find)
185
                        {
186
                            find = false;
187
                            foreach (Ingr.RAD2D.Menu menu in menus)
188
                            {
189
                                if (menu.Name == "&Tools")
190
                                {
191
                                    foreach (MenuControl item in menus["&Tools"].Controls)
192
                                    {
193
                                        if (item.Caption == GetTooltip)
194
                                        {
195
                                            item.Delete();
196
                                            find = true;
197
                                            break;
198
                                        }
199
                                    }
200
                                    break;
201
                                }
202
                            }
203
                        }
204
                        foreach (Ingr.RAD2D.Menu menu in menus)
205
                        {
206
                            if (menu.Name == "&Tools")
207
                            {
208
                                MenuControl menuControl = application.Menus["&Tools"].Controls.AppendMacroCommand(GetTooltip, autoModelingDllPath);
209
                                menuControl.ToolTipText = GetTooltip;
210
                            }
211
                        }
212

    
213
                        #endregion
214

    
215
                        #region Add Docking
216
                        try
217
                        {
218
                            bool bExist = false;
219
                            foreach (DialogBar dialogBar in application.DialogBars)
220
                            {
221
                                if (dialogBar.Name == DialogBarName)
222
                                {
223
                                    bExist = true;
224
                                    ConverterDocking ui = (ConverterDocking)dialogBar.Controls[0].ControlDispatch;
225
                                    ui.ClearHotKey();
226
                                    dialogBar.Delete();
227
                                    break;
228
                                }
229
                            }
230
                            if (!bExist)
231
                            {
232
                                DialogBar dlgBar = application.DialogBars.Add(DialogBarName, DockingFlagsConstants.igDockableOnLeft, DockingLocationConstants.igDockOnLeft,
233
                                     DialogBarStyleConstants.igDialogBarStyleShowCaption | DialogBarStyleConstants.igDialogBarStyleStretchToFitHorizontal | DialogBarStyleConstants.igDialogBarStyleStretchToFitVertical | DialogBarStyleConstants.igDialogBarStyleNoBorder, 0, 0);
234
                                DialogbarControl dialogBarControl_UserControl = dlgBar.Controls.AddManaged(autoModelingDllPath, "Converter.SPPID.Wrapper.ConverterDocking", 250, 930);
235
                            }
236
                        }
237
                        catch (Exception ex)
238
                        {
239
                            MessageBox.Show("Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
240
                        }
241

    
242
                        if (application.ActiveDocument == null)
243
                            application.RunCommand(CommandConstants.igcmdFileNew);
244

    
245
                        #endregion
246
                    }
247
                }
248
                else
249
                {
250
                    MessageBox.Show("Please SetUp ID2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
251
                }
252
            }
253
            catch (Exception ex)
254
            {
255
                MessageBox.Show(ex.Message);
256
            }
257
            finally
258
            {
259
                Close();
260
            }
261

    
262
        }
263

    
264
        /// <summary>
265
        /// The Terminate event is where the command can clean up any command
266
        /// specific allocated resources.
267
        /// </summary>
268
        /// <param name="sender">The sender of the event</param>
269
        /// <param name="e">The event's arguments</param>
270
        public void commandControl_Terminate(object sender, EventArgs e)
271
        {
272

    
273
        }
274

    
275
        /// <summary>
276
        /// The primary form should not simply be unloaded.  You should set 
277
        /// the Intergraph Command Control Done property to True when you 
278
        /// want the form to be unloaded.  Then unload the form in the
279
        /// dispose method.
280
        /// </summary>
281
        /// <param name="sender">The sender of the event</param>
282
        /// <param name="e">The event's arguments</param>
283
        private void SPPIDConverterDialogBarWrapper_FormClosing(object sender, FormClosingEventArgs e)
284
        {
285
            commandControl.Application.RADApplication.Interactive = true;
286
            commandControl.Done = true;
287
        }
288

    
289
    }
290
}
클립보드 이미지 추가 (최대 크기: 500 MB)