예제 #1
0
        /*******************************************/

        private static void Canvas_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e)
        {
            GH_Canvas canvas = sender as GH_Canvas;

            if (canvas == null || !m_UseWireMenu)
            {
                return;
            }

            GH_WireInteraction wire = canvas.ActiveInteraction as GH_WireInteraction;

            if (wire != null)
            {
                // Get source
                FieldInfo sourceField = typeof(GH_WireInteraction).GetField("m_source", BindingFlags.NonPublic | BindingFlags.Instance);
                if (sourceField == null)
                {
                    return;
                }
                IGH_Param sourceParam = sourceField.GetValue(wire) as IGH_Param;

                // Get the source Type
                Type sourceType = GetSourceType(sourceParam);

                // Get IsInput
                FieldInfo inputField = typeof(GH_WireInteraction).GetField("m_dragfrominput", BindingFlags.NonPublic | BindingFlags.Instance);
                if (inputField == null)
                {
                    return;
                }
                bool isInput = (bool)inputField.GetValue(wire);

                // Save wire info
                m_LastWire = new WireInfo
                {
                    Wire       = wire,
                    Source     = sourceParam,
                    SourceType = sourceType,
                    IsInput    = isInput
                };

                try
                {
                    IGH_DocumentObject docObject = sourceParam.Attributes.GetTopLevel.DocObject;
                    m_LastWire.Tags = new HashSet <string> {
                        docObject.Category, docObject.SubCategory
                    };
                }
                catch { }

                Debug.WriteLine(DateTime.Now.ToString("HH:mm:ss") + "- Created wire info.");
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
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);
                    }
                }
            }
        }