프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Wrapper / SPPIDConverterWrapper.cs @ 6d12a734

이력 | 보기 | 이력해설 | 다운로드 (11.9 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

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

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

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

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

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

    
96
        }
97

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

    
110
        }
111

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

    
123
            try
124
            {
125
                RegistryKey key = Registry.LocalMachine;
126
                RegistryKey software = key.OpenSubKey("SOFTWARE");
127
                RegistryKey DOFTECH = software.OpenSubKey("DOFTECH");
128
                if (DOFTECH != null)
129
                {
130
                    RegistryKey ID2 = DOFTECH.OpenSubKey("ID2");
131
                    if (ID2 != null)
132
                    {
133
                        autoModelingDllPath = ID2.GetValue("path") + @"Converter\SPPIDConverter.dll";
134
#if DEBUG
135
                        autoModelingDllPath = @"Z:\HanKyouHo\Source\DTIPID\DTI_PID\SPPIDConverterDll\SPPIDConverter.dll";
136
#endif
137

    
138
                        #region Set ToolBar and Menu
139
                        ToolBars toolBars = application.ToolBars;
140
                        //application.ActiveDocument.SelectSet.GetEnumerator();
141
                        bool find = true;
142
                        while (find)
143
                        {
144
                            find = false;
145
                            foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
146
                            {
147
                                if (toolBar.Name == "Main")
148
                                {
149
                                    foreach (ToolbarControl item in toolBars["Main"].Controls)
150
                                    {
151
                                        if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
152
                                        {
153
                                            item.Delete();
154
                                            find = true;
155
                                            break;
156
                                        }
157
                                    }
158
                                    break;
159
                                }
160
                            }
161

    
162
                        }
163
                        foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
164
                        {
165
                            if (toolBar.Name == "Main")
166
                            {
167
                                ToolbarControl toolBarControl = toolBars["Main"].Controls.AppendMacroCommand(autoModelingDllPath);
168
                                toolBarControl.ToolTipText = GetTooltip;
169
                                toolBarControl.Picture = ToolbarImage;
170
                                break;
171
                            }
172
                        }
173

    
174
                        Menus menus = application.Menus;
175
                        find = true;
176
                        while (find)
177
                        {
178
                            find = false;
179
                            foreach (Ingr.RAD2D.Menu menu in menus)
180
                            {
181
                                if (menu.Name == "&Tools")
182
                                {
183
                                    foreach (MenuControl item in menus["&Tools"].Controls)
184
                                    {
185
                                        if (item.Caption == GetTooltip)
186
                                        {
187
                                            item.Delete();
188
                                            find = true;
189
                                            break;
190
                                        }
191
                                    }
192
                                    break;
193
                                }
194
                            }
195
                        }
196
                        foreach (Ingr.RAD2D.Menu menu in menus)
197
                        {
198
                            if (menu.Name == "&Tools")
199
                            {
200
                                MenuControl menuControl = application.Menus["&Tools"].Controls.AppendMacroCommand(GetTooltip, autoModelingDllPath);
201
                                menuControl.ToolTipText = GetTooltip;
202
                            }
203
                        }
204

    
205
                        #endregion
206

    
207
                        #region Add Docking
208
                        try
209
                        {
210
                            bool bExist = false;
211
                            foreach (DialogBar dialogBar in application.DialogBars)
212
                            {
213
                                if (dialogBar.Name == DialogBarName)
214
                                {
215
                                    bExist = true;
216
                                    dialogBar.Delete();
217
                                    break;
218
                                }
219
                            }
220
                            if (!bExist)
221
                            {
222
                                DialogBar dlgBar = application.DialogBars.Add(DialogBarName, DockingFlagsConstants.igDockableOnLeft, DockingLocationConstants.igDockOnLeft,
223
                                     DialogBarStyleConstants.igDialogBarStyleShowCaption | DialogBarStyleConstants.igDialogBarStyleStretchToFitHorizontal | DialogBarStyleConstants.igDialogBarStyleStretchToFitVertical | DialogBarStyleConstants.igDialogBarStyleNoBorder, 0, 0);
224
                                DialogbarControl dialogBarControl_UserControl = dlgBar.Controls.AddManaged(autoModelingDllPath, "Converter.SPPID.Wrapper.ConverterDocking", 200, 500);
225
                            }
226
                        }
227
                        catch (Exception ex)
228
                        {
229
                            MessageBox.Show("Fail", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
230
                        }
231

    
232
                        if (application.ActiveDocument == null)
233
                            application.RunCommand(CommandConstants.igcmdFileNew);
234

    
235
                        #endregion
236
                    }
237
                }
238
                else
239
                {
240
                    MessageBox.Show("Please SetUp ID2", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
241
                }
242
            }
243
            catch (Exception ex)
244
            {
245
                MessageBox.Show(ex.Message);
246
            }
247
            finally
248
            {
249
                Close();
250
            }
251

    
252
        }
253

    
254
        /// <summary>
255
        /// The Terminate event is where the command can clean up any command
256
        /// specific allocated resources.
257
        /// </summary>
258
        /// <param name="sender">The sender of the event</param>
259
        /// <param name="e">The event's arguments</param>
260
        public void commandControl_Terminate(object sender, EventArgs e)
261
        {
262

    
263
        }
264

    
265
        /// <summary>
266
        /// The primary form should not simply be unloaded.  You should set 
267
        /// the Intergraph Command Control Done property to True when you 
268
        /// want the form to be unloaded.  Then unload the form in the
269
        /// dispose method.
270
        /// </summary>
271
        /// <param name="sender">The sender of the event</param>
272
        /// <param name="e">The event's arguments</param>
273
        private void SPPIDConverterDialogBarWrapper_FormClosing(object sender, FormClosingEventArgs e)
274
        {
275
            commandControl.Application.RADApplication.Interactive = true;
276
            commandControl.Done = true;
277
        }
278

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