forked from chilipeppr/eagle-brd-import
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauto-generated-widget.html
12343 lines (10778 loc) · 555 KB
/
auto-generated-widget.html
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Widget / Machine Vision</title>
<!-- ChiliPeppr is based on bootstrap CSS. -->
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<!-- Customized version of require.js for ChiliPeppr. Please see require.js docs for how
ChiliPeppr's dependency system works as it's based on require.js. -->
<script type='text/javascript' src="//i2dcui.appspot.com/js/require.js"></script>
<style type='text/css'>
/* CSS for ChiliPeppr Widget */
#com-chilipeppr-widget-eagle {
/* width: 200px; */
}
#com-chilipeppr-widget-eagle input {
padding: 0 0 0 6px;
}
#com-chilipeppr-widget-eagle .eagle-advanced {
padding: 0 10px 10px 10px;
border: 1px gray dashed;
}
#com-chilipeppr-widget-eagle .eagle-advanced .checkbox {
margin-bottom: 4px;
}
#com-chilipeppr-widget-eagle .input-group-addon {
padding: 5px;
}
#com-chilipeppr-widget-eagle .descriptive-text {
font-size: 10px;
padding-top: 5px;
}
#com-chilipeppr-widget-eagle h2 {
font-size: 17px;
}
#com-chilipeppr-widget-eagle #eagle-gcode {
/* padding:0; */
}
#com-chilipeppr-widget-eagle .com-chilipeppr-widget-eagle-gcode {
width: 100%;
height: 100%;
min-height: 100px;
margin: 0;
}
.com-chilipeppr-widget-eagle-info {
padding-bottom: 0;
margin-bottom: 0;
font-size: 10px;
position: absolute;
width: 200px;
}
.com-chilipeppr-widget-eagle-info-signal {
padding-bottom: 0;
margin-bottom: 0;
font-size: 10px;
position: absolute;
width: 200px;
}
#com-chilipeppr-widget-eagle #eagle-canvas {
width: 100%;
}
#com-chilipeppr-widget-eagle .nav-tabs>li>a {
padding: 2px 6px;
}
#com-chilipeppr-widget-eagle .tab-pane {
padding: 10px 16px 20px 16px;
overflow: auto;
max-height: 240px;
}
#com-chilipeppr-widget-eagle .panel-body {
padding: 3px;
}
#com-chilipeppr-widget-eagle .panel-footer {
font-size: 11px;
padding: 0;
margin: 0;
}
#com-chilipeppr-widget-eagle .process-list {
list-style-type: none;
margin: 0;
padding: 0;
width: 60%;
}
#com-chilipeppr-widget-eagle .process-list li {
margin: 0 3px 3px 3px;
padding: 0.4em;
padding-left: 1.5em;
font-size: 1.4em;
height: 18px;
}
#com-chilipeppr-widget-eagle .process-list li span {
position: absolute;
margin-left: -1.3em;
}
</style>
<script type='text/javascript'>
//<![CDATA[
requirejs.config({
paths: {
//Three: '//threejs.org/build/three.min',
Three: '//i2dcui.appspot.com/geturl?url=http://threejs.org/build/three.min.js',
//Three: '//i2dcui.appspot.com/js/three.min_73',
ThreeTextGeometry: '//i2dcui.appspot.com/js/three/TextGeometry',
ThreeFontUtils: '//i2dcui.appspotr.com/js/three/FontUtils',
ThreeHelvetiker: '//i2dcui.appspot.com/js/three/threehelvetiker',
Clipper: '//i2dcui.appspot.com/js/clipper/clipper_unminified'
},
shim: {
ThreeTextGeometry: ['Three'],
ThreeFontUtils: ['Three', 'ThreeTextGeometry'],
ThreeHelvetiker: ['Three', 'ThreeTextGeometry', 'ThreeFontUtils'],
}
});
// Test this element. This code is auto-removed by the chilipeppr.load()
cprequire_test(["inline:com-chilipeppr-widget-eagle"], function(ew) {
console.log("test running of " + ew.id);
//ew.init();
$('#com-chilipeppr-widget-eagle').css('position', 'relative');
$('#com-chilipeppr-widget-eagle').css('background', 'none');
$('#com-chilipeppr-widget-eagle').css('width', '300px');
$('body').prepend('<div id="3dviewer"></div>');
chilipeppr.load("#3dviewer", "http://fiddle.jshell.net/chilipeppr/y3HRF/195/show/light/", function() {
cprequire(['inline:com-chilipeppr-widget-3dviewer'], function(threed) {
threed.init({
doMyOwnDragDrop: false
});
//$('#com-chilipeppr-widget-3dviewer .panel-heading').addClass('hidden');
//autolevel.addRegionTo3d();
//autolevel.loadFileFromLocalStorageKey('com-chilipeppr-widget-autolevel-recent8');
//autolevel.toggleShowMatrix();
// only init eagle widget once 3d is loaded
// set doMyOwnDragDrop
ew.init(true);
});
});
chilipeppr.load("#test-drag-drop", "http://fiddle.jshell.net/chilipeppr/Z9F6G/show/light/",
function() {
cprequire(
["inline:com-chilipeppr-elem-dragdrop"],
function(dd) {
dd.init();
dd.bind("body", null);
});
});
chilipeppr.load("#com-chilipeppr-flash",
"http://fiddle.jshell.net/chilipeppr/90698kax/show/light/",
function() {
console.log("mycallback got called after loading flash msg module");
cprequire(["inline:com-chilipeppr-elem-flashmsg"], function(fm) {
//console.log("inside require of " + fm.id);
fm.init();
});
});
} /*end_test*/ );
cpdefine("inline:com-chilipeppr-widget-eagle", ["chilipeppr_ready", "Clipper", "jqueryuiWidget"], function() {
return {
id: "com-chilipeppr-widget-eagle",
url: "http://fiddle.jshell.net/chilipeppr/3fe23xsr/show/light/",
fiddleurl: "http://jsfiddle.net/chilipeppr/3fe23xsr/",
name: "Widget / Eagle PCB v3",
desc: "This widget lets you drag in an Eagle PCB \".brd\" file to mill.",
publish: {},
subscribe: {
},
foreignPublish: {},
foreignSubscribe: {
'/com-chilipeppr-elem-dragdrop/ondropped': 'We subscribe to this signal at a higher priority to intercept the signal, double check if it is an Eagle Brd file and if so, we do not let it propagate by returning false. That way the 3D Viewer, Gcode widget, or other widgets will not get Eagle Brd file drag/drop events because they will not know how to interpret them.'
},
init: function(doMyOwnDragDrop) {
// the workspace may want to handle the drag drop
// but when in dev mode it makes sense for us to do our own
if (doMyOwnDragDrop) {
this.setupDragDrop();
}
else {
// the workspace is doing the drag/drop. this is important
// because this code base for this widget is huge and thus
// the workspace should handle dragging in BRD files
// and once it sees one, it should then load this widget
// so that users who don't use ChiliPeppr for BRD files
// don't have to load all this insane code
}
this.setupUiFromLocalStorage();
this.btnSetup();
//this.status("Loaded...");
this.forkSetup();
this.lazyLoadTutorial();
$('#com-chilipeppr-widget-eagle .btnAnimate').click(this.animateOverlapPath.bind(this));
// init 3d for eagle widget
this.init3d();
this.setupMouseOver();
this.setupAdvancedInflateByUI();
this.setupGcodeTab();
this.setupFeedsDepths();
// setup clear button
$('#com-chilipeppr-widget-eagle .btn-clear').click(this.clearEagleBrd.bind(this));
this.setupLayerToggleDropdown();
console.log(this.name + " done loading.");
},
setupLayerToggleDropdown: function() {
$('#com-chilipeppr-widget-eagle .selectLayer').change(this.onChangeLayerToggleDropdown.bind(this));
console.log("r0: ");
},
populateLayerToggleDropdown: function() {
var selectLayerDropdown = $('#com-chilipeppr-widget-eagle .selectLayer');
var actionableLayers = [];
//var allSignals = Object.keys(this.eagle.signalItems);
var allSignals = this.eagle.signalItems;
console.log("ray: allSignals:", allSignals)
//alert(allSignals[0]);
for (var signalKeyR in this.eagle.signalItems) {
var signalLayersR = this.eagle.signalItems[signalKeyR];
var sigKeyR = Object.keys(signalLayersR);
for (i = 0; i < sigKeyR.length; i++) {
var sigKeyAsInt = sigKeyR[i];
console.log("r2: ", signalLayersR, "keys:", sigKeyR, "int: ", sigKeyAsInt);
if (sigKeyAsInt > 0 && sigKeyAsInt <= 16) { //brd layer is 1-16
actionableLayers[sigKeyAsInt - 1] = true; //-1 for array index
console.log("layer true: ", sigKeyAsInt);
}
else {
actionableLayers[sigKeyAsInt - 1] = false;
console.log("layer false: ", sigKeyAsInt);
}
}
} //this function returns the layer # of each signal!!!
selectLayerDropdown.empty();
for (i = 0; i < 16; i++) {
var loopingLayer = i + 1; //brd layer # is 1 greater than index
if (actionableLayers[i] == true) {
selectLayerDropdown.append($("<option />").text(this.eagle.layersByNumber[loopingLayer].name));
console.log("r3: sent layer to dropdown:", this.eagle.layersByNumber[loopingLayer].name);
}
console.log("r3.5: activeLayer:", this.activeLayer);
selectLayerDropdown.val(this.activeLayer);
}
},
onChangeLayerToggleDropdown: function() {
var that = this;
var selectedLayerInDropdown = $("#com-chilipeppr-widget-eagle .selectLayer :selected").text();
//var activeLayer = this.layer.name;
//console.log("r4.9: ", this.layer.name);
console.log("r5: selected:", selectedLayerInDropdown);
/*console.log("r6: ", activeLayer);
if (selectedLayerInDropdown != activeLayer) {
console.log("r7: Different");
}*/
var oldActiveLayer = this.activeLayer;
if (selectedLayerInDropdown != oldActiveLayer) {
this.activeLayer = selectedLayerInDropdown;
console.log("r6: layer active now", this.activeLayer);
//debugger;
//this.draw3dSignalWires [this.activeLayer];
var layerName = this.activeLayer;
if (layerName == "Top") {
//console.log("RAY!!! 3dSignalWireLayerName: T. ", layerName)
that.colorSignal = 9249571;
that.colorSmd = 9249571;
}
else if (layerName == "Bottom") {
//console.log("RAY!!! 3dSignalWireLayerName: B. ", layerName)
that.colorSignal = 2302861;
that.colorSmd = 2302861;
//console.log("RAY!!! Bottom Color: ", tempColor)
}
else {
that.colorSignal = 11403055;
that.colorSmd = 11403055;
}
this.clearEagleBrd();
this.draw3d();
//this.onRefresh();
}
//console.log("r5.5: active before", oldActiveLayer);
//this.activeLayer=selectedLayerInDropdown;
//console.log("r6: active now", this.activeLayer);
//console.log("r7: layer.name", this.layer.name);
//this.onRefresh();
/*
var selectLayerDropdown = $('#com-chilipeppr-widget-eagle .selectLayer');
//var activeLayer= 'Top'; //Set as property around line 610, ignore this
selectLayerDropdown.change(function(){ //Just onchange for now
//$('#dropDownId :selected').text(); //Still need to write this jq to get dropdown selected text
this.activeLayer = 'Bottom'; //Will set to selected contents of dropdown
console.log("r4: ActiveLayer: ", this.activeLayer); //this gets logged successfully
this.onRefresh(); //console says this is not a function.
});
*/
},
setupFeedsDepths: function() {
// As user changes vals, just update our global props
var el = $('#com-chilipeppr-widget-eagle');
var that = this;
el.find('.trace-depth').change(function(evt) {
console.log("evt:", evt);
that.depthOfSignalMilling = evt.currentTarget.valueAsNumber;
console.log("that.depthOfSignalMilling:", that.depthOfSignalMilling);
});
el.find('.trace-fr').change(function(evt) {
console.log("evt:", evt);
that.feedRateSignals = evt.currentTarget.valueAsNumber;
});
el.find('.trace-fr-plunge').change(function(evt) {
console.log("evt:", evt);
that.feedRatePlunge = evt.currentTarget.valueAsNumber;
});
el.find('.clearance-height').change(function(evt) {
console.log("evt:", evt);
that.clearanceHeight = evt.currentTarget.valueAsNumber;
});
el.find('.drill-feedrate').change(function(evt) {
console.log("evt:", evt);
if (evt.currentTarget.valueAsNumber) // arrow buttons send 2 events
that.drillFeedrate = evt.currentTarget.valueAsNumber;
});
el.find('.drill-max').change(function(evt) {
console.log("evt:", evt);
if (evt.currentTarget.valueAsNumber) // arrow buttons send 2 events
that.drillMaxDiameter = evt.currentTarget.valueAsNumber;
});
el.find('.drill-depth').change(function(evt) {
console.log("evt:", evt);
if (evt.currentTarget.valueAsNumber) // arrow buttons send 2 events
that.drillDepth = evt.currentTarget.valueAsNumber;
});
el.find('.dimension-mill-diameter').change(function(evt) {
console.log("evt:", evt);
/*
TODO:
- Test to exists holes they are smaller as this mill diameter and
Compare that.drillMaxDiameter greater as this holes or alert!
Cuz i.e.
The user has 1mm and 1.5mm holes, the user settings are:
* that.drillMaxDiameter = 1.1
* that.millDiameter = 2
then it's impossible to mill 1.5mm holes with a 2mm tool.
Send user a message and prevent a change here
*/
var choosedDiameter = evt.currentTarget.valueAsNumber;
for (var diameter in that.sortObjByKey(that.drillPads)) {
if (diameter > that.drillMaxDiameter && diameter < choosedDiameter) {
evt.currentTarget.style.color = "#ff0000";
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg",
"Warning",
"The choosed mill diameter " + choosedDiameter + "mm are to small to mill holes with " + diameter + "mm! Please check you drill max diameter!",
3 * 1000);
return;
}
else {
evt.currentTarget.style.color = ""
}
}
if (evt.currentTarget.valueAsNumber) // arrow buttons send 2 events
that.millDiameter = evt.currentTarget.valueAsNumber;
});
el.find('.dimension-depth').keyup(function(evt) {
console.log("evt:", evt);
var item = $(evt.currentTarget);
that.depthOfDimensions = parseFloat(item.val());
console.log("depthOfDimensions:", that.depthOfDimensions);
if (that.depthOfDimensions > 0) {
that.depthOfDimensions = that.depthOfDimensions * -1;
item.val(that.depthOfDimensions);
}
that.calcPasses(el);
});
el.find('.dimension-stepdown').keyup(function(evt) {
console.log("evt:", evt);
var item = $(evt.currentTarget);
that.stepDownDimensions = parseFloat(item.val());
if (isNaN(that.stepDownDimensions)) {
item.addClass("alert-danger");
return;
}
item.removeClass('alert-danger');
if (that.stepDownDimensions > 0) {
that.stepDownDimensions = that.stepDownDimensions * -1;
item.val(that.stepDownDimensions);
}
if (that.stepDownDimensions < that.depthOfDimensions) {
// they can't make their step down be greater than dimensions
that.stepDownDimensions = that.depthOfDimensions;
item.val(that.stepDownDimensions);
}
that.calcPasses(el);
});
el.find('.dimension-feedrate').change(function(evt) {
console.log("evt:", evt);
that.feedRateDimensions = evt.currentTarget.valueAsNumber;
});
el.find('.dispenser-axis').change(function(evt) {
console.log("evt:", evt);
that.dispenserAxis = evt.currentTarget.valueAsNumber;
});
el.find('.stepsfordrop').change(function(evt) {
console.log("evt:", evt);
that.stepsfordrop = evt.currentTarget.valueAsNumber;
});
el.find('.cannula-diameter').change(function(evt) {
console.log("evt:", evt);
that.cannulaDiameter = evt.currentTarget.valueAsNumber;
});
},
calcPasses: function(el) {
// calc passes
var passesFloat = this.depthOfDimensions / this.stepDownDimensions;
var passes = parseInt(passesFloat);
passesFloat -= passes;
if (passesFloat > 0) passes++;
el.find('.dimension-passes i').text(passes);
var lastPass = this.depthOfDimensions - ((passes - 1) * this.stepDownDimensions);
//if (lastPass == 0) lastPass = that.stepDownDimensions;
el.find('.dimension-lastpass i').text(lastPass.toFixed(2));
console.log("passes:", passes, "lastPass:", lastPass, "passesFloat:", passesFloat);
},
activateWidget: function() {
console.log("activating Eagle BRD widget");
this.reactivateMouseMove();
this.sceneReAddMySceneGroup();
},
unactivateWidget: function() {
console.log("unactivating Eagle BRD widget");
this.sceneRemoveMySceneGroup();
this.deactivateMouseMove();
},
init3d: function() {
this.get3dObj();
if (this.obj3d == null) {
console.log("loading 3d scene failed, try again in 1 second");
var attempts = 1;
var that = this;
setTimeout(function() {
that.get3dObj();
if (that.obj3d == null) {
attempts++;
setTimeout(function() {
that.get3dObj();
if (that.obj3d == null) {
console.log("giving up on trying to get 3d");
}
else {
console.log("succeeded on getting 3d after attempts:", attempts);
that.onInit3dSuccess();
}
}, 5000);
}
else {
console.log("succeeded on getting 3d after attempts:", attempts);
that.onInit3dSuccess();
}
}, 1000);
}
else {
this.onInit3dSuccess();
}
},
onInit3dSuccess: function() {
console.log("onInit3dSuccess. That means we finally got an object back.");
this.clear3dViewer();
// open the last file
var that = this;
//setTimeout(function () {
that.open();
//}, 1000);
},
obj3d: null, // gets the 3dviewer obj stored in here on callback
obj3dmeta: null, // gets metadata for 3dviewer
userCallbackForGet3dObj: null,
get3dObj: function(callback) {
this.userCallbackForGet3dObj = callback;
chilipeppr.subscribe("/com-chilipeppr-widget-3dviewer/recv3dObject", this, this.get3dObjCallback);
chilipeppr.publish("/com-chilipeppr-widget-3dviewer/request3dObject", "");
chilipeppr.unsubscribe("/com-chilipeppr-widget-3dviewer/recv3dObject", this.get3dObjCallback);
},
get3dObjCallback: function(data, meta) {
console.log("got 3d obj:", data, meta);
this.obj3d = data;
this.obj3dmeta = meta;
if (this.userCallbackForGet3dObj) {
//setTimeout(this.userCallbackForGet3dObj.bind(this), 200);
//console.log("going to call callback after getting back the new 3dobj. this.userCallbackForGet3dObj:", this.userCallbackForGet3dObj);
this.userCallbackForGet3dObj();
this.userCallbackForGet3dObj = null;
}
},
is3dViewerReady: false,
clear3dViewer: function() {
console.log("clearing 3d viewer");
chilipeppr.publish("/com-chilipeppr-widget-3dviewer/sceneclear");
//if (this.obj3d) this.obj3d.children = [];
/*
this.obj3d.children.forEach(function(obj3d) {
chilipeppr.publish("/com-chilipeppr-widget-3dviewer/sceneremove", obj3d);
});
*/
this.is3dViewerReady = true;
},
clearEagleBrd: function() {
this.get3dObj(this.clearEagleBrdStep2.bind(this));
},
clearEagleBrdStep2: function() {
console.log("clearing Eagle BRD. this.obj3d:", this.obj3d, "this.mySceneGroup:", this.mySceneGroup);
// remove all 3d viewer stuff
this.sceneRemoveMySceneGroup();
this.mySceneGroup = null;
console.log("after clearing Eagle BRD. this.obj3d:", this.obj3d, "this.mySceneGroup:", this.mySceneGroup);
//this.sceneRemove(this.threeDimensions);
this.threeDimensions = null;
// contains the end mill path (blue/gray line)
/*this.threePathEndMill.forEach(function(threeObj) {
this.sceneRemove(threeObj);
}, this);*/
this.threePathEndMill = [];
// contains the mesh signals (wires/pads/smds/vias)
/*this.threePathEndMillArr.forEach(function(p) {
this.sceneRemove(p);
}, this);
this.threePathDeflatedActualArr.forEach(function(p) {
this.sceneRemove(p);
}, this);
this.threePathInflatedActualArr.forEach(function(p) {
this.sceneRemove(p);
}, this);*/
// now reset arrays since they're useless now that
// we removed them and will regenerate below
this.threePathEndMillArr = [];
this.threePathDeflatedActualArr = [];
this.threePathInflatedActualArr = [];
this.pathEndMillArr = [];
this.pathEndMillHolesArr = [];
this.pathInflatedActualArr = [];
this.pathDeflatedActualArr = [];
// reset all main properties
//this.pathsUnion = null;
this.clipperBySignalKey = [];
this.intersectObjects = [];
this.clipperDimension = [];
this.clipperSignalWires = [];
this.clipperElements = [];
this.clipperPads = [];
this.clipperSmds = [];
this.clipperVias = [];
this.drillPads = {};
this.drillVias = {};
this.paths = null; // final paths generated from onRefresh() used to export gcode
this.pathsUnion = null;
this.pathsUnionHoles = null;
},
setupGcodeTab: function() {
// attach click event to "Send Gcode to workspace" button
$('#com-chilipeppr-widget-eagle .btn-eagle-sendgcodetows').click(this.sendGcodeToWorkspace.bind(this));
//$('#com-chilipeppr-widget-eagle .process-list').sortable();
//$('#com-chilipeppr-widget-eagle .process-list').disableSelection();
},
sendGcodeToWorkspace: function() {
this.exportGcode();
var info = {
name: "Eagle BRD: " + this.fileInfo.name.replace(/.brd$/i, ""),
lastModified: new Date()
};
// grab gcode from textarea
var gcodetxt = $('.com-chilipeppr-widget-eagle-gcode').val();
if (gcodetxt.length < 10) {
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Error Sending Gcode", "It looks like you don't have any Gcode to send to the workspace. Huh?", 5 * 1000);
return;
}
// send event off as if the file was drag/dropped
chilipeppr.publish("/com-chilipeppr-elem-dragdrop/ondropped", gcodetxt, info);
// convert the color on the end mill path because it's irrelevant now based
// on the gcode being shown by the 3d viewer
this.threePathEndMill.forEach(function(threeObj) {
console.log("tweaking endmill path now that we're sending gcode. threeObj:", threeObj);
if (threeObj.children.length > 0) {
threeObj.children[0].material.opacity = 0.1;
threeObj.children[0].material.color = 0x000000;
/*threeObj.children.forEach(function(threeObjChild) {
threeObjChild.material.color = 0x000000;
threeObjChild.material.opacity = 0.1;
});*/
}
else {
threeObj.material.color = 0x000000;
threeObj.material.opacity = 0.1;
}
}, this);
// or use alternate pubsub
// "/com-chilipeppr-elem-dragdrop/loadGcode"
var that = this;
this.get3dObj(function() {
console.log("got callback after 3dviewer re-sent us the 3dobj and 3dobjmeta. 3dobj:", that.obj3d, "obj3dmeta:", that.obj3dmeta);
that.sceneReAddMySceneGroup();
});
},
setupDragDrop: function() {
// subscribe to events
chilipeppr.subscribe("/com-chilipeppr-elem-dragdrop/ondragover", this, this.onDragOver);
chilipeppr.subscribe("/com-chilipeppr-elem-dragdrop/ondragleave", this, this.onDragLeave);
// /com-chilipeppr-elem-dragdrop/ondropped
chilipeppr.subscribe("/com-chilipeppr-elem-dragdrop/ondropped", this, this.onDropped, 9); // default is 10, we do 9 to be higher priority
},
eagle: null, // contains the eagle object
open: function(data, info) {
// if we are passed the file data, then use that, otherwise look to
// see if we had one saved from before, i.e. this is a browser reload scenario
// and we'd like to show them their recent Eagle BRD
var file;
if (data) {
console.log("open. loading from passed in data. data.length:", data.length, "info:", info);
file = data;
this.fileInfo = info;
$('#com-chilipeppr-widget-eagle .eagle-draghere').addClass("hidden");
}
else {
// try to retrieve the most recent board file
file = localStorage.getItem('com-chilipeppr-widget-eagle-lastDropped');
if (file && file.length > 0) {
this.fileInfo = localStorage.getItem('com-chilipeppr-widget-eagle-lastDropped-info');
if (this.fileInfo && this.fileInfo.match(/^{/)) {
this.fileInfo = JSON.parse(this.fileInfo);
}
console.log("open. loading data from localStorage. file.length:", file.length, "info:", this.fileInfo);
}
else {
// there's no file, just return
return;
}
}
if (file) {
// make sure this file is an Eagle board
if (!(file.match(/<!DOCTYPE eagle SYSTEM "eagle.dtd">/i))) {
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Error Loading Eagle BRD", "It looks like you had a previous Eagle BRD, but it doesn't seem to be the correct format.", 10 * 1000);
return;
}
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Opening Eagle BRD", "Parsing Eagle BRD file and generating signal paths.", 3000, true);
// reset main properties
this.activeLayer = 'Top';
this.clearEagleBrd();
this.clear3dViewer();
this.colorSignal = 9249571;
this.colorSmd = 9249571;
// create board
this.eagle = new EagleCanvas('eagle-canvas');
this.eagle.loadText(file);
//this.eagle.setScaleToFit('eagle-main');
//this.eagle.setScale(this.eagle.getScale() / 2);
//this.eagle.draw();
//var that = this;
this.draw3d(function() {
console.log("got callback from draw3d");
});
$('#com-chilipeppr-widget-eagle .btn-eagle-sendgcodetows').prop('disabled', false);
console.log("eagle:", this.eagle);
}
else {
console.log("no last file, so not opening");
}
},
draw3d: function(callback) {
if (!this.is3dViewerReady) {
var that = this;
setTimeout(function() {
if (!that.is3dViewerReady) {
setTimeout(function() {
if (!that.is3dViewerReady) {
console.log("giving up on drawing into 3d for Eagle Brd");
}
else {
console.log("ready to draw 3d on 3rd attempt");
that.onDraw3dReady();
if (callback) callback();
}
}, 5000);
}
else {
console.log("ready to draw 3d on 2nd attempt");
that.onDraw3dReady();
if (callback) callback();
}
}, 2000);
}
else {
console.log("ready to draw 3d on 1st attempt");
this.onDraw3dReady();
if (callback) callback();
}
},
colorSignal: 9249571, // match eagle colors. red for top wire
colorSmd: 9249571, // same color as signal (again top)
colorSignalBottom: 2302861, //match eagle colors. blue for bottom wire
colorSmdBottom: 2302861, //same color as signal (again bottom)
colorVia: 11842560, // yellow
colorPad: 2329891, // pads are green
colorMill: 255, // match color ChiliPeppr shows for milling
colorHole: 9276813, // light gray
colorsDrop: [2722312, 8817160, 9046024], // green, yellow, red
colorDimension: 9276813, // light gray
opacitySignal: 0.1,
opacityDimension: 0.3,
opacityVia: 0.1,
opacityPad: 0.1,
endmillSize: 0.0, // size of endmill that user picks
actualEndmill: 0.2,
inflateMillPathBy: null,
paths: null, // final paths generated from onRefresh() used to export gcode
pathsUnion: null,
pathsUnionHoles: null,
threeDimensions: null,
activeLayer: 'Top',
clipperDimensions: [], // contains the dimensions of the board as clipper path
onDraw3dReady: function() {
console.group("draw3d");
this.populateLayerToggleDropdown();
console.log("iterating Eagle Brd and drawing into 3d viewer");
console.log("eagle obj we will draw:", this.eagle);
this.clear3dViewer();
//var activeLayer = 'Top';
//var activeLayer = 'Bottom';
// these methods will draw all Eagle objects into several global
// properties, the most important of which is this.clipperBySignalKey
// which holds a structured object of each signal, i.e. +3V, GND, etc.
/*
this.draw3dSignalWires(this.eagle.eagleLayersByName['Top']);
this.draw3dSignalPolygons(this.eagle.eagleLayersByName['Top']);
this.draw3dElements(this.eagle.eagleLayersByName['Top']);
*/
this.draw3dSignalWires(this.eagle.eagleLayersByName[this.activeLayer]);
this.draw3dSignalPolygons(this.eagle.eagleLayersByName[this.activeLayer]);
this.draw3dElements(this.eagle.eagleLayersByName[this.activeLayer]);
this.draw3dVias('1-16');
this.threeDimensions = this.draw3dDimension(this.endmillSize);
//this.obj3d.children = [];
// obj3d is the original THREE.Object3D() for the 3d
// viewer. the extents x/y/z vals are calculated off of
// it so we need a fake object to put in there
console.log("this.obj3d:", this.obj3d);
/*
if (this.obj3d == null) {
this.obj3d = new THREE.Object3D();
this.sceneAdd(this.obj3d);
}
*/
//this.obj3d.add(this.threeDimensions.clone());
//this.drawUnionOfSignalWiresAndElements(
// this.eagle.eagleLayersByName['Top']);
// old way of getting clipper paths
//var paths = this.getClipperPaths();
// this ensures no path acts like a hole. all these paths
// should union themselves
//var paths = this.getAllPathsAsOuterOrientation(paths);
// for debug, draw the paths
//var z = 0;
/*
var pathTest = this.getUnionOfClipperPaths([paths[0], paths[1]]);
this.drawClipperPaths(pathTest, 0xff00ff, 0.9, z);
console.log("pathTest:", pathTest);
z += 1;
paths.forEach(function(path) {
this.drawClipperPaths([path], this.colorMill, 0.9, z);
z += 0.2;
}, this);
*/
// we have all of these nicely formatted clipperPaths that were the result
// of looking at each signal/via/pad and unioning each of those for one higher
// level path. those paths are 90% good now, but we need to union them one last
// time in case there's any overlap
//this.pathsUnion = this.getUnionOfClipperPaths(paths);
//this.pathsUnion = paths;
// sometimes there is an inside path that doesn't get unioned, so do additional
// processing
//console.log("pathsUnion:", this.pathsUnion);
//console.log("started with N paths. ended with N paths:", paths.length, this.pathsUnion.length);
// for debug purposes, let's draw these
//this.drawClipperPaths(this.pathsUnion, this.colorMill, 0.5);
// check orientation of all new paths, because we could have ended up
// with some inside paths, known as "holes"
/*
this.pathsUnionHoles = [];
var ctr = 0;
this.pathsUnion.forEach(function(path) {
if (ClipperLib.Clipper.Orientation(path)) {
// do nothing.
this.pathsUnionHoles[ctr] = false;
} else {
console.warn("found a hole:", path);
this.pathsUnionHoles[ctr] = true;
}
ctr++;
}, this);
*/
//var z = 0;
/*
z += 1;
this.pathsUnion.forEach(function(path) {
this.drawClipperPaths([path], 0xff0000, 0.5, z);
z += 0.3;
}, this);
*/
//var endmillSize = this.findBestEndMillSize(pathsUnion);
/*
var endmillSize = this.findBestEndMillSizeLowestFirst(this.pathsUnion);
$('#com-chilipeppr-widget-eagle .best-size').html(endmillSize);
$('#com-chilipeppr-widget-eagle .inflate-by').val(endmillSize);
*/
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/viewextents');
setTimeout(this.onRefresh.bind(this, null, this.onDraw3dReadyAfter), 2000);
//this.onRefresh();
/*
// this approach isolates out the ldc1000 region
// then finds best endmill size again
pathEndMill.push([{X:47,Y:10},{X:58.5,Y:10},{X:58.5,Y:18},{X:47,Y:18},{X:47,Y:10}]);
var pathDiff = this.getUnionOfClipperPaths(pathEndMill);
var pathDiff = this.getInflatePath(pathEndMill, 0.01);
var endmillSize = this.findBestEndMillSizeLowestFirst(pathDiff);
var pathEndMill = this.getInflatePath(pathDiff, endmillSize);
//this.drawClipperPaths(pathDiff, this.colorMill, 0.8);
this.drawClipperPaths(pathEndMill, this.colorMill, 0.8);
*/
/*
// this approach isolates out the TI tca9406 region
// then finds best endmill size again
pathEndMill.push([{X:5,Y:5},{X:9.5,Y:5},{X:9.5,Y:13},{X:5,Y:13},{X:5,Y:5}]);
var pathDiff = this.getUnionOfClipperPaths(pathEndMill);
//var pathDiff = this.getInflatePath(pathEndMill, 0.01);
var endmillSize = this.findBestEndMillSizeLowestFirst(pathDiff);
var pathEndMill = this.getInflatePath(pathDiff, endmillSize);
//this.drawClipperPaths(pathDiff, this.colorMill, 0.8);
this.drawClipperPaths(pathEndMill, this.colorMill, 0.8);
*/
// try technique where inflate to desired endmill then subtract
// the "best fit"
//var pathEndMillDesired = this.getInflatePath(pathsUnion, 0.2);
//var pathHotZones = this.getDiffOfClipperPaths(pathEndMillDesired, pathEndMill);
//var pathHotZones2 = this.getDiffOfClipperPaths(pathHotZones, pathEndMillDesired);
// subtract outer path from final
//var pathHotZonesFinal = this.getDiffOfClipperPaths(pathHotZones2, pathHotZones);
//this.drawClipperPaths(pathEndMillDesired, this.colorMill, 0.8);
// trigger resize to ensure our mouse events
// are lined up correctly
console.log("done drawing Eagle PCB Board");
console.groupEnd();
},
onDraw3dReadyAfter: function() {
console.log("onDraw3dReadyAfter");
// ask 3d viewer to set things up now
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/setunits', "mm");
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/drawextents');
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/viewextents');
$(window).trigger('resize');
if (this.obj3dmeta && this.obj3dmeta.widget)
this.obj3dmeta.widget.wakeAnimate();
},
clearanceHeight: 1.0, // move z to clearance
// 1 oz = 0.035mm, 2 oz = 0.07mm, 3 oz = 0.105mm
depthOfSignalMilling: -0.1, // cutting how deep?
feedRatePlunge: 30, // plunging into FR4 copper
feedRateSignals: 80, // feedrate for milling signals,pads,smds,vias
feedRateDimensions: 100,
drillFeedrate: 100.0, // mm/min
drillMaxDiameter: 3.00, //mm/min
drillDepth: -1.7, // std thickness
depthOfDimensions: -1.7, // std thickness
millDiameter: 2,
stepDownDimensions: -0.5,
stepDownPasses: 3, // use passes or dimension
cannulaDiameter: 1,
stepsfordrop: 0.5,
dispenserAxis: 'D',
renderedDrops: [],
renderDispenserDrops: function() {
var that = this;
// remove all old drops
this.renderedDrops.forEach(function(thing) {
that.sceneRemove(thing);
}, this);
if (!$('#com-chilipeppr-widget-eagle .dispenser-active').is(':checked'))
return;