mirror of
				https://github.com/SoftFever/OrcaSlicer.git
				synced 2025-10-30 20:21:12 -06:00 
			
		
		
		
	ENH: generate wipe tower when custom change gcode filament
Change-Id: Ia0c81453f09457a9d1d56fbcdce79112953c0208
This commit is contained in:
		
							parent
							
								
									75c5d7b267
								
							
						
					
					
						commit
						4284d2ddb0
					
				
					 10 changed files with 58 additions and 11 deletions
				
			
		|  | @ -327,10 +327,18 @@ std::vector<unsigned int> Print::support_material_extruders() const | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // returns 0-based indices of used extruders
 | // returns 0-based indices of used extruders
 | ||||||
| std::vector<unsigned int> Print::extruders() const | std::vector<unsigned int> Print::extruders(bool conside_custom_gcode) const | ||||||
| { | { | ||||||
|     std::vector<unsigned int> extruders = this->object_extruders(); |     std::vector<unsigned int> extruders = this->object_extruders(); | ||||||
|     append(extruders, this->support_material_extruders()); |     append(extruders, this->support_material_extruders()); | ||||||
|  | 
 | ||||||
|  |     if (conside_custom_gcode) { | ||||||
|  |         for (auto item : m_model.custom_gcode_per_print_z.gcodes) { | ||||||
|  |         if (item.type == CustomGCode::Type::ToolChange) | ||||||
|  |             extruders.push_back((unsigned int)item.extruder); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     sort_remove_duplicates(extruders); |     sort_remove_duplicates(extruders); | ||||||
|     return extruders; |     return extruders; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -660,7 +660,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     std::vector<unsigned int> object_extruders() const; |     std::vector<unsigned int> object_extruders() const; | ||||||
|     std::vector<unsigned int> support_material_extruders() const; |     std::vector<unsigned int> support_material_extruders() const; | ||||||
|     std::vector<unsigned int> extruders() const; |     std::vector<unsigned int> extruders(bool conside_custom_gcode = false) const; | ||||||
|     double              max_allowed_layer_height() const; |     double              max_allowed_layer_height() const; | ||||||
|     bool                has_support_material() const; |     bool                has_support_material() const; | ||||||
|     // Make sure the background processing has no access to this model_object during this call!
 |     // Make sure the background processing has no access to this model_object during this call!
 | ||||||
|  |  | ||||||
|  | @ -1020,7 +1020,8 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ | ||||||
| 	new_full_config.option("filament_settings_id",         true); | 	new_full_config.option("filament_settings_id",         true); | ||||||
| 	new_full_config.option("printer_settings_id",          true); | 	new_full_config.option("printer_settings_id",          true); | ||||||
|     // BBS
 |     // BBS
 | ||||||
|     int used_filaments = this->extruders().size(); |     int used_filaments = this->extruders(true).size(); | ||||||
|  | 
 | ||||||
|     //new_full_config.normalize_fdm(used_filaments);
 |     //new_full_config.normalize_fdm(used_filaments);
 | ||||||
|     new_full_config.normalize_fdm_1(); |     new_full_config.normalize_fdm_1(); | ||||||
|     t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(used_filaments); |     t_config_option_keys changed_keys = new_full_config.normalize_fdm_2(used_filaments); | ||||||
|  | @ -1413,7 +1414,7 @@ Print::ApplyStatus Print::apply(const Model &model, DynamicPrintConfig new_full_ | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     //BBS: check the config again
 |     //BBS: check the config again
 | ||||||
|     int new_used_filaments = this->extruders().size(); |     int new_used_filaments = this->extruders(true).size(); | ||||||
|     t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(new_used_filaments); |     t_config_option_keys new_changed_keys = new_full_config.normalize_fdm_2(new_used_filaments); | ||||||
|     if (new_changed_keys.size() > 0) { |     if (new_changed_keys.size() > 0) { | ||||||
|         BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got new_changed_keys, size=%1%")%new_changed_keys.size(); |         BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(", got new_changed_keys, size=%1%")%new_changed_keys.size(); | ||||||
|  |  | ||||||
|  | @ -2883,7 +2883,7 @@ void PrintConfigDef::init_fff_params() | ||||||
|     //def->sidetext = L("mm");
 |     //def->sidetext = L("mm");
 | ||||||
|     def->mode = comDevelop; |     def->mode = comDevelop; | ||||||
|     // BBS: change data type to floats to add partplate logic
 |     // BBS: change data type to floats to add partplate logic
 | ||||||
|     def->set_default_value(new ConfigOptionFloats{ 240. }); |     def->set_default_value(new ConfigOptionFloats{ 220. }); | ||||||
| 
 | 
 | ||||||
|     def = this->add("prime_tower_width", coFloat); |     def = this->add("prime_tower_width", coFloat); | ||||||
|     def->label = L("Width"); |     def->label = L("Width"); | ||||||
|  |  | ||||||
|  | @ -1149,7 +1149,7 @@ int GLVolumeCollection::load_wipe_tower_preview( | ||||||
|     std::vector<std::array<float, 4>> extruder_colors = get_extruders_colors(); |     std::vector<std::array<float, 4>> extruder_colors = get_extruders_colors(); | ||||||
|     std::vector<std::array<float, 4>> colors; |     std::vector<std::array<float, 4>> colors; | ||||||
|     GUI::PartPlateList& ppl = GUI::wxGetApp().plater()->get_partplate_list(); |     GUI::PartPlateList& ppl = GUI::wxGetApp().plater()->get_partplate_list(); | ||||||
|     std::vector<int> plate_extruders = ppl.get_plate(plate_idx)->get_extruders(); |     std::vector<int> plate_extruders = ppl.get_plate(plate_idx)->get_extruders(true); | ||||||
|     TriangleMesh wipe_tower_shell = make_cube(width, depth, height); |     TriangleMesh wipe_tower_shell = make_cube(width, depth, height); | ||||||
|     for (int extruder_id : plate_extruders) { |     for (int extruder_id : plate_extruders) { | ||||||
|         if (extruder_id <= extruder_colors.size()) |         if (extruder_id <= extruder_colors.size()) | ||||||
|  |  | ||||||
|  | @ -692,6 +692,8 @@ void MainFrame::update_layout() | ||||||
|         { |         { | ||||||
|             // jump to 3deditor under preview_only mode
 |             // jump to 3deditor under preview_only mode
 | ||||||
|             if (evt.GetId() == tp3DEditor){ |             if (evt.GetId() == tp3DEditor){ | ||||||
|  |                 m_plater->update(true); | ||||||
|  | 
 | ||||||
|                 if (!preview_only_hint()) |                 if (!preview_only_hint()) | ||||||
|                     return; |                     return; | ||||||
|             } |             } | ||||||
|  |  | ||||||
|  | @ -1136,7 +1136,7 @@ void PartPlate::release_opengl_resource() | ||||||
| 	} | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| std::vector<int> PartPlate::get_extruders() const | std::vector<int> PartPlate::get_extruders(bool conside_custom_gcode) const | ||||||
| { | { | ||||||
| 	std::vector<int> plate_extruders; | 	std::vector<int> plate_extruders; | ||||||
| 	// if gcode.3mf file
 | 	// if gcode.3mf file
 | ||||||
|  | @ -1192,6 +1192,13 @@ std::vector<int> PartPlate::get_extruders() const | ||||||
| 			plate_extruders.push_back(glb_support_extr); | 			plate_extruders.push_back(glb_support_extr); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (conside_custom_gcode) { | ||||||
|  |         for (auto item : m_model->custom_gcode_per_print_z.gcodes) { | ||||||
|  |         if (item.type == CustomGCode::Type::ToolChange) | ||||||
|  |             plate_extruders.push_back(item.extruder); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
| 	std::sort(plate_extruders.begin(), plate_extruders.end()); | 	std::sort(plate_extruders.begin(), plate_extruders.end()); | ||||||
| 	auto it_end = std::unique(plate_extruders.begin(), plate_extruders.end()); | 	auto it_end = std::unique(plate_extruders.begin(), plate_extruders.end()); | ||||||
| 	plate_extruders.resize(std::distance(plate_extruders.begin(), it_end)); | 	plate_extruders.resize(std::distance(plate_extruders.begin(), it_end)); | ||||||
|  | @ -1223,7 +1230,7 @@ std::vector<int> PartPlate::get_used_extruders() | ||||||
| Vec3d PartPlate::estimate_wipe_tower_size(const double w, const double wipe_volume) const | Vec3d PartPlate::estimate_wipe_tower_size(const double w, const double wipe_volume) const | ||||||
| { | { | ||||||
| 	Vec3d wipe_tower_size; | 	Vec3d wipe_tower_size; | ||||||
| 	std::vector<int> plate_extruders = get_extruders(); | 	std::vector<int> plate_extruders = get_extruders(true); | ||||||
| 	double layer_height = 0.08f; // hard code layer height
 | 	double layer_height = 0.08f; // hard code layer height
 | ||||||
| 	double max_height = 0.f; | 	double max_height = 0.f; | ||||||
| 	wipe_tower_size.setZero(); | 	wipe_tower_size.setZero(); | ||||||
|  |  | ||||||
|  | @ -258,7 +258,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     Vec3d get_origin() { return m_origin; } |     Vec3d get_origin() { return m_origin; } | ||||||
|     Vec3d estimate_wipe_tower_size(const double w, const double wipe_volume) const; |     Vec3d estimate_wipe_tower_size(const double w, const double wipe_volume) const; | ||||||
|     std::vector<int> get_extruders() const; |     std::vector<int> get_extruders(bool conside_custom_gcode = false) const; | ||||||
|     std::vector<int> get_used_extruders(); |     std::vector<int> get_used_extruders(); | ||||||
| 
 | 
 | ||||||
|     /* instance related operations*/ |     /* instance related operations*/ | ||||||
|  |  | ||||||
|  | @ -1659,6 +1659,8 @@ struct Plater::priv | ||||||
|     bool m_is_slicing {false}; |     bool m_is_slicing {false}; | ||||||
|     bool m_is_publishing {false}; |     bool m_is_publishing {false}; | ||||||
|     int m_cur_slice_plate; |     int m_cur_slice_plate; | ||||||
|  | 
 | ||||||
|  |     bool m_need_update{false}; | ||||||
|     //BBS: add popup object table logic
 |     //BBS: add popup object table logic
 | ||||||
|     //ObjectTableDialog* m_popup_table{ nullptr };
 |     //ObjectTableDialog* m_popup_table{ nullptr };
 | ||||||
| 
 | 
 | ||||||
|  | @ -1770,6 +1772,9 @@ struct Plater::priv | ||||||
|     priv(Plater *q, MainFrame *main_frame); |     priv(Plater *q, MainFrame *main_frame); | ||||||
|     ~priv(); |     ~priv(); | ||||||
| 
 | 
 | ||||||
|  |     bool need_update() const { return m_need_update; } | ||||||
|  |     void set_need_update(bool need_update) { m_need_update = need_update; } | ||||||
|  | 
 | ||||||
|     bool is_project_dirty() const { return dirty_state.is_dirty(); } |     bool is_project_dirty() const { return dirty_state.is_dirty(); } | ||||||
|     bool is_presets_dirty() const { return dirty_state.is_presets_dirty(); } |     bool is_presets_dirty() const { return dirty_state.is_presets_dirty(); } | ||||||
|     void update_project_dirty_from_presets() |     void update_project_dirty_from_presets() | ||||||
|  | @ -2401,6 +2406,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) | ||||||
| 
 | 
 | ||||||
|             // update slice and print button
 |             // update slice and print button
 | ||||||
|             wxGetApp().mainframe->update_slice_print_status(MainFrame::SlicePrintEventType::eEventSliceUpdate, true, false); |             wxGetApp().mainframe->update_slice_print_status(MainFrame::SlicePrintEventType::eEventSliceUpdate, true, false); | ||||||
|  |             set_need_update(true); | ||||||
|         }); |         }); | ||||||
|     } |     } | ||||||
|     if (wxGetApp().is_gcode_viewer()) |     if (wxGetApp().is_gcode_viewer()) | ||||||
|  | @ -8628,7 +8634,17 @@ void Plater::add_file() | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void Plater::update() { p->update(); } | void Plater::update(bool conside_update_flag) | ||||||
|  | { | ||||||
|  |     if (conside_update_flag) { | ||||||
|  |         if (need_update()) { | ||||||
|  |             p->update(); | ||||||
|  |             p->set_need_update(false); | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  |     else | ||||||
|  |         p->update(); | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| void Plater::object_list_changed() { p->object_list_changed(); } | void Plater::object_list_changed() { p->object_list_changed(); } | ||||||
| 
 | 
 | ||||||
|  | @ -11353,6 +11369,16 @@ void Plater::bring_instance_forward() | ||||||
|     p->bring_instance_forward(); |     p->bring_instance_forward(); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | bool Plater::need_update() const | ||||||
|  | { | ||||||
|  |     return p->need_update(); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | void Plater::set_need_update(bool need_update) | ||||||
|  | { | ||||||
|  |     p->set_need_update(need_update); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| // BBS
 | // BBS
 | ||||||
| //BBS: add popup logic for table object
 | //BBS: add popup logic for table object
 | ||||||
| bool Plater::PopupObjectTable(int object_id, int volume_id, const wxPoint& position) | bool Plater::PopupObjectTable(int object_id, int volume_id, const wxPoint& position) | ||||||
|  |  | ||||||
|  | @ -256,7 +256,7 @@ public: | ||||||
| 
 | 
 | ||||||
|     const wxString& get_last_loaded_gcode() const { return m_last_loaded_gcode; } |     const wxString& get_last_loaded_gcode() const { return m_last_loaded_gcode; } | ||||||
| 
 | 
 | ||||||
|     void update(); |     void update(bool conside_update_flag = false); | ||||||
|     //BBS
 |     //BBS
 | ||||||
|     void object_list_changed(); |     void object_list_changed(); | ||||||
|     void stop_jobs(); |     void stop_jobs(); | ||||||
|  | @ -558,6 +558,9 @@ public: | ||||||
| 
 | 
 | ||||||
|     void bring_instance_forward(); |     void bring_instance_forward(); | ||||||
| 
 | 
 | ||||||
|  |     bool need_update() const; | ||||||
|  |     void set_need_update(bool need_update); | ||||||
|  | 
 | ||||||
|     // ROII wrapper for suppressing the Undo / Redo snapshot to be taken.
 |     // ROII wrapper for suppressing the Undo / Redo snapshot to be taken.
 | ||||||
| 	class SuppressSnapshots | 	class SuppressSnapshots | ||||||
| 	{ | 	{ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 zhimin.zeng
						zhimin.zeng