1 #ifndef slic3r_PresetComboBoxes_hpp_
2 #define slic3r_PresetComboBoxes_hpp_
3 
4 #include <wx/bmpcbox.h>
5 #include <wx/gdicmn.h>
6 
7 #include "libslic3r/Preset.hpp"
8 #include "wxExtensions.hpp"
9 #include "GUI_Utils.hpp"
10 
11 class wxString;
12 class wxTextCtrl;
13 class wxStaticText;
14 class ScalableButton;
15 class wxBoxSizer;
16 class wxComboBox;
17 class wxStaticBitmap;
18 class wxRadioBox;
19 
20 namespace Slic3r {
21 
22 namespace GUI {
23 
24 class BitmapCache;
25 
26 // ---------------------------------
27 // ***  PresetComboBox  ***
28 // ---------------------------------
29 
30 // BitmapComboBox used to presets list on Sidebar and Tabs
31 class PresetComboBox : public wxBitmapComboBox
32 {
33 public:
34     PresetComboBox(wxWindow* parent, Preset::Type preset_type, const wxSize& size = wxDefaultSize);
35     ~PresetComboBox();
36 
37 	enum LabelItemType {
38 		LABEL_ITEM_PHYSICAL_PRINTER = 0xffffff01,
39 		LABEL_ITEM_DISABLED,
40 		LABEL_ITEM_MARKER,
41 		LABEL_ITEM_PHYSICAL_PRINTERS,
42 		LABEL_ITEM_WIZARD_PRINTERS,
43         LABEL_ITEM_WIZARD_FILAMENTS,
44         LABEL_ITEM_WIZARD_MATERIALS,
45 
46         LABEL_ITEM_MAX,
47 	};
48 
49     void set_label_marker(int item, LabelItemType label_item_type = LABEL_ITEM_MARKER);
50     bool set_printer_technology(PrinterTechnology pt);
51 
set_selection_changed_function(std::function<void (int)> sel_changed)52     void set_selection_changed_function(std::function<void(int)> sel_changed) { on_selection_changed = sel_changed; }
53 
54     bool is_selected_physical_printer();
55 
56     // Return true, if physical printer was selected
57     // and next internal selection was accomplished
58     bool selection_is_changed_according_to_physical_printers();
59 
60     void update(std::string select_preset);
61 
62     void edit_physical_printer();
63     void add_physical_printer();
64     bool del_physical_printer(const wxString& note_string = wxEmptyString);
65 
66     virtual void update();
67     virtual void msw_rescale();
68 
69 protected:
70     typedef std::size_t Marker;
71     std::function<void(int)>    on_selection_changed { nullptr };
72 
73     Preset::Type        m_type;
74     std::string         m_main_bitmap_name;
75 
76     PresetBundle*       m_preset_bundle {nullptr};
77     PresetCollection*   m_collection {nullptr};
78 
79     // Caching bitmaps for the all bitmaps, used in preset comboboxes
80     static BitmapCache& bitmap_cache();
81 
82     // Indicator, that the preset is compatible with the selected printer.
83     ScalableBitmap      m_bitmapCompatible;
84     // Indicator, that the preset is NOT compatible with the selected printer.
85     ScalableBitmap      m_bitmapIncompatible;
86 
87     int m_last_selected;
88     int m_em_unit;
89     bool m_suppress_change { true };
90 
91     // parameters for an icon's drawing
92     int icon_height;
93     int norm_icon_width;
94     int thin_icon_width;
95     int wide_icon_width;
96     int space_icon_width;
97     int thin_space_icon_width;
98     int wide_space_icon_width;
99 
100     PrinterTechnology printer_technology {ptAny};
101 
102     void invalidate_selection();
103     void validate_selection(bool predicate = false);
104     void update_selection();
105 
106 #ifdef __linux__
separator_head()107     static const char* separator_head() { return "------- "; }
separator_tail()108     static const char* separator_tail() { return " -------"; }
109 #else // __linux__
separator_head()110     static const char* separator_head() { return "————— "; }
separator_tail()111     static const char* separator_tail() { return " —————"; }
112 #endif // __linux__
113     static wxString    separator(const std::string& label);
114 
115     wxBitmap* get_bmp(  std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
116                         bool is_compatible = true, bool is_system = false, bool is_single_bar = false,
117                         std::string filament_rgb = "", std::string extruder_rgb = "");
118 
119     wxBitmap* get_bmp(  std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name,
120                         bool is_enabled = true, bool is_compatible = true, bool is_system = false);
121 
122 #ifdef __APPLE__
123     /* For PresetComboBox we use bitmaps that are created from images that are already scaled appropriately for Retina
124      * (Contrary to the intuition, the `scale` argument for Bitmap's constructor doesn't mean
125      * "please scale this to such and such" but rather
126      * "the wxImage is already sized for backing scale such and such". )
127      * Unfortunately, the constructor changes the size of wxBitmap too.
128      * Thus We need to use unscaled size value for bitmaps that we use
129      * to avoid scaled size of control items.
130      * For this purpose control drawing methods and
131      * control size calculation methods (virtual) are overridden.
132      **/
133     bool OnAddBitmap(const wxBitmap& bitmap) override;
134     void OnDrawItem(wxDC& dc, const wxRect& rect, int item, int flags) const override;
135 #endif
136 
137 private:
138     void fill_width_height();
139 };
140 
141 
142 // ---------------------------------
143 // ***  PlaterPresetComboBox  ***
144 // ---------------------------------
145 
146 class PlaterPresetComboBox : public PresetComboBox
147 {
148 public:
149     PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type);
150     ~PlaterPresetComboBox();
151 
152     ScalableButton* edit_btn { nullptr };
153 
set_extruder_idx(const int extr_idx)154     void set_extruder_idx(const int extr_idx)   { m_extruder_idx = extr_idx; }
get_extruder_idx() const155     int  get_extruder_idx() const               { return m_extruder_idx; }
156 
157     bool switch_to_tab();
158     void show_add_menu();
159     void show_edit_menu();
160 
161     void update() override;
162     void msw_rescale() override;
163 
164 private:
165     int     m_extruder_idx = -1;
166 };
167 
168 
169 // ---------------------------------
170 // ***  TabPresetComboBox  ***
171 // ---------------------------------
172 
173 class TabPresetComboBox : public PresetComboBox
174 {
175     bool show_incompatible {false};
176     bool m_enable_all {false};
177 
178 public:
179     TabPresetComboBox(wxWindow *parent, Preset::Type preset_type);
~TabPresetComboBox()180     ~TabPresetComboBox() {}
set_show_incompatible_presets(bool show_incompatible_presets)181     void set_show_incompatible_presets(bool show_incompatible_presets) {
182         show_incompatible = show_incompatible_presets;
183     }
184 
185     void update() override;
186     void update_dirty();
187     void msw_rescale() override;
188 
set_enable_all(bool enable=true)189     void set_enable_all(bool enable=true) { m_enable_all = enable; }
190 
presets() const191     PresetCollection*   presets()   const { return m_collection; }
type() const192     Preset::Type        type()      const { return m_type; }
193 };
194 
195 } // namespace GUI
196 } // namespace Slic3r
197 
198 #endif
199