diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 170051207..991402a51 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -138,7 +138,8 @@ bool g_show_print_info = false; bool g_show_manifold_warning_icon = false; wxSizer *m_sizer_object_buttons = nullptr; wxSizer *m_sizer_part_buttons = nullptr; -wxDataViewCtrl *m_objects_ctrl = nullptr; +wxDataViewCtrl *m_objects_ctrl = nullptr; +MyObjectTreeModel *m_objects_model = nullptr; PrusaCollapsiblePane *m_collpane_settings = nullptr; wxFont g_small_font{ wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) }; @@ -853,10 +854,10 @@ wxBoxSizer* content_objects_list(wxWindow *win) m_objects_ctrl = new wxDataViewCtrl(win, wxID_ANY, wxDefaultPosition, wxDefaultSize); m_objects_ctrl->SetInitialSize(wxSize(-1, 150)); // TODO - Set correct height according to the opened/closed objects auto objects_sz = new wxBoxSizer(wxVERTICAL); - objects_sz->Add(m_objects_ctrl, 1, wxGROW | wxLEFT/*ALL*/, 20/*5*/); + objects_sz->Add(m_objects_ctrl, 1, wxGROW | wxLEFT, 20); - auto objects_model = new MyObjectTreeModel; - m_objects_ctrl->AssociateModel(objects_model); + m_objects_model = new MyObjectTreeModel; + m_objects_ctrl->AssociateModel(m_objects_model); #if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE m_objects_ctrl->EnableDragSource(wxDF_UNICODETEXT); m_objects_ctrl->EnableDropTarget(wxDF_UNICODETEXT); @@ -883,13 +884,13 @@ wxBoxSizer* content_objects_list(wxWindow *win) wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE); m_objects_ctrl->AppendColumn(column02); - m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [objects_model](wxEvent& evt) + m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& evt) { wxWindowUpdateLocker noUpdates(g_right_panel); auto item = m_objects_ctrl->GetSelection(); if (!item) return; // m_objects_ctrl->SetSize(m_objects_ctrl->GetBestSize()); // TODO override GetBestSize(), than use it - auto show_obj_sizer = objects_model->GetParent(item) == wxDataViewItem(0); + auto show_obj_sizer = m_objects_model->GetParent(item) == wxDataViewItem(0); m_sizer_object_buttons->Show(show_obj_sizer); m_sizer_part_buttons->Show(!show_obj_sizer); m_collpane_settings->SetLabelText((show_obj_sizer ? _(L("Object Settings")) : _(L("Part Settings"))) + ":"); @@ -910,6 +911,17 @@ wxBoxSizer* content_edit_object_buttons(wxWindow* win) auto btn_split = new wxButton(win, wxID_ANY, "Split"/*" part"*/, wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER/*wxBU_LEFT*/); auto btn_move_up = new wxButton(win, wxID_ANY, "", wxDefaultPosition, wxDefaultSize/*wxSize(30, -1)*/, wxBU_LEFT); auto btn_move_down = new wxButton(win, wxID_ANY, "", wxDefaultPosition, wxDefaultSize/*wxSize(30, -1)*/, wxBU_LEFT); + + //*** button's functions + btn_load_part->Bind(wxEVT_BUTTON, [](wxEvent&) + { + auto item = m_objects_ctrl->GetSelection(); + if (!item) return; + wxString name = "Part"; + m_objects_model->AddChild(item, name); + }); + //*** + btn_move_up->SetMinSize(wxSize(20, -1)); btn_move_down->SetMinSize(wxSize(20, -1)); btn_load_part->SetBitmap(wxBitmap(from_u8(Slic3r::var("brick_add.png")), wxBITMAP_TYPE_PNG)); @@ -1021,6 +1033,10 @@ void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer) wxWindowUpdateLocker noUpdates(parent); // Experiments with new UI + auto add_btn = new wxButton(parent, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT | wxNO_BORDER); + if (wxMSW) add_btn->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + add_btn->SetBitmap(wxBitmap(from_u8(Slic3r::var("add.png")), wxBITMAP_TYPE_PNG)); + sizer->Add(add_btn, 0, wxALIGN_LEFT | wxLEFT, 20); // *** Objects List *** auto collpane = add_prusa_collapsible_pane(parent, sizer, "Objects List:", content_objects_list); @@ -1042,6 +1058,12 @@ void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer) m_collpane_settings = add_prusa_collapsible_pane(parent, sizer, "Settings:", content_settings); m_collpane_settings->Hide(); // ? TODO why doesn't work? + add_btn->Bind(wxEVT_BUTTON, [](wxEvent& ) + { + wxString name = "Object"; + m_objects_model->Add(name); + }); + // More experiments with UI // auto listctrl = new wxDataViewListCtrl(main_page, wxID_ANY, wxDefaultPosition, wxSize(-1, 100)); // listctrl->AppendToggleColumn("Toggle"); diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index eb851ffd4..7e7792ee4 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -352,26 +352,52 @@ bool PrusaCollapsiblePane::Layout() // MyObjectTreeModel // ---------------------------------------------------------------------------- -MyObjectTreeModel::MyObjectTreeModel() +void MyObjectTreeModel::Add(wxString &name) { - auto root1 = new MyObjectTreeModelNode("Object1"); - m_objects.emplace(root1); + auto root = new MyObjectTreeModelNode(name); + m_objects.emplace(root); + // notify control + wxDataViewItem child((void*)root); + wxDataViewItem parent((void*)NULL); + ItemAdded(parent, child); +} - auto root2 = new MyObjectTreeModelNode("Object2"); - m_objects.emplace(root2); - root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_1")); - root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_2")); - root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_3")); +void MyObjectTreeModel::AddChild(const wxDataViewItem &parent_item, wxString &name) +{ + MyObjectTreeModelNode *root = (MyObjectTreeModelNode*)parent_item.GetID(); + if (!root) return; - auto root3 = new MyObjectTreeModelNode("Object3"); - m_objects.emplace(root3); - auto root4 = new MyObjectTreeModelNode("Object4"); - m_objects.emplace(root4); - root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_1")); - root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_2")); + auto node = new MyObjectTreeModelNode(root, name); + root->Append(node); + // notify control + wxDataViewItem child((void*)node); + ItemAdded(parent_item, child); +} - auto root5 = new MyObjectTreeModelNode("Object5"); - m_objects.emplace(root5); +void MyObjectTreeModel::Delete(const wxDataViewItem &item) +{ + MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID(); + if (!node) // happens if item.IsOk()==false + return; + + wxDataViewItem parent(node->GetParent()); + if (!parent.IsOk()) + { +// wxASSERT(node == m_root); + // don't make the control completely empty: + //wxLogError("Cannot remove the root item!"); + return; + } + + // first remove the node from the parent's array of children; + // NOTE: MyObjectTreeModelNodePtrArray is only an array of _pointers_ + // thus removing the node from it doesn't result in freeing it + node->GetParent()->GetChildren().Remove(node); + // free the node + delete node; + + // notify control + ItemDeleted(parent, item); } wxString MyObjectTreeModel::GetName(const wxDataViewItem &item) const @@ -463,7 +489,7 @@ wxDataViewItem MyObjectTreeModel::GetParent(const wxDataViewItem &item) const MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID(); - // objects nodes also has no parent + // objects nodes has no parent too if (m_objects.find(node) != m_objects.end()) return wxDataViewItem(0); diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 51c77210e..02bcfe148 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -209,13 +209,17 @@ class MyObjectTreeModel :public wxDataViewModel { std::set m_objects; public: - MyObjectTreeModel(); + MyObjectTreeModel(){} ~MyObjectTreeModel() { for (auto object : m_objects) delete object; } + void Add(wxString &name); + void AddChild(const wxDataViewItem &parent_item, wxString &name); + void Delete(const wxDataViewItem &item); + // helper method for wxLog wxString GetName(const wxDataViewItem &item) const; @@ -224,10 +228,6 @@ public: // helper methods to change the model -// void AddToClassical(const wxString &title, const wxString &artist, -// unsigned int year); -// void Delete(const wxDataViewItem &item); - virtual unsigned int GetColumnCount() const override { return 3;} virtual wxString GetColumnType(unsigned int col) const override{ return wxT("string"); }