mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 16:57:53 -06:00
Added Perl to C++ interfaces for creating the preset editor pages
from C++ and to add debugging menus from C++. These lightweigth interfaces should help new team members to hack the UI without a Perl knowledge.
This commit is contained in:
parent
16bd3fc624
commit
8af329e660
5 changed files with 88 additions and 0 deletions
|
@ -79,6 +79,7 @@ sub OnInit {
|
||||||
# Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
|
# Windows: "C:\Users\username\AppData\Roaming\Slic3r" or "C:\Documents and Settings\username\Application Data\Slic3r"
|
||||||
# Mac: "~/Library/Application Support/Slic3r"
|
# Mac: "~/Library/Application Support/Slic3r"
|
||||||
Slic3r::set_data_dir($datadir || Wx::StandardPaths::Get->GetUserDataDir);
|
Slic3r::set_data_dir($datadir || Wx::StandardPaths::Get->GetUserDataDir);
|
||||||
|
Slic3r::GUI::set_wxapp($self);
|
||||||
|
|
||||||
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
$self->{notifier} = Slic3r::GUI::Notifier->new;
|
||||||
$self->{app_config} = Slic3r::GUI::AppConfig->new;
|
$self->{app_config} = Slic3r::GUI::AppConfig->new;
|
||||||
|
|
|
@ -22,6 +22,7 @@ sub new {
|
||||||
my ($class, %params) = @_;
|
my ($class, %params) = @_;
|
||||||
|
|
||||||
my $self = $class->SUPER::new(undef, -1, $Slic3r::FORK_NAME . ' - ' . $Slic3r::VERSION, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE);
|
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') {
|
if ($^O eq 'MSWin32') {
|
||||||
# Load the icon either from the exe, or from the ico file.
|
# Load the icon either from the exe, or from the ico file.
|
||||||
my $iconfile = Slic3r::decode_path($FindBin::Bin) . '\slic3r.exe';
|
my $iconfile = Slic3r::decode_path($FindBin::Bin) . '\slic3r.exe';
|
||||||
|
@ -92,6 +93,8 @@ sub _init_tabpanel {
|
||||||
my ($self) = @_;
|
my ($self) = @_;
|
||||||
|
|
||||||
$self->{tabpanel} = my $panel = Wx::Notebook->new($self, -1, wxDefaultPosition, wxDefaultSize, wxNB_TOP | wxTAB_TRAVERSAL);
|
$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 {
|
EVT_NOTEBOOK_PAGE_CHANGED($self, $self->{tabpanel}, sub {
|
||||||
my $panel = $self->{tabpanel}->GetCurrentPage;
|
my $panel = $self->{tabpanel}->GetCurrentPage;
|
||||||
$panel->OnActivate if $panel->can('OnActivate');
|
$panel->OnActivate if $panel->can('OnActivate');
|
||||||
|
@ -145,6 +148,9 @@ sub _init_tabpanel {
|
||||||
$tab->load_current_preset;
|
$tab->load_current_preset;
|
||||||
$panel->AddPage($tab, $tab->title);
|
$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}) {
|
if ($self->{plater}) {
|
||||||
$self->{plater}->on_select_preset(sub {
|
$self->{plater}->on_select_preset(sub {
|
||||||
|
@ -330,6 +336,8 @@ sub _init_menubar {
|
||||||
$menubar->Append($windowMenu, "&Window");
|
$menubar->Append($windowMenu, "&Window");
|
||||||
$menubar->Append($self->{viewMenu}, "&View") if $self->{viewMenu};
|
$menubar->Append($self->{viewMenu}, "&View") if $self->{viewMenu};
|
||||||
$menubar->Append($helpMenu, "&Help");
|
$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);
|
$self->SetMenuBar($menubar);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,14 @@
|
||||||
#pragma comment(lib, "user32.lib")
|
#pragma comment(lib, "user32.lib")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <wx/app.h>
|
||||||
|
#include <wx/button.h>
|
||||||
|
#include <wx/frame.h>
|
||||||
|
#include <wx/menu.h>
|
||||||
|
#include <wx/notebook.h>
|
||||||
|
#include <wx/panel.h>
|
||||||
|
#include <wx/sizer.h>
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
|
@ -134,4 +142,45 @@ void break_to_debugger()
|
||||||
#endif /* _WIN32 */
|
#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);
|
||||||
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
|
|
@ -4,6 +4,11 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
class wxApp;
|
||||||
|
class wxFrame;
|
||||||
|
class wxMenuBar;
|
||||||
|
class wxNotebook;
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
void disable_screensaver();
|
void disable_screensaver();
|
||||||
|
@ -12,6 +17,16 @@ std::vector<std::string> scan_serial_ports();
|
||||||
bool debugged();
|
bool debugged();
|
||||||
void break_to_debugger();
|
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
|
#endif
|
||||||
|
|
|
@ -22,3 +22,18 @@ bool debugged()
|
||||||
|
|
||||||
void break_to_debugger()
|
void break_to_debugger()
|
||||||
%code{% Slic3r::GUI::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); %};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue