2018-10-04 14:43:10 +00:00
|
|
|
#include "GUI_ObjectList.hpp"
|
2018-10-05 21:29:15 +00:00
|
|
|
#include "GUI_ObjectManipulation.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
#include "GUI_App.hpp"
|
|
|
|
|
|
|
|
#include "OptionsGroup.hpp"
|
|
|
|
#include "PresetBundle.hpp"
|
|
|
|
#include "Tab.hpp"
|
|
|
|
#include "wxExtensions.hpp"
|
2018-10-05 21:29:15 +00:00
|
|
|
#include "Model.hpp"
|
|
|
|
#include "LambdaObjectDialog.hpp"
|
2018-10-11 13:57:09 +00:00
|
|
|
#include "GLCanvas3D.hpp"
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
#include <boost/algorithm/string.hpp>
|
|
|
|
#include "slic3r/Utils/FixModelByWin10.hpp"
|
|
|
|
|
|
|
|
namespace Slic3r
|
|
|
|
{
|
|
|
|
namespace GUI
|
|
|
|
{
|
|
|
|
|
2018-11-01 13:02:38 +00:00
|
|
|
wxDEFINE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
|
2018-11-01 11:33:56 +00:00
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
ObjectList::ObjectList(wxWindow* parent) :
|
2018-10-10 14:22:20 +00:00
|
|
|
wxDataViewCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE)
|
2018-10-04 14:43:10 +00:00
|
|
|
{
|
2018-10-05 21:29:15 +00:00
|
|
|
// Fill CATEGORY_ICON
|
|
|
|
{
|
|
|
|
CATEGORY_ICON[L("Layers and Perimeters")] = wxBitmap(from_u8(var("layers.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Infill")] = wxBitmap(from_u8(var("infill.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Support material")] = wxBitmap(from_u8(var("building.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Speed")] = wxBitmap(from_u8(var("time.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Extruders")] = wxBitmap(from_u8(var("funnel.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Extrusion Width")] = wxBitmap(from_u8(var("funnel.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
// CATEGORY_ICON[L("Skirt and brim")] = wxBitmap(from_u8(var("box.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
// CATEGORY_ICON[L("Speed > Acceleration")] = wxBitmap(from_u8(var("time.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
CATEGORY_ICON[L("Advanced")] = wxBitmap(from_u8(var("wand.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
// create control
|
|
|
|
create_objects_ctrl();
|
|
|
|
|
2018-11-02 22:27:31 +00:00
|
|
|
init_icons();
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
// describe control behavior
|
2018-10-08 14:27:38 +00:00
|
|
|
Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this](wxEvent& event) {
|
2018-10-11 13:57:09 +00:00
|
|
|
selection_changed();
|
2018-10-04 14:43:10 +00:00
|
|
|
#ifndef __WXMSW__
|
|
|
|
set_tooltip_for_item(get_mouse_position_in_control());
|
|
|
|
#endif //__WXMSW__
|
|
|
|
});
|
|
|
|
|
2018-10-08 14:27:38 +00:00
|
|
|
Bind(wxEVT_DATAVIEW_ITEM_CONTEXT_MENU, [this](wxDataViewEvent& event) {
|
2018-10-11 13:57:09 +00:00
|
|
|
context_menu();
|
2018-10-04 14:43:10 +00:00
|
|
|
});
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
Bind(wxEVT_CHAR, [this](wxKeyEvent& event) { key_event(event); }); // doesn't work on OSX
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
#ifdef __WXMSW__
|
|
|
|
// Extruder value changed
|
2018-10-08 14:27:38 +00:00
|
|
|
Bind(wxEVT_CHOICE, [this](wxCommandEvent& event) { update_extruder_in_config(event.GetString()); });
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-10-08 14:27:38 +00:00
|
|
|
GetMainWindow()->Bind(wxEVT_MOTION, [this](wxMouseEvent& event) {
|
2018-10-16 09:08:37 +00:00
|
|
|
set_tooltip_for_item(/*event.GetPosition()*/get_mouse_position_in_control());
|
2018-10-04 14:43:10 +00:00
|
|
|
event.Skip();
|
|
|
|
});
|
|
|
|
#else
|
|
|
|
// equivalent to wxEVT_CHOICE on __WXMSW__
|
2018-10-11 13:57:09 +00:00
|
|
|
Bind(wxEVT_DATAVIEW_ITEM_VALUE_CHANGED, [this](wxDataViewEvent& e) { item_value_change(e); });
|
2018-10-04 14:43:10 +00:00
|
|
|
#endif //__WXMSW__
|
|
|
|
|
2018-10-08 14:27:38 +00:00
|
|
|
Bind(wxEVT_DATAVIEW_ITEM_BEGIN_DRAG, [this](wxDataViewEvent& e) {on_begin_drag(e); });
|
|
|
|
Bind(wxEVT_DATAVIEW_ITEM_DROP_POSSIBLE, [this](wxDataViewEvent& e) {on_drop_possible(e); });
|
|
|
|
Bind(wxEVT_DATAVIEW_ITEM_DROP, [this](wxDataViewEvent& e) {on_drop(e); });
|
2018-11-12 12:47:24 +00:00
|
|
|
|
|
|
|
Bind(wxCUSTOMEVT_LAST_VOLUME_IS_DELETED,[this](wxCommandEvent& e) {last_volume_is_deleted(e.GetInt()); });
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ObjectList::~ObjectList()
|
|
|
|
{
|
|
|
|
if (m_default_config)
|
|
|
|
delete m_default_config;
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::create_objects_ctrl()
|
|
|
|
{
|
2018-11-15 11:25:08 +00:00
|
|
|
// temporary workaround for the correct behavior of the Scrolled sidebar panel:
|
|
|
|
// 1. set a height of the list to some big value
|
|
|
|
// 2. change it to the normal min value (200) after first whole App updating/layouting
|
|
|
|
SetMinSize(wxSize(-1, 1500)); // #ys_FIXME
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
m_sizer = new wxBoxSizer(wxVERTICAL);
|
2018-10-08 14:27:38 +00:00
|
|
|
m_sizer->Add(this, 1, wxGROW | wxLEFT, 20);
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
m_objects_model = new PrusaObjectDataViewModel;
|
2018-10-08 14:27:38 +00:00
|
|
|
AssociateModel(m_objects_model);
|
2018-11-12 12:47:24 +00:00
|
|
|
m_objects_model->SetAssociatedControl(this);
|
2018-10-04 14:43:10 +00:00
|
|
|
#if wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
2018-10-08 14:27:38 +00:00
|
|
|
EnableDragSource(wxDF_UNICODETEXT);
|
|
|
|
EnableDropTarget(wxDF_UNICODETEXT);
|
2018-10-04 14:43:10 +00:00
|
|
|
#endif // wxUSE_DRAG_AND_DROP && wxUSE_UNICODE
|
|
|
|
|
|
|
|
// column 0(Icon+Text) of the view control:
|
|
|
|
// And Icon can be consisting of several bitmaps
|
2018-10-08 14:27:38 +00:00
|
|
|
AppendColumn(new wxDataViewColumn(_(L("Name")), new PrusaBitmapTextRenderer(),
|
2018-11-12 12:47:24 +00:00
|
|
|
0, 200, wxALIGN_LEFT, wxDATAVIEW_COL_RESIZABLE));
|
2018-10-04 14:43:10 +00:00
|
|
|
|
|
|
|
// column 1 of the view control:
|
2018-10-08 14:27:38 +00:00
|
|
|
AppendColumn(create_objects_list_extruder_column(4));
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-10-18 09:28:31 +00:00
|
|
|
// column 2 of the view control:
|
|
|
|
AppendBitmapColumn(" ", 2, wxDATAVIEW_CELL_INERT, 25,
|
2018-10-04 14:43:10 +00:00
|
|
|
wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::set_tooltip_for_item(const wxPoint& pt)
|
|
|
|
{
|
|
|
|
wxDataViewItem item;
|
|
|
|
wxDataViewColumn* col;
|
2018-10-08 14:27:38 +00:00
|
|
|
HitTest(pt, item, col);
|
2018-10-04 14:43:10 +00:00
|
|
|
if (!item) return;
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
if (col->GetTitle() == " " && GetSelectedItemsCount()<2)
|
2018-10-08 14:27:38 +00:00
|
|
|
GetMainWindow()->SetToolTip(_(L("Right button click the icon to change the object settings")));
|
2018-10-05 21:29:15 +00:00
|
|
|
else if (col->GetTitle() == _("Name") &&
|
2018-10-16 09:08:37 +00:00
|
|
|
m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.GetRefData()) {
|
2018-10-05 21:29:15 +00:00
|
|
|
int obj_idx = m_objects_model->GetIdByItem(item);
|
|
|
|
auto& stats = (*m_objects)[obj_idx]->volumes[0]->mesh.stl.stats;
|
|
|
|
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
|
|
|
|
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
|
|
|
|
|
|
|
|
wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors):\n")), errors);
|
|
|
|
|
|
|
|
std::map<std::string, int> error_msg;
|
|
|
|
error_msg[L("degenerate facets")] = stats.degenerate_facets;
|
|
|
|
error_msg[L("edges fixed")] = stats.edges_fixed;
|
|
|
|
error_msg[L("facets removed")] = stats.facets_removed;
|
|
|
|
error_msg[L("facets added")] = stats.facets_added;
|
|
|
|
error_msg[L("facets reversed")] = stats.facets_reversed;
|
|
|
|
error_msg[L("backwards edges")] = stats.backwards_edges;
|
|
|
|
|
|
|
|
for (auto error : error_msg)
|
|
|
|
{
|
|
|
|
if (error.second > 0)
|
|
|
|
tooltip += wxString::Format(_("\t%d %s\n"), error.second, error.first);
|
|
|
|
}
|
|
|
|
// OR
|
|
|
|
// tooltip += wxString::Format(_(L("%d degenerate facets, %d edges fixed, %d facets removed, "
|
|
|
|
// "%d facets added, %d facets reversed, %d backwards edges")),
|
|
|
|
// stats.degenerate_facets, stats.edges_fixed, stats.facets_removed,
|
|
|
|
// stats.facets_added, stats.facets_reversed, stats.backwards_edges);
|
|
|
|
|
|
|
|
if (is_windows10())
|
|
|
|
tooltip += _(L("Right button click the icon to fix STL through Netfabb"));
|
|
|
|
|
2018-10-08 14:27:38 +00:00
|
|
|
GetMainWindow()->SetToolTip(tooltip);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
else
|
2018-10-08 14:27:38 +00:00
|
|
|
GetMainWindow()->SetToolTip(""); // hide tooltip
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 14:41:27 +00:00
|
|
|
wxPoint ObjectList::get_mouse_position_in_control()
|
|
|
|
{
|
2018-10-04 14:43:10 +00:00
|
|
|
const wxPoint& pt = wxGetMousePosition();
|
2018-10-08 14:27:38 +00:00
|
|
|
// wxWindow* win = GetMainWindow();
|
|
|
|
// wxPoint screen_pos = win->GetScreenPosition();
|
|
|
|
return wxPoint(pt.x - /*win->*/GetScreenPosition().x, pt.y - /*win->*/GetScreenPosition().y);
|
2018-10-04 14:43:10 +00:00
|
|
|
}
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
int ObjectList::get_selected_obj_idx() const
|
|
|
|
{
|
2018-10-31 14:41:27 +00:00
|
|
|
if (GetSelectedItemsCount() == 1)
|
|
|
|
return m_objects_model->GetIdByItem(m_objects_model->GetTopParent(GetSelection()));
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
wxDataViewColumn* ObjectList::create_objects_list_extruder_column(int extruders_count)
|
|
|
|
{
|
|
|
|
wxArrayString choices;
|
|
|
|
choices.Add("default");
|
|
|
|
for (int i = 1; i <= extruders_count; ++i)
|
|
|
|
choices.Add(wxString::Format("%d", i));
|
|
|
|
wxDataViewChoiceRenderer *c =
|
|
|
|
new wxDataViewChoiceRenderer(choices, wxDATAVIEW_CELL_EDITABLE, wxALIGN_CENTER_HORIZONTAL);
|
2018-10-18 09:28:31 +00:00
|
|
|
wxDataViewColumn* column = new wxDataViewColumn(_(L("Extruder")), c, 1, 80, wxALIGN_CENTER_HORIZONTAL, wxDATAVIEW_COL_RESIZABLE);
|
2018-10-04 14:43:10 +00:00
|
|
|
return column;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::update_objects_list_extruder_column(int extruders_count)
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
if (!this) return; // #ys_FIXME
|
2018-10-04 14:43:10 +00:00
|
|
|
if (wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA)
|
|
|
|
extruders_count = 1;
|
|
|
|
|
2018-10-18 09:28:31 +00:00
|
|
|
// delete old 2nd column
|
|
|
|
DeleteColumn(GetColumn(1));
|
2018-10-04 14:43:10 +00:00
|
|
|
// insert new created 3rd column
|
2018-10-18 09:28:31 +00:00
|
|
|
InsertColumn(1, create_objects_list_extruder_column(extruders_count));
|
2018-10-04 14:43:10 +00:00
|
|
|
// set show/hide for this column
|
|
|
|
set_extruder_column_hidden(extruders_count <= 1);
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
void ObjectList::set_extruder_column_hidden(bool hide)
|
|
|
|
{
|
2018-10-18 09:28:31 +00:00
|
|
|
GetColumn(1)->SetHidden(hide);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::update_extruder_in_config(const wxString& selection)
|
|
|
|
{
|
|
|
|
if (!m_config || selection.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
int extruder = selection.size() > 1 ? 0 : atoi(selection.c_str());
|
|
|
|
m_config->set_key_value("extruder", new ConfigOptionInt(extruder));
|
|
|
|
|
2018-10-15 08:53:47 +00:00
|
|
|
// update scene
|
|
|
|
wxGetApp().plater()->update();
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
void ObjectList::init_icons()
|
|
|
|
{
|
2018-11-02 11:35:26 +00:00
|
|
|
m_bmp_modifiermesh = wxBitmap(from_u8(var("lambda.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("plugin.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
m_bmp_solidmesh = wxBitmap(from_u8(var("object.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("package.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
|
|
|
|
m_bmp_support_enforcer = wxBitmap(from_u8(var("support_enforcer_.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
m_bmp_support_blocker = wxBitmap(from_u8(var("support_blocker_.png")), wxBITMAP_TYPE_PNG);
|
|
|
|
|
|
|
|
m_bmp_vector.reserve(4); // bitmaps for different types of parts
|
|
|
|
m_bmp_vector.push_back(&m_bmp_solidmesh); // Add part
|
|
|
|
m_bmp_vector.push_back(&m_bmp_modifiermesh); // Add modifier
|
|
|
|
m_bmp_vector.push_back(&m_bmp_support_enforcer); // Add support enforcer
|
|
|
|
m_bmp_vector.push_back(&m_bmp_support_blocker); // Add support blocker
|
2018-11-02 22:27:31 +00:00
|
|
|
m_objects_model->SetVolumeBitmaps(m_bmp_vector);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// init icon for manifold warning
|
2018-11-02 11:35:26 +00:00
|
|
|
m_bmp_manifold_warning = wxBitmap(from_u8(var("exclamation_mark_.png")), wxBITMAP_TYPE_PNG);//(Slic3r::var("error.png")), wxBITMAP_TYPE_PNG);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// init bitmap for "Split to sub-objects" context menu
|
2018-11-02 11:35:26 +00:00
|
|
|
m_bmp_split = wxBitmap(from_u8(var("split.png")), wxBITMAP_TYPE_PNG);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// init bitmap for "Add Settings" context menu
|
2018-11-02 11:35:26 +00:00
|
|
|
m_bmp_cog = wxBitmap(from_u8(var("cog.png")), wxBITMAP_TYPE_PNG);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
void ObjectList::selection_changed()
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
if (m_prevent_list_events) return;
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
fix_multiselection_conflicts();
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
// update object selection on Plater
|
|
|
|
update_selections_on_canvas();
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-01 11:33:56 +00:00
|
|
|
// to update the toolbar and info sizer
|
|
|
|
if (!GetSelection() || m_objects_model->GetItemType(GetSelection()) == itObject) {
|
|
|
|
auto event = SimpleEvent(EVT_OBJ_LIST_OBJECT_SELECT);
|
|
|
|
event.SetEventObject(this);
|
|
|
|
wxPostEvent(this, event);
|
|
|
|
}
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
part_selection_changed();
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
update_extruder_in_config(m_selected_extruder);
|
|
|
|
#endif //__WXOSX__
|
|
|
|
}
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
void ObjectList::context_menu()
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
wxDataViewItem item;
|
|
|
|
wxDataViewColumn* col;
|
|
|
|
const wxPoint pt = get_mouse_position_in_control();
|
2018-10-08 14:27:38 +00:00
|
|
|
HitTest(pt, item, col);
|
2018-10-05 21:29:15 +00:00
|
|
|
if (!item)
|
|
|
|
#ifdef __WXOSX__ // #ys_FIXME temporary workaround for OSX
|
|
|
|
// after Yosemite OS X version, HitTest return undefined item
|
2018-10-08 14:27:38 +00:00
|
|
|
item = GetSelection();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (item)
|
|
|
|
show_context_menu();
|
|
|
|
else
|
|
|
|
printf("undefined item\n");
|
|
|
|
return;
|
|
|
|
#else
|
|
|
|
return;
|
|
|
|
#endif // __WXOSX__
|
|
|
|
const wxString title = col->GetTitle();
|
|
|
|
|
|
|
|
if (title == " ")
|
|
|
|
show_context_menu();
|
|
|
|
|
|
|
|
else if (title == _("Name") && pt.x >15 &&
|
2018-10-16 09:08:37 +00:00
|
|
|
m_objects_model->GetBitmap(item).GetRefData() == m_bmp_manifold_warning.GetRefData())
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-11-07 12:40:24 +00:00
|
|
|
if (is_windows10()) {
|
|
|
|
const auto obj_idx = m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item));
|
|
|
|
wxGetApp().plater()->fix_through_netfabb(obj_idx);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
#ifndef __WXMSW__
|
2018-10-08 14:27:38 +00:00
|
|
|
GetMainWindow()->SetToolTip(""); // hide tooltip
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif //__WXMSW__
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::show_context_menu()
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
const auto item = GetSelection();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (item)
|
|
|
|
{
|
2018-10-18 08:40:26 +00:00
|
|
|
if (!(m_objects_model->GetItemType(item) & (itObject | itVolume)))
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
|
|
|
const auto menu = m_objects_model->GetParent(item) == wxDataViewItem(0) ?
|
|
|
|
create_add_part_popupmenu() :
|
|
|
|
create_part_settings_popupmenu();
|
|
|
|
wxGetApp().tab_panel()->GetPage(0)->PopupMenu(menu);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
void ObjectList::key_event(wxKeyEvent& event)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
if (event.GetKeyCode() == WXK_TAB)
|
2018-10-08 14:27:38 +00:00
|
|
|
Navigate(event.ShiftDown() ? wxNavigationKeyEvent::IsBackward : wxNavigationKeyEvent::IsForward);
|
2018-10-05 21:29:15 +00:00
|
|
|
else if (event.GetKeyCode() == WXK_DELETE
|
|
|
|
#ifdef __WXOSX__
|
|
|
|
|| event.GetKeyCode() == WXK_BACK
|
|
|
|
#endif //__WXOSX__
|
2018-10-31 11:56:08 +00:00
|
|
|
) {
|
2018-10-05 21:29:15 +00:00
|
|
|
printf("WXK_BACK\n");
|
|
|
|
remove();
|
|
|
|
}
|
2018-10-12 10:00:37 +00:00
|
|
|
else if (wxGetKeyState(wxKeyCode('A')) && wxGetKeyState(WXK_CONTROL))
|
2018-11-08 14:45:55 +00:00
|
|
|
select_item_all_children();
|
2018-10-05 21:29:15 +00:00
|
|
|
else
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
void ObjectList::item_value_change(wxDataViewEvent& event)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-10-18 09:28:31 +00:00
|
|
|
if (event.GetColumn() == 1)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
wxVariant variant;
|
2018-10-18 09:28:31 +00:00
|
|
|
m_objects_model->GetValue(variant, event.GetItem(), 1);
|
2018-10-05 21:29:15 +00:00
|
|
|
#ifdef __WXOSX__
|
|
|
|
m_selected_extruder = variant.GetString();
|
|
|
|
#else // --> for Linux
|
|
|
|
update_extruder_in_config(variant.GetString());
|
|
|
|
#endif //__WXOSX__
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-16 09:08:37 +00:00
|
|
|
struct draging_item_data
|
|
|
|
{
|
|
|
|
int obj_idx;
|
|
|
|
int vol_idx;
|
|
|
|
};
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
void ObjectList::on_begin_drag(wxDataViewEvent &event)
|
|
|
|
{
|
|
|
|
wxDataViewItem item(event.GetItem());
|
|
|
|
|
|
|
|
// only allow drags for item, not containers
|
2018-10-10 14:22:20 +00:00
|
|
|
if (multiple_selection() ||
|
2018-10-16 09:08:37 +00:00
|
|
|
m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
|
|
|
m_objects_model->GetItemType(item) != itVolume ) {
|
2018-10-05 21:29:15 +00:00
|
|
|
event.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Under MSW or OSX, DnD moves an item to the place of another selected item
|
|
|
|
* But under GTK, DnD moves an item between another two items.
|
|
|
|
* And as a result - call EVT_CHANGE_SELECTION to unselect all items.
|
|
|
|
* To prevent such behavior use g_prevent_list_events
|
|
|
|
**/
|
|
|
|
m_prevent_list_events = true;//it's needed for GTK
|
|
|
|
|
|
|
|
wxTextDataObject *obj = new wxTextDataObject;
|
|
|
|
obj->SetText(wxString::Format("%d", m_objects_model->GetVolumeIdByItem(item)));
|
|
|
|
event.SetDataObject(obj);
|
|
|
|
event.SetDragFlags(/*wxDrag_AllowMove*/wxDrag_DefaultMove); // allows both copy and move;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::on_drop_possible(wxDataViewEvent &event)
|
|
|
|
{
|
|
|
|
wxDataViewItem item(event.GetItem());
|
|
|
|
|
|
|
|
// only allow drags for item or background, not containers
|
|
|
|
if (item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
2018-10-16 09:08:37 +00:00
|
|
|
event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume)
|
2018-10-05 21:29:15 +00:00
|
|
|
event.Veto();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::on_drop(wxDataViewEvent &event)
|
|
|
|
{
|
|
|
|
wxDataViewItem item(event.GetItem());
|
|
|
|
|
|
|
|
// only allow drops for item, not containers
|
2018-11-06 10:39:38 +00:00
|
|
|
if (m_selected_object_id < 0 ||
|
|
|
|
item.IsOk() && m_objects_model->GetParent(item) == wxDataViewItem(0) ||
|
2018-10-16 09:08:37 +00:00
|
|
|
event.GetDataFormat() != wxDF_UNICODETEXT || m_objects_model->GetItemType(item) != itVolume) {
|
2018-10-05 21:29:15 +00:00
|
|
|
event.Veto();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxTextDataObject obj;
|
|
|
|
obj.SetData(wxDF_UNICODETEXT, event.GetDataSize(), event.GetDataBuffer());
|
|
|
|
|
|
|
|
int from_volume_id = std::stoi(obj.GetText().ToStdString());
|
|
|
|
int to_volume_id = m_objects_model->GetVolumeIdByItem(item);
|
|
|
|
|
|
|
|
#ifdef __WXGTK__
|
|
|
|
/* Under GTK, DnD moves an item between another two items.
|
|
|
|
* And event.GetItem() return item, which is under "insertion line"
|
|
|
|
* So, if we move item down we should to decrease the to_volume_id value
|
|
|
|
**/
|
|
|
|
if (to_volume_id > from_volume_id) to_volume_id--;
|
|
|
|
#endif // __WXGTK__
|
|
|
|
|
|
|
|
auto& volumes = (*m_objects)[m_selected_object_id]->volumes;
|
|
|
|
auto delta = to_volume_id < from_volume_id ? -1 : 1;
|
|
|
|
int cnt = 0;
|
|
|
|
for (int id = from_volume_id; cnt < abs(from_volume_id - to_volume_id); id += delta, cnt++)
|
|
|
|
std::swap(volumes[id], volumes[id + delta]);
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
select_item(m_objects_model->ReorganizeChildren(from_volume_id, to_volume_id,
|
|
|
|
m_objects_model->GetParent(item)));
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
m_parts_changed = true;
|
|
|
|
parts_changed(m_selected_object_id);
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
// m_prevent_list_events = false;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Context Menu
|
|
|
|
|
|
|
|
std::vector<std::string> get_options(const bool is_part)
|
|
|
|
{
|
|
|
|
PrintRegionConfig reg_config;
|
|
|
|
auto options = reg_config.keys();
|
|
|
|
if (!is_part) {
|
|
|
|
PrintObjectConfig obj_config;
|
|
|
|
std::vector<std::string> obj_options = obj_config.keys();
|
|
|
|
options.insert(options.end(), obj_options.begin(), obj_options.end());
|
|
|
|
}
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
|
|
|
// category -> vector ( option ; label )
|
|
|
|
typedef std::map< std::string, std::vector< std::pair<std::string, std::string> > > settings_menu_hierarchy;
|
|
|
|
void get_options_menu(settings_menu_hierarchy& settings_menu, bool is_part)
|
|
|
|
{
|
|
|
|
auto options = get_options(is_part);
|
|
|
|
|
|
|
|
auto extruders_cnt = wxGetApp().preset_bundle->printers.get_selected_preset().printer_technology() == ptSLA ? 1 :
|
|
|
|
wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionFloats>("nozzle_diameter")->values.size();
|
|
|
|
|
|
|
|
DynamicPrintConfig config;
|
|
|
|
for (auto& option : options)
|
|
|
|
{
|
|
|
|
auto const opt = config.def()->get(option);
|
|
|
|
auto category = opt->category;
|
|
|
|
if (category.empty() ||
|
|
|
|
(category == "Extruders" && extruders_cnt == 1)) continue;
|
|
|
|
|
|
|
|
std::pair<std::string, std::string> option_label(option, opt->label);
|
|
|
|
std::vector< std::pair<std::string, std::string> > new_category;
|
|
|
|
auto& cat_opt_label = settings_menu.find(category) == settings_menu.end() ? new_category : settings_menu.at(category);
|
|
|
|
cat_opt_label.push_back(option_label);
|
|
|
|
if (cat_opt_label.size() == 1)
|
|
|
|
settings_menu[category] = cat_opt_label;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::get_settings_choice(wxMenu *menu, int id, bool is_part)
|
|
|
|
{
|
|
|
|
const auto category_name = menu->GetLabel(id);
|
|
|
|
|
|
|
|
wxArrayString names;
|
|
|
|
wxArrayInt selections;
|
|
|
|
|
|
|
|
settings_menu_hierarchy settings_menu;
|
|
|
|
get_options_menu(settings_menu, is_part);
|
|
|
|
std::vector< std::pair<std::string, std::string> > *settings_list = nullptr;
|
|
|
|
|
|
|
|
auto opt_keys = m_config->keys();
|
|
|
|
|
|
|
|
for (auto& cat : settings_menu)
|
|
|
|
{
|
|
|
|
if (_(cat.first) == category_name) {
|
|
|
|
int sel = 0;
|
|
|
|
for (auto& pair : cat.second) {
|
|
|
|
names.Add(_(pair.second));
|
|
|
|
if (find(opt_keys.begin(), opt_keys.end(), pair.first) != opt_keys.end())
|
|
|
|
selections.Add(sel);
|
|
|
|
sel++;
|
|
|
|
}
|
|
|
|
settings_list = &cat.second;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!settings_list)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (wxGetSelectedChoices(selections, _(L("Select showing settings")), category_name, names) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::vector <std::string> selected_options;
|
|
|
|
for (auto sel : selections)
|
|
|
|
selected_options.push_back((*settings_list)[sel].first);
|
|
|
|
|
|
|
|
for (auto& setting : (*settings_list))
|
|
|
|
{
|
|
|
|
auto& opt_key = setting.first;
|
|
|
|
if (find(opt_keys.begin(), opt_keys.end(), opt_key) != opt_keys.end() &&
|
|
|
|
find(selected_options.begin(), selected_options.end(), opt_key) == selected_options.end())
|
|
|
|
m_config->erase(opt_key);
|
|
|
|
|
|
|
|
if (find(opt_keys.begin(), opt_keys.end(), opt_key) == opt_keys.end() &&
|
|
|
|
find(selected_options.begin(), selected_options.end(), opt_key) != selected_options.end())
|
|
|
|
m_config->set_key_value(opt_key, m_default_config->option(opt_key)->clone());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Add settings item for object
|
2018-10-08 14:27:38 +00:00
|
|
|
const auto item = GetSelection();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (item) {
|
2018-10-16 09:08:37 +00:00
|
|
|
const auto settings_item = m_objects_model->GetSettingsItem(item);
|
2018-10-11 13:57:09 +00:00
|
|
|
select_item(settings_item ? settings_item :
|
2018-10-05 21:29:15 +00:00
|
|
|
m_objects_model->AddSettingsChild(item));
|
|
|
|
#ifndef __WXOSX__
|
2018-10-11 13:57:09 +00:00
|
|
|
// part_selection_changed();
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif //no __WXOSX__
|
|
|
|
}
|
2018-11-09 17:39:07 +00:00
|
|
|
else {
|
|
|
|
auto panel = wxGetApp().sidebar().scrolled_panel();
|
|
|
|
panel->Freeze();
|
|
|
|
wxGetApp().obj_settings()->UpdateAndShow(true);//obj_manipul()->update_settings_list();
|
|
|
|
panel->Thaw();
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
void ObjectList::menu_item_add_generic(wxMenuItem* &menu, int id, const int type) {
|
2018-10-05 21:29:15 +00:00
|
|
|
auto sub_menu = new wxMenu;
|
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
const wxString menu_load = _(L("Load")) +" "+ dots;
|
|
|
|
sub_menu->Append(new wxMenuItem(sub_menu, id++, menu_load));
|
|
|
|
sub_menu->AppendSeparator();
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
std::vector<std::string> menu_items = { L("Box"), L("Cylinder"), L("Sphere"), L("Slab") };
|
|
|
|
for (auto& item : menu_items)
|
2018-11-06 14:34:44 +00:00
|
|
|
sub_menu->Append(new wxMenuItem(sub_menu, id++, _(item)));
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
#ifndef __WXMSW__
|
2018-11-06 14:34:44 +00:00
|
|
|
sub_menu->Bind(wxEVT_MENU, [sub_menu, type, menu_load, this](wxEvent &event) {
|
|
|
|
auto selection = sub_menu->GetLabel(event.GetId());
|
|
|
|
if (selection == menu_load)
|
|
|
|
load_subobject(type);
|
|
|
|
else
|
|
|
|
load_generic_subobject(selection.ToStdString(), type);
|
2018-10-05 21:29:15 +00:00
|
|
|
});
|
|
|
|
#endif //no __WXMSW__
|
|
|
|
|
|
|
|
menu->SetSubMenu(sub_menu);
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenuItem* ObjectList::menu_item_split(wxMenu* menu, int id) {
|
|
|
|
auto menu_item = new wxMenuItem(menu, id, _(L("Split to parts")));
|
|
|
|
menu_item->SetBitmap(m_bmp_split);
|
|
|
|
return menu_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenuItem* ObjectList::menu_item_settings(wxMenu* menu, int id, const bool is_part) {
|
|
|
|
auto menu_item = new wxMenuItem(menu, id, _(L("Add settings")));
|
|
|
|
menu_item->SetBitmap(m_bmp_cog);
|
|
|
|
|
|
|
|
auto sub_menu = create_add_settings_popupmenu(is_part);
|
|
|
|
menu_item->SetSubMenu(sub_menu);
|
|
|
|
return menu_item;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenu* ObjectList::create_add_part_popupmenu()
|
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
2018-11-06 14:34:44 +00:00
|
|
|
// Note: id accords to type of the sub-object, so sequence of the menu items is important
|
|
|
|
std::vector<std::string> menu_object_types_items = {L("Add part"), // ~ModelVolume::MODEL_PART
|
|
|
|
L("Add modifier"), // ~ModelVolume::PARAMETER_MODIFIER
|
|
|
|
L("Add support enforcer"), // ~ModelVolume::SUPPORT_ENFORCER
|
|
|
|
L("Add support bloker") }; // ~ModelVolume::SUPPORT_BLOCKER
|
|
|
|
|
2018-11-02 11:35:26 +00:00
|
|
|
const int obj_types_count = menu_object_types_items.size();
|
2018-11-06 14:34:44 +00:00
|
|
|
const int generics_count = 5; // "Load ...", "Box", "Cylinder", "Sphere", "Slab"
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
wxWindowID config_id_base = NewControlId(generics_count*obj_types_count + 2);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-02 11:35:26 +00:00
|
|
|
// Add first 4 menu items
|
2018-11-06 14:34:44 +00:00
|
|
|
for (int type = 0; type < obj_types_count; type++) {
|
|
|
|
auto& item = menu_object_types_items[type];
|
|
|
|
auto menu_item = new wxMenuItem(menu, config_id_base + type, _(item));
|
|
|
|
menu_item->SetBitmap(*m_bmp_vector[type]);
|
|
|
|
menu_item_add_generic(menu_item, config_id_base + type*generics_count, type);
|
2018-10-05 21:29:15 +00:00
|
|
|
menu->Append(menu_item);
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:35:26 +00:00
|
|
|
// Split object to parts
|
2018-10-05 21:29:15 +00:00
|
|
|
menu->AppendSeparator();
|
2018-11-06 14:34:44 +00:00
|
|
|
auto menu_item = menu_item_split(menu, config_id_base + obj_types_count * generics_count);
|
2018-10-05 21:29:15 +00:00
|
|
|
menu->Append(menu_item);
|
|
|
|
menu_item->Enable(is_splittable_object(false));
|
|
|
|
|
2018-11-02 11:35:26 +00:00
|
|
|
// Settings
|
2018-10-05 21:29:15 +00:00
|
|
|
menu->AppendSeparator();
|
|
|
|
// Append settings popupmenu
|
2018-11-06 14:34:44 +00:00
|
|
|
menu->Append(menu_item_settings(menu, config_id_base + obj_types_count * generics_count+1, false));
|
|
|
|
|
|
|
|
menu->Bind(wxEVT_MENU, [config_id_base, menu, obj_types_count, generics_count, this](wxEvent &event) {
|
|
|
|
auto selection = event.GetId() - config_id_base;
|
|
|
|
|
|
|
|
if ( selection == 0 * generics_count || // ~ModelVolume::MODEL_PART
|
|
|
|
selection == 1 * generics_count || // ~ModelVolume::PARAMETER_MODIFIER
|
|
|
|
selection == 2 * generics_count || // ~ModelVolume::SUPPORT_ENFORCER
|
|
|
|
selection == 3 * generics_count ) // ~ModelVolume::SUPPORT_BLOCKER
|
|
|
|
load_subobject(int(selection / generics_count));
|
|
|
|
else if ( selection == obj_types_count * generics_count)
|
2018-10-05 21:29:15 +00:00
|
|
|
split(false);
|
|
|
|
#ifdef __WXMSW__
|
2018-11-06 14:34:44 +00:00
|
|
|
else if ( selection > obj_types_count * generics_count) // "Add Settings" is selected
|
2018-10-05 21:29:15 +00:00
|
|
|
get_settings_choice(menu, event.GetId(), false);
|
2018-11-06 14:34:44 +00:00
|
|
|
else // Some generic model is selected
|
|
|
|
load_generic_subobject(menu->GetLabel(event.GetId()).ToStdString(), int(selection / generics_count));
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif // __WXMSW__
|
|
|
|
});
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenu* ObjectList::create_part_settings_popupmenu()
|
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
2018-11-02 22:27:31 +00:00
|
|
|
wxWindowID config_id_base = NewControlId(3);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
auto menu_item = menu_item_split(menu, config_id_base);
|
|
|
|
menu->Append(menu_item);
|
|
|
|
menu_item->Enable(is_splittable_object(true));
|
|
|
|
|
2018-11-02 22:27:31 +00:00
|
|
|
// Append change part type
|
2018-10-05 21:29:15 +00:00
|
|
|
menu->AppendSeparator();
|
2018-11-02 22:27:31 +00:00
|
|
|
menu->Append(new wxMenuItem(menu, config_id_base + 1, _(L("Change type"))));
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
// Append settings popupmenu
|
2018-11-02 22:27:31 +00:00
|
|
|
menu->AppendSeparator();
|
|
|
|
menu_item = menu_item_settings(menu, config_id_base + 2, true);
|
|
|
|
menu->Append(menu_item);
|
|
|
|
menu_item->Enable(get_selected_model_volume()->type() <= ModelVolume::PARAMETER_MODIFIER);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-10-31 11:56:08 +00:00
|
|
|
menu->Bind(wxEVT_MENU, [config_id_base, menu, this](wxEvent &event) {
|
2018-10-05 21:29:15 +00:00
|
|
|
switch (event.GetId() - config_id_base) {
|
|
|
|
case 0:
|
|
|
|
split(true);
|
|
|
|
break;
|
2018-11-02 22:27:31 +00:00
|
|
|
case 1:
|
|
|
|
change_part_type();
|
|
|
|
break;
|
|
|
|
default:
|
2018-10-05 21:29:15 +00:00
|
|
|
get_settings_choice(menu, event.GetId(), true);
|
2018-11-02 22:27:31 +00:00
|
|
|
break;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
});
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxMenu* ObjectList::create_add_settings_popupmenu(bool is_part)
|
|
|
|
{
|
|
|
|
wxMenu *menu = new wxMenu;
|
|
|
|
|
|
|
|
settings_menu_hierarchy settings_menu;
|
|
|
|
get_options_menu(settings_menu, is_part);
|
|
|
|
|
|
|
|
for (auto cat : settings_menu)
|
|
|
|
{
|
|
|
|
auto menu_item = new wxMenuItem(menu, wxID_ANY, _(cat.first));
|
|
|
|
menu_item->SetBitmap(CATEGORY_ICON.find(cat.first) == CATEGORY_ICON.end() ?
|
|
|
|
wxNullBitmap : CATEGORY_ICON.at(cat.first));
|
|
|
|
menu->Append(menu_item);
|
|
|
|
}
|
|
|
|
#ifndef __WXMSW__
|
2018-10-04 09:12:55 +00:00
|
|
|
menu->Bind(wxEVT_MENU, [this, menu, is_part](wxEvent &event) {
|
2018-10-05 21:29:15 +00:00
|
|
|
get_settings_choice(menu, event.GetId(), is_part);
|
|
|
|
});
|
|
|
|
#endif //no __WXMSW__
|
|
|
|
return menu;
|
|
|
|
}
|
|
|
|
|
2018-11-02 11:35:26 +00:00
|
|
|
void ObjectList::load_subobject(int type)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
auto item = GetSelection();
|
2018-11-02 11:35:26 +00:00
|
|
|
if (!item || m_objects_model->GetParent(item) != wxDataViewItem(0))
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
2018-11-02 11:35:26 +00:00
|
|
|
int obj_idx = m_objects_model->GetIdByItem(item);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
if (obj_idx < 0) return;
|
|
|
|
wxArrayString part_names;
|
2018-11-02 11:35:26 +00:00
|
|
|
load_part((*m_objects)[obj_idx], part_names, type);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
parts_changed(obj_idx);
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
for (int i = 0; i < part_names.size(); ++i) {
|
2018-11-12 15:03:29 +00:00
|
|
|
const wxDataViewItem sel_item = m_objects_model->AddVolumeChild(item, part_names.Item(i), type);
|
2018-10-11 13:57:09 +00:00
|
|
|
|
|
|
|
if (i == part_names.size() - 1)
|
|
|
|
select_item(sel_item);
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME
|
2018-10-11 13:57:09 +00:00
|
|
|
// selection_changed();
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif //no __WXOSX__//__WXMSW__
|
2018-11-02 11:35:26 +00:00
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::load_part( ModelObject* model_object,
|
|
|
|
wxArrayString& part_names,
|
2018-11-02 11:35:26 +00:00
|
|
|
int type)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
wxWindow* parent = wxGetApp().tab_panel()->GetPage(0);
|
|
|
|
|
2018-10-31 14:41:27 +00:00
|
|
|
m_parts_changed = false;
|
2018-10-05 21:29:15 +00:00
|
|
|
wxArrayString input_files;
|
2018-11-15 14:27:39 +00:00
|
|
|
#if ENABLE_NEW_MENU_LAYOUT
|
|
|
|
wxGetApp().import_model(parent, input_files);
|
|
|
|
#else
|
2018-10-05 21:29:15 +00:00
|
|
|
wxGetApp().open_model(parent, input_files);
|
2018-11-15 14:27:39 +00:00
|
|
|
#endif // ENABLE_NEW_MENU_LAYOUT
|
2018-10-05 21:29:15 +00:00
|
|
|
for (int i = 0; i < input_files.size(); ++i) {
|
|
|
|
std::string input_file = input_files.Item(i).ToStdString();
|
|
|
|
|
|
|
|
Model model;
|
|
|
|
try {
|
|
|
|
model = Model::read_from_file(input_file);
|
|
|
|
}
|
|
|
|
catch (std::exception &e) {
|
|
|
|
auto msg = _(L("Error! ")) + input_file + " : " + e.what() + ".";
|
|
|
|
show_error(parent, msg);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto object : model.objects) {
|
|
|
|
Vec3d delta = Vec3d::Zero();
|
|
|
|
if (model_object->origin_translation != Vec3d::Zero())
|
|
|
|
{
|
|
|
|
object->center_around_origin();
|
2018-11-06 14:51:33 +00:00
|
|
|
#if !ENABLE_MODELVOLUME_TRANSFORM
|
2018-10-30 15:03:03 +00:00
|
|
|
object->ensure_on_bed();
|
2018-11-06 14:51:33 +00:00
|
|
|
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
2018-10-05 21:29:15 +00:00
|
|
|
delta = model_object->origin_translation - object->origin_translation;
|
|
|
|
}
|
|
|
|
for (auto volume : object->volumes) {
|
2018-11-06 14:51:33 +00:00
|
|
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
2018-11-12 07:54:22 +00:00
|
|
|
volume->center_geometry();
|
|
|
|
volume->translate(delta);
|
2018-11-06 14:51:33 +00:00
|
|
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
2018-10-05 21:29:15 +00:00
|
|
|
auto new_volume = model_object->add_volume(*volume);
|
2018-11-02 11:35:26 +00:00
|
|
|
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
2018-10-05 21:29:15 +00:00
|
|
|
new_volume->name = boost::filesystem::path(input_file).filename().string();
|
|
|
|
|
|
|
|
part_names.Add(new_volume->name);
|
|
|
|
|
2018-11-06 14:51:33 +00:00
|
|
|
#if !ENABLE_MODELVOLUME_TRANSFORM
|
2018-10-05 21:29:15 +00:00
|
|
|
if (delta != Vec3d::Zero())
|
2018-11-01 13:25:10 +00:00
|
|
|
new_volume->translate(delta);
|
2018-11-06 14:51:33 +00:00
|
|
|
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// set a default extruder value, since user can't add it manually
|
|
|
|
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
|
|
|
|
|
|
|
m_parts_changed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
void ObjectList::load_generic_subobject(const std::string& type_name, const int type)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-11-06 16:26:33 +00:00
|
|
|
const auto obj_idx = get_selected_obj_idx();
|
|
|
|
if (obj_idx < 0) return;
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
const std::string name = "lambda-" + type_name;
|
|
|
|
TriangleMesh mesh;
|
|
|
|
|
2018-11-06 16:26:33 +00:00
|
|
|
auto& bed_shape = wxGetApp().preset_bundle->printers.get_edited_preset().config.option<ConfigOptionPoints>("bed_shape")->values;
|
|
|
|
const auto& sz = BoundingBoxf(bed_shape).size();
|
|
|
|
const auto side = 0.1 * std::max(sz(0), sz(1));
|
|
|
|
|
2018-11-12 15:03:29 +00:00
|
|
|
if (type_name == _("Box")) {
|
2018-11-06 16:26:33 +00:00
|
|
|
mesh = make_cube(side, side, side);
|
2018-11-12 15:03:29 +00:00
|
|
|
// box sets the base coordinate at 0, 0, move to center of plate
|
|
|
|
mesh.translate(-side * 0.5, -side * 0.5, 0);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
else if (type_name == _("Cylinder"))
|
2018-11-06 16:26:33 +00:00
|
|
|
mesh = make_cylinder(0.5*side, side);
|
2018-10-05 21:29:15 +00:00
|
|
|
else if (type_name == _("Sphere"))
|
2018-11-06 16:26:33 +00:00
|
|
|
mesh = make_sphere(side, PI/18);
|
2018-10-31 11:56:08 +00:00
|
|
|
else if (type_name == _("Slab")) {
|
2018-11-06 16:26:33 +00:00
|
|
|
const auto& size = (*m_objects)[obj_idx]->bounding_box().size();
|
|
|
|
mesh = make_cube(size(0)*1.5, size(1)*1.5, size(2)*0.5);
|
2018-10-05 21:29:15 +00:00
|
|
|
// box sets the base coordinate at 0, 0, move to center of plate and move it up to initial_z
|
2018-11-06 16:26:33 +00:00
|
|
|
mesh.translate(-size(0)*1.5 / 2.0, -size(1)*1.5 / 2.0, 0);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
mesh.repair();
|
2018-11-12 07:54:22 +00:00
|
|
|
|
2018-11-06 16:26:33 +00:00
|
|
|
auto new_volume = (*m_objects)[obj_idx]->add_volume(mesh);
|
2018-11-06 14:34:44 +00:00
|
|
|
new_volume->set_type(static_cast<ModelVolume::Type>(type));
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-12 07:54:22 +00:00
|
|
|
#if ENABLE_MODELVOLUME_TRANSFORM
|
|
|
|
new_volume->center_geometry();
|
|
|
|
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
new_volume->name = name;
|
|
|
|
// set a default extruder value, since user can't add it manually
|
|
|
|
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
|
|
|
|
|
|
|
m_parts_changed = true;
|
2018-11-06 16:26:33 +00:00
|
|
|
parts_changed(obj_idx);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
select_item(m_objects_model->AddVolumeChild(GetSelection(), name, type));
|
2018-10-05 21:29:15 +00:00
|
|
|
#ifndef __WXOSX__ //#ifdef __WXMSW__ // #ys_FIXME
|
2018-10-11 13:57:09 +00:00
|
|
|
selection_changed();
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif //no __WXOSX__ //__WXMSW__
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:17:35 +00:00
|
|
|
void ObjectList::del_object(const int obj_idx)
|
|
|
|
{
|
|
|
|
wxGetApp().plater()->delete_object_from_model(obj_idx);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// Delete subobject
|
2018-10-12 10:00:37 +00:00
|
|
|
void ObjectList::del_subobject_item(wxDataViewItem& item)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
|
|
|
if (!item) return;
|
|
|
|
|
2018-10-16 09:08:37 +00:00
|
|
|
int obj_idx, idx;
|
|
|
|
ItemType type;
|
2018-10-12 10:00:37 +00:00
|
|
|
|
2018-10-16 09:08:37 +00:00
|
|
|
m_objects_model->GetItemInfo(item, type, obj_idx, idx);
|
|
|
|
if (type == itUndef)
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
|
|
|
|
2018-10-16 09:08:37 +00:00
|
|
|
if (type == itSettings)
|
2018-10-05 21:29:15 +00:00
|
|
|
del_settings_from_config();
|
2018-10-16 09:08:37 +00:00
|
|
|
else if (type == itInstanceRoot && obj_idx != -1)
|
|
|
|
del_instances_from_object(obj_idx);
|
|
|
|
else if (idx == -1)
|
|
|
|
return;
|
|
|
|
else if (!del_subobject_from_object(obj_idx, idx, type))
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
m_objects_model->Delete(item);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::del_settings_from_config()
|
|
|
|
{
|
|
|
|
auto opt_keys = m_config->keys();
|
|
|
|
if (opt_keys.size() == 1 && opt_keys[0] == "extruder")
|
|
|
|
return;
|
|
|
|
int extruder = -1;
|
|
|
|
if (m_config->has("extruder"))
|
|
|
|
extruder = m_config->option<ConfigOptionInt>("extruder")->value;
|
|
|
|
|
|
|
|
m_config->clear();
|
|
|
|
|
|
|
|
if (extruder >= 0)
|
|
|
|
m_config->set_key_value("extruder", new ConfigOptionInt(extruder));
|
|
|
|
}
|
|
|
|
|
2018-10-16 09:08:37 +00:00
|
|
|
void ObjectList::del_instances_from_object(const int obj_idx)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-10-19 09:02:50 +00:00
|
|
|
auto& instances = (*m_objects)[obj_idx]->instances;
|
2018-10-16 09:08:37 +00:00
|
|
|
if (instances.size() <= 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while ( instances.size()> 1)
|
|
|
|
instances.pop_back();
|
|
|
|
|
|
|
|
(*m_objects)[obj_idx]->invalidate_bounding_box(); // ? #ys_FIXME
|
|
|
|
|
|
|
|
m_parts_changed = true;
|
|
|
|
parts_changed(obj_idx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectList::del_subobject_from_object(const int obj_idx, const int idx, const int type)
|
|
|
|
{
|
|
|
|
if (type == itVolume) {
|
|
|
|
const auto volume = (*m_objects)[obj_idx]->volumes[idx];
|
|
|
|
|
|
|
|
// if user is deleting the last solid part, throw error
|
|
|
|
int solid_cnt = 0;
|
|
|
|
for (auto vol : (*m_objects)[obj_idx]->volumes)
|
|
|
|
if (vol->is_model_part())
|
|
|
|
++solid_cnt;
|
|
|
|
if (volume->is_model_part() && solid_cnt == 1) {
|
2018-10-18 08:40:26 +00:00
|
|
|
Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last solid part from object.")));
|
2018-10-16 09:08:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
(*m_objects)[obj_idx]->delete_volume(idx);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-10-18 08:40:26 +00:00
|
|
|
else if (type == itInstance) {
|
|
|
|
if ((*m_objects)[obj_idx]->instances.size() == 1) {
|
|
|
|
Slic3r::GUI::show_error(nullptr, _(L("You can't delete the last intance from object.")));
|
|
|
|
return false;
|
|
|
|
}
|
2018-10-16 09:08:37 +00:00
|
|
|
(*m_objects)[obj_idx]->delete_instance(idx);
|
2018-10-18 08:40:26 +00:00
|
|
|
}
|
2018-10-16 09:08:37 +00:00
|
|
|
else
|
|
|
|
return false;
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
m_parts_changed = true;
|
2018-10-12 10:00:37 +00:00
|
|
|
parts_changed(obj_idx);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::split(const bool split_part)
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
const auto item = GetSelection();
|
2018-11-06 08:06:26 +00:00
|
|
|
const int obj_idx = get_selected_obj_idx();
|
|
|
|
if (!item || obj_idx < 0)
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
2018-11-06 08:06:26 +00:00
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
ModelVolume* volume;
|
|
|
|
if (!get_volume_by_item(split_part, item, volume)) return;
|
|
|
|
DynamicPrintConfig& config = wxGetApp().preset_bundle->printers.get_edited_preset().config;
|
2018-11-08 19:44:07 +00:00
|
|
|
const ConfigOption *nozzle_dmtrs_opt = config.option("nozzle_diameter", false);
|
|
|
|
const auto nozzle_dmrs_cnt = (nozzle_dmtrs_opt == nullptr) ? size_t(1) : dynamic_cast<const ConfigOptionFloats*>(nozzle_dmtrs_opt)->values.size();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (volume->split(nozzle_dmrs_cnt) == 1) {
|
|
|
|
wxMessageBox(_(L("The selected object couldn't be split because it contains only one part.")));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-11-06 08:06:26 +00:00
|
|
|
auto model_object = (*m_objects)[obj_idx];
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-11-06 08:06:26 +00:00
|
|
|
auto parent = m_objects_model->GetTopParent(item);
|
|
|
|
if (parent)
|
|
|
|
m_objects_model->DeleteVolumeChildren(parent);
|
|
|
|
else
|
|
|
|
parent = item;
|
|
|
|
|
|
|
|
for (auto id = 0; id < model_object->volumes.size(); id++) {
|
|
|
|
const auto vol_item = m_objects_model->AddVolumeChild(parent, model_object->volumes[id]->name,
|
|
|
|
model_object->volumes[id]->is_modifier() ?
|
|
|
|
ModelVolume::PARAMETER_MODIFIER : ModelVolume::MODEL_PART,
|
|
|
|
model_object->volumes[id]->config.has("extruder") ?
|
|
|
|
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value : 0,
|
|
|
|
false);
|
|
|
|
// add settings to the part, if it has those
|
|
|
|
auto opt_keys = model_object->volumes[id]->config.keys();
|
|
|
|
if ( !(opt_keys.size() == 1 && opt_keys[0] == "extruder") ) {
|
|
|
|
select_item(m_objects_model->AddSettingsChild(vol_item));
|
|
|
|
Collapse(vol_item);
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 14:34:44 +00:00
|
|
|
if (parent == item)
|
|
|
|
Expand(parent);
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
m_parts_changed = true;
|
2018-11-06 08:06:26 +00:00
|
|
|
parts_changed(obj_idx);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectList::get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume)
|
|
|
|
{
|
2018-11-06 08:06:26 +00:00
|
|
|
auto obj_idx = get_selected_obj_idx();
|
|
|
|
if (!item || obj_idx < 0)
|
2018-10-05 21:29:15 +00:00
|
|
|
return false;
|
|
|
|
const auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
2018-11-06 08:06:26 +00:00
|
|
|
|
|
|
|
// object is selected
|
2018-10-05 21:29:15 +00:00
|
|
|
if (volume_id < 0) {
|
2018-11-06 08:06:26 +00:00
|
|
|
if ( split_part || (*m_objects)[obj_idx]->volumes.size() > 1 )
|
|
|
|
return false;
|
|
|
|
volume = (*m_objects)[obj_idx]->volumes[0];
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-11-06 08:06:26 +00:00
|
|
|
// volume is selected
|
2018-10-05 21:29:15 +00:00
|
|
|
else
|
2018-11-06 08:06:26 +00:00
|
|
|
volume = (*m_objects)[obj_idx]->volumes[volume_id];
|
|
|
|
|
|
|
|
return true;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ObjectList::is_splittable_object(const bool split_part)
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
const wxDataViewItem item = GetSelection();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (!item) return false;
|
|
|
|
|
|
|
|
ModelVolume* volume;
|
|
|
|
if (!get_volume_by_item(split_part, item, volume) || !volume)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
TriangleMeshPtrs meshptrs = volume->mesh.split();
|
|
|
|
bool splittable = meshptrs.size() > 1;
|
2018-11-06 08:06:26 +00:00
|
|
|
for (TriangleMesh* m : meshptrs) { delete m; }
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
return splittable;
|
|
|
|
}
|
|
|
|
|
2018-10-31 14:41:27 +00:00
|
|
|
void ObjectList::part_settings_changed()
|
|
|
|
{
|
|
|
|
m_part_settings_changed = true;
|
|
|
|
wxGetApp().plater()->changed_object(get_selected_obj_idx());
|
|
|
|
m_part_settings_changed = false;
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
void ObjectList::parts_changed(int obj_idx)
|
|
|
|
{
|
2018-11-02 22:27:31 +00:00
|
|
|
wxGetApp().plater()->changed_object(obj_idx);
|
2018-10-31 14:41:27 +00:00
|
|
|
m_parts_changed = false;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::part_selection_changed()
|
|
|
|
{
|
|
|
|
int obj_idx = -1;
|
|
|
|
m_config = nullptr;
|
2018-11-09 17:39:07 +00:00
|
|
|
wxString og_name = wxEmptyString;
|
|
|
|
|
|
|
|
bool update_and_show_manipulations = false;
|
|
|
|
bool update_and_show_settings = false;
|
2018-11-08 14:45:55 +00:00
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
if (multiple_selection()) {
|
|
|
|
og_name = _(L("Group manipulation"));
|
|
|
|
update_and_show_manipulations = true;
|
|
|
|
}
|
2018-11-08 14:45:55 +00:00
|
|
|
else
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-11-08 14:45:55 +00:00
|
|
|
const auto item = GetSelection();
|
|
|
|
if (item)
|
|
|
|
{
|
|
|
|
bool is_part = false;
|
|
|
|
if (m_objects_model->GetParent(item) == wxDataViewItem(0)) {
|
|
|
|
obj_idx = m_objects_model->GetIdByItem(item);
|
|
|
|
og_name = _(L("Object manipulation"));
|
|
|
|
m_config = &(*m_objects)[obj_idx]->config;
|
2018-11-09 17:39:07 +00:00
|
|
|
update_and_show_manipulations = true;
|
2018-11-08 14:45:55 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
auto parent = m_objects_model->GetParent(item);
|
|
|
|
// 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);
|
2018-11-09 17:39:07 +00:00
|
|
|
if (m_objects_model->GetItemType(item) == itSettings) {
|
2018-11-08 14:45:55 +00:00
|
|
|
if (m_objects_model->GetParent(parent) == wxDataViewItem(0)) {
|
|
|
|
og_name = _(L("Object Settings to modify"));
|
|
|
|
m_config = &(*m_objects)[obj_idx]->config;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
og_name = _(L("Part Settings to modify"));
|
|
|
|
is_part = true;
|
|
|
|
auto main_parent = m_objects_model->GetParent(parent);
|
|
|
|
obj_idx = m_objects_model->GetIdByItem(main_parent);
|
|
|
|
const auto volume_id = m_objects_model->GetVolumeIdByItem(parent);
|
|
|
|
m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config;
|
|
|
|
}
|
2018-11-09 17:39:07 +00:00
|
|
|
update_and_show_settings = true;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-11-08 14:45:55 +00:00
|
|
|
else if (m_objects_model->GetItemType(item) == itVolume) {
|
|
|
|
og_name = _(L("Part manipulation"));
|
2018-10-05 21:29:15 +00:00
|
|
|
is_part = true;
|
2018-11-08 14:45:55 +00:00
|
|
|
const auto volume_id = m_objects_model->GetVolumeIdByItem(item);
|
2018-10-05 21:29:15 +00:00
|
|
|
m_config = &(*m_objects)[obj_idx]->volumes[volume_id]->config;
|
2018-11-09 17:39:07 +00:00
|
|
|
update_and_show_manipulations = true;
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
2018-11-08 14:45:55 +00:00
|
|
|
else if (m_objects_model->GetItemType(item) == itInstance) {
|
|
|
|
og_name = _(L("Instance manipulation"));
|
2018-11-09 17:39:07 +00:00
|
|
|
update_and_show_manipulations = true;
|
2018-11-08 14:45:55 +00:00
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-08 14:45:55 +00:00
|
|
|
if (m_default_config) delete m_default_config;
|
|
|
|
m_default_config = DynamicPrintConfig::new_from_defaults_keys(get_options(is_part));
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
m_selected_object_id = obj_idx;
|
|
|
|
|
2018-11-09 17:39:07 +00:00
|
|
|
if (update_and_show_manipulations) {
|
|
|
|
wxGetApp().obj_manipul()->get_og()->set_name(" " + og_name + " ");
|
|
|
|
wxGetApp().obj_manipul()->get_og()->set_value("object_name", m_objects_model->GetName(GetSelection()));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (update_and_show_settings)
|
|
|
|
wxGetApp().obj_settings()->get_og()->set_name(" " + og_name + " ");
|
|
|
|
|
2018-11-13 11:19:56 +00:00
|
|
|
Sidebar& panel = wxGetApp().sidebar();
|
|
|
|
panel.Freeze();
|
2018-11-09 17:39:07 +00:00
|
|
|
|
|
|
|
wxGetApp().obj_manipul() ->UpdateAndShow(update_and_show_manipulations);
|
|
|
|
wxGetApp().obj_settings()->UpdateAndShow(update_and_show_settings);
|
2018-11-13 11:19:56 +00:00
|
|
|
wxGetApp().sidebar().show_info_sizer();
|
2018-11-09 17:39:07 +00:00
|
|
|
|
2018-11-13 11:19:56 +00:00
|
|
|
panel.Layout();
|
|
|
|
panel.Thaw();
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-10-08 14:27:38 +00:00
|
|
|
void ObjectList::add_object_to_list(size_t obj_idx)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
auto model_object = (*m_objects)[obj_idx];
|
|
|
|
wxString item_name = model_object->name;
|
2018-10-18 09:28:31 +00:00
|
|
|
auto item = m_objects_model->Add(item_name);
|
2018-10-05 21:29:15 +00:00
|
|
|
|
|
|
|
// Add error icon if detected auto-repaire
|
|
|
|
auto stats = model_object->volumes[0]->mesh.stl.stats;
|
|
|
|
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
|
|
|
|
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
|
2018-10-31 11:26:57 +00:00
|
|
|
if (errors > 0) {
|
2018-10-05 21:29:15 +00:00
|
|
|
wxVariant variant;
|
2018-10-16 09:08:37 +00:00
|
|
|
variant << PrusaDataViewBitmapText(item_name, m_bmp_manifold_warning);
|
2018-10-05 21:29:15 +00:00
|
|
|
m_objects_model->SetValue(variant, item, 0);
|
|
|
|
}
|
|
|
|
|
2018-11-06 08:06:26 +00:00
|
|
|
// add volumes to the object
|
2018-10-05 21:29:15 +00:00
|
|
|
if (model_object->volumes.size() > 1) {
|
|
|
|
for (auto id = 0; id < model_object->volumes.size(); id++)
|
2018-10-18 08:40:26 +00:00
|
|
|
m_objects_model->AddVolumeChild(item,
|
2018-10-05 21:29:15 +00:00
|
|
|
model_object->volumes[id]->name,
|
2018-11-02 22:27:31 +00:00
|
|
|
ModelVolume::MODEL_PART,
|
2018-11-19 13:01:14 +00:00
|
|
|
!model_object->volumes[id]->config.has("extruder") ? 0 :
|
|
|
|
model_object->volumes[id]->config.option<ConfigOptionInt>("extruder")->value,
|
2018-10-05 21:29:15 +00:00
|
|
|
false);
|
2018-10-08 14:27:38 +00:00
|
|
|
Expand(item);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-06 08:06:26 +00:00
|
|
|
// add instances to the object, if it has those
|
2018-11-01 15:22:16 +00:00
|
|
|
if (model_object->instances.size()>1)
|
|
|
|
increase_object_instances(obj_idx, model_object->instances.size());
|
|
|
|
|
2018-11-06 08:06:26 +00:00
|
|
|
// add settings to the object, if it has those
|
|
|
|
auto opt_keys = model_object->config.keys();
|
2018-11-07 12:40:24 +00:00
|
|
|
if (!opt_keys.empty() && !(opt_keys.size() == 1 && opt_keys[0] == "extruder")) {
|
2018-11-06 08:06:26 +00:00
|
|
|
select_item(m_objects_model->AddSettingsChild(item));
|
|
|
|
Collapse(item);
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
#ifndef __WXOSX__
|
2018-10-11 13:57:09 +00:00
|
|
|
selection_changed();
|
2018-10-05 21:29:15 +00:00
|
|
|
#endif //__WXMSW__
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::delete_object_from_list()
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
auto item = GetSelection();
|
2018-10-12 10:00:37 +00:00
|
|
|
if (!item)
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
2018-10-12 10:00:37 +00:00
|
|
|
if (m_objects_model->GetParent(item) == wxDataViewItem(0))
|
|
|
|
select_item(m_objects_model->Delete(item));
|
|
|
|
else
|
|
|
|
select_item(m_objects_model->Delete(m_objects_model->GetParent(item)));
|
|
|
|
}
|
2018-10-05 21:29:15 +00:00
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
void ObjectList::delete_object_from_list(const size_t obj_idx)
|
|
|
|
{
|
|
|
|
select_item(m_objects_model->Delete(m_objects_model->GetItemById(obj_idx)));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::delete_volume_from_list(const size_t obj_idx, const size_t vol_idx)
|
|
|
|
{
|
|
|
|
select_item(m_objects_model->Delete(m_objects_model->GetItemByVolumeId(obj_idx, vol_idx)));
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
2018-11-13 12:34:31 +00:00
|
|
|
void ObjectList::delete_instance_from_list(const size_t obj_idx, const size_t inst_idx)
|
|
|
|
{
|
|
|
|
select_item(m_objects_model->Delete(m_objects_model->GetItemByInstanceId(obj_idx, inst_idx)));
|
|
|
|
}
|
|
|
|
|
2018-11-13 13:17:35 +00:00
|
|
|
void ObjectList::delete_from_model_and_list(const ItemType type, const int obj_idx, const int sub_obj_idx)
|
|
|
|
{
|
|
|
|
if ( !(type&(itObject|itVolume|itInstance)) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (type&itObject) {
|
|
|
|
del_object(obj_idx);
|
|
|
|
delete_object_from_list(obj_idx);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
del_subobject_from_object(obj_idx, sub_obj_idx, type);
|
|
|
|
|
|
|
|
type == itVolume ? delete_volume_from_list(obj_idx, sub_obj_idx) :
|
|
|
|
delete_instance_from_list(obj_idx, sub_obj_idx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-11-14 07:53:56 +00:00
|
|
|
void ObjectList::delete_from_model_and_list(const std::vector<ItemForDelete>& items_for_delete)
|
2018-11-13 13:17:35 +00:00
|
|
|
{
|
2018-11-14 10:22:13 +00:00
|
|
|
if (items_for_delete.empty())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (std::vector<ItemForDelete>::const_reverse_iterator item = items_for_delete.rbegin(); item != items_for_delete.rend(); ++item)
|
2018-11-13 13:17:35 +00:00
|
|
|
{
|
2018-11-14 10:22:13 +00:00
|
|
|
if (!(item->type&(itObject | itVolume | itInstance)))
|
2018-11-13 13:17:35 +00:00
|
|
|
continue;
|
2018-11-14 10:22:13 +00:00
|
|
|
if (item->type&itObject) {
|
|
|
|
del_object(item->obj_idx);
|
|
|
|
m_objects_model->Delete(m_objects_model->GetItemById(item->obj_idx));
|
2018-11-13 13:17:35 +00:00
|
|
|
}
|
|
|
|
else {
|
2018-11-14 10:22:13 +00:00
|
|
|
del_subobject_from_object(item->obj_idx, item->sub_obj_idx, item->type);
|
|
|
|
if (item->type&itVolume)
|
|
|
|
m_objects_model->Delete(m_objects_model->GetItemByVolumeId(item->obj_idx, item->sub_obj_idx));
|
2018-11-13 13:17:35 +00:00
|
|
|
else
|
2018-11-14 10:22:13 +00:00
|
|
|
m_objects_model->Delete(m_objects_model->GetItemByInstanceId(item->obj_idx, item->sub_obj_idx));
|
2018-11-13 13:17:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
part_selection_changed();
|
|
|
|
}
|
|
|
|
|
2018-10-05 21:29:15 +00:00
|
|
|
void ObjectList::delete_all_objects_from_list()
|
|
|
|
{
|
|
|
|
m_objects_model->DeleteAll();
|
|
|
|
part_selection_changed();
|
|
|
|
}
|
|
|
|
|
2018-10-18 08:40:26 +00:00
|
|
|
void ObjectList::increase_object_instances(const size_t obj_idx, const size_t num)
|
|
|
|
{
|
|
|
|
select_item(m_objects_model->AddInstanceChild(m_objects_model->GetItemById(obj_idx), num));
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::decrease_object_instances(const size_t obj_idx, const size_t num)
|
2018-10-05 21:29:15 +00:00
|
|
|
{
|
2018-10-18 08:40:26 +00:00
|
|
|
select_item(m_objects_model->DeleteLastInstance(m_objects_model->GetItemById(obj_idx), num));
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::unselect_objects()
|
|
|
|
{
|
2018-10-08 14:27:38 +00:00
|
|
|
if (!GetSelection())
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_prevent_list_events = true;
|
2018-10-08 14:27:38 +00:00
|
|
|
UnselectAll();
|
2018-10-05 21:29:15 +00:00
|
|
|
part_selection_changed();
|
|
|
|
m_prevent_list_events = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::select_current_object(int idx)
|
|
|
|
{
|
|
|
|
m_prevent_list_events = true;
|
2018-10-08 14:27:38 +00:00
|
|
|
UnselectAll();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (idx >= 0)
|
2018-10-08 14:27:38 +00:00
|
|
|
Select(m_objects_model->GetItemById(idx));
|
2018-10-05 21:29:15 +00:00
|
|
|
part_selection_changed();
|
|
|
|
m_prevent_list_events = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::select_current_volume(int idx, int vol_idx)
|
|
|
|
{
|
|
|
|
if (vol_idx < 0) {
|
|
|
|
select_current_object(idx);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
m_prevent_list_events = true;
|
2018-10-08 14:27:38 +00:00
|
|
|
UnselectAll();
|
2018-10-05 21:29:15 +00:00
|
|
|
if (idx >= 0)
|
2018-10-08 14:27:38 +00:00
|
|
|
Select(m_objects_model->GetItemByVolumeId(idx, vol_idx));
|
2018-10-05 21:29:15 +00:00
|
|
|
part_selection_changed();
|
|
|
|
m_prevent_list_events = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::remove()
|
|
|
|
{
|
2018-10-12 10:00:37 +00:00
|
|
|
if (GetSelectedItemsCount() == 0)
|
2018-10-05 21:29:15 +00:00
|
|
|
return;
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
wxDataViewItemArray sels;
|
|
|
|
GetSelections(sels);
|
|
|
|
|
|
|
|
for (auto& item : sels)
|
|
|
|
{
|
|
|
|
if (m_objects_model->GetParent(item) == wxDataViewItem(0))
|
|
|
|
wxGetApp().plater()->remove(m_objects_model->GetIdByItem(item));
|
|
|
|
else
|
|
|
|
del_subobject_item(item);
|
2018-10-05 21:29:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::init_objects()
|
|
|
|
{
|
|
|
|
m_objects = wxGetApp().model_objects();
|
|
|
|
}
|
2018-10-04 14:43:10 +00:00
|
|
|
|
2018-10-10 14:22:20 +00:00
|
|
|
bool ObjectList::multiple_selection() const
|
|
|
|
{
|
2018-10-11 13:57:09 +00:00
|
|
|
return GetSelectedItemsCount() > 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::update_selections()
|
|
|
|
{
|
|
|
|
auto& selection = _3DScene::get_canvas(wxGetApp().canvas3D())->get_selection();
|
|
|
|
wxDataViewItemArray sels;
|
|
|
|
|
2018-11-08 14:45:55 +00:00
|
|
|
if (selection.is_single_full_object())
|
|
|
|
{
|
|
|
|
sels.Add(m_objects_model->GetItemById(selection.get_object_idx()));
|
|
|
|
}
|
2018-11-12 15:03:29 +00:00
|
|
|
else if (selection.is_single_volume() || selection.is_modifier() ||
|
|
|
|
selection.is_multiple_volume() || selection.is_multiple_full_object()) {
|
2018-11-05 12:53:30 +00:00
|
|
|
for (auto idx : selection.get_volume_idxs()) {
|
|
|
|
const auto gl_vol = selection.get_volume(idx);
|
2018-11-08 14:45:55 +00:00
|
|
|
if (selection.is_multiple_full_object())
|
|
|
|
sels.Add(m_objects_model->GetItemById(gl_vol->object_idx()));
|
|
|
|
else
|
|
|
|
sels.Add(m_objects_model->GetItemByVolumeId(gl_vol->object_idx(), gl_vol->volume_idx()));
|
2018-11-05 12:53:30 +00:00
|
|
|
}
|
|
|
|
}
|
2018-11-08 12:39:35 +00:00
|
|
|
else if (selection.is_single_full_instance() || selection.is_multiple_full_instance()) {
|
2018-11-05 12:53:30 +00:00
|
|
|
for (auto idx : selection.get_instance_idxs()) {
|
|
|
|
sels.Add(m_objects_model->GetItemByInstanceId(selection.get_object_idx(), idx));
|
|
|
|
}
|
2018-10-11 13:57:09 +00:00
|
|
|
}
|
2018-11-05 12:53:30 +00:00
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
select_items(sels);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::update_selections_on_canvas()
|
|
|
|
{
|
|
|
|
auto& selection = _3DScene::get_canvas(wxGetApp().canvas3D())->get_selection();
|
|
|
|
|
|
|
|
const int sel_cnt = GetSelectedItemsCount();
|
|
|
|
if (sel_cnt == 0) {
|
|
|
|
selection.clear();
|
|
|
|
_3DScene::render(wxGetApp().canvas3D());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-16 11:56:28 +00:00
|
|
|
auto add_to_selection = [this](const wxDataViewItem& item, GLCanvas3D::Selection& selection, bool as_single_selection)
|
2018-10-11 13:57:09 +00:00
|
|
|
{
|
2018-10-31 11:26:57 +00:00
|
|
|
if (m_objects_model->GetParent(item) == wxDataViewItem(0)) {
|
2018-10-11 13:57:09 +00:00
|
|
|
selection.add_object(m_objects_model->GetIdByItem(item), as_single_selection);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2018-10-18 08:40:26 +00:00
|
|
|
if (m_objects_model->GetItemType(item) == itVolume) {
|
|
|
|
const int obj_idx = m_objects_model->GetIdByItem(m_objects_model->GetParent(item));
|
|
|
|
const int vol_idx = m_objects_model->GetVolumeIdByItem(item);
|
2018-11-07 09:34:44 +00:00
|
|
|
selection.add_volume(obj_idx, vol_idx, 0, as_single_selection);
|
2018-10-18 08:40:26 +00:00
|
|
|
}
|
|
|
|
else if (m_objects_model->GetItemType(item) == itInstance) {
|
|
|
|
const int obj_idx = m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item));
|
|
|
|
const int inst_idx = m_objects_model->GetInstanceIdByItem(item);
|
|
|
|
selection.add_instance(obj_idx, inst_idx, as_single_selection);
|
|
|
|
}
|
2018-10-11 13:57:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (sel_cnt == 1) {
|
|
|
|
wxDataViewItem item = GetSelection();
|
2018-10-18 08:40:26 +00:00
|
|
|
if (m_objects_model->GetItemType(item) & (itSettings|itInstanceRoot))
|
2018-10-12 10:00:37 +00:00
|
|
|
add_to_selection(m_objects_model->GetParent(item), selection, true);
|
2018-10-11 13:57:09 +00:00
|
|
|
else
|
|
|
|
add_to_selection(item, selection, true);
|
|
|
|
|
|
|
|
_3DScene::render(wxGetApp().canvas3D());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
wxDataViewItemArray sels;
|
|
|
|
GetSelections(sels);
|
|
|
|
|
|
|
|
selection.clear();
|
|
|
|
for (auto item: sels)
|
|
|
|
add_to_selection(item, selection, false);
|
|
|
|
|
|
|
|
_3DScene::render(wxGetApp().canvas3D());
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::select_item(const wxDataViewItem& item)
|
|
|
|
{
|
|
|
|
m_prevent_list_events = true;
|
|
|
|
|
|
|
|
UnselectAll();
|
|
|
|
Select(item);
|
|
|
|
part_selection_changed();
|
|
|
|
|
|
|
|
m_prevent_list_events = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::select_items(const wxDataViewItemArray& sels)
|
|
|
|
{
|
|
|
|
m_prevent_list_events = true;
|
|
|
|
|
|
|
|
UnselectAll();
|
|
|
|
SetSelections(sels);
|
|
|
|
part_selection_changed();
|
|
|
|
|
|
|
|
m_prevent_list_events = false;
|
|
|
|
}
|
|
|
|
|
2018-10-12 10:00:37 +00:00
|
|
|
void ObjectList::select_all()
|
|
|
|
{
|
|
|
|
SelectAll();
|
|
|
|
selection_changed();
|
|
|
|
}
|
|
|
|
|
2018-11-08 14:45:55 +00:00
|
|
|
void ObjectList::select_item_all_children()
|
|
|
|
{
|
|
|
|
wxDataViewItemArray sels;
|
|
|
|
|
|
|
|
// There is no selection before OR some object is selected => select all objects
|
|
|
|
if (!GetSelection() || m_objects_model->GetItemType(GetSelection()) == itObject) {
|
|
|
|
for (int i = 0; i < m_objects->size(); i++)
|
|
|
|
sels.Add(m_objects_model->GetItemById(i));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
const auto item = GetSelection();
|
|
|
|
// Some volume(instance) is selected => select all volumes(instances) inside the current object
|
|
|
|
if (m_objects_model->GetItemType(item) & (itVolume | itInstance)) {
|
|
|
|
m_objects_model->GetChildren(m_objects_model->GetParent(item), sels);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSelections(sels);
|
|
|
|
selection_changed();
|
|
|
|
}
|
|
|
|
|
2018-10-11 13:57:09 +00:00
|
|
|
void ObjectList::fix_multiselection_conflicts()
|
|
|
|
{
|
2018-10-12 10:00:37 +00:00
|
|
|
if (GetSelectedItemsCount() <= 1)
|
2018-10-11 13:57:09 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_prevent_list_events = true;
|
|
|
|
|
2018-10-10 14:22:20 +00:00
|
|
|
wxDataViewItemArray sels;
|
|
|
|
GetSelections(sels);
|
2018-10-11 13:57:09 +00:00
|
|
|
|
|
|
|
for (auto item : sels) {
|
2018-11-08 14:45:55 +00:00
|
|
|
if (m_objects_model->GetItemType(item) & (itSettings|itInstanceRoot))
|
2018-10-11 13:57:09 +00:00
|
|
|
Unselect(item);
|
2018-10-12 10:00:37 +00:00
|
|
|
else if (m_objects_model->GetParent(item) != wxDataViewItem(0))
|
2018-10-11 13:57:09 +00:00
|
|
|
Unselect(m_objects_model->GetParent(item));
|
|
|
|
}
|
|
|
|
|
|
|
|
m_prevent_list_events = false;
|
2018-10-10 14:22:20 +00:00
|
|
|
}
|
|
|
|
|
2018-11-02 22:27:31 +00:00
|
|
|
ModelVolume* ObjectList::get_selected_model_volume()
|
|
|
|
{
|
|
|
|
auto item = GetSelection();
|
|
|
|
if (!item || m_objects_model->GetItemType(item) != itVolume)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
const auto vol_idx = m_objects_model->GetVolumeIdByItem(item);
|
|
|
|
const auto obj_idx = get_selected_obj_idx();
|
|
|
|
if (vol_idx < 0 || obj_idx < 0)
|
|
|
|
return nullptr;
|
|
|
|
|
|
|
|
return (*m_objects)[obj_idx]->volumes[vol_idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
void ObjectList::change_part_type()
|
|
|
|
{
|
|
|
|
ModelVolume* volume = get_selected_model_volume();
|
|
|
|
if (!volume)
|
|
|
|
return;
|
|
|
|
const auto type = volume->type();
|
|
|
|
|
|
|
|
const wxString names[] = { "Part", "Modifier", "Support Enforcer", "Support Blocker" };
|
|
|
|
|
|
|
|
auto new_type = wxGetSingleChoiceIndex("Type: ", _(L("Select type of part")), wxArrayString(4, names), type);
|
|
|
|
|
|
|
|
if (new_type == type || new_type < 0)
|
|
|
|
return;
|
|
|
|
|
2018-11-05 07:55:44 +00:00
|
|
|
const auto item = GetSelection();
|
2018-11-02 22:27:31 +00:00
|
|
|
volume->set_type(static_cast<ModelVolume::Type>(new_type));
|
2018-11-05 07:55:44 +00:00
|
|
|
m_objects_model->SetVolumeType(item, new_type);
|
2018-11-02 22:27:31 +00:00
|
|
|
|
|
|
|
m_parts_changed = true;
|
|
|
|
parts_changed(get_selected_obj_idx());
|
2018-11-05 07:55:44 +00:00
|
|
|
|
|
|
|
// Update settings showing, if we have it
|
|
|
|
//(we show additional settings for Part and Modifier and hide it for Support Blocker/Enforcer)
|
|
|
|
const auto settings_item = m_objects_model->GetSettingsItem(item);
|
|
|
|
if (settings_item &&
|
|
|
|
new_type == ModelVolume::SUPPORT_ENFORCER || new_type == ModelVolume::SUPPORT_BLOCKER) {
|
|
|
|
m_objects_model->Delete(settings_item);
|
|
|
|
}
|
|
|
|
else if (!settings_item &&
|
|
|
|
new_type == ModelVolume::MODEL_PART || new_type == ModelVolume::PARAMETER_MODIFIER) {
|
|
|
|
select_item(m_objects_model->AddSettingsChild(item));
|
|
|
|
}
|
2018-11-02 22:27:31 +00:00
|
|
|
}
|
|
|
|
|
2018-11-12 12:47:24 +00:00
|
|
|
void ObjectList::last_volume_is_deleted(const int obj_idx)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (obj_idx < 0 || (*m_objects).empty() || (*m_objects)[obj_idx]->volumes.empty())
|
|
|
|
return;
|
|
|
|
auto volume = (*m_objects)[obj_idx]->volumes[0];
|
|
|
|
|
|
|
|
// clear volume's config values
|
|
|
|
volume->config.clear();
|
|
|
|
|
|
|
|
// set a default extruder value, since user can't add it manually
|
|
|
|
volume->config.set_key_value("extruder", new ConfigOptionInt(0));
|
|
|
|
}
|
|
|
|
|
2018-10-04 14:43:10 +00:00
|
|
|
} //namespace GUI
|
|
|
|
} //namespace Slic3r
|