private void InsertStyledElements(SvgGroupElement linesGroup, IEnumerable <SvgStyledTransformedElement> styledElements)
        {
            SvgGroupElement minorGroup = new SvgGroupElement("MinorLines");

            minorGroup.Style = s_MinorLineStyle;
            linesGroup.AddChild(minorGroup);

            SvgGroupElement normalGroup = new SvgGroupElement("NormalLines");

            normalGroup.Style = s_NormalLineStyle;
            linesGroup.AddChild(normalGroup);

            SvgGroupElement majorGroup = new SvgGroupElement("MajorLines");

            majorGroup.Style = s_MajorLineStyle;
            linesGroup.AddChild(majorGroup);

            int i = -1;

            foreach (SvgStyledTransformedElement styledElement in styledElements)
            {
                i++;
                if (i % 10 == 0)
                {
                    majorGroup.AddChild(styledElement);
                    continue;
                }
                if (i % 2 == 0)
                {
                    normalGroup.AddChild(styledElement);
                    continue;
                }
                minorGroup.AddChild(styledElement);
            }
        }
        public void AddAlignmentLines()
        {
            SvgGroupElement alinmentLinesGroup = new SvgGroupElement("AlignmentLines");

            alinmentLinesGroup.Style = s_AlignmentLineStyle;

            SvgLineElement line1 = new SvgLineElement(
                GetSvgLength(this.Origin.X), GetSvgLength(0),
                GetSvgLength(this.Origin.X), GetSvgLength(this.Page.Width));

            alinmentLinesGroup.AddChild(line1);

            SvgLineElement line2 = new SvgLineElement(
                GetSvgLength(0), GetSvgLength(this.Origin.Y),
                GetSvgLength(this.Page.Width), GetSvgLength(this.Origin.Y));

            alinmentLinesGroup.AddChild(line2);

            float             radius       = 65;
            SvgEllipseElement cutOutCircle = new SvgEllipseElement(
                GetSvgLength(this.Origin.X), GetSvgLength(this.Origin.Y),
                GetSvgLength(radius), GetSvgLength(radius));

            alinmentLinesGroup.AddChild(cutOutCircle);

            this.Root.AddChild(alinmentLinesGroup);
        }
Ejemplo n.º 3
0
        internal void Build(Wheel wheel, SvgSvgElement root)
        {
            SvgGroupElement helperLinesGroup = new SvgGroupElement("HelperLines");

            helperLinesGroup.Style = Styles.HelperLineStyle;
            root.AddChild(helperLinesGroup);

            // Wheel pitch circle
            helperLinesGroup.AddChild(SvgHelper.CreateCircle(wheel.Center, wheel.PitchDiameter / 2.0));

            // Wheel addendum circle
            helperLinesGroup.AddChild(SvgHelper.CreateCircle(wheel.Center, wheel.PitchDiameter / 2.0 + wheel.Addendum));

            // Wheel dedendum circle
            helperLinesGroup.AddChild(SvgHelper.CreateCircle(wheel.Center, wheel.PitchDiameter / 2.0 - wheel.Dedendum));

            // wheel center
            double halfCrossLength = 10;

            helperLinesGroup.AddChild(new SvgLineElement(wheel.Center.X - halfCrossLength, wheel.Center.Y, wheel.Center.X + halfCrossLength, wheel.Center.Y));
            helperLinesGroup.AddChild(new SvgLineElement(wheel.Center.X, wheel.Center.Y - halfCrossLength, wheel.Center.X, wheel.Center.Y + halfCrossLength));


            SvgGroupElement mainGroup = new SvgGroupElement("Main");

            mainGroup.Style = Styles.MinorLineStyle;
            root.AddChild(mainGroup);


            WheelTooth[]  teeth       = wheel.GetTeeth(0);
            StringBuilder pathBuilder = new StringBuilder();

            pathBuilder.AppendFormat(CultureInfo.InvariantCulture, "M{0},{1}", (float)teeth[0].DedendumIntersectLeft.X, (float)teeth[0].DedendumIntersectLeft.Y);
            for (int i = 0; i < teeth.Length; i++)
            {
                WheelTooth tooth     = teeth[i];
                WheelTooth nextTooth = teeth[(i + 1) % teeth.Length];
                InsertWheelToothPath(wheel, tooth, nextTooth, pathBuilder);
            }
            pathBuilder.Append(" z");

            SvgPath        svgPath        = new SvgPath(pathBuilder.ToString());
            SvgPathElement svgPathElement = new SvgPathElement();

            svgPathElement.D = svgPath;

            mainGroup.AddChild(svgPathElement);

            if (wheel.CenterHoleDiameter > 0)
            {
                mainGroup.AddChild(SvgHelper.CreateCircle(wheel.Center, wheel.CenterHoleDiameter / 2.0));
            }
        }
Ejemplo n.º 4
0
        private void AddGuideLines(SvgGroupElement group, float radius)
        {
            SvgLineElement verticalLineElement = new SvgLineElement(
                0, radius,
                0, -radius);

            group.AddChild(verticalLineElement);

            SvgLineElement horizontalLineElement = new SvgLineElement(
                -radius, 0,
                radius, 0);

            group.AddChild(horizontalLineElement);
        }
        private void AddCenteredCircle(SvgGroupElement group, float radius)
        {
            SvgEllipseElement circleElement = new SvgEllipseElement(
                0, 0,
                radius, radius);

            group.AddChild(circleElement);
        }
        private void AddRays(SvgGroupElement group, float radius)
        {
            double[] angles = { 90, 150, 210, 270, 330, 30 };             //, 120, 180, 240, 300 };

            foreach (double angle in angles)
            {
                SvgLineElement rayElement = new SvgLineElement(
                    0, 0,
                    radius * (float)Math.Cos(angle * Math.PI / 180), radius * (float)Math.Sin(angle * Math.PI / 180));
                group.AddChild(rayElement);
            }
        }
        private void AddCenteredTriangle(SvgGroupElement group, float sideLength, float radius)
        {
            float middleLineLength = sideLength * (float)Math.Cos(30 / 180.0 * Math.PI);
            float centerToBase     = middleLineLength - radius;

            SvgLineElement sideLineElement1 = new SvgLineElement(
                -sideLength / 2f, -centerToBase,
                sideLength / 2f, -centerToBase);

            group.AddChild(sideLineElement1);

            SvgLineElement sideLineElement2 = new SvgLineElement(
                sideLength / 2f, -centerToBase,
                0, middleLineLength - centerToBase);

            group.AddChild(sideLineElement2);

            SvgLineElement sideLineElement3 = new SvgLineElement(
                0, middleLineLength - centerToBase,
                -sideLength / 2f, -centerToBase);

            group.AddChild(sideLineElement3);
        }
Ejemplo n.º 8
0
        private void AddSlice(SvgGroupElement group, double radius, double angle, double angularWidth)
        {
            PointF firstPointOnCircle  = GetPointOnCircle(radius, angle - angularWidth / 2.0);
            PointF secondPointOnCircle = GetPointOnCircle(radius, angle + angularWidth / 2.0);

            // for an explanation of the arc syntax see: http://www.codestore.net/store.nsf/unid/EPSD-5DTT4L
            string path = String.Format(
                CultureInfo.InvariantCulture,
                "M0,0 L{0},{1} A{2},{2} 0 0,1 {3},{4} z",
                firstPointOnCircle.X, firstPointOnCircle.Y, (float)radius, secondPointOnCircle.X, secondPointOnCircle.Y);

            SvgPath        svgPath        = new SvgPath(path);
            SvgPathElement svgPathElement = new SvgPathElement();

            svgPathElement.D = svgPath;
            group.AddChild(svgPathElement);
        }
Ejemplo n.º 9
0
        private void InsertSquare(SvgGroupElement group, int xIndex, int yIndex)
        {
            bool isBlack = ((xIndex + yIndex) % 2 == 0);

            if (!isBlack)
            {
                // nothing to draw in case of a white square
                return;
            }

            float x = m_UpperLeft.X + xIndex * m_SquareLength;
            float y = m_UpperLeft.Y + yIndex * m_SquareLength;

            SvgRectElement rectangle = new SvgRectElement(
                x, y,
                m_SquareLength, m_SquareLength
                );

            rectangle.Style = s_FilledBlack;

            group.AddChild(rectangle);
        }
        public void AddSquares(float yOffset, float xOffset, float sideLength, int xCount, int yCount)
        {
            SvgGroupElement squaresGroup = new SvgGroupElement("Squares");

            squaresGroup.Style = s_NormalLineStyle;

            float xStart = this.Origin.X + xOffset - xCount / 2.0F * sideLength;
            float yStart = this.Origin.Y + yOffset;

            for (int i = 0; i < xCount; i++)
            {
                for (int j = 0; j < yCount; j++)
                {
                    SvgRectElement rectElement = new SvgRectElement(
                        GetSvgLength(xStart + i * sideLength), GetSvgLength(yStart + j * sideLength),
                        GetSvgLength(sideLength), GetSvgLength(sideLength));

                    squaresGroup.AddChild(rectElement);
                }
            }

            this.Root.AddChild(squaresGroup);
        }
Ejemplo n.º 11
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            var root = new SvgSvgElement("4in", "4in", "-10,-10 250,250");

            //adding multiple children

            root.AddChildren(
                new SvgRectElement(5, 5, 5, 5),
                new SvgEllipseElement(20, 20, 8, 12)
            {
                Style = "fill:yellow;stroke:red"
            },

                new SvgAElement("https://github.com/managed-commons/SvgNet").AddChildren(
                    new SvgTextElement("Textastic!", 30, 20)
            {
                Style = "fill:midnightblue;stroke:navy;stroke-width:1px;font-size:30px;font-family:Calibri"
            })
                );

            //group and path

            var grp = new SvgGroupElement("green_group")
            {
                Style = "fill:green;stroke:black;"
            };

            grp.AddChild(new SvgRectElement(30, 30, 5, 20));

            var ell = new SvgEllipseElement
            {
                CX = 50,
                CY = 50,
                RX = 10,
                RY = 20
            };

            var pathy = new SvgPathElement
            {
                D     = "M 20,80 C 20,90 30,80 70,100 C 70,100 40,60 50,60 z",
                Style = ell.Style
            };

            root.AddChild(grp);

            //cloning and style arithmetic

            grp.AddChildren(ell, pathy);

            grp.Style.Set("fill", "blue");

            var grp2 = (SvgGroupElement)SvgFactory.CloneElement(grp);

            grp2.Id = "cloned_red_group";

            grp2.Style.Set("fill", "red");

            grp2.Style += "opacity:0.5";

            grp2.Transform = "scale (1.2, 1.2)  translate(10)";

            root.AddChild(grp2);

            //output

            string s = root.WriteSVGString(true);

            tbOut.Text = s;

            string tempFile = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "foo.svg");

            using (var tw = new StreamWriter(tempFile, false))
                tw.Write(s);

            svgOut.Navigate(new Uri(tempFile));
            svgOut.Refresh(WebBrowserRefreshOption.Completely);
        }