Exemplo n.º 1
0
        // Render a course onto a map.
        public Map RenderToMap(MapRenderOptions mapRenderOptions)
        {
            // Create the map to render into.
            Map map = new Map(MapUtil.TextMetricsProvider, null);

            if (Count == 0)
            {
                return(map);
            }

            SymColor[] colors = new SymColor[LAYERCOUNT];

            using (map.Write()) {
                // Create dictionary for holding Symdef state
                Dictionary <object, SymDef>         dict         = new Dictionary <object, SymDef>();
                Dictionary <SpecialColor, SymColor> customColors = new Dictionary <SpecialColor, SymColor>();

                // Create white color and white-out symdef.
                SymColor   white     = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[KeyLayout] = layoutSymDef;

                // Create colors for the special colors.
                short customColorId = 61;
                foreach (CourseObj courseObject in this)
                {
                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        if (!customColors.ContainsKey(courseObject.CustomColor))
                        {
                            CmykColor cmyk = courseObject.CustomColor.CustomColor;
                            customColors.Add(courseObject.CustomColor, map.AddColor(string.Format("Color {0}", customColorId), customColorId,
                                                                                    cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false));
                            ++customColorId;
                        }
                    }
                }

                // Create colors for the regular colors in the correct order (lower on top).
                for (int layerIndex = LAYERCOUNT - 1; layerIndex >= 0; --layerIndex)
                {
                    if (colorName[layerIndex] != null)
                    {
                        // Create the symColor for rendering.
                        colors[layerIndex] = map.AddColor(colorName[layerIndex], ocadColorId[layerIndex],
                                                          colorC[layerIndex], colorM[layerIndex], colorY[layerIndex], colorK[layerIndex], colorOverprint[layerIndex]);
                    }
                }

                foreach (CourseObj courseObject in this)
                {
                    int layerIndex = (int)courseObject.layer;

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Black)
                    {
                        layerIndex = (int)CourseLayer.Descriptions;
                    }

                    SymColor color = colors[layerIndex];

                    if (courseObject.CustomColor != null && courseObject.CustomColor.Kind == SpecialColor.ColorKind.Custom)
                    {
                        color = customColors[courseObject.CustomColor];
                    }

                    courseObject.AddToMap(map, color, mapRenderOptions, dict);
                }
            }

            return(map);
        }
Exemplo n.º 2
0
        // Render one course object to a map.
        internal Map RenderCourseObjToMap(CourseObj courseobj)
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();

                // Create white color and white-out symdef.
                SymColor white = map.AddColorBottom("White", 44, 0, 0, 0, 0, false);
                AreaSymDef whiteArea = new AreaSymDef("White out", "890", white, null);
                whiteArea.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.WhiteOut_OcadToolbox);
                map.AddSymdef(whiteArea);
                dict[CourseLayout.KeyWhiteOut] = whiteArea;

                // Create layout symdef.
                ImageSymDef layoutSymDef = new ImageSymDef(SymLayer.Layout);
                map.AddSymdef(layoutSymDef);
                dict[CourseLayout.KeyLayout] = layoutSymDef;

                SymColor symColor = null;
                SpecialColor specialColor = courseobj.CustomColor ?? SpecialColor.Purple;
                switch (specialColor.Kind) {
                    case SpecialColor.ColorKind.Black:
                        symColor = map.AddColor("Black", 1, 0, 0, 0, 1F, false);
                        break;
                    case SpecialColor.ColorKind.Purple:
                        symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                        break;
                    case SpecialColor.ColorKind.Custom:
                        CmykColor cmyk = specialColor.CustomColor;
                        symColor = map.AddColor("Custom", 61, cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black, false);
                        break;
                }

                courseobj.AddToMap(map, symColor, dict);

                // Make drop targets visible for debugging.
                foreach (SymDef symdef in map.AllSymdefs) {
                    if (symdef.SymbolId == "781")
                        map.SetSymdefVisible(symdef, true);
                }
            }
            return map;
        }