Exemplo n.º 1
0
Arquivo: IO.cs Projeto: i-noah/noah-n
        public static GH_Structure <IGH_Goo> DeserializeGrasshopperData(byte[] array)
        {
            GH_LooseChunk val = new GH_LooseChunk("Noah Data");

            val.Deserialize_Binary(array);
            if (val.ItemCount == 0)
            {
                return(null);
            }

            GH_Structure <IGH_Goo> gH_Structure = new GH_Structure <IGH_Goo>();
            GH_IReader             val2         = val.FindChunk("Block", 0);

            bool boolean = val2.GetBoolean("Empty");

            if (boolean)
            {
                return(null);
            }

            GH_IReader val3 = val2.FindChunk("Data");

            if (val3 == null)
            {
                return(null);
            }
            else if (!gH_Structure.Read(val3))
            {
                return(null);
            }

            return(gH_Structure);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Read a file
        /// </summary>
        /// <param name="reader"></param>
        /// <returns></returns>
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            var hisChunk = reader.FindChunk("historicData");
            var genChunk = reader.FindChunk("genoData");

            if (hisChunk != null)
            {
                var data = new GH_Structure <GH_Number>();
                data.Read(hisChunk);
                Value.historicData = new GH_Structure <GH_Number>(data, true);
            }

            if (genChunk != null)
            {
                var data = new GH_Structure <GH_Guid>();
                data.Read(genChunk);
                Value.genoGuids = new GH_Structure <GH_Guid>(data, true);
            }

            if (reader.ItemExists("popCount"))
            {
                Value.PopCount = reader.GetInt32("popCount");
            }

            return(true);
        }
Exemplo n.º 3
0
        public override bool Read(GH_IReader reader)
        {
            if (storage.Count > 0)
            {
                storage.Clear();
            }
            // Try and read as many "StoredData" chunks as possible.
            // This approach demands that all these chunks are stored under increasing indices.
            for (int i = 0; i < int.MaxValue; i++)
            {
                var chunk = reader.FindChunk("StoredData", i);
                // Stop looking once we've run out.
                if (chunk is null)
                {
                    break;
                }

                var key       = chunk.GetString("Key");
                var treeChunk = chunk.FindChunk("Tree");
                var tree      = new GH_Structure <IGH_Goo>();
                tree.Read(treeChunk);

                storage.Add(key, tree);
            }
            return(base.Read(reader));
        }
Exemplo n.º 4
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            DA.DisableGapLogic();
            string SourceFile = "";

            DA.GetData(0, ref SourceFile);
            if (string.IsNullOrWhiteSpace(SourceFile))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No source file has been specified.");
                return;
            }
            if (!File.Exists(SourceFile))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Source file location doesn't exist: " + SourceFile);
                return;
            }
            byte[] array;
            try
            {
                array = File.ReadAllBytes(SourceFile);
            }
            catch (Exception ex)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, ex.Message);
                return;
            }
            GH_LooseChunk val = new GH_LooseChunk("Grasshopper Data");

            val.Deserialize_Binary(array);
            if (val.ItemCount == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Source data file is corrupt.");
                return;
            }

            GH_Structure <IGH_Goo> gH_Structure = new GH_Structure <IGH_Goo>();
            GH_IReader             val2         = val.FindChunk("Block", 0);

            if (val2 == null)
            {
                base.Params.Output[0].NickName = "?";
                DA.SetDataTree(0, gH_Structure);
            }
            bool boolean = val2.GetBoolean("Empty");

            if (!boolean)
            {
                GH_IReader val3 = val2.FindChunk("Data");
                if (val3 == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Source file is corrupt.");
                }
                else if (!gH_Structure.Read(val3))
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Data could not be deserialized.");
                }
            }
            DA.SetDataTree(0, gH_Structure);
        }
Exemplo n.º 5
0
        public static GH_Structure <IGH_Goo> GetTree(this GH_IReader reader, string treeName)
        {
            var tree       = new GH_Structure <IGH_Goo>();
            var treeReader = reader.FindChunk(treeName);

            tree.Read(treeReader);
            return(tree);
        }
Exemplo n.º 6
0
        public static List <IGH_Goo> GetList(this GH_IReader reader, string listName)
        {
            var listReader = reader.FindChunk(listName);
            var tree       = new GH_Structure <IGH_Goo>();

            tree.Read(listReader);
            return(tree.Branches[0]);
        }
Exemplo n.º 7
0
        public static IGH_Goo GetGoo(this GH_IReader reader, string itemName)
        {
            var dataReader = reader.FindChunk(itemName);
            var tree       = new GH_Structure <IGH_Goo>();

            tree.Read(dataReader);
            return(tree.Branches[0][0]);
        }