ENH:remember filament custom color
Jira: STUDIO-5635 Change-Id: Id7f7204851c6bc3975c8447db4b8ee7d2e9c6d9d
This commit is contained in:
parent
0abc30ebe2
commit
4f5d15be34
|
@ -1188,6 +1188,38 @@ bool AppConfig::is_engineering_region(){
|
|||
return false;
|
||||
}
|
||||
|
||||
void AppConfig::save_custom_color_to_config(const std::vector<std::string> &colors)
|
||||
{
|
||||
auto set_colors = [](std::map<std::string, std::string> &data, const std::vector<std::string> &colors) {
|
||||
for (size_t i = 0; i < colors.size(); i++) {
|
||||
data[std::to_string(10 + i)] = colors[i]; // for map sort:10 begin
|
||||
}
|
||||
};
|
||||
if (colors.size() > 0) {
|
||||
if (!has_section("custom_color_list")) {
|
||||
std::map<std::string, std::string> data;
|
||||
set_colors(data, colors);
|
||||
set_section("custom_color_list", data);
|
||||
} else {
|
||||
auto data = get_section("custom_color_list");
|
||||
auto data_modify = const_cast<std::map<std::string, std::string> *>(&data);
|
||||
set_colors(*data_modify, colors);
|
||||
set_section("custom_color_list", *data_modify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> AppConfig::get_custom_color_from_config()
|
||||
{
|
||||
std::vector<std::string> colors;
|
||||
if (has_section("custom_color_list")) {
|
||||
auto data = get_section("custom_color_list");
|
||||
for (auto iter : data) {
|
||||
colors.push_back(iter.second);
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
|
||||
void AppConfig::reset_selections()
|
||||
{
|
||||
|
|
|
@ -200,6 +200,8 @@ public:
|
|||
std::string get_country_code();
|
||||
bool is_engineering_region();
|
||||
|
||||
void save_custom_color_to_config(const std::vector<std::string> &colors);
|
||||
std::vector<std::string> get_custom_color_from_config();
|
||||
// reset the current print / filament / printer selections, so that
|
||||
// the PresetBundle::load_selections(const AppConfig &config) call will select
|
||||
// the first non-default preset when called.
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#include <wx/colordlg.h>
|
||||
#include <wx/dcgraph.h>
|
||||
#include "CalibUtils.hpp"
|
||||
|
||||
#include "../Utils/ColorSpaceConvert.hpp"
|
||||
namespace Slic3r { namespace GUI {
|
||||
|
||||
wxDEFINE_EVENT(EVT_SELECTED_COLOR, wxCommandEvent);
|
||||
|
@ -1392,11 +1392,22 @@ ColorPickerPopup::ColorPickerPopup(wxWindow* parent)
|
|||
|
||||
void ColorPickerPopup::on_custom_clr_picker(wxMouseEvent& event)
|
||||
{
|
||||
std::vector<std::string> colors = wxGetApp().app_config->get_custom_color_from_config();
|
||||
for (int i = 0; i < colors.size(); i++) {
|
||||
m_clrData->SetCustomColour(i, string_to_wxColor(colors[i]));
|
||||
}
|
||||
auto clr_dialog = new wxColourDialog(nullptr, m_clrData);
|
||||
wxColour picker_color;
|
||||
|
||||
if (clr_dialog->ShowModal() == wxID_OK) {
|
||||
m_clrData = &(clr_dialog->GetColourData());
|
||||
if (colors.size() != CUSTOM_COLOR_COUNT) {
|
||||
colors.resize(CUSTOM_COLOR_COUNT);
|
||||
}
|
||||
for (int i = 0; i < CUSTOM_COLOR_COUNT; i++) {
|
||||
colors[i] = color_to_string(m_clrData->GetCustomColour(i));
|
||||
}
|
||||
wxGetApp().app_config->save_custom_color_to_config(colors);
|
||||
|
||||
picker_color = wxColour(
|
||||
m_clrData->GetColour().Red(),
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "Widgets/ComboBox.hpp"
|
||||
#include "Widgets/TextCtrl.h"
|
||||
|
||||
#include "../Utils/ColorSpaceConvert.hpp"
|
||||
#ifdef __WXOSX__
|
||||
#define wxOSX true
|
||||
#else
|
||||
|
@ -1568,6 +1569,7 @@ void ColourPicker::BUILD()
|
|||
if (parent_is_custom_ctrl && m_opt.height < 0)
|
||||
opt_height = (double)temp->GetSize().GetHeight() / m_em_unit;
|
||||
temp->SetFont(Slic3r::GUI::wxGetApp().normal_font());
|
||||
convert_to_picker_widget(temp);
|
||||
if (!wxOSX) temp->SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||
|
||||
wxGetApp().UpdateDarkUI(temp->GetPickerCtrl());
|
||||
|
@ -1624,6 +1626,7 @@ void ColourPicker::set_value(const boost::any& value, bool change_event)
|
|||
|
||||
boost::any& ColourPicker::get_value()
|
||||
{
|
||||
save_colors_to_config();
|
||||
auto colour = static_cast<wxColourPickerCtrl*>(window)->GetColour();
|
||||
if (colour == wxTransparentColour)
|
||||
m_value = std::string("");
|
||||
|
@ -1663,6 +1666,44 @@ void ColourPicker::sys_color_changed()
|
|||
#endif
|
||||
}
|
||||
|
||||
void ColourPicker::on_button_click(wxCommandEvent &event) {
|
||||
#if !defined(__linux__) && !defined(__LINUX__)
|
||||
if (m_clrData) {
|
||||
std::vector<std::string> colors = wxGetApp().app_config->get_custom_color_from_config();
|
||||
for (int i = 0; i < colors.size(); i++) {
|
||||
m_clrData->SetCustomColour(i, string_to_wxColor(colors[i]));
|
||||
}
|
||||
}
|
||||
m_picker_widget->OnButtonClick(event);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ColourPicker::convert_to_picker_widget(wxColourPickerCtrl *widget)
|
||||
{
|
||||
#if !defined(__linux__) && !defined(__LINUX__)
|
||||
m_picker_widget = dynamic_cast<wxColourPickerWidget*>(widget->GetPickerCtrl());
|
||||
if (m_picker_widget) {
|
||||
m_picker_widget->Bind(wxEVT_BUTTON, &ColourPicker::on_button_click, this);
|
||||
m_clrData = m_picker_widget->GetColourData();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ColourPicker::save_colors_to_config() {
|
||||
#if !defined(__linux__) && !defined(__LINUX__)
|
||||
if (m_clrData) {
|
||||
std::vector<std::string> colors;
|
||||
if (colors.size() != CUSTOM_COLOR_COUNT) {
|
||||
colors.resize(CUSTOM_COLOR_COUNT);
|
||||
}
|
||||
for (int i = 0; i < CUSTOM_COLOR_COUNT; i++) {
|
||||
colors[i] = color_to_string(m_clrData->GetCustomColour(i));
|
||||
}
|
||||
wxGetApp().app_config->save_custom_color_to_config(colors);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void PointCtrl::BUILD()
|
||||
{
|
||||
auto temp = new wxBoxSizer(wxHORIZONTAL);
|
||||
|
|
|
@ -424,6 +424,14 @@ public:
|
|||
void enable() override { dynamic_cast<wxColourPickerCtrl*>(window)->Enable(); }
|
||||
void disable() override{ dynamic_cast<wxColourPickerCtrl*>(window)->Disable(); }
|
||||
wxWindow* getWindow() override { return window; }
|
||||
|
||||
private:
|
||||
void convert_to_picker_widget(wxColourPickerCtrl *widget);
|
||||
void on_button_click(wxCommandEvent &WXUNUSED(ev));
|
||||
void save_colors_to_config();
|
||||
private:
|
||||
wxColourData* m_clrData{nullptr};
|
||||
wxColourPickerWidget* m_picker_widget{nullptr};
|
||||
};
|
||||
|
||||
class PointCtrl : public Field {
|
||||
|
|
|
@ -35,6 +35,7 @@
|
|||
#include "../Utils/ASCIIFolding.hpp"
|
||||
#include "../Utils/FixModelByWin10.hpp"
|
||||
#include "../Utils/UndoRedo.hpp"
|
||||
#include "../Utils/ColorSpaceConvert.hpp"
|
||||
#include "BitmapCache.hpp"
|
||||
#include "SavePresetDialog.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
|
@ -625,37 +626,6 @@ bool PresetComboBox::selection_is_changed_according_to_physical_printers()
|
|||
return true;
|
||||
}
|
||||
|
||||
void PlaterPresetComboBox::save_custom_color_to_config(const std::vector<std::string>& colors)
|
||||
{
|
||||
auto set_colors = [](std::map<std::string, std::string> &data, const std::vector<std::string> &colors) {
|
||||
for (size_t i = 0; i < colors.size(); i++) {
|
||||
data[std::to_string(10 + i)] = colors[i]; //for map sort:10 begin
|
||||
}
|
||||
};
|
||||
if (colors.size() > 0) {
|
||||
if (!wxGetApp().app_config->has_section("custom_color_list")) {
|
||||
std::map<std::string, std::string> data;
|
||||
set_colors(data,colors);
|
||||
wxGetApp().app_config->set_section("custom_color_list", data);
|
||||
} else {
|
||||
auto data = wxGetApp().app_config->get_section("custom_color_list");
|
||||
auto data_modify = const_cast<std::map<std::string, std::string> *>(&data);
|
||||
set_colors(*data_modify, colors);
|
||||
wxGetApp().app_config->set_section("custom_color_list", *data_modify);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> PlaterPresetComboBox::get_custom_color_from_config() {
|
||||
std::vector<std::string> colors;
|
||||
if (wxGetApp().app_config->has_section("custom_color_list")) {
|
||||
auto data = wxGetApp().app_config->get_section("custom_color_list");
|
||||
for (auto iter : data) {
|
||||
colors.push_back(iter.second);
|
||||
}
|
||||
}
|
||||
return colors;
|
||||
}
|
||||
// ---------------------------------
|
||||
// *** PlaterPresetComboBox ***
|
||||
// ---------------------------------
|
||||
|
@ -704,20 +674,8 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
|
|||
m_clrData.SetColour(clr_picker->GetBackgroundColour());
|
||||
m_clrData.SetChooseFull(true);
|
||||
m_clrData.SetChooseAlpha(false);
|
||||
auto color_to_string = [](const wxColour& color) {
|
||||
std::string str = std::to_string(color.Red()) + "," + std::to_string(color.Green()) + "," + std::to_string(color.Blue()) + "," + std::to_string(color.Alpha());
|
||||
return str;
|
||||
};
|
||||
auto string_to_wxColor = [](const std::string& str) {
|
||||
wxColour color;
|
||||
std::vector<std::string> result;
|
||||
boost::split(result, str, boost::is_any_of(","));
|
||||
if (result.size() == 4) {
|
||||
color = wxColour(std::stoi(result[0]), std::stoi(result[1]), std::stoi(result[2]), std::stoi(result[3]));
|
||||
}
|
||||
return color;
|
||||
};
|
||||
std::vector<std::string> colors=get_custom_color_from_config();
|
||||
|
||||
std::vector<std::string> colors = wxGetApp().app_config->get_custom_color_from_config();
|
||||
for (int i = 0; i < colors.size(); i++) {
|
||||
m_clrData.SetCustomColour(i, string_to_wxColor(colors[i]));
|
||||
}
|
||||
|
@ -726,13 +684,13 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
|
|||
if ( dialog.ShowModal() == wxID_OK )
|
||||
{
|
||||
m_clrData = dialog.GetColourData();
|
||||
const int custom_color_count = 15;
|
||||
if (colors.size() != custom_color_count) {
|
||||
colors.resize(custom_color_count); }
|
||||
for (int i = 0; i < custom_color_count; i++) {
|
||||
if (colors.size() != CUSTOM_COLOR_COUNT) {
|
||||
colors.resize(CUSTOM_COLOR_COUNT);
|
||||
}
|
||||
for (int i = 0; i < CUSTOM_COLOR_COUNT; i++) {
|
||||
colors[i] = color_to_string(m_clrData.GetCustomColour(i));
|
||||
}
|
||||
save_custom_color_to_config(colors);
|
||||
wxGetApp().app_config->save_custom_color_to_config(colors);
|
||||
// get current color
|
||||
DynamicPrintConfig* cfg = &wxGetApp().preset_bundle->project_config;
|
||||
auto colors = static_cast<ConfigOptionStrings*>(cfg->option("filament_colour")->clone());
|
||||
|
|
|
@ -164,8 +164,6 @@ public:
|
|||
PlaterPresetComboBox(wxWindow *parent, Preset::Type preset_type);
|
||||
~PlaterPresetComboBox();
|
||||
|
||||
void save_custom_color_to_config(const std::vector<std::string> &colors);
|
||||
std::vector<std::string> get_custom_color_from_config();
|
||||
ScalableButton* edit_btn { nullptr };
|
||||
|
||||
// BBS
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
#include "ColorSpaceConvert.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
||||
#include <wx/colordlg.h>
|
||||
const static float param_13 = 1.0f / 3.0f;
|
||||
const static float param_16116 = 16.0f / 116.0f;
|
||||
const static float Xn = 0.950456f;
|
||||
|
@ -234,3 +233,19 @@ float DeltaE76(float l1, float a1, float b1, float l2, float a2, float b2)
|
|||
return std::sqrt(std::pow((l1 - l2), 2) + std::pow((a1 - a2), 2) + std::pow((b1 - b2), 2));
|
||||
}
|
||||
|
||||
std::string color_to_string(const wxColour &color)
|
||||
{
|
||||
std::string str = std::to_string(color.Red()) + "," + std::to_string(color.Green()) + "," + std::to_string(color.Blue()) + "," + std::to_string(color.Alpha());
|
||||
return str;
|
||||
}
|
||||
|
||||
wxColour string_to_wxColor(const std::string &str)
|
||||
{
|
||||
wxColour color;
|
||||
std::vector<std::string> result;
|
||||
boost::split(result, str, boost::is_any_of(","));
|
||||
if (result.size() == 4) {
|
||||
color = wxColour(std::stoi(result[0]), std::stoi(result[1]), std::stoi(result[2]), std::stoi(result[3]));
|
||||
}
|
||||
return color;
|
||||
};
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#ifndef slic3r_Utils_ColorSpaceConvert_hpp_
|
||||
#define slic3r_Utils_ColorSpaceConvert_hpp_
|
||||
#include <string>
|
||||
const int CUSTOM_COLOR_COUNT = 16;
|
||||
|
||||
#include <tuple>
|
||||
|
||||
|
@ -18,4 +20,7 @@ float DeltaE00(float l1, float a1, float b1, float l2, float a2, float b2);
|
|||
float DeltaE94(float l1, float a1, float b1, float l2, float a2, float b2);
|
||||
float DeltaE76(float l1, float a1, float b1, float l2, float a2, float b2);
|
||||
|
||||
class wxColour;
|
||||
std::string color_to_string(const wxColour &color);
|
||||
wxColour string_to_wxColor(const std::string &str);
|
||||
#endif /* slic3r_Utils_ColorSpaceConvert_hpp_ */
|
||||
|
|
Loading…
Reference in New Issue