FIX: Delete and search object outside the plate
JIRA: 1. STUDIO-5132 Deleting object outside the plate will crash 2. STUDIO-5146 The search function cannot search for object outside the plate Signed-off-by: Kunlong Ma <kunlong.ma@bambulab.com> Change-Id: I84cb3fe990a9c2a182e7434c262466a70545280e
This commit is contained in:
parent
3fe19f87f3
commit
939f64d90d
|
@ -781,14 +781,15 @@ void ObjectList::printable_state_changed(const std::vector<ObjectVolumeID>& ov_i
|
||||||
|
|
||||||
void ObjectList::search_object_list() {
|
void ObjectList::search_object_list() {
|
||||||
|
|
||||||
auto found_size = m_found_list.size();
|
auto found_list = m_objects_model->get_search_list();
|
||||||
|
auto found_size = found_list.size();
|
||||||
|
|
||||||
if (cur_pos >= found_size) {
|
if (cur_pos >= found_size) {
|
||||||
cur_pos = 0;
|
cur_pos = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cur_pos < found_size) {
|
if (cur_pos < found_size) {
|
||||||
wxDataViewItem cur_item = m_found_list.Item(cur_pos);
|
wxDataViewItem cur_item = found_list.Item(cur_pos);
|
||||||
select_item(cur_item);
|
select_item(cur_item);
|
||||||
cur_pos++;
|
cur_pos++;
|
||||||
ensure_current_item_visible();
|
ensure_current_item_visible();
|
||||||
|
@ -796,31 +797,13 @@ void ObjectList::search_object_list() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectList::append_found_list(wxString current_search_text, wxDataViewItem item) {
|
|
||||||
|
|
||||||
wxString item_name = m_objects_model->GetName(item);
|
|
||||||
item_name = item_name.MakeLower();
|
|
||||||
|
|
||||||
if (item_name.find(current_search_text) != wxString::npos) {
|
|
||||||
m_found_list.Add(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
ObjectDataViewModelNode* root = static_cast<ObjectDataViewModelNode*>(item.GetID());
|
|
||||||
size_t child_count = root->GetChildCount();
|
|
||||||
for (size_t i = 0; i < child_count; ++i) {
|
|
||||||
append_found_list(current_search_text, wxDataViewItem(root->GetNthChild(i)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void ObjectList::set_found_list(wxString current_search_text) {
|
void ObjectList::set_found_list(wxString current_search_text) {
|
||||||
|
|
||||||
m_found_list.clear();
|
|
||||||
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
||||||
current_search_text = current_search_text.MakeLower();
|
current_search_text = current_search_text.MakeLower();
|
||||||
for (int i = 0; i < ppl.get_plate_count(); ++i) {
|
|
||||||
wxDataViewItem plate_item = m_objects_model->GetItemByPlateId(i);
|
m_objects_model->append_found_list(current_search_text);
|
||||||
append_found_list(current_search_text, plate_item);
|
|
||||||
}
|
|
||||||
if (current_search_text.empty()) {
|
if (current_search_text.empty()) {
|
||||||
if (ppl.get_plate_count() > 0) {
|
if (ppl.get_plate_count() > 0) {
|
||||||
wxDataViewItem item = m_objects_model->GetItemByPlateId(0);
|
wxDataViewItem item = m_objects_model->GetItemByPlateId(0);
|
||||||
|
@ -832,8 +815,9 @@ void ObjectList::set_found_list(wxString current_search_text) {
|
||||||
column->SetTitle(_L("Name"));
|
column->SetTitle(_L("Name"));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
auto found_list = m_objects_model->get_search_list();
|
||||||
auto column = GetColumn(colName);
|
auto column = GetColumn(colName);
|
||||||
wxString match_num = wxString::Format("%d", m_found_list.size());
|
wxString match_num = wxString::Format("%d", found_list.size());
|
||||||
wxString match_message = " (" + match_num + _L(" search results") + ")";
|
wxString match_message = " (" + match_num + _L(" search results") + ")";
|
||||||
wxString column_name = _L("Name") + match_message;
|
wxString column_name = _L("Name") + match_message;
|
||||||
column->SetTitle(column_name);
|
column->SetTitle(column_name);
|
||||||
|
|
|
@ -186,7 +186,6 @@ private:
|
||||||
|
|
||||||
wxDataViewItem m_last_selected_item {nullptr};
|
wxDataViewItem m_last_selected_item {nullptr};
|
||||||
|
|
||||||
wxDataViewItemArray m_found_list;
|
|
||||||
#ifdef __WXMSW__
|
#ifdef __WXMSW__
|
||||||
// Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected.
|
// Workaround for entering the column editing mode on Windows. Simulate keyboard enter when another column of the active line is selected.
|
||||||
int m_last_selected_column = -1;
|
int m_last_selected_column = -1;
|
||||||
|
@ -217,8 +216,7 @@ public:
|
||||||
std::vector<ModelObject*>* objects() const { return m_objects; }
|
std::vector<ModelObject*>* objects() const { return m_objects; }
|
||||||
|
|
||||||
ModelObject* object(const int obj_idx) const ;
|
ModelObject* object(const int obj_idx) const ;
|
||||||
wxDataViewItemArray get_found_list() const { return m_found_list; }
|
|
||||||
|
|
||||||
|
|
||||||
void create_objects_ctrl();
|
void create_objects_ctrl();
|
||||||
// BBS
|
// BBS
|
||||||
|
@ -460,7 +458,6 @@ public:
|
||||||
|
|
||||||
// search objectlist
|
// search objectlist
|
||||||
void search_object_list();
|
void search_object_list();
|
||||||
void append_found_list(wxString current_search_text, wxDataViewItem item);
|
|
||||||
void set_found_list(wxString current_search_text);
|
void set_found_list(wxString current_search_text);
|
||||||
void set_cur_pos(int value);
|
void set_cur_pos(int value);
|
||||||
void searchbar_kill_focus();
|
void searchbar_kill_focus();
|
||||||
|
|
|
@ -213,10 +213,15 @@ bool ObjectSettings::update_settings_list()
|
||||||
is_plate_settings = true;
|
is_plate_settings = true;
|
||||||
|
|
||||||
int plate_id = objects_model->GetPlateIdByItem(item);
|
int plate_id = objects_model->GetPlateIdByItem(item);
|
||||||
assert(plate_id >= 0);
|
|
||||||
|
|
||||||
static ModelConfig cfg;
|
static ModelConfig cfg;
|
||||||
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
PartPlateList& ppl = wxGetApp().plater()->get_partplate_list();
|
||||||
|
|
||||||
|
if (plate_id < 0 || plate_id >= ppl.get_plate_count()) {
|
||||||
|
plate_id = ppl.get_curr_plate_index();
|
||||||
|
}
|
||||||
|
assert(plate_id >= 0 && plate_id < ppl.get_plate_count());
|
||||||
|
|
||||||
cfg.assign_config(*ppl.get_plate(plate_id)->config());
|
cfg.assign_config(*ppl.get_plate(plate_id)->config());
|
||||||
plate_configs.emplace(ppl.get_plate(plate_id), &cfg);
|
plate_configs.emplace(ppl.get_plate(plate_id), &cfg);
|
||||||
}
|
}
|
||||||
|
|
|
@ -469,7 +469,7 @@ wxBitmap& ObjectDataViewModel::GetWarningBitmap(const std::string& warning_icon_
|
||||||
wxDataViewItem ObjectDataViewModel::AddPlate(PartPlate* part_plate, wxString name, bool refresh)
|
wxDataViewItem ObjectDataViewModel::AddPlate(PartPlate* part_plate, wxString name, bool refresh)
|
||||||
{
|
{
|
||||||
int plate_idx = part_plate ? part_plate->get_index() : -1;
|
int plate_idx = part_plate ? part_plate->get_index() : -1;
|
||||||
wxString plate_name;
|
wxString plate_name = name;
|
||||||
if (name.empty()) {
|
if (name.empty()) {
|
||||||
plate_name = _L("Plate");
|
plate_name = _L("Plate");
|
||||||
plate_name += wxString::Format(" %d", plate_idx + 1);
|
plate_name += wxString::Format(" %d", plate_idx + 1);
|
||||||
|
@ -1492,6 +1492,29 @@ void ObjectDataViewModel::UpdateItemNames()
|
||||||
ItemsChanged(changed_items);
|
ItemsChanged(changed_items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectDataViewModel::append_found_list(wxString current_search_text)
|
||||||
|
{
|
||||||
|
found_list.clear();
|
||||||
|
for (int i = 0; i < m_plates.size(); ++i) {
|
||||||
|
append_found(current_search_text, m_plates[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectDataViewModel::append_found(wxString current_search_text, ObjectDataViewModelNode* item)
|
||||||
|
{
|
||||||
|
wxString item_name = item->GetName();
|
||||||
|
item_name = item_name.MakeLower();
|
||||||
|
|
||||||
|
if (item_name.find(current_search_text) != wxString::npos) {
|
||||||
|
if(item != m_plate_outside)
|
||||||
|
found_list.Add(wxDataViewItem(item));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (size_t i = 0; i < item->GetChildCount(); ++i) {
|
||||||
|
append_found(current_search_text, item->GetNthChild(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BBS: add use_obj_extruder
|
// BBS: add use_obj_extruder
|
||||||
void ObjectDataViewModel::UpdateVolumesExtruderBitmap(wxDataViewItem obj_item, bool use_obj_extruder)
|
void ObjectDataViewModel::UpdateVolumesExtruderBitmap(wxDataViewItem obj_item, bool use_obj_extruder)
|
||||||
{
|
{
|
||||||
|
|
|
@ -329,6 +329,7 @@ class ObjectDataViewModel :public wxDataViewModel
|
||||||
ObjectDataViewModelNode* m_plate_outside;
|
ObjectDataViewModelNode* m_plate_outside;
|
||||||
|
|
||||||
wxDataViewCtrl* m_ctrl { nullptr };
|
wxDataViewCtrl* m_ctrl { nullptr };
|
||||||
|
wxDataViewItemArray found_list;
|
||||||
public:
|
public:
|
||||||
ObjectDataViewModel();
|
ObjectDataViewModel();
|
||||||
~ObjectDataViewModel();
|
~ObjectDataViewModel();
|
||||||
|
@ -484,6 +485,9 @@ public:
|
||||||
// BBS
|
// BBS
|
||||||
void UpdateItemNames();
|
void UpdateItemNames();
|
||||||
|
|
||||||
|
void append_found_list(wxString current_search_text);
|
||||||
|
void append_found(wxString current_search_text, ObjectDataViewModelNode* item);
|
||||||
|
wxDataViewItemArray get_search_list() { return found_list; }
|
||||||
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);
|
||||||
|
|
Loading…
Reference in New Issue