Example #1
0
        private Dictionary <ICommandSpec, int> CreateCommandItems(CommandGroup cmdGroup, int groupId, ICommandSpec[] cmds)
        {
            var createdCmds = new Dictionary <ICommandSpec, int>();

            var callbackMethodName = nameof(OnCommandClick);
            var enableMethodName   = nameof(OnCommandEnable);

            for (int i = 0; i < cmds.Length; i++)
            {
                var cmd = cmds[i];

                swCommandItemType_e menuToolbarOpts = 0;

                if (cmd.HasMenu)
                {
                    menuToolbarOpts |= swCommandItemType_e.swMenuItem;
                }

                if (cmd.HasToolbar)
                {
                    menuToolbarOpts |= swCommandItemType_e.swToolbarItem;
                }

                if (menuToolbarOpts == 0)
                {
                    throw new InvalidMenuToolbarOptionsException(cmd);
                }

                var cmdName = $"{groupId}.{cmd.UserId}";

                m_Commands.Add(cmdName, cmd);

                var callbackFunc = $"{callbackMethodName}({cmdName})";
                var enableFunc   = $"{enableMethodName}({cmdName})";

                if (cmd.HasSpacer)
                {
                    cmdGroup.AddSpacer2(-1, (int)menuToolbarOpts);
                }

                var cmdIndex = cmdGroup.AddCommandItem2(cmd.Title, -1, cmd.Tooltip,
                                                        cmd.Title, i, callbackFunc, enableFunc, cmd.UserId,
                                                        (int)menuToolbarOpts);

                createdCmds.Add(cmd, cmdIndex);

                Logger.Log($"Created command {cmdIndex} for {cmd}");
            }

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

            return(createdCmds.ToDictionary(p => p.Key, p => cmdGroup.CommandID[p.Value]));
        }
Example #2
0
        private bool add_commands()
        {
            int err = 0;

            String mCommandGroupName = "Utilities";
            int    nth_group         = mCommandGroupId - mCommandGroupId_0;

            if (null != mCommandGroup)
            {
                Marshal.ReleaseComObject(mCommandGroup);
                mCommandGroup = null;
                GC.Collect();
                mCommandGroup = mCommandManager.GetCommandGroup(mCommandGroupId);
            }

            if (null == mCommandGroup)
            {
                mCommandGroup = mCommandManager.CreateCommandGroup2(mCommandGroupId, mCommandGroupName, "Utility scripts for automating tasks.",
                                                                    "Plugins used to automate solidworks tasks", -1, false, ref err);

                if (err != 0 && err != (int)swCreateCommandGroupErrors.swCreateCommandGroup_Success)
                {
                    String str_err_message = "Error creating the command group.\n";
                    if (err == (int)swCreateCommandGroupErrors.swCreateCommandGroup_Failed)
                    {
                        str_err_message += "Failed.\n";
                    }
                    if (err == (int)swCreateCommandGroupErrors.swCreateCommandGroup_Exceeds_ToolBarIDs)
                    {
                        str_err_message += "Exceeds toolbar ids.\n";
                    }
                }
            }

            if (mCommandGroup != null)
            {
                mCommandGroup.LargeIconList = plugin_icon_img_path;
                mCommandGroup.SmallIconList = plugin_icon_img_path;
                mCommandGroup.LargeMainIcon = Path.GetFullPath(Path.Combine(working_dir(), "MainIconLarge.png"));

                plugins_populated = !plugins_populated && populate_plugin_commands(mCommandGroup, plugin_info);

                mCommandGroup.HasMenu    = true;
                mCommandGroup.HasToolbar = true;

                bool activated = mCommandGroup.Activate();
                //System.Windows.Forms.MessageBox.Show("id:" + mCommandGroupId + "group# " + nth_group + "groups count:" + ((int)mCommandManager.NumberOfGroups));
                return(activated);
            }
            else
            {
                return(false);
            }
        }
        public void SetupCommands()
        {
            BitmapHandler imageManager = new BitmapHandler();
            Assembly thisAssembly;
            int cmdIndex0, cmdIndex1, cmdIndex2, cmdIndex3, cmdIndex4, cmdIndex5;
            string Title = "Gazebo", ToolTip = "Tools for exporting this assembly as a robot for simulation in Gazebo";

            int cmdGroupErr = 0;
            bool ignorePrevious = false;

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

            int[] knownIDs = new int[3] {settingsItemID, manageRobotItemID, exportItemID};

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

            //Get a reference to the current assembly and load bitmaps form it into a new command group
            thisAssembly = System.Reflection.Assembly.GetAssembly(this.GetType());
            cmdGroup = iCmdMgr.CreateCommandGroup2(cmdGroupID, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr);
            cmdGroup.LargeIconList = imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.ToolbarLarge.bmp", thisAssembly);
            cmdGroup.SmallIconList = imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.ToolbarSmall.bmp", thisAssembly);
            cmdGroup.LargeMainIcon = imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.MainIconLarge.bmp", thisAssembly);
            cmdGroup.SmallMainIcon = imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.MainIconSmall.bmp", thisAssembly);
            GazeboLogo = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.Gazebo.png", thisAssembly));
            MotorPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.motor.png", thisAssembly));
            EncoderPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.QuadratureEncoder.png", thisAssembly));
            PotPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.AnalogPotentiometer.png", thisAssembly));
            GyroPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.Gyro.png", thisAssembly));
            RangefinderPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.Ultrasonic.png", thisAssembly));
            CameraPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.Camera.png", thisAssembly));
            ExtLimitSwitchPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.LimitSwitch_E.png", thisAssembly));
            IntLimitSwitchPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.LimitSwitch_I.png", thisAssembly));
            PistonPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.Piston.png", thisAssembly));
            NewLinkPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.NewLinkIcon.png", thisAssembly));
            NewJointPic = Image.FromFile(imageManager.CreateFileFromResourceBitmap("GazeboExporter.Images.NewJointIcon.png", thisAssembly));

            int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem);
            cmdIndex3 = cmdGroup.AddCommandItem2("Exporter Settings", -1, "Change exporter plugin settings", "Exporter settings", 0, "settingsCB", "settingsEN", settingsItemID, menuToolbarOption);
            cmdIndex4 = cmdGroup.AddCommandItem2("Manage Robot", -1, "Manage robot paramters", "Manage Robot", 1, "manageRobotCB", "manageRobotEN", manageRobotItemID, menuToolbarOption);
            cmdIndex5 = cmdGroup.AddCommandItem2("Export", -1, "Save this robot as a Gazebo package", "Export", 2, "exportCB", "exportEN", exportItemID, menuToolbarOption);

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

            cmdTab = iCmdMgr.GetCommandTab((int)swDocumentTypes_e.swDocASSEMBLY, 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 = 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 = iCmdMgr.AddCommandTab((int)swDocumentTypes_e.swDocASSEMBLY, Title);

                cmdBox = cmdTab.AddCommandTabBox();

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

                cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex3);
                cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex4);
                cmdIDs[2] = cmdGroup.get_CommandID(cmdIndex5);

                TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
                TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
                TextType[2] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
                /*int[] cmdIDs = new int[2];
                int[] TextType = new int[2];

                cmdIDs[0] = cmdGroup.get_CommandID(cmdIndex4);
                cmdIDs[1] = cmdGroup.get_CommandID(cmdIndex5);

                TextType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;
                TextType[1] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextBelow;*/

                cmdBox.AddCommands(cmdIDs, TextType);
            }

            thisAssembly = null;
            imageManager.Dispose();
        }
Example #4
0
        public void CreerMenu()
        {
            try
            {
                int cmdGroupErr = 0;
                CmdGrp = CmdMgr.CreateCommandGroup2(Id, Titre, Info, Info, -1, true, ref cmdGroupErr);
                Log.Message("   " + Titre);
                Log.Message("      Création : " + (swCreateCommandGroupErrors)cmdGroupErr);

                // Création des icons
                CmdGrp.IconList     = CreerIcons();
                CmdGrp.MainIconList = CmdGrp.IconList;

                // Nb de cmde dans le menu
                var index = 0;
                // Ajout des commandes du menu
                foreach (var listeCmd in ListeGrp)
                {
                    index += listeCmd.Count;
                    foreach (var Cmd in listeCmd)
                    {
                        Cmd.Ajouter(CmdGrp);
                    }
                }

                // On parcours les commandes à l'envers pour y inserer les séparateurs
                for (int i = ListeGrp.Count - 1; i > 0; i--)
                {
                    var listeCmd = ListeGrp[i];
                    index -= listeCmd.Count;
                    CmdGrp.AddSpacer2(index, (int)swCommandItemType_e.swMenuItem);

                    // On met à jour l'index en fonction du nb de séparateur ajouté
                    foreach (var cmd in listeCmd)
                    {
                        cmd.CommandIndex += i;
                    }
                }

                // On active le groupe
                CmdGrp.HasToolbar = true;
                CmdGrp.HasMenu    = true;
                CmdGrp.Activate();

                // Mise à jour des CommandId après activation des menus
                foreach (var listeCmd in ListeGrp)
                {
                    foreach (var Cmd in listeCmd)
                    {
                        Cmd.SetCommandId(CmdGrp);
                        Log.Message("        " + Cmd.Titre + "-> " + Cmd.CommandId + " // " + Cmd.AddinId);
                    }
                }



                CmdGrp.Activate();
            }
            catch (Exception e)
            { this.LogMethode(new Object[] { e }); }
        }