示例#1
0
        public static void CreateNewObject(IGH_DocumentObject obj, IGH_Param target, bool isInputSide, int index = 0, float leftMove = 100, string init = null)
        {
            if (obj == null)
            {
                return;
            }

            PointF comRightCenter = new PointF(target.Attributes.Bounds.Left + (isInputSide ? -leftMove:(leftMove + target.Attributes.Bounds.Width)),
                                               target.Attributes.Bounds.Top + target.Attributes.Bounds.Height / 2);

            if (obj is GH_Component)
            {
                GH_Component com = obj as GH_Component;

                CanvasRenderEngine.AddAObjectToCanvas(com, comRightCenter, false, init);

                if (isInputSide)
                {
                    target.AddSource(com.Params.Output[index]);
                }
                else
                {
                    com.Params.Input[index].AddSource(target);
                }
                //com.Params.Output[outIndex].Recipients.Add(target);

                target.OnPingDocument().NewSolution(false);
            }
            else if (obj is IGH_Param)
            {
                IGH_Param param = obj as IGH_Param;

                CanvasRenderEngine.AddAObjectToCanvas(param, comRightCenter, false, init);

                if (isInputSide)
                {
                    target.AddSource(param);
                }
                else
                {
                    param.AddSource(target);
                }

                target.OnPingDocument().NewSolution(false);
            }
            else
            {
                target.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, LanguagableComponent.GetTransLation(new string[]
                {
                    "The added object is not a Component or Parameters!", "添加的对象不是一个运算器或参数!",
                }));
            }
        }
        /*******************************************/
        /**** Helper Methods                    ****/
        /*******************************************/

        protected virtual void MoveLinks(IGH_Param oldParam, IGH_Param newParam)
        {
            foreach (IGH_Param source in oldParam.Sources)
            {
                newParam.AddSource(source);
            }
            foreach (IGH_Param target in oldParam.Recipients)
            {
                target.AddSource(newParam);
            }

            oldParam.IsolateObject();
        }
示例#3
0
        /*******************************************/

        private static void Connect(IGH_Param param, WireInfo wire)
        {
            if (param != null && wire != null && wire.SourceType != null)
            {
                if (wire.IsInput)
                {
                    wire.Source.AddSource(param);
                }
                else
                {
                    param.AddSource(wire.Source);
                }
            }
        }
示例#4
0
 public void Apply(GH_SwitcherComponent component, GH_Document document)
 {
     if (noUnit)
     {
         component.ClearUnit(recompute: true, recordEvent: false);
     }
     else
     {
         component.SwitchUnit(unit, recompute: true, recordEvent: false);
     }
     for (int i = 0; i < inputs.Count; i++)
     {
         GH_SwitcherParamState gH_SwitcherParamState = inputs[i];
         int num = component.Params.IndexOfInputParam(gH_SwitcherParamState.ParameterId);
         if (num == -1)
         {
             continue;
         }
         IGH_Param val = component.Params.Input[num];
         for (int j = 0; j < gH_SwitcherParamState.Targets.Count; j++)
         {
             IGH_Param val2 = document.FindParameter(gH_SwitcherParamState.Targets[j]);
             if (val2 != null)
             {
                 val.AddSource(val2);
             }
         }
     }
     for (int k = 0; k < outputs.Count; k++)
     {
         GH_SwitcherParamState gH_SwitcherParamState2 = outputs[k];
         int num2 = component.Params.IndexOfOutputParam(gH_SwitcherParamState2.ParameterId);
         if (num2 == -1)
         {
             continue;
         }
         IGH_Param val3 = component.Params.Output[num2];
         for (int l = 0; l < gH_SwitcherParamState2.Targets.Count; l++)
         {
             IGH_Param val4 = document.FindParameter(gH_SwitcherParamState2.Targets[l]);
             if (val4 != null)
             {
                 val4.AddSource(val3);
             }
         }
     }
 }
        protected override void BeforeSolveInstance()
        {
            if (valueList == null)
            {
                if (parameter.Sources.Count == 0)
                {
                    valueList = new GH_ValueList();
                }
                else
                {
                    foreach (var source in parameter.Sources)
                    {
                        if (source is GH_ValueList)
                        {
                            valueList = source as GH_ValueList;
                        }
                        return;
                    }
                }

                valueList.CreateAttributes();
                valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 200, this.Attributes.Pivot.Y - 1);
                valueList.ListItems.Clear();

                var alignmentNames  = Enum.GetNames(typeof(GlulamData.CrossSectionPosition));
                var alignmentValues = Enum.GetValues(typeof(GlulamData.CrossSectionPosition));

                for (int i = 0; i < alignmentNames.Length; ++i)
                {
                    valueList.ListItems.Add(new GH_ValueListItem(alignmentNames[i], $"{i}"));
                }

                valueList.SelectItem(4);

                Instances.ActiveCanvas.Document.AddObject(valueList, false);
                parameter.AddSource(valueList);
                parameter.CollectData();
            }
        }
示例#6
0
        /*******************************************/

        private static void Connect(GH_Component component, WireInfo wire)
        {
            if (component != null && wire != null && wire.SourceType != null)
            {
                if (wire.IsInput)
                {
                    IGH_Param param = component.Params.Output.FirstOrDefault(x => GetSourceType(x) == wire.SourceType);
                    if (param == null)
                    {
                        param = component.Params.Output.FirstOrDefault(x => wire.SourceType.IsAssignableFrom(GetSourceType(x)));
                    }
                    if (param == null)
                    {
                        param = component.Params.Output.FirstOrDefault(x => GetSourceType(x) == typeof(object));
                    }
                    if (param != null)
                    {
                        wire.Source.AddSource(param);
                    }
                }
                else
                {
                    IGH_Param param = component.Params.Input.FirstOrDefault(x => GetSourceType(x) == wire.SourceType);
                    if (param == null)
                    {
                        param = component.Params.Input.FirstOrDefault(x =>
                        {
                            Type sourceType = GetSourceType(x);
                            return(sourceType != null && GetSourceType(x).IsAssignableFrom(wire.SourceType));
                        });
                    }
                    if (param != null)
                    {
                        param.AddSource(wire.Source);
                    }
                }
            }
        }
示例#7
0
        protected override void BeforeSolveInstance()
        {
            if (valueList == null)
            {
                if (parameter.Sources.Count == 0)
                {
                    valueList = new GH_ValueList();
                }
                else
                {
                    foreach (var source in parameter.Sources)
                    {
                        if (source is GH_ValueList)
                        {
                            valueList = source as GH_ValueList;
                        }
                        return;
                    }
                }

                valueList.CreateAttributes();
                valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 200, this.Attributes.Pivot.Y - 1);
                valueList.ListItems.Clear();

                var glulamParameters = Glulam.ListProperties();

                foreach (string param in glulamParameters)
                {
                    valueList.ListItems.Add(new GH_ValueListItem(param, $"\"{param}\""));
                }

                Instances.ActiveCanvas.Document.AddObject(valueList, false);
                parameter.AddSource(valueList);
                parameter.CollectData();
            }
        }
示例#8
0
文件: Machine.cs 项目: zimhe/Robots
        protected override void BeforeSolveInstance()
        {
            if (valueList == null)
            {
                if (parameter.Sources.Count == 0)
                {
                    valueList = new GH_ValueList();
                }
                else
                {
                    foreach (var source in parameter.Sources)
                    {
                        if (source is GH_ValueList)
                        {
                            valueList = source as GH_ValueList;
                        }
                        return;
                    }
                }

                valueList.CreateAttributes();
                valueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 180, this.Attributes.Pivot.Y - 31);
                valueList.ListItems.Clear();

                var robotSystems = RobotSystem.ListRobotSystems();

                foreach (string robotSystemName in robotSystems)
                {
                    valueList.ListItems.Add(new GH_ValueListItem(robotSystemName, $"\"{robotSystemName}\""));
                }

                Instances.ActiveCanvas.Document.AddObject(valueList, false);
                parameter.AddSource(valueList);
                parameter.CollectData();
            }
        }
        public static bool ConnectNewObject(this IGH_Param param, IGH_DocumentObject obj)
        {
            if (obj is null)
            {
                return(false);
            }

            if (param.Kind == GH_ParamKind.unknown)
            {
                return(false);
            }

            var document = param.OnPingDocument();

            if (document is null)
            {
                return(false);
            }

            obj.CreateAttributes();
            if (CentralSettings.CanvasFullNames)
            {
                var atts = new List <IGH_Attributes>();
                obj.Attributes.AppendToAttributeTree(atts);
                foreach (var att in atts)
                {
                    att.DocObject.NickName = att.DocObject.Name;
                }
            }

            obj.NewInstanceGuid();
            obj.Attributes.Pivot = default;
            obj.Attributes.PerformLayout();

            float offsetX = param.Kind == GH_ParamKind.input ? -(obj.Attributes.Bounds.X + obj.Attributes.Bounds.Width) - 94 : -(obj.Attributes.Bounds.X) + 100.0f;

            if (obj is IGH_Param)
            {
                obj.Attributes.Pivot = new System.Drawing.PointF(param.Attributes.Pivot.X + offsetX, param.Attributes.Pivot.Y - obj.Attributes.Bounds.Height / 2);
            }
            else if (obj is IGH_Component)
            {
                obj.Attributes.Pivot = new System.Drawing.PointF(param.Attributes.Pivot.X + offsetX, param.Attributes.Pivot.Y);
            }

            obj.Attributes.ExpireLayout();

            document.AddObject(obj, false);
            document.UndoUtil.RecordAddObjectEvent($"Add {obj.Name}", obj);

            if (param.Kind == GH_ParamKind.input)
            {
                if (obj is IGH_Param parameter)
                {
                    param.AddSource(parameter);
                }
                else if (obj is IGH_Component component)
                {
                    var selfType = param.Type;
                    foreach (var output in component.Params.Output)
                    {
                        if (output.GetType() == param.GetType() || output.Type.IsAssignableFrom(selfType))
                        {
                            param.AddSource(output);
                            break;
                        }
                    }
                }
            }
            else
            {
                if (obj is IGH_Param parameter)
                {
                    parameter.AddSource(param);
                }
                else if (obj is IGH_Component component)
                {
                    var selfType = param.Type;
                    foreach (var input in component.Params.Input)
                    {
                        if (input.GetType() == param.GetType() || input.Type.IsAssignableFrom(selfType))
                        {
                            input.AddSource(param);
                            break;
                        }
                    }
                }
            }

            return(true);
        }