OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
Slic3r::GUI::OrientJob Class Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Jobs/OrientJob.hpp>

Inheritance diagram for Slic3r::GUI::OrientJob:
Collaboration diagram for Slic3r::GUI::OrientJob:

Public Types

enum  JobPrepareState { PREPARE_STATE_DEFAULT = 0 , PREPARE_STATE_MENU = 1 }

Public Member Functions

void prepare ()
void process (Ctl &ctl) override
 OrientJob ()
void finalize (bool canceled, std::exception_ptr &e) override

Static Public Member Functions

static orientation::OrientMesh get_orient_mesh (ModelInstance *instance)

Private Types

using OrientMesh = orientation::OrientMesh
using OrientMeshs = orientation::OrientMeshs

Private Member Functions

void clear_input ()
void prepare_selection (std::vector< bool > obj_sel, bool only_one_plate)
void prepare_selected ()
void prepare_partplate ()

Private Attributes

OrientMeshs m_selected
OrientMeshs m_unselected
OrientMeshs m_unprintable
Plater * m_plater

Detailed Description

Member Typedef Documentation

◆ OrientMesh

◆ OrientMeshs

Member Enumeration Documentation

◆ JobPrepareState

Enumerator
PREPARE_STATE_DEFAULT 
PREPARE_STATE_MENU 
22 {
25 };
@ PREPARE_STATE_MENU
Definition Job.hpp:24
@ PREPARE_STATE_DEFAULT
Definition Job.hpp:23

Constructor & Destructor Documentation

◆ OrientJob()

Slic3r::GUI::OrientJob::OrientJob ( )
259: m_plater{wxGetApp().plater()} {}
Plater * m_plater
Definition OrientJob.hpp:24

References m_plater, and Slic3r::GUI::plater().

Here is the call graph for this function:

Member Function Documentation

◆ clear_input()

void Slic3r::GUI::OrientJob::clear_input ( )
private
37{
38 const Model &model = m_plater->model();
39
40 size_t count = 0, cunprint = 0; // To know how much space to reserve
41 for (auto obj : model.objects)
42 for (auto mi : obj->instances)
43 mi->printable ? count++ : cunprint++;
44
45 m_selected.clear();
46 m_unselected.clear();
47 m_unprintable.clear();
48 m_selected.reserve(count);
49 m_unselected.reserve(count);
50 m_unprintable.reserve(cunprint);
51}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
OrientMeshs m_selected
Definition OrientJob.hpp:23
OrientMeshs m_unselected
Definition OrientJob.hpp:23
OrientMeshs m_unprintable
Definition OrientJob.hpp:23

References count, m_plater, m_selected, m_unprintable, m_unselected, and Slic3r::Model::objects.

Referenced by prepare_partplate(), and prepare_selected().

Here is the caller graph for this function:

◆ finalize()

void Slic3r::GUI::OrientJob::finalize ( bool canceled,
std::exception_ptr & e )
overridevirtual

Reimplemented from Slic3r::GUI::Job.

262{
263 try {
264 if (eptr)
265 std::rethrow_exception(eptr);
266 eptr = nullptr;
267 } catch (...) {
268 eptr = std::current_exception();
269 }
270
271 // Ignore the arrange result if aborted.
272 if (canceled || eptr)
273 return;
274
275 for (OrientMesh& mesh : m_selected)
276 {
277 mesh.apply();
278 }
279
280 if (!m_selected.empty()) {
281 Slic3r::LifecycleEventContext ctx;
283 ctx.msg = "auto_oriented";
285 }
286
287 m_plater->update();
288
289 // BBS
290 //wxGetApp().obj_manipul()->set_dirty();
291}
orientation::OrientMesh OrientMesh
Definition OrientJob.hpp:20
std::string msg
Definition LifecycleEvents.hpp:83
@ ObjectTransformed
Definition LifecycleEvents.hpp:38
@ Ok
Definition LifecycleEvents.hpp:68
LifecycleEvtCode code
Definition LifecycleEvents.hpp:79
void fire_lifecycle_event(LifecycleEvent event, const LifecycleEventContext &ctx)
Definition LifecycleEvents.hpp:234

References Slic3r::LifecycleEventContext::code, Slic3r::fire_lifecycle_event(), m_plater, m_selected, Slic3r::LifecycleEventContext::msg, Slic3r::ObjectTransformed, and Slic3r::Ok.

Here is the call graph for this function:

◆ get_orient_mesh()

orientation::OrientMesh Slic3r::GUI::OrientJob::get_orient_mesh ( ModelInstance * instance)
static
294{
295 using OrientMesh = orientation::OrientMesh;
296 OrientMesh om;
297 auto obj = instance->get_object();
298 om.name = obj->name;
299 om.mesh = obj->mesh(); // don't know the difference to obj->raw_mesh(). Both seem OK
300 const Slic3r::DynamicPrintConfig& config = wxGetApp().preset_bundle->full_config();
301 if (obj->config.has("support_threshold_angle"))
302 om.overhang_angle = obj->config.opt_int("support_threshold_angle");
303 else {
304 om.overhang_angle = config.opt_int("support_threshold_angle");
305 }
306
307 if (config.has("fan_direction") && config.has("auxiliary_fan")) {
308 FanDirection config_dir = config.option<ConfigOptionEnum<FanDirection>>("fan_direction")->value;
309 if (config_dir == FanDirection::fdUndefine || !config.opt_bool("auxiliary_fan")) {
310 // no part cooling airflow to face, keep the orientation around the z axis unchanged
311 om.cooling_direction = {0, 0, 0};
312 } else if (config_dir == FanDirection::fdRight) {
313 // the part cooling airflow comes from the right side
314 om.cooling_direction = {1, 0, 0};
315 om.has_cooling_fan = true;
316 } else {
317 // the part cooling airflow comes from the left side, or from both sides
318 om.cooling_direction = {-1, 0, 0};
319 om.has_cooling_fan = true;
320 }
321 }
322
323 om.setter = [instance](const OrientMesh& p) {
324 instance->rotate(p.rotation_matrix);
325 instance->rotate(p.rotation_matrix_vertical);
326 instance->get_object()->invalidate_bounding_box();
327 instance->get_object()->ensure_on_bed();
328 };
329 return om;
330}
ConfigOption * option(const t_config_option_key &opt_key, bool create=false)
Definition Config.hpp:2768
bool has(const t_config_option_key &opt_key) const
Definition Config.hpp:2697
bool opt_bool(const t_config_option_key &opt_key) const
Definition Config.hpp:3072
int & opt_int(const t_config_option_key &opt_key)
Definition Config.hpp:3056
FanDirection
Definition PrintConfig.hpp:531
@ fdUndefine
Definition PrintConfig.hpp:532
@ fdRight
Definition PrintConfig.hpp:534

References Slic3r::orientation::OrientMesh::cooling_direction, Slic3r::ModelObject::ensure_on_bed(), Slic3r::fdRight, Slic3r::fdUndefine, Slic3r::ModelInstance::get_object(), Slic3r::ConfigOptionResolver::has(), Slic3r::orientation::OrientMesh::has_cooling_fan, Slic3r::ModelObject::invalidate_bounding_box(), Slic3r::orientation::OrientMesh::mesh, Slic3r::orientation::OrientMesh::name, Slic3r::DynamicConfig::opt_bool(), Slic3r::DynamicConfig::opt_int(), Slic3r::ConfigBase::option(), Slic3r::orientation::OrientMesh::overhang_angle, Slic3r::ModelInstance::rotate(), and Slic3r::orientation::OrientMesh::setter.

Referenced by prepare_selection().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare()

void Slic3r::GUI::OrientJob::prepare ( )
161{
162 int state = m_plater->get_prepare_state();
163 m_plater->get_notification_manager()->bbl_close_plateinfo_notification();
165 // only_on_partplate = false;
167 }
169 // only_on_partplate = true; // only arrange items on current plate
171 }
172}
void prepare_partplate()
Definition OrientJob.cpp:121
void prepare_selected()
Definition OrientJob.cpp:105

References m_plater, prepare_partplate(), prepare_selected(), Slic3r::GUI::Job::PREPARE_STATE_DEFAULT, and Slic3r::GUI::Job::PREPARE_STATE_MENU.

Referenced by process().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_partplate()

void Slic3r::GUI::OrientJob::prepare_partplate ( )
private
121 {
122 clear_input();
123
124 PartPlateList& plate_list = m_plater->get_partplate_list();
125 PartPlate* plate = plate_list.get_curr_plate();
126 assert(plate != nullptr);
127
128 if (plate->empty())
129 {
130 //no instances on this plate
131 BOOST_LOG_TRIVIAL(info) << __FUNCTION__ << boost::format(": no instances in current plate!");
132
133 return;
134 }
135
136 if (plate->is_locked()) {
137 m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
138 NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("This plate is locked.\nCannot auto-orient on this plate.")));
139 return;
140 }
141
142 Model& model = m_plater->model();
143
144 std::vector<bool> obj_sel(model.objects.size(), false);
145
146 // Go through the objects and check if inside the selection
147 for (size_t oidx = 0; oidx < model.objects.size(); ++oidx)
148 {
149 ModelObject* mo = model.objects[oidx];
150 for (size_t inst_idx = 0; inst_idx < mo->instances.size(); ++inst_idx)
151 {
152 obj_sel[oidx] = plate->contain_instance(oidx, inst_idx);
153 }
154 }
155
156 prepare_selection(obj_sel, true);
157}
#define _L(s)
Definition OBJ.cpp:34
@ WarningNotificationLevel
Definition NotificationManager.hpp:224
void prepare_selection(std::vector< bool > obj_sel, bool only_one_plate)
Definition OrientJob.cpp:54
void clear_input()
Definition OrientJob.cpp:36
@ BBLPlateInfo
Definition NotificationManager.hpp:157
std::string into_u8(const wxString &str)
Definition GUI.cpp:549

References _L, Slic3r::GUI::BBLPlateInfo, clear_input(), Slic3r::GUI::PartPlate::contain_instance(), Slic3r::GUI::PartPlate::empty(), Slic3r::GUI::PartPlateList::get_curr_plate(), Slic3r::ModelObject::instances, Slic3r::GUI::into_u8(), Slic3r::GUI::PartPlate::is_locked(), m_plater, Slic3r::Model::objects, prepare_selection(), and Slic3r::GUI::NotificationManager::WarningNotificationLevel.

Referenced by prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_selected()

void Slic3r::GUI::OrientJob::prepare_selected ( )
private
105 {
106 clear_input();
107
108 Model &model = m_plater->model();
109
110 std::vector<bool> obj_sel(model.objects.size(), false);
111
112 for (auto &s : m_plater->get_selection().get_content())
113 if (s.first < int(obj_sel.size()))
114 obj_sel[size_t(s.first)] = !s.second.empty();
115
116 //BBS: add only one plate mode
117 prepare_selection(obj_sel, false);
118}

References clear_input(), m_plater, Slic3r::Model::objects, and prepare_selection().

Referenced by prepare().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ prepare_selection()

void Slic3r::GUI::OrientJob::prepare_selection ( std::vector< bool > obj_sel,
bool only_one_plate )
private
55{
56 Model& model = m_plater->model();
57 PartPlateList& plate_list = m_plater->get_partplate_list();
58 //OrientMeshs selected_in_lock, unselect_in_lock;
59 bool selected_is_locked = false;
60
61 // Go through the objects and check if inside the selection
62 for (size_t oidx = 0; oidx < obj_sel.size(); ++oidx) {
63 bool selected = obj_sel[oidx];
64 ModelObject* mo = model.objects[oidx];
65
66 for (size_t inst_idx = 0; inst_idx < mo->instances.size(); ++inst_idx)
67 {
68 ModelInstance* mi = mo->instances[inst_idx];
69 OrientMesh&& om = get_orient_mesh(mi);
70
71 bool locked = false;
72 if (!only_one_plate) {
73 int plate_index = plate_list.find_instance(oidx, inst_idx);
74 if ((plate_index >= 0)&&(plate_index < plate_list.get_plate_count())) {
75 if (plate_list.is_locked(plate_index)) {
76 if (selected) {
77 //selected_in_lock.emplace_back(std::move(om));
78 selected_is_locked = true;
79 }
80 //else
81 // unselect_in_lock.emplace_back(std::move(om));
82 continue;
83 }
84 }
85 }
86 auto& cont = mo->printable ? (selected ? m_selected : m_unselected) : m_unprintable;
87
88 cont.emplace_back(std::move(om));
89 }
90 }
91
92 // If the selection was empty orient everything
93 if (m_selected.empty()) {
94 if (!selected_is_locked) {
96 //m_unselected.insert(m_unselected.begin(), unselect_in_lock.begin(), unselect_in_lock.end());
97 }
98 else {
99 m_plater->get_notification_manager()->push_notification(NotificationType::BBLPlateInfo,
100 NotificationManager::NotificationLevel::WarningNotificationLevel, into_u8(_L("All the selected objects are on a locked plate.\nCannot auto-orient these objects.")));
101 }
102 }
103}
static orientation::OrientMesh get_orient_mesh(ModelInstance *instance)
Definition OrientJob.cpp:293

References _L, Slic3r::GUI::BBLPlateInfo, Slic3r::GUI::PartPlateList::find_instance(), get_orient_mesh(), Slic3r::GUI::PartPlateList::get_plate_count(), Slic3r::ModelObject::instances, Slic3r::GUI::into_u8(), Slic3r::GUI::PartPlateList::is_locked(), m_plater, m_selected, m_unprintable, m_unselected, Slic3r::Model::objects, Slic3r::ModelObject::printable, and Slic3r::GUI::NotificationManager::WarningNotificationLevel.

Referenced by prepare_partplate(), and prepare_selected().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ process()

void Slic3r::GUI::OrientJob::process ( Ctl & ctl)
overridevirtual

Implements Slic3r::GUI::Job.

215{
216 static const auto arrangestr = _u8L("Orienting...");
217
218 ctl.update_status(0, arrangestr);
219 ctl.call_on_main_thread([this]{ prepare(); }).wait();;
220
221 auto start = std::chrono::steady_clock::now();
222
223 const GLCanvas3D::OrientSettings& settings = m_plater->canvas3D()->get_orient_settings();
224
225 orientation::OrientParams params;
226 if (settings.min_area) {
228 params.min_volume = false;
229 }
230 else {
231 params.min_volume = true;
232 }
233
234 auto count = unsigned(m_selected.size() + m_unprintable.size());
235 params.stopcondition = [&ctl]() { return ctl.was_canceled(); };
236
237 params.progressind = [this, count, &ctl](unsigned st, std::string orientstr) {
238 st += m_unprintable.size();
239 // TRN Progress status. %1% is the name of the object being oriented.
240 if (st > 0) ctl.update_status(int(st / float(count) * 100), GUI::format(_u8L("Orienting %1%"), orientstr));
241 };
242
244
245 auto time_elapsed = std::chrono::duration_cast<std::chrono::seconds>(std::chrono::steady_clock::now() - start);
246
247 std::stringstream ss;
248 if (!m_selected.empty())
249 ss << std::fixed << std::setprecision(3) << "Orient " << m_selected.back().name << " in " << time_elapsed.count() << " seconds. "
250 << "Orientation: " << m_selected.back().orientation.transpose() << "; v,phi: " << m_selected.back().axis.transpose() << ", " << m_selected.back().angle << "; euler: " << m_selected.back().euler_angles.transpose();
251
252 // finalize just here.
253 ctl.update_status(100,
254 ctl.was_canceled() ? _u8L("Orienting canceled.")
255 : _u8L(ss.str().c_str()));
256 wxGetApp().plater()->show_status_message(ctl.was_canceled() ? "Orienting canceled." : ss.str());
257}
void prepare()
Definition OrientJob.cpp:160
std::string format(const char *fmt, TArgs &&... args)
Definition format.hpp:36
static void setMinimalSupportAreaPrams(Slic3r::orientation::OrientParams &out)
parameters to minimize support area
Definition OrientJob.cpp:175
void orient(OrientMeshs &arrangables, const OrientMeshs &excludes, const OrientParams &params)
Orients the input polygons.
Definition Orient.cpp:613
#define _u8L(s)
Definition I18N.hpp:11

References _u8L, Slic3r::GUI::Job::Ctl::call_on_main_thread(), count, Slic3r::GUI::format(), m_plater, m_selected, m_unprintable, m_unselected, Slic3r::GUI::GLCanvas3D::OrientSettings::min_area, Slic3r::orientation::OrientParams::min_volume, Slic3r::orientation::orient(), prepare(), Slic3r::orientation::OrientParams::progressind, Slic3r::GUI::setMinimalSupportAreaPrams(), Slic3r::orientation::OrientParams::stopcondition, Slic3r::GUI::Job::Ctl::update_status(), and Slic3r::GUI::Job::Ctl::was_canceled().

Here is the call graph for this function:

Member Data Documentation

◆ m_plater

Plater* Slic3r::GUI::OrientJob::m_plater
private

◆ m_selected

OrientMeshs Slic3r::GUI::OrientJob::m_selected
private

◆ m_unprintable

OrientMeshs Slic3r::GUI::OrientJob::m_unprintable
private

◆ m_unselected

OrientMeshs Slic3r::GUI::OrientJob::m_unselected
private

The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Jobs/OrientJob.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/Jobs/OrientJob.cpp