프로젝트

일반

사용자정보

통계
| 개정판:

hytos / DTI_PID / SPPIDConverter / Wrapper / SPPIDConverterWrapper.cs @ 91c7a82a

이력 | 보기 | 이력해설 | 다운로드 (12.1 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 && DOFTECH.License.License.IsEnabled())
134
                    {
135
                        autoModelingDllPath = SPPIDConverter.GetValue("path") + @"SPPIDConverter.dll";
136
#if DEBUG
137
                        autoModelingDllPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) , "SPPIDConverter.dll");
138
#endif
139
                        Log.Write("Path : " + autoModelingDllPath);
140
                        #region Set ToolBar and Menu
141
                        ToolBars toolBars = application.ToolBars;
142
                        //application.ActiveDocument.SelectSet.GetEnumerator();
143
                        bool find = true;
144
                        while (find)
145
                        {
146
                            find = false;
147
                            foreach (Ingr.RAD2D.ToolBar toolBar in toolBars)
148
                            {
149
                                if (toolBar.Name == "Main")
150
                                {
151
                                    foreach (ToolbarControl item in toolBars["Main"].Controls)
152
                                    {
153
                                        if (item.DLLName.Contains("SPPIDConverter.dll") || item.DLLName.Contains("SPPIDConverter_Wrapper.dll"))
154
                                        {
155
                                            item.Delete();
156
                                            find = true;
157
                                            break;
158
                                        }
159
                                    }
160
                                    break;
161
                                }
162
                            }
163

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

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

    
207
                        #endregion
208

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

    
234
                        if (application.ActiveDocument == null)
235
                            application.RunCommand(CommandConstants.igcmdFileNew);
236

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

    
254
        }
255

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

    
265
        }
266

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

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