public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);

            executeTimer = new System.Timers.Timer(500)
            {
                AutoReset = false, Enabled = false
            };
            executeTimer.Elapsed += ExecuteTimer_Elapsed;

            if (selectedMethod == null)
            {
                var myForm = new UrlGrabber();
                var result = myForm.ShowDialog();
                myForm.StartPosition = FormStartPosition.Manual;
                Grasshopper.GUI.GH_WindowsFormUtil.CenterFormOnCursor(myForm, true);

                if (result == DialogResult.OK)
                {
                    selectedMethod = myForm.selectedMethod;
                    SetIO();
                }
            }
            else
            {
                //SetIO(); // io is already set you
            }
        }
Esempio n. 2
0
        public PoopUp( )
        {
            InitializeComponent();

            var bindingList = new BindingList <CcMethod>(Cc.METHODS);
            var source      = new BindingSource(bindingList, null);

            this.MethodGrid.DataSource = ConvertToDatatable(Cc.METHODS);

            this.MethodGrid.DefaultCellStyle.BackColor = Color.White;
            this.MethodGrid.DefaultCellStyle.Font      = new Font("Tahoma", 8);
            this.MethodGrid.DefaultCellStyle.Padding   = new Padding(5);

            this.MethodGrid.RowHeadersVisible    = false;
            this.MethodGrid.ColumnHeadersVisible = false;

            this.MethodGrid.Columns["isCtor"].Visible      = false;
            this.MethodGrid.Columns["returnsSelf"].Visible = false;
            this.MethodGrid.Columns["parent"].DisplayIndex = 0;
            this.MethodGrid.Columns["parent"].Width        = 500;
            this.MethodGrid.Columns["name"].DisplayIndex   = 1;
            this.MethodGrid.Columns["name"].Width          = 342;
            this.MethodGrid.Columns["inpt"].DisplayIndex   = 2;
            this.MethodGrid.Columns["inpt"].Width          = 402;

            this.SearchBox.TextChanged += SearchBox_TextChanged;
            this.SearchBox.GotFocus    += (object sender, EventArgs e) =>
            {
                if (SearchBox.Text == "type to search")
                {
                    SearchBox.Text = "";
                }
                SearchBox.ForeColor = Color.Black;
            };

            this.SearchBox.LostFocus += (object sender, EventArgs e) =>
            {
                //SearchBox.Text = "type to search...";
                SearchBox.ForeColor = Color.DimGray;
            };

            this.KeyDown           += PoopUp_KeyDown;
            this.SearchBox.KeyDown += PoopUp_KeyDown;

            this.KeyDown += (object sender, KeyEventArgs e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    var x = MethodGrid.CurrentRow.DataBoundItem as DataRowView;
                    selectedMethod = Cc.METHODS[Convert.ToInt32(( string )x.Row.ItemArray[7])];

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            };
        }
        public override bool Read(GH_IReader reader)
        {
            try
            {
                var methodId = reader.GetString("ccmethod");
                selectedMethod = Cc.METHODS[Convert.ToInt32(methodId)];
            }
            catch { }

            return(base.Read(reader));
        }
        private void MethodBox_TextChanged(object sender, EventArgs e)
        {
            Uri  uriResult;
            bool result = Uri.TryCreate(MethodBox.Text, UriKind.Absolute, out uriResult) &&
                          (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps);

            if (!result)
            {
                return;
            }

            var httpWebRequest = ( HttpWebRequest )WebRequest.Create(uriResult);

            httpWebRequest.Method = "GET";

            try
            {
                var httpResponse = ( HttpWebResponse )httpWebRequest.GetResponse();

                //basic check so we don't load the BBC
                if (httpResponse.Headers["content-type"] != "application/json")
                {
                    return;
                }

                using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                {
                    var responseString = streamReader.ReadToEnd();
                    var myres          = result;

                    TreeTree.Nodes.Clear();

                    TreeNode myTree = Json2Tree(JsonConvert.DeserializeObject <JObject>(responseString));


                    TreeTree.Nodes.Add(myTree);
                    TreeTree.Refresh();

                    this.responseMethod = JsonConvert.DeserializeObject <CcMethod>(responseString);
                    if (this.responseMethod == null)
                    {
                        return;
                    }

                    this.responseMethod.url        = uriResult.ToString();
                    this.responseMethod.methodBase = Cc.METHODS[Convert.ToInt32(this.responseMethod.methodId)].methodBase;
                }
            }
            catch
            {
            }
        }
        public override void AddedToDocument(GH_Document document)
        {
            base.AddedToDocument(document);

            if (selectedMethod == null)
            {
                var myForm = new PoopUp();
                var result = myForm.ShowDialog();
                myForm.StartPosition = FormStartPosition.Manual;
                Grasshopper.GUI.GH_WindowsFormUtil.CenterFormOnCursor(myForm, true);

                if (result == DialogResult.OK)
                {
                    selectedMethod = myForm.selectedMethod;
                    SetIO();
                }
            }
        }
        public UrlGrabber( )
        {
            InitializeComponent();

            MethodBox.TextChanged += MethodBox_TextChanged;

            this.KeyDown += (object sender, KeyEventArgs e) =>
            {
                if (e.KeyCode == Keys.Enter)
                {
                    if (this.responseMethod == null)
                    {
                        MessageBox.Show("No method selected. Sorry!");
                        return;
                    }

                    this.selectedMethod = this.responseMethod;

                    this.DialogResult = DialogResult.OK;
                    this.Close();
                }
            };
        }
Esempio n. 7
0
        public void CreateMethodsCollections( )
        {
            var asm = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.GetName().Name == "RhinoCommon");

            //var types = asm.GetTypes().Where( type => type.FullName.Contains( "Rhino.Geometry.Intersect" ) ).ToList();
            //var types = asm.GetTypes().Where( type => type.FullName == "Rhino.Geometry.Arc" ).ToList();
            var types = asm.GetTypes().Where(type => type.FullName.Contains("Rhino.Geometry")).ToList();

            string[] dontexpose = new string[] { "ToString", "GetHashCode", "GetType", "get_Unset", "Equals", "HasFlag" };

            List <CcMethodCollection> GlobalList = new List <CcMethodCollection>();
            int k = 0;

            foreach (Type myType in types)
            {
                var methods = myType.GetMethods();
                foreach (var method in methods)
                {
                    var myMethod = new CcMethod();
                    if (dontexpose.Any(method.Name.Contains))
                    {
                        continue;
                    }

                    myMethod.name       = method.Name;
                    myMethod.methodBase = method;
                    myMethod.isStatic   = method.IsStatic;

                    var pinfos = method.GetParameters();
                    foreach (var pi in pinfos)
                    {
                        if (pi.ParameterType.IsByRef)
                        {
                            myMethod.outputs.Add(new CcParam()
                            {
                                name = pi.Name, type = pi.ParameterType.FullName, isByRef = pi.ParameterType.IsByRef, isOptional = pi.IsOptional
                            });
                        }
                        else
                        {
                            myMethod.inputs.Add(new CcParam()
                            {
                                name = pi.Name, type = pi.ParameterType.FullName, isByRef = pi.ParameterType.IsByRef, isOptional = pi.IsOptional
                            });
                        }
                    }

                    if (!method.IsStatic)
                    {
                        myMethod.inputs.Add(new CcParam()
                        {
                            name = myType.Name, type = myType.FullName, isSelf = true
                        });
                    }

                    if (method.ReturnParameter.ParameterType == typeof(void))
                    {
                        myMethod.outputs.Add(new CcParam()
                        {
                            name = "Out " + myType.Name, type = myType.FullName
                        });
                        myMethod.returnsSelf = true;
                    }
                    else
                    {
                        myMethod.outputs.Add(new CcParam()
                        {
                            name = method.ReturnParameter.ParameterType.Name, type = method.ReturnParameter.ParameterType.FullName
                        });
                    }

                    myMethod.parent   = myType.FullName;
                    myMethod.methodId = k++.ToString();
                    Cc.METHODS.Add(myMethod);
                }

                // CTORS
                var ctors = myType.GetConstructors();
                foreach (var ctor in ctors)
                {
                    var myMethod = new CcMethod();
                    myMethod.isCtor     = true;
                    myMethod.name       = "New " + myType.Name;
                    myMethod.methodBase = ctor;

                    var pinfos = ctor.GetParameters();
                    foreach (var pi in pinfos)
                    {
                        if (pi.ParameterType.IsByRef)
                        {
                            myMethod.outputs.Add(new CcParam()
                            {
                                name = pi.Name, type = pi.ParameterType.FullName, isByRef = pi.ParameterType.IsByRef, isOptional = pi.IsOptional
                            });
                        }
                        else
                        {
                            myMethod.inputs.Add(new CcParam()
                            {
                                name = pi.Name, type = pi.ParameterType.FullName, isByRef = pi.ParameterType.IsByRef, isOptional = pi.IsOptional
                            });
                        }
                    }
                    myMethod.outputs.Add(
                        new CcParam()
                    {
                        name = myType.Name, type = myType.FullName, isByRef = false
                    });

                    myMethod.parent   = myType.FullName;
                    myMethod.methodId = k++.ToString();
                    Cc.METHODS.Add(myMethod);
                }
            }
        }