프로젝트

일반

사용자정보

통계
| 개정판:

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

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

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 91c7a82a gaqhf
using DOFTECH;
28 2cae7d1f gaqhf
29 0a24b232 gaqhf
namespace Converter.SPPID.Wrapper
30 2cae7d1f gaqhf
{
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 e3e2d41f gaqhf
    public partial class SPPIDConverterWrapper : System.Windows.Forms.Form
49 2cae7d1f gaqhf
    {
50
        const string DialogBarName = "Auto Converter";
51 e3e2d41f gaqhf
        public static string autoModelingDllPath = string.Empty;
52 2cae7d1f gaqhf
53
        /// <summary>
54
        /// Constructor for the form.
55
        /// </summary>
56 2f0955d4 gaqhf
        public SPPIDConverterWrapper()
57 2cae7d1f gaqhf
        {
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 b33b0d0a gaqhf
125 2cae7d1f gaqhf
            try
126
            {
127
                RegistryKey key = Registry.LocalMachine;
128
                RegistryKey software = key.OpenSubKey("SOFTWARE");
129 91c7a82a gaqhf
                RegistryKey Doftech = software.OpenSubKey("DOFTECH");
130
                if (Doftech != null)
131 2cae7d1f gaqhf
                {
132 91c7a82a gaqhf
                    RegistryKey SPPIDConverter = Doftech.OpenSubKey("SPPIDConverter");
133 da8624d4 gaqhf
                    if (SPPIDConverter != null)
134 2cae7d1f gaqhf
                    {
135 9c451472 gaqhf
                        //if (!DOFTECH.License.License.IsEnabled())
136
                        //{
137
                        //    MessageBox.Show("Check License!", "SPPID Converter", MessageBoxButtons.OK, MessageBoxIcon.Warning);
138
                        //    return;
139
                        //}
140 da8624d4 gaqhf
141 32205389 gaqhf
                        autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
142 e62fd094 gaqhf
#if DEBUG
143 b427ebf9 humkyung
                        autoModelingDllPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) , "SPPIDConverter.dll");
144 e62fd094 gaqhf
#endif
145 42cf8c56 gaqhf
                        Log.Write("Path : " + autoModelingDllPath);
146 2cae7d1f gaqhf
                        #region Set ToolBar and Menu
147
                        ToolBars toolBars = application.ToolBars;
148 8aa6f2db gaqhf
                        //application.ActiveDocument.SelectSet.GetEnumerator();
149 2cae7d1f gaqhf
                        bool find = true;
150
                        while (find)
151
                        {
152
                            find = false;
153 b33b0d0a gaqhf
                            foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
154 2cae7d1f gaqhf
                            {
155 b33b0d0a gaqhf
                                if (toolBar.Name == "Main")
156 2cae7d1f gaqhf
                                {
157 b33b0d0a gaqhf
                                    foreach (ToolbarControl item in toolBars["Main"].Controls)
158
                                    {
159 6d12a734 gaqhf
                                        if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
160 b33b0d0a gaqhf
                                        {
161
                                            item.Delete();
162
                                            find = true;
163
                                            break;
164
                                        }
165
                                    }
166 2cae7d1f gaqhf
                                    break;
167
                                }
168
                            }
169
170 b33b0d0a gaqhf
                        }
171
                        foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
172
                        {
173
                            if (toolBar.Name == "Main")
174
                            {
175 d19ae675 gaqhf
                                ToolbarControl toolBarControl = toolBars["Main"].Controls.AppendMacroCommand(autoModelingDllPath);
176 b33b0d0a gaqhf
                                toolBarControl.ToolTipText = GetTooltip;
177
                                toolBarControl.Picture = ToolbarImage;
178
                                break;
179
                            }
180
                        }
181 2cae7d1f gaqhf
182 b33b0d0a gaqhf
                        Menus menus = application.Menus;
183 2cae7d1f gaqhf
                        find = true;
184
                        while (find)
185
                        {
186
                            find = false;
187 b33b0d0a gaqhf
                            foreach (Ingr.RAD2D.Menu menu in menus)
188 2cae7d1f gaqhf
                            {
189 b33b0d0a gaqhf
                                if (menu.Name == "&Tools")
190 2cae7d1f gaqhf
                                {
191 b33b0d0a gaqhf
                                    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 2cae7d1f gaqhf
                                    break;
201
                                }
202
                            }
203 b33b0d0a gaqhf
                        }
204
                        foreach (Ingr.RAD2D.Menu menu in menus)
205
                        {
206
                            if (menu.Name == "&Tools")
207
                            {
208 d19ae675 gaqhf
                                MenuControl menuControl = application.Menus["&Tools"].Controls.AppendMacroCommand(GetTooltip, autoModelingDllPath);
209 b33b0d0a gaqhf
                                menuControl.ToolTipText = GetTooltip;
210
                            }
211 2cae7d1f gaqhf
                        }
212
213
                        #endregion
214 96a2080c gaqhf
215 c4d079c4 gaqhf
                        #region Add Docking
216 e3e2d41f gaqhf
                        try
217
                        {
218
                            bool bExist = false;
219
                            foreach (DialogBar dialogBar in application.DialogBars)
220
                            {
221
                                if (dialogBar.Name == DialogBarName)
222
                                {
223
                                    bExist = true;
224 5a47c65c gaqhf
                                    ConverterDocking ui = (ConverterDocking)dialogBar.Controls[0].ControlDispatch;
225
                                    ui.ClearHotKey();
226 e3e2d41f gaqhf
                                    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 d129b131 gaqhf
                                DialogbarControl dialogBarControl_UserControl = dlgBar.Controls.AddManaged(autoModelingDllPath, "Converter.SPPID.Wrapper.ConverterDocking", 250, 930);
235 e3e2d41f gaqhf
                            }
236
                        }
237
                        catch (Exception ex)
238
                        {
239 d19ae675 gaqhf
                            MessageBox.Show("Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
240 e3e2d41f gaqhf
                        }
241 c4d079c4 gaqhf
242 1ba9c671 gaqhf
                        if (application.ActiveDocument == null)
243
                            application.RunCommand(CommandConstants.igcmdFileNew);
244
245 c4d079c4 gaqhf
                        #endregion
246 2cae7d1f gaqhf
                    }
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 b33b0d0a gaqhf
            finally
258
            {
259 d19ae675 gaqhf
                Close();
260 b33b0d0a gaqhf
            }
261
262 2cae7d1f gaqhf
        }
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)