/// <summary> /// Adds tab completion for a specific command /// </summary> public void AddTab(CommandTab action, params string[] commands) { foreach (string c in commands) { CommandTabs.Add(c, action); } }
/// <summary> /// /Создание нового таббокса /// </summary> /// <param name="cmdTab">Лента Союз-PLM</param> private static void CreateNewTab(CommandTab cmdTab) { CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); bool bResult = cmdBox.AddCommands(cmdIDs, TextType); Debug.Print(bResult.ToString()); cmdTab.Active = true; }
/// <summary> /// Проверка наличия команд ТТ и их таббокса. При отсутствии - восстановление. /// </summary> /// <param name="cmdTab">Лента Союз-PLM</param> private static void RestoreTab(CommandTab cmdTab) { bool tabexists = false; int trcount = 0; // Найдём все CommandTabBox int tblen = cmdTab.GetCommandTabBoxCount(); object[] cmdTabBoxes = (object[])cmdTab.CommandTabBoxes(); // Перебираем TabBoxes и ищем - есть такой с командами ТТ? for (int i = tblen - 1; i >= 0; i--) { object idObject = null; object textTypeObject = null; // Выбираем команды из таббокса int cmdcount = (cmdTabBoxes[i] as CommandTabBox).GetCommands(out idObject, out textTypeObject); int[] ids = (int[])idObject; trcount = 0; // Ищем команды ТТ for (int j = 0; j < cmdIDs.Length; j++) { for (int k = 0; k < cmdcount; k++) { if (cmdIDs[j] == ids[k]) { trcount++; } } } // Если у таббокса команд не больше ccomcount, и есть команды ТТ, то это наш таббокс. if (cmdcount <= ccomcount && trcount > 0) { // Проверим число команд. Если не хватает, то пересоздадим if (trcount != ccomcount) { (cmdTabBoxes[i] as CommandTabBox).RemoveCommands(cmdIDs); (cmdTabBoxes[i] as CommandTabBox).AddCommands(cmdIDs, TextType); } tabexists = true; break; } } // Если таббокс ТТ не нашёлся - пересоздадим его if (!tabexists) { CreateNewTab(cmdTab); } }
/// <summary> /// Настройка команд ТТ в интерфейсе SolidWorks /// </summary> public static void RefreshUI() { CommandTab cmdTab = SwAddin.Instance.UiManager.CmdMgr.GetCommandTab(doctype, Title); if (cmdTab == null) { return; } PrepareCmd(); if (NeedRecreate()) { DeleteOldTab(cmdTab); CreateNewTab(cmdTab); } else { RestoreTab(cmdTab); } }
private bool TryClearTab(string tabName, swDocumentTypes_e docType, ref CommandTab cmdTab) { var cmdTabBoxes = (object[])cmdTab.CommandTabBoxes(); if (cmdTabBoxes?.Any() == true) { foreach (CommandTabBox cmdTabBox in cmdTabBoxes) { cmdTab.RemoveCommandTabBox(cmdTabBox); } if (cmdTab.GetCommandTabBoxCount() > 0) { m_Logger.Log($"Failed to clear command tab boxes in '{tabName}' in {docType}", LoggerMessageSeverity_e.Debug); var removeTabRes = CmdMgr.RemoveCommandTab(cmdTab); if (!removeTabRes) //NOTE: sometimes API returns false despite the tab been removed correctly { removeTabRes = CmdMgr.GetCommandTab((int)docType, tabName) == null; } if (removeTabRes) { cmdTab = CmdMgr.AddCommandTab((int)docType, tabName); return(true); } else { return(false); } } else { return(true); } } else { return(true); } }
/// <summary> /// Удаление существующих команд и их таббокса /// </summary> /// <param name="cmdTab">Лента Союз-PLM</param> private static void DeleteOldTab(CommandTab cmdTab) { int trcount = 0; // Найдём все CommandTabBox int tblen = cmdTab.GetCommandTabBoxCount(); object[] cmdTabBoxes = (object[])cmdTab.CommandTabBoxes(); // Перебираем TabBoxes и ищем - есть такой с нужными командами? for (int i = tblen - 1; i >= 0; i--) { object idObject = null; object textTypeObject = null; // Выбираем команды из таббокса int cmdcount = (cmdTabBoxes[i] as CommandTabBox).GetCommands(out idObject, out textTypeObject); int[] ids = (int[])idObject; trcount = 0; // Перебираем команды ТТ и удаляем их из таббокса for (int j = 0; j < cmdIDs.Length; j++) { for (int k = 0; k < cmdcount; k++) { if (cmdIDs[j] == ids[k]) { trcount++; (cmdTabBoxes[i] as CommandTabBox).RemoveCommands(cmdIDs); } } } // Если у таббокса ccomcount команд, и есть команды ТТ, то это наш таббокс. удалим его. if (cmdcount == ccomcount && trcount > 0) { cmdTab.RemoveCommandTabBox((CommandTabBox)cmdTabBoxes[i]); break; } } }
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(); }
/// <summary> /// Adds tab completion for a specific command /// </summary> public void AddTab(CommandTab action, params string[] commands) { foreach (string c in commands) CommandTabs.Add(c, action); }
public void CreerOnglet() { try { foreach (eTypeDoc T in Enum.GetValues(typeof(eTypeDoc))) { var Liste = new List <List <Cmde> >(); // Liste les cmds à afficher dans cet onglet pour ce type de document foreach (var listeCmd in ListeGrp) { var liste = new List <Cmde>(); foreach (var Cmd in listeCmd) { if (Cmd.Type.HasFlag(T)) { liste.Add(Cmd); } } if (liste.Count > 0) { Liste.Add(liste); } } // Si la liste comprend des cmds if (Liste.Count > 0) { CommandTab cmdTab = CmdMgr.GetCommandTab((int)Sw.eGetSwTypeDoc(T), Titre); if (cmdTab.IsRef()) { CmdMgr.RemoveCommandTab(cmdTab); } cmdTab = CmdMgr.AddCommandTab((int)Sw.eGetSwTypeDoc(T), Titre); Boolean sep = false; foreach (var ListeCmd in Liste) { var ListeId = new List <int>(); var ListePosition = new List <int>(); // Liste les cmds, on recupère les Id et la position des textes foreach (var Cmd in ListeCmd) { ListeId.Add(Cmd.CommandId); ListePosition.Add((int)Cmd.PositionTexte); } // On ajoute les cmds CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); cmdBox.AddCommands(ListeId.ToArray(), ListePosition.ToArray()); // Si c'est le deuxième groupe, on ajoute un séparateur // !!!! On ne peut ajouter un séparateur que devant un nouveau CommandTabBox if (sep) { cmdTab.AddSeparator(cmdBox, ListeId[0]); } sep = true; } } } } catch (Exception e) { this.LogMethode(new Object[] { e }); } }
private void AddCmdbox(List <Dictionary <int, KeyValuePair <CommandType, int> > > tabIdList, ref ICommandGroup cmdGroup, ref CommandTab cmdTab) { int index = 0; foreach (var boxIds in tabIdList) { List <int> cmdIDs = new List <int>(); List <int> TextType = new List <int>(); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); foreach (var cmdId in boxIds) { switch (cmdId.Value.Key) { case CommandType.Command: cmdIDs.Add(cmdGroup.get_CommandID(cmdId.Key)); break; case CommandType.FlyoutCommand: cmdIDs.Add(cmdId.Key); break; } TextType.Add(cmdId.Value.Value); index++; } bool result = cmdBox.AddCommands(cmdIDs.ToArray(), TextType.ToArray()); } }
/// <summary> /// The add command mgr. /// </summary> public void AddCommandMgr() { if (this.iBmp == null) { this.iBmp = new BitmapHandler(); } const string Title = "Save PDF"; const string ToolTip = "Save PDF"; int[] docTypes = { (int)swDocumentTypes_e.swDocASSEMBLY, (int)swDocumentTypes_e.swDocDRAWING, (int)swDocumentTypes_e.swDocPART }; Assembly thisAssembly = Assembly.GetAssembly(this.GetType()); int cmdGroupErr = 0; bool ignorePrevious = false; object registryIDs; // get the ID information stored in the registry bool getDataResult = this.CmdMgr.GetGroupDataFromRegistry(MainCmdGroupId, out registryIDs); int[] knownIDs = { MainItemId1 }; if (getDataResult) { if (!this.CompareIDs((int[])registryIDs, knownIDs)) { // if the IDs don't match, reset the commandGroup ignorePrevious = true; } } ICommandGroup cmdGroup = this.CmdMgr.CreateCommandGroup2( MainCmdGroupId, Title, ToolTip, "", -1, ignorePrevious, ref cmdGroupErr); cmdGroup.LargeIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarLarge.bmp", thisAssembly); cmdGroup.SmallIconList = this.iBmp.CreateFileFromResourceBitmap("SavePDF.ToolbarSmall.bmp", thisAssembly); const int menuToolbarOption = (int)(swCommandItemType_e.swMenuItem | swCommandItemType_e.swToolbarItem); int cmdIndex0 = cmdGroup.AddCommandItem2( "Save PDF", -1, "Save PDF Options", "Save PDF Options", 0, "ShowPMP", "EnablePMP", MainItemId1, menuToolbarOption); cmdGroup.HasToolbar = true; cmdGroup.HasMenu = true; cmdGroup.Activate(); foreach (int type in docTypes) { CommandTab cmdTab = this.CmdMgr.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 = this.CmdMgr.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 = this.CmdMgr.AddCommandTab(type, Title); CommandTabBox cmdBox = cmdTab.AddCommandTabBox(); var cmdIDs = new int[1]; var textType = new int[1]; cmdIDs[0] = cmdGroup.CommandID[cmdIndex0]; textType[0] = (int)swCommandTabButtonTextDisplay_e.swCommandTabButton_TextHorizontal; cmdBox.AddCommands(cmdIDs, textType); } } thisAssembly = null; }