void GenerateSubFromPolygon(ref StringBuilder sb, Polygon poly) { BindableCodeTemplate tmpl; CurrentPathIndex = (int)poly.Tag; // add start of path Bind(ref sb, PathStartTemplate()); PathFragment points = new PathFragment(poly.Points); if (!_context.UseAbsoluteMoves) { points = OffsetList(points); } // loop round points in list _currentPoint = _context.FirstPoint = points[0]; tmpl = _context.Templates.FirstPointTemplate; Bind(ref sb, tmpl); for (int i = 1; i < points.Count - 1; i++) { _currentPoint = points[i]; tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; Bind(ref sb, tmpl); } _currentPoint = _context.LastPoint = points[points.Count - 1]; tmpl = _context.Templates.LastPointTemplate; Bind(ref sb, tmpl); // add end of path Bind(ref sb, PathEndTemplate()); }
void GenerateSubFromPath(ref StringBuilder sb, Windows.UI.Xaml.Shapes.Path path) { CurrentPathIndex = (int)path.Tag; Bind(ref sb, PathStartTemplate()); PathFragment points = new PathFragment(); if (path.Data is GeometryGroup) { GeometryGroup gg = path.Data as GeometryGroup; foreach (PathGeometry pg in gg.Children) { foreach (PathFigure pf in pg.Figures) { // now deal with all lines in this figure foreach (PathSegment ps in pf.Segments) { if (ps is LineSegment) { _currentPoint = _context.FirstPoint = new Cartesian(pf.StartPoint); Bind(ref sb, _context.Templates.FirstPointTemplate); LineSegment ls = ps as LineSegment; _currentPoint = _context.LastPoint = new Cartesian(ls.Point); BindableCodeTemplate tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; Bind(ref sb, tmpl); Bind(ref sb, _context.Templates.LastPointTemplate); } if (ps is PolyLineSegment) { PolyLineSegment pls = ps as PolyLineSegment; BindableCodeTemplate tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; _context.FirstPoint = new Cartesian(pls.Points.First()); _context.LastPoint = new Cartesian(pls.Points.Last()); foreach (Point p in pls.Points) { _currentPoint = new Cartesian(p); if (_currentPoint == _context.FirstPoint) { Bind(ref sb, _context.Templates.FirstPointTemplate); } else if (_currentPoint == _context.LastPoint) { Bind(ref sb, _context.Templates.LastPointTemplate); } else { Bind(ref sb, tmpl); } } } Bind(ref sb, PathEndTemplate()); } } } } }
public void FromPathFragmentsDirectory() { var absFilename = AbsoluteDirectory.FromAbsolutePath("C:\\dirA\\dirB"); var fragments = new PathFragment[] { new RootFragment("C:\\"), new DirectoryFragment("dirA"), new DirectoryFragment("dirB") }; var fromFragments = AbsoluteDirectory.FromPathFragments(fragments, true); Assert.AreEqual(absFilename, fromFragments); TestUtilities.AssertCollectionEqual(absFilename.PathFragments, fromFragments.PathFragments); }
public static PathFragment TransformFragment <TSource>(this IEnumerable <TSource> sourceItems, Func <TSource, ICoordinate> transformFunction) { PathFragment targetItems = new PathFragment(); foreach (TSource sourceItem in sourceItems) { targetItems.Add(transformFunction(sourceItem)); } return(targetItems); }
private PathFragment OffsetList(PathFragment p) { PathFragment offsets = new PathFragment(); for (int indx = 1; indx < p.Count; indx++) { Cartesian pc = p[indx] as Cartesian; Cartesian pc1 = p[indx - 1] as Cartesian; Cartesian pnt = new Cartesian(pc.X - pc1.X, pc.Y - pc1.Y, pc.Z - pc1.Z); offsets.Add(pnt); } return(offsets); }
/// <summary> /// Subroutines each have an individual header file /// </summary> /// <param name="cntxt"></param> void GenerateSubroutines() { foreach (List <Point> pl in CurrentPath) { CurrentPathIndex = CurrentPath.IndexOf(pl); BindableCodeTemplate tmpl; StringBuilder sb = new StringBuilder(); Bind(ref sb, _context.Templates.Header_Template); // add start of path Bind(ref sb, PathStartTemplate()); // now generate points in path PathFragment points = new PathFragment(pl); //(_context.UseRotaryTable) //? MapToCylindricalList(pl) : MapToCartesianList(pl); if (!_context.UseAbsoluteMoves) { points = OffsetList(points); } // loop round points in list foreach (Cartesian coord in points) { CurrentPoint = coord; tmpl = (coord is Cartesian) ?_context.Templates.XY_Point_Template :_context.Templates.RA_Point_Template; Bind(ref sb, tmpl); } // add end of path Bind(ref sb, PathEndTemplate()); // now deal with name tmpl = _context.Templates.SubFilenameTemplate; tmpl.DataContext = _context; Code.Add(new GcodeFile(tmpl.Text, sb.ToString())); } }
public void TestGenerationFromFragmenst() { var fragments = new PathFragment[] {new DirectoryFragment("somedir"), new FileFragment("test.txt")}; var fileInSubdir = RelativeFilename.FromPathFragments(fragments); Assert.AreEqual("test.txt", fileInSubdir.FilenameWithExtension); TestUtilities.AssertCollectionEqual(new PathFragment[] { new DirectoryFragment("somedir"), new FileFragment("test.txt") }, fileInSubdir.PathFragments); Assert.AreEqual(fileInSubdir.Extension, new FileExtension("txt")); }
public void TestCreateWithRootFragmentInvalid() { var fragments = new PathFragment[] { new RootFragment("C:\\"), new FileFragment("test.txt") }; var fileInSubdir = RelativeFilename.FromPathFragments(fragments, true); }
public void TestCreateWithoutFileFragmentInvalid() { var fragments = new PathFragment[] {new DirectoryFragment("somdedir"), new DirectoryFragment("test.txt"),}; var fileInSubdir = RelativeFilename.FromPathFragments(fragments, true); }
public void FromPathFragmentsInvalidIfRootMissingDirectory() { var fragments = new PathFragment[] { new DirectoryFragment("dirA"), new DirectoryFragment("dirB")}; var fromFragments = AbsoluteDirectory.FromPathFragments(fragments, true); }
public void FromPathFragmentsInvalidIfRootMissing() { var fragments = new PathFragment[] { new DirectoryFragment("dirA"), new DirectoryFragment("dirB"), new FileFragment("file.txt") }; var fromFragments = AbsoluteFilename.FromPathFragments(fragments, true); }
public void FromPathFragmentsInvalidIfFileMissing() { var fragments = new PathFragment[] { new RootFragment("C:\\"), new DirectoryFragment("dirA"), new DirectoryFragment("dirB") }; var fromFragments = AbsoluteFilename.FromPathFragments(fragments, true); }
private PathFragment OffsetList(PathFragment p) { PathFragment offsets = new PathFragment(); for (int indx = 1; indx < p.Count; indx++) { Cartesian pc = p[indx] as Cartesian; Cartesian pc1 = p[indx - 1] as Cartesian; Cartesian pnt = new Cartesian(pc.X - pc1.X, pc.Y - pc1.Y, pc.Z - pc1.Z); offsets.Add(pnt); } return offsets; }
/// <summary> /// Subroutines each have an individual header file /// </summary> /// <param name="cntxt"></param> void GenerateSubroutines() { foreach (List<Point> pl in CurrentPath) { CurrentPathIndex = CurrentPath.IndexOf(pl); BindableCodeTemplate tmpl; StringBuilder sb = new StringBuilder(); Bind(ref sb, _context.Templates.Header_Template); // add start of path Bind(ref sb, PathStartTemplate()); // now generate points in path PathFragment points = new PathFragment(pl); //(_context.UseRotaryTable) //? MapToCylindricalList(pl) : MapToCartesianList(pl); if (!_context.UseAbsoluteMoves) points = OffsetList(points); // loop round points in list foreach (Cartesian coord in points) { CurrentPoint = coord; tmpl = (coord is Cartesian) ?_context.Templates.XY_Point_Template :_context.Templates.RA_Point_Template; Bind(ref sb, tmpl); } // add end of path Bind(ref sb, PathEndTemplate()); // now deal with name tmpl = _context.Templates.SubFilenameTemplate; tmpl.DataContext = _context; Code.Add(new GcodeFile(tmpl.Text,sb.ToString())); } }
void GenerateSubFromPath(ref StringBuilder sb, Windows.UI.Xaml.Shapes.Path path) { CurrentPathIndex = (int)path.Tag; Bind(ref sb, PathStartTemplate()); PathFragment points = new PathFragment(); if (path.Data is GeometryGroup) { GeometryGroup gg = path.Data as GeometryGroup; foreach (PathGeometry pg in gg.Children) { foreach (PathFigure pf in pg.Figures) { // now deal with all lines in this figure foreach (PathSegment ps in pf.Segments) { if (ps is LineSegment) { _currentPoint = _context.FirstPoint = new Cartesian(pf.StartPoint); Bind(ref sb, _context.Templates.FirstPointTemplate); LineSegment ls = ps as LineSegment; _currentPoint = _context.LastPoint = new Cartesian(ls.Point); BindableCodeTemplate tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; Bind(ref sb, tmpl); Bind(ref sb, _context.Templates.LastPointTemplate); } if (ps is PolyLineSegment) { PolyLineSegment pls = ps as PolyLineSegment; BindableCodeTemplate tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; _context.FirstPoint = new Cartesian(pls.Points.First()); _context.LastPoint = new Cartesian(pls.Points.Last()); foreach (Point p in pls.Points) { _currentPoint = new Cartesian(p); if (_currentPoint == _context.FirstPoint) { Bind(ref sb, _context.Templates.FirstPointTemplate); } else if (_currentPoint == _context.LastPoint) { Bind(ref sb, _context.Templates.LastPointTemplate); } else Bind(ref sb, tmpl); } } Bind(ref sb, PathEndTemplate()); } } } } }
void GenerateSubFromPolygon(ref StringBuilder sb, Polygon poly) { BindableCodeTemplate tmpl; CurrentPathIndex = (int)poly.Tag; // add start of path Bind(ref sb, PathStartTemplate()); PathFragment points = new PathFragment(poly.Points); if (!_context.UseAbsoluteMoves) points = OffsetList(points); // loop round points in list _currentPoint = _context.FirstPoint = points[0]; tmpl = _context.Templates.FirstPointTemplate; Bind(ref sb, tmpl); for (int i = 1; i < points.Count - 1 ; i++) { _currentPoint = points[i]; tmpl = (_context.UseRotaryTable) ? _context.Templates.RA_Point_Template : _context.Templates.XY_Point_Template; Bind(ref sb, tmpl); } _currentPoint = _context.LastPoint = points[points.Count - 1]; tmpl = _context.Templates.LastPointTemplate; Bind(ref sb, tmpl); // add end of path Bind(ref sb, PathEndTemplate()); }