Canguro.Commands.Model.ImportDXFCmd.Import C# (CSharp) Method

Import() public static method

Reads a DXF file and adds all the lines defined in it to the given Model
public static Import ( string path, Canguro model ) : void
path string The path to the DXF file
model Canguro The current Model object
return void
        public static void Import(string path, Canguro.Model.Model model)
        {
            if (path.Length > 0)
            {
                string[] file = File.ReadAllLines(path);
                List<string> search = new List<string>(new string[] { "LINE", "10", "20", "30", "11", "21", "31", "LWPOLYLINE" });
                int state = 0;
                Joint ji = null;
                Joint jj = null;
                StraightFrameProps props = new StraightFrameProps();
                List<LineElement> newLines = new List<LineElement>();
                List<AreaElement> newAreas = new List<AreaElement>();
                List<Joint> newJoints = new List<Joint>();

                bool addLine = false;
                bool polyline = false;
                for (int i = 0; i < file.Length; i++)
                {
                    string line = file[i].Trim().ToUpper();
                    while (!search.Contains(line) && i < file.Length - 1)
                        line = file[++i].Trim().ToUpper();
                    state = search.IndexOf(line);
                    if (state == 0 || state > 6)
                    {
                        addLine = true;
                        jj = null;
                        ji = null;
                    }
                    if (state == 7)
                        polyline = true;

                    if (!addLine)
                        continue;
                    if (i == file.Length - 1)
                        break;
                    line = file[++i].Trim();
                    switch (state)
                    {
                        case 1:
                            jj = (polyline) ? ji : jj;
                            ji = new Joint(Convert.ToSingle(line), 0, 0);
                            if (polyline && jj != null)
                                AddLine(model, ji, jj, props, newJoints, newLines);
                            break;
                        case 2:
                            if (ji != null)
                                ji.Y = Convert.ToSingle(line);
                            break;
                        case 3:
                            if (ji != null)
                                ji.Z = Convert.ToSingle(line);
                            break;
                        case 4:
                            jj = new Joint(Convert.ToSingle(line), 0, 0);
                            break;
                        case 5:
                            if (addLine && jj != null)
                                jj.Y = Convert.ToSingle(line);
                            AddLine(model, ji, jj, props, newJoints, newLines);
                            polyline = false;
                            break;
                        case 6:
                            if (jj != null)
                                jj.Z = Convert.ToSingle(line);
                            break;
                    }
                }
                JoinCmd.Join(model, newJoints, newLines, newAreas);
            }
        }