Пример #1
0
        public CcpFile(String path)
        {
            Elements = new List <CppElement>();

            StreamReader file = File.OpenText(path);

            string line;
            var    profiles = new List <List <Point> >();
            Match  match;

            while (!file.EndOfStream)
            {
                line = file.ReadLine();

                // Comment lines
                if (Regex.Match(line, @"^/\*").Success)
                {
                    continue;
                }

                match = Regex.Match(line, @"HEX_NUMCOMP\s*=\s*(\d+)");
                if (match.Success)
                {
                    int components;
                    if (int.TryParse(match.Groups[1].Value, out components))
                    {
                        Components = components;
                        for (int i = 0; i < components; i++)
                        {
                            Elements.Add(new CppElement());
                        }

                        continue;
                    }

                    Warn(line);
                    break;
                }

                match = Regex.Match(line, @"NUM_RAYS\s*=\s*(\d+)");
                if (match.Success)
                {
                    int rays;
                    if (int.TryParse(match.Groups[1].Value, out rays))
                    {
                        Rays = rays;
                        continue;
                    }

                    Warn(line);
                    break;
                }

                match = Regex.Match(line, @"ENVELOPE\s*=\s*(\w+)");
                if (match.Success)
                {
                    string value = match.Groups[1].Value;
                    if (value == "YES")
                    {
                        IsEnvelope = true;
                        continue;
                    }

                    if (value == "NO")
                    {
                        IsEnvelope = false;
                        continue;
                    }

                    Warn(line);
                    break;
                }

                match = Regex.Match(line, @"F(\d\d)TYP\s*=\s*""(.+)""");
                if (match.Success)
                {
                    int index;
                    if (int.TryParse(match.Groups[1].Value, out index))
                    {
                        Elements[index - 1].Type = match.Groups[2].Value;
                        Elements[index - 1].Type = Elements[index - 1].Type.Replace(' ', '"');
                        continue;
                    }

                    Warn(line);
                    break;
                }

                match = Regex.Match(line, @"F(\d\d)DEN\s*=\s*""(\d+)""");
                if (match.Success)
                {
                    int    index;
                    double value;
                    if (
                        int.TryParse(match.Groups[1].Value, out index) &&
                        double.TryParse(match.Groups[2].Value, out value)
                        )
                    {
                        Elements[index - 1].Density = value / 1000;                          // TBD guessing that density units are also scaled to mm
                        continue;
                    }

                    Warn(line);
                    break;
                }

                match = Regex.Match(line, @"([FB])(\d\d)(\w+)\s*=\s*([-\d\.]+)");
                if (match.Success)
                {
                    string side = match.Groups[1].Value;
                    int    index;
                    string key = match.Groups[3].Value;
                    double value;
                    if ((side == "F" || side == "B") &&
                        int.TryParse(match.Groups[2].Value, out index) &&
                        double.TryParse(match.Groups[4].Value, out value)
                        )
                    {
                        CppSideData sideData = side == "F" ? Elements[index - 1].Front : Elements[index - 1].Back;
                        double      units;
                        if (key == "A" || key == "B" || key == "M")
                        {
                            units = -Math.PI / 180;                             // angular units are specified in degrees (TBD sign only tested for A rotations, may be different for others)
                        }
                        else
                        {
                            units = 0.001;                             // linear units are specified in mm
                        }
                        sideData.ElementValues[key] = value * units;
                        continue;
                    }

                    Warn(line);
                    break;
                }
            }

            WriteBlock.ExecuteTask("Import CCP data", CreateGeometry);
        }
 public CppElement()
 {
     Front = new CppSideData();
     Back = new CppSideData();
 }
Пример #3
0
 public CppElement()
 {
     Front = new CppSideData();
     Back  = new CppSideData();
 }