public static string GenerateSVG(Cutouts cutoutCalculator, float docDimension) { SVGCreator svgCreator = new SVGCreator { InfoComment = cutoutCalculator.Gear.Information + cutoutCalculator.Information }; svgCreator.AddClosedPath(cutoutCalculator.Gear.GenerateCompleteGearPath(), string.Empty, 0, "black"); foreach (List <PointF> cutout in cutoutCalculator.CutoutPlots) { svgCreator.AddClosedPath(cutout, string.Empty, 0, "white"); } if (cutoutCalculator.HexKeyPlot != null) { svgCreator.AddClosedPath(cutoutCalculator.HexKeyPlot, string.Empty, 0, "lightgray"); } if (cutoutCalculator.InlayPlot != null) { svgCreator.AddClosedPath(cutoutCalculator.InlayPlot, string.Empty, 0, "gray"); } if (cutoutCalculator.SpindlePlot != null) { svgCreator.AddClosedPath(cutoutCalculator.SpindlePlot, string.Empty, 0, "white"); } svgCreator.DocumentDimensions = new SizeF(docDimension, docDimension); svgCreator.DocumentDimensionUnits = "mm"; svgCreator.ViewBoxDimensions = new RectangleF( -svgCreator.DocumentDimensions.Width / 2f, -svgCreator.DocumentDimensions.Width / 2f, svgCreator.DocumentDimensions.Width, svgCreator.DocumentDimensions.Height); svgCreator.ViewBoxDimensionUnits = ""; return(svgCreator.ToString()); }
static void Main(string[] args) { // Validate arguments if (args.Length != 3) { Usage("nutrecess [flat-distance] [hole-diameter] [destination]"); } if (!double.TryParse(args[0], out double flats)) { Usage("Distance across flats must be digits with possible decimal point"); } if (!double.TryParse(args[1], out double holeDiameter)) { Usage("Hole diameter must be digits with possible decimal point"); } if (flats <= 0) { Usage("Distance across flats must be non-zero and positive"); } if (holeDiameter < 0) { Usage("Hole diameter must be positive, or set to zero for no hole"); } if (!args[2].EndsWith(".svg", StringComparison.CurrentCultureIgnoreCase)) { Usage("Destination file must have a '.svg' extension"); } // Create the cutout and its centering crosshairs var svgCreator = new SVGCreator { DocumentDimensions = NewSz(flats * 2, flats * 2), DocumentDimensionUnits = "mm", ViewBoxDimensions = NewRect(-flats, -flats, 2 * flats, 2 * flats) }; svgCreator.AddClosedPath(NutRecessPoints(flats), "black", 0.03, "gray"); if (holeDiameter > 0) { svgCreator.AddClosedPath(Arc(0, 360, holeDiameter / 2, PointF.Empty), "black", 0.03, "darkgray"); } var pathX = new SVGPath(Line(-2 * flats / 3.0, 0, 2 * flats / 3.0, 0), false); pathX.SetDrawingParams("black", 0.03, ""); svgCreator.AddPath(pathX); var pathY = new SVGPath(Line(0, -2 * flats / 3.0, 0, 2 * flats / 3.0), false); pathY.SetDrawingParams("black", 0.03, ""); svgCreator.AddPath(pathY); // Save out to the destination file using TextWriter tw = new StreamWriter(args[2]); tw.Write(svgCreator.ToString()); }