Exemplo n.º 1
0
        public override bool Read(GH_IReader reader)
        {
            var result = base.Read(reader);

            m_script = new CsxScript();

            m_script.OnError += OnError;

            var source = reader.GetString("source");

            if (File.Exists(source))
            {
                SourceUri = source;
                m_script.DefineSource(SourceUri);
            }

            m_script.OnUpdated += OnUpdated;

            m_inside  = new CsxInputsSide(this, m_script);
            m_outside = new CsxOutputsSide(this, m_script);

            if (reader.ChunkExists("m_inconnector"))
            {
                m_inside.Read(reader.FindChunk("m_inconnector"));
            }

            if (reader.ChunkExists("m_outconnector"))
            {
                m_outside.Read(reader.FindChunk("m_outconnector"));
            }

            return(result);
        }
Exemplo n.º 2
0
 public bool Read(GH_IReader reader)
 {
     if (reader.ChunkExists("params"))
     {
         GH_IReader val = reader.FindChunk("params");
         if (val.ChunkExists("input") && inputs != null)
         {
             GH_IReader val2 = val.FindChunk("input");
             int        num  = -1;
             if (val2.TryGetInt32("count", ref num) && inputs.Count == num)
             {
                 for (int i = 0; i < num; i++)
                 {
                     if (val2.ChunkExists("p", i))
                     {
                         inputs[i].Parameter.Read(val2.FindChunk("p", i));
                     }
                     else if (val2.ChunkExists("param", i))
                     {
                         inputs[i].Parameter.Read(val2.FindChunk("param", i));
                     }
                 }
             }
         }
         if (val.ChunkExists("output") && outputs != null)
         {
             GH_IReader val3 = val.FindChunk("output");
             int        num2 = -1;
             if (val3.TryGetInt32("count", ref num2) && outputs.Count == num2)
             {
                 for (int j = 0; j < num2; j++)
                 {
                     if (val3.ChunkExists("p", j))
                     {
                         outputs[j].Parameter.Read(val3.FindChunk("p", j));
                     }
                     else if (val3.ChunkExists("param", j))
                     {
                         outputs[j].Parameter.Read(val3.FindChunk("param", j));
                     }
                 }
             }
         }
     }
     try
     {
         GH_IReader val4 = reader.FindChunk("context");
         if (val4 != null)
         {
             cxt.Collection.Read(val4);
         }
     }
     catch (Exception ex)
     {
         RhinoApp.WriteLine("Component error:" + ex.Message + "\n" + ex.StackTrace);
     }
     return(true);
 }
Exemplo n.º 3
0
        public override bool Read(GH_IReader reader)
        {
            bool flag = true;

            SetReadState();
            flag &= base.Read(reader);
            string text = null;

            if (reader.ChunkExists("ActiveUnit"))
            {
                text = reader.FindChunk("ActiveUnit").GetString("unitname");
            }
            if (reader.ChunkExists("EvalUnits"))
            {
                GH_IReader val = reader.FindChunk("EvalUnits");
                int        num = -1;
                if (val.TryGetInt32("count", ref num))
                {
                    for (int i = 0; i < num; i++)
                    {
                        if (val.ChunkExists("unit", i))
                        {
                            GH_IReader val2    = val.FindChunk("unit", i);
                            string     @string = val2.GetString("name");
                            if (text != null)
                            {
                                @string.Equals(text);
                            }
                            evalUnits.GetUnit(@string)?.Read(val2);
                        }
                    }
                }
            }
            if (text != null)
            {
                GetUnit(text);
                SwitchUnit(GetUnit(text), recompute: false, recordEvent: false);
            }
            for (int j = 0; j < EvalUnits.Count; j++)
            {
                if (!EvalUnits[j].Active)
                {
                    EvalUnits[j].NewParameterIds();
                }
            }
            OnComponentLoaded();
            return(flag);
        }
        public override bool Read(GH_IReader reader)
        {
            GH_IReader gH_IReader = reader.FindChunk("Checkbox", Index);

            _active = gH_IReader.GetBoolean("Active");
            return(true);
        }
Exemplo n.º 5
0
        public override bool Read(GH_IReader reader)
        {
            Container = null;
            if (!base.Read(reader))
            {
                return(false);
            }
            RemapToTarget = reader.GetBoolean("Remap");
            if (RemapToTarget)
            {
                Message = "Remap";
            }
            else
            {
                Message = string.Empty;
            }
            GH_IReader gH_IReader = reader.FindChunk("LocalGraph");

            if (gH_IReader != null)
            {
                GH_GraphContainer val = new GH_GraphContainer(null);
                if (!val.Read(gH_IReader))
                {
                    return(false);
                }
                Container = val;
            }
            return(true);
        }
Exemplo n.º 6
0
 public override bool Read(GH_IReader reader)
 {
     serializedDocumentObjectPivotVectors = reader.FindChunk("SelectedDocumentObjects").Items.Select(x => x.InternalData)
                                            .Cast <GH_Point2D>().ToArray();
     isSerialized = false;
     return(base.Read(reader));
 }
Exemplo n.º 7
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.º 8
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));
        }
        public override bool Read(GH_IReader reader)
        {
            GH_IReader val = reader.FindChunk("RadioButton", Index);

            _active = val.GetBoolean("Active");
            return(true);
        }
Exemplo n.º 10
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.º 11
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]);
        }
Exemplo n.º 12
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.º 13
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.º 14
0
        public override bool Read(GH_IReader reader)
        {
            GH_IReader reader2 = reader.FindChunk("Panel", Index);

            for (int i = 0; i < _controls.Count; i++)
            {
                _controls[i].Read(reader2);
            }
            return(base.Read(reader));
        }
Exemplo n.º 15
0
        private static GH_ISerializable ReadGH_ISerializable(GH_IReader reader)
        {
            var valueTypeString     = reader.GetString("TypeString");
            var valueAssemblyString = reader.GetString("AssemblyString");
            var valueInstance       = (GH_ISerializable)Activator.CreateInstance(valueAssemblyString, valueTypeString).Unwrap();
            var instanceReader      = reader.FindChunk("Data");

            valueInstance.Read(instanceReader);
            return(valueInstance);
        }
Exemplo n.º 16
0
        public static IDictionary <T1, T2> GetDictionary <T1, T2>(
            this GH_IReader reader,
            string itemName,
            Func <GH_IReader, string, int, T1> keyGetter,
            Func <GH_IReader, string, int, T2> valueGetter
            )
        {
            var dataReader = reader.FindChunk(itemName);

            return(ReadDictionary(dataReader, keyGetter, valueGetter));
        }
Exemplo n.º 17
0
        public override bool Read(GH_IReader reader)
        {
            GH_IReader val = reader.FindChunk("MenuDropDown", Index);

            try
            {
                current_value = val.GetInt32("ActiveItemIndex");
            }
            catch
            {
                current_value = default_item_index;
            }
            return(true);
        }
        public override bool Read(GH_IReader reader)
        {
            GH_IReader gH_IReader = reader.FindChunk("Slider", Index);

            minValue     = gH_IReader.GetDouble("MinValue");
            maxValue     = gH_IReader.GetDouble("MaxValue");
            currentValue = gH_IReader.GetDouble("CurrentValue");
            if (!gH_IReader.TryGetInt32("NumDecimals", ref numDecimals))
            {
                numDecimals = 2;
            }
            FixValues();
            return(true);
        }
        public override bool Read(GH_IReader reader)
        {
            //IL_0078: Unknown result type (might be due to invalid IL or missing references)
            //IL_007e: Expected O, but got Unknown
            string     text = "RadioButtonGroup";
            GH_IReader val  = reader.FindChunk(text, Index);

            if (val == null)
            {
                List <GH_IChunk> chunks = ((GH_IChunk)reader).Chunks;
                GH_IChunk        val2   = null;
                foreach (GH_IChunk chunk in ((GH_IChunk)reader).Chunks)
                {
                    if (chunk.Name.Equals(text))
                    {
                        val2 = chunk;
                        break;
                    }
                }
                if (val2 == null)
                {
                    throw new ArgumentException("fail");
                }
                if (chunks.Count != 1)
                {
                    throw new ArgumentException("RadioButtonGroup could not be loaded");
                }
                val = (GH_IReader)(GH_Chunk)val2;
            }
            int        count = _buttons.Count;
            int        @int  = val.GetInt32("Count");
            GH_IReader val3  = val.FindChunk("Active");

            actives.Clear();
            for (int i = 0; i < count; i++)
            {
                bool boolean = val3.GetBoolean("button", i);
                _buttons[i].Active = boolean;
                if (boolean)
                {
                    actives.Add(_buttons[i]);
                }
            }
            return(true);
        }
Exemplo n.º 20
0
        public override bool Read(GH_IReader reader)
        {
            int mode = 1;

            reader.TryGetInt32("UIMode", ref mode);
            reader.TryGetInt32("ListMode", ref mode);
            this.ListMode = (GH_ValueListMode)mode;
            int count = reader.GetInt32("ListCount");
            int cache = 0;

            reader.TryGetInt32("CacheCount", ref cache);
            this.m_userItems.Clear();
            int arg_52_0 = 0;
            int num      = count - 1;

            for (int i = arg_52_0; i <= num; i++)
            {
                GH_IReader chunk = reader.FindChunk("ListItem", i);
                if (chunk == null)
                {
                    reader.AddMessage("Missing chunk for List Value: " + i.ToString(), GH_Message_Type.error);
                }
                else
                {
                    string itemName       = chunk.GetString("Name");
                    string itemExpression = chunk.GetString("Expression");
                    bool   itemSelected   = false;
                    chunk.TryGetBoolean("Selected", ref itemSelected);
                    Type            t = JsonConvert.DeserializeObject <Type>(chunk.GetString("Type"));
                    object          deserializedExpression = JsonConvert.DeserializeObject(itemExpression, t);
                    GuanacoListItem item = new GuanacoListItem(itemName, deserializedExpression);
                    item.Selected = itemSelected;
                    this.m_userItems.Add(item);
                }
            }
            if (reader.ItemExists("ListIndex"))
            {
                int idx = reader.GetInt32("ListIndex");
                if (idx >= 0 && idx < this.m_userItems.Count)
                {
                    this.m_userItems[idx].Selected = true;
                }
            }
            return(base.Read(reader));
        }
Exemplo n.º 21
0
        /// <summary>
        /// Read all required data for deserialization from an IO archive.
        /// </summary>
        /// <param name="reader">Object to read with.</param>
        /// <returns>
        /// True on success, false on failure.
        /// </returns>
        public override bool Read(GH_IReader reader)
        {
            // set up a "shadow" state set of only basic data types
            // check out that wackadoodle data type - it's a Dictionary<string, Dictionary<Tuple<Guid, int>, object>>  :-p
            Dictionary <string, Dictionary <Tuple <Guid, int>, object> > stateSet = new Dictionary <string, Dictionary <Tuple <Guid, int>, object> >();
            GH_IReader stateSetChunk = reader.FindChunk("stateSetChunk");
            int        stateCount    = stateSetChunk.GetInt32("StateCount");

            //for all the states in the archive
            for (int i = 0; i < stateCount; i++)
            {
                Dictionary <Tuple <Guid, int>, object> state = new Dictionary <Tuple <Guid, int>, object>();
                GH_IReader stateChunk = stateSetChunk.FindChunk("State", i);
                string     stateName  = stateChunk.GetString("stateName");
                int        itemCount  = stateChunk.GetInt32("itemCount");

                //for all the elements in the state
                for (int j = 0; j < itemCount; j++)
                {
                    GH_IReader stateItemChunk   = stateChunk.FindChunk("stateItem", j);
                    Guid       elementID        = new Guid(stateItemChunk.GetString("ElementID"));
                    int        index            = stateItemChunk.GetInt32("ElementIndex");
                    string     elementValue     = stateItemChunk.GetString("ElementValue");
                    string     elementValueType = stateItemChunk.GetString("ElementValueType");

                    Tuple <Guid, int> goo   = new Tuple <Guid, int>(elementID, index);
                    object            value = getValue(elementValue, elementValueType);
                    state.Add(goo, value);
                }
                if (stateSet.ContainsKey(stateName))
                {
                    stateSet[stateName] = state;
                }
                else
                {
                    stateSet.Add(stateName, state);
                }
            }
            savedShadowStates = stateSet;



            return(base.Read(reader));
        }
Exemplo n.º 22
0
        //
        // Writing and Reading.
        // Any methods to save custom properties apart from those of the original
        // component should be defined here.
        // ______________________________________________

        public override bool Read(GH_IReader reader)
        {
            try
            {
                GH_IReader reader2 = reader.FindChunk("Hoopsnake_Data");
                if (reader2 != null)
                {
                    dataLimit          = Int32.MaxValue;// FIX THAT!!! //int.Parse(reader2.GetInt32("dataLimit").ToString());
                    resetCounterOnLoop = reader2.GetBoolean("resetCounter");
                    updateView         = reader2.GetBoolean("updateView");
                    autoUpdate         = reader2.GetBoolean("autoUpdate");
                    int newDelay = 0;
                    reader2.TryGetInt32("delay", ref newDelay);
                }
            }
            catch {}
            // In the end, call the reader of the base component to load inherited fields.
            return(base.Read(reader));
        }
Exemplo n.º 23
0
        public bool Read(GH_IReader reader)
        {
            GH_IReader val = reader.FindChunk("Collection");

            if (val == null)
            {
                RhinoApp.WriteLine("Invalid menu collection");
                return(false);
            }
            for (int i = 0; i < _menus.Count; i++)
            {
                GH_IReader val2 = val.FindChunk("Menu", i);
                if (val2 == null)
                {
                    return(false);
                }
                _menus[i].Read(val2);
            }
            return(true);
        }
Exemplo n.º 24
0
 public override bool Read(GH_IReader reader)
 {
     try {
         base.Read(reader);
         var count = reader.GetInt32("GridCount");
         var data  = new GH_Structure <GH_VoxelGrid>();
         for (var i = 0; i < count; i++)
         {
             var currentGrid = reader.FindChunk("Grid", i);
             var gridString  = currentGrid.GetString("Data");
             var pathString  = currentGrid.GetString("Path");
             var path        = new GH_Path();
             path.FromString(pathString);
             var output = ByteHelper.ToVoxelGrid(ByteHelper.Decompress(ByteHelper.StringToByteArray(gridString)));
             data.Append(new GH_VoxelGrid(output), path);
         }
         SetPersistentData(data);
         return(true);
     } catch (Exception e) {
         AddRuntimeMessage(GH_RuntimeMessageLevel.Error, e + " " + e.StackTrace);
         return(true);
     }
 }
Exemplo n.º 25
0
        public override bool Read(GH_IReader reader)
        {
            int num1 = 1;

            reader.TryGetInt32("UIMode", ref num1);
            reader.TryGetInt32("ListMode", ref num1);
            ListMode = (GH_ValueListMode)num1;
            int int32 = reader.GetInt32("ListCount");
            int num2  = 0;

            reader.TryGetInt32("CacheCount", ref num2);
            m_userItems.Clear();
            int num3 = 0;
            int num4 = int32 - 1;

            for (int index = num3; index <= num4; ++index)
            {
                GH_IReader chunk = reader.FindChunk("ListItem", index);
                if (chunk == null)
                {
                    reader.AddMessage("Missing chunk for List Value: " + index.ToString(), GH_Message_Type.error);
                }
                else
                {
                    string name       = chunk.GetString("Name");
                    string expression = chunk.GetString("Expression");
                    bool   flag       = false;
                    chunk.TryGetBoolean("Selected", ref flag);
                    m_userItems.Add(new GH_ValueListItem(name, expression)
                    {
                        Selected = flag
                    });
                }
            }
            return(base.Read(reader));
        }
Exemplo n.º 26
0
        public static IEnumerable <T> GetEnumerable <T>(this GH_IReader reader, string itemName, Func <GH_IReader, string, int, T> getter)
        {
            var dataReader = reader.FindChunk(itemName);

            return(ReadEnumerable <T>(dataReader, getter));
        }
Exemplo n.º 27
0
        public static GeometryBase GetGeometryBase(this GH_IReader reader, string itemName)
        {
            var dataReader = reader.FindChunk(itemName);

            return(ReadGeometryBase(dataReader));
        }
Exemplo n.º 28
0
        //
        // Writing and Reading.
        // Any methods to save custom properties apart from those of the original
        // component should be defined here.
        // ______________________________________________

        public override bool Read(GH_IReader reader)
        {
            try
            {
                GH_IReader reader2 = reader.FindChunk("Hoopsnake_Data");
                if (reader2 != null)
                {
                    dataLimit = Int32.MaxValue;// FIX THAT!!! //int.Parse(reader2.GetInt32("dataLimit").ToString());
                    resetCounterOnLoop = reader2.GetBoolean("resetCounter");
                    updateView = reader2.GetBoolean("updateView");
                    autoUpdate = reader2.GetBoolean("autoUpdate");
                    int newDelay = 0;
                    reader2.TryGetInt32("delay", ref newDelay);
                }
            }
            catch {}
            // In the end, call the reader of the base component to load inherited fields.
            return base.Read(reader);
        }
Exemplo n.º 29
0
        public static GH_ISerializable GetGH_ISerializable(this GH_IReader reader, string itemName)
        {
            var dataReader = reader.FindChunk(itemName);

            return(ReadGH_ISerializable(dataReader));
        }