Beispiel #1
0
        public OurLine(LineKind kind, string blockName = "")
        {
            this.Declaration = blockName;
            this.Kind        = kind;

            // this.Info = new Info();
        }
        private void LineKindChanged()
        {
            LineKind lineKind = this.LineKind;

            switch (lineKind)
            {
            case PurplePen.LineKind.Single:
                labelGapSize.Visible  = labelGapSizeMm.Visible = upDownGapSize.Visible = false;
                labelDashSize.Visible = labelDashSizeMm.Visible = upDownDashSize.Visible = false;
                break;

            case PurplePen.LineKind.Double:
                labelGapSize.Visible    = labelGapSizeMm.Visible = upDownGapSize.Visible = true;
                labelDashSize.Visible   = labelDashSizeMm.Visible = upDownDashSize.Visible = false;
                upDownGapSize.Increment = 0.01M;
                break;

            case PurplePen.LineKind.Dashed:
                labelGapSize.Visible    = labelGapSizeMm.Visible = upDownGapSize.Visible = true;
                labelDashSize.Visible   = labelDashSizeMm.Visible = upDownDashSize.Visible = true;
                upDownGapSize.Value     = Math.Round(upDownGapSize.Value, 1);
                upDownGapSize.Increment = 0.1M;
                break;
            }

            UpdatePreview();
        }
Beispiel #3
0
 public LineStack(LineKind kind, uint money)
 {
     _kind      = kind;
     StackMoney = money;
     Multiple   = 3;
 }
        private void pictureBoxPreview_Paint(object sender, PaintEventArgs e)
        {
            // Get the graphics, size to 10 mm high.
            float    scale = 10.0F / pictureBoxPreview.ClientSize.Height;
            Graphics g     = e.Graphics;

            g.ScaleTransform(1 / scale, 1 / scale);
            g.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;

            // Get sizes and colors and so forth.
            float controlLineWidth        = NormalCourseAppearance.lineThickness * appearance.lineWidth;
            float controlCircleDiameter   = appearance.ControlCircleOutsideDiameter;        // outside diameter
            float controlDotDiameter      = appearance.centerDotDiameter;
            float controlCircleDrawRadius = (controlCircleDiameter - controlLineWidth) / 2; // radius to pen center

            SpecialColor lineSpecialColor = this.Color;
            Color        lineColor;

            if (lineSpecialColor.Kind == SpecialColor.ColorKind.Black)
            {
                lineColor = System.Drawing.Color.Black;
            }
            else if (lineSpecialColor.Kind == SpecialColor.ColorKind.Purple)
            {
                lineColor = purpleColor;
            }
            else
            {
                lineColor = SwopColorConverter.CmykToRgbColor(lineSpecialColor.CustomColor);
            }

            using (Brush purpleBrush = new SolidBrush(purpleColor))
                using (Pen purplePen = new Pen(purpleColor, controlLineWidth))
                    using (Pen linePen = new Pen(lineColor, this.LineWidth))
                    {
                        // Create the pen to be correct for the style and so forth.
                        LineKind lineKind = this.LineKind;
                        linePen.StartCap = linePen.EndCap = System.Drawing.Drawing2D.LineCap.Flat;
                        if (lineKind == PurplePen.LineKind.Double)
                        {
                            linePen.Width = this.LineWidth * 2 + this.GapSize;
                            float widthFract = this.LineWidth / linePen.Width;
                            float gapFract   = this.GapSize / linePen.Width;
                            linePen.CompoundArray = new float[4] {
                                0, widthFract, widthFract + gapFract, 1
                            };
                        }
                        else if (lineKind == PurplePen.LineKind.Dashed && this.DashSize > 0 && this.GapSize > 0)
                        {
                            linePen.DashCap     = System.Drawing.Drawing2D.DashCap.Flat;
                            linePen.DashOffset  = 0;
                            linePen.DashPattern = new float[2] {
                                this.DashSize / this.LineWidth, this.GapSize / this.LineWidth
                            };
                        }

                        // Draw control circle
                        PointF centerCircle = new PointF(5, 5);
                        g.DrawEllipse(purplePen, RectangleF.FromLTRB(centerCircle.X - controlCircleDrawRadius, centerCircle.Y - controlCircleDrawRadius, centerCircle.X + controlCircleDrawRadius, centerCircle.Y + controlCircleDrawRadius));

                        // Draw center dot.
                        if (controlDotDiameter > 0.0F)
                        {
                            g.FillEllipse(purpleBrush, RectangleF.FromLTRB(centerCircle.X - controlDotDiameter / 2, centerCircle.Y - controlDotDiameter / 2, centerCircle.X + controlDotDiameter / 2, centerCircle.Y + controlDotDiameter / 2));
                        }

                        // Draw legs
                        double angle = (Math.PI * 1.4);
                        g.DrawLine(purplePen, (float)(centerCircle.X + Math.Cos(angle) * 15), (float)(centerCircle.Y + Math.Sin(angle) * 15),
                                   (float)(centerCircle.X + Math.Cos(angle) * controlCircleDrawRadius), (float)(centerCircle.Y + Math.Sin(angle) * controlCircleDrawRadius));
                        angle = (Math.PI * 0.8);
                        g.DrawLine(purplePen, (float)(centerCircle.X + Math.Cos(angle) * 15), (float)(centerCircle.Y + Math.Sin(angle) * 15),
                                   (float)(centerCircle.X + Math.Cos(angle) * controlCircleDrawRadius), (float)(centerCircle.Y + Math.Sin(angle) * controlCircleDrawRadius));

                        // Draw line
                        PointF lineStart = new PointF(12, -5), lineCorner = new PointF(12, 5), lineEnd = new PointF(100, 5);
                        using (GraphicsPath path = new GraphicsPath()) {
                            if (!this.showRadius)
                            {
                                // Line, not rectangle. Just show line.
                                path.AddLine(lineCorner, lineEnd);
                            }
                            else if (this.CornerRadius > 0)
                            {
                                const float kappa = 0.5522847498F; // constant used to create near-circle with a bezier.

                                PointF roundStart = new PointF(lineCorner.X, lineCorner.Y - CornerRadius);
                                PointF roundEnd   = new PointF(lineCorner.X + CornerRadius, lineCorner.Y);
                                PointF control1   = new PointF(lineCorner.X, lineCorner.Y - (1 - kappa) * CornerRadius);
                                PointF control2   = new PointF(lineCorner.X + (1 - kappa) * CornerRadius, lineCorner.Y);
                                path.AddLine(lineStart, roundStart);
                                path.AddBezier(roundStart, control1, control2, roundEnd);
                                path.AddLine(roundEnd, lineEnd);
                            }
                            else
                            {
                                // No corner radius.
                                path.AddLine(lineStart, lineCorner);
                                path.AddLine(lineCorner, lineEnd);
                            }
                            try {
                                g.DrawPath(linePen, path);
                            }
                            catch (Exception) {
                                // Do nothing. Very occasionally, GDI+ given an overflow exception or ExternalException or OutOfMemory exception.
                                // Just ignore it; there's nothing else to do. See bug #1997301.
                            }
                        }
                    }
        }
Beispiel #5
0
        public static OurLine NewLine(LineKind kind, string blockName)
        {
            var l = new OurLine(kind, blockName);

            return(l);
        }
Beispiel #6
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;
        }
Beispiel #7
0
 public RectSpecialCourseObj(Id<Special> specialId, CourseAppearance appearance, SpecialColor color, LineKind lineKind, float lineWidth, float cornerRadius, float gapSize, float dashSize, RectangleF rect)
     : base(Id<ControlPoint>.None, Id<CourseControl>.None, specialId, 1.0F, appearance, rect)
 {
     this.color = color;
     this.lineKind = lineKind;
     this.lineWidth = lineWidth;
     this.cornerRadius = cornerRadius;
     this.gapSize = gapSize;
     this.dashSize = dashSize;
 }
Beispiel #8
0
 public static Id<Special> AddRectangleSpecial(EventDB eventDB, RectangleF rect, SpecialColor color, LineKind lineKind, float lineWidth, float gapSize, float dashSize, float cornerRadius)
 {
     Special special = new Special(SpecialKind.Rectangle, new PointF[] { rect.Location, new PointF(rect.Right, rect.Bottom)});
     special.color = color;
     special.lineKind = lineKind;
     special.lineWidth = lineWidth;
     special.gapSize = gapSize;
     special.dashSize = dashSize;
     special.cornerRadius = cornerRadius;
     return eventDB.AddSpecial(special);
 }
Beispiel #9
0
 public LineSpecialCourseObj(Id<Special> specialId, CourseAppearance appearance, SpecialColor color, LineKind lineKind, float lineWidth, float gapSize, float dashSize, SymPath path)
     : base(Id<ControlPoint>.None, Id<CourseControl>.None, Id<CourseControl>.None, specialId, 1.0F, appearance, 
            (lineKind == LineKind.Double) ? (lineWidth * 2 + gapSize) : lineWidth, path, null)
 {
     this.color = color;
     this.lineKind = lineKind;
     this.lineWidth = lineWidth;
     this.gapSize = gapSize;
     this.dashSize = dashSize;
 }
Beispiel #10
0
 public static Id<Special> AddLineSpecial(EventDB eventDB, PointF[] locations, SpecialColor color, LineKind lineKind, float lineWidth, float gapSize, float dashSize)
 {
     Special special = new Special(SpecialKind.Line, locations);
     special.color = color;
     special.lineKind = lineKind;
     special.lineWidth = lineWidth;
     special.gapSize = gapSize;
     special.dashSize = dashSize;
     return eventDB.AddSpecial(special);
 }
Beispiel #11
0
        // Change the line properties associated with a special
        internal static void ChangeSpecialLineAppearance(EventDB eventDB, Id<Special> specialId, SpecialColor color, LineKind lineKind, float lineWidth, float gapSize, float dashSize, float cornerRadius)
        {
            Special special = eventDB.GetSpecial(specialId);

            Debug.Assert(special.kind == SpecialKind.Rectangle || special.kind == SpecialKind.Line);

            special = (Special)special.Clone();
            special.color = color;
            special.lineKind = lineKind;
            special.lineWidth = lineWidth;
            special.gapSize = gapSize;
            special.dashSize = dashSize;
            if (special.kind == SpecialKind.Rectangle)
                special.cornerRadius = cornerRadius;

            eventDB.ReplaceSpecial(specialId, special);
        }
Beispiel #12
0
 public CreateLine(int @from, int to, LineKind kind)
 {
     this.@from = @from;
     this.to    = to;
     this.kind  = kind;
 }
Beispiel #13
0
        public override void ReadAttributesAndContent(XmlInput xmlinput)
        {
            string kindText = xmlinput.GetAttributeString("kind");
            switch (kindText) {
            case "first-aid": kind = SpecialKind.FirstAid; break;
            case "water": kind = SpecialKind.Water; break;
            case "optional-crossing-point": kind = SpecialKind.OptCrossing; break;
            case "forbidden-route": kind = SpecialKind.Forbidden; break;
            case "registration-mark": kind = SpecialKind.RegMark; break;
            case "boundary": kind = SpecialKind.Boundary; break;
            case "out-of-bounds": kind = SpecialKind.OOB; break;
            case "dangerous-area": kind = SpecialKind.Dangerous; break;
            case "white-out": kind = SpecialKind.WhiteOut; break;
            case "text": kind = SpecialKind.Text; break;
            case "descriptions": kind = SpecialKind.Descriptions; break;
            case "image": kind = SpecialKind.Image; break;
            case "line": kind = SpecialKind.Line; break;
            case "rectangle": kind = SpecialKind.Rectangle; break;
              
            default: xmlinput.BadXml("Invalid special-object kind '{0}'", kindText); break;
            }

            if (kind == SpecialKind.OptCrossing)
                orientation = xmlinput.GetAttributeFloat("orientation");

            text = null;
            locations = null;
            allCourses = true;
            courses = null;
            imageBitmap = null;
            List<PointF> locationList = new List<PointF>();

            if (kind == SpecialKind.Text || kind == SpecialKind.Line || kind == SpecialKind.Rectangle)
                color = SpecialColor.Purple;  // default color is purple.

            bool first = true;
            while (xmlinput.FindSubElement(first, "text", "font", "location", "appearance", "courses", "image-data")) {
                switch (xmlinput.Name) {
                case "text":
                    text = xmlinput.GetContentString();
                    break;

                case "image-data":
                    // We ignore the format, since Image.FromStream auto-detects.
                    MemoryStream stm = xmlinput.GetContentBase64();
                    try {
                        imageBitmap = (Bitmap) Image.FromStream(stm);
                    }
                    catch (ArgumentException) {
                        xmlinput.BadXml("Image data could not be loaded");
                    }
                    break;

                case "font":
                    fontName = xmlinput.GetAttributeString("name");
                    fontBold = xmlinput.GetAttributeBool("bold");
                    fontItalic = xmlinput.GetAttributeBool("italic");
                    xmlinput.Skip();
                    break;

                case "location":
                    float x = xmlinput.GetAttributeFloat("x");
                    float y = xmlinput.GetAttributeFloat("y");
                    locationList.Add(new PointF(x, y));
                    xmlinput.Skip();
                    break;

                case "appearance":
                    numColumns = xmlinput.GetAttributeInt("columns", 1);

                    if (kind == SpecialKind.Text || kind == SpecialKind.Line || kind == SpecialKind.Rectangle) {
                        color = xmlinput.GetAttributeColor("color", SpecialColor.Purple);
                    }

                    string lineKindValue = xmlinput.GetAttributeString("line-kind", "");
                    switch (lineKindValue) {
                        case "single": lineKind = LineKind.Single; break;
                        case "double": lineKind = LineKind.Double; break;
                        case "dashed": lineKind = LineKind.Dashed; break;
                    }

                    lineWidth = xmlinput.GetAttributeFloat("line-width", 0);
                    gapSize = xmlinput.GetAttributeFloat("gap-size", 0);
                    dashSize = xmlinput.GetAttributeFloat("dash-size", 0);
                    if (kind == SpecialKind.Rectangle)
                        cornerRadius = xmlinput.GetAttributeFloat("corner-radius", 0);

                    xmlinput.Skip();
                    break;

                case "courses":
                    allCourses = xmlinput.GetAttributeBool("all", false);
                    if (!allCourses) {
                        List<CourseDesignator> courseIdList = new List<CourseDesignator>();
                        xmlinput.MoveToContent();

                        bool firstCourse = true;
                        while (xmlinput.FindSubElement(firstCourse, "course")) {
                            int id = xmlinput.GetAttributeInt("course");
                            int part = xmlinput.GetAttributeInt("part", -1);
                            if (part >= 0)
                                courseIdList.Add(new CourseDesignator(new Id<Course>(id), part));
                            else
                                courseIdList.Add(new CourseDesignator(new Id<Course>(id)));
                            xmlinput.Skip();
                            firstCourse = false;
                        }

                        courses = courseIdList.ToArray();
                    }
                    else {
                        xmlinput.Skip();
                    }
                    break;
                }

                first = false;
            }

            if (locationList.Count == 0)
                xmlinput.BadXml("missing 'location' element");
            if ((kind == SpecialKind.Text) && fontName == null)
                xmlinput.BadXml("missing 'font' element");
            if ((kind == SpecialKind.Image) && imageBitmap == null)
                xmlinput.BadXml("Missing 'image-data' element");
            locations = locationList.ToArray();
        }
Beispiel #14
0
        void Parse()
        {
            string[] Lines;
            string   Line;
            string   L; // trimmed line

            DocLet   DocLet = null;
            Block    Block  = null;
            LineKind Kind   = LineKind.None;
            string   S;
            string   TagName = string.Empty;



            foreach (string FilePath in FilePaths)
            {
                Lines = File.ReadAllLines(FilePath);

                for (int i = 0; i < Lines.Length; i++)
                {
                    Line = Lines[i];

                    if (DocLet == null && Line.Trim().Length == 0 && (Block == null))
                    {
                        continue;
                    }


                    L = Line.Trim(' ', '\n', '\r', '\t');


                    // line kind detection
                    // ------------------------------------------------------------------------
                    Kind    = LineKind.None;
                    TagName = string.Empty;

                    if (DocLet == null && L.StartsWith("/**"))
                    {
                        Kind |= LineKind.First;
                        L     = L.Remove(0, 3).TrimStart();
                        Line  = L;

                        DocLet = new DocLet(FilePath, i, Lines);
                    }


                    if (DocLet != null)
                    {
                        if (L.EndsWith("*/"))
                        {
                            Kind |= LineKind.Last;
                            L     = L.Remove(L.Length - 2, 2);
                            L     = L.TrimEnd();

                            Line = Line.TrimEnd();
                            Line = Line.Remove(Line.Length - 2, 2);
                        }

                        if (L.TrimStart(' ', '*').StartsWith("@"))
                        {
                            L = L.TrimStart(' ', '*');
                            S = Tags.FindBlockTag(L);

                            if (S != string.Empty)
                            {
                                Kind   |= LineKind.Block;
                                TagName = S;

                                L    = L.Remove(0, TagName.Length).TrimStart();
                                Line = L;

                                Block = new Block(TagName, L);
                                DocLet.Blocks.Add(Block);
                                L = "";

                                if (!Block.IsMultiLine)
                                {
                                    Block = null;
                                }

                                if (!Sys.In(LineKind.Last, Kind))
                                {
                                    continue;
                                }
                            }
                        }

                        if (!string.IsNullOrWhiteSpace(L))
                        {
                            if (Block == null)
                            {
                                Kind   |= LineKind.Block;
                                TagName = Tags.Description;

                                Block = new Block(TagName, L);
                                DocLet.Blocks.Add(Block);
                            }
                            else if (Block.IsMultiLine)
                            {
                                Kind |= LineKind.Line;
                                Block.Lines.Add(Line);
                            }
                        }
                        else if (Block != null && !Sys.In(LineKind.Last, Kind))
                        {
                            Block.Lines.Add(Line);
                        }


                        // doclet or block creation and line addition
                        // ------------------------------------------------------------------------

                        if (Sys.In(LineKind.Last, Kind))
                        {
                            DocLet.LastLineIndex = i;
                            if (DocLet.Blocks.Count > 0)
                            {
                                ParseDocLet(DocLet);
                            }

                            DocLet = null;
                            Block  = null;
                        }
                    }
                }
            }
        }