예제 #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!", "添加的对象不是一个运算器或参数!",
                }));
            }
        }
예제 #2
0
        public WireConnectRenderItem(IGH_Param target, ParamGlassesComponent owner, Func <bool> showFunc = null)
            : base(target, showFunc, true)
        {
            if (!target.Attributes.HasInputGrip)
            {
                throw new ArgumentOutOfRangeException("Target must has InputGrip!");
            }
            ParamProxies = new List <GooTypeProxy>();
            this.Owner   = owner;

            UpdateParamProxy();
            target.OnPingDocument().SolutionEnd += WireConnectRenderItem_SolutionEnd;
        }
예제 #3
0
        public static IGH_DocumentObject ConnectNewObject(this IGH_Param self, Guid componentGuid)
        {
            var document = self.OnPingDocument();

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

            var obj = Grasshopper.Instances.ComponentServer.EmitObject(componentGuid) as IGH_ActiveObject;

            if (obj is null)
            {
                return(null);
            }

            obj.CreateAttributes();
            if (Grasshopper.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 = new System.Drawing.PointF();
            obj.Attributes.PerformLayout();

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

            obj.Attributes.ExpireLayout();

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

            if (obj is IGH_Param param)
            {
                param.AddSource(self);
            }
            else if (obj is IGH_Component component)
            {
                var selfType = self.Type;
                foreach (var input in component.Params.Input.Where(i => typeof(GH.Types.IGH_ElementId).IsAssignableFrom(i.Type)))
                {
                    if (input.GetType() == self.GetType() || input.Type.IsAssignableFrom(selfType))
                    {
                        input.AddSource(self);
                        break;
                    }
                }
            }

            return(obj);
        }
        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);
        }