NEW:add hide function in assemble_view menu

1.support hide funtion in assemble view
2.fix an issue that switch printable in assemble view will make
model-in-assemble-view turn transparent instead of model-in-view3D
3.fix a crash: right-click on objectlist after entering assemble view

Change-Id: Ia1a7ca492637eeaacd862ba015c440a55a83ca6e
This commit is contained in:
liz.li 2022-10-17 16:51:51 +08:00 committed by Lane.Wei
parent 674348c575
commit 5fc3694e08
9 changed files with 115 additions and 20 deletions

View File

@ -390,6 +390,8 @@ std::array<float, 4> GLVolume::MODEL_NEGTIVE_COL = {0.3f, 0.3f, 0.3f, 0.4f};
std::array<float, 4> GLVolume::SUPPORT_ENFORCER_COL = {0.3f, 0.3f, 1.0f, 0.4f};
std::array<float, 4> GLVolume::SUPPORT_BLOCKER_COL = {1.0f, 0.3f, 0.3f, 0.4f};
std::array<float, 4> GLVolume::MODEL_HIDDEN_COL = {0.f, 0.f, 0.f, 0.3f};
std::array<std::array<float, 4>, 5> GLVolume::MODEL_COLOR = { {
{ 1.0f, 1.0f, 0.0f, 1.f },
{ 1.0f, 0.5f, 0.5f, 1.f },
@ -430,6 +432,7 @@ GLVolume::GLVolume(float r, float g, float b, float a)
, selected(false)
, disabled(false)
, printable(true)
, visible(true)
, is_active(true)
, zoom_to_volumes(true)
, shader_outside_printer_detection_enabled(false)
@ -521,6 +524,14 @@ void GLVolume::set_render_color()
render_color[2] = UNPRINTABLE_COLOR[2];
render_color[3] = UNPRINTABLE_COLOR[3];
}
//BBS set invisible color
if (!visible) {
render_color[0] = MODEL_HIDDEN_COL[0];
render_color[1] = MODEL_HIDDEN_COL[1];
render_color[2] = MODEL_HIDDEN_COL[2];
render_color[3] = MODEL_HIDDEN_COL[3];
}
}
std::array<float, 4> color_from_model_volume(const ModelVolume& model_volume)

View File

@ -269,6 +269,7 @@ public:
static std::array<float, 4> MODEL_NEGTIVE_COL;
static std::array<float, 4> SUPPORT_ENFORCER_COL;
static std::array<float, 4> SUPPORT_BLOCKER_COL;
static std::array<float, 4> MODEL_HIDDEN_COL;
static void update_render_colors();
static void load_render_colors();
@ -363,6 +364,8 @@ public:
bool disabled : 1;
// Is this object printable?
bool printable : 1;
// Is this object visible(in assemble view)?
bool visible : 1;
// Whether or not this volume is active for rendering
bool is_active : 1;
// Whether or not to use this volume when applying zoom_to_volumes()

View File

@ -2030,6 +2030,16 @@ void GLCanvas3D::deselect_all()
post_event(SimpleEvent(EVT_GLCANVAS_OBJECT_SELECT));
}
void GLCanvas3D::set_selected_visible(bool visible)
{
for (unsigned int i : m_selection.get_volume_idxs()) {
GLVolume* volume = const_cast<GLVolume*>(m_selection.get_volume(i));
volume->visible = visible;
volume->color[3] = visible ? 1.f : GLVolume::MODEL_HIDDEN_COL[3];
volume->render_color[3] = volume->color[3];
}
}
void GLCanvas3D::delete_selected()
{
m_selection.erase();
@ -3520,6 +3530,28 @@ void GLCanvas3D::on_mouse_wheel(wxMouseEvent& evt)
if (m_gizmos.on_mouse_wheel(evt))
return;
if (m_canvas_type == CanvasAssembleView && (evt.AltDown() || evt.CmdDown())) {
float rotation = (float)evt.GetWheelRotation() / (float)evt.GetWheelDelta();
if (evt.AltDown()) {
auto clp_dist = m_gizmos.m_assemble_view_data->model_objects_clipper()->get_position();
clp_dist = rotation < 0.f
? std::max(0., clp_dist - 0.01)
: std::min(1., clp_dist + 0.01);
m_gizmos.m_assemble_view_data->model_objects_clipper()->set_position(clp_dist, true);
}
else if (evt.CmdDown()) {
m_explosion_ratio = rotation < 0.f
? std::max(1., m_explosion_ratio - 0.01)
: std::min(3., m_explosion_ratio + 0.01);
if (m_explosion_ratio != GLVolume::explosion_ratio) {
for (GLVolume* volume : m_volumes.volumes) {
volume->set_bounding_boxes_as_dirty();
}
GLVolume::explosion_ratio = m_explosion_ratio;
}
}
return;
}
// Calculate the zoom delta and apply it to the current zoom factor
#ifdef SUPPORT_REVERSE_MOUSE_ZOOM
double direction_factor = (wxGetApp().app_config->get("reverse_mouse_wheel_zoom") == "1") ? -1.0 : 1.0;
@ -6561,7 +6593,7 @@ void GLCanvas3D::_render_objects(GLVolumeCollection::ERenderType type, bool with
return true;
}
}, with_outline);
if (m_canvas_type == CanvasAssembleView) {
if (m_canvas_type == CanvasAssembleView && m_gizmos.m_assemble_view_data->model_objects_clipper()->get_position() > 0) {
const GLGizmosManager& gm = get_gizmos_manager();
shader->stop_using();
gm.render_painter_assemble_view();

View File

@ -847,6 +847,7 @@ public:
void select_all();
void deselect_all();
void set_selected_visible(bool visible);
void delete_selected();
void ensure_on_bed(unsigned int object_idx, bool allow_negative_z);

View File

@ -432,6 +432,19 @@ std::vector<wxBitmap> MenuFactory::get_volume_bitmaps()
return volume_bmps;
}
void MenuFactory::append_menu_item_set_visible(wxMenu* menu)
{
bool has_one_shown = false;
const Selection& selection = plater()->canvas3D()->get_selection();
for (unsigned int i : selection.get_volume_idxs()) {
has_one_shown |= selection.get_volume(i)->visible;
}
append_menu_item(menu, wxID_ANY, has_one_shown ?_L("Hide") : _L("Show"), "",
[has_one_shown](wxCommandEvent&) { plater()->set_selected_visible(!has_one_shown); }, "", nullptr,
[]() { return true; }, m_parent);
}
void MenuFactory::append_menu_item_delete(wxMenu* menu)
{
#ifdef __WINDOWS__
@ -735,6 +748,8 @@ void MenuFactory::append_menu_items_flush_options(wxMenu* menu)
bool show_flush_option_menu = false;
ObjectList* object_list = obj_list();
const Selection& selection = get_selection();
if (selection.get_object_idx() < 0)
return;
if (wxGetApp().plater()->get_partplate_list().get_curr_plate()->contains(selection.get_bounding_box())) {
auto plate_extruders = wxGetApp().plater()->get_partplate_list().get_curr_plate()->get_extruders();
for (auto extruder : plate_extruders) {
@ -784,7 +799,7 @@ void MenuFactory::append_menu_items_flush_options(wxMenu* menu)
{
i++;
wxMenuItem* item = node->GetData();
if (item->GetItemLabelText() == "Edit in Parameter Table")
if (item->GetItemLabelText() == _L("Edit in Parameter Table"))
break;
}
menu->Insert(i, wxID_ANY, _L("Flush Options"), flush_options_menu);
@ -1310,8 +1325,9 @@ wxMenu* MenuFactory::assemble_multi_selection_menu()
return nullptr;
wxMenu* menu = new MenuWithSeparators();
append_menu_item_fix_through_netfabb(menu);
append_menu_item_simplify(menu);
append_menu_item_set_visible(menu);
//append_menu_item_fix_through_netfabb(menu);
//append_menu_item_simplify(menu);
append_menu_item_delete(menu);
menu->AppendSeparator();
append_menu_item_change_extruder(menu);
@ -1328,18 +1344,36 @@ wxMenu* MenuFactory::plate_menu()
wxMenu* MenuFactory::assemble_object_menu()
{
wxMenu* menu = new MenuWithSeparators();
// Set Visible
append_menu_item_set_visible(menu);
// Delete
append_menu_item_delete(menu);
//// Object Repair
//append_menu_item_fix_through_netfabb(menu);
//// Object Simplify
//append_menu_item_simplify(menu);
menu->AppendSeparator();
// Set filament
append_menu_item_change_extruder(&m_assemble_object_menu);
// Enter per object parameters
append_menu_item_per_object_settings(&m_assemble_object_menu);
return &m_assemble_object_menu;
append_menu_item_change_extruder(menu);
//// Enter per object parameters
//append_menu_item_per_object_settings(menu);
return menu;
}
wxMenu* MenuFactory::assemble_part_menu()
{
append_menu_item_change_extruder(&m_assemble_part_menu);
append_menu_item_per_object_settings(&m_assemble_part_menu);
return &m_assemble_part_menu;
wxMenu* menu = new MenuWithSeparators();
append_menu_item_set_visible(menu);
append_menu_item_delete(menu);
//append_menu_item_simplify(menu);
menu->AppendSeparator();
append_menu_item_change_extruder(menu);
//append_menu_item_per_object_settings(menu);
return menu;
}
void MenuFactory::append_menu_item_clone(wxMenu* menu)

View File

@ -126,6 +126,7 @@ private:
void append_menu_item_reload_from_disk(wxMenu* menu);
void append_menu_item_replace_with_stl(wxMenu* menu);
void append_menu_item_change_extruder(wxMenu* menu);
void append_menu_item_set_visible(wxMenu* menu);
void append_menu_item_delete(wxMenu* menu);
void append_menu_item_scale_selection_to_fit_print_volume(wxMenu* menu);
void append_menu_items_convert_unit(wxMenu* menu); // Add "Conver/Revert..." menu items (from/to inches/meters) after "Reload From Disk"

View File

@ -731,7 +731,7 @@ void ObjectList::printable_state_changed(const std::vector<ObjectVolumeID>& ov_i
obj_idxs.erase(unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end());
// update printable state on canvas
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
// update scene
wxGetApp().plater()->update();
@ -1777,7 +1777,7 @@ void ObjectList::load_subobject(ModelVolumeType type, bool from_galery/* = false
if (type == ModelVolumeType::MODEL_PART)
// update printable state on canvas
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
if (items.size() > 1) {
m_selection_mode = smVolume;
@ -2055,7 +2055,7 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode
});
if (type == ModelVolumeType::MODEL_PART)
// update printable state on canvas
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
// apply the instance transform to all volumes and reset instance transform except the offset
apply_object_instance_transfrom_to_all_volumes(&model_object);
@ -2192,7 +2192,7 @@ void ObjectList::load_mesh_part(const TriangleMesh &mesh, const wxString &name,
wxDataViewItemArray items = reorder_volumes_and_get_selection(obj_idx, [volumes](const ModelVolume* volume) {
return std::find(volumes.begin(), volumes.end(), volume) != volumes.end(); });
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_object((size_t)obj_idx);
if (items.size() > 1) {
m_selection_mode = smVolume;
@ -4565,7 +4565,7 @@ void ObjectList::instances_to_separated_object(const int obj_idx, const std::set
}
// update printable state for new volumes on canvas3D
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_object(new_obj_indx);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_object(new_obj_indx);
update_info_items(new_obj_indx);
}
@ -4598,7 +4598,7 @@ void ObjectList::instances_to_separated_objects(const int obj_idx)
}
// update printable state for new volumes on canvas3D
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects(object_idxs);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(object_idxs);
for (size_t object : object_idxs)
update_info_items(object);
}
@ -5012,7 +5012,7 @@ void ObjectList::reload_all_plates(bool notify_partplate)
m_prevent_canvas_selection_update = false;
// update printable states on canvas
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
// update scene
wxGetApp().plater()->update();
}
@ -5146,7 +5146,7 @@ void ObjectList::toggle_printable_state()
obj_idxs.erase(unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end());
// update printable state on canvas
wxGetApp().plater()->canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
wxGetApp().plater()->get_view3D_canvas3D()->update_instance_printable_state_for_objects(obj_idxs);
// update scene
wxGetApp().plater()->update();

View File

@ -8739,6 +8739,18 @@ void Plater::delete_all_objects_from_model()
p->delete_all_objects_from_model();
}
void Plater::set_selected_visible(bool visible)
{
if (p->get_curr_selection().is_empty())
return;
Plater::TakeSnapshot snapshot(this, "Set Selected Objects Visible in AssembleView");
p->m_ui_jobs.cancel_all();
p->get_current_canvas3D()->set_selected_visible(visible);
}
void Plater::remove_selected()
{
/*if (p->get_selection().is_empty())

View File

@ -295,6 +295,7 @@ public:
void trigger_restore_project(int skip_confirm = 0);
void delete_object_from_model(size_t obj_idx, bool refresh_immediately = true); // BBS support refresh immediately
void delete_all_objects_from_model(); //BBS delete all objects from model
void set_selected_visible(bool visible);
void remove_selected();
void increase_instances(size_t num = 1);
void decrease_instances(size_t num = 1);