From 1149c24b86535d564c984a02eadf5ea70670bf8e Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 6 Mar 2015 08:48:53 -0800 Subject: [PATCH] More grouping, cleanup, start on overrides --- Marlin/configurator/config/Configuration.h | 2 +- Marlin/configurator/index.html | 3 - Marlin/configurator/js/configurator.js | 285 ++++++++++++--------- 3 files changed, 166 insertions(+), 124 deletions(-) diff --git a/Marlin/configurator/config/Configuration.h b/Marlin/configurator/config/Configuration.h index 253567fc95..272a0eb66d 100644 --- a/Marlin/configurator/config/Configuration.h +++ b/Marlin/configurator/config/Configuration.h @@ -347,7 +347,7 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of // @section machine // For Inverting Stepper Enable Pins (Active Low) use 0, Non Inverting (Active High) use 1 -// :{0:'Active Low',1:'Active High'} +// :{0:'Low',1:'High'} #define X_ENABLE_ON 0 #define Y_ENABLE_ON 0 #define Z_ENABLE_ON 0 diff --git a/Marlin/configurator/index.html b/Marlin/configurator/index.html index a804e7c740..93d2ae553f 100644 --- a/Marlin/configurator/index.html +++ b/Marlin/configurator/index.html @@ -65,9 +65,6 @@ - - - diff --git a/Marlin/configurator/js/configurator.js b/Marlin/configurator/js/configurator.js index f14255ab28..ff41fa39c0 100644 --- a/Marlin/configurator/js/configurator.js +++ b/Marlin/configurator/js/configurator.js @@ -85,7 +85,9 @@ String.prototype.prePad = function(len, chr) { return len ? this.lpad(len, chr) String.prototype.zeroPad = function(len) { return this.prePad(len, '0'); }; String.prototype.toHTML = function() { return jQuery('
').text(this).html(); }; String.prototype.regEsc = function() { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); } -String.prototype.lineCount = function() { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; }; +String.prototype.lineCount = function(ind) { var len = (ind === undefined ? this : this.substr(0,ind*1)).split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; }; +String.prototype.line = function(num) { var arr = this.split(/\r?\n|\r/); return num < arr.length ? arr[1*num] : ''; }; +String.prototype.replaceLine = function(num,txt) { var arr = this.split(/\r?\n|\r/); if (num < arr.length) { arr[num] = txt; return arr.join('\n'); } else return this; } String.prototype.toLabel = function() { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); } String.prototype.toTitleCase = function() { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); } Number.prototype.limit = function(m1, m2) { @@ -148,11 +150,12 @@ window.configuratorApp = (function(){ $config = $cfg.find('pre'), $config_adv = $adv.find('pre'), config_file_list = [ boards_file, config_file, config_adv_file ], config_list = [ $config, $config_adv ], - define_info = {}, - define_list = [[],[]], - define_groups = [{},{}], - define_section = {}, - dependentGroups = {}, + define_info = {}, // info for all defines, by name + define_list = [[],[]], // arrays with all define names + define_occur = [{},{}], // lines where defines occur in each file + define_groups = [{},{}], // similarly-named defines that group in the form + define_section = {}, // the section of each define + dependent_groups = {}, boards_list = {}, therms_list = {}, total_config_lines, @@ -339,32 +342,62 @@ window.configuratorApp = (function(){ }, /** - * Get all the unique define names + * Get all the unique define names, building lists that will be used + * when gathering info about each define. + * + * define_list[c][j] : Define names in each config (in order of occurrence) + * define_section[name] : Section where define should appear in the form + * define_occur[c][name][i] : Lines in each config where the same define occurs + * .cindex Config file index + * .lineNum Line number of the occurrence + * .line The occurrence line */ initDefineList: function(cindex) { var section = 'hidden', leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'], define_sect = {}, + occ_list = {}, txt = config_list[cindex].text(), - r, findDef = new RegExp('(@section|#define)[ \\t]+(\\w+)', 'gm'); + r, findDef = new RegExp('^.*(@section|#define)[ \\t]+(\\w+).*$', 'gm'); while((r = findDef.exec(txt)) !== null) { var name = r[2]; - if (r[1] == '@section') + if (r[1] == '@section') { section = name; - else if ($.inArray(name, leave_out_defines) < 0 && !(name in define_section) && !(name in define_sect)) - define_sect[name] = section; + } + else if ($.inArray(name, leave_out_defines) < 0) { + var lineNum = txt.lineCount(r.index), + inst = { cindex:cindex, lineNum:lineNum, line:r[0] }, + in_sect = (name in define_sect); + if (!in_sect) { + occ_list[name] = [ inst ]; + } + if (!(name in define_section) && !in_sect) { + define_sect[name] = section; // new first-time define + } + else { + occ_list[name].push(inst); + } + } } define_list[cindex] = Object.keys(define_sect); + define_occur[cindex] = occ_list; $.extend(define_section, define_sect); this.log(define_list[cindex], 2); + this.log(occ_list, 2); + this.log(define_sect, 2); }, /** * Find the defines in one of the configs that are just variants. * Group them together for form-building and other uses. + * + * define_groups[c][name] + * .pattern regexp matching items in the group + * .title title substitution + * .count number of items in the group */ refreshDefineGroups: function(cindex) { - var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/; + var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid]|HOTEND|HPB|JAPAN|WESTERN|LEFT|RIGHT|BACK|FRONT|[XYZ]_POINT)(_.*|)$/i; var match_prev, patt, title, nameList, groups = {}, match_section; $.each(define_list[cindex], function(i, name) { if (match_prev) { @@ -387,7 +420,8 @@ window.configuratorApp = (function(){ if (!match_prev) { var r = findDef.exec(name); if (r != null) { - switch(r[2]) { + title = ''; + switch(r[2].toUpperCase()) { case '0': patt = '([0123])'; title = 'N'; @@ -400,18 +434,31 @@ window.configuratorApp = (function(){ patt = 'E([0-3])'; title = 'E'; break; - case 'bedKp': + case 'BEDKP': patt = 'bed(K[pid])'; title = 'BED_PID'; break; - case 'Kp': + case 'KP': patt = '(K[pid])'; title = 'PID'; break; + case 'LEFT': + case 'RIGHT': + case 'BACK': + case 'FRONT': + patt = '([LRBF])(EFT|IGHT|ACK|RONT)'; + break; case 'MAX': case 'MIN': patt = '(MAX|MIN)'; - title = ''; + break; + case 'HOTEND': + case 'HPB': + patt = '(HOTEND|HPB)'; + break; + case 'JAPAN': + case 'WESTERN': + patt = '(JAPAN|WESTERN)'; break; case 'XMIN': case 'XMAX': @@ -425,7 +472,7 @@ window.configuratorApp = (function(){ if (patt) { patt = '^' + r[1] + patt + r[7] + '$'; title = r[1] + title + r[7]; - match_prev = new RegExp(patt); + match_prev = new RegExp(patt, 'i'); match_section = define_section[name]; nameList = [ name ]; } @@ -433,21 +480,29 @@ window.configuratorApp = (function(){ } }); define_groups[cindex] = groups; + this.log(define_groups[cindex], 2); }, /** - * Get all condition blocks and their line ranges. - * Conditions may control multiple line-ranges - * across both config files. + * Get all conditional blocks and their line ranges + * and store them in the dependent_groups list. + * + * dependent_groups[condition][i] + * + * .cindex config file index + * .start starting line + * .end ending line + * */ initDependentGroups: function() { var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm, leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H']; + dependent_groups = {}; $.each(config_list, function(i, $v) { var ifStack = []; var r, txt = $v.text(); while((r = findBlock.exec(txt)) !== null) { - var lineNum = txt.substr(0, r.index).lineCount(); + var lineNum = txt.lineCount(r.index); var code = r[2].replace(/[ \t]*\/\/.*$/, ''); switch(r[1]) { case 'if': @@ -481,8 +536,8 @@ window.configuratorApp = (function(){ if (c) { var cond = c[0], line = c[1]; self.log("pop " + c[0], 4); - if (dependentGroups[cond] === undefined) dependentGroups[cond] = []; - dependentGroups[cond].push({cindex:i,start:line,end:lineNum}); + if (dependent_groups[cond] === undefined) dependent_groups[cond] = []; + dependent_groups[cond].push({cindex:i,start:line,end:lineNum}); if (r[1] == 'else') { // Reverse the condition cond = (cond.indexOf('!') === 0) ? cond.substr(1) : ('!'+cond); @@ -544,11 +599,11 @@ window.configuratorApp = (function(){ grouping = true; g_subitem = false; var grp = group[name]; - g_pattern = grp.pattern; - g_class = 'one_of_' + grp.count; - label_text = grp.title; - g_regex = new RegExp(g_pattern); g_section = section; + g_class = 'one_of_' + grp.count; + g_pattern = grp.pattern; + g_regex = new RegExp(g_pattern, 'i'); + label_text = grp.title; sublabel = g_regex.exec(name)[1]; } @@ -596,8 +651,9 @@ window.configuratorApp = (function(){ $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail); if (grouping) { $newfield.addClass(g_class); - if (sublabel) + if (sublabel) { $ff.append($('