Exemple #1
0
        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());
                        }
                    }
                }
            }
        }
Exemple #2
0
        void GenerateCodeInMultipleFiles()
        {
            // first generate subroutines or paths
            // then main program to call them
            StringBuilder sb = new StringBuilder();

            foreach (Shape s in _currentToolPaths.Shapes)
            {
                if (s is Polygon)
                {
                    GenerateSubFromPolygon(ref sb, (s as Polygon));
                }
                else if (s is Windows.UI.Xaml.Shapes.Path)
                {
                    GenerateSubFromPath(ref sb, (s as Windows.UI.Xaml.Shapes.Path));
                }

                string filename = string.Empty;
                string ext      = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
                // now deal with name and save in code list
                if ((bool)BasicLib.GetSetting(SettingsNames.USE_NAMED_O_WORDS))
                {
                    BindableCodeTemplate tmpl = _context.Templates.SubFilenameTemplate;
                    tmpl.DataContext = _context;
                    filename         = System.IO.Path.ChangeExtension(tmpl.Text, ext);
                }
                else
                {
                    filename = System.IO.Path.ChangeExtension(_context.SubPathName.ToString(), ext);
                }
                Code.Add(new GcodeFile(filename, sb.ToString()));
            }

            GenerateMain();
        }
Exemple #3
0
        public TemplateCollection()
        {
            Header_Template = new BindableCodeTemplate(SettingsNames.HEADER_TEMPLATE,
                                                       DefaultSettings.HEADER_TEMPLATE_FORMAT);
            Globals_Template = new BindableCodeTemplate(SettingsNames.GLOBALS_TEMPLATE,
                                                        DefaultSettings.GLOBALS_TEMPLATE_FORMAT);
            XY_Point_Template = new BindableCodeTemplate(SettingsNames.XY_POINT_TEMPLATE,
                                                         DefaultSettings.XY_POINT_TEMPLATE_FORMAT);
            RA_Point_Template = new BindableCodeTemplate(SettingsNames.RA_POINT_TEMPLATE,
                                                         DefaultSettings.RA_POINT_TEMPLATE_FORMAT);

            SubStartTemplate = new BindableCodeTemplate(SettingsNames.SUB_START_TEMPLATE,
                                                        DefaultSettings.SUB_START_TEMPLATE_FORMAT);
            SubEndTemplate = new BindableCodeTemplate(SettingsNames.SUB_END_TEMPLATE,
                                                      DefaultSettings.SUB_END_TEMPLATE_FORMAT);
            SubCallTemplate = new BindableCodeTemplate(SettingsNames.SUB_CALL_TEMPLATE,
                                                       DefaultSettings.SUB_CALL_TEMPLATE_FORMAT);

            PathStartTemplate = new BindableCodeTemplate(SettingsNames.PATH_START_TEMPLATE,
                                                         DefaultSettings.PATH_START_TEMPLATE_FORMAT);
            PathEndTemplate = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                                       DefaultSettings.PATH_END_TEMPLATE_FORMAT);
            MainProgramTemplate = new BindableCodeTemplate(SettingsNames.MAIN_BODY_TEMPLATE,
                                                           DefaultSettings.MAIN_PROGRAM_BODY_TEMPLATE_FORMAT);
            ProgramEndTemplate = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                                          DefaultSettings.PROGRAM_END_TEMPLATE_FORMAT);
            SubFilenameTemplate = new BindableCodeTemplate(SettingsNames.SUB_FILE_NAME_TEMPLATE,
                                                           DefaultSettings.SUB_FILE_NAME_TEMPLATE_FORMAT);
            MainFilenameTemplate = new BindableCodeTemplate(SettingsNames.MAIN_FILE_NAME_TEMPLATE,
                                                            DefaultSettings.MAIN_FILE_NAME_TEMPLATE_FORMAT);
            FirstPointTemplate = new BindableCodeTemplate(SettingsNames.FIRST_POINT_TEMPLATE,
                                                          DefaultSettings.FIRST_POINT_TEMPLATE_FORMAT);
            LastPointTemplate = new BindableCodeTemplate(SettingsNames.LAST_POINT_TEMPLATE,
                                                         DefaultSettings.LAST_POINT_TEMPLATE_FORMAT);
        }
Exemple #4
0
 void Bind(ref StringBuilder sb, BindableCodeTemplate t)
 {
     if (t.Include)
     {
         t.DataContext = _context;
         sb.AppendLine(t.Text);
     }
 }
Exemple #5
0
 public BindableCodeTemplate Lookup(string name)
 {
     try
     {
         BindableCodeTemplate tmpl = AllTemplates.First <BindableCodeTemplate>(
             t => t.Name == name);
         return(tmpl);
     }
     catch (ArgumentNullException)
     {
         return(null);
     }
     catch (InvalidOperationException)
     {
         return(null);
     }
 }
Exemple #6
0
        private void GenerateMain()
        {
            StringBuilder sb = new StringBuilder();

            Bind(ref sb, _context.Templates.Header_Template);
            Bind(ref sb, _context.Templates.Globals_Template);
            Bind(ref sb, _context.Templates.MainProgramTemplate);
            foreach (Shape s in _currentToolPaths.Shapes)
            {
                Bind(ref sb, _context.Templates.SubCallTemplate);
            }
            Bind(ref sb, _context.Templates.ProgramEndTemplate);

            string ext = (string)BasicLib.GetSetting(SettingsNames.GCODE_FILE_EXT);
            BindableCodeTemplate tmpl = _context.Templates.MainFilenameTemplate;

            tmpl.DataContext = _context;
            Code.Add(new GcodeFile(System.IO.Path.ChangeExtension(tmpl.Text, ext), sb.ToString()));
        }
Exemple #7
0
 void Bind(ref StringBuilder sb, BindableCodeTemplate t)
 {
     if (t.Include)
     {
         t.DataContext = _context;
         sb.AppendLine(t.Text);
     }
 }
Exemple #8
0
        public CodeGenTemplates()
        {
            _allTemplates = new List <BindableCodeTemplate>();

            BindableCodeTemplate template = new BindableCodeTemplate(SettingsNames.HEADER_TEMPLATE,
                                                                     DefaultSettings.HEADER_TEMPLATE_FORMAT);

            Header_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.GLOBALS_TEMPLATE,
                                                DefaultSettings.GLOBALS_TEMPLATE_FORMAT);
            Globals_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.XY_POINT_TEMPLATE,
                                                DefaultSettings.XY_POINT_TEMPLATE_FORMAT);
            XY_Point_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.RA_POINT_TEMPLATE,
                                                DefaultSettings.RA_POINT_TEMPLATE_FORMAT);
            RA_Point_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_START_TEMPLATE,
                                                DefaultSettings.SUB_START_TEMPLATE_FORMAT);
            SubStartTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_END_TEMPLATE,
                                                DefaultSettings.SUB_END_TEMPLATE_FORMAT);
            SubEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PATH_START_TEMPLATE,
                                                DefaultSettings.PATH_START_TEMPLATE_FORMAT);
            PathStartTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                                DefaultSettings.PATH_END_TEMPLATE_FORMAT);
            PathEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.MAIN_BODY_TEMPLATE,
                                                DefaultSettings.MAIN_PROGRAM_BODY_TEMPLATE_FORMAT);
            MainProgramTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                                DefaultSettings.PROGRAM_END_TEMPLATE_FORMAT);
            ProgramEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_FILE_NAME_TEMPLATE,
                                                DefaultSettings.SUB_FILE_NAME_TEMPLATE_FORMAT);
            SubFilenameTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.MAIN_FILE_NAME_TEMPLATE,
                                                DefaultSettings.MAIN_FILE_NAME_TEMPLATE_FORMAT);
            MainFilenameTemplate = template;
            _allTemplates.Add(template);
        }
Exemple #9
0
        public CodeGenTemplates()
        {
            _allTemplates = new List<BindableCodeTemplate>();

            BindableCodeTemplate template = new BindableCodeTemplate(SettingsNames.HEADER_TEMPLATE,
                                            DefaultSettings.HEADER_TEMPLATE_FORMAT);
            Header_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.GLOBALS_TEMPLATE,
                                            DefaultSettings.GLOBALS_TEMPLATE_FORMAT);
            Globals_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.XY_POINT_TEMPLATE,
                                             DefaultSettings.XY_POINT_TEMPLATE_FORMAT);
            XY_Point_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.RA_POINT_TEMPLATE,
                                            DefaultSettings.RA_POINT_TEMPLATE_FORMAT);
            RA_Point_Template = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_START_TEMPLATE,
                                            DefaultSettings.SUB_START_TEMPLATE_FORMAT);
            SubStartTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_END_TEMPLATE,
                                            DefaultSettings.SUB_END_TEMPLATE_FORMAT);
            SubEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PATH_START_TEMPLATE,
                                            DefaultSettings.PATH_START_TEMPLATE_FORMAT);
            PathStartTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                            DefaultSettings.PATH_END_TEMPLATE_FORMAT);
            PathEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.MAIN_BODY_TEMPLATE,
                                          DefaultSettings.MAIN_PROGRAM_BODY_TEMPLATE_FORMAT);
            MainProgramTemplate= template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.PROGRAM_END_TEMPLATE,
                                        DefaultSettings.PROGRAM_END_TEMPLATE_FORMAT);
            ProgramEndTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.SUB_FILE_NAME_TEMPLATE,
                                         DefaultSettings.SUB_FILE_NAME_TEMPLATE_FORMAT);
            SubFilenameTemplate = template;
            _allTemplates.Add(template);

            template = new BindableCodeTemplate(SettingsNames.MAIN_FILE_NAME_TEMPLATE,
                                         DefaultSettings.MAIN_FILE_NAME_TEMPLATE_FORMAT);
            MainFilenameTemplate = template;
            _allTemplates.Add(template);
        }