private object GetListFromParameter(IGH_DataAccess DA, int index) { List <IGH_Goo> list2 = new List <IGH_Goo>(); DA.GetDataList(index, list2); IGH_TypeHint typeHint = ((Param_ScriptVariable)_component.Params.Input[index]).TypeHint; var t = Type.GetType("IronPython.Runtime.List,IronPython"); IList list = Activator.CreateInstance(t) as IList; if (_component.DocStorageMode != DocStorage.AutomaticMarshal) { for (int i = 0; i < list2.Count; i++) { list.Add(this.TypeCast(list2[i], typeHint)); } } else { for (int i = 0; i < list2.Count; i++) { object thisInput = this.TypeCast(list2[i], typeHint); DocumentSingle(ref thisInput); list.Add(thisInput); } } return(list); }
private object GetTreeFromParameter(IGH_DataAccess DA, int index, bool addIntoGhDoc) { GH_Structure <IGH_Goo> structure; DA.GetDataTree(index, out structure); IGH_TypeHint typeHint = ((Param_ScriptVariable)_component.Params.Input[index]).TypeHint; var tree = new DataTree <object>(); for (int i = 0; i < structure.PathCount; i++) { GH_Path path = structure.get_Path(i); List <IGH_Goo> list = structure.Branches[i]; List <object> data = new List <object>(); for (int j = 0; j < list.Count; j++) { object cast = this.TypeCast(list[j], typeHint); DocumentSingle(ref cast, addIntoGhDoc); data.Add(cast); } tree.AddRange(data, path); } return(tree); }
public MapItem(Type ghType, IGH_TypeHint ghHint, string iconame) { m_inoname = iconame; m_ico = null; GhType = ghType; GhHint = ghHint; }
/***************************************************/ public static Type Type(this IGH_TypeHint hint, GH_ParamAccess access) { if (hint == null) { return(Type <object>(access)); } switch (hint.TypeName) { case "null": return(Type <object>(access)); case "BH.oM.Base.BHoMObject": return(Type <BH.oM.Base.BHoMObject>(access)); case "BH.oM.Geometry.IGeometry": return(Type <BH.oM.Geometry.IGeometry>(access)); case "Dictionary": return(Type <IDictionary>(access)); case "System.Enum": return(Type <System.Enum>(access)); case "System.Type": return(Type <Type>(access)); case "bool": return(Type <bool>(access)); case "int": return(Type <int>(access)); case "double": return(Type <double>(access)); case "string": return(Type <string>(access)); case "DateTime": return(Type <DateTime>(access)); case "Color": return(Type <System.Drawing.Color>(access)); case "Guid": return(Type <Guid>(access)); default: return(Type <object>(access)); } }
private object TypeCast(IGH_Goo data, IGH_TypeHint hint) { if (data == null) { return(null); } if (hint == null) { return(data.ScriptVariable()); } object objectValue = data.ScriptVariable(); object target; hint.Cast(objectValue, out target); return(target); }
public static bool ToNewRhinoscriptHint(IGH_TypeHint probe, out IGH_TypeHint newHint) { newHint = null; if (probe == null) { return(false); } var probeType = probe.GetType(); if (_old_to_rs.ContainsKey(probeType)) { newHint = _new_marshallings[_old_to_rs[probeType]]; return(true); } return(false); }
/*************************************/ public List <T> GetDataList <T>(int index) { if (GH_Accessor == null) { return(new List <T>()); } IGH_TypeHint hint = null; Param_Variable scriptParam = Inputs[index] as Param_Variable; if (scriptParam != null) { hint = scriptParam.SelectedHint; } List <IGH_Goo> goo = new List <IGH_Goo>(); GH_Accessor.GetDataList <IGH_Goo>(index, goo); return(goo.Select(x => Helpers.IFromGoo <T>(x, hint)).ToList()); }
/*************************************/ /**** Input Getter Methods ****/ /*************************************/ public T GetDataItem <T>(int index) { if (GH_Accessor == null) { return(default(T)); } IGH_Goo goo = null; GH_Accessor.GetData(index, ref goo); IGH_TypeHint hint = null; Param_Variable scriptParam = Inputs[index] as Param_Variable; if (scriptParam != null) { hint = scriptParam.SelectedHint; } return(Helpers.IFromGoo <T>(goo, hint)); }
private object GetListFromParameter(IGH_DataAccess DA, int index, bool addIntoGhDoc) { List <IGH_Goo> list2 = new List <IGH_Goo>(); DA.GetDataList(index, list2); IGH_TypeHint typeHint = ((Param_ScriptVariable)_component.Params.Input[index]).TypeHint; var t = Type.GetType("IronPython.Runtime.List,IronPython"); IList list = Activator.CreateInstance(t) as IList; if (list != null) { for (int i = 0; i < list2.Count; i++) { object cast = this.TypeCast(list2[i], typeHint); DocumentSingle(ref cast, addIntoGhDoc); list.Add(cast); } } return(list); }
/*************************************/ public List <List <T> > GetDataTree <T>(int index) { if (GH_Accessor == null || Inputs.Count <= index) { return(new List <List <T> >()); } IGH_TypeHint hint = null; Param_Variable scriptParam = Inputs[index] as Param_Variable; if (scriptParam != null) { hint = scriptParam.SelectedHint; } IGH_Param param = Inputs[index]; return(param.VolatileData.StructureProxy.Select(x => x.Cast <IGH_Goo>().Select(y => Helpers.IFromGoo <T>(y, hint)).ToList()).ToList()); // This shows that using the GetDataTree method from GH is actually giving the exact same result with the exact same problem of collecting the entire data instead of a subtree /*IGH_Structure goo = Activator.CreateInstance(typeof(GH_Structure<>).GetGenericTypeDefinition().MakeGenericType(new Type[] { param.Type })) as IGH_Structure; * return ConvertDataTree(goo as dynamic, index, new List<List<T>>());*/ }
/*************************************/ private static T FromGoo <T>(this GH_Surface goo, IGH_TypeHint hint = null) { Brep brep = goo.ScriptVariable() as Brep; oM.Geometry.IGeometry geometry = null; if (brep.IsSurface) { geometry = BH.Engine.Rhinoceros.Convert.IFromRhino(brep.Faces[0].UnderlyingSurface()); } else { geometry = BH.Engine.Rhinoceros.Convert.IFromRhino(brep); } try { return((T)(geometry as dynamic)); } catch { Engine.Base.Compute.RecordError("Failed to cast " + geometry.GetType().IToText() + " into " + typeof(T).IToText()); return(default(T)); } }
public static bool ToNewRhinoscriptHint(IGH_TypeHint probe, out IGH_TypeHint newHint) { newHint = null; if (probe == null) return false; var probeType = probe.GetType(); if (_old_to_rs.ContainsKey(probeType)) { newHint = _new_marshallings[_old_to_rs[probeType]]; return true; } return false; }
/*******************************************/ /**** Private Methods ****/ /*******************************************/ private static T FromGoo <T>(this IGH_Goo goo, IGH_TypeHint hint = null) { if (goo == null) { return(default(T)); } // Get the data out of the Goo object data = goo.ScriptVariable(); while (data is IGH_Goo) { data = ((IGH_Goo)data).ScriptVariable(); } if (data == null) { return(default(T)); } if (data.GetType().Namespace.StartsWith("Rhino.Geometry") && !typeof(T).Namespace.StartsWith("Rhino.Geometry")) { data = BH.Engine.Rhinoceros.Convert.IFromRhino(data); } // Convert the data to an acceptable format if (hint != null) { object result; hint.Cast(RuntimeHelpers.GetObjectValue(data), out result); data = result; if (data.GetType().Namespace.StartsWith("Rhino.Geometry") && !typeof(T).Namespace.StartsWith("Rhino.Geometry")) { data = BH.Engine.Rhinoceros.Convert.IFromRhino(data); } } else if (data is T) { return((T)data); } else if (data is IEnumerable) { UnderlyingType subType = data.GetType().UnderlyingType(); if (typeof(T).IsAssignableFrom(subType.Type)) { List <T> list = ((IEnumerable)data).Cast <T>().ToList(); if (list.Count == 0) { return(default(T)); } else { return(list.First()); } } } try { return((T)(data as dynamic)); } catch { Engine.Base.Compute.RecordError("Failed to cast " + data.GetType().IToText() + " into " + typeof(T).IToText()); return(default(T)); } }
/*******************************************/ /**** Public Methods ****/ /*******************************************/ public static T IFromGoo <T>(this IGH_Goo goo, IGH_TypeHint hint = null) { return(goo != null?FromGoo <T>(goo as dynamic, hint) : default(T)); }