private bool populate_plugin_commands(CommandGroup group, List <Dictionary <String, String> > plugins) { // if (plugins_populated) { return false; } // All command items to be a menu and toolbar item int itemType = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); int n = plugins.Count; for (int i = 0; i < n; i++) { String cmd = plugins[i]["command"]; String strCallback = ""; // Special cases List and Exit if (cmd.ToUpper() == "EXIT") { strCallback = "call_exit"; } else if (cmd == "") { strCallback = "call_list"; } else { strCallback = PluginCall.prefixed_callback(plugins[i]["command"]); } plugin_count_id++; strCallback = PluginCall.prefixed_callback(plugins[i]["command"]); group.AddCommandItem2(plugins[i]["name"], (i + 1), plugins[i]["hint"], plugins[i]["tooltip"], Convert.ToInt16(plugins[i]["icon_index"]), strCallback, "enable_plugin", Convert.ToInt16(plugins[i]["id"]), itemType); } return(true); }
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])); }
private int AddDownloadFromServerCommand(CommandGroup commandGroup) { return(commandGroup.AddCommandItem2( "DownloadFromServer", _lastItemIndex, "Downloads a document from the server", "Downloads a document", 1, nameof(DownloadFromServer), nameof(CommandAlwaysEnabled), _downloadFromServerCmdId, (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem))); }
private int AddSaveAndUploadCommand(CommandGroup commandGroup) { return(commandGroup.AddCommandItem2( "SaveAndUpload", _lastItemIndex, "Saves the current document and uploads it", "Saves and uploads the document", 6, nameof(SaveAndUpload), nameof(CommandAlwaysEnabled), _saveAndUploadToServerCmdId, (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem))); }
private int AddDeleteDocumentCommand(CommandGroup commandGroup) { return(commandGroup.AddCommandItem2( "DeleteDocument", _lastItemIndex, "Deletes a document", "Deletes a document", 2, nameof(DeleteDocument), nameof(CommandAlwaysEnabled), _deleteDocument, (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem))); }
private int AddSaveWithNewIdAndUploadCommand(CommandGroup commandGroup) { return(commandGroup.AddCommandItem2( "SaveWithNewIdAndUpload", _lastItemIndex, "Saves the current document with a new ID and uploads it", "Saves with a new ID and upload", 5, nameof(SaveWithNewIdAndUpload), nameof(CommandAlwaysEnabled), _saveWithNewIdAndUploadCmdId, (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem))); }
private int AddGenerateNewIdCommand(CommandGroup commandGroup) { return(commandGroup.AddCommandItem2( "NewId", _lastItemIndex, "Generates a new document ID", "Generates ID", 3, nameof(GenerateNewId), nameof(CommandAlwaysEnabled), _generateNewIdCmdId, (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem))); }
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(); }
public int Ajouter(CommandGroup CmdGrp) { CommandIndex = CmdGrp.AddCommandItem2(Titre, Position, InfoBulle, InfoBulle, IndexImage, CallbackFunction, EnableMethod, AddinId, Options); return(CommandIndex); }
private void CreateCommandItems(CommandGroup cmdGroup, int groupId, Enum[] cmds, Delegate callbackMethod, Delegate enableMethod) { var callbackMethodName = nameof(OnCommandClick); var enableMethodName = nameof(OnCommandEnable); for (int i = 0; i < cmds.Length; i++) { var cmd = cmds[i]; var cmdTitle = ""; var cmdToolTip = ""; swCommandItemType_e menuToolbarOpts = 0; swWorkspaceTypes_e suppWorkSpaces = 0; if (!cmd.TryGetAttribute <DisplayNameAttribute>( att => cmdTitle = att.DisplayName)) { cmdTitle = cmd.ToString(); } if (!cmd.TryGetAttribute <DescriptionAttribute>( att => cmdToolTip = att.Description)) { cmdToolTip = cmd.ToString(); } if (!cmd.TryGetAttribute <CommandItemInfoAttribute>( att => { if (att.HasMenu) { menuToolbarOpts |= swCommandItemType_e.swMenuItem; } if (att.HasToolbar) { menuToolbarOpts |= swCommandItemType_e.swToolbarItem; } suppWorkSpaces = att.SupportedWorkspaces; })) { menuToolbarOpts = swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem; suppWorkSpaces = swWorkspaceTypes_e.All; } if (menuToolbarOpts == 0) { throw new InvalidMenuToolbarOptionsException(cmd); } var cmdId = Convert.ToInt32(cmd); var cmdName = $"{groupId}.{cmdId}"; m_CachedCmdsEnable.Add(cmdName, suppWorkSpaces); m_CallbacksParams.Add(cmdName, new Tuple <Delegate, Enum>(callbackMethod, cmd)); if (enableMethod != null) { m_EnableParams.Add(cmdName, new Tuple <Delegate, Enum>(enableMethod, cmd)); } var callbackFunc = $"{callbackMethodName}({cmdName})"; var enableFunc = $"{enableMethodName}({cmdName})"; cmdGroup.AddCommandItem2(cmdTitle, -1, cmdToolTip, cmdTitle, i, callbackFunc, enableFunc, cmdId, (int)menuToolbarOpts); } }