Пример #1
0
        public AreaTypeRegistration RegisterNewAreaType(string ruleName, bool insertAsFirst)
        {
            int id = customAreaNextTypeId++;

            if (customPointNextTypeId == 0x4b)
            {
                customPointNextTypeId++;
            }

            if (customPointNextTypeId == 0x4c)
            {
                customPointNextTypeId++;
            }

            if ((customAreaNextTypeId & 0xff) == 20)
            {
                customAreaNextTypeId += 0xe0;
            }

            AreaTypeRegistration reg = new AreaTypeRegistration(id, ruleName);

            areaTypeRegistrations.Add(ruleName, reg);

            if (insertAsFirst)
            {
                areaTypeRegistrationsByPriority.Insert(0, reg);
            }
            else
            {
                areaTypeRegistrationsByPriority.Add(reg);
            }

            return(reg);
        }
Пример #2
0
        public AreaTypeRegistration RegisterStandardAreaType(int typeId, string ruleName)
        {
            AreaTypeRegistration reg = new AreaTypeRegistration(typeId, ruleName);

            areaTypeRegistrations.Add(ruleName, reg);
            areaTypeRegistrationsByPriority.Add(reg);
            return(reg);
        }
Пример #3
0
        public void CheckNewTypesIdGeneration()
        {
            TypesRegistry reg = new TypesRegistry();

            for (int i = 0; i < 100; i++)
            {
                AreaTypeRegistration type = reg.RegisterNewAreaType(i.ToString(), false);

                Assert.AreNotEqual <int> (0x010f20, type.TypeId);
                Assert.AreNotEqual <int> (0x010f21, type.TypeId);
                Assert.AreNotEqual <int> (0x010f30, type.TypeId);
            }
        }
Пример #4
0
        public override void RegisterType(
            string ruleName,
            TypesRegistry typesRegistry,
            bool insertAsFirst)
        {
            // if the type was already registered, skip it
            if (typesRegistry.AreaTypeRegistrations.ContainsKey(ruleName))
            {
                return;
            }

            AreaTypeRegistration typeRegistration = null;

            string typeName = null;

            if (Style.HasParameter("typename"))
            {
                typeName = Style.GetParameter("typename");
            }
            else
            {
                typeName = Style.GetParameter("rulename");
            }

            // is it a standard Garmin type?
            if (typesRegistry.GarminAreaTypesDictionary.HasType(typeName))
            {
                int standardType = typesRegistry.GarminAreaTypesDictionary.GetType(typeName);
                typeRegistration = typesRegistry.RegisterStandardAreaType(standardType, ruleName);
            }
            else
            {
                typeRegistration          = typesRegistry.RegisterNewAreaType(ruleName, insertAsFirst);
                typeRegistration.TypeName = typeName;
            }

            IList <string> colors = Style.GetParameter <IList <string> >("colors");

            foreach (string color in colors)
            {
                typeRegistration.Pattern.AddColor(color);
            }

            if (Style.HasParameter("label"))
            {
                LabelExpressionParser labelExpressionParser = new LabelExpressionParser();
                typeRegistration.Label = labelExpressionParser.Parse(Style.GetParameter("label"), 0);
            }

            if (Style.HasParameter("pattern"))
            {
                string   pattern      = Style.GetParameter("pattern");
                string[] patternLines = pattern.Split('|');

                foreach (string patternLine in patternLines)
                {
                    typeRegistration.Pattern.PatternLines.Add(patternLine);
                }
            }

            typeRegistration.MinLevel = Math.Max(12, Style.MinZoomFactor);
            typeRegistration.MaxLevel = Math.Min(24, Style.MaxZoomFactor);

            this.TypeRegistration = typeRegistration;
        }
Пример #5
0
        private static void WritePolygonTypeDefinition(
            MapMakerSettings mapMakerSettings,
            CGpsMapperGeneralFileWriter file,
            AreaTypeRegistration registration)
        {
            // constant labels are placed on type definitions instead of each individual map element
            if (registration.Label != null && registration.Label.IsConstant)
            {
                file.AddFormat("string1=4,{0}", registration.Label.BuildLabel(mapMakerSettings, null, null));
            }

            bool bitmapUsed = registration.Pattern.Height > 0;

            file.AddFormat("xpm=\"{0} {1} {2} {3}\"", 32, 32, 4, 1);

            List <string> realColors = new List <string>();

            foreach (string color in registration.Pattern.EnumerateColorList())
            {
                realColors.Add(color);
            }

            // add a transparent color if only one color was specified
            if (realColors.Count == 1)
            {
                realColors.Insert(0, null);
            }

            // if only the 2 colors were specified, reuse them for the nighttime scheme
            if (realColors.Count == 2)
            {
                realColors.Add(realColors[0]);
                realColors.Add(realColors[1]);
            }

            for (int i = 0; i < realColors.Count; i++)
            {
                if (realColors[i] != null)
                {
                    file.AddFormat("\"{0} c #{1}\"", i, realColors[i]);
                }
                else
                {
                    file.AddFormat("\"{0} c none\"", i);
                }
            }

            // if the pattern is not specified, we should still fill the 32x32 box with the main color
            // otherwise the pattern will look like garbage (this is a cgpsmapper bug?)
            if (false == bitmapUsed)
            {
                for (int i = 0; i < 32; i++)
                {
                    file.AddFormat("\"{0}\"", new string('1', 32));
                }
            }
            else
            {
                for (int i = 0; i < 32; i++)
                {
                    StringBuilder normalizedPatternLine = new StringBuilder();

                    for (int j = 0; j < 32; j++)
                    {
                        char patternChar = registration.Pattern.PatternLines[i % registration.Pattern.Height][j % registration.Pattern.Width];
                        normalizedPatternLine.Append(patternChar);
                    }

                    file.AddFormat("\"{0}\"", normalizedPatternLine);
                }
            }
        }