Exemple #1
0
        private bool SetMaterialFilteredBrep(IReadOnlyList <GH_Structure <GH_Brep> > results, GH_Brep brep, string materialType, GH_Path path)
        {
            if (brep != null)
            {
                switch (materialType)
                {
                case "RC":
                    results[0].Append(brep.DuplicateBrep(), path);
                    break;

                case "S":
                    results[1].Append(brep.DuplicateBrep(), path);
                    break;

                case "SRC":
                    results[2].Append(brep.DuplicateBrep(), path);
                    break;

                case "CFT":
                    results[3].Append(brep.DuplicateBrep(), path);
                    break;

                default:
                    AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Unknown material type");
                    return(true);
                }
            }

            return(false);
        }
        // SOLVER
        // Retrieves data from Grasshopper and changes component properties that can be accessed in the code-behind of stormcloud.xaml
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            //// GEOMETRY
            //// Use IGH_GeometricGoo to deal with different geometry types
            List <IGH_GeometricGoo> g = new List <IGH_GeometricGoo>();

            if (!DA.GetDataList <IGH_GeometricGoo>(0, g))
            {
                return;
            }                                                        // retrieves list of geometries as list of IGH_GeometricGoo
            List <Curve> curves = new List <Curve>();
            List <Mesh>  meshes = new List <Mesh>();
            List <Brep>  breps  = new List <Brep>();

            foreach (IGH_GeometricGoo goo in g)
            {
                GH_Line l = goo as GH_Line;
                if (l != null)
                {
                    GH_Curve lc = new GH_Curve();
                    l.CastTo <GH_Curve>(out lc);
                    curves.Add(lc.DuplicateCurve().Value);
                }
                GH_Curve c = goo as GH_Curve; // c = null if geometry is not a curve
                if (c != null)
                {
                    curves.Add(c.DuplicateCurve().Value); // add to curves if geometry is a curve
                    Console.WriteLine("There is a Curve");
                }
                GH_Mesh m = goo as GH_Mesh;
                if (m != null)
                {
                    GH_Brep br = new GH_Brep();
                    m.CastTo <GH_Brep>(out br);
                    breps.Add(br.DuplicateBrep().Value);
                }

                //GH_Surface s = goo as GH_Surface;
                //if (s != null)
                //{
                //    GH_Brep brs = new GH_Brep();
                //    s.CastTo<GH_Brep>(out brs);
                //    breps.Add(brs.DuplicateBrep().Value);
                //}

                GH_Brep b = goo as GH_Brep;
                if (b != null)
                {
                    breps.Add(b.DuplicateBrep().Value);
                }
            }



            //// Change values of relevant component properties

            DesignCurves = curves;
            DesignMeshes = meshes;
            DesignBreps  = breps;

            // DesignLines
            //List<Line> lines = new List<Line>();
            //if (!DA.GetDataList(0, lines)) { return; }
            //DesignLines = lines;
            // SCORE
            double score = 0; // instantiate score

            if (!DA.GetData(1, ref score))
            {
                return;
            }
            Score = score; // Change value of component property

            // Update model of main 3D viewports in stormcloud
            if (this.DesignView.InitialDesign.Score != 0)
            {
                DesignView.UpdateCurrentScore(Score);
            }
            else
            {
                DesignView.UpdateCurrentScore(1.00);
            }
            //DesignView.UpdateCurrentModel(DesignLines, RenderingSettings.diameter, RenderingSettings.resolutiontube, RenderingSettings.mat);
            DesignView.UpdateCurrentModelAdvanced(DesignCurves, DesignMeshes, DesignBreps, RenderingSettings.diameter, RenderingSettings.resolution, RenderingSettings.resolutiontube, RenderingSettings.mat);
        }