public string BuildSvg(Page page)
		{
			//this.Page = page;
			//this.Origin = new PointF(page.Width / 2, page.Height / 2);

			this.Root = new SvgSvgElement(
				page.SvgLengthWidth, page.SvgLengthHeight,
				new SvgNumList(new float[] { -page.Width / 2, -page.Height / 2, page.Width, page.Height }));

			SvgGroupElement mainGroup = new SvgGroupElement("Main");
			mainGroup.Style = s_MajorLineStyle;
			this.Root.AddChild(mainGroup);

			float outerRadius = 40f;

			AddCenteredCircle(mainGroup, outerRadius);
			AddCenteredCircle(mainGroup, 24.7f);
			AddCenteredCircle(mainGroup, 7.5f);
			AddGuideLines(mainGroup, outerRadius);

			float sideLength = 59f;
			float radius = sideLength / 2f / (float)Math.Cos(30.0 / 180.0 * Math.PI);
			AddCenteredTriangle(mainGroup, sideLength, radius);
			AddCenteredCircle(mainGroup, radius);

			AddRays(mainGroup, outerRadius);

			return this.Root.WriteSVGString(true, false);
		}
		private void AddCenteredCircle(SvgGroupElement group, float radius)
		{
			SvgEllipseElement circleElement = new SvgEllipseElement(
				0, 0,
				radius, radius);

			group.AddChild(circleElement);
		}
Esempio n. 3
0
		public void InsertSvg(SvgSvgElement root, int index)
		{
			SvgGroupElement slicesGroup = new SvgGroupElement("Slices" + index.ToString());
			slicesGroup.Style = s_FilledWhite;
			root.AddChild(slicesGroup);

			InsertSlices(slicesGroup);
			// Add inner black disk
			root.AddChild(EncoderDisk.CreateCenteredCircle(this.OuterRadius - this.SlotLength, s_FilledBlack));
		}
Esempio n. 4
0
		private void InsertSlices(SvgGroupElement group)
		{
			double angularWidth = 360.0 / this.SlotCount / 2;
			double angleOffset = angularWidth * this.PhaseAngle / 360.0;

			for (int i = 0; i < this.SlotCount; i++)
			{
				double angle = 360.0 * i / this.SlotCount + angleOffset;
				AddSlice(group, this.OuterRadius, angle, angularWidth);
			}
		}
		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);
		}
Esempio n. 6
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);
		}
Esempio n. 7
0
        internal void Build(Pinion pinion, SvgSvgElement root)
        {
            SvgGroupElement helperLinesGroup = new SvgGroupElement("HelperLines");
            helperLinesGroup.Style = Styles.HelperLineStyle;
            root.AddChild(helperLinesGroup);

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

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

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

            // wheel center
            double halfCrossLength = 10;
            helperLinesGroup.AddChild(new SvgLineElement(pinion.Center.X - halfCrossLength, pinion.Center.Y, pinion.Center.X + halfCrossLength, pinion.Center.Y));
            helperLinesGroup.AddChild(new SvgLineElement(pinion.Center.X, pinion.Center.Y - halfCrossLength, pinion.Center.X, pinion.Center.Y + halfCrossLength));

            SvgGroupElement mainGroup = new SvgGroupElement("Main");
            mainGroup.Style = Styles.MinorLineStyle;
            root.AddChild(mainGroup);

            PinionTooth[] teeth = pinion.GetTeeth(Math.PI / pinion.ToothCount);
            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++)
            {
                PinionTooth tooth = teeth[i];
                PinionTooth nextTooth = teeth[(i + 1) % teeth.Length];
                InsertToothPath(pinion, tooth, nextTooth, pathBuilder);
            }
            pathBuilder.Append(" z");

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

            mainGroup.AddChild(svgPathElement);

            if (pinion.CenterHoleDiameter > 0)
            {
                mainGroup.AddChild(SvgHelper.CreateCircle(pinion.Center, pinion.CenterHoleDiameter / 2.0));
            }
        }
		private string BuildSvg()
		{
			m_Root = new SvgSvgElement(
				m_Page.SvgLengthWidth, m_Page.SvgLengthHeight,
				new SvgNumList(new float[] { -m_Page.Width / 2, -m_Page.Height / 2, m_Page.Width, m_Page.Height }));

			SvgGroupElement mainGroup = new SvgGroupElement("Main");

			for (int xIndex = 0; xIndex < m_XCount; xIndex++)
			{
				for (int yIndex = 0; yIndex < m_YCount; yIndex++)
				{
					InsertSquare(mainGroup, xIndex, yIndex);
				}
			}

			m_Root.AddChild(mainGroup);
			return m_Root.WriteSVGString(true, false);
		}
		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);
		}
Esempio n. 10
0
		public string BuildSvg(Page page)
		{
			SvgSvgElement root = new SvgSvgElement(
				page.SvgLengthWidth, page.SvgLengthHeight,
				new SvgNumList(new float[] { -page.Width / 2, -page.Height / 2, page.Width, page.Height }));

			root.AddChild(CreateCenteredCircle(this.OuterRadius, s_FilledBlack));

			// Add encoder rings
			AddEncoderRing(root, this.OuterEncoderRing, 1);
			AddEncoderRing(root, this.InnerEncoderRing, 2);

			root.AddChild(CreateCenteredCircle(this.CenterHoleRadius, s_FilledWhite));

			SvgGroupElement crossLinesGroup = new SvgGroupElement("CrossLines");
			crossLinesGroup.Style = s_NormalLineStyle;
			root.AddChild(crossLinesGroup);
			AddGuideLines(crossLinesGroup, (float)this.CenterHoleRadius);

			return root.WriteSVGString(true, false);
		}
		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);
		}
		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);
		}
		public void AddHorizontalLines(float distance)
		{
			SvgGroupElement horizontalLinesGroup = new SvgGroupElement("HorizontalLines");
			InsertStyledElements(horizontalLinesGroup, GetHorizontalLines(distance));
			this.Root.AddChild(horizontalLinesGroup);
		}
		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);
		}
Esempio n. 15
0
 /// <summary>
 /// Implemented, but returns null as SVG has a proper scenegraph, unlike GDI+.  The effect of calling <c>BeginContainer</c> is to create a new SVG group
 /// and apply transformations etc to produce the effect that a GDI+ container would produce.
 /// </summary>
 public GraphicsContainer BeginContainer()
 {
     var gr = new SvgGroupElement();
     cur.AddChild(gr);
     cur = gr;
     cur.Id += "_BeginContainer";
     transforms.Push();
     return null;
 }
Esempio n. 16
0
        ///<summary>
        /// Constructs a new <c>SVGGraphics</c> object.
        ///</summary>
        public SvgGraphics(int width, int height)
        {
            root = new SvgSvgElement(width, height);

            //bg = new SvgRectElement(0, 0, "100%", "100%");
            //bg.Style.Set("fill", new SvgColor(Color.FromName("Control")));
            //bg.Id = "background";
            //root.AddChild(bg);

            topgroup = new SvgGroupElement();
            topgroup.Style.Set("shape-rendering", "crispEdges");
            cur = topgroup;
            root.AddChild(topgroup);

            defs = new SvgDefsElement();
            root.AddChild(defs);

            transforms = new MatrixStack();
        }
Esempio n. 17
0
        private void DrawBitmapData(Bitmap b, float x, float y, float w, float h, bool scale)
        {
            SvgGroupElement g = new SvgGroupElement("bitmap_at_" + x.ToString() + "_" + y.ToString());

            float scalex=1, scaley=1;

            if (scale)
            {
                scalex = w/b.Width;
                scaley = h/b.Height;
            }

            for(int line = 0; line < b.Height; ++line)
            {
                for (int col = 0; col < b.Width; ++ col)
                {
                    //This is SO slow, but better than making the whole library 'unsafe'
                    Color c = b.GetPixel(col, line);

                    if (!scale)
                    {
                        if (col <= w && line <= h)
                            DrawImagePixel(g, c, x + col, y + line, 1, 1);
                    }
                    else
                    {
                        DrawImagePixel(g, c, x + (col*scalex), y + (line*scaley), scalex, scaley);
                    }
                }
            }

            if (!_transforms.Result.IsIdentity)
                g.Transform = _transforms.Result.Clone();
            _cur.AddChild(g);
        }
Esempio n. 18
0
        private void button2_Click(object sender, System.EventArgs e)
        {
            SvgSvgElement root = new SvgSvgElement("4in", "4in", "0,0 100,100");

            //adding multiple children

            root.AddChildren(
                new SvgRectElement(5,5,5,5),
                new SvgEllipseElement(30,10,8,12),
                new SvgTextElement("Textastic!", 3, 20)
                );

            //group and path

            SvgGroupElement grp = new SvgGroupElement("green_group");

            grp.Style = "fill:green;stroke:black;";

            SvgEllipseElement ell = new SvgEllipseElement();
            ell.CX = 50;
            ell.CY = 50;
            ell.RX = 10;
            ell.RY = 20;

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

            root.AddChild(grp);

            //cloning and style arithmetic

            grp.AddChildren(ell, pathy);

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

            SvgGroupElement 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;

            StreamWriter tw = new StreamWriter("c:\\temp\\foo.svg", false);

            tw.Write(s);

            tw.Close();

            svgOut.SRC = "c:\\temp\\foo.svg";
        }
		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 AddCircles(float distance)
		{
			SvgGroupElement circlesGroup = new SvgGroupElement("Circles");
			InsertStyledElements(circlesGroup, GetCircles(distance));
			this.Root.AddChild(circlesGroup);
		}
Esempio n. 21
0
 /// <summary>
 /// Implemented, but returns null as SVG has a proper scenegraph, unlike GDI+.  The effect of calling <c>BeginContainer</c> is to create a new SVG group
 /// and apply transformations etc to produce the effect that a GDI+ container would produce.
 /// </summary>
 public System.Drawing.Drawing2D.GraphicsContainer BeginContainer()
 {
     SvgGroupElement gr = new SvgGroupElement();
     _cur.AddChild(gr);
     _cur = gr;
     _cur.Id += "_BeginContainer";
     _transforms.Push();
     return null;
 }
Esempio n. 22
0
        /// <summary>
        /// Creates a new SvgGraphics
        /// <para>
        /// Note that our current documentation tool, NDoc, does not handle overloaded methods well, so if you are reading the .chm file, please read the documentation
        /// for the particular exact method you want to use.  
        /// </para>
        /// </summary>
        public SvgGraphics()
        {
            _root = new SvgSvgElement();
            _root.Id = "SvgGdi_output";

            _bg = new SvgRectElement(0, 0, "100%", "100%");
            _bg.Style.Set("fill", new SvgColor(Color.FromName("Control")));
            _bg.Id = "background";
            _root.AddChild(_bg);

            _topgroup = new SvgGroupElement("root_group");
            _topgroup.Style.Set("shape-rendering", "crispEdges");
            _cur = _topgroup;
            _root.AddChild(_topgroup);

            _defs = new SvgDefsElement("clips_hatches_and_gradients");
            _root.AddChild(_defs);

            _transforms = new MatrixStack();
        }
		public void AddVerticalLines(float distance)
		{
			SvgGroupElement verticalLinesGroup = new SvgGroupElement("VerticalLines");
			InsertStyledElements(verticalLinesGroup, GetVerticalLines(distance));
			this.Root.AddChild(verticalLinesGroup);
		}
		public void AddAngleLines(float deltaAngleDegree, float innerRadius)
		{
			SvgGroupElement angleLinesGroup = new SvgGroupElement("AngleLines");
			InsertStyledElements(angleLinesGroup, GetAngleLines(deltaAngleDegree, innerRadius));
			this.Root.AddChild(angleLinesGroup);
		}
		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);
			}
		}