Exemple #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);
        }
Exemple #2
0
    internal static bool CreateIfEmpty(GH_Document document, GH_Component component, ElementType type, string?selected = null)
    {
        var inputParam = component.Params.First();

        if (inputParam.SourceCount > 0)
        {
            return(false);
        }

        var libraryParam = new LibraryParam
        {
            _type = type
        };

        if (selected is not null)
        {
            var selectedItem = new GH_ValueListItem(selected, $"\"{selected}\"")
            {
                Selected = true
            };

            libraryParam.ListItems.Add(selectedItem);
        }

        libraryParam.Update();
        var pivot = component.Attributes.Pivot;

        libraryParam.Attributes.Pivot = new PointF(pivot.X - 240, pivot.Y - 21);
        document.AddObject(libraryParam, false);
        inputParam.AddSource(libraryParam);
        return(true);
    }
Exemple #3
0
        /// <summary>
        /// Generates selection list for cell oritentation.
        /// </summary>
        /// <param name="index">Component input index. (first input is index 0)</param>
        /// <param name="offset">Vertical offset of the menu, to help with positioning.</param>
        public static void OrientSelect(ref IGH_Component Component, ref GH_Document GrasshopperDocument, int index, float offset)
        {
            // Instantiate  new value list
            var vallist = new Grasshopper.Kernel.Special.GH_ValueList();

            vallist.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.Cycle;
            vallist.CreateAttributes();

            // Customise value list position
            float  xCoord   = (float)Component.Attributes.Pivot.X - 200;
            float  yCoord   = (float)Component.Attributes.Pivot.Y + index * 40 - offset;
            PointF cornerPt = new PointF(xCoord, yCoord);

            vallist.Attributes.Pivot = cornerPt;

            // Populate value list with our own data
            vallist.ListItems.Clear();
            var items = new List <Grasshopper.Kernel.Special.GH_ValueListItem>();

            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Default", "0"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateZ", "1"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateY", "2"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("RotateX", "3"));

            vallist.ListItems.AddRange(items);

            // Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(vallist, false);

            //Connect the new slider to this component
            Component.Params.Input[index].AddSource(vallist);
            Component.Params.Input[index].CollectData();
        }
Exemple #4
0
        private static GrasshopperDefinition Construct(Guid componentId)
        {
            var component = Grasshopper.Instances.ComponentServer.EmitObject(componentId) as GH_Component;

            if (component == null)
            {
                return(null);
            }

            var definition = new GH_Document();

            definition.AddObject(component, false);

            // raise DocumentServer.DocumentAdded event (used by some plug-ins)
            Grasshopper.Instances.DocumentServer.AddDocument(definition);

            GrasshopperDefinition rc = new GrasshopperDefinition(definition);

            rc._singularComponent = component;
            foreach (var input in component.Params.Input)
            {
                rc._input[input.NickName] = new InputGroup(input);
            }
            foreach (var output in component.Params.Output)
            {
                rc._output[output.NickName] = output;
            }
            return(rc);
        }
        /// <summary>
        /// Adds a property to the component's inputs.
        /// </summary>
        /// <param name="param"></param>
        private void RegisterPropertyAsInputParameter(ParameterInfo param, int index)
        {
            // get property name and value
              Type propType = param.ParameterType;
              if (propType.IsGenericType && propType.GetGenericTypeDefinition() == typeof(Nullable<>))
            propType = Nullable.GetUnderlyingType(propType);

              string propName = param.Name;
              object propValue = param;

              var inputDesc = param.GetCustomAttribute<SchemaParamInfo>();
              var d = inputDesc != null ? inputDesc.Description : "";
              if (param.IsOptional)
              {
            if (!string.IsNullOrEmpty(d))
              d += ", ";
            var def = param.DefaultValue == null ? "null" : param.DefaultValue.ToString();
            d += "default = " + def;
              }

              // Create new param based on property name
              Param_GenericObject newInputParam = new Param_GenericObject();
              newInputParam.Name = propName;
              newInputParam.NickName = propName;
              newInputParam.MutableNickName = false;

              newInputParam.Description = $"({propType.Name}) {d}";
              newInputParam.Optional = param.IsOptional;
              if (param.IsOptional)
            newInputParam.SetPersistentData(param.DefaultValue);

              // check if input needs to be a list or item access
              bool isCollection = typeof(System.Collections.IEnumerable).IsAssignableFrom(propType) &&
                          propType != typeof(string) && !propType.Name.ToLower().Contains("dictionary");
              if (isCollection == true)
              {
            newInputParam.Access = GH_ParamAccess.list;
              }
              else
              {
            newInputParam.Access = GH_ParamAccess.item;
              }

              Params.RegisterInputParam(newInputParam, index);

              //add dropdown
              if (propType.IsEnum)
              {
            //expire solution so that node gets proper size
            ExpireSolution(true);

            var instance = Activator.CreateInstance(propType);

            var vals = Enum.GetValues(propType).Cast<Enum>().Select(x => x.ToString()).ToList();
            var options = CreateDropDown(propName, vals, Attributes.Bounds.X, Params.Input[index].Attributes.Bounds.Y);
            _document.AddObject(options, false);
            Params.Input[index].AddSource(options);
              }
        }
Exemple #6
0
        private void AddToggle()
        {
            var toggle = new GH.Kernel.Special.GH_BooleanToggle();

            toggle.CreateAttributes();
            toggle.Value            = false;
            toggle.NickName         = "Release the fly...";
            toggle.Attributes.Pivot = new PointF((float)(this.Attributes.Bounds.Left - 200), (float)(this.Attributes.Bounds.Top + 30));
            doc.AddObject(toggle, false);
            this.Params.Input[1].AddSource(toggle);
            toggle.ExpireSolution(true);

            grp = new GH.Kernel.Special.GH_Group();
            grp.CreateAttributes();
            grp.Border = GH.Kernel.Special.GH_GroupBorder.Blob;
            grp.AddObject(toggle.InstanceGuid);
            grp.Colour   = System.Drawing.Color.IndianRed;
            grp.NickName = "";
            doc.AddObject(grp, false);
        }
Exemple #7
0
        /// <summary>
        /// Adds a property to the component's inputs.
        /// </summary>
        /// <param name="prop"></param>
        void RegisterPropertyAsInputParameter(PropertyInfo prop, int index)
        {
            // get property name and value
            Type propType = prop.PropertyType;

            string propName  = prop.Name;
            object propValue = prop;

            // Create new param based on property name
            Param_GenericObject newInputParam = new Param_GenericObject();

            newInputParam.Name            = propName;
            newInputParam.NickName        = propName;
            newInputParam.MutableNickName = false;
            newInputParam.Description     = propName + " as " + propType.Name;
            newInputParam.Optional        = true;

            // check if input needs to be a list or item access
            bool isCollection = typeof(System.Collections.IEnumerable).IsAssignableFrom(propType) && propType != typeof(string) && !propType.Name.ToLower().Contains("dictionary");

            if (isCollection == true)
            {
                newInputParam.Access = GH_ParamAccess.list;
            }
            else
            {
                newInputParam.Access = GH_ParamAccess.item;
            }
            Params.RegisterInputParam(newInputParam, index);


            //add dropdown
            if (propType.IsEnum)
            {
                //expire solution so that node gets proper size
                ExpireSolution(true);

                var instance = Activator.CreateInstance(propType);

                var vals    = Enum.GetValues(propType).Cast <Enum>().Select(x => x.ToString()).ToList();
                var options = CreateDropDown(propName, vals, Attributes.Bounds.X, Params.Input[index].Attributes.Bounds.Y);
                _document.AddObject(options, false);
                Params.Input[index].AddSource(options);
            }
        }
Exemple #8
0
        private void createAccentList(object sender, System.EventArgs e)
        {
            GH_ValueList vl = new GH_ValueList();

            vl.ListItems.Clear();
            foreach (string color in ACCENT_COLORS)
            {
                GH_ValueListItem vi = new GH_ValueListItem(color, String.Format("\"{0}\"", color));
                vl.ListItems.Add(vi);
            }
            vl.NickName = "Accent Colors";
            GH_Document doc = OnPingDocument();

            doc.AddObject(vl, false, doc.ObjectCount + 1);
            PointF currPivot = Params.Input[3].Attributes.Pivot;

            vl.Attributes.Pivot = new PointF(currPivot.X - 120, currPivot.Y - 11);
        }
Exemple #9
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool   activate = false;

            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename))
            {
                return;
            }
            if (!DA.GetData(1, ref activate))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null)
            {
                return;
            }
            if (!File.Exists(filename))
            {
                return;
            }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);
            }
        }
Exemple #10
0
        ////////////////////////////////////////////////////////////////////////
        // Create a drop down to select supported robot if no robot selected.
        private void RobotOptionList()
        {
            // TODO: check instead if alreeady set.
            // Create robot Option List.
            GH_ValueList robotValueList = new GH_ValueList();

            robotValueList.CreateAttributes();
            robotValueList.Attributes.Pivot = new PointF(this.Attributes.Pivot.X - 300, this.Attributes.Pivot.Y - 41);
            robotValueList.ListItems.Clear();
            robotValueList.NickName = "Robot";
            // Add supported robot names.
            foreach (string robotName in HoloBot.listRobotNames)
            {
                GH_ValueListItem item = new GH_ValueListItem(robotName, "\"" + robotName + "\"");
                robotValueList.ListItems.Add(item);
            }
            // Update grasshopper document.
            GH_Document document = this.OnPingDocument();

            document.AddObject(robotValueList, false);
            this.Params.Input[0].AddSource(robotValueList);
            this.Params.Input[0].CollectData();
        }
Exemple #11
0
        /// <summary>
        /// Generates selection list for preset unit cell topologies.
        /// </summary>
        /// <param name="index">Component input index. (first input is index 0)</param>
        /// <param name="offset">Vertical offset of the menu, to help with positioning.</param>
        public static void TopoSelect(ref IGH_Component Component, ref GH_Document GrasshopperDocument, int index, float offset)
        {
            // Instantiate  new value list
            var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
            vallist.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.Cycle;
            vallist.CreateAttributes();

            // Customise value list position
            float xCoord = (float)Component.Attributes.Pivot.X - 250;
            float yCoord = (float)Component.Attributes.Pivot.Y + index * 40 - offset;
            PointF cornerPt = new PointF(xCoord, yCoord);
            vallist.Attributes.Pivot = cornerPt;

            // Populate value list with our own data
            vallist.ListItems.Clear();
            var items = new List<Grasshopper.Kernel.Special.GH_ValueListItem>();
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Grid", "0"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("X", "1"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Star", "2"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Cross", "3"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Tesseract", "4"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Vintiles", "5"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Octet", "6"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Diamond", "7"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Honeycomb 1", "8"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Honeycomb 2", "9"));

            vallist.ListItems.AddRange(items);

            // Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(vallist, false);

            //Connect the new slider to this component
            Component.Params.Input[index].AddSource(vallist);
            Component.Params.Input[index].CollectData();
        }
Exemple #12
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[10].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[10].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[10].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[10].AddSource(vallist);
            }
            //AQUI COMEÇA O PLGUIN MESMO
            double t1     = 0;
            double t2     = 0;
            double al1    = 0;
            double al2    = 0;
            double npar   = 0;
            double npep   = 0;
            double d      = 0;
            string type   = "bolt";
            int    wood   = 0;
            bool   pdrill = false;
            double pk     = 0;
            bool   sd     = false;
            double kmod   = 0;
            double Vrd    = 0;
            double a1     = 0;
            double a4     = 0;
            double dw     = 0;

            if (!DA.GetData <double>(0, ref Vrd))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref t1))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref t2))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref al1))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref al2))
            {
                return;
            }
            if (!DA.GetData <double>(5, ref npar))
            {
                return;
            }
            if (!DA.GetData <double>(6, ref npep))
            {
                return;
            }
            if (!DA.GetData <double>(7, ref d))
            {
                return;
            }
            if (!DA.GetData <bool>(8, ref sd))
            {
                return;
            }
            if (!DA.GetData <double>(9, ref kmod))
            {
                return;
            }
            if (!DA.GetData <int>(10, ref wood))
            {
                return;
            }
            if (!DA.GetData <double>(11, ref a1))
            {
                return;
            }
            if (!DA.GetData <double>(12, ref a4))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref a4))
            {
                return;
            }

            //Pegar valores da Madeira do Excel
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var    reader   = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));
            int    cont     = -1;
            bool   stop     = false;
            string woodtype = "";
            double fc90     = 0;

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == wood)
                {
                    pk       = 1000 * Double.Parse(values[7]);
                    woodtype = values[13];
                    fc90     = 10 * Double.Parse(values[4]);
                    stop     = true;
                }
                cont++;
            }
            //CALCULO DAS LIGAÇÕES
            var    fast     = new Fastener(type, d, dw, -1, true, 1000);
            var    analysis = new TimberToTimberCapacity(fast, t1, t2, al1, al2, woodtype, "steel", pdrill, pk, pk, fc90, woodtype, -1, -1, npar, npep, a1);
            double fvd      = 0;

            if (sd == false)
            {
                fvd = kmod * analysis.FvkSingleShear() / 1.3;
            }
            else
            {
                fvd = kmod * analysis.FvkDoubleShear() / 1.3;
            }
            double faxd = kmod * analysis.variables.Faxrk / 1.3;
            double DIV  = 0;

            DIV = 1000 * Vrd / fvd;
            DA.SetData(0, fvd);
            DA.SetData(1, DIV);
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[8].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[8].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[8].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[8].AddSource(vallist);
            }
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var reader = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));
            //inputs
            double Nd    = 0;
            double Myd   = 0;
            double Mzd   = 0;
            double b     = 0;
            double h     = 0;
            double l     = 0;
            double kflam = 0;
            double Kmod  = 0;
            double Km    = 0.7;
            double Ym    = 0;
            double fc0k  = 0;
            double fmk   = 0;
            double E05   = 0;
            double Bc    = 0.2;
            int    test  = 0;

            if (!DA.GetData <double>(0, ref Nd))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref Myd))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref Mzd))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref b))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref h))
            {
                return;
            }
            if (!DA.GetData <double>(5, ref l))
            {
                return;
            }
            if (!DA.GetData <double>(6, ref kflam))
            {
                return;
            }
            if (!DA.GetData <int>(8, ref test))
            {
                return;
            }
            if (!DA.GetData <double>(7, ref Kmod))
            {
                return;
            }
            int  cont = -1;
            bool stop = false;

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == test)
                {
                    Ym   = Double.Parse(values[12]);
                    fc0k = Double.Parse(values[1]);
                    fmk  = Double.Parse(values[3]);
                    E05  = Double.Parse(values[9]);
                    if (values[13] == "MLC")
                    {
                        Bc = 0.1;
                    }
                    stop = true;
                }
                cont++;
            }
            //Definição de valores geométricos
            double A    = h * b;
            double Iy   = b * Math.Pow(h, 3) / 12;
            double Iz   = h * Math.Pow(b, 3) / 12;
            double Wy   = Iy * (2 / h);
            double Wz   = Iz * (2 / b);
            double ry   = Math.Sqrt(Iy / A);
            double rz   = Math.Sqrt(Iz / A);
            double lamy = ry / (100 * l);
            double lamz = rz / (100 * l);
            double lef  = kflam * l * 100;

            //Definição de valores do material (ver se os sigmas devem mesmo serem multiplicados por 100)
            double lampi   = Math.Sqrt(fc0k / E05) / Math.PI;
            double fc0d    = Kmod * fc0k / Ym;
            double fmd     = Kmod * fmk / Ym;
            double lamyrel = lamy * lampi;
            double lamzrel = lamz * lampi;
            double sigN    = Nd / A;
            double sigMy   = 100 * Myd / Wy;
            double sigMz   = 100 * Mzd / Wz;
            double G05     = E05 / 16;

            //Definição dos valores de cálculo necessários para verificação em pilares ou vigas (exclui parte em que dizia que lamrely=lamm e lamrelz=sgmcrit)
            double sigMcrit = (Math.PI * Math.Pow(b, 2) * Math.Sqrt(E05 * G05 * (1 - 0.63 * (b / h)))) / (h * lef);
            double lamm     = Math.Sqrt(fmk / sigMcrit);
            double ky       = 0.5 * (1 + Bc * (lamyrel - 0.3) + Math.Pow(lamyrel, 2));
            double kz       = 0.5 * (1 + Bc * (lamzrel - 0.3) + Math.Pow(lamzrel, 2));
            double kyc      = 1 / (ky + Math.Sqrt(Math.Pow(ky, 2) - Math.Pow(lamyrel, 2)));
            double kzc      = 1 / (kz + Math.Sqrt(Math.Pow(kz, 2) - Math.Pow(lamzrel, 2)));

            //Verificação de comportamento de Pilares
            if (lamm < 0.75)
            {
                if (lamyrel <= 0.3 && lamzrel <= 0.3)
                {
                    double DIVY = Math.Pow(sigN / fc0d, 2) + (sigMy / fmd) + Km * (sigMz / fmd);
                    double DIVZ = Math.Pow(sigN / fc0d, 2) + Km * (sigMy / fmd) + (sigMz / fmd);
                    DA.SetData(0, DIVY);
                    DA.SetData(1, DIVZ);
                }
                else
                {
                    List <double> divs = new List <double>();
                    double        DIVY = (sigN / (kyc * fc0d)) + (sigMy / fmd) + Km * (sigMz / fmd);
                    double        DIVZ = (sigN / (kzc * fc0d)) + Km * (sigMy / fmd) + (sigMz / fmd);
                    DA.SetData(0, DIVY);
                    DA.SetData(1, DIVZ);
                }
            }
            //Verificação de comportamento de Vigas
            else
            {
                if (lamm >= 0.75 && lamm < 1.4)
                {
                    double kcrit = 1.56 - 0.75 * lamm;
                    double DIVY  = Math.Pow(sigMy / (kcrit * fmd), 2) + (sigN / (kzc * fc0d));
                    double DIVZ  = 0;
                    DA.SetData(0, DIVY);
                    DA.SetData(1, DIVZ);
                }
                if (lamm >= 1.4)
                {
                    double kcrit = 1 / Math.Pow(lamm, 2);
                    double DIVY  = Math.Pow(sigMy / (kcrit * fmd), 2) + (sigN / (kzc * fc0d));
                    double DIVZ  = 0;
                    DA.SetData(0, DIVY);
                    DA.SetData(1, DIVZ);
                }
            }

            //Outros Outputs
            DA.SetData(2, lamm);
        }
        public void InitCluster()
        {
            debugText = "";

            // if we had a previous document, then let's delete it and start over
            if (wormDoc != null)
            {
                wormDoc.Enabled = false;
                wormDoc.RemoveObject(wormCluster, false);
                wormDoc.Dispose();
                wormDoc = null;
            }

            ////////////////////////
            // get clusterFileURL param again, since inputs may not have run if invalid
            ////////////////////////
            string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString();

            ////////////////////////
            // get clustername and process/validate into URL
            ////////////////////////
            string clusterUrl = processValidateClusterName(clusterName);

            ////////////////////////
            // set path for temporary file location
            ////////////////////////
            string tempPath = System.IO.Path.GetTempPath();
            Uri uri = new Uri(clusterUrl);
            string filename = System.IO.Path.GetFileName(uri.LocalPath);
            fullTempFilePath = tempPath + filename;

            ////////////////////////
            // attempt to downloadCluster file
            ////////////////////////

            using (WebClient Client = new WebClient())
            {
                try {
                    Client.DownloadFile(clusterUrl, fullTempFilePath);
                }
                catch(WebException webEx)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message);

                }
            }
            debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n";
            debugText += "into " + fullTempFilePath + "\n";

            // if gh file doesn't exist in temporary location, abort
            if (!File.Exists(fullTempFilePath)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!"); }

            ////////////////////////
            // Create a cluster
            ////////////////////////

            // create cluster
            wormCluster = new GH_Cluster();
            wormCluster.CreateFromFilePath(fullTempFilePath);

            // set cluster parameter count
            clusterParamNumInput = wormCluster.Params.Input.Count;
            clusterParamNumOutput = wormCluster.Params.Output.Count;
            debugText += "\ncluster input params # = " + clusterParamNumInput;
            debugText += "\ncluster output params # = " + clusterParamNumOutput;

            // add/remove/rename parameters to match cluster parameter count.
            MatchParameterCount();

            // change hairworm name to match cluster name
            if(wormCluster.Name == "Cluster") {
                HairwormClusterName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
            } else {
                HairwormClusterName = wormCluster.Name;
                HairwormClusterNickName = wormCluster.NickName;
            }
            Name = HairwormBaseName + " (" + HairwormClusterName + ")";
            NickName = HairwormBaseName + " (" + this.HairwormClusterNickName + ")";
            debugText += "cluster is named = " + wormCluster.Name;
            debugText += "cluster is nicknamed = " + wormCluster.NickName;

            //get new document, enable it, and add cluster to it
            wormDoc = new GH_Document();
            wormDoc.Enabled = true;
            wormDoc.AddObject(wormCluster, true, 0);

            // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params)
            loadedClusterUrlParam = clusterUrlParam;

            ExpireSolution(true);
        }
Exemple #15
0
        public void InitCluster()
        {
            debugText = "";

            // if we had a previous document, then let's delete it and start over
            if (wormDoc != null)
            {
                wormDoc.Enabled = false;
                wormDoc.RemoveObject(wormCluster, false);
                wormDoc.Dispose();
                wormDoc = null;
            }

            ////////////////////////
            // get clusterFileURL param again, since inputs may not have run if invalid
            ////////////////////////
            string clusterName = Params.Input[0].VolatileData.get_Branch(0)[0].ToString();

            ////////////////////////
            // get clustername and process/validate into URL
            ////////////////////////
            string clusterUrl = processValidateClusterName(clusterName);


            ////////////////////////
            // set path for temporary file location
            ////////////////////////
            string tempPath = System.IO.Path.GetTempPath();
            Uri    uri      = new Uri(clusterUrl);
            string filename = System.IO.Path.GetFileName(uri.LocalPath);

            fullTempFilePath = tempPath + filename;

            ////////////////////////
            // attempt to downloadCluster file
            ////////////////////////

            using (WebClient Client = new WebClient())
            {
                try {
                    Client.DownloadFile(clusterUrl, fullTempFilePath);
                }
                catch (WebException webEx)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Network error: " + webEx.Message);
                }
            }
            debugText += "Downloaded file " + clusterUrl + ", " + filename + "\n";
            debugText += "into " + fullTempFilePath + "\n";

            // if gh file doesn't exist in temporary location, abort
            if (!File.Exists(fullTempFilePath))
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "File does not exist!");
            }

            ////////////////////////
            // Create a cluster
            ////////////////////////

            // create cluster
            wormCluster = new GH_Cluster();
            wormCluster.CreateFromFilePath(fullTempFilePath);

            // set cluster parameter count
            clusterParamNumInput  = wormCluster.Params.Input.Count;
            clusterParamNumOutput = wormCluster.Params.Output.Count;
            debugText            += "\ncluster input params # = " + clusterParamNumInput;
            debugText            += "\ncluster output params # = " + clusterParamNumOutput;

            // add/remove/rename parameters to match cluster parameter count.
            MatchParameterCount();

            // change hairworm name to match cluster name
            if (wormCluster.Name == "Cluster")
            {
                HairwormClusterName     = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
                HairwormClusterNickName = System.IO.Path.GetFileNameWithoutExtension(uri.LocalPath);
            }
            else
            {
                HairwormClusterName     = wormCluster.Name;
                HairwormClusterNickName = wormCluster.NickName;
            }
            Name       = HairwormBaseName + " (" + HairwormClusterName + ")";
            NickName   = HairwormBaseName + " (" + this.HairwormClusterNickName + ")";
            debugText += "cluster is named = " + wormCluster.Name;
            debugText += "cluster is nicknamed = " + wormCluster.NickName;

            //get new document, enable it, and add cluster to it
            wormDoc         = new GH_Document();
            wormDoc.Enabled = true;
            wormDoc.AddObject(wormCluster, true, 0);

            // loading cluster worked. (it's important that this is almost last, because MatchParameterCount scans this to know when to disconnect params)
            loadedClusterUrlParam = clusterUrlParam;

            ExpireSolution(true);
        }
Exemple #16
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[10].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[12].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[12].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[10].AddSource(vallist);
            }
            if (Component.Params.Input[11].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[12].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[14].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("Single Shear", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("Double Shear Steel In", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("Double Shear Steel Out", "2");
                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[11].AddSource(vallist);
            }

            //AQUI COMEÇA O PLGUIN MESMO
            double Nrd        = 0;
            double Vrd        = 0;
            double t          = 0;
            double tsteel     = 0;
            double alfa       = 0;
            double n_par      = 0;
            double n_pep      = 0;
            double d          = 0;
            double dw         = 0;
            int    wood       = 0;
            int    shear_type = 0;
            double kmod       = 0;
            double a1         = 0;
            double a4         = 0;

            string woodtype = "";
            double fc90     = 0;

            //Constant Values
            string type        = "bolt";
            bool   pre_drilled = true;
            double pk          = 0;
            double l           = -1;   //irrelevant
            bool   smooth      = true; //irrelevant
            double fu          = 1000; //default
            double alfa_fast   = -1;   //irrelevant

            if (!DA.GetData <double>(0, ref Nrd))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref Vrd))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref t))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref tsteel))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref alfa))
            {
                return;
            }
            if (!DA.GetData <double>(6, ref n_par))
            {
                return;
            }
            if (!DA.GetData <double>(7, ref n_pep))
            {
                return;
            }
            if (!DA.GetData <double>(8, ref d))
            {
                return;
            }
            if (!DA.GetData <double>(8, ref dw))
            {
                return;
            }
            if (!DA.GetData <int>(9, ref wood))
            {
                return;
            }
            if (!DA.GetData <int>(10, ref shear_type))
            {
                return;
            }
            if (!DA.GetData <double>(11, ref kmod))
            {
                return;
            }
            if (!DA.GetData <double>(12, ref a1))
            {
                return;
            }
            if (!DA.GetData <double>(13, ref a4))
            {
                return;
            }

            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var  reader = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));
            int  cont   = -1;
            bool stop   = false;

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == wood)
                {
                    pk       = 1000 * Double.Parse(values[7]);
                    fc90     = 10 * Double.Parse(values[4]);
                    woodtype = values[13];
                    stop     = true;
                }
                cont++;
            }

            //CALCULO DAS LIGAÇÕES
            var    fast     = new Fastener(type, d, dw, l, smooth, fu);
            var    analysis = new TimberToSteelCapacity(fast, pre_drilled, pk, alfa, alfa_fast, woodtype, t, tsteel, fc90, n_par, n_pep, shear_type, a1);
            double fvd      = 0;

            if (shear_type == 0)
            {
                fvd = kmod * analysis.FvrkSingleShear() / 1.3;
            }
            else
            {
                fvd = kmod * analysis.FvrkDoubleShear() / 1.3;
            }
            double faxd = kmod * analysis.variables.Faxrk / 1.3;
            double DIV  = 0;

            DIV = 1000 * Vrd / fvd;

            //Steel Plate
            double Fsrd     = Math.Min(1.2 * a4 * tsteel * 400 / 1.35, 2.4 * fast.d * tsteel * 400 / 1.35);
            double DIVsteel = 1000 * Vrd / Fsrd;

            DA.SetData(0, fvd);
            DA.SetData(1, faxd);
            DA.SetData(2, DIV);
            DA.SetData(3, DIVsteel);
        }
Exemple #17
0
        // This is the method that actually does the work.
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Creating this component in the grasshopperdocument
            IGH_Component Component           = this;
            GH_Document   GrasshopperDocument = this.OnPingDocument();

            // Creating input parameters
            //object component = null;
            int    nbCopy    = 0;
            string groupName = null;
            bool   trigger   = false;

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

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

            Grasshopper.Kernel.IGH_Param         selNumsInput = Component.Params.Input[0];
            IList <Grasshopper.Kernel.IGH_Param> sources      = selNumsInput.Sources;

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

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

            List <Guid> objectsToCopy = new List <Guid>();

            objectsToCopy.Add(comp.InstanceGuid);

            // 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 duplicate component and to assign properties to it (size, datalist...)
            for (int i = 0; i < nbCopy; i++)
            {
                GH_DocumentIO documentIO = new GH_DocumentIO(GrasshopperDocument);
                documentIO.Copy(GH_ClipboardType.System, objectsToCopy);
                documentIO.Paste(GH_ClipboardType.System);

                documentIO.Document.TranslateObjects(new Size(0, vStart + i * vShift), false);
                documentIO.Document.SelectAll();
                documentIO.Document.MutateAllIds();

                GrasshopperDocument.DeselectAll();
                GrasshopperDocument.MergeDocument(documentIO.Document);
                g.AddObject(documentIO.Document.Objects[0].InstanceGuid);
            }
            GrasshopperDocument.DeselectAll();
        }
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[8].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[8].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[8].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[8].AddSource(vallist);
            }
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var reader = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));

            //inputs
            double Fcad   = 0;
            double acomp  = 0;
            double lFcad  = 0;
            double d1     = 0;
            double d1tipo = 0;
            double d2     = 0;
            double d2tipo = 0;
            double b      = 0;
            double h      = 0;
            double Kmod   = 0;
            double Ym     = 0;
            double fc0k   = 0;
            double fc90k  = 0;
            double E05    = 0;
            int    test   = 0;

            if (!DA.GetData <double>(0, ref Fcad))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref acomp))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref lFcad))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref d1))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref d1tipo))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref d2))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref d2tipo))
            {
                return;
            }
            if (!DA.GetData <double>(5, ref b))
            {
                return;
            }
            if (!DA.GetData <double>(6, ref h))
            {
                return;
            }
            if (!DA.GetData <double>(7, ref Kmod))
            {
                return;
            }
            if (!DA.GetData <int>(8, ref test))
            {
                return;
            }
            int    cont          = -1;
            bool   stop          = false;
            double tipodemadeira = 0;

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == test)
                {
                    Ym    = Double.Parse(values[12]);
                    fc0k  = Double.Parse(values[1]);
                    fc90k = Double.Parse(values[4]);
                    E05   = Double.Parse(values[9]);
                    if (values[13] == "SOLID")
                    {
                        tipodemadeira = 1;
                    }
                    stop = true;
                }
                cont++;
            }

            //Definição de valores do material
            double fc0d  = Kmod * fc0k / Ym;
            double fc90d = Kmod * fc90k / Ym;

            //compressão perpendicular ou em ângulo (garantir que acomp foi fornecido corretamente)
            if (acomp <= 90)
            {
                //Definição de valores geométricos e de tensão efetiva
                double d1min   = Math.Min(d1 / 2, lFcad);
                double d1ef    = Math.Min(d1min, 3);
                double d2min   = Math.Min(d2 / 2, lFcad);
                double d2ef    = Math.Min(d2min, 3);
                double lef     = lFcad + d1ef + d2ef;
                double Aef     = lef * b;
                double sigc90d = Fcad / Aef;
                double kc90    = 1;

                // determinando valor de kc90 (caso não seja majorado por um if abaixo, deve valer igual a 1.0)
                // ifs também perguntam se a madeira é MLC ou SOLID (coluna 13 do excel deve ser preenchida)

                if (d1tipo == 0 && d2tipo == 1 && d2 >= 2 * h)
                {
                    if (tipodemadeira == 0 && lFcad <= 40)
                    {
                        kc90 = 1.75;
                    }
                    if (tipodemadeira == 1)
                    {
                        kc90 = 1.5;
                    }
                }

                if (d2tipo == 0 && d1tipo == 1 && d1 >= 2 * h)
                {
                    if (tipodemadeira == 0 && lFcad <= 40)
                    {
                        kc90 = 1.75;
                    }
                    if (tipodemadeira == 1)
                    {
                        kc90 = 1.5;
                    }
                }

                if (d2tipo == 1 && d1tipo == 1)
                {
                    if (d1 >= 2 * h && d2 >= 2 * h)
                    {
                        if (tipodemadeira == 0 && lFcad <= 40)
                        {
                            kc90 = 1.75;
                        }
                        if (tipodemadeira == 1)
                        {
                            kc90 = 1.5;
                        }
                    }
                }

                //Verificação de compressão perpendicular ou em ângulo

                double acompR = Math.PI * acomp / 180;
                double DIV    = sigc90d * (fc0d * Math.Pow(Math.Sin(acompR), 2) / (kc90 * fc90d) + Math.Pow(Math.Cos(acompR), 2)) / fc0d;
                DA.SetData(0, DIV);
            }
        }
Exemple #19
0
        /// <summary>
        /// Generates selection list for heterogeneous radii gradients.
        /// </summary>
        /// <param name="index">Component input index. (first input is index 0)</param>
        /// <param name="offset">Vertical offset of the menu, to help with positioning.</param>
        public static void GradientSelect(ref IGH_Component Component, ref GH_Document GrasshopperDocument, int index, float offset)
        {
            // Instantiate  new value list
            var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
            vallist.ListMode = Grasshopper.Kernel.Special.GH_ValueListMode.DropDown;
            vallist.CreateAttributes();

            // Customise value list position
            float xCoord = (float)Component.Attributes.Pivot.X - 200;
            float yCoord = (float)Component.Attributes.Pivot.Y + index * 40 - offset;
            PointF cornerPt = new PointF(xCoord, yCoord);
            vallist.Attributes.Pivot = cornerPt;

            // Populate value list with our own data
            vallist.ListItems.Clear();
            var items = new List<Grasshopper.Kernel.Special.GH_ValueListItem>();
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Linear (X)", "0"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Linear (Y)", "1"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Linear (Z)", "2"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Centered (X)", "3"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Centered (Y)", "4"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Centered (Z)", "5"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Cylindrical (X)", "6"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Cylindrical (Y)", "7"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Cylindrical (Z)", "8"));
            items.Add(new Grasshopper.Kernel.Special.GH_ValueListItem("Spherical", "9"));

            vallist.ListItems.AddRange(items);

            // Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(vallist, false);

            // Connect the new slider to this component
            Component.Params.Input[index].AddSource(vallist);
            Component.Params.Input[index].CollectData();
        }
Exemple #20
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        ///


        protected override void SolveInstance(IGH_DataAccess DA)
        {   ///The logic for finding the different chains is far from perfect
            docu = this.OnPingDocument();

            //Get al components in the document
            List <IGH_DocumentObject> objects = new List <IGH_DocumentObject>();

            try
            {
                objects = docu.Objects.ToList <IGH_DocumentObject>();
            }
            catch { }

            //Filter those components to only get active components (remove groups, scribbles etc)
            List <IGH_ActiveObject> activeObjects = new List <IGH_ActiveObject>();

            foreach (IGH_DocumentObject obji in objects)
            {
                IGH_ActiveObject actiObj = obji as IGH_ActiveObject;
                if (actiObj != null & obji != this)
                {
                    activeObjects.Add(actiObj);
                }
            }


            //Sort element in chains
            List <List <IGH_ActiveObject> > chains = new List <List <IGH_ActiveObject> >();

            while (activeObjects.Count > 0)
            {
                //Start with the first document of the list

                IGH_ActiveObject        obj   = activeObjects[0];
                List <IGH_ActiveObject> chain = new List <IGH_ActiveObject>();
                //List<IGH_DocumentObject> longest_set = new List<IGH_DocumentObject>();

                //Retrieve all the components downstream and get last elements, once the last elements is found
                //all the upstream elements will be colected from here
                List <IGH_ActiveObject> downObjects = docu.FindAllDownstreamObjects(obj);
                downObjects.Insert(0, obj);



                //Retrieve all the component upstream from the last element, this process is repeated until
                // all the downstream elements have been added to the chain.
                while (downObjects.Count != 0)
                {
                    IGH_ActiveObject lastElement = downObjects[downObjects.Count - 1];

                    List <IGH_DocumentObject> upstream = new List <IGH_DocumentObject>();
                    Helpers.UpStreamObjects(upstream, lastElement, docu);
                    foreach (GH_DocumentObject ob in upstream)
                    {
                        IGH_ActiveObject ob_Active = ob as IGH_ActiveObject;
                        downObjects.Remove(ob_Active);
                        activeObjects.Remove(ob_Active);
                        if (!chain.Contains(ob_Active))
                        {
                            chain.Add(ob_Active);
                        }
                    }
                }

                //Add the chain to the collection of chains
                chains.Add(chain);
            }

            //Previous logic is quite shitty and you may still end up with two chains which are not totally independant,
            //To fix this chains are compared to see if any component if common to both, if that happend both chains are merged.
            //List<List<IGH_ActiveObject>> cleanChains = new List<List<IGH_ActiveObject>>();

            List <List <IGH_ActiveObject> > cleanChains = new List <List <IGH_ActiveObject> >();

            while (chains.Count > 0)
            {
                bool flag = true;
                List <IGH_ActiveObject> checkingChain = chains[0];
                for (int i = 1; i < chains.Count; i++)
                {
                    List <IGH_ActiveObject> otherChain = chains[i];
                    if (checkingChain.Intersect(otherChain).Any())
                    {
                        flag = false;
                        foreach (IGH_ActiveObject chainObj in otherChain)
                        {
                            if (!checkingChain.Contains(chainObj))
                            {
                                checkingChain.Add(chainObj);
                            }
                            chains.Remove(otherChain);
                        }
                        break;
                    }
                }

                if (flag)
                {
                    cleanChains.Add(checkingChain);
                    chains.Remove(checkingChain);
                }
            }

            chains = cleanChains;
            //Group each of the chains
            int    counter = 1;
            Random random  = new Random();

            foreach (List <IGH_ActiveObject> chain in chains)
            {
                Grasshopper.Kernel.Special.GH_Group group = new Grasshopper.Kernel.Special.GH_Group();

                group.Colour   = System.Drawing.Color.FromArgb(200, (int)(random.NextDouble() * 255), (int)(random.NextDouble() * 255), (int)(random.NextDouble() * 255));
                group.Name     = string.Format(("Chain {0}"), counter.ToString());
                group.NickName = string.Format(("Chain {0}"), counter.ToString());
                docu.AddObject(group, false, docu.ObjectCount);

                foreach (IGH_ActiveObject obj in chain)
                {
                    group.AddObject(obj.Attributes.InstanceGuid);
                }

                group.ExpireCaches();
                counter += 1;
            }
        }
Exemple #21
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object can be used to retrieve data from input parameters and
        /// to store data in output parameters.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[4].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[4].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[4].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[4].AddSource(vallist);
            }
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var reader = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));

            double Mt   = 0;
            double h    = 0;
            double b    = 0;
            double Kmod = 0;
            double Gamm = 0;
            double Fvk  = 0;
            int    test = 0;

            if (!DA.GetData <double>(0, ref Mt))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref h))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref b))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref Kmod))
            {
                return;
            }
            if (!DA.GetData(4, ref test))
            {
                return;
            }
            int  cont = -1;
            bool stop = false;

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == test)
                {
                    Fvk  = Double.Parse(values[6]);
                    Gamm = Double.Parse(values[12]);
                    stop = true;
                }
                cont++;
            }
            double bef  = 0.67 * b;
            double Sigv = (3 / 2) * (Mt / (bef * h));
            double fvd  = Kmod * Fvk / Gamm;
            double Div  = Sigv / fvd;

            DA.SetData(0, Div);
        }
Exemple #22
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();
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            IGH_Component Component           = this;
            GH_Document   GrasshopperDocument = this.OnPingDocument();


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

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


            // Trigger input
            if (!trigger)
            {
                return;
            }

            // Taking out the position and attributes of the template panel
            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;
            IGH_Attributes     att          = templateComp.Attributes;



            // taking out the measures from the template panel and adding a shift
            RectangleF bounds = att.Bounds;
            int        vShift = (int)Math.Round(bounds.Height) + 10;
            float      refX   = bounds.X;
            float      refY   = bounds.Y + 30 + vShift;

            int nbCopy = data.Count;


            // Creating a group, naming it, assigning color, adding it to the document
            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);

            // Putting in all the new components in the document and grouping them
            for (int i = 0; i < nbCopy; i++)
            {
                Grasshopper.Kernel.Parameters.Param_GenericObject comp = new Grasshopper.Kernel.Parameters.Param_GenericObject();
                comp.CreateAttributes();
                comp.SetPersistentData(data[i]);
                float w = comp.Attributes.Bounds.Width;
                comp.Attributes.Pivot = new PointF(refX + w / 2, refY + i * vShift);
                GrasshopperDocument.AddObject(comp, false);
                g.AddObject(comp.InstanceGuid);
            }


            GrasshopperDocument.DeselectAll();
        }
Exemple #24
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[8].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[8].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[8].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[13].AddSource(vallist);
            }

            double t1      = 0;
            double t2      = 0;
            double alfast  = 0;
            double Nscrews = 0;
            double d       = 0;
            double dh      = 0;
            double l       = 0;
            double lt      = 0;
            int    wood    = 0;
            double pk      = 0;
            double kmod    = 0;
            double Frd     = 0;


            if (!DA.GetData <double>(0, ref Frd))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref Nscrews))
            {
                return;
            }
            if (!DA.GetData <double>(2, ref Frd))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref Frd))
            {
                return;
            }
            if (!DA.GetData <double>(4, ref Ctype))
            {
                return;
            }
            if (!DA.GetData <double>(5, ref afast))
            {
                return;
            }
            if (!DA.GetData <double>(6, ref d))
            {
                return;
            }
            if (!DA.GetData <double>(7, ref dh))
            {
                return;
            }
            if (!DA.GetData <double>(8, ref l))
            {
                return;
            }
            if (!DA.GetData <double>(9, ref lt))
            {
                return;
            }
            if (!DA.GetData <int>(10, ref wood))
            {
                return;
            }
            if (!DA.GetData <double>(11, ref kmod))
            {
                return;
            }



            //Pegar valores da Madeira do Excel
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var    reader   = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));
            int    cont     = -1;
            bool   stop     = false;
            string woodtype = "";

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == wood)
                {
                    pk       = 1000 * Double.Parse(values[7]);
                    woodtype = values[13];
                    stop     = true;
                }
                cont++;
            }



            double f_ax_k = 3.6 * 0.001 * Math.Pow(pk, 1.5);
        }
Exemple #25
0
    private void SolutionCallback(GH_Document doc)
    {
        //read file, deserialize json, send variables out of the extracted class

        string     jsonstring = File.ReadAllText(_path);
        ParamsData paramdata  = new ParamsData();

        paramdata   = JsonConvert.DeserializeObject <ParamsData>(jsonstring);
        _n          = paramdata.NumSliders;
        _dataIn     = paramdata.SliderVals;
        _pointsdata = paramdata.Points;


        Random rnd = new Random();

        List <IGH_DocumentObject> deletions       = new List <IGH_DocumentObject>(); //list of objects to delete from grasshopper document
        List <OutputParam>        outputParams    = new List <OutputParam>();        //list of the slider grouping params and their output connections
        List <IGH_Param>          PointRecvParams = new List <IGH_Param>();          //list of what the point param is connected to

        foreach (IGH_DocumentObject obj in GrasshopperDocument.Objects)
        {
            if (obj.NickName.StartsWith(_controlComponentName)) //the point and integer params i've created
            {
                deletions.Add(obj);
                IGH_Param tempParam = obj as IGH_Param; //cast obj into a param to locate sources and recipients
                if (tempParam.SourceCount > 0)
                {
                    deletions.AddRange(tempParam.Sources); //add source sliders to deletions list
                }

                if (obj.NickName.StartsWith(_controlComponentName + "points"))
                {
                    foreach (IGH_Param recip in tempParam.Recipients)
                    {
                        PointRecvParams.Add(recip);
                    }
                }

                if (obj.NickName.StartsWith(_controlComponentName + "slids")) //the integer params
                {
                    int ObjectIndex;
                    Int32.TryParse(System.Text.RegularExpressions.Regex.Match(obj.NickName, @"(\d+)\z").Value, out ObjectIndex); //regex to extract index number from end of param name
                    List <IGH_Param> receivingParams = new List <IGH_Param>();
                    foreach (IGH_Param recip in tempParam.Recipients)
                    {
                        receivingParams.Add(recip);
                    }
                    outputParams.Add(new OutputParam(ObjectIndex, receivingParams)); //put output param index and recipients into an object in a list
                }
            }
        }

        foreach (IGH_DocumentObject delobj in deletions) //delete the stuff
        {
            GrasshopperDocument.RemoveObject(delobj, false);
        }

        List <Grasshopper.Kernel.Parameters.Param_Integer> targetParam = new List <Grasshopper.Kernel.Parameters.Param_Integer>(); //holds the new output params as we build them  //rename targetParam

        for (int index = 0; index < _n.Count; index++)                                                                             //this loop runs once per slider bank    //rename index

        {
            targetParam.Add(new Grasshopper.Kernel.Parameters.Param_Integer());    //create the new output param
            targetParam[index].NickName = _controlComponentName + "slids" + index; //assign the name to the output param including the index number
            GrasshopperDocument.AddObject(targetParam[index], false);

            if (index == 0) //put param in place
            {
                targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110);
            }
            else
            {
                _n[index] = _n[index] + _n[index - 1]; //aggregate list of number of sliders per bank to create slider index breakpoints
                targetParam[index].Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 110 + _n[index - 1] * 20 + index * 10);
            }

            if (outputParams.Exists(opar => opar.outParam == index)) //looks in the list of deleted output params and determines if one has the same index as the param being created
            {
                foreach (IGH_Param receivingParam in outputParams.Find(opar => opar.outParam == index).recvParams)
                {
                    receivingParam.AddSource(targetParam[index]); //connects the new param to the old param stuff
                }
            }
        }

        Grasshopper.Kernel.Parameters.Param_Point pointsParam = new Grasshopper.Kernel.Parameters.Param_Point();
        pointsParam.NickName = _controlComponentName + "points";
        GrasshopperDocument.AddObject(pointsParam, false);
        pointsParam.Attributes.Pivot = new System.Drawing.PointF(Component.Attributes.Pivot.X + 20, Component.Attributes.Pivot.Y + 70);
        foreach (IGH_Param receivingParam in PointRecvParams)
        {
            receivingParam.AddSource(pointsParam);
        }

        pointsParam.SetPersistentData(_pointsdata.ToArray());



        int Yoffset      = -12;
        int CurrentParam = 0;

        for (int i = 0; i < _n[_n.Count - 1]; i++)
        {
            if (_n.Exists(x => x == i))
            {
                Yoffset = Yoffset + 10;
                CurrentParam++;
            }
            //instantiate  new slider
            Grasshopper.Kernel.Special.GH_NumberSlider slid = new Grasshopper.Kernel.Special.GH_NumberSlider();
            slid.CreateAttributes(); //sets up default values, and makes sure your slider doesn't crash rhino

            //customise slider (position, ranges etc)
            //targetParam.Attributes.Bounds


            slid.Attributes.Pivot     = new System.Drawing.PointF((float)targetParam[0].Attributes.Pivot.X - slid.Attributes.Bounds.Width - 70, (float)targetParam[0].Attributes.Pivot.Y + i * 20 + Yoffset);
            slid.Slider.Maximum       = 100;
            slid.Slider.Minimum       = 0;
            slid.Slider.DecimalPlaces = 0;
            // slid.SetSliderValue((decimal) (rnd.Next(-50, 51)));

            if (i + 1 > _dataIn.Count)
            {
                slid.SetSliderValue(_dataIn[_dataIn.Count - 1]);
            }
            else
            {
                slid.SetSliderValue(_dataIn[i]);
            }

            //Until now, the slider is a hypothetical object.
            // This command makes it 'real' and adds it to the canvas.
            GrasshopperDocument.AddObject(slid, false);

            //Connect the new slider to this component
            targetParam[CurrentParam].AddSource(slid);
        }
    }
Exemple #26
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            Component           = this;
            GrasshopperDocument = this.OnPingDocument();
            if (Component.Params.Input[2].SourceCount == 0)
            {
                //instantiate  new value list
                var vallist = new Grasshopper.Kernel.Special.GH_ValueList();
                vallist.CreateAttributes();

                //customise value list position
                int inputcount = this.Component.Params.Input[2].SourceCount;
                //vallist.Attributes.Pivot = new PointF((float)this.Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30,
                //    (float)this.Component.Params.Input[1].Attributes.Bounds.Y + inputcount * 30);
                vallist.Attributes.Pivot = new PointF(Component.Attributes.DocObject.Attributes.Bounds.Left - vallist.Attributes.Bounds.Width - 30, Component.Params.Input[2].Attributes.Bounds.Y + inputcount * 30);
                //populate value list with our own data
                vallist.ListItems.Clear();
                var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24h", "0");
                var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28h", "1");
                var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32h", "2");
                var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 24c", "3");
                var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 28c", "4");
                var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL 32c", "5");
                var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL CROSSLAM", "6");
                var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("GL ITA", "7");
                vallist.ListItems.Add(item1);
                vallist.ListItems.Add(item2);
                vallist.ListItems.Add(item3);
                vallist.ListItems.Add(item4);
                vallist.ListItems.Add(item5);
                vallist.ListItems.Add(item6);
                vallist.ListItems.Add(item7);
                vallist.ListItems.Add(item8);

                //Until now, the slider is a hypothetical object.
                // This command makes it 'real' and adds it to the canvas.
                GrasshopperDocument.AddObject(vallist, false);

                //Connect the new slider to this component
                this.Component.Params.Input[2].AddSource(vallist);
            }


            string type   = "screw";
            double d      = 0;
            double pk     = 0;
            double alfa   = 0;
            bool   pdrill = false;
            int    wood   = 0;



            if (!DA.GetData <string>(0, ref type))
            {
                return;
            }
            if (!DA.GetData <double>(1, ref d))
            {
                return;
            }
            if (!DA.GetData <int>(2, ref wood))
            {
                return;
            }
            if (!DA.GetData <double>(3, ref alfa))
            {
                return;
            }
            if (!DA.GetData <bool>(4, ref pdrill))
            {
                return;
            }

            //Pegar valores da Madeira do Excel
            string text = Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);

            text = Path.Combine(Directory.GetParent(text).FullName, "Plug-ins");
            var    reader   = new StreamReader(File.OpenRead(text + "\\Madeira\\MLCPROP.csv"));
            int    cont     = -1;
            bool   stop     = false;
            string woodtype = "";

            while (!reader.EndOfStream || stop == false)
            {
                var line   = reader.ReadLine();
                var values = line.Split(',');
                if (cont == wood)
                {
                    pk       = 1000 * Double.Parse(values[7]);
                    woodtype = values[13];
                    stop     = true;
                }
                cont++;
            }
            //CALCULOS DE BRITTLE FAILURE (minimos espaçamentos aceitáveis)
            Fastener       fast     = new Fastener(type, d, -1, -1, true, -1);
            BrittleFailure analysis = new BrittleFailure(fast, pk, alfa, pdrill);
            double         a1       = analysis.a1;
            double         a2       = analysis.a2;
            double         a3c      = analysis.a3c;
            double         a3t      = analysis.a3t;
            double         a4c      = analysis.a4c;
            double         a4t      = analysis.a4t;
            double         a1best   = analysis.a1_n;

            DA.SetData(0, a1);
            DA.SetData(1, a1best);
            DA.SetData(2, a2);
            DA.SetData(3, a3c);
            DA.SetData(4, a3t);
            DA.SetData(5, a4c);
            DA.SetData(6, a4t);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            // Declare a variable for the input String
            string filename = null;
            bool   activate = false;

            Rhino.Geometry.Point3d point = Rhino.Geometry.Point3d.Unset;
            // 1. Declare placeholder variables and assign initial invalid data.
            //    This way, if the input parameters fail to supply valid data, we know when to abort.

            // 2. Retrieve input data.
            if (!DA.GetData(0, ref filename))
            {
                return;
            }
            if (!DA.GetData(1, ref activate))
            {
                return;
            }
            if (!DA.GetData(2, ref point))
            {
                return;
            }

            // If the retrieved data is Nothing, we need to abort.
            if (filename == null)
            {
                return;
            }
            if (!File.Exists(filename))
            {
                return;
            }

            if (activate)
            {
                GH_Cluster cluster = new GH_Cluster();
                cluster.CreateFromFilePath(filename);

                GH_Document doc = OnPingDocument();
                doc.AddObject(cluster, false);

                Grasshopper.Kernel.Parameters.Param_Point    paramIn  = new Grasshopper.Kernel.Parameters.Param_Point();
                Grasshopper.Kernel.Parameters.Param_Geometry paramOut = new Grasshopper.Kernel.Parameters.Param_Geometry();

                paramIn.SetPersistentData(point);

                cluster.Params.RegisterInputParam(paramIn);
                cluster.Params.RegisterOutputParam(paramOut);

                cluster.CollectData();

                cluster.ComputeData();


                //Grasshopper.DataTree<object> test = new DataTree<object>();
                //test.Add(paramIn, 0);



                DA.SetData(1, paramOut);
            }
        }