mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-12 01:07:57 -06:00
"MoveUp" & "MoveDown" work correctly
This commit is contained in:
parent
12232f1a6d
commit
a772a19915
3 changed files with 86 additions and 7 deletions
|
@ -81,15 +81,15 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
||||||
|
|
||||||
// column 0(Icon+Text) of the view control:
|
// column 0(Icon+Text) of the view control:
|
||||||
m_objects_ctrl->AppendIconTextColumn(_(L("Name")), 0, wxDATAVIEW_CELL_INERT, 150,
|
m_objects_ctrl->AppendIconTextColumn(_(L("Name")), 0, wxDATAVIEW_CELL_INERT, 150,
|
||||||
wxALIGN_LEFT, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
wxALIGN_LEFT, /*wxDATAVIEW_COL_SORTABLE | */wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
|
||||||
// column 1 of the view control:
|
// column 1 of the view control:
|
||||||
m_objects_ctrl->AppendTextColumn(_(L("Copy")), 1, wxDATAVIEW_CELL_INERT, 65,
|
m_objects_ctrl->AppendTextColumn(_(L("Copy")), 1, wxDATAVIEW_CELL_INERT, 65,
|
||||||
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
|
||||||
// column 2 of the view control:
|
// column 2 of the view control:
|
||||||
m_objects_ctrl->AppendTextColumn(_(L("Scale")), 2, wxDATAVIEW_CELL_INERT, 70,
|
m_objects_ctrl->AppendTextColumn(_(L("Scale")), 2, wxDATAVIEW_CELL_INERT, 70,
|
||||||
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_SORTABLE | wxDATAVIEW_COL_RESIZABLE);
|
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
||||||
|
|
||||||
m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& event)
|
m_objects_ctrl->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [](wxEvent& event)
|
||||||
{
|
{
|
||||||
|
@ -106,7 +106,8 @@ wxBoxSizer* content_objects_list(wxWindow *win)
|
||||||
obj_idx = m_objects_model->GetIdByItem(item);
|
obj_idx = m_objects_model->GetIdByItem(item);
|
||||||
else {
|
else {
|
||||||
auto parent = m_objects_model->GetParent(item);
|
auto parent = m_objects_model->GetParent(item);
|
||||||
obj_idx = m_objects_model->GetIdByItem(parent); // TODO Temporary decision for sub-objects selection
|
// Take ID of the parent object to "inform" perl-side which object have to be selected on the scene
|
||||||
|
obj_idx = m_objects_model->GetIdByItem(parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_selected_object_id = obj_idx;
|
m_selected_object_id = obj_idx;
|
||||||
|
@ -605,7 +606,7 @@ void on_btn_move_up(){
|
||||||
if (0 < volume_id && volume_id < volumes.size()) {
|
if (0 < volume_id && volume_id < volumes.size()) {
|
||||||
std::swap(volumes[volume_id - 1], volumes[volume_id]);
|
std::swap(volumes[volume_id - 1], volumes[volume_id]);
|
||||||
m_parts_changed = true;
|
m_parts_changed = true;
|
||||||
// TODO update model ($volume_id - 1);
|
m_objects_ctrl->Select(m_objects_model->MoveChildUp(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,9 +619,9 @@ void on_btn_move_down(){
|
||||||
return;
|
return;
|
||||||
auto& volumes = m_objects[m_selected_object_id]->volumes;
|
auto& volumes = m_objects[m_selected_object_id]->volumes;
|
||||||
if (0 <= volume_id && volume_id+1 < volumes.size()) {
|
if (0 <= volume_id && volume_id+1 < volumes.size()) {
|
||||||
std::swap(volumes[volume_id + 1], volumes[volume_id - 1]);
|
std::swap(volumes[volume_id + 1], volumes[volume_id]);
|
||||||
m_parts_changed = true;
|
m_parts_changed = true;
|
||||||
// TODO update model ($volume_id - 1);
|
m_objects_ctrl->Select(m_objects_model->MoveChildDown(item));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -556,6 +556,54 @@ bool PrusaObjectDataViewModel::SetValue(const wxVariant &variant, const int item
|
||||||
return m_objects[item_idx]->SetValue(variant, col);
|
return m_objects[item_idx]->SetValue(variant, col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wxDataViewItem PrusaObjectDataViewModel::MoveChildUp(const wxDataViewItem &item)
|
||||||
|
{
|
||||||
|
auto ret_item = wxDataViewItem(0);
|
||||||
|
wxASSERT(item.IsOk());
|
||||||
|
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||||
|
if (!node) // happens if item.IsOk()==false
|
||||||
|
return ret_item;
|
||||||
|
|
||||||
|
auto node_parent = node->GetParent();
|
||||||
|
if (!node_parent) // If isn't part, but object
|
||||||
|
return ret_item;
|
||||||
|
|
||||||
|
auto volume_id = node->GetVolumeId();
|
||||||
|
if (0 < volume_id && volume_id < node_parent->GetChildCount()){
|
||||||
|
node_parent->SwapChildrens(volume_id - 1, volume_id);
|
||||||
|
ret_item = wxDataViewItem(node_parent->GetNthChild(volume_id - 1));
|
||||||
|
ItemChanged(item);
|
||||||
|
ItemChanged(ret_item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret_item = wxDataViewItem(node_parent->GetNthChild(0));
|
||||||
|
return ret_item;
|
||||||
|
}
|
||||||
|
|
||||||
|
wxDataViewItem PrusaObjectDataViewModel::MoveChildDown(const wxDataViewItem &item)
|
||||||
|
{
|
||||||
|
auto ret_item = wxDataViewItem(0);
|
||||||
|
wxASSERT(item.IsOk());
|
||||||
|
PrusaObjectDataViewModelNode *node = (PrusaObjectDataViewModelNode*)item.GetID();
|
||||||
|
if (!node) // happens if item.IsOk()==false
|
||||||
|
return ret_item;
|
||||||
|
|
||||||
|
auto node_parent = node->GetParent();
|
||||||
|
if (!node_parent) // If isn't part, but object
|
||||||
|
return ret_item;
|
||||||
|
|
||||||
|
auto volume_id = node->GetVolumeId();
|
||||||
|
if (0 <= volume_id && volume_id+1 < node_parent->GetChildCount()){
|
||||||
|
node_parent->SwapChildrens(volume_id + 1, volume_id);
|
||||||
|
ret_item = wxDataViewItem(node_parent->GetNthChild(volume_id + 1));
|
||||||
|
ItemChanged(item);
|
||||||
|
ItemChanged(ret_item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
ret_item = wxDataViewItem(node_parent->GetNthChild(node_parent->GetChildCount()-1));
|
||||||
|
return ret_item;
|
||||||
|
}
|
||||||
|
|
||||||
// bool MyObjectTreeModel::IsEnabled(const wxDataViewItem &item, unsigned int col) const
|
// bool MyObjectTreeModel::IsEnabled(const wxDataViewItem &item, unsigned int col) const
|
||||||
// {
|
// {
|
||||||
//
|
//
|
||||||
|
|
|
@ -282,6 +282,33 @@ public:
|
||||||
const int& GetVolumeId(){
|
const int& GetVolumeId(){
|
||||||
return m_volume_id;
|
return m_volume_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// use this function only for childrens
|
||||||
|
void AssignAllVal(PrusaObjectDataViewModelNode& from_node)
|
||||||
|
{
|
||||||
|
// ! Don't overwrite other values because of equality of this values for all children --
|
||||||
|
m_name = from_node.m_name;
|
||||||
|
m_icon = from_node.m_icon;
|
||||||
|
m_volume_id = from_node.m_volume_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool SwapChildrens(int frst_id, int scnd_id) {
|
||||||
|
if (GetChildCount() < 2 ||
|
||||||
|
frst_id < 0 || frst_id >= GetChildCount() ||
|
||||||
|
scnd_id < 0 || scnd_id >= GetChildCount())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
PrusaObjectDataViewModelNode new_scnd = *GetNthChild(frst_id);
|
||||||
|
PrusaObjectDataViewModelNode new_frst = *GetNthChild(scnd_id);
|
||||||
|
|
||||||
|
new_scnd.m_volume_id = m_children.Item(scnd_id)->m_volume_id;
|
||||||
|
new_frst.m_volume_id = m_children.Item(frst_id)->m_volume_id;
|
||||||
|
|
||||||
|
m_children.Item(frst_id)->AssignAllVal(new_frst);
|
||||||
|
m_children.Item(scnd_id)->AssignAllVal(new_scnd);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
@ -328,6 +355,9 @@ public:
|
||||||
const wxDataViewItem &item, unsigned int col) override;
|
const wxDataViewItem &item, unsigned int col) override;
|
||||||
bool SetValue(const wxVariant &variant, const int item_idx, unsigned int col);
|
bool SetValue(const wxVariant &variant, const int item_idx, unsigned int col);
|
||||||
|
|
||||||
|
wxDataViewItem MoveChildUp(const wxDataViewItem &item);
|
||||||
|
wxDataViewItem MoveChildDown(const wxDataViewItem &item);
|
||||||
|
|
||||||
// virtual bool IsEnabled(const wxDataViewItem &item,
|
// virtual bool IsEnabled(const wxDataViewItem &item,
|
||||||
// unsigned int col) const override;
|
// unsigned int col) const override;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue