mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer into et_gcode_viewer
This commit is contained in:
		
						commit
						cae84d2857
					
				
					 8 changed files with 145 additions and 4 deletions
				
			
		|  | @ -993,6 +993,56 @@ void ModelObject::scale_mesh_after_creation(const Vec3d &versor) | |||
|     this->invalidate_bounding_box(); | ||||
| } | ||||
| 
 | ||||
| void ModelObject::convert_units(ModelObjectPtrs& new_objects, bool from_imperial, std::vector<int> volume_idxs) | ||||
| { | ||||
|     BOOST_LOG_TRIVIAL(trace) << "ModelObject::convert_units - start"; | ||||
| 
 | ||||
|     ModelObject* new_object = new_clone(*this); | ||||
| 
 | ||||
|     double koef = from_imperial ? 25.4 : 0.0393700787; | ||||
|     const Vec3d versor = Vec3d(koef, koef, koef); | ||||
| 
 | ||||
|     new_object->set_model(nullptr); | ||||
|     new_object->sla_support_points.clear(); | ||||
|     new_object->sla_drain_holes.clear(); | ||||
|     new_object->sla_points_status = sla::PointsStatus::NoPoints; | ||||
|     new_object->clear_volumes(); | ||||
|     new_object->input_file.clear(); | ||||
| 
 | ||||
|     int vol_idx = 0; | ||||
|     for (ModelVolume* volume : volumes) | ||||
|     { | ||||
|         volume->m_supported_facets.clear(); | ||||
|         if (!volume->mesh().empty()) { | ||||
|             TriangleMesh mesh(volume->mesh()); | ||||
|             mesh.require_shared_vertices(); | ||||
| 
 | ||||
|             ModelVolume* vol = new_object->add_volume(mesh); | ||||
|             vol->name = volume->name; | ||||
|             // Don't copy the config's ID.
 | ||||
|             static_cast<DynamicPrintConfig&>(vol->config) = static_cast<const DynamicPrintConfig&>(volume->config); | ||||
|             assert(vol->config.id().valid()); | ||||
|             assert(vol->config.id() != volume->config.id()); | ||||
|             vol->set_material(volume->material_id(), *volume->material()); | ||||
| 
 | ||||
|             // Perform conversion
 | ||||
|             if (volume_idxs.empty() ||  | ||||
|                 std::find(volume_idxs.begin(), volume_idxs.end(), vol_idx) != volume_idxs.end()) { | ||||
|                 vol->scale_geometry_after_creation(versor); | ||||
|                 vol->set_offset(versor.cwiseProduct(vol->get_offset())); | ||||
|             } | ||||
|             else | ||||
|                 vol->set_offset(volume->get_offset()); | ||||
|         } | ||||
|         vol_idx ++; | ||||
|     } | ||||
|     new_object->invalidate_bounding_box(); | ||||
| 
 | ||||
|     new_objects.push_back(new_object); | ||||
| 
 | ||||
|     BOOST_LOG_TRIVIAL(trace) << "ModelObject::convert_units - end"; | ||||
| } | ||||
| 
 | ||||
| size_t ModelObject::materials_count() const | ||||
| { | ||||
|     std::set<t_model_material_id> material_ids; | ||||
|  |  | |||
|  | @ -281,6 +281,7 @@ public: | |||
| 
 | ||||
|     // This method could only be called before the meshes of this ModelVolumes are not shared!
 | ||||
|     void scale_mesh_after_creation(const Vec3d& versor); | ||||
|     void convert_units(ModelObjectPtrs&new_objects, bool from_imperial, std::vector<int> volume_idxs); | ||||
| 
 | ||||
|     size_t materials_count() const; | ||||
|     size_t facets_count() const; | ||||
|  |  | |||
|  | @ -5723,7 +5723,7 @@ void GLCanvas3D::_check_and_update_toolbar_icon_scale() const | |||
| 
 | ||||
|     // set minimum scale as a auto scale for the toolbars
 | ||||
|     float new_scale = std::min(new_h_scale, new_v_scale); | ||||
|     if (fabs(new_scale - scale) > EPSILON) | ||||
|     if (fabs(new_scale - scale) > 0.01) // scale is changed by 1% and more
 | ||||
|         wxGetApp().set_auto_toolbar_icon_scale(new_scale); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -333,6 +333,34 @@ void ObjectList::get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxD | |||
|     vol_idx =   type & itVolume ? m_objects_model->GetVolumeIdByItem(item) : -1; | ||||
| } | ||||
| 
 | ||||
| void ObjectList::get_selection_indexes(std::vector<int>& obj_idxs, std::vector<int>& vol_idxs) | ||||
| { | ||||
|     wxDataViewItemArray sels; | ||||
|     GetSelections(sels); | ||||
|     assert(!sels.IsEmpty()); | ||||
| 
 | ||||
|     if (m_objects_model->GetItemType(sels[0]) & itVolume) { | ||||
|         for (wxDataViewItem item : sels) { | ||||
|             obj_idxs.emplace_back(m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item))); | ||||
| 
 | ||||
|             assert(m_objects_model->GetItemType(item) & itVolume); | ||||
|             vol_idxs.emplace_back(m_objects_model->GetVolumeIdByItem(item)); | ||||
|         } | ||||
|     } | ||||
|     else { | ||||
|         for (wxDataViewItem item : sels) { | ||||
|             const ItemType type = m_objects_model->GetItemType(item); | ||||
|             assert(type & itObject | itInstance | itInstanceRoot); | ||||
| 
 | ||||
|             obj_idxs.emplace_back(type & itObject ? m_objects_model->GetIdByItem(item) : | ||||
|                                   m_objects_model->GetIdByItem(m_objects_model->GetTopParent(item))); | ||||
|         } | ||||
|     } | ||||
| 
 | ||||
|     std::sort(obj_idxs.begin(), obj_idxs.end(), std::greater<int>()); | ||||
|     obj_idxs.erase(std::unique(obj_idxs.begin(), obj_idxs.end()), obj_idxs.end()); | ||||
| } | ||||
| 
 | ||||
| int ObjectList::get_mesh_errors_count(const int obj_idx, const int vol_idx /*= -1*/) const | ||||
| { | ||||
|     if (obj_idx < 0) | ||||
|  | @ -1744,6 +1772,15 @@ void ObjectList::append_menu_item_scale_selection_to_fit_print_volume(wxMenu* me | |||
|         [](wxCommandEvent&) { wxGetApp().plater()->scale_selection_to_fit_print_volume(); }, "", menu); | ||||
| } | ||||
| 
 | ||||
| void ObjectList::append_menu_items_convert_unit(wxMenu* menu) | ||||
| { | ||||
|     append_menu_item(menu, wxID_ANY, _L("Convert from imperial unit"), _L("Convert from imperial unit"), | ||||
|         [](wxCommandEvent&) { wxGetApp().plater()->convert_unit(true); }, "", menu); | ||||
| 
 | ||||
|     append_menu_item(menu, wxID_ANY, _L("Convert to imperial unit"), _L("Convert to imperial unit"), | ||||
|         [](wxCommandEvent&) { wxGetApp().plater()->convert_unit(false); }, "", menu); | ||||
| } | ||||
| 
 | ||||
| void ObjectList::create_object_popupmenu(wxMenu *menu) | ||||
| { | ||||
| #ifdef __WXOSX__   | ||||
|  | @ -1751,6 +1788,7 @@ void ObjectList::create_object_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
|     append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
|  | @ -1775,6 +1813,7 @@ void ObjectList::create_sla_object_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
|     // rest of a object_sla_menu will be added later in:
 | ||||
|  | @ -1788,6 +1827,7 @@ void ObjectList::create_part_popupmenu(wxMenu *menu) | |||
| #endif // __WXOSX__
 | ||||
| 
 | ||||
|     append_menu_item_reload_from_disk(menu); | ||||
|     append_menu_items_convert_unit(menu); | ||||
|     append_menu_item_export_stl(menu); | ||||
|     append_menu_item_fix_through_netfabb(menu); | ||||
| 
 | ||||
|  | @ -4050,6 +4090,8 @@ void ObjectList::show_multi_selection_menu() | |||
|         return wxGetApp().plater()->can_reload_from_disk(); | ||||
|     }, wxGetApp().plater()); | ||||
| 
 | ||||
|     append_menu_items_convert_unit(menu); | ||||
| 
 | ||||
|     wxGetApp().plater()->PopupMenu(menu); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
|  | @ -210,6 +210,7 @@ public: | |||
| 
 | ||||
|     // Get obj_idx and vol_idx values for the selected (by default) or an adjusted item
 | ||||
|     void                get_selected_item_indexes(int& obj_idx, int& vol_idx, const wxDataViewItem& item = wxDataViewItem(0)); | ||||
|     void                get_selection_indexes(std::vector<int>& obj_idxs, std::vector<int>& vol_idxs); | ||||
|     // Get count of errors in the mesh
 | ||||
|     int                 get_mesh_errors_count(const int obj_idx, const int vol_idx = -1) const; | ||||
|     /* Get list of errors in the mesh. Return value is a string, used for the tooltip
 | ||||
|  | @ -252,6 +253,7 @@ public: | |||
|     void                append_menu_item_change_extruder(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); | ||||
|     void                create_object_popupmenu(wxMenu *menu); | ||||
|     void                create_sla_object_popupmenu(wxMenu*menu); | ||||
|     void                create_part_popupmenu(wxMenu*menu); | ||||
|  |  | |||
|  | @ -3751,6 +3751,9 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/ | |||
| 
 | ||||
|         menu->AppendSeparator(); | ||||
| 
 | ||||
|         // "Scale to print volume" makes a sense just for whole object
 | ||||
|         sidebar->obj_list()->append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
| 
 | ||||
|         q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { | ||||
|             const Selection& selection = get_selection(); | ||||
|             int instance_idx = selection.get_instance_idx(); | ||||
|  | @ -3763,10 +3766,9 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/ | |||
|             }, menu_item_printable->GetId()); | ||||
|     } | ||||
| 
 | ||||
|     sidebar->obj_list()->append_menu_items_convert_unit(menu); | ||||
|     sidebar->obj_list()->append_menu_item_fix_through_netfabb(menu); | ||||
| 
 | ||||
|     sidebar->obj_list()->append_menu_item_scale_selection_to_fit_print_volume(menu); | ||||
| 
 | ||||
|     wxMenu* mirror_menu = new wxMenu(); | ||||
|     if (mirror_menu == nullptr) | ||||
|         return false; | ||||
|  | @ -4604,6 +4606,37 @@ void Plater::scale_selection_to_fit_print_volume() | |||
|     p->scale_selection_to_fit_print_volume(); | ||||
| } | ||||
| 
 | ||||
| void Plater::convert_unit(bool from_imperial_unit) | ||||
| { | ||||
|     std::vector<int> obj_idxs, volume_idxs; | ||||
|     wxGetApp().obj_list()->get_selection_indexes(obj_idxs, volume_idxs); | ||||
|     if (obj_idxs.empty() && volume_idxs.empty()) | ||||
|         return; | ||||
| 
 | ||||
|     TakeSnapshot snapshot(this, from_imperial_unit ? _L("Convert from imperial units") : _L("Convert to imperial units")); | ||||
|     wxBusyCursor wait; | ||||
| 
 | ||||
|     ModelObjectPtrs objects; | ||||
|     for (int obj_idx : obj_idxs) { | ||||
|         ModelObject *object = p->model.objects[obj_idx]; | ||||
|         object->convert_units(objects, from_imperial_unit, volume_idxs); | ||||
|         remove(obj_idx); | ||||
|     } | ||||
|     p->load_model_objects(objects); | ||||
|      | ||||
|     Selection& selection = p->view3D->get_canvas3d()->get_selection(); | ||||
|     size_t last_obj_idx = p->model.objects.size() - 1; | ||||
| 
 | ||||
|     if (volume_idxs.empty()) { | ||||
|         for (size_t i = 0; i < objects.size(); ++i) | ||||
|             selection.add_object((unsigned int)(last_obj_idx - i), i == 0); | ||||
|     } | ||||
|     else { | ||||
|         for (int vol_idx : volume_idxs) | ||||
|             selection.add_volume(last_obj_idx, vol_idx, 0, false); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void Plater::cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper, bool keep_lower, bool rotate_lower) | ||||
| { | ||||
|     wxCHECK_RET(obj_idx < p->model.objects.size(), "obj_idx out of bounds"); | ||||
|  |  | |||
|  | @ -212,6 +212,7 @@ public: | |||
|     void set_number_of_copies(/*size_t num*/); | ||||
|     bool is_selection_empty() const; | ||||
|     void scale_selection_to_fit_print_volume(); | ||||
|     void convert_unit(bool from_imperial_unit); | ||||
| 
 | ||||
|     void cut(size_t obj_idx, size_t instance_idx, coordf_t z, bool keep_upper = true, bool keep_lower = true, bool rotate_lower = false); | ||||
| 
 | ||||
|  |  | |||
|  | @ -483,11 +483,18 @@ SearchDialog::SearchDialog(OptionsSearcher* searcher) | |||
|     search_list->GetMainWindow()->Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); | ||||
| #endif //__WXMSW__
 | ||||
| 
 | ||||
|     // Under OSX mouse and key states didn't fill after wxEVT_DATAVIEW_SELECTION_CHANGED call
 | ||||
|     // As a result, we can't to identify what kind of actions was done
 | ||||
|     // So, under OSX is used OnKeyDown function to navigate inside the list
 | ||||
| #ifdef __APPLE__ | ||||
|     search_list->Bind(wxEVT_KEY_DOWN, &SearchDialog::OnKeyDown, this); | ||||
| #endif | ||||
| 
 | ||||
|     check_category->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); | ||||
|     if (check_english) | ||||
|         check_english ->Bind(wxEVT_CHECKBOX, &SearchDialog::OnCheck, this); | ||||
| 
 | ||||
|     Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this); | ||||
| //    Bind(wxEVT_MOTION, &SearchDialog::OnMotion, this);
 | ||||
|     Bind(wxEVT_LEFT_DOWN, &SearchDialog::OnLeftDown, this); | ||||
| 
 | ||||
|     SetSizer(topSizer); | ||||
|  | @ -585,11 +592,16 @@ void SearchDialog::OnSelect(wxDataViewEvent& event) | |||
|     if (prevent_list_events) | ||||
|         return;     | ||||
| 
 | ||||
|     // Under OSX mouse and key states didn't fill after wxEVT_DATAVIEW_SELECTION_CHANGED call
 | ||||
|     // As a result, we can't to identify what kind of actions was done
 | ||||
|     // So, under OSX is used OnKeyDown function to navigate inside the list
 | ||||
| #ifndef __APPLE__ | ||||
|     // wxEVT_DATAVIEW_SELECTION_CHANGED is processed, when selection is changed after mouse click or press the Up/Down arrows
 | ||||
|     // But this two cases should be processed in different way:
 | ||||
|     // Up/Down arrows   -> leave it as it is (just a navigation)
 | ||||
|     // LeftMouseClick   -> call the ProcessSelection function  
 | ||||
|     if (wxGetMouseState().LeftIsDown()) | ||||
| #endif //__APPLE__
 | ||||
|         ProcessSelection(search_list->GetSelection()); | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 enricoturri1966
						enricoturri1966