mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-17 11:47:54 -06:00
Added color for extruder
This commit is contained in:
parent
c07a193b4e
commit
d7ebc4de5b
5 changed files with 208 additions and 126 deletions
|
@ -267,7 +267,8 @@ void ObjectList::create_objects_ctrl()
|
||||||
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
|
||||||
// column Extruder of the view control:
|
// column Extruder of the view control:
|
||||||
AppendColumn(create_objects_list_extruder_column(4));
|
AppendColumn(new wxDataViewColumn(_(L("Extruder")), new BitmapChoiceRenderer(),
|
||||||
|
colExtruder, 8*em, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE));
|
||||||
|
|
||||||
// column ItemEditing of the view control:
|
// column ItemEditing of the view control:
|
||||||
AppendBitmapColumn(_(L("Editing")), colEditing, wxDATAVIEW_CELL_INERT, 3*em,
|
AppendBitmapColumn(_(L("Editing")), colEditing, wxDATAVIEW_CELL_INERT, 3*em,
|
||||||
|
@ -434,19 +435,6 @@ DynamicPrintConfig& ObjectList::get_item_config(const wxDataViewItem& item) cons
|
||||||
(*m_objects)[obj_idx]->config;
|
(*m_objects)[obj_idx]->config;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewColumn* ObjectList::create_objects_list_extruder_column(size_t extruders_count)
|
|
||||||
{
|
|
||||||
wxArrayString choices;
|
|
||||||
choices.Add(_(L("default")));
|
|
||||||
for (int i = 1; i <= extruders_count; ++i)
|
|
||||||
choices.Add(wxString::Format("%d", i));
|
|
||||||
wxDataViewChoiceRenderer *c =
|
|
||||||
new wxDataViewChoiceRenderer(choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_CENTER_HORIZONTAL);
|
|
||||||
wxDataViewColumn* column = new wxDataViewColumn(_(L("Extruder")), c, colExtruder,
|
|
||||||
8*wxGetApp().em_unit()/*80*/, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
|
||||||
return column;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectList::update_extruder_values_for_items(const size_t max_extruder)
|
void ObjectList::update_extruder_values_for_items(const size_t max_extruder)
|
||||||
{
|
{
|
||||||
for (size_t i = 0; i < m_objects->size(); ++i)
|
for (size_t i = 0; i < m_objects->size(); ++i)
|
||||||
|
@ -462,7 +450,7 @@ void ObjectList::update_extruder_values_for_items(const size_t max_extruder)
|
||||||
else
|
else
|
||||||
extruder = wxString::Format("%d", object->config.option<ConfigOptionInt>("extruder")->value);
|
extruder = wxString::Format("%d", object->config.option<ConfigOptionInt>("extruder")->value);
|
||||||
|
|
||||||
m_objects_model->SetValue(extruder, item, colExtruder);
|
m_objects_model->SetExtruder(extruder, item);
|
||||||
|
|
||||||
if (object->volumes.size() > 1) {
|
if (object->volumes.size() > 1) {
|
||||||
for (size_t id = 0; id < object->volumes.size(); id++) {
|
for (size_t id = 0; id < object->volumes.size(); id++) {
|
||||||
|
@ -474,7 +462,7 @@ void ObjectList::update_extruder_values_for_items(const size_t max_extruder)
|
||||||
else
|
else
|
||||||
extruder = wxString::Format("%d", object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value);
|
extruder = wxString::Format("%d", object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value);
|
||||||
|
|
||||||
m_objects_model->SetValue(extruder, item, colExtruder);
|
m_objects_model->SetExtruder(extruder, item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -486,19 +474,13 @@ void ObjectList::update_objects_list_extruder_column(size_t extruders_count)
|
||||||
if (printer_technology() == ptSLA)
|
if (printer_technology() == ptSLA)
|
||||||
extruders_count = 1;
|
extruders_count = 1;
|
||||||
|
|
||||||
wxDataViewChoiceRenderer* ch_render = dynamic_cast<wxDataViewChoiceRenderer*>(GetColumn(colExtruder)->GetRenderer());
|
|
||||||
if (ch_render->GetChoices().GetCount() - 1 == extruders_count)
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_prevent_update_extruder_in_config = true;
|
m_prevent_update_extruder_in_config = true;
|
||||||
|
|
||||||
if (m_objects && extruders_count > 1)
|
if (m_objects && extruders_count > 1)
|
||||||
update_extruder_values_for_items(extruders_count);
|
update_extruder_values_for_items(extruders_count);
|
||||||
|
|
||||||
// delete old extruder column
|
update_extruder_colors();
|
||||||
DeleteColumn(GetColumn(colExtruder));
|
|
||||||
// insert new created extruder column
|
|
||||||
InsertColumn(colExtruder, create_objects_list_extruder_column(extruders_count));
|
|
||||||
// set show/hide for this column
|
// set show/hide for this column
|
||||||
set_extruder_column_hidden(extruders_count <= 1);
|
set_extruder_column_hidden(extruders_count <= 1);
|
||||||
//a workaround for a wrong last column width updating under OSX
|
//a workaround for a wrong last column width updating under OSX
|
||||||
|
@ -507,6 +489,11 @@ void ObjectList::update_objects_list_extruder_column(size_t extruders_count)
|
||||||
m_prevent_update_extruder_in_config = false;
|
m_prevent_update_extruder_in_config = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectList::update_extruder_colors()
|
||||||
|
{
|
||||||
|
m_objects_model->UpdateColumValues(colExtruder);
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectList::set_extruder_column_hidden(const bool hide) const
|
void ObjectList::set_extruder_column_hidden(const bool hide) const
|
||||||
{
|
{
|
||||||
GetColumn(colExtruder)->SetHidden(hide);
|
GetColumn(colExtruder)->SetHidden(hide);
|
||||||
|
@ -535,14 +522,10 @@ void ObjectList::update_extruder_in_config(const wxDataViewItem& item)
|
||||||
m_config = &get_item_config(item);
|
m_config = &get_item_config(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
wxVariant variant;
|
if (!m_config)
|
||||||
m_objects_model->GetValue(variant, item, colExtruder);
|
|
||||||
const wxString selection = variant.GetString();
|
|
||||||
|
|
||||||
if (!m_config || selection.empty())
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int extruder = /*selection.size() > 1 ? 0 : */atoi(selection.c_str());
|
const int extruder = m_objects_model->GetExtruderNumber(item);
|
||||||
m_config->set_key_value("extruder", new ConfigOptionInt(extruder));
|
m_config->set_key_value("extruder", new ConfigOptionInt(extruder));
|
||||||
|
|
||||||
// update scene
|
// update scene
|
||||||
|
@ -2547,7 +2530,7 @@ void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& it
|
||||||
(*m_objects)[item->obj_idx]->config.has("extruder"))
|
(*m_objects)[item->obj_idx]->config.has("extruder"))
|
||||||
{
|
{
|
||||||
const wxString extruder = wxString::Format("%d", (*m_objects)[item->obj_idx]->config.option<ConfigOptionInt>("extruder")->value);
|
const wxString extruder = wxString::Format("%d", (*m_objects)[item->obj_idx]->config.option<ConfigOptionInt>("extruder")->value);
|
||||||
m_objects_model->SetValue(extruder, m_objects_model->GetItemById(item->obj_idx), colExtruder);
|
m_objects_model->SetExtruder(extruder, m_objects_model->GetItemById(item->obj_idx));
|
||||||
}
|
}
|
||||||
wxGetApp().plater()->canvas3D()->ensure_on_bed(item->obj_idx);
|
wxGetApp().plater()->canvas3D()->ensure_on_bed(item->obj_idx);
|
||||||
}
|
}
|
||||||
|
@ -3822,7 +3805,7 @@ void ObjectList::set_extruder_for_selected_items(const int extruder) const
|
||||||
/* We can change extruder for Object/Volume only.
|
/* We can change extruder for Object/Volume only.
|
||||||
* So, if Instance is selected, get its Object item and change it
|
* So, if Instance is selected, get its Object item and change it
|
||||||
*/
|
*/
|
||||||
m_objects_model->SetValue(extruder_str, type & itInstance ? m_objects_model->GetTopParent(item) : item, colExtruder);
|
m_objects_model->SetExtruder(extruder_str, type & itInstance ? m_objects_model->GetTopParent(item) : item);
|
||||||
|
|
||||||
const int obj_idx = type & itObject ? m_objects_model->GetIdByItem(item) :
|
const int obj_idx = type & itObject ? m_objects_model->GetIdByItem(item) :
|
||||||
m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item));
|
m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item));
|
||||||
|
|
|
@ -183,8 +183,8 @@ public:
|
||||||
|
|
||||||
void create_objects_ctrl();
|
void create_objects_ctrl();
|
||||||
void create_popup_menus();
|
void create_popup_menus();
|
||||||
wxDataViewColumn* create_objects_list_extruder_column(size_t extruders_count);
|
|
||||||
void update_objects_list_extruder_column(size_t extruders_count);
|
void update_objects_list_extruder_column(size_t extruders_count);
|
||||||
|
void update_extruder_colors();
|
||||||
// show/hide "Extruder" column for Objects List
|
// show/hide "Extruder" column for Objects List
|
||||||
void set_extruder_column_hidden(const bool hide) const;
|
void set_extruder_column_hidden(const bool hide) const;
|
||||||
// update extruder in current config
|
// update extruder in current config
|
||||||
|
|
|
@ -4785,6 +4785,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
||||||
filament_colors.push_back(filaments.find_preset(filament_preset, true)->config.opt_string("filament_colour", (unsigned)0));
|
filament_colors.push_back(filaments.find_preset(filament_preset, true)->config.opt_string("filament_colour", (unsigned)0));
|
||||||
|
|
||||||
p->config->option<ConfigOptionStrings>(opt_key)->values = filament_colors;
|
p->config->option<ConfigOptionStrings>(opt_key)->values = filament_colors;
|
||||||
|
p->sidebar->obj_list()->update_extruder_colors();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4810,6 +4811,7 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
|
||||||
else if(opt_key == "extruder_colour") {
|
else if(opt_key == "extruder_colour") {
|
||||||
update_scheduled = true;
|
update_scheduled = true;
|
||||||
p->preview->set_number_extruders(p->config->option<ConfigOptionStrings>(opt_key)->values.size());
|
p->preview->set_number_extruders(p->config->option<ConfigOptionStrings>(opt_key)->values.size());
|
||||||
|
p->sidebar->obj_list()->update_extruder_colors();
|
||||||
} else if(opt_key == "max_print_height") {
|
} else if(opt_key == "max_print_height") {
|
||||||
update_scheduled = true;
|
update_scheduled = true;
|
||||||
}
|
}
|
||||||
|
@ -4858,8 +4860,10 @@ void Plater::force_filament_colors_update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (update_scheduled)
|
if (update_scheduled) {
|
||||||
update();
|
update();
|
||||||
|
p->sidebar->obj_list()->update_extruder_colors();
|
||||||
|
}
|
||||||
|
|
||||||
if (p->main_frame->is_loaded())
|
if (p->main_frame->is_loaded())
|
||||||
this->p->schedule_background_process();
|
this->p->schedule_background_process();
|
||||||
|
|
|
@ -447,6 +447,47 @@ wxBitmap create_scaled_bitmap(wxWindow *win, const std::string& bmp_name_in,
|
||||||
return *bmp;
|
return *bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Slic3r::GUI::BitmapCache* m_bitmap_cache = nullptr;
|
||||||
|
static std::vector<wxBitmap*> get_extruder_color_icons()
|
||||||
|
{
|
||||||
|
// Create the bitmap with color bars.
|
||||||
|
std::vector<wxBitmap*> bmps;
|
||||||
|
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
||||||
|
|
||||||
|
unsigned char rgb[3];
|
||||||
|
|
||||||
|
/* It's supposed that standard size of an icon is 36px*16px for 100% scaled display.
|
||||||
|
* So set sizes for solid_colored icons used for filament preset
|
||||||
|
* and scale them in respect to em_unit value
|
||||||
|
*/
|
||||||
|
const double em = Slic3r::GUI::wxGetApp().em_unit();
|
||||||
|
const int icon_width = lround(3.2 * em);
|
||||||
|
const int icon_height = lround(1.6 * em);
|
||||||
|
|
||||||
|
for (const std::string& color : colors)
|
||||||
|
{
|
||||||
|
wxBitmap* bitmap = m_bitmap_cache->find(color);
|
||||||
|
if (bitmap == nullptr) {
|
||||||
|
// Paint the color icon.
|
||||||
|
Slic3r::PresetBundle::parse_color(color, rgb);
|
||||||
|
bitmap = m_bitmap_cache->insert(color, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
|
||||||
|
}
|
||||||
|
bmps.emplace_back(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
return bmps;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static wxBitmap get_extruder_color_icon(size_t extruder_idx)
|
||||||
|
{
|
||||||
|
// Create the bitmap with color bars.
|
||||||
|
std::vector<wxBitmap*> bmps = get_extruder_color_icons();
|
||||||
|
|
||||||
|
return *bmps[extruder_idx >= bmps.size() ? 0 : extruder_idx];
|
||||||
|
}
|
||||||
|
|
||||||
// *****************************************************************************
|
// *****************************************************************************
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// ObjectDataViewModelNode
|
// ObjectDataViewModelNode
|
||||||
|
@ -479,7 +520,7 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent
|
||||||
m_idx = parent->GetChildCount();
|
m_idx = parent->GetChildCount();
|
||||||
m_name = wxString::Format(_(L("Instance %d")), m_idx + 1);
|
m_name = wxString::Format(_(L("Instance %d")), m_idx + 1);
|
||||||
|
|
||||||
set_action_icon();
|
set_action_and_extruder_icons();
|
||||||
}
|
}
|
||||||
else if (type == itLayerRoot)
|
else if (type == itLayerRoot)
|
||||||
{
|
{
|
||||||
|
@ -514,7 +555,7 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent
|
||||||
m_name = _(L("Range")) + label_range + "(" + _(L("mm")) + ")";
|
m_name = _(L("Range")) + label_range + "(" + _(L("mm")) + ")";
|
||||||
m_bmp = create_scaled_bitmap(nullptr, LAYER_ICON); // FIXME: pass window ptr
|
m_bmp = create_scaled_bitmap(nullptr, LAYER_ICON); // FIXME: pass window ptr
|
||||||
|
|
||||||
set_action_icon();
|
set_action_and_extruder_icons();
|
||||||
init_container();
|
init_container();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,11 +568,16 @@ bool ObjectDataViewModelNode::valid()
|
||||||
}
|
}
|
||||||
#endif /* NDEBUG */
|
#endif /* NDEBUG */
|
||||||
|
|
||||||
void ObjectDataViewModelNode::set_action_icon()
|
void ObjectDataViewModelNode::set_action_and_extruder_icons()
|
||||||
{
|
{
|
||||||
m_action_icon_name = m_type & itObject ? "advanced_plus" :
|
m_action_icon_name = m_type & itObject ? "advanced_plus" :
|
||||||
m_type & (itVolume | itLayer) ? "cog" : /*m_type & itInstance*/ "set_separate_obj";
|
m_type & (itVolume | itLayer) ? "cog" : /*m_type & itInstance*/ "set_separate_obj";
|
||||||
m_action_icon = create_scaled_bitmap(nullptr, m_action_icon_name); // FIXME: pass window ptr
|
m_action_icon = create_scaled_bitmap(nullptr, m_action_icon_name); // FIXME: pass window ptr
|
||||||
|
|
||||||
|
// set extruder bitmap
|
||||||
|
int extruder_idx = atoi(m_extruder.c_str());
|
||||||
|
if (extruder_idx > 0) --extruder_idx;
|
||||||
|
m_extruder_bmp = get_extruder_color_icon(extruder_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectDataViewModelNode::set_printable_icon(PrintIndicator printable)
|
void ObjectDataViewModelNode::set_printable_icon(PrintIndicator printable)
|
||||||
|
@ -541,7 +587,6 @@ void ObjectDataViewModelNode::set_printable_icon(PrintIndicator printable)
|
||||||
create_scaled_bitmap(nullptr, m_printable == piPrintable ? "eye_open.png" : "eye_closed.png");
|
create_scaled_bitmap(nullptr, m_printable == piPrintable ? "eye_open.png" : "eye_closed.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
Slic3r::GUI::BitmapCache *m_bitmap_cache = nullptr;
|
|
||||||
void ObjectDataViewModelNode::update_settings_digest_bitmaps()
|
void ObjectDataViewModelNode::update_settings_digest_bitmaps()
|
||||||
{
|
{
|
||||||
m_bmp = m_empty_bmp;
|
m_bmp = m_empty_bmp;
|
||||||
|
@ -607,8 +652,10 @@ bool ObjectDataViewModelNode::SetValue(const wxVariant& variant, unsigned col)
|
||||||
m_name = data.GetText();
|
m_name = data.GetText();
|
||||||
return true; }
|
return true; }
|
||||||
case colExtruder: {
|
case colExtruder: {
|
||||||
const wxString & val = variant.GetString();
|
DataViewBitmapText data;
|
||||||
m_extruder = val == "0" ? _(L("default")) : val;
|
data << variant;
|
||||||
|
m_extruder_bmp = data.GetBitmap();
|
||||||
|
m_extruder = data.GetText() == "0" ? _(L("default")) : data.GetText();
|
||||||
return true; }
|
return true; }
|
||||||
case colEditing:
|
case colEditing:
|
||||||
m_action_icon << variant;
|
m_action_icon << variant;
|
||||||
|
@ -1381,6 +1428,51 @@ t_layer_height_range ObjectDataViewModel::GetLayerRangeByItem(const wxDataViewIt
|
||||||
return node->GetLayerRange();
|
return node->GetLayerRange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool ObjectDataViewModel::UpdateColumValues(unsigned col)
|
||||||
|
{
|
||||||
|
switch (col)
|
||||||
|
{
|
||||||
|
case colPrint:
|
||||||
|
case colName:
|
||||||
|
case colEditing:
|
||||||
|
return true;
|
||||||
|
case colExtruder:
|
||||||
|
{
|
||||||
|
wxDataViewItemArray items;
|
||||||
|
GetAllChildren(wxDataViewItem(nullptr), items);
|
||||||
|
|
||||||
|
if (items.IsEmpty()) return false;
|
||||||
|
|
||||||
|
for (auto item : items)
|
||||||
|
UpdateExtruderBitmap(item);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
printf("MyObjectTreeModel::SetValue: wrong column");
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ObjectDataViewModel::UpdateExtruderBitmap(wxDataViewItem item)
|
||||||
|
{
|
||||||
|
wxString extruder = GetExtruder(item);
|
||||||
|
if (extruder.IsEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
// set extruder bitmap
|
||||||
|
int extruder_idx = atoi(extruder.c_str());
|
||||||
|
if (extruder_idx > 0) --extruder_idx;
|
||||||
|
|
||||||
|
const DataViewBitmapText extruder_val(extruder, get_extruder_color_icon(extruder_idx));
|
||||||
|
|
||||||
|
wxVariant value;
|
||||||
|
value << extruder_val;
|
||||||
|
|
||||||
|
SetValue(value, item, colExtruder);
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx)
|
void ObjectDataViewModel::GetItemInfo(const wxDataViewItem& item, ItemType& type, int& obj_idx, int& idx)
|
||||||
{
|
{
|
||||||
wxASSERT(item.IsOk());
|
wxASSERT(item.IsOk());
|
||||||
|
@ -1477,6 +1569,24 @@ wxBitmap& ObjectDataViewModel::GetBitmap(const wxDataViewItem &item) const
|
||||||
return node->m_bmp;
|
return node->m_bmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxString ObjectDataViewModel::GetExtruder(const wxDataViewItem& item) const
|
||||||
|
{
|
||||||
|
ObjectDataViewModelNode *node = (ObjectDataViewModelNode*)item.GetID();
|
||||||
|
if (!node) // happens if item.IsOk()==false
|
||||||
|
return wxEmptyString;
|
||||||
|
|
||||||
|
return node->m_extruder;
|
||||||
|
}
|
||||||
|
|
||||||
|
int ObjectDataViewModel::GetExtruderNumber(const wxDataViewItem& item) const
|
||||||
|
{
|
||||||
|
ObjectDataViewModelNode *node = (ObjectDataViewModelNode*)item.GetID();
|
||||||
|
if (!node) // happens if item.IsOk()==false
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
return atoi(node->m_extruder.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
void ObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
|
void ObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &item, unsigned int col) const
|
||||||
{
|
{
|
||||||
wxASSERT(item.IsOk());
|
wxASSERT(item.IsOk());
|
||||||
|
@ -1491,7 +1601,7 @@ void ObjectDataViewModel::GetValue(wxVariant &variant, const wxDataViewItem &ite
|
||||||
variant << DataViewBitmapText(node->m_name, node->m_bmp);
|
variant << DataViewBitmapText(node->m_name, node->m_bmp);
|
||||||
break;
|
break;
|
||||||
case colExtruder:
|
case colExtruder:
|
||||||
variant = node->m_extruder;
|
variant << DataViewBitmapText(node->m_extruder, node->m_extruder_bmp);
|
||||||
break;
|
break;
|
||||||
case colEditing:
|
case colEditing:
|
||||||
variant << node->m_action_icon;
|
variant << node->m_action_icon;
|
||||||
|
@ -1517,6 +1627,22 @@ bool ObjectDataViewModel::SetValue(const wxVariant &variant, const int item_idx,
|
||||||
return m_objects[item_idx]->SetValue(variant, col);
|
return m_objects[item_idx]->SetValue(variant, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectDataViewModel::SetExtruder(const wxString& extruder, wxDataViewItem item)
|
||||||
|
{
|
||||||
|
DataViewBitmapText extruder_val;
|
||||||
|
extruder_val.SetText(extruder);
|
||||||
|
|
||||||
|
// set extruder bitmap
|
||||||
|
int extruder_idx = atoi(extruder.c_str());
|
||||||
|
if (extruder_idx > 0) --extruder_idx;
|
||||||
|
extruder_val.SetBitmap(get_extruder_color_icon(extruder_idx));
|
||||||
|
|
||||||
|
wxVariant value;
|
||||||
|
value << extruder_val;
|
||||||
|
|
||||||
|
SetValue(value, item, colExtruder);
|
||||||
|
}
|
||||||
|
|
||||||
wxDataViewItem ObjectDataViewModel::ReorganizeChildren( const int current_volume_id,
|
wxDataViewItem ObjectDataViewModel::ReorganizeChildren( const int current_volume_id,
|
||||||
const int new_volume_id,
|
const int new_volume_id,
|
||||||
const wxDataViewItem &parent)
|
const wxDataViewItem &parent)
|
||||||
|
@ -1969,20 +2095,22 @@ bool BitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// BitmapChoiseRenderer
|
// BitmapChoiceRenderer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
bool BitmapChoiseRenderer::SetValue(const wxVariant& value)
|
bool BitmapChoiceRenderer::SetValue(const wxVariant& value)
|
||||||
{
|
{
|
||||||
m_value << value;
|
m_value << value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool BitmapChoiseRenderer::GetValue(wxVariant& value) const
|
|
||||||
|
bool BitmapChoiceRenderer::GetValue(wxVariant& value) const
|
||||||
{
|
{
|
||||||
value << m_value;
|
value << m_value;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
bool BitmapChoiseRenderer::Render(wxRect rect, wxDC* dc, int state)
|
|
||||||
|
bool BitmapChoiceRenderer::Render(wxRect rect, wxDC* dc, int state)
|
||||||
{
|
{
|
||||||
int xoffset = 0;
|
int xoffset = 0;
|
||||||
|
|
||||||
|
@ -1993,69 +2121,25 @@ bool BitmapChoiseRenderer::Render(wxRect rect, wxDC* dc, int state)
|
||||||
xoffset = icon.GetWidth() + 4;
|
xoffset = icon.GetWidth() + 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (rect.height==0)
|
||||||
|
rect.height= icon.GetHeight();
|
||||||
RenderText(m_value.GetText(), xoffset, rect, dc, state);
|
RenderText(m_value.GetText(), xoffset, rect, dc, state);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxSize BitmapChoiseRenderer::GetSize() const
|
wxSize BitmapChoiceRenderer::GetSize() const
|
||||||
{
|
{
|
||||||
if (!m_value.GetText().empty())
|
wxSize sz = GetTextExtent(m_value.GetText());
|
||||||
{
|
|
||||||
wxSize size = GetTextExtent(m_value.GetText());
|
|
||||||
|
|
||||||
if (m_value.GetBitmap().IsOk())
|
if (m_value.GetBitmap().IsOk())
|
||||||
size.x += m_value.GetBitmap().GetWidth() + 4;
|
sz.x += m_value.GetBitmap().GetWidth() + 4;
|
||||||
return size;
|
|
||||||
}
|
|
||||||
return wxSize(80, 20);
|
|
||||||
|
|
||||||
/* from wxDataViewChoiceRenderer
|
|
||||||
wxSize sz;
|
|
||||||
|
|
||||||
for ( wxArrayString::const_iterator i = m_choices.begin(); i != m_choices.end(); ++i )
|
|
||||||
sz.IncTo(GetTextExtent(*i));
|
|
||||||
|
|
||||||
// Allow some space for the right-side button, which is approximately the
|
|
||||||
// size of a scrollbar (and getting pixel-exact value would be complicated).
|
|
||||||
// Also add some whitespace between the text and the button:
|
|
||||||
sz.x += wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
|
||||||
sz.x += GetTextExtent("M").x;
|
|
||||||
|
|
||||||
return sz;
|
return sz;
|
||||||
*/
|
|
||||||
}
|
|
||||||
|
|
||||||
static void update_extruder_color_icons_in_cache()
|
|
||||||
{
|
|
||||||
// Create the bitmap with color bars.
|
|
||||||
std::vector<wxBitmap*> bmps;
|
|
||||||
std::vector<std::string> colors = Slic3r::GUI::wxGetApp().plater()->get_extruder_colors_from_plater_config();
|
|
||||||
|
|
||||||
unsigned char rgb[3];
|
|
||||||
|
|
||||||
/* It's supposed that standard size of an icon is 36px*16px for 100% scaled display.
|
|
||||||
* So set sizes for solid_colored icons used for filament preset
|
|
||||||
* and scale them in respect to em_unit value
|
|
||||||
*/
|
|
||||||
const double em = Slic3r::GUI::wxGetApp().em_unit();
|
|
||||||
const int icon_width = lround(3.6 * em);
|
|
||||||
const int icon_height = lround(1.6 * em);
|
|
||||||
|
|
||||||
for (const std::string& color : colors)
|
|
||||||
{
|
|
||||||
wxBitmap* bitmap = m_bitmap_cache->find(color);
|
|
||||||
if (bitmap == nullptr) {
|
|
||||||
// Paint the color icon.
|
|
||||||
Slic3r::PresetBundle::parse_color(color, rgb);
|
|
||||||
bitmap = m_bitmap_cache->insert(color, m_bitmap_cache->mksolid(icon_width, icon_height, rgb));
|
|
||||||
}
|
|
||||||
bmps.emplace_back(bitmap);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
wxWindow* BitmapChoiseRenderer::CreateEditorCtrl(wxWindow* parent, wxRect labelRect, const wxVariant& value)
|
wxWindow* BitmapChoiceRenderer::CreateEditorCtrl(wxWindow* parent, wxRect labelRect, const wxVariant& value)
|
||||||
{
|
{
|
||||||
wxDataViewCtrl* const dv_ctrl = GetOwner()->GetOwner();
|
wxDataViewCtrl* const dv_ctrl = GetOwner()->GetOwner();
|
||||||
ObjectDataViewModel* const model = dynamic_cast<ObjectDataViewModel*>(dv_ctrl->GetModel());
|
ObjectDataViewModel* const model = dynamic_cast<ObjectDataViewModel*>(dv_ctrl->GetModel());
|
||||||
|
@ -2063,28 +2147,36 @@ wxWindow* BitmapChoiseRenderer::CreateEditorCtrl(wxWindow* parent, wxRect labelR
|
||||||
if (!(model->GetItemType(dv_ctrl->GetSelection()) & (itVolume | itObject)))
|
if (!(model->GetItemType(dv_ctrl->GetSelection()) & (itVolume | itObject)))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
|
std::vector<wxBitmap*> icons = get_extruder_color_icons();
|
||||||
|
if (icons.empty())
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
DataViewBitmapText data;
|
DataViewBitmapText data;
|
||||||
data << value;
|
data << value;
|
||||||
|
|
||||||
// m_was_unusable_symbol = false;
|
auto c_editor = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString,
|
||||||
|
|
||||||
wxPoint position = labelRect.GetPosition();
|
|
||||||
if (data.GetBitmap().IsOk()) {
|
|
||||||
const int bmp_width = data.GetBitmap().GetWidth();
|
|
||||||
position.x += bmp_width;
|
|
||||||
labelRect.SetWidth(labelRect.GetWidth() - bmp_width);
|
|
||||||
}
|
|
||||||
|
|
||||||
auto c_editor = new wxBitmapComboBox(parent, wxID_ANY, wxEmptyString, //data.GetText(),
|
|
||||||
labelRect.GetTopLeft(), wxSize(labelRect.GetWidth(), -1),
|
labelRect.GetTopLeft(), wxSize(labelRect.GetWidth(), -1),
|
||||||
0, nullptr , wxCB_READONLY);
|
0, nullptr , wxCB_READONLY);
|
||||||
|
|
||||||
c_editor->Move(labelRect.GetRight() - c_editor->GetRect().width, wxDefaultCoord);
|
int i=0;
|
||||||
c_editor->SetStringSelection(data.GetText());
|
for (wxBitmap* bmp : icons) {
|
||||||
|
if (i==0) {
|
||||||
|
c_editor->Append(_(L("default")), *bmp);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
|
||||||
|
c_editor->Append(wxString::Format("%d", i), *bmp);
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
c_editor->SetSelection(atoi(data.GetText().c_str()));
|
||||||
|
|
||||||
|
// to avoid event propagation to other sidebar items
|
||||||
|
c_editor->Bind(wxEVT_COMBOBOX, [](wxCommandEvent& evt) { evt.StopPropagation(); });
|
||||||
|
|
||||||
return c_editor;
|
return c_editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool BitmapChoiseRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value)
|
bool BitmapChoiceRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& value)
|
||||||
{
|
{
|
||||||
wxBitmapComboBox* c = (wxBitmapComboBox*)ctrl;
|
wxBitmapComboBox* c = (wxBitmapComboBox*)ctrl;
|
||||||
int selection = c->GetSelection();
|
int selection = c->GetSelection();
|
||||||
|
|
|
@ -209,6 +209,7 @@ class ObjectDataViewModelNode
|
||||||
int m_idx = -1;
|
int m_idx = -1;
|
||||||
bool m_container = false;
|
bool m_container = false;
|
||||||
wxString m_extruder = "default";
|
wxString m_extruder = "default";
|
||||||
|
wxBitmap m_extruder_bmp;
|
||||||
wxBitmap m_action_icon;
|
wxBitmap m_action_icon;
|
||||||
PrintIndicator m_printable {piUndef};
|
PrintIndicator m_printable {piUndef};
|
||||||
wxBitmap m_printable_icon;
|
wxBitmap m_printable_icon;
|
||||||
|
@ -224,7 +225,7 @@ public:
|
||||||
m_type(itObject),
|
m_type(itObject),
|
||||||
m_extruder(extruder)
|
m_extruder(extruder)
|
||||||
{
|
{
|
||||||
set_action_icon();
|
set_action_and_extruder_icons();
|
||||||
init_container();
|
init_container();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,7 +241,7 @@ public:
|
||||||
m_extruder (extruder)
|
m_extruder (extruder)
|
||||||
{
|
{
|
||||||
m_bmp = bmp;
|
m_bmp = bmp;
|
||||||
set_action_icon();
|
set_action_and_extruder_icons();
|
||||||
init_container();
|
init_container();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,7 +357,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set action icons for node
|
// Set action icons for node
|
||||||
void set_action_icon();
|
void set_action_and_extruder_icons();
|
||||||
// Set printable icon for node
|
// Set printable icon for node
|
||||||
void set_printable_icon(PrintIndicator printable);
|
void set_printable_icon(PrintIndicator printable);
|
||||||
|
|
||||||
|
@ -438,6 +439,8 @@ public:
|
||||||
|
|
||||||
wxString GetName(const wxDataViewItem &item) const;
|
wxString GetName(const wxDataViewItem &item) const;
|
||||||
wxBitmap& GetBitmap(const wxDataViewItem &item) const;
|
wxBitmap& GetBitmap(const wxDataViewItem &item) const;
|
||||||
|
wxString GetExtruder(const wxDataViewItem &item) const;
|
||||||
|
int GetExtruderNumber(const wxDataViewItem &item) const;
|
||||||
|
|
||||||
// helper methods to change the model
|
// helper methods to change the model
|
||||||
|
|
||||||
|
@ -454,6 +457,8 @@ public:
|
||||||
const int item_idx,
|
const int item_idx,
|
||||||
unsigned int col);
|
unsigned int col);
|
||||||
|
|
||||||
|
void SetExtruder(const wxString& extruder, wxDataViewItem item);
|
||||||
|
|
||||||
// For parent move child from cur_volume_id place to new_volume_id
|
// For parent move child from cur_volume_id place to new_volume_id
|
||||||
// Remaining items will moved up/down accordingly
|
// Remaining items will moved up/down accordingly
|
||||||
wxDataViewItem ReorganizeChildren( const int cur_volume_id,
|
wxDataViewItem ReorganizeChildren( const int cur_volume_id,
|
||||||
|
@ -504,6 +509,9 @@ public:
|
||||||
void DeleteWarningIcon(const wxDataViewItem& item, const bool unmark_object = false);
|
void DeleteWarningIcon(const wxDataViewItem& item, const bool unmark_object = false);
|
||||||
t_layer_height_range GetLayerRangeByItem(const wxDataViewItem& item) const;
|
t_layer_height_range GetLayerRangeByItem(const wxDataViewItem& item) const;
|
||||||
|
|
||||||
|
bool UpdateColumValues(unsigned col);
|
||||||
|
void UpdateExtruderBitmap(wxDataViewItem item);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
wxDataViewItem AddRoot(const wxDataViewItem& parent_item, const ItemType root_type);
|
wxDataViewItem AddRoot(const wxDataViewItem& parent_item, const ItemType root_type);
|
||||||
wxDataViewItem AddInstanceRoot(const wxDataViewItem& parent_item);
|
wxDataViewItem AddInstanceRoot(const wxDataViewItem& parent_item);
|
||||||
|
@ -564,22 +572,18 @@ private:
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
// BitmapChoiseRenderer
|
// BitmapChoiceRenderer
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
class BitmapChoiseRenderer : public wxDataViewCustomRenderer
|
class BitmapChoiceRenderer : public wxDataViewCustomRenderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
BitmapChoiseRenderer(wxDataViewCellMode mode = wxDATAVIEW_CELL_INERT
|
BitmapChoiceRenderer(wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE,
|
||||||
|
int align = wxALIGN_LEFT | wxALIGN_CENTER_VERTICAL
|
||||||
, int align = wxDVR_DEFAULT_ALIGNMENT
|
|
||||||
) : wxDataViewCustomRenderer(wxT("DataViewBitmapText"), mode, align) {}
|
) : wxDataViewCustomRenderer(wxT("DataViewBitmapText"), mode, align) {}
|
||||||
|
|
||||||
bool SetValue(const wxVariant& value);
|
bool SetValue(const wxVariant& value);
|
||||||
bool GetValue(wxVariant& value) const;
|
bool GetValue(wxVariant& value) const;
|
||||||
#if ENABLE_NONCUSTOM_DATA_VIEW_RENDERING && wxUSE_ACCESSIBILITY
|
|
||||||
virtual wxString GetAccessibleDescription() const override;
|
|
||||||
#endif // wxUSE_ACCESSIBILITY && ENABLE_NONCUSTOM_DATA_VIEW_RENDERING
|
|
||||||
|
|
||||||
virtual bool Render(wxRect cell, wxDC* dc, int state);
|
virtual bool Render(wxRect cell, wxDC* dc, int state);
|
||||||
virtual wxSize GetSize() const;
|
virtual wxSize GetSize() const;
|
||||||
|
@ -593,7 +597,6 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DataViewBitmapText m_value;
|
DataViewBitmapText m_value;
|
||||||
wxArrayString m_choices;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue