Exemplo n.º 1
0
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            string all = "";

            if (reader.TryGetString("selectedobject", ref all))
            {
                //storedPath = all;
                if (all.Length > 0)
                {
                    string[] seg = all.Split(new char[] { '|' });
                    storedPath = new List <string>(seg);
                }
            }
            bool readLock     = false;
            bool readMaintain = false;
            bool readOrder    = false;

            if (reader.TryGetBoolean("lock", ref readLock))
            {
                inputLock = readLock;
            }
            if (reader.TryGetBoolean("maintain", ref readMaintain))
            {
                maintainPath = readMaintain;
            }
            if (reader.TryGetBoolean("order", ref readOrder))
            {
                sortByIndex = readMaintain;
            }
            return(base.Read(reader));
        }
Exemplo n.º 2
0
        /*************************************/

        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            if (!base.Read(reader))
            {
                return(false);
            }

            string callerString = ""; reader.TryGetString("Component", ref callerString);

            if (Caller.Read(callerString))
            {
                int selection = -1;
                reader.TryGetInt32("Selection", ref selection);

                if (selection >= 0 && selection < ListItems.Count)
                {
                    //To acount for changes in orders of enums and dataset, match name of previous item with name of new items instead of
                    //simply relying on previous index.

                    //Get name of selected item
                    string prevName = ListItems[selection].Name;
                    //Find index in list of new items with matching name to selected name
                    int index = Caller.GetChoiceNames().IndexOf(prevName);
                    //Make sure component is up to date with backend caller
                    UpdateFromSelectedItem();

                    //If index is found, update to this. If item is not found, use previous selection.
                    if (index != -1)
                    {
                        selection = index;
                    }

                    //As item count might have been reduced in UpdateFromSelected, a final check that the selection is not out of bounds needed.
                    if (selection < ListItems.Count)
                    {
                        this.SelectItem(selection);
                    }
                }
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 3
0
        /*************************************/

        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            if (!base.Read(reader) || !Params.Read(reader))
            {
                return(false);
            }

            if (reader.ArchiveLocation != null && reader.ArchiveLocation != m_CurrentLoadingDocument)
            {
                BH.UI.Base.Global.DocumentListener.OnDocumentBeginOpening(reader.ArchiveLocation);
                m_CurrentLoadingDocument = reader.ArchiveLocation;
            }

            string callerString = ""; reader.TryGetString("Component", ref callerString);

            Caller.Read(callerString);

            return(true);
        }
Exemplo n.º 4
0
        // Deserialize this instance from a Grasshopper reader object.
        //Serialization is required for reading persistent data from a .gh or .ghx file.
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            string s = "";

            if (reader.TryGetString("Object_bin", ref s))
            {
                IFormatter   formatter           = RFSerializer.GetInstance().Formatter;
                MemoryStream serializationStream = new MemoryStream(Convert.FromBase64String(s));
                try
                {
                    serializationStream.Position = 0;
                    Value = ((RFFilter)formatter.Deserialize(serializationStream));
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(base.Read(reader));
        }
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            props_visible = false;
            reader.TryGetBoolean("props_visible", ref props_visible);
            if (props_visible)
            {
                VariableParameterMaintenance();
            }

            script_variables_in_use = new List <string>();
            for (int s = 0; s < reader.ItemCount; s++)
            {
                string str = null;
                reader.TryGetString("script_variables_in_use[" + s + "]", ref str);
                if (str != null)
                {
                    script_variables_in_use.Add(str);
                }
            }

            bool ret = base.Read(reader);

            return(ret);
        }
Exemplo n.º 6
0
 public override bool Read(GH_IO.Serialization.GH_IReader reader)
 {
     reader.TryGetString("path", ref selectedFolder);
     return(base.Read(reader));
 }
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            // 8 Aug. 2012
            // There are a couple of "hacks" in here to get IO code to work properly.
            // I'll discuss fixes for this so we can skip over the code in future
            // versions of grasshopper

            bool perform_hacks = this is IGH_VarParamComponent;

            if (perform_hacks)
            {
                // only perform these hacks on 0.9.6 and below. Assuming that this
                // will get fixed in the very next GH release
                var version = Grasshopper.Versioning.Version;
                if (version.major > 0 || version.minor > 9 || (version.minor == 9 && version.revision > 6))
                {
                    perform_hacks = false;
                }
            }

            if (perform_hacks)
            {
                // Hack #1
                // When deserializing, this component is constructed and the I can't tell
                // that this component was created for deserializing from disk and the
                // "AddDefaultInput" / "AddDefaultOutput" functions are called. The low level
                // parameter reading code skips reading of params when they already exists
                // (see Read_IGH_VarParamParamList in GH_ComponentParamServer.vb)
                //   ... If (i<params.Count) Then Continue For
                // Clear out the default input parameters so the GH variable
                // parameter reader doesn't get hosed
                for (int i = Params.Input.Count - 1; i >= 0; i--)
                {
                    Params.UnregisterParameter(Params.Input[0]);
                }
                for (int i = Params.Output.Count - 1; i >= 0; i--)
                {
                    Params.UnregisterParameter(Params.Output[0]);
                }
            }

            bool rc = base.Read(reader);

            if (perform_hacks)
            {
                // Hack #2
                // The IO code in checks to see if "Access" exists when it looks like
                // it should be checking if "Access" at index exists
                // (see Read_IGH_VarParamParamList in GH_ComponentParamServer.vb)
                //   ...If( reader.ItemExists("Access")) Then
                //   probably should be
                //   ...If( reader.ItemExists("Access", i)) Then
                //
                // Working around this issue by manually digging through the chuncks
                if (reader.ChunkCount > 1)
                {
                    var chunk = reader.Chunks[1];
                    for (int i = 0; i < chunk.ItemCount; i++)
                    {
                        var item = chunk.Items[i];
                        if (item != null && string.Compare(item.Name, "Access", StringComparison.InvariantCulture) == 0)
                        {
                            int index = item.Index;
                            if (index >= 0 && index < Params.Input.Count)
                            {
                                int access = item._int32;
                                if (1 == access)
                                {
                                    Params.Input[index].Access = GH_ParamAccess.list;
                                }
                                else if (2 == access)
                                {
                                    Params.Input[index].Access = GH_ParamAccess.tree;
                                }
                            }
                        }
                    }
                }
            }

            bool hideInput = false;

            if (reader.TryGetBoolean(HideInputIdentifier, ref hideInput))
            {
                CodeInputVisible = !hideInput;
            }

            if (!CodeInputVisible)
            {
                string code = null;
                if (reader.TryGetString(CodeInputIdentifier, ref code))
                {
                    CodeInput = code;
                }
            }


            bool hideOutput = false;

            if (reader.TryGetBoolean(HideOutputIdentifier, ref hideOutput))
            {
                HideCodeOutput = hideOutput;
            }

            if (HideCodeOutput)
            {
                Params.Output.RemoveAt(0);
            }


            // Dynamic input fix for existing scripts
            // Always assign DynamicHint or Grasshopper
            // will set Line and not LineCurve, etc...
            if (Params != null && Params.Input != null)
            {
                for (int i = CodeInputVisible ? 1 : 0; i < Params.Input.Count; i++)
                {
                    var p = Params.Input[i] as Param_ScriptVariable; // ksteinfe (previously Param_ScriptVariable)
                    if (p != null)
                    {
                        FixGhInput(p, false);
                        if (p.TypeHint == null)
                        {
                            p.TypeHint = p.Hints[0];
                        }
                    }
                }
            }
            return(rc);
        }
        public override bool Read(GH_IO.Serialization.GH_IReader reader)
        {
            // 2013 Oct 8 - Giulio
            // Removing all hacks and making this work properly from Gh 0.9.61 onwards
            // The logic is this: this component ALWAYS gets constructed without "code" & with "out".
            // Then, when they are not necessary, these are added or removed.
            // RegisterInput/Output must always insert the original amount of items.


            if (reader.ItemExists(ID_EditorLocation))
            {
                DefaultEditorLocation = reader.GetDrawingPoint(ID_EditorLocation);
            }
            if (reader.ItemExists(ID_EditorSize))
            {
                DefaultEditorSize = reader.GetDrawingSize(ID_EditorSize);
            }

            bool hideInput = true;

            if (reader.TryGetBoolean(ID_HideInput, ref hideInput))
            {
                HiddenCodeInput = hideInput;
            }

            bool hideOutput = false;

            if (reader.TryGetBoolean(ID_HideOutput, ref hideOutput))
            {
                HiddenOutOutput = hideOutput;
            }

            if (hideInput)
            {
                if (!reader.TryGetString(ID_CodeInput, ref m_inner_codeInput))
                {
                    m_inner_codeInput = string.Empty;
                }
            }

            bool rc = base.Read(reader);


            // Dynamic input fix for existing scripts
            // Always assign DynamicHint or Grasshopper
            // will set Line and not LineCurve, etc...
            if (Params != null && Params.Input != null)
            {
                for (int i = HiddenCodeInput ? 1 : 0; i < Params.Input.Count; i++)
                {
                    var p = Params.Input[i] as Param_ScriptVariable;
                    if (p != null)
                    {
                        FixGhInput(p, false);
                        if (p.TypeHint == null)
                        {
                            p.TypeHint = p.Hints[0];
                        }
                    }
                }
            }
            return(rc);
        }