From 5a28693ff42589084c467f4991882fac6504204c Mon Sep 17 00:00:00 2001 From: YuSanka Date: Wed, 30 Jan 2019 14:45:18 +0100 Subject: [PATCH 1/2] Updated draw_colored_band() according to the new colors. + some code refactoring --- src/slic3r/GUI/GLCanvas3D.cpp | 4 ++-- src/slic3r/GUI/GUI_ObjectList.cpp | 14 ++++---------- src/slic3r/GUI/GUI_ObjectList.hpp | 3 --- src/slic3r/GUI/GUI_Preview.cpp | 2 +- src/slic3r/GUI/wxExtensions.cpp | 14 +++++++------- 5 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 65e8cd3fb..982ac4a26 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -3753,7 +3753,7 @@ void GLCanvas3D::LegendTexture::fill_color_print_legend_values(const GCodePrevie { if (preview_data.extrusion.view_type == GCodePreviewData::Extrusion::ColorPrint) { - const auto& config = wxGetApp().preset_bundle->full_config(); + auto& config = wxGetApp().preset_bundle->project_config; const std::vector& color_print_values = config.option("colorprint_heights")->values; const int values_cnt = color_print_values.size(); if (values_cnt > 0) { @@ -7295,7 +7295,7 @@ void GLCanvas3D::_load_print_object_toolpaths(const PrintObject& print_object, c bool color_by_color_print() const { return color_print_values!=nullptr; } const float* color_print_by_layer_idx(const size_t layer_idx) const { - auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z - EPSILON); + auto it = std::lower_bound(color_print_values->begin(), color_print_values->end(), layers[layer_idx]->print_z + EPSILON); return color_tool((it - color_print_values->begin()) % number_tools()); } } ctxt; diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index a38248d3a..c2f9a4a5c 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -100,8 +100,6 @@ ObjectList::ObjectList(wxWindow* parent) : ObjectList::~ObjectList() { - if (m_default_config) - delete m_default_config; } void ObjectList::create_objects_ctrl() @@ -749,10 +747,8 @@ void ObjectList::get_settings_choice(const wxString& category_name) const ConfigOption* option = from_config.option(opt_key); if (!option) { // if current option doesn't exist in prints.get_edited_preset(), - // get it from m_default_config - if (m_default_config) delete m_default_config; - m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false)); - option = m_default_config->option(opt_key); + // get it from default config values + option = DynamicPrintConfig::new_from_defaults_keys({ opt_key })->option(opt_key); } m_config->set_key_value(opt_key, option->clone()); } @@ -776,10 +772,8 @@ void ObjectList::get_freq_settings_choice(const wxString& bundle_name) const ConfigOption* option = from_config.option(opt_key); if (!option) { // if current option doesn't exist in prints.get_edited_preset(), - // get it from m_default_config - if (m_default_config) delete m_default_config; - m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(false)); - option = m_default_config->option(opt_key); + // get it from default config values + option = DynamicPrintConfig::new_from_defaults_keys({ opt_key })->option(opt_key); } m_config->set_key_value(opt_key, option->clone()); } diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 86e2167dd..66e142394 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -97,9 +97,6 @@ class ObjectList : public wxDataViewCtrl } m_dragged_data; wxBoxSizer *m_sizer {nullptr}; - - DynamicPrintConfig *m_default_config {nullptr}; - wxWindow *m_parent {nullptr}; wxBitmap m_bmp_modifiermesh; diff --git a/src/slic3r/GUI/GUI_Preview.cpp b/src/slic3r/GUI/GUI_Preview.cpp index c2a769586..b594d0fef 100644 --- a/src/slic3r/GUI/GUI_Preview.cpp +++ b/src/slic3r/GUI/GUI_Preview.cpp @@ -740,7 +740,7 @@ void Preview::load_print_as_fff() if (! gcode_preview_data_valid) { //FIXME accessing full_config() is pretty expensive. // Only initialize color_print_values for the initial preview, not for the full preview where the color_print_values is extracted from the G-code. - const auto& config = wxGetApp().preset_bundle->full_config(); + const auto& config = wxGetApp().preset_bundle->project_config; color_print_values = config.option("colorprint_heights")->values; } } diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 238a36c74..d24db63ea 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1668,7 +1668,7 @@ void PrusaDoubleSlider::render() // draw colored band on the background of a scroll line // and only in a case of no-empty m_values -// draw_colored_band(dc); + draw_colored_band(dc); // draw line draw_scroll_line(dc, lower_pos, higher_pos); @@ -1867,8 +1867,10 @@ void PrusaDoubleSlider::draw_colored_band(wxDC& dc) return; } - const std::vector& clr_bytes = Slic3r::GCodePreviewData::Range::Default_Colors[0].as_bytes(); - wxColour clr = wxColour(clr_bytes[0], clr_bytes[1], clr_bytes[2], clr_bytes[3]); + const std::vector& colors = Slic3r::GCodePreviewData::ColorPrintColors(); + const size_t colors_cnt = colors.size(); + + wxColour clr(colors[0]); dc.SetPen(clr); dc.SetBrush(clr); dc.DrawRectangle(main_band); @@ -1876,15 +1878,13 @@ void PrusaDoubleSlider::draw_colored_band(wxDC& dc) int i = 1; for (auto tick : m_ticks) { - if (i == Slic3r::GCodePreviewData::Range::Colors_Count) + if (i == colors_cnt) i = 0; const wxCoord pos = get_position_from_value(tick); is_horizontal() ? main_band.SetLeft(SLIDER_MARGIN + pos) : main_band.SetBottom(pos-1); - const std::vector& clr_b = Slic3r::GCodePreviewData::Range::Default_Colors[i].as_bytes(); - - clr = wxColour(clr_b[0], clr_b[1], clr_b[2], clr_b[3]); + clr = wxColour(colors[i]); dc.SetPen(clr); dc.SetBrush(clr); dc.DrawRectangle(main_band); From eec289961ac81c0d631be132360acd681f01f379 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Wed, 30 Jan 2019 15:27:11 +0100 Subject: [PATCH 2/2] Removed Microsoft specific _DEBUG flag from the Unix systems. Made condional compilation of assert code based on #ifndef NDEBUG instead of #ifdef _DEBUG to compile on Unix systems. --- CMakeLists.txt | 3 +-- src/slic3r/GUI/GLCanvas3D.cpp | 16 ++++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 4e42e24e9..90ebd1e5b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,9 +86,8 @@ set(CMAKE_C_STANDARD 11) set(CMAKE_C_STANDARD_REQUIRED ON) if(NOT WIN32) - # Add DEBUG flags for the debug builds in a way the Visual Studio adds these flags. + # Add DEBUG flags to debug builds. add_compile_options("$<$:-DDEBUG>") - add_compile_options("$<$:-D_DEBUG>") endif() # To be able to link libslic3r with the Perl XS module. diff --git a/src/slic3r/GUI/GLCanvas3D.cpp b/src/slic3r/GUI/GLCanvas3D.cpp index 982ac4a26..de3c2e6aa 100644 --- a/src/slic3r/GUI/GLCanvas3D.cpp +++ b/src/slic3r/GUI/GLCanvas3D.cpp @@ -1793,12 +1793,12 @@ static double rotation_diff_z(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to Eigen::AngleAxisd angle_axis(rotation_xyz_diff(rot_xyz_from, rot_xyz_to)); Vec3d axis = angle_axis.axis(); double angle = angle_axis.angle(); -#ifdef _DEBUG +#ifndef NDEBUG if (std::abs(angle) > 1e-8) { assert(std::abs(axis.x()) < 1e-8); assert(std::abs(axis.y()) < 1e-8); } -#endif /* _DEBUG */ +#endif /* NDEBUG */ return (axis.z() < 0) ? -angle : angle; } @@ -2786,7 +2786,7 @@ void GLCanvas3D::Selection::_render_sidebar_size_hint(Axis axis, double length) { } -#ifdef _DEBUG +#ifndef NDEBUG static bool is_rotation_xy_synchronized(const Vec3d &rot_xyz_from, const Vec3d &rot_xyz_to) { Eigen::AngleAxisd angle_axis(rotation_xyz_diff(rot_xyz_from, rot_xyz_to)); @@ -2820,7 +2820,7 @@ static void verify_instances_rotation_synchronized(const Model &model, const GLV } } } -#endif /* _DEBUG */ +#endif /* NDEBUG */ void GLCanvas3D::Selection::_synchronize_unselected_instances(SyncRotationType sync_rotation_type) { @@ -2880,9 +2880,9 @@ void GLCanvas3D::Selection::_synchronize_unselected_instances(SyncRotationType s } } -#ifdef _DEBUG +#ifndef NDEBUG verify_instances_rotation_synchronized(*m_model, *m_volumes); -#endif /* _DEBUG */ +#endif /* NDEBUG */ } void GLCanvas3D::Selection::_synchronize_unselected_volumes() @@ -4681,10 +4681,10 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re } if (printer_technology == ptSLA) { const SLAPrint *sla_print = this->sla_print(); - #ifdef _DEBUG + #ifndef NDEBUG // Verify that the SLAPrint object is synchronized with m_model. check_model_ids_equal(*m_model, sla_print->model()); - #endif /* _DEBUG */ + #endif /* NDEBUG */ sla_support_state.reserve(sla_print->objects().size()); for (const SLAPrintObject *print_object : sla_print->objects()) { SLASupportState state;