Ver código fonte

Find fields that group together

- Do field grouping
- Tweak configurations for better grouping
Scott Lahteine 9 anos atrás
pai
commit
2eeb241b42

+ 10
- 8
Marlin/configurator/config/Configuration.h Ver arquivo

@@ -393,12 +393,12 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
393 393
 // @section machine
394 394
 
395 395
 // Travel limits after homing (units are in mm)
396
-#define X_MAX_POS 205
397 396
 #define X_MIN_POS 0
398
-#define Y_MAX_POS 205
399 397
 #define Y_MIN_POS 0
400
-#define Z_MAX_POS 200
401 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 403
 // @section hidden
404 404
 
@@ -535,12 +535,14 @@ const bool Z_MAX_ENDSTOP_INVERTING = true; // set to true to invert the logic of
535 535
 //#define MANUAL_HOME_POSITIONS  // If defined, MANUAL_*_HOME_POS below will be used
536 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 539
 // For deltabots this means top and center of the Cartesian print volume.
540
-#define MANUAL_X_HOME_POS 0
541
-#define MANUAL_Y_HOME_POS 0
542
-#define MANUAL_Z_HOME_POS 0
543
-//#define MANUAL_Z_HOME_POS 402 // For delta: Distance between nozzle and print surface after homing.
540
+#ifdef MANUAL_HOME_POSITIONS
541
+  #define MANUAL_X_HOME_POS 0
542
+  #define MANUAL_Y_HOME_POS 0
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 547
 // @section movement
546 548
 

+ 3
- 0
Marlin/configurator/config/Configuration_adv.h Ver arquivo

@@ -100,6 +100,9 @@
100 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 106
 //// AUTOSET LOCATIONS OF LIMIT SWITCHES
104 107
 //// Added by ZetaPhoenix 09-15-2012
105 108
 #ifdef MANUAL_HOME_POSITIONS  // Use manual limit switch locations

+ 36
- 5
Marlin/configurator/css/configurator.css Ver arquivo

@@ -91,7 +91,19 @@ label {
91 91
 	margin-right: -450px;
92 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 108
 input[type="text"], select { margin: 0.75em 0 0; }
97 109
 input[type="checkbox"], input[type="radio"], input[type="file"] { margin: 1em 0 0; }
@@ -104,10 +116,10 @@ input:disabled { color: #BBB; }
104 116
 
105 117
 input[type="text"].added { width: 20em; }
106 118
 label.added {
107
-	width: 275px; /* label area */
119
+	width: 265px; /* label area */
108 120
 	height: 1em;
109
-	padding: 10px 360px 10px 1em;
110
-	margin-right: -350px;
121
+	padding: 10px 370px 10px 1em;
122
+	margin-right: -360px;
111 123
 	text-align: right;
112 124
 	}
113 125
 
@@ -297,6 +309,16 @@ a.download, a.download-all {
297 309
 	}
298 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 322
 @media all and (min-width: 1140px) {
301 323
 
302 324
 	#main { max-width: 10000px; }
@@ -309,6 +331,15 @@ a.download-all { margin: 9px 2em 0; color: #449; border-color: #449; }
309 331
 
310 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 Ver arquivo

@@ -86,7 +86,7 @@ String.prototype.zeroPad = function(len)     { return this.prePad(len, '0'); };
86 86
 String.prototype.toHTML = function()         { return jQuery('<div>').text(this).html(); };
87 87
 String.prototype.regEsc = function()         { return this.replace(/[.?*+^$[\]\\(){}|-]/g, "\\$&"); }
88 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 90
 String.prototype.toTitleCase = function()    { return this.replace(/([A-Z])(\w+)/gi, function(m,p1,p2) { return p1.toUpperCase() + p2.toLowerCase(); }); }
91 91
 Number.prototype.limit = function(m1, m2)  {
92 92
   if (m2 == null) return this > m1 ? m1 : this;
@@ -124,6 +124,10 @@ $.fn.extend({
124 124
             .attr('unselectable', 'on')
125 125
             .css('user-select', 'none')
126 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,6 +148,7 @@ window.configuratorApp = (function(){
144 148
       $config = $cfg.find('pre'), $config_adv = $adv.find('pre'),
145 149
       define_info = {},
146 150
       define_list = [[],[]],
151
+      define_groups = [{},{}],
147 152
       define_section = {},
148 153
       dependentGroups = {},
149 154
       boards_list = {},
@@ -354,17 +359,93 @@ window.configuratorApp = (function(){
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 438
      * Get all condition blocks and their line ranges.
358 439
      * Conditions may control multiple line-ranges
359 440
      * across both config files.
360 441
      */
361 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 444
           leave_out_defines = ['CONFIGURATION_H', 'CONFIGURATION_ADV_H'];
364 445
       $.each([$config, $config_adv], function(i, $v) {
365 446
         var ifStack = [];
366 447
         var r, txt = $v.text();
367
-        while((r = findDef.exec(txt)) !== null) {
448
+        while((r = findBlock.exec(txt)) !== null) {
368 449
           var lineNum = txt.substr(0, r.index).lineCount();
369 450
           var code = r[2].replace(/[ \t]*\/\/.*$/, '');
370 451
           switch(r[1]) {
@@ -431,34 +512,67 @@ window.configuratorApp = (function(){
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 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 522
         var section = define_section[name];
440 523
         if (section != 'hidden' && !$('#'+name).length) {
441 524
           var inf = define_info[name];
442 525
 
443 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 554
             var $ff = $('#'+section), $newfield,
446
-                avail = eval(inf.enabled),
447
-                $newlabel = $('<label>',{for:name,class:'added'}).text(name.toLabel());
555
+                avail = eval(inf.enabled);
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))
452
-              $newlabel.addClass('newline');
563
+              // if (!(++n % 3))
564
+                $newlabel.addClass('newline');
453 565
 
454
-            $ff.append($newlabel);
566
+              $ff.append($newlabel);
567
+
568
+            }
455 569
 
456 570
             // Multiple fields?
457 571
             if (inf.type == 'list') {
458 572
               for (var i=0; i<inf.size; i++) {
459 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});
461
-                if (!avail) $newfield.addClass('blocked');
574
+                $newfield = $('<input>',{type:'text',size:6,maxlength:10,id:fieldname,name:fieldname,class:'subitem added',disabled:!avail}).unblock(avail);
575
+                if (grouping) $newfield.addClass(group_class);
462 576
                 $ff.append($newfield);
463 577
               }
464 578
             }
@@ -478,8 +592,12 @@ window.configuratorApp = (function(){
478 592
               else {
479 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});
482
-              if (!avail) $newfield.addClass('blocked');
595
+              $newfield.attr({id:name,name:name,class:'added',disabled:!avail}).unblock(avail);
596
+              if (grouping) {
597
+                $newfield.addClass(group_class);
598
+                if (sublabel)
599
+                  $ff.append($('<span class="label"/>').text(sublabel.toTitleCase()).unblock(avail));
600
+              }
483 601
               // Add the new field to the form
484 602
               $ff.append($newfield);
485 603
             }
@@ -558,7 +676,7 @@ window.configuratorApp = (function(){
558 676
         this.initDefineList(init_index, txt);
559 677
         // TODO: Find sequential names and group them
560 678
         //       Allows related settings to occupy one line in the form
561
-          // this.refreshSequentialDefines();
679
+        this.refreshDefineGroups(init_index);
562 680
         // Build the dependent defines list
563 681
         this.initDependentGroups(); // all config text
564 682
         // Get define_info for all known defines
@@ -721,15 +839,13 @@ window.configuratorApp = (function(){
721 839
           var inf = define_info[this];
722 840
           if (inf && inf.enabled != 'true') {
723 841
             var $elm = $('#'+this), ena = eval(inf.enabled);
842
+            var isEnabled = (inf.type == 'switch') || self.defineIsEnabled(this);
724 843
             // Make any switch toggle also
725 844
             $('#'+this+'-switch').attr('disabled', !ena);
726
-            var alreadyEnabled = inf.type == 'switch' || self.defineIsEnabled(this);
727
-            $elm.attr('disabled', !(ena && alreadyEnabled));
728
-            ena ? $elm.removeClass('blocked') : $elm.addClass('blocked');
845
+            $elm.attr('disabled', !(ena && isEnabled)).unblock(ena);
846
+            //self.log("Setting " + this + " to " + (ena && isEnabled ? 'enabled' : 'disabled'));
729 847
             // Dim label for unavailable element
730
-            var $lbl = $elm.prev('label');
731
-            if ($lbl.length)
732
-              ena ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
848
+            $elm.prevAll('label, span.label').filter(':first').unblock(ena);
733 849
           }
734 850
         });
735 851
       });
@@ -745,7 +861,8 @@ window.configuratorApp = (function(){
745 861
 
746 862
       // Create a tooltip on the label if there is one
747 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 866
         if ($tipme.length) {
750 867
           $tipme.unbind('mouseenter mouseleave');
751 868
           $tipme.hover(
@@ -972,7 +1089,7 @@ window.configuratorApp = (function(){
972 1089
 
973 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 1093
       var $cb = $('#'+name+'-switch'), avail = eval(inf.enabled), on = true;
977 1094
       if ($cb.length) {
978 1095
         on = self.defineIsEnabled(name);
@@ -983,20 +1100,17 @@ window.configuratorApp = (function(){
983 1100
         $.each(val.split(','),function(i,v){
984 1101
           var $e = i > 0 ? $('#'+name+'-'+i) : $elm;
985 1102
           $e.val(v.trim());
986
-          $e.attr('disabled', !on);
987
-          avail ? $e.removeClass('blocked') : $e.addClass('blocked');
1103
+          $e.attr('disabled', !(on && avail)).unblock(avail);
988 1104
         });
989 1105
       }
990 1106
       else {
991 1107
         if (inf.type == 'toggle') val = val == inf.options[1];
992 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)
994
-        avail ? $elm.removeClass('blocked') : $elm.addClass('blocked');
1109
+        $elm.attr('disabled', !(on && avail)).unblock(avail); // enable/disable the form field (could also dim it)
995 1110
       }
996 1111
 
997 1112
       // set label color
998
-      var $lbl = $elm.prev('label');
999
-      avail ? $lbl.removeClass('blocked') : $lbl.addClass('blocked');
1113
+      $elm.prevAll('label, span.label').filter(':first').unblock(avail);
1000 1114
     },
1001 1115
 
1002 1116
     /**

Carregando…
Cancelar
Salvar