diff --git a/src/libslic3r/SLAPrint.cpp b/src/libslic3r/SLAPrint.cpp index 0c61b591bb..96b304ac21 100644 --- a/src/libslic3r/SLAPrint.cpp +++ b/src/libslic3r/SLAPrint.cpp @@ -420,6 +420,12 @@ void swapXY(ExPolygon& expoly) { } +template +void report_status(SLAPrint& p, int st, const std::string& msg, Args&&...args) { + BOOST_LOG_TRIVIAL(info) << st << "% " << msg; + p.set_status(st, msg, std::forward(args)...); +} + void SLAPrint::process() { using namespace sla; @@ -524,9 +530,11 @@ void SLAPrint::process() // scaling for the sub operations double d = *stthis / (objcount * 100.0); - ctl.statuscb = [this, init, d](unsigned st, const std::string& msg){ - set_status(int(init + st*d), msg); + ctl.statuscb = [this, init, d](unsigned st, const std::string& msg) + { + report_status(*this, int(init + st*d), msg); }; + ctl.stopcondition = [this](){ return canceled(); }; ctl.cancelfn = [this]() { throw_if_canceled(); }; @@ -536,9 +544,9 @@ void SLAPrint::process() // Create the unified mesh auto rc = SlicingStatus::RELOAD_SCENE; - set_status(-1, L("Visualizing supports")); + report_status(*this, -1, L("Visualizing supports")); po.m_supportdata->support_tree_ptr->merged_mesh(); - set_status(-1, L("Visualizing supports"), rc); + report_status(*this, -1, L("Visualizing supports"), rc); } catch(sla::SLASupportsStoppedException&) { // no need to rethrow // throw_if_canceled(); @@ -581,7 +589,7 @@ void SLAPrint::process() po.throw_if_canceled(); auto rc = SlicingStatus::RELOAD_SCENE; - set_status(-1, L("Visualizing supports"), rc); + report_status(*this, -1, L("Visualizing supports"), rc); }; // Slicing the support geometries similarly to the model slicing procedure. @@ -740,8 +748,12 @@ void SLAPrint::process() auto lvlcnt = unsigned(m_printer_input.size()); printer.layers(lvlcnt); + // slot is the portion of 100% that is realted to rasterization unsigned slot = PRINT_STEP_LEVELS[slapsRasterize]; + // ist: initial state; pst: previous state unsigned ist = max_objstatus, pst = ist; + // coefficient to map the rasterization state (0-99) to the allocated + // portion (slot) of the process state double sd = (100 - ist) / 100.0; SpinMutex slck; @@ -778,11 +790,11 @@ void SLAPrint::process() // Finish the layer for later saving it. printer.finish_layer(level_id); - // Status indication + // Status indication guarded with the spinlock auto st = ist + unsigned(sd*level_id*slot/m_printer_input.size()); { std::lock_guard lck(slck); if( st > pst) { - set_status(int(st), PRINT_STEP_LABELS[slapsRasterize]); + report_status(*this, int(st), PRINT_STEP_LABELS[slapsRasterize]); pst = st; } } @@ -832,9 +844,14 @@ void SLAPrint::process() unsigned st = min_objstatus; unsigned incr = 0; + BOOST_LOG_TRIVIAL(info) << "Start slicing process."; + // TODO: this loop could run in parallel but should not exhaust all the CPU // power available for(SLAPrintObject * po : m_objects) { + + BOOST_LOG_TRIVIAL(info) << "Slicing object " << po->model_object()->name; + for(size_t s = 0; s < objectsteps.size(); ++s) { auto currentstep = objectsteps[s]; @@ -846,8 +863,7 @@ void SLAPrint::process() st += unsigned(incr * ostepd); if(po->m_stepmask[currentstep] && po->set_started(currentstep)) { - - set_status(int(st), OBJ_STEP_LABELS[currentstep]); + report_status(*this, int(st), OBJ_STEP_LABELS[currentstep]); pobj_program[currentstep](*po); po->set_done(currentstep); } @@ -872,7 +888,7 @@ void SLAPrint::process() if(m_stepmask[currentstep] && set_started(currentstep)) { - set_status(int(st), PRINT_STEP_LABELS[currentstep]); + report_status(*this, int(st), PRINT_STEP_LABELS[currentstep]); print_program[currentstep](); set_done(currentstep); } @@ -881,7 +897,7 @@ void SLAPrint::process() } // If everything vent well - set_status(100, L("Slicing done")); + report_status(*this, 100, L("Slicing done")); } bool SLAPrint::invalidate_state_by_config_options(const std::vector &opt_keys) diff --git a/src/slic3r/GUI/GUI_ObjectList.cpp b/src/slic3r/GUI/GUI_ObjectList.cpp index a90dff621a..a7f1ca608c 100644 --- a/src/slic3r/GUI/GUI_ObjectList.cpp +++ b/src/slic3r/GUI/GUI_ObjectList.cpp @@ -1460,9 +1460,12 @@ void ObjectList::update_selections() select_items(sels); if (GetSelection()) { - const wxRect& top_rc = GetItemRect(GetTopItem()); const wxRect& sel_rc = GetItemRect(GetSelection()); - ScrollLines(int((sel_rc.y - top_rc.y) / top_rc.GetHeight()) - 0.5*GetCountPerPage()); + if (!sel_rc.IsEmpty()) { + const int rc_h = sel_rc.height; + const int displ = GetMainWindow()->GetClientRect().GetHeight()/(2*rc_h)+1; + ScrollLines(int(sel_rc.y / rc_h - displ)); + } } } @@ -1654,7 +1657,9 @@ void ObjectList::change_part_type() void ObjectList::last_volume_is_deleted(const int obj_idx) { - if (obj_idx < 0 || (*m_objects).empty() || (*m_objects)[obj_idx]->volumes.empty()) + if (obj_idx < 0 || m_objects->empty() || + obj_idx <= m_objects->size() || + (*m_objects)[obj_idx]->volumes.empty()) return; auto volume = (*m_objects)[obj_idx]->volumes[0]; diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index 2e5a37040b..710710913f 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -1228,6 +1228,14 @@ void PrusaObjectDataViewModel::SetVolumeType(const wxDataViewItem &item, const i ItemChanged(item); } +PrusaBitmapTextRenderer::PrusaBitmapTextRenderer(wxDataViewCellMode mode /*= wxDATAVIEW_CELL_EDITABLE*/, + int align /*= wxDVR_DEFAULT_ALIGNMENT*/): +wxDataViewRenderer(wxT("PrusaDataViewBitmapText"), mode, align) +{ + SetMode(mode); + SetAlignment(align); +} + //----------------------------------------------------------------------------- // PrusaDataViewBitmapText //----------------------------------------------------------------------------- @@ -1251,6 +1259,13 @@ bool PrusaBitmapTextRenderer::GetValue(wxVariant& WXUNUSED(value)) const return false; } +#if wxUSE_ACCESSIBILITY +wxString PrusaBitmapTextRenderer::GetAccessibleDescription() const +{ + return m_value.GetText(); +} +#endif // wxUSE_ACCESSIBILITY + bool PrusaBitmapTextRenderer::Render(wxRect rect, wxDC *dc, int state) { int xoffset = 0; @@ -1291,12 +1306,12 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab PrusaDataViewBitmapText data; data << value; - m_bmp_from_editing_item = data.GetBitmap(); + m_was_unusable_symbol = false; wxPoint position = labelRect.GetPosition(); - if (m_bmp_from_editing_item.IsOk()) { - const int bmp_width = m_bmp_from_editing_item.GetWidth(); + if (data.GetBitmap().IsOk()) { + const int bmp_width = data.GetBitmap().GetWidth(); position.x += bmp_width; labelRect.SetWidth(labelRect.GetWidth() - bmp_width); } @@ -1304,6 +1319,7 @@ wxWindow* PrusaBitmapTextRenderer::CreateEditorCtrl(wxWindow* parent, wxRect lab wxTextCtrl* text_editor = new wxTextCtrl(parent, wxID_ANY, data.GetText(), position, labelRect.GetSize(), wxTE_PROCESS_ENTER); text_editor->SetInsertionPointEnd(); + text_editor->SelectAll(); return text_editor; } @@ -1323,7 +1339,17 @@ bool PrusaBitmapTextRenderer::GetValueFromEditorCtrl(wxWindow* ctrl, wxVariant& } } - value << PrusaDataViewBitmapText(text_editor->GetValue(), m_bmp_from_editing_item); + // The icon can't be edited so get its old value and reuse it. + wxVariant valueOld; + GetView()->GetModel()->GetValue(valueOld, m_item, 0); + + PrusaDataViewBitmapText bmpText; + bmpText << valueOld; + + // But replace the text with the value entered by user. + bmpText.SetText(text_editor->GetValue()); + + value << bmpText; return true; } diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 3fbf9a0839..e3fd1cbf6f 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -519,15 +519,18 @@ public: // PrusaBitmapTextRenderer // ---------------------------------------------------------------------------- -class PrusaBitmapTextRenderer : public wxDataViewCustomRenderer +class PrusaBitmapTextRenderer : public wxDataViewRenderer//CustomRenderer { public: - PrusaBitmapTextRenderer( wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, - int align = wxDVR_DEFAULT_ALIGNMENT): - wxDataViewCustomRenderer(wxT("PrusaDataViewBitmapText"), mode, align) {} + PrusaBitmapTextRenderer(wxDataViewCellMode mode = wxDATAVIEW_CELL_EDITABLE, + int align = wxDVR_DEFAULT_ALIGNMENT);//: +// wxDataViewRenderer/*CustomRenderer*/(wxT("PrusaDataViewBitmapText"), mode, align) {} bool SetValue(const wxVariant &value); bool GetValue(wxVariant &value) const; +#if wxUSE_ACCESSIBILITY + virtual wxString GetAccessibleDescription() const override; +#endif // wxUSE_ACCESSIBILITY virtual bool Render(wxRect cell, wxDC *dc, int state); virtual wxSize GetSize() const; @@ -542,8 +545,7 @@ public: private: PrusaDataViewBitmapText m_value; - wxBitmap m_bmp_from_editing_item; - bool m_was_unusable_symbol; + bool m_was_unusable_symbol {false}; };