-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgui_mode.cpp
More file actions
1575 lines (1327 loc) · 56 KB
/
Copy pathgui_mode.cpp
File metadata and controls
1575 lines (1327 loc) · 56 KB
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
// Tool mode switching, keyboard routing, and Options panel (mode-specific UI).
#include <GLFW/glfw3.h>
#include <algorithm>
#include <array>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <optional>
#include <string_view>
#include <unordered_map>
#include <vector>
#include "utl_geom.h"
#include "gui.h"
#include "imgui.h"
#include "imgui_internal.h"
#include "mode.h"
#include "gui_occt_view.h"
#include "skt.h"
#include "utl_occt.h"
#include <gp_Pnt2d.hxx>
using namespace glm;
namespace
{
constexpr ImGuiTableFlags k_options_table_flags = ImGuiTableFlags_SizingFixedFit;
constexpr float k_options_control_col_w = 148.f;
constexpr float k_options_sketch_control_col_w = 176.f;
void options_table_setup_columns_(float label_col_w, float control_col_w);
void options_right_aligned_label_(const char* text);
void format_double_trim_fraction_(char* dst, std::size_t dst_sz, double v, int max_frac);
void set_default_material_(const std::vector<std::string>& material_names, int current_mat, Occt_view::uptr& view);
} // namespace
std::string GUI::get_doc_url_for_mode(Mode mode)
{
static const std::unordered_map<Mode, std::string> doc_urls = {
// clang-format off
{Mode::Normal, "https://ezycad.readthedocs.io/en/latest/usage.html#user-interface"},
{Mode::Move, "https://ezycad.readthedocs.io/en/latest/usage.html#shape-move-tool-g"},
{Mode::Rotate, "https://ezycad.readthedocs.io/en/latest/usage.html#shape-rotate-tool-r"},
{Mode::Scale, "https://ezycad.readthedocs.io/en/latest/usage.html#shape-scale-tool-s"},
{Mode::Shape_shaft_align, "https://ezycad.readthedocs.io/en/latest/usage.html#align-shafts-tool-j"},
{Mode::Sketch_inspection_mode, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#sketch-origin"},
{Mode::Sketch_from_planar_face, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#create-sketch-from-planar-face-tool"},
{Mode::Sketch_face_extrude, "https://ezycad.readthedocs.io/en/latest/usage.html#extrude-sketch-face-tool-e"},
{Mode::Shape_chamfer, "https://ezycad.readthedocs.io/en/latest/usage.html#other-feature-operations"},
{Mode::Shape_fillet, "https://ezycad.readthedocs.io/en/latest/usage.html#other-feature-operations"},
{Mode::Shape_polar_duplicate, "https://ezycad.readthedocs.io/en/latest/usage.html#shape-polar-duplicate-tool"},
{Mode::Sketch_add_node, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#add-node-tool"},
{Mode::Sketch_add_edge, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#single-line-edge-tool"},
{Mode::Sketch_add_multi_edges, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#multi-line-edge-tool"},
{Mode::Sketch_add_seg_circle_arc, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#arc-segment-creation-tool"},
{Mode::Sketch_operation_axis, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#operation-axis-tool"},
{Mode::Sketch_add_square, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#square-tool"},
{Mode::Sketch_add_rectangle, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#rectangle-tool-two-points"},
{Mode::Sketch_add_rectangle_center_pt, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#rectangle-tool-center-point"},
{Mode::Sketch_add_circle, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#circle-creation-tools"},
{Mode::Sketch_add_circle_3_pts, ""}, // planned feature - no specific section in the docs yet; falls back to main guide
{Mode::Sketch_add_slot, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#slot-creation-tool"},
{Mode::Sketch_dim_anno, "https://ezycad.readthedocs.io/en/latest/usage-sketch.html#dimension-tool"},
{Mode::Shape_cross_section, "https://ezycad.readthedocs.io/en/latest/usage.html#shape-cross-section-tool"},
// clang-format on
};
EZY_ASSERT_MSG(doc_urls.size() == static_cast<std::size_t>(Mode::_count),
"get_doc_url_for_mode: doc_urls map size does not match Mode::_count");
auto it = doc_urls.find(mode);
if (it != doc_urls.end() && !it->second.empty())
return it->second;
// fallback to main guide
return "https://ezycad.readthedocs.io/en/latest/usage.html";
}
const char* GUI::current_mode_description_() const
{
for (const auto& b : m_toolbar_buttons)
if (b.data.index() == 0) // holds a Mode
if (std::get<Mode>(b.data) == m_mode)
return b.tooltip.c_str();
EZY_ASSERT_MSG(false, "Current mode not found in toolbar buttons");
return "";
}
void GUI::options_doc_help_button_()
{
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
if (get_mode() == Mode::Sketch_face_extrude)
{
GUI_DOC_HELP_("Extrude a sketch face into a solid. Dense faces can use a fast drag preview "
"(face copies) controlled in Settings -> Sketch -> Appearance -> Extrude fast preview. "
"Click ? to open the user guide.",
doc_urls::k_extrude_sketch_face);
return;
}
GUI_DOC_HELP_("Open the relevant section of the online user guide.", get_doc_url_for_mode(get_mode()).c_str());
}
void GUI::set_mode(Mode mode)
{
cancel_underlay_calib_();
m_mode = mode;
m_view->on_mode();
sync_sketch_add_mid_pt_edges_if_applicable_();
for (Toolbar_button& b : m_toolbar_buttons)
if (b.data.index() == 0)
b.is_active = std::get<Mode>(b.data) == mode;
}
Mode GUI::parent_mode_of(Mode mode)
{
static const std::map<Mode, Mode> parent_modes = {
// clang-format off
{Mode::Normal, Mode::Normal},
{Mode::Move, Mode::Normal},
{Mode::Scale, Mode::Normal},
{Mode::Rotate, Mode::Normal},
{Mode::Shape_shaft_align, Mode::Normal},
{Mode::Sketch_inspection_mode, Mode::Normal},
{Mode::Sketch_from_planar_face, Mode::Normal},
{Mode::Sketch_face_extrude, Mode::Normal},
{Mode::Shape_chamfer, Mode::Normal},
{Mode::Shape_fillet, Mode::Normal},
{Mode::Shape_polar_duplicate, Mode::Normal},
{Mode::Sketch_add_node, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_edge, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_multi_edges, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_seg_circle_arc, Mode::Sketch_inspection_mode},
{Mode::Sketch_operation_axis, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_square, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_rectangle, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_rectangle_center_pt, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_circle, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_circle_3_pts, Mode::Sketch_inspection_mode},
{Mode::Sketch_add_slot, Mode::Sketch_inspection_mode},
{Mode::Sketch_dim_anno, Mode::Sketch_inspection_mode},
{Mode::Shape_cross_section, Mode::Normal},
// clang-format on
};
static const bool check = []()
{
for (size_t idx = 0; idx < size_t(Mode::_count); ++idx)
EZY_ASSERT(parent_modes.find(Mode(idx)) != parent_modes.end());
return true;
}();
(void)check;
const auto itr = parent_modes.find(mode);
EZY_ASSERT(itr != parent_modes.end());
return itr->second;
}
void GUI::set_parent_mode() { set_mode(parent_mode_of(get_mode())); }
void GUI::on_key(int key, int scancode, int action, int mods)
{
(void)scancode;
const bool press_or_repeat = (action == GLFW_PRESS || action == GLFW_REPEAT);
// Capture before fixed view/nav handlers so reserved chords can be rejected with a message.
if (action == GLFW_PRESS && try_capture_hotkey_press_(key, mods))
return;
// Zoom (+/-): scaled like mouse wheel; GLFW_REPEAT while held; Shift = Blender-style finer step.
if (press_or_repeat && (mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT)) == 0)
{
bool zoom_in = false;
bool zoom_out = false;
// Shift+= is the main-keyboard zoom-in path; Shift is structural (produces '+'), not "finer step" intent.
bool zoom_in_shift_is_structural = false;
switch (key)
{
case GLFW_KEY_KP_ADD:
zoom_in = true;
break;
case GLFW_KEY_KP_SUBTRACT:
case GLFW_KEY_MINUS:
zoom_out = true;
break;
case GLFW_KEY_EQUAL:
if ((mods & GLFW_MOD_SHIFT) != 0)
{
zoom_in = true;
zoom_in_shift_is_structural = true;
}
break;
default:
break;
}
const bool shift_finer = ((mods & GLFW_MOD_SHIFT) != 0) && !zoom_in_shift_is_structural;
if (zoom_in)
{
m_view->zoom_view_wheel_notches(1.0, shift_finer);
return;
}
else if (zoom_out)
{
m_view->zoom_view_wheel_notches(-1.0, shift_finer);
return;
}
}
// Blender-style view roll: Shift + NumPad 4/6, main 4/6, or Left/Right (NumLock-on numpad often maps here).
// Use PRESS and REPEAT (like zoom) so hold-to-repeat works; route before keypad digit -> selection filter.
if (press_or_repeat && (mods & GLFW_MOD_SHIFT) != 0 && (mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT)) == 0)
{
const bool roll_ccw = (key == GLFW_KEY_KP_4 || key == GLFW_KEY_4 || key == GLFW_KEY_LEFT);
const bool roll_cw = (key == GLFW_KEY_KP_6 || key == GLFW_KEY_6 || key == GLFW_KEY_RIGHT);
if (roll_ccw || roll_cw)
{
const double step = m_view_roll_step_deg;
m_view->roll_view_z_deg(roll_ccw ? -step : step);
return;
}
}
if (action != GLFW_PRESS)
return;
// Nearest world-axis orthographic view (roll zero). Routes before Normal-mode keypad selection filters.
if (key == GLFW_KEY_KP_5 && (mods & (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT)) == 0)
{
m_view->snap_view_to_nearest_standard_axis();
return;
}
// Orbit like trihedron / LMB orbit (AIS_ViewController axes); step matches Settings view rotation step.
if ((mods & (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT)) == 0)
{
const double step = m_view_roll_step_deg;
// clang-format off
switch (key)
{
case GLFW_KEY_KP_8: m_view->orbit_view_screen_step_deg(0.0, step); return;
case GLFW_KEY_KP_2: m_view->orbit_view_screen_step_deg(0.0, -step); return;
case GLFW_KEY_KP_4: m_view->orbit_view_screen_step_deg(step, 0.0); return;
case GLFW_KEY_KP_6: m_view->orbit_view_screen_step_deg(-step, 0.0); return;
default: break;
}
// clang-format on
}
const ScreenCoords screen_coords = cursor_screen_coords();
// -------------------------------------------------------------------------
// Shape selection filter hotkeys (Options -> Selection Mode combo, Normal mode only)
//
// Maps main-row 1-9 and keypad 1-9 to TopAbs_ShapeEnum values 0..8 in OCCT order
// (same order as c_names_TopAbs_ShapeEnum in utl_occt.h):
// 1 Compound, 2 CompSolid, 3 Solid, 4 Shell, 5 Face, 6 Wire, 7 Edge, 8 Vertex, 9 Shape
//
// Input routing: main.cpp calls GUI::on_key only when !io.WantTextInput, so digits go to
// text fields while typing. We return early so these keys are not handled again below.
//
// Other modes: chamfer/fillet/sketch may override selection mode via Occt_view::on_mode().
// -------------------------------------------------------------------------
if (get_mode() == Mode::Normal)
{
int idx = -1;
if (key >= GLFW_KEY_1 && key <= GLFW_KEY_9)
idx = key - GLFW_KEY_1;
else if (key >= GLFW_KEY_KP_1 && key <= GLFW_KEY_KP_9)
idx = key - GLFW_KEY_KP_1;
if (idx >= 0 && idx <= static_cast<int>(TopAbs_SHAPE) && (mods & (GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)) == 0)
{
m_view->set_shp_selection_mode(static_cast<TopAbs_ShapeEnum>(idx));
return;
}
}
switch (key)
{
case GLFW_KEY_ESCAPE:
if (m_hotkey_capture_action)
{
m_hotkey_capture_action.reset();
m_hotkey_capture_error.clear();
return;
}
cancel_underlay_calib_();
hide_sketch_origin_set_edit(false);
hide_dist_edit(false);
hide_angle_edit(false);
m_view->cancel(Set_parent_mode::Yes);
return;
case GLFW_KEY_TAB:
{
// Move / Rotate / Align shafts handle Tab in their mode key handlers (distance / angle / depth / twist).
const Mode mode = get_mode();
if (mode == Mode::Move || mode == Mode::Rotate || mode == Mode::Shape_shaft_align)
break;
bool shift_pressed = (mods & GLFW_MOD_SHIFT) != 0;
if (shift_pressed)
m_view->angle_input(screen_coords);
else
m_view->dimension_input(screen_coords);
return;
}
case GLFW_KEY_ENTER:
// Rotate / Align shafts finalize on Enter in their mode key handlers.
if (get_mode() == Mode::Rotate || get_mode() == Mode::Shape_shaft_align)
break;
hide_sketch_origin_set_edit(true);
hide_dist_edit();
hide_angle_edit();
m_view->on_enter(screen_coords);
return;
case GLFW_KEY_DELETE:
case GLFW_KEY_BACKSPACE:
// Fixed aliases: remapping edit.delete (default Shift+D) must not remove these keys.
m_view->delete_selected();
return;
default:
break;
}
// Fixed second redo chord (Ctrl+Shift+Z); edit.redo default remains Ctrl+Y.
if (key == GLFW_KEY_Z && (mods & GLFW_MOD_CONTROL) != 0 && (mods & GLFW_MOD_SHIFT) != 0 &&
(mods & (GLFW_MOD_ALT | GLFW_MOD_SUPER)) == 0)
{
m_view->redo();
return;
}
if (const std::optional<Gui_action> act = m_hotkeys.action_for(key, mods))
{
dispatch_hotkey_action_(*act);
return;
}
switch (get_mode())
{
case Mode::Move:
on_key_move_mode_(key);
break;
case Mode::Rotate:
on_key_rotate_mode_(key);
break;
case Mode::Shape_shaft_align:
on_key_cyl_align_mode_(key, mods);
break;
default:
break;
}
}
void GUI::dispatch_hotkey_action_(Gui_action action)
{
// clang-format off
switch (action)
{
case Gui_action::Mode_move: set_mode(Mode::Move); break;
case Gui_action::Mode_rotate: set_mode(Mode::Rotate); break;
case Gui_action::Mode_scale: set_mode(Mode::Scale); break;
case Gui_action::Mode_cyl_align: set_mode(Mode::Shape_shaft_align); break;
case Gui_action::Mode_extrude: set_mode(Mode::Sketch_face_extrude); break;
case Gui_action::Mode_chamfer: set_mode(Mode::Shape_chamfer); break;
case Gui_action::Mode_fillet: set_mode(Mode::Shape_fillet); break;
case Gui_action::Mode_dimension: set_mode(Mode::Sketch_dim_anno); break;
case Gui_action::Mode_sketch_inspection: set_mode(Mode::Sketch_inspection_mode); break;
case Gui_action::Mode_sketch_from_face: set_mode(Mode::Sketch_from_planar_face); break;
case Gui_action::Mode_operation_axis: set_mode(Mode::Sketch_operation_axis); break;
case Gui_action::Mode_add_node: set_mode(Mode::Sketch_add_node); break;
case Gui_action::Mode_add_edge: set_mode(Mode::Sketch_add_edge); break;
case Gui_action::Mode_add_multi_edges: set_mode(Mode::Sketch_add_multi_edges); break;
case Gui_action::Mode_add_arc: set_mode(Mode::Sketch_add_seg_circle_arc); break;
case Gui_action::Mode_add_square: set_mode(Mode::Sketch_add_square); break;
case Gui_action::Mode_add_rectangle: set_mode(Mode::Sketch_add_rectangle); break;
case Gui_action::Mode_add_rectangle_center: set_mode(Mode::Sketch_add_rectangle_center_pt); break;
case Gui_action::Mode_add_circle: set_mode(Mode::Sketch_add_circle); break;
case Gui_action::Mode_add_circle_3_pts: set_mode(Mode::Sketch_add_circle_3_pts); break;
case Gui_action::Mode_add_slot: set_mode(Mode::Sketch_add_slot); break;
case Gui_action::Mode_polar_duplicate: set_mode(Mode::Shape_polar_duplicate); break;
case Gui_action::Mode_cross_section: set_mode(Mode::Shape_cross_section); break;
case Gui_action::Cmd_shape_cut:
if (Status s = m_view->shp_cut().selected_cut(); !s.is_ok())
show_message(s.message());
break;
case Gui_action::Cmd_shape_fuse:
if (Status s = m_view->shp_fuse().selected_fuse(); !s.is_ok())
show_message(s.message());
break;
case Gui_action::Cmd_shape_common:
if (Status s = m_view->shp_common().selected_common(); !s.is_ok())
show_message(s.message());
break;
case Gui_action::Edit_delete: m_view->delete_selected(); break;
case Gui_action::Edit_copy:
if (Status s = m_view->copy_selected_shapes(); !s.is_ok())
show_message(s.message());
break;
case Gui_action::Edit_paste:
if (Status s = m_view->paste_clipboard_shapes(); !s.is_ok())
show_message(s.message());
break;
case Gui_action::File_new: new_project_(); break;
case Gui_action::File_open: open_file_dialog_(); break;
case Gui_action::File_save: save_file_dialog_(); break;
case Gui_action::Edit_undo: m_view->undo(); break;
case Gui_action::Edit_redo: m_view->redo(); break;
case Gui_action::_count:
EZY_ASSERT(false); // Logic error: _count should never be dispatched as an action.
break;
}
// clang-format on
}
bool GUI::try_capture_hotkey_press_(int key, int mods)
{
if (!m_hotkey_capture_action)
return false;
switch (key)
{
case GLFW_KEY_LEFT_SHIFT:
case GLFW_KEY_RIGHT_SHIFT:
case GLFW_KEY_LEFT_CONTROL:
case GLFW_KEY_RIGHT_CONTROL:
case GLFW_KEY_LEFT_ALT:
case GLFW_KEY_RIGHT_ALT:
case GLFW_KEY_LEFT_SUPER:
case GLFW_KEY_RIGHT_SUPER:
return true; // keep capturing; ignore pure modifiers
case GLFW_KEY_ESCAPE:
m_hotkey_capture_action.reset();
m_hotkey_capture_error.clear();
return true;
default:
break;
}
const Key_chord chord{key, Gui_hotkeys::normalize_mods(mods)};
if (!Gui_hotkeys::is_bindable_key(key))
{
m_hotkey_capture_error = "Unsupported key. Use a letter, digit, or Space (modifiers allowed).";
show_message(m_hotkey_capture_error);
return true;
}
if (Gui_hotkeys::is_reserved_chord(chord))
{
m_hotkey_capture_error = "Reserved: " + Gui_hotkeys::format_chord(chord) + " is a fixed shortcut and cannot be remapped.";
show_message(m_hotkey_capture_error);
return true;
}
if (!m_hotkeys.set_chord(*m_hotkey_capture_action, chord))
{
m_hotkey_capture_error = "Conflict: " + Gui_hotkeys::format_chord(chord) + " is already assigned.";
show_message(m_hotkey_capture_error);
return true;
}
m_hotkey_capture_action.reset();
m_hotkey_capture_error.clear();
sync_toolbar_hotkey_tooltips_();
save_occt_view_settings();
return true;
}
void GUI::options_()
{
if (!show_options_effective())
return;
if (!ImGui::Begin("Options", &m_show_options, ImGuiWindowFlags_None))
{
ImGui::End();
return;
}
ImGui::BeginChild("##options_scroll", ImVec2(0.f, 0.f), false, ImGuiWindowFlags_HorizontalScrollbar);
// clang-format off
switch (get_mode())
{
case Mode::Normal: options_normal_mode_(); break;
case Mode::Move: options_move_mode_(); break;
case Mode::Rotate: options_rotate_mode_(); break;
case Mode::Scale: options_scale_mode_(); break;
case Mode::Shape_shaft_align: options_shape_shaft_align_mode_(); break;
case Mode::Shape_chamfer: options_shape_chamfer_mode_(); break;
case Mode::Shape_fillet: options_shape_fillet_mode_(); break;
case Mode::Shape_polar_duplicate: options_shape_polar_duplicate_mode_(); break;
case Mode::Shape_cross_section: options_shape_cross_section_mode_(); break;
// Sketch related modes:
case Mode::Sketch_inspection_mode: options_sketch_inspection_mode_(); break;
case Mode::Sketch_from_planar_face: options_sketch_from_planer_face_mode_(); break;
case Mode::Sketch_operation_axis: options_sketch_operation_axis_mode_(); break;
case Mode::Sketch_face_extrude: options_sketch_face_extrude_mode_(); break;
case Mode::Sketch_dim_anno: options_sketch_dim_anno_mode_(); break;
case Mode::Sketch_add_node: options_sketch_add_node_mode_(); break;
case Mode::Sketch_add_edge: options_sketch_add_edge_mode_(); break;
case Mode::Sketch_add_multi_edges: options_sketch_add_multi_line_edge_mode_(); break;
case Mode::Sketch_add_seg_circle_arc: options_sketch_add_arc_circle_mode_(); break;
case Mode::Sketch_add_square: options_sketch_add_square_mode_(); break;
case Mode::Sketch_add_rectangle: options_sketch_add_rectangle_mode_(); break;
case Mode::Sketch_add_rectangle_center_pt: options_sketch_add_rectangle_center_mode_(); break;
case Mode::Sketch_add_circle: options_sketch_add_circle_mode_(); break;
case Mode::Sketch_add_circle_3_pts: options_sketch_add_circle_three_pts_mode_(); break;
case Mode::Sketch_add_slot: options_sketch_add_slot_mode_(); break;
default:
EZY_ASSERT_MSG(false, "Options panel: unhandled mode");
break;
}
// clang-format on
ImGui::EndChild();
ImGui::End();
}
void GUI::options_sketch_inspection_mode_()
{
EZY_ASSERT(get_mode() == Mode::Sketch_inspection_mode);
options_sketch_common_();
}
void GUI::options_normal_mode_()
{
EZY_ASSERT(get_mode() == Mode::Normal);
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
float label_col_w = ImGui::CalcTextSize("Selection Mode").x;
label_col_w += ImGui::GetStyle().CellPadding.x * 2.0f + 8.0f;
ImGui::TextUnformatted("Selection");
if (ImGui::BeginTable("options_normal_selection", 2, k_options_table_flags))
{
options_table_setup_columns_(label_col_w, k_options_control_col_w);
int current_item = static_cast<int>(m_view->get_shp_selection_mode());
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Selection Mode");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(120.0f);
if (ImGui::BeginCombo("##selection_mode", c_names_TopAbs_ShapeEnum[current_item].data(), ImGuiComboFlags_HeightSmall))
{
for (int i = 0; i < static_cast<int>(c_names_TopAbs_ShapeEnum.size()); i++)
if (ImGui::Selectable(c_names_TopAbs_ShapeEnum[i].data(), current_item == i))
m_view->set_shp_selection_mode(static_cast<TopAbs_ShapeEnum>(i));
ImGui::EndCombo();
}
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
GUI_DOC_HELP_("Hotkeys: 1-9 (Normal mode) set filter when the 3D view has focus, not while typing in UI. Click ? to "
"open the user guide.",
doc_urls::k_shape_selection_filter);
ImGui::EndTable();
}
ImGui::Separator();
ImGui::TextUnformatted("Material");
const std::vector<std::string>& material_names = occt_material_combo_labels_();
int current_mat = int(m_view->get_default_material().Name());
if (current_mat < 0 || current_mat >= static_cast<int>(material_names.size()))
current_mat = 0;
const float material_row_w = label_col_w + k_options_control_col_w;
ImGui::SetNextItemWidth(std::max(ImGui::GetContentRegionAvail().x, material_row_w));
if (ImGui::BeginCombo("##default_material_normal", material_names[static_cast<size_t>(current_mat)].data(),
ImGuiComboFlags_HeightSmall))
{
set_default_material_(material_names, current_mat, m_view);
ImGui::EndCombo();
}
options_orthographic_projection_();
}
void GUI::options_move_mode_()
{
EZY_ASSERT(get_mode() == Mode::Move);
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
ImGui::TextUnformatted("Constrain axis:");
Move_options& opts = m_view->shp_move().get_opts();
ImGui::Checkbox("X", &opts.constr_axis_x);
ImGui::SameLine();
ImGui::Checkbox("Y", &opts.constr_axis_y);
ImGui::SameLine();
ImGui::Checkbox("Z", &opts.constr_axis_z);
options_orthographic_projection_();
}
void GUI::options_scale_mode_()
{
EZY_ASSERT(get_mode() == Mode::Scale);
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
options_orthographic_projection_();
}
void GUI::options_shape_shaft_align_mode_()
{
EZY_ASSERT(get_mode() == Mode::Shape_shaft_align);
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
ImGui::TextWrapped(
"Pick a cylindrical face on the shape to move, then a cylindrical face on the fixed shape. "
"Drag insert depth. With Clock rotation on, LMB or Shift+Tab rotates about the shared axis; Enter finalizes. "
"First pick moves; pick the hole first to move the hole onto the shaft.");
Cyl_align_options& opts = m_view->shp_cyl_align().get_opts();
if (ImGui::Checkbox("Flip direction", &opts.flip_direction))
m_view->shp_cyl_align().apply_preview();
bool clock_rotation = opts.clock_rotation;
if (ImGui::Checkbox("Clock rotation", &clock_rotation))
m_view->shp_cyl_align().set_clock_rotation_enabled(clock_rotation);
ImGui::Separator();
options_orthographic_projection_();
}
void GUI::options_rotate_mode_()
{
EZY_ASSERT(get_mode() == Mode::Rotate);
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
int selected_axis = static_cast<int>(m_view->shp_rotate().get_rotation_axis());
if (ImGui::RadioButton("View to object axis", &selected_axis, static_cast<int>(Rotation_axis::View_to_object)))
m_view->shp_rotate().set_rotation_axis(Rotation_axis::View_to_object);
if (ImGui::RadioButton("Around X axis", &selected_axis, static_cast<int>(Rotation_axis::X_axis)))
m_view->shp_rotate().set_rotation_axis(Rotation_axis::X_axis);
if (ImGui::RadioButton("Around Y axis", &selected_axis, static_cast<int>(Rotation_axis::Y_axis)))
m_view->shp_rotate().set_rotation_axis(Rotation_axis::Y_axis);
if (ImGui::RadioButton("Around Z axis", &selected_axis, static_cast<int>(Rotation_axis::Z_axis)))
m_view->shp_rotate().set_rotation_axis(Rotation_axis::Z_axis);
options_orthographic_projection_();
}
void GUI::options_shape_chamfer_mode_()
{
EZY_ASSERT(get_mode() == Mode::Shape_chamfer);
float label_col_w = std::max(ImGui::CalcTextSize("Chamfer Mode").x, ImGui::CalcTextSize("Chamfer dist").x);
label_col_w += ImGui::GetStyle().CellPadding.x * 2.0f + 8.0f;
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
if (ImGui::BeginTable("options_chamfer_tool", 2, k_options_table_flags))
{
options_table_setup_columns_(label_col_w, k_options_control_col_w);
int current_mode = static_cast<int>(m_chamfer_mode);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Chamfer Mode");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(120.0f);
if (ImGui::Combo("##chamfer_mode", ¤t_mode, c_chamfer_mode_strs.data(), (int)c_chamfer_mode_strs.size()))
{
m_chamfer_mode = static_cast<Chamfer_mode>(current_mode);
m_view->on_chamfer_mode();
}
static char chamfer_buf[64];
const double scale = m_view->get_display_to_model_scale();
const double chamfer_dist = m_view->shp_chamfer().get_chamfer_dist() / scale;
ImGui::PushID("chamfer_dist_micron");
const ImGuiID chamfer_input_id = ImGui::GetID("##micron");
ImGuiContext* ctx = ImGui::GetCurrentContext();
if (ctx && ctx->ActiveId != chamfer_input_id)
format_double_trim_fraction_(chamfer_buf, sizeof chamfer_buf, chamfer_dist, 6);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Chamfer dist");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(100.0f);
constexpr ImGuiInputTextFlags k_dim_flags = ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific;
if (ImGui::InputText("##micron", chamfer_buf, sizeof chamfer_buf, k_dim_flags))
{
char* end = nullptr;
const double p = std::strtod(chamfer_buf, &end);
if (end != chamfer_buf)
{
while (*end == ' ' || *end == '\t')
++end;
if (*end == '\0')
m_view->shp_chamfer().set_chamfer_dist(p * scale);
}
}
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::TextUnformatted(m_view->project_unit_suffix());
ImGui::PopID();
ImGui::EndTable();
}
options_orthographic_projection_();
}
void GUI::options_shape_fillet_mode_()
{
EZY_ASSERT(get_mode() == Mode::Shape_fillet);
float label_col_w = std::max(ImGui::CalcTextSize("Fillet Mode").x, ImGui::CalcTextSize("Fillet radius").x);
label_col_w += ImGui::GetStyle().CellPadding.x * 2.0f + 8.0f;
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
if (ImGui::BeginTable("options_fillet_tool", 2, k_options_table_flags))
{
options_table_setup_columns_(label_col_w, k_options_control_col_w);
int current_mode = static_cast<int>(m_fillet_mode);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Fillet Mode");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(120.0f);
if (ImGui::Combo("##fillet_mode", ¤t_mode, c_fillet_mode_strs.data(), (int)c_fillet_mode_strs.size()))
{
m_fillet_mode = static_cast<Fillet_mode>(current_mode);
m_view->on_fillet_mode();
}
static char fillet_buf[64];
const double scale = m_view->get_display_to_model_scale();
const double fillet_radius = m_view->shp_fillet().get_fillet_radius() / scale;
ImGui::PushID("fillet_rad_micron");
const ImGuiID fillet_input_id = ImGui::GetID("##micron");
ImGuiContext* ctx = ImGui::GetCurrentContext();
if (ctx && ctx->ActiveId != fillet_input_id)
format_double_trim_fraction_(fillet_buf, sizeof fillet_buf, fillet_radius, 6);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Fillet radius");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(100.0f);
constexpr ImGuiInputTextFlags k_dim_flags = ImGuiInputTextFlags_CharsDecimal | ImGuiInputTextFlags_CharsScientific;
if (ImGui::InputText("##micron", fillet_buf, sizeof fillet_buf, k_dim_flags))
{
char* end = nullptr;
const double p = std::strtod(fillet_buf, &end);
if (end != fillet_buf)
{
while (*end == ' ' || *end == '\t')
++end;
if (*end == '\0')
m_view->shp_fillet().set_fillet_radius(p * scale);
}
}
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::TextUnformatted(m_view->project_unit_suffix());
ImGui::PopID();
ImGui::EndTable();
}
options_orthographic_projection_();
}
void GUI::options_shape_polar_duplicate_mode_()
{
EZY_ASSERT(get_mode() == Mode::Shape_polar_duplicate);
auto& polar_dup = m_view->shp_polar_dup();
float polar_angle = float(polar_dup.get_polar_angle());
int num_elms = int(polar_dup.get_num_elms());
bool rotate_dups = polar_dup.get_rotate_dups();
bool combine_dups = polar_dup.get_combine_dups();
float label_col_w = ImGui::CalcTextSize("Polar angle").x;
label_col_w = std::max(label_col_w, ImGui::CalcTextSize("Num Elms").x);
label_col_w = std::max(label_col_w, ImGui::CalcTextSize("Rotate dups").x);
label_col_w = std::max(label_col_w, ImGui::CalcTextSize("Combine dups").x);
label_col_w = std::max(label_col_w, ImGui::CalcTextSize("Material").x);
label_col_w += ImGui::GetStyle().CellPadding.x * 2.0f + 8.0f;
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
if (ImGui::BeginTable("options_polar_dup_tool", 2, k_options_table_flags))
{
options_table_setup_columns_(label_col_w, k_options_control_col_w);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Polar angle");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(120.0f);
if (ImGui::InputFloat("##polar_angle", &polar_angle, 0.0f, 0.0f, "%.2f"))
polar_dup.set_polar_angle(polar_angle);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Num Elms");
ImGui::TableSetColumnIndex(1);
ImGui::SetNextItemWidth(120.0f);
if (ImGui::InputInt("##num_elms", &num_elms))
polar_dup.set_num_elms(num_elms);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Rotate dups");
ImGui::TableSetColumnIndex(1);
if (ImGui::Checkbox("##rotate_dups", &rotate_dups))
polar_dup.set_rotate_dups(rotate_dups);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Combine dups");
ImGui::TableSetColumnIndex(1);
if (ImGui::Checkbox("##combine_dups", &combine_dups))
polar_dup.set_combine_dups(combine_dups);
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(1);
if (ImGui::Button("Dup"))
if (Status s = polar_dup.dup(); !s.is_ok())
show_message(s.message());
ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
options_right_aligned_label_("Material");
ImGui::TableSetColumnIndex(1);
const std::vector<std::string>& material_names = occt_material_combo_labels_();
int current_item = int(m_view->get_default_material().Name());
if (current_item < 0 || current_item >= static_cast<int>(material_names.size()))
current_item = 0;
ImGui::SetNextItemWidth(120.0f);
if (ImGui::BeginCombo("##default_material_polar_dup", material_names[static_cast<size_t>(current_item)].data(),
ImGuiComboFlags_HeightSmall))
{
set_default_material_(material_names, current_item, m_view);
ImGui::EndCombo();
}
ImGui::EndTable();
}
options_orthographic_projection_();
}
void GUI::options_shape_cross_section_mode_()
{
EZY_ASSERT(get_mode() == Mode::Shape_cross_section);
Shp_cross_section& section = m_view->shp_cross_section();
int plane = static_cast<int>(section.get_plane());
double offset = section.get_offset_display();
ImGui::TextUnformatted(current_mode_description_());
options_doc_help_button_();
ImGui::Separator();
const bool have_selection = !m_view->get_selected_shps().empty();
if (!have_selection)
{
// No dedicated bold font is loaded; offset a second draw for a bold look.
const char* msg = "Select one or more shapes.";
const ImVec2 pos = ImGui::GetCursorScreenPos();
const ImU32 col = ImGui::GetColorU32(ImGuiCol_Text);
ImGui::GetWindowDrawList()->AddText(ImVec2(pos.x + 1.0f, pos.y), col, msg);
ImGui::TextUnformatted(msg);
}
ImGui::TextUnformatted("Section plane");
ImGui::RadioButton("Local XY", &plane, static_cast<int>(Cross_section_plane::XY));
ImGui::SameLine();
ImGui::RadioButton("Local XZ", &plane, static_cast<int>(Cross_section_plane::XZ));
ImGui::SameLine();
ImGui::RadioButton("Local YZ", &plane, static_cast<int>(Cross_section_plane::YZ));
section.set_plane(static_cast<Cross_section_plane>(plane));
bool invert_normal = section.get_invert_normal();
if (ImGui::Checkbox("Invert normal", &invert_normal))
section.set_invert_normal(invert_normal);
bool hide_back_side = section.get_hide_back_side();
if (ImGui::Checkbox("Hide back side", &hide_back_side))
section.set_hide_back_side(hide_back_side);
bool show_section_outline = section.get_show_section_outline();
if (ImGui::Checkbox("Show section outline", &show_section_outline))
section.set_show_section_outline(show_section_outline);
double offset_min = -1.0;
double offset_max = 1.0;
const bool have_range = section.try_get_offset_range_display(offset_min, offset_max);
offset = section.get_offset_display();
if (have_range)
{
if (offset < offset_min)
offset = offset_min;
else if (offset > offset_max)
offset = offset_max;
}
else
{
offset_min = std::min(offset, -1.0);
offset_max = std::max(offset, 1.0);
if (!(offset_max > offset_min))
{
offset_min = offset - 1.0;
offset_max = offset + 1.0;
}
}
ImGui::SetNextItemWidth(180.0f);
ImGui::BeginDisabled(!have_range);
ImGui::SliderScalar("Offset", ImGuiDataType_Double, &offset, &offset_min, &offset_max, "%.6g");
ImGui::EndDisabled();
section.set_offset_display(offset);
ImGui::SameLine(0.0f, ImGui::GetStyle().ItemInnerSpacing.x);
ImGui::TextUnformatted(m_view->project_unit_suffix());
if (have_selection && !have_range)
ImGui::TextDisabled("Select solid shapes to enable the offset slider.");
// Plane annotation updates immediately; section wires run async (poll below).
if (section.preview_inputs_stale())
{
if (m_view->get_selected_shps().empty())
{
section.clear();
section.acknowledge_current_selection();
}
else if (const Status status = section.request_preview_selected(); !status.is_ok())
show_message(status.message());
}
if (std::optional<Status> finished = section.poll())
{
// Toast failures only; success edge-count spam on Offset drag is noise.
if (!finished->is_ok())
show_message(finished->message());
}
ImGui::BeginDisabled(!have_selection);
if (ImGui::Button("Clip"))