diff --git a/lib/Slic3r/GUI.pm b/lib/Slic3r/GUI.pm index a8799c458f..78e82a6ef4 100644 --- a/lib/Slic3r/GUI.pm +++ b/lib/Slic3r/GUI.pm @@ -79,6 +79,7 @@ sub OnInit { # Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r" # Mac: "~/Library/Application Support/Slic3r" Slic3r::set_data_dir($datadir || Wx::StandardPaths::Get->GetUserDataDir); + Slic3r::GUI::set_wxapp($self); $self->{notifier} = Slic3r::GUI::Notifier->new; $self->{app_config} = Slic3r::GUI::AppConfig->new; diff --git a/lib/Slic3r/GUI/MainFrame.pm b/lib/Slic3r/GUI/MainFrame.pm index 2f93899a42..370bac2ed0 100644 --- a/lib/Slic3r/GUI/MainFrame.pm +++ b/lib/Slic3r/GUI/MainFrame.pm @@ -22,6 +22,7 @@ sub new { my ($class, %params) = @_; my $self = $class->SUPER::new(undef, -1, $Slic3r::FORK_NAME . ' - ' . $Slic3r::VERSION, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE); + Slic3r::GUI::set_main_frame($self); if ($^O eq 'MSWin32') { # Load the icon either from the exe, or from the ico file. my $iconfile = Slic3r::decode_path($FindBin::Bin) . '\slic3r.exe'; @@ -92,6 +93,8 @@ sub _init_tabpanel { my ($self) = @_; $self->{tabpanel} = my $panel = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL); + Slic3r::GUI::set_tab_panel($panel); + EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{tabpanel}, sub { my $panel = $self->{tabpanel}->GetCurrentPage; $panel->OnActivate if $panel->can('OnActivate'); @@ -145,6 +148,9 @@ sub _init_tabpanel { $tab->load_current_preset; $panel->AddPage($tab, $tab->title); } + +#TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view. +# Slic3r::GUI::create_preset_tab("print"); if ($self->{plater}) { $self->{plater}->on_select_preset(sub { @@ -330,6 +336,8 @@ sub _init_menubar { $menubar->Append($windowMenu, "&Window"); $menubar->Append($self->{viewMenu}, "&View") if $self->{viewMenu}; $menubar->Append($helpMenu, "&Help"); + # Add an optional debug menu. In production code, the add_debug_menu() call should do nothing. + Slic3r::GUI::add_debug_menu($menubar); $self->SetMenuBar($menubar); } } diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 63cc7749d4..8db0508f13 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -13,6 +13,14 @@ #pragma comment(lib, "user32.lib") #endif +#include +#include +#include +#include +#include +#include +#include + namespace Slic3r { namespace GUI { #if __APPLE__ @@ -134,4 +142,45 @@ void break_to_debugger() #endif /* _WIN32 */ } +// Passing the wxWidgets GUI classes instantiated by the Perl part to C++. +wxApp *g_wxApp = nullptr; +wxFrame *g_wxMainFrame = nullptr; +wxNotebook *g_wxTabPanel = nullptr; + +void set_wxapp(wxApp *app) +{ + g_wxApp = app; +} + +void set_main_frame(wxFrame *main_frame) +{ + g_wxMainFrame = main_frame; +} + +void set_tab_panel(wxNotebook *tab_panel) +{ + g_wxTabPanel = tab_panel; +} + +void add_debug_menu(wxMenuBar *menu) +{ +#if 0 + auto debug_menu = new wxMenu(); + debug_menu->Append(wxWindow::NewControlId(1), "Some debug"); + menu->Append(debug_menu, _T("&Debug")); +#endif +} + +void create_preset_tab(const char *name) +{ + auto *panel = new wxPanel(g_wxTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL); + // Vertical sizer to hold the choice menu and the rest of the page. + auto *sizer = new wxBoxSizer(wxVERTICAL); + sizer->SetSizeHints(panel); + panel->SetSizer(sizer); + auto *button = new wxButton(panel, wxID_ANY, "Hello World", wxDefaultPosition, wxDefaultSize, 0); + sizer->Add(button, 0, 0, 0); + g_wxTabPanel->AddPage(panel, name); +} + } } diff --git a/xs/src/slic3r/GUI/GUI.hpp b/xs/src/slic3r/GUI/GUI.hpp index 955a1cd8db..3634e0bc8a 100644 --- a/xs/src/slic3r/GUI/GUI.hpp +++ b/xs/src/slic3r/GUI/GUI.hpp @@ -4,6 +4,11 @@ #include #include +class wxApp; +class wxFrame; +class wxMenuBar; +class wxNotebook; + namespace Slic3r { namespace GUI { void disable_screensaver(); @@ -12,6 +17,16 @@ std::vector scan_serial_ports(); bool debugged(); void break_to_debugger(); +// Passing the wxWidgets GUI classes instantiated by the Perl part to C++. +void set_wxapp(wxApp *app); +void set_main_frame(wxFrame *main_frame); +void set_tab_panel(wxNotebook *tab_panel); + +void add_debug_menu(wxMenuBar *menu); +// Create a new preset tab (print, filament or printer), +// add it at the end of the tab panel. +void create_preset_tab(const char *name); + } } #endif diff --git a/xs/xsp/GUI.xsp b/xs/xsp/GUI.xsp index ce3c178a14..d6b55dbf13 100644 --- a/xs/xsp/GUI.xsp +++ b/xs/xsp/GUI.xsp @@ -22,3 +22,18 @@ bool debugged() void break_to_debugger() %code{% Slic3r::GUI::break_to_debugger(); %}; + +void set_wxapp(SV *ui) + %code%{ Slic3r::GUI::set_wxapp((wxApp*)wxPli_sv_2_object(aTHX_ ui, "Wx::App")); %}; + +void set_main_frame(SV *ui) + %code%{ Slic3r::GUI::set_main_frame((wxFrame*)wxPli_sv_2_object(aTHX_ ui, "Wx::Frame")); %}; + +void set_tab_panel(SV *ui) + %code%{ Slic3r::GUI::set_tab_panel((wxNotebook*)wxPli_sv_2_object(aTHX_ ui, "Wx::Notebook")); %}; + +void add_debug_menu(SV *ui) + %code%{ Slic3r::GUI::add_debug_menu((wxMenuBar*)wxPli_sv_2_object(aTHX_ ui, "Wx::MenuBar")); %}; + +void create_preset_tab(const char *name) + %code%{ Slic3r::GUI::create_preset_tab(name); %};