From 47e817a9a3a92dc5c0ae3fe84e70e3580f210d4d Mon Sep 17 00:00:00 2001 From: supermerill Date: Mon, 17 Aug 2020 15:41:20 +0200 Subject: [PATCH] #161 allow user-defined colours for the preview. --- resources/ui_layout/colors.ini | 15 +++++++++++++++ src/slic3r/GUI/GUI_Preview.cpp | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 resources/ui_layout/colors.ini diff --git a/resources/ui_layout/colors.ini b/resources/ui_layout/colors.ini new file mode 100644 index 000000000..16de83f66 --- /dev/null +++ b/resources/ui_layout/colors.ini @@ -0,0 +1,15 @@ +Perimeter = FFFF66 +External perimeter = FFA500 +Overhang perimeter = 0000FF +Internal infill = B1302A +Solid infill = D732D7 +Top solid infill = FF1A1A +Bridge infill = 9999FF +Thin wall = FFB000 +Gap fill = FFFFFF +Skirt = 845321 +Support material = 00FF00 +Support material interface = 008000 +Wipe tower = B3E3AB +Mill = B3B3B3 +Custom = 28CC94 \ No newline at end of file diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index 9c2f13126..322402417 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -21,9 +21,13 @@ #include #include +#include +#include + // this include must follow the wxWidgets ones or it won't compile on Windows -> see http://trac.wxwidgets.org/ticket/2421 #include "libslic3r/Print.hpp" #include "libslic3r/SLAPrint.hpp" +#include "libslic3r/FileParserError.hpp" namespace Slic3r { namespace GUI { @@ -330,6 +334,26 @@ bool Preview::init(wxWindow* parent, Bed3D& bed, Camera& camera, GLToolbar& view "Mill", "B3B3B3", "Custom", "28CC94" }; + + //try to laod colors from ui file + boost::property_tree::ptree tree_colors; + boost::filesystem::path path_colors = boost::filesystem::path(resources_dir()) / "ui_layout" / "colors.ini"; + try { + boost::nowide::ifstream ifs; + ifs.imbue(boost::locale::generator()("en_US.UTF-8")); + ifs.open(path_colors.string()); + boost::property_tree::read_ini(ifs, tree_colors); + } catch (const std::ifstream::failure &err) { + throw file_parser_error(std::string("The color file cannot be loaded. Reason: ") + err.what(), path_colors.string()); + } catch (const std::runtime_error &err) { + throw file_parser_error(std::string("Failed loading the color file. Reason: ") + err.what(), path_colors.string()); + } + + for (int i = 0; i < extrusion_roles_colors.size(); i += 2) { + std::string color_code = tree_colors.get(extrusion_roles_colors[i]); + extrusion_roles_colors[i + 1] = color_code; + } + m_gcode_preview_data->set_extrusion_paths_colors(extrusion_roles_colors); return true;