summaryrefslogtreecommitdiffabout
path: root/delta.jscad
blob: b46534aeda97f24a7f51c2d4bb4527d44e9d886e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
var PRINT = {
 layer_height: 0.2,
 extrusion_width: 0.4,

 fit_tolerance: .2, slide_tolerance: .4, play_tolerance: .6, screw_tolerance: .3
};

var CONFIG = {
 extrusion: {
  w: 20, slotdepth: 6
 },
 base: {
  el: 240,		// side extrusion length
  sl: 240+2*70,		// triangle side length
  gap: 9		// vertical gap between side extrusions
 },
 column: {
  h: 600		// column height
 },
 heatbed: {
  r: 220/2,		// heatbed radius
  sr: 220/2-4.5,	// radius of the screwholes circle
  h: 3+1.5		// thickness (including insulation)
 },
 glass: {
  r: 195/2,		// glass radius
  h: 3			// glass thickness
 },
 duet: {
  pcb_size: { x: 124, y: 100, z: 1 },
  hole_spacing: { x: 115, y: 92 },
  h: 30
 },
 foot: {
  d: 20*Math.sqrt(2), h: 30,
  bolt: { d:5, l: 19, hd: 10 },
  margin: 2.5,
  nut: { d: 8.6 /* TODO: */, h: 3.5 },
  shell: 4,
  zscalefactor: 1.6,
  foot: { ho: 2.5, hi: 5 }
 },
 duetholder: {
  bolt: { d: 3, l: 10, head: { d: 5.33, h: 3 } },
  margin: 3,
  s: 2.5
 },
 bedholder: {
  h: 15,
  margin: 3,
  nut: { w: 5.4, h: 2.5 },
  bolt: { d: 3, l: 10, head: { d: 5.33, h: 3 } }
 },
 hotend: {
  h: 62.4, 			// full assembly height
  groove: { d:12, h:6 }, 	// grove diameter and height
  ungroove: { d:16, above:3.7, below: 3+4 }
 },
 effector: {
  h: 6,
  o: 20,	// offset to the rod mounts line
  rods_apart: 40,
  cone: { shell: 1, angle: Math.PI/6 },
  rodend: {
   joint_w: 7,	// thickness of the joint
   screw_l: 20-1, // 20 with the head
   screw_d: 3
  },
  hotend: { margin: 2 },
  hinge: {
   d: 3, w: 5, margin: 2.5,
   h: 1+(6+3.7)/2, // elevation + grove + top
   e: 1 // elevation
  },
  clamp: {
   shell: 4.6,
   d: 3,
   margin: 2.5,
   split: 0.6
  },
  mswitch: {
   size: [ 19.8, 6, 10 ],
   screw: {
    d: 2, h: 10/2-2,
    s: 1.3, // screw shell
    o: [-9.5/2,9.5/2].map(function(x) {
     return -19.8/2+x;
    })
   },
   switch_x: 2.5
  },
  guide: {
   width: 3, height: 5+1, length: 6
  },
  fanholder: {
   r: 30,
   screw: { d: 3, m: 2.5/*margin*/ },
   w: 3
  }
 },
 nut: { h: 2.3, w: 5.5 },
 color: {
  extrusion: [0.8, 0.8, 0.8, 0.8],
  pcb: [ 0, 0.3, 0.2, 0.8 ],
  bulk: [ .9, .9, .9, .2 ],
  parts: [ 0, 0.8, 0, 0.9 ],
  softparts: [ 0, 0, 0.8, 0.9 ],
  heatbed: [0.8, 0.8, 0.8, 0.8 ],
  glass: [0.9, 0.9, 0.9, 0.7 ]
 }
};

var CD = {
 base: (function(){
  var rv = {};
  rv.circumscription_r =
   CONFIG.base.sl/2/Math.cos(Math.PI/6);
  rv.outer_inscription_r =
   Math.sqrt(Math.pow(rv.circumscription_r,2)-
    Math.pow(CONFIG.base.sl/2,2));
  rv.mid_inscription_r =
    rv.outer_inscription_r-CONFIG.extrusion.w/2;
  rv.inner_inscription_r =
    rv.outer_inscription_r-CONFIG.extrusion.w;
  // TODO: properly calculate
  rv.column_r = rv.circumscription_r - 48.29;
  return rv;
 })(),
 duetholder: (function() {
  var rv = {};
  var s = CONFIG.base.sl;
  var l = CONFIG.duet.hole_spacing.x;
  var w = CONFIG.duet.hole_spacing.y;
  var h = s*Math.cos(Math.PI/6);
  var h1 = h*(1-l/s);
  rv.distance = (h1-w)/3; // hole to side
  return rv;
 })()
};
console.log(CONFIG); console.log(CD);

var U = {
 hypotenuse: function(a,b) {
  return Math.sqrt(Math.pow(a,2)+Math.pow(b,2));
 },
 peek: function(x,m) {
  console.log(x,m);
  return x;
 },
 axes: function U_axes(o) {
  if(!o) o = {};
  var l = o.l||20, g = o.g||0.7;
  return union([
   CSG.roundedCylinder({start:[0,0,0],end:[l,0,0]}).setColor([1,0,0,g]),
   CSG.roundedCylinder({start:[0,0,0],end:[0,l,0]}).setColor([0,1,0,g]),
   CSG.roundedCylinder({start:[0,0,0],end:[0,0,l]}).setColor([0,0,1,g])
  ]);
 },
 pextract: function U_pextract(a,pn) { // TODO: monkeypatch Array
  return a.map(function(x){return x[pn]});
 },
 hole: function U_hole(o) {
  var r = o.r||o.radius||(o.d/2)||(o.diameter/2);
  var n = Math.max(Math.round(4*r),4);
  return CSG.cylinder({
   start: o.start, end: o.end,
   radius: r/Math.cos(Math.PI/n),
   resultion: n
  });
 },

 upright: function U_upright() { return new CSG.Connector([0,0,0],[0,0,1],[1,0,0]) },
 downright: function U_downright() { return new CSG.Connector([0,0,0],[0,0,-1],[1,0,0]) },
 P: function U_P(x) {
  if(!x.properties.P) return x;
  return x.connectTo(x.properties.P,U.upright(),false,0);
 }
 
};

/* {h:,w:} */
function nut(o) {
 var rv = CSG.cylinder({
  start:[0,0,0],end:[0,0,o.h],
  radius: o.w/2/Math.cos(Math.PI/6),
  resolution: 6
 });
 rv.properties.axis_connector = new CSG.Connector([0,0,0],[0,0,1],[0,1,0]);
 return rv;
}

var E3DV6 = {
 dimensions: {
  big_d: 22.3,

 },
 heatsink: function() {
  var fn = 16;
  var z=0;
  var unite = [ {d:16,h:3.7},{d:12,h:6},{d:16,h:3} ].map(function(x) {
   return CSG.cylinder({
    start: [0,0,z], end: [0,0,z-=x.h],
    radius: x.d/2, resolution: fn
   });
  });
  unite.push(CSG.cylinder({
   start:[0,0,z-=1.5], end:[0,0,z-=1],
   radius: 16/2, resolution: fn
  }));
  for(var i=0;i<11;++i) unite.push(CSG.cylinder({
   start:[0,0,z-=1.5], end:[0,0,z-=1],
   radius: this.dimensions.big_d/2, resolution: fn
  }));
  unite.push(CSG.cylinder({
   start:[0,0,z], end: [0,0,-12.7],
   radiusStart: 10/2, radiusEnd: 8.5/2, /* pretty arbitrary */
   resolution: fn
  }));
  var rv = union(unite);
  rv = rv.subtract([CSG.cylinder({
   start:[0,0,1], end: [0,0,z-1],
   radius: 4.2/2, resolution: fn
  }),CSG.cylinder({
   start:[0,0,1], end: [0,0,-6.7/*somewhat arbitrary*/],
   radius: 8/2, resolution: fn
  }),CSG.cylinder({
   start:[0,0,z-1], end: [0,0,z+14.8],
   radius: 6/2 /*M7*/, resolution: fn
  })]);
  rv.properties.pushfit_connector = new CSG.Connector([0,0,0],[0,0,-1],[1,0,0]);
  rv.properties.heatbreak_connector = new CSG.Connector([0,0,z+14.8],[0,0,-1],[1,0,0]);
  rv.properties.grove_connector = new CSG.Connector([0,0,-3.7-3],[0,0,1],[1,0,0]);
  return rv.setColor([0.8,0.8,0.8,0.9]);
 }
};

var EFFECTOR = {
 /* {sd: screw diameter, l: cone length, s: screw shell, a: angle from axis} */
 cone: function effector_cone(o) {
  var re = o.sd/2+o.s, rs = re+o.l*Math.tan(o.a||(Math.PI/4));
  var rv = CSG.cylinder({
   start: [0,0,0], end: [0,0,o.l],
   radiusStart: rs, radiusEnd: re,
   resolution: Math.floor(rs*2*2)
  }).subtract(CSG.cylinder({
   start:[0,0,-1], end:[0,0,o.l+1], radius: o.sd,
   //resolution: Math.floor(o.sd*2*2)
  }));
  rv.properties.top_connector = new CSG.Connector([0,0,o.l],[0,0,-1],[1,0,0]);
  rv.properties.bottom_connector = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  var nuthole = nut(CONFIG.nut);
  rv = rv.subtract(nuthole.connectTo(
   nuthole.properties.axis_connector, rv.properties.bottom_connector,
   false, 0
  ));
  return rv.intersect(CSG.cylinder({start:[0,0,0],end:[0,0,o.l],radius:6/*TODO:calculate*/}));
 },
 platform_bb: function platform_bb() {
  var e = CONFIG.effector;
  var r = U.hypotenuse(e.rods_apart/2,e.o+e.rodend.screw_d/2+e.cone.shell);
  var rv = CSG.sphere({
   center: [0,0,e.h/2], radius: r,
   resolution: r*2*2
  }).intersect(CSG.cube({
   corner1: [-r,-r,0], corner2: [r,r,e.h]
  }));
  rv.properties.base_connector = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  return rv;
 },
 effector: function effector_effector() {
  var e = CONFIG.effector;
  var conel = e.rodend.screw_l-e.rodend.joint_w;
  var nutr = CONFIG.nut.w/2/Math.cos(Math.PI/6);
  var cone = this.cone({sd:e.rodend.screw_d/2,l:conel,s:e.cone.shell,a:e.cone.angle});
  var rcorner = U.hypotenuse(e.o-e.rodend.screw_d/2-e.cone.shell,e.rods_apart/2)-3.85; //XXX:config/calc
  var ropen = E3DV6.dimensions.big_d/2+e.hotend.margin;
  var rmount = this.rmount = (rcorner+ropen)/2;
  var rv = [];
  for(var a=0;a<360;a+=120) {
   rv.push(union([-1,1].map(function(s) {
    return cone.connectTo(cone.properties.top_connector,
     new CSG.Connector([s*e.rods_apart/2,e.o,e.h/2],[-s,0,0],[0,0,1]),
     false, 0);
   })).union(CSG.cube({
    corner1:[e.rods_apart/2-conel+.1,e.o-nutr,0],
    corner2:[-e.rods_apart/2+conel-.1,
     -rcorner,
     e.h]
   })).rotateZ(a));
  }
  rv.push(CSG.cylinder({
   start:[0,0,0], end:[0,0,e.h],
   radius: U.hypotenuse(e.o-nutr,e.rods_apart/2-conel)
  }));
  rv = union(rv).intersect(this.platform_bb()).subtract(CSG.cylinder({
   start:[0,0,-1], end:[0,0,e.h+1],
   radius: ropen, resolution: ropen*4
  })).subtract([/*0, probe here*/120,240].map(function(x) { /* nut pockets */
   return CSG.cube({
    corner1:[-CONFIG.nut.w/2,0,(e.h-CONFIG.nut.h)/2],
    corner2:[CONFIG.nut.w/2,-rcorner-1,(e.h+CONFIG.nut.h)/2]
   }).union(CSG.cylinder({
    start:[0,-rmount,-1], end:[0,-rmount,e.h+1],
    radius: 3/2 // XXX:
   })).subtract(CSG.cylinder({
    start:[0,-rmount,(e.h+CONFIG.nut.h)/2],
    end:[0,-rmount,(e.h+CONFIG.nut.h)/2+PRINT.layer_height*3/2],
    radius: 3/2+.1
   })).rotateZ(x);
  })).subtract( CSG.cylinder({ // pulldown screw
   start: [0,-rcorner+e.mswitch.size[1]+PRINT.extrusion_width+3/2/*XXX:conf*/,-1],
   end: [0,-rcorner+e.mswitch.size[1]+PRINT.extrusion_width+3/2/*XXX:conf*/,e.h+1],
   radius: 3/2+1 /*XXX: config */
  })).subtract( CSG.cylinder({ /* switch-screw */
   start: [e.mswitch.switch_x,-rcorner+e.mswitch.size[1]/2,-1],
   end: [e.mswitch.switch_x,-rcorner+e.mswitch.size[1]/2,e.h+1],
   radius: e.mswitch.screw.d/2
  }));
  // add hinges
  rv.properties.hinge_connector=new CSG.Properties();
  var hinges_apart=e.rods_apart/2-conel;
  rv = rv.union([-1,1].map(function hinge(s) {
   rv.properties.hinge_connector[s]=new CSG.Connector([s*hinges_apart,e.o,e.h+e.hinge.h],[s,0,0],[0,0,1]);
   return CSG.cube({
    corner1: [s*hinges_apart,e.o-e.hinge.margin-e.hinge.d/2,e.h],
    corner2: [s*(hinges_apart+e.hinge.w),e.o+e.hinge.margin+e.hinge.d/2,e.h+e.hinge.h]
   }).union(CSG.cylinder({
    start: [s*hinges_apart,e.o,e.h+e.hinge.h],
    end: [s*(hinges_apart+e.hinge.w),e.o,e.h+e.hinge.h],
    radius: e.hinge.d/2+e.hinge.margin
   })).subtract(CSG.cylinder({
    start: [s*(hinges_apart-1),e.o,e.h+e.hinge.h],
    end: [s*(hinges_apart+e.hinge.w+1),e.o,e.h+e.hinge.h],
    radius: e.hinge.d/2
   }));
  }));
  // add clamp guides
  var cgrr = e.guide.width/3;
  rv = rv.union([-1,1].map(function guide(s) {
   return CSG.roundedCube({
    center: [s*(e.mswitch.size[0]+PRINT.slide_tolerance+e.guide.width)/2,-rcorner+e.guide.length/2,e.h+e.guide.height/2-cgrr],
    radius: [e.guide.width/2,e.guide.length/2,e.guide.height/2+cgrr],
    roundradius: cgrr
   }).intersect(CSG.cube({
     center: [s*(e.mswitch.size[0]+PRINT.slide_tolerance+e.guide.width)/2,-rcorner+e.guide.length/2,e.h+e.guide.height/2],
     radius: [e.guide.width/2,e.guide.length/2,e.guide.height/2+.1],
     roundradius: cgrr
   }));
  }));
  rv.properties.grove_connector = new CSG.Connector([0,0,e.h+e.hinge.e+6/2],[0,0,1],[1,0,0]);
  rv.properties.rcorner = rcorner;
  return rv.setColor([0.4,0.8,0.4,0.9]);
 },
 hinged: function effector_hinged(o) {
  var e = CONFIG.effector;
  var conel = e.rodend.screw_l-e.rodend.joint_w;
  var hinges_apart = e.rods_apart/2-conel;
  var hhr = e.o-e.hinge.d/2-e.hinge.margin; // hotend holder radius
  var hhh = CONFIG.hotend.groove.h+CONFIG.hotend.ungroove.above;
  var rv = CSG.cylinder({ /* hinge */
   start: [-hinges_apart+PRINT.slide_tolerance,e.o,e.h+e.hinge.h],
   end: [hinges_apart-PRINT.slide_tolerance,e.o,e.h+e.hinge.h],
   radius: e.hinge.d/2+e.hinge.margin
  }).union( /* lower hotend holder */
   CSG.cylinder({
    start: [0,0,e.h+e.hinge.e], end: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h],
    radius: hhr
   }).subtract(CSG.cylinder({
    start: [0,0,e.h+e.hinge.e-1], end: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h+1],
    radius: CONFIG.hotend.groove.d/2 +PRINT.fit_tolerance
   }))
  ).union( /* upper hotend holder */
   CSG.cylinder({
    start: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h],
    end: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h+CONFIG.hotend.ungroove.above],
    radius: hhr
   }).subtract(CSG.cylinder({
    start: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h-1],
    end: [0,0,e.h+e.hinge.e+CONFIG.hotend.groove.h+CONFIG.hotend.ungroove.above+1],
    radius: CONFIG.hotend.ungroove.d/2 +PRINT.fit_tolerance
   }))
  ).union( /* connect mount with hinge */
   CSG.cube({
    corner1: [-hinges_apart+PRINT.slide_tolerance,CONFIG.hotend.ungroove.d/2+PRINT.fit_tolerance,e.h+e.hinge.e],
    corner2: [hinges_apart-PRINT.slide_tolerance,e.o,e.h+e.hinge.h+e.hinge.d/2+e.hinge.margin]
   })
  ).subtract( /* hinge screwhole */
   CSG.cylinder({
    start: [-hinges_apart-1,e.o,e.h+e.hinge.h],
    end: [hinges_apart+1,e.o,e.h+e.hinge.h],
    radius: e.hinge.d/2
   })
  ).union( /* hold clamp together */
   [-1,1].map(function(s) {
    return CSG.roundedCube({
     corner1: [s*(-hhr-e.clamp.margin*2-e.clamp.d),-e.clamp.shell,e.h+e.hinge.e],
     corner2: [s*(-CONFIG.hotend.ungroove.d/2-PRINT.fit_tolerance),+e.clamp.shell,e.h+e.hinge.e+hhh],
     roundradius: 1.5
    });
   })
  ).subtract( /* screws for holding clamp */
   [-1,1].map(function(s) {
    var nuthole = nut(CONFIG.nut);
    var x = s*(-hhr-e.clamp.margin-e.clamp.d/2);
    return CSG.cylinder({
     start: [x,-e.clamp.shell-1,e.h+e.hinge.e+hhh/2],
     end: [x,e.clamp.shell+1,e.h+e.hinge.e+hhh/2],
     radius: e.clamp.d/2
    }).union(nuthole.connectTo(
     nuthole.properties.axis_connector,
     new CSG.Connector([x,e.clamp.shell,e.h+e.hinge.e+hhh/2],[0,-1,0],[0,0,1]),
     false, 0
    )).union(CSG.cylinder({
     start: [x,-e.clamp.shell-1,e.h+e.hinge.e+hhh/2],
     end: [x,0,e.h+e.hinge.e+hhh/2],
     radius: e.clamp.d/2+PRINT.slide_tolerance
    }));
   })
  );
  var ms = o.microswitch;
  var msedge = o.effector.properties.rcorner;
  var msh = 9.5; // microswitch holes apart
  var mshh = Math.abs(ms.properties.switch_connector.point.z-ms.properties.screw_connector[0].point.z); // microswitch holes height
  rv = rv.union(CSG.cube({ // connect clamp with microswitch
   corner1: [-ms.properties.microswitch.size.x/2,-msedge+.1,e.h+e.hinge.e],
   corner2: [+ms.properties.microswitch.size.x/2,-CONFIG.hotend.ungroove.d/2-PRINT.fit_tolerance,e.h+e.hinge.e+hhh]
  })).union([-msh/2,msh/2].map(function(x) { // shell for microswitch screws
    return CSG.roundedCylinder({
     start: [x,-CONFIG.hotend.ungroove.d/2-PRINT.fit_tolerance-(e.mswitch.screw.d/2+e.mswitch.screw.s),e.h+e.hinge.e+mshh],
     end: [x,-msedge+ms.properties.microswitch.size.y,e.h+e.hinge.e+mshh],
     radius: e.mswitch.screw.d/2+e.mswitch.screw.s
    });
  })).subtract(CSG.cube({ // cut off excess if any
   corner1:[-hhr,-msedge+ms.properties.microswitch.size.y,e.h+e.hinge.e-1],
   corner2:[hhr,-msedge-1,e.h+e.hinge.e+hhh+e.mswitch.screw.d+e.mswitch.screw.s+1]
  })).subtract([-msh/2,msh/2].map(function(x) { return CSG.roundedCylinder({ // screwholes
   start: [x,-CONFIG.hotend.ungroove.d/2-PRINT.fit_tolerance-(e.mswitch.screw.d/2+e.mswitch.screw.s),e.h+e.hinge.e+mshh],
   end: [x,-msedge+ms.properties.microswitch.size.y,e.h+e.hinge.e+mshh],
   radius: e.mswitch.screw.d/2
  })})).subtract(CSG.cylinder({ // pulldown screw
   start:[0,-msedge+ms.properties.microswitch.size.y+3/2/*XXX:config*/+PRINT.extrusion_width,e.h+e.hinge.e-1],
   end:[0,-msedge+ms.properties.microswitch.size.y+3/2/*XXX:config*/+PRINT.extrusion_width,e.h+e.hinge.e+hhh+1],
   radius: 3/2/*XXX:config*/
  }));
  rv.properties.microswitch_screw_connector = new CSG.Properties();
  [-msh/2,msh/2].forEach(function(x,i) {
   rv.properties.microswitch_screw_connector[i] = new CSG.Connector(
    [x,-msedge,e.h+e.hinge.e+mshh],
    [0,1,0], [0,0,-1]
   );
  });
  return rv.setColor([0.3,0.8,0.3,0.9]);
 },
 split_hinged: function effector_split_hinged(hinged) {
  var e = CONFIG.effector;
  var b = hinged.getBounds();
  var ymax = Math.max(Math.abs(b[0].y),Math.abs(b[1].y));
  var zmax = Math.max(b[0].z,b[1].z);
  return [-1,1].map(function(s) {
   return hinged.intersect(CSG.cube({
    corner1: [Math.min(b[0].x,b[1].x)-1,s*e.clamp.split/2,-zmax-1],
    corner2: [Math.max(b[0].x,b[1].x)+1,s*(ymax+1),zmax+1]
   }));
  });
 },
 fanholder: function effector_fanholder() {
  var fh = CONFIG.effector.fanholder;
  var od = fh.screw.d+2*fh.screw.m;
  var rv = linear_extrude({height:fh.w},hull(
   CAG.circle({center:[0,-this.rmount],radius:od/2}),
   CAG.circle({center:[0,-fh.r+od/2+fh.w/2],radius:fh.w/2})
  )).translate([0,0,-fh.w]).union(
   linear_extrude({height:fh.w},hull(
    CAG.circle({center:[fh.w/2,-this.rmount-od/2-fh.w/2],radius:fh.w/2}),
    CAG.circle({center:[od/2,-fh.r],radius:od/2})
   )).rotateY(90).translate([-fh.w/2,0,0])
  ).subtract( CSG.cylinder({
   start: [-fh.w,-fh.r,-od/2],
   end: [fh.w,-fh.r,-od/2],
   radius: fh.screw.d/2
  })).subtract( CSG.cylinder({
   start: [0,-this.rmount,1],
   end: [0,-this.rmount,-fh.w-1],
   radius: fh.screw.d/2
  }));
  rv.properties.P = new CSG.Connector([0,0,0],[0,0,-1],[1,0,0]);
  return rv.setColor([0.3,0.8,0.3,0.9]).rotateZ(-120);
 }
};

function columns() {
 var rv = [0,1,2].map(function(x) {
  return union(vector_char(0,0,String.fromCharCode('A'.charCodeAt(0)+x)).segments.map(function(x) {
   return rectangular_extrude(x,{w:2,h:1});
  })).center().rotateX(90).translate([0,50,0]).rotateZ(x*120+120);
 });
 return union(rv);
}

function microswitch() {
 var screw_connector = new CSG.Properties();
 var rv = CSG.cube({ center:[0,0,2.5],radius: [19.8/2,6/2,10/2] }).union(
  CSG.cube({ center: [2.5,0.5,6], radius: [2/2,3.5/2,5/2] })
 ).union(
  [-8,-1,8].map(function(x) {
   return CSG.cube({ center:[x,0,0], radius: [0.6/2,3.2/2,13/2] })
  })
 ).subtract(
  [-9.5/2,9.5/2].map(function(x,i) {
   screw_connector[i] = new CSG.Connector([x,6/2,0],[0,-1,0],[0,0,1]);
   return CSG.cylinder({
    start: [x,-4,0], end: [x,4,0],
    radius: 2/2
   })
  })
 );
 rv.properties.switch_connector = new CSG.Connector([2.5,0.5,6+5/2],[0,0,1],[0,-1,0]);
 rv.properties.screw_connector = screw_connector;
 rv.properties.microswitch = new CSG.Properties();
 rv.properties.microswitch.size = new CSG.Vector3D(
  19.8,6,10
 );
 return rv;
}

var FOURWINDS = [0,90,180,270];

var E2020 = {
 outer: 20, thickness: 1.8,
 roundius: 1, centerhole: 5,
 slot_width: 6,
 T: { width: 10, thickness: 1.5, depth: 6.5 },

 extrusion: function(o) {
  if(!o) o = {};
  var e = o.extrusion || this;
  var l = o.l||5;
  var iy = e.outer/2-e.T.depth;
  var ix = e.T.width/2-(e.outer/2-iy-e.thickness-e.T.thickness);
  var rv = CAG.roundedRectangle({
   corner1: [-e.outer/2,-e.outer/2], corner2: [e.outer/2,e.outer/2],
   roundradius: e.roundius
  }).subtract(
   FOURWINDS.map(function(w) {
    return CAG.fromPoints([
     [  e.slot_width/2,e.outer/2+1],
     [  e.slot_width/2,e.outer/2-e.thickness],
     [  e.T.width/2,e.outer/2-e.thickness],
     [  e.T.width/2,e.outer/2-e.thickness-e.T.thickness],
     [  ix, iy ],
     [ -ix, iy ],
     [ -e.T.width/2,e.outer/2-e.thickness-e.T.thickness],
     [ -e.T.width/2,e.outer/2-e.thickness],
     [ -e.slot_width/2,e.outer/2-e.thickness],
     [ -e.slot_width/2,e.outer/2+1],
    ]).rotateZ(w);
   })
  ).subtract(CAG.circle({
   center: [0,0], radius: e.centerhole/2
  })).extrude({offset:[0,0,l]});
  rv.properties.c_top=rv.properties.c_left
   = new CSG.Connector([0,0,l],[0,0,-1],[1,0,0]);
  rv.properties.c_bottom=rv.properties.c_right
   = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  rv.properties.c_midway = new CSG.Connector([0,0,l/2],[0,0,1],[1,0,0]);
  rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  rv.properties.vitamin = true;
  return rv;
 },

 cap: function extrusion_cap(o) {
  if(!o) o = {};
  var e = o.extrusion || this;
  var thickness = o.thickness||2, l = o.l||5;
  var rv = CSG.roundedCube({
   corner1: [-e.outer/2,-e.outer/2,thickness],
   corner2: [e.outer/2,e.outer/2,0],
   roundradius: [e.roundius,e.roundius,0]
  });
  var fw = [0,90,180,270]; // four winds
  var iy = e.outer/2-e.T.depth;
  var ix = e.T.width/2-(e.outer/2-iy-e.thickness-e.T.thickness);
  rv = rv.union(fw.map(function(w) {
   return CAG.fromPoints([
    [  e.slot_width/2,e.outer/2],
    [  e.slot_width/2,e.outer/2-e.thickness],
    [  e.T.width/2,e.outer/2-e.thickness],
    [  e.T.width/2,e.outer/2-e.thickness-e.T.thickness],
    [  ix, iy ],
    [ -ix, iy ],
    [ -e.T.width/2,e.outer/2-e.thickness-e.T.thickness],
    [ -e.T.width/2,e.outer/2-e.thickness],
    [ -e.slot_width/2,e.outer/2-e.thickness],
    [ -e.slot_width/2,e.outer/2],
   ]).extrude({offset:[0,0,l+thickness]}).rotateZ(w);
  }));
  rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  return rv;
 }
};

var THREEWINDS = [0,120,240];

function base_sides() {
 return [0,1].map(function(l) {
  return THREEWINDS.map(function(w) {
   var e = E2020.extrusion({l:CONFIG.base.el});
   e = e.connectTo(e.properties.c_midway,
    new CSG.Connector([0,-CD.base.mid_inscription_r,CONFIG.extrusion.w/2],[1,0,0],[0,0,1]),
    false, 0);
   return ( e.translate([0,0,CONFIG.foot.h+l*(CONFIG.extrusion.w+CONFIG.base.gap)])
    .rotateZ(w)
    .setColor(CONFIG.color.extrusion) );
  });
 });
}
function base_extrusions() {
 var rv = union( base_sides().map(function(x){return union(x)}) );
 rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 return rv;
}

function columns() {
 return THREEWINDS.map(function(w) {
  return (E2020.extrusion({l:CONFIG.column.h})
   .translate([0,CD.base.column_r,CONFIG.foot.h])
   .rotateZ(w).setColor(CONFIG.color.extrusion)
  );
 });
}
function column_extrusions() {
 var rv = union( columns() );
 rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 return rv;
}

function duet() {
 var C = CONFIG.duet;
 var pholes = new CSG.Properties();
 var hx = C.hole_spacing.x/2;
 var hy = C.hole_spacing.y/2;
 var hh = { nw: [-1,1], ne: [1,1], se: [1,-1], sw: [-1,-1] };
 var holes = [];
 for(w in hh) {
  var h = hh[w],_x=h[0]*hx,_y=h[1]*hy;
  holes.push(CSG.cylinder({start:[_x,_y,-1],end:[_x,_y,C.pcb_size.z+1],radius:3/2}));
  pholes['c_'+w] = new CSG.Connector([_x,_y,0],[0,0,1],[1,0,0]);
 }
 rv = CSG.cube({
  corner1: [-C.pcb_size.x/2, -C.pcb_size.y/2,            0],
  corner2: [ C.pcb_size.x/2,  C.pcb_size.y/2, C.pcb_size.z]
 }).subtract(holes).setColor(CONFIG.color.pcb).union(
  CSG.cube({
   corner1: [-C.pcb_size.x/2,-C.hole_spacing.y/2+3,C.pcb_size.z],
   corner2: [ C.pcb_size.x/2, C.hole_spacing.y/2-3,C.h]
  }).setColor(CONFIG.color.bulk)
 );
 rv.properties.holes = pholes;
 rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 rv.properties.vitamin = true;
 return rv;
}

function foot() {
 var F = CONFIG.foot;
 var br = F.bolt.hd/2+F.margin;
 var bh = F.zscalefactor*Math.sqrt(Math.pow(F.d/2,2)-Math.pow(br,2));
 var th = F.h-bh;
 var r = 2*F.d;
 var rv = CSG.sphere({ // botom contorted sphere
  center: [0,0,0], radius: F.d/2, resolution: r
 }).scale([1,1,F.zscalefactor]).translate([0,0,bh]).union(CSG.cylinder({ // top hat
  start: [0,0,bh], end: [0,0,F.h], radius: F.d/2, resolution: r
 })).intersect(CSG.cylinder({ // cut off excess
  start: [0,0,0], end: [0,0,F.h], radius: F.d
 })).subtract([
   CSG.cylinder({ // bolt hole
   start: [0,0,-1], end: [0,0,F.h+1], radius: F.bolt.d/2+PRINT.slide_tolerance
  }), CSG.cylinder({ // nut hole
   start: [0,0,F.h-F.nut.h-PRINT.play_tolerance],
   end: [0,0,F.h],
   radius: F.nut.d/2+PRINT.slide_tolerance, resolution: 6
  }), CSG.cylinder({ // bolthead/washer hole
   start: [0,0,-1], end: [0,0,F.h-F.nut.h-PRINT.play_tolerance-F.shell],
   radius: F.bolt.hd/2+PRINT.play_tolerance
  })
 ]).union(CSG.cylinder({ // bridging patch
  start: [0,0,F.h-F.nut.h-PRINT.play_tolerance-PRINT.layer_height],
  end: [0,0,F.h-F.nut.h-PRINT.play_tolerance],
  radius: F.nut.d/2
 }));
 rv.properties.c_column = new CSG.Connector([0,0,F.h],[0,0,1],[1,0,0]);
 rv.properties.c_shoe = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 rv.properties.P = new CSG.Connector([0,0,F.h],[0,0,-1],[1,0,0]);
 return rv.setColor(CONFIG.color.parts);
}
function shoe() {
 var F = CONFIG.foot;
 var rv = CSG.cylinder({
  start: [0,0,0], end: [0,0,F.foot.ho],
  radius: F.bolt.hd/2+F.margin
 }).union(CSG.cylinder({
  start: [0,0,0], end: [0,0,F.foot.ho+F.foot.hi],
  radius: F.bolt.hd/2+PRINT.play_tolerance-PRINT.fit_tolerance
 }));
 rv.properties.c_foot = new CSG.Connector([0,0,F.foot.ho],[0,0,1],[1,0,0]);
 rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 return rv.setColor(CONFIG.color.softparts);
}

function duetholder() {
 var DH = CONFIG.duetholder;
 var DHD = CD.duetholder;
 var hw = DH.bolt.head.d+2*DH.margin;
 var s = DH.bolt.l-CONFIG.extrusion.slotdepth+PRINT.play_tolerance*2;
 var lower = CONFIG.foot.h-2*DH.s;
 var hl = DHD.distance-CONFIG.extrusion.w;
 var rv = union([
  CSG.cube({ // vertical
   corner1: [-hw/2,s,CONFIG.extrusion.w],
   corner2: [hw/2,0,-lower]
  }),
  CSG.cube({ // horizontal extrusion
   corner1: [-hw/2,-CONFIG.extrusion.w,0],
   corner2: [ hw/2,0,-s]
  }),
  CSG.cube({ // horizontal
   corner1: [-hw/2,0,-lower],
   corner2: [hw/2,hl,-lower+DH.s]
  }),
  CSG.cylinder({ // boltend of horizontal part
   start: [0,hl,-lower], end: [0,hl,-lower+DH.s],
   radius: hw/2
  })
 ]);
 rv = rv.subtract([
  CSG.cylinder({ // through vertical
   start: [0,-1,CONFIG.extrusion.w/2], end: [0,s+1,CONFIG.extrusion.w/2],
   radius: DH.bolt.d/2+PRINT.slide_tolerance
  }),
  CSG.cylinder({ // through horizontal to extrusion
   start: [0,-CONFIG.extrusion.w/2,-s-1],
   end: [0,-CONFIG.extrusion.w/2,1],
   radius: DH.bolt.d/2+PRINT.slide_tolerance
  }),
  CSG.cube({ // cut off
   corner1: [-hw/2-1,-2*s,0],
   corner2: [hw/2+1,0,-2*s]
  }).rotateX(45).translate([0,-CONFIG.extrusion.w,0]),
  CSG.cylinder({ // duet bolt
   start: [0,hl,-lower], end: [0,hl,-lower+DH.s],
   radius: DH.bolt.d/2+PRINT.slide_tolerance
  })
 ]);
 var cp = [0,hl,-lower+DH.s];
 rv.properties.duet = new CSG.Properties();
 rv.properties.duet.c_sw = new CSG.Connector(cp,[0,0,1],[1,0,0]);
 rv.properties.duet.c_se = new CSG.Connector(cp,[0,0,1],[1,0,0]);
 rv.properties.duet.c_ne = new CSG.Connector(cp,[0,0,1],[-Math.cos(Math.PI/3),-Math.sin(Math.PI/3),0]);
 rv.properties.duet.c_nw = new CSG.Connector(cp,[0,0,1],[-Math.cos(Math.PI/3),Math.sin(Math.PI/3),0]);
 rv.properties.c_h = new CSG.Connector([0,-CONFIG.extrusion.w/2,0],[0,0,1],[1,0,0]);
 rv.properties.c_v = new CSG.Connector([0,0,CONFIG.extrusion.w/2],[0,-1,0],[0,0,1]);
 rv.properties.P = new CSG.Connector([-hw/2,0,0],[1,0,0],[0,1,0]);
 return rv.setColor(CONFIG.color.parts);
}

function heatbed() {
 var rv = CSG.cylinder({
  start: [0,0,0], end: [0,0,CONFIG.heatbed.h],
  radius: CONFIG.heatbed.r, resolution: 72
 });
 var screw = CSG.cylinder({
  start: [0,-CONFIG.heatbed.sr,-1],
  end: [0,-CONFIG.heatbed.sr,CONFIG.heatbed.h+1],
  radius: 3/2
 });
 var screws = [];
 for(var a=0;a<360;a+=60) screws.push(screw.rotateZ(a)); // TODO: connectors
 rv = rv.subtract(screws);
 rv.properties.c_glass = new CSG.Connector([0,0,CONFIG.heatbed.h],[0,0,1],[1,0,0]);
 rv.properties.P = new CSG.Connector(
  [0,0,-CONFIG.foot.h-CONFIG.extrusion.w*2-CONFIG.base.gap-CONFIG.bedholder.h],
  [0,0,1],[1,0,0]);
 rv.properties.vitamin = true;
 return rv.setColor(CONFIG.color.heatbed);
}
function glass() {
 var rv = CSG.cylinder({
  start: [0,0,0], end: [0,0,CONFIG.glass.h],
  radius: CONFIG.glass.r, resolution: 72
 });
 rv.properties.c_bed = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
 rv.properties.P = new CSG.Connector([0,0,-CONFIG.foot.h-CONFIG.heatbed.h],[0,0,1],[1,0,0]);
 rv.properties.vitamin = true;
 return rv.setColor(CONFIG.color.glass);
}
function platform() {
 var b = heatbed();
 var g = glass();
 g = g.connectTo(g.properties.c_bed,b.properties.c_glass,false,0);
 return b.union(g);
}

function bedholder(params) {
 var h0 = CONFIG.foot.h+CONFIG.extrusion.w*2+CONFIG.base.gap;
 var e_h=E2020.T.thickness; // height of the bump for extrusion
 var e_w=E2020.slot_width-PRINT.fit_tolerance; // width of the bump for extrusion
 var e_o=E2020.slot_width+PRINT.fit_tolerance; // opening for the T-Nut width
 var rv = CSG.cylinder({
  start: [0,0,h0], end: [0,0,h0+CONFIG.bedholder.h],
  radiusStart: CD.base.outer_inscription_r,
  radiusEnd: CD.base.outer_inscription_r+CONFIG.bedholder.h/2,
  resolution: 240
 });
 rv=rv.intersect(CSG.cube({
  corner1: [-CONFIG.extrusion.w/2,-CD.base.inner_inscription_r,h0],
  corner2: [ CONFIG.extrusion.w/2,-CD.base.mid_inscription_r*2,h0+2*CONFIG.bedholder.h]
 }));

 rv=rv.union(CSG.cube({ // bump to fix on extrusion
  corner1: [-CONFIG.extrusion.w/2,-CD.base.mid_inscription_r-e_w/2,h0],
  corner2: [ CONFIG.extrusion.w/2,-CD.base.mid_inscription_r+e_w/2,h0-e_h]
 }).subtract(
  CSG.cube({center:[0,0,0],radius:[(e_o+2*e_h)/(2*Math.sqrt(2)),e_w+2,(e_o+2*e_h)/(2*Math.sqrt(2))]})
  .rotateY(45)
  .translate([0,-CD.base.mid_inscription_r,h0-e_h])
 ));

 var ebolt_s = CONFIG.bedholder.bolt.l-CONFIG.extrusion.slotdepth+PRINT.play_tolerance*2;
 rv=rv.subtract([
  CSG.cylinder({ // base screw
   start: [0,-CD.base.mid_inscription_r,h0-1],
   end: [0,-CD.base.mid_inscription_r,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.d/2+PRINT.screw_tolerance/2
  }),
  CSG.cylinder({ // base screw head
   start: [0,-CD.base.mid_inscription_r,h0+ebolt_s],
   end: [0,-CD.base.mid_inscription_r,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.head.d/2+PRINT.play_tolerance
  })
 ]);

 var nuth=h0+CONFIG.bedholder.h*3/4;
 rv=rv.subtract([
  CSG.cylinder({ // bed screw
   start: [0,-CONFIG.heatbed.sr,h0-1],
   end: [0,-CONFIG.heatbed.sr,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.d/2+PRINT.screw_tolerance/2
  }),
  CSG.cube({ // nut pocket
   center: [0,-CONFIG.heatbed.sr,nuth],
   radius: [CONFIG.extrusion.w/2+1,CONFIG.bedholder.nut.w/2+PRINT.slide_tolerance/2,CONFIG.bedholder.nut.h/2+PRINT.slide_tolerance/2]
  })
 ]);

 rv.properties.P = new CSG.Connector([-CONFIG.extrusion.w/2,-CD.base.mid_inscription_r,h0+CONFIG.bedholder.h/2],
  [1,0,0],[0,0,1]);
 return rv.setColor(CONFIG.color.parts);
 var bolt_s = CONFIG.bedholder.bolt.l-CONFIG.extrusion.slotdepth+PRINT.play_tolerance*2;
 var nuth=h0+CONFIG.bedholder.h*3/4;
 var nutth = nuth+CONFIG.bedholder.nut.h/2+PRINT.slide_tolerance/2;
 var rv = CSG.roundedCube({
  corner1: [-CONFIG.extrusion.w/2,-CD.base.inner_inscription_r,h0],
  corner2: [ CONFIG.extrusion.w/2,-CONFIG.heatbed.sr-3/2-CONFIG.bedholder.margin,h0+CONFIG.bedholder.h],
  roundradius: CONFIG.bedholder.margin
 });
 rv = rv.subtract([
  CSG.cylinder({ // base screw
   start: [0,-CD.base.mid_inscription_r,h0-1],
   end: [0,-CD.base.mid_inscription_r,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.d/2+PRINT.screw_tolerance/2
  }),
  CSG.cylinder({ // bed screw
   start: [0,-CONFIG.heatbed.sr,h0-1],
   end: [0,-CONFIG.heatbed.sr,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.d/2+PRINT.screw_tolerance/2
  }),
  CSG.cube({ // nut pocket
   center: [0,-CONFIG.heatbed.sr,nuth],
   radius: [CONFIG.extrusion.w/2+1,(CONFIG.bedholder.nut.w+PRINT.slide_tolerance)/2,(CONFIG.bedholder.nut.h+PRINT.slide_tolerance)/2]
  }),
  CSG.cylinder({ // sink base screw
   start: [0,-CD.base.mid_inscription_r,h0+bolt_s],
   end: [0,-CD.base.mid_inscription_r,h0+CONFIG.bedholder.h+1],
   radius: CONFIG.bedholder.bolt.head.d/2+PRINT.play_tolerance
  })
 ]);
 rv = rv.union(CSG.cylinder({ // patch up for bridging
  start: [0,-CONFIG.heatbed.sr,nutth], end: [0,-CONFIG.heatbed.sr,nutth+PRINT.layer_height],
  radius: (CONFIG.bedholder.nut.w+PRINT.slide_tolerance)/2+PRINT.extrusion_width
 }));
 rv = rv.intersect(CSG.cylinder({ // cut off excess
  start: [0,0,h0-1], end: [0,0,h0+CONFIG.bedholder.h+1],
  radius: CONFIG.heatbed.r, resolution: 270
 }));
 rv.properties.P = new CSG.Connector([0,-CD.base.mid_inscription_r,h0],[0,0,1],[1,0,0]);
 return rv.setColor(CONFIG.color.parts);
}

var PARTS = {
 wip: function(params) {
  return duetholder(params);
  return PARTS.alltogethernow(params);
  return base_extrusions();
  return foot();
  return union(base_extrusions(),column_extrusions(),duet().translate([0,-20,0]));
 },
 alltogethernow: function(params) {
  var cols = columns();
  var sides = base_sides();
  var feet = THREEWINDS.map(function(w,i) {
   var rv = foot();
   rv = rv.connectTo(rv.properties.c_column,cols[i].properties.c_bottom,false,0);
   var s = shoe();
   s = s.connectTo(s.properties.c_foot,rv.properties.c_shoe,false,0);
   return rv.union(s);
  });
  var dh = duetholder();
  var dhsw = dh.connectTo(dh.properties.c_h,
   new CSG.Connector([-CONFIG.duet.hole_spacing.x/2,-CD.base.mid_inscription_r,CONFIG.foot.h],[0,0,1],[1,0,0]),
   false,0);
  var d = duet();
  d = d.connectTo(d.properties.holes.c_sw,dhsw.properties.duet.c_sw,false,0);
  var dhse = dh.connectTo(dh.properties.duet.c_se,d.properties.holes.c_se,false,0);
  var dhne = dh.connectTo(dh.properties.duet.c_ne,d.properties.holes.c_ne,false,0);
  var dhnw = dh.connectTo(dh.properties.duet.c_nw,d.properties.holes.c_nw,false,0);
  var rv = union(cols).union(sides.map(union)).union(feet).union([
   d,dhsw,dhse,dhne,dhnw
  ]);
  var p = U.P(platform());
  rv = rv.union(p);
  rv.properties.P = new CSG.Connector([0,0,0],[0,0,1],[1,0,0]);
  return rv;
 },
 duetholder: function(params) {
  return duetholder();
 },
 foot: foot,
 shoe: shoe,
 bedholder: bedholder,
 platform: function(params) { return U.P(EFFECTOR.effector()) },
 hinged: function(params) {
  // TODO: handle print mode
  var ms = microswitch();
  var e = EFFECTOR.effector();
  var hd = EFFECTOR.hinged({
   microswitch:ms,effector:e
  });
  ms = ms.connectTo(
   ms.properties.screw_connector[0],
   hd.properties.microswitch_screw_connector[0],
   false, 0);
  var hdhd = EFFECTOR.split_hinged(hd);
  return U.P(hdhd[1]);
 },
 // TODO: eliminate common code above and below
 clamp: function(params) {
  // TODO: handle print mode
  var ms = microswitch();
  var e = EFFECTOR.effector();
  var hd = EFFECTOR.hinged({
   microswitch:ms,effector:e
  });
  ms = ms.connectTo(
   ms.properties.screw_connector[0],
   hd.properties.microswitch_screw_connector[0],
   false, 0);
  var hdhd = EFFECTOR.split_hinged(hd);
  return U.P(hdhd[0]);
 },
 fanholder: function(params) {
  EFFECTOR.effector(); // to set up rmount
  return U.P(EFFECTOR.fanholder());
 }
};

function main(params) {
 var part = params.part && PARTS[params.part];
 if(!part) return U.axes();
 var rv = U.P(part(params));
 if(!params.print) rv = rv.union(U.axes());
 return rv;
}

function _main(params) {
 var e = EFFECTOR.effector();
 var hs = E3DV6.heatsink();
 hs = hs.connectTo(hs.properties.grove_connector,e.properties.grove_connector,false,0);
 var ms = microswitch();
 var hd = EFFECTOR.hinged({
  microswitch:ms,effector:e
 });
 ms = ms.connectTo(
  ms.properties.screw_connector[0],
  hd.properties.microswitch_screw_connector[0],
  false, 0);
 var hdhd = EFFECTOR.split_hinged(hd);
 var fh = EFFECTOR.fanholder();
 return union({
  platform: e,
  hinged: hdhd[1],
  clamp: hdhd[0],
  fanholder: fh,
  alltogethernow: [e,hdhd[0],hdhd[1], columns(),hs,ms,fh]
 }[params.part||'alltogethernow'])
 var rv = union(
  e,
  hs,
  columns(),
  ///hd,
  hdhd[0], hdhd[1],
  ms);
 return rv;
}

function getParameterDefinitions() {
 return [{
  name: 'part',
  type: 'choice',
  values: [
   'platform',
   'hinged',
   'clamp',
   'fanholder',
   'duetholder',
   'foot', 'shoe',
   'bedholder',
   'alltogethernow',
   'wip'
  ],
  captions: [
   'Effector platform',
   'Hinged part',
   'Clamp',
   'Fan holder',
   'Duet holder',
   'Foot', 'Shoe',
   'Bed holder',
   'All together now!',
   'Work in progress'
  ],
  caption: 'Part',
  initial: 'wip'
 },{
  name: 'print',
  type: 'checkbox',
  checked: false,
  caption: 'For print, no nonsense',
  initial: false
 }];
}

/* vim:set ft=javascript ai: */