Added "Add/Delete" functions to the MyObjectTreeModel
This commit is contained in:
parent
45b6c99353
commit
db7c58009c
3 changed files with 76 additions and 28 deletions
|
@ -139,6 +139,7 @@ bool g_show_manifold_warning_icon = false;
|
||||||
wxSizer *m_sizer_object_buttons = nullptr;
|
wxSizer *m_sizer_object_buttons = nullptr;
|
||||||
wxSizer *m_sizer_part_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;
|
PrusaCollapsiblePane *m_collpane_settings = nullptr;
|
||||||
|
|
||||||
wxFont g_small_font{ wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) };
|
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 = new wxDataViewCtrl(win, wxID_ANY, wxDefaultPosition, wxDefaultSize);
|
||||||
m_objects_ctrl->SetInitialSize(wxSize(-1, 150)); // TODO - Set correct height according to the opened/closed objects
|
m_objects_ctrl->SetInitialSize(wxSize(-1, 150)); // TODO - Set correct height according to the opened/closed objects
|
||||||
auto objects_sz = new wxBoxSizer(wxVERTICAL);
|
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_model = new MyObjectTreeModel;
|
||||||
m_objects_ctrl->AssociateModel(objects_model);
|
m_objects_ctrl->AssociateModel(m_objects_model);
|
||||||
#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
||||||
m_objects_ctrl->EnableDragSource(wxDF_UNICODETEXT);
|
m_objects_ctrl->EnableDragSource(wxDF_UNICODETEXT);
|
||||||
m_objects_ctrl->EnableDropTarget(wxDF_UNICODETEXT);
|
m_objects_ctrl->EnableDropTarget(wxDF_UNICODETEXT);
|
||||||
|
@ -883,13 +884,13 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
||||||
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
||||||
m_objects_ctrl->AppendColumn(column02);
|
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);
|
wxWindowUpdateLocker noUpdates(g_right_panel);
|
||||||
auto item = m_objects_ctrl->GetSelection();
|
auto item = m_objects_ctrl->GetSelection();
|
||||||
if (!item) return;
|
if (!item) return;
|
||||||
// m_objects_ctrl->SetSize(m_objects_ctrl->GetBestSize()); // TODO override GetBestSize(), than use it
|
// 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_object_buttons->Show(show_obj_sizer);
|
||||||
m_sizer_part_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"))) + ":");
|
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_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_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);
|
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_up->SetMinSize(wxSize(20, -1));
|
||||||
btn_move_down->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));
|
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);
|
wxWindowUpdateLocker noUpdates(parent);
|
||||||
|
|
||||||
// Experiments with new UI
|
// 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 ***
|
// *** Objects List ***
|
||||||
auto collpane = add_prusa_collapsible_pane(parent, sizer, "Objects List:", content_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 = add_prusa_collapsible_pane(parent, sizer, "Settings:", content_settings);
|
||||||
m_collpane_settings->Hide(); // ? TODO why doesn't work?
|
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
|
// More experiments with UI
|
||||||
// auto listctrl = new wxDataViewListCtrl(main_page, wxID_ANY, wxDefaultPosition, wxSize(-1, 100));
|
// auto listctrl = new wxDataViewListCtrl(main_page, wxID_ANY, wxDefaultPosition, wxSize(-1, 100));
|
||||||
// listctrl->AppendToggleColumn("Toggle");
|
// listctrl->AppendToggleColumn("Toggle");
|
||||||
|
|
|
@ -352,26 +352,52 @@ bool PrusaCollapsiblePane::Layout()
|
||||||
// MyObjectTreeModel
|
// MyObjectTreeModel
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
MyObjectTreeModel::MyObjectTreeModel()
|
void MyObjectTreeModel::Add(wxString &name)
|
||||||
{
|
{
|
||||||
auto root1 = new MyObjectTreeModelNode("Object1");
|
auto root = new MyObjectTreeModelNode(name);
|
||||||
m_objects.emplace(root1);
|
m_objects.emplace(root);
|
||||||
|
// notify control
|
||||||
|
wxDataViewItem child((void*)root);
|
||||||
|
wxDataViewItem parent((void*)NULL);
|
||||||
|
ItemAdded(parent, child);
|
||||||
|
}
|
||||||
|
|
||||||
auto root2 = new MyObjectTreeModelNode("Object2");
|
void MyObjectTreeModel::AddChild(const wxDataViewItem &parent_item, wxString &name)
|
||||||
m_objects.emplace(root2);
|
{
|
||||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_1"));
|
MyObjectTreeModelNode *root = (MyObjectTreeModelNode*)parent_item.GetID();
|
||||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_2"));
|
if (!root) return;
|
||||||
root2->Append(new MyObjectTreeModelNode(root2, "SubObject2_3"));
|
|
||||||
|
|
||||||
auto root3 = new MyObjectTreeModelNode("Object3");
|
auto node = new MyObjectTreeModelNode(root, name);
|
||||||
m_objects.emplace(root3);
|
root->Append(node);
|
||||||
auto root4 = new MyObjectTreeModelNode("Object4");
|
// notify control
|
||||||
m_objects.emplace(root4);
|
wxDataViewItem child((void*)node);
|
||||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_1"));
|
ItemAdded(parent_item, child);
|
||||||
root4->Append(new MyObjectTreeModelNode(root4, "SubObject4_2"));
|
}
|
||||||
|
|
||||||
auto root5 = new MyObjectTreeModelNode("Object5");
|
void MyObjectTreeModel::Delete(const wxDataViewItem &item)
|
||||||
m_objects.emplace(root5);
|
{
|
||||||
|
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
|
wxString MyObjectTreeModel::GetName(const wxDataViewItem &item) const
|
||||||
|
@ -463,7 +489,7 @@ wxDataViewItem MyObjectTreeModel::GetParent(const wxDataViewItem &item) const
|
||||||
|
|
||||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
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())
|
if (m_objects.find(node) != m_objects.end())
|
||||||
return wxDataViewItem(0);
|
return wxDataViewItem(0);
|
||||||
|
|
||||||
|
|
|
@ -209,13 +209,17 @@ class MyObjectTreeModel :public wxDataViewModel
|
||||||
{
|
{
|
||||||
std::set<MyObjectTreeModelNode*> m_objects;
|
std::set<MyObjectTreeModelNode*> m_objects;
|
||||||
public:
|
public:
|
||||||
MyObjectTreeModel();
|
MyObjectTreeModel(){}
|
||||||
~MyObjectTreeModel()
|
~MyObjectTreeModel()
|
||||||
{
|
{
|
||||||
for (auto object : m_objects)
|
for (auto object : m_objects)
|
||||||
delete object;
|
delete object;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Add(wxString &name);
|
||||||
|
void AddChild(const wxDataViewItem &parent_item, wxString &name);
|
||||||
|
void Delete(const wxDataViewItem &item);
|
||||||
|
|
||||||
// helper method for wxLog
|
// helper method for wxLog
|
||||||
|
|
||||||
wxString GetName(const wxDataViewItem &item) const;
|
wxString GetName(const wxDataViewItem &item) const;
|
||||||
|
@ -224,10 +228,6 @@ public:
|
||||||
|
|
||||||
// helper methods to change the model
|
// 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 unsigned int GetColumnCount() const override { return 3;}
|
||||||
virtual wxString GetColumnType(unsigned int col) const override{ return wxT("string"); }
|
virtual wxString GetColumnType(unsigned int col) const override{ return wxT("string"); }
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue