Browse Source

Find fields that group together

- Do field grouping
- Tweak configurations for better grouping
Scott Lahteine 10 years ago
parent
commit
2eeb241b42

+ 10
- 8
Marlin/configurator/config/Configuration.h View File

393
 // @section machine
393
 // @section machine
394
 
394
 
395
 // Travel limits after homing (units are in mm)
395
 // Travel limits after homing (units are in mm)
396
-#define X_MAX_POS 205
397
 #define X_MIN_POS 0
396
 #define X_MIN_POS 0
398
-#define Y_MAX_POS 205
399
 #define Y_MIN_POS 0
397
 #define Y_MIN_POS 0
400
-#define Z_MAX_POS 200
401
 #define Z_MIN_POS 0
398
 #define Z_MIN_POS 0
399
+#define X_MAX_POS 205
400
+#define Y_MAX_POS 205
401
+#define Z_MAX_POS 200
402
 
402
 
403
 // @section hidden
403
 // @section hidden
404
 
404
 
535
 //#define MANUAL_HOME_POSITIONS  // If defined, MANUAL_*_HOME_POS below will be used
535
 //#define MANUAL_HOME_POSITIONS  // If defined, MANUAL_*_HOME_POS below will be used
536
 //#define BED_CENTER_AT_0_0  // If defined, the center of the bed is at (X=0, Y=0)
536
 //#define BED_CENTER_AT_0_0  // If defined, the center of the bed is at (X=0, Y=0)
537
 
537
 
538
-//Manual homing switch locations:
538
+// Manual homing switch locations:
539
 // For deltabots this means top and center of the Cartesian print volume.
539
 // For deltabots this means top and center of the Cartesian print volume.
540
-#define MANUAL_X_HOME_POS 0
540
+#ifdef MANUAL_HOME_POSITIONS
541
-#define MANUAL_Y_HOME_POS 0
541
+  #define MANUAL_X_HOME_POS 0
542
-#define MANUAL_Z_HOME_POS 0
542
+  #define MANUAL_Y_HOME_POS 0
543
-//#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing.
543
+  #define MANUAL_Z_HOME_POS 0
544
+  //#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing.
545
+#endif
544
 
546
 
545
 // @section movement
547
 // @section movement
546
 
548
 

+ 3
- 0
Marlin/configurator/config/Configuration_adv.h View File

100
 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
100
 #define ENDSTOPS_ONLY_FOR_HOMING // If defined the endstops will only be used for homing
101
 
101
 
102
 
102
 
103
+// @section hidden
104
+
105
+
103
 //// AUTOSET LOCATIONS OF LIMIT SWITCHES
106
 //// AUTOSET LOCATIONS OF LIMIT SWITCHES
104
 //// Added by ZetaPhoenix 09-15-2012
107
 //// Added by ZetaPhoenix 09-15-2012
105
 #ifdef MANUAL_HOME_POSITIONS  // Use manual limit switch locations
108
 #ifdef MANUAL_HOME_POSITIONS  // Use manual limit switch locations

+ 36
- 5
Marlin/configurator/css/configurator.css View File

91
 	margin-right: -450px;
91
 	margin-right: -450px;
92
 	text-align: right;
92
 	text-align: right;
93
 	}
93
 	}
94
-label.blocked { color: #AAA; }
94
+label.blocked, span.label.blocked { color: #AAA; }
95
+
96
+span.label {
97
+	display: block;
98
+	float: left;
99
+	margin: 11px -2.5em 0 1em;
100
+	padding-right: 3em;
101
+	font-style: italic;
102
+	color: #444;
103
+	}
104
+label+span.label {
105
+	margin-left: 0;
106
+	}
95
 
107
 
96
 input[type="text"], select { margin: 0.75em 0 0; }
108
 input[type="text"], select { margin: 0.75em 0 0; }
97
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
109
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
104
 
116
 
105
 input[type="text"].added { width: 20em; }
117
 input[type="text"].added { width: 20em; }
106
 label.added {
118
 label.added {
107
-	width: 275px; /* label area */
119
+	width: 265px; /* label area */
108
 	height: 1em;
120
 	height: 1em;
109
-	padding: 10px 360px 10px 1em;
121
+	padding: 10px 370px 10px 1em;
110
-	margin-right: -350px;
122
+	margin-right: -360px;
111
 	text-align: right;
123
 	text-align: right;
112
 	}
124
 	}
113
 
125
 
297
 	}
309
 	}
298
 a.download-all { margin: 9px 2em 0; color: #449; border-color: #449; }
310
 a.download-all { margin: 9px 2em 0; color: #449; border-color: #449; }
299
 
311
 
312
+input[type="text"].one_of_2 { max-width: 15%; }
313
+input[type="text"].one_of_3 { max-width: 10%; }
314
+input[type="text"].one_of_4 { max-width: 7%; }
315
+
316
+select.one_of_2 { max-width: 15%; }
317
+select.one_of_3 { max-width: 10%; }
318
+select.one_of_4 { max-width: 14%; }
319
+select.one_of_4+span.label+select.one_of_4+span.label { clear: both; margin-left: 265px; padding-left: 1.75em; }
320
+select.one_of_4+span.label+select.one_of_4+span.label+select.one_of_4+span.label { clear: none; margin-left: 1em; padding-left: 0; }
321
+
300
 @media all and (min-width: 1140px) {
322
 @media all and (min-width: 1140px) {
301
 
323
 
302
 	#main { max-width: 10000px; }
324
 	#main { max-width: 10000px; }
309
 
331
 
310
 	.disclose { display: none; }
332
 	.disclose { display: none; }
311
 
333
 
334
+	input[type="text"].one_of_2 { max-width: 15%; }
335
+	input[type="text"].one_of_3 { max-width: 9%; }
336
+	input[type="text"].one_of_4 { max-width: 8%; }
337
+
338
+	select.one_of_2 { max-width: 15%; }
339
+	select.one_of_3 { max-width: 10%; }
340
+	select.one_of_4 { max-width: 16%; }
341
+
312
 }
342
 }
313
 
343
 
314
-/*.blocked { display: none; }*/
344
+/*span.label.blocked, .blocked { display: none; }*/
345
+

+ 145
- 31
Marlin/configurator/js/configurator.js View File

86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
87
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
87
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
88
 String.prototype.lineCount = function()      { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
88
 String.prototype.lineCount = function()      { var len = this.split(/\r?\n|\r/).length; return len > 0 ? len - 1 : 0; };
89
-String.prototype.toLabel = function()        { return this.replace(/_/g, ' ').toTitleCase(); }
89
+String.prototype.toLabel = function()        { return this.replace(/[\[\]]/g, '').replace(/_/g, ' ').toTitleCase(); }
90
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
90
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
91
 Number.prototype.limit = function(m1, m2)  {
91
 Number.prototype.limit = function(m1, m2)  {
92
   if (m2 == null) return this > m1 ? m1 : this;
92
   if (m2 == null) return this > m1 ? m1 : this;
124
             .attr('unselectable', 'on')
124
             .attr('unselectable', 'on')
125
             .css('user-select', 'none')
125
             .css('user-select', 'none')
126
             .on('selectstart', false);
126
             .on('selectstart', false);
127
+  },
128
+  unblock: function(on) {
129
+    on ? this.removeClass('blocked') : this.addClass('blocked');
130
+    return this;
127
   }
131
   }
128
 });
132
 });
129
 
133
 
144
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
148
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
145
       define_info = {},
149
       define_info = {},
146
       define_list = [[],[]],
150
       define_list = [[],[]],
151
+      define_groups = [{},{}],
147
       define_section = {},
152
       define_section = {},
148
       dependentGroups = {},
153
       dependentGroups = {},
149
       boards_list = {},
154
       boards_list = {},
354
     },
359
     },
355
 
360
 
356
     /**
361
     /**
362
+     * Find the defines in one of the configs that are just variants.
363
+     * Group them together for form-building and other uses.
364
+     */
365
+    refreshDefineGroups: function(index) {
366
+      var findDef = /^(|.*_)(([XYZE](MAX|MIN))|(E[0-3]|[XYZE01234])|MAX|MIN|(bed)?K[pid])(_.*|)$/;
367
+      var match_prev, patt, title, nameList, groups = {}, match_section;
368
+      $.each(define_list[index], function() {
369
+        if (match_prev) {
370
+          if (match_prev.exec(this) && define_section[this] == match_section) {
371
+            nameList.push(this);
372
+          }
373
+          else {
374
+            if (nameList.length > 1) {
375
+              $.each(nameList, function(){
376
+                groups[this] = {
377
+                  pattern: patt,
378
+                  title: title,
379
+                  count: nameList.length
380
+                };
381
+              });
382
+            }
383
+            match_prev = null;
384
+          }
385
+        }
386
+        if (!match_prev) {
387
+          var r = findDef.exec(this);
388
+          if (r != null) {
389
+            switch(r[2]) {
390
+              case '0':
391
+                patt = '([0123])';
392
+                title = 'N';
393
+                break;
394
+              case 'X':
395
+                patt = '([XYZE])';
396
+                title = 'AXIS';
397
+                break;
398
+              case 'E0':
399
+                patt = 'E([0-3])';
400
+                title = 'E';
401
+                break;
402
+              case 'bedKp':
403
+                patt = 'bed(K[pid])';
404
+                title = 'BED_PID';
405
+                break;
406
+              case 'Kp':
407
+                patt = '(K[pid])';
408
+                title = 'PID';
409
+                break;
410
+              case 'MAX':
411
+              case 'MIN':
412
+                patt = '(MAX|MIN)';
413
+                title = '';
414
+                break;
415
+              case 'XMIN':
416
+              case 'XMAX':
417
+                patt = '([XYZ])'+r[4];
418
+                title = 'XYZ_'+r[4];
419
+                break;
420
+              default:
421
+                patt = null;
422
+                break;
423
+            }
424
+            if (patt) {
425
+              patt = '^' + r[1] + patt + r[7] + '$';
426
+              title = r[1] + title + r[7];
427
+              match_prev = new RegExp(patt);
428
+              match_section = define_section[this];
429
+              nameList = [ this ];
430
+            }
431
+          }
432
+        }
433
+      });
434
+      define_groups[index] = groups;
435
+    },
436
+
437
+    /**
357
      * Get all condition blocks and their line ranges.
438
      * Get all condition blocks and their line ranges.
358
      * Conditions may control multiple line-ranges
439
      * Conditions may control multiple line-ranges
359
      * across both config files.
440
      * across both config files.
360
      */
441
      */
361
     initDependentGroups: function() {
442
     initDependentGroups: function() {
362
-      var findDef = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
443
+      var findBlock = /^[ \t]*#(ifn?def|if|else|endif)[ \t]*(.*)([ \t]*\/\/[^\n]+)?$/gm,
363
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
444
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
364
       $.each([$config, $config_adv], function(i, $v) {
445
       $.each([$config, $config_adv], function(i, $v) {
365
         var ifStack = [];
446
         var ifStack = [];
366
         var r, txt = $v.text();
447
         var r, txt = $v.text();
367
-        while((r = findDef.exec(txt)) !== null) {
448
+        while((r = findBlock.exec(txt)) !== null) {
368
           var lineNum = txt.substr(0, r.index).lineCount();
449
           var lineNum = txt.substr(0, r.index).lineCount();
369
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
450
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
370
           switch(r[1]) {
451
           switch(r[1]) {
431
     },
512
     },
432
 
513
 
433
     /**
514
     /**
434
-     * Create fields for any defines that have none
515
+     * Create fields for defines in a config that have none
516
+     * Use define_groups data to group fields together
435
      */
517
      */
436
-    createFieldsForDefines: function(e) {
518
+    createFieldsForDefines: function(index) {
437
       var n = 0, fail_list = [];
519
       var n = 0, fail_list = [];
438
-      $.each(define_list[e], function(i,name) {
520
+      var grouping = false, group_pattern, group_regex, subitem, group_section, group_class;
521
+      $.each(define_list[index], function(i,name) {
439
         var section = define_section[name];
522
         var section = define_section[name];
440
         if (section != 'hidden' && !$('#'+name).length) {
523
         if (section != 'hidden' && !$('#'+name).length) {
441
           var inf = define_info[name];
524
           var inf = define_info[name];
442
 
525
 
443
           if (inf) {
526
           if (inf) {
444
 
527
 
528
+            var label_text = name, sublabel;
529
+
530
+            // Is this field in a sequence?
531
+            // Then see if it's the second or after
532
+            var group = define_groups[index];
533
+            if (grouping) {
534
+              if (name in group && group_pattern == group[name].pattern && group_section == section) {
535
+                subitem = true;
536
+                sublabel = group_regex.exec(name)[1];
537
+              }
538
+              else
539
+                grouping = false;
540
+            }
541
+            // Start grouping?
542
+            if (!grouping && name in group) {
543
+              grouping = true;
544
+              subitem = false;
545
+              var grp = group[name];
546
+              group_pattern = grp.pattern;
547
+              group_class = 'one_of_' + grp.count;
548
+              label_text = grp.title;
549
+              group_regex = new RegExp(group_pattern);
550
+              group_section = section;
551
+              sublabel = group_regex.exec(name)[1];
552
+            }
553
+
445
             var $ff = $('#'+section), $newfield,
554
             var $ff = $('#'+section), $newfield,
446
-                avail = eval(inf.enabled),
555
+                avail = eval(inf.enabled);
447
-                $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
556
+
557
+            if (!(grouping && subitem)) {
558
+
559
+              var $newlabel = $('<label>',{for:name,class:'added'}).text(label_text.toLabel());
448
 
560
 
449
-            if (!avail) $newlabel.addClass('blocked');
561
+              $newlabel.unblock(avail);
450
 
562
 
451
-            // if (!(++n % 3))
563
+              // if (!(++n % 3))
452
-              $newlabel.addClass('newline');
564
+                $newlabel.addClass('newline');
453
 
565
 
454
-            $ff.append($newlabel);
566
+              $ff.append($newlabel);
567
+
568
+            }
455
 
569
 
456
             // Multiple fields?
570
             // Multiple fields?
457
             if (inf.type == 'list') {
571
             if (inf.type == 'list') {
458
               for (var i=0; i<inf.size; i++) {
572
               for (var i=0; i<inf.size; i++) {
459
                 var fieldname = i > 0 ? name+'-'+i : name;
573
                 var fieldname = i > 0 ? name+'-'+i : name;
460
-                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail});
574
+                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
461
-                if (!avail) $newfield.addClass('blocked');
575
+                if (grouping) $newfield.addClass(group_class);
462
                 $ff.append($newfield);
576
                 $ff.append($newfield);
463
               }
577
               }
464
             }
578
             }
478
               else {
592
               else {
479
                 $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
593
                 $newfield = inf.type == 'switch' ? $('<input>',{type:'checkbox'}) : $('<input>',{type:'text',size:10,maxlength:40});
480
               }
594
               }
481
-              $newfield.attr({id:name,name:name,class:'added',disabled:!avail});
595
+              $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
482
-              if (!avail) $newfield.addClass('blocked');
596
+              if (grouping) {
597
+                $newfield.addClass(group_class);
598
+                if (sublabel)
599
+                  $ff.append($('<span class="label"/>').text(sublabel.toTitleCase()).unblock(avail));
600
+              }
483
               // Add the new field to the form
601
               // Add the new field to the form
484
               $ff.append($newfield);
602
               $ff.append($newfield);
485
             }
603
             }
558
         this.initDefineList(init_index, txt);
676
         this.initDefineList(init_index, txt);
559
         // TODO: Find sequential names and group them
677
         // TODO: Find sequential names and group them
560
         //       Allows related settings to occupy one line in the form
678
         //       Allows related settings to occupy one line in the form
561
-          // this.refreshSequentialDefines();
679
+        this.refreshDefineGroups(init_index);
562
         // Build the dependent defines list
680
         // Build the dependent defines list
563
         this.initDependentGroups(); // all config text
681
         this.initDependentGroups(); // all config text
564
         // Get define_info for all known defines
682
         // Get define_info for all known defines
721
           var inf = define_info[this];
839
           var inf = define_info[this];
722
           if (inf && inf.enabled != 'true') {
840
           if (inf && inf.enabled != 'true') {
723
             var $elm = $('#'+this), ena = eval(inf.enabled);
841
             var $elm = $('#'+this), ena = eval(inf.enabled);
842
+            var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(this);
724
             // Make any switch toggle also
843
             // Make any switch toggle also
725
             $('#'+this+'-switch').attr('disabled', !ena);
844
             $('#'+this+'-switch').attr('disabled', !ena);
726
-            var alreadyEnabled = inf.type == 'switch' || self.defineIsEnabled(this);
845
+            $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
727
-            $elm.attr('disabled', !(ena && alreadyEnabled));
846
+            //self.log("Setting " + this + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
728
-            ena ? $elm.removeClass('blocked') : $elm.addClass('blocked');
729
             // Dim label for unavailable element
847
             // Dim label for unavailable element
730
-            var $lbl = $elm.prev('label');
848
+            $elm.prevAll('label, span.label').filter(':first').unblock(ena);
731
-            if ($lbl.length)
732
-              ena ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
733
           }
849
           }
734
         });
850
         });
735
       });
851
       });
745
 
861
 
746
       // Create a tooltip on the label if there is one
862
       // Create a tooltip on the label if there is one
747
       if (inf.tooltip) {
863
       if (inf.tooltip) {
748
-        var $tipme = $elm.prev('label');
864
+        // previous label or 
865
+        var $tipme = $elm.prevAll('label, span.label').filter(':first');
749
         if ($tipme.length) {
866
         if ($tipme.length) {
750
           $tipme.unbind('mouseenter mouseleave');
867
           $tipme.unbind('mouseenter mouseleave');
751
           $tipme.hover(
868
           $tipme.hover(
972
 
1089
 
973
       this.log('initFieldValue:' + name + ' to ' + val, 2);
1090
       this.log('initFieldValue:' + name + ' to ' + val, 2);
974
 
1091
 
975
-      // If the item has a checkbox then set enabled state too
1092
+      // If the item is switchable then set enabled state too
976
       var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
1093
       var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
977
       if ($cb.length) {
1094
       if ($cb.length) {
978
         on = self.defineIsEnabled(name);
1095
         on = self.defineIsEnabled(name);
983
         $.each(val.split(','),function(i,v){
1100
         $.each(val.split(','),function(i,v){
984
           var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
1101
           var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
985
           $e.val(v.trim());
1102
           $e.val(v.trim());
986
-          $e.attr('disabled', !on);
1103
+          $e.attr('disabled', !(on && avail)).unblock(avail);
987
-          avail ? $e.removeClass('blocked') : $e.addClass('blocked');
988
         });
1104
         });
989
       }
1105
       }
990
       else {
1106
       else {
991
         if (inf.type == 'toggle') val = val == inf.options[1];
1107
         if (inf.type == 'toggle') val = val == inf.options[1];
992
         $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
1108
         $elm.attr('type') == 'checkbox' ? $elm.prop('checked', val) : $elm.val(''+val);
993
-        $elm.attr('disabled', !on); // enable/disable the form field (could also dim it)
1109
+        $elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
994
-        avail ? $elm.removeClass('blocked') : $elm.addClass('blocked');
995
       }
1110
       }
996
 
1111
 
997
       // set label color
1112
       // set label color
998
-      var $lbl = $elm.prev('label');
1113
+      $elm.prevAll('label, span.label').filter(':first').unblock(avail);
999
-      avail ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
1000
     },
1114
     },
1001
 
1115
 
1002
     /**
1116
     /**

Loading…
Cancel
Save