mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-11 08:47:52 -06:00
Update for PresetComboBoxes
All "Printer-PresetName" pairs are like a separated items now + some code refactoring for PresetComboBoxes::update()
This commit is contained in:
parent
c5197f3350
commit
5eac36a310
8 changed files with 489 additions and 270 deletions
|
@ -63,8 +63,7 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const
|
|||
m_type(preset_type),
|
||||
m_last_selected(wxNOT_FOUND),
|
||||
m_em_unit(em_unit(this)),
|
||||
m_preset_bundle(wxGetApp().preset_bundle),
|
||||
m_bitmap_cache(new BitmapCache)
|
||||
m_preset_bundle(wxGetApp().preset_bundle)
|
||||
{
|
||||
SetFont(wxGetApp().normal_font());
|
||||
#ifdef _WIN32
|
||||
|
@ -105,17 +104,31 @@ PresetComboBox::PresetComboBox(wxWindow* parent, Preset::Type preset_type, const
|
|||
|
||||
m_bitmapCompatible = ScalableBitmap(this, "flag_green");
|
||||
m_bitmapIncompatible = ScalableBitmap(this, "flag_red");
|
||||
m_bitmapLock = ScalableBitmap(this, "lock_closed");
|
||||
m_bitmapLockDisabled = ScalableBitmap(this, "lock_closed", 16, true);
|
||||
|
||||
// parameters for an icon's drawing
|
||||
fill_width_height();
|
||||
|
||||
Bind(wxEVT_COMBOBOX, [this](wxCommandEvent& evt) {
|
||||
// see https://github.com/prusa3d/PrusaSlicer/issues/3889
|
||||
// Under OSX: in case of use of a same names written in different case (like "ENDER" and "Ender")
|
||||
// m_presets_choice->GetSelection() will return first item, because search in PopupListCtrl is case-insensitive.
|
||||
// So, use GetSelection() from event parameter
|
||||
auto selected_item = evt.GetSelection();
|
||||
|
||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||
if (marker >= LABEL_ITEM_DISABLED && marker < LABEL_ITEM_MAX)
|
||||
this->SetSelection(this->m_last_selected);
|
||||
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty())) {
|
||||
m_last_selected = selected_item;
|
||||
on_selection_changed(selected_item);
|
||||
evt.StopPropagation();
|
||||
}
|
||||
evt.Skip();
|
||||
});
|
||||
}
|
||||
|
||||
PresetComboBox::~PresetComboBox()
|
||||
{
|
||||
delete m_bitmap_cache;
|
||||
m_bitmap_cache = nullptr;
|
||||
}
|
||||
|
||||
void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type)
|
||||
|
@ -123,12 +136,96 @@ void PresetComboBox::set_label_marker(int item, LabelItemType label_item_type)
|
|||
this->SetClientData(item, (void*)label_item_type);
|
||||
}
|
||||
|
||||
void PresetComboBox::update(const std::string& select_preset_name)
|
||||
{
|
||||
Freeze();
|
||||
Clear();
|
||||
size_t selected_preset_item = INT_MAX; // some value meaning that no one item is selected
|
||||
|
||||
const std::deque<Preset>& presets = m_collection->get_presets();
|
||||
|
||||
std::map<wxString, std::pair<wxBitmap*, bool>> nonsys_presets;
|
||||
wxString selected = "";
|
||||
if (!presets.front().is_visible)
|
||||
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||
|
||||
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i)
|
||||
{
|
||||
const Preset& preset = presets[i];
|
||||
if (!preset.is_visible || !preset.is_compatible)
|
||||
continue;
|
||||
|
||||
// marker used for disable incompatible printer models for the selected physical printer
|
||||
bool is_enabled = true;
|
||||
|
||||
std::string bitmap_key = "tab";
|
||||
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
bitmap_key += "_printer";
|
||||
if (preset.printer_technology() == ptSLA)
|
||||
bitmap_key += "_sla";
|
||||
if (!is_enabled)
|
||||
bitmap_key += "_disabled";
|
||||
}
|
||||
bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt";
|
||||
bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst";
|
||||
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default);
|
||||
assert(bmp);
|
||||
|
||||
if (preset.is_default || preset.is_system) {
|
||||
int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
|
||||
if (!is_enabled)
|
||||
set_label_marker(item_id, LABEL_ITEM_DISABLED);
|
||||
if (preset.name == select_preset_name ||//i == idx_selected ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::pair<wxBitmap*, bool> pair(bmp, is_enabled);
|
||||
nonsys_presets.emplace(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), std::pair<wxBitmap*, bool>(bmp, is_enabled));
|
||||
if (preset.name == select_preset_name)
|
||||
selected = wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str());
|
||||
}
|
||||
if (i + 1 == m_collection->num_default_presets())
|
||||
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||
}
|
||||
if (!nonsys_presets.empty())
|
||||
{
|
||||
set_label_marker(Append(separator(L("User presets")), wxNullBitmap));
|
||||
for (std::map<wxString, std::pair<wxBitmap*, bool>>::iterator it = nonsys_presets.begin(); it != nonsys_presets.end(); ++it) {
|
||||
int item_id = Append(it->first, *it->second.first);
|
||||
bool is_enabled = it->second.second;
|
||||
if (!is_enabled)
|
||||
set_label_marker(item_id, LABEL_ITEM_DISABLED);
|
||||
if (it->first == selected ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
}
|
||||
}
|
||||
|
||||
/* But, if selected_preset_item is still equal to INT_MAX, it means that
|
||||
* there is no presets added to the list.
|
||||
* So, select last combobox item ("Add/Remove preset")
|
||||
*/
|
||||
if (selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
|
||||
SetSelection(selected_preset_item);
|
||||
SetToolTip(GetString(selected_preset_item));
|
||||
Thaw();
|
||||
|
||||
m_last_selected = selected_preset_item;
|
||||
}
|
||||
|
||||
void PresetComboBox::msw_rescale()
|
||||
{
|
||||
m_em_unit = em_unit(this);
|
||||
|
||||
m_bitmapLock.msw_rescale();
|
||||
m_bitmapLockDisabled.msw_rescale();
|
||||
m_bitmapIncompatible.msw_rescale();
|
||||
m_bitmapCompatible.msw_rescale();
|
||||
|
||||
|
@ -142,9 +239,9 @@ void PresetComboBox::msw_rescale()
|
|||
void PresetComboBox::fill_width_height()
|
||||
{
|
||||
// To avoid asserts, each added bitmap to wxBitmapCombobox should be the same size, so
|
||||
// set a bitmap's height to m_bitmapLock->GetHeight() and norm_icon_width to m_bitmapLock->GetWidth()
|
||||
icon_height = m_bitmapLock.GetBmpHeight();
|
||||
norm_icon_width = m_bitmapLock.GetBmpWidth();
|
||||
// set a bitmap's height to m_bitmapCompatible->GetHeight() and norm_icon_width to m_bitmapCompatible->GetWidth()
|
||||
icon_height = m_bitmapCompatible.GetBmpHeight();
|
||||
norm_icon_width = m_bitmapCompatible.GetBmpWidth();
|
||||
|
||||
/* It's supposed that standard size of an icon is 16px*16px for 100% scaled display.
|
||||
* So set sizes for solid_colored icons used for filament preset
|
||||
|
@ -165,6 +262,110 @@ wxString PresetComboBox::separator(const std::string& label)
|
|||
return wxString::FromUTF8(separator_head()) + _(label) + wxString::FromUTF8(separator_tail());
|
||||
}
|
||||
|
||||
wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, bool wide_icons, const std::string& main_icon_name,
|
||||
bool is_compatible/* = true*/, bool is_system/* = false*/, bool is_single_bar/* = false*/,
|
||||
std::string filament_rgb/* = ""*/, std::string extruder_rgb/* = ""*/)
|
||||
{
|
||||
bitmap_key += ",h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = bitmap_cache().find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
if (wide_icons)
|
||||
// Paint a red flag for incompatible presets.
|
||||
bmps.emplace_back(is_compatible ? bitmap_cache().mkclear(norm_icon_width, icon_height) : m_bitmapIncompatible.bmp());
|
||||
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
unsigned char rgb[3];
|
||||
// Paint the color bars.
|
||||
bitmap_cache().parse_color(filament_rgb, rgb);
|
||||
bmps.emplace_back(bitmap_cache().mksolid(is_single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb));
|
||||
if (!is_single_bar) {
|
||||
bitmap_cache().parse_color(extruder_rgb, rgb);
|
||||
bmps.emplace_back(bitmap_cache().mksolid(thin_icon_width, icon_height, rgb));
|
||||
}
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(bitmap_cache().mkclear(space_icon_width, icon_height));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Paint the color bars.
|
||||
bmps.emplace_back(bitmap_cache().mkclear(thin_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap(main_icon_name));
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(bitmap_cache().mkclear(wide_space_icon_width, icon_height));
|
||||
}
|
||||
bmps.emplace_back(is_system ? create_scaled_bitmap("lock_closed") : bitmap_cache().mkclear(norm_icon_width, icon_height));
|
||||
bmp = bitmap_cache().insert(bitmap_key, bmps);
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
wxBitmap* PresetComboBox::get_bmp( std::string bitmap_key, const std::string& main_icon_name, const std::string& next_icon_name,
|
||||
bool is_enabled/* = true*/, bool is_compatible/* = true*/, bool is_system/* = false*/)
|
||||
{
|
||||
bitmap_key += ",h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = bitmap_cache().find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
bmps.emplace_back(m_type == Preset::TYPE_PRINTER ? create_scaled_bitmap(main_icon_name, this, 16, !is_enabled) :
|
||||
is_compatible ? m_bitmapCompatible.bmp() : m_bitmapIncompatible.bmp());
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(is_system ? create_scaled_bitmap(next_icon_name, this, 16, !is_enabled) : bitmap_cache().mkclear(norm_icon_width, icon_height));
|
||||
bmp = bitmap_cache().insert(bitmap_key, bmps);
|
||||
}
|
||||
|
||||
return bmp;
|
||||
}
|
||||
|
||||
bool PresetComboBox::is_selected_physical_printer()
|
||||
{
|
||||
auto selected_item = this->GetSelection();
|
||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||
return marker == LABEL_ITEM_PHYSICAL_PRINTER;
|
||||
}
|
||||
|
||||
bool PresetComboBox::selection_is_changed_according_to_physical_printers()
|
||||
{
|
||||
if (m_type != Preset::TYPE_PRINTER || !is_selected_physical_printer())
|
||||
return false;
|
||||
|
||||
PhysicalPrinterCollection& physical_printers = m_preset_bundle->physical_printers;
|
||||
|
||||
std::string selected_string = this->GetString(this->GetSelection()).ToUTF8().data();
|
||||
|
||||
std::string old_printer_full_name, old_printer_preset;
|
||||
if (physical_printers.has_selection()) {
|
||||
old_printer_full_name = physical_printers.get_selected_full_printer_name();
|
||||
old_printer_preset = physical_printers.get_selected_printer_preset_name();
|
||||
}
|
||||
else
|
||||
old_printer_preset = m_collection->get_edited_preset().name;
|
||||
// Select related printer preset on the Printer Settings Tab
|
||||
physical_printers.select_printer_by_name(selected_string);
|
||||
std::string preset_name = physical_printers.get_selected_printer_preset_name();
|
||||
|
||||
// if new preset wasn't selected, there is no need to call update preset selection
|
||||
if (old_printer_preset == preset_name) {
|
||||
// we need just to update according Plater<->Tab PresetComboBox
|
||||
if (dynamic_cast<PlaterPresetComboBox*>(this)!=nullptr)
|
||||
wxGetApp().get_tab(m_type)->update_preset_choice();
|
||||
else if (dynamic_cast<TabPresetComboBox*>(this)!=nullptr)
|
||||
wxGetApp().sidebar().update_presets(m_type);
|
||||
return true;
|
||||
}
|
||||
|
||||
Tab* tab = wxGetApp().get_tab(Preset::TYPE_PRINTER);
|
||||
if (tab)
|
||||
tab->select_preset(preset_name, false, old_printer_full_name);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
bool PresetComboBox::OnAddBitmap(const wxBitmap& bitmap)
|
||||
{
|
||||
|
@ -245,25 +446,6 @@ PlaterPresetComboBox::PlaterPresetComboBox(wxWindow *parent, Preset::Type preset
|
|||
if (marker >= LABEL_ITEM_MARKER && marker < LABEL_ITEM_MAX) {
|
||||
this->SetSelection(this->m_last_selected);
|
||||
evt.StopPropagation();
|
||||
/*
|
||||
if (marker == LABEL_ITEM_PHYSICAL_PRINTERS)
|
||||
{
|
||||
PhysicalPrinterDialog dlg(wxEmptyString);
|
||||
if (dlg.ShowModal() == wxID_OK)
|
||||
this->update();
|
||||
return;
|
||||
}
|
||||
if (marker >= LABEL_ITEM_WIZARD_PRINTERS) {
|
||||
ConfigWizard::StartPage sp = ConfigWizard::SP_WELCOME;
|
||||
switch (marker) {
|
||||
case LABEL_ITEM_WIZARD_PRINTERS: sp = ConfigWizard::SP_PRINTERS; break;
|
||||
case LABEL_ITEM_WIZARD_FILAMENTS: sp = ConfigWizard::SP_FILAMENTS; break;
|
||||
case LABEL_ITEM_WIZARD_MATERIALS: sp = ConfigWizard::SP_MATERIALS; break;
|
||||
default: break;
|
||||
}
|
||||
wxTheApp->CallAfter([sp]() { wxGetApp().run_wizard(ConfigWizard::RR_USER, sp); });
|
||||
}
|
||||
*/
|
||||
if (marker == LABEL_ITEM_WIZARD_PRINTERS)
|
||||
show_add_menu();
|
||||
else
|
||||
|
@ -372,13 +554,6 @@ PlaterPresetComboBox::~PlaterPresetComboBox()
|
|||
edit_btn->Destroy();
|
||||
}
|
||||
|
||||
bool PlaterPresetComboBox::is_selected_physical_printer()
|
||||
{
|
||||
auto selected_item = this->GetSelection();
|
||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(selected_item));
|
||||
return marker == LABEL_ITEM_PHYSICAL_PRINTER;
|
||||
}
|
||||
|
||||
bool PlaterPresetComboBox::switch_to_tab()
|
||||
{
|
||||
Tab* tab = wxGetApp().get_tab(m_type);
|
||||
|
@ -465,7 +640,7 @@ void PlaterPresetComboBox::update()
|
|||
{
|
||||
unsigned char rgb[3];
|
||||
extruder_color = m_preset_bundle->printers.get_edited_preset().config.opt_string("extruder_colour", (unsigned int)m_extruder_idx);
|
||||
if (!m_bitmap_cache->parse_color(extruder_color, rgb))
|
||||
if (!bitmap_cache().parse_color(extruder_color, rgb))
|
||||
// Extruder color is not defined.
|
||||
extruder_color.clear();
|
||||
selected_filament_preset = m_collection->find_preset(m_preset_bundle->filament_presets[m_extruder_idx]);
|
||||
|
@ -499,64 +674,33 @@ void PlaterPresetComboBox::update()
|
|||
continue;
|
||||
|
||||
std::string bitmap_key, filament_rgb, extruder_rgb;
|
||||
std::string bitmap_type_name = bitmap_key = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
|
||||
bool single_bar = false;
|
||||
if (m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA)
|
||||
bitmap_key = "sla_printer";
|
||||
else if (m_type == Preset::TYPE_FILAMENT)
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
// Assign an extruder color to the selected item if the extruder color is defined.
|
||||
filament_rgb = preset.config.opt_string("filament_colour", 0);
|
||||
extruder_rgb = (selected && !extruder_color.empty()) ? extruder_color : filament_rgb;
|
||||
single_bar = filament_rgb == extruder_rgb;
|
||||
|
||||
bitmap_key = single_bar ? filament_rgb : filament_rgb + extruder_rgb;
|
||||
bitmap_key += single_bar ? filament_rgb : filament_rgb + extruder_rgb;
|
||||
}
|
||||
wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name);
|
||||
|
||||
// If the filament preset is not compatible and there is a "red flag" icon loaded, show it left
|
||||
// to the filament color image.
|
||||
if (wide_icons)
|
||||
bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt";
|
||||
bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
if (wide_icons)
|
||||
// Paint a red flag for incompatible presets.
|
||||
bmps.emplace_back(preset.is_compatible ? m_bitmap_cache->mkclear(norm_icon_width, icon_height) : m_bitmapIncompatible.bmp());
|
||||
|
||||
if (m_type == Preset::TYPE_FILAMENT)
|
||||
{
|
||||
unsigned char rgb[3];
|
||||
// Paint the color bars.
|
||||
m_bitmap_cache->parse_color(filament_rgb, rgb);
|
||||
bmps.emplace_back(m_bitmap_cache->mksolid(single_bar ? wide_icon_width : norm_icon_width, icon_height, rgb));
|
||||
if (!single_bar) {
|
||||
m_bitmap_cache->parse_color(extruder_rgb, rgb);
|
||||
bmps.emplace_back(m_bitmap_cache->mksolid(thin_icon_width, icon_height, rgb));
|
||||
}
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(space_icon_width, icon_height));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Paint the color bars.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
|
||||
bmps.emplace_back(main_bmp);
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height));
|
||||
}
|
||||
bmps.emplace_back((preset.is_system || preset.is_default) ? m_bitmapLock.bmp() : m_bitmap_cache->mkclear(norm_icon_width, icon_height));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
}
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, bitmap_type_name,
|
||||
preset.is_compatible, preset.is_system || preset.is_default,
|
||||
single_bar, filament_rgb, extruder_rgb);
|
||||
assert(bmp);
|
||||
|
||||
const std::string name = preset.alias.empty() ? preset.name : preset.alias;
|
||||
if (preset.is_default || preset.is_system) {
|
||||
Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()),
|
||||
!bmp ? main_bmp : *bmp);
|
||||
Append(wxString::FromUTF8((name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
|
||||
if (is_selected ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX) {
|
||||
|
@ -595,59 +739,26 @@ void PlaterPresetComboBox::update()
|
|||
const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers;
|
||||
|
||||
for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) {
|
||||
std::string bitmap_key = it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
if (wide_icons)
|
||||
bitmap_key += "wide,";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
for (const std::string preset_name : it->get_preset_names()) {
|
||||
Preset* preset = m_collection->find_preset(preset_name);
|
||||
if (!preset)
|
||||
continue;
|
||||
std::string main_icon_name, bitmap_key = main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
if (wide_icons)
|
||||
// Paint a red flag for incompatible presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(norm_icon_width, icon_height));
|
||||
// Paint the color bars.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap(it->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name));
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width+norm_icon_width, icon_height));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
}
|
||||
bitmap_key += ",cmpt";
|
||||
bitmap_key += ",nsyst";
|
||||
|
||||
set_label_marker(Append(wxString::FromUTF8((it->full_name).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
|
||||
if (ph_printers.has_selection() && it->name == ph_printers.get_selected_printer_name() ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, main_icon_name);
|
||||
assert(bmp);
|
||||
|
||||
set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
|
||||
if (ph_printers.is_selected(it, preset_name) ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
// add LABEL_ITEM_PHYSICAL_PRINTERS
|
||||
std::string bitmap_key;
|
||||
if (wide_icons)
|
||||
bitmap_key += "wide,";
|
||||
bitmap_key += "edit_preset_list";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
if (wide_icons)
|
||||
// Paint a red flag for incompatible presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(norm_icon_width, icon_height));
|
||||
// Paint the color bars.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap("printer"));
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap("edit_uni"));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
}
|
||||
set_label_marker(Append(separator(L("Add physical printer")), *bmp), LABEL_ITEM_PHYSICAL_PRINTERS);
|
||||
*/
|
||||
}
|
||||
|
||||
if (m_type == Preset::TYPE_PRINTER || m_type == Preset::TYPE_SLA_MATERIAL) {
|
||||
|
@ -657,23 +768,10 @@ void PlaterPresetComboBox::update()
|
|||
if (wide_icons)
|
||||
bitmap_key += "wide,";
|
||||
bitmap_key += "edit_preset_list";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.update_plater_ui
|
||||
std::vector<wxBitmap> bmps;
|
||||
if (wide_icons)
|
||||
// Paint a red flag for incompatible presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(norm_icon_width, icon_height));
|
||||
// Paint the color bars.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(thin_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name));
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back(m_bitmap_cache->mkclear(wide_space_icon_width, icon_height));
|
||||
bmps.emplace_back(create_scaled_bitmap("edit_uni"));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
}
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, wide_icons, "edit_uni");
|
||||
assert(bmp);
|
||||
|
||||
if (m_type == Preset::TYPE_SLA_MATERIAL)
|
||||
set_label_marker(Append(separator(L("Add/Remove materials")), *bmp), LABEL_ITEM_WIZARD_MATERIALS);
|
||||
else
|
||||
|
@ -731,8 +829,10 @@ TabPresetComboBox::TabPresetComboBox(wxWindow* parent, Preset::Type preset_type)
|
|||
update();
|
||||
});
|
||||
}
|
||||
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) )
|
||||
else if (on_selection_changed && (m_last_selected != selected_item || m_collection->current_is_dirty()) ) {
|
||||
m_last_selected = selected_item;
|
||||
on_selection_changed(selected_item);
|
||||
}
|
||||
|
||||
evt.StopPropagation();
|
||||
});
|
||||
|
@ -754,7 +854,12 @@ void TabPresetComboBox::update()
|
|||
if (!presets.front().is_visible)
|
||||
set_label_marker(Append(separator(L("System presets")), wxNullBitmap));
|
||||
int idx_selected = m_collection->get_selected_idx();
|
||||
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i) {
|
||||
|
||||
std::string sel_preset_name = m_preset_bundle->physical_printers.get_selected_printer_preset_name();
|
||||
PrinterTechnology proper_pt = (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) ?
|
||||
m_collection->find_preset(sel_preset_name)->printer_technology() : ptAny;
|
||||
for (size_t i = presets.front().is_visible ? 0 : m_collection->num_default_presets(); i < presets.size(); ++i)
|
||||
{
|
||||
const Preset& preset = presets[i];
|
||||
if (!preset.is_visible || (!show_incompatible && !preset.is_compatible && i != idx_selected))
|
||||
continue;
|
||||
|
@ -762,14 +867,12 @@ void TabPresetComboBox::update()
|
|||
// marker used for disable incompatible printer models for the selected physical printer
|
||||
bool is_enabled = true;
|
||||
// check this value just for printer presets, when physical printer is selected
|
||||
if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection()) {
|
||||
is_enabled = m_enable_all ? true :
|
||||
preset.name == m_preset_bundle->physical_printers.get_selected_printer_preset_name()/* ||
|
||||
preset.config.opt_string("printer_model") == m_preset_bundle->physical_printers.get_selected_printer_model()*/;
|
||||
}
|
||||
if (m_type == Preset::TYPE_PRINTER && m_preset_bundle->physical_printers.has_selection())
|
||||
is_enabled = m_enable_all ? true : preset.printer_technology() == proper_pt;//m_preset_bundle->physical_printers.get_selected_printer_technology();
|
||||
|
||||
std::string bitmap_key = "tab";
|
||||
wxBitmap main_bmp = create_scaled_bitmap(m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name, this, 16, !is_enabled);
|
||||
std::string main_icon_name = m_type == Preset::TYPE_PRINTER && preset.printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
bitmap_key += "_printer";
|
||||
if (preset.printer_technology() == ptSLA)
|
||||
|
@ -779,20 +882,12 @@ void TabPresetComboBox::update()
|
|||
}
|
||||
bitmap_key += preset.is_compatible ? ",cmpt" : ",ncmpt";
|
||||
bitmap_key += (preset.is_system || preset.is_default) ? ",syst" : ",nsyst";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
bmps.emplace_back(m_type == Preset::TYPE_PRINTER ? main_bmp : preset.is_compatible ? m_bitmapCompatible.bmp() : m_bitmapIncompatible.bmp());
|
||||
// Paint a lock at the system presets.
|
||||
bmps.emplace_back((preset.is_system || preset.is_default) ? (is_enabled ? m_bitmapLock.bmp() : m_bitmapLockDisabled.bmp()) : m_bitmap_cache->mkclear(norm_icon_width, icon_height));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
}
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "lock_closed", is_enabled, preset.is_compatible, preset.is_system || preset.is_default);
|
||||
assert(bmp);
|
||||
|
||||
if (preset.is_default || preset.is_system) {
|
||||
int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), !bmp ? main_bmp : *bmp);
|
||||
int item_id = Append(wxString::FromUTF8((preset.name + (preset.is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp);
|
||||
if (!is_enabled)
|
||||
set_label_marker(item_id, LABEL_ITEM_DISABLED);
|
||||
if (i == idx_selected ||
|
||||
|
@ -824,18 +919,38 @@ void TabPresetComboBox::update()
|
|||
selected_preset_item = GetCount() - 1;
|
||||
}
|
||||
}
|
||||
if (m_type == Preset::TYPE_PRINTER) {
|
||||
std::string bitmap_key = "edit_preset_list";
|
||||
bitmap_key += "-h" + std::to_string(icon_height);
|
||||
|
||||
wxBitmap* bmp = m_bitmap_cache->find(bitmap_key);
|
||||
if (bmp == nullptr) {
|
||||
// Create the bitmap with color bars.
|
||||
std::vector<wxBitmap> bmps;
|
||||
bmps.emplace_back(create_scaled_bitmap(m_main_bitmap_name, this));
|
||||
bmps.emplace_back(create_scaled_bitmap("edit_uni", this));
|
||||
bmp = m_bitmap_cache->insert(bitmap_key, bmps);
|
||||
if (m_type == Preset::TYPE_PRINTER)
|
||||
{
|
||||
// add Physical printers, if any exists
|
||||
if (!m_preset_bundle->physical_printers.empty()) {
|
||||
set_label_marker(Append(separator(L("Physical printers")), wxNullBitmap));
|
||||
const PhysicalPrinterCollection& ph_printers = m_preset_bundle->physical_printers;
|
||||
|
||||
for (PhysicalPrinterCollection::ConstIterator it = ph_printers.begin(); it != ph_printers.end(); ++it) {
|
||||
for (const std::string preset_name : it->get_preset_names()) {
|
||||
Preset* preset = m_collection->find_preset(preset_name);
|
||||
if (!preset)
|
||||
continue;
|
||||
std::string main_icon_name = preset->printer_technology() == ptSLA ? "sla_printer" : m_main_bitmap_name;
|
||||
std::string bitmap_key = main_icon_name + ",nsyst";
|
||||
|
||||
wxBitmap* bmp = get_bmp(bitmap_key, main_icon_name, "", true, true, false);
|
||||
assert(bmp);
|
||||
|
||||
set_label_marker(Append(wxString::FromUTF8((it->get_full_name(preset_name) + (preset->is_dirty ? Preset::suffix_modified() : "")).c_str()), *bmp), LABEL_ITEM_PHYSICAL_PRINTER);
|
||||
if (ph_printers.is_selected(it, preset_name) ||
|
||||
// just in case: mark selected_preset_item as a first added element
|
||||
selected_preset_item == INT_MAX)
|
||||
selected_preset_item = GetCount() - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add "Add/Remove printers" item
|
||||
wxBitmap* bmp = get_bmp("edit_preset_list", m_main_bitmap_name, "edit_uni", true, true, true);
|
||||
assert(bmp);
|
||||
|
||||
set_label_marker(Append(separator(L("Add/Remove printers")), *bmp), LABEL_ITEM_WIZARD_PRINTERS);
|
||||
}
|
||||
|
||||
|
@ -869,11 +984,26 @@ void TabPresetComboBox::update_dirty()
|
|||
// 2) Update the labels.
|
||||
wxWindowUpdateLocker noUpdates(this);
|
||||
for (unsigned int ui_id = 0; ui_id < GetCount(); ++ui_id) {
|
||||
auto marker = reinterpret_cast<Marker>(this->GetClientData(ui_id));
|
||||
if (marker >= LABEL_ITEM_MARKER)
|
||||
continue;
|
||||
|
||||
std::string old_label = GetString(ui_id).utf8_str().data();
|
||||
std::string preset_name = Preset::remove_suffix_modified(old_label);
|
||||
std::string ph_printer_name;
|
||||
|
||||
if (marker == LABEL_ITEM_PHYSICAL_PRINTER) {
|
||||
ph_printer_name = PhysicalPrinter::get_short_name(preset_name);
|
||||
preset_name = PhysicalPrinter::get_preset_name(preset_name);
|
||||
}
|
||||
|
||||
const Preset* preset = m_collection->find_preset(preset_name, false);
|
||||
if (preset) {
|
||||
std::string new_label = preset->is_dirty ? preset->name + Preset::suffix_modified() : preset->name;
|
||||
|
||||
if (marker == LABEL_ITEM_PHYSICAL_PRINTER)
|
||||
new_label = ph_printer_name + PhysicalPrinter::separator() + new_label;
|
||||
|
||||
if (old_label != new_label)
|
||||
SetString(ui_id, wxString::FromUTF8(new_label.c_str()));
|
||||
}
|
||||
|
@ -885,6 +1015,12 @@ void TabPresetComboBox::update_dirty()
|
|||
#endif /* __APPLE __ */
|
||||
}
|
||||
|
||||
void TabPresetComboBox::update_physical_printers( const std::string& preset_name)
|
||||
{
|
||||
if (m_type == Preset::TYPE_PRINTER && update_ph_printers)
|
||||
update_ph_printers(preset_name);
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
// PresetForPrinter
|
||||
|
@ -900,9 +1036,7 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::str
|
|||
m_delete_preset_btn->SetToolTip(_L("Delete this preset from this printer device"));
|
||||
m_delete_preset_btn->Bind(wxEVT_BUTTON, &PresetForPrinter::DeletePreset, this);
|
||||
|
||||
m_presets_list = new TabPresetComboBox(parent, Preset::TYPE_PRINTER);
|
||||
if (preset_name.empty())
|
||||
m_presets_list->set_enable_all();
|
||||
m_presets_list = new PresetComboBox(parent, Preset::TYPE_PRINTER);
|
||||
|
||||
m_presets_list->set_selection_changed_function([this](int selection) {
|
||||
std::string selected_string = Preset::remove_suffix_modified(m_presets_list->GetString(selection).ToUTF8().data());
|
||||
|
@ -922,8 +1056,7 @@ PresetForPrinter::PresetForPrinter(PhysicalPrinterDialog* parent, const std::str
|
|||
|
||||
update_full_printer_name();
|
||||
});
|
||||
m_presets_list->update();
|
||||
m_presets_list->SetStringSelection(from_u8(preset_name));
|
||||
m_presets_list->update(preset_name);
|
||||
|
||||
m_info_line = new wxStaticText(parent, wxID_ANY, _L("This printer will be shown in the presets list as") + ":");
|
||||
|
||||
|
@ -997,11 +1130,10 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name)
|
|||
SetFont(wxGetApp().normal_font());
|
||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
|
||||
if (printer_name.IsEmpty()) {
|
||||
printer_name = _L("My Printer Device");
|
||||
// if printer_name is empty it means that new printer is created, so enable all items in the preset list
|
||||
m_presets.emplace_back(new PresetForPrinter(this, ""));
|
||||
}
|
||||
m_default_name = _L("My Printer Device");
|
||||
|
||||
if (printer_name.IsEmpty())
|
||||
printer_name = m_default_name;
|
||||
else {
|
||||
std::string full_name = into_u8(printer_name);
|
||||
printer_name = from_u8(PhysicalPrinter::get_short_name(full_name));
|
||||
|
@ -1022,6 +1154,8 @@ PhysicalPrinterDialog::PhysicalPrinterDialog(wxString printer_name)
|
|||
if (!printer) {
|
||||
const Preset& preset = wxGetApp().preset_bundle->printers.get_edited_preset();
|
||||
printer = new PhysicalPrinter(into_u8(printer_name), preset);
|
||||
// if printer_name is empty it means that new printer is created, so enable all items in the preset list
|
||||
m_presets.emplace_back(new PresetForPrinter(this, preset.name));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -1275,7 +1409,11 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||
{
|
||||
wxString printer_name = m_printer_name->GetValue();
|
||||
if (printer_name.IsEmpty()) {
|
||||
show_error(this, _L("The supplied name is empty. It can't be saved."));
|
||||
warning_catcher(this, _L("The supplied name is empty. It can't be saved."));
|
||||
return;
|
||||
}
|
||||
if (printer_name == m_default_name) {
|
||||
warning_catcher(this, _L("You should to change a name of your printer device. It can't be saved."));
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1311,9 +1449,10 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||
repeatable_presets += "\n";
|
||||
|
||||
wxString msg_text = from_u8((boost::format(_u8L("Next printer preset(s) is(are) duplicated:%1%"
|
||||
"It(they) will be added just once for the printer \"%2%\".")) % repeatable_presets % printer_name).str());
|
||||
wxMessageDialog dialog(nullptr, msg_text, _L("Infornation"), wxICON_INFORMATION | wxOK);
|
||||
dialog.ShowModal();
|
||||
"Should I add it(they) just once for the printer \"%2%\" and close the Editing Dialog?")) % repeatable_presets % printer_name).str());
|
||||
wxMessageDialog dialog(nullptr, msg_text, _L("Warning"), wxICON_WARNING | wxYES | wxNO);
|
||||
if (dialog.ShowModal() == wxID_NO)
|
||||
return;
|
||||
}
|
||||
|
||||
std::string renamed_from;
|
||||
|
@ -1344,8 +1483,7 @@ void PhysicalPrinterDialog::OnOK(wxEvent& event)
|
|||
|
||||
void PhysicalPrinterDialog::AddPreset(wxEvent& event)
|
||||
{
|
||||
// if printer_name is empty it means that new printer is created, so enable all items in the preset list
|
||||
m_presets.emplace_back(new PresetForPrinter(this, ""));
|
||||
m_presets.emplace_back(new PresetForPrinter(this));
|
||||
// enable DELETE button for the first preset, if was disabled
|
||||
m_presets.front()->EnableDeleteBtn();
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue