public IEnumerable <IModifiable> TargetObjects()
        {
            if (_targetIds.Count != _targetObjs.Count)
            {
                GH_Document doc = OnPingDocument();
                if (doc == null)
                {
                    return new IModifiable[] { }
                }
                ;

                _targetObjs.Clear();
                foreach (Guid id in _targetIds)
                {
                    IGH_DocumentObject obj = doc.FindObject(id, true);

                    if (obj == null)
                    {
                        _targetObjs.Add(null);
                        continue;
                    }
                    _targetObjs.Add(obj as IModifiable);
                }
            }

            return(_targetObjs);
        }
Exemple #2
0
        protected override void Internal_Undo(GH_Document doc)
        {
            IGH_DocumentObject val = doc.FindObject(oldState.ComponentId, true);

            if (val == null || !(val is GH_SwitcherComponent))
            {
                throw new GH_UndoException("Switcher component with id[" + oldState.ComponentId + "] not found");
            }
            GH_SwitcherComponent component = (GH_SwitcherComponent)val;

            oldState.Apply(component, doc);
        }
Exemple #3
0
        //Get Variables
        public bool SetInputs()
        {
            Sliders    = new List <GH_NumberSlider>();
            _genepools = new List <GalapagosGeneListObject>();

            var s = new GH_NumberSlider();
            var g = new GalapagosGeneListObject();

            foreach (var source in OptimizationComponent.Params.Input[0].Sources)
            {
                var guid = source.InstanceGuid;
                _inputGuids.Add(guid);
            }

            if (_inputGuids.Count == 0)
            {
                MessageBox.Show("FrOG needs at least one variable input (defined as a number slider or gene pool, of type integer or float", "FrOG Error");
                return(false);
            }

            foreach (var guid in _inputGuids)
            {
                var input = _doc.FindObject(guid, true);

                if (input == null)
                {
                    MessageBox.Show(
                        "The variables connected to FrOG are inconsistent. This error typically occurs after removing one or more connected number sliders. Please consider deleting and setting up all variables connections again.",
                        "FrOG Error");
                    return(false);
                }

                if (input.ComponentGuid == s.ComponentGuid)
                {
                    var slider = (GH_NumberSlider)input;
                    Sliders.Add(slider);
                }

                if (input.ComponentGuid == g.ComponentGuid)
                {
                    var genepool = (GalapagosGeneListObject)input;
                    _genepools.Add(genepool);
                }
            }

            SetVariables();
            return(true);
        }
Exemple #4
0
        protected override void Internal_Redo(GH_Document doc)
        {
            IGH_DocumentObject val = doc.FindObject(oldState.ComponentId, true);

            if (val == null || !(val is GH_SwitcherComponent))
            {
                throw new GH_UndoException("Switcher component with id[" + oldState.ComponentId + "] not found");
            }
            GH_SwitcherComponent gH_SwitcherComponent = (GH_SwitcherComponent)val;

            if (newUnit != null)
            {
                gH_SwitcherComponent.SwitchUnit(newUnit, recompute: true, recordEvent: false);
            }
            else
            {
                gH_SwitcherComponent.ClearUnit(recompute: false);
            }
        }
Exemple #5
0
        private void SetPackageInput()
        {
            foreach (KeyValuePair <Guid, Guid> item in ParamHookMap)
            {
                IGH_Param           iGH_Param           = base.Params.Find(item.Key);
                GH_ClusterInputHook gH_ClusterInputHook = m_document.FindObject <GH_ClusterInputHook>(item.Value, topLevelOnly: true);

                if (iGH_Param != null && gH_ClusterInputHook != null)
                {
                    GH_Structure <IGH_Goo> gH_Structure = new GH_Structure <IGH_Goo>();
                    IEnumerator            enumerator   = default;
                    for (int i = 0; i < iGH_Param.VolatileData.PathCount; i++)
                    {
                        GH_Path path = iGH_Param.VolatileData.get_Path(i);
                        IList   list = iGH_Param.VolatileData.get_Branch(i);
                        try
                        {
                            enumerator = list.GetEnumerator();
                            while (enumerator.MoveNext())
                            {
                                IGH_Goo data = (IGH_Goo)enumerator.Current;
                                gH_Structure.Append(data, path);
                            }
                        }
                        finally
                        {
                            if (enumerator is IDisposable)
                            {
                                (enumerator as IDisposable).Dispose();
                            }
                        }

                        gH_ClusterInputHook.SetPlaceholderData(gH_Structure);
                    }
                }
            }
        }
Exemple #6
0
    public static void UpStreamObjects(List <IGH_DocumentObject> upComponents, IGH_DocumentObject obj, GH_Document docu)
    {
        //Find all the upstream components from a given starting node.


        IGH_Param param = obj as IGH_Param;

        if (param != null)
        {
            if (!upComponents.Contains(obj))
            {
                upComponents.Add(obj);
            }

            IList <IGH_Param> params2 = param.Sources;
            foreach (IGH_Param p in params2)
            {
                Guid id = p.Attributes.GetTopLevel.InstanceGuid;
                IGH_DocumentObject comp2 = docu.FindObject(id, true);
                IGH_ActiveObject   PA    = comp2 as IGH_ActiveObject;
                UpStreamObjects(upComponents, PA, docu);
            }
        }

        IGH_Component comp = obj as IGH_Component;

        if (comp != null)
        {
            List <IGH_DocumentObject> PreviousComponents = new List <IGH_DocumentObject>();


            List <IGH_Param> paramtrs = comp.Params.Input;

            foreach (IGH_Param pm in paramtrs)
            {
                IList <IGH_Param> sources = pm.Sources;
                foreach (IGH_Param pm2 in sources)
                {
                    Guid id = pm2.Attributes.GetTopLevel.InstanceGuid;
                    IGH_DocumentObject comp2 = docu.FindObject(id, true);
                    if (comp2 != null)
                    {
                        PreviousComponents.Add(comp2);
                    }
                }
            }

            if (PreviousComponents.Count == 0)
            {
                if (!upComponents.Contains(obj))
                {
                    upComponents.Add(obj);
                }
            }

            else
            {
                if (!upComponents.Contains(obj))
                {
                    upComponents.Add(obj);
                }


                foreach (IGH_DocumentObject obj3 in PreviousComponents)
                {
                    UpStreamObjects(upComponents, obj3, docu);
                }
            }
        }
    }