Skip to content

Commit f3ed674

Browse files
committed
Add Standard 3MF color import preference
(cherry picked from commit 31646dc)
1 parent 6adb840 commit f3ed674

5 files changed

Lines changed: 70 additions & 6 deletions

File tree

src/libslic3r/AppConfig.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ void AppConfig::set_defaults()
111111
if (get("drop_project_action").empty())
112112
set_bool("drop_project_action", true);
113113

114+
if (get("standard_3mf_color_import_mode").empty())
115+
set("standard_3mf_color_import_mode", "ask");
116+
114117
#ifdef _WIN32
115118
if (get("associate_3mf").empty())
116119
set_bool("associate_3mf", false);

src/slic3r/GUI/ObjColorDialog.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,16 @@ bool ObjColorDialog::Show(bool show) {
168168
}
169169
};
170170

171+
bool ObjColorDialog::apply_default_mapping()
172+
{
173+
if (!m_panel_ObjColor || !m_panel_ObjColor->is_ok())
174+
return false;
175+
176+
m_panel_ObjColor->clear_instance_and_revert_offset();
177+
m_panel_ObjColor->send_new_filament_to_ui();
178+
return true;
179+
}
180+
171181
ObjColorDialog::ObjColorDialog(wxWindow *parent, Slic3r::ObjDialogInOut &in_out, const std::vector<std::string> &extruder_colours)
172182
: DPIDialog(parent ? parent : static_cast<wxWindow *>(wxGetApp().mainframe),
173183
wxID_ANY,
@@ -244,9 +254,8 @@ ObjColorDialog::ObjColorDialog(wxWindow *parent, Slic3r::ObjDialogInOut &in_out,
244254
EndModal(wxCANCEL);
245255
return;
246256
}
247-
m_panel_ObjColor->clear_instance_and_revert_offset();
248-
m_panel_ObjColor->send_new_filament_to_ui();
249-
EndModal(wxID_OK);
257+
if (apply_default_mapping())
258+
EndModal(wxID_OK);
250259
}, wxID_OK);
251260
}
252261
if (this->FindWindowById(wxID_CANCEL, this)) {

src/slic3r/GUI/ObjColorDialog.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class ObjColorDialog : public Slic3r::GUI::DPIDialog
131131
void on_dpi_changed(const wxRect &suggested_rect) override;
132132
void update_layout();
133133
bool Show(bool show) override;
134+
bool apply_default_mapping();
134135

135136
private:
136137
ObjColorPanel* m_panel_ObjColor = nullptr;

src/slic3r/GUI/Plater.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8347,9 +8347,37 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
83478347
color_dialog_in_out.model = &model;
83488348
color_dialog_in_out.input_type = ObjDialogInOut::FormatType::Standard3mf;
83498349
color_dialog_in_out.volume_colors = volume_color_data;
8350-
ObjColorDialog color_dlg(nullptr, color_dialog_in_out, extruder_colours);
8351-
if (color_dlg.ShowModal() == wxID_OK) {
8352-
color_dialog_in_out.filament_ids.clear();
8350+
8351+
const std::string color_import_mode =
8352+
wxGetApp().app_config->get("standard_3mf_color_import_mode");
8353+
8354+
if (color_import_mode != "geometry_only") {
8355+
ObjColorDialog color_dlg(
8356+
nullptr,
8357+
color_dialog_in_out,
8358+
extruder_colours);
8359+
8360+
bool colors_accepted = false;
8361+
8362+
if (color_import_mode == "auto") {
8363+
colors_accepted =
8364+
color_dlg.apply_default_mapping();
8365+
8366+
if (!colors_accepted) {
8367+
BOOST_LOG_TRIVIAL(warning)
8368+
<< "Standard 3MF automatic color mapping "
8369+
"was incomplete; showing the import dialog";
8370+
}
8371+
}
8372+
8373+
if (color_import_mode != "auto" ||
8374+
!colors_accepted) {
8375+
colors_accepted =
8376+
color_dlg.ShowModal() == wxID_OK;
8377+
}
8378+
8379+
if (colors_accepted)
8380+
color_dialog_in_out.filament_ids.clear();
83538381
}
83548382
}
83558383
}

src/slic3r/GUI/Preferences.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1385,6 +1385,28 @@ wxWindow* PreferencesDialog::create_general_page()
13851385
auto item_gamma_correct_in_import_obj = create_item_checkbox(_L("Enable gamma correction for the imported obj file"), page,
13861386
_L("Perform gamma correction on color after importing the obj model."), 50,
13871387
"gamma_correct_in_import_obj");
1388+
1389+
std::vector<wxString> standard_3mf_color_import_labels = {
1390+
_L("Ask every time"),
1391+
_L("Apply automatic color mapping"),
1392+
_L("Import geometry only")
1393+
};
1394+
std::vector<std::string> standard_3mf_color_import_values = {
1395+
"ask",
1396+
"auto",
1397+
"geometry_only"
1398+
};
1399+
auto item_standard_3mf_color_import = create_item_combobox(
1400+
_L("Standard 3MF color import"),
1401+
page,
1402+
_L("Choose how color information from standard 3MF files is handled during import."),
1403+
"standard_3mf_color_import_mode",
1404+
standard_3mf_color_import_labels,
1405+
standard_3mf_color_import_values,
1406+
nullptr,
1407+
FromDIP(180),
1408+
FromDIP(190));
1409+
13881410
auto item_enable_record_gcodeviewer_option_item = create_item_checkbox(_L("Remember last used color scheme"), page,
13891411
_L("When enabled, the last used color scheme (e.g., Line Type, Speed) will be automatically applied on next startup."), 50,
13901412
"enable_record_gcodeviewer_option_item");
@@ -1552,6 +1574,7 @@ wxWindow* PreferencesDialog::create_general_page()
15521574
sizer_page->Add(item_show_shells_in_preview_settings, 0, wxTOP, FromDIP(3));
15531575
sizer_page->Add(item_import_single_svg_and_split, 0, wxTOP, FromDIP(3));
15541576
sizer_page->Add(item_gamma_correct_in_import_obj, 0, wxTOP, FromDIP(3));
1577+
sizer_page->Add(item_standard_3mf_color_import, 0, wxTOP, FromDIP(3));
15551578
sizer_page->Add(item_enable_record_gcodeviewer_option_item, 0, wxTOP, FromDIP(3));
15561579
sizer_page->Add(enable_assemble_view_preview_settings, 0, wxTOP, FromDIP(3));
15571580
#if !BBL_RELEASE_TO_PUBLIC

0 commit comments

Comments
 (0)