Esempio n. 1
0
        protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
        {
            Menu_AppendSeparator(menu);
            Menu_AppendItem(menu, "Select the converter you want to use:");
            var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

            foreach (var kit in kits)
            {
                Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SetConverterFromKit(kit.Name); }, true,
                                kit.Name == Kit.Name);
            }

            Menu_AppendSeparator(menu);

            if (InputType == "Stream" || InputType == "Branch")
            {
                var autoReceiveMi = Menu_AppendItem(menu, "Receive automatically", (s, e) =>
                {
                    AutoReceive = !AutoReceive;
                    RhinoApp.InvokeOnUiThread((Action) delegate { OnDisplayExpired(true); });
                }, true, AutoReceive);
                autoReceiveMi.ToolTipText =
                    "Toggle automatic receiving. If set, any upstream change will be pulled instantly. This only is applicable when receiving a stream or a branch.";
            }
            else
            {
                var autoReceiveMi = Menu_AppendItem(menu,
                                                    "Automatic receiving is disabled because you have specified a direct commit.");
                autoReceiveMi.ToolTipText =
                    "To enable automatic receiving, you need to input a stream rather than a specific commit.";
            }

            base.AppendAdditionalComponentMenuItems(menu);
        }
        public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
        {
            try
            {
                var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

                Menu_AppendSeparator(menu);
                Menu_AppendItem(menu, "Select the converter you want to use:");
                if (CanDisableConversion)
                {
                    Menu_AppendItem(menu, "Do Not Convert", (s, e) =>
                    {
                        SelectedKitName = "None";
                        SetConverter();
                        ExpireSolution(true);
                    }, true, Kit == null);
                }

                foreach (var kit in kits)
                {
                    Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SelectedKitName = kit.Name; SetConverter(); ExpireSolution(true); }, true,
                                    kit.Name == Kit?.Name);
                }

                Menu_AppendSeparator(menu);
            }
            catch (Exception e)
            {
                Menu_AppendItem(menu, "An error occurred while fetching Kits", null, false);
            }
        }
        protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
        {
            Menu_AppendSeparator(menu);
            var menuItem = Menu_AppendItem(menu, "Select the converter you want to use:", null, false);

            menuItem.Enabled = false;
            var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino6);

            foreach (var kit in kits)
            {
                Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SetConverterFromKit(kit.Name); }, true,
                                kit.Name == Kit.Name);
            }

            Menu_AppendSeparator(menu);

            if (OutputWrappers != null)
            {
                if (OutputWrappers.Count != 0)
                {
                    Menu_AppendSeparator(menu);
                    foreach (var ow in OutputWrappers)
                    {
                        Menu_AppendItem(menu, $"View commit {ow.CommitId} @ {ow.ServerUrl} online ↗",
                                        (s, e) => System.Diagnostics.Process.Start($"{ow.ServerUrl}/streams/{ow.StreamId}/commits/{ow.CommitId}"));
                    }
                }
            }
            Menu_AppendSeparator(menu);


            base.AppendAdditionalComponentMenuItems(menu);
        }
Esempio n. 4
0
        protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
        {
            Menu_AppendSeparator(menu);
            var menuItem = Menu_AppendItem(menu, "Select the converter you want to use:");

            menuItem.Enabled = false;
            var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

            foreach (var kit in kits)
            {
                Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SetConverterFromKit(kit.Name); }, true,
                                kit.Name == Kit.Name);
            }

            Menu_AppendSeparator(menu);

            var cacheMi = Menu_AppendItem(menu, "Use default cache", (s, e) => UseDefaultCache = !UseDefaultCache, true,
                                          UseDefaultCache);

            cacheMi.ToolTipText =
                "It's advised you always use the default cache, unless you are providing a list of custom transports and you understand the consequences.";

            var autoSendMi = Menu_AppendItem(menu, "Send automatically", (s, e) =>
            {
                AutoSend = !AutoSend;
                Rhino.RhinoApp.InvokeOnUiThread((Action) delegate { OnDisplayExpired(true); });
            }, true, AutoSend);

            autoSendMi.ToolTipText =
                "Toggle automatic data sending. If set, any change in any of the input parameters of this component will start sending.\n Please be aware that if a new send starts before an old one is finished, the previous operation is cancelled.";

            if (OutputWrappers.Count != 0)
            {
                Menu_AppendSeparator(menu);
                foreach (var ow in OutputWrappers)
                {
                    Menu_AppendItem(menu, $"View commit {ow.CommitId} @ {ow.ServerUrl} online ↗",
                                    (s, e) => System.Diagnostics.Process.Start($"{ow.ServerUrl}/streams/{ow.StreamId}/commits/{ow.CommitId}"));
                }
            }
            Menu_AppendSeparator(menu);

            if (CurrentComponentState == "sending")
            {
                Menu_AppendItem(menu, "Cancel Send", (s, e) =>
                {
                    CurrentComponentState = "expired";
                    RequestCancellation();
                });
            }

            base.AppendAdditionalComponentMenuItems(menu);
        }
Esempio n. 5
0
        private void AddSpeckleMenu(object sender, ElapsedEventArgs e)
        {
            if (Grasshopper.Instances.DocumentEditor == null || MenuHasBeenAdded)
            {
                return;
            }

            speckleMenu = new ToolStripMenuItem("Speckle 2");

            var kitHeader = speckleMenu.DropDown.Items.Add("Select the converter you want to use.");

            kitHeader.Enabled = false;

            loadedKits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

            var kitItems = new List <ToolStripItem>();

            loadedKits.ToList().ForEach(kit =>
            {
                var item = speckleMenu.DropDown.Items.Add("  " + kit.Name);

                item.Click += HandleKitSelectedEvent;
                kitItems.Add(item);
            });
            kitMenuItems = kitItems;

            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());

            speckleMenu.DropDown.Items.Add("Open Speckle Manager", Properties.Resources.speckle_logo);

            try
            {
                var mainMenu = Grasshopper.Instances.DocumentEditor.MainMenuStrip;
                Grasshopper.Instances.DocumentEditor.Invoke(new Action(() =>
                {
                    if (!MenuHasBeenAdded)
                    {
                        mainMenu.Items.Add(speckleMenu);
                        // Select the first kit by default.
                        if (speckleMenu.DropDown.Items.Count > 0)
                        {
                            HandleKitSelectedEvent(kitMenuItems.FirstOrDefault(k => k.Text.Trim() == "Objects"), null);
                        }
                    }
                }));
                MenuHasBeenAdded = true;
            }
            catch (Exception err)
            {
                Debug.WriteLine(err.Message);
            }
        }
Esempio n. 6
0
        protected override void AppendAdditionalComponentMenuItems(ToolStripDropDown menu)
        {
            Menu_AppendSeparator(menu);
            Menu_AppendItem(menu, "Select the converter you want to use:");
            var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

            foreach (var kit in kits)
            {
                Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SetConverterFromKit(kit.Name); }, true,
                                kit.Name == Kit.Name);
            }

            base.AppendAdditionalComponentMenuItems(menu);
        }
Esempio n. 7
0
        public SelectKitAsyncComponentBase(string name, string nickname, string description, string category, string subCategory) : base(name, nickname, description, category, subCategory)
        {
            var key = "Speckle2:kit.default.name";
            var n   = Grasshopper.Instances.Settings.GetValue(key, "Objects");

            Kit = KitManager.GetKitsWithConvertersForApp(Applications.Rhino).FirstOrDefault(kit => kit.Name == n);
            try
            {
                Converter = Kit.LoadConverter(Applications.Rhino);
                Converter.SetContextDocument(Rhino.RhinoDoc.ActiveDoc);
                Message = $"{Kit.Name} Kit";
            }
            catch
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No default kit found on this machine.");
            }
        }
Esempio n. 8
0
        public static ISpeckleConverter GetDefaultConverter()
        {
            var key = "Speckle2:kit.default.name";
            var n   = Grasshopper.Instances.Settings.GetValue(key, "Objects");

            try
            {
                var defKit    = KitManager.GetKitsWithConvertersForApp(Applications.Rhino).FirstOrDefault(kit => kit != null && kit.Name == n);
                var converter = defKit.LoadConverter(Applications.Rhino);
                converter.SetContextDocument(Rhino.RhinoDoc.ActiveDoc);
                return(converter);
            }
            catch
            {
                throw new Exception("Default kit was not found");
            }
        }
Esempio n. 9
0
        public static ISpeckleConverter GetDefaultConverter()
        {
            var n = SpeckleGHSettings.SelectedKitName;

            try
            {
                var defKit    = KitManager.GetKitsWithConvertersForApp(Applications.Rhino6).FirstOrDefault(kit => kit != null && kit.Name == n);
                var converter = defKit.LoadConverter(Applications.Rhino6);
                converter.SetConverterSettings(SpeckleGHSettings.MeshSettings);
                converter.SetContextDocument(Rhino.RhinoDoc.ActiveDoc);
                return(converter);
            }
            catch
            {
                throw new Exception("Default kit was not found");
            }
        }
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);
            var key = "Speckle2:kit.default.name";
            var n   = Grasshopper.Instances.Settings.GetValue(key, "Objects");

            try
            {
                Kit       = KitManager.GetKitsWithConvertersForApp(Applications.Rhino).FirstOrDefault(kit => kit.Name == n);
                Converter = Kit.LoadConverter(Applications.Rhino);
                Converter.SetContextDocument(Rhino.RhinoDoc.ActiveDoc);
                Message = $"{Kit.Name} Kit";
            }
            catch
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No default kit found on this machine.");
            }
        }
 public override void AddedToDocument(GH_Document document)
 {
     base.AddedToDocument(document);
     try
     {
         Kit       = KitManager.GetKitsWithConvertersForApp(Applications.Rhino6).FirstOrDefault(kit => kit.Name == SpeckleGHSettings.SelectedKitName);
         Converter = Kit.LoadConverter(Applications.Rhino6);
         Converter.SetContextDocument(Rhino.RhinoDoc.ActiveDoc);
         Converter.SetConverterSettings(SpeckleGHSettings.MeshSettings);
         SpeckleGHSettings.OnMeshSettingsChanged +=
             (sender, args) => Converter.SetConverterSettings(SpeckleGHSettings.MeshSettings);
         Message = $"{Kit.Name} Kit";
     }
     catch
     {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "No default kit found on this machine.");
     }
 }
        public override void AppendAdditionalMenuItems(ToolStripDropDown menu)
        {
            try
            {
                var kits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino);

                Menu_AppendSeparator(menu);
                Menu_AppendItem(menu, "Select the converter you want to use:");
                foreach (var kit in kits)
                {
                    Menu_AppendItem(menu, $"{kit.Name} ({kit.Description})", (s, e) => { SetConverterFromKit(kit.Name); }, true,
                                    kit.Name == Kit.Name);
                }

                Menu_AppendSeparator(menu);
            }
            catch (Exception e)
            {
                // Todo: handle this
                Console.WriteLine(e);
            }
        }
Esempio n. 13
0
        private void AddSpeckleMenu(object sender, ElapsedEventArgs e)
        {
            if (Grasshopper.Instances.DocumentEditor == null || MenuHasBeenAdded)
            {
                return;
            }

            speckleMenu = new ToolStripMenuItem("Speckle 2");

            var kitHeader = speckleMenu.DropDown.Items.Add("Select the converter you want to use.");

            kitHeader.Enabled = false;

            try
            {
                loadedKits = KitManager.GetKitsWithConvertersForApp(Applications.Rhino6);

                var kitItems = new List <ToolStripItem>();
                loadedKits.ToList().ForEach(kit =>
                {
                    var item = speckleMenu.DropDown.Items.Add("  " + kit.Name);

                    item.Click += HandleKitSelectedEvent;
                    kitItems.Add(item);
                });
                kitMenuItems = kitItems;
            }
            catch (Exception exception)
            {
                Log.CaptureException(exception);
                var errItem = speckleMenu.DropDown.Items.Add("An error occurred while fetching Kits");
                errItem.Enabled = false;
            }

            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());
            CreateSchemaConversionMenu();
            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());
            CreateMeshingSettingsMenu();
            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());
            CreateTabsMenu();
            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());

            // Help items
            var helpHeader = speckleMenu.DropDown.Items.Add("Looking for help?");

            helpHeader.Enabled = false;
            speckleMenu.DropDown.Items.Add("Community Forum", Properties.Resources.forum16,
                                           (o, args) => Process.Start("https://speckle.community"));
            speckleMenu.DropDown.Items.Add("Tutorials", Properties.Resources.tutorials16,
                                           (o, args) => Process.Start("https://speckle.systems/tutorials"));
            speckleMenu.DropDown.Items.Add("Docs", Properties.Resources.docs16,
                                           (o, args) => Process.Start("https://speckle.guide"));

            speckleMenu.DropDown.Items.Add(new ToolStripSeparator());

            // Manager button
            speckleMenu.DropDown.Items.Add("Open Speckle Manager", Properties.Resources.speckle_logo,
                                           (o, args) => Process.Start("speckle://"));


            try
            {
                var mainMenu = Grasshopper.Instances.DocumentEditor.MainMenuStrip;
                Grasshopper.Instances.DocumentEditor.Invoke(new Action(() =>
                {
                    if (!MenuHasBeenAdded)
                    {
                        mainMenu.Items.Add(speckleMenu);
                        // Select the first kit by default.
                        if (speckleMenu.DropDown.Items.Count > 0)
                        {
                            HandleKitSelectedEvent(kitMenuItems.FirstOrDefault(k => k.Text.Trim() == "Objects"), null);
                        }
                    }
                }));
            }
            catch (Exception err)
            {
                Log.CaptureException(err);
                var errItem = speckleMenu.DropDown.Items.Add("An error occurred while fetching Kits", null);
                errItem.Enabled = false;
            }

            MenuHasBeenAdded = true;
        }