mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-08-08 22:35:15 -06:00
CallBack from C++ to Perl to manipulations with object list
This commit is contained in:
parent
bc6e6492af
commit
9e0d2793cb
7 changed files with 94 additions and 13 deletions
|
@ -141,6 +141,7 @@ wxSizer *m_sizer_part_buttons = nullptr;
|
|||
wxDataViewCtrl *m_objects_ctrl = nullptr;
|
||||
MyObjectTreeModel *m_objects_model = nullptr;
|
||||
wxCollapsiblePane *m_collpane_settings = nullptr;
|
||||
int m_event_object_selection_changed = 0;
|
||||
|
||||
wxFont g_small_font;
|
||||
wxFont g_bold_font;
|
||||
|
@ -895,11 +896,24 @@ 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, [](wxEvent& evt)
|
||||
m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& event)
|
||||
{
|
||||
wxWindowUpdateLocker noUpdates(g_right_panel);
|
||||
auto item = m_objects_ctrl->GetSelection();
|
||||
if (!item) return;
|
||||
int obj_idx = -1;
|
||||
if (!item)
|
||||
unselect_objects();
|
||||
else
|
||||
obj_idx = m_objects_model->GetIdByItem(item);
|
||||
|
||||
if (m_event_object_selection_changed > 0) {
|
||||
wxCommandEvent event(m_event_object_selection_changed);
|
||||
event.SetInt(obj_idx);
|
||||
g_wxMainFrame->ProcessWindowEvent(event);
|
||||
}
|
||||
|
||||
if (obj_idx < 0) return;
|
||||
|
||||
// m_objects_ctrl->SetSize(m_objects_ctrl->GetBestSize()); // TODO override GetBestSize(), than use it
|
||||
auto show_obj_sizer = m_objects_model->GetParent(item) == wxDataViewItem(0);
|
||||
m_sizer_object_buttons->Show(show_obj_sizer);
|
||||
|
@ -908,6 +922,14 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
|||
m_collpane_settings->Show(true);
|
||||
});
|
||||
|
||||
m_objects_ctrl->Bind(wxEVT_KEY_DOWN, [](wxKeyEvent& event)
|
||||
{
|
||||
if (event.GetKeyCode() == WXK_TAB)
|
||||
m_objects_ctrl->Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
|
||||
else
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
return objects_sz;
|
||||
}
|
||||
|
||||
|
@ -1088,15 +1110,29 @@ void set_object_scale(int idx, int scale)
|
|||
void unselect_objects()
|
||||
{
|
||||
m_objects_ctrl->UnselectAll();
|
||||
if (m_sizer_object_buttons->IsShown(1))
|
||||
m_sizer_object_buttons->Show(false);
|
||||
if (m_sizer_part_buttons->IsShown(1))
|
||||
m_sizer_part_buttons->Show(false);
|
||||
if (m_collpane_settings->IsShown())
|
||||
m_collpane_settings->Show(false);
|
||||
}
|
||||
|
||||
void select_current_object(int idx)
|
||||
{
|
||||
m_objects_ctrl->UnselectAll();
|
||||
if (idx < 0) return;
|
||||
m_objects_ctrl->Select(m_objects_model->GetItemById(idx));
|
||||
|
||||
if (!m_sizer_object_buttons->IsShown(1))
|
||||
m_sizer_object_buttons->Show(true);
|
||||
if (!m_collpane_settings->IsShown())
|
||||
m_collpane_settings->Show(true);
|
||||
}
|
||||
|
||||
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer)
|
||||
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer, int event_object_selection_changed)
|
||||
{
|
||||
m_event_object_selection_changed = event_object_selection_changed;
|
||||
wxWindowUpdateLocker noUpdates(parent);
|
||||
|
||||
auto btn_grid_sizer = new wxGridSizer(1, 3, 2, 2);
|
||||
|
@ -1135,8 +1171,7 @@ void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer)
|
|||
}));
|
||||
|
||||
// *** Object/Part Settings ***
|
||||
m_collpane_settings = add_collapsible_pane(parent, sizer, "Settings:", content_settings);
|
||||
m_collpane_settings->Hide(); // ? TODO why doesn't work?
|
||||
m_collpane_settings = add_collapsible_pane(parent, sizer, "Settings", content_settings);
|
||||
|
||||
add_btn->Bind(wxEVT_BUTTON, [](wxEvent& )
|
||||
{
|
||||
|
|
|
@ -190,7 +190,7 @@ void unselect_objects();
|
|||
// Select current object in the list on c++ side
|
||||
void select_current_object(int idx);
|
||||
|
||||
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer);
|
||||
void add_expert_mode_part(wxWindow* parent, wxBoxSizer* sizer, int event_object_selection_changed);
|
||||
void add_frequently_changed_parameters(wxWindow* parent, wxBoxSizer* sizer, wxFlexGridSizer* preset_sizer);
|
||||
// Update view mode according to selected menu
|
||||
void update_mode();
|
||||
|
|
|
@ -452,6 +452,18 @@ wxDataViewItem MyObjectTreeModel::GetItemById(int obj_idx)
|
|||
}
|
||||
|
||||
|
||||
int MyObjectTreeModel::GetIdByItem(wxDataViewItem& item)
|
||||
{
|
||||
wxASSERT(item.IsOk());
|
||||
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
auto it = find(m_objects.begin(), m_objects.end(), node);
|
||||
if (it == m_objects.end())
|
||||
return -1;
|
||||
|
||||
return it - m_objects.begin();
|
||||
}
|
||||
|
||||
wxString MyObjectTreeModel::GetName(const wxDataViewItem &item) const
|
||||
{
|
||||
MyObjectTreeModelNode *node = (MyObjectTreeModelNode*)item.GetID();
|
||||
|
|
|
@ -253,6 +253,7 @@ public:
|
|||
wxDataViewItem Delete(const wxDataViewItem &item);
|
||||
void DeleteAll();
|
||||
wxDataViewItem GetItemById(int obj_idx);
|
||||
int GetIdByItem(wxDataViewItem& item);
|
||||
bool IsEmpty() { return m_objects.empty(); }
|
||||
|
||||
// helper method for wxLog
|
||||
|
|
|
@ -87,9 +87,9 @@ void add_frequently_changed_parameters(SV *ui_parent, SV *ui_sizer, SV *ui_p_siz
|
|||
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"),
|
||||
(wxFlexGridSizer*)wxPli_sv_2_object(aTHX_ ui_p_sizer, "Wx::FlexGridSizer")); %};
|
||||
|
||||
void add_expert_mode_part(SV *ui_parent, SV *ui_sizer)
|
||||
void add_expert_mode_part(SV *ui_parent, SV *ui_sizer, int event)
|
||||
%code%{ Slic3r::GUI::add_expert_mode_part((wxWindow*)wxPli_sv_2_object(aTHX_ ui_parent, "Wx::Window"),
|
||||
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer")); %};
|
||||
(wxBoxSizer*)wxPli_sv_2_object(aTHX_ ui_sizer, "Wx::BoxSizer"), event); %};
|
||||
|
||||
void set_objects_from_perl( SV *ui_parent,
|
||||
SV *frequently_changed_parameters_sizer,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue