-
Notifications
You must be signed in to change notification settings - Fork 23
/
auto-generated-widget.html
9664 lines (8518 loc) · 477 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 / Eagle BRD v5.8</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 */
/* 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,
#com-chilipeppr-widget-eagle .reg-holes-gcode{
width: 100%;
height: 100%;
min-height: 150px;
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: 260px;
}
#com-chilipeppr-widget-eagle .tab-pane-container {
padding: 0px 0px 0px 0px;
overflow: visible;
max-height: 295px;
}
#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;
}
.nav-tabs-2ndpos {
margin-left:10px;
margin-right:10px;
}
.nav-tabs-2ndpos li {
font-size:12px;
}
.nav-tabs.nav-tabs-2ndpos li.active a {
border-style: dashed;
}
</style>
<script type='text/javascript'>
//<![CDATA[
/* global requirejs cprequire cpdefine chilipeppr THREE */
// Defining the globals above helps Cloud9 not show warnings for those variables
// ChiliPeppr Widget/Element Javascript
requirejs.config({
/*
Dependencies can be defined here. ChiliPeppr uses require.js so
please refer to http://requirejs.org/docs/api.html for info.
Most widgets will not need to define Javascript dependencies.
Make sure all URLs are https and http accessible. Try to use URLs
that start with // rather than http:// or https:// so they simply
use whatever method the main page uses.
Also, please make sure you are not loading dependencies from different
URLs that other widgets may already load like jquery, bootstrap,
three.js, etc.
You may slingshot content through ChiliPeppr's proxy URL if you desire
to enable SSL for non-SSL URL's. ChiliPeppr's SSL URL is
https://i2dcui.appspot.com which is the SSL equivalent for
http://chilipeppr.com
*/
paths: {
// Don't put .js at end of URL (except when passing thru CP geturl proxy)
// Three: '//i2dcui.appspot.com/geturl?url=http://threejs.org/build/three.min.js',
Three: 'https://cdnjs.cloudflare.com/ajax/libs/three.js/r76/three',
ThreeTextGeometry: '//i2dcui.appspot.com/js/three/TextGeometry',
ThreeFontUtils: '//i2dcui.appspot.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) {
// Test this element. This code is auto-removed by the chilipeppr.load()
// when using this widget in production. So use the cpquire_test to do things
// you only want to have happen during testing, like loading other widgets or
// doing unit tests. Don't remove end_test at the end or auto-remove will fail.
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', '320px');
$('body').prepend('<div id="3dviewer"></div>');
chilipeppr.load(
"#3dviewer",
"http://raw.githubusercontent.com/chilipeppr/widget-3dviewer/master/auto-generated-widget.html",
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);
});
});
$('body').prepend('<div id="test-drag-drop"></div>');
chilipeppr.load("#test-drag-drop", "http://raw.githubusercontent.com/chilipeppr/elem-dragdrop/master/auto-generated-widget.html",
function () {
cprequire(
["inline:com-chilipeppr-elem-dragdrop"],
function (dd) {
dd.init();
dd.bind("body", null);
});
});
$('body').prepend('<div id="com-chilipeppr-flash"></div>');
chilipeppr.load("#com-chilipeppr-flash",
"http://raw.githubusercontent.com/chilipeppr/element-flash/master/auto-generated-widget.html",
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();
});
});
// test before and after render
chilipeppr.subscribe("/" + ew.id + '/beforeToolPathRender', this, function(eagleWidget) {
console.log("publish test. got the /beforeToolPathRender signal. eagleWidget:", eagleWidget);
});
chilipeppr.subscribe("/" + ew.id + '/afterToolPathRender', this, function(eagleWidget) {
console.log("publish test. got the /afterToolPathRender signal. eagleWidget:", eagleWidget);
});
// test before and after render
chilipeppr.subscribe("/" + ew.id + '/beforeLayerGenerate', this, function(eagleWidget) {
console.log("publish test. got the /beforeLayerGenerate signal. layer:", eagleWidget.activeLayer, "eagleWidget:", eagleWidget);
});
chilipeppr.subscribe("/" + ew.id + '/afterLayerGenerate', this, function(eagleWidget) {
console.log("publish test. got the /afterLayerGenerate signal. layer:", eagleWidget.activeLayer, "eagleWidget:", eagleWidget);
});
} /*end_test*/ );
// This is the main definition of your widget. Give it a unique name.
cpdefine("inline:com-chilipeppr-widget-eagle", ["chilipeppr_ready", "Clipper", "jqueryuiWidget"], function () {
return {
/**
* The ID of the widget. You must define this and make it unique.
*/
id: "com-chilipeppr-widget-eagle",
name: "Widget / Eagle BRD v5.8",
desc: "This widget lets you drag in an Eagle PCB \".brd\" file to mill.",
url: "http://raw.githubusercontent.com/ameennihad/widget-eagle/master/auto-generated-widget.html", // The final URL of the working widget as a single HTML file with CSS and Javascript inlined. You can let runme.js auto fill this if you are using Cloud9.
fiddleurl: "http://ide.c9.io/ameennihad/widget-eagle", // The edit URL. This can be auto-filled by runme.js in Cloud9 if you'd like, or just define it on your own to help people know where they can edit/fork your widget
githuburl: "http://github.com/ameennihad/widget-eagle", // The backing github repo
testurl: "http://widget-eagle-ameennihad.c9users.io/widget.html", // The standalone working widget so can view it working by itself
/**
* Define pubsub signals below. These are basically ChiliPeppr's event system.
* ChiliPeppr uses amplify.js's pubsub system so please refer to docs at
* http://amplifyjs.com/api/pubsub/
*/
/**
* Define the publish signals that this widget/element owns or defines so that
* other widgets know how to subscribe to them and what they do.
*/
publish: {
// Define a key:value pair here as strings to document what signals you publish.
'/onAddGcode': `This signal lets a 3rd party add-on inject its own Gcode into the
overall final Gcode for the Eagle BRD Widget. Here is an example of how to subscribe.
<pre>
chilipeppr.subscribe(
"/com-chilipeppr-widget-eagle/addGcode",
this,
this.myOnAddGcode
);
</pre>
Then, your callback would look like this with 4 parameters receiving the variables
that the addGcode publish signal sends you.
<pre>
onAddGcode : function(addGcodeCallback, gcodeParts, eagleWidget, helpDesc){
console.log("Got onAddGcode:", arguments);
// this method calls back to the main Eagle widget to inject our Gcode
addGcodeCallback(1500, myOwnGcode );
}
</pre>
The 1500 in the example above is to attach a priority to where our Gcode will get positioned.
The base Gcode ends around line 900. The footer starts at line 2000. So putting our Gcode at
the end but before the footer means using 1500 should do fine. You can analyze the existing
Gcode by looking at parameter 2 gcodeParts to see if an index has already been used so you
don't clobber it. If you want to delete Gcode from gcodeParts you could do that as well and
the main widget will reflect the deletion.
`,
'/beforeLayerGenerate' : `This widget fires a signal before generating the Three.js objects
and Clipper paths for a board layer. The Three.js objects are 3D objects representing the
pads, vias, smds, wires, polygons, and dimensions. Those Three.js objects are used to
populate the 3D viewer and to calculate 2D Clipper paths from.
Clipper paths are the 2D XY
values of all the layer's objects and are generated so that unions and diffs can be
calculated on those paths in the render step. Clipper paths can be easily inflated and
deflated by the Clipper.js library which is why they are so important to this widget.
When you get this signal a reference to "this", i.e. the Eagle Widget, is included in
the payload so you may use it to manipulate this widget as you see fit.`,
'/afterLayerGenerate' : `Please see the /beforeLayerGenerate description to understand this
signal better. The /afterLayerGenerate signal is fired after this widget is done
generating the board layer. The payload is the same as the before signal.`,
'/beforeToolPathRender' : `This widget fires a signal before the rendering of the tool path
for the milling of the Eagle BRD. As the user tests out different inflate values, you
will get this signal for each re-render of the tool path the user asks for, i.e. when
they click the "render" button.
In the payload is a reference to "this" so you can possibly grab info or do other
manipulations of the board before we render the tool path. This is especially useful for add-on
widgets to the Eagle BRD widget such as the Solder Paste Dispenser Add-On or the
Pick and Place Add-On.
`,
'/afterToolPathRender' : `This widget fires a signal after the rendering of the tool path
for the Eagle BRD. The tool path is the blue line in the 3D viewer.
Similar to the /beforeToolPathRender signal, in the payload is a reference to "this" so you can possibly grab info or do other
manipulations of the board after we render. This is especially useful for add-on
widgets to the Eagle BRD widget such as the Solder Paste Dispenser Add-On or the
Pick and Place Add-On.
`
},
/**
* Define the subscribe signals that this widget/element owns or defines so that
* other widgets know how to subscribe to them and what they do.
*/
subscribe: {
// Define a key:value pair here as strings to document what signals you subscribe to
// so other widgets can publish to this widget to have it do something.
// '/onExampleConsume': 'Example: This widget subscribe to this signal so other widgets can send to us and we'll do something with it.'
'/getBoardData' : `Call this with a callback and you will immediately get back the baord data
to your callback. Call like
chilipeppr.publish("/com-chilipeppr-eagle/getBoardData", mycallback);
This returns all of the board data for you, so that you can know
all of the information that this Eagle BRD widget created. You will get back data like:
{
clipperBySignalKey: {}, // contains all signals (wires)
clipperDimension: {}, // contains dimension of board
clipperElements: {},
clipperPads: {}, // contains all pads (pads have holes)
clipperSignalPolys: {}, // polygons that are signals like a GND plane
clipperSignalWires: {}, // wires by name
clipperSmds: {}, // all the smd pads, i.e. where components sit for soldering
clipperVias: {}, // your vias. these have holes too.
eagle: {}, // the parsed Eagle BRD XML into a structure
}`
},
/**
* Document the foreign publish signals, i.e. signals owned by other widgets
* or elements, that this widget/element publishes to.
*/
foreignPublish: {
// Define a key:value pair here as strings to document what signals you publish to
// that are owned by foreign/other widgets.
// '/jsonSend': 'Example: We send Gcode to the serial port widget to do stuff with the CNC controller.'
},
/**
* Document the foreign subscribe signals, i.e. signals owned by other widgets
* or elements, that this widget/element subscribes to.
*/
foreignSubscribe: {
// Define a key:value pair here as strings to document what signals you subscribe to
// that are owned by foreign/other widgets.
'/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.'
},
/**
* All widgets should have an init method. It should be run by the
* instantiating code like a workspace or a different widget.
* If you are doing development on this widget, it's important to understand what
* data is available to you after the board is parsed. This data can enable you to
* do enhanced operations. For example, I'm working on creating laser paths to laser
* out the solder mask to reveal the underlying pads and smds. I had to re-figure out
* what data is available to figure out those laser paths. Here's my summary. -Jlauer
*
* Why clipper? Clipper is the library used to do boolean operations on polygons. Eagle
* gives us XY values for everything, and if we are to combine those into overall paths
* for milling, etc, then we need to merge those polygons. The clipper items below represent
* the clean final version of all that merging.
*
* clipperBySignalKey: {}, // contains all signals (wires)
* clipperDimension: {}, // contains dimension of board
* clipperElements: {},
* clipperPads: {}, // contains all pads (pads have holes)
* clipperSignalPolys: {}, // polygons that are signals like a GND plane
* clipperSignalWires: {}, // wires by name
* clipperSmds: {}, // all the smd pads, i.e. where components sit for soldering
* clipperVias: {}, // your vias. these have holes too.
* eagle: {}, // the parsed Eagle BRD XML into a structure
*/
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.setupFrequentThreeFeatures(); //global definition of frequently used Three features
this.setupUiFromLocalStorage();
this.btnSetup();
//this.status("Loaded...");
this.forkSetup();
this.lazyLoadTutorial();
//$('#com-chilipeppr-widget-eagle .btnAnimate').click( this.animateOverlapPath.bind(this) );
this.setupBlankBoardParamenters();
this.setupRegHolesParamenters();
// 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.setupMirrorAxis(); //V5.1D20161229 - Added
this.setupTabParameters();
this.setupLayerToggleDropdown();
//this.setupBoardMirrorCheckboxes(); V5.1D20161229 - Commented
this.setupSolderMaskTab();
console.log(this.name + " done loading.");
},
blankBoard: {
use: false,
x: 0,
y: 0,
width: 150,
height: 100
},
blankBoardSceneGroup: null,
setupBlankBoardParamenters: function() {
$("#com-chilipeppr-widget-eagle .use-blank-pcb").prop("checked", this.blankBoard.use);
$("#com-chilipeppr-widget-eagle .blank-pcb-width").val(this.blankBoard.width);
$("#com-chilipeppr-widget-eagle .blank-pcb-height").val(this.blankBoard.height);
$("#com-chilipeppr-widget-eagle .blank-pcb-x").val(this.blankBoard.x);
$("#com-chilipeppr-widget-eagle .blank-pcb-y").val(this.blankBoard.y);
$("#com-chilipeppr-widget-eagle .use-blank-pcb").change(this.onChangeBlankBoardParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .blank-pcb-width").change(this.onChangeBlankBoardParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .blank-pcb-height").change(this.onChangeBlankBoardParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .blank-pcb-x").change(this.onChangeBlankBoardParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .blank-pcb-y").change(this.onChangeBlankBoardParamenters.bind(this));
},
onChangeBlankBoardParamenters: function() {
this.blankBoard.use = $("#com-chilipeppr-widget-eagle .use-blank-pcb").prop("checked");
$("#com-chilipeppr-widget-eagle .use-reg-holes").prop("disabled", !this.blankBoard.use);
if(this.blankBoard.use)
$("#com-chilipeppr-widget-eagle .reg-holes-note").hide();
else
$("#com-chilipeppr-widget-eagle .reg-holes-note").show();
console.log("Ameen", $("#com-chilipeppr-widget-eagle .reg-holes-note"));
var item = $("#com-chilipeppr-widget-eagle .blank-pcb-x");
if (item.val() == "") item.val(this.blankBoard.x); else this.blankBoard.x = parseFloat(item.val());
item = $("#com-chilipeppr-widget-eagle .blank-pcb-y");
if (item.val() == "") item.val(this.blankBoard.y); else this.blankBoard.y = parseFloat(item.val());
item = $("#com-chilipeppr-widget-eagle .blank-pcb-width");
if (item.val() == "") item.val(this.blankBoard.width);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min);
if(v<min) {v = min; item.val(v);}
this.blankBoard.width = v;
}
item = $("#com-chilipeppr-widget-eagle .blank-pcb-height");
if (item.val() == "") item.val(this.blankBoard.height);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min);
if(v<min) {v = min; item.val(v);}
this.blankBoard.height = v;
}
if(this.blankBoardSceneGroup != null) this.sceneRemove(this.blankBoardSceneGroup);
this.draw3dBlankBoard();
if(this.regHolesSceneGroup != null) this.sceneRemove(this.regHolesSceneGroup);
this.regHoles.holes = this.getRegHoles();
this.draw3dRegHoles();
this.exportGcodeRegistrationHoles();
chilipeppr.publish('/com-chilipeppr-widget-3dviewer/drawextents' );
},
draw3dBlankBoard: function(){
if(!this.blankBoard.use) return;
var x1 = this.blankBoard.x,
x2 = this.blankBoard.x + this.blankBoard.width,
y1 = this.blankBoard.y,
y2 = this.blankBoard.y + this.blankBoard.height;
this.blankBoundaries = {
MinimumX: x1,
MinimumY: y1,
MaximumX: x2,
MaximumY: y2
};
var regColor = 0xB87333;
var lineMat = new THREE.LineBasicMaterial({
color: regColor,
transparent: true,
opacity: .4
});
var lineGeo = new THREE.Geometry();
lineGeo.vertices.push(new THREE.Vector3(x1, y1, 0));
lineGeo.vertices.push(new THREE.Vector3(x2, y1, 0));
lineGeo.vertices.push(new THREE.Vector3(x2, y2, 0));
lineGeo.vertices.push(new THREE.Vector3(x1, y2, 0));
lineGeo.vertices.push(new THREE.Vector3(x1, y1, 0));
var line = new THREE.Line(lineGeo, lineMat);
this.blankBoardSceneGroup = new THREE.Group();
this.blankBoardSceneGroup.add(line);
this.sceneAdd(this.blankBoardSceneGroup);
},
regHoles: {
use: true,
pattern: 201,
diameter: 3.175,
distance: 1,
holes: []
},
regHoleGcodePara: {
depth: -1.7,
clearance: 2,
feedrate: 200,
spindleRPM: 1200
},
regHolesSceneGroup: null,
setupRegHolesParamenters: function() {
$("#com-chilipeppr-widget-eagle .use-reg-holes").prop("checked", this.regHoles.use);
$("#com-chilipeppr-widget-eagle .use-reg-holes").prop("disabled", !this.blankBoard.use);
$("#com-chilipeppr-widget-eagle #reg-holes-pattern").val(this.regHoles.pattern);
$("#com-chilipeppr-widget-eagle .reg-holes-diameter").val(this.regHoles.diameter);
$("#com-chilipeppr-widget-eagle .reg-holes-distance").val(this.regHoles.distance);
$("#com-chilipeppr-widget-eagle .reg-holes-depth").val(this.regHoleGcodePara.depth);
$("#com-chilipeppr-widget-eagle .reg-holes-clearance").val(this.regHoleGcodePara.clearance);
$("#com-chilipeppr-widget-eagle .reg-holes-feedrate").val(this.regHoleGcodePara.feedrate);
$("#com-chilipeppr-widget-eagle .reg-holes-spindle-rpm").val(this.regHoleGcodePara.spindleRPM);
$("#com-chilipeppr-widget-eagle .use-reg-holes").change(this.onChangeRegHolesParamenters.bind(this));
$("#com-chilipeppr-widget-eagle #reg-holes-pattern").change(this.onChangeRegHolesParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-diameter").change(this.onChangeRegHolesParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-distance").change(this.onChangeRegHolesParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-sendgcodetows").click(this.sendRegHoleGcodeToWorkspace.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-depth").change(this.onChangeRegHolesGcodeParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-clearance").change(this.onChangeRegHolesGcodeParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-feedrate").change(this.onChangeRegHolesGcodeParamenters.bind(this));
$("#com-chilipeppr-widget-eagle .reg-holes-spindle-rpm").change(this.onChangeRegHolesGcodeParamenters.bind(this));
this.regHoles.holes = this.getRegHoles();
},
onChangeRegHolesGcodeParamenters: function() {
var item = $("#com-chilipeppr-widget-eagle .reg-holes-depth");
if (item.val() == "") item.val(this.regHoleGcodePara.depth);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min), max = parseFloat(item[0].max);
if(v>max) {v = max; item.val(v);}
if(v<min) {v = min; item.val(v);}
this.regHoleGcodePara.depth = v;
}
item = $("#com-chilipeppr-widget-eagle .reg-holes-clearance");
if (item.val() == "") item.val(this.regHoleGcodePara.clearance);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min);
if(v<min) {v = min; item.val(v);}
this.regHoleGcodePara.clearance = v;
}
item = $("#com-chilipeppr-widget-eagle .reg-holes-feedrate");
if (item.val() == "") item.val(this.regHoleGcodePara.feedrate);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min);
if(v<min) {v = min; item.val(v);}
this.regHoleGcodePara.feedrate = v;
}
item = $("#com-chilipeppr-widget-eagle .reg-holes-spindle-rpm");
if (item.val() == "") item.val(this.regHoleGcodePara.spindleRPM);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min);
if(v<min) {v = min; item.val(v);}
this.regHoleGcodePara.spindleRPM = v;
}
},
onChangeRegHolesParamenters: function() {
this.regHoles.use = $("#com-chilipeppr-widget-eagle .use-reg-holes").prop("checked");
this.regHoles.pattern = parseInt($('#com-chilipeppr-widget-eagle #reg-holes-pattern').val());
var item = $("#com-chilipeppr-widget-eagle .reg-holes-diameter");
if (item.val() == "") item.val(this.regHoles.diameter);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min), max = parseFloat(item[0].max);
if(v>max) {v = max; item.val(v);}
if(v<min) {v = min; item.val(v);}
this.regHoles.diameter = v;
}
item = $("#com-chilipeppr-widget-eagle .reg-holes-distance");
if (item.val() == "") item.val(this.regHoles.distance);
else {
var v = parseFloat(item.val()), min = parseFloat(item[0].min), max = parseFloat(item[0].max);
if(v>max) {v = max; item.val(v);}
if(v<min) {v = min; item.val(v);}
this.regHoles.distance = v;
}
this.regHoles.holes = this.getRegHoles();
if(this.regHolesSceneGroup != null)
this.sceneRemove(this.regHolesSceneGroup);
this.draw3dRegHoles();
this.exportGcodeRegistrationHoles();
},
getRegHoles: function(){
var pattern = this.regHoles.pattern;
var count = Math.round(pattern/100);
var onSides = Math.round((pattern - 100 * count)/10) == 1;
var v = (pattern - 100 * count - 10 * onSides) == 0;
var x = this.blankBoard.x,
y = this.blankBoard.y,
w = this.blankBoard.width,
h = this.blankBoard.height,
d = this.regHoles.distance + this.regHoles.diameter/2;
var holes = [];
if(count == 4){
holes.push({x: x + d, y: y + (onSides?h/2:d)});
holes.push({x: x + (onSides?w/2:d), y: y + h - d});
holes.push({x: x + w - d, y: y + (onSides?h/2:h-d)});
holes.push({x: x + (onSides?w/2:w-d), y: y + d});
}
else {
holes.push({x: x + (onSides?(v?w/2:d) :d ), y: y + (onSides?(v?d:h/2) :(v?d:h-d))});
holes.push({x: x + (onSides?(v?w/2:w-d):w-d), y: y + (onSides?(v?h-d:h/2):(v?h-d:d))});
}
return holes;
},
draw3dRegHoles: function(){
if(!this.regHoles.use || !this.blankBoard.use) return;
var that = this;
var r = this.regHoles.diameter/2;
var regColor = 0xB87333;
var lineMat = new THREE.LineBasicMaterial({
color: regColor,
transparent: true,
opacity: .4
});
this.regHolesSceneGroup = new THREE.Group();
var that = this;
this.regHoles.holes.forEach(function(hole){
var line = that.drawCircle(hole.x, hole.y, r, regColor, 32, .4);
line.rotateZ(Math.PI / 8);
that.regHolesSceneGroup.add(line);
var line1Geo = new THREE.Geometry();
line1Geo.vertices.push(new THREE.Vector3(hole.x-r/2, hole.y, 0));
line1Geo.vertices.push(new THREE.Vector3(hole.x+r/2, hole.y, 0));
var line1 = new THREE.Line(line1Geo, lineMat);
var line2Geo = new THREE.Geometry();
line2Geo.vertices.push(new THREE.Vector3(hole.x, hole.y-r/2, 0));
line2Geo.vertices.push(new THREE.Vector3(hole.x, hole.y+r/2, 0));
var line2 = new THREE.Line(line2Geo, lineMat);
that.regHolesSceneGroup.add(line1);
that.regHolesSceneGroup.add(line2);
});
this.sceneAdd(this.regHolesSceneGroup);
},
exportGcodeRegistrationHoles: function() {
var holes = this.regHoles.holes;
if(holes.length < 2 || !this.regHoles.use) {
$('#com-chilipeppr-widget-eagle .reg-holes-gcode').text("");
return;
}
var clearanceHeight = $("#com-chilipeppr-widget-eagle .reg-holes-clearance").val();
var drillDepth = $("#com-chilipeppr-widget-eagle .reg-holes-depth").val();
var drillFeedrate = $("#com-chilipeppr-widget-eagle .reg-holes-feedrate").val();
var spindleRPM = $("#com-chilipeppr-widget-eagle .reg-holes-spindle-rpm").val();
var toolDia = this.regHoles.diameter;
var g = '';
g += "(Gcode generated by ChiliPeppr Eagle PCB Widget " + (new Date()).toLocaleString() + ")\n";
g += "G21 (mm mode)\n";
g += "G90 (abs mode)\n";
g += "(------ DRILLING REGISTRATION HOLES -------)\n";
g += "M5 (spindle off)\n";
g += "T0 M6 (Drilling holes - diameter " + toolDia + "mm)\n";
g += "(T0 D=" + toolDia + "mm - PCB Drill Bit)\n";
g += "M3 S" + spindleRPM + " (spindle on)\n";
g += "F" + drillFeedrate + "\n";
holes.forEach(function(hole){
g += "G0 Z" + clearanceHeight + "\n";
g += "G0 X" + hole.x + " Y" + hole.y + "\n";
g += "G0 Z" + clearanceHeight/10 + "\n";
g += "G1 Z" + drillDepth + "\n";
g += "G1 Z" + clearanceHeight/10 + "\n";
});
g += "G0 Z" + clearanceHeight + "\n";
g += "M5 (spindle stop)\n";
g += "M30 (prog stop)\n";
$('#com-chilipeppr-widget-eagle .reg-holes-gcode').text(g);
},
sendRegHoleGcodeToWorkspace: function(){
this.exportGcodeRegistrationHoles();
var info = {
name: "Eagle Registration Holes",
lastModified: new Date()
};
// grab gcode from textarea
var gcodetxt = $('.reg-holes-gcode').text();
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);
chilipeppr.publish("/com-chilipeppr-elem-flashmsg/flashmsg", "Sent Gcode to Workspace", "Sent your solder mask Gcode to the workscape. Close the Eagle widget to see it.");
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();
});
},
/**
* This sets up the tab to generate solder mask Gcode.
*/
setupSolderMaskTab: function() {
console.log("setup soldermask");
var that = this;
$('.com-chilipeppr-widget-eagle-soldermask-render').click(this.solderMaskRender.bind(this));
$('.com-chilipeppr-widget-eagle-soldermask-showAsLine').click(this.solderMaskRender.bind(this));
$('.com-chilipeppr-widget-eagle-soldermask-showAsMesh').click(this.solderMaskRender.bind(this));
$('.com-chilipeppr-widget-eagle-soldermask-full').click(this.solderMaskRender.bind(this));
$('.com-chilipeppr-widget-eagle-soldermask-outline').click(this.solderMaskRender.bind(this));
$('.eagle-soldermask-regen-onrender').on('blur', this.solderMaskRender.bind(this));
$('.eagle-soldermask-regen-onrender-click').on('click', this.solderMaskRender.bind(this));
$('.eagle-soldermask-regen-onblur').on('blur', this.solderMaskGenerateGcode.bind(this));
$('.eagle-soldermask-regen-onchange').on('change', this.solderMaskGenerateGcode.bind(this));
$('.btn-eagle-soldermask-sendgcodetows').click(this.solderMaskSendGcodeToWorkspace.bind(this));
// if outline turned on, hide the overlap choice
$('.com-chilipeppr-widget-eagle-soldermask-outline').click(function() {
var isOutlineOnly = $('.com-chilipeppr-widget-eagle-soldermask-outline').is(":checked");
if (isOutlineOnly) {
// hide overlap input textbox
$('.com-chilipeppr-widget-soldermask-laser-overlapRegion').addClass("hidden");
// if outline is shown, show 3 sub-choices
$('.com-chilipeppr-widget-eagle-soldermask-outlineRegion').removeClass("hidden");
}
});
$('.com-chilipeppr-widget-eagle-soldermask-full').click(function() {
var isOutlineOnly = $('.com-chilipeppr-widget-eagle-soldermask-outline').is(":checked");
if (!isOutlineOnly) {
// show overlap input textbox
$('.com-chilipeppr-widget-soldermask-laser-overlapRegion').removeClass("hidden");
// if outline is not shown, hide 3 sub-choices
$('.com-chilipeppr-widget-eagle-soldermask-outlineRegion').addClass("hidden");
}
});
// based on mode, show/hide different sub-items
$('.eagle-soldermask-modetype').click(function() {
console.log("got click on mode type radio");
var mode = $('#' + that.id + ' input[name=com-chilipeppr-widget-eagle-soldermask-mode]:checked').val();
var laseron = $('#' + that.id + ' input[name=com-chilipeppr-widget-eagle-soldermask-laseron]:checked').val();
console.log("mode:", mode, "laseron:", laseron);
// if OutN selected, hide other options, show outn options
// if cayenn, show those options
$('.eagle-soldermask-modeoutN').addClass('hidden');
$('.eagle-soldermask-modecayenn').addClass('hidden');
$('.eagle-soldermask-modem3').addClass('hidden');
$('.eagle-soldermask-mode-millRegion').addClass('hidden');
if (mode == "laser") {
if (laseron == "outN") {
$('.eagle-soldermask-modeoutN').removeClass('hidden');
} else if (laseron == "cayenn") {
$('.eagle-soldermask-modecayenn').removeClass('hidden');
} else if (laseron == "M3") {
$('.eagle-soldermask-modem3').removeClass('hidden');
}
} else {
// mode is mill
$('.eagle-soldermask-mode-millRegion').removeClass('hidden');
}
});
// invert show/hide
$('.com-chilipeppr-widget-eagle-soldermask-invert').click(function() {
var isInvert = $('#' + that.id + ' input[name=com-chilipeppr-widget-eagle-soldermask-invert]:checked').val();
if (isInvert) {
$('.com-chilipeppr-widget-eagle-soldermask-invert-insetRegion').removeClass("hidden");
} else {
$('.com-chilipeppr-widget-eagle-soldermask-invert-insetRegion').addClass("hidden");
}
});
// when tab is shown, render solder mask
$('#' + this.id + ' a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
console.log("tab shown. e:", e);
if ($(e.target).text() == 'Solder Mask') {
// our tab got shown
console.log("Solder Mask tab showing");
setTimeout(that.solderMaskRender.bind(that), 100);
} else {
// since a different tab is showing, hide ours
console.log("Solder Mask tab hidden");
setTimeout(that.solderMaskRenderHide.bind(that), 10);
}
});
// $('#' + this.id + ' a[data-toggle="tab"]').on('hide.bs.tab', function (e) {
// console.log("tab hidden. e:", e);
// if ($(e.target).text() == 'Solder Mask') {
// // our tab got shown
// console.log("Solder Mask tab hidden");
// setTimeout(that.solderMaskRenderHide.bind(that), 10);
// }
// });
},
solderMaskRenderHide: function() {
if (this.solderMaskGrp != null) {
// this means we ran previously, and we should remove
this.sceneRemove(this.solderMaskGrp);
this.solderMaskGrp = null;
}
},
solderMaskGrp: null, // holds all THREE.js objects for solder mask
solderMaskGcodePath: [], // array of arrays of line paths
/**
* Look at all the pads/smds and render a path based on what the user gave us in
* the solder mask tab.
*/
solderMaskRender: function() {
console.log("solderMaskRender");
$('.com-chilipeppr-widget-eagle-infoTemp')
.html("Rendering path...")
.removeClass("hidden");
setTimeout(this.solderMaskRenderCallback.bind(this), 10);
},
solderMaskRenderCallback: function() {
// we will use clipperPads and clipperSmds
// create our overall THREE group
if (this.solderMaskGrp != null) {
// this means we ran previously, and we should remove
this.sceneRemove(this.solderMaskGrp);
}
this.solderMaskGrp = new THREE.Group();
// reset the final Gcode path
this.solderMaskGcodePath = [];
this.solderMaskGcodePath.push("move to safe height");
// get user width of laser or end mill
var w = 0.1; // mm
w = $('.com-chilipeppr-widget-soldermask-laser-width').val();
// get user overlap of path
var overlapPct = 20; // mm
overlapPct = $('.com-chilipeppr-widget-soldermask-laser-overlap').val();
// see if user wants to see actual path
var isShowAsMesh = true;
isShowAsMesh = $('.com-chilipeppr-widget-eagle-soldermask-showAsMesh').is(":checked");
var isOutlineOnly = false;
isOutlineOnly = $('.com-chilipeppr-widget-eagle-soldermask-outline').is(":checked");
var outlineOut, outlineOn, outlineIn;
if (isOutlineOnly) {
outlineOut = $('.com-chilipeppr-widget-eagle-soldermask-outlineOutside').is(":checked");
outlineOn = $('.com-chilipeppr-widget-eagle-soldermask-outlineOn').is(":checked");
outlineIn = $('.com-chilipeppr-widget-eagle-soldermask-outlineInside').is(":checked");
}
var isIncludeDimensions = $('.com-chilipeppr-widget-eagle-soldermask-outlineDimensions').is(":checked");
var isInvert = false;
isInvert = $('.com-chilipeppr-widget-eagle-soldermask-invert').is(":checked");
// hide the alert. we'll show it below if we find a path we can't render for
$('.eagle-soldermask-alert').addClass("hidden");
// create new array of pads and smds
var padsAndSmds = [];
padsAndSmds = padsAndSmds.concat(this.clipperPads.slice(0)); // clone
padsAndSmds = padsAndSmds.concat(this.clipperSmds.slice(0)); // clone
// if invert, branch to alternate render method just to keep stuff clean
// we probably should move the normal render to a method like this as well
// to keep the approaches parallel
if (isInvert) {
var opts = {
width: w,
overlapPct: overlapPct,
isShowAsMesh: isShowAsMesh,
isOutlineOnly: isOutlineOnly,
outlineOut: outlineOut,
outlineOn: outlineOn,
outlineIn: outlineIn,
gcodePath: this.solderMaskGcodePath,
threeGrp: this.solderMaskGrp,
padsAndSmds: padsAndSmds,
clipperDimension: this.clipperDimension,
// dimensions: this.clipperDimensions,
}
this.solderMaskRenderInvert(opts);
return;
}
padsAndSmds.forEach(function(pad) {
console.log("pad:", pad);
this.solderMaskGcodePath.push("move to pad/smd start");
var deflateBy = w * (1 - overlapPct / 100) * -1;
if (isOutlineOnly) {
// we change the deflateBy relevant to their settings
if (outlineOut) deflateBy = (w / 2) * 1;