This commit is contained in:
Vojtech Bubnik 2021-02-09 18:36:36 +01:00
commit 5a638f10cc
7 changed files with 74 additions and 5 deletions

View file

@ -123,6 +123,9 @@ void AppConfig::set_defaults()
if (get("default_action_on_select_preset").empty())
set("default_action_on_select_preset", "none"); // , "transfer", "discard" or "save"
if (get("color_mapinulation_panel").empty())
set("color_mapinulation_panel", "0");
}
#if ENABLE_CUSTOMIZABLE_FILES_ASSOCIATION_ON_WIN
else {

View file

@ -472,6 +472,29 @@ void Model::convert_from_imperial_units(bool only_small_volumes)
}
}
bool Model::looks_like_saved_in_meters() const
{
if (this->objects.size() == 0)
return false;
for (ModelObject* obj : this->objects)
if (obj->get_object_stl_stats().volume < 0.001) // 0.001 = 0.1*0.1*0.1;
return true;
return false;
}
void Model::convert_from_meters(bool only_small_volumes)
{
double m_to_mm = 1000;
for (ModelObject* obj : this->objects)
if (! only_small_volumes || obj->get_object_stl_stats().volume < 0.001) { // 0.001 = 0.1*0.1*0.1;
obj->scale_mesh_after_creation(Vec3d(m_to_mm, m_to_mm, m_to_mm));
for (ModelVolume* v : obj->volumes)
v->source.is_converted_from_inches = true;
}
}
void Model::adjust_min_z()
{
if (objects.empty())

View file

@ -1019,6 +1019,8 @@ public:
void convert_multipart_object(unsigned int max_extruders);
bool looks_like_imperial_units() const;
void convert_from_imperial_units(bool only_small_volumes);
bool looks_like_saved_in_meters() const;
void convert_from_meters(bool only_small_volumes);
// Ensures that the min z of the model is not negative
void adjust_min_z();

View file

@ -109,10 +109,13 @@ static void set_font_and_background_style(wxWindow* win, const wxFont& font)
win->SetBackgroundStyle(wxBG_STYLE_PAINT);
}
static const wxString axes_color_text[] = { "#990000", "#009900", "#000099" };
static const wxString axes_color_back[] = { "#f5dcdc", "#dcf5dc", "#dcdcf5" };
ObjectManipulation::ObjectManipulation(wxWindow* parent) :
OG_Settings(parent, true)
{
m_imperial_units = wxGetApp().app_config->get("use_inches") == "1";
m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1";
m_manifold_warning_bmp = ScalableBitmap(parent, "exclamation");
@ -236,13 +239,14 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) :
// Add Axes labels with icons
static const char axes[] = { 'X', 'Y', 'Z' };
// std::vector<wxString> axes_color = {"#990000", "#009900","#000099"};
// std::vector<wxString> axes_color = {"#EE0000", "#00EE00", "#0000EE"};
for (size_t axis_idx = 0; axis_idx < sizeof(axes); axis_idx++) {
const char label = axes[axis_idx];
wxStaticText* axis_name = new wxStaticText(m_parent, wxID_ANY, wxString(label));
set_font_and_background_style(axis_name, wxGetApp().bold_font());
// axis_name->SetForegroundColour(wxColour(axes_color[axis_idx]));
//if (m_use_colors)
// axis_name->SetForegroundColour(wxColour(axes_color_text[axis_idx]));
sizer = new wxBoxSizer(wxHORIZONTAL);
// Under OSX we use font, smaller than default font, so
@ -481,8 +485,20 @@ void ObjectManipulation::update_ui_from_settings()
update(3/*meSize*/, m_new_size);
}
}
m_check_inch->SetValue(m_imperial_units);
if (m_use_colors != (wxGetApp().app_config->get("color_mapinulation_panel") == "1"))
{
m_use_colors = wxGetApp().app_config->get("color_mapinulation_panel") == "1";
// update colors for edit-boxes
int axis_id = 0;
for (ManipulationEditor* editor : m_editors) {
// editor->SetForegroundColour(m_use_colors ? wxColour(axes_color_text[axis_id]) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
editor->SetBackgroundColour(m_use_colors ? wxColour(axes_color_back[axis_id]) : wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
if (++axis_id == 3)
axis_id = 0;
}
}
}
void ObjectManipulation::update_settings_value(const Selection& selection)
@ -1000,6 +1016,10 @@ ManipulationEditor::ManipulationEditor(ObjectManipulation* parent,
#ifdef __WXOSX__
this->OSXDisableAllSmartSubstitutions();
#endif // __WXOSX__
if (parent->use_colors()) {
// this->SetForegroundColour(wxColour(axes_color_text[axis]));
this->SetBackgroundColour(wxColour(axes_color_back[axis]));
}
// A name used to call handle_sidebar_focus_event()
m_full_opt_name = m_opt_key+"_"+axes[axis];

View file

@ -95,6 +95,7 @@ private:
wxStaticText* m_rotate_Label = nullptr;
bool m_imperial_units { false };
bool m_use_colors { false };
wxStaticText* m_position_unit { nullptr };
wxStaticText* m_size_unit { nullptr };
@ -162,7 +163,8 @@ public:
void Show(const bool show) override;
bool IsShown() override;
void UpdateAndShow(const bool show) override;
void update_ui_from_settings();
void update_ui_from_settings();
bool use_colors() { return m_use_colors; }
void set_dirty() { m_dirty = true; }
// Called from the App to update the UI if dirty.

View file

@ -2415,13 +2415,24 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
auto convert_from_imperial_units = [](Model& model, bool only_small_volumes) {
model.convert_from_imperial_units(only_small_volumes);
// wxGetApp().app_config->set("use_inches", "1");
wxGetApp().sidebar().update_ui_from_settings();
// wxGetApp().sidebar().update_ui_from_settings();
};
if (!is_project_file) {
if (imperial_units)
// Convert even if the object is big.
convert_from_imperial_units(model, false);
else if (model.looks_like_saved_in_meters()) {
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
"The object in file %s looks like saved in meters.\n"
"Should I consider it as a saved in meters and convert it?",
"Some objects in file %s look like saved in meters.\n"
"Should I consider them as a saved in meters and convert them?", model.objects.size()), from_path(filename)) + "\n",
_L("The object appears to be saved in meters"), wxICON_WARNING | wxYES | wxNO);
if (msg_dlg.ShowModal() == wxID_YES)
//FIXME up-scale only the small parts?
model.convert_from_meters(true);
}
else if (model.looks_like_imperial_units()) {
wxMessageDialog msg_dlg(q, format_wxstr(_L_PLURAL(
"The object in file %s looks like saved in inches.\n"

View file

@ -297,6 +297,14 @@ void PreferencesDialog::build()
option = Option(def, "suppress_hyperlinks");
m_optgroup_gui->append_single_option_line(option);
def.label = L("Use colors for axes values in Manipulation panel");
def.type = coBool;
def.tooltip = L("If enabled, the axes names and axes values will be colorized according to the axes colors. "
"If disabled, old UI will be used.");
def.set_default_value(new ConfigOptionBool{ app_config->get("color_mapinulation_panel") == "1" });
option = Option(def, "color_mapinulation_panel");
m_optgroup_gui->append_single_option_line(option);
def.label = L("Use custom size for toolbar icons");
def.type = coBool;
def.tooltip = L("If enabled, you can change size of toolbar icons manually.");