1 #ifndef slic3r_Plater_hpp_
2 #define slic3r_Plater_hpp_
3 
4 #include <memory>
5 #include <vector>
6 #include <boost/filesystem/path.hpp>
7 
8 #include <wx/panel.h>
9 
10 #include "Selection.hpp"
11 
12 #include "libslic3r/Preset.hpp"
13 #include "libslic3r/BoundingBox.hpp"
14 #include "libslic3r/GCode/GCodeProcessor.hpp"
15 #include "Jobs/Job.hpp"
16 #include "Search.hpp"
17 
18 class wxButton;
19 class ScalableButton;
20 class wxScrolledWindow;
21 class wxString;
22 
23 namespace Slic3r {
24 
25 class Model;
26 class ModelObject;
27 class ModelInstance;
28 class Print;
29 class SLAPrint;
30 enum SLAPrintObjectStep : unsigned int;
31 
32 using ModelInstancePtrs = std::vector<ModelInstance*>;
33 
34 namespace UndoRedo {
35     class Stack;
36     struct Snapshot;
37 }
38 
39 namespace GUI {
40 
41 class MainFrame;
42 class ConfigOptionsGroup;
43 class ObjectManipulation;
44 class ObjectSettings;
45 class ObjectLayers;
46 class ObjectList;
47 class GLCanvas3D;
48 class Mouse3DController;
49 class NotificationManager;
50 struct Camera;
51 class Bed3D;
52 class GLToolbar;
53 class PlaterPresetComboBox;
54 
55 using t_optgroups = std::vector <std::shared_ptr<ConfigOptionsGroup>>;
56 
57 class Plater;
58 enum class ActionButtonType : int;
59 
60 class Sidebar : public wxPanel
61 {
62     ConfigOptionMode    m_mode;
63 public:
64     Sidebar(Plater *parent);
65     Sidebar(Sidebar &&) = delete;
66     Sidebar(const Sidebar &) = delete;
67     Sidebar &operator=(Sidebar &&) = delete;
68     Sidebar &operator=(const Sidebar &) = delete;
69     ~Sidebar();
70 
71     void init_filament_combo(PlaterPresetComboBox **combo, const int extr_idx);
72     void remove_unused_filament_combos(const size_t current_extruder_count);
73     void update_all_preset_comboboxes();
74     void update_presets(Slic3r::Preset::Type preset_type);
75     void update_mode_sizer() const;
76     void change_top_border_for_mode_sizer(bool increase_border);
77     void update_reslice_btn_tooltip() const;
78     void msw_rescale();
79     void sys_color_changed();
80     void search();
81     void jump_to_option(size_t selected);
82 
83     ObjectManipulation*     obj_manipul();
84     ObjectList*             obj_list();
85     ObjectSettings*         obj_settings();
86     ObjectLayers*           obj_layers();
87     wxScrolledWindow*       scrolled_panel();
88     wxPanel*                presets_panel();
89 
90     ConfigOptionsGroup*     og_freq_chng_params(const bool is_fff);
91     wxButton*               get_wiping_dialog_button();
92     void                    update_objects_list_extruder_column(size_t extruders_count);
93     void                    show_info_sizer();
94     void                    show_sliced_info_sizer(const bool show);
95     void                    update_sliced_info_sizer();
96     void                    enable_buttons(bool enable);
97     void                    set_btn_label(const ActionButtonType btn_type, const wxString& label) const;
98     bool                    show_reslice(bool show) const;
99 	bool                    show_export(bool show) const;
100 	bool                    show_send(bool show) const;
101     bool                    show_eject(bool show)const;
102 	bool                    show_export_removable(bool show) const;
103 	bool                    get_eject_shown() const;
104     bool                    is_multifilament();
105     void                    update_mode();
106     bool                    is_collapsed();
107     void                    collapse(bool collapse);
108     void                    update_searcher();
109     void                    update_ui_from_settings();
110 
111     std::vector<PlaterPresetComboBox*>&   combos_filament();
112     Search::OptionsSearcher&        get_searcher();
113     std::string&                    get_search_line();
114 
115 private:
116     struct priv;
117     std::unique_ptr<priv> p;
118 };
119 
120 class Plater: public wxPanel
121 {
122 public:
123     using fs_path = boost::filesystem::path;
124 
125     Plater(wxWindow *parent, MainFrame *main_frame);
126     Plater(Plater &&) = delete;
127     Plater(const Plater &) = delete;
128     Plater &operator=(Plater &&) = delete;
129     Plater &operator=(const Plater &) = delete;
130     ~Plater();
131 
132     Sidebar& sidebar();
133     Model& model();
134     const Print& fff_print() const;
135     Print& fff_print();
136     const SLAPrint& sla_print() const;
137     SLAPrint& sla_print();
138 
139     void new_project();
140     void load_project();
141     void load_project(const wxString& filename);
142     void add_model(bool imperial_units = false);
143     void import_sl1_archive();
144     void extract_config_from_project();
145     void load_gcode();
146     void load_gcode(const wxString& filename);
147     void reload_gcode_from_disk();
148     void refresh_print();
149 
150     std::vector<size_t> load_files(const std::vector<boost::filesystem::path>& input_files, bool load_model = true, bool load_config = true, bool imperial_units = false);
151     // To be called when providing a list of files to the GUI slic3r on command line.
152     std::vector<size_t> load_files(const std::vector<std::string>& input_files, bool load_model = true, bool load_config = true, bool imperial_units = false);
153 #if ENABLE_DRAG_AND_DROP_FIX
154     // to be called on drag and drop
155     bool load_files(const wxArrayString& filenames);
156 #endif // ENABLE_DRAG_AND_DROP_FIX
157 
get_last_loaded_gcode() const158     const wxString& get_last_loaded_gcode() const { return m_last_loaded_gcode; }
159 
160     void update();
161     void stop_jobs();
162     void select_view(const std::string& direction);
163     void select_view_3D(const std::string& name);
164 
165     bool is_preview_shown() const;
166     bool is_preview_loaded() const;
167     bool is_view3D_shown() const;
168 
169     bool are_view3D_labels_shown() const;
170     void show_view3D_labels(bool show);
171 
172     bool is_sidebar_collapsed() const;
173     void collapse_sidebar(bool show);
174 
175     bool is_view3D_layers_editing_enabled() const;
176 
177     // Called after the Preferences dialog is closed and the program settings are saved.
178     // Update the UI based on the current preferences.
179     void update_ui_from_settings(bool apply_free_camera_correction = true);
180 
181     void select_all();
182     void deselect_all();
183     void remove(size_t obj_idx);
184     void reset();
185     void reset_with_confirm();
186     void delete_object_from_model(size_t obj_idx);
187     void remove_selected();
188     void increase_instances(size_t num = 1);
189     void decrease_instances(size_t num = 1);
190     void set_number_of_copies(/*size_t num*/);
191     void fill_bed_with_instances();
192     bool is_selection_empty() const;
193     void scale_selection_to_fit_print_volume();
194     void convert_unit(bool from_imperial_unit);
195 
196     void cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false);
197 
198     void export_gcode(bool prefer_removable);
199     void export_stl(bool extended = false, bool selection_only = false);
200     void export_amf();
201     void export_3mf(const boost::filesystem::path& output_path = boost::filesystem::path());
202     void reload_from_disk();
203     void reload_all_from_disk();
204     bool has_toolpaths_to_export() const;
205     void export_toolpaths_to_obj() const;
206     void reslice();
207     void reslice_SLA_supports(const ModelObject &object, bool postpone_error_messages = false);
208     void reslice_SLA_hollowing(const ModelObject &object, bool postpone_error_messages = false);
209     void reslice_SLA_until_step(SLAPrintObjectStep step, const ModelObject &object, bool postpone_error_messages = false);
210     void changed_object(int obj_idx);
211     void changed_objects(const std::vector<size_t>& object_idxs);
212     void schedule_background_process(bool schedule = true);
213     bool is_background_process_update_scheduled() const;
214     void suppress_background_process(const bool stop_background_process) ;
215     void fix_through_netfabb(const int obj_idx, const int vol_idx = -1);
216     void send_gcode();
217 	void eject_drive();
218 
219     void take_snapshot(const std::string &snapshot_name);
220     void take_snapshot(const wxString &snapshot_name);
221     void undo();
222     void redo();
223     void undo_to(int selection);
224     void redo_to(int selection);
225     bool undo_redo_string_getter(const bool is_undo, int idx, const char** out_text);
226     void undo_redo_topmost_string_getter(const bool is_undo, std::string& out_text);
227     bool search_string_getter(int idx, const char** label, const char** tooltip);
228     // For the memory statistics.
229     const Slic3r::UndoRedo::Stack& undo_redo_stack_main() const;
230     void clear_undo_redo_stack_main();
231     // Enter / leave the Gizmos specific Undo / Redo stack. To be used by the SLA support point editing gizmo.
232     void enter_gizmos_stack();
233     void leave_gizmos_stack();
234 
235     void on_extruders_change(size_t extruders_count);
236     void on_config_change(const DynamicPrintConfig &config);
237     void force_filament_colors_update();
238     void force_print_bed_update();
239     // On activating the parent window.
240     void on_activate();
241     std::vector<std::string> get_extruder_colors_from_plater_config(const GCodeProcessor::Result* const result = nullptr) const;
242     std::vector<std::string> get_colors_for_color_print(const GCodeProcessor::Result* const result = nullptr) const;
243 
244     void update_object_menu();
245     void show_action_buttons(const bool is_ready_to_slice) const;
246 
247     wxString get_project_filename(const wxString& extension = wxEmptyString) const;
248     void set_project_filename(const wxString& filename);
249 
250     bool is_export_gcode_scheduled() const;
251 
252     const Selection& get_selection() const;
253     int get_selected_object_idx();
254     bool is_single_full_object_selection() const;
255     GLCanvas3D* canvas3D();
256     const GLCanvas3D * canvas3D() const;
257     GLCanvas3D* get_current_canvas3D();
258     BoundingBoxf bed_shape_bb() const;
259 
260     void arrange();
261     void find_new_position(const ModelInstancePtrs  &instances, coord_t min_d);
262 
263     void set_current_canvas_as_dirty();
264     void unbind_canvas_event_handlers();
265     void reset_canvas_volumes();
266 
267     PrinterTechnology   printer_technology() const;
268     const DynamicPrintConfig * config() const;
269     bool                set_printer_technology(PrinterTechnology printer_technology);
270 
271     void copy_selection_to_clipboard();
272     void paste_from_clipboard();
273     void search(bool plater_is_active);
274 
275     bool can_delete() const;
276     bool can_delete_all() const;
277     bool can_increase_instances() const;
278     bool can_decrease_instances() const;
279     bool can_set_instance_to_object() const;
280     bool can_fix_through_netfabb() const;
281     bool can_split_to_objects() const;
282     bool can_split_to_volumes() const;
283     bool can_arrange() const;
284     bool can_layers_editing() const;
285     bool can_paste_from_clipboard() const;
286     bool can_copy_to_clipboard() const;
287     bool can_undo() const;
288     bool can_redo() const;
289     bool can_reload_from_disk() const;
290 
291     void msw_rescale();
292     void sys_color_changed();
293 
294     bool init_view_toolbar();
295     void enable_view_toolbar(bool enable);
296     bool init_collapse_toolbar();
297     void enable_collapse_toolbar(bool enable);
298 
299     const Camera& get_camera() const;
300     Camera& get_camera();
301 
302 #if ENABLE_ENVIRONMENT_MAP
303     void init_environment_texture();
304     unsigned int get_environment_texture_id() const;
305 #endif // ENABLE_ENVIRONMENT_MAP
306 
307     const Bed3D& get_bed() const;
308     Bed3D& get_bed();
309 
310     const GLToolbar& get_view_toolbar() const;
311     GLToolbar& get_view_toolbar();
312 
313     const GLToolbar& get_collapse_toolbar() const;
314     GLToolbar& get_collapse_toolbar();
315 
316     void update_preview_bottom_toolbar();
317     void update_preview_moves_slider();
318     void enable_preview_moves_slider(bool enable);
319 
320     void reset_gcode_toolpaths();
reset_last_loaded_gcode()321     void reset_last_loaded_gcode() { m_last_loaded_gcode = ""; }
322 
323     const Mouse3DController& get_mouse3d_controller() const;
324     Mouse3DController& get_mouse3d_controller();
325 
326 	void set_bed_shape() const;
327     void set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model, bool force_as_custom = false) const;
328 
329 	const NotificationManager* get_notification_manager() const;
330 	NotificationManager* get_notification_manager();
331 
332     void bring_instance_forward();
333 
334     // ROII wrapper for suppressing the Undo / Redo snapshot to be taken.
335 	class SuppressSnapshots
336 	{
337 	public:
SuppressSnapshots(Plater * plater)338 		SuppressSnapshots(Plater *plater) : m_plater(plater)
339 		{
340 			m_plater->suppress_snapshots();
341 		}
~SuppressSnapshots()342 		~SuppressSnapshots()
343 		{
344 			m_plater->allow_snapshots();
345 		}
346 	private:
347 		Plater *m_plater;
348 	};
349 
350 	// ROII wrapper for taking an Undo / Redo snapshot while disabling the snapshot taking by the methods called from inside this snapshot.
351 	class TakeSnapshot
352 	{
353 	public:
TakeSnapshot(Plater * plater,const wxString & snapshot_name)354 		TakeSnapshot(Plater *plater, const wxString &snapshot_name) : m_plater(plater)
355 		{
356 			m_plater->take_snapshot(snapshot_name);
357 			m_plater->suppress_snapshots();
358 		}
~TakeSnapshot()359 		~TakeSnapshot()
360 		{
361 			m_plater->allow_snapshots();
362 		}
363 	private:
364 		Plater *m_plater;
365 	};
366 
367     bool inside_snapshot_capture();
368 
369 #if ENABLE_RENDER_STATISTICS
370     void toggle_render_statistic_dialog();
371     bool is_render_statistic_dialog_visible() const;
372 #endif // ENABLE_RENDER_STATISTICS
373 
374 	// Wrapper around wxWindow::PopupMenu to suppress error messages popping out while tracking the popup menu.
375 	bool PopupMenu(wxMenu *menu, const wxPoint& pos = wxDefaultPosition);
PopupMenu(wxMenu * menu,int x,int y)376     bool PopupMenu(wxMenu *menu, int x, int y) { return this->PopupMenu(menu, wxPoint(x, y)); }
377 
378 private:
379     struct priv;
380     std::unique_ptr<priv> p;
381 
382     // Set true during PopupMenu() tracking to suppress immediate error message boxes.
383     // The error messages are collected to m_tracking_popup_menu_error_message instead and these error messages
384     // are shown after the pop-up dialog closes.
385     bool 	 m_tracking_popup_menu = false;
386     wxString m_tracking_popup_menu_error_message;
387 
388     wxString m_last_loaded_gcode;
389 
390     void suppress_snapshots();
391     void allow_snapshots();
392 
393     friend class SuppressBackgroundProcessingUpdate;
394 };
395 
396 class SuppressBackgroundProcessingUpdate
397 {
398 public:
399     SuppressBackgroundProcessingUpdate();
400     ~SuppressBackgroundProcessingUpdate();
401 private:
402     bool m_was_scheduled;
403 };
404 
405 } // namespace GUI
406 } // namespace Slic3r
407 
408 #endif
409