mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-05-05 03:54:02 +08:00
First steps
This commit is contained in:
parent
5cf9cd5395
commit
c5e21c1fbf
@ -152,7 +152,7 @@ sub _init_tabpanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#TODO this is an example of a Slic3r XS interface call to add a new preset editor page to the main view.
|
#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");
|
Slic3r::GUI::create_preset_tab("print");
|
||||||
|
|
||||||
if ($self->{plater}) {
|
if ($self->{plater}) {
|
||||||
$self->{plater}->on_select_preset(sub {
|
$self->{plater}->on_select_preset(sub {
|
||||||
|
@ -21,6 +21,13 @@
|
|||||||
#include <wx/panel.h>
|
#include <wx/panel.h>
|
||||||
#include <wx/sizer.h>
|
#include <wx/sizer.h>
|
||||||
|
|
||||||
|
#include "Tab.h"
|
||||||
|
|
||||||
|
//#include <wx/bmpcbox.h>
|
||||||
|
//#include <wx/bmpbuttn.h>
|
||||||
|
//#include <wx/treectrl.h>
|
||||||
|
//#include <wx/imaglist.h>
|
||||||
|
|
||||||
namespace Slic3r { namespace GUI {
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
#if __APPLE__
|
#if __APPLE__
|
||||||
@ -171,16 +178,11 @@ void add_debug_menu(wxMenuBar *menu)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
void create_preset_tab(const char *name)
|
void create_preset_tab(const char *name)
|
||||||
{
|
{
|
||||||
auto *panel = new wxPanel(g_wxTabPanel, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
|
CTabPrint* panel = new CTabPrint(g_wxTabPanel, name/*, someParams*/);
|
||||||
// Vertical sizer to hold the choice menu and the rest of the page.
|
g_wxTabPanel->AddPage(panel, name);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} }
|
} }
|
||||||
|
124
xs/src/slic3r/GUI/OptionsGroup.cpp
Normal file
124
xs/src/slic3r/GUI/OptionsGroup.cpp
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
#include "OptionsGroup.hpp"
|
||||||
|
#include "OptionsGroup/Field.hpp"
|
||||||
|
#include "Config.hpp"
|
||||||
|
|
||||||
|
// Translate the ifdef
|
||||||
|
#ifdef __WXOSX__
|
||||||
|
#define wxOSX true
|
||||||
|
#else
|
||||||
|
#define wxOSX false
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define BORDER(a, b) ((wxOSX ? a : b))
|
||||||
|
|
||||||
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
|
||||||
|
void OptionsGroup::BUILD() {
|
||||||
|
if (staticbox) {
|
||||||
|
wxStaticBox* box = new wxStaticBox(_parent, -1, title);
|
||||||
|
_sizer = new wxStaticBoxSizer(box, wxVERTICAL);
|
||||||
|
} else {
|
||||||
|
_sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
}
|
||||||
|
size_t num_columns = 1;
|
||||||
|
if (label_width != 0) ++num_columns;
|
||||||
|
if (extra_column != 0) ++num_columns;
|
||||||
|
|
||||||
|
_grid_sizer = new wxFlexGridSizer(0, num_columns, 0, 0);
|
||||||
|
_grid_sizer->SetFlexibleDirection(wxHORIZONTAL);
|
||||||
|
_grid_sizer->AddGrowableCol(label_width > 0);
|
||||||
|
_sizer->Add(_grid_sizer, 0, wxEXPAND | wxALL, BORDER(0,5));
|
||||||
|
}
|
||||||
|
|
||||||
|
void OptionsGroup::append_line(const Line& line) {
|
||||||
|
if (line.has_sizer() || (line.has_widget() && line.full_width)) {
|
||||||
|
wxASSERT(line.sizer() != nullptr);
|
||||||
|
_sizer->Add( (line.has_sizer() ? line.sizer() : line.widget().sizer()), 0, wxEXPAND | wxALL, BORDER(0, 15));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
wxSizer* grid_sizer = _grid_sizer;
|
||||||
|
// If we have an extra column, build it.
|
||||||
|
// If there's a label, build it.
|
||||||
|
if (label_width != 0) {
|
||||||
|
wxStaticText* label = new wxStaticText(_parent, -1, (line.label) + ":", wxDefaultPosition);
|
||||||
|
label->Wrap(label_width);
|
||||||
|
if (wxIsEmpty(line.tooltip())) { label->SetToolTip(line.tooltip()); }
|
||||||
|
grid_sizer->Add(label, 0, wxALIGN_CENTER_VERTICAL, 0);
|
||||||
|
}
|
||||||
|
// If we have a widget, add it to the sizer
|
||||||
|
if (line.has_widget()) {
|
||||||
|
grid_sizer->Add(line.widget().sizer(), 0, wxEXPAND | wxALL, BORDER(0,15));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// If we have a single option with no sidetext just add it directly to the grid sizer
|
||||||
|
if (line.options().size() == 1) {
|
||||||
|
const ConfigOptionDef& opt = line.options()[0];
|
||||||
|
if (line.extra_widgets().size() && !wxIsEmpty(opt.sidetext) && line.extra_widgets().size() == 0) {
|
||||||
|
Field* field = _build_field(opt);
|
||||||
|
if (field != nullptr) {
|
||||||
|
if (field->has_sizer()) {
|
||||||
|
grid_sizer->Add(field->sizer(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0);
|
||||||
|
} else if (field->has_window()) {
|
||||||
|
grid_sizer->Add(field->window(), 0, (opt.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Otherwise, there's more than one option or a single option with sidetext -- make
|
||||||
|
// a horizontal sizer to arrange things.
|
||||||
|
wxBoxSizer* sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
grid_sizer->Add(sizer, 0, 0, 0);
|
||||||
|
for (auto& option : line.options()) {
|
||||||
|
// add label if any
|
||||||
|
if (!wxIsEmpty(option.label)) {
|
||||||
|
wxStaticText* field_label = new wxStaticText(_parent, -1, __(option.label) + ":", wxDefaultPosition, wxDefaultSize);
|
||||||
|
sizer->Add(field_label, 0, wxALIGN_CENTER_VERTICAL,0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add field
|
||||||
|
Field* field = _build_field(option);
|
||||||
|
if (field != nullptr) {
|
||||||
|
if (field->has_sizer()) {
|
||||||
|
sizer->Add(field->sizer(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0);
|
||||||
|
} else if (field->has_window()) {
|
||||||
|
sizer->Add(field->window(), 0, (option.full_width ? wxEXPAND : 0) | wxALIGN_CENTER_VERTICAL, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!wxIsEmpty(option.sidetext)) {
|
||||||
|
}
|
||||||
|
// !!! side_widget !!! find out the purpose
|
||||||
|
// if (option.side_widget.valid()) {
|
||||||
|
// sizer->Add(option.side_widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 1);
|
||||||
|
// }
|
||||||
|
if (&option != &line.options().back()) {
|
||||||
|
sizer->AddSpacer(4);
|
||||||
|
}
|
||||||
|
|
||||||
|
// add side text if any
|
||||||
|
// add side widget if any
|
||||||
|
}
|
||||||
|
// Append extra sizers
|
||||||
|
for (auto& widget : line.extra_widgets()) {
|
||||||
|
_sizer->Add(widget.sizer(), 0, wxLEFT | wxALIGN_CENTER_VERTICAL, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Field* OptionsGroup::_build_field(const ConfigOptionDef& opt) {
|
||||||
|
Field* built_field = nullptr;
|
||||||
|
switch (opt.type) {
|
||||||
|
case coString:
|
||||||
|
{
|
||||||
|
printf("Making new textctrl\n");
|
||||||
|
TextCtrl* temp = new TextCtrl(_parent, opt);
|
||||||
|
printf("recasting textctrl\n");
|
||||||
|
built_field = dynamic_cast<Field*>(temp);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return built_field;
|
||||||
|
}
|
||||||
|
} }
|
109
xs/src/slic3r/GUI/OptionsGroup.hpp
Normal file
109
xs/src/slic3r/GUI/OptionsGroup.hpp
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
#ifndef OPTIONSGROUP_HPP
|
||||||
|
#define OPTIONSGROUP_HPP
|
||||||
|
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
#include <map>
|
||||||
|
#include "wxinit.h"
|
||||||
|
#include "Widget.hpp"
|
||||||
|
#include "OptionsGroup/Field.hpp"
|
||||||
|
#include "Config.hpp"
|
||||||
|
namespace Slic3r {
|
||||||
|
class ConfigOptionDef;
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
|
||||||
|
/// Enumeration class to provide flags for these GUI hints.
|
||||||
|
/// they resolve to hex numbers to permit boolean masking.
|
||||||
|
enum class GUI_Type {
|
||||||
|
i_enum_open = 0x1,
|
||||||
|
f_enum_open = 0x2,
|
||||||
|
select_open = 0x4
|
||||||
|
};
|
||||||
|
|
||||||
|
// Map these flags
|
||||||
|
/*constexpr */std::map<std::string, GUI_Type>gui_type_map =
|
||||||
|
{ { "i_enum_open", GUI_Type::i_enum_open },
|
||||||
|
{ "f_enum_open", GUI_Type::f_enum_open },
|
||||||
|
{ "select_open", GUI_Type::select_open }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Abstraction cribbed from Slic3r::ConfigOptionDefGroup::Line
|
||||||
|
// Unsure if templated class or function overloading is the appropriate thing here.
|
||||||
|
class Line {
|
||||||
|
private:
|
||||||
|
std::vector<ConfigOptionDef> _options;
|
||||||
|
std::vector<Widget> _extra_widgets;
|
||||||
|
Widget _widget;
|
||||||
|
wxSizer* _sizer;
|
||||||
|
wxString _tooltip;
|
||||||
|
public:
|
||||||
|
wxString label;
|
||||||
|
bool full_width;
|
||||||
|
wxSizer* sizer() const { return _sizer; }
|
||||||
|
Line() : label(wxT("")), _tooltip(wxT("")), _sizer(nullptr), full_width(false), _widget(Widget()) { }
|
||||||
|
Line(const ConfigOptionDef& z) : label(z.label), _tooltip(z.tooltip), _sizer(nullptr), full_width(false), _widget(Widget()) { append_option(z); }
|
||||||
|
Line(const wxString& label, const wxString& tooltip) : label(label), _tooltip(tooltip), _sizer(nullptr), full_width(false), _widget(Widget()) { }
|
||||||
|
inline void append_option(const ConfigOptionDef& z) { _options.push_back(z); };
|
||||||
|
void append_widget(const Widget& wid) { _extra_widgets.push_back(wid); }
|
||||||
|
std::vector<ConfigOptionDef> options() const { return _options; }
|
||||||
|
const std::vector<Widget> extra_widgets() const { return _extra_widgets; }
|
||||||
|
bool has_sizer() const { return _sizer != nullptr; }
|
||||||
|
bool has_widget() const { return _widget.valid(); }
|
||||||
|
Widget widget() const { return _widget; }
|
||||||
|
const wxString tooltip() const { return _tooltip; }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// OptionsGroup building class, cribbed from Slic3r::OptionGroup
|
||||||
|
// Usage: Instantitate, add individual items to it, and add its sizer to another wxWidgets sizer.
|
||||||
|
class OptionsGroup {
|
||||||
|
private:
|
||||||
|
bool _disabled;
|
||||||
|
wxFlexGridSizer* _grid_sizer;
|
||||||
|
wxSizer* _sizer;
|
||||||
|
void BUILD();
|
||||||
|
const bool staticbox;
|
||||||
|
wxFrame* _parent;
|
||||||
|
std::map<size_t, Field*> fields;
|
||||||
|
Field* _build_field(const ConfigOptionDef& opt);
|
||||||
|
public:
|
||||||
|
const wxString title;
|
||||||
|
|
||||||
|
size_t label_width;
|
||||||
|
wxFont label_font;
|
||||||
|
wxFont sidetext_font;
|
||||||
|
bool extra_column;
|
||||||
|
|
||||||
|
OptionsGroup() : _parent(nullptr), title(wxT("")), staticbox(1), fields(std::map<size_t, Field*>()){};
|
||||||
|
OptionsGroup(wxFrame* parent, std::string title) :
|
||||||
|
_parent(parent),
|
||||||
|
title(title.c_str()),
|
||||||
|
staticbox(1),
|
||||||
|
extra_column(false),
|
||||||
|
label_width(0),
|
||||||
|
fields(std::map<size_t, Field*>())
|
||||||
|
{ BUILD(); }
|
||||||
|
|
||||||
|
OptionsGroup(wxFrame* parent, std::string, size_t label_width) :
|
||||||
|
_parent(parent),
|
||||||
|
title(title.c_str()),
|
||||||
|
staticbox(1),
|
||||||
|
extra_column(false),
|
||||||
|
fields(std::map<size_t, Field*>()),
|
||||||
|
label_width(label_width) { BUILD(); }
|
||||||
|
|
||||||
|
void append_line(const Line& line);
|
||||||
|
Line create_single_option_line(const ConfigOptionDef& opt) { Line a = Line(opt); append_line(a); return a; }
|
||||||
|
void append_single_option_line(const Line& line);
|
||||||
|
|
||||||
|
wxSizer* sizer() { return _sizer; }
|
||||||
|
void disable() { for (auto& f: fields) f.second->disable(); }
|
||||||
|
void enable() { for (auto& f: fields) f.second->enable(); }
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
} }
|
||||||
|
|
||||||
|
#endif
|
36
xs/src/slic3r/GUI/OptionsGroup/Field.cpp
Normal file
36
xs/src/slic3r/GUI/OptionsGroup/Field.cpp
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
#include "Field.hpp"
|
||||||
|
|
||||||
|
namespace Slic3r { namespace GUI {
|
||||||
|
|
||||||
|
void TextCtrl::BUILD() {
|
||||||
|
wxString default_value = "";
|
||||||
|
// Empty wxString object fails cast, default to "" if
|
||||||
|
// the recast fails from boost::any.
|
||||||
|
try {
|
||||||
|
if (opt.default_value != nullptr) {
|
||||||
|
default_value = boost::any_cast<wxString>(*(opt.default_value));
|
||||||
|
}
|
||||||
|
} catch (const boost::bad_any_cast& e) {
|
||||||
|
//TODO log error
|
||||||
|
}
|
||||||
|
auto size = wxSize(opt.height,opt.width);
|
||||||
|
if (opt.height == 0 || opt.width == 0) { size = wxDefaultSize; }
|
||||||
|
|
||||||
|
wxTextCtrl* temp = new wxTextCtrl(_parent, wxID_ANY, default_value, wxDefaultPosition, size, (opt.multiline ? wxTE_MULTILINE : 0));
|
||||||
|
|
||||||
|
_on_change = [=](wxCommandEvent& a) { this->__on_change(a);};
|
||||||
|
|
||||||
|
// This replaces the generic EVT_TEXT call to set the table up, it works with function objects.
|
||||||
|
temp->Bind(wxEVT_TEXT, _on_change, temp->GetId());
|
||||||
|
if (opt.tooltip.length() > 0) { temp->SetToolTip(opt.tooltip); }
|
||||||
|
|
||||||
|
// recast as a wxWindow to fit the calling convention
|
||||||
|
_window = dynamic_cast<wxWindow*>(temp);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fixed (temporary) function. We can (and probably should) use lambdas instead.
|
||||||
|
void TextCtrl::__on_change(wxCommandEvent& a) {
|
||||||
|
printf("Calling _on_change for %d.\n", opt.label);
|
||||||
|
}
|
||||||
|
|
||||||
|
} }
|
95
xs/src/slic3r/GUI/OptionsGroup/Field.hpp
Normal file
95
xs/src/slic3r/GUI/OptionsGroup/Field.hpp
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
#ifndef FIELD_HPP
|
||||||
|
#define FIELD_HPP
|
||||||
|
|
||||||
|
#include "../wxinit.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include <boost/any.hpp>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
// ConfigOptionDef definition
|
||||||
|
#include "Config.hpp"
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
class ConfigOptionDef;
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/// Interface class for fields
|
||||||
|
///
|
||||||
|
class Field {
|
||||||
|
protected:
|
||||||
|
wxSizer* _sizer;
|
||||||
|
wxWindow* _window;
|
||||||
|
wxWindow* _parent;
|
||||||
|
|
||||||
|
/// Instantiate the underlying wxWidgets control/window.
|
||||||
|
/// This function is expected to be called by the constructor.
|
||||||
|
virtual void BUILD() = 0;
|
||||||
|
|
||||||
|
/// Reference to underlying ConfigOptionDef this Field is
|
||||||
|
/// implementing.
|
||||||
|
/// TODO: This may not be necessary.
|
||||||
|
const ConfigOptionDef& opt;
|
||||||
|
std::string type;
|
||||||
|
|
||||||
|
public:
|
||||||
|
std::function<void(wxCommandEvent&)> _on_change;
|
||||||
|
std::function<void(wxCommandEvent&)> _on_kill_focus;
|
||||||
|
// used if we need to know which ConfigOptionDef this corresponds.
|
||||||
|
Field() : opt(ConfigOptionDef()), _on_change(nullptr), _on_kill_focus(nullptr){}
|
||||||
|
Field(const ConfigOptionDef& opt) : opt(opt), type(opt.gui_type) { }
|
||||||
|
Field(wxFrame* parent, const ConfigOptionDef& opt) : opt(opt), _parent(parent) { }
|
||||||
|
wxSizer* sizer() { return _sizer; }
|
||||||
|
wxWindow* window() { return _window; }
|
||||||
|
|
||||||
|
//
|
||||||
|
bool has_sizer() { return _sizer != nullptr; }
|
||||||
|
bool has_window() { return _window != nullptr; }
|
||||||
|
|
||||||
|
/// Return the wxWidgets ID for this object.
|
||||||
|
///
|
||||||
|
wxWindowID get_id() { if (this->has_window()) return _window->GetId(); }
|
||||||
|
|
||||||
|
/// Sets a value for this control.
|
||||||
|
/// subclasses should overload with a specific version
|
||||||
|
virtual void set_value(boost::any value) = 0;
|
||||||
|
|
||||||
|
/// Gets a boost::any representing this control.
|
||||||
|
/// subclasses should overload with a specific version
|
||||||
|
virtual boost::any get_value() = 0;
|
||||||
|
|
||||||
|
/// subclasses should overload with a specific version
|
||||||
|
virtual void enable() = 0;
|
||||||
|
virtual void disable() = 0;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
class TextCtrl : public Field {
|
||||||
|
protected:
|
||||||
|
void BUILD();
|
||||||
|
public:
|
||||||
|
TextCtrl();
|
||||||
|
TextCtrl(wxFrame* parent, const ConfigOptionDef& opt) : Field(parent, opt) { BUILD(); };
|
||||||
|
|
||||||
|
void set_value(std::string value) {
|
||||||
|
dynamic_cast<wxTextCtrl*>(_window)->SetValue(wxString(value));
|
||||||
|
}
|
||||||
|
void set_value(boost::any value) {
|
||||||
|
try {
|
||||||
|
dynamic_cast<wxTextCtrl*>(_window)->SetValue(boost::any_cast<wxString>(value));
|
||||||
|
} catch (boost::bad_any_cast) {
|
||||||
|
// TODO Log error and do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boost::any get_value() { return boost::any(dynamic_cast<wxTextCtrl*>(_window)->GetValue()); }
|
||||||
|
|
||||||
|
void enable() { dynamic_cast<wxTextCtrl*>(_window)->Enable(); dynamic_cast<wxTextCtrl*>(_window)->SetEditable(1); }
|
||||||
|
void disable() { dynamic_cast<wxTextCtrl*>(_window)->Disable(); dynamic_cast<wxTextCtrl*>(_window)->SetEditable(0); }
|
||||||
|
void __on_change(wxCommandEvent&);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
} }
|
||||||
|
#endif
|
173
xs/src/slic3r/GUI/Tab.cpp
Normal file
173
xs/src/slic3r/GUI/Tab.cpp
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
#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>
|
||||||
|
|
||||||
|
#include <wx/bmpcbox.h>
|
||||||
|
#include <wx/bmpbuttn.h>
|
||||||
|
#include <wx/treectrl.h>
|
||||||
|
#include <wx/imaglist.h>
|
||||||
|
|
||||||
|
#include "Tab.h"
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
// Declare some IDs.
|
||||||
|
/*const int BUTTON1 = 100;
|
||||||
|
|
||||||
|
// Attach the event handlers. Put this after Slis3rFrame declaration.
|
||||||
|
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
|
||||||
|
EVT_BUTTON(BUTTON1, MyFrame::OnButton1)
|
||||||
|
END_EVENT_TABLE()
|
||||||
|
*/
|
||||||
|
|
||||||
|
// sub new
|
||||||
|
void CTab::create_preset_tab()
|
||||||
|
{
|
||||||
|
// Vertical sizer to hold the choice menu and the rest of the page.
|
||||||
|
CTab *panel = this;
|
||||||
|
auto *sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
sizer->SetSizeHints(panel);
|
||||||
|
(panel)->SetSizer(sizer);
|
||||||
|
panel->SetSizer(sizer);
|
||||||
|
|
||||||
|
// preset chooser
|
||||||
|
// choice menu for Experiments
|
||||||
|
wxString choices[] =
|
||||||
|
{
|
||||||
|
_T("Washington"),
|
||||||
|
_T("Adams"),
|
||||||
|
_T("Jefferson"),
|
||||||
|
_T("Madison"),
|
||||||
|
_T("Lincoln"),
|
||||||
|
_T("One"),
|
||||||
|
_T("Two"),
|
||||||
|
_T("Three"),
|
||||||
|
_T("Four")
|
||||||
|
};
|
||||||
|
int nCntEl = 9;
|
||||||
|
|
||||||
|
presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), nCntEl, choices, wxCB_READONLY);
|
||||||
|
|
||||||
|
//buttons
|
||||||
|
wxBitmap bmpMenu;
|
||||||
|
bmpMenu = wxBitmap(wxT("var\\disk.png"), wxBITMAP_TYPE_PNG);
|
||||||
|
auto *btn_save_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||||
|
bmpMenu = wxBitmap(wxT("var\\delete.png"), wxBITMAP_TYPE_PNG);
|
||||||
|
auto *btn_delete_preset = new wxBitmapButton(panel, wxID_ANY, bmpMenu, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||||
|
|
||||||
|
// $self->{show_incompatible_presets} = 0; // !!!
|
||||||
|
|
||||||
|
bmp_show_incompatible_presets = new wxBitmap(wxT("var\\flag-red-icon.png"), wxBITMAP_TYPE_PNG);
|
||||||
|
bmp_hide_incompatible_presets = new wxBitmap(wxT("var\\flag-green-icon.png"), wxBITMAP_TYPE_PNG);
|
||||||
|
btn_hide_incompatible_presets = new wxBitmapButton(panel, wxID_ANY, *bmp_hide_incompatible_presets, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE);
|
||||||
|
|
||||||
|
wxString stTitle = _T("Save current ") + wxString(_title);//. lc($self->title)
|
||||||
|
btn_save_preset->SetToolTip(stTitle);
|
||||||
|
btn_delete_preset->SetToolTip(_T("Delete this preset"));
|
||||||
|
btn_delete_preset->Disable();
|
||||||
|
|
||||||
|
hsizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
sizer->Add(hsizer, 0, wxBOTTOM, 3);
|
||||||
|
hsizer->Add(presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3);
|
||||||
|
hsizer->AddSpacer(4);
|
||||||
|
hsizer->Add(btn_save_preset, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
hsizer->AddSpacer(4);
|
||||||
|
hsizer->Add(btn_delete_preset, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
hsizer->AddSpacer(16);
|
||||||
|
hsizer->Add(btn_hide_incompatible_presets, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
|
||||||
|
//Horizontal sizer to hold the tree and the selected page.
|
||||||
|
hsizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
sizer->Add(hsizer, 1, wxEXPAND, 0);
|
||||||
|
|
||||||
|
//left vertical sizer
|
||||||
|
left_sizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
hsizer->Add(left_sizer, 0, wxEXPAND | wxLEFT | wxTOP | wxBOTTOM, 3);
|
||||||
|
|
||||||
|
// tree
|
||||||
|
auto *treectrl = new wxTreeCtrl(panel, wxID_ANY, wxDefaultPosition, wxSize(185, -1), wxTR_NO_BUTTONS | wxTR_HIDE_ROOT | wxTR_SINGLE | wxTR_NO_LINES | wxBORDER_SUNKEN | wxWANTS_CHARS);
|
||||||
|
left_sizer->Add(treectrl, 1, wxEXPAND);
|
||||||
|
icons = new wxImageList(16, 16, 1);
|
||||||
|
// Map from an icon file name to its index in $self->{icons}.
|
||||||
|
// $self->{icon_index} = {};
|
||||||
|
// Index of the last icon inserted into $self->{icons}.
|
||||||
|
icon_count = -1;
|
||||||
|
treectrl->AssignImageList(icons);
|
||||||
|
treectrl->AddRoot("root");
|
||||||
|
// $self->{pages} = [];
|
||||||
|
treectrl->SetIndent(0);
|
||||||
|
disable_tree_sel_changed_event = 0;
|
||||||
|
|
||||||
|
/* EVT_TREE_SEL_CHANGED($parent, $self->{treectrl}, sub {
|
||||||
|
return if $self->{disable_tree_sel_changed_event};
|
||||||
|
my $page = first { $_->{title} eq $self->{treectrl}->GetItemText($self->{treectrl}->GetSelection) } @{$self->{pages}}
|
||||||
|
or return;
|
||||||
|
$_->Hide for @{$self->{pages}};
|
||||||
|
$page->Show;
|
||||||
|
$self->{hsizer}->Layout;
|
||||||
|
$self->Refresh;
|
||||||
|
});
|
||||||
|
EVT_KEY_DOWN($self->{treectrl}, sub {
|
||||||
|
my ($treectrl, $event) = @_;
|
||||||
|
if ($event->GetKeyCode == WXK_TAB) {
|
||||||
|
$treectrl->Navigate($event->ShiftDown ? &Wx::wxNavigateBackward : &Wx::wxNavigateForward);
|
||||||
|
} else {
|
||||||
|
$event->Skip;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
EVT_COMBOBOX($parent, $self->{presets_choice}, sub {
|
||||||
|
$self->select_preset($self->{presets_choice}->GetStringSelection);
|
||||||
|
});
|
||||||
|
|
||||||
|
EVT_BUTTON($self, $self->{btn_save_preset}, sub { $self->save_preset });
|
||||||
|
EVT_BUTTON($self, $self->{btn_delete_preset}, sub { $self->delete_preset });
|
||||||
|
EVT_BUTTON($self, $self->{btn_hide_incompatible_presets}, sub { $self->_toggle_show_hide_incompatible });
|
||||||
|
*/
|
||||||
|
// Initialize the DynamicPrintConfig by default keys/values.
|
||||||
|
// Possible %params keys: no_controller
|
||||||
|
// build(/*%params*/);
|
||||||
|
// rebuild_page_tree();
|
||||||
|
// _update();
|
||||||
|
|
||||||
|
|
||||||
|
return;//$self;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CTab::OnTreeSelChange(wxCommandEvent& event)
|
||||||
|
{
|
||||||
|
if (disable_tree_sel_changed_event) return;
|
||||||
|
CPage* page = nullptr;
|
||||||
|
for (auto& el : pages)
|
||||||
|
if (el.title() == treectrl->GetSelection())
|
||||||
|
{
|
||||||
|
page = ⪙
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (page == nullptr) return;
|
||||||
|
|
||||||
|
for (auto& el : pages)
|
||||||
|
el.Hide();
|
||||||
|
page->Show();
|
||||||
|
hsizer->Layout();
|
||||||
|
this->Refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
void CTab::OnKeyDown(wxKeyEvent& event)
|
||||||
|
{
|
||||||
|
event.GetKeyCode() == WXK_TAB ?
|
||||||
|
treectrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward) :
|
||||||
|
event.Skip();
|
||||||
|
};
|
||||||
|
|
||||||
|
void CTab::save_preset(wxCommandEvent &event){};
|
||||||
|
void CTab::delete_preset(wxCommandEvent &event){};
|
||||||
|
void CTab::_toggle_show_hide_incompatible(wxCommandEvent &event){};
|
||||||
|
|
||||||
|
} // GUI
|
||||||
|
} // Slic3r
|
109
xs/src/slic3r/GUI/Tab.h
Normal file
109
xs/src/slic3r/GUI/Tab.h
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
// The "Expert" tab at the right of the main tabbed window.
|
||||||
|
//
|
||||||
|
// This file implements following packages:
|
||||||
|
// Slic3r::GUI::Tab;
|
||||||
|
// Slic3r::GUI::Tab::Print;
|
||||||
|
// Slic3r::GUI::Tab::Filament;
|
||||||
|
// Slic3r::GUI::Tab::Printer;
|
||||||
|
// Slic3r::GUI::Tab::Page
|
||||||
|
// - Option page: For example, the Slic3r::GUI::Tab::Print has option pages "Layers and perimeters", "Infill", "Skirt and brim" ...
|
||||||
|
// Slic3r::GUI::SavePresetWindow
|
||||||
|
// - Dialog to select a new preset name to store the configuration.
|
||||||
|
// Slic3r::GUI::Tab::Preset;
|
||||||
|
// - Single preset item: name, file is default or external.
|
||||||
|
|
||||||
|
#include <wx/panel.h>
|
||||||
|
#include <wx/notebook.h>
|
||||||
|
#include <wx/scrolwin.h>
|
||||||
|
#include <wx/sizer.h>
|
||||||
|
#include <wx/bmpcbox.h>
|
||||||
|
#include <wx/bmpbuttn.h>
|
||||||
|
#include <wx/treectrl.h>
|
||||||
|
#include <wx/imaglist.h>
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
// Single Tab page containing a{ vsizer } of{ optgroups }
|
||||||
|
// package Slic3r::GUI::Tab::Page;
|
||||||
|
class CPage : public wxScrolledWindow
|
||||||
|
{
|
||||||
|
const char* _title;
|
||||||
|
wxWindow* _parent;
|
||||||
|
wxBoxSizer* _vsizer;
|
||||||
|
size_t _iconID;
|
||||||
|
// const OptionsGroup opt; // $self->{optgroups} = [];
|
||||||
|
public:
|
||||||
|
CPage(){};
|
||||||
|
CPage(wxWindow* parent, const char* title, int iconID) :
|
||||||
|
_parent(parent),
|
||||||
|
_title(title),
|
||||||
|
_iconID(iconID)
|
||||||
|
{
|
||||||
|
Create(_parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
|
||||||
|
this->SetScrollbars(1, 1, 1, 1);
|
||||||
|
_vsizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
this->SetSizer(_vsizer);
|
||||||
|
}
|
||||||
|
~CPage(){};
|
||||||
|
wxBoxSizer * vsizer(){ return this->_vsizer; }
|
||||||
|
wxString title(){ return wxString(_title); }
|
||||||
|
};
|
||||||
|
|
||||||
|
// Slic3r::GUI::Tab;
|
||||||
|
class CTab: public wxPanel
|
||||||
|
{
|
||||||
|
protected:
|
||||||
|
const char* _title;
|
||||||
|
wxBitmapComboBox* presets_choice;
|
||||||
|
wxBitmap* bmp_show_incompatible_presets;
|
||||||
|
wxBitmap* bmp_hide_incompatible_presets;
|
||||||
|
wxBitmapButton* btn_hide_incompatible_presets;
|
||||||
|
wxBoxSizer* hsizer;
|
||||||
|
wxBoxSizer* left_sizer;
|
||||||
|
wxTreeCtrl* treectrl;
|
||||||
|
wxImageList* icons;
|
||||||
|
int icon_count;
|
||||||
|
// std::map<size_t, wxImageList*> icon_index;
|
||||||
|
std::vector<CPage> pages;
|
||||||
|
bool disable_tree_sel_changed_event;
|
||||||
|
public:
|
||||||
|
CTab(){};
|
||||||
|
CTab(wxNotebook* parent, const char *title/*, someParams*/){}
|
||||||
|
~CTab(){};
|
||||||
|
|
||||||
|
void create_preset_tab();
|
||||||
|
void OnTreeSelChange(wxCommandEvent& event);
|
||||||
|
void OnKeyDown(wxKeyEvent& event);
|
||||||
|
void OnComboBox(wxCommandEvent& event){ /*$self->select_preset(presets_choice->GetStringSelection)*/ };
|
||||||
|
void save_preset(wxCommandEvent &event);
|
||||||
|
void delete_preset(wxCommandEvent &event);
|
||||||
|
void _toggle_show_hide_incompatible(wxCommandEvent &event);
|
||||||
|
|
||||||
|
// virtual void build(/*%params*/);
|
||||||
|
// virtual void rebuild_page_tree();
|
||||||
|
// virtual void _update();
|
||||||
|
private:
|
||||||
|
// DECLARE_EVENT_TABLE()
|
||||||
|
};
|
||||||
|
|
||||||
|
//Slic3r::GUI::Tab::Print;
|
||||||
|
class CTabPrint : public CTab
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CTabPrint() {};
|
||||||
|
CTabPrint(wxNotebook* parent, const char *title/*, someParams*/)
|
||||||
|
{
|
||||||
|
_title = title;
|
||||||
|
Create(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBK_LEFT | wxTAB_TRAVERSAL);
|
||||||
|
create_preset_tab();
|
||||||
|
}
|
||||||
|
~CTabPrint(){};
|
||||||
|
// void build(/*%params*/){};
|
||||||
|
};
|
||||||
|
|
||||||
|
} // GUI
|
||||||
|
} // Slic3r
|
12
xs/src/slic3r/GUI/Widget.hpp
Normal file
12
xs/src/slic3r/GUI/Widget.hpp
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#ifndef WIDGET_HPP
|
||||||
|
#define WIDGET_HPP
|
||||||
|
#include "wxinit.h"
|
||||||
|
class Widget {
|
||||||
|
protected:
|
||||||
|
wxSizer* _sizer;
|
||||||
|
public:
|
||||||
|
Widget(): _sizer(nullptr) { }
|
||||||
|
bool valid() const { return _sizer != nullptr; }
|
||||||
|
wxSizer* sizer() const { return _sizer; }
|
||||||
|
};
|
||||||
|
#endif
|
25
xs/src/slic3r/GUI/wxinit.h
Normal file
25
xs/src/slic3r/GUI/wxinit.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#ifndef slic3r_wxinit_hpp_
|
||||||
|
#define slic3r_wxinit_hpp_
|
||||||
|
|
||||||
|
#include <wx/wx.h>
|
||||||
|
#include <wx/intl.h>
|
||||||
|
#include <wx/html/htmlwin.h>
|
||||||
|
|
||||||
|
// Perl redefines a _ macro, so we undef this one
|
||||||
|
#undef _
|
||||||
|
|
||||||
|
// We do want to use translation however, so define it as __ so we can do a find/replace
|
||||||
|
// later when we no longer need to undef _
|
||||||
|
#define __(s) wxGetTranslation((s))
|
||||||
|
|
||||||
|
// legacy macros
|
||||||
|
// https://wiki.wxwidgets.org/EventTypes_and_Event-Table_Macros
|
||||||
|
#ifndef wxEVT_BUTTON
|
||||||
|
#define wxEVT_BUTTON wxEVT_COMMAND_BUTTON_CLICKED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef wxEVT_HTML_LINK_CLICKED
|
||||||
|
#define wxEVT_HTML_LINK_CLICKED wxEVT_COMMAND_HTML_LINK_CLICKED
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user