Exemple #1
0
        //this resets the parameter - clears the context menu options and sets the current member name to empty string
        public void Reset(GeomObjGoo goo)
        {
            GeomObject obj = goo.Value;

            this.Update(obj);
            this.OnDisplayExpired(true);
        }
Exemple #2
0
        /// This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GeomObjGoo objGoo = new GeomObjGoo();

            if (!DA.GetData(0, ref objGoo))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "No Object received");
                return;
            }

            this.obj = objGoo.Value.Duplicate();
            if (obj.MemberDict.Count == 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The Object is empty");
                return;
            }
            //making a copy of the object in case mutation fails
            GeomObject obj_original = obj.Duplicate();

            MemberSelect param0 = Params.Input[0] as MemberSelect;

            param0.Update(obj);

            //now mutating the object
            List <IGH_Goo> obj_in = new List <IGH_Goo>();

            if (!DA.GetDataList(1, obj_in))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, "The member was not replaced: No replacement received");
                DA.SetData(0, new GeomObjGoo(obj_original));
                return;
            }
            //Debug.WriteLine(obj_in[0] == null);
            //here check if all data are of same type within the list of this param
            if (!ObjectifyComponent.validDatatypes(obj_in))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "All data in an object member should be of the same type!");
                return;
            }

            MemberInput param1 = Params.Input[1] as MemberInput;

            param1.HasGeometry = typeof(IGH_GeometricGoo).IsAssignableFrom(obj_in[0].GetType());
            if (!obj.MemberDict.ContainsKey(param0.NickName))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "The object does not have a member with this name !");
                return;
            }

            //deleting the old member
            obj.MemberDict.Remove(param0.NickName);
            obj.MemberDict.Add(param0.NickName, obj_in);

            //now updating the visibility and bakability settings
            this.obj.Visibility[param0.NickName] = param1.Settings["Visible"];
            this.obj.Bakability[param0.NickName] = param1.Settings["Bakable"];

            DA.SetData(0, new GeomObjGoo(obj));
        }
Exemple #3
0
 //constructor
 public ObjectifyComponent()
     : base("Objectify", "Object",
            "Creates an object out of the input data",
            "Data", "Objectify")
 {
     obj = new GeomObject(this.NickName);
     Params.ParameterChanged += new GH_ComponentParamServer.ParameterChangedEventHandler(OnParameterChanged);
 }
Exemple #4
0
        //this updates the context menu to member names and then sets the current member to the first one if it is unset
        public void Update(GeomObject obj)
        {
            this._options.Clear();
            foreach (string key in obj.MemberDict.Keys)
            {
                _options.Add(key);
            }

            //if nickname not set then empty string
            if (this.NickName == "" && _options.Count > 0)
            {
                this.NickName = _options[0];
            }
        }
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            List <IGH_Goo> members = new List <IGH_Goo>();

            for (int i = 0; i < Params.Input.Count; i++)
            {
                GeomObjGoo   objGoo   = new GeomObjGoo();
                MemberSelect curParam = Params.Input[i] as MemberSelect;
                if (curParam == null)
                {
                    continue;
                }
                if (!DA.GetData(i, ref objGoo))
                {
                    curParam.Reset(objGoo);
                    continue;
                }

                GeomObject obj = objGoo.Value;
                if (obj.MemberDict.Count == 0)
                {
                    //AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Nothing to show");
                    curParam.Reset(objGoo);
                    continue;
                }

                curParam.Update(obj);
                string key = curParam.NickName;
                if (obj.MemberDict.ContainsKey(key))
                {
                    members.AddRange(obj.MemberDict[key]);
                }
            }

            //returning as a list or as a single item based how many things need to be returned
            if (members.Count == 1)
            {
                Params.Output[0].Access = GH_ParamAccess.item;
                DA.SetData(0, members.First());
            }
            else
            {
                Params.Output[0].Access = GH_ParamAccess.item;
                DA.SetDataList(0, members);
            }
        }
Exemple #6
0
    //this is for morphing - dont even know what it is, but I dont have to
    public GeomObject Morph(SpaceMorph morph)
    {
        GeomObject mObj = Duplicate();

        foreach (string key in mObj.MemberDict.Keys)
        {
            List <IGH_Goo> newData = new List <IGH_Goo>();
            for (int i = 0; i < mObj.MemberDict[key].Count; i++)
            {
                if (typeof(IGH_GeometricGoo).IsAssignableFrom(mObj.MemberDict[key][i].GetType()))
                {
                    IGH_GeometricGoo geom = (IGH_GeometricGoo)mObj.MemberDict[key][i];
                    mObj.MemberDict[key][i] = geom.Morph(morph);
                }
            }
        }

        return(mObj);
    }
Exemple #7
0
    //this is for transform
    public GeomObject Transform(Transform xform)
    {
        GeomObject xObj = Duplicate();

        foreach (string key in xObj.MemberDict.Keys)
        {
            List <IGH_Goo> newData = new List <IGH_Goo>();
            for (int i = 0; i < xObj.MemberDict[key].Count; i++)
            {
                if (typeof(IGH_GeometricGoo).IsAssignableFrom(xObj.MemberDict[key][i].GetType()))
                {
                    IGH_GeometricGoo geom = (IGH_GeometricGoo)xObj.MemberDict[key][i];
                    xObj.MemberDict[key][i] = geom.Transform(xform);
                }
            }
        }

        return(xObj);
    }
Exemple #8
0
    //this copies the object - all data except geometry unless the bool is true
    public GeomObject Duplicate()
    {
        //have to manually recreate the object to avoid references and create a true deep copy
        GeomObject nObj = new GeomObject(this._name);

        foreach (string key in this._memberDict.Keys)
        {
            nObj._memberDict.Add(key, this._memberDict[key].Select((m) => m.Duplicate()).ToList());
        }
        foreach (string key in this._visibility.Keys)
        {
            nObj._visibility.Add(key, this._visibility[key]);
        }
        foreach (string key in this._bakability.Keys)
        {
            nObj._bakability.Add(key, this._bakability[key]);
        }

        return(nObj);
    }
Exemple #9
0
 //constructor
 public MutateObject() :
     base("Mutate Object", "Mutate", "Mutate an object by changing one or more members", "Data", "Objectify")
 {
     obj = new GeomObject(this.NickName);
     Params.ParameterChanged += new GH_ComponentParamServer.ParameterChangedEventHandler(OnParameterChanged);
 }