// daq - GH_ValueList from Enum protected override void BeforeSolveInstance() { foreach (var unit in EvalUnits) { foreach (var item in unit.Inputs) { // Provide the possibility of a drop-down list in case of enumeration inputs: if (item.EnumInput != null && item.Parameter.SourceCount == 1 && item.Parameter.Sources[0] is GH_ValueList) { GH_ValueList val = item.Parameter.Sources[0] as GH_ValueList; val.ListMode = GH_ValueListMode.DropDown; // We just want to reset the list once!!! if (val.ListItems.Count != item.EnumInput.Count || !(val.ListItems.Select(x => x.Name).SequenceEqual(item.EnumInput))) { var counter = 0; val.ListItems.Clear(); foreach (var input in item.EnumInput) { val.ListItems.Add(new GH_ValueListItem(input, counter.ToString())); counter++; } val.ExpireSolution(true); } } } } }
/// <summary> /// Creates the value list for the motion type and connects it the input parameter is other source is connected /// </summary> private void CreateValueList() { // Creates the empty value list GH_ValueList obj = new GH_ValueList(); obj.CreateAttributes(); obj.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.DropDown; obj.ListItems.Clear(); // Add the items to the value list string[] names = Enum.GetNames(typeof(CodeType)); int[] values = (int[])Enum.GetValues(typeof(CodeType)); for (int i = 0; i < names.Length; i++) { obj.ListItems.Add(new GH_ValueListItem(names[i], values[i].ToString())); } // Make point where the valuelist should be created on the canvas obj.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - obj.Attributes.Bounds.Width / 4, this.Attributes.Pivot.Y - obj.Attributes.Bounds.Height / 2); // Add the value list to the active canvas Instances.ActiveCanvas.Document.AddObject(obj, false); // Created _created = true; // Expire value list obj.ExpireSolution(true); }
/// <summary> /// Creates the value list for the motion type and connects it the input parameter is other source is connected /// </summary> private void CreateValueList() { // Creates the empty value list GH_ValueList obj = new GH_ValueList(); obj.CreateAttributes(); obj.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.DropDown; obj.ListItems.Clear(); // Add the items to the value list for (int i = 0; i < SpeedData.ValidPredefinedNames.Length; i++) { string name = SpeedData.ValidPredefinedNames[i]; string value = SpeedData.ValidPredefinedValues[i].ToString(); obj.ListItems.Add(new GH_ValueListItem(name, value)); } // Make point where the valuelist should be created on the canvas obj.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - obj.Attributes.Bounds.Width / 4, this.Attributes.Pivot.Y - obj.Attributes.Bounds.Height / 2); // Add the value list to the active canvas Instances.ActiveCanvas.Document.AddObject(obj, false); // Created _created = true; // Expire value list obj.ExpireSolution(true); }
/// <summary> /// Creates a value list pre-populated with possible accent colors and adds it to the Grasshopper Document, located near the component pivot. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void CreateRasterList(object sender, System.EventArgs e) { string source = sender.ToString(); source = source.Replace("Create ", ""); source = source.Replace(" Source List", ""); GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); ///Initialize object GH_ValueList vl = new GH_ValueList(); ///Clear default contents vl.ListItems.Clear(); foreach (var service in rasterJson["REST Raster"]) { if (service["source"].ToString() == source) { GH_ValueListItem vi = new GH_ValueListItem(service["service"].ToString(), String.Format("\"{0}\"", service["url"].ToString())); vl.ListItems.Add(vi); } } ///Set component nickname vl.NickName = source; ///Get active GH doc GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } ///Place the object docIO.Document.AddObject(vl, false, 1); ///Get the pivot of the "URL" param PointF currPivot = Params.Input[4].Attributes.Pivot; ///Set the pivot of the new object vl.Attributes.Pivot = new PointF(currPivot.X - 400, currPivot.Y - 11); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent("Create REST Raster Source List", objs); doc.MergeDocument(docIO.Document); }
private void createAccentList(object sender, System.EventArgs e) { GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); foreach (string color in ACCENT_COLORS) { GH_ValueListItem vi = new GH_ValueListItem(color, String.Format("\"{0}\"", color)); vl.ListItems.Add(vi); } vl.NickName = "Accent Colors"; GH_Document doc = OnPingDocument(); doc.AddObject(vl, false, doc.ObjectCount + 1); PointF currPivot = Params.Input[3].Attributes.Pivot; vl.Attributes.Pivot = new PointF(currPivot.X - 120, currPivot.Y - 11); }
/// <summary> /// Creates a value list pre-populated with possible accent colors and adds it to the Grasshopper Document, located near the component pivot. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> private void createAccentList(object sender, System.EventArgs e) { GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); //initialize object GH_ValueList vl = new GH_ValueList(); //clear default contents vl.ListItems.Clear(); //add all the accent colors as both "Keys" and values foreach (string color in ACCENT_COLORS) { GH_ValueListItem vi = new GH_ValueListItem(color, String.Format("\"{0}\"", color)); vl.ListItems.Add(vi); } //set component nickname vl.NickName = "Accent Colors"; //get active GH doc GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } // place the object docIO.Document.AddObject(vl, false, 1); //get the pivot of the "accent" param PointF currPivot = Params.Input[3].Attributes.Pivot; //set the pivot of the new object vl.Attributes.Pivot = new PointF(currPivot.X - 120, currPivot.Y - 11); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent("Create Accent List", objs); doc.MergeDocument(docIO.Document); //doc.ScheduleSolution(10); }
private IGH_Param CreateNumberValueList(int d) { //instantiate new value list var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.ListMode = GH_ValueListMode.Cycle; //populate value list with our own data valueList.ListItems.Clear(); for (int i = 0; i < ghGrid.Value.NodeDimCount[d]; i++) { var val = String.Format("{0:F3}", ghGrid.Value.Data[d][i]); var item = new GH_ValueListItem(val, val); valueList.ListItems.Add(item); } return(valueList); }
private void AddMotion(object sender, EventArgs e) { AddParam(4); var parameter = parameters[4]; if (Params.Input.Any(x => x.Name == parameter.Name)) { var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.Attributes.Pivot = new PointF(parameter.Attributes.InputGrip.X - 130, parameter.Attributes.InputGrip.Y - 11); valueList.ListItems.Clear(); valueList.ListItems.Add(new GH_ValueListItem("Joint", "\"Joint\"")); valueList.ListItems.Add(new GH_ValueListItem("Linear", "\"Linear\"")); Instances.ActiveCanvas.Document.AddObject(valueList, false); parameter.AddSource(valueList); parameter.CollectData(); ExpireSolution(true); } }
private IGH_Param CreateTupleValueList(int d) { //instantiate new value list var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.ListMode = GH_ValueListMode.Sequence; //populate value list with our own data valueList.ListItems.Clear(); for (int i = 0; i < ghGrid.Value.NodeDimCount[d]; i++) { var val = "" + i; var item = new GH_ValueListItem(val, val); valueList.ListItems.Add(item); } return(valueList); }
public static GH_ValueList CreateDropDown(string name, List<string> values, float x, float y) { var valueList = new GH_ValueList(); valueList.CreateAttributes(); valueList.Name = name; valueList.NickName = name + ":"; valueList.Description = "Select an option..."; valueList.ListMode = GH_ValueListMode.DropDown; valueList.ListItems.Clear(); for (int i = 0; i < values.Count; i++) { valueList.ListItems.Add(new GH_ValueListItem(values[i], i.ToString())); } valueList.Attributes.Pivot = new PointF(x - 200, y - 10); return valueList; }
// Method for creating the value list with movement types #region valuelist /// <summary> /// Creates the value list for the motion type and connects it the input parameter is other source is connected /// </summary> private void CreateValueList() { if (this.Params.Input[2].SourceCount == 0) { // Gets the input parameter var parameter = Params.Input[2]; // Creates the empty value list GH_ValueList obj = new GH_ValueList(); obj.CreateAttributes(); obj.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.DropDown; obj.ListItems.Clear(); // Add the items to the value list // Add the items to the value list string[] names = Enum.GetNames(typeof(MovementType)); int[] values = (int[])Enum.GetValues(typeof(MovementType)); for (int i = 0; i < names.Length; i++) { obj.ListItems.Add(new GH_ValueListItem(names[i], values[i].ToString())); } // Make point where the valuelist should be created on the canvas obj.Attributes.Pivot = new PointF(parameter.Attributes.InputGrip.X - 120, parameter.Attributes.InputGrip.Y - 11); // Add the value list to the active canvas Instances.ActiveCanvas.Document.AddObject(obj, false); // Connect the value list to the input parameter parameter.AddSource(obj); // Collect data parameter.CollectData(); // Set bool for expire solution of this component _expire = true; // First expire the solution of the value list obj.ExpireSolution(true); } }
// Method for creating the value list with coordinate system types #region valuelist /// <summary> /// Creates the value list for the motion type and connects it the input parameter is other source is connected /// </summary> private void CreateValueList() { if (this.Params.Input[1].SourceCount == 0) { // Gets the input parameter var parameter = Params.Input[1]; // Creates the empty value list GH_ValueList obj = new GH_ValueList(); obj.CreateAttributes(); obj.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.DropDown; obj.ListItems.Clear(); // Add the items to the value list //obj.ListItems.Add(new GH_ValueListItem("Undefined", "0")); // doesn't return a robtarget obj.ListItems.Add(new GH_ValueListItem("World", "1")); obj.ListItems.Add(new GH_ValueListItem("Base", "2")); //obj.ListItems.Add(new GH_ValueListItem("Tool", "3")); // doesn't return a robtarget obj.ListItems.Add(new GH_ValueListItem("Work Object", "4")); // Make point where the valuelist should be created on the canvas obj.Attributes.Pivot = new PointF(parameter.Attributes.InputGrip.X - 120, parameter.Attributes.InputGrip.Y - 11); // Add the value list to the active canvas Instances.ActiveCanvas.Document.AddObject(obj, false); // Connect the value list to the input parameter parameter.AddSource(obj); // Collect data parameter.CollectData(); // Set bool for expire solution of this component _expire = true; // First expire the solution of the value list obj.ExpireSolution(true); } }
protected override void BeforeSolveInstance() { if (valueList == null) { if (parameter.Sources.Count == 0) { valueList = new GH_ValueList(); } else { foreach (var source in parameter.Sources) { if (source is GH_ValueList) { valueList = source as GH_ValueList; } return; } } valueList.CreateAttributes(); valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 200, this.Attributes.Pivot.Y - 1); valueList.ListItems.Clear(); var alignmentNames = Enum.GetNames(typeof(GlulamData.CrossSectionPosition)); var alignmentValues = Enum.GetValues(typeof(GlulamData.CrossSectionPosition)); for (int i = 0; i < alignmentNames.Length; ++i) { valueList.ListItems.Add(new GH_ValueListItem(alignmentNames[i], $"{i}")); } valueList.SelectItem(4); Instances.ActiveCanvas.Document.AddObject(valueList, false); parameter.AddSource(valueList); parameter.CollectData(); } }
private void CreateAccentList(string[] values, string nick, int inputParam, int offsetX, int offsetY) { GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); foreach (string item in values) { GH_ValueListItem vi = new GH_ValueListItem(item, String.Format("\"{0}\"", item)); vl.ListItems.Add(vi); } vl.NickName = nick; GH_Document doc = OnPingDocument(); if (docIO.Document == null) { return; } docIO.Document.AddObject(vl, false, inputParam); PointF currPivot = Params.Input[inputParam].Attributes.Pivot; vl.Attributes.Pivot = new PointF(currPivot.X - offsetX, currPivot.Y + offsetY); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.MergeDocument(docIO.Document); Component.Params.Input[inputParam].AddSource(vl); doc.DeselectAll(); }
//////////////////////////////////////////////////////////////////////// // Create a drop down to select supported robot if no robot selected. private void RobotOptionList() { // TODO: check instead if alreeady set. // Create robot Option List. GH_ValueList robotValueList = new GH_ValueList(); robotValueList.CreateAttributes(); robotValueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 300, this.Attributes.Pivot.Y - 41); robotValueList.ListItems.Clear(); robotValueList.NickName = "Robot"; // Add supported robot names. foreach (string robotName in HoloBot.listRobotNames) { GH_ValueListItem item = new GH_ValueListItem(robotName, "\"" + robotName + "\""); robotValueList.ListItems.Add(item); } // Update grasshopper document. GH_Document document = this.OnPingDocument(); document.AddObject(robotValueList, false); this.Params.Input[0].AddSource(robotValueList); this.Params.Input[0].CollectData(); }
/*******************************************/ public static INode ToNode(this GH_ValueList component, List <object> choices, object selectedItem) { int index = 0; bool success = component.SelectedItems.First().Value.CastTo <int>(out index); if (success && index >= 0 && index < choices.Count) { object choice = choices[index]; if (component.GetType().Name == "CreateDataComponent") { DataParam parameter = PopulateParam(new DataParam { Data = choice as BHoMObject, DataType = choice.GetType() }, component); return(new LibraryNode { SourceFile = selectedItem as string, Name = parameter.Name, Description = parameter.Description, BHoM_Guid = parameter.BHoM_Guid, Inputs = new List <ReceiverParam>(), Outputs = new List <DataParam> { parameter } }); } else { return(ParamNode(PopulateParam(new DataParam { Data = choice, DataType = choice.GetType() }, component))); } } else { return(null); } }
protected override void BeforeSolveInstance() { if (valueList == null) { if (parameter.Sources.Count == 0) { valueList = new GH_ValueList(); } else { foreach (var source in parameter.Sources) { if (source is GH_ValueList) { valueList = source as GH_ValueList; } return; } } valueList.CreateAttributes(); valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 200, this.Attributes.Pivot.Y - 1); valueList.ListItems.Clear(); var glulamParameters = Glulam.ListProperties(); foreach (string param in glulamParameters) { valueList.ListItems.Add(new GH_ValueListItem(param, $"\"{param}\"")); } Instances.ActiveCanvas.Document.AddObject(valueList, false); parameter.AddSource(valueList); parameter.CollectData(); } }
protected override void BeforeSolveInstance() { if (valueList == null) { if (parameter.Sources.Count == 0) { valueList = new GH_ValueList(); } else { foreach (var source in parameter.Sources) { if (source is GH_ValueList) { valueList = source as GH_ValueList; } return; } } valueList.CreateAttributes(); valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 180, this.Attributes.Pivot.Y - 31); valueList.ListItems.Clear(); var robotSystems = RobotSystem.ListRobotSystems(); foreach (string robotSystemName in robotSystems) { valueList.ListItems.Add(new GH_ValueListItem(robotSystemName, $"\"{robotSystemName}\"")); } Instances.ActiveCanvas.Document.AddObject(valueList, false); parameter.AddSource(valueList); parameter.CollectData(); } }
static public void SetValueList(GH_Document doc, GH_Component comp, int InputIndex, List <KeyValuePair <string, string> > valuePairs, string name) { if (valuePairs.Count == 0) { return; } GH_DocumentIO docIO = new GH_DocumentIO(); docIO.Document = new GH_Document(); if (docIO.Document == null) { return; } doc.MergeDocument(docIO.Document); docIO.Document.SelectAll(); docIO.Document.ExpireSolution(); docIO.Document.MutateAllIds(); IEnumerable <IGH_DocumentObject> objs = docIO.Document.Objects; doc.DeselectAll(); doc.UndoUtil.RecordAddObjectEvent("Create Accent List", objs); doc.MergeDocument(docIO.Document); doc.ScheduleSolution(10, chanegValuelist); void chanegValuelist(GH_Document document) { IList <IGH_Param> sources = comp.Params.Input[InputIndex].Sources; int inputs = sources.Count; // If nothing has been conected create a new component if (inputs == 0) { //instantiate new value list and clear it GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); vl.NickName = name; vl.Name = name; //Create values for list and populate it for (int i = 0; i < valuePairs.Count; ++i) { var item = new GH_ValueListItem(valuePairs[i].Key, valuePairs[i].Value); vl.ListItems.Add(item); } //Add value list to the document document.AddObject(vl, false, 1); //get the pivot of the "accent" param System.Drawing.PointF currPivot = comp.Params.Input[InputIndex].Attributes.Pivot; //set the pivot of the new object vl.Attributes.Pivot = new System.Drawing.PointF(currPivot.X - 210, currPivot.Y - 11); // Connect to input comp.Params.Input[InputIndex].AddSource(vl); } // If inputs exist replace the existing ones else { for (int i = 0; i < inputs; ++i) { if (sources[i].Name == "Value List" | sources[i].Name == name) { //instantiate new value list and clear it GH_ValueList vl = new GH_ValueList(); vl.ListItems.Clear(); vl.NickName = name; vl.Name = name; //Create values for list and populate it for (int j = 0; j < valuePairs.Count; ++j) { var item = new GH_ValueListItem(valuePairs[j].Key, valuePairs[j].Value); vl.ListItems.Add(item); } document.AddObject(vl, false, 1); //set the pivot of the new object vl.Attributes.Pivot = sources[i].Attributes.Pivot; var currentSource = sources[i]; comp.Params.Input[InputIndex].RemoveSource(sources[i]); currentSource.IsolateObject(); document.RemoveObject(currentSource, false); //Connect new vl comp.Params.Input[InputIndex].AddSource(vl); } else { //Do nothing if it dosent mach any of the above } } } } }
/*******************************************/ /**** Constructors ****/ /*******************************************/ public PrototypeValueListAttribute(GH_ValueList owner) : base(owner) { }
public CatalogueValueListAttributes(GH_ValueList owner) : base(owner) { }
public static HashSet <string> GetValueListNames(GH_ValueList valueList) { return(valueList.ListItems.Select(item => item.Name).ToHashSet()); }
public static void RebuildValueList(GH_ValueList valueList, IEnumerable <(string Key, string Value)> keyValuePairs)
protected override void BeforeSolveInstance() { if (valueList == null) { if (parameter.Sources.Count == 0) { valueList = new GH_ValueList(); } else { foreach (var source in parameter.Sources) { if (source is GH_ValueList) valueList = source as GH_ValueList; return; } } valueList.CreateAttributes(); valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 180, this.Attributes.Pivot.Y - 31); valueList.ListItems.Clear(); var robotSystems = RobotSystem.ListRobotSystems(); foreach (string robotSystemName in robotSystems) { valueList.ListItems.Add(new GH_ValueListItem(robotSystemName, $"\"{robotSystemName}\"")); } Instances.ActiveCanvas.Document.AddObject(valueList, false); parameter.AddSource(valueList); parameter.CollectData(); } }