Exemple #1
0
        public void AddCommandMgr()
        {
            ICommandGroup cmdGroup;

            if (m_iBmp == null)
            {
                m_iBmp = new BitmapHandler();
            }
            Assembly thisAssembly;
            int      cmdIndex0, cmdIndex1;
            string   Title = "C# Addin", ToolTip = "C# Addin";


            int[] docTypes = new int[] { (int)swDocumentTypes_e.swDocASSEMBLY,
                                         (int)swDocumentTypes_e.swDocDRAWING,
                                         (int)swDocumentTypes_e.swDocPART };

            thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());


            int  cmdGroupErr    = 0;
            bool ignorePrevious = false;

            object registryIDs;
            //get the ID information stored in the registry
            bool getDataResult = m_iCmdMgr.GetGroupDataFromRegistry(mainCmdGroupID, out registryIDs);

            int[] knownIDs = new int[2] {
                mainItemID1, mainItemID2
            };

            if (getDataResult)
            {
                if (!CompareIDs((int[])registryIDs, knownIDs)) //if the IDs don't match, reset the commandGroup
                {
                    ignorePrevious = true;
                }
            }

            cmdGroup = m_iCmdMgr.CreateCommandGroup2(mainCmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr);

            // Add bitmaps to your project and set them as embedded resources or provide a direct path to the bitmaps.
            icons[0] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar20x.png", thisAssembly);
            icons[1] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar32x.png", thisAssembly);
            icons[2] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar40x.png", thisAssembly);
            icons[3] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar64x.png", thisAssembly);
            icons[4] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar96x.png", thisAssembly);
            icons[5] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.toolbar128x.png", thisAssembly);

            mainIcons[0] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_20.png", thisAssembly);
            mainIcons[1] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_32.png", thisAssembly);
            mainIcons[2] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_40.png", thisAssembly);
            mainIcons[3] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_64.png", thisAssembly);
            mainIcons[4] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_96.png", thisAssembly);
            mainIcons[5] = m_iBmp.CreateFileFromResourceBitmap("SwCSharpAddin1.mainicon_128.png", thisAssembly);

            cmdGroup.MainIconList = mainIcons;
            cmdGroup.IconList     = icons;

            int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);

            cmdIndex0 = cmdGroup.AddCommandItem2("CreateCube", -1, "Create a cube", "Create cube", 0, "CreateCube", "", mainItemID1, menuToolbarOption);
            cmdIndex1 = cmdGroup.AddCommandItem2("Show PMP", -1, "Display sample property manager", "Show PMP", 2, "ShowPMP", "EnablePMP", mainItemID2, menuToolbarOption);

            cmdGroup.HasToolbar = true;
            cmdGroup.HasMenu    = true;
            cmdGroup.Activate();

            bool bResult;



            FlyoutGroup flyGroup = m_iCmdMgr.CreateFlyoutGroup2(flyoutGroupID, "Dynamic Flyout", "Flyout Tooltip", "Flyout Hint",
                                                                cmdGroup.MainIconList, cmdGroup.IconList, "FlyoutCallback", "FlyoutEnable");


            flyGroup.AddCommandItem("FlyoutCommand 1", "test", 0, "FlyoutCommandItem1", "FlyoutEnableCommandItem1");

            flyGroup.FlyoutType = (int)swCommandFlyoutStyle_e.swCommandFlyoutStyle_Simple;


            foreach (int type in docTypes)
            {
                CommandTab cmdTab;

                cmdTab = m_iCmdMgr.GetCommandTab(type, Title);

                if (cmdTab != null & !getDataResult | ignorePrevious)//if tab exists, but we have ignored the registry info (or changed command group ID), re-create the tab.  Otherwise the ids won't matchup and the tab will be blank
                {
                    bool res = m_iCmdMgr.RemoveCommandTab(cmdTab);
                    cmdTab = null;
                }

                //if cmdTab is null, must be first load (possibly after reset), add the commands to the tabs
                if (cmdTab == null)
                {
                    cmdTab = m_iCmdMgr.AddCommandTab(type, Title);

                    CommandTabBox cmdBox = cmdTab.AddCommandTabBox();

                    int[] cmdIDs   = new int[3];
                    int[] TextType = new int[3];

                    cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex0);

                    TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal;

                    cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex1);

                    TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal;

                    cmdIDs[2] = cmdGroup.ToolbarId;

                    TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout;

                    bResult = cmdBox.AddCommands(cmdIDs, TextType);



                    CommandTabBox cmdBox1 = cmdTab.AddCommandTabBox();
                    cmdIDs   = new int[1];
                    TextType = new int[1];

                    cmdIDs[0]   = flyGroup.CmdID;
                    TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow | (int)swCommandTabButtonFlyoutStyle_e.swCommandTabButton_ActionFlyout;

                    bResult = cmdBox1.AddCommands(cmdIDs, TextType);

                    cmdTab.AddSeparator(cmdBox1, cmdIDs[0]);
                }
            }

            // Create a third-party icon in the context-sensitive menus of faces in parts
            // To see this menu, right click on any face in the part
            Frame swFrame;

            swFrame = m_iSwApp.Frame();
            bResult = swFrame.AddMenuPopupIcon3((int)swDocumentTypes_e.swDocPART, (int)swSelectType_e.swSelFACES, "third-party context-sensitive CSharp", m_addinID,
                                                "PopupCallbackFunction", "PopupEnable", "", cmdGroup.MainIconList);

            // create and register the shortcut menu
            registerID = m_iSwApp.RegisterThirdPartyPopupMenu();

            // add a menu break at the top of the shortcut menu
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Menu Break", m_addinID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Break);

            // add a couple of items to the shortcut menu
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test1", m_addinID, "TestCallback", "EnableTest", "", "Test1", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default);
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test2", m_addinID, "TestCallback", "EnableTest", "", "Test2", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default);

            // add a separator bar to the shortcut menu
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "separator", m_addinID, "", "", "", "", "", (int)swMenuItemType_e.swMenuItemType_Separator);

            // add another item to the shortcut menu
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "Test3", m_addinID, "TestCallback", "EnableTest", "", "Test3", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default);

            // add an icon to a menu bar of the shortcut menu
            bResult = m_iSwApp.AddItemToThirdPartyPopupMenu2(registerID, (int)swDocumentTypes_e.swDocPART, "", m_addinID, "TestCallback", "EnableTest", "", "NoOp", mainIcons[0], (int)swMenuItemType_e.swMenuItemType_Default);

            thisAssembly = null;
        }
Exemple #2
0
        public bool ConnectToSW(object thisSw, int cookie)
        {
            // �������� ��� ��������� � xml config
            Furniture.Helpers.SaveLoadSettings.SaveAllProperties();

            bool ret;
            _iSwApp = (ISldWorks)thisSw;
            if (!Properties.Settings.Default.CashModeAvailable)
            {
                Properties.Settings.Default.CashModeOn = false;
                Properties.Settings.Default.Save();
            }
            if (!Properties.Settings.Default.KitchenModeAvailable)
            {
                Properties.Settings.Default.KitchenModeOn = false;
                Properties.Settings.Default.Save();
            }
            _addinId = cookie;
            _iSwApp.SetAddinCallbackInfo(0, this, _addinId);

            if (!CheckSolid())
            {
                string strReg = Interaction.InputBox("������� ��������������� ���:", MyTitle, "", 0, 0);
                if (strReg != "")
                {

                    try
                    {
                        // ������ �����
                        // SaveInRegEdit(strReg);
                        Furniture.Helpers.SaveLoadSettings.AddOrUpdateAppSettings("SerialKey", strReg);

                        Properties.Settings.Default.AppRegCode = strReg;  // ������ �������
                        Properties.Settings.Default.Save();

                    }

                    catch (SecurityException ex)
                    {
                        Logging.Log.Instance.Fatal(ex, ex.Message.ToString() + "ConnectToSW");
                    }
                    catch (UnauthorizedAccessException ex)
                    {
                        Logging.Log.Instance.Fatal(ex, ex.Message.ToString() + "ConnectToSW");
                    }
                    finally
                    {
                        Properties.Settings.Default.AppRegCode = strReg;  // ������ �������
                        Properties.Settings.Default.Save();
                    }
                }
            }
            if (CheckSolid())
            {
                var dirName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);

                #region �������� ������ ����������� �����
                List<string> filesToDownload = new List<string>();
                filesToDownload.Add("Oracle.ManagedDataAccess.dll");
                filesToDownload.Add("log4net.dll");
                foreach (string file in filesToDownload)
                {
                    if (!File.Exists(Path.Combine(dirName, file)))
                    {
                        //�������..
                        UpdaterFromFtp.DownloadFromFtp(file);
                    }
                }

                #endregion

                #region ���������� ������ ����� ��� ����������
                string newFileLocation;

                string lastFileLocation = dirName + "\\Furniture.dll";
                string updFullName = dirName + "\\update_furniture.exe";
                var ss = new SecureString();
                foreach (var ch in Properties.Settings.Default.AdmUsrPsw)
                {
                    ss.AppendChar(ch);
                }
                var psi = new ProcessStartInfo
                              {
                                  UseShellExecute = false,
                                  Domain = Environment.UserDomainName
                              };
                if (CheckIsSolidUserInAdmin())
                {
                    psi.UserName = Properties.Settings.Default.AdmUsrName;
                    psi.Password = ss;
                }
                if (!File.Exists(updFullName))
                {
                    string updTmpPath;
                    if (DownloadUpdFrn(out updTmpPath))
                    {
                        psi.FileName = updTmpPath;
                        psi.Arguments = Path.GetDirectoryName(updTmpPath) + "\\update_furniture.exe" + "@" +
                                        updFullName;
                        Process.Start(psi);
                    }
                }

                #endregion

                #region ����������

                if (CheckUpdate(out newFileLocation))
                {
                    string arguments = newFileLocation + "@" + lastFileLocation;

                    if (File.Exists(updFullName))
                    {
                        if (!CheckIsSolidUserInAdmin())
                        {
                            psi = new ProcessStartInfo(updFullName, arguments);
                            psi.UseShellExecute = false;
                            psi.Domain = Environment.UserDomainName;
                        }
                        else
                        {
                            psi.FileName = updFullName;
                            psi.Arguments = arguments;
                        }
                        Process.Start(psi);
                        return false;
                    }
                }

                if (Properties.Settings.Default.CheckUpdateLib)
                    UpdatePatch();

                #endregion

                _iCmdMgr = _iSwApp.GetCommandManager(cookie);
                ChangeActiveDoc(false);

                _swEventPtr = (SldWorks)_iSwApp;
                _openDocs = new Hashtable();
                AttachEventHandlers();

                AddPmp();
                _swHandle = (IntPtr)((Frame)_iSwApp.Frame()).GetHWnd();
                WriteLogInfoOnServer();

                ret = true;

                hook = new KeyboardHook();
                hook.AddFilter(Keys.F, true, true, true);
                hook.AddFilter(Keys.Enter, false, false, false);
                hook.KeyPressed += new KeyboardHookEventHandler(hook_KeyPressed);
                hook.Install();
            }
            else
            {
                throw new Exception();
            }
            return ret;
        }