Пример #1
0
        // Test for rendering into a map.

        // Render one course object to a map.
        internal Map RenderSymbolToMap(Symbol sym, float boxSize)
        {
            Map map = new Map(new GDIPlus_TextMetrics(), null);

            using (map.Write()) {
                //Dictionary<object, SymDef> dict = new Dictionary<object, SymDef>();
                SymColor    symColor = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                PointSymDef symdef   = sym.CreateSymdef(map, symColor, boxSize);
                PointSymbol symbol   = new PointSymbol(symdef, new PointF(0, 0), 0, null);
                map.AddSymbol(symbol);
            }
            return(map);
        }
Пример #2
0
        // Render a description to a map, then to a bitmap for testing purposes. Hardcoded 6 mm box size.
        internal static Bitmap RenderToMapThenToBitmap(SymbolDB symbolDB, DescriptionLine[] description, DescriptionKind kind, int numColumns)
        {
            DescriptionRenderer descriptionRenderer = new DescriptionRenderer(symbolDB);

            descriptionRenderer.Description     = description;
            descriptionRenderer.DescriptionKind = kind;
            descriptionRenderer.CellSize        = 6.0F;
            descriptionRenderer.Margin          = 0.7F;
            descriptionRenderer.NumberOfColumns = numColumns;
            PointF location = new PointF(30, -100);

            SizeF size = descriptionRenderer.Measure();

            Bitmap   bm = new Bitmap((int)size.Width * 8, (int)size.Height * 8);
            Graphics g  = Graphics.FromImage(bm);

            g.ScaleTransform(bm.Width / size.Width, -bm.Height / size.Height);
            g.TranslateTransform(-location.X, -location.Y);

            g.Clear(Color.White);

            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;

                SymColor color = map.AddColor("Purple", 11, 0.045F, 0.59F, 0, 0.255F, false);
                descriptionRenderer.RenderToMap(map, color, location, dict);
            }

            InputOutput.WriteFile(TestUtil.GetTestFile("descriptions\\desc_temp.ocd"), map, new MapFileFormat(MapFileFormatKind.OCAD, 8));

            using (map.Read()) {
                RenderOptions renderOpts = new RenderOptions();
                renderOpts.usePatternBitmaps = true;
                renderOpts.minResolution     = 0.1F;
                renderOpts.renderTemplates   = RenderTemplateOption.MapAndTemplates;
                map.Draw(new GDIPlus_GraphicsTarget(g), new RectangleF(location.X, location.Y - size.Height, size.Width, size.Height), renderOpts, null);
            }

            g.Dispose();

            return(bm);
        }
Пример #3
0
        // Create a point symbol that can be used to put this symbol onto a map inside
        // a box of the given size (in mm).
        public PointSymDef CreateSymdef(Map map, SymColor color, float boxSize)
        {
            Glyph glyph = new Glyph();

            for (int i = 0; i < strokes.Length; ++i)
            {
                strokes[i].AddToMapGlyph(glyph, color, boxSize);
            }
            glyph.ConstructionComplete();

            // Find a free OCAD ID number.
            string symbolId = map.GetFreeSymbolId(800);

            // Create the symdef
            PointSymDef symdef;

            symdef = new PointSymDef("Description: " + this.GetName(Util.CurrentLangName()), symbolId, glyph, false);

            // Create the toolbox image.
            Bitmap bm = new Bitmap(24, 24);

            using (Graphics g = Graphics.FromImage(bm)) {
                g.Clear(Color.White);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                if (kind >= 'T')
                {
                    g.SetClip(new RectangleF(0, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(0, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                    g.SetClip(new RectangleF(bm.Width / 2, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(-bm.Width * 5F / 3F, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                }
                else
                {
                    Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                }
            }
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(bm);

            // Add the symdef to the map.
            map.AddSymdef(symdef);

            return(symdef);
        }
Пример #4
0
        // Search all the colors for a color called "Purple".
        public static bool FindPurpleColor(List<SymColor> colors, out short ocadId, out float cyan, out float magenta, out float yellow, out float black)
        {
            float c, m, y, k;

            // Search all colors for one names "Purple" (in any language).
            foreach (SymColor color in colors) {
                if (Array.IndexOf(purpleNames, color.Name) >= 0) {
                    color.GetCMYK(out c, out m, out y, out k);
                    if (IsPurple(c, m, y, k)) {
                        ocadId = color.OcadId;
                        cyan = c; magenta = m; yellow = y; black = k;
                        return true;
                    }
                }
            }

            // Search all colors for one that is closest to pure magenta.
            double distance, minDistance = 1000;
            SymColor bestColor = null;
            foreach (SymColor color in colors) {
                color.GetCMYK(out c, out m, out y, out k);
                if (IsPurple(c, m, y, k)) {
                    distance = c * c + (m - 1) * (m - 1) + (y * y) + (k * k);
                    if (distance < minDistance) {
                        minDistance = distance;
                        bestColor = color;
                    }
                }
            }

            if (bestColor != null) {
                bestColor.GetCMYK(out c, out m, out y, out k);
                ocadId = bestColor.OcadId;
                cyan = c; magenta = m; yellow = y; black = k;
                return true;
            }

            // Did not find purple. 
            ocadId = -1;
            cyan = 0; magenta = 0; yellow = 0; black = 0;
            return false;
        }
Пример #5
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();
            glyph.AddCircle(symColor, new PointF(0.0F, 0.0F), NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, (5.35F * scaleRatio * appearance.controlCircleSize - NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth));
            glyph.AddCircle(symColor, new PointF(0.0F, 0.0F), NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, 7.0F * scaleRatio * appearance.controlCircleSize);
            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Finish", "706", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Finish_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #6
0
        // Render the description into the given map at the given location in the given color.
        public void RenderToMap(Map map, SymColor color, PointF point, Dictionary<object, SymDef> dict)
        {
            IRenderer renderer = new MapRenderer(map, color, dict);

            // Set the correct transform.
            Matrix mat = new Matrix();
            mat.Scale(1, -1);      // flip Y axis.
            mat.Translate(point.X, -point.Y);
            renderer.Transform = mat;

            // White out the background.
            SizeF size = Measure();
            PointKind[] kinds = { PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal};
            PointF[] pts = {Geometry.TransformPoint(new PointF(0, 0), mat), Geometry.TransformPoint(new PointF(size.Width, 0), mat),Geometry.TransformPoint(new PointF(size.Width, size.Height), mat),
                Geometry.TransformPoint(new PointF(0, size.Height), mat),Geometry.TransformPoint(new PointF(0, 0), mat) };
            SymPath path = new SymPath(pts, kinds);
            AreaSymbol whiteout = new AreaSymbol((AreaSymDef) dict[CourseLayout.KeyWhiteOut], new SymPathWithHoles(path, null), 0, new PointF());
            map.AddSymbol(whiteout);

            replaceMultiplySign = false;   // OCAD doesn't handle the multiple character well.
            Render(renderer, new RectangleF(-100000, -100000, 200000, 200000), 0, description.Length);
        }
Пример #7
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();
            SymPath path1, path2;

            GetPaths(out path1, out path2);
            glyph.AddLine(symColor, path1, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Miter, LineCap.Flat);
            glyph.AddLine(symColor, path2, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Miter, LineCap.Flat);

            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Crossing point", "708", glyph, true);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Crossing_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #8
0
            // Add the stroke to an OCAD Map glyph with the given box size.
            public void AddToMapGlyph(Glyph glyph, SymColor color, float boxSize)
            {
                float scaleFactor = boxSize / 200.0F; // symbols are designed in box from -100 to 100.

                switch (kind)
                {
                case SymbolStrokes.Disc:
                    glyph.AddFilledCircle(color, new PointF(points[0].X * scaleFactor, points[0].Y * scaleFactor), radius * 2 * scaleFactor);
                    break;

                case SymbolStrokes.Circle:
                    glyph.AddCircle(color, new PointF(points[0].X * scaleFactor, points[0].Y * scaleFactor), thickness * scaleFactor, (radius * 2 + thickness) * scaleFactor);
                    break;

                case SymbolStrokes.Polyline: {
                    PointKind[] pathKinds  = new PointKind[points.Length];
                    PointF[]    pathPoints = new PointF[points.Length];
                    for (int i = 0; i < points.Length; ++i)
                    {
                        pathKinds[i]  = PointKind.Normal;
                        pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                    }
                    SymPath path = new SymPath(pathPoints, pathKinds);

                    glyph.AddLine(color, path, thickness * scaleFactor, corners, ends);
                    break;
                }

                case SymbolStrokes.Polygon: {
                    PointKind[] pathKinds  = new PointKind[points.Length + 1];
                    PointF[]    pathPoints = new PointF[points.Length + 1];
                    for (int i = 0; i < points.Length; ++i)
                    {
                        pathKinds[i]  = PointKind.Normal;
                        pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                    }
                    pathKinds[points.Length]  = pathKinds[0];
                    pathPoints[points.Length] = pathPoints[0];
                    SymPath path = new SymPath(pathPoints, pathKinds);

                    glyph.AddLine(color, path, thickness * scaleFactor, corners, corners == LineJoin.Round ? LineCap.Round : LineCap.Flat);
                    break;
                }

                case SymbolStrokes.FilledPolygon: {
                    PointKind[] pathKinds  = new PointKind[points.Length + 1];
                    PointF[]    pathPoints = new PointF[points.Length + 1];
                    for (int i = 0; i < points.Length; ++i)
                    {
                        pathKinds[i]  = PointKind.Normal;
                        pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                    }
                    pathKinds[points.Length]  = pathKinds[0];
                    pathPoints[points.Length] = pathPoints[0];
                    SymPath path = new SymPath(pathPoints, pathKinds);
                    glyph.AddArea(color, new SymPathWithHoles(path, null));
                    break;
                }

                case SymbolStrokes.PolyBezier: {
                    PointKind[] pathKinds  = new PointKind[points.Length];
                    PointF[]    pathPoints = new PointF[points.Length];
                    for (int i = 0; i < points.Length; ++i)
                    {
                        pathKinds[i]  = (i % 3 == 0) ? PointKind.Normal : PointKind.BezierControl;
                        pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                    }
                    SymPath path = new SymPath(pathPoints, pathKinds);
                    glyph.AddLine(color, path, thickness * scaleFactor, corners, ends);
                    break;
                }

                case SymbolStrokes.FilledPolyBezier: {
                    PointKind[] pathKinds  = new PointKind[points.Length];
                    PointF[]    pathPoints = new PointF[points.Length];
                    for (int i = 0; i < points.Length; ++i)
                    {
                        pathKinds[i]  = (i % 3 == 0) ? PointKind.Normal : PointKind.BezierControl;
                        pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                    }
                    SymPath path = new SymPath(pathPoints, pathKinds);
                    glyph.AddArea(color, new SymPathWithHoles(path, null));
                    break;
                }

                default:
                    Debug.Fail("Bad SymbolStroke kind");
                    break;
                }
            }
Пример #9
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     LineSymDef symdef = new LineSymDef("Uncrossable boundary", "707", symColor, 0.7F * scaleRatio * appearance.lineWidth, LineJoin.Bevel, LineCap.Flat);
     symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Line_OcadToolbox);
     map.AddSymdef(symdef);
     return symdef;
 }
Пример #10
0
        // Add the given course object to the map, creating a SymDef if needed. The passed dictionary
        // should have the same lifetime as the map and is used to store symdefs.
        public virtual void AddToMap(Map map, SymColor symColor, Dictionary<object, SymDef> dict)
        {
            object key = new Pair<short,object>(symColor.OcadId, SymDefKey());

            if (! dict.ContainsKey(key))
                dict[key] = CreateSymDef(map, symColor);

            AddToMap(map, dict[key]);
        }
Пример #11
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     throw new NotImplementedException("Must be overridden");
 }
Пример #12
0
 public override void AddToMap(Map map, SymColor symColor, Dictionary<object, SymDef> dict)
 {
     AddToMap(map, dict[CourseLayout.KeyWhiteOut]);
 }
Пример #13
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     return CreateLineSpecialSymDef(map, symColor, lineKind, lineWidth, gapSize, dashSize, LineJoin.Bevel, LineCap.Flat);
 }
Пример #14
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     AreaSymDef symdef = new AreaSymDef("Out-of-bounds area", "709", null, null);
     AreaSymDef.HatchInfo hatchInfo = new AreaSymDef.HatchInfo();
     hatchInfo.hatchColor = symColor;
     hatchInfo.hatchWidth = 0.25F * scaleRatio;
     hatchInfo.hatchSpacing = 0.6F * scaleRatio;
     hatchInfo.hatchAngle = 90;
     symdef.AddHatching(hatchInfo);
     symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.OOB_OcadToolbox);
     map.AddSymdef(symdef);
     return symdef;
 }
Пример #15
0
        // This is used by both line and rectangle specials.
        public static SymDef CreateLineSpecialSymDef(Map map, SymColor symColor, LineKind lineKind, float lineWidth, float gapSize, float dashSize, LineJoin lineJoin, LineCap lineCap)
        {
            string symbolId = map.GetFreeSymbolId(901);

            LineSymDef symdef;
            switch (lineKind) {
                case LineKind.Single:
                    symdef = new LineSymDef("Line", symbolId, symColor, lineWidth, lineJoin, lineCap);
                    break;

                case LineKind.Double:
                    LineSymDef.DoubleLineInfo doubleInfo = new LineSymDef.DoubleLineInfo();
                    doubleInfo.doubleLeftColor = doubleInfo.doubleRightColor = symColor;
                    doubleInfo.doubleThick = gapSize;
                    doubleInfo.doubleLeftWidth = doubleInfo.doubleRightWidth = lineWidth;
                    symdef = new LineSymDef("Line", symbolId, null, 0, lineJoin, lineCap);
                    symdef.SetDoubleLines(doubleInfo);
                    break;

                case LineKind.Dashed:
                    LineSymDef.DashInfo dashInfo = new LineSymDef.DashInfo();
                    dashInfo.dashLength = dashInfo.firstDashLength = dashInfo.lastDashLength = dashSize;
                    dashInfo.gapLength = gapSize;
                    symdef = new LineSymDef("Line", symbolId, symColor, lineWidth, lineJoin, lineCap);
                    symdef.SetDashInfo(dashInfo);
                    break;

                default: throw new ApplicationException("Unexpected line kind");
            }

            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.LineSpecial_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #16
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     LineSymDef symdef = new LineSymDef("Line", "704", symColor, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Bevel, LineCap.Flat);
     symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Line_OcadToolbox);
     map.AddSymdef(symdef);
     return symdef;
 }
Пример #17
0
        public override void AddToMap(Map map, SymColor symColor, Dictionary<object, SymDef> dict)
        {
            IList<TemplateInfo> currentTemplates = map.Templates;

            PointF center = Geometry.RectCenter(rect);
            float dpi = (25.4F * imageBitmap.Width) / rect.Width;
            TemplateInfo newTemplate = new TemplateInfo(imageName, center, dpi, 0, true, imageLoader);

            List<TemplateInfo> newTemplates = new List<TemplateInfo>(currentTemplates.Count + 1);
            newTemplates.Add(newTemplate);
            newTemplates.AddRange(currentTemplates);
            map.Templates = newTemplates;

            /* The following code creates the image as a ImageSymDef instead of a template. We use templates because
             * they are compatible with OCAD 8,9,10, while ImageSymDef only works for OCAD 11+.

            ImageSymDef layoutSymDef = (ImageSymDef) dict[CourseLayout.KeyLayout];

            PointF center = Geometry.RectCenter(rect);
            ImageBitmapSymbol symbol = new ImageBitmapSymbol(layoutSymDef, imageName, center, rect.Width / imageBitmap.Width, rect.Height / imageBitmap.Height, true, specialId.id, imageLoader);
            map.AddSymbol(symbol);
             */
        }
Пример #18
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();

            // Note: the line thickness of forbidden marks do NOT scale with the Line Thickness in the Course Appearance. This is by design,
            // otherwise it would look kind of weird. The scale with the control circle size instead to maintain the ratio.

            SymPath path = new SymPath(ScaleCoords((PointF[]) coords1.Clone()), kinds1);
            glyph.AddLine(symColor, path, 0.35F * scaleRatio * appearance.controlCircleSize, LineJoin.Miter, LineCap.Flat);

            path = new SymPath(ScaleCoords((PointF[]) coords2.Clone()), kinds2);
            glyph.AddLine(symColor, path, 0.35F * scaleRatio * appearance.controlCircleSize, LineJoin.Miter, LineCap.Flat);

            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Forbidden route", "710", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Forbidden_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #19
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     return LineSpecialCourseObj.CreateLineSpecialSymDef(map, symColor, lineKind, lineWidth, gapSize, dashSize, LineJoin.Miter, LineCap.Flat);
 }
Пример #20
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();

            SymPath path = new SymPath(ScaleCoords((PointF[]) coords1.Clone()), kinds1);
            glyph.AddLine(symColor, path, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Round, LineCap.Round);

            path = new SymPath(ScaleCoords((PointF[]) coords2.Clone()), kinds2);
            glyph.AddLine(symColor, path, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Round, LineCap.Round);

            path = new SymPath(ScaleCoords((PointF[]) coords3.Clone()), kinds3);
            glyph.AddLine(symColor, path, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Round, LineCap.Round);

            path = new SymPath(ScaleCoords((PointF[]) coords4.Clone()), kinds4);
            glyph.AddLine(symColor, path, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Round, LineCap.Round);

            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Refreshment point", "713", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Water_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #21
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();

            SymPath path = new SymPath(ScaleCoords((PointF[]) coords1.Clone()), kinds1);
            glyph.AddLine(symColor, path, lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Miter, LineCap.Flat);

            path = new SymPath(ScaleCoords((PointF[]) coords2.Clone()), kinds2);
            glyph.AddLine(symColor, path, lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Miter, LineCap.Flat);

            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Registration mark", "714", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Registration_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #22
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     Debug.Fail("should never be called");
     return null;
 }
Пример #23
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            PointKind[] kinds = { PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal };
            PointF[] pts = ScaleCoords((PointF[]) coords.Clone());
            SymPath path = new SymPath(pts, kinds);

            Glyph glyph = new Glyph();
            glyph.AddLine(symColor, path, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Miter, LineCap.Flat);
            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Start", "701", glyph, true);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Start_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #24
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            Glyph glyph = new Glyph();
            glyph.AddCircle(symColor, new PointF(0.0F, 0.0F), NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, diameter * scaleRatio * appearance.controlCircleSize);
            if (appearance.centerDotDiameter > 0.0F) {
                glyph.AddFilledCircle(symColor, new PointF(0.0F, 0.0F), appearance.centerDotDiameter * scaleRatio);
            }
            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Control point", "702", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Control_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #25
0
        public override void AddToMap(Map map, SymColor symColor, Dictionary<object, SymDef> dict)
        {
            object key = new Pair<short, object>(symColor.OcadId, SymDefKey());

            if (!dict.ContainsKey(key)) {
                SymColor whiteColor = ((AreaSymDef)dict[CourseLayout.KeyWhiteOut]).FillColor;
                dict[key] = CreateSymDef(map, symColor, whiteColor);
            }

            AddToMap(map, dict[key]);
        }
Пример #26
0
 // Create the SymDef for this symbol kind. Only called once for each "key"
 protected abstract SymDef CreateSymDef(Map map, SymColor symColor);
Пример #27
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     throw new NotImplementedException("Should not be called.");
 }
Пример #28
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);
        }
Пример #29
0
        // Create a point symbol that can be used to put this symbol onto a map inside
        // a box of the given size (in mm).
        public PointSymDef CreateSymdef(Map map, SymColor color, float boxSize)
        {
            Glyph glyph = new Glyph();
            for (int i = 0; i < strokes.Length; ++i)
                strokes[i].AddToMapGlyph(glyph, color, boxSize);
            glyph.ConstructionComplete();

            // Find a free OCAD ID number.
            string symbolId = map.GetFreeSymbolId(800);

            // Create the symdef
            PointSymDef symdef;
            symdef = new PointSymDef("Description: " + this.GetName(Util.CurrentLangName()), symbolId, glyph, false);

            // Create the toolbox image.
            Bitmap bm = new Bitmap(24, 24);
            using (Graphics g = Graphics.FromImage(bm)) {
                g.Clear(Color.White);
                g.SmoothingMode = SmoothingMode.AntiAlias;
                if (kind >= 'T') {
                    g.SetClip(new RectangleF(0, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(0, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                    g.SetClip(new RectangleF(bm.Width / 2, 0, bm.Width / 2, bm.Height));
                    Draw(g, Color.Black, new RectangleF(- bm.Width * 5F / 3F, bm.Height / 3F, bm.Width * 8F / 3F, bm.Height / 3F));
                }
                else {
                    Draw(g, Color.Black, new RectangleF(0, 0, bm.Width, bm.Height));
                }
            }
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(bm);

            // Add the symdef to the map.
            map.AddSymdef(symdef);

            return symdef;
        }
Пример #30
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            PointKind[] kinds = {
                PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal,
                PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal,
                PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal
            };
            PointF[] coords = ScaleCoords((PointF[]) outlineCoords.Clone());
            SymPath path = new SymPath(coords, kinds);

            Glyph glyph = new Glyph();
            glyph.AddArea(symColor, new SymPathWithHoles(path, null));
            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("First aid post", "712", glyph, false);
            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.FirstAid_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #31
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     throw new NotSupportedException("never needed, so intentionally unimplemented");
 }
Пример #32
0
 public MapRenderer(Map map, SymColor color, Dictionary<object, SymDef> dict)
 {
     this.map = map;
     this.color = color;
     this.dict = dict;
     currentTransform = new Matrix();
 }
Пример #33
0
 protected override SymDef CreateSymDef(Map map, SymColor symColor)
 {
     LineSymDef symdef = new LineSymDef("Line", "704", symColor, LineThickness * scaleRatio, LineJoin.Round, LineCap.Flat);
     symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Line_OcadToolbox);
     map.AddSymdef(symdef);
     return symdef;
 }
Пример #34
0
        protected virtual SymDef CreateSymDef(Map map, SymColor symColor, SymColor whiteColor)
        {
            // Find a free id.
            string symbolId = map.GetFreeSymbolId(OcadIdIntegerPart);

            TextSymDef symdef = new TextSymDef(SymDefName, symbolId, TextSymDef.PreferredSymbolKind.NormalText, null);
            symdef.SetFont(fontName, emHeight, Util.GetTextEffects(fontStyle), symColor, emHeight, 0, 0, 0, null, 0, 1F, TextSymDefHorizAlignment.Left, TextSymDefVertAlignment.TopAscent);
            if (outlineWidth > 0) {
                TextSymDef.Framing framing = new TextSymDef.Framing() {
                    framingColor = whiteColor,
                    framingStyle = TextSymDef.FramingStyle.Line,
                    lineStyle = LineStyle.Rounded,
                    lineWidth = outlineWidth
                };
                symdef.SetFraming(framing);
            }

            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.Number_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #35
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            LineSymDef symdef = new LineSymDef("Marked route", "705", symColor, NormalCourseAppearance.lineThickness * scaleRatio * appearance.lineWidth, LineJoin.Bevel, LineCap.Flat);

            LineSymDef.DashInfo dashes = new LineSymDef.DashInfo();
            dashes.dashLength = dashes.firstDashLength = dashes.lastDashLength = 2.0F * scaleRatio;
            dashes.gapLength = 0.5F * scaleRatio;
            dashes.minGaps = 1;
            symdef.SetDashInfo(dashes);

            symdef.ToolboxImage = MapUtil.CreateToolboxIcon(Properties.Resources.DashedLine_OcadToolbox);
            map.AddSymdef(symdef);
            return symdef;
        }
Пример #36
0
            // Add the stroke to an OCAD Map glyph with the given box size.
            public void AddToMapGlyph(Glyph glyph, SymColor color, float boxSize)
            {
                float scaleFactor = boxSize / 200.0F; // symbols are designed in box from -100 to 100.

                switch (kind) {
                case SymbolStrokes.Disc:
                    glyph.AddFilledCircle(color, new PointF(points[0].X * scaleFactor, points[0].Y * scaleFactor), radius * 2 * scaleFactor);
                    break;

                case SymbolStrokes.Circle:
                    glyph.AddCircle(color, new PointF(points[0].X * scaleFactor, points[0].Y * scaleFactor), thickness * scaleFactor, (radius * 2 + thickness) * scaleFactor);
                    break;

                case SymbolStrokes.Polyline: {
                        PointKind[] pathKinds = new PointKind[points.Length];
                        PointF[] pathPoints = new PointF[points.Length];
                        for (int i = 0; i < points.Length; ++i) {
                            pathKinds[i] = PointKind.Normal;
                            pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                        }
                        SymPath path = new SymPath(pathPoints, pathKinds);

                        glyph.AddLine(color, path, thickness * scaleFactor, corners, ends);
                        break;
                    }

                case SymbolStrokes.Polygon: {
                        PointKind[] pathKinds = new PointKind[points.Length + 1];
                        PointF[] pathPoints = new PointF[points.Length + 1];
                        for (int i = 0; i < points.Length; ++i) {
                            pathKinds[i] = PointKind.Normal;
                            pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                        }
                        pathKinds[points.Length] = pathKinds[0];
                        pathPoints[points.Length] = pathPoints[0];
                        SymPath path = new SymPath(pathPoints, pathKinds);

                        glyph.AddLine(color, path, thickness * scaleFactor, corners, corners == LineJoin.Round ? LineCap.Round : LineCap.Flat);
                        break;
                    }

                case SymbolStrokes.FilledPolygon: {
                        PointKind[] pathKinds = new PointKind[points.Length + 1];
                        PointF[] pathPoints = new PointF[points.Length + 1];
                        for (int i = 0; i < points.Length; ++i) {
                            pathKinds[i] = PointKind.Normal;
                            pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                        }
                        pathKinds[points.Length] = pathKinds[0];
                        pathPoints[points.Length] = pathPoints[0];
                        SymPath path = new SymPath(pathPoints, pathKinds);
                        glyph.AddArea(color, new SymPathWithHoles(path, null));
                        break;
                    }

                case SymbolStrokes.PolyBezier: {
                        PointKind[] pathKinds = new PointKind[points.Length];
                        PointF[] pathPoints = new PointF[points.Length];
                        for (int i = 0; i < points.Length; ++i) {
                            pathKinds[i] = (i % 3 == 0) ? PointKind.Normal : PointKind.BezierControl;
                            pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                        }
                        SymPath path = new SymPath(pathPoints, pathKinds);
                        glyph.AddLine(color, path, thickness * scaleFactor, corners, ends);
                        break;
                    }

                case SymbolStrokes.FilledPolyBezier: {
                        PointKind[] pathKinds = new PointKind[points.Length];
                        PointF[] pathPoints = new PointF[points.Length];
                        for (int i = 0; i < points.Length; ++i) {
                            pathKinds[i] = (i % 3 == 0) ? PointKind.Normal : PointKind.BezierControl;
                            pathPoints[i] = new PointF(points[i].X * scaleFactor, points[i].Y * scaleFactor);
                        }
                        SymPath path = new SymPath(pathPoints, pathKinds);
                        glyph.AddArea(color, new SymPathWithHoles(path, null));
                        break;
                    }

                default:
                    Debug.Fail("Bad SymbolStroke kind");
                    break;
                }
            }
Пример #37
0
        protected override SymDef CreateSymDef(Map map, SymColor symColor)
        {
            PointKind[] kinds = {
                PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal,
                PointKind.Normal, PointKind.Normal, PointKind.Normal, PointKind.Normal,
            };
            PointF[] coords = ScaleCoords((PointF[])outlineCoordsRight.Clone());
            SymPath pathRight = new SymPath(coords, kinds);
            coords = ScaleCoords((PointF[])outlineCoordsLeft.Clone());
            SymPath pathLeft = new SymPath(coords, kinds);

            Glyph glyph = new Glyph();
            glyph.AddArea(symColor, new SymPathWithHoles(pathLeft, null));
            glyph.AddArea(symColor, new SymPathWithHoles(pathRight, null));
            glyph.ConstructionComplete();

            PointSymDef symdef = new PointSymDef("Move control target", "781", glyph, false);
            map.AddSymdef(symdef);

            // should not be visible, we only use the highlight part in actual usages.
            // the map part is very useful for testing, though.
            map.SetSymdefVisible(symdef, false);
            return symdef;
        }