/// <summary>
        /// Set a Loop Box item in Winform Menu
        /// </summary>
        /// <param name="menu"></param>
        /// <param name="component"></param>
        /// <param name="itemName">item's name for set infront of the name.</param>
        /// <param name="enable"></param>
        /// <param name="NameList"></param>
        /// <param name="IconList"></param>
        /// <param name="defaultIndex"></param>
        /// <param name="valueName"></param>
        public static void AddLoopBoexItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, bool enable,
                                           string[] NameList, int defaultIndex, string valueName, Bitmap[] IconList = null)
        {
            if (defaultIndex > NameList.Length - 1)
            {
                throw new ArgumentOutOfRangeException("defaultIndex");
            }
            if (IconList != null && IconList.Length != NameList.Length)
            {
                throw new ArgumentOutOfRangeException("IconList");
            }

            int index = component.GetValuePub(valueName, defaultIndex);
            ToolStripMenuItem item = new ToolStripMenuItem(itemName + LanguagableComponent.GetTransLation(new string[] { ": ", ":" }) + NameList[index]);

            item.ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to switch to ", "单击以切换到" }) +
                               NameList[(index + 1) % NameList.Length];

            if (IconList != null)
            {
                item.Image = IconList[index];
            }
            item.Enabled = enable;

            item.Click += Item_Click;
            void Item_Click(object sender, EventArgs e)
            {
                component.SetValuePub(valueName, (index + 1) % NameList.Length);
                component.ExpireSolution(true);
            }

            menu.Items.Add(item);
        }
        public static void AddComboBoxItemSingle(ToolStripDropDown menu, LanguagableComponent component, ItemSet <bool> set, string valueName, int index)
        {
            GH_DocumentObject.Menu_AppendItem(menu, set.itemName, click, set.itemIcon, set.enable, component.GetValuePub(valueName, 0) == index).ToolTipText = set.itemTip;

            void click(object sender, EventArgs e)
            {
                component.SetValuePub(valueName, index);
            }
        }
        public static void AddComboBoxItemMulty(ToolStripDropDown menu, LanguagableComponent component, ItemSet <bool> set)
        {
            GH_DocumentObject.Menu_AppendItem(menu, set.itemName, click, set.itemIcon, set.enable, component.GetValuePub(set.valueName, set.Default)).ToolTipText = set.itemTip;

            void click(object sender, EventArgs e)
            {
                component.SetValuePub(set.valueName, true);
            }
        }
示例#4
0
        public static string GetReadMessage(int successCount, int failCount)
        {
            string all = successCount.ToString() + LanguagableComponent.GetTransLation(new string[] { " data imported successfully!", "个数据导入成功!" });

            if (failCount > 0)
            {
                all += "\n" + failCount.ToString() + LanguagableComponent.GetTransLation(new string[] { " data imported failed!", "个数据导入失败!" });
            }
            return(all);
        }
        public static void AddComboBoxItemsMulty(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, ItemSet <bool>[] sets)
        {
            ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable);

            foreach (var set in sets)
            {
                AddComboBoxItemMulty(item.DropDown, component, set);
            }

            menu.Items.Add(item);
        }
        public static void AddComboBoxItemsSingle(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, string valueName, Bitmap itemIcon, bool enable, ItemSet <bool>[] sets)
        {
            ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable);

            for (int i = 0; i < sets.Length; i++)
            {
                AddComboBoxItemSingle(item.DropDown, component, sets[i], valueName, i);
            }

            menu.Items.Add(item);
        }
        public static void AddTextItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable,
                                       string Default, string valueName, int width = 100)
        {
            bool flag = true;

            GH_DocumentObject.Menu_AppendTextItem(menu, itemName, BoxItemKeyDown, textchanged, true, width, true);
            void textchanged(GH_MenuTextBox sender, string newText)
            {
                component.SetValuePub(valueName, newText, flag);
                flag = false;
                component.ExpireSolution(true);
            }
        }
        public static void AddNumberBoxItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable,
                                            double Default, double Min, double Max, string valueName, int width = 150)
        {
            if (Max <= Min)
            {
                throw new ArgumentOutOfRangeException("Max less than Min!");
            }

            bool              flag    = true;
            string            English = "Value must be in " + Min.ToString() + " - " + Max.ToString() + ". Default is " + Default.ToString() + ".";
            string            Chinese = "输入值域为 " + Min.ToString() + " - " + Max.ToString() + ", 默认为 " + Default.ToString() + "。";
            string            tip     = itemTip + LanguagableComponent.GetTransLation(new string[] { English, Chinese });
            ToolStripMenuItem item    = CreateOneItem(itemName, tip, itemIcon, enable);

            var slider = new GH_DigitScroller
            {
                MinimumValue  = (decimal)Min,
                MaximumValue  = (decimal)Max,
                DecimalPlaces = 3,
                Value         = (decimal)Default,
                Size          = new Size(width, 24)
            };

            slider.ValueChanged += Slider_ValueChanged;

            void Slider_ValueChanged(object sender, GH_DigitScrollerEventArgs e)
            {
                double result = (double)e.Value;

                result = result >= Min ? result : Min;
                result = result <= Max ? result : Max;
                component.SetValuePub(valueName, result, flag);
                flag = false;
                component.ExpireSolution(true);
            }

            WinFormPlus.AddLabelItem(item.DropDown, itemName, tip);
            GH_DocumentObject.Menu_AppendCustomItem(item.DropDown, slider);

            GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Number", "重置数值" }), resetClick, Properties.Resources.ResetLogo,
                                              true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset Number.", "点击以重置数值。" });
            void resetClick(object sender, EventArgs e)
            {
                component.SetValuePub(valueName, Default);
                component.ExpireSolution(true);
            }

            menu.Items.Add(item);
        }
示例#9
0
        public static void ExportSaveFileDialog(string defaultName, Action <string> saveAction)
        {
            System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog();

            saveFileDialog.Title    = LanguagableComponent.GetTransLation(new string[] { "Set a Paht", "设定一个路径" });
            saveFileDialog.Filter   = "*.txt|*.txt";
            saveFileDialog.FileName = "defaultName";
            saveFileDialog.SupportMultiDottedExtensions = false;
            saveFileDialog.RestoreDirectory             = true;

            if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                saveAction.Invoke(saveFileDialog.FileName);
            }
        }
示例#10
0
        public static string GetNamedPath(IGH_ActiveObject obj, string name, string suffix = ".txt", bool create = false)
        {
            string result = GetNamedLocationWithObject(obj, name, suffix, create);

            if (result != null)
            {
                return(result);
            }
            var strs = FindObjectInAssemblyFolder(name);

            if (strs.Count() > 0)
            {
                return(strs.First());
            }
            obj.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, LanguagableComponent.GetTransLation(new string[]
            {
                $"Finding {name} Failed!", $"{name} 查找失败!"
            }));
            return(null);
        }
        public static void AddColorBoxItems(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable, ItemSet <Color>[] sets)
        {
            ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable);

            foreach (var set in sets)
            {
                AddColorBoxItem(item.DropDown, component, set);
            }

            GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Color", "重置颜色" }), resetClick, Properties.Resources.ResetLogo,
                                              true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset colors.", "点击以重置颜色。" });
            void resetClick(object sender, EventArgs e)
            {
                foreach (var set in sets)
                {
                    component.SetValuePub(set.valueName, set.Default);
                }
                component.ExpireSolution(true);
            }

            menu.Items.Add(item);
        }
示例#12
0
        public static void ImportOpenFileDialog(Action <string> openAction)
        {
            System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog();
            openFileDialog.Title = LanguagableComponent.GetTransLation(new string[] { "Select a template", "选择一个模板" });


            openFileDialog.Filter = "*.txt|*.txt";


            openFileDialog.FileName = string.Empty;


            openFileDialog.Multiselect = false;


            openFileDialog.RestoreDirectory = true;


            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                openAction.Invoke(openFileDialog.FileName);
            }
        }
        public static void AddColorBoxItem(ToolStripDropDown menu, LanguagableComponent component, string itemName, string itemTip, Bitmap itemIcon, bool enable,
                                           Color @default, string valueName)
        {
            bool flag = true;
            ToolStripMenuItem item = CreateOneItem(itemName, itemTip, itemIcon, enable);

            GH_DocumentObject.Menu_AppendColourPicker(item.DropDown, component.GetValuePub(valueName, @default), textcolorChange);
            void textcolorChange(GH_ColourPicker sender, GH_ColourPickerEventArgs e)
            {
                component.SetValuePub(valueName, e.Colour, flag);
                component.ExpireSolution(true);
                flag = false;
            }

            GH_DocumentObject.Menu_AppendItem(item.DropDown, LanguagableComponent.GetTransLation(new string[] { "Reset Color", "重置颜色" }), resetClick, Properties.Resources.ResetLogo,
                                              true, false).ToolTipText = LanguagableComponent.GetTransLation(new string[] { "Click to reset colors.", "点击以重置颜色。" });
            void resetClick(object sender, EventArgs e)
            {
                component.SetValuePub(valueName, @default);
                component.ExpireSolution(true);
            }

            menu.Items.Add(item);
        }
 public static void AddColorBoxItem(ToolStripDropDown menu, LanguagableComponent component, ItemSet <Color> set)
 {
     AddColorBoxItem(menu, component, set.itemName, set.itemTip, set.itemIcon, set.enable, set.Default, set.valueName);
 }
示例#15
0
 public static string GetWriteMessage(string path)
 {
     return(LanguagableComponent.GetTransLation(new string[] { "Export successfully! \n Location: ", "导出成功!\n 位置:" }) + path);
 }