コード例 #1
0
        /// <summary>
        /// Creates the panel with the signal name and connects it to the input parameter
        /// </summary>
        /// <param name="text"> The signal name. </param>
        private void CreatePanel(string text)
        {
            // Create a panel
            Grasshopper.Kernel.Special.GH_Panel panel = new Grasshopper.Kernel.Special.GH_Panel();

            // Set the text with the signal name
            panel.SetUserText(text);

            // Change the color of the panel
            panel.Properties.Colour = System.Drawing.Color.White;

            // Get the current active canvas / document
            GH_Document doc = Grasshopper.Instances.ActiveCanvas.Document;

            // Add the panel to the active canvas
            doc.AddObject(panel, false);

            // Change the size of the panel
            panel.Attributes.Bounds = new System.Drawing.RectangleF(0.0f, 0.0f, 80.0f, 25.0f);

            // Set the location of the panel (relative to the location of the input parameter)
            panel.Attributes.Pivot = new System.Drawing.PointF(
                (float)this.Attributes.DocObject.Attributes.Bounds.Left - panel.Attributes.Bounds.Width - 30,
                (float)this.Params.Input[1].Attributes.Bounds.Y - 2);

            // Connect the panel to the input parameter
            Params.Input[1].AddSource(panel);
        }
コード例 #2
0
        public static string getPanelNameAndVal(IGH_Param param)
        {
            Grasshopper.Kernel.Special.GH_Panel myParam = param as Grasshopper.Kernel.Special.GH_Panel;
            if (myParam != null)
            {
                string panelVal = "";

                foreach (Object myObj in myParam.VolatileData.AllData(true))
                {
                    GH_String temporary = myObj as GH_String;
                    string    myString  = temporary.Value;
                    double    mydbl     = 0;
                    try
                    {
                        mydbl = Double.Parse(myString);
                    }
                    catch
                    {
                    }

                    panelVal += mydbl;
                }

                return(myParam.NickName + "," + panelVal);
            }
            else
            {
                return(null);
            }
        }
コード例 #3
0
        public void OpenFile()
        {
            var fdi = new Rhino.UI.OpenFileDialog {
                Filter = "GSA Files(*.gwb)|*.gwb|All files (*.*)|*.*"
            };                                                                                               //"GSA Files(*.gwa; *.gwb)|*.gwa;*.gwb|All files (*.*)|*.*"
            var res = fdi.ShowOpenDialog();

            if (res) // == DialogResult.OK)
            {
                string file = fdi.FileName;

                // instantiate  new panel
                var panel = new Grasshopper.Kernel.Special.GH_Panel();
                panel.CreateAttributes();

                // set the location relative to the open component on the canvas
                panel.Attributes.Pivot = new PointF((float)Attributes.DocObject.Attributes.Bounds.Left -
                                                    panel.Attributes.Bounds.Width - 30, (float)Params.Input[0].Attributes.Pivot.Y - panel.Attributes.Bounds.Height / 2);

                // check for existing input
                while (Params.Input[0].Sources.Count > 0)
                {
                    var input = Params.Input[0].Sources[0];
                    // check if input is the one we automatically create below
                    if (Params.Input[0].Sources[0].InstanceGuid == panelGUID)
                    {
                        // update the UserText in existing panel
                        //RecordUndoEvent("Changed OpenGSA Component input");
                        panel          = input as Grasshopper.Kernel.Special.GH_Panel;
                        panel.UserText = file;
                        panel.ExpireSolution(true); // update the display of the panel
                    }

                    // remove input
                    Params.Input[0].RemoveSource(input);
                }

                //populate panel with our own content
                panel.UserText = file;

                // record the panel's GUID if new, so that we can update it on change
                panelGUID = panel.InstanceGuid;

                //Until now, the panel is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                Grasshopper.Instances.ActiveCanvas.Document.AddObject(panel, false);

                //Connect the new slider to this component
                Params.Input[0].AddSource(panel);

                (this as IGH_VariableParameterComponent).VariableParameterMaintenance();
                Params.OnParametersChanged();
                Params.Input[0].ClearRuntimeMessages();
                CancellationSources.Add(new System.Threading.CancellationTokenSource());
                ClearData();
            }
        }
コード例 #4
0
        public void SaveAsFile()
        {
            var fdi = new Rhino.UI.SaveFileDialog {
                Filter = "GSA Files(*.gwb)|*.gwb|All files (*.*)|*.*"
            };
            var res = fdi.ShowSaveDialog();

            if (res) // == DialogResult.OK)
            {
                fileName        = fdi.FileName;
                usersetFileName = true;
                string mes = gsaSaveModel.SaveAs(fileName).ToString();
                if (mes == GsaAPI.ReturnValue.GS_OK.ToString())
                {
                    canOpen = true;
                    //CreateAttributes();
                    mes = "Saved file";

                    //add panel input with string
                    //delete existing inputs if any
                    while (Params.Input[2].Sources.Count > 0)
                    {
                        Grasshopper.Instances.ActiveCanvas.Document.RemoveObject(Params.Input[2].Sources[0], false);
                    }

                    //instantiate  new panel
                    var panel = new Grasshopper.Kernel.Special.GH_Panel();
                    panel.CreateAttributes();

                    panel.Attributes.Pivot = new PointF((float)Attributes.DocObject.Attributes.Bounds.Left -
                                                        panel.Attributes.Bounds.Width - 40, (float)Attributes.DocObject.Attributes.Bounds.Bottom - panel.Attributes.Bounds.Height);

                    //populate value list with our own data
                    panel.UserText = fileName;

                    //Until now, the panel is a hypothetical object.
                    // This command makes it 'real' and adds it to the canvas.
                    Grasshopper.Instances.ActiveCanvas.Document.AddObject(panel, false);

                    //Connect the new slider to this component
                    Params.Input[2].AddSource(panel);
                    Params.OnParametersChanged();
                    ExpireSolution(true);
                }
                else
                {
                    mes = Char.ToUpper(mes[3]) + mes.Substring(4).ToLower().Replace("_", " ");
                }
                this.Message = mes;
            }
        }
コード例 #5
0
        public static string getPanelName(IGH_Param param)
        {
            Grasshopper.Kernel.Special.GH_Panel myParam = param as Grasshopper.Kernel.Special.GH_Panel;

            if (myParam != null)
            {
                return(myParam.NickName);
            }

            else
            {
                return(null);
            }
        }
コード例 #6
0
 public override void AddedToDocument(GH_Document document)
 {
     base.AddedToDocument(document);
     Attributes.ExpireLayout();
     Attributes.PerformLayout();
     if (Params.Output[0].SourceCount == 0)
     {
         var panel = new Grasshopper.Kernel.Special.GH_Panel();
         panel.CreateAttributes();
         var pivotPoint = new System.Drawing.PointF();
         var bounds     = Attributes.DocObject.Attributes.Bounds;
         pivotPoint.X           = (float)bounds.Right + 50;
         pivotPoint.Y           = (float)(bounds.Y + bounds.Height * 0.5);
         panel.Attributes.Pivot = pivotPoint;
         OnPingDocument().AddObject(panel, false);
         panel.AddSource(Params.Output[0]);
     }
 }
コード例 #7
0
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Component Component           = this;
            GH_Document   GrasshopperDocument = this.OnPingDocument();

            // Creating input parameters
            List <string> data      = new List <string>();
            string        groupName = "";
            bool          trigger   = false;
            object        template  = null;

            // Getting the data from Grasshopper
            DA.GetDataList <string>(0, data);
            DA.GetData <string>(1, ref groupName);
            DA.GetData <object>(2, ref template);
            DA.GetData <bool>(3, ref trigger);

            // If the botton is pressed it will proceed
            if (!trigger)
            {
                return;
            }

            // Detecting the the source parameter for the templateInput
            Grasshopper.Kernel.IGH_Param         templateInput = Component.Params.Input[2];
            IList <Grasshopper.Kernel.IGH_Param> sources       = templateInput.Sources;

            if (!sources.Any())
            {
                return;
            }
            IGH_DocumentObject templateComp = sources[0].Attributes.GetTopLevel.DocObject;


            // Gets component attributes like the bounds of the Panel which is used to shift
            //the next one and get the size of the panels
            IGH_Attributes att    = templateComp.Attributes;
            RectangleF     bounds = att.Bounds;
            int            vShift = (int)Math.Round(bounds.Height) + 10;
            float          refX   = bounds.X;
            float          refY   = bounds.Y + 30 + vShift;

            // Creating a Grasshopper Group g and assignning a nickname and color to it.
            //Adding group g to the GrasshopperDocument
            Grasshopper.Kernel.Special.GH_Group g = new Grasshopper.Kernel.Special.GH_Group();
            g.NickName = groupName;
            g.Colour   = Grasshopper.GUI.Canvas.GH_Skin.group_back;
            GrasshopperDocument.AddObject(g, false);
            List <IGH_Component> components = new List <IGH_Component>();


            // For-loop used to create panels and assign properties to it (size, datalist...)
            int nbCopy = data.Count;

            for (int i = 0; i < nbCopy; i++)
            {
                Grasshopper.Kernel.Special.GH_Panel panel = new Grasshopper.Kernel.Special.GH_Panel();
                panel.CreateAttributes();
                panel.SetUserText(data[i]);
                panel.Attributes.Bounds = bounds;
                panel.Attributes.Pivot  = new PointF(refX, refY + i * vShift);
                GrasshopperDocument.AddObject(panel, false);

                g.AddObject(panel.InstanceGuid);
            }
            GrasshopperDocument.DeselectAll();
        }