public virtual SLExpression Visit(SLExpression expression) { var expType = expression.GetType().Name; switch (expType) { case "DrawingExpression": return(VisitDrawing((DrawingExpression)expression)); case "PolygonFromLinesExpression": return(VisitPolygonFromLines((PolygonFromLinesExpression)expression)); case "PolygonFromPointsExpression": return(VisitPolygonFromPoints((PolygonFromPointsExpression)expression)); case "IdentifiedLineExpression": return(VisitIdentifiedLine((IdentifiedLineExpression)expression)); case "TwoPointsLineExpression": return(VisitTwoPointsLine((TwoPointsLineExpression)expression)); case "HalfwayPointExpression": return(VisitHalfwayPoint((HalfwayPointExpression)expression)); case "CoordinatesPointExpression": return(VisitCoordinatesPoint((CoordinatesPointExpression)expression)); case "LineExtremityPointExpression": return(VisitLineExtremityPoint((LineExtremityPointExpression)expression)); case "LineReferenceExpression": return(VisitLineReference((LineReferenceExpression)expression)); case "LinesIntersectionPointExpression": return(VisitLinesIntersectionPoint((LinesIntersectionPointExpression)expression)); case "EquidistantPointExpression": return(VisitEquidistantPoint((EquidistantPointExpression)expression)); case "SideLengthAndPositionSquareExpression": return(VisitSideLengthAndPositionSquare((SideLengthAndPositionSquareExpression)expression)); case "DefinedByTwoPointsPointExpression": return(VisitDefinedByTwoPointsPoint((DefinedByTwoPointsPointExpression)expression)); default: throw new NotImplementedException(expType); } }
public XDocument Convert(SLExpression expression) { PolygonsFromLines = new List <PolygonFromLinesExpression>(); PolygonsFromPoints = new List <PolygonFromPointsExpression>(); this.Visit(expression); var doc = new XDocument( new XElement("svg", new XElement("rect", new XAttribute("x", 0), new XAttribute("y", 0), new XAttribute("width", 1), new XAttribute("height", 1), new XAttribute("fill", "none"), new XAttribute("stroke", "blue"), new XAttribute("stroke-width", "0.001")), PolygonsFromPoints.Select(ConvertPolygon).ToArray(), PolygonsFromLines.Select(ConvertPolygon).ToArray(), new XAttribute("viewBox", "0 0 1 1"))); return(doc); }