-
Notifications
You must be signed in to change notification settings - Fork 2
/
toolbars.c
1013 lines (899 loc) · 37.1 KB
/
toolbars.c
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
#include "stdafx.h"
#include "LoftyCAD.h"
#include <CommCtrl.h>
#include <CommDlg.h>
#include <shellapi.h>
// Set up a tooltip for a button or other dialog item.
void
load_tooltip(HWND hWnd, int button, int toolstring)
{
char buffer[256];
HWND hWndButton = GetDlgItem(hWnd, button);
TOOLINFO ti = { 0 };
// Create a tooltip.
HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, TOOLTIPS_CLASS, NULL,
WS_POPUP | TTS_NOPREFIX | TTS_ALWAYSTIP,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
hWndButton, NULL, hInst, NULL);
SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0,
SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, 200);
ti.cbSize = sizeof(TOOLINFO);
ti.uFlags = TTF_SUBCLASS;
ti.hwnd = hWndButton;
ti.hinst = hInst;
LoadString(hInst, toolstring, buffer, 256);
ti.lpszText = buffer;
GetClientRect(hWndButton, &ti.rect);
// Associate the tooltip with the "tool" window.
SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM)(LPTOOLINFO)&ti);
}
// Put the icon in the button (if not zero) and set up a tooltip for the button.
void
LoadAndDisplayIcon(HWND hWnd, int icon, int button, int toolstring)
{
HICON hIcon;
if (icon != 0)
{
hIcon = LoadIcon(hInst, MAKEINTRESOURCE(icon));
SendDlgItemMessage(hWnd, button, BM_SETIMAGE, (WPARAM)IMAGE_ICON, (LPARAM)hIcon);
}
load_tooltip(hWnd, button, toolstring);
}
// Hook proc for the ChooseFont dialog.
int WINAPI
font_hook(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static Text *text;
static CHOOSEFONT *cf;
switch (msg)
{
case WM_INITDIALOG:
cf = (CHOOSEFONT *)lParam;
text = (Text *)cf->lCustData;
SetDlgItemText(hWnd, IDC_FONT_STRING, text->string);
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
GetDlgItemText(hWnd, IDC_FONT_STRING, text->string, 80);
break;
}
}
return 0;
}
// Window proc for the toolbar tab.
int WINAPI
toolbar_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
CHOOSEFONT cf;
LOGFONT lf;
PSHNOTIFY* notify;
switch (msg)
{
case WM_INITDIALOG:
hWndToolbar = hWnd;
LoadAndDisplayIcon(hWnd, IDI_EDGE, IDB_EDGE, IDS_EDGE);
LoadAndDisplayIcon(hWnd, IDI_RECT, IDB_RECT, IDS_RECT);
LoadAndDisplayIcon(hWnd, IDI_HEX, IDB_HEX, IDS_HEX);
LoadAndDisplayIcon(hWnd, IDI_CIRCLE, IDB_CIRCLE, IDS_CIRCLE);
LoadAndDisplayIcon(hWnd, IDI_CONST_EDGE, IDB_CONST_EDGE, IDS_CONST_EDGE);
LoadAndDisplayIcon(hWnd, IDI_CONST_RECT, IDB_CONST_RECT, IDS_CONST_RECT);
LoadAndDisplayIcon(hWnd, IDI_CONST_HEX, IDB_CONST_HEX, IDS_CONST_HEX);
LoadAndDisplayIcon(hWnd, IDI_CONST_CIRCLE, IDB_CONST_CIRCLE, IDS_CONST_CIRCLE);
LoadAndDisplayIcon(hWnd, IDI_BEZIER_EDGE, IDB_BEZIER_EDGE, IDS_BEZIER_EDGE);
LoadAndDisplayIcon(hWnd, IDI_ARC_EDGE, IDB_ARC_EDGE, IDS_ARC_EDGE);
LoadAndDisplayIcon(hWnd, IDI_BEZ_RECT, IDB_BEZ_RECT, IDS_BEZ_RECT);
LoadAndDisplayIcon(hWnd, IDI_BEZ_CIRCLE, IDB_BEZ_CIRCLE, IDS_BEZ_CIRCLE);
LoadAndDisplayIcon(hWnd, IDI_EXTRUDE, IDB_EXTRUDE, IDS_EXTRUDE);
LoadAndDisplayIcon(hWnd, IDI_EXTRUDE_LOCAL, IDB_EXTRUDE_LOCAL, IDS_EXTRUDE_LOCAL);
LoadAndDisplayIcon(hWnd, IDI_TEXT, IDB_TEXT, IDS_TEXT);
LoadAndDisplayIcon(hWnd, IDI_SCALE, IDB_SCALE, IDS_SCALE);
LoadAndDisplayIcon(hWnd, IDI_ROTATE, IDB_ROTATE, IDS_ROTATE);
LoadAndDisplayIcon(hWnd, IDI_RENDERED, IDB_RENDERED, IDS_RENDERED);
LoadAndDisplayIcon(hWnd, IDI_TOP, IDB_XY, IDS_XY);
LoadAndDisplayIcon(hWnd, IDI_FRONT, IDB_YZ, IDS_YZ);
LoadAndDisplayIcon(hWnd, IDI_LEFT, IDB_XZ, IDS_XZ);
LoadAndDisplayIcon(hWnd, IDI_BOTTOM, IDB_MINUS_XY, IDS_MINUS_XY);
LoadAndDisplayIcon(hWnd, IDI_BACK, IDB_MINUS_YZ, IDS_MINUS_YZ);
LoadAndDisplayIcon(hWnd, IDI_RIGHT, IDB_MINUS_XZ, IDS_MINUS_XZ);
// Tools are disabled when in render view
enable_rendered_view_items();
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
construction = FALSE;
switch (LOWORD(wParam))
{
case IDB_CONST_EDGE:
construction = TRUE;
case IDB_EDGE:
change_state(STATE_STARTING_EDGE);
break;
case IDB_ARC_EDGE:
change_state(STATE_STARTING_ARC);
break;
case IDB_BEZIER_EDGE:
change_state(STATE_STARTING_BEZIER);
break;
case IDB_CONST_RECT:
construction = TRUE;
case IDB_RECT:
change_state(STATE_STARTING_RECT);
break;
case IDB_CONST_HEX:
construction = TRUE;
case IDB_HEX:
change_state(STATE_STARTING_HEX);
break;
case IDB_CONST_CIRCLE:
construction = TRUE;
case IDB_CIRCLE:
change_state(STATE_STARTING_CIRCLE);
break;
case IDB_BEZ_RECT:
change_state(STATE_STARTING_BEZ_RECT);
break;
case IDB_BEZ_CIRCLE:
change_state(STATE_STARTING_BEZ_CIRCLE);
break;
case IDB_EXTRUDE:
change_state(STATE_STARTING_EXTRUDE);
break;
case IDB_EXTRUDE_LOCAL:
change_state(STATE_STARTING_EXTRUDE_LOCAL);
break;
case IDB_TEXT:
display_help_state(STATE_STARTING_TEXT); // get the prompt up
curr_text = calloc(1, sizeof(Text));
// Choose font and input string here
memset(&cf, 0, sizeof(CHOOSEFONT));
cf.lStructSize = sizeof(CHOOSEFONT);
cf.Flags = CF_NOSIZESEL | CF_TTONLY | CF_ENABLETEMPLATE | CF_ENABLEHOOK | CF_INITTOLOGFONTSTRUCT;
cf.lpTemplateName = MAKEINTRESOURCE(1543);
cf.lpfnHook = font_hook;
cf.lCustData = (LPARAM)curr_text;
memset(&lf, 0, sizeof(LOGFONT));
cf.lpLogFont = &lf;
if (!ChooseFont(&cf))
{
free(curr_text);
display_help_state(STATE_NONE);
break;
}
curr_text->bold = lf.lfWeight > FW_NORMAL;
curr_text->italic = lf.lfItalic;
strcpy_s(curr_text->font, 32, lf.lfFaceName);
// TODO check string and valid font here
change_state(STATE_STARTING_TEXT);
break;
case IDB_SCALE:
change_state(STATE_STARTING_SCALE);
break;
case IDB_ROTATE:
change_state(STATE_STARTING_ROTATE);
break;
case IDB_XY:
facing_plane = &plane_XY;
facing_index = PLANE_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XY\r\n");
#endif
trackball_InitQuat(quat_XY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_YZ:
facing_plane = &plane_YZ;
facing_index = PLANE_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane YZ\r\n");
#endif
trackball_InitQuat(quat_YZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_XZ:
facing_plane = &plane_XZ;
facing_index = PLANE_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XZ\r\n");
#endif
trackball_InitQuat(quat_mXZ); // negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XY:
facing_plane = &plane_mXY;
facing_index = PLANE_MINUS_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XY\r\n");
#endif
trackball_InitQuat(quat_mXY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_YZ:
facing_plane = &plane_mYZ;
facing_index = PLANE_MINUS_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -YZ\r\n");
#endif
trackball_InitQuat(quat_mYZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XZ:
facing_plane = &plane_mXZ;
facing_index = PLANE_MINUS_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XZ\r\n");
#endif
trackball_InitQuat(quat_XZ); // negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_RENDERED:
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
if (view_rendered)
{
view_rendered = FALSE;
glEnable(GL_BLEND);
CheckMenuItem(hMenu, ID_VIEW_RENDEREDVIEW, MF_UNCHECKED);
}
else
{
gen_view_list_tree_volumes(&object_tree);
if (!gen_view_list_tree_surfaces(&object_tree, &object_tree))
break;
view_rendered = TRUE;
glDisable(GL_BLEND);
CheckMenuItem(hMenu, ID_VIEW_RENDEREDVIEW, MF_CHECKED);
}
enable_rendered_view_items();
invalidate_dl();
break;
}
}
break;
case WM_NOTIFY:
notify = (PSHNOTIFY*)lParam;
switch (notify->hdr.code)
{
case PSN_SETACTIVE:
view_printer = FALSE;
glEnable(GL_BLEND);
invalidate_dl();
break;
case PSN_RESET:
view_tools = FALSE;
ShowWindow(hWndPropSheet, SW_HIDE);
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
CheckMenuItem(hMenu, ID_VIEW_TOOLS, view_tools ? MF_CHECKED : MF_UNCHECKED);
break;
}
break;
}
return 0;
}
// Window proc for the slicer tab.
int WINAPI
slicer_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
static HFONT hFontStd, hFontBold;
LOGFONT lf;
PSHNOTIFY* notify;
char printer[64], print[64], filament[64];
char cmd[1024], filename[MAX_PATH], dir[MAX_PATH], gcode_filename[MAX_PATH], button_title[256];
OPENFILENAME ofn;
int indx, len;
char* slosh, *pdot;
char inifile[MAX_PATH];
char buf[16];
char option[80];
static BOOL text_changed = FALSE;
static BOOL first_focus = FALSE;
switch (msg)
{
case WM_INITDIALOG:
hWndSlicer = hWnd;
read_slic3r_config("printer", IDC_SLICER_PRINTER, printer);
read_slic3r_config("print", IDC_SLICER_PRINTSETTINGS, printer);
read_slic3r_config("filament", IDC_SLICER_FILAMENT, printer);
indx = SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETLBTEXT, indx, (LPARAM)print);
read_string_and_load_dlgitem(print, "support_material", IDB_SLICER_SUPPORT, TRUE);
read_string_and_load_dlgitem(print, "layer_height", IDC_SLICER_LAYERHEIGHT, FALSE);
read_string_and_load_dlgitem(print, "perimeters", IDC_SLICER_WALLTHICK, FALSE);
read_string_and_load_dlgitem(print, "top_solid_layers", IDC_SLICER_ROOFTHICK, FALSE);
read_string_and_load_dlgitem(print, "bottom_solid_layers", IDC_SLICER_FLOORTHICK, FALSE);
read_string_and_load_dlgitem(print, "fill_density", IDC_SLICER_INFILL, FALSE);
// Get the font used by the edit boes, and make a bold version of it
hFontStd = (HFONT)SendDlgItemMessage(hWnd, IDC_SLICER_LAYERHEIGHT, WM_GETFONT, 0, 0);
GetObject(hFontStd, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
hFontBold = CreateFontIndirect(&lf);
if (curr_filename[0] == '\0')
{
SendDlgItemMessage(hWndSlicer, IDB_SLICER_SLICE, WM_SETTEXT, 0, (LPARAM)"Slice Current Model");
EnableWindow(GetDlgItem(hWndSlicer, IDB_SLICER_SLICE), FALSE);
}
else
{
strcpy_s(button_title, 256, "Export and Slice ");
strcat_s(button_title, 256, curr_filename);
SendDlgItemMessage(hWndSlicer, IDB_SLICER_SLICE, WM_SETTEXT, 0, (LPARAM)button_title);
EnableWindow(GetDlgItem(hWndSlicer, IDB_SLICER_SLICE), TRUE);
}
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDC_SLICER_PRINTER:
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
indx = SendDlgItemMessage(hWnd, IDC_SLICER_PRINTER, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_PRINTER, CB_GETLBTEXT, indx, (LPARAM)printer);
read_slic3r_config("print", IDC_SLICER_PRINTSETTINGS, printer);
read_slic3r_config("filament", IDC_SLICER_FILAMENT, printer);
// Pull out bed shape from cached printer section
set_bed_shape(printer);
break;
}
break;
case IDC_SLICER_PRINTSETTINGS:
switch (HIWORD(wParam))
{
case CBN_SELCHANGE:
indx = SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETLBTEXT, indx, (LPARAM)print);
read_string_and_load_dlgitem(print, "support_material", IDB_SLICER_SUPPORT, TRUE);
read_string_and_load_dlgitem(print, "layer_height", IDC_SLICER_LAYERHEIGHT, FALSE);
read_string_and_load_dlgitem(print, "perimeters", IDC_SLICER_WALLTHICK, FALSE);
read_string_and_load_dlgitem(print, "top_solid_layers", IDC_SLICER_ROOFTHICK, FALSE);
read_string_and_load_dlgitem(print, "bottom_solid_layers", IDC_SLICER_FLOORTHICK, FALSE);
read_string_and_load_dlgitem(print, "fill_density", IDC_SLICER_INFILL, FALSE);
SendDlgItemMessage(hWnd, IDC_SLICER_LAYERHEIGHT, WM_SETFONT, (WPARAM)hFontStd, TRUE);
SendDlgItemMessage(hWnd, IDC_SLICER_WALLTHICK, WM_SETFONT, (WPARAM)hFontStd, TRUE);
SendDlgItemMessage(hWnd, IDC_SLICER_ROOFTHICK, WM_SETFONT, (WPARAM)hFontStd, TRUE);
SendDlgItemMessage(hWnd, IDC_SLICER_FLOORTHICK, WM_SETFONT, (WPARAM)hFontStd, TRUE);
SendDlgItemMessage(hWnd, IDC_SLICER_INFILL, WM_SETFONT, (WPARAM)hFontStd, TRUE);
text_changed = FALSE;
break;
}
break;
case IDB_SLICER_SUPPORT:
switch (HIWORD(wParam))
{
case BN_CLICKED:
SetWindowLong(GetDlgItem(hWndSlicer, LOWORD(wParam)), GWL_USERDATA, 1);
break;
}
break;
case IDC_SLICER_LAYERHEIGHT:
case IDC_SLICER_WALLTHICK:
case IDC_SLICER_ROOFTHICK:
case IDC_SLICER_FLOORTHICK:
case IDC_SLICER_INFILL:
// Set changed overrides to bold face
switch (HIWORD(wParam))
{
case EN_SETFOCUS:
// Catch the first time it gets the focus, so we don't count
// the EN_CHANGE when the edit box is first written to
first_focus = TRUE;
break;
case EN_CHANGE:
text_changed = first_focus;
break;
case EN_KILLFOCUS:
if (text_changed)
{
SendDlgItemMessage(hWnd, LOWORD(wParam), WM_SETFONT, (WPARAM)hFontBold, TRUE);
SetWindowLong(GetDlgItem(hWndSlicer, LOWORD(wParam)), GWL_USERDATA, 1);
}
text_changed = FALSE;
}
break;
case IDB_SLICER_GUI:
ShellExecute(hWndSlicer, "open", slicer_exe[slicer_index].exe, NULL, NULL, SW_SHOW);
break;
case IDB_SLICER_SLICE_EXISTING:
// Open an existing triangle mesh (STL, AMF, ...) and slice it
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = auxGetHWND();
ofn.lpstrFilter =
"STL Meshes (*.STL)\0*.STL\0"
"AMF Files (*.AMF)\0*.AMF\0"
"OBJ Files (*.OBJ)\0*.OBJ\0"
"All Files\0*.*\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrDefExt = "lcd";
filename[0] = '\0';
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;
if (!GetOpenFileName(&ofn))
break;
goto slice_it;
case IDB_SLICER_SLICE:
// Export the object tree as STL (note: this may change with multi-materials)
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = auxGetHWND();
ofn.lpstrFilter =
"STL Meshes (*.STL)\0*.STL\0"
"STL Meshes for each material (*_1.STL)\0*.STL\0"
"All Files\0*.*\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrDefExt = "stl";
strcpy_s(filename, MAX_PATH, curr_filename);
pdot = strrchr(filename, '.');
if (pdot != NULL)
*pdot = '\0'; // cut off any ".lcd"
ofn.lpstrFile = filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&ofn))
break;
// Export the model
gen_view_list_tree_volumes(&object_tree);
if (!gen_view_list_tree_surfaces(&object_tree, &object_tree))
break;
export_object_tree(&object_tree, filename, ofn.nFilterIndex);
slice_it:
// Get the directory with its trailing '\\'
strcpy_s(dir, MAX_PATH, filename);
slosh = strrchr(dir, '\\');
*(slosh + 1) = '\0';
// Open the ini files for writing and fill them from the selected presets.
// Separate ini files are used as there may be duplicates between sections
strcpy_s(inifile, MAX_PATH, dir);
strcat_s(inifile, MAX_PATH, "slicer_settings_printer.ini");
indx = SendDlgItemMessage(hWnd, IDC_SLICER_PRINTER, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_PRINTER, CB_GETLBTEXT, indx, (LPARAM)printer);
get_slic3r_config_section("printer", printer, inifile);
// Add load options to slic3r cmd line for settings
strcpy_s(cmd, 1024, " --load ");
strcat_s(cmd, 1024, inifile);
strcpy_s(inifile, MAX_PATH, dir);
strcat_s(inifile, MAX_PATH, "slicer_settings_print.ini");
indx = SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_PRINTSETTINGS, CB_GETLBTEXT, indx, (LPARAM)print);
get_slic3r_config_section("print", print, inifile);
strcat_s(cmd, 1024, " --load ");
strcat_s(cmd, 1024, inifile);
strcpy_s(inifile, MAX_PATH, dir);
strcat_s(inifile, MAX_PATH, "slicer_settings_filament.ini");
indx = SendDlgItemMessage(hWnd, IDC_SLICER_FILAMENT, CB_GETCURSEL, 0, 0);
SendDlgItemMessage(hWnd, IDC_SLICER_FILAMENT, CB_GETLBTEXT, indx, (LPARAM)filament);
get_slic3r_config_section("filament", filament, inifile);
strcat_s(cmd, 1024, " --load ");
strcat_s(cmd, 1024, inifile);
// Build slic3r options. Centre model on the current print bed dimensions.
sprintf_s(option, 80, slicer_cmd[slicer_config[config_index].type],
(int)(bed_xmax - bed_xmin) / 2,
(int)(bed_ymax - bed_ymin) / 2);
strcat_s(cmd, 1024, option);
// Put in the output file option if we are specifying it explicitly.
// (otherwise it will be generated according to output_filename_format,
// but beware of PrusaSlicer issue #4872 messing this up)
if (explicit_gcode)
{
memset(&ofn, 0, sizeof(OPENFILENAME));
ofn.lStructSize = sizeof(OPENFILENAME);
ofn.hwndOwner = auxGetHWND();
ofn.lpstrFilter =
"G-code (*.GCODE)\0*.GCODE\0"
"All Files\0*.*\0\0";
ofn.nFilterIndex = 1;
ofn.lpstrDefExt = "gcode";
strcpy_s(gcode_filename, MAX_PATH, filename);
pdot = strrchr(gcode_filename, '.');
if (pdot != NULL)
*pdot = '\0'; // cut off any ".stl" and add extra stuff
ofn.lpstrFile = gcode_filename;
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_EXPLORER | OFN_OVERWRITEPROMPT;
if (!GetSaveFileName(&ofn))
break;
sprintf_s(option, 80, " -o %s ", gcode_filename);
strcat_s(cmd, 1024, option);
}
// Put in any changed overrrides as options. Apart from the infill density (below)
// NO checking is done.
if (GetWindowLong(GetDlgItem(hWnd, IDB_SLICER_SUPPORT), GWL_USERDATA) != 0)
{
if (IsDlgButtonChecked(hWnd, IDB_SLICER_SUPPORT))
strcat_s(cmd, 1024, " --support-material ");
else
strcat_s(cmd, 1024, " --no-support-material ");
}
if (GetWindowLong(GetDlgItem(hWnd, IDC_SLICER_LAYERHEIGHT), GWL_USERDATA) != 0)
{
SendDlgItemMessage(hWnd, IDC_SLICER_LAYERHEIGHT, WM_GETTEXT, 16, (LPARAM)buf);
sprintf_s(option, 80, " --layer-height %s ", buf);
strcat_s(cmd, 1024, option);
}
if (GetWindowLong(GetDlgItem(hWnd, IDC_SLICER_WALLTHICK), GWL_USERDATA) != 0)
{
SendDlgItemMessage(hWnd, IDC_SLICER_WALLTHICK, WM_GETTEXT, 16, (LPARAM)buf);
sprintf_s(option, 80, " --perimeters %s ", buf);
strcat_s(cmd, 1024, option);
}
if (GetWindowLong(GetDlgItem(hWnd, IDC_SLICER_ROOFTHICK), GWL_USERDATA) != 0)
{
SendDlgItemMessage(hWnd, IDC_SLICER_ROOFTHICK, WM_GETTEXT, 16, (LPARAM)buf);
sprintf_s(option, 80, " --top-solid-layers %s ", buf);
strcat_s(cmd, 1024, option);
}
if (GetWindowLong(GetDlgItem(hWnd, IDC_SLICER_FLOORTHICK), GWL_USERDATA) != 0)
{
SendDlgItemMessage(hWnd, IDC_SLICER_FLOORTHICK, WM_GETTEXT, 16, (LPARAM)buf);
sprintf_s(option, 80, " --bottom-solid-layers %s ", buf);
strcat_s(cmd, 1024, option);
}
if (GetWindowLong(GetDlgItem(hWnd, IDC_SLICER_INFILL), GWL_USERDATA) != 0)
{
SendDlgItemMessage(hWnd, IDC_SLICER_INFILL, WM_GETTEXT, 16, (LPARAM)buf);
// Make sure the "%" is present, otherwise PS runs away in an infinite loop!
// Raised issue #4887 on PS.
len = strlen(buf);
if (buf[len - 1] != '%')
strcat_s(buf, 16, "%");
sprintf_s(option, 80, " --fill-density %s ", buf);
strcat_s(cmd, 1024, option);
}
// Add the input file and run it
strcat_s(cmd, 1024, filename);
run_slicer(slicer_exe[slicer_index].exe, cmd, dir, gcode_filename);
break;
}
break;
case WM_NOTIFY:
notify = (PSHNOTIFY*)lParam;
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
switch (notify->hdr.code)
{
case PSN_SETACTIVE:
break;
case PSN_RESET:
view_tools = FALSE;
ShowWindow(hWndPropSheet, SW_HIDE);
CheckMenuItem(hMenu, ID_VIEW_TOOLS, view_tools ? MF_CHECKED : MF_UNCHECKED);
break;
}
break;
}
return 0;
}
// Window proc for the print preview tab.
int WINAPI
preview_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
PSHNOTIFY* notify;
char buf[16], print_button[128], gcode_filename[MAX_PATH];
switch (msg)
{
case WM_INITDIALOG:
hWndPrintPreview = hWnd;
LoadAndDisplayIcon(hWnd, IDI_TOP, IDB_XY, IDS_XY);
LoadAndDisplayIcon(hWnd, IDI_FRONT, IDB_YZ, IDS_YZ);
LoadAndDisplayIcon(hWnd, IDI_LEFT, IDB_XZ, IDS_XZ);
LoadAndDisplayIcon(hWnd, IDI_BOTTOM, IDB_MINUS_XY, IDS_MINUS_XY);
LoadAndDisplayIcon(hWnd, IDI_BACK, IDB_MINUS_YZ, IDS_MINUS_YZ);
LoadAndDisplayIcon(hWnd, IDI_RIGHT, IDB_MINUS_XZ, IDS_MINUS_XZ);
sprintf_s(buf, 16, "%.2f", print_zmin);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZFROM, WM_SETTEXT, 0, (LPARAM)buf);
sprintf_s(buf, 16, "%.2f", print_zmax);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZTO, WM_SETTEXT, 0, (LPARAM)buf);
if (print_zmin <= 0 && print_zmax >= 9999)
{
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), FALSE);
SendDlgItemMessage(hWnd, IDC_PRINTER_FULL, BM_CLICK, 0, 0);
}
else if (print_zmin == print_zmax)
{
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), FALSE);
SendDlgItemMessage(hWnd, IDC_PRINTER_LAYER, BM_CLICK, 0, 0);
}
else
{
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), TRUE);
SendDlgItemMessage(hWnd, IDC_PRINTER_UPTO, BM_CLICK, 0, 0);
}
if (print_octo)
sprintf_s(print_button, 128, "Upload G-code to %s", octoprint_server);
else
sprintf_s(print_button, 128, "Print G-code to %s", printer_port);
SendDlgItemMessage(hWndPrintPreview, IDB_PRINTER_PRINT, WM_SETTEXT, 0, (LPARAM)print_button);
EnableWindow(GetDlgItem(hWnd, IDB_PRINTER_PRINT), FALSE);
SendDlgItemMessage(hWndPrintPreview, IDC_PRINT_FILENAME, WM_SETTEXT, 0, (LPARAM)"");
SendDlgItemMessage(hWndPrintPreview, IDC_PRINT_FIL_USED, WM_SETTEXT, 0, (LPARAM)"");
SendDlgItemMessage(hWndPrintPreview, IDC_PRINT_EST_PRINT, WM_SETTEXT, 0, (LPARAM)"");
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDC_PRINTER_FULL:
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), FALSE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), FALSE);
print_zmin = 0;
print_zmax = 9999;
invalidate_dl();
break;
case IDC_PRINTER_LAYER:
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), FALSE);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZFROM, WM_GETTEXT, 16, (LPARAM)buf);
print_zmin = print_zmax = (double)atof(buf);
invalidate_dl();
break;
case IDC_PRINTER_UPTO:
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZFROM), TRUE);
EnableWindow(GetDlgItem(hWnd, IDC_PRINTER_ZTO), TRUE);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZFROM, WM_GETTEXT, 16, (LPARAM)buf);
print_zmin = (double)atof(buf);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZTO, WM_GETTEXT, 16, (LPARAM)buf);
print_zmax = (double)atof(buf);
invalidate_dl();
break;
case IDB_XY:
facing_plane = &plane_XY;
facing_index = PLANE_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XY\r\n");
#endif
trackball_InitQuat(quat_XY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_YZ:
facing_plane = &plane_YZ;
facing_index = PLANE_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane YZ\r\n");
#endif
trackball_InitQuat(quat_YZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_XZ:
facing_plane = &plane_XZ;
facing_index = PLANE_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XZ\r\n");
#endif
trackball_InitQuat(quat_mXZ); // negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XY:
facing_plane = &plane_mXY;
facing_index = PLANE_MINUS_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XY\r\n");
#endif
trackball_InitQuat(quat_mXY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_YZ:
facing_plane = &plane_mYZ;
facing_index = PLANE_MINUS_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -YZ\r\n");
#endif
trackball_InitQuat(quat_mYZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XZ:
facing_plane = &plane_mXZ;
facing_index = PLANE_MINUS_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XZ\r\n");
#endif
trackball_InitQuat(quat_XZ); // negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_PRINTER_PRINT:
if (SendDlgItemMessage(hWnd, IDC_PRINT_FILENAME, WM_GETTEXT, MAX_PATH, (LPARAM)gcode_filename) == 0)
break;
if (print_octo)
send_to_octoprint(gcode_filename, "local");
else
send_to_serial(gcode_filename);
break;
}
}
else if (HIWORD(wParam) == EN_KILLFOCUS)
{
if (LOWORD(wParam) == IDC_PRINTER_ZFROM)
{
SendDlgItemMessage(hWnd, IDC_PRINTER_ZFROM, WM_GETTEXT, 16, (LPARAM)buf);
print_zmin = (double)atof(buf);
if (print_zmax < print_zmin)
{
print_zmax = print_zmin;
sprintf_s(buf, 16, "%.2f", print_zmax);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZTO, WM_SETTEXT, 0, (LPARAM)buf);
}
invalidate_dl();
}
else if (LOWORD(wParam) == IDC_PRINTER_ZTO)
{
SendDlgItemMessage(hWnd, IDC_PRINTER_ZTO, WM_GETTEXT, 16, (LPARAM)buf);
print_zmax = (double)atof(buf);
if (print_zmin > print_zmax)
{
print_zmin = print_zmax;
sprintf_s(buf, 16, "%.2f", print_zmin);
SendDlgItemMessage(hWnd, IDC_PRINTER_ZFROM, WM_SETTEXT, 0, (LPARAM)buf);
}
invalidate_dl();
}
}
break;
case WM_NOTIFY:
notify = (PSHNOTIFY*)lParam;
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
switch (notify->hdr.code)
{
case PSN_SETACTIVE:
view_printer = TRUE;
view_rendered = FALSE;
glDisable(GL_BLEND);
invalidate_dl();
view_printbed = TRUE;
CheckMenuItem(hMenu, ID_VIEW_PRINTBED, MF_CHECKED);
break;
case PSN_RESET:
view_tools = FALSE;
ShowWindow(hWndPropSheet, SW_HIDE);
CheckMenuItem(hMenu, ID_VIEW_TOOLS, view_tools ? MF_CHECKED : MF_UNCHECKED);
break;
}
break;
}
return 0;
}
// Window proc for the printer tab.
int WINAPI
printer_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
PSHNOTIFY* notify;
switch (msg)
{
case WM_INITDIALOG:
hWndPrinter = hWnd;
LoadAndDisplayIcon(hWnd, IDI_TOP, IDB_XY, IDS_XY);
LoadAndDisplayIcon(hWnd, IDI_FRONT, IDB_YZ, IDS_YZ);
LoadAndDisplayIcon(hWnd, IDI_LEFT, IDB_XZ, IDS_XZ);
LoadAndDisplayIcon(hWnd, IDI_BOTTOM, IDB_MINUS_XY, IDS_MINUS_XY);
LoadAndDisplayIcon(hWnd, IDI_BACK, IDB_MINUS_YZ, IDS_MINUS_YZ);
LoadAndDisplayIcon(hWnd, IDI_RIGHT, IDB_MINUS_XZ, IDS_MINUS_XZ);
break;
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
//case IDC_PRINTER_FULL:
// break;
case IDB_XY:
facing_plane = &plane_XY;
facing_index = PLANE_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XY\r\n");
#endif
trackball_InitQuat(quat_XY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_YZ:
facing_plane = &plane_YZ;
facing_index = PLANE_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane YZ\r\n");
#endif
trackball_InitQuat(quat_YZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_XZ:
facing_plane = &plane_XZ;
facing_index = PLANE_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane XZ\r\n");
#endif
trackball_InitQuat(quat_mXZ); // negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XY:
facing_plane = &plane_mXY;
facing_index = PLANE_MINUS_XY;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XY\r\n");
#endif
trackball_InitQuat(quat_mXY);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_YZ:
facing_plane = &plane_mYZ;
facing_index = PLANE_MINUS_YZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -YZ\r\n");
#endif
trackball_InitQuat(quat_mYZ);
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
case IDB_MINUS_XZ:
facing_plane = &plane_mXZ;
facing_index = PLANE_MINUS_XZ;
#ifdef DEBUG_TOOLBAR_FACING
Log("Facing plane -XZ\r\n");
#endif
trackball_InitQuat(quat_XZ); //negation deliberate
SetWindowPos(auxGetHWND(), HWND_TOP, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOREPOSITION);
break;
}
}
else if (HIWORD(wParam) == EN_KILLFOCUS)
{
// if (LOWORD(wParam) == IDC_PRINTER_ZFROM)
// {
// }
}
break;
case WM_NOTIFY:
notify = (PSHNOTIFY*)lParam;
hMenu = GetSubMenu(GetMenu(auxGetHWND()), 2);
switch (notify->hdr.code)
{
case PSN_SETACTIVE:
view_printer = TRUE;
view_rendered = FALSE;
glDisable(GL_BLEND);
invalidate_dl();
view_printbed = TRUE;
CheckMenuItem(hMenu, ID_VIEW_PRINTBED, MF_CHECKED);
break;
case PSN_RESET:
view_tools = FALSE;
ShowWindow(hWndPropSheet, SW_HIDE);
CheckMenuItem(hMenu, ID_VIEW_TOOLS, view_tools ? MF_CHECKED : MF_UNCHECKED);
break;
}
break;
}
return 0;
}
// Wndproc for debug log dialog. Contains one large edit box.
int WINAPI
debug_dialog(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
HMENU hMenu;
switch (msg)
{
case WM_COMMAND:
if (HIWORD(wParam) == BN_CLICKED)
{
switch (LOWORD(wParam))
{
case IDB_CLEARDEBUG:
SendDlgItemMessage(hWnd, IDC_DEBUG, EM_SETSEL, 0, -1);
SendDlgItemMessage(hWnd, IDC_DEBUG, EM_REPLACESEL, 0, (LPARAM)"");
break;
}
}