예제 #1
0
        // SOLVER
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            StructureType structuretype = new StormCloud.Types.StructureType();

            //List<decimal> inputval = new List<decimal>();

            if (!DA.GetData(0, ref structuretype))
            {
                return;
            }
            //if (!DA.GetDataList(1, inputval)) { return; }

            ComputedStructure comp = structuretype.Value;

            compstruc = (ComputedStructure)structuretype.Value.CloneImpl();
            //paramval = inputval;

            DesignView.UpdateCurrentModel(comp);
        }
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            /* Declare variables to contain all inputs
             * We can assign initial values (or not) that are either indicative or sensible */
            //AllocConsole();

            List <Rhino.Geometry.Line> lines = new List <Line>();

            Types.MaterialType materialtype = new Types.MaterialType();
            String             sectiontype  = "";

            Boolean isframe = true;

            /* Use the DA object to retrieve the data inside the input parameters
             * If the retrieval fails (e.g. there is no data), abort*/
            if (!DA.GetDataList(0, lines))
            {
                return;
            }
            if (!DA.GetData(1, ref materialtype))
            {
                return;
            }
            if (!DA.GetData(2, ref sectiontype))
            {
                return;
            }
            if (!DA.GetData(3, ref isframe))
            {
                return;
            }


            // material

            StructureEngine.Model.Material material = materialtype.Value;

            // section
            ISection SectionType = new RodSection();

            if (sectiontype == "Square")
            {
                SectionType = new SquareSection();
            }

            //if (!DA.GetData(1, ref Material)) { return; }
            //if (!DA.GetData(2, ref Section)) { return; }
            // if (!DA.GetData(1, ref tolerance)) { return; }

            /* If the tolerance is not a valid number, abort */
            // if (!Rhino.RhinoMath.IsValidDouble(tolerance)) { return; }

            /*Retrieve coordinates of start and end points*/
            List <Rhino.Geometry.Point3d> pts = new List <Rhino.Geometry.Point3d>();
            List <Node>   Nodes   = new List <Node>();
            List <Member> Members = new List <Member>();


            foreach (Line line in lines)
            {
                Point3d start = line.From;
                Point3d end   = line.To;



                int index1 = Nodes.FindIndex(n => n.IsAtPoint(start));
                int index2 = Nodes.FindIndex(n => n.IsAtPoint(end));



                Node n1 = new Node(start, isframe);

                Node n2 = new Node(end, isframe);

                if (index1 == -1 && index2 == -1)
                {
                    n1.SetIndex(Nodes.Count);
                    Nodes.Add(n1);

                    n2.SetIndex(Nodes.Count + 1);
                    Nodes.Add(n2);
                }

                else if (index1 != -1 && index2 == -1)
                {
                    n1 = Nodes[index1];

                    n2.SetIndex(Nodes.Count);
                    Nodes.Add(n2);
                }

                else if (index1 == -1 && index2 != -1)
                {
                    n1.SetIndex(Nodes.Count);
                    Nodes.Add(n1);

                    n2 = Nodes[index2];
                }

                if (!(index1 != -1 && index2 != -1))
                {
                    Member m = new Member(n1, n2);

                    m.Material    = material;
                    m.SectionType = SectionType;

                    //m.Material = Material.MaterialValue;
                    //m.Section = Section.SectionValue;

                    // Add member and nodes to respective list
                    Members.Add(m);
                }
            }



            //Console.WriteLine(5);

            //foreach (Rhino.Geometry.Line line in lines)
            //{
            //    pts.Add(line.From);
            //    pts.Add(line.To);

            //    int n1Index = pts.Count - 2;
            //    int n2Index = pts.Count - 1;

            //    // Define start node, eliminate dup if necessary

            //    for (int i = 0; i < pts.Count - 2; i++) // < should become <= (or not?)
            //    {
            //        if (Rhino.Geometry.Point3d.Equals(pts[pts.Count - 2], pts[i]))
            //        {
            //            pts.RemoveAt(pts.Count - 2);
            //            n1Index = i;
            //            n2Index = n2Index - 1; // test
            //        }
            //    }



            //    DOF x1 = new DOF(pts[n1Index].X);
            //    DOF y1 = new DOF(pts[n1Index].Y);
            //    DOF z1 = new DOF(pts[n1Index].Z);

            //    DOF[] coor1 = new DOF[] { x1, y1, z1, new DOF(0,isframe), new DOF(0,isframe), new DOF(0,isframe) };

            //    Node n1 = new Node(coor1);
            //    n1.Index = n1Index;

            // check that it is a new node


            // Define end node, eliminate dup if necessary

            //    for (int i = 0; i < pts.Count - 1; i++)
            //    {
            //        if (Rhino.Geometry.Point3d.Equals(pts[pts.Count - 1], pts[i]))
            //        {
            //            pts.RemoveAt(pts.Count - 1);
            //            n2Index = i;
            //        }
            //    }

            //    DOF x2 = new DOF(pts[n2Index].X);
            //    DOF y2 = new DOF(pts[n2Index].Y);
            //    DOF z2 = new DOF(pts[n2Index].Z);

            //    DOF[] coor2 = new DOF[] {x2, y2, z2, new DOF(0, isframe), new DOF(0, isframe), new DOF(0, isframe)};

            //    Node n2 = new Node(coor2);
            //    n2.Index = n2Index;

            //    // Define member

            //    Member m = new Member(n1, n2);

            //    m.Material = material;
            //    m.SectionType = SectionType;

            //    //m.Material = Material.MaterialValue;
            //    //m.Section = Section.SectionValue;

            //    // Add member and nodes to respective list

            //    Nodes.Add(n1);
            //    Nodes.Add(n2);
            //    Members.Add(m);

            //}


            Structure Structure = new Structure(Nodes, Members);

            ComputedStructure CompStructure = new ComputedStructure(Structure);

            Types.StructureType Structure_GHrep = new Types.StructureType(CompStructure);

            /*Assign the outputs via the DA object*/
            DA.SetDataList(0, pts);

            DA.SetData(1, Structure_GHrep);
        }