private void SetBooleanToFalse(GH.Kernel.Special.GH_BooleanToggle boolTrigger) { if (boolTrigger == null) { return; } grp.Colour = System.Drawing.Color.IndianRed; boolTrigger.Value = false; //set trigger value to false boolTrigger.ExpireSolution(true); }
private void AddToggle() { var toggle = new GH.Kernel.Special.GH_BooleanToggle(); toggle.CreateAttributes(); toggle.Value = false; toggle.NickName = "Release the fly..."; toggle.Attributes.Pivot = new PointF((float)(this.Attributes.Bounds.Left - 200), (float)(this.Attributes.Bounds.Top + 30)); doc.AddObject(toggle, false); this.Params.Input[1].AddSource(toggle); toggle.ExpireSolution(true); grp = new GH.Kernel.Special.GH_Group(); grp.CreateAttributes(); grp.Border = GH.Kernel.Special.GH_GroupBorder.Blob; grp.AddObject(toggle.InstanceGuid); grp.Colour = System.Drawing.Color.IndianRed; grp.NickName = ""; doc.AddObject(grp, false); }
private void AddToggle() { var toggle = new Grasshopper.Kernel.Special.GH_BooleanToggle(); toggle.CreateAttributes(); toggle.Value = false; toggle.NickName = "Release the fly..."; toggle.Attributes.Pivot = new PointF((float) (Component.Attributes.Bounds.Left - 200), (float) (Component.Attributes.Bounds.Top + 30)); GrasshopperDocument.AddObject(toggle, false); Component.Params.Input[1].AddSource(toggle); toggle.ExpireSolution(true); grp = new Grasshopper.Kernel.Special.GH_Group(); grp.CreateAttributes(); grp.Border = Grasshopper.Kernel.Special.GH_GroupBorder.Blob; grp.AddObject(toggle.InstanceGuid); grp.Colour = System.Drawing.Color.IndianRed; grp.NickName = ""; GrasshopperDocument.AddObject(grp, false); }
private List <string> getConnectedSlidersNames() { List <string> names = new List <string>(); // Find the Guid for connected slides List <System.Guid> guids = new List <System.Guid>(); //empty list for guids GH.Kernel.IGH_Param selSlidersInput = this.Params.Input[0]; //ref for input where sliders are connected to this component IList <GH.Kernel.IGH_Param> sources = selSlidersInput.Sources; //list of things connected on this input bool isAnythingConnected = sources.Any(); //is there actually anything connected? // Find connected GH.Kernel.IGH_Param trigger = this.Params.Input[1].Sources[0]; //ref for input where a boolean or a button is connected GH.Kernel.Special.GH_BooleanToggle boolTrigger = trigger as GH.Kernel.Special.GH_BooleanToggle; if (isAnythingConnected) { //if something's connected, foreach (var source in sources) //for each of these connected things: { IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject; //for this connected thing, bring it into the code in a way where we can access its properties GH.Kernel.Special.GH_NumberSlider mySlider = component as GH.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider if (mySlider == null) //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls { continue; } guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid. //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider' } } // Find all sliders. List <GH.Kernel.Special.GH_NumberSlider> sliders = new List <GH.Kernel.Special.GH_NumberSlider>(); foreach (IGH_DocumentObject docObject in doc.Objects) { GH.Kernel.Special.GH_NumberSlider slider = docObject as GH.Kernel.Special.GH_NumberSlider; if (slider != null) { // check if the slider is in the selected list if (isAnythingConnected) { if (guids.Contains(slider.InstanceGuid)) { sliders.Add(slider); } } else { sliders.Add(slider); } } } foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders) { names.Add(slider.NickName); } return(names); }
private void OnSolutionEnd(object sender, GH_SolutionEventArgs e) { // Unregister the event, we don't want to get called again. e.Document.SolutionEnd -= OnSolutionEnd; // If we're not supposed to run, abort now. if (!_run) { return; } // If we're already running, abort now. if (_running) { return; } // Reset run and running states. _run = false; _running = true; try { // Find the Guid for connected slides List <System.Guid> guids = new List <System.Guid>(); //empty list for guids GH.Kernel.IGH_Param selSlidersInput = this.Params.Input[0]; //ref for input where sliders are connected to this component IList <GH.Kernel.IGH_Param> sources = selSlidersInput.Sources; //list of things connected on this input bool isAnythingConnected = sources.Any(); //is there actually anything connected? // Find connected GH.Kernel.IGH_Param trigger = this.Params.Input[1].Sources[0]; //ref for input where a boolean or a button is connected GH.Kernel.Special.GH_BooleanToggle boolTrigger = trigger as GH.Kernel.Special.GH_BooleanToggle; if (isAnythingConnected) { //if something's connected, foreach (var source in sources) //for each of these connected things: { IGH_DocumentObject component = source.Attributes.GetTopLevel.DocObject; //for this connected thing, bring it into the code in a way where we can access its properties GH.Kernel.Special.GH_NumberSlider mySlider = component as GH.Kernel.Special.GH_NumberSlider; //...then cast (?) it as a slider if (mySlider == null) //of course, if the thing isn't a slider, the cast doesn't work, so we get null. let's filter out the nulls { continue; } guids.Add(mySlider.InstanceGuid); //things left over are sliders and are connected to our input. save this guid. //we now have a list of guids of sliders connected to our input, saved in list var 'mySlider' } } // Find all sliders. List <GH.Kernel.Special.GH_NumberSlider> sliders = new List <GH.Kernel.Special.GH_NumberSlider>(); foreach (IGH_DocumentObject docObject in doc.Objects) { GH.Kernel.Special.GH_NumberSlider slider = docObject as GH.Kernel.Special.GH_NumberSlider; if (slider != null) { // check if the slider is in the selected list if (isAnythingConnected) { if (guids.Contains(slider.InstanceGuid)) { sliders.Add(slider); } } else { sliders.Add(slider); } } } if (sliders.Count == 0) { System.Windows.Forms.MessageBox.Show("No sliders could be found", "<harsh buzzing sound>", MessageBoxButtons.OK); return; } //we now have all sliders //ask the user to give a sanity check int counter = 0; int totalLoops = 1; string popupMessage = ""; // create progress bar by dots and | string pb = ".................................................."; //50 of "." - There should be a better way to create this in C# > 50 * "." does it in Python! char[] pbChars = pb.ToCharArray(); foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders) { totalLoops *= (slider.TickCount + 1); popupMessage += slider.ImpliedNickName; popupMessage += "\n"; } if (System.Windows.Forms.MessageBox.Show(sliders.Count + " slider(s) connected:\n" + popupMessage + "\n" + totalLoops.ToString() + " iterations will be done. Continue?" + "\n\n (Press ESC to pause during progressing!)", "Start?", MessageBoxButtons.YesNo) == DialogResult.No) { SetBooleanToFalse(boolTrigger); this.Message = "Release Colibri!"; return; } // Set all sliders back to first tick foreach (GH.Kernel.Special.GH_NumberSlider slider in sliders) { slider.TickValue = 0; } //start a stopwatch System.Diagnostics.Stopwatch sw = System.Diagnostics.Stopwatch.StartNew(); // Start a giant loop in which we'll permutate our way across all slider layouts. while (true) { int idx = 0; // let the user cancel the process if (GH_Document.IsEscapeKeyDown()) { if (System.Windows.Forms.MessageBox.Show("Do you want to stop the process?\nSo far " + counter.ToString() + " out of " + totalLoops.ToString() + " iterations are done!", "Stop?", MessageBoxButtons.YesNo) == DialogResult.Yes) { // cancel the process by user input! SetBooleanToFalse(boolTrigger); this.Message += "\nCanceled by user! :|"; return; } } if (!MoveToNextPermutation(ref idx, sliders)) { // study is over! SetBooleanToFalse(boolTrigger); sw.Stop(); //stop start watch UpdateProgressBar(counter, totalLoops, sw, pbChars); this.Message += "\nFinished at " + DateTime.Now.ToShortTimeString(); //wipe out colibri variables sliderSteps = new List <int>(); sliderStepsPositions = new Dictionary <int, int>(); break; } // We've just got a new valid permutation. Solve the new solution. counter++; e.Document.NewSolution(false); Rhino.RhinoDoc.ActiveDoc.Views.Redraw(); UpdateProgressBar(counter, totalLoops, sw, pbChars); } } catch { // "something went wrong!"; } finally { // Always make sure that _running is switched off. _running = false; } }