protected DictHelper(SerializationInfo info, StreamingContext context) { Type t = typeof(ArchivableDictionary); var constructor = t.GetConstructor(System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance, null, new Type[] { typeof(SerializationInfo), typeof(StreamingContext) }, null); SerializedDictionary = constructor.Invoke(new object[] { info, context }) as ArchivableDictionary; }
public ArchivableDictionary GetArchivableDictionary() { ArchivableDictionary ad = new ArchivableDictionary(); ad.Set("id", ID); ad.Set("centreline", Centreline); ad.Set("width", Width); ad.Set("height", Height); ad.Set("length", Centreline.GetLength()); ad.Set("lamella_width", Data.LamWidth); ad.Set("lamella_height", Data.LamHeight); ad.Set("lamella_count_width", Data.NumWidth); ad.Set("lamella_count_height", Data.NumHeight); ad.Set("volume", GetVolume()); ad.Set("samples", Data.Samples); //var planes = GetAllPlanes(); //ArchivableDictionary pd = new ArchivableDictionary(); //for (int i = 0; i < planes.Length; ++i) //{ // pd.Set(string.Format("Frame_{0}", i), planes[i]); //} //ad.Set("frames", pd); double max_kw = 0.0, max_kh = 0.0; ad.Set("max_curvature", GetMaxCurvature(ref max_kw, ref max_kh)); ad.Set("max_curvature_width", max_kw); ad.Set("max_curvature_height", max_kh); ad.Set("type", ToString()); ad.Set("type_id", (int)Type()); return(ad); }
/// <summary> /// Constructor /// </summary> public SampleCsUserDataPlugIn() { Instance = this; StringDocumentDataTable = new SampleCsStringDocumentData(); SimpleDocumentDataTable = new SampleCsSimpleDocumentDataTable(); Dictionary = new ArchivableDictionary(MAJOR, "SampleCsDictionary"); }
private void GetValues(ArchivableDictionary dictionary) { if (null == dictionary) { return; } RhinoApp.WriteLine(dictionary.Name); int integer_value; if (dictionary.TryGetInteger(INTEGER_VALUE, out integer_value)) { m_integer_value = integer_value; RhinoApp.WriteLine(" Integer = {0}", m_integer_value); } else { RhinoApp.WriteLine(" Integer = <none>"); } double double_value; if (dictionary.TryGetDouble(DOUBLE_VALUE, out double_value)) { m_double_value = double_value; RhinoApp.WriteLine(" Double = {0}", m_double_value); } else { RhinoApp.WriteLine(" Double = <none>"); } }
public Element(Plane handle, string name = "") { Connections = new List <Connection>(); Name = name; m_plane = handle; UserDictionary = new ArchivableDictionary(); }
// TODO: // Extension method for ArchivableDictionary -> Dictionary // Extension mehtod Dictionary-> Archivable dictionary // Dictionaries & ArchivableDictionaries public static Dictionary <string, object> ToSpeckle(this ArchivableDictionary dict) { if (dict == null) { return(null); } Dictionary <string, object> myDictionary = new Dictionary <string, object>(); foreach (var key in dict.Keys) { if (dict[key] is ArchivableDictionary) { myDictionary.Add(key, (( ArchivableDictionary )dict[key]).ToSpeckle()); } else if (dict[key] is string || dict[key] is double || dict[key] is float || dict[key] is int) { myDictionary.Add(key, dict[key]); } else { myDictionary.Add(key, SpeckleCore.Converter.Serialize(dict[key])); } } return(myDictionary); }
private protected override void Deserialize(ArchivableDictionary dictionary) { base.Deserialize(dictionary); var dic = dictionary; var json = dic.GetString("HBData"); this.HBObject = HB.Room.FromJson(json); }
public Element(string name = "") { Connections = new List <Connection>(); Handles = new List <Plane>(); Name = name; m_plane = Plane.WorldXY; m_geometry = null; UserDictionary = new ArchivableDictionary(); }
public virtual ArchivableDictionary DeserializeToDictionary() { var dict = new ArchivableDictionary(); // Set Component Plane dict.Set("Plane", Plane); return(dict); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { ArchivableDictionary Archives = new ArchivableDictionary(); if (!DA.GetData(0, ref Archives)) { return; } DA.SetDataList(0, Archives.Values); }
public static ArchivableDictionary ToNative(this Dictionary <string, object> dict) { ArchivableDictionary myDictionary = new ArchivableDictionary(); if (dict == null) { return(myDictionary); } foreach (var key in dict.Keys) { if (dict[key] is Dictionary <string, object> ) { myDictionary.Set(key, ((Dictionary <string, object>)dict[key]).ToNative()); } else if (dict[key] is SpeckleObject) { var converted = SpeckleCore.Converter.Deserialise(( SpeckleObject )dict[key]); if (converted is GeometryBase) { myDictionary.Set(key, ( GeometryBase )converted); } else if (converted is Interval) { myDictionary.Set(key, ( Interval )converted); } else if (converted is Vector3d) { myDictionary.Set(key, ( Vector3d )converted); } else if (converted is Plane) { myDictionary.Set(key, ( Plane )converted); } } else if (dict[key] is int) { myDictionary.Set(key, Convert.ToInt32(dict[key])); } else if (dict[key] is double) { myDictionary.Set(key, ( double )dict[key]); } else if (dict[key] is bool) { myDictionary.Set(key, ( bool )dict[key]); } else if (dict[key] is string) { myDictionary.Set(key, ( string )dict[key]); } } return(myDictionary); }
private protected override void Deserialize(ArchivableDictionary dictionary) { var dic = dictionary; base.Deserialize(dic); var json = dic.GetString("HBData"); this.HBObject = HB.Face.FromJson(json); this.ApertureObjRefs = (dic[nameof(ApertureObjRefs)] as IEnumerable <ObjRef>).ToList(); this.DoorObjRefs = (dic[nameof(DoorObjRefs)] as IEnumerable <ObjRef>).ToList(); }
private void Deserialize(ArchivableDictionary dictionary) { var dic = dictionary; this.HBObject = HB.Model.FromJson(dic[nameof(HBObject)].ToString()); this.Rooms = (dic[nameof(Rooms)] as IEnumerable <ObjRef>).ToList(); this.OrphanedApertures = (dic[nameof(OrphanedApertures)] as IEnumerable <ObjRef>).ToList(); this.OrphanedDoors = (dic[nameof(OrphanedDoors)] as IEnumerable <ObjRef>).ToList(); this.OrphanedFaces = (dic[nameof(OrphanedFaces)] as IEnumerable <ObjRef>).ToList(); this.OrphanedShades = (dic[nameof(OrphanedShades)] as IEnumerable <ObjRef>).ToList(); }
private ArchivableDictionary Serialize() { var dic = new ArchivableDictionary(); dic.Set(nameof(HBObject), HBObject.ToJson()); dic.Set(nameof(Rooms), RoomEntitiesWithoutHistory); dic.Set(nameof(OrphanedApertures), OrphanedAperturesWithoutHistory); dic.Set(nameof(OrphanedDoors), OrphanedDoorsWithoutHistory); dic.Set(nameof(OrphanedFaces), OrphanedFacesWithoutHistory); dic.Set(nameof(OrphanedShades), OrphanedShadesWithoutHistory); return(dic); }
private void SetValues(ArchivableDictionary dictionary) { if (null == dictionary) { return; } m_integer_value++; m_double_value *= 1.57; dictionary.Set(INTEGER_VALUE, m_integer_value); dictionary.Set(DOUBLE_VALUE, m_double_value); }
/// <summary> /// Builds the cell mesh in a clean way. /// This lends the cell mesh to being referenced for PolyFrame use. /// This needs the face meshes stored in the faces /// </summary> public Mesh CreateCellMesh() { // create a dict for quick find of the vertices // take the faces from each faceMesh and reconstruct them in the cell var cellMesh = new Mesh(); ArchivableDictionary vertDict = new ArchivableDictionary(); for (int i = 0; i < Vertices.Count; i++) { vertDict.Set(i.ToString(), Vertices[i].Id); } cellMesh.UserDictionary.Set("VertexIds", vertDict); cellMesh.UserDictionary.Set("Id", Id); var cellVerts = new Dictionary <int, int>(); foreach (var vert in Vertices) { cellVerts.Add(vert.Id, cellMesh.Vertices.Add(vert.Point)); // vert id : index in cell } foreach (var face in Faces) { //cellMesh.Ngons.AddNgon(new MeshNgon(new List<MeshFace>())); var mFaceList = new List <int>(); foreach (var mFace in face.FMesh.Faces) { var cellMFace = new MeshFace( cellVerts[face.Vertices[mFace.A].Id], cellVerts[face.Vertices[mFace.B].Id], cellVerts[face.Vertices[mFace.C].Id] ); mFaceList.Add(cellMesh.Faces.AddFace(cellMFace)); } cellMesh.Ngons.AddNgon(MeshNgon.Create(face.Vertices.Select(x => cellVerts[x.Id]).ToList(), mFaceList)); } cellMesh.UnifyNormals(); cellMesh.Normals.ComputeNormals(); cellMesh.Normals.UnitizeNormals(); cellMesh.Flip(true, true, true); return(cellMesh); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object can be used to retrieve data from input parameters and /// to store data in output parameters.</param> protected override void SolveInstance(IGH_DataAccess DA) { object objectRef = null; DA.GetData(0, ref objectRef); if (objectRef == null) { return; } object valueExtract = objectRef.GetType().GetProperty("Value").GetValue(objectRef, null); GeometryBase recipient = getGeometryBase(valueExtract); if (recipient == null) { DA.SetData(0, null); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Input object not supported."); return; } object dictObject = null; DA.GetData(1, ref dictObject); GH_ObjectWrapper temp = dictObject as GH_ObjectWrapper; if (temp == null) { DA.SetData(0, recipient); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dictionary not provided. Object not modified."); return; } ArchivableDictionary dict = ((GH_ObjectWrapper)dictObject).Value as ArchivableDictionary; if (dict == null) { DA.SetData(0, recipient); this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Dictionary not valid. Object not modified."); return; } recipient.UserDictionary.ReplaceContentsWith(dict); DA.SetData(0, new GH_ObjectWrapper(recipient)); }
private protected virtual void Deserialize(ArchivableDictionary dictionary) { var dic = dictionary; var hashost = dic.TryGetValue(nameof(HostObjRef), out object obj); if (hashost) { //Subsurfaces have no host ObjRef object this.HostObjRef = obj as ObjRef; } if (dic.TryGetValue(nameof(HostRoomObjRef), out object roomObj)) { this.HostRoomObjRef = roomObj as ObjRef; } }
/// <inheritdoc /> /// <summary> /// Called whenever a Rhino document is being loaded and plug-in user data was /// encountered written by a plug-in with this plug-in's GUID. /// </summary> protected override void ReadDocument(RhinoDoc doc, BinaryArchiveReader archive, FileReadOptions options) { archive.Read3dmChunkVersion(out var major, out var minor); if (MAJOR == major && MINOR == minor) { var dictionary = archive.ReadDictionary(); if (null != dictionary && !options.ImportMode && !options.ImportReferenceMode) { m_dictionary = dictionary.Clone(); // Note, if we read our user data from a document, then // assume that we can to track commands... CommandTrackingEnabled = true; } } }
public List <string> getDictProps(string rootProp, ArchivableDictionary d) { List <string> props = new List <string>(); foreach (var key in d.Keys) { if (d[key] is ArchivableDictionary) { props.AddRange(getDictProps(rootProp + (rootProp == "" ? "" : ".") + key, d[key] as ArchivableDictionary)); } else { props.Add(rootProp + (rootProp == "" ? "" : ".") + key); } } return(props); }
private protected virtual ArchivableDictionary Serialize() { var dic = new ArchivableDictionary(); if (HostObjRef != null) { //Subsurfaces have no host ObjRef object dic.Set(nameof(HostObjRef), HostObjRef); } if (HostRoomObjRef != null) { dic.Set(nameof(HostRoomObjRef), HostRoomObjRef); } return(dic); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { //动态绑定 List <dynamic> Inputs = new List <dynamic>(); if (!DA.GetDataList(0, Inputs)) { return; } ArchivableDictionary Archives = new ArchivableDictionary(); for (int Index = 0; Index < Inputs.Count; Index++) { string Key = Guid.NewGuid().ToString(); Archives.Set(Key, Inputs[Index].Value); } DA.SetData(0, Archives); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { int format = 0; DA.GetData(1, ref format); List <object> objs = new List <object>(); DA.GetDataList(0, objs); if (objs.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No dictionaries found."); return; } List <ArchivableDictionary> dictList = new List <ArchivableDictionary>(); foreach (var obj in objs) { GH_ObjectWrapper goo = obj as GH_ObjectWrapper; if (goo == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary."); return; } ArchivableDictionary dict = goo.Value as ArchivableDictionary; if (dict == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary."); return; } dictList.Add(dict); } if (dictList.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No dictionaries found."); return; } serialisedUDs = JsonConvert.SerializeObject(dictList, format == 1 ? Formatting.Indented : Formatting.None); DA.SetData(0, serialisedUDs); }
private static ArchivableDictionary getArchivableDict(ExpandoObject dict) { var myDictionary = new ArchivableDictionary(); foreach (var kvp in dict) { if (kvp.Value is ExpandoObject) { myDictionary.Set(kvp.Key, getArchivableDict(kvp.Value as ExpandoObject)); } else { try { myDictionary.Set((string)kvp.Key, Convert.ToInt32(kvp.Value)); } catch { } try { myDictionary.Set((string)kvp.Key, (double)kvp.Value); } catch { } try { myDictionary.Set((string)kvp.Key, (bool)kvp.Value); } catch { } try { myDictionary.Set((string)kvp.Key, (string)kvp.Value); } catch { } } } return(myDictionary); }
public ArchivableDictionary GlulamPropertiesToArchivableDictionary(Glulam g) { ArchivableDictionary ad = new ArchivableDictionary(); var gd = g.GetProperties(); //ad.Set("id", g.ID); ad.Set("centreline", g.Centreline); ad.Set("width", g.Width); ad.Set("height", g.Height); ad.Set("lamella_width", g.Data.LamWidth); ad.Set("lamella_height", g.Data.LamHeight); ad.Set("lamella_count_width", g.Data.NumWidth); ad.Set("lamella_count_height", g.Data.NumHeight); ad.Set("volume", g.GetVolume()); ad.Set("samples", g.Data.Samples); /* * var planes = g.GetAllPlanes(); * ArchivableDictionary pd = new ArchivableDictionary(); * * for (int i = 0; i < planes.Length; ++i) * { * pd.Set(string.Format("Frame_{0}", i), planes[i]); * } * ad.Set("frames", pd); * */ double max_kw = 0.0, max_kh = 0.0; ad.Set("max_curvature", g.GetMaxCurvature(ref max_kw, ref max_kh)); ad.Set("max_curvature_width", max_kw); ad.Set("max_curvature_height", max_kh); ad.Set("type", g.ToString()); ad.Set("type_id", (int)g.Type()); return(ad); }
public object tryGetProperty(string prop, ArchivableDictionary d) { List <string> props = prop.Split('.').ToList(); if (props.Count == 0) { return("error"); } if (!d.Keys.Contains(props.ElementAt(0))) { return("null"); } if (props.Count > 1) { var key = props.ElementAt(0); props.RemoveAt(0); return(tryGetProperty(String.Join(".", props), d[key] as ArchivableDictionary)); } return(d[props.ElementAt(0)]); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { object o1 = null; DA.GetData(0, ref o1); ArchivableDictionary dict = ((GH_ObjectWrapper)o1).Value as ArchivableDictionary; if (dict == null) { throw new Exception("No dictionary provided."); } string path = null; DA.GetData(1, ref path); if (path == null) { throw new Exception("No path provided."); } object target = null; ArchivableDictionary temp = dict; var keys = path.Split('.'); for (int i = 0; i < keys.Length; i++) { if (i == keys.Length - 1) { target = temp[keys[i]]; } else { temp = temp[keys[i]] as ArchivableDictionary; } } DA.SetData(0, new GH_ObjectWrapper(target)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <object> objs = new List <object>(); DA.GetDataList(0, objs); if (objs.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No dictionaries found."); return; } List <ArchivableDictionary> dictList = new List <ArchivableDictionary>(); foreach (var obj in objs) { GH_ObjectWrapper goo = obj as GH_ObjectWrapper; if (goo == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary."); return; } ArchivableDictionary dict = goo.Value as ArchivableDictionary; if (dict == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary."); return; } dictList.Add(dict); } if (dictList.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No dictionaries found."); return; } HashSet <string> allProps = new HashSet <string>(); List <string> rows = new List <string>(); // construct headers foreach (var dict in dictList) { allProps.UnionWith(getDictProps("", dict)); } rows.Add(String.Join(",", allProps.ToArray())); foreach (var dict in dictList) { List <string> row = new List <string>(); foreach (string prop in allProps) { row.Add(tryGetProperty(prop, dict).ToString()); } rows.Add(String.Join(",", row)); } csv = String.Join("\n", rows); DA.SetData(0, csv); }
// Dictionaries & ArchivableDictionaries public static Dictionary <string, object> ToSpeckle(this ArchivableDictionary dict, Dictionary <int, string> traversed = null, string path = "root", GeometryBase root = null) { if (dict.Values.Length == 0) { return(null); } if (dict == null) { return(null); } if (traversed == null) { traversed = new Dictionary <int, string>(); traversed.Add(root.GetHashCode(), "root"); } Dictionary <string, object> myDictionary = new Dictionary <string, object>(); foreach (var key in dict.Keys) { var myObj = dict[key]; if (traversed.ContainsKey(myObj.GetHashCode())) { myDictionary.Add(key, new SpeckleAbstract() { _type = "ref", _ref = traversed[myObj.GetHashCode()] }); continue; } traversed.Add(myObj.GetHashCode(), path + "/" + key); if (dict[key] is ArchivableDictionary) { myDictionary.Add(key, (( ArchivableDictionary )dict[key]).ToSpeckle(traversed, path + "/" + key, root)); } else if (dict[key] is string || dict[key] is double || dict[key] is float || dict[key] is int || dict[key] is SpeckleObject) { myDictionary.Add(key, dict[key]); } else if (dict[key] is IEnumerable) { myDictionary.Add(key, "enums not supported yet."); } else { if (dict[key] is GeometryBase) { GeometryBase obj = dict[key] as GeometryBase; ArchivableDictionary dictCopy = obj.UserDictionary.Clone(); obj.UserDictionary.Clear(); SpeckleObject conv = SpeckleCore.Converter.Serialise(obj); conv.Properties = dictCopy.ToSpeckle(traversed, path + "/" + key, root); conv.GenerateHash(); myDictionary.Add(key, conv); obj.UserDictionary.ReplaceContentsWith(dictCopy); } else { myDictionary.Add(key, SpeckleCore.Converter.Serialise(dict[key])); } } } return(myDictionary); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { List <object> objs = new List <object>(); objs = Params.Input[0].VolatileData.AllData(true).ToList <object>(); if (objs.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No dictionaries found."); return; } global = new Dictionary <string, List <object> >(); var first = true; foreach (var obj in objs) { GH_ObjectWrapper goo = obj as GH_ObjectWrapper; if (goo == null) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Provided object not a dictionary."); return; } ArchivableDictionary dict = goo.Value as ArchivableDictionary; if (dict != null) { foreach (var key in dict.Keys) { if ((first)) { global.Add(key, new List <object>()); global[key].Add(dict[key]); } else if (!global.Keys.Contains(key)) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Object dictionaries do not match."); return; } else { global[key].Add(dict[key]); } } } first = false; } if (global.Keys.Count == 0) { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Empty dictionary."); return; } var changed = false; if (Params.Output.Count != global.Keys.Count) { changed = true; } Debug.WriteLine("changed:" + changed); if (changed) { Rhino.RhinoApp.MainApplicationWindow.Invoke(setInputsAndExpireComponent); } else { int k = 0; foreach (var key in global.Keys) { Params.Output[k].Name = Params.Output[k].NickName = key; DA.SetDataList(k++, global[key].Select(x => new GH_ObjectWrapper(x))); } } }