From ea30385fd0fe85b368c03ec3fb359bf8b75d36d0 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Fri, 5 Oct 2018 23:29:15 +0200 Subject: [PATCH] Completed split of the GUI_ObjectParts --- src/slic3r/CMakeLists.txt | 2 - src/slic3r/GUI/GLCanvas3D.cpp | 5 +- src/slic3r/GUI/GUI.cpp | 229 +--- src/slic3r/GUI/GUI.hpp | 82 +- src/slic3r/GUI/GUI_App.cpp | 46 +- src/slic3r/GUI/GUI_App.hpp | 36 +- src/slic3r/GUI/GUI_ObjectList.cpp | 1077 ++++++++++++++++- src/slic3r/GUI/GUI_ObjectList.hpp | 101 +- src/slic3r/GUI/GUI_ObjectManipulation.cpp | 137 ++- src/slic3r/GUI/GUI_ObjectManipulation.hpp | 14 +- src/slic3r/GUI/GUI_ObjectParts.cpp | 1274 --------------------- src/slic3r/GUI/GUI_ObjectParts.hpp | 134 --- src/slic3r/GUI/GUI_Preview.cpp | 102 +- src/slic3r/GUI/GUI_Preview.hpp | 16 + src/slic3r/GUI/LambdaObjectDialog.hpp | 18 + src/slic3r/GUI/MainFrame.cpp | 25 +- src/slic3r/GUI/MainFrame.hpp | 10 + src/slic3r/GUI/Plater.cpp | 54 +- src/slic3r/GUI/Plater.hpp | 9 +- src/slic3r/GUI/Tab.cpp | 28 +- src/slic3r/GUI/wxExtensions.cpp | 5 +- 21 files changed, 1524 insertions(+), 1880 deletions(-) delete mode 100644 src/slic3r/GUI/GUI_ObjectParts.cpp delete mode 100644 src/slic3r/GUI/GUI_ObjectParts.hpp diff --git a/src/slic3r/CMakeLists.txt b/src/slic3r/CMakeLists.txt index 4974d66fc..54c90c20e 100644 --- a/src/slic3r/CMakeLists.txt +++ b/src/slic3r/CMakeLists.txt @@ -33,8 +33,6 @@ add_library(libslic3r_gui STATIC ${LIBDIR}/slic3r/GUI/PresetHints.hpp ${LIBDIR}/slic3r/GUI/GUI.cpp ${LIBDIR}/slic3r/GUI/GUI.hpp - ${LIBDIR}/slic3r/GUI/GUI_ObjectParts.cpp - ${LIBDIR}/slic3r/GUI/GUI_ObjectParts.hpp ${LIBDIR}/slic3r/GUI/GUI_Preview.cpp ${LIBDIR}/slic3r/GUI/GUI_Preview.hpp ${LIBDIR}/slic3r/GUI/GUI_PreviewIface.cpp diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index f65e380e5..5a28ee5c0 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -11,6 +11,7 @@ #include "../../libslic3r/PrintConfig.hpp" #include "../../libslic3r/GCode/PreviewData.hpp" #include "GUI_App.hpp" +#include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" #include @@ -3243,7 +3244,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt) { v->set_scaling_factor((double)scale_factor); } - update_scale_values((double)scale_factor); + wxGetApp().obj_manipul()->update_scale_values((double)scale_factor); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM break; } @@ -5397,7 +5398,7 @@ void GLCanvas3D::_on_select(int volume_idx, int object_idx) } post_event(ObjectSelectEvent(obj_id, vol_id)); - Slic3r::GUI::select_current_volume(obj_id, vol_id); + wxGetApp().obj_list()->select_current_volume(obj_id, vol_id); } std::vector GLCanvas3D::_parse_colors(const std::vector& colors) diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 34889b809..e06f6b721 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -1,14 +1,12 @@ #include "GUI.hpp" +#include "GUI_App.hpp" #include "../AppController.hpp" #include "WipeTowerDialog.hpp" #include -#include #include #include -#include -#include #if __APPLE__ #import @@ -26,50 +24,18 @@ #include "boost/nowide/convert.hpp" #endif -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include #include -#include -#include #include "wxExtensions.hpp" - -#include "Tab.hpp" -#include "TabIface.hpp" #include "GUI_Preview.hpp" #include "GUI_PreviewIface.hpp" #include "AboutDialog.hpp" #include "AppConfig.hpp" -#include "ConfigSnapshotDialog.hpp" -#include "ProgressStatusBar.hpp" -#include "Utils.hpp" -#include "MsgDialog.hpp" #include "ConfigWizard.hpp" -#include "Preferences.hpp" #include "PresetBundle.hpp" #include "UpdateDialogs.hpp" -#include "FirmwareDialog.hpp" -#include "GUI_ObjectParts.hpp" - -#include "../Utils/PresetUpdater.hpp" -#include "../Config/Snapshot.hpp" - -#include "3DScene.hpp" -#include "libslic3r/I18N.hpp" -#include "Model.hpp" -#include "LambdaObjectDialog.hpp" +#include "../../libslic3r/Utils.hpp" #include "../../libslic3r/Print.hpp" namespace Slic3r { namespace GUI { @@ -116,91 +82,8 @@ void break_to_debugger() #endif /* _WIN32 */ } -// #ys_FIXME_for_delete -std::vector g_tabs_list; - -//showed/hided controls according to the view mode -wxWindow *g_right_panel = nullptr; -wxBoxSizer *g_frequently_changed_parameters_sizer = nullptr; -wxBoxSizer *g_info_sizer = nullptr; -wxBoxSizer *g_object_list_sizer = nullptr; -std::vector g_buttons; -wxStaticBitmap *g_manifold_warning_icon = nullptr; -bool g_show_print_info = false; -bool g_show_manifold_warning_icon = false; - PreviewIface* g_preview = nullptr; -enum ActionButtons -{ - abExportGCode, - abReslice, - abPrint, - abSendGCode, -}; - -void set_objects_from_perl( wxWindow* parent, - wxBoxSizer *frequently_changed_parameters_sizer, - wxBoxSizer *info_sizer, - wxButton *btn_export_gcode, - wxButton *btn_reslice, - wxButton *btn_print, - wxButton *btn_send_gcode, - wxStaticBitmap *manifold_warning_icon) -{ - g_right_panel = parent->GetParent(); - g_frequently_changed_parameters_sizer = frequently_changed_parameters_sizer; - g_info_sizer = info_sizer; - - g_buttons.push_back(btn_export_gcode); - g_buttons.push_back(btn_reslice); - g_buttons.push_back(btn_print); - g_buttons.push_back(btn_send_gcode); - - // Update font style for buttons -// for (auto btn : g_buttons) -// btn->SetFont(bold_font()); - - g_manifold_warning_icon = manifold_warning_icon; -} - -void set_show_print_info(bool show) -{ - g_show_print_info = show; -} - -void set_show_manifold_warning_icon(bool show) -{ - g_show_manifold_warning_icon = show; - if (!g_manifold_warning_icon) - return; - - // update manifold_warning_icon showing - if (show && !g_info_sizer->IsShown(static_cast(0))) - g_show_manifold_warning_icon = false; - - g_manifold_warning_icon->Show(g_show_manifold_warning_icon); - g_manifold_warning_icon->GetParent()->Layout(); -} - -void set_objects_list_sizer(wxBoxSizer *objects_list_sizer){ - g_object_list_sizer = objects_list_sizer; -} - -void open_model(wxWindow *parent, wxArrayString& input_files){ - auto dialog = new wxFileDialog(parent /*? parent : GetTopWindow()*/, - _(L("Choose one or more files (STL/OBJ/AMF/3MF/PRUSA):")), - get_app_config()->get_last_dir(), "", - MODEL_WILDCARD, wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST); - if (dialog->ShowModal() != wxID_OK) { - dialog->Destroy(); - return ; - } - - dialog->GetPaths(input_files); - dialog->Destroy(); -} - bool config_wizard_startup(bool app_config_exists) { if (!app_config_exists || wxGetApp().preset_bundle->printers.size() <= 1) { @@ -236,38 +119,6 @@ void config_wizard(int reason) // Load the currently selected preset into the GUI, update the preset selection box. wxGetApp().load_current_presets(); } -// #ys_FIXME_for_delete -std::vector preset_tabs = { - { "print", nullptr, ptFFF }, - { "filament", nullptr, ptFFF }, - { "sla_material", nullptr, ptSLA } -}; -std::vector* get_preset_tabs() { - return &preset_tabs; -} - -Tab* get_tab(const std::string& name) -{ - std::vector::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(), - [name](PresetTab& tab){ return name == tab.name; }); - return it != preset_tabs.end() ? it->panel : nullptr; -} - -TabIface* get_preset_tab_iface(char *name) -{ - Tab* tab = get_tab(name); - if (tab) return new TabIface(tab); - - for (size_t i = 0; i < wxGetApp().tab_panel()->GetPageCount(); ++i) { - Tab *tab = dynamic_cast(wxGetApp().tab_panel()->GetPage(i)); - if (! tab) - continue; - if (tab->name() == name) { - return new TabIface(tab); - } - } - return new TabIface(nullptr); -} PreviewIface* create_preview_iface(wxNotebook* parent, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data) { @@ -422,9 +273,6 @@ void set_print_callback_event(Print *print, int id) }); } -wxWindow* get_right_panel(){ - return g_right_panel; -} void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string items, bool initial_value) { if (comboCtrl == nullptr) @@ -499,65 +347,6 @@ std::string into_u8(const wxString &str) return std::string(buffer_utf8.data()); } -void set_model_events_from_perl(Model &model, - int event_object_selection_changed, - int event_object_settings_changed, - int event_remove_object, - int event_update_scene) -{ - set_event_object_selection_changed(event_object_selection_changed); - set_event_object_settings_changed(event_object_settings_changed); - set_event_remove_object(event_remove_object); - set_event_update_scene(event_update_scene); - set_objects_from_model(model); - init_mesh_icons(); - -// wxWindowUpdateLocker noUpdates(parent); - -// add_objects_list(parent, sizer); - -// add_collapsible_panes(parent, sizer); -} - -void show_buttons(bool show) -{ - g_buttons[abReslice]->Show(show); - for (size_t i = 0; i < wxGetApp().tab_panel()->GetPageCount(); ++i) { - TabPrinter *tab = dynamic_cast(wxGetApp().tab_panel()->GetPage(i)); - if (!tab) - continue; - if (wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptFFF) { - g_buttons[abPrint]->Show(show && !tab->m_config->opt_string("serial_port").empty()); - g_buttons[abSendGCode]->Show(show && !tab->m_config->opt_string("print_host").empty()); - } - break; - } -} - -void show_info_sizer(const bool show) -{ - g_info_sizer->Show(static_cast(0), show); - g_info_sizer->Show(1, show && g_show_print_info); - g_manifold_warning_icon->Show(show && g_show_manifold_warning_icon); -} - -void show_object_name(bool show) -{ - wxGridSizer* grid_sizer = get_optgroup(ogFrequentlyObjectSettings)->get_grid_sizer(); - grid_sizer->Show(static_cast(0), show); - grid_sizer->Show(static_cast(1), show); -} - -ConfigOptionsGroup* get_optgroup(size_t i) -{ - return wxGetApp().mainframe->m_plater->sidebar().get_optgroup(i); -// return m_optgroups.empty() ? nullptr : m_optgroups[i].get(); -} - -std::vector >& get_optgroups() { - return wxGetApp().mainframe->m_plater->sidebar().get_optgroups();//m_optgroups; -} - wxWindow* export_option_creator(wxWindow* parent) { wxPanel* panel = new wxPanel(parent, -1); @@ -664,20 +453,6 @@ void restore_window_size(wxTopLevelWindow *window, const std::string &name) } } -void enable_action_buttons(bool enable) -{ - if (g_buttons.empty()) - return; - - // Update background colour for buttons - const wxColour bgrd_color = enable ? wxColour(224, 224, 224/*255, 96, 0*/) : wxColour(204, 204, 204); - - for (auto btn : g_buttons) { - btn->Enable(enable); - btn->SetBackgroundColour(bgrd_color); - } -} - void about() { AboutDialog dlg; diff --git a/src/slic3r/GUI/GUI.hpp b/src/slic3r/GUI/GUI.hpp index de17ff7a2..1f2107d59 100644 --- a/src/slic3r/GUI/GUI.hpp +++ b/src/slic3r/GUI/GUI.hpp @@ -1,44 +1,22 @@ #ifndef slic3r_GUI_hpp_ #define slic3r_GUI_hpp_ -#include -#include -#include "PrintConfig.hpp" +#include "Config.hpp" #include "callback.hpp" -#include "GUI_ObjectParts.hpp" #include -#include -class wxApp; class wxWindow; -class wxFrame; class wxMenuBar; class wxNotebook; -class wxPanel; class wxComboCtrl; -class wxString; -class wxArrayString; -class wxArrayLong; -class wxColour; -class wxBoxSizer; -class wxFlexGridSizer; -class wxButton; class wxFileDialog; -class wxStaticBitmap; -class wxFont; class wxTopLevelWindow; namespace Slic3r { -class PresetBundle; -class PresetCollection; -class Print; -class ProgressStatusBar; class AppConfig; -class PresetUpdater; class DynamicPrintConfig; -class TabIface; class PreviewIface; class Print; class GCodePreviewData; @@ -71,56 +49,17 @@ namespace GUI { namespace I18N { namespace GUI { -class Tab; -class ConfigOptionsGroup; -// Map from an file_type name to full file wildcard name. -const std::map FILE_WILDCARDS{ - std::make_pair("known", "Known files (*.stl, *.obj, *.amf, *.xml, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.prusa;*.PRUSA"), - std::make_pair("stl", "STL files (*.stl)|*.stl;*.STL"), - std::make_pair("obj", "OBJ files (*.obj)|*.obj;*.OBJ"), - std::make_pair("amf", "AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML"), - std::make_pair("3mf", "3MF files (*.3mf)|*.3mf;*.3MF;"), - std::make_pair("prusa", "Prusa Control files (*.prusa)|*.prusa;*.PRUSA"), - std::make_pair("ini", "INI files *.ini|*.ini;*.INI"), - std::make_pair("gcode", "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC"), - std::make_pair("svg", "SVG files *.svg|*.svg;*.SVG") -}; - -const std::string MODEL_WILDCARD{ FILE_WILDCARDS.at("known") + std::string("|") + - FILE_WILDCARDS.at("stl") + std::string("|") + - FILE_WILDCARDS.at("obj") + std::string("|") + - FILE_WILDCARDS.at("amf") + std::string("|") + - FILE_WILDCARDS.at("3mf") + std::string("|") + - FILE_WILDCARDS.at("prusa") }; -struct PresetTab { - std::string name; - Tab* panel; - PrinterTechnology technology; -}; - - void disable_screensaver(); void enable_screensaver(); bool debugged(); void break_to_debugger(); -void set_show_print_info(bool show); -void set_show_manifold_warning_icon(bool show); -void set_objects_list_sizer(wxBoxSizer *objects_list_sizer); - AppConfig* get_app_config(); AppControllerPtr get_appctl(); void set_cli_appctl(); void set_gui_appctl(); -void open_model(wxWindow *parent, wxArrayString& input_files); - -wxWindow* get_right_panel(); - -Tab* get_tab(const std::string& name); -std::vector* get_preset_tabs(); - extern void add_menus(wxMenuBar *menu, int event_preferences_changed, int event_language_change); // Checks if configuration wizard needs to run, calls config_wizard if so. @@ -131,12 +70,8 @@ extern bool config_wizard_startup(bool app_config_exists); // The run_reason argument is actually ConfigWizard::RunReason, but int is used here because of Perl. extern void config_wizard(int run_reason); -TabIface* get_preset_tab_iface(char *name); - PreviewIface* create_preview_iface(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data); -// add it at the end of the tab panel. -// void add_created_tab(Tab* panel, int event_value_change, int event_presets_changed); // Change option value in config void change_opt_value(DynamicPrintConfig& config, const t_config_option_key& opt_key, const boost::any& value, int opt_index = 0); @@ -149,8 +84,6 @@ void warning_catcher(wxWindow* parent, const wxString& message); // to deliver a progress status message. void set_print_callback_event(Print *print, int id); -void show_info_sizer(const bool show); - // Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items. // Items are all initialized to the given value. // Items must be separated by '|', for example "Item1|Item2|Item3", and so on. @@ -167,19 +100,9 @@ wxString from_u8(const std::string &str); // Return std::string in UTF8 from wxString std::string into_u8(const wxString &str); -void set_model_events_from_perl(Model &model, - int event_object_selection_changed, - int event_object_settings_changed, - int event_remove_object, - int event_update_scene); -void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer); - // Callback to trigger a configuration update timer on the Plater. static PerlCallback g_on_request_update_callback; -ConfigOptionsGroup* get_optgroup(size_t i); -std::vector >& get_optgroups(); - void add_export_option(wxFileDialog* dlg, const std::string& format); int get_export_option(wxFileDialog* dlg); @@ -191,9 +114,6 @@ void save_window_size(wxTopLevelWindow *window, const std::string &name); // Restore the above void restore_window_size(wxTopLevelWindow *window, const std::string &name); -// Update buttons view according to enable/disable -void enable_action_buttons(bool enable); - // Display an About dialog extern void about(); // Ask the destop to open the datadir using the default file explorer. diff --git a/src/slic3r/GUI/GUI_App.cpp b/src/slic3r/GUI/GUI_App.cpp index 8fdef00cd..1862bab8a 100644 --- a/src/slic3r/GUI/GUI_App.cpp +++ b/src/slic3r/GUI/GUI_App.cpp @@ -1,4 +1,5 @@ #include "GUI_App.hpp" +#include "GUI_ObjectList.hpp" #include "GUI_ObjectManipulation.hpp" #include @@ -18,6 +19,7 @@ #include "AppConfig.hpp" #include "PresetBundle.hpp" #include "3DScene.hpp" +#include "Model.hpp" #include "../Utils/PresetUpdater.hpp" #include "ConfigWizard_private.hpp" @@ -92,6 +94,8 @@ bool GUI_App::OnInit() // wxImage::FindHandlerType(wxBITMAP_TYPE_PNG) || wxImage::AddHandler(new wxPNGHandler()); mainframe = new MainFrame(no_plater, false); + sidebar().obj_list()->init_objects(); // propagate model objects to object list + update_mode(); SetTopWindow(mainframe); // This makes CallAfter() work @@ -220,6 +224,8 @@ void GUI_App::recreate_GUI() auto topwindow = GetTopWindow(); mainframe = new MainFrame(no_plater,false); + sidebar().obj_list()->init_objects(); // propagate model objects to object list + update_mode(); if (topwindow) { SetTopWindow(mainframe); @@ -493,18 +499,18 @@ ConfigMenuIDs GUI_App::get_view_mode() // Update view mode according to selected menu void GUI_App::update_mode() { - wxWindowUpdateLocker noUpdates(/*g_right_panel->GetParent()*/mainframe); + wxWindowUpdateLocker noUpdates(mainframe->m_plater); ConfigMenuIDs mode = wxGetApp().get_view_mode(); -// g_object_list_sizer->Show(mode == ConfigMenuModeExpert); - show_info_sizer(mode == ConfigMenuModeExpert); -// show_buttons(mode == ConfigMenuModeExpert); -// show_object_name(mode == ConfigMenuModeSimple); - show_manipulation_sizer(mode == ConfigMenuModeSimple); + obj_list()->get_sizer()->Show(mode == ConfigMenuModeExpert); + sidebar().show_info_sizers(mode == ConfigMenuModeExpert); + sidebar().show_buttons(mode == ConfigMenuModeExpert); + obj_manipul()->show_object_name(mode == ConfigMenuModeSimple); + obj_list()->update_manipulation_sizer(mode == ConfigMenuModeSimple); - /*g_right_panel*/mainframe->m_plater->Layout(); - /*g_right_panel->GetParent()*/mainframe->Layout(); + sidebar().Layout(); + mainframe->m_plater->Layout(); } void GUI_App::add_config_menu(wxMenuBar *menu) @@ -658,25 +664,21 @@ ObjectManipulation* GUI_App::obj_manipul() return sidebar().obj_manipul(); } +ObjectList* GUI_App::obj_list() +{ + return sidebar().obj_list(); +} + +ModelObjectPtrs* GUI_App::model_objects() +{ + return &mainframe->m_plater->model().objects; +} + wxNotebook* GUI_App::tab_panel() const { return mainframe->m_tabpanel; } -// std::vector preset_tabs = { -// { "print", nullptr, ptFFF }, -// { "filament", nullptr, ptFFF }, -// { "sla_material", nullptr, ptSLA } -// }; -// -// Tab* GUI_App::get_tab(const std::string& name) -// { -// std::vector::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(), -// [name](PresetTab& tab){ return name == tab.name; }); -// return it != preset_tabs.end() ? it->panel : nullptr; -// } - - // static method accepting a wxWindow object as first parameter // void warning_catcher{ // my($self, $message_dialog) = @_; diff --git a/src/slic3r/GUI/GUI_App.hpp b/src/slic3r/GUI/GUI_App.hpp index 022fd0d37..e5ea77a38 100644 --- a/src/slic3r/GUI/GUI_App.hpp +++ b/src/slic3r/GUI/GUI_App.hpp @@ -2,11 +2,8 @@ #define slic3r_GUI_App_hpp_ #include -// #include #include "PrintConfig.hpp" #include "MainFrame.hpp" -// #include "../../libslic3r/Utils.hpp" -// #include "GUI.hpp" #include #include @@ -24,9 +21,31 @@ namespace Slic3r { class AppConfig; class PresetBundle; class PresetUpdater; +class ModelObject; namespace GUI { +// Map from an file_type name to full file wildcard name. +const std::map FILE_WILDCARDS{ + std::make_pair("known", "Known files (*.stl, *.obj, *.amf, *.xml, *.prusa)|*.stl;*.STL;*.obj;*.OBJ;*.amf;*.AMF;*.xml;*.XML;*.prusa;*.PRUSA"), + std::make_pair("stl", "STL files (*.stl)|*.stl;*.STL"), + std::make_pair("obj", "OBJ files (*.obj)|*.obj;*.OBJ"), + std::make_pair("amf", "AMF files (*.amf)|*.zip.amf;*.amf;*.AMF;*.xml;*.XML"), + std::make_pair("3mf", "3MF files (*.3mf)|*.3mf;*.3MF;"), + std::make_pair("prusa", "Prusa Control files (*.prusa)|*.prusa;*.PRUSA"), + std::make_pair("ini", "INI files *.ini|*.ini;*.INI"), + std::make_pair("gcode", "G-code files (*.gcode, *.gco, *.g, *.ngc)|*.gcode;*.GCODE;*.gco;*.GCO;*.g;*.G;*.ngc;*.NGC"), + std::make_pair("svg", "SVG files *.svg|*.svg;*.SVG") +}; + +const std::string MODEL_WILDCARD{ FILE_WILDCARDS.at("known") + std::string("|") + + FILE_WILDCARDS.at("stl") + std::string("|") + + FILE_WILDCARDS.at("obj") + std::string("|") + + FILE_WILDCARDS.at("amf") + std::string("|") + + FILE_WILDCARDS.at("3mf") + std::string("|") + + FILE_WILDCARDS.at("prusa") }; + + enum ConfigMenuIDs { ConfigMenuWizard, ConfigMenuSnapshots, @@ -61,8 +80,6 @@ class GUI_App : public wxApp wxFont m_small_font; wxFont m_bold_font; - // #ys_FIXME -// std::vector g_tabs_list; wxLocale* m_wxLocale{ nullptr }; public: @@ -120,17 +137,12 @@ public: bool check_unsaved_changes(); bool checked_tab(Tab* tab); void delete_tab_from_list(Tab* tab); - // Tab* get_tab(const std::string& name); void load_current_presets(); - Sidebar& sidebar(); ObjectManipulation* obj_manipul(); -// ObjectList& get_obj_list(); - - // Functions for updating of the object manipulation values - void update_position_values(); - void update_position_values(const Vec3d& position); + ObjectList* obj_list(); + std::vector *model_objects(); AppConfig* app_config{ nullptr }; PresetBundle* preset_bundle{ nullptr }; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index f44c5be8e..e9fc6a3d0 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1,25 +1,17 @@ #include "GUI_ObjectList.hpp" +#include "GUI_ObjectManipulation.hpp" #include "GUI_App.hpp" #include "OptionsGroup.hpp" #include "PresetBundle.hpp" #include "Tab.hpp" #include "wxExtensions.hpp" +#include "Model.hpp" +#include "LambdaObjectDialog.hpp" -// #include "Model.hpp" -// #include "LambdaObjectDialog.hpp" -// #include "../../libslic3r/Utils.hpp" -// -// #include -// #include #include -// #include "Geometry.hpp" #include "slic3r/Utils/FixModelByWin10.hpp" -// -// #include -// #include "3DScene.hpp" - namespace Slic3r { namespace GUI @@ -28,28 +20,41 @@ namespace GUI ObjectList::ObjectList(wxWindow* parent) : m_parent(parent) { -// wxBoxSizer* sizer; + // Fill CATEGORY_ICON + { + CATEGORY_ICON[L("Layers and Perimeters")] = wxBitmap(from_u8(var("layers.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Infill")] = wxBitmap(from_u8(var("infill.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Support material")] = wxBitmap(from_u8(var("building.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Speed")] = wxBitmap(from_u8(var("time.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Extruders")] = wxBitmap(from_u8(var("funnel.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Extrusion Width")] = wxBitmap(from_u8(var("funnel.png")), wxBITMAP_TYPE_PNG); +// CATEGORY_ICON[L("Skirt and brim")] = wxBitmap(from_u8(var("box.png")), wxBITMAP_TYPE_PNG); +// CATEGORY_ICON[L("Speed > Acceleration")] = wxBitmap(from_u8(var("time.png")), wxBITMAP_TYPE_PNG); + CATEGORY_ICON[L("Advanced")] = wxBitmap(from_u8(var("wand.png")), wxBITMAP_TYPE_PNG); + } + + init_icons(); + // create control create_objects_ctrl(); // describe control behavior - m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& event) { + m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxEvent& event) { object_ctrl_selection_changed(); #ifndef __WXMSW__ set_tooltip_for_item(get_mouse_position_in_control()); #endif //__WXMSW__ }); - m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [](wxDataViewEvent& event) { + m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [this](wxDataViewEvent& event) { object_ctrl_context_menu(); - // event.Skip(); }); - m_objects_ctrl->Bind(wxEVT_CHAR, [](wxKeyEvent& event) { object_ctrl_key_event(event); }); // doesn't work on OSX + m_objects_ctrl->Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { object_ctrl_key_event(event); }); // doesn't work on OSX #ifdef __WXMSW__ // Extruder value changed - m_objects_ctrl->Bind(wxEVT_CHOICE, [](wxCommandEvent& event) { update_extruder_in_config(event.GetString()); }); + m_objects_ctrl->Bind(wxEVT_CHOICE, [this](wxCommandEvent& event) { update_extruder_in_config(event.GetString()); }); m_objects_ctrl->GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) { set_tooltip_for_item(event.GetPosition()); @@ -57,12 +62,18 @@ ObjectList::ObjectList(wxWindow* parent) : }); #else // equivalent to wxEVT_CHOICE on __WXMSW__ - m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [](wxDataViewEvent& event) { object_ctrl_item_value_change(event); }); + m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [this](wxDataViewEvent& e) { object_ctrl_item_value_change(e); }); #endif //__WXMSW__ - m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, [](wxDataViewEvent& e) {on_begin_drag(e); }); - m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, [](wxDataViewEvent& e) {on_drop_possible(e); }); - m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_DROP, [](wxDataViewEvent& e) {on_drop(e); }); + m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, [this](wxDataViewEvent& e) {on_begin_drag(e); }); + m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, [this](wxDataViewEvent& e) {on_drop_possible(e); }); + m_objects_ctrl->Bind(wxEVT_DATAVIEW_ITEM_DROP, [this](wxDataViewEvent& e) {on_drop(e); }); +} + +ObjectList::~ObjectList() +{ + if (m_default_config) + delete m_default_config; } void ObjectList::create_objects_ctrl() @@ -97,12 +108,6 @@ void ObjectList::create_objects_ctrl() wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE); } -// ModelObjectPtrs& ObjectList::get_objects() -// { -// return wxGetApp().mainframe->m_plater->model().objects; -// } - - void ObjectList::set_tooltip_for_item(const wxPoint& pt) { wxDataViewItem item; @@ -112,39 +117,39 @@ void ObjectList::set_tooltip_for_item(const wxPoint& pt) if (col->GetTitle() == " ") m_objects_ctrl->GetMainWindow()->SetToolTip(_(L("Right button click the icon to change the object settings"))); -// else if (col->GetTitle() == _("Name") && -// m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) { -// int obj_idx = m_objects_model->GetIdByItem(item); -// auto& stats = (*m_objects)[obj_idx]->volumes[0]->mesh.stl.stats; -// int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed + -// stats.facets_added + stats.facets_reversed + stats.backwards_edges; -// -// wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors); -// -// std::map error_msg; -// error_msg[L("degenerate facets")] = stats.degenerate_facets; -// error_msg[L("edges fixed")] = stats.edges_fixed; -// error_msg[L("facets removed")] = stats.facets_removed; -// error_msg[L("facets added")] = stats.facets_added; -// error_msg[L("facets reversed")] = stats.facets_reversed; -// error_msg[L("backwards edges")] = stats.backwards_edges; -// -// for (auto error : error_msg) -// { -// if (error.second > 0) -// tooltip += wxString::Format(_("\t%d %s\n"), error.second, error.first); -// } -// // OR -// // tooltip += wxString::Format(_(L("%d degenerate facets, %d edges fixed, %d facets removed, " -// // "%d facets added, %d facets reversed, %d backwards edges")), -// // stats.degenerate_facets, stats.edges_fixed, stats.facets_removed, -// // stats.facets_added, stats.facets_reversed, stats.backwards_edges); -// -// if (is_windows10()) -// tooltip += _(L("Right button click the icon to fix STL through Netfabb")); -// -// m_objects_ctrl->GetMainWindow()->SetToolTip(tooltip); -// } + else if (col->GetTitle() == _("Name") && + m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) { + int obj_idx = m_objects_model->GetIdByItem(item); + auto& stats = (*m_objects)[obj_idx]->volumes[0]->mesh.stl.stats; + int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed + + stats.facets_added + stats.facets_reversed + stats.backwards_edges; + + wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors); + + std::map error_msg; + error_msg[L("degenerate facets")] = stats.degenerate_facets; + error_msg[L("edges fixed")] = stats.edges_fixed; + error_msg[L("facets removed")] = stats.facets_removed; + error_msg[L("facets added")] = stats.facets_added; + error_msg[L("facets reversed")] = stats.facets_reversed; + error_msg[L("backwards edges")] = stats.backwards_edges; + + for (auto error : error_msg) + { + if (error.second > 0) + tooltip += wxString::Format(_("\t%d %s\n"), error.second, error.first); + } +// OR +// tooltip += wxString::Format(_(L("%d degenerate facets, %d edges fixed, %d facets removed, " +// "%d facets added, %d facets reversed, %d backwards edges")), +// stats.degenerate_facets, stats.edges_fixed, stats.facets_removed, +// stats.facets_added, stats.facets_reversed, stats.backwards_edges); + + if (is_windows10()) + tooltip += _(L("Right button click the icon to fix STL through Netfabb")); + + m_objects_ctrl->GetMainWindow()->SetToolTip(tooltip); + } else m_objects_ctrl->GetMainWindow()->SetToolTip(""); // hide tooltip } @@ -182,7 +187,959 @@ void ObjectList::update_objects_list_extruder_column(int extruders_count) set_extruder_column_hidden(extruders_count <= 1); } +void ObjectList::set_extruder_column_hidden(bool hide) +{ + m_objects_ctrl->GetColumn(2)->SetHidden(hide); +} +void ObjectList::update_extruder_in_config(const wxString& selection) +{ + if (!m_config || selection.empty()) + return; + + int extruder = selection.size() > 1 ? 0 : atoi(selection.c_str()); + m_config->set_key_value("extruder", new ConfigOptionInt(extruder)); + +// #ys_FIXME_events + // call function to update the scene after extruder changing +} + +void ObjectList::init_icons(){ + m_icon_modifiermesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG); + m_icon_solidmesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG); + + // init icon for manifold warning + m_icon_manifold_warning = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); + + // init bitmap for "Split to sub-objects" context menu + m_bmp_split = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("split.png")), wxBITMAP_TYPE_PNG); + + // init bitmap for "Add Settings" context menu + m_bmp_cog = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("cog.png")), wxBITMAP_TYPE_PNG); +} + + +void ObjectList::object_ctrl_selection_changed() +{ + if (m_prevent_list_events) return; + + part_selection_changed(); + +// #ys_FIXME_events +// call function to update object selection on Plater +// using obj_idx and vol_idx values + int obj_idx, vol_idx = -1; + obj_idx = m_selected_object_id; + + const wxDataViewItem item = m_objects_ctrl->GetSelection(); + if (!item || m_objects_model->GetParent(item) == wxDataViewItem(0)) + vol_idx = -1; + else { + vol_idx = m_objects_model->GetVolumeIdByItem(item); + if (vol_idx == -2) // is settings item + vol_idx = m_objects_model->GetVolumeIdByItem(m_objects_model->GetParent(item)); + } + +#ifdef __WXOSX__ + update_extruder_in_config(m_selected_extruder); +#endif //__WXOSX__ +} + +void ObjectList::object_ctrl_context_menu() +{ + wxDataViewItem item; + wxDataViewColumn* col; + const wxPoint pt = get_mouse_position_in_control(); + m_objects_ctrl->HitTest(pt, item, col); + if (!item) +#ifdef __WXOSX__ // #ys_FIXME temporary workaround for OSX + // after Yosemite OS X version, HitTest return undefined item + item = m_objects_ctrl->GetSelection(); + if (item) + show_context_menu(); + else + printf("undefined item\n"); + return; +#else + return; +#endif // __WXOSX__ + const wxString title = col->GetTitle(); + + if (title == " ") + show_context_menu(); + + else if (title == _("Name") && pt.x >15 && + m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) + { + if (is_windows10()) + /*fix_through_netfabb()*/;// #ys_FIXME + } +#ifndef __WXMSW__ + m_objects_ctrl->GetMainWindow()->SetToolTip(""); // hide tooltip +#endif //__WXMSW__ +} + +void ObjectList::show_context_menu() +{ + const auto item = m_objects_ctrl->GetSelection(); + if (item) + { + if (m_objects_model->IsSettingsItem(item)) + return; + const auto menu = m_objects_model->GetParent(item) == wxDataViewItem(0) ? + create_add_part_popupmenu() : + create_part_settings_popupmenu(); + wxGetApp().tab_panel()->GetPage(0)->PopupMenu(menu); + } +} + + +void ObjectList::object_ctrl_key_event(wxKeyEvent& event) +{ + if (event.GetKeyCode() == WXK_TAB) + m_objects_ctrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); + else if (event.GetKeyCode() == WXK_DELETE +#ifdef __WXOSX__ + || event.GetKeyCode() == WXK_BACK +#endif //__WXOSX__ + ){ + printf("WXK_BACK\n"); + remove(); + } + else + event.Skip(); +} + +void ObjectList::object_ctrl_item_value_change(wxDataViewEvent& event) +{ + if (event.GetColumn() == 2) + { + wxVariant variant; + m_objects_model->GetValue(variant, event.GetItem(), 2); +#ifdef __WXOSX__ + m_selected_extruder = variant.GetString(); +#else // --> for Linux + update_extruder_in_config(variant.GetString()); +#endif //__WXOSX__ + } +} + +void ObjectList::on_begin_drag(wxDataViewEvent &event) +{ + wxDataViewItem item(event.GetItem()); + + // only allow drags for item, not containers + if (m_objects_model->GetParent(item) == wxDataViewItem(0) || m_objects_model->IsSettingsItem(item)) { + event.Veto(); + return; + } + + /* Under MSW or OSX, DnD moves an item to the place of another selected item + * But under GTK, DnD moves an item between another two items. + * And as a result - call EVT_CHANGE_SELECTION to unselect all items. + * To prevent such behavior use g_prevent_list_events + **/ + m_prevent_list_events = true;//it's needed for GTK + + wxTextDataObject *obj = new wxTextDataObject; + obj->SetText(wxString::Format("%d", m_objects_model->GetVolumeIdByItem(item))); + event.SetDataObject(obj); + event.SetDragFlags(/*wxDrag_AllowMove*/wxDrag_DefaultMove); // allows both copy and move; +} + +void ObjectList::on_drop_possible(wxDataViewEvent &event) +{ + wxDataViewItem item(event.GetItem()); + + // only allow drags for item or background, not containers + if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || + event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) + event.Veto(); +} + +void ObjectList::on_drop(wxDataViewEvent &event) +{ + wxDataViewItem item(event.GetItem()); + + // only allow drops for item, not containers + if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || + event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) { + event.Veto(); + return; + } + + wxTextDataObject obj; + obj.SetData(wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer()); + + int from_volume_id = std::stoi(obj.GetText().ToStdString()); + int to_volume_id = m_objects_model->GetVolumeIdByItem(item); + +#ifdef __WXGTK__ + /* Under GTK, DnD moves an item between another two items. + * And event.GetItem() return item, which is under "insertion line" + * So, if we move item down we should to decrease the to_volume_id value + **/ + if (to_volume_id > from_volume_id) to_volume_id--; +#endif // __WXGTK__ + + m_objects_ctrl->Select(m_objects_model->ReorganizeChildren(from_volume_id, to_volume_id, + m_objects_model->GetParent(item))); + + auto& volumes = (*m_objects)[m_selected_object_id]->volumes; + auto delta = to_volume_id < from_volume_id ? -1 : 1; + int cnt = 0; + for (int id = from_volume_id; cnt < abs(from_volume_id - to_volume_id); id += delta, cnt++) + std::swap(volumes[id], volumes[id + delta]); + + m_parts_changed = true; + parts_changed(m_selected_object_id); + + m_prevent_list_events = false; +} + + +// Context Menu + +std::vector get_options(const bool is_part) +{ + PrintRegionConfig reg_config; + auto options = reg_config.keys(); + if (!is_part) { + PrintObjectConfig obj_config; + std::vector obj_options = obj_config.keys(); + options.insert(options.end(), obj_options.begin(), obj_options.end()); + } + return options; +} + +// category -> vector ( option ; label ) +typedef std::map< std::string, std::vector< std::pair > > settings_menu_hierarchy; +void get_options_menu(settings_menu_hierarchy& settings_menu, bool is_part) +{ + auto options = get_options(is_part); + + auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 : + wxGetApp().preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values.size(); + + DynamicPrintConfig config; + for (auto& option : options) + { + auto const opt = config.def()->get(option); + auto category = opt->category; + if (category.empty() || + (category == "Extruders" && extruders_cnt == 1)) continue; + + std::pair option_label(option, opt->label); + std::vector< std::pair > new_category; + auto& cat_opt_label = settings_menu.find(category) == settings_menu.end() ? new_category : settings_menu.at(category); + cat_opt_label.push_back(option_label); + if (cat_opt_label.size() == 1) + settings_menu[category] = cat_opt_label; + } +} + +void ObjectList::get_settings_choice(wxMenu *menu, int id, bool is_part) +{ + const auto category_name = menu->GetLabel(id); + + wxArrayString names; + wxArrayInt selections; + + settings_menu_hierarchy settings_menu; + get_options_menu(settings_menu, is_part); + std::vector< std::pair > *settings_list = nullptr; + + auto opt_keys = m_config->keys(); + + for (auto& cat : settings_menu) + { + if (_(cat.first) == category_name) { + int sel = 0; + for (auto& pair : cat.second) { + names.Add(_(pair.second)); + if (find(opt_keys.begin(), opt_keys.end(), pair.first) != opt_keys.end()) + selections.Add(sel); + sel++; + } + settings_list = &cat.second; + break; + } + } + + if (!settings_list) + return; + + if (wxGetSelectedChoices(selections, _(L("Select showing settings")), category_name, names) == -1) + return; + + std::vector selected_options; + for (auto sel : selections) + selected_options.push_back((*settings_list)[sel].first); + + for (auto& setting : (*settings_list)) + { + auto& opt_key = setting.first; + if (find(opt_keys.begin(), opt_keys.end(), opt_key) != opt_keys.end() && + find(selected_options.begin(), selected_options.end(), opt_key) == selected_options.end()) + m_config->erase(opt_key); + + if (find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() && + find(selected_options.begin(), selected_options.end(), opt_key) != selected_options.end()) + m_config->set_key_value(opt_key, m_default_config->option(opt_key)->clone()); + } + + + // Add settings item for object + const auto item = m_objects_ctrl->GetSelection(); + if (item) { + const auto settings_item = m_objects_model->HasSettings(item); + m_objects_ctrl->Select(settings_item ? settings_item : + m_objects_model->AddSettingsChild(item)); +#ifndef __WXOSX__ + part_selection_changed(); +#endif //no __WXOSX__ + } + else + wxGetApp().obj_manipul()->update_settings_list(); +} + +void ObjectList::menu_item_add_generic(wxMenuItem* &menu, int id) { + auto sub_menu = new wxMenu; + + std::vector menu_items = { L("Box"), L("Cylinder"), L("Sphere"), L("Slab") }; + for (auto& item : menu_items) + sub_menu->Append(new wxMenuItem(sub_menu, ++id, _(item))); + +#ifndef __WXMSW__ + sub_menu->Bind(wxEVT_MENU, [sub_menu](wxEvent &event) { + load_lambda(sub_menu->GetLabel(event.GetId()).ToStdString()); + }); +#endif //no __WXMSW__ + + menu->SetSubMenu(sub_menu); +} + +wxMenuItem* ObjectList::menu_item_split(wxMenu* menu, int id) { + auto menu_item = new wxMenuItem(menu, id, _(L("Split to parts"))); + menu_item->SetBitmap(m_bmp_split); + return menu_item; +} + +wxMenuItem* ObjectList::menu_item_settings(wxMenu* menu, int id, const bool is_part) { + auto menu_item = new wxMenuItem(menu, id, _(L("Add settings"))); + menu_item->SetBitmap(m_bmp_cog); + + auto sub_menu = create_add_settings_popupmenu(is_part); + menu_item->SetSubMenu(sub_menu); + return menu_item; +} + +wxMenu* ObjectList::create_add_part_popupmenu() +{ + wxMenu *menu = new wxMenu; + std::vector menu_items = { L("Add part"), L("Add modifier"), L("Add generic") }; + + wxWindowID config_id_base = wxWindow::NewControlId(menu_items.size() + 4 + 2); + + int i = 0; + for (auto& item : menu_items) { + auto menu_item = new wxMenuItem(menu, config_id_base + i, _(item)); + menu_item->SetBitmap(i == 0 ? m_icon_solidmesh : m_icon_modifiermesh); + if (item == "Add generic") + menu_item_add_generic(menu_item, config_id_base + i); + menu->Append(menu_item); + i++; + } + + menu->AppendSeparator(); + auto menu_item = menu_item_split(menu, config_id_base + i + 4); + menu->Append(menu_item); + menu_item->Enable(is_splittable_object(false)); + + menu->AppendSeparator(); + // Append settings popupmenu + menu->Append(menu_item_settings(menu, config_id_base + i + 5, false)); + + menu->Bind(wxEVT_MENU, [config_id_base, menu, this](wxEvent &event){ + switch (event.GetId() - config_id_base) { + case 0: + load_subobject(); + break; + case 1: + load_subobject(true); + break; + case 2: + case 3: + case 4: + case 5: + case 6: +#ifdef __WXMSW__ + load_lambda(menu->GetLabel(event.GetId()).ToStdString()); +#endif // __WXMSW__ + break; + case 7: //3: + split(false); + break; + default: +#ifdef __WXMSW__ + get_settings_choice(menu, event.GetId(), false); +#endif // __WXMSW__ + break; + } + }); + + return menu; +} + +wxMenu* ObjectList::create_part_settings_popupmenu() +{ + wxMenu *menu = new wxMenu; + wxWindowID config_id_base = wxWindow::NewControlId(2); + + auto menu_item = menu_item_split(menu, config_id_base); + menu->Append(menu_item); + menu_item->Enable(is_splittable_object(true)); + + menu->AppendSeparator(); + // Append settings popupmenu + menu->Append(menu_item_settings(menu, config_id_base + 1, true)); + + menu->Bind(wxEVT_MENU, [config_id_base, menu, this](wxEvent &event){ + switch (event.GetId() - config_id_base) { + case 0: + split(true); + break; + default:{ + get_settings_choice(menu, event.GetId(), true); + break; } + } + }); + + return menu; +} + +wxMenu* ObjectList::create_add_settings_popupmenu(bool is_part) +{ + wxMenu *menu = new wxMenu; + + settings_menu_hierarchy settings_menu; + get_options_menu(settings_menu, is_part); + + for (auto cat : settings_menu) + { + auto menu_item = new wxMenuItem(menu, wxID_ANY, _(cat.first)); + menu_item->SetBitmap(CATEGORY_ICON.find(cat.first) == CATEGORY_ICON.end() ? + wxNullBitmap : CATEGORY_ICON.at(cat.first)); + menu->Append(menu_item); + } +#ifndef __WXMSW__ + menu->Bind(wxEVT_MENU, [menu, is_part](wxEvent &event) { + get_settings_choice(menu, event.GetId(), is_part); + }); +#endif //no __WXMSW__ + return menu; +} + + +// Load SubObjects (parts and modifiers) +void ObjectList::load_subobject(bool is_modifier /*= false*/, bool is_lambda/* = false*/) +{ + auto item = m_objects_ctrl->GetSelection(); + if (!item) + return; + int obj_idx = -1; + if (m_objects_model->GetParent(item) == wxDataViewItem(0)) + obj_idx = m_objects_model->GetIdByItem(item); + else + return; + + if (obj_idx < 0) return; + wxArrayString part_names; + if (is_lambda) + load_lambda((*m_objects)[obj_idx], part_names, is_modifier); + else + load_part((*m_objects)[obj_idx], part_names, is_modifier); + + parts_changed(obj_idx); + + for (int i = 0; i < part_names.size(); ++i) + m_objects_ctrl->Select(m_objects_model->AddChild(item, part_names.Item(i), + is_modifier ? m_icon_modifiermesh : m_icon_solidmesh)); +#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME + object_ctrl_selection_changed(); +#endif //no __WXOSX__//__WXMSW__ +} + +void ObjectList::load_part( ModelObject* model_object, + wxArrayString& part_names, + const bool is_modifier) +{ + wxWindow* parent = wxGetApp().tab_panel()->GetPage(0); + + wxArrayString input_files; + wxGetApp().open_model(parent, input_files); + for (int i = 0; i < input_files.size(); ++i) { + std::string input_file = input_files.Item(i).ToStdString(); + + Model model; + try { + model = Model::read_from_file(input_file); + } + catch (std::exception &e) { + auto msg = _(L("Error! ")) + input_file + " : " + e.what() + "."; + show_error(parent, msg); + exit(1); + } + + for (auto object : model.objects) { + Vec3d delta = Vec3d::Zero(); + if (model_object->origin_translation != Vec3d::Zero()) + { + object->center_around_origin(); + delta = model_object->origin_translation - object->origin_translation; + } + for (auto volume : object->volumes) { + auto new_volume = model_object->add_volume(*volume); + new_volume->set_type(is_modifier ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART); + boost::filesystem::path(input_file).filename().string(); + new_volume->name = boost::filesystem::path(input_file).filename().string(); + + part_names.Add(new_volume->name); + + if (delta != Vec3d::Zero()) + { + new_volume->mesh.translate((float)delta(0), (float)delta(1), (float)delta(2)); + new_volume->get_convex_hull().translate((float)delta(0), (float)delta(1), (float)delta(2)); + } + + // set a default extruder value, since user can't add it manually + new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); + + m_parts_changed = true; + } + } + } +} + +void ObjectList::load_lambda( ModelObject* model_object, + wxArrayString& part_names, + const bool is_modifier) +{ + auto dlg = new LambdaObjectDialog(m_objects_ctrl->GetMainWindow()); + if (dlg->ShowModal() == wxID_CANCEL) { + return; + } + + std::string name = "lambda-"; + TriangleMesh mesh; + + auto params = dlg->ObjectParameters(); + switch (params.type) + { + case LambdaTypeBox:{ + mesh = make_cube(params.dim[0], params.dim[1], params.dim[2]); + name += "Box"; + break; } + case LambdaTypeCylinder:{ + mesh = make_cylinder(params.cyl_r, params.cyl_h); + name += "Cylinder"; + break; } + case LambdaTypeSphere:{ + mesh = make_sphere(params.sph_rho); + name += "Sphere"; + break; } + case LambdaTypeSlab:{ + const auto& size = model_object->bounding_box().size(); + mesh = make_cube(size(0)*1.5, size(1)*1.5, params.slab_h); + // box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z + mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, params.slab_z); + name += "Slab"; + break; } + default: + break; + } + mesh.repair(); + + auto new_volume = model_object->add_volume(mesh); + new_volume->set_type(is_modifier ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART); + + new_volume->name = name; + // set a default extruder value, since user can't add it manually + new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); + + part_names.Add(name); + + m_parts_changed = true; +} + +void ObjectList::load_lambda(const std::string& type_name) +{ + if (m_selected_object_id < 0) return; + + auto dlg = new LambdaObjectDialog(m_objects_ctrl->GetMainWindow(), type_name); + if (dlg->ShowModal() == wxID_CANCEL) + return; + + const std::string name = "lambda-" + type_name; + TriangleMesh mesh; + + const auto params = dlg->ObjectParameters(); + if (type_name == _("Box")) + mesh = make_cube(params.dim[0], params.dim[1], params.dim[2]); + else if (type_name == _("Cylinder")) + mesh = make_cylinder(params.cyl_r, params.cyl_h); + else if (type_name == _("Sphere")) + mesh = make_sphere(params.sph_rho); + else if (type_name == _("Slab")){ + const auto& size = (*m_objects)[m_selected_object_id]->bounding_box().size(); + mesh = make_cube(size(0)*1.5, size(1)*1.5, params.slab_h); + // box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z + mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, params.slab_z); + } + mesh.repair(); + + auto new_volume = (*m_objects)[m_selected_object_id]->add_volume(mesh); + new_volume->set_type(ModelVolume::PARAMETER_MODIFIER); + + new_volume->name = name; + // set a default extruder value, since user can't add it manually + new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); + + m_parts_changed = true; + parts_changed(m_selected_object_id); + + m_objects_ctrl->Select(m_objects_model->AddChild(m_objects_ctrl->GetSelection(), + name, m_icon_modifiermesh)); +#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME + object_ctrl_selection_changed(); +#endif //no __WXOSX__ //__WXMSW__ +} + + +// Delete subobject + +void ObjectList::del_subobject() +{ + auto item = m_objects_ctrl->GetSelection(); + if (!item) return; + + const auto volume_id = m_objects_model->GetVolumeIdByItem(item); + if (volume_id == -1) + return; + + if (volume_id == -2) + del_settings_from_config(); + else if (!del_subobject_from_object(volume_id)) + return; + + m_objects_ctrl->Select(m_objects_model->Delete(item)); + part_selection_changed(); +} + +void ObjectList::del_settings_from_config() +{ + auto opt_keys = m_config->keys(); + if (opt_keys.size() == 1 && opt_keys[0] == "extruder") + return; + int extruder = -1; + if (m_config->has("extruder")) + extruder = m_config->option("extruder")->value; + + m_config->clear(); + + if (extruder >= 0) + m_config->set_key_value("extruder", new ConfigOptionInt(extruder)); +} + + +bool ObjectList::del_subobject_from_object(const int volume_id) +{ + const auto volume = (*m_objects)[m_selected_object_id]->volumes[volume_id]; + + // if user is deleting the last solid part, throw error + int solid_cnt = 0; + for (auto vol : (*m_objects)[m_selected_object_id]->volumes) + if (vol->is_model_part()) + ++solid_cnt; + if (volume->is_model_part() && solid_cnt == 1) { + Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object."))); + return false; + } + + (*m_objects)[m_selected_object_id]->delete_volume(volume_id); + m_parts_changed = true; + + parts_changed(m_selected_object_id); + return true; +} + +void ObjectList::split(const bool split_part) +{ + const auto item = m_objects_ctrl->GetSelection(); + if (!item || m_selected_object_id < 0) + return; + ModelVolume* volume; + if (!get_volume_by_item(split_part, item, volume)) return; + DynamicPrintConfig& config = wxGetApp().preset_bundle->printers.get_edited_preset().config; + const auto nozzle_dmrs_cnt = config.option("nozzle_diameter")->values.size(); + if (volume->split(nozzle_dmrs_cnt) == 1) { + wxMessageBox(_(L("The selected object couldn't be split because it contains only one part."))); + return; + } + + auto model_object = (*m_objects)[m_selected_object_id]; + + if (split_part) { + auto parent = m_objects_model->GetParent(item); + m_objects_model->DeleteChildren(parent); + + for (auto id = 0; id < model_object->volumes.size(); id++) + m_objects_model->AddChild(parent, model_object->volumes[id]->name, + model_object->volumes[id]->is_modifier() ? m_icon_modifiermesh : m_icon_solidmesh, + model_object->volumes[id]->config.has("extruder") ? + model_object->volumes[id]->config.option("extruder")->value : 0, + false); + + m_objects_ctrl->Expand(parent); + } + else { + for (auto id = 0; id < model_object->volumes.size(); id++) + m_objects_model->AddChild(item, model_object->volumes[id]->name, + m_icon_solidmesh, + model_object->volumes[id]->config.has("extruder") ? + model_object->volumes[id]->config.option("extruder")->value : 0, + false); + m_objects_ctrl->Expand(item); + } + + m_parts_changed = true; + parts_changed(m_selected_object_id); +} + +bool ObjectList::get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume) +{ + if (!item || m_selected_object_id < 0) + return false; + const auto volume_id = m_objects_model->GetVolumeIdByItem(item); + if (volume_id < 0) { + if (split_part) return false; + volume = (*m_objects)[m_selected_object_id]->volumes[0]; + } + else + volume = (*m_objects)[m_selected_object_id]->volumes[volume_id]; + if (volume) + return true; + return false; +} + +bool ObjectList::is_splittable_object(const bool split_part) +{ + const wxDataViewItem item = m_objects_ctrl->GetSelection(); + if (!item) return false; + + wxDataViewItemArray children; + if (!split_part && m_objects_model->GetChildren(item, children) > 0) + return false; + + ModelVolume* volume; + if (!get_volume_by_item(split_part, item, volume) || !volume) + return false; + + TriangleMeshPtrs meshptrs = volume->mesh.split(); + bool splittable = meshptrs.size() > 1; + for (TriangleMesh* m : meshptrs) + { + delete m; + } + return splittable; +} + +void ObjectList::parts_changed(int obj_idx) +{ +// #ys_FIXME_events +// call function to update scene after some changes in ObjectList +// auto event_str = wxString::Format("%d %d %d", obj_idx, +// is_parts_changed() ? 1 : 0, +// is_part_settings_changed() ? 1 : 0); +} + +void ObjectList::part_selection_changed() +{ + auto item = m_objects_ctrl->GetSelection(); + int obj_idx = -1; + ConfigOptionsGroup* og = wxGetApp().obj_manipul()->get_og();// get_optgroup(ogFrequentlyObjectSettings); + m_config = nullptr; + wxString object_name = wxEmptyString; + if (item) + { + const bool is_settings_item = m_objects_model->IsSettingsItem(item); + bool is_part = false; + wxString og_name = wxEmptyString; + if (m_objects_model->GetParent(item) == wxDataViewItem(0)) { + obj_idx = m_objects_model->GetIdByItem(item); + og_name = _(L("Object manipulation")); + m_config = &(*m_objects)[obj_idx]->config; + } + else { + auto parent = m_objects_model->GetParent(item); + // Take ID of the parent object to "inform" perl-side which object have to be selected on the scene + obj_idx = m_objects_model->GetIdByItem(parent); + if (is_settings_item) { + if (m_objects_model->GetParent(parent) == wxDataViewItem(0)) { + og_name = _(L("Object Settings to modify")); + m_config = &(*m_objects)[obj_idx]->config; + } + else { + og_name = _(L("Part Settings to modify")); + is_part = true; + auto main_parent = m_objects_model->GetParent(parent); + obj_idx = m_objects_model->GetIdByItem(main_parent); + const auto volume_id = m_objects_model->GetVolumeIdByItem(parent); + m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config; + } + } + else { + og_name = _(L("Part manipulation")); + is_part = true; + const auto volume_id = m_objects_model->GetVolumeIdByItem(item); + m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config; + } + } + + og->set_name(" " + og_name + " "); + object_name = m_objects_model->GetName(item); + if (m_default_config) delete m_default_config; + m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(is_part)); + } + og->set_value("object_name", object_name); + + wxGetApp().obj_manipul()->update_settings_list(); + + m_selected_object_id = obj_idx; + + wxGetApp().obj_manipul()->update_values(); +} + +void ObjectList::update_manipulation_sizer(const bool is_simple_mode) +{ + auto item = m_objects_ctrl->GetSelection(); + if (!item || !is_simple_mode) + return; + + if (m_objects_model->IsSettingsItem(item)) { + m_objects_ctrl->Select(m_objects_model->GetParent(item)); + part_selection_changed(); + } +} + +void ObjectList::add_object_to_list(const std::string &name, ModelObject* model_object) +{ + wxString item_name = name; + auto item = m_objects_model->Add(item_name, model_object->instances.size()); + m_objects_ctrl->Select(item); + + // Add error icon if detected auto-repaire + auto stats = model_object->volumes[0]->mesh.stl.stats; + int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed + + stats.facets_added + stats.facets_reversed + stats.backwards_edges; + if (errors > 0) { + const PrusaDataViewBitmapText data(item_name, m_icon_manifold_warning); + wxVariant variant; + variant << data; + m_objects_model->SetValue(variant, item, 0); + } + + if (model_object->volumes.size() > 1) { + for (auto id = 0; id < model_object->volumes.size(); id++) + m_objects_model->AddChild(item, + model_object->volumes[id]->name, + m_icon_solidmesh, + model_object->volumes[id]->config.option("extruder")->value, + false); + m_objects_ctrl->Expand(item); + } + +#ifndef __WXOSX__ + object_ctrl_selection_changed(); +#endif //__WXMSW__ +} + +void ObjectList::delete_object_from_list() +{ + auto item = m_objects_ctrl->GetSelection(); + if (!item || m_objects_model->GetParent(item) != wxDataViewItem(0)) + return; + // m_objects_ctrl->Select(m_objects_model->Delete(item)); + m_objects_model->Delete(item); + + part_selection_changed(); +} + +void ObjectList::delete_all_objects_from_list() +{ + m_objects_model->DeleteAll(); + part_selection_changed(); +} + +void ObjectList::set_object_count(int idx, int count) +{ + m_objects_model->SetValue(wxString::Format("%d", count), idx, 1); + m_objects_ctrl->Refresh(); +} + +void ObjectList::unselect_objects() +{ + if (!m_objects_ctrl->GetSelection()) + return; + + m_prevent_list_events = true; + m_objects_ctrl->UnselectAll(); + part_selection_changed(); + m_prevent_list_events = false; +} + +void ObjectList::select_current_object(int idx) +{ + m_prevent_list_events = true; + m_objects_ctrl->UnselectAll(); + if (idx >= 0) + m_objects_ctrl->Select(m_objects_model->GetItemById(idx)); + part_selection_changed(); + m_prevent_list_events = false; +} + +void ObjectList::select_current_volume(int idx, int vol_idx) +{ + if (vol_idx < 0) { + select_current_object(idx); + return; + } + m_prevent_list_events = true; + m_objects_ctrl->UnselectAll(); + if (idx >= 0) + m_objects_ctrl->Select(m_objects_model->GetItemByVolumeId(idx, vol_idx)); + part_selection_changed(); + m_prevent_list_events = false; +} + +void ObjectList::remove() +{ + auto item = m_objects_ctrl->GetSelection(); + if (!item) + return; + + if (m_objects_model->GetParent(item) == wxDataViewItem(0)) { +// #ys_FIXME_events +// call function to remove object from model and to update scene + } + else + del_subobject(); +} + +void ObjectList::init_objects() +{ + m_objects = wxGetApp().model_objects(); +} } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 77530a590..a2702228d 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -3,23 +3,29 @@ #include #include +#include class wxBoxSizer; class wxDataViewCtrl; class wxDataViewColumn; +class wxDataViewEvent; +class wxDataViewItem; class PrusaObjectDataViewModel; namespace Slic3r { -namespace GUI { - class ConfigOptionsGroup; +class DynamicPrintConfig; +class ModelObject; +class ModelVolume; + +namespace GUI { class ObjectList { - wxBoxSizer *m_sizer {nullptr}; - wxDataViewCtrl *m_objects_ctrl{ nullptr }; - PrusaObjectDataViewModel *m_objects_model{ nullptr }; - wxWindow *m_parent{ nullptr }; + wxBoxSizer *m_sizer {nullptr}; + wxWindow *m_parent{ nullptr }; + + DynamicPrintConfig *m_default_config {nullptr}; wxBitmap m_icon_modifiermesh; wxBitmap m_icon_solidmesh; @@ -28,20 +34,99 @@ class ObjectList wxBitmap m_bmp_split; int m_selected_object_id = -1; + bool m_prevent_list_events = false; // We use this flag to avoid circular event handling Select() + // happens to fire a wxEVT_LIST_ITEM_SELECTED on OSX, whose event handler + // calls this method again and again and again +#ifdef __WXOSX__ + wxString m_selected_extruder = ""; +#endif //__WXOSX__ + bool m_parts_changed = false; + bool m_part_settings_changed = false; public: ObjectList(wxWindow* parent); - ~ObjectList() {} + ~ObjectList(); + + + std::map CATEGORY_ICON; + + wxDataViewCtrl *m_objects_ctrl{ nullptr }; + PrusaObjectDataViewModel *m_objects_model{ nullptr }; + DynamicPrintConfig *m_config {nullptr}; + + std::vector *m_objects{ nullptr }; + void create_objects_ctrl(); wxDataViewColumn* create_objects_list_extruder_column(int extruders_count); void update_objects_list_extruder_column(int extruders_count); + // show/hide "Extruder" column for Objects List + void set_extruder_column_hidden(bool hide); + // update extruder in current config + void update_extruder_in_config(const wxString& selection); + + void init_icons(); void set_tooltip_for_item(const wxPoint& pt); + void object_ctrl_selection_changed(); + void object_ctrl_context_menu(); + void show_context_menu(); + void object_ctrl_key_event(wxKeyEvent& event); + void object_ctrl_item_value_change(wxDataViewEvent& event); + + void on_begin_drag(wxDataViewEvent &event); + void on_drop_possible(wxDataViewEvent &event); + void on_drop(wxDataViewEvent &event); + + void get_settings_choice(wxMenu *menu, int id, bool is_part); + void menu_item_add_generic(wxMenuItem* &menu, int id); + wxMenuItem* menu_item_split(wxMenu* menu, int id); + wxMenuItem* menu_item_settings(wxMenu* menu, int id, const bool is_part); + wxMenu* create_add_part_popupmenu(); + wxMenu* create_part_settings_popupmenu(); + wxMenu* create_add_settings_popupmenu(bool is_part); + + void load_subobject(bool is_modifier = false, bool is_lambda = false); + void load_part(ModelObject* model_object, wxArrayString& part_names, const bool is_modifier); + void load_lambda(ModelObject* model_object, wxArrayString& part_names, const bool is_modifier); + void load_lambda(const std::string& type_name); + void del_subobject(); + void del_settings_from_config(); + bool del_subobject_from_object(const int volume_id); + void split(const bool split_part); + bool get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume); + bool is_splittable_object(const bool split_part); + wxPoint get_mouse_position_in_control(); wxBoxSizer* get_sizer(){return m_sizer;} - int get_sel_obj_id() { return m_selected_object_id; } + int get_sel_obj_id() const { return m_selected_object_id; } + bool is_parts_changed() const { return m_parts_changed; } + bool is_part_settings_changed() const{ return m_part_settings_changed; } + + void parts_changed(int obj_idx); + void part_selection_changed(); + + void update_manipulation_sizer(const bool is_simple_mode); + + // Add object to the list + void add_object_to_list(const std::string &name, ModelObject* model_object); + // Delete object from the list + void delete_object_from_list(); + // Delete all objects from the list + void delete_all_objects_from_list(); + // Set count of object on c++ side + void set_object_count(int idx, int count); + // Unselect all objects in the list on c++ side + void unselect_objects(); + // Select current object in the list on c++ side + void select_current_object(int idx); + // Select current volume in the list on c++ side + void select_current_volume(int idx, int vol_idx); + // Remove objects/sub-object from the list + void remove(); + + void init_objects(); }; diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index 86e657d8e..2858cb106 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -1,7 +1,9 @@ #include "GUI_ObjectManipulation.hpp" +#include "GUI_ObjectList.hpp" #include "OptionsGroup.hpp" #include "wxExtensions.hpp" +#include "PresetBundle.hpp" #include "Model.hpp" #include "Geometry.hpp" @@ -36,7 +38,7 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): std::vector axes{ "x", "y", "z" }; for (auto axis : axes) { std::string key = "scale_" + axis; - get_optgroup(ogFrequentlyObjectSettings)->set_side_text(key, selection); + m_og->set_side_text(key, selection); } m_is_percent_scale = selection == _("%"); @@ -80,7 +82,9 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): auto btn = new PrusaLockButton(parent, wxID_ANY); btn->Bind(wxEVT_BUTTON, [btn](wxCommandEvent &event){ event.Skip(); - wxTheApp->CallAfter([btn]() { set_uniform_scaling(btn->IsLocked()); }); + wxTheApp->CallAfter([btn]() { + wxGetApp().obj_manipul()->set_uniform_scaling(btn->IsLocked()); + }); }); return btn; }; @@ -136,8 +140,8 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent): def.default_value = new ConfigOptionBool{ false }; m_og->append_single_option_line(Option(def, "place_on_bed")); - m_extra_settings_sizer = new wxBoxSizer(wxVERTICAL); - m_og->sizer->Add(m_extra_settings_sizer, 1, wxEXPAND | wxLEFT, 5); + m_settings_list_sizer = new wxBoxSizer(wxVERTICAL); + m_og->sizer->Add(m_settings_list_sizer, 1, wxEXPAND | wxLEFT, 5); m_og->disable(); } @@ -147,6 +151,117 @@ int ObjectManipulation::ol_selection() return wxGetApp().sidebar().get_ol_selection(); } +void ObjectManipulation::update_settings_list() +{ +#ifdef __WXGTK__ + auto parent = m_og->get_parent(); +#else + auto parent = m_og->parent(); +#endif /* __WXGTK__ */ + +// There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/Slic3r/issues/898 and https://github.com/prusa3d/Slic3r/issues/952. +// The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason, +// we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely. +#ifdef __linux__ + std::unique_ptr no_updates(new wxWindowUpdateLocker(parent)); +#else + wxWindowUpdateLocker noUpdates(parent); +#endif + + m_settings_list_sizer->Clear(true); + bool show_manipulations = true; + + auto objects_ctrl = wxGetApp().obj_list()->m_objects_ctrl; + auto objects_model = wxGetApp().obj_list()->m_objects_model; + auto config = wxGetApp().obj_list()->m_config; + + const auto item = objects_ctrl->GetSelection(); + if (config && objects_model->IsSettingsItem(item)) + { + auto extra_column = [config](wxWindow* parent, const Line& line) + { + auto opt_key = (line.get_options())[0].opt_id; //we assume that we have one option per line + + auto btn = new wxBitmapButton(parent, wxID_ANY, wxBitmap(from_u8(var("colorchange_delete_on.png")), wxBITMAP_TYPE_PNG), + wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); +#ifdef __WXMSW__ + btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); +#endif // __WXMSW__ + btn->Bind(wxEVT_BUTTON, [opt_key, config](wxEvent &event){ + config->erase(opt_key); + wxTheApp->CallAfter([]() { wxGetApp().obj_manipul()->update_settings_list(); }); + }); + return btn; + }; + + std::map> cat_options; + auto opt_keys = config->keys(); + m_og_settings.resize(0); + std::vector categories; + if (!(opt_keys.size() == 1 && opt_keys[0] == "extruder"))// return; + { + auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 : + wxGetApp().preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values.size(); + + for (auto& opt_key : opt_keys) { + auto category = config->def()->get(opt_key)->category; + if (category.empty() || + (category == "Extruders" && extruders_cnt == 1)) continue; + + std::vector< std::string > new_category; + + auto& cat_opt = cat_options.find(category) == cat_options.end() ? new_category : cat_options.at(category); + cat_opt.push_back(opt_key); + if (cat_opt.size() == 1) + cat_options[category] = cat_opt; + } + + for (auto& cat : cat_options) { + if (cat.second.size() == 1 && cat.second[0] == "extruder") + continue; + + auto optgroup = std::make_shared(parent, cat.first, config, false, ogDEFAULT, extra_column); + optgroup->label_width = 150; + optgroup->sidetext_width = 70; + + for (auto& opt : cat.second) + { + if (opt == "extruder") + continue; + Option option = optgroup->get_option(opt); + option.opt.width = 70; + optgroup->append_single_option_line(option); + } + optgroup->reload_config(); + m_settings_list_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0); + m_og_settings.push_back(optgroup); + + categories.push_back(cat.first); + } + } + + if (m_og_settings.empty()) { + objects_ctrl->Select(objects_model->Delete(item)); + wxGetApp().obj_list()->part_selection_changed(); + } + else { + if (!categories.empty()) + objects_model->UpdateSettingsDigest(item, categories); + show_manipulations = false; + } + } + + show_manipulation_og(show_manipulations); + wxGetApp().sidebar().show_info_sizers(show_manipulations && item && objects_model->GetParent(item) == wxDataViewItem(0)); + +#ifdef __linux__ + no_updates.reset(nullptr); +#endif + + parent->Layout(); + /*wxGetApp().sidebar().*/parent->GetParent()->Layout(); +} + void ObjectManipulation::update_values() { int selection = ol_selection(); @@ -298,7 +413,21 @@ void ObjectManipulation::update_rotation_value(const Vec3d& rotation) } #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM +void ObjectManipulation::show_object_name(bool show) +{ + wxGridSizer* grid_sizer = m_og->get_grid_sizer(); + grid_sizer->Show(static_cast(0), show); + grid_sizer->Show(static_cast(1), show); +} +void ObjectManipulation::show_manipulation_og(const bool show) +{ + wxGridSizer* grid_sizer = m_og->get_grid_sizer(); + if (show == grid_sizer->IsShown(2)) + return; + for (size_t id = 2; id < 12; id++) + grid_sizer->Show(id, show); +} } //namespace GUI } //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.hpp b/src/slic3r/GUI/GUI_ObjectManipulation.hpp index feeaeb3ab..19683362f 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.hpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.hpp @@ -22,7 +22,8 @@ public: OG_Settings(wxWindow* parent, const bool staticbox); ~OG_Settings() {} - wxSizer* get_sizer(); + wxSizer* get_sizer(); + ConfigOptionsGroup* get_og() { return m_og.get(); } }; @@ -30,13 +31,18 @@ class ObjectManipulation : public OG_Settings { bool m_is_percent_scale = false; // true -> percentage scale unit // false -> uniform scale unit - wxBoxSizer* m_extra_settings_sizer{ nullptr }; // sizer for extra Object/Part's settings + bool m_is_uniform_scale = false; // It indicates if scale is uniform + // sizer for extra Object/Part's settings + wxBoxSizer* m_settings_list_sizer{ nullptr }; + // option groups for settings + std::vector > m_og_settings; public: ObjectManipulation(wxWindow* parent); ~ObjectManipulation() {} int ol_selection(); + void update_settings_list(); void update_values(); // update position values displacements or "gizmos" @@ -57,6 +63,10 @@ public: void update_rotation_value(const Vec3d& rotation); #endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM + void set_uniform_scaling(const bool uniform_scale) { m_is_uniform_scale = uniform_scale; } + + void show_object_name(bool show); + void show_manipulation_og(const bool show); }; }} diff --git a/src/slic3r/GUI/GUI_ObjectParts.cpp b/src/slic3r/GUI/GUI_ObjectParts.cpp deleted file mode 100644 index f578f6466..000000000 --- a/src/slic3r/GUI/GUI_ObjectParts.cpp +++ /dev/null @@ -1,1274 +0,0 @@ -#include "GUI.hpp" -#include "OptionsGroup.hpp" -#include "PresetBundle.hpp" -#include "GUI_ObjectParts.hpp" -#include "Model.hpp" -#include "wxExtensions.hpp" -#include "LambdaObjectDialog.hpp" -#include "../../libslic3r/Utils.hpp" - -#include -#include -#include -#include "Geometry.hpp" -#include "slic3r/Utils/FixModelByWin10.hpp" - -#include -#include "3DScene.hpp" -#include "GUI_App.hpp" - -namespace Slic3r -{ -namespace GUI -{ -wxDataViewCtrl *m_objects_ctrl = nullptr; -PrusaObjectDataViewModel *m_objects_model = nullptr; -PrusaDoubleSlider *m_slider = nullptr; -wxGLCanvas *m_preview_canvas = nullptr; - -wxBitmap m_icon_modifiermesh; -wxBitmap m_icon_solidmesh; -wxBitmap m_icon_manifold_warning; -wxBitmap m_bmp_cog; -wxBitmap m_bmp_split; - -int m_selected_object_id = -1; - -bool g_prevent_list_events = false; // We use this flag to avoid circular event handling Select() - // happens to fire a wxEVT_LIST_ITEM_SELECTED on OSX, whose event handler - // calls this method again and again and again -// bool g_is_percent_scale = false; // It indicates if scale unit is percentage -bool g_is_uniform_scale = false; // It indicates if scale is uniform -ModelObjectPtrs* m_objects; -std::shared_ptr m_config; -std::shared_ptr m_default_config; -wxBoxSizer* m_option_sizer = nullptr; - -// option groups for settings -std::vector > m_og_settings; - -int m_event_object_selection_changed = 0; -int m_event_object_settings_changed = 0; -int m_event_remove_object = 0; -int m_event_update_scene = 0; - -bool m_parts_changed = false; -bool m_part_settings_changed = false; - -#ifdef __WXOSX__ - wxString g_selected_extruder = ""; -#endif //__WXOSX__ - -inline t_category_icon& get_category_icon() { - static t_category_icon CATEGORY_ICON; - if (CATEGORY_ICON.empty()){ - CATEGORY_ICON[L("Layers and Perimeters")] = wxBitmap(from_u8(Slic3r::var("layers.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Infill")] = wxBitmap(from_u8(Slic3r::var("infill.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Support material")] = wxBitmap(from_u8(Slic3r::var("building.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Speed")] = wxBitmap(from_u8(Slic3r::var("time.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Extruders")] = wxBitmap(from_u8(Slic3r::var("funnel.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Extrusion Width")] = wxBitmap(from_u8(Slic3r::var("funnel.png")), wxBITMAP_TYPE_PNG); -// CATEGORY_ICON[L("Skirt and brim")] = wxBitmap(from_u8(Slic3r::var("box.png")), wxBITMAP_TYPE_PNG); -// CATEGORY_ICON[L("Speed > Acceleration")] = wxBitmap(from_u8(Slic3r::var("time.png")), wxBITMAP_TYPE_PNG); - CATEGORY_ICON[L("Advanced")] = wxBitmap(from_u8(Slic3r::var("wand.png")), wxBITMAP_TYPE_PNG); - } - return CATEGORY_ICON; -} - -std::vector get_options(const bool is_part) -{ - PrintRegionConfig reg_config; - auto options = reg_config.keys(); - if (!is_part) { - PrintObjectConfig obj_config; - std::vector obj_options = obj_config.keys(); - options.insert(options.end(), obj_options.begin(), obj_options.end()); - } - return options; -} - -// category -> vector ( option ; label ) -typedef std::map< std::string, std::vector< std::pair > > settings_menu_hierarchy; -void get_options_menu(settings_menu_hierarchy& settings_menu, bool is_part) -{ - auto options = get_options(is_part); - - auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 : - wxGetApp().preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values.size(); - - DynamicPrintConfig config; - for (auto& option : options) - { - auto const opt = config.def()->get(option); - auto category = opt->category; - if (category.empty() || - (category == "Extruders" && extruders_cnt == 1)) continue; - - std::pair option_label(option, opt->label); - std::vector< std::pair > new_category; - auto& cat_opt_label = settings_menu.find(category) == settings_menu.end() ? new_category : settings_menu.at(category); - cat_opt_label.push_back(option_label); - if (cat_opt_label.size() == 1) - settings_menu[category] = cat_opt_label; - } -} - -void set_event_object_selection_changed(const int& event){ - m_event_object_selection_changed = event; -} -void set_event_object_settings_changed(const int& event){ - m_event_object_settings_changed = event; -} -void set_event_remove_object(const int& event){ - m_event_remove_object = event; -} -void set_event_update_scene(const int& event){ - m_event_update_scene = event; -} - -void set_objects_from_model(Model &model) { - m_objects = &(model.objects); -} - -void init_mesh_icons(){ - m_icon_modifiermesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG); - m_icon_solidmesh = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG); - - // init icon for manifold warning - m_icon_manifold_warning = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG); - - // init bitmap for "Split to sub-objects" context menu - m_bmp_split = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("split.png")), wxBITMAP_TYPE_PNG); - - // init bitmap for "Add Settings" context menu - m_bmp_cog = wxBitmap(Slic3r::GUI::from_u8(Slic3r::var("cog.png")), wxBITMAP_TYPE_PNG); -} - -bool is_parts_changed(){return m_parts_changed;} -bool is_part_settings_changed(){ return m_part_settings_changed; } - -void delete_object_from_list() -{ - auto item = m_objects_ctrl->GetSelection(); - if (!item || m_objects_model->GetParent(item) != wxDataViewItem(0)) - return; -// m_objects_ctrl->Select(m_objects_model->Delete(item)); - m_objects_model->Delete(item); - - part_selection_changed(); -} - -void delete_all_objects_from_list() -{ - m_objects_model->DeleteAll(); - part_selection_changed(); -} - -void set_object_count(int idx, int count) -{ - m_objects_model->SetValue(wxString::Format("%d", count), idx, 1); - m_objects_ctrl->Refresh(); -} - -void unselect_objects() -{ - if (!m_objects_ctrl->GetSelection()) - return; - - g_prevent_list_events = true; - m_objects_ctrl->UnselectAll(); - part_selection_changed(); - g_prevent_list_events = false; -} - -void select_current_object(int idx) -{ - g_prevent_list_events = true; - m_objects_ctrl->UnselectAll(); - if (idx>=0) - m_objects_ctrl->Select(m_objects_model->GetItemById(idx)); - part_selection_changed(); - g_prevent_list_events = false; -} - -void select_current_volume(int idx, int vol_idx) -{ - if (vol_idx < 0) { - select_current_object(idx); - return; - } - g_prevent_list_events = true; - m_objects_ctrl->UnselectAll(); - if (idx >= 0) - m_objects_ctrl->Select(m_objects_model->GetItemByVolumeId(idx, vol_idx)); - part_selection_changed(); - g_prevent_list_events = false; -} - -void remove() -{ - auto item = m_objects_ctrl->GetSelection(); - if (!item) - return; - - if (m_objects_model->GetParent(item) == wxDataViewItem(0)) { - if (m_event_remove_object > 0) { - wxCommandEvent event(m_event_remove_object); -// get_main_frame()->ProcessWindowEvent(event); // #ys_FIXME - } - } - else - on_btn_del(); -} - -void object_ctrl_selection_changed() -{ - if (g_prevent_list_events) return; - - part_selection_changed(); - - if (m_event_object_selection_changed > 0) { - wxCommandEvent event(m_event_object_selection_changed); - event.SetId(m_selected_object_id); // set $obj_idx - const wxDataViewItem item = m_objects_ctrl->GetSelection(); - if (!item || m_objects_model->GetParent(item) == wxDataViewItem(0)) - event.SetInt(-1); // set $vol_idx - else { - const int vol_idx = m_objects_model->GetVolumeIdByItem(item); - if (vol_idx == -2) // is settings item - event.SetInt(m_objects_model->GetVolumeIdByItem(m_objects_model->GetParent(item))); // set $vol_idx - else - event.SetInt(vol_idx); - } -// get_main_frame()->ProcessWindowEvent(event); // #ys_FIXME - } - -#ifdef __WXOSX__ - update_extruder_in_config(g_selected_extruder); -#endif //__WXOSX__ -} - -void object_ctrl_context_menu() -{ - wxDataViewItem item; - wxDataViewColumn* col; - const wxPoint pt;//!!! = get_mouse_position_in_control(); - m_objects_ctrl->HitTest(pt, item, col); - if (!item) -#ifdef __WXOSX__ // #ys_FIXME temporary workaround for OSX - // after Yosemite OS X version, HitTest return undefined item - item = m_objects_ctrl->GetSelection(); - if (item) - show_context_menu(); - else - printf("undefined item\n"); - return; -#else - return; -#endif // __WXOSX__ - const wxString title = col->GetTitle(); - - if (title == " ") - show_context_menu(); -// #ys_FIXME -// else if (title == _("Name") && pt.x >15 && -// m_objects_model->GetIcon(item).GetRefData() == m_icon_manifold_warning.GetRefData()) -// { -// if (is_windows10()) -// fix_through_netfabb(); -// } -#ifndef __WXMSW__ - m_objects_ctrl->GetMainWindow()->SetToolTip(""); // hide tooltip -#endif //__WXMSW__ -} - -void object_ctrl_key_event(wxKeyEvent& event) -{ - if (event.GetKeyCode() == WXK_TAB) - m_objects_ctrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward); - else if (event.GetKeyCode() == WXK_DELETE -#ifdef __WXOSX__ - || event.GetKeyCode() == WXK_BACK -#endif //__WXOSX__ - ){ - printf("WXK_BACK\n"); - remove(); - } - else - event.Skip(); -} - -void object_ctrl_item_value_change(wxDataViewEvent& event) -{ - if (event.GetColumn() == 2) - { - wxVariant variant; - m_objects_model->GetValue(variant, event.GetItem(), 2); -#ifdef __WXOSX__ - g_selected_extruder = variant.GetString(); -#else // --> for Linux - update_extruder_in_config(variant.GetString()); -#endif //__WXOSX__ - } -} - -void show_manipulation_og(const bool show) -{ - wxGridSizer* grid_sizer = get_optgroup(ogFrequentlyObjectSettings)->get_grid_sizer(); - if (show == grid_sizer->IsShown(2)) - return; - for (size_t id = 2; id < 12; id++) - grid_sizer->Show(id, show); -} - -//update_optgroup -void update_settings_list() -{ -#ifdef __WXGTK__ - auto parent = get_optgroup(ogFrequentlyObjectSettings)->get_parent(); -#else - auto parent = get_optgroup(ogFrequentlyObjectSettings)->parent(); -#endif /* __WXGTK__ */ - -// There is a bug related to Ubuntu overlay scrollbars, see https://github.com/prusa3d/Slic3r/issues/898 and https://github.com/prusa3d/Slic3r/issues/952. -// The issue apparently manifests when Show()ing a window with overlay scrollbars while the UI is frozen. For this reason, -// we will Thaw the UI prematurely on Linux. This means destroing the no_updates object prematurely. -#ifdef __linux__ - std::unique_ptr no_updates(new wxWindowUpdateLocker(parent)); -#else - wxWindowUpdateLocker noUpdates(parent); -#endif - - m_option_sizer->Clear(true); - - bool show_manipulations = true; - const auto item = m_objects_ctrl->GetSelection(); - if (m_config && m_objects_model->IsSettingsItem(item)) - { - auto extra_column = [](wxWindow* parent, const Line& line) - { - auto opt_key = (line.get_options())[0].opt_id; //we assume that we have one option per line - - auto btn = new wxBitmapButton(parent, wxID_ANY, wxBitmap(from_u8(var("colorchange_delete_on.png")), wxBITMAP_TYPE_PNG), - wxDefaultPosition, wxDefaultSize, wxBORDER_NONE); -#ifdef __WXMSW__ - btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); -#endif // __WXMSW__ - btn->Bind(wxEVT_BUTTON, [opt_key](wxEvent &event){ - (*m_config)->erase(opt_key); - wxTheApp->CallAfter([]() { update_settings_list(); }); - }); - return btn; - }; - - std::map> cat_options; - auto opt_keys = (*m_config)->keys(); - m_og_settings.resize(0); - std::vector categories; - if (!(opt_keys.size() == 1 && opt_keys[0] == "extruder"))// return; - { - auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 : - wxGetApp().preset_bundle->printers.get_edited_preset().config.option("nozzle_diameter")->values.size(); - - for (auto& opt_key : opt_keys) { - auto category = (*m_config)->def()->get(opt_key)->category; - if (category.empty() || - (category == "Extruders" && extruders_cnt == 1)) continue; - - std::vector< std::string > new_category; - - auto& cat_opt = cat_options.find(category) == cat_options.end() ? new_category : cat_options.at(category); - cat_opt.push_back(opt_key); - if (cat_opt.size() == 1) - cat_options[category] = cat_opt; - } - - for (auto& cat : cat_options) { - if (cat.second.size() == 1 && cat.second[0] == "extruder") - continue; - - auto optgroup = std::make_shared(parent, cat.first, *m_config, false, ogDEFAULT, extra_column); - optgroup->label_width = 150; - optgroup->sidetext_width = 70; - - for (auto& opt : cat.second) - { - if (opt == "extruder") - continue; - Option option = optgroup->get_option(opt); - option.opt.width = 70; - optgroup->append_single_option_line(option); - } - optgroup->reload_config(); - m_option_sizer->Add(optgroup->sizer, 0, wxEXPAND | wxALL, 0); - m_og_settings.push_back(optgroup); - - categories.push_back(cat.first); - } - } - - if (m_og_settings.empty()) { - m_objects_ctrl->Select(m_objects_model->Delete(item)); - part_selection_changed(); - } - else { - if (!categories.empty()) - m_objects_model->UpdateSettingsDigest(item, categories); - show_manipulations = false; - } - } - - show_manipulation_og(show_manipulations); - show_info_sizer(show_manipulations && item && m_objects_model->GetParent(item) == wxDataViewItem(0)); - -#ifdef __linux__ - no_updates.reset(nullptr); -#endif - - parent->Layout(); - get_right_panel()->GetParent()->Layout(); -} - -void get_settings_choice(wxMenu *menu, int id, bool is_part) -{ - const auto category_name = menu->GetLabel(id); - - wxArrayString names; - wxArrayInt selections; - - settings_menu_hierarchy settings_menu; - get_options_menu(settings_menu, is_part); - std::vector< std::pair > *settings_list = nullptr; - - auto opt_keys = (*m_config)->keys(); - - for (auto& cat : settings_menu) - { - if (_(cat.first) == category_name) { - int sel = 0; - for (auto& pair : cat.second) { - names.Add(_(pair.second)); - if (find(opt_keys.begin(), opt_keys.end(), pair.first) != opt_keys.end()) - selections.Add(sel); - sel++; - } - settings_list = &cat.second; - break; - } - } - - if (!settings_list) - return; - - if (wxGetSelectedChoices(selections, _(L("Select showing settings")), category_name, names) == -1) - return; - - std::vector selected_options; - for (auto sel : selections) - selected_options.push_back((*settings_list)[sel].first); - - for (auto& setting:(*settings_list) ) - { - auto& opt_key = setting.first; - if (find(opt_keys.begin(), opt_keys.end(), opt_key) != opt_keys.end() && - find(selected_options.begin(), selected_options.end(), opt_key) == selected_options.end()) - (*m_config)->erase(opt_key); - - if(find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() && - find(selected_options.begin(), selected_options.end(), opt_key) != selected_options.end()) - (*m_config)->set_key_value(opt_key, m_default_config.get()->option(opt_key)->clone()); - } - - - // Add settings item for object - const auto item = m_objects_ctrl->GetSelection(); - if (item) { - const auto settings_item = m_objects_model->HasSettings(item); - m_objects_ctrl->Select(settings_item ? settings_item : - m_objects_model->AddSettingsChild(item)); -#ifndef __WXOSX__ - part_selection_changed(); -#endif //no __WXOSX__ - } - else - update_settings_list(); -} - -void menu_item_add_generic(wxMenuItem* &menu, int id) { - auto sub_menu = new wxMenu; - - std::vector menu_items = { L("Box"), L("Cylinder"), L("Sphere"), L("Slab") }; - for (auto& item : menu_items) - sub_menu->Append(new wxMenuItem(sub_menu, ++id, _(item))); - -#ifndef __WXMSW__ - sub_menu->Bind(wxEVT_MENU, [sub_menu](wxEvent &event) { - load_lambda(sub_menu->GetLabel(event.GetId()).ToStdString()); - }); -#endif //no __WXMSW__ - - menu->SetSubMenu(sub_menu); -} - -wxMenuItem* menu_item_split(wxMenu* menu, int id) { - auto menu_item = new wxMenuItem(menu, id, _(L("Split to parts"))); - menu_item->SetBitmap(m_bmp_split); - return menu_item; -} - -wxMenuItem* menu_item_settings(wxMenu* menu, int id, const bool is_part) { - auto menu_item = new wxMenuItem(menu, id, _(L("Add settings"))); - menu_item->SetBitmap(m_bmp_cog); - - auto sub_menu = create_add_settings_popupmenu(is_part); - menu_item->SetSubMenu(sub_menu); - return menu_item; -} - -wxMenu *create_add_part_popupmenu() -{ - wxMenu *menu = new wxMenu; - std::vector menu_items = { L("Add part"), L("Add modifier"), L("Add generic") }; - - wxWindowID config_id_base = wxWindow::NewControlId(menu_items.size()+4+2); - - int i = 0; - for (auto& item : menu_items) { - auto menu_item = new wxMenuItem(menu, config_id_base + i, _(item)); - menu_item->SetBitmap(i == 0 ? m_icon_solidmesh : m_icon_modifiermesh); - if (item == "Add generic") - menu_item_add_generic(menu_item, config_id_base + i); - menu->Append(menu_item); - i++; - } - - menu->AppendSeparator(); - auto menu_item = menu_item_split(menu, config_id_base + i + 4); - menu->Append(menu_item); - menu_item->Enable(is_splittable_object(false)); - - menu->AppendSeparator(); - // Append settings popupmenu - menu->Append(menu_item_settings(menu, config_id_base + i + 5, false)); - - menu->Bind(wxEVT_MENU, [config_id_base, menu](wxEvent &event){ - switch (event.GetId() - config_id_base) { - case 0: - on_btn_load(); - break; - case 1: - on_btn_load(true); - break; - case 2: -// on_btn_load(true, true); - break; - case 3: - case 4: - case 5: - case 6: -#ifdef __WXMSW__ - load_lambda(menu->GetLabel(event.GetId()).ToStdString()); -#endif // __WXMSW__ - break; - case 7: //3: - on_btn_split(false); - break; - default: -#ifdef __WXMSW__ - get_settings_choice(menu, event.GetId(), false); -#endif // __WXMSW__ - break; - } - }); - - return menu; -} - -wxMenu *create_part_settings_popupmenu() -{ - wxMenu *menu = new wxMenu; - wxWindowID config_id_base = wxWindow::NewControlId(2); - - auto menu_item = menu_item_split(menu, config_id_base); - menu->Append(menu_item); - menu_item->Enable(is_splittable_object(true)); - - menu->AppendSeparator(); - // Append settings popupmenu - menu->Append(menu_item_settings(menu, config_id_base + 1, true)); - - menu->Bind(wxEVT_MENU, [config_id_base, menu](wxEvent &event){ - switch (event.GetId() - config_id_base) { - case 0: - on_btn_split(true); - break; - default:{ - get_settings_choice(menu, event.GetId(), true); - break; } - } - }); - - return menu; -} - -wxMenu *create_add_settings_popupmenu(bool is_part) -{ - wxMenu *menu = new wxMenu; - - auto categories = get_category_icon(); - - settings_menu_hierarchy settings_menu; - get_options_menu(settings_menu, is_part); - - for (auto cat : settings_menu) - { - auto menu_item = new wxMenuItem(menu, wxID_ANY, _(cat.first)); - menu_item->SetBitmap(categories.find(cat.first) == categories.end() ? - wxNullBitmap : categories.at(cat.first)); - menu->Append(menu_item); - } -#ifndef __WXMSW__ - menu->Bind(wxEVT_MENU, [menu,is_part](wxEvent &event) { - get_settings_choice(menu, event.GetId(), is_part); - }); -#endif //no __WXMSW__ - return menu; -} - -void show_context_menu() -{ - const auto item = m_objects_ctrl->GetSelection(); - if (item) - { - if (m_objects_model->IsSettingsItem(item)) - return; - const auto menu = m_objects_model->GetParent(item) == wxDataViewItem(0) ? - create_add_part_popupmenu() : - create_part_settings_popupmenu(); - wxGetApp().tab_panel()->GetPage(0)->PopupMenu(menu); - } -} - -// ****** - -void load_part( ModelObject* model_object, - wxArrayString& part_names, const bool is_modifier) -{ - wxWindow* parent = wxGetApp().tab_panel()->GetPage(0); - - wxArrayString input_files; - open_model(parent, input_files); - for (int i = 0; i < input_files.size(); ++i) { - std::string input_file = input_files.Item(i).ToStdString(); - - Model model; - try { - model = Model::read_from_file(input_file); - } - catch (std::exception &e) { - auto msg = _(L("Error! ")) + input_file + " : " + e.what() + "."; - show_error(parent, msg); - exit(1); - } - - for ( auto object : model.objects) { - Vec3d delta = Vec3d::Zero(); - if (model_object->origin_translation != Vec3d::Zero()) - { - object->center_around_origin(); - delta = model_object->origin_translation - object->origin_translation; - } - for (auto volume : object->volumes) { - auto new_volume = model_object->add_volume(*volume); - new_volume->set_type(is_modifier ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART); - boost::filesystem::path(input_file).filename().string(); - new_volume->name = boost::filesystem::path(input_file).filename().string(); - - part_names.Add(new_volume->name); - - if (delta != Vec3d::Zero()) - { - new_volume->mesh.translate((float)delta(0), (float)delta(1), (float)delta(2)); - new_volume->get_convex_hull().translate((float)delta(0), (float)delta(1), (float)delta(2)); - } - - // set a default extruder value, since user can't add it manually - new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - - m_parts_changed = true; - } - } - } -} - -void load_lambda( ModelObject* model_object, - wxArrayString& part_names, const bool is_modifier) -{ - auto dlg = new LambdaObjectDialog(m_objects_ctrl->GetMainWindow()); - if (dlg->ShowModal() == wxID_CANCEL) { - return; - } - - std::string name = "lambda-"; - TriangleMesh mesh; - - auto params = dlg->ObjectParameters(); - switch (params.type) - { - case LambdaTypeBox:{ - mesh = make_cube(params.dim[0], params.dim[1], params.dim[2]); - name += "Box"; - break;} - case LambdaTypeCylinder:{ - mesh = make_cylinder(params.cyl_r, params.cyl_h); - name += "Cylinder"; - break;} - case LambdaTypeSphere:{ - mesh = make_sphere(params.sph_rho); - name += "Sphere"; - break;} - case LambdaTypeSlab:{ - const auto& size = model_object->bounding_box().size(); - mesh = make_cube(size(0)*1.5, size(1)*1.5, params.slab_h); - // box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z - mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, params.slab_z); - name += "Slab"; - break; } - default: - break; - } - mesh.repair(); - - auto new_volume = model_object->add_volume(mesh); - new_volume->set_type(is_modifier ? ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART); - - new_volume->name = name; - // set a default extruder value, since user can't add it manually - new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - - part_names.Add(name); - - m_parts_changed = true; -} - -void load_lambda(const std::string& type_name) -{ - if (m_selected_object_id < 0) return; - - auto dlg = new LambdaObjectDialog(m_objects_ctrl->GetMainWindow(), type_name); - if (dlg->ShowModal() == wxID_CANCEL) - return; - - const std::string name = "lambda-"+type_name; - TriangleMesh mesh; - - const auto params = dlg->ObjectParameters(); - if (type_name == _("Box")) - mesh = make_cube(params.dim[0], params.dim[1], params.dim[2]); - else if (type_name == _("Cylinder")) - mesh = make_cylinder(params.cyl_r, params.cyl_h); - else if (type_name == _("Sphere")) - mesh = make_sphere(params.sph_rho); - else if (type_name == _("Slab")){ - const auto& size = (*m_objects)[m_selected_object_id]->bounding_box().size(); - mesh = make_cube(size(0)*1.5, size(1)*1.5, params.slab_h); - // box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z - mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, params.slab_z); - } - mesh.repair(); - - auto new_volume = (*m_objects)[m_selected_object_id]->add_volume(mesh); - new_volume->set_type(ModelVolume::PARAMETER_MODIFIER); - - new_volume->name = name; - // set a default extruder value, since user can't add it manually - new_volume->config.set_key_value("extruder", new ConfigOptionInt(0)); - - m_parts_changed = true; - parts_changed(m_selected_object_id); - - m_objects_ctrl->Select(m_objects_model->AddChild(m_objects_ctrl->GetSelection(), - name, m_icon_modifiermesh)); -#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME - object_ctrl_selection_changed(); -#endif //no __WXOSX__ //__WXMSW__ -} - -void on_btn_load(bool is_modifier /*= false*/, bool is_lambda/* = false*/) -{ - auto item = m_objects_ctrl->GetSelection(); - if (!item) - return; - int obj_idx = -1; - if (m_objects_model->GetParent(item) == wxDataViewItem(0)) - obj_idx = m_objects_model->GetIdByItem(item); - else - return; - - if (obj_idx < 0) return; - wxArrayString part_names; - if (is_lambda) - load_lambda((*m_objects)[obj_idx], part_names, is_modifier); - else - load_part((*m_objects)[obj_idx], part_names, is_modifier); - - parts_changed(obj_idx); - - for (int i = 0; i < part_names.size(); ++i) - m_objects_ctrl->Select( m_objects_model->AddChild(item, part_names.Item(i), - is_modifier ? m_icon_modifiermesh : m_icon_solidmesh)); -#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME - object_ctrl_selection_changed(); -#endif //no __WXOSX__//__WXMSW__ -} - -void remove_settings_from_config() -{ - auto opt_keys = (*m_config)->keys(); - if (opt_keys.size() == 1 && opt_keys[0] == "extruder") - return; - int extruder = -1; - if ((*m_config)->has("extruder")) - extruder = (*m_config)->option("extruder")->value; - - (*m_config)->clear(); - - if (extruder >=0 ) - (*m_config)->set_key_value("extruder", new ConfigOptionInt(extruder)); -} - -bool remove_subobject_from_object(const int volume_id) -{ - const auto volume = (*m_objects)[m_selected_object_id]->volumes[volume_id]; - - // if user is deleting the last solid part, throw error - int solid_cnt = 0; - for (auto vol : (*m_objects)[m_selected_object_id]->volumes) - if (vol->is_model_part()) - ++solid_cnt; - if (volume->is_model_part() && solid_cnt == 1) { - Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from this object."))); - return false; - } - - (*m_objects)[m_selected_object_id]->delete_volume(volume_id); - m_parts_changed = true; - - parts_changed(m_selected_object_id); - return true; -} - -void on_btn_del() -{ - auto item = m_objects_ctrl->GetSelection(); - if (!item) return; - - const auto volume_id = m_objects_model->GetVolumeIdByItem(item); - if (volume_id ==-1) - return; - - if (volume_id ==-2) - remove_settings_from_config(); - else if (!remove_subobject_from_object(volume_id)) - return; - - m_objects_ctrl->Select(m_objects_model->Delete(item)); - part_selection_changed(); -} - -bool get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume) -{ - if (!item || m_selected_object_id < 0) - return false; - const auto volume_id = m_objects_model->GetVolumeIdByItem(item); - if (volume_id < 0) { - if (split_part) return false; - volume = (*m_objects)[m_selected_object_id]->volumes[0]; - } - else - volume = (*m_objects)[m_selected_object_id]->volumes[volume_id]; - if (volume) - return true; - return false; -} - -bool is_splittable_object(const bool split_part) -{ - const wxDataViewItem item = m_objects_ctrl->GetSelection(); - if (!item) return false; - - wxDataViewItemArray children; - if (!split_part && m_objects_model->GetChildren(item, children) > 0) - return false; - - ModelVolume* volume; - if (!get_volume_by_item(split_part, item, volume) || !volume) - return false; - - TriangleMeshPtrs meshptrs = volume->mesh.split(); - bool splittable = meshptrs.size() > 1; - for (TriangleMesh* m : meshptrs) - { - delete m; - } - return splittable; -} - -void on_btn_split(const bool split_part) -{ - const auto item = m_objects_ctrl->GetSelection(); - if (!item || m_selected_object_id<0) - return; - ModelVolume* volume; - if (!get_volume_by_item(split_part, item, volume)) return; - DynamicPrintConfig& config = wxGetApp().preset_bundle->printers.get_edited_preset().config; - const auto nozzle_dmrs_cnt = config.option("nozzle_diameter")->values.size(); - if (volume->split(nozzle_dmrs_cnt) == 1) { - wxMessageBox(_(L("The selected object couldn't be split because it contains only one part."))); - return; - } - - auto model_object = (*m_objects)[m_selected_object_id]; - - if (split_part) { - auto parent = m_objects_model->GetParent(item); - m_objects_model->DeleteChildren(parent); - - for (auto id = 0; id < model_object->volumes.size(); id++) - m_objects_model->AddChild(parent, model_object->volumes[id]->name, - model_object->volumes[id]->is_modifier() ? m_icon_modifiermesh : m_icon_solidmesh, - model_object->volumes[id]->config.has("extruder") ? - model_object->volumes[id]->config.option("extruder")->value : 0, - false); - - m_objects_ctrl->Expand(parent); - } - else { - for (auto id = 0; id < model_object->volumes.size(); id++) - m_objects_model->AddChild(item, model_object->volumes[id]->name, - m_icon_solidmesh, - model_object->volumes[id]->config.has("extruder") ? - model_object->volumes[id]->config.option("extruder")->value : 0, - false); - m_objects_ctrl->Expand(item); - } - - m_parts_changed = true; - parts_changed(m_selected_object_id); -} - -void on_btn_move_up(){ - auto item = m_objects_ctrl->GetSelection(); - if (!item) - return; - auto volume_id = m_objects_model->GetVolumeIdByItem(item); - if (volume_id < 0) - return; - auto& volumes = (*m_objects)[m_selected_object_id]->volumes; - if (0 < volume_id && volume_id < volumes.size()) { - std::swap(volumes[volume_id - 1], volumes[volume_id]); - m_parts_changed = true; - m_objects_ctrl->Select(m_objects_model->MoveChildUp(item)); - part_selection_changed(); -// #ifdef __WXMSW__ -// object_ctrl_selection_changed(); -// #endif //__WXMSW__ - } -} - -void on_btn_move_down(){ - auto item = m_objects_ctrl->GetSelection(); - if (!item) - return; - auto volume_id = m_objects_model->GetVolumeIdByItem(item); - if (volume_id < 0) - return; - auto& volumes = (*m_objects)[m_selected_object_id]->volumes; - if (0 <= volume_id && volume_id+1 < volumes.size()) { - std::swap(volumes[volume_id + 1], volumes[volume_id]); - m_parts_changed = true; - m_objects_ctrl->Select(m_objects_model->MoveChildDown(item)); - part_selection_changed(); -// #ifdef __WXMSW__ -// object_ctrl_selection_changed(); -// #endif //__WXMSW__ - } -} - -void parts_changed(int obj_idx) -{ - if (m_event_object_settings_changed <= 0) return; - - wxCommandEvent e(m_event_object_settings_changed); - auto event_str = wxString::Format("%d %d %d", obj_idx, - is_parts_changed() ? 1 : 0, - is_part_settings_changed() ? 1 : 0); - e.SetString(event_str); -// get_main_frame()->ProcessWindowEvent(e); // #ys_FIXME -} - -void part_selection_changed() -{ - auto item = m_objects_ctrl->GetSelection(); - int obj_idx = -1; - auto og = get_optgroup(ogFrequentlyObjectSettings); - m_config = nullptr; - wxString object_name = wxEmptyString; - if (item) - { - const bool is_settings_item = m_objects_model->IsSettingsItem(item); - bool is_part = false; - wxString og_name = wxEmptyString; - if (m_objects_model->GetParent(item) == wxDataViewItem(0)) { - obj_idx = m_objects_model->GetIdByItem(item); - og_name = _(L("Object manipulation")); - m_config = std::make_shared(&(*m_objects)[obj_idx]->config); - } - else { - auto parent = m_objects_model->GetParent(item); - // Take ID of the parent object to "inform" perl-side which object have to be selected on the scene - obj_idx = m_objects_model->GetIdByItem(parent); - if (is_settings_item) { - if (m_objects_model->GetParent(parent) == wxDataViewItem(0)) { - og_name = _(L("Object Settings to modify")); - m_config = std::make_shared(&(*m_objects)[obj_idx]->config); - } - else { - og_name = _(L("Part Settings to modify")); - is_part = true; - auto main_parent = m_objects_model->GetParent(parent); - obj_idx = m_objects_model->GetIdByItem(main_parent); - const auto volume_id = m_objects_model->GetVolumeIdByItem(parent); - m_config = std::make_shared(&(*m_objects)[obj_idx]->volumes[volume_id]->config); - } - } - else { - og_name = _(L("Part manipulation")); - is_part = true; - const auto volume_id = m_objects_model->GetVolumeIdByItem(item); - m_config = std::make_shared(&(*m_objects)[obj_idx]->volumes[volume_id]->config); - } - } - - og->set_name(" " + og_name + " "); - object_name = m_objects_model->GetName(item); - m_default_config = std::make_shared(*DynamicPrintConfig::new_from_defaults_keys(get_options(is_part))); - } - og->set_value("object_name", object_name); - - update_settings_list(); - - m_selected_object_id = obj_idx; - -// update_values(); -} - -void set_extruder_column_hidden(bool hide) -{ - m_objects_ctrl->GetColumn(2)->SetHidden(hide); -} - -void update_extruder_in_config(const wxString& selection) -{ - if (!m_config || selection.empty()) - return; - - int extruder = selection.size() > 1 ? 0 : atoi(selection.c_str()); - (*m_config)->set_key_value("extruder", new ConfigOptionInt(extruder)); - - if (m_event_update_scene > 0) { - wxCommandEvent e(m_event_update_scene); -// get_main_frame()->ProcessWindowEvent(e); // #ys_FIXME - } -} - -void set_uniform_scaling(const bool uniform_scale) -{ - g_is_uniform_scale = uniform_scale; -} - -void on_begin_drag(wxDataViewEvent &event) -{ - wxDataViewItem item(event.GetItem()); - - // only allow drags for item, not containers - if (m_objects_model->GetParent(item) == wxDataViewItem(0) || m_objects_model->IsSettingsItem(item)) { - event.Veto(); - return; - } - - /* Under MSW or OSX, DnD moves an item to the place of another selected item - * But under GTK, DnD moves an item between another two items. - * And as a result - call EVT_CHANGE_SELECTION to unselect all items. - * To prevent such behavior use g_prevent_list_events - **/ - g_prevent_list_events = true;//it's needed for GTK - - wxTextDataObject *obj = new wxTextDataObject; - obj->SetText(wxString::Format("%d", m_objects_model->GetVolumeIdByItem(item))); - event.SetDataObject(obj); - event.SetDragFlags(/*wxDrag_AllowMove*/wxDrag_DefaultMove); // allows both copy and move; -} - -void on_drop_possible(wxDataViewEvent &event) -{ - wxDataViewItem item(event.GetItem()); - - // only allow drags for item or background, not containers - if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || - event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) - event.Veto(); -} - -void on_drop(wxDataViewEvent &event) -{ - wxDataViewItem item(event.GetItem()); - - // only allow drops for item, not containers - if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) || - event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->IsSettingsItem(item)) { - event.Veto(); - return; - } - - wxTextDataObject obj; - obj.SetData(wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer()); - - int from_volume_id = std::stoi(obj.GetText().ToStdString()); - int to_volume_id = m_objects_model->GetVolumeIdByItem(item); - -#ifdef __WXGTK__ - /* Under GTK, DnD moves an item between another two items. - * And event.GetItem() return item, which is under "insertion line" - * So, if we move item down we should to decrease the to_volume_id value - **/ - if (to_volume_id > from_volume_id) to_volume_id--; -#endif // __WXGTK__ - - m_objects_ctrl->Select(m_objects_model->ReorganizeChildren(from_volume_id, to_volume_id, - m_objects_model->GetParent(item))); - - auto& volumes = (*m_objects)[m_selected_object_id]->volumes; - auto delta = to_volume_id < from_volume_id ? -1 : 1; - int cnt = 0; - for (int id = from_volume_id; cnt < abs(from_volume_id - to_volume_id); id+=delta, cnt++) - std::swap(volumes[id], volumes[id +delta]); - - m_parts_changed = true; - parts_changed(m_selected_object_id); - - g_prevent_list_events = false; -} - -void create_double_slider(wxWindow* parent, wxBoxSizer* sizer, wxGLCanvas* canvas) -{ - m_slider = new PrusaDoubleSlider(parent, wxID_ANY, 0, 0, 0, 100); - sizer->Add(m_slider, 0, wxEXPAND, 0); - - m_preview_canvas = canvas; - m_preview_canvas->Bind(wxEVT_KEY_DOWN, update_double_slider_from_canvas); - - m_slider->Bind(wxEVT_SCROLL_CHANGED, [parent](wxEvent& event) { - _3DScene::set_toolpaths_range(m_preview_canvas, m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6); - if (parent->IsShown()) - m_preview_canvas->Refresh(); - }); -} - -void fill_slider_values(std::vector> &values, - const std::vector &layers_z) -{ - std::vector layers_all_z = _3DScene::get_current_print_zs(m_preview_canvas, false); - if (layers_all_z.size() == layers_z.size()) - for (int i = 0; i < layers_z.size(); i++) - values.push_back(std::pair(i+1, layers_z[i])); - else if (layers_all_z.size() > layers_z.size()) { - int cur_id = 0; - for (int i = 0; i < layers_z.size(); i++) - for (int j = cur_id; j < layers_all_z.size(); j++) - if (layers_z[i] - 1e-6 < layers_all_z[j] && layers_all_z[j] < layers_z[i] + 1e-6) { - values.push_back(std::pair(j+1, layers_z[i])); - cur_id = j; - break; - } - } -} - -void set_double_slider_thumbs( const bool force_sliders_full_range, - const std::vector &layers_z, - const double z_low, const double z_high) -{ - // Force slider full range only when slider is created. - // Support selected diapason on the all next steps - if (/*force_sliders_full_range*/z_high == 0.0) { - m_slider->SetLowerValue(0); - m_slider->SetHigherValue(layers_z.size() - 1); - return; - } - - for (int i = layers_z.size() - 1; i >= 0; i--) - if (z_low >= layers_z[i]) { - m_slider->SetLowerValue(i); - break; - } - for (int i = layers_z.size() - 1; i >= 0 ; i--) - if (z_high >= layers_z[i]) { - m_slider->SetHigherValue(i); - break; - } -} - -void update_double_slider(bool force_sliders_full_range) -{ - std::vector> values; - std::vector layers_z = _3DScene::get_current_print_zs(m_preview_canvas, true); - fill_slider_values(values, layers_z); - - const double z_low = m_slider->GetLowerValueD(); - const double z_high = m_slider->GetHigherValueD(); - m_slider->SetMaxValue(layers_z.size() - 1); - m_slider->SetSliderValues(values); - - set_double_slider_thumbs(force_sliders_full_range, layers_z, z_low, z_high); -} - -void reset_double_slider() -{ - m_slider->SetHigherValue(0); - m_slider->SetLowerValue(0); -} - -void update_double_slider_from_canvas(wxKeyEvent& event) -{ - if (event.HasModifiers()) { - event.Skip(); - return; - } - - const auto key = event.GetKeyCode(); - - if (key == 'U' || key == 'D') { - const int new_pos = key == 'U' ? m_slider->GetHigherValue() + 1 : m_slider->GetHigherValue() - 1; - m_slider->SetHigherValue(new_pos); - if (event.ShiftDown()) m_slider->SetLowerValue(m_slider->GetHigherValue()); - } - else if (key == 'S') - m_slider->ChangeOneLayerLock(); - else - event.Skip(); -} - -void show_manipulation_sizer(const bool is_simple_mode) -{ - auto item = m_objects_ctrl->GetSelection(); - if (!item || !is_simple_mode) - return; - - if (m_objects_model->IsSettingsItem(item)) { - m_objects_ctrl->Select(m_objects_model->GetParent(item)); - part_selection_changed(); - } -} - -} //namespace GUI -} //namespace Slic3r \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_ObjectParts.hpp b/src/slic3r/GUI/GUI_ObjectParts.hpp deleted file mode 100644 index 18614c4ee..000000000 --- a/src/slic3r/GUI/GUI_ObjectParts.hpp +++ /dev/null @@ -1,134 +0,0 @@ -#ifndef slic3r_GUI_ObjectParts_hpp_ -#define slic3r_GUI_ObjectParts_hpp_ -// #include "OptionsGroup.hpp" - -class wxWindow; -class wxSizer; -class wxBoxSizer; -class wxString; -class wxArrayString; -class wxMenu; -class wxDataViewEvent; -class wxKeyEvent; -class wxGLCanvas; -class wxBitmap; - -namespace Slic3r { -class ModelObject; -class Model; - -namespace GUI { -class ConfigOptionsGroup; -using t_optgroups = std::vector >; - -enum ogGroup{ - ogFrequentlyChangingParameters, - ogFrequentlyObjectSettings, - ogObjectSettings -}; - -enum LambdaTypeIDs{ - LambdaTypeBox, - LambdaTypeCylinder, - LambdaTypeSphere, - LambdaTypeSlab -}; - -struct OBJECT_PARAMETERS -{ - LambdaTypeIDs type = LambdaTypeBox; - double dim[3];// = { 1.0, 1.0, 1.0 }; - int cyl_r = 1; - int cyl_h = 1; - double sph_rho = 1.0; - double slab_h = 1.0; - double slab_z = 0.0; -}; - -typedef std::map t_category_icon; -inline t_category_icon& get_category_icon(); - -void add_objects_list(wxWindow* parent, wxBoxSizer* sizer); -void add_object_settings(wxWindow* parent, wxBoxSizer* sizer, t_optgroups& optgroups); - -wxMenu *create_add_settings_popupmenu(bool is_part); -wxMenu *create_add_part_popupmenu(); -wxMenu *create_part_settings_popupmenu(); - -// Add object to the list -//void add_object(const std::string &name); -void add_object_to_list(const std::string &name, ModelObject* model_object); -// Delete object from the list -void delete_object_from_list(); -// Delete all objects from the list -void delete_all_objects_from_list(); -// Set count of object on c++ side -void set_object_count(int idx, int count); -// Unselect all objects in the list on c++ side -void unselect_objects(); -// Select current object in the list on c++ side -void select_current_object(int idx); -// Select current volume in the list on c++ side -void select_current_volume(int idx, int vol_idx); -// Remove objects/sub-object from the list -void remove(); - -void object_ctrl_selection_changed(); -void object_ctrl_context_menu(); -void object_ctrl_key_event(wxKeyEvent& event); -void object_ctrl_item_value_change(wxDataViewEvent& event); -void show_context_menu(); -bool is_splittable_object(const bool split_part); - -void init_mesh_icons(); -void set_event_object_selection_changed(const int& event); -void set_event_object_settings_changed(const int& event); -void set_event_remove_object(const int& event); -void set_event_update_scene(const int& event); -void set_objects_from_model(Model &model); - -bool is_parts_changed(); -bool is_part_settings_changed(); - -void load_part( ModelObject* model_object, - wxArrayString& part_names, const bool is_modifier); - -void load_lambda( ModelObject* model_object, - wxArrayString& part_names, const bool is_modifier); -void load_lambda( const std::string& type_name); - -void on_btn_load(bool is_modifier = false, bool is_lambda = false); -void on_btn_del(); -void on_btn_split(const bool split_part); -void on_btn_move_up(); -void on_btn_move_down(); - -void parts_changed(int obj_idx); -void part_selection_changed(); - -// show/hide "Extruder" column for Objects List -void set_extruder_column_hidden(bool hide); -// update extruder in current config -void update_extruder_in_config(const wxString& selection); - -void set_uniform_scaling(const bool uniform_scale); - -void on_begin_drag(wxDataViewEvent &event); -void on_drop_possible(wxDataViewEvent &event); -void on_drop(wxDataViewEvent &event); - -// update extruder column for objects_ctrl according to extruders count -void update_objects_list_extruder_column(int extruders_count); - -// Create/Update/Reset double slider on 3dPreview -void create_double_slider(wxWindow* parent, wxBoxSizer* sizer, wxGLCanvas* canvas); -void update_double_slider(bool force_sliders_full_range); -void reset_double_slider(); -// update DoubleSlider after keyDown in canvas -void update_double_slider_from_canvas(wxKeyEvent& event); - -void show_manipulation_sizer(const bool is_simple_mode); - -} //namespace GUI -} //namespace Slic3r -#endif //slic3r_GUI_ObjectParts_hpp_ \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 988f6e507..5618eab04 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -6,6 +6,7 @@ #include "GLCanvas3DManager.hpp" #include "../../libslic3r/GCode/PreviewData.hpp" #include "PresetBundle.hpp" +#include "wxExtensions.hpp" #include #include @@ -69,7 +70,7 @@ bool Preview::init(wxNotebook* notebook, DynamicPrintConfig* config, Print* prin _3DScene::enable_dynamic_background(m_canvas, true); m_double_slider_sizer = new wxBoxSizer(wxHORIZONTAL); - create_double_slider(this, m_double_slider_sizer, m_canvas); + create_double_slider(); m_label_view_type = new wxStaticText(this, wxID_ANY, _(L("View"))); @@ -468,5 +469,104 @@ void Preview::on_checkbox_shells(wxCommandEvent& evt) refresh_print(); } +void Preview::create_double_slider() +{ + m_slider = new PrusaDoubleSlider(this, wxID_ANY, 0, 0, 0, 100); + m_double_slider_sizer->Add(m_slider, 0, wxEXPAND, 0); + + // sizer, m_canvas + m_canvas->Bind(wxEVT_KEY_DOWN, &Preview::update_double_slider_from_canvas, this); + + m_slider->Bind(wxEVT_SCROLL_CHANGED, [this](wxEvent& event) { + _3DScene::set_toolpaths_range(m_canvas, m_slider->GetLowerValueD() - 1e-6, m_slider->GetHigherValueD() + 1e-6); + if (IsShown()) + m_canvas->Refresh(); + }); +} + +void Preview::update_double_slider(bool force_sliders_full_range) +{ + std::vector> values; + std::vector layers_z = _3DScene::get_current_print_zs(m_canvas, true); + fill_slider_values(values, layers_z); + + const double z_low = m_slider->GetLowerValueD(); + const double z_high = m_slider->GetHigherValueD(); + m_slider->SetMaxValue(layers_z.size() - 1); + m_slider->SetSliderValues(values); + + set_double_slider_thumbs(force_sliders_full_range, layers_z, z_low, z_high); +} + +void Preview::fill_slider_values(std::vector> &values, + const std::vector &layers_z) +{ + std::vector layers_all_z = _3DScene::get_current_print_zs(m_canvas, false); + if (layers_all_z.size() == layers_z.size()) + for (int i = 0; i < layers_z.size(); i++) + values.push_back(std::pair(i + 1, layers_z[i])); + else if (layers_all_z.size() > layers_z.size()) { + int cur_id = 0; + for (int i = 0; i < layers_z.size(); i++) + for (int j = cur_id; j < layers_all_z.size(); j++) + if (layers_z[i] - 1e-6 < layers_all_z[j] && layers_all_z[j] < layers_z[i] + 1e-6) { + values.push_back(std::pair(j + 1, layers_z[i])); + cur_id = j; + break; + } + } +} + +void Preview::set_double_slider_thumbs(const bool force_sliders_full_range, + const std::vector &layers_z, + const double z_low, + const double z_high) +{ + // Force slider full range only when slider is created. + // Support selected diapason on the all next steps + if (/*force_sliders_full_range*/z_high == 0.0) { + m_slider->SetLowerValue(0); + m_slider->SetHigherValue(layers_z.size() - 1); + return; + } + + for (int i = layers_z.size() - 1; i >= 0; i--) + if (z_low >= layers_z[i]) { + m_slider->SetLowerValue(i); + break; + } + for (int i = layers_z.size() - 1; i >= 0; i--) + if (z_high >= layers_z[i]) { + m_slider->SetHigherValue(i); + break; + } +} + +void Preview::reset_double_slider() +{ + m_slider->SetHigherValue(0); + m_slider->SetLowerValue(0); +} + +void Preview::update_double_slider_from_canvas(wxKeyEvent& event) +{ + if (event.HasModifiers()) { + event.Skip(); + return; + } + + const auto key = event.GetKeyCode(); + + if (key == 'U' || key == 'D') { + const int new_pos = key == 'U' ? m_slider->GetHigherValue() + 1 : m_slider->GetHigherValue() - 1; + m_slider->SetHigherValue(new_pos); + if (event.ShiftDown()) m_slider->SetLowerValue(m_slider->GetHigherValue()); + } + else if (key == 'S') + m_slider->ChangeOneLayerLock(); + else + event.Skip(); +} + } // namespace GUI } // namespace Slic3r diff --git a/src/slic3r/GUI/GUI_Preview.hpp b/src/slic3r/GUI/GUI_Preview.hpp index e7b7f4c94..7c7430c7c 100644 --- a/src/slic3r/GUI/GUI_Preview.hpp +++ b/src/slic3r/GUI/GUI_Preview.hpp @@ -13,6 +13,7 @@ class wxStaticText; class wxChoice; class wxComboCtrl; class wxCheckBox; +class PrusaDoubleSlider; namespace Slic3r { @@ -46,6 +47,8 @@ class Preview : public wxPanel bool m_enabled; bool m_force_sliders_full_range; + PrusaDoubleSlider* m_slider {nullptr}; + public: Preview(wxNotebook* notebook, DynamicPrintConfig* config, Print* print, GCodePreviewData* gcode_preview_data); virtual ~Preview(); @@ -84,6 +87,19 @@ private: void on_checkbox_retractions(wxCommandEvent& evt); void on_checkbox_unretractions(wxCommandEvent& evt); void on_checkbox_shells(wxCommandEvent& evt); + + // Create/Update/Reset double slider on 3dPreview + void create_double_slider(); + void update_double_slider(bool force_sliders_full_range); + void fill_slider_values(std::vector> &values, + const std::vector &layers_z); + void set_double_slider_thumbs( const bool force_sliders_full_range, + const std::vector &layers_z, + const double z_low, + const double z_high); + void reset_double_slider(); + // update DoubleSlider after keyDown in canvas + void update_double_slider_from_canvas(wxKeyEvent& event); }; } // namespace GUI diff --git a/src/slic3r/GUI/LambdaObjectDialog.hpp b/src/slic3r/GUI/LambdaObjectDialog.hpp index 8f3e8cd80..9ee7824fc 100644 --- a/src/slic3r/GUI/LambdaObjectDialog.hpp +++ b/src/slic3r/GUI/LambdaObjectDialog.hpp @@ -13,6 +13,24 @@ namespace Slic3r { namespace GUI { +enum LambdaTypeIDs{ + LambdaTypeBox, + LambdaTypeCylinder, + LambdaTypeSphere, + LambdaTypeSlab +}; + +struct OBJECT_PARAMETERS +{ + LambdaTypeIDs type = LambdaTypeBox; + double dim[3];// = { 1.0, 1.0, 1.0 }; + int cyl_r = 1; + int cyl_h = 1; + double sph_rho = 1.0; + double slab_h = 1.0; + double slab_z = 0.0; +}; +class ConfigOptionsGroup; using ConfigOptionsGroupShp = std::shared_ptr; class LambdaObjectDialog : public wxDialog { diff --git a/src/slic3r/GUI/MainFrame.cpp b/src/slic3r/GUI/MainFrame.cpp index 07f4c5e8e..1c52d2155 100644 --- a/src/slic3r/GUI/MainFrame.cpp +++ b/src/slic3r/GUI/MainFrame.cpp @@ -100,9 +100,6 @@ wxFrame(NULL, wxID_ANY, SLIC3R_BUILD, wxDefaultPosition, wxDefaultSize, wxDEFAUL }); update_ui_from_settings(); - -// Slic3r::GUI::update_mode(); - return; } @@ -247,6 +244,23 @@ void MainFrame::init_tabpanel() } } +std::vector preset_tabs = { + { "print", nullptr, ptFFF }, + { "filament", nullptr, ptFFF }, + { "sla_material", nullptr, ptSLA } +}; + +std::vector& MainFrame::get_preset_tabs() { + return preset_tabs; +} + +Tab* MainFrame::get_tab(const std::string& name) +{ + std::vector::iterator it = std::find_if(preset_tabs.begin(), preset_tabs.end(), + [name](PresetTab& tab){ return name == tab.name; }); + return it != preset_tabs.end() ? it->panel : nullptr; +} + Tab* MainFrame::get_preset_tab(const std::string& name) { Tab* tab = get_tab(name); @@ -282,10 +296,9 @@ void MainFrame::add_created_tab(Tab* panel) const wxString& tab_name = panel->GetName(); bool add_panel = true; - auto preset_tabs = get_preset_tabs(); - auto it = std::find_if(preset_tabs->begin(), preset_tabs->end(), + auto it = std::find_if(preset_tabs.begin(), preset_tabs.end(), [tab_name](PresetTab& tab){return tab.name == tab_name; }); - if (it != preset_tabs->end()) { + if (it != preset_tabs.end()) { it->panel = panel; add_panel = it->technology == wxGetApp().preset_bundle->printers.get_edited_preset().printer_technology(); } diff --git a/src/slic3r/GUI/MainFrame.hpp b/src/slic3r/GUI/MainFrame.hpp index f4c75de65..4063bd0c4 100644 --- a/src/slic3r/GUI/MainFrame.hpp +++ b/src/slic3r/GUI/MainFrame.hpp @@ -36,6 +36,12 @@ enum QuickSlice qsExportPNG }; +struct PresetTab { + std::string name; + Tab* panel; + PrinterTechnology technology; +}; + class MainFrame : public wxFrame { bool m_no_plater; @@ -64,6 +70,9 @@ class MainFrame : public wxFrame std::string get_base_name(const wxString full_name) const ; std::string get_dir_name(const wxString full_name) const ; + + Tab* get_tab(const std::string& name); + public: MainFrame() {} MainFrame(const bool no_plater, const bool loaded); @@ -94,6 +103,7 @@ public: void select_tab(size_t tab) const; void select_view(const std::string& direction); + std::vector& get_preset_tabs(); Plater* m_plater { nullptr }; wxNotebook* m_tabpanel { nullptr }; diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 29e79b79d..522dfb471 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -72,13 +72,13 @@ class ObjectInfo : public wxStaticBoxSizer public: ObjectInfo(wxWindow *parent); + wxStaticBitmap *manifold_warning_icon; private: wxStaticText *info_size; wxStaticText *info_volume; wxStaticText *info_facets; wxStaticText *info_materials; wxStaticText *info_manifold; - wxStaticBitmap *manifold_warning_icon; }; ObjectInfo::ObjectInfo(wxWindow *parent) : @@ -362,8 +362,6 @@ struct Sidebar::priv wxButton *btn_reslice; // wxButton *btn_print; // XXX: remove wxButton *btn_send_gcode; - - std::vector > optgroups {}; }; @@ -512,13 +510,14 @@ ObjectManipulation* Sidebar::obj_manipul() return p->object_manipulation; } -ConfigOptionsGroup* Sidebar::get_optgroup(size_t i) +ObjectList* Sidebar::obj_list() { - return p->optgroups.empty() ? nullptr : p->optgroups[i].get(); + return p->object_list; } -t_optgroups& Sidebar::get_optgroups() { - return p->optgroups; +ConfigOptionsGroup* Sidebar::og_freq_chng_params() +{ + return p->frequently_changed_parameters->get_og(); } wxButton* Sidebar::get_wiping_dialog_button() @@ -536,6 +535,26 @@ int Sidebar::get_ol_selection() return p->object_list->get_sel_obj_id(); } +void Sidebar::show_info_sizers(const bool show) +{ + p->object_info->Show(show); + p->object_info->manifold_warning_icon->Show(show/* && g_show_manifold_warning_icon*/); // where is g_show_manifold_warning_icon updating? #ys_FIXME + p->sliced_info->Show(show /*&& g_show_print_info*/); // where is g_show_print_info updating? #ys_FIXME +} + +void Sidebar::show_buttons(const bool show) +{ + p->btn_reslice->Show(show); + for (size_t i = 0; i < wxGetApp().tab_panel()->GetPageCount(); ++i) { + TabPrinter *tab = dynamic_cast(wxGetApp().tab_panel()->GetPage(i)); + if (!tab) + continue; + if (wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptFFF) { + p->btn_send_gcode->Show(show && !tab->m_config->opt_string("print_host").empty()); + } + break; + } +} // Plater::Object @@ -712,27 +731,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) : // Drop target: q->SetDropTarget(new PlaterDropTarget(q)); // if my understanding is right, wxWindow takes the owenership - // Setting of global access pointers - // FIXME: We really should get rid of these once Perl code is gone... - set_objects_from_model(model); - // TODO: ? - // # Send sizers/buttons to C++ - // Slic3r::GUI::set_objects_from_perl( $self->{scrolled_window_panel}, - // $frequently_changed_parameters_sizer, - // $info_sizer, - // $self->{btn_export_gcode}, - // # $self->{btn_export_stl}, - // $self->{btn_reslice}, - // $self->{btn_print}, - // $self->{btn_send_gcode}, - // $self->{object_info_manifold_warning_icon} ); - - // Slic3r::GUI::set_model_events_from_perl( $self->{model}, - // $self->{event_object_selection_changed}, - // $self->{event_object_settings_changed}, - // $self->{event_remove_object}, - // $self->{event_update_scene}); - update_ui_from_settings(); q->Layout(); } diff --git a/src/slic3r/GUI/Plater.hpp b/src/slic3r/GUI/Plater.hpp index 1d9022350..a060eda9c 100644 --- a/src/slic3r/GUI/Plater.hpp +++ b/src/slic3r/GUI/Plater.hpp @@ -16,6 +16,7 @@ namespace GUI { class MainFrame; class ConfigOptionsGroup; class ObjectManipulation; +class ObjectList; using t_optgroups = std::vector >; @@ -31,13 +32,15 @@ public: void update_presets(Slic3r::Preset::Type preset_type); - ObjectManipulation* obj_manipul(); + ObjectManipulation* obj_manipul(); + ObjectList* obj_list(); - ConfigOptionsGroup* get_optgroup(size_t i); // #ys_FIXME_for_delete - t_optgroups& get_optgroups();// #ys_FIXME_for_delete + ConfigOptionsGroup* og_freq_chng_params(); wxButton* get_wiping_dialog_button(); void update_objects_list_extruder_column(int extruders_count); int get_ol_selection(); + void show_info_sizers(const bool show); + void show_buttons(const bool show); private: struct priv; diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 7a13f6df7..1e39e2a70 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -683,10 +683,12 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) // g_wxMainFrame->ProcessWindowEvent(event);// #ys_FIXME } + + auto og_freq_chng_params = wxGetApp().sidebar().og_freq_chng_params(); if (opt_key == "fill_density") { - boost::any val = get_optgroup(ogFrequentlyChangingParameters)->get_config_value(*m_config, opt_key); - get_optgroup(ogFrequentlyChangingParameters)->set_value(opt_key, val); + boost::any val = og_freq_chng_params->get_config_value(*m_config, opt_key); + og_freq_chng_params->set_value(opt_key, val); } if (opt_key == "support_material" || opt_key == "support_material_buildplate_only") { @@ -695,12 +697,12 @@ void Tab::on_value_change(const std::string& opt_key, const boost::any& value) m_config->opt_bool("support_material_buildplate_only") ? _("Support on build plate only") : _("Everywhere"); - get_optgroup(ogFrequentlyChangingParameters)->set_value("support", new_selection); + og_freq_chng_params->set_value("support", new_selection); } if (opt_key == "brim_width") { bool val = m_config->opt_float("brim_width") > 0.0 ? true : false; - get_optgroup(ogFrequentlyChangingParameters)->set_value("brim", val); + og_freq_chng_params->set_value("brim", val); } if (opt_key == "wipe_tower" || opt_key == "single_extruder_multi_material" || opt_key == "extruders_count" ) @@ -789,19 +791,20 @@ void Tab::update_preset_description_line() void Tab::update_frequently_changed_parameters() { - if (!get_optgroup(ogFrequentlyChangingParameters)) return; - boost::any value = get_optgroup(ogFrequentlyChangingParameters)->get_config_value(*m_config, "fill_density"); - get_optgroup(ogFrequentlyChangingParameters)->set_value("fill_density", value); + auto og_freq_chng_params = wxGetApp().sidebar().og_freq_chng_params(); + if (!og_freq_chng_params) return; + boost::any value = og_freq_chng_params->get_config_value(*m_config, "fill_density"); + og_freq_chng_params->set_value("fill_density", value); wxString new_selection = !m_config->opt_bool("support_material") ? _("None") : m_config->opt_bool("support_material_buildplate_only") ? _("Support on build plate only") : _("Everywhere"); - get_optgroup(ogFrequentlyChangingParameters)->set_value("support", new_selection); + og_freq_chng_params->set_value("support", new_selection); bool val = m_config->opt_float("brim_width") > 0.0 ? true : false; - get_optgroup(ogFrequentlyChangingParameters)->set_value("brim", val); + og_freq_chng_params->set_value("brim", val); update_wiping_button_visibility(); } @@ -1841,9 +1844,10 @@ void TabPrinter::extruders_count_changed(size_t extruders_count){ m_preset_bundle->update_multi_material_filament_presets(); build_extruder_pages(); reload_config(); + if (!wxGetApp().mainframe) + return; on_value_change("extruders_count", extruders_count); - if (wxGetApp().mainframe) - wxGetApp().mainframe->m_plater->sidebar().update_objects_list_extruder_column(extruders_count); + wxGetApp().mainframe->m_plater->sidebar().update_objects_list_extruder_column(extruders_count); } void TabPrinter::append_option_line(ConfigOptionsGroupShp optgroup, const std::string opt_key) @@ -2193,7 +2197,7 @@ void Tab::load_current_preset() PrinterTechnology& printer_technology = m_presets->get_edited_preset().printer_technology(); if (printer_technology != static_cast(this)->m_printer_technology) { - for (auto& tab : *get_preset_tabs()){ + for (auto& tab : wxGetApp().mainframe->get_preset_tabs()){ if (tab.technology != printer_technology) { int page_id = wxGetApp().tab_panel()->FindPage(tab.panel); diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 13730a497..bae1055b8 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1,6 +1,5 @@ #include "wxExtensions.hpp" -#include "GUI.hpp" #include "../../libslic3r/Utils.hpp" #include "BitmapCache.hpp" @@ -8,6 +7,8 @@ #include #include #include +#include "GUI_App.hpp" +#include "GUI_ObjectList.hpp" const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200; const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200; @@ -368,7 +369,7 @@ bool PrusaObjectDataViewModelNode::update_settings_digest(const std::vector& categories_icon = Slic3r::GUI::wxGetApp().obj_list()->CATEGORY_ICON;//Slic3r::GUI::get_category_icon(); for (auto& cat : m_opt_categories) m_name += cat + "; ";