private string ConstructLambertMaterial(GH_Colour col, GH_Colour amb, GH_Colour em, Double opp, bool smooth)
        {
            dynamic jason = new ExpandoObject();

            jason.uuid     = Guid.NewGuid();
            jason.type     = "MeshLambertMaterial";
            jason.color    = _Utilities.hexColor(col);
            jason.ambient  = _Utilities.hexColor(amb);
            jason.emissive = _Utilities.hexColor(em);
            if (opp < 1)
            {
                jason.transparent = true;
                jason.opacity     = opp;
            }
            jason.wireframe = false;
            jason.side      = 2;
            if (smooth)
            {
                jason.shading = 2;
            }
            else
            {
                jason.shading = 1;
            }
            return(JsonConvert.SerializeObject(jason));
        }
Esempio n. 2
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)
        {
            double thickness  = 0.5;
            var    horizontal = true;
            var    color      = new GH_Colour();
            double width      = 0;
            double height     = 0;

            if (!DA.GetData <double>("Thickness", ref thickness))
            {
                return;
            }
            if (!DA.GetData <bool>("Horizontal", ref horizontal))
            {
                return;
            }

            DA.GetData <GH_Colour>("Color", ref color);
            DA.GetData <double>("Width", ref width);
            DA.GetData <double>("Height", ref height);


            var rect = new Rectangle();

            SetupSeparator(thickness, horizontal, ToMediaColor(color.Value), width, height, rect);

            // pass out the separator
            DA.SetData("Separator", new UIElement_Goo(rect, "Separator", InstanceGuid, DA.Iteration));
        }
Esempio n. 3
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)
        {
            //local varaibles
            GH_Colour inColor     = null;
            Double    inOpacity   = 1;
            string    outMaterial = null;

            //catch inputs and populate local variables
            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            if (inColor == null)
            {
                return;
            }
            DA.GetData(1, ref inOpacity);
            if (inOpacity > 1 || inOpacity < 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1.  Check your 'O' input.");
                inOpacity = 1.0;
            }

            outMaterial = CreateMaterial(inColor, inOpacity);
            Material material = new Material(outMaterial, va3cMaterialType.Mesh);

            //set the output - build up a basic material json string
            DA.SetData(0, material);
        }
Esempio n. 4
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            GH_Colour CurrentCrvColor;

            base.DrawViewportMeshes(args);
            int Thickness = CrvThickness.Value < 0 ? Math.Abs(CrvThickness.Value) : CrvThickness.Value == 0 ? 2 : CrvThickness.Value;

            if (this.Hidden || this.Locked)
            {
                return;
            }

            if (this.Attributes.Selected)
            {
                CurrentCrvColor = new GH_Colour(Color.Green);
            }
            else
            {
                CurrentCrvColor = CrvColor;
            }

            for (int Index = 0; Index < CrvList.Count; Index++)
            {
                GH_Curve Crv = CrvList[Index];
                args.Display.DrawCurve(Crv.Value, CurrentCrvColor.Value, Thickness);
            }
        }
        /// <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)
        {
            //System.Drawing.Color inColor = System.Drawing.Color.White;
            GH_Colour inColor     = null;
            Double    inOpacity   = 1;
            String    inName      = String.Empty;
            String    outMaterial = null;
            String    outName     = null;

            //if (!DA.GetData(0, ref inColor)) { return; }
            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            if (inColor == null)
            {
                return;
            }
            DA.GetData(1, ref inOpacity);
            DA.GetData(2, ref inName);

            if (inName == string.Empty)
            {
                inName = DateTime.Now.ToShortDateString();
            }                                                                               //autogenerate name
            outName     = inName;
            outMaterial = ConstructMaterial(inColor, inOpacity, inName);
            //call json conversion function

            DA.SetData(0, outMaterial);
        }
        /// <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)
        {
            GH_Colour  inColor     = null;
            GH_Colour  inAmbient   = null;
            GH_Colour  inEmissive  = null;
            GH_Number  inOpacity   = null;
            GH_Boolean inSmooth    = null;
            String     outMaterial = null;

            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            if (inColor == null)
            {
                return;
            }
            DA.GetData(1, ref inAmbient);
            DA.GetData(2, ref inEmissive);
            DA.GetData(3, ref inOpacity);
            if (inOpacity.Value > 1 || inOpacity.Value < 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1.  Check your 'O' input.");
                inOpacity.Value = 1.0;
            }
            DA.GetData(4, ref inSmooth);

            outMaterial = ConstructLambertMaterial(inColor, inAmbient, inEmissive, inOpacity.Value, inSmooth.Value);

            Material material = new Material(outMaterial, va3cMaterialType.Mesh);

            DA.SetData(0, material);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaSection sect = new GsaSection();

            //profile
            GH_String gh_profile = new GH_String();

            if (DA.GetData(0, ref gh_profile))
            {
                if (GH_Convert.ToString(gh_profile, out string profile, GH_Conversion.Both))
                {
                    sect.Section.Profile = profile;

                    // 1 material
                    // to be implemented

                    // 2 pool
                    GH_Integer gh_pool = new GH_Integer();
                    if (DA.GetData(2, ref gh_pool))
                    {
                        if (GH_Convert.ToInt32(gh_pool, out int pool, GH_Conversion.Both))
                        {
                            sect.Section.Pool = pool;
                        }
                    }

                    // 3 ID
                    GH_Integer gh_id = new GH_Integer();
                    if (DA.GetData(3, ref gh_id))
                    {
                        if (GH_Convert.ToInt32(gh_id, out int idd, GH_Conversion.Both))
                        {
                            sect.ID = idd;
                        }
                    }

                    // 4 name
                    GH_String gh_n = new GH_String();
                    if (DA.GetData(4, ref gh_n))
                    {
                        if (GH_Convert.ToString(gh_n, out string name, GH_Conversion.Both))
                        {
                            sect.Section.Name = name;
                        }
                    }

                    // 5 colour
                    GH_Colour gh_Colour = new GH_Colour();
                    if (DA.GetData(5, ref gh_Colour))
                    {
                        if (GH_Convert.ToColor(gh_Colour, out System.Drawing.Color colour, GH_Conversion.Both))
                        {
                            sect.Section.Colour = colour;
                        }
                    }
                }
                DA.SetData(0, new GsaSectionGoo(sect));
            }
        }
        /// <summary>
        /// Returns a string representation of a hex color given a GH_Colour object
        /// </summary>
        /// <param name="ghColor">the grasshopper color to convert</param>
        /// <returns>a hex color string</returns>
        public static string hexColor(GH_Colour ghColor)
        {
            string hexStr = "0x" + ghColor.Value.R.ToString("X2") +
                            ghColor.Value.G.ToString("X2") +
                            ghColor.Value.B.ToString("X2");

            return(hexStr);
        }
Esempio n. 9
0
 public static Grevit.Types.Color ToGrevitColor(this GH_Colour color)
 {
     return
         (new Types.Color()
     {
         R = color.Value.R, B = color.Value.B, G = color.Value.G
     });
 }
Esempio n. 10
0
        /*******************************************/

        public static bool CastToGoo(object value, ref IGH_QuickCast target)
        {
            try
            {
                if (value is bool)
                {
                    target = new GH_Boolean((bool)value);
                }
                else if (value is Color)
                {
                    target = new GH_Colour((Color)value);
                }
                else if (value is Complex)
                {
                    target = new GH_ComplexNumber((Complex)value);
                }
                else if (value is int)
                {
                    target = new GH_Integer((int)value);
                }
                else if (value is Interval)
                {
                    target = new GH_Interval((Interval)value);
                }
                else if (value is Matrix)
                {
                    target = new GH_Matrix((Matrix)value);
                }
                else if (value is double || value is float)
                {
                    target = new GH_Number((double)value);
                }
                else if (value is Point3d)
                {
                    target = new GH_Point((Point3d)value);
                }
                else if (value is string)
                {
                    target = new GH_String(value.ToString());
                }
                else if (value is Vector3d)
                {
                    target = new GH_Vector((Vector3d)value);
                }
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 11
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            var connectionType = new ConnectionType();

            DA.GetData(0, ref connectionType);
            var connection      = connectionType.Value;
            var colorHasChanged = false;

            var d = connection.graph;

            if (d == null)
            {
                return;
            }

            string id = "";

            DA.GetData(1, ref id);
            var nodeIndex = connection.indexOfNode(id);

            if (nodeIndex < 0)
            {
                return;
            }
            var colorsOfNode = colorsFromGraph(d, nodeIndex);

            if (colorsOfNode == null)
            {
                return;
            }

            for (int i = 0; i < 4; i++)
            {
                var color = new GH_Colour();
                if (DA.GetData(2 + i, ref color))
                {
                    if (colorsOfNode[i].Value != color.Value)
                    {
                        colorsOfNode[i] = color;
                        colorHasChanged = true;
                    }
                }
            }

            if (colorHasChanged)
            {
                sendColorsToServer(connection, id, colorsOfNode);
            }

            DA.SetDataList(0, colorsOfNode);
        }
Esempio n. 12
0
        private string CreateMaterial(GH_Colour inColor, double inOpacity)
        {
            dynamic jason = new ExpandoObject();

            jason.uuid  = Guid.NewGuid();
            jason.type  = "MeshBasicMaterial";
            jason.color = _Utilities.hexColor(inColor);
            jason.side  = 2;
            if (inOpacity < 1)
            {
                jason.transparent = true;
                jason.opacity     = inOpacity;
            }
            return(JsonConvert.SerializeObject(jason));
        }
Esempio n. 13
0
        private string ConstructMaterial(GH_Colour inColor, GH_Number inNumber)
        {
            //json object to populate
            dynamic jason = new ExpandoObject();

            //JSON properties
            jason.uuid      = Guid.NewGuid();
            jason.type      = "LineBasicMaterial";
            jason.color     = _Utilities.hexColor(inColor);
            jason.linewidth = inNumber.Value;
            jason.opacity   = 1;


            return(JsonConvert.SerializeObject(jason));
        }
Esempio n. 14
0
        public override Boolean Equals(Object that)
        {
            if (that == null)
            {
                return(false);
            }
            if (that.GetType() != this.GetType())
            {
                return(false);
            }

            //FIXME: use a reflection to get the Value property of the GH_Goo
            //if a value property is missing, it seems that we could not compare Goos (or different method should be used)

            // GH_Goo.Equals(GH_Goo) compare the GUIDs which are different in the common case
            // that's why we need to compare GH_Goo inner values
            // unfortunately the Value property is not generic for GH_Goo
            // only some GH_Goo have value assigned
            GH_CellState thatState = (GH_CellState)that;

            if (value.GetType() == GH_TypeLib.t_gh_colour)
            {
                GH_Colour thisGH_Colour = (GH_Colour)value;
                GH_Colour thatGH_Colour = (GH_Colour)thatState.value;

                return(thisGH_Colour.Value.Equals(thatGH_Colour.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_bool)
            {
                GH_Boolean thisGH_Boolean = (GH_Boolean)this.value;
                GH_Boolean thatGH_Boolean = (GH_Boolean)thatState.value;
                return(thisGH_Boolean.Value.Equals(thatGH_Boolean.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_int)
            {
                GH_Integer thisGH_Integer = (GH_Integer)this.value;
                GH_Integer thatGH_Integer = (GH_Integer)thatState.value;
                return(thisGH_Integer.Value.Equals(thatGH_Integer.Value));
            }
            else if (value.GetType() == GH_TypeLib.t_gh_string)
            {
                GH_String thisGH_String = (GH_String)this.value;
                GH_String thatGH_String = (GH_String)thatState.value;
                return(thisGH_String.Value.Equals(thatGH_String.Value));
            }

            throw new NotSupportedException("Could not compare GH_Goo type: " + value.GetType());
        }
Esempio n. 15
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)
        {
            //loacl varaibles
            GH_Colour inColor  = null;
            GH_Number inNumber = new GH_Number(1.0);

            //get user data
            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            DA.GetData(1, ref inNumber);

            //spin up a JSON material from the inputs
            string outJSON = ConstructMaterial(inColor, inNumber);

            //output
            DA.SetData(0, outJSON);
        }
        private string ConstructPhongMaterial(GH_Colour col, GH_Colour amb, GH_Colour em, GH_Colour spec, Double shin, Double opp)
        {
            dynamic jason = new ExpandoObject();

            jason.uuid      = Guid.NewGuid();
            jason.type      = "MeshPhongMaterial";
            jason.color     = _Utilities.hexColor(col);
            jason.ambient   = _Utilities.hexColor(amb);
            jason.emissive  = _Utilities.hexColor(em);
            jason.specular  = _Utilities.hexColor(spec);
            jason.shininess = shin;
            if (opp < 1)
            {
                jason.transparent = true;
                jason.opacity     = opp;
            }
            jason.wireframe = false;
            jason.side      = 2;
            return(JsonConvert.SerializeObject(jason));
        }
        public string ConstructMaterial(GH_Colour Col, Double Opp, String Name)
        {
            dynamic JsonMat = new ExpandoObject();
            //JsonMat.metadata = new ExpandoObject();
            //JsonMat.metadata.version = 4.2;
            //JsonMat.metadata.type = "material";
            //JsonMat.metadata.generator = "MaterialExporter";

            JsonMat.uuid = Guid.NewGuid();
            JsonMat.type = "MeshPhongMaterial";
            JsonMat.color = _Utilities.hexColor(Col);
            JsonMat.ambient = _Utilities.hexColor(Col);
            JsonMat.emissive = _Utilities.hexColor(new GH_Colour(System.Drawing.Color.Black));
            JsonMat.specular = _Utilities.hexColor(new GH_Colour(System.Drawing.Color.Gray));
            JsonMat.shininess = 50;
            JsonMat.opacity = Opp;
            JsonMat.transparent = false;
            JsonMat.wireframe = false;
            JsonMat.side = 2;
            return JsonConvert.SerializeObject(JsonMat);
        }
        public string ConstructMaterial(GH_Colour Col, Double Opp, String Name)
        {
            dynamic JsonMat = new ExpandoObject();

            //JsonMat.metadata = new ExpandoObject();
            //JsonMat.metadata.version = 4.2;
            //JsonMat.metadata.type = "material";
            //JsonMat.metadata.generator = "MaterialExporter";

            JsonMat.uuid        = Guid.NewGuid();
            JsonMat.type        = "MeshPhongMaterial";
            JsonMat.color       = _Utilities.hexColor(Col);
            JsonMat.ambient     = _Utilities.hexColor(Col);
            JsonMat.emissive    = _Utilities.hexColor(new GH_Colour(System.Drawing.Color.Black));
            JsonMat.specular    = _Utilities.hexColor(new GH_Colour(System.Drawing.Color.Gray));
            JsonMat.shininess   = 50;
            JsonMat.opacity     = Opp;
            JsonMat.transparent = false;
            JsonMat.wireframe   = false;
            JsonMat.side        = 2;
            return(JsonConvert.SerializeObject(JsonMat));
        }
Esempio n. 19
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)
        {
            //System.Drawing.Color inColor = System.Drawing.Color.White;
            GH_Colour inColor     = null;
            GH_Colour inAmbient   = null;
            GH_Colour inEmissive  = null;
            GH_Colour inSpecular  = null;
            GH_Number inShininess = null;
            GH_Number inOpacity   = null;
            String    outMaterial = null;

            //if (!DA.GetData(0, ref inColor)) { return; }
            if (!DA.GetData(0, ref inColor))
            {
                return;
            }
            if (inColor == null)
            {
                return;
            }
            DA.GetData(1, ref inAmbient);
            DA.GetData(2, ref inEmissive);
            DA.GetData(3, ref inSpecular);
            DA.GetData(4, ref inShininess);
            DA.GetData(5, ref inOpacity);
            if (inOpacity.Value > 1 || inOpacity.Value < 0)
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "The opacity input must be between 0 and 1, and has been defaulted back to 1.  Check your 'O' input.");
                inOpacity.Value = 1.0;
            }

            outMaterial = ConstructPhongMaterial(inColor, inAmbient, inEmissive, inSpecular, inShininess.Value, inOpacity.Value);
            //call json conversion function

            Material material = new Material(outMaterial, va3cMaterialType.Mesh);

            DA.SetData(0, material);
        }
Esempio n. 20
0
        public override void DrawViewportWires(IGH_PreviewArgs args)
        {
            GH_Colour CurrentArrowColor;

            base.DrawViewportMeshes(args);
            // 下面这句代码比较重要,决定了
            if (this.Hidden || this.Locked)
            {
                return;
            }
            //检测Component有没有被选中
            // this.ExpireSolution(true) 会带来较高的刷新率
            if (this.Attributes.Selected)
            {
                CurrentArrowColor = new GH_Colour(Color.Green);
            }
            else
            {
                CurrentArrowColor = ArrowColor;
            }
            IEnumerable <Line> Lines = CrvList.Select(item => { Curve CrvItem = item.Value; return(new Line(CrvItem.PointAtStart, CrvItem.PointAtEnd)); });

            args.Display.DrawArrows(Lines, CurrentArrowColor.Value);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember2d gsaMember2d = new GsaMember2d();

            if (DA.GetData(0, ref gsaMember2d))
            {
                GsaMember2d mem = gsaMember2d.Duplicate();

                // #### inputs ####

                // 1 brep
                Brep brep = mem.Brep; //existing brep

                GH_Brep ghbrep = new GH_Brep();
                if (DA.GetData(1, ref ghbrep))
                {
                    if (GH_Convert.ToBrep(ghbrep, ref brep, GH_Conversion.Both))
                    {
                        mem.Brep = brep;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

                if (DA.GetData(2, ref gh_typ))
                {
                    GsaProp2d prop2d = new GsaProp2d();
                    if (gh_typ.Value is GsaProp2d)
                    {
                        gh_typ.CastTo(ref prop2d);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            prop2d.ID = idd;
                        }
                    }
                    mem.Property = prop2d;
                }

                // 3 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(3, ref offset))
                {
                    mem.Member.Offset.Z = offset.Z;
                }

                // 4 inclusion points
                List <Point3d>  pts   = mem.InclusionPoints;
                List <GH_Point> ghpts = new List <GH_Point>();
                if (DA.GetDataList(4, ghpts))
                {
                    for (int i = 0; i < ghpts.Count; i++)
                    {
                        Point3d pt = new Point3d();
                        if (GH_Convert.ToPoint3d(ghpts[i], ref pt, GH_Conversion.Both))
                        {
                            pts.Add(pt);
                        }
                    }
                }

                // 5 inclusion lines
                CurveList       crvlist = new CurveList(mem.InclusionLines);
                List <Curve>    crvs    = crvlist.ToList();
                List <GH_Curve> ghcrvs  = new List <GH_Curve>();
                if (DA.GetDataList(5, ghcrvs))
                {
                    for (int i = 0; i < ghcrvs.Count; i++)
                    {
                        Curve crv = null;
                        if (GH_Convert.ToCurve(ghcrvs[i], ref crv, GH_Conversion.Both))
                        {
                            crvs.Add(crv);
                        }
                    }
                }

                GsaMember2d tmpmem = new GsaMember2d(brep, crvs, pts)
                {
                    ID       = mem.ID,
                    Member   = mem.Member,
                    Property = mem.Property
                };
                mem = tmpmem;

                // 6 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(6, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 7 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(7, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 8 type
                GH_Integer ghint = new GH_Integer();
                if (DA.GetData(8, ref ghint))
                {
                    if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type = Util.Gsa.GsaToModel.Member2dType(type);
                    }
                }

                // 9 element type / analysis order
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(9, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type2D = Util.Gsa.GsaToModel.Element2dType(type);
                    }
                }

                // 10 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(10, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 11 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(11, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 12 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(12, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 13 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(13, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 14 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(14, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####

                DA.SetData(0, new GsaMember2dGoo(mem));

                DA.SetData(1, mem.Brep);

                DA.SetData(2, mem.Property);

                GsaOffset gsaOffset = new GsaOffset
                {
                    Z = mem.Member.Offset.Z
                };
                DA.SetData(3, gsaOffset);

                DA.SetDataList(4, mem.InclusionPoints);
                DA.SetDataList(5, mem.InclusionLines);

                DA.SetData(6, mem.Member.MeshSize);
                //DA.SetData(7, mem.member.MeshWithOthers);

                DA.SetData(8, mem.Member.Type);
                DA.SetData(9, mem.Member.Type2D);

                DA.SetData(10, mem.ID);
                DA.SetData(11, mem.Member.Name);
                DA.SetData(12, mem.Member.Group);
                DA.SetData(13, mem.Member.Colour);

                DA.SetData(14, mem.Member.IsDummy);
            }
        }
Esempio n. 22
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)
        {
            string filename = string.Empty;

            DA.GetData <string>(0, ref filename);

            Brep boundary = new Brep();

            DA.GetData <Brep>(1, ref boundary);

            bool        filter = (boundary.IsValid);
            BoundingBox bbox   = boundary.GetBoundingBox(true);

            if (filter)
            {
                AddPreviewItem(bbox);
            }

            List <string> info = new List <string>();

            var lazReader  = new laszip_dll();
            var compressed = true;

            lazReader.laszip_open_reader(filename, ref compressed);
            var numberOfPoints     = lazReader.header.number_of_point_records;
            List <laszip_vlr> vlrs = lazReader.header.vlrs;

            info.Add("Points: " + lazReader.header.number_of_point_records.ToString("N0"));
            info.Add("Returns: " + lazReader.header.number_of_points_by_return.Length);
            info.Add("File source ID: " + lazReader.header.file_source_ID);
            info.Add("Created on: " + lazReader.header.file_creation_day + " day of " + lazReader.header.file_creation_year);
            info.Add("Created with: " + Encoding.Default.GetString(lazReader.header.generating_software));

            ///Try to fetch SRS of point cloud
            string pcSRS = "Data does not have associated spatial reference system (SRS).";

            foreach (var vlr in vlrs)
            {
                string description = Encoding.Default.GetString(vlr.description);
                if (description.Contains("SRS") || description.Contains("WKT"))
                {
                    pcSRS = Encoding.Default.GetString(vlr.data);
                }
            }

            Point3d     min    = new Point3d(lazReader.header.min_x, lazReader.header.min_y, lazReader.header.min_z);
            Point3d     max    = new Point3d(lazReader.header.max_x, lazReader.header.max_y, lazReader.header.max_z);
            BoundingBox maxBox = new BoundingBox(min, max);

            AddPreviewItem(maxBox);

            Message = numberOfPoints.ToString("N0") + " points";

            PointCloud pointCloud             = new PointCloud();
            GH_Structure <GH_Point>  ghPC     = new GH_Structure <GH_Point>();
            GH_Structure <GH_Colour> ghColors = new GH_Structure <GH_Colour>();

            var coordArray = new double[3];

            for (int pointIndex = 0; pointIndex < numberOfPoints; pointIndex++)
            {
                ///Read the point
                lazReader.laszip_read_point();

                ///Get precision coordinates
                lazReader.laszip_get_coordinates(coordArray);
                Point3d pt = new Point3d(coordArray[0], coordArray[1], coordArray[2]);

                ///Get classification value for sorting into branches
                int     classification = lazReader.point.classification;
                GH_Path path           = new GH_Path(classification);

                GH_Colour col = new GH_Colour(Color.FromArgb(lazReader.point.rgb[0], lazReader.point.rgb[1], lazReader.point.rgb[2]));

                if (!filter)
                {
                    ghPC.Append(new GH_Point(pt), new GH_Path(classification));
                    ghColors.Append(col, new GH_Path(classification));
                }

                else
                {
                    if (bbox.Contains(pt))
                    {
                        ghPC.Append(new GH_Point(pt), new GH_Path(classification));
                        ghColors.Append(col, new GH_Path(classification));
                    }
                }
            }
            lazReader.laszip_close_reader();

            DA.SetDataList(0, info);
            DA.SetDataTree(1, ghPC);
            DA.SetDataTree(2, ghColors);
            DA.SetData(3, pcSRS);
        }
Esempio n. 23
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();

            if (DA.GetData(0, ref gh_typ))
            {
                GsaNode gsaNode = new GsaNode();
                Point3d tempPt  = new Point3d();
                if (gh_typ.Value is GsaNodeGoo)
                {
                    gh_typ.CastTo(ref gsaNode);
                    if (gsaNode == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null");
                    }
                    if (gsaNode.Node == null)
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Node input is null");
                    }
                }
                else if (GH_Convert.ToPoint3d(gh_typ.Value, ref tempPt, GH_Conversion.Both))
                {
                    gsaNode = new GsaNode(tempPt);
                }
                else
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert input to Node");
                    return;
                }
                GsaNode node = gsaNode.Duplicate();

                // #### inputs ####

                // 1 ID
                GH_Integer ghInt = new GH_Integer();
                if (DA.GetData(1, ref ghInt))
                {
                    if (GH_Convert.ToInt32(ghInt, out int id, GH_Conversion.Both))
                    {
                        node.ID = id;
                    }
                }

                // 2 Point
                GH_Point ghPt = new GH_Point();
                if (DA.GetData(2, ref ghPt))
                {
                    Point3d pt = new Point3d();
                    if (GH_Convert.ToPoint3d(ghPt, ref pt, GH_Conversion.Both))
                    {
                        node.Point           = pt;
                        node.Node.Position.X = pt.X;
                        node.Node.Position.Y = pt.Y;
                        node.Node.Position.Z = pt.Z;
                    }
                }

                // 3 plane
                GH_Plane ghPln = new GH_Plane();
                if (DA.GetData(3, ref ghPln))
                {
                    Plane pln = new Plane();
                    if (GH_Convert.ToPlane(ghPln, ref pln, GH_Conversion.Both))
                    {
                        pln.Origin     = node.Point;
                        node.LocalAxis = pln;
                    }
                }

                // 4 Restraint
                GsaBool6 restraint = new GsaBool6();
                if (DA.GetData(4, ref restraint))
                {
                    node.Node.Restraint.X  = restraint.X;
                    node.Node.Restraint.Y  = restraint.Y;
                    node.Node.Restraint.Z  = restraint.Z;
                    node.Node.Restraint.XX = restraint.XX;
                    node.Node.Restraint.YY = restraint.YY;
                    node.Node.Restraint.ZZ = restraint.ZZ;
                }

                // 5 Spring
                GsaSpring spring = new GsaSpring();
                if (DA.GetData(5, ref spring))
                {
                    if (spring != null)
                    {
                        node.Spring = spring;
                    }
                }

                // 6 Name
                GH_String ghStr = new GH_String();
                if (DA.GetData(6, ref ghStr))
                {
                    if (GH_Convert.ToString(ghStr, out string name, GH_Conversion.Both))
                    {
                        node.Node.Name = name;
                    }
                }

                // 7 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(7, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        node.Colour = col;
                    }
                }

                // #### outputs ####
                DA.SetData(0, new GsaNodeGoo(node));
                DA.SetData(1, node.ID);
                DA.SetData(2, node.Point);
                DA.SetData(3, node.LocalAxis);
                GsaBool6 restraint1 = new GsaBool6
                {
                    X  = node.Node.Restraint.X,
                    Y  = node.Node.Restraint.Y,
                    Z  = node.Node.Restraint.Z,
                    XX = node.Node.Restraint.XX,
                    YY = node.Node.Restraint.YY,
                    ZZ = node.Node.Restraint.ZZ
                };
                DA.SetData(4, restraint1);
                GsaSpring spring1 = new GsaSpring();
                if (node.Spring != null)
                {
                    spring1 = node.Spring.Duplicate();
                }
                DA.SetData(5, new GsaSpringGoo(spring1));
                DA.SetData(6, node.Node.Name);
                DA.SetData(7, node.Colour);
                try { DA.SetDataList(8, node.Node.ConnectedElements); } catch (Exception) { }
                try { DA.SetDataList(9, node.Node.ConnectedMembers); } catch (Exception) { }
            }
        }
Esempio n. 24
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember3d gsaMember3d = new GsaMember3d();

            if (DA.GetData(0, ref gsaMember3d))
            {
                if (gsaMember3d == null)
                {
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Member3D input is null");
                }
                GsaMember3d mem = gsaMember3d.Duplicate();

                // #### inputs ####

                // 1 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(1, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 2 geometry
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaMember3d tempMem = new GsaMember3d();
                    Brep        brep    = new Brep();
                    Mesh        mesh    = new Mesh();
                    if (GH_Convert.ToBrep(gh_typ.Value, ref brep, GH_Conversion.Both))
                    {
                        tempMem = new GsaMember3d(brep);
                    }
                    else if (GH_Convert.ToMesh(gh_typ.Value, ref mesh, GH_Conversion.Both))
                    {
                        tempMem = new GsaMember3d(mesh);
                    }
                    else
                    {
                        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert Geometry input to a 3D Member");
                        return;
                    }
                    mem.SolidMesh = tempMem.SolidMesh;
                }

                // 3 prop3d -- to be implemented GsaAPI
                gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(3, ref gh_typ))
                {
                    if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                    {
                        mem.Member.Property = idd;
                    }
                    //GsaProp3d prop3d = new GsaProp3d();
                    //if (gh_typ.Value is GsaProp3dGoo)
                    //    gh_typ.CastTo(ref prop3d);
                    //else
                    //{
                    //    if (GH_Convert.ToInt32(gh_typ.Value, out int idd, GH_Conversion.Both))
                    //        prop3d.ID = idd;
                    //    else
                    //    {
                    //        AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unable to convert PA input to a 3D Property of reference integer");
                    //        return;
                    //    }
                    //}
                    //mem.Property = prop3d;
                }

                // 4 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(4, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 5 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(5, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 6 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(6, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 7 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(7, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 8 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(8, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 9 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(9, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####

                DA.SetData(0, new GsaMember3dGoo(mem));
                DA.SetData(1, mem.ID);
                DA.SetData(2, mem.SolidMesh);

                //DA.SetData(3, mem.Property);

                DA.SetData(4, mem.Member.MeshSize);
                //DA.SetData(5, mem.Member.MeshWithOthers);

                DA.SetData(6, mem.Member.Name);
                DA.SetData(7, mem.Member.Group);
                DA.SetData(8, mem.Member.Colour);
                DA.SetData(9, mem.Member.IsDummy);
            }
        }
Esempio n. 25
0
        /*******************************************/

        public static bool CastToGoo(object value, ref GH_Colour target)
        {
            return(GH_Convert.ToGHColour(value, GH_Conversion.Both, ref target));
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaElement1d gsaElement1d = new GsaElement1d();

            if (DA.GetData(0, ref gsaElement1d))
            {
                GsaElement1d elem = gsaElement1d.Duplicate();

                // #### inputs ####
                // 1 curve
                GH_Line ghcrv = new GH_Line();
                if (DA.GetData(1, ref ghcrv))
                {
                    Line crv = new Line();
                    if (GH_Convert.ToLine(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        LineCurve    ln      = new LineCurve(crv);
                        GsaElement1d tmpelem = new GsaElement1d(ln)
                        {
                            ID           = elem.ID,
                            Element      = elem.Element,
                            ReleaseEnd   = elem.ReleaseEnd,
                            ReleaseStart = elem.ReleaseStart
                        };
                        elem = tmpelem;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSection)
                    {
                        gh_typ.CastTo(ref section);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            section.ID = idd;
                        }
                    }
                    elem.Section = section;
                }

                // 3 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(3, ref offset))
                {
                    elem.Element.Offset.X1 = offset.X1;
                    elem.Element.Offset.X2 = offset.X2;
                    elem.Element.Offset.Y  = offset.Y;
                    elem.Element.Offset.Z  = offset.Z;
                }

                // 4 start release
                GsaBool6 start = new GsaBool6();
                if (DA.GetData(4, ref start))
                {
                    elem.ReleaseStart = start; //should handle setting the release in elem.Element.SetRelease
                }

                // 5 end release
                GsaBool6 end = new GsaBool6();
                if (DA.GetData(5, ref end))
                {
                    elem.ReleaseEnd = end; //should handle setting the release in elem.Element.SetRelease
                }

                // 6 orientation angle
                GH_Number ghangle = new GH_Number();
                if (DA.GetData(6, ref ghangle))
                {
                    if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both))
                    {
                        elem.Element.OrientationAngle = angle;
                    }
                }

                // 7 orientation node
                GH_Integer ghori = new GH_Integer();
                if (DA.GetData(7, ref ghori))
                {
                    if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both))
                    {
                        elem.Element.OrientationNode = orient;
                    }
                }

                // 8 type
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(8, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        elem.Element.Type = Util.Gsa.GsaToModel.Element1dType(type);
                    }
                }

                // 9 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(9, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        elem.ID = id;
                    }
                }

                // 10 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(10, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        elem.Element.Name = name;
                    }
                }

                // 11 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(11, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        elem.Element.Group = grp;
                    }
                }

                // 12 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(12, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        elem.Element.Colour = col;
                    }
                }

                // #### outputs ####
                DA.SetData(0, new GsaElement1dGoo(elem));

                DA.SetData(1, elem.Line);
                DA.SetData(2, elem.Section);

                GsaOffset offset1 = new GsaOffset
                {
                    X1 = elem.Element.Offset.X1,
                    X2 = elem.Element.Offset.X2,
                    Y  = elem.Element.Offset.Y,
                    Z  = elem.Element.Offset.Z
                };
                DA.SetData(3, offset1);

                DA.SetData(4, elem.ReleaseStart);
                DA.SetData(5, elem.ReleaseEnd);

                DA.SetData(6, elem.Element.OrientationAngle);
                DA.SetData(7, elem.Element.OrientationNode);

                DA.SetData(8, elem.Element.Type);

                DA.SetData(9, elem.ID);
                DA.SetData(10, elem.Element.Name);
                DA.SetData(11, elem.Element.Group);
                DA.SetData(12, elem.Element.Colour);

                try { DA.SetData(13, elem.Element.ParentMember.Member); } catch (Exception) { }
                //DA.SetData(16, gsaElement1d.Element.IsDummy);
            }
        }
Esempio n. 27
0
    public override bool CastFrom(object source)
    {
        var switchExpr = source.GetType();

        switch (switchExpr)
        {
        case var @case when @case == typeof(Tensor):
        {
            this.Value = (Tensor)source;
            return(true);
        }

        case var case1 when case1 == typeof(TensorSet):
        {
            TensorSet ts = (TensorSet)source;
            if (ts.Count != 1)
            {
                return(false);
            }
            this.Value = ts[0];
            return(true);
        }

        case var case2 when case2 == typeof(Point3d):
        {
            Point3d asp = source;
            this.Value = new Tensor(new[] { asp.X, asp.Y, asp.Z });
            return(true);
        }

        case var case3 when case3 == typeof(GH_Point):
        {
            GH_Point asp = source;
            this.Value = new Tensor(new[] { asp.Value.X, asp.Value.Y, asp.Value.Z });
            return(true);
        }

        case var case4 when case4 == typeof(GH_Vector):
        {
            GH_Vector asp = source;
            this.Value = new Tensor(new[] { asp.Value.X, asp.Value.Y, asp.Value.Z });
            return(true);
        }

        case var case5 when case5 == typeof(Vector3d):
        {
            Vector3d asp = source;
            this.Value = new Tensor(new[] { asp.X, asp.Y, asp.Z });
            return(true);
        }

        case var case6 when case6 == typeof(Color):
        {
            Color asp = (Color)source;
            this.Value = new Tensor(new[] { Convert.ToDouble(asp.A), Convert.ToDouble(asp.R), Convert.ToDouble(asp.G), Convert.ToDouble(asp.B) });
            return(true);
        }

        case var case7 when case7 == typeof(GH_Colour):
        {
            GH_Colour asp = source;
            this.Value = new Tensor(new[] { Convert.ToDouble(asp.Value.A), Convert.ToDouble(asp.Value.R), Convert.ToDouble(asp.Value.G), Convert.ToDouble(asp.Value.B) });
            return(true);
        }

        case var case8 when case8 == typeof(Line):
        {
            Line asp = source;
            this.Value = new Tensor(new[] { asp.From.X, asp.From.Y, asp.From.Z, asp.To.X, asp.To.Y, asp.To.Z });
            return(true);
        }

        case var case9 when case9 == typeof(GH_Line):
        {
            GH_Line thisv = source;
            Line    asp   = thisv.Value;
            this.Value = new Tensor(new[] { asp.From.X, asp.From.Y, asp.From.Z, asp.To.X, asp.To.Y, asp.To.Z });
            return(true);
        }
        }

        return(false);
    }
Esempio n. 28
0
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaProp2d gsaProp2d = new GsaProp2d();

            if (DA.GetData(0, ref gsaProp2d))
            {
                GsaProp2d prop = gsaProp2d.Duplicate();

                // #### inputs ####
                // 1 thickness
                string thk = ""; //prop.Prop2d.Thickness;
                if (DA.GetData(1, ref thk))
                {
                    //prop.Prop2d.Thickness = thk;
                }

                // 2 Material
                // to be implemented

                // 3 analysis type
                int analtype = 0; //prop.Prop2d.Thickness;
                if (DA.GetData(3, ref analtype))
                {
                    prop.Prop2d.MaterialAnalysisProperty = analtype;
                }

                // 4 alignment
                string ali = "";
                if (DA.GetData(4, ref ali))
                {
                    // to be implement / GsaAPI can handle alignment / reference surface
                }

                // 5 offset
                GsaOffset offsetGSA = new GsaOffset();
                double    offset    = 0;
                if (DA.GetData(5, ref offsetGSA))
                {
                    //prop.Prop2d.Offeset = offsetGSA.Z;
                }
                else if (DA.GetData(5, ref offset))
                {
                    //prop.Prop2d.Offeset = offset;
                }

                // 6 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(6, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        prop.ID = id;
                    }
                }

                // 7 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(7, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        prop.Prop2d.Name = name;
                    }
                }

                // 8 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(8, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        prop.Prop2d.Colour = col;
                    }
                }

                //#### outputs ####
                DA.SetData(0, new GsaProp2dGoo(prop));

                //DA.SetData(1, gsaProp2d.Thickness); // GsaAPI to be updated
                //DA.SetData(2, gsaProp2d.Prop2d.Material); // to be implemented
                DA.SetData(3, prop.Prop2d.MaterialAnalysisProperty); // GsaAPI to be updated
                //DA.SetData(4, gsaProp2d.??); GsaAPI to include alignment / reference surface

                GsaOffset gsaoffset = new GsaOffset();
                //offset.Z = gsaProp2d.Prop2d.Offset; // GsaAPI to include prop2d offset
                DA.SetData(5, gsaoffset);

                DA.SetData(6, prop.ID);
                DA.SetData(7, prop.Prop2d.Name);
                DA.SetData(8, prop.Prop2d.Colour);
            }
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaSection gsaSection = new GsaSection();

            if (DA.GetData(0, ref gsaSection))
            {
                if (gsaSection != null)
                {
                    // #### input ####
                    // 1 profile
                    string profile = "";
                    if (DA.GetData(1, ref profile))
                    {
                        gsaSection.Section.Profile = profile;
                    }

                    // 2 Material
                    // to be implemented

                    // 3 analysis type
                    int analtype = 0; //prop.Prop2d.Thickness;
                    if (DA.GetData(3, ref analtype))
                    {
                        gsaSection.Section.MaterialAnalysisProperty = analtype;
                    }

                    // 4 section pool
                    int pool = 0; //prop.Prop2d.Thickness;
                    if (DA.GetData(4, ref pool))
                    {
                        gsaSection.Section.Pool = pool;
                    }

                    // 5 offset

                    int offset = 0;
                    if (DA.GetData(5, ref offset))
                    {
                        //prop.Prop2d.Offeset = offset;
                    }

                    // 6 ID
                    GH_Integer ghID = new GH_Integer();
                    if (DA.GetData(6, ref ghID))
                    {
                        if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                        {
                            gsaSection.ID = id;
                        }
                    }

                    // 7 name
                    GH_String ghnm = new GH_String();
                    if (DA.GetData(7, ref ghnm))
                    {
                        if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                        {
                            gsaSection.Section.Name = name;
                        }
                    }

                    // 8 Colour
                    GH_Colour ghcol = new GH_Colour();
                    if (DA.GetData(8, ref ghcol))
                    {
                        if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                        {
                            gsaSection.Section.Colour = col;
                        }
                    }

                    // #### outputs ####
                    DA.SetData(0, new GsaSectionGoo(gsaSection));

                    DA.SetData(1, gsaSection.Section.Profile.Replace("%", " "));
                    //DA.SetData(2, gsaProp2d.Prop2d.Material); // to be implemented
                    DA.SetData(3, gsaSection.Section.MaterialAnalysisProperty);
                    DA.SetData(4, gsaSection.Section.Pool);
                    //DA.SetData(5, gsaSection.Section.Offset);
                    DA.SetData(6, gsaSection.ID);
                    DA.SetData(7, gsaSection.Section.Name);
                    DA.SetData(8, gsaSection.Section.Colour);
                }
            }
        }
Esempio n. 30
0
        /// <summary>
        /// Returns a string representation of a hex color given a GH_Colour object
        /// </summary>
        /// <param name="ghColor">the grasshopper color to convert</param>
        /// <returns>a hex color string</returns>
        public static string hexColor(GH_Colour ghColor)
        {
            string hexStr = "0x" + ghColor.Value.R.ToString("X2") +
                ghColor.Value.G.ToString("X2") +
                ghColor.Value.B.ToString("X2");

            return hexStr;
        }
        private string ConstructMaterial(GH_Colour inColor, GH_Number inNumber)
        {
            //json object to populate
            dynamic jason = new ExpandoObject();

            //JSON properties
            jason.uuid = Guid.NewGuid();
            jason.type = "LineBasicMaterial";
            jason.color = _Utilities.hexColor(inColor);
            jason.linewidth = inNumber.Value;
            jason.opacity = 1;

            return JsonConvert.SerializeObject(jason);
        }
Esempio n. 32
0
        private string ConstructPhongMaterial(GH_Colour col, GH_Colour amb, GH_Colour em, GH_Colour spec, Double shin, Double opp)
        {
            dynamic jason = new ExpandoObject();

            jason.uuid = Guid.NewGuid();
            jason.type = "MeshPhongMaterial";
            jason.color = _Utilities.hexColor(col);
            jason.ambient = _Utilities.hexColor(amb);
            jason.emissive = _Utilities.hexColor(em);
            jason.specular = _Utilities.hexColor(spec);
            jason.shininess = shin;
            if (opp < 1)
            {
                jason.transparent = true;
                jason.opacity = opp;
            }
            jason.wireframe = false;
            jason.side = 2;
            return JsonConvert.SerializeObject(jason);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            GsaMember1d gsaMember1d = new GsaMember1d();

            if (DA.GetData(0, ref gsaMember1d))
            {
                GsaMember1d mem = gsaMember1d.Duplicate();

                // #### inputs ####

                // 1 curve
                GH_Curve ghcrv = new GH_Curve();
                if (DA.GetData(1, ref ghcrv))
                {
                    Curve crv = null;
                    if (GH_Convert.ToCurve(ghcrv, ref crv, GH_Conversion.Both))
                    {
                        GsaMember1d tmpmem = new GsaMember1d(crv)
                        {
                            ID           = mem.ID,
                            Member       = mem.Member,
                            ReleaseEnd   = mem.ReleaseEnd,
                            ReleaseStart = mem.ReleaseStart
                        };
                        mem = tmpmem;
                    }
                }

                // 2 section
                GH_ObjectWrapper gh_typ = new GH_ObjectWrapper();
                if (DA.GetData(2, ref gh_typ))
                {
                    GsaSection section = new GsaSection();
                    if (gh_typ.Value is GsaSection)
                    {
                        gh_typ.CastTo(ref section);
                    }
                    else if (gh_typ.Value is GH_Number)
                    {
                        if (GH_Convert.ToInt32((GH_Number)gh_typ.Value, out int idd, GH_Conversion.Both))
                        {
                            section.ID = idd;
                        }
                    }
                    mem.Section = section;
                }


                // 3 type
                GH_Integer ghint = new GH_Integer();
                if (DA.GetData(4, ref ghint))
                {
                    if (GH_Convert.ToInt32(ghint, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type = Util.Gsa.GsaToModel.Member1dType(type);
                    }
                }

                // 4 element type
                GH_Integer ghinteg = new GH_Integer();
                if (DA.GetData(4, ref ghinteg))
                {
                    if (GH_Convert.ToInt32(ghinteg, out int type, GH_Conversion.Both))
                    {
                        mem.Member.Type1D = Util.Gsa.GsaToModel.Element1dType(type);
                    }
                }

                // 5 offset
                GsaOffset offset = new GsaOffset();
                if (DA.GetData(5, ref offset))
                {
                    mem.Member.Offset.X1 = offset.X1;
                    mem.Member.Offset.X2 = offset.X2;
                    mem.Member.Offset.Y  = offset.Y;
                    mem.Member.Offset.Z  = offset.Z;
                }

                // 6 start release
                GsaBool6 start = new GsaBool6();
                if (DA.GetData(6, ref start))
                {
                    mem.ReleaseStart = start;
                }

                // 7 end release
                GsaBool6 end = new GsaBool6();
                if (DA.GetData(7, ref end))
                {
                    mem.ReleaseEnd = end;
                }

                // 8 orientation angle
                GH_Number ghangle = new GH_Number();
                if (DA.GetData(8, ref ghangle))
                {
                    if (GH_Convert.ToDouble(ghangle, out double angle, GH_Conversion.Both))
                    {
                        mem.Member.OrientationAngle = angle;
                    }
                }

                // 9 orientation node
                GH_Integer ghori = new GH_Integer();
                if (DA.GetData(9, ref ghori))
                {
                    if (GH_Convert.ToInt32(ghori, out int orient, GH_Conversion.Both))
                    {
                        mem.Member.OrientationNode = orient;
                    }
                }

                // 10 mesh size
                GH_Number ghmsz = new GH_Number();
                if (DA.GetData(10, ref ghmsz))
                {
                    if (GH_Convert.ToDouble(ghmsz, out double msz, GH_Conversion.Both))
                    {
                        mem.Member.MeshSize = msz;
                    }
                }

                // 11 mesh with others
                GH_Boolean ghbool = new GH_Boolean();
                if (DA.GetData(11, ref ghbool))
                {
                    if (GH_Convert.ToBoolean(ghbool, out bool mbool, GH_Conversion.Both))
                    {
                        //mem.member.MeshWithOthers
                    }
                }

                // 12 ID
                GH_Integer ghID = new GH_Integer();
                if (DA.GetData(12, ref ghID))
                {
                    if (GH_Convert.ToInt32(ghID, out int id, GH_Conversion.Both))
                    {
                        mem.ID = id;
                    }
                }

                // 13 name
                GH_String ghnm = new GH_String();
                if (DA.GetData(13, ref ghnm))
                {
                    if (GH_Convert.ToString(ghnm, out string name, GH_Conversion.Both))
                    {
                        mem.Member.Name = name;
                    }
                }

                // 14 Group
                GH_Integer ghgrp = new GH_Integer();
                if (DA.GetData(14, ref ghgrp))
                {
                    if (GH_Convert.ToInt32(ghgrp, out int grp, GH_Conversion.Both))
                    {
                        mem.Member.Group = grp;
                    }
                }

                // 15 Colour
                GH_Colour ghcol = new GH_Colour();
                if (DA.GetData(15, ref ghcol))
                {
                    if (GH_Convert.ToColor(ghcol, out System.Drawing.Color col, GH_Conversion.Both))
                    {
                        mem.Member.Colour = col;
                    }
                }

                // 16 Dummy
                GH_Boolean ghdum = new GH_Boolean();
                if (DA.GetData(16, ref ghdum))
                {
                    if (GH_Convert.ToBoolean(ghdum, out bool dum, GH_Conversion.Both))
                    {
                        mem.Member.IsDummy = dum;
                    }
                }

                // #### outputs ####
                DA.SetData(0, new GsaMember1dGoo(mem));
                DA.SetData(1, mem.PolyCurve);
                DA.SetData(2, mem.Section);

                DA.SetData(3, mem.Member.Type);

                DA.SetData(4, mem.Member.Type1D);

                GsaOffset gsaOffset = new GsaOffset
                {
                    X1 = mem.Member.Offset.X1,
                    X2 = mem.Member.Offset.X2,
                    Y  = mem.Member.Offset.Y,
                    Z  = mem.Member.Offset.Z
                };
                DA.SetData(5, gsaOffset);

                DA.SetData(6, mem.ReleaseStart);
                DA.SetData(7, mem.ReleaseEnd);

                DA.SetData(8, mem.Member.OrientationAngle);
                DA.SetData(9, mem.Member.OrientationNode);

                DA.SetData(10, mem.Member.MeshSize);
                //DA.SetData(11, mem.member.MeshSize); //mesh with others bool

                DA.SetData(12, mem.ID);
                DA.SetData(13, mem.Member.Name);
                DA.SetData(14, mem.Member.Group);
                DA.SetData(15, mem.Member.Colour);

                DA.SetData(16, mem.Member.IsDummy);
            }
        }
 private object CreateMaterial(GH_Colour inColor, double inOpacity)
 {
     dynamic jason = new ExpandoObject();
     jason.uuid = Guid.NewGuid();
     jason.type = "MeshBasicMaterial";
     jason.color = _Utilities.hexColor(inColor);
     jason.side = 2;
     if (inOpacity < 1)
     {
         jason.transparent = true;
         jason.opacity = inOpacity;
     }
     return JsonConvert.SerializeObject(jason);
 }
Esempio n. 35
0
        SolveResults Compute(string fileLoc, int numColors)
        {
            var rc = new SolveResults();
            Dictionary <Color, int> dictColors = new Dictionary <Color, int>();
            Dictionary <Color, List <GH_Point> > dictColorLocation = new Dictionary <Color, List <GH_Point> >();
            List <GH_Colour>        topCols     = new List <GH_Colour>();
            List <GH_Integer>       colCount    = new List <GH_Integer>();
            GH_Structure <GH_Point> colLocation = new GH_Structure <GH_Point>();


            try
            {
                using (Bitmap bitmap = new Bitmap(fileLoc))
                {
                    GH_Integer pixCount = new GH_Integer();
                    GH_Convert.ToGHInteger(bitmap.Height * bitmap.Width, 0, ref pixCount);
                    rc.PixCount = pixCount;

                    ///https://www.grasshopper3d.com/forum/topics/unsafe?page=1&commentId=2985220%3AComment%3A808291&x=1#2985220Comment808291
                    GH_MemoryBitmap sampler = new GH_MemoryBitmap(bitmap);

                    Color col = Color.Transparent;
                    for (int x = 0; x < bitmap.Width; x++)
                    {
                        for (int y = 0; y < bitmap.Height; y++)
                        {
                            ///GH_MemoryBitmap Sample is faster than GetPixel
                            //col = bitmap.GetPixel(x, y);
                            if (sampler.Sample(x, y, ref col))
                            {
                                if (!dictColors.ContainsKey(col))
                                {
                                    dictColors.Add(col, 1);
                                    //dictColorLocation.Add(col, new List<GH_Point> { new GH_Point(new Point3d(x,y,0)) });
                                }
                                else
                                {
                                    dictColors[col]++;
                                    //dictColorLocation[col].Add(new GH_Point(new Point3d(x,y,0)));
                                }
                            }
                        }
                    }

                    if (numColors > dictColors.Count || numColors <= 0)
                    {
                        numColors = dictColors.Count;
                    }

                    var sortedColorDict = (from entry in dictColors orderby entry.Value descending select entry)
                                          .Take(numColors)
                                          .ToDictionary(pair => pair.Key, pair => pair.Value);

                    //var sortedColorLocation = (from entry in dictColorLocation orderby entry.Value.Count descending select entry)
                    //    .Take(numColors)
                    //   .ToDictionary(pair => pair.Key, pair => pair.Value);

                    foreach (var clr in sortedColorDict)
                    {
                        GH_Colour gh_Col = new GH_Colour();
                        GH_Convert.ToGHColour(clr.Key, 0, ref gh_Col);
                        topCols.Add(gh_Col);

                        GH_Integer gh_Count = new GH_Integer();
                        GH_Convert.ToGHInteger(clr.Value, 0, ref gh_Count);
                        colCount.Add(gh_Count);
                    }

                    /*int i = 0;
                     * foreach (var clr in sortedColorLocation)
                     * {
                     *  GH_Path path = new GH_Path(i);
                     *  colLocation.AppendRange(clr.Value, path);
                     *  i++;
                     * }
                     */

                    sampler.Release(false);
                    bitmap.Dispose();
                }
            }

            catch
            {
                AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Could not load image from file path: " + fileLoc);
            }

            rc.TopColors  = topCols;
            rc.ColorCount = colCount;
            //rc.ColorLocation = colLocation;

            return(rc);
        }
        private string ConstructLambertMaterial(GH_Colour col, GH_Colour amb, GH_Colour em,  Double opp, bool smooth)
        {
            dynamic jason = new ExpandoObject();

            jason.uuid = Guid.NewGuid();
            jason.type = "MeshLambertMaterial";
            jason.color = _Utilities.hexColor(col);
            jason.ambient = _Utilities.hexColor(amb);
            jason.emissive = _Utilities.hexColor(em);
            if (opp < 1)
            {
                jason.transparent = true;
                jason.opacity = opp;
            }
            jason.wireframe = false;
            jason.side = 2;
            if (smooth)
            {
                jason.shading = 2;
            }
            else
            {
                jason.shading = 1;
            }
            return JsonConvert.SerializeObject(jason);
        }