Esempio n. 1
0
        public static RenderingRuleSet CreateTestRenderingRules()
        {
            RenderingRuleSet rules = new RenderingRuleSet();

            for (int i = 0; i < pointTypesCount; i++)
            {
                IOsmElementSelector selector = new KeyValueSelector(
                    "garmin_icon",
                    i.ToString(CultureInfo.InvariantCulture));
                IconTemplate template = new IconTemplate();

                template.Style.SetParameter("standardtype", i);
                template.Style.SetParameter("label", i.ToString("x", CultureInfo.InvariantCulture));

                RenderingRule rule = new RenderingRule(
                    string.Format(CultureInfo.InvariantCulture, "GarminIcon{0}", i),
                    RenderingRuleTargets.Nodes,
                    selector,
                    template);

                rules.AddRule(rule);
            }

            return(rules);
        }
Esempio n. 2
0
        public void ExceptionIfRulesVersionIsIncompatible()
        {
            TypesRegistry typesRegistry = new TypesRegistry();

            string rulesText = @"== Rendering Rules ==

=== Options ===
{| class='wikitable' border='1' cellspacing='0' cellpadding='2' 
|- style='background-color:#F8F4C2'
! Option
! Value
! Comment 
|-
| RulesVersion || 1.7 || Minimal version of [[GroundTruth]] needed to use these rules
|-
| LandBackgroundColor || #218CFF || Color of the map background. If not set, the default unit color will be used
|-
|}
";

            using (MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(rulesText)))
            {
                WikiRulesParser parser = new WikiRulesParser(
                    stream,
                    typesRegistry,
                    null,
                    SerializersRegistry);
                parser.Parse();
                RenderingRuleSet rules = parser.Rules;
            }
        }
Esempio n. 3
0
        private TypesRegistry ParseRules(string rulesFile, out RenderingRuleSet rules)
        {
            TypesRegistry typesRegistry = new TypesRegistry();

            using (Stream stream = File.OpenRead(rulesFile))
            {
                WikiRulesParser parser = new WikiRulesParser(
                    stream,
                    typesRegistry,
                    null,
                    SerializersRegistry);
                parser.Parse();
                rules = parser.Rules;
            }

            return(typesRegistry);
        }
Esempio n. 4
0
        /// <summary>
        /// Parses the rendering rules and adds the parsed rules to the <see cref="Rules"/> property.
        /// </summary>
        public void Parse()
        {
            string currentMainSection      = null;
            string currentSubsection       = null;
            bool   ignoreRestOfMainSection = false;
            bool   ignoreRestOfSubsection  = false;
            bool   moveNext = true;

            rules = new RenderingRuleSet();

            while (true)
            {
                WikiContentType wikiContentType;

                if (moveNext)
                {
                    wikiContentType = WikiParser.Next();
                }
                else
                {
                    wikiContentType = WikiParser.Context.CurrentType;
                    moveNext        = true;
                }

                if (wikiContentType == WikiContentType.Eof)
                {
                    break;
                }

                if (wikiContentType == WikiContentType.Section || wikiContentType == WikiContentType.Text)
                {
                    WikiSection section = WikiParser.Context.LowestSection;
                    if (section == null)
                    {
                        continue;
                    }

                    if (wikiContentType == WikiContentType.Section)
                    {
                        if (section.SectionLevel == 1)
                        {
                            if (log.IsDebugEnabled)
                            {
                                log.DebugFormat("Found new main section: '{0}'", section.SectionName);
                            }

                            currentMainSection      = section.SectionName;
                            currentSubsection       = null;
                            ignoreRestOfMainSection = false;
                            ignoreRestOfSubsection  = false;
                        }
                        else if (section.SectionLevel == 2)
                        {
                            currentSubsection      = section.SectionName;
                            ignoreRestOfSubsection = false;
                        }
                    }
                    else if (wikiContentType == WikiContentType.Text &&
                             (ignoreRestOfMainSection || ignoreRestOfSubsection))
                    {
                        continue;
                    }

                    switch (currentMainSection.ToLowerInvariant())
                    {
                    case "rendering rules":
                    {
                        if (currentSubsection == null)
                        {
                            continue;
                        }

                        switch (section.SectionName.ToLowerInvariant())
                        {
                        case "options":
                            SkipToTableAndParseIt(ParseOption);
                            AssertRulesVersionCompatibility();
                            ignoreRestOfSubsection = true;
                            break;

                        case "points":
                            SkipToTableAndParseIt(ParsePointRule);
                            ignoreRestOfSubsection = true;
                            break;

                        case "lines":
                            SkipToTableAndParseIt(ParseLineRule);
                            ignoreRestOfSubsection = true;
                            break;

                        case "areas":
                            SkipToTableAndParseIt(ParseAreaRule);
                            ignoreRestOfSubsection = true;
                            break;

                        default:
                            ThrowParseError("Invalid section: '{0}'", section.SectionName);
                            return;
                        }

                        break;
                    }

                    case "standard garmin types":
                    {
                        if (currentSubsection == null)
                        {
                            continue;
                        }

                        switch (section.SectionName.ToLowerInvariant())
                        {
                        case "points":
                            SkipToTableAndParseIt((tableRowCells)
                                                  =>
                                                  ParseStandardGarminTypesDictionary(
                                                      tableRowCells,
                                                      typesRegistry.GarminPointTypesDictionary));
                            ignoreRestOfSubsection = true;
                            break;

                        case "lines":
                            SkipToTableAndParseIt((tableRowCells)
                                                  =>
                                                  ParseStandardGarminTypesDictionary(
                                                      tableRowCells,
                                                      typesRegistry.GarminLineTypesDictionary));
                            ignoreRestOfSubsection = true;
                            break;

                        case "areas":

                            SkipToTableAndParseIt((tableRowCells)
                                                  =>
                                                  ParseStandardGarminTypesDictionary(
                                                      tableRowCells,
                                                      typesRegistry.GarminAreaTypesDictionary));
                            ignoreRestOfSubsection = true;
                            break;

                        default:
                            ThrowParseError("Invalid Garmin standard types section: '{0}'",
                                            section.SectionName);
                            return;
                        }

                        break;
                    }

                    case "characters conversion table":
                    {
                        SkipToTableAndParseIt(ParseCharactersConversionTable);
                        ignoreRestOfMainSection = true;
                        break;
                    }

                    case "patterns":
                    {
                        if (currentSubsection == null)
                        {
                            continue;
                        }

                        ParsePointPattern(section.SectionName);
                        moveNext = false;
                        break;
                    }
                    }
                }
            }
        }