コード例 #1
0
        public object Clone()
        {
            HatchPatternLineDefinition copy = new HatchPatternLineDefinition
            {
                Angle  = this.angle,
                Origin = this.origin,
                Delta  = this.delta,
            };

            foreach (double dash in this.dashPattern)
            {
                copy.DashPattern.Add(dash);
            }

            return(copy);
        }
コード例 #2
0
ファイル: HatchPattern.cs プロジェクト: liyangTeam/WSXCut
        public static HatchPattern FromFile(string file, string patternName)
        {
            HatchPattern pattern = null;

            using (StreamReader reader = new StreamReader(File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite), true))
            {
                while (!reader.EndOfStream)
                {
                    string line = reader.ReadLine();
                    if (line == null)
                    {
                        throw new FileLoadException("Unknown error reading pat file.", file);
                    }
                    // lines starting with semicolons are comments
                    if (line.StartsWith(";"))
                    {
                        continue;
                    }
                    // every pattern definition starts with '*'
                    if (!line.StartsWith("*"))
                    {
                        continue;
                    }

                    // reading pattern name and description
                    int    endName     = line.IndexOf(','); // the first semicolon divides the name from the description that might contain more semicolons
                    string name        = line.Substring(1, endName - 1);
                    string description = line.Substring(endName + 1, line.Length - endName - 1);

                    // remove start and end spaces
                    description = description.Trim();
                    if (!name.Equals(patternName, StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    // we have found the pattern name, the next lines of the file contains the pattern definition
                    line = reader.ReadLine();
                    if (line == null)
                    {
                        throw new FileLoadException("Unknown error reading pat file.", file);
                    }
                    pattern = new HatchPattern(name, description);

                    while (!reader.EndOfStream && !line.StartsWith("*") && !string.IsNullOrEmpty(line))
                    {
                        string[] tokens = line.Split(',');
                        double   angle  = double.Parse(tokens[0]);
                        Vector2  origin = new Vector2(double.Parse(tokens[1]), double.Parse(tokens[2]));
                        Vector2  delta  = new Vector2(double.Parse(tokens[3]), double.Parse(tokens[4]));

                        HatchPatternLineDefinition lineDefinition = new HatchPatternLineDefinition
                        {
                            Angle  = angle,
                            Origin = origin,
                            Delta  = delta,
                        };

                        // the rest of the info is optional if it exists define the dash pattern definition
                        for (int i = 5; i < tokens.Length; i++)
                        {
                            lineDefinition.DashPattern.Add(double.Parse(tokens[i]));
                        }

                        pattern.LineDefinitions.Add(lineDefinition);
                        pattern.Type = HatchType.UserDefined;
                        line         = reader.ReadLine();
                        if (line == null)
                        {
                            throw new FileLoadException("Unknown error reading pat file.", file);
                        }
                        line = line.Trim();
                    }
                    // there is no need to continue parsing the file, the info has been read
                    break;
                }
            }

            return(pattern);
        }