mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-19 14:51:11 -06:00
fix
This commit is contained in:
parent
476c05a764
commit
e6fcbfae07
1073 changed files with 8562 additions and 629353 deletions
|
@ -1,107 +0,0 @@
|
|||
#include "ButtonsDescription.hpp"
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/statbmp.h>
|
||||
#include <wx/clrpicker.h>
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
void ButtonsDescription::FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour)
|
||||
{
|
||||
wxFlexGridSizer* grid_sizer = new wxFlexGridSizer(3, 5, 5);
|
||||
sizer->Add(grid_sizer, 0, wxEXPAND);
|
||||
|
||||
ScalableBitmap bmp_delete = ScalableBitmap(parent, "cross");
|
||||
ScalableBitmap bmp_delete_focus = ScalableBitmap(parent, "cross_focus");
|
||||
|
||||
auto add_color = [grid_sizer, parent](wxColourPickerCtrl** color_picker, const wxColour& color, const wxColour& def_color, wxString label_text) {
|
||||
// wrap the label_text to the max 80 characters
|
||||
if (label_text.Len() > 80) {
|
||||
size_t brack_pos = label_text.find_last_of(" ", 79);
|
||||
if (brack_pos > 0 && brack_pos < 80)
|
||||
label_text.insert(brack_pos + 1, "\n");
|
||||
}
|
||||
|
||||
auto sys_label = new wxStaticText(parent, wxID_ANY, label_text);
|
||||
sys_label->SetForegroundColour(color);
|
||||
|
||||
*color_picker = new wxColourPickerCtrl(parent, wxID_ANY, color);
|
||||
wxGetApp().UpdateDarkUI((*color_picker)->GetPickerCtrl(), true);
|
||||
(*color_picker)->Bind(wxEVT_COLOURPICKER_CHANGED, [color_picker, sys_label](wxCommandEvent&) {
|
||||
sys_label->SetForegroundColour((*color_picker)->GetColour());
|
||||
sys_label->Refresh();
|
||||
});
|
||||
|
||||
auto btn = new ScalableButton(parent, wxID_ANY, "undo");
|
||||
btn->SetToolTip(_L("Revert color to default"));
|
||||
btn->Bind(wxEVT_BUTTON, [sys_label, color_picker, def_color](wxEvent& event) {
|
||||
(*color_picker)->SetColour(def_color);
|
||||
sys_label->SetForegroundColour(def_color);
|
||||
sys_label->Refresh();
|
||||
});
|
||||
parent->Bind(wxEVT_UPDATE_UI, [color_picker, def_color](wxUpdateUIEvent& evt) {
|
||||
evt.Enable((*color_picker)->GetColour() != def_color);
|
||||
}, btn->GetId());
|
||||
|
||||
grid_sizer->Add(*color_picker, 0, wxALIGN_CENTRE_VERTICAL);
|
||||
grid_sizer->Add(btn, 0, wxALIGN_CENTRE_VERTICAL);
|
||||
grid_sizer->Add(sys_label, 0, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
|
||||
};
|
||||
|
||||
add_color(sys_colour, wxGetApp().get_label_clr_sys(), wxGetApp().get_label_default_clr_system(), _L("Value is the same as the system value"));
|
||||
add_color(mod_colour, wxGetApp().get_label_clr_modified(),wxGetApp().get_label_default_clr_modified(), _L("Value was changed and is not equal to the system value or the last saved preset"));
|
||||
}
|
||||
|
||||
ButtonsDescription::ButtonsDescription(wxWindow* parent, const std::vector<Entry> &entries) :
|
||||
wxDialog(parent, wxID_ANY, _(L("Buttons And Text Colors Description")), wxDefaultPosition, wxDefaultSize),
|
||||
m_entries(entries)
|
||||
{
|
||||
wxGetApp().UpdateDarkUI(this);
|
||||
|
||||
auto grid_sizer = new wxFlexGridSizer(3, 20, 20);
|
||||
|
||||
auto main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
main_sizer->Add(grid_sizer, 0, wxEXPAND | wxALL, 20);
|
||||
|
||||
// Icon description
|
||||
for (const Entry &entry : m_entries)
|
||||
{
|
||||
auto icon = new wxStaticBitmap(this, wxID_ANY, entry.bitmap->bmp());
|
||||
grid_sizer->Add(icon, -1, wxALIGN_CENTRE_VERTICAL);
|
||||
auto description = new wxStaticText(this, wxID_ANY, _(entry.symbol));
|
||||
grid_sizer->Add(description, -1, wxALIGN_CENTRE_VERTICAL);
|
||||
description = new wxStaticText(this, wxID_ANY, _(entry.explanation));
|
||||
grid_sizer->Add(description, -1, wxALIGN_CENTRE_VERTICAL | wxEXPAND);
|
||||
}
|
||||
|
||||
// Text color description
|
||||
wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
|
||||
FillSizerWithTextColorDescriptions(sizer, this, &sys_colour, &mod_colour);
|
||||
main_sizer->Add(sizer, 0, wxEXPAND | wxALL, 20);
|
||||
|
||||
auto buttons = CreateStdDialogButtonSizer(wxOK|wxCANCEL);
|
||||
main_sizer->Add(buttons, 0, wxALIGN_CENTER_HORIZONTAL | wxBOTTOM, 10);
|
||||
|
||||
wxButton* btn = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
|
||||
btn->Bind(wxEVT_BUTTON, [this](wxCommandEvent&) {
|
||||
wxGetApp().set_label_clr_sys(sys_colour->GetColour());
|
||||
wxGetApp().set_label_clr_modified(mod_colour->GetColour());
|
||||
EndModal(wxID_OK);
|
||||
});
|
||||
|
||||
wxGetApp().UpdateDarkUI(btn);
|
||||
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(FindWindowById(wxID_CANCEL, this)));
|
||||
|
||||
SetSizer(main_sizer);
|
||||
main_sizer->SetSizeHints(this);
|
||||
}
|
||||
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef slic3r_ButtonsDescription_hpp
|
||||
#define slic3r_ButtonsDescription_hpp
|
||||
|
||||
#include <wx/dialog.h>
|
||||
#include <vector>
|
||||
|
||||
class ScalableBitmap;
|
||||
class wxColourPickerCtrl;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
class ButtonsDescription : public wxDialog
|
||||
{
|
||||
wxColourPickerCtrl* sys_colour{ nullptr };
|
||||
wxColourPickerCtrl* mod_colour{ nullptr };
|
||||
public:
|
||||
struct Entry {
|
||||
Entry(ScalableBitmap *bitmap, const std::string &symbol, const std::string &explanation) : bitmap(bitmap), symbol(symbol), explanation(explanation) {}
|
||||
|
||||
ScalableBitmap *bitmap;
|
||||
std::string symbol;
|
||||
std::string explanation;
|
||||
};
|
||||
|
||||
ButtonsDescription(wxWindow* parent, const std::vector<Entry> &entries);
|
||||
~ButtonsDescription() {}
|
||||
|
||||
static void FillSizerWithTextColorDescriptions(wxSizer* sizer, wxWindow* parent, wxColourPickerCtrl** sys_colour, wxColourPickerCtrl** mod_colour);
|
||||
|
||||
private:
|
||||
std::vector<Entry> m_entries;
|
||||
};
|
||||
|
||||
} // GUI
|
||||
} // Slic3r
|
||||
|
||||
|
||||
#endif
|
||||
|
|
@ -1,199 +0,0 @@
|
|||
#include "ConfigSnapshotDialog.hpp"
|
||||
#include "I18N.hpp"
|
||||
|
||||
#include "../Config/Snapshot.hpp"
|
||||
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/Time.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
static wxString format_reason(const Config::Snapshot::Reason reason)
|
||||
{
|
||||
switch (reason) {
|
||||
case Config::Snapshot::SNAPSHOT_UPGRADE:
|
||||
return wxString(_(L("Upgrade")));
|
||||
case Config::Snapshot::SNAPSHOT_DOWNGRADE:
|
||||
return wxString(_(L("Downgrade")));
|
||||
case Config::Snapshot::SNAPSHOT_BEFORE_ROLLBACK:
|
||||
return wxString(_(L("Before roll back")));
|
||||
case Config::Snapshot::SNAPSHOT_USER:
|
||||
return wxString(_(L("User")));
|
||||
case Config::Snapshot::SNAPSHOT_UNKNOWN:
|
||||
default:
|
||||
return wxString(_(L("Unknown")));
|
||||
}
|
||||
}
|
||||
|
||||
static std::string get_color(wxColour colour)
|
||||
{
|
||||
wxString clr_str = wxString::Format(wxT("#%02X%02X%02X"), colour.Red(), colour.Green(), colour.Blue());
|
||||
return clr_str.ToStdString();
|
||||
};
|
||||
|
||||
|
||||
static wxString generate_html_row(const Config::Snapshot &snapshot, bool row_even, bool snapshot_active, bool dark_mode)
|
||||
{
|
||||
// Start by declaring a row with an alternating background color.
|
||||
wxString text = "<tr bgcolor=\"";
|
||||
text += snapshot_active ?
|
||||
dark_mode ? "#208a20" : "#B3FFCB" :
|
||||
(row_even ? get_color(wxGetApp().get_window_default_clr()/*wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)*/) : dark_mode ? "#656565" : "#D5D5D5" );
|
||||
text += "\">";
|
||||
text += "<td>";
|
||||
|
||||
static const constexpr char *LOCALE_TIME_FMT = "%x %X";
|
||||
wxString datetime = wxDateTime(snapshot.time_captured).Format(LOCALE_TIME_FMT);
|
||||
|
||||
// Format the row header.
|
||||
text += wxString("<font size=\"5\"><b>") + (snapshot_active ? _(L("Active")) + ": " : "") +
|
||||
datetime + ": " + format_reason(snapshot.reason);
|
||||
|
||||
if (! snapshot.comment.empty())
|
||||
text += " (" + wxString::FromUTF8(snapshot.comment.data()) + ")";
|
||||
text += "</b></font><br>";
|
||||
// End of row header.
|
||||
text += _(L("PrusaSlicer version")) + ": " + snapshot.slic3r_version_captured.to_string() + "<br>";
|
||||
bool has_fff = ! snapshot.print.empty() || ! snapshot.filaments.empty();
|
||||
bool has_sla = ! snapshot.sla_print.empty() || ! snapshot.sla_material.empty();
|
||||
if (has_fff || ! has_sla) {
|
||||
text += _(L("print")) + ": " + snapshot.print + "<br>";
|
||||
text += _(L("filaments")) + ": " + snapshot.filaments.front() + "<br>";
|
||||
}
|
||||
if (has_sla) {
|
||||
text += _(L("SLA print")) + ": " + snapshot.sla_print + "<br>";
|
||||
text += _(L("SLA material")) + ": " + snapshot.sla_material + "<br>";
|
||||
}
|
||||
text += _(L("printer")) + ": " + (snapshot.physical_printer.empty() ? snapshot.printer : snapshot.physical_printer) + "<br>";
|
||||
|
||||
bool compatible = true;
|
||||
for (const Config::Snapshot::VendorConfig &vc : snapshot.vendor_configs) {
|
||||
text += _(L("vendor")) + ": " + vc.name +", " + _(L("version")) + ": " + vc.version.config_version.to_string() +
|
||||
", " + _(L("min PrusaSlicer version")) + ": " + vc.version.min_slic3r_version.to_string();
|
||||
if (vc.version.max_slic3r_version != Semver::inf())
|
||||
text += ", " + _(L("max PrusaSlicer version")) + ": " + vc.version.max_slic3r_version.to_string();
|
||||
text += "<br>";
|
||||
for (const auto& model : vc.models_variants_installed) {
|
||||
text += _(L("model")) + ": " + model.first + ", " + _(L("variants")) + ": ";
|
||||
for (const std::string &variant : model.second) {
|
||||
if (&variant != &*model.second.begin())
|
||||
text += ", ";
|
||||
text += variant;
|
||||
}
|
||||
text += "<br>";
|
||||
}
|
||||
if (! vc.version.is_current_slic3r_supported()) { compatible = false; }
|
||||
}
|
||||
|
||||
if (! compatible) {
|
||||
text += "<p align=\"right\">" + from_u8((boost::format(_utf8(L("Incompatible with this %s"))) % SLIC3R_APP_NAME).str()) + "</p>";
|
||||
}
|
||||
else if (! snapshot_active)
|
||||
text += "<p align=\"right\"><a href=\"" + snapshot.id + "\">" + _(L("Activate")) + "</a></p>";
|
||||
text += "</td>";
|
||||
text += "</tr>";
|
||||
return text;
|
||||
}
|
||||
|
||||
static wxString generate_html_page(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot)
|
||||
{
|
||||
bool dark_mode = wxGetApp().dark_mode();
|
||||
wxString text =
|
||||
"<html>"
|
||||
"<body bgcolor=\"" + get_color(wxGetApp().get_window_default_clr()/*wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)*/) + "\" cellspacing=\"2\" cellpadding=\"0\" border=\"0\" link=\"#800000\">"
|
||||
"<font color=\"" + get_color(wxGetApp().get_label_clr_default()/*wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)*/) + "\">";
|
||||
text += "<table style=\"width:100%\">";
|
||||
for (size_t i_row = 0; i_row < snapshot_db.snapshots().size(); ++ i_row) {
|
||||
const Config::Snapshot &snapshot = snapshot_db.snapshots()[snapshot_db.snapshots().size() - i_row - 1];
|
||||
text += generate_html_row(snapshot, i_row & 1, snapshot.id == on_snapshot, dark_mode);
|
||||
}
|
||||
text +=
|
||||
"</table>"
|
||||
"</font>"
|
||||
"</body>"
|
||||
"</html>";
|
||||
return text;
|
||||
}
|
||||
|
||||
ConfigSnapshotDialog::ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db, const wxString &on_snapshot)
|
||||
: DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, _(L("Configuration Snapshots")), wxDefaultPosition,
|
||||
wxSize(45 * wxGetApp().em_unit(), 40 * wxGetApp().em_unit()),
|
||||
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX)
|
||||
{
|
||||
this->SetFont(wxGetApp().normal_font());
|
||||
#ifdef _WIN32
|
||||
wxGetApp().UpdateDarkUI(this);
|
||||
#else
|
||||
this->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
#endif
|
||||
|
||||
wxBoxSizer* vsizer = new wxBoxSizer(wxVERTICAL);
|
||||
this->SetSizer(vsizer);
|
||||
|
||||
// text
|
||||
html = new wxHtmlWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO);
|
||||
{
|
||||
wxFont font = get_default_font(this);
|
||||
#ifdef __WXMSW__
|
||||
const int fs = font.GetPointSize();
|
||||
const int fs1 = static_cast<int>(0.8f*fs);
|
||||
const int fs2 = static_cast<int>(1.1f*fs);
|
||||
int size[] = {fs1, fs1, fs1, fs1, fs2, fs2, fs2};
|
||||
// int size[] = {8,8,8,8,11,11,11};
|
||||
#else
|
||||
int size[] = {11,11,11,11,14,14,14};
|
||||
#endif
|
||||
html->SetFonts(font.GetFaceName(), font.GetFaceName(), size);
|
||||
html->SetBorders(2);
|
||||
wxString text = generate_html_page(snapshot_db, on_snapshot);
|
||||
html->SetPage(text);
|
||||
vsizer->Add(html, 1, wxEXPAND | wxALIGN_LEFT | wxRIGHT | wxBOTTOM, 0);
|
||||
html->Bind(wxEVT_HTML_LINK_CLICKED, &ConfigSnapshotDialog::onLinkClicked, this);
|
||||
}
|
||||
|
||||
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxCLOSE);
|
||||
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(this->FindWindowById(wxID_CLOSE, this)));
|
||||
this->SetEscapeId(wxID_CLOSE);
|
||||
this->Bind(wxEVT_BUTTON, &ConfigSnapshotDialog::onCloseDialog, this, wxID_CLOSE);
|
||||
vsizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, 3);
|
||||
}
|
||||
|
||||
void ConfigSnapshotDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
{
|
||||
wxFont font = get_default_font(this);
|
||||
const int fs = font.GetPointSize();
|
||||
const int fs1 = static_cast<int>(0.8f*fs);
|
||||
const int fs2 = static_cast<int>(1.1f*fs);
|
||||
int font_size[] = { fs1, fs1, fs1, fs1, fs2, fs2, fs2 };
|
||||
|
||||
html->SetFonts(font.GetFaceName(), font.GetFaceName(), font_size);
|
||||
html->Refresh();
|
||||
|
||||
const int& em = em_unit();
|
||||
|
||||
msw_buttons_rescale(this, em, { wxID_CLOSE});
|
||||
|
||||
const wxSize& size = wxSize(45 * em, 40 * em);
|
||||
SetMinSize(size);
|
||||
Fit();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void ConfigSnapshotDialog::onLinkClicked(wxHtmlLinkEvent &event)
|
||||
{
|
||||
m_snapshot_to_activate = event.GetLinkInfo().GetHref().ToUTF8();
|
||||
this->EndModal(wxID_CLOSE);
|
||||
}
|
||||
|
||||
void ConfigSnapshotDialog::onCloseDialog(wxEvent &)
|
||||
{
|
||||
this->EndModal(wxID_CLOSE);
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef slic3r_GUI_ConfigSnapshotDialog_hpp_
|
||||
#define slic3r_GUI_ConfigSnapshotDialog_hpp_
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_Utils.hpp"
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/intl.h>
|
||||
#include <wx/html/htmlwin.h>
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
namespace Config {
|
||||
class SnapshotDB;
|
||||
}
|
||||
|
||||
class ConfigSnapshotDialog : public DPIDialog
|
||||
{
|
||||
public:
|
||||
ConfigSnapshotDialog(const Config::SnapshotDB &snapshot_db, const wxString &id);
|
||||
const std::string& snapshot_to_activate() const { return m_snapshot_to_activate; }
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||
|
||||
private:
|
||||
void onLinkClicked(wxHtmlLinkEvent &event);
|
||||
void onCloseDialog(wxEvent &);
|
||||
|
||||
// If set, it contains a snapshot ID to be restored after the dialog closes.
|
||||
std::string m_snapshot_to_activate;
|
||||
|
||||
wxHtmlWindow* html;
|
||||
};
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif /* slic3r_GUI_ConfigSnapshotDialog_hpp_ */
|
File diff suppressed because it is too large
Load diff
|
@ -1,465 +0,0 @@
|
|||
#ifndef slic3r_GUI_DoubleSlider_hpp_
|
||||
#define slic3r_GUI_DoubleSlider_hpp_
|
||||
|
||||
#include "libslic3r/CustomGCode.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
#include "DoubleSlider_Utils.hpp"
|
||||
|
||||
#include <wx/window.h>
|
||||
#include <wx/control.h>
|
||||
#include <wx/dc.h>
|
||||
#include <wx/slider.h>
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
|
||||
class wxMenu;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
using namespace CustomGCode;
|
||||
class PrintObject;
|
||||
class Layer;
|
||||
|
||||
namespace DoubleSlider {
|
||||
|
||||
/* For exporting GCode in GCodeWriter is used XYZF_NUM(val) = PRECISION(val, 3) for XYZ values.
|
||||
* So, let use same value as a permissible error for layer height.
|
||||
*/
|
||||
constexpr double epsilon() { return 0.0011; }
|
||||
|
||||
// return true when areas are mostly equivalent
|
||||
bool equivalent_areas(const double& bottom_area, const double& top_area);
|
||||
|
||||
// return true if color change was detected
|
||||
bool check_color_change(PrintObject* object, size_t frst_layer_id, size_t layers_cnt, bool check_overhangs,
|
||||
// what to do with detected color change
|
||||
// and return true when detection have to be desturbed
|
||||
std::function<bool(Layer*)> break_condition);
|
||||
|
||||
// custom message the slider sends to its parent to notify a tick-change:
|
||||
wxDECLARE_EVENT(wxCUSTOMEVT_TICKSCHANGED, wxEvent);
|
||||
|
||||
enum SelectedSlider {
|
||||
ssUndef,
|
||||
ssLower,
|
||||
ssHigher
|
||||
};
|
||||
|
||||
enum FocusedItem {
|
||||
fiNone,
|
||||
fiRevertIcon,
|
||||
fiOneLayerIcon,
|
||||
fiCogIcon,
|
||||
fiColorBand,
|
||||
fiActionIcon,
|
||||
fiLowerThumb,
|
||||
fiHigherThumb,
|
||||
fiSmartWipeTower,
|
||||
fiTick
|
||||
};
|
||||
|
||||
enum ConflictType
|
||||
{
|
||||
ctNone,
|
||||
ctModeConflict,
|
||||
ctMeaninglessColorChange,
|
||||
ctMeaninglessToolChange,
|
||||
ctRedundant
|
||||
};
|
||||
|
||||
enum MouseAction
|
||||
{
|
||||
maNone,
|
||||
maAddMenu, // show "Add" context menu for NOTexist active tick
|
||||
maEditMenu, // show "Edit" context menu for exist active tick
|
||||
maCogIconMenu, // show context for "cog" icon
|
||||
maForceColorEdit, // force color editing from colored band
|
||||
maAddTick, // force tick adding
|
||||
maDeleteTick, // force tick deleting
|
||||
maCogIconClick, // LeftMouseClick on "cog" icon
|
||||
maOneLayerIconClick, // LeftMouseClick on "one_layer" icon
|
||||
maRevertIconClick, // LeftMouseClick on "revert" icon
|
||||
};
|
||||
|
||||
enum DrawMode
|
||||
{
|
||||
dmRegular,
|
||||
dmSlaPrint,
|
||||
dmSequentialFffPrint,
|
||||
dmSequentialGCodeView,
|
||||
};
|
||||
|
||||
enum LabelType
|
||||
{
|
||||
ltHeightWithLayer,
|
||||
ltHeight,
|
||||
ltEstimatedTime,
|
||||
};
|
||||
|
||||
struct TickCode
|
||||
{
|
||||
bool operator<(const TickCode& other) const { return other.tick > this->tick; }
|
||||
bool operator>(const TickCode& other) const { return other.tick < this->tick; }
|
||||
|
||||
int tick = 0;
|
||||
Type type = ColorChange;
|
||||
int extruder = 0;
|
||||
std::string color;
|
||||
std::string extra;
|
||||
};
|
||||
|
||||
class TickCodeInfo
|
||||
{
|
||||
std::string custom_gcode;
|
||||
std::string pause_print_msg;
|
||||
bool m_suppress_plus = false;
|
||||
bool m_suppress_minus = false;
|
||||
bool m_use_default_colors= false;
|
||||
// int m_default_color_idx = 0;
|
||||
|
||||
std::vector<std::string>* m_colors {nullptr};
|
||||
ColorGenerator color_generator;
|
||||
|
||||
std::string get_color_for_tick(TickCode tick, Type type, const int extruder);
|
||||
|
||||
public:
|
||||
std::set<TickCode> ticks {};
|
||||
Mode mode = Undef;
|
||||
|
||||
bool empty() const { return ticks.empty(); }
|
||||
void set_pause_print_msg(const std::string& message) { pause_print_msg = message; }
|
||||
|
||||
bool add_tick(const int tick, Type type, int extruder, double print_z);
|
||||
bool edit_tick(std::set<TickCode>::iterator it, double print_z);
|
||||
void switch_code(Type type_from, Type type_to);
|
||||
bool switch_code_for_tick(std::set<TickCode>::iterator it, Type type_to, const int extruder);
|
||||
void erase_all_ticks_with_code(Type type);
|
||||
|
||||
bool has_tick_with_code(Type type);
|
||||
bool has_tick(int tick);
|
||||
ConflictType is_conflict_tick(const TickCode& tick, Mode out_mode, int only_extruder, double print_z);
|
||||
|
||||
// Get used extruders for tick.
|
||||
// Means all extruders(tools) which will be used during printing from current tick to the end
|
||||
std::set<int> get_used_extruders_for_tick(int tick, int only_extruder, double print_z, Mode force_mode = Undef) const;
|
||||
|
||||
void suppress_plus (bool suppress) { m_suppress_plus = suppress; }
|
||||
void suppress_minus(bool suppress) { m_suppress_minus = suppress; }
|
||||
bool suppressed_plus () { return m_suppress_plus; }
|
||||
bool suppressed_minus() { return m_suppress_minus; }
|
||||
void set_default_colors(bool default_colors_on) { m_use_default_colors = default_colors_on; }
|
||||
|
||||
void set_extruder_colors(std::vector<std::string>* extruder_colors) { m_colors = extruder_colors; }
|
||||
};
|
||||
|
||||
|
||||
struct ExtrudersSequence
|
||||
{
|
||||
bool is_mm_intervals = true;
|
||||
double interval_by_mm = 3.0;
|
||||
int interval_by_layers = 10;
|
||||
bool random_sequence { false };
|
||||
bool color_repetition { false };
|
||||
std::vector<size_t> extruders = { 0 };
|
||||
|
||||
bool operator==(const ExtrudersSequence& other) const
|
||||
{
|
||||
return (other.is_mm_intervals == this->is_mm_intervals ) &&
|
||||
(other.interval_by_mm == this->interval_by_mm ) &&
|
||||
(other.interval_by_layers == this->interval_by_layers ) &&
|
||||
(other.random_sequence == this->random_sequence ) &&
|
||||
(other.color_repetition == this->color_repetition ) &&
|
||||
(other.extruders == this->extruders ) ;
|
||||
}
|
||||
bool operator!=(const ExtrudersSequence& other) const
|
||||
{
|
||||
return (other.is_mm_intervals != this->is_mm_intervals ) ||
|
||||
(other.interval_by_mm != this->interval_by_mm ) ||
|
||||
(other.interval_by_layers != this->interval_by_layers ) ||
|
||||
(other.random_sequence != this->random_sequence ) ||
|
||||
(other.color_repetition != this->color_repetition ) ||
|
||||
(other.extruders != this->extruders ) ;
|
||||
}
|
||||
|
||||
void add_extruder(size_t pos, size_t extruder_id = size_t(0))
|
||||
{
|
||||
extruders.insert(extruders.begin() + pos+1, extruder_id);
|
||||
}
|
||||
|
||||
void delete_extruder(size_t pos)
|
||||
{
|
||||
if (extruders.size() == 1)
|
||||
return;// last item can't be deleted
|
||||
extruders.erase(extruders.begin() + pos);
|
||||
}
|
||||
|
||||
void init(size_t extruders_count)
|
||||
{
|
||||
extruders.clear();
|
||||
for (size_t extruder = 0; extruder < extruders_count; extruder++)
|
||||
extruders.push_back(extruder);
|
||||
}
|
||||
};
|
||||
|
||||
class Control : public wxControl
|
||||
{
|
||||
public:
|
||||
Control(
|
||||
wxWindow *parent,
|
||||
wxWindowID id,
|
||||
int lowerValue,
|
||||
int higherValue,
|
||||
int minValue,
|
||||
int maxValue,
|
||||
const wxPoint& pos = wxDefaultPosition,
|
||||
const wxSize& size = wxDefaultSize,
|
||||
long style = wxSL_VERTICAL,
|
||||
const wxValidator& val = wxDefaultValidator,
|
||||
const wxString& name = wxEmptyString);
|
||||
~Control() {}
|
||||
|
||||
void msw_rescale();
|
||||
void sys_color_changed();
|
||||
|
||||
int GetMinValue() const { return m_min_value; }
|
||||
int GetMaxValue() const { return m_max_value; }
|
||||
double GetMinValueD() { return m_values.empty() ? 0. : m_values[m_min_value]; }
|
||||
double GetMaxValueD() { return m_values.empty() ? 0. : m_values[m_max_value]; }
|
||||
int GetLowerValue() const { return m_lower_value; }
|
||||
int GetHigherValue() const { return m_higher_value; }
|
||||
int GetActiveValue() const;
|
||||
double GetLowerValueD() { return get_double_value(ssLower); }
|
||||
double GetHigherValueD() { return get_double_value(ssHigher); }
|
||||
wxSize DoGetBestSize() const override;
|
||||
wxSize get_min_size() const ;
|
||||
|
||||
// Set low and high slider position. If the span is non-empty, disable the "one layer" mode.
|
||||
void SetLowerValue (const int lower_val);
|
||||
void SetHigherValue(const int higher_val);
|
||||
void SetSelectionSpan(const int lower_val, const int higher_val);
|
||||
|
||||
void SetMaxValue(const int max_value);
|
||||
void SetKoefForLabels(const double koef) { m_label_koef = koef; }
|
||||
void SetSliderValues(const std::vector<double>& values);
|
||||
void ChangeOneLayerLock();
|
||||
void SetSliderAlternateValues(const std::vector<double>& values) { m_alternate_values = values; }
|
||||
|
||||
Info GetTicksValues() const;
|
||||
void SetTicksValues(const Info &custom_gcode_per_print_z);
|
||||
void SetLayersTimes(const std::vector<float>& layers_times, float total_time);
|
||||
void SetLayersTimes(const std::vector<double>& layers_times);
|
||||
|
||||
void SetDrawMode(bool is_sla_print, bool is_sequential_print);
|
||||
void SetDrawMode(DrawMode mode) { m_draw_mode = mode; }
|
||||
|
||||
void SetManipulationMode(Mode mode) { m_mode = mode; }
|
||||
Mode GetManipulationMode() const { return m_mode; }
|
||||
void SetModeAndOnlyExtruder(const bool is_one_extruder_printed_model, const int only_extruder);
|
||||
void SetExtruderColors(const std::vector<std::string>& extruder_colors);
|
||||
|
||||
bool IsNewPrint();
|
||||
|
||||
void set_render_as_disabled(bool value) { m_render_as_disabled = value; }
|
||||
bool is_rendering_as_disabled() const { return m_render_as_disabled; }
|
||||
|
||||
bool is_horizontal() const { return m_style == wxSL_HORIZONTAL; }
|
||||
bool is_one_layer() const { return m_is_one_layer; }
|
||||
bool is_lower_at_min() const { return m_lower_value == m_min_value; }
|
||||
bool is_higher_at_max() const { return m_higher_value == m_max_value; }
|
||||
bool is_full_span() const { return this->is_lower_at_min() && this->is_higher_at_max(); }
|
||||
|
||||
void OnPaint(wxPaintEvent& ) { render(); }
|
||||
void OnLeftDown(wxMouseEvent& event);
|
||||
void OnMotion(wxMouseEvent& event);
|
||||
void OnLeftUp(wxMouseEvent& event);
|
||||
void OnEnterWin(wxMouseEvent& event) { enter_window(event, true); }
|
||||
void OnLeaveWin(wxMouseEvent& event) { enter_window(event, false); }
|
||||
void UseDefaultColors(bool def_colors_on) { m_ticks.set_default_colors(def_colors_on); }
|
||||
void OnWheel(wxMouseEvent& event);
|
||||
void OnKeyDown(wxKeyEvent &event);
|
||||
void OnKeyUp(wxKeyEvent &event);
|
||||
void OnChar(wxKeyEvent &event);
|
||||
void OnRightDown(wxMouseEvent& event);
|
||||
void OnRightUp(wxMouseEvent& event);
|
||||
|
||||
void add_code_as_tick(Type type, int selected_extruder = -1);
|
||||
// add default action for tick, when press "+"
|
||||
void add_current_tick(bool call_from_keyboard = false);
|
||||
// delete current tick, when press "-"
|
||||
void delete_current_tick();
|
||||
void edit_tick(int tick = -1);
|
||||
void switch_one_layer_mode();
|
||||
void discard_all_thicks();
|
||||
void move_current_thumb_to_pos(wxPoint pos);
|
||||
void edit_extruder_sequence();
|
||||
void jump_to_value();
|
||||
void enable_action_icon(bool enable) { m_enable_action_icon = enable; }
|
||||
void show_add_context_menu();
|
||||
void show_edit_context_menu();
|
||||
void show_cog_icon_context_menu();
|
||||
void auto_color_change();
|
||||
|
||||
ExtrudersSequence m_extruders_sequence;
|
||||
|
||||
protected:
|
||||
|
||||
void render();
|
||||
void draw_focus_rect();
|
||||
void draw_action_icon(wxDC& dc, const wxPoint pt_beg, const wxPoint pt_end);
|
||||
void draw_scroll_line(wxDC& dc, const int lower_pos, const int higher_pos);
|
||||
void draw_thumb(wxDC& dc, const wxCoord& pos_coord, const SelectedSlider& selection);
|
||||
void draw_thumbs(wxDC& dc, const wxCoord& lower_pos, const wxCoord& higher_pos);
|
||||
void draw_ticks_pair(wxDC& dc, wxCoord pos, wxCoord mid, int tick_len);
|
||||
void draw_ticks(wxDC& dc);
|
||||
void draw_colored_band(wxDC& dc);
|
||||
void draw_ruler(wxDC& dc);
|
||||
void draw_one_layer_icon(wxDC& dc);
|
||||
void draw_revert_icon(wxDC& dc);
|
||||
void draw_cog_icon(wxDC &dc);
|
||||
void draw_thumb_item(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection);
|
||||
void draw_info_line_with_icon(wxDC& dc, const wxPoint& pos, SelectedSlider selection);
|
||||
void draw_tick_on_mouse_position(wxDC &dc);
|
||||
void draw_tick_text(wxDC& dc, const wxPoint& pos, int tick, LabelType label_type = ltHeight, bool right_side = true) const;
|
||||
void draw_thumb_text(wxDC& dc, const wxPoint& pos, const SelectedSlider& selection) const;
|
||||
|
||||
void update_thumb_rect(const wxCoord begin_x, const wxCoord begin_y, const SelectedSlider& selection);
|
||||
bool is_lower_thumb_editable();
|
||||
bool detect_selected_slider(const wxPoint& pt);
|
||||
void correct_lower_value();
|
||||
void correct_higher_value();
|
||||
void move_current_thumb(const bool condition);
|
||||
void enter_window(wxMouseEvent& event, const bool enter);
|
||||
bool is_wipe_tower_layer(int tick) const;
|
||||
|
||||
private:
|
||||
|
||||
bool is_point_in_rect(const wxPoint& pt, const wxRect& rect);
|
||||
int get_tick_near_point(const wxPoint& pt);
|
||||
|
||||
double get_scroll_step();
|
||||
wxString get_label(int tick, LabelType label_type = ltHeightWithLayer) const;
|
||||
void get_lower_and_higher_position(int& lower_pos, int& higher_pos);
|
||||
int get_value_from_position(const wxCoord x, const wxCoord y);
|
||||
int get_value_from_position(const wxPoint pos) { return get_value_from_position(pos.x, pos.y); }
|
||||
wxCoord get_position_from_value(const int value);
|
||||
wxSize get_size() const;
|
||||
void get_size(int* w, int* h) const;
|
||||
double get_double_value(const SelectedSlider& selection);
|
||||
int get_tick_from_value(double value, bool force_lower_bound = false);
|
||||
wxString get_tooltip(int tick = -1);
|
||||
int get_edited_tick_for_position(wxPoint pos, Type type = ColorChange);
|
||||
|
||||
std::string get_color_for_tool_change_tick(std::set<TickCode>::const_iterator it) const;
|
||||
std::string get_color_for_color_change_tick(std::set<TickCode>::const_iterator it) const;
|
||||
wxRect get_colored_band_rect();
|
||||
|
||||
// Get active extruders for tick.
|
||||
// Means one current extruder for not existing tick OR
|
||||
// 2 extruders - for existing tick (extruder before ToolChangeCode and extruder of current existing tick)
|
||||
// Use those values to disable selection of active extruders
|
||||
std::array<int, 2> get_active_extruders_for_tick(int tick) const;
|
||||
|
||||
void post_ticks_changed_event(Type type = Custom);
|
||||
bool check_ticks_changed_event(Type type);
|
||||
|
||||
void append_change_extruder_menu_item (wxMenu*, bool switch_current_code = false);
|
||||
void append_add_color_change_menu_item(wxMenu*, bool switch_current_code = false);
|
||||
|
||||
bool is_osx { false };
|
||||
wxFont m_font;
|
||||
int m_min_value;
|
||||
int m_max_value;
|
||||
int m_lower_value;
|
||||
int m_higher_value;
|
||||
|
||||
bool m_render_as_disabled{ false };
|
||||
|
||||
ScalableBitmap m_bmp_thumb_higher;
|
||||
ScalableBitmap m_bmp_thumb_lower;
|
||||
ScalableBitmap m_bmp_add_tick_on;
|
||||
ScalableBitmap m_bmp_add_tick_off;
|
||||
ScalableBitmap m_bmp_del_tick_on;
|
||||
ScalableBitmap m_bmp_del_tick_off;
|
||||
ScalableBitmap m_bmp_one_layer_lock_on;
|
||||
ScalableBitmap m_bmp_one_layer_lock_off;
|
||||
ScalableBitmap m_bmp_one_layer_unlock_on;
|
||||
ScalableBitmap m_bmp_one_layer_unlock_off;
|
||||
ScalableBitmap m_bmp_revert;
|
||||
ScalableBitmap m_bmp_cog;
|
||||
SelectedSlider m_selection;
|
||||
bool m_is_left_down = false;
|
||||
bool m_is_right_down = false;
|
||||
bool m_is_one_layer = false;
|
||||
bool m_is_focused = false;
|
||||
bool m_force_mode_apply = true;
|
||||
bool m_enable_action_icon = true;
|
||||
bool m_is_wipe_tower = false; //This flag indicates that there is multiple extruder print with wipe tower
|
||||
|
||||
DrawMode m_draw_mode = dmRegular;
|
||||
|
||||
Mode m_mode = SingleExtruder;
|
||||
int m_only_extruder = -1;
|
||||
|
||||
MouseAction m_mouse = maNone;
|
||||
FocusedItem m_focus = fiNone;
|
||||
wxPoint m_moving_pos = wxDefaultPosition;
|
||||
|
||||
wxRect m_rect_lower_thumb;
|
||||
wxRect m_rect_higher_thumb;
|
||||
wxRect m_rect_tick_action;
|
||||
wxRect m_rect_one_layer_icon;
|
||||
wxRect m_rect_revert_icon;
|
||||
wxRect m_rect_cog_icon;
|
||||
wxSize m_thumb_size;
|
||||
int m_tick_icon_dim;
|
||||
int m_lock_icon_dim;
|
||||
int m_revert_icon_dim;
|
||||
int m_cog_icon_dim;
|
||||
long m_style;
|
||||
long m_extra_style;
|
||||
float m_label_koef{ 1.0 };
|
||||
|
||||
std::vector<double> m_values;
|
||||
TickCodeInfo m_ticks;
|
||||
std::vector<double> m_layers_times;
|
||||
std::vector<double> m_layers_values;
|
||||
std::vector<std::string> m_extruder_colors;
|
||||
std::string m_print_obj_idxs;
|
||||
|
||||
std::vector<double> m_alternate_values;
|
||||
|
||||
// control's view variables
|
||||
wxCoord SLIDER_MARGIN; // margin around slider
|
||||
|
||||
wxPen DARK_ORANGE_PEN;
|
||||
wxPen ORANGE_PEN;
|
||||
wxPen LIGHT_ORANGE_PEN;
|
||||
|
||||
wxPen DARK_GREY_PEN;
|
||||
wxPen GREY_PEN;
|
||||
wxPen LIGHT_GREY_PEN;
|
||||
|
||||
std::vector<wxPen*> m_line_pens;
|
||||
std::vector<wxPen*> m_segm_pens;
|
||||
|
||||
struct Ruler {
|
||||
double long_step;
|
||||
double short_step;
|
||||
std::vector<double> max_values;// max value for each object/instance in sequence print
|
||||
// > 1 for sequential print
|
||||
|
||||
void init(const std::vector<double>& values);
|
||||
void update(wxWindow* win, const std::vector<double>& values, double scroll_step);
|
||||
bool is_ok() { return long_step > 0 && short_step > 0; }
|
||||
size_t count() { return max_values.size(); }
|
||||
} m_ruler;
|
||||
};
|
||||
|
||||
} // DoubleSlider;
|
||||
|
||||
} // Slic3r
|
||||
|
||||
|
||||
|
||||
#endif // slic3r_GUI_DoubleSlider_hpp_
|
|
@ -1,191 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <random>
|
||||
|
||||
#include "wx/colour.h"
|
||||
|
||||
class ColorGenerator
|
||||
{
|
||||
// Some of next code is borrowed from https://stackoverflow.com/questions/3018313/algorithm-to-convert-rgb-to-hsv-and-hsv-to-rgb-in-range-0-255-for-both
|
||||
typedef struct {
|
||||
double r; // a fraction between 0 and 1
|
||||
double g; // a fraction between 0 and 1
|
||||
double b; // a fraction between 0 and 1
|
||||
} rgb;
|
||||
|
||||
typedef struct {
|
||||
double h; // angle in degrees
|
||||
double s; // a fraction between 0 and 1
|
||||
double v; // a fraction between 0 and 1
|
||||
} hsv;
|
||||
|
||||
//static hsv rgb2hsv(rgb in);
|
||||
//static rgb hsv2rgb(hsv in);
|
||||
|
||||
hsv rgb2hsv(rgb in)
|
||||
{
|
||||
hsv out;
|
||||
double min, max, delta;
|
||||
|
||||
min = in.r < in.g ? in.r : in.g;
|
||||
min = min < in.b ? min : in.b;
|
||||
|
||||
max = in.r > in.g ? in.r : in.g;
|
||||
max = max > in.b ? max : in.b;
|
||||
|
||||
out.v = max; // v
|
||||
delta = max - min;
|
||||
if (delta < 0.00001)
|
||||
{
|
||||
out.s = 0;
|
||||
out.h = 0; // undefined, maybe nan?
|
||||
return out;
|
||||
}
|
||||
if (max > 0.0) { // NOTE: if Max is == 0, this divide would cause a crash
|
||||
out.s = (delta / max); // s
|
||||
}
|
||||
else {
|
||||
// if max is 0, then r = g = b = 0
|
||||
// s = 0, h is undefined
|
||||
out.s = 0.0;
|
||||
out.h = NAN; // its now undefined
|
||||
return out;
|
||||
}
|
||||
if (in.r >= max) // > is bogus, just keeps compilor happy
|
||||
out.h = (in.g - in.b) / delta; // between yellow & magenta
|
||||
else
|
||||
if (in.g >= max)
|
||||
out.h = 2.0 + (in.b - in.r) / delta; // between cyan & yellow
|
||||
else
|
||||
out.h = 4.0 + (in.r - in.g) / delta; // between magenta & cyan
|
||||
|
||||
out.h *= 60.0; // degrees
|
||||
|
||||
if (out.h < 0.0)
|
||||
out.h += 360.0;
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
hsv rgb2hsv(const std::string& str_clr_in)
|
||||
{
|
||||
wxColour clr(str_clr_in);
|
||||
rgb in = { clr.Red() / 255.0, clr.Green() / 255.0, clr.Blue() / 255.0 };
|
||||
return rgb2hsv(in);
|
||||
}
|
||||
|
||||
|
||||
rgb hsv2rgb(hsv in)
|
||||
{
|
||||
double hh, p, q, t, ff;
|
||||
long i;
|
||||
rgb out;
|
||||
|
||||
if (in.s <= 0.0) { // < is bogus, just shuts up warnings
|
||||
out.r = in.v;
|
||||
out.g = in.v;
|
||||
out.b = in.v;
|
||||
return out;
|
||||
}
|
||||
hh = in.h;
|
||||
if (hh >= 360.0) hh -= 360.0;//hh = 0.0;
|
||||
hh /= 60.0;
|
||||
i = (long)hh;
|
||||
ff = hh - i;
|
||||
p = in.v * (1.0 - in.s);
|
||||
q = in.v * (1.0 - (in.s * ff));
|
||||
t = in.v * (1.0 - (in.s * (1.0 - ff)));
|
||||
|
||||
switch (i) {
|
||||
case 0:
|
||||
out.r = in.v;
|
||||
out.g = t;
|
||||
out.b = p;
|
||||
break;
|
||||
case 1:
|
||||
out.r = q;
|
||||
out.g = in.v;
|
||||
out.b = p;
|
||||
break;
|
||||
case 2:
|
||||
out.r = p;
|
||||
out.g = in.v;
|
||||
out.b = t;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
out.r = p;
|
||||
out.g = q;
|
||||
out.b = in.v;
|
||||
break;
|
||||
case 4:
|
||||
out.r = t;
|
||||
out.g = p;
|
||||
out.b = in.v;
|
||||
break;
|
||||
case 5:
|
||||
default:
|
||||
out.r = in.v;
|
||||
out.g = p;
|
||||
out.b = q;
|
||||
break;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
std::random_device rd;
|
||||
|
||||
public:
|
||||
|
||||
ColorGenerator() {}
|
||||
~ColorGenerator() {}
|
||||
|
||||
double rand_val()
|
||||
{
|
||||
std::mt19937 rand_generator(rd());
|
||||
|
||||
// this value will be used for Saturation and Value
|
||||
// to avoid extremely light/dark colors, take this value from range [0.65; 1.0]
|
||||
std::uniform_real_distribution<double> distrib(0.65, 1.0);
|
||||
return distrib(rand_generator);
|
||||
}
|
||||
|
||||
|
||||
std::string get_opposite_color(const std::string& color)
|
||||
{
|
||||
std::string opp_color = "";
|
||||
|
||||
hsv hsv_clr = rgb2hsv(color);
|
||||
hsv_clr.h += 65; // 65 instead 60 to avoid circle values
|
||||
hsv_clr.s = rand_val();
|
||||
hsv_clr.v = rand_val();
|
||||
|
||||
rgb rgb_opp_color = hsv2rgb(hsv_clr);
|
||||
|
||||
wxString clr_str = wxString::Format(wxT("#%02X%02X%02X"), (unsigned char)(rgb_opp_color.r * 255), (unsigned char)(rgb_opp_color.g * 255), (unsigned char)(rgb_opp_color.b * 255));
|
||||
opp_color = clr_str.ToStdString();
|
||||
|
||||
return opp_color;
|
||||
}
|
||||
|
||||
std::string get_opposite_color(const std::string& color_frst, const std::string& color_scnd)
|
||||
{
|
||||
std::string opp_color = "";
|
||||
|
||||
hsv hsv_frst = rgb2hsv(color_frst);
|
||||
hsv hsv_scnd = rgb2hsv(color_scnd);
|
||||
|
||||
double delta_h = fabs(hsv_frst.h - hsv_scnd.h);
|
||||
double start_h = delta_h > 180 ? std::min<double>(hsv_scnd.h, hsv_frst.h) : std::max<double>(hsv_scnd.h, hsv_frst.h);
|
||||
start_h += 5; // to avoid circle change of colors for 120 deg
|
||||
if (delta_h < 180)
|
||||
delta_h = 360 - delta_h;
|
||||
|
||||
hsv hsv_opp = hsv{ start_h + 0.5 * delta_h, rand_val(), rand_val() };
|
||||
rgb rgb_opp_color = hsv2rgb(hsv_opp);
|
||||
|
||||
wxString clr_str = wxString::Format(wxT("#%02X%02X%02X"), (unsigned char)(rgb_opp_color.r * 255), (unsigned char)(rgb_opp_color.g * 255), (unsigned char)(rgb_opp_color.b * 255));
|
||||
opp_color = clr_str.ToStdString();
|
||||
|
||||
return opp_color;
|
||||
}
|
||||
};
|
|
@ -1,289 +0,0 @@
|
|||
#include "ExtruderSequenceDialog.hpp"
|
||||
|
||||
#include <wx/wx.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/dialog.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/bmpcbox.h>
|
||||
#include <wx/checkbox.h>
|
||||
|
||||
#include <vector>
|
||||
#include <set>
|
||||
#include <functional>
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "OptionsGroup.hpp"
|
||||
#include "MainFrame.hpp"
|
||||
#include "BitmapComboBox.hpp"
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
ExtruderSequenceDialog::ExtruderSequenceDialog(const DoubleSlider::ExtrudersSequence& sequence)
|
||||
: DPIDialog(static_cast<wxWindow*>(wxGetApp().mainframe), wxID_ANY, wxString(SLIC3R_APP_NAME) + " - " + _(L("Set extruder sequence")),
|
||||
wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
||||
m_sequence(sequence)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
wxGetApp().UpdateDarkUI(this);
|
||||
#else
|
||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
#endif
|
||||
SetDoubleBuffered(true);
|
||||
SetFont(wxGetApp().normal_font());
|
||||
|
||||
auto main_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
const int em = wxGetApp().em_unit();
|
||||
|
||||
m_bmp_del = ScalableBitmap(this, "remove_copies");
|
||||
m_bmp_add = ScalableBitmap(this, "add_copies");
|
||||
|
||||
auto option_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
auto intervals_box = new wxStaticBox(this, wxID_ANY, _(L("Set extruder change for every"))+ ": ");
|
||||
wxGetApp().UpdateDarkUI(intervals_box);
|
||||
auto intervals_box_sizer = new wxStaticBoxSizer(intervals_box, wxVERTICAL);
|
||||
|
||||
m_intervals_grid_sizer = new wxFlexGridSizer(3, 5, em);
|
||||
|
||||
auto editor_sz = wxSize(4*em, wxDefaultCoord);
|
||||
|
||||
auto ID_RADIO_BUTTON = wxID_ANY;// wxWindow::NewControlId(1);
|
||||
|
||||
wxRadioButton* rb_by_layers = new wxRadioButton(this, ID_RADIO_BUTTON, "", wxDefaultPosition, wxDefaultSize, wxRB_GROUP);
|
||||
rb_by_layers->Bind(wxEVT_RADIOBUTTON, [this](wxCommandEvent& event) { m_sequence.is_mm_intervals = false; });
|
||||
rb_by_layers->SetValue(!m_sequence.is_mm_intervals);
|
||||
|
||||
wxStaticText* st_by_layers = new wxStaticText(this, wxID_ANY, _(L("layers")));
|
||||
m_interval_by_layers = new wxTextCtrl(this, wxID_ANY,
|
||||
wxString::Format("%d", m_sequence.interval_by_layers),
|
||||
wxDefaultPosition, editor_sz
|
||||
#ifdef _WIN32
|
||||
, wxBORDER_SIMPLE
|
||||
#endif
|
||||
);
|
||||
wxGetApp().UpdateDarkUI(m_interval_by_layers);
|
||||
m_interval_by_layers->Bind(wxEVT_TEXT, [this, rb_by_layers](wxEvent&)
|
||||
{
|
||||
wxString str = m_interval_by_layers->GetValue();
|
||||
if (str.IsEmpty()) {
|
||||
m_interval_by_layers->SetValue(wxString::Format("%d", m_sequence.interval_by_layers));
|
||||
return;
|
||||
}
|
||||
|
||||
int val = wxAtoi(str);
|
||||
if (val < 1) {
|
||||
m_interval_by_layers->SetValue("1");
|
||||
val = 1;
|
||||
}
|
||||
|
||||
if (m_sequence.interval_by_layers == val)
|
||||
return;
|
||||
|
||||
m_sequence.interval_by_layers = val;
|
||||
|
||||
m_sequence.is_mm_intervals = false;
|
||||
rb_by_layers->SetValue(true);
|
||||
});
|
||||
|
||||
m_intervals_grid_sizer->Add(rb_by_layers, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_intervals_grid_sizer->Add(m_interval_by_layers,0, wxALIGN_CENTER_VERTICAL);
|
||||
m_intervals_grid_sizer->Add(st_by_layers,0, wxALIGN_CENTER_VERTICAL);
|
||||
|
||||
wxRadioButton* rb_by_mm = new wxRadioButton(this, ID_RADIO_BUTTON, "");
|
||||
rb_by_mm->Bind(wxEVT_RADIOBUTTON, [this](wxEvent&) { m_sequence.is_mm_intervals = true; });
|
||||
rb_by_mm->SetValue(m_sequence.is_mm_intervals);
|
||||
|
||||
wxStaticText* st_by_mm = new wxStaticText(this, wxID_ANY, _(L("mm")));
|
||||
m_interval_by_mm = new wxTextCtrl(this, wxID_ANY,
|
||||
double_to_string(sequence.interval_by_mm),
|
||||
wxDefaultPosition, editor_sz, wxTE_PROCESS_ENTER
|
||||
#ifdef _WIN32
|
||||
| wxBORDER_SIMPLE
|
||||
#endif
|
||||
);
|
||||
wxGetApp().UpdateDarkUI(m_interval_by_mm);
|
||||
|
||||
double min_layer_height = wxGetApp().preset_bundle->prints.get_edited_preset().config.opt_float("layer_height");
|
||||
auto change_value = [this, min_layer_height]()
|
||||
{
|
||||
wxString str = m_interval_by_mm->GetValue();
|
||||
if (str.IsEmpty()) {
|
||||
m_interval_by_mm->SetValue(wxString::Format("%d", m_sequence.interval_by_mm));
|
||||
return;
|
||||
}
|
||||
|
||||
char dec_sep = '.';
|
||||
if (! is_decimal_separator_point()) {
|
||||
str.Replace(".", ",", false);
|
||||
dec_sep = ',';
|
||||
}
|
||||
|
||||
double val;
|
||||
if (str == dec_sep || !str.ToDouble(&val) || val <= 0.0)
|
||||
val = 3.0; // default value
|
||||
|
||||
if (fabs(m_sequence.interval_by_layers - val) < 0.001)
|
||||
return;
|
||||
|
||||
if (val < min_layer_height) {
|
||||
val = min_layer_height;
|
||||
m_interval_by_mm->SetValue(double_to_string(val, 2));
|
||||
}
|
||||
|
||||
m_sequence.interval_by_mm = val;
|
||||
};
|
||||
|
||||
m_interval_by_mm->Bind(wxEVT_TEXT, [this, rb_by_mm](wxEvent&)
|
||||
{
|
||||
m_sequence.is_mm_intervals = true;
|
||||
rb_by_mm->SetValue(true);
|
||||
});
|
||||
|
||||
m_interval_by_mm->Bind(wxEVT_KILL_FOCUS, [change_value](wxFocusEvent& event)
|
||||
{
|
||||
change_value();
|
||||
event.Skip();
|
||||
});
|
||||
|
||||
m_interval_by_mm->Bind(wxEVT_TEXT_ENTER, [change_value](wxEvent&)
|
||||
{
|
||||
change_value();
|
||||
});
|
||||
|
||||
m_intervals_grid_sizer->Add(rb_by_mm, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_intervals_grid_sizer->Add(m_interval_by_mm, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_intervals_grid_sizer->Add(st_by_mm,0, wxALIGN_CENTER_VERTICAL);
|
||||
|
||||
intervals_box_sizer->Add(m_intervals_grid_sizer, 0, wxLEFT, em);
|
||||
option_sizer->Add(intervals_box_sizer, 0, wxEXPAND);
|
||||
|
||||
m_random_sequence = new wxCheckBox(this, wxID_ANY, _L("Random sequence"));
|
||||
m_random_sequence->SetValue(m_sequence.random_sequence);
|
||||
m_random_sequence->SetToolTip(_L("If enabled, random sequence of the selected extruders will be used."));
|
||||
m_random_sequence->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) {
|
||||
m_sequence.random_sequence = e.IsChecked();
|
||||
m_color_repetition->Enable(m_sequence.random_sequence);
|
||||
});
|
||||
|
||||
m_color_repetition = new wxCheckBox(this, wxID_ANY, _L("Allow next color repetition"));
|
||||
m_color_repetition->SetValue(m_sequence.color_repetition);
|
||||
m_color_repetition->SetToolTip(_L("If enabled, a repetition of the next random color will be allowed."));
|
||||
m_color_repetition->Bind(wxEVT_CHECKBOX, [this](wxCommandEvent& e) {m_sequence.color_repetition = e.IsChecked(); });
|
||||
|
||||
auto extruders_box = new wxStaticBox(this, wxID_ANY, _(L("Set extruder(tool) sequence"))+ ": ");
|
||||
wxGetApp().UpdateDarkUI(extruders_box);
|
||||
|
||||
auto extruders_box_sizer = new wxStaticBoxSizer(extruders_box, wxVERTICAL);
|
||||
|
||||
m_extruders_grid_sizer = new wxFlexGridSizer(3, 5, em);
|
||||
|
||||
apply_extruder_sequence();
|
||||
|
||||
extruders_box_sizer->Add(m_extruders_grid_sizer, 0, wxALL, em);
|
||||
extruders_box_sizer->Add(m_random_sequence, 0, wxLEFT | wxBOTTOM, em);
|
||||
extruders_box_sizer->Add(m_color_repetition, 0, wxLEFT | wxBOTTOM, em);
|
||||
option_sizer->Add(extruders_box_sizer, 0, wxEXPAND | wxTOP, em);
|
||||
|
||||
main_sizer->Add(option_sizer, 0, wxEXPAND | wxALL, em);
|
||||
|
||||
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCANCEL);
|
||||
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(this->FindWindowById(wxID_OK, this)));
|
||||
wxGetApp().UpdateDarkUI(static_cast<wxButton*>(this->FindWindowById(wxID_CANCEL, this)));
|
||||
main_sizer->Add(buttons, 0, wxEXPAND | wxRIGHT | wxBOTTOM, em);
|
||||
|
||||
SetSizer(main_sizer);
|
||||
main_sizer->SetSizeHints(this);
|
||||
|
||||
/* For this moment min sizes for dialog and its sizer are calculated.
|
||||
* If we left them, it can cause a problem with layouts during deleting of extruders
|
||||
*/
|
||||
if (m_sequence.extruders.size()>1)
|
||||
{
|
||||
wxSize sz = wxSize(-1, 10 * em);
|
||||
SetMinSize(sz);
|
||||
GetSizer()->SetMinSize(sz);
|
||||
}
|
||||
}
|
||||
|
||||
void ExtruderSequenceDialog::apply_extruder_sequence()
|
||||
{
|
||||
m_extruders_grid_sizer->Clear(true);
|
||||
|
||||
for (size_t extruder=0; extruder < m_sequence.extruders.size(); ++extruder)
|
||||
{
|
||||
BitmapComboBox* extruder_selector = nullptr;
|
||||
apply_extruder_selector(&extruder_selector, this, "", wxDefaultPosition, wxSize(15*wxGetApp().em_unit(), -1));
|
||||
extruder_selector->SetSelection(m_sequence.extruders[extruder]);
|
||||
|
||||
extruder_selector->Bind(wxEVT_COMBOBOX, [this, extruder_selector, extruder](wxCommandEvent& evt)
|
||||
{
|
||||
m_sequence.extruders[extruder] = extruder_selector->GetSelection();
|
||||
evt.StopPropagation();
|
||||
});
|
||||
|
||||
auto del_btn = new ScalableButton(this, wxID_ANY, m_bmp_del);
|
||||
del_btn->SetToolTip(_(L("Remove extruder from sequence")));
|
||||
if (m_sequence.extruders.size()==1)
|
||||
del_btn->Disable();
|
||||
|
||||
del_btn->Bind(wxEVT_BUTTON, [this, extruder](wxEvent&) {
|
||||
m_sequence.delete_extruder(extruder);
|
||||
apply_extruder_sequence();
|
||||
});
|
||||
|
||||
auto add_btn = new ScalableButton(this, wxID_ANY, m_bmp_add);
|
||||
add_btn->SetToolTip(_(L("Add extruder to sequence")));
|
||||
|
||||
add_btn->Bind(wxEVT_BUTTON, [this, extruder, extruder_selector](wxEvent&) {
|
||||
size_t extr_cnt = (size_t)extruder_selector->GetCount();
|
||||
size_t seq_extr_cnt = m_sequence.extruders.size();
|
||||
size_t extr_id = seq_extr_cnt - size_t(seq_extr_cnt / extr_cnt) * extr_cnt;
|
||||
m_sequence.add_extruder(extruder, std::min(extr_id, extr_cnt-1));
|
||||
apply_extruder_sequence();
|
||||
});
|
||||
|
||||
m_extruders_grid_sizer->Add(extruder_selector, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_extruders_grid_sizer->Add(del_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
m_extruders_grid_sizer->Add(add_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||
}
|
||||
m_extruders_grid_sizer->ShowItems(true); // show items hidden in apply_extruder_selector()
|
||||
|
||||
bool show_checkboxes = m_sequence.extruders.size() > 1;
|
||||
m_random_sequence->Enable(show_checkboxes);
|
||||
m_color_repetition->Enable(show_checkboxes && m_sequence.random_sequence);
|
||||
|
||||
Fit();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
void ExtruderSequenceDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
{
|
||||
SetFont(wxGetApp().normal_font());
|
||||
|
||||
m_bmp_add.msw_rescale();
|
||||
m_bmp_del.msw_rescale();
|
||||
|
||||
const int em = em_unit();
|
||||
|
||||
m_intervals_grid_sizer->SetHGap(em);
|
||||
m_intervals_grid_sizer->SetVGap(em);
|
||||
m_extruders_grid_sizer->SetHGap(em);
|
||||
m_extruders_grid_sizer->SetVGap(em);
|
||||
|
||||
msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
|
||||
|
||||
// wxSize size = get_size();
|
||||
// SetMinSize(size);
|
||||
|
||||
Fit();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
#ifndef slic3r_GUI_ExtruderSequenceDialog_hpp_
|
||||
#define slic3r_GUI_ExtruderSequenceDialog_hpp_
|
||||
|
||||
#include "GUI_Utils.hpp"
|
||||
#include "DoubleSlider.hpp"
|
||||
|
||||
class wxTextCtrl;
|
||||
class wxFlexGridSizer;
|
||||
class wxCheckBox;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// ExtruderSequenceDialog: a node inside ObjectDataViewModel
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
class ExtruderSequenceDialog: public DPIDialog
|
||||
{
|
||||
ScalableBitmap m_bmp_del;
|
||||
ScalableBitmap m_bmp_add;
|
||||
DoubleSlider::ExtrudersSequence m_sequence;
|
||||
|
||||
wxTextCtrl* m_interval_by_layers {nullptr};
|
||||
wxTextCtrl* m_interval_by_mm {nullptr};
|
||||
wxCheckBox* m_random_sequence {nullptr};
|
||||
wxCheckBox* m_color_repetition{nullptr};
|
||||
|
||||
wxFlexGridSizer* m_intervals_grid_sizer {nullptr};
|
||||
wxFlexGridSizer* m_extruders_grid_sizer {nullptr};
|
||||
public:
|
||||
ExtruderSequenceDialog(const DoubleSlider::ExtrudersSequence& sequence);
|
||||
|
||||
~ExtruderSequenceDialog() {}
|
||||
|
||||
DoubleSlider::ExtrudersSequence GetValue() { return m_sequence; }
|
||||
|
||||
protected:
|
||||
void apply_extruder_sequence();
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif // slic3r_GUI_ExtruderSequenceDialog_hpp_
|
|
@ -1,978 +0,0 @@
|
|||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <thread>
|
||||
#include <condition_variable>
|
||||
#include <stdexcept>
|
||||
#include <boost/format.hpp>
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
#if _WIN32
|
||||
#include <regex>
|
||||
#endif
|
||||
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "avrdude/avrdude-slic3r.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
#include "../Utils/HexFile.hpp"
|
||||
#include "../Utils/Serial.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
|
||||
// wx includes need to come after asio because of the WinSock.h problem
|
||||
#include "FirmwareDialog.hpp"
|
||||
|
||||
#include <wx/app.h>
|
||||
#include <wx/event.h>
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/settings.h>
|
||||
#include <wx/timer.h>
|
||||
#include <wx/panel.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/filepicker.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/combobox.h>
|
||||
#include <wx/gauge.h>
|
||||
#include <wx/collpane.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <wx/filefn.h>
|
||||
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
namespace asio = boost::asio;
|
||||
using boost::system::error_code;
|
||||
using boost::optional;
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
using Utils::HexFile;
|
||||
using Utils::SerialPortInfo;
|
||||
using Utils::Serial;
|
||||
|
||||
|
||||
// USB IDs used to perform device lookup
|
||||
enum {
|
||||
USB_VID_PRUSA = 0x2c99,
|
||||
USB_PID_MK2 = 1,
|
||||
USB_PID_MK3 = 2,
|
||||
USB_PID_MMU_BOOT = 3,
|
||||
USB_PID_MMU_APP = 4,
|
||||
USB_PID_CW1_BOOT = 7,
|
||||
USB_PID_CW1_APP = 8,
|
||||
USB_PID_CW1S_BOOT = 14,
|
||||
USB_PID_CW1S_APP = 15,
|
||||
};
|
||||
|
||||
// This enum discriminates the kind of information in EVT_AVRDUDE,
|
||||
// it's stored in the ExtraLong field of wxCommandEvent.
|
||||
enum AvrdudeEvent
|
||||
{
|
||||
AE_MESSAGE,
|
||||
AE_PROGRESS,
|
||||
AE_STATUS,
|
||||
AE_EXIT,
|
||||
};
|
||||
|
||||
wxDECLARE_EVENT(EVT_AVRDUDE, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_AVRDUDE, wxCommandEvent);
|
||||
|
||||
wxDECLARE_EVENT(EVT_ASYNC_DIALOG, wxCommandEvent);
|
||||
wxDEFINE_EVENT(EVT_ASYNC_DIALOG, wxCommandEvent);
|
||||
|
||||
struct Avr109Pid
|
||||
{
|
||||
unsigned boot;
|
||||
unsigned app;
|
||||
|
||||
Avr109Pid(unsigned boot, unsigned app) : boot(boot), app(app) {}
|
||||
};
|
||||
|
||||
// Private
|
||||
|
||||
struct FirmwareDialog::priv
|
||||
{
|
||||
enum AvrDudeComplete
|
||||
{
|
||||
AC_NONE,
|
||||
AC_SUCCESS,
|
||||
AC_FAILURE,
|
||||
AC_USER_CANCELLED,
|
||||
};
|
||||
|
||||
FirmwareDialog *q; // PIMPL back pointer ("Q-Pointer")
|
||||
|
||||
// GUI elements
|
||||
wxComboBox *port_picker;
|
||||
wxStaticText *txt_port_autodetect;
|
||||
wxFilePickerCtrl *hex_picker;
|
||||
wxStaticText *txt_status;
|
||||
wxGauge *progressbar;
|
||||
wxCollapsiblePane *spoiler;
|
||||
wxTextCtrl *txt_stdout;
|
||||
wxButton *btn_rescan;
|
||||
wxButton *btn_close;
|
||||
wxButton *btn_flash;
|
||||
wxString btn_flash_label_ready;
|
||||
wxString btn_flash_label_flashing;
|
||||
wxString label_status_flashing;
|
||||
|
||||
wxTimer timer_pulse;
|
||||
|
||||
int min_width;
|
||||
int min_height;
|
||||
int min_height_expanded;
|
||||
|
||||
// Async modal dialog during flashing
|
||||
std::mutex mutex;
|
||||
int modal_response;
|
||||
std::condition_variable response_cv;
|
||||
|
||||
// Data
|
||||
std::vector<SerialPortInfo> ports;
|
||||
optional<SerialPortInfo> port;
|
||||
bool port_autodetect;
|
||||
HexFile hex_file;
|
||||
|
||||
// This is a shared pointer holding the background AvrDude task
|
||||
// also serves as a status indication (it is set _iff_ the background task is running, otherwise it is reset).
|
||||
AvrDude::Ptr avrdude;
|
||||
unsigned progress_tasks_done;
|
||||
unsigned progress_tasks_bar;
|
||||
bool user_cancelled;
|
||||
const bool extra_verbose; // For debugging
|
||||
|
||||
priv(FirmwareDialog *q) :
|
||||
q(q),
|
||||
btn_flash_label_ready(_(L("Flash!"))),
|
||||
btn_flash_label_flashing(_(L("Cancel"))),
|
||||
label_status_flashing(_(L("Flashing in progress. Please do not disconnect the printer!"))),
|
||||
timer_pulse(q),
|
||||
port_autodetect(false),
|
||||
progress_tasks_done(0),
|
||||
progress_tasks_bar(0),
|
||||
user_cancelled(false),
|
||||
extra_verbose(false)
|
||||
{}
|
||||
|
||||
void find_serial_ports();
|
||||
void fit_no_shrink();
|
||||
void set_txt_status(const wxString &label);
|
||||
void flashing_start(unsigned tasks);
|
||||
void flashing_done(AvrDudeComplete complete);
|
||||
void set_autodetect(bool autodetect);
|
||||
void update_flash_enabled();
|
||||
void load_hex_file(const wxString &path);
|
||||
void queue_event(AvrdudeEvent aevt, wxString message);
|
||||
|
||||
bool ask_model_id_mismatch(const std::string &printer_model);
|
||||
bool check_model_id();
|
||||
void avr109_wait_for_bootloader(Avr109Pid usb_pid, unsigned retries);
|
||||
void avr109_reboot(const SerialPortInfo &port);
|
||||
void avr109_lookup_port(Avr109Pid usb_pid);
|
||||
void prepare_common();
|
||||
void prepare_mk2();
|
||||
void prepare_mk3();
|
||||
void prepare_avr109(Avr109Pid usb_pid);
|
||||
bool get_serial_port();
|
||||
void perform_upload();
|
||||
|
||||
void user_cancel();
|
||||
void on_avrdude(const wxCommandEvent &evt);
|
||||
void on_async_dialog(const wxCommandEvent &evt);
|
||||
void ensure_joined();
|
||||
|
||||
void queue_status(wxString message) { queue_event(AE_STATUS, std::move(message)); }
|
||||
|
||||
template<class ...Args> void queue_message(const wxString &format, Args... args) {
|
||||
auto message = wxString::Format(format, args...);
|
||||
BOOST_LOG_TRIVIAL(info) << message;
|
||||
message.Append('\n');
|
||||
queue_event(AE_MESSAGE, std::move(message));
|
||||
}
|
||||
|
||||
template<class ...Args> void queue_error(const wxString &format, Args... args) {
|
||||
queue_message(format, args...);
|
||||
queue_event(AE_STATUS, _(L("Flashing failed")) +": "+ wxString::Format(format, args...));
|
||||
avrdude->cancel();
|
||||
}
|
||||
|
||||
static const char* avr109_dev_name(Avr109Pid usb_pid);
|
||||
};
|
||||
|
||||
void FirmwareDialog::priv::find_serial_ports()
|
||||
{
|
||||
auto new_ports = Utils::scan_serial_ports_extended();
|
||||
if (new_ports != this->ports) {
|
||||
this->ports = new_ports;
|
||||
port_picker->Clear();
|
||||
for (const auto &port : this->ports)
|
||||
port_picker->Append(wxString::FromUTF8(port.friendly_name.data()));
|
||||
if (ports.size() > 0) {
|
||||
int idx = port_picker->GetValue().IsEmpty() ? 0 : -1;
|
||||
for (int i = 0; i < (int)this->ports.size(); ++ i)
|
||||
if (this->ports[i].is_printer) {
|
||||
idx = i;
|
||||
break;
|
||||
}
|
||||
if (idx != -1) {
|
||||
port_picker->SetSelection(idx);
|
||||
update_flash_enabled();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::fit_no_shrink()
|
||||
{
|
||||
// Ensure content fits into window and window is not shrinked
|
||||
const auto old_size = q->GetSize();
|
||||
q->Layout();
|
||||
q->Fit();
|
||||
const auto new_size = q->GetSize();
|
||||
const auto new_width = std::max(old_size.GetWidth(), new_size.GetWidth());
|
||||
const auto new_height = std::max(old_size.GetHeight(), new_size.GetHeight());
|
||||
q->SetSize(new_width, new_height);
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::set_txt_status(const wxString &label)
|
||||
{
|
||||
const auto width = txt_status->GetSize().GetWidth();
|
||||
txt_status->SetLabel(label);
|
||||
txt_status->Wrap(width);
|
||||
|
||||
fit_no_shrink();
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::flashing_start(unsigned tasks)
|
||||
{
|
||||
modal_response = wxID_NONE;
|
||||
txt_stdout->Clear();
|
||||
set_txt_status(label_status_flashing);
|
||||
txt_status->SetForegroundColour(GUI::wxGetApp().get_label_clr_modified());
|
||||
port_picker->Disable();
|
||||
btn_rescan->Disable();
|
||||
hex_picker->Disable();
|
||||
btn_close->Disable();
|
||||
btn_flash->SetLabel(btn_flash_label_flashing);
|
||||
progressbar->SetRange(200 * tasks); // See progress callback below
|
||||
progressbar->SetValue(0);
|
||||
progress_tasks_done = 0;
|
||||
progress_tasks_bar = 0;
|
||||
user_cancelled = false;
|
||||
timer_pulse.Start(50);
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::flashing_done(AvrDudeComplete complete)
|
||||
{
|
||||
auto text_color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
|
||||
port_picker->Enable();
|
||||
btn_rescan->Enable();
|
||||
hex_picker->Enable();
|
||||
btn_close->Enable();
|
||||
btn_flash->SetLabel(btn_flash_label_ready);
|
||||
txt_status->SetForegroundColour(text_color);
|
||||
timer_pulse.Stop();
|
||||
progressbar->SetValue(progressbar->GetRange());
|
||||
|
||||
switch (complete) {
|
||||
case AC_SUCCESS: set_txt_status(_(L("Flashing succeeded!"))); break;
|
||||
case AC_FAILURE: set_txt_status(_(L("Flashing failed. Please see the avrdude log below."))); break;
|
||||
case AC_USER_CANCELLED: set_txt_status(_(L("Flashing cancelled."))); break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::set_autodetect(bool autodetect)
|
||||
{
|
||||
port_autodetect = autodetect;
|
||||
|
||||
port_picker->Show(!autodetect);
|
||||
btn_rescan->Show(!autodetect);
|
||||
txt_port_autodetect->Show(autodetect);
|
||||
q->Layout();
|
||||
fit_no_shrink();
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::update_flash_enabled()
|
||||
{
|
||||
const bool hex_exists = wxFileExists(hex_picker->GetPath());
|
||||
const bool port_valid = port_autodetect || get_serial_port();
|
||||
|
||||
btn_flash->Enable(hex_exists && port_valid);
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::load_hex_file(const wxString &path)
|
||||
{
|
||||
hex_file = HexFile(path.wx_str());
|
||||
const bool autodetect = hex_file.device == HexFile::DEV_MM_CONTROL || hex_file.device == HexFile::DEV_CW1 || hex_file.device == HexFile::DEV_CW1S;
|
||||
set_autodetect(autodetect);
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::queue_event(AvrdudeEvent aevt, wxString message)
|
||||
{
|
||||
auto evt = new wxCommandEvent(EVT_AVRDUDE, this->q->GetId());
|
||||
evt->SetExtraLong(aevt);
|
||||
evt->SetString(std::move(message));
|
||||
wxQueueEvent(this->q, evt);
|
||||
}
|
||||
|
||||
bool FirmwareDialog::priv::ask_model_id_mismatch(const std::string &printer_model)
|
||||
{
|
||||
// model_id in the hex file doesn't match what the printer repoted.
|
||||
// Ask the user if it should be flashed anyway.
|
||||
|
||||
std::unique_lock<std::mutex> lock(mutex);
|
||||
|
||||
auto evt = new wxCommandEvent(EVT_ASYNC_DIALOG, this->q->GetId());
|
||||
evt->SetString(wxString::Format(_(L(
|
||||
"This firmware hex file does not match the printer model.\n"
|
||||
"The hex file is intended for: %s\n"
|
||||
"Printer reported: %s\n\n"
|
||||
"Do you want to continue and flash this hex file anyway?\n"
|
||||
"Please only continue if you are sure this is the right thing to do.")),
|
||||
hex_file.model_id, printer_model
|
||||
));
|
||||
wxQueueEvent(this->q, evt);
|
||||
|
||||
response_cv.wait(lock, [this]() { return this->modal_response != wxID_NONE; });
|
||||
|
||||
if (modal_response == wxID_YES) {
|
||||
return true;
|
||||
} else {
|
||||
user_cancel();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool FirmwareDialog::priv::check_model_id()
|
||||
{
|
||||
// XXX: The implementation in Serial doesn't currently work reliably enough to be used.
|
||||
// Therefore, regretably, so far the check cannot be used and we just return true here.
|
||||
// TODO: Rewrite Serial using more platform-native code.
|
||||
return true;
|
||||
|
||||
// if (hex_file.model_id.empty()) {
|
||||
// // No data to check against, assume it's ok
|
||||
// return true;
|
||||
// }
|
||||
|
||||
// asio::io_service io;
|
||||
// Serial serial(io, port->port, 115200);
|
||||
// serial.printer_setup();
|
||||
|
||||
// enum {
|
||||
// TIMEOUT = 2000,
|
||||
// RETREIES = 5,
|
||||
// };
|
||||
|
||||
// if (! serial.printer_ready_wait(RETREIES, TIMEOUT)) {
|
||||
// queue_error(wxString::Format(_(L("Could not connect to the printer at %s")), port->port));
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// std::string line;
|
||||
// error_code ec;
|
||||
// serial.printer_write_line("PRUSA Rev");
|
||||
// while (serial.read_line(TIMEOUT, line, ec)) {
|
||||
// if (ec) {
|
||||
// queue_error(wxString::Format(_(L("Could not connect to the printer at %s")), port->port));
|
||||
// return false;
|
||||
// }
|
||||
|
||||
// if (line == "ok") { continue; }
|
||||
|
||||
// if (line == hex_file.model_id) {
|
||||
// return true;
|
||||
// } else {
|
||||
// return ask_model_id_mismatch(line);
|
||||
// }
|
||||
|
||||
// line.clear();
|
||||
// }
|
||||
|
||||
// return false;
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::avr109_wait_for_bootloader(Avr109Pid usb_pid, unsigned retries)
|
||||
{
|
||||
enum {
|
||||
SLEEP_MS = 500,
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < retries && !user_cancelled; i++) {
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MS));
|
||||
|
||||
auto ports = Utils::scan_serial_ports_extended();
|
||||
ports.erase(std::remove_if(ports.begin(), ports.end(), [=](const SerialPortInfo &port ) {
|
||||
return port.id_vendor != USB_VID_PRUSA || port.id_product != usb_pid.boot;
|
||||
}), ports.end());
|
||||
|
||||
if (ports.size() == 1) {
|
||||
port = ports[0];
|
||||
return;
|
||||
} else if (ports.size() > 1) {
|
||||
queue_message("Several VID/PID 0x2c99/%u devices found", usb_pid.boot);
|
||||
queue_error(_(L("Multiple %s devices found. Please only connect one at a time for flashing.")), avr109_dev_name(usb_pid));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::avr109_reboot(const SerialPortInfo &port)
|
||||
{
|
||||
asio::io_service io;
|
||||
Serial serial(io, port.port, 1200);
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::avr109_lookup_port(Avr109Pid usb_pid)
|
||||
{
|
||||
const char *dev_name = avr109_dev_name(usb_pid);
|
||||
const wxString msg_not_found = wxString::Format(
|
||||
_(L("The %s device was not found.\n"
|
||||
"If the device is connected, please press the Reset button next to the USB connector ...")),
|
||||
dev_name);
|
||||
|
||||
queue_message("Flashing %s, looking for VID/PID 0x2c99/%u or 0x2c99/%u ...", dev_name, usb_pid.boot, usb_pid.app);
|
||||
|
||||
auto ports = Utils::scan_serial_ports_extended();
|
||||
ports.erase(std::remove_if(ports.begin(), ports.end(), [=](const SerialPortInfo &port ) {
|
||||
return port.id_vendor != USB_VID_PRUSA ||
|
||||
(port.id_product != usb_pid.boot && port.id_product != usb_pid.app);
|
||||
}), ports.end());
|
||||
|
||||
if (ports.size() == 0) {
|
||||
queue_message("The %s device was not found.", dev_name);
|
||||
queue_status(msg_not_found);
|
||||
avr109_wait_for_bootloader(usb_pid, 30);
|
||||
} else if (ports.size() > 1) {
|
||||
queue_message("Several VID/PID 0x2c99/%u devices found", usb_pid.boot);
|
||||
queue_error(_(L("Multiple %s devices found. Please only connect one at a time for flashing.")), dev_name);
|
||||
} else {
|
||||
if (ports[0].id_product == usb_pid.app) {
|
||||
// The device needs to be rebooted into the bootloader mode
|
||||
queue_message("Found VID/PID 0x2c99/%u at `%s`, rebooting the device ...", usb_pid.app, ports[0].port);
|
||||
avr109_reboot(ports[0]);
|
||||
avr109_wait_for_bootloader(usb_pid, 10);
|
||||
|
||||
if (! port) {
|
||||
// The device in bootloader mode was not found, inform the user and wait some more...
|
||||
queue_message("%s device not found after reboot", dev_name);
|
||||
queue_status(msg_not_found);
|
||||
avr109_wait_for_bootloader(usb_pid, 30);
|
||||
}
|
||||
} else {
|
||||
port = ports[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::prepare_common()
|
||||
{
|
||||
std::vector<std::string> args {{
|
||||
extra_verbose ? "-vvvvv" : "-v",
|
||||
"-p", "atmega2560",
|
||||
// Using the "Wiring" mode to program Rambo or Einsy, using the STK500v2 protocol (not the STK500).
|
||||
// The Prusa's avrdude is patched to never send semicolons inside the data packets, as the USB to serial chip
|
||||
// is flashed with a buggy firmware.
|
||||
"-c", "wiring",
|
||||
"-P", port->port,
|
||||
"-b", "115200", // TODO: Allow other rates? Ditto elsewhere.
|
||||
"-D",
|
||||
"-U", (boost::format("flash:w:0:%1%:i") % hex_file.path.string()).str(),
|
||||
}};
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Preparing arguments avrdude: "
|
||||
<< std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
|
||||
return a + ' ' + b;
|
||||
});
|
||||
|
||||
avrdude->push_args(std::move(args));
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::prepare_mk2()
|
||||
{
|
||||
if (! port) { return; }
|
||||
|
||||
if (! check_model_id()) {
|
||||
avrdude->cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
prepare_common();
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::prepare_mk3()
|
||||
{
|
||||
if (! port) { return; }
|
||||
|
||||
if (! check_model_id()) {
|
||||
avrdude->cancel();
|
||||
return;
|
||||
}
|
||||
|
||||
prepare_common();
|
||||
|
||||
// The hex file also contains another section with l10n data to be flashed into the external flash on MK3 (Einsy)
|
||||
// This is done via another avrdude invocation, here we build arg list for that:
|
||||
std::vector<std::string> args {{
|
||||
extra_verbose ? "-vvvvv" : "-v",
|
||||
"-p", "atmega2560",
|
||||
// Using the "Arduino" mode to program Einsy's external flash with languages, using the STK500 protocol (not the STK500v2).
|
||||
// The Prusa's avrdude is patched again to never send semicolons inside the data packets.
|
||||
"-c", "arduino",
|
||||
"-P", port->port,
|
||||
"-b", "115200",
|
||||
"-D",
|
||||
"-u", // disable safe mode
|
||||
"-U", (boost::format("flash:w:1:%1%:i") % hex_file.path.string()).str(),
|
||||
}};
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Preparing avrdude arguments for external flash flashing: "
|
||||
<< std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
|
||||
return a + ' ' + b;
|
||||
});
|
||||
|
||||
avrdude->push_args(std::move(args));
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::prepare_avr109(Avr109Pid usb_pid)
|
||||
{
|
||||
port = boost::none;
|
||||
avr109_lookup_port(usb_pid);
|
||||
if (! port) {
|
||||
queue_error(_(L("The %s device could not have been found")), avr109_dev_name(usb_pid));
|
||||
return;
|
||||
}
|
||||
|
||||
queue_message("Found VID/PID 0x2c99/%u at `%s`, flashing ...", usb_pid.boot, port->port);
|
||||
queue_status(label_status_flashing);
|
||||
|
||||
std::vector<std::string> args {{
|
||||
extra_verbose ? "-vvvvv" : "-v",
|
||||
"-p", "atmega32u4",
|
||||
"-c", "avr109",
|
||||
"-P", port->port,
|
||||
"-b", "57600",
|
||||
"-D",
|
||||
"-U", (boost::format("flash:w:0:%1%:i") % hex_file.path.string()).str(),
|
||||
}};
|
||||
|
||||
BOOST_LOG_TRIVIAL(info) << "Preparing avrdude arguments: "
|
||||
<< std::accumulate(std::next(args.begin()), args.end(), args[0], [](std::string a, const std::string &b) {
|
||||
return a + ' ' + b;
|
||||
});
|
||||
|
||||
avrdude->push_args(std::move(args));
|
||||
}
|
||||
|
||||
|
||||
bool FirmwareDialog::priv::get_serial_port()
|
||||
{
|
||||
const int selection = port_picker->GetSelection();
|
||||
if (selection != wxNOT_FOUND) {
|
||||
port = this->ports[selection];
|
||||
} else {
|
||||
// User has supplied a custom filename
|
||||
|
||||
std::string path_u8 = GUI::into_u8(port_picker->GetValue());
|
||||
#ifdef _WIN32
|
||||
static const std::regex com_pattern("COM[0-9]+", std::regex::icase);
|
||||
std::smatch matches;
|
||||
if (std::regex_match(path_u8, matches, com_pattern)) {
|
||||
#else
|
||||
if (fs::is_other(fs::path(path_u8))) {
|
||||
#endif
|
||||
port = SerialPortInfo(std::move(path_u8));
|
||||
} else {
|
||||
port = boost::none;
|
||||
}
|
||||
}
|
||||
|
||||
return !!port;
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::perform_upload()
|
||||
{
|
||||
auto filename = hex_picker->GetPath();
|
||||
if (filename.IsEmpty()) { return; }
|
||||
|
||||
load_hex_file(filename); // Might already be loaded, but we want to make sure it's fresh
|
||||
|
||||
if (!port_autodetect && !get_serial_port()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const bool extra_verbose = false; // For debugging
|
||||
|
||||
flashing_start(hex_file.device == HexFile::DEV_MK3 ? 2 : 1);
|
||||
|
||||
// Init the avrdude object
|
||||
AvrDude avrdude;
|
||||
|
||||
// It is ok here to use the q-pointer to the FirmwareDialog
|
||||
// because the dialog ensures it doesn't exit before the background thread is done.
|
||||
auto q = this->q;
|
||||
|
||||
avrdude
|
||||
.on_run([this](AvrDude::Ptr avrdude) {
|
||||
this->avrdude = std::move(avrdude);
|
||||
|
||||
try {
|
||||
switch (this->hex_file.device) {
|
||||
case HexFile::DEV_MK3:
|
||||
this->prepare_mk3();
|
||||
break;
|
||||
|
||||
case HexFile::DEV_MM_CONTROL:
|
||||
this->prepare_avr109(Avr109Pid(USB_PID_MMU_BOOT, USB_PID_MMU_APP));
|
||||
break;
|
||||
|
||||
case HexFile::DEV_CW1:
|
||||
this->prepare_avr109(Avr109Pid(USB_PID_CW1_BOOT, USB_PID_CW1_APP));
|
||||
break;
|
||||
|
||||
case HexFile::DEV_CW1S:
|
||||
this->prepare_avr109(Avr109Pid(USB_PID_CW1S_BOOT, USB_PID_CW1S_APP));
|
||||
break;
|
||||
|
||||
default:
|
||||
this->prepare_mk2();
|
||||
break;
|
||||
}
|
||||
} catch (const std::exception &ex) {
|
||||
if (port) {
|
||||
queue_error(_(L("Error accessing port at %s: %s")), port->port, ex.what());
|
||||
} else {
|
||||
queue_error(_(L("Error: %s")), ex.what());
|
||||
}
|
||||
}
|
||||
})
|
||||
.on_message([
|
||||
#ifndef __APPLE__
|
||||
// clang complains when capturing constants.
|
||||
extra_verbose,
|
||||
#endif // __APPLE__
|
||||
q](const char* msg, unsigned /* size */) {
|
||||
if (extra_verbose) {
|
||||
BOOST_LOG_TRIVIAL(debug) << "avrdude: " << msg;
|
||||
}
|
||||
|
||||
auto evt = new wxCommandEvent(EVT_AVRDUDE, q->GetId());
|
||||
auto wxmsg = wxString::FromUTF8(msg);
|
||||
#ifdef WIN32
|
||||
// The string might be in local encoding
|
||||
if (wxmsg.IsEmpty() && *msg != '\0') {
|
||||
wxmsg = wxString(msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
evt->SetExtraLong(AE_MESSAGE);
|
||||
evt->SetString(std::move(wxmsg));
|
||||
wxQueueEvent(q, evt);
|
||||
})
|
||||
.on_progress([q](const char * /* task */, unsigned progress) {
|
||||
auto evt = new wxCommandEvent(EVT_AVRDUDE, q->GetId());
|
||||
evt->SetExtraLong(AE_PROGRESS);
|
||||
evt->SetInt(progress);
|
||||
wxQueueEvent(q, evt);
|
||||
})
|
||||
.on_complete([this]() {
|
||||
auto evt = new wxCommandEvent(EVT_AVRDUDE, this->q->GetId());
|
||||
evt->SetExtraLong(AE_EXIT);
|
||||
evt->SetInt(this->avrdude->exit_code());
|
||||
wxQueueEvent(this->q, evt);
|
||||
})
|
||||
.run();
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::user_cancel()
|
||||
{
|
||||
if (avrdude) {
|
||||
user_cancelled = true;
|
||||
avrdude->cancel();
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::on_avrdude(const wxCommandEvent &evt)
|
||||
{
|
||||
AvrDudeComplete complete_kind;
|
||||
|
||||
switch (evt.GetExtraLong()) {
|
||||
case AE_MESSAGE:
|
||||
txt_stdout->AppendText(evt.GetString());
|
||||
break;
|
||||
|
||||
case AE_PROGRESS:
|
||||
// We try to track overall progress here.
|
||||
// Avrdude performs 3 tasks per one memory operation ("-U" arg),
|
||||
// first of which is reading of status data (very short).
|
||||
// We use the timer_pulse during the very first task to indicate intialization
|
||||
// and then display overall progress during the latter tasks.
|
||||
|
||||
if (progress_tasks_done > 0) {
|
||||
progressbar->SetValue(progress_tasks_bar + evt.GetInt());
|
||||
}
|
||||
|
||||
if (evt.GetInt() == 100) {
|
||||
timer_pulse.Stop();
|
||||
if (progress_tasks_done % 3 != 0) {
|
||||
progress_tasks_bar += 100;
|
||||
}
|
||||
progress_tasks_done++;
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case AE_EXIT:
|
||||
BOOST_LOG_TRIVIAL(info) << "avrdude exit code: " << evt.GetInt();
|
||||
|
||||
// Figure out the exit state
|
||||
if (user_cancelled) { complete_kind = AC_USER_CANCELLED; }
|
||||
else if (avrdude->cancelled()) { complete_kind = AC_NONE; } // Ie. cancelled programatically
|
||||
else { complete_kind = evt.GetInt() == 0 ? AC_SUCCESS : AC_FAILURE; }
|
||||
|
||||
flashing_done(complete_kind);
|
||||
ensure_joined();
|
||||
break;
|
||||
|
||||
case AE_STATUS:
|
||||
set_txt_status(evt.GetString());
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::on_async_dialog(const wxCommandEvent &evt)
|
||||
{
|
||||
//wxMessageDialog dlg(this->q, evt.GetString(), wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||
GUI::MessageDialog dlg(this->q, evt.GetString(), wxMessageBoxCaptionStr, wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mutex);
|
||||
modal_response = dlg.ShowModal();
|
||||
}
|
||||
response_cv.notify_all();
|
||||
}
|
||||
|
||||
void FirmwareDialog::priv::ensure_joined()
|
||||
{
|
||||
// Make sure the background thread is collected and the AvrDude object reset
|
||||
if (avrdude) { avrdude->join(); }
|
||||
avrdude.reset();
|
||||
}
|
||||
|
||||
const char* FirmwareDialog::priv::avr109_dev_name(Avr109Pid usb_pid) {
|
||||
switch (usb_pid.boot) {
|
||||
case USB_PID_MMU_BOOT:
|
||||
return "Original Prusa MMU 2.0 Control";
|
||||
case USB_PID_CW1_BOOT:
|
||||
return "Original Prusa CW1";
|
||||
case USB_PID_CW1S_BOOT:
|
||||
return "Original Prusa CW1S";
|
||||
default: throw Slic3r::RuntimeError((boost::format("Invalid avr109 device USB PID: %1%") % usb_pid.boot).str());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Public
|
||||
|
||||
FirmwareDialog::FirmwareDialog(wxWindow *parent) :
|
||||
GUI::DPIDialog(parent, wxID_ANY, _(L("Firmware flasher")), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER),
|
||||
p(new priv(this))
|
||||
{
|
||||
const int em = GUI::wxGetApp().em_unit();
|
||||
p->min_width = MIN_WIDTH * em;
|
||||
p->min_height = MIN_HEIGHT * em;
|
||||
p->min_height_expanded = MIN_HEIGHT_EXPANDED * em;
|
||||
|
||||
/* get current font from application,
|
||||
* because of wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) function
|
||||
* returns font for primary Display
|
||||
*/
|
||||
const wxFont& font = GUI::wxGetApp().normal_font();
|
||||
SetFont(font);
|
||||
wxFont status_font = font;//wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
status_font.MakeBold();
|
||||
wxFont mono_font = GUI::wxGetApp().code_font();
|
||||
mono_font.MakeSmaller();
|
||||
|
||||
// Create GUI components and layout
|
||||
|
||||
auto *panel = new wxPanel(this);
|
||||
wxBoxSizer *vsizer = new wxBoxSizer(wxVERTICAL);
|
||||
panel->SetSizer(vsizer);
|
||||
|
||||
auto *label_hex_picker = new wxStaticText(panel, wxID_ANY, _(L("Firmware image:")));
|
||||
p->hex_picker = new wxFilePickerCtrl(panel, wxID_ANY, wxEmptyString, wxFileSelectorPromptStr,
|
||||
"Hex files (*.hex)|*.hex|All files|*.*");
|
||||
p->hex_picker->GetPickerCtrl()->SetLabelText(_(L("Browse")));
|
||||
|
||||
auto *label_port_picker = new wxStaticText(panel, wxID_ANY, _(L("Serial port:")));
|
||||
p->port_picker = new wxComboBox(panel, wxID_ANY);
|
||||
p->txt_port_autodetect = new wxStaticText(panel, wxID_ANY, _(L("Autodetected")));
|
||||
p->btn_rescan = new wxButton(panel, wxID_ANY, _(L("Rescan")));
|
||||
auto *port_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
port_sizer->Add(p->port_picker, 1, wxEXPAND | wxRIGHT, SPACING);
|
||||
port_sizer->Add(p->btn_rescan, 0);
|
||||
port_sizer->Add(p->txt_port_autodetect, 1, wxEXPAND);
|
||||
p->set_autodetect(false);
|
||||
|
||||
auto *label_progress = new wxStaticText(panel, wxID_ANY, _(L("Progress:")));
|
||||
p->progressbar = new wxGauge(panel, wxID_ANY, 1, wxDefaultPosition, wxDefaultSize, wxGA_HORIZONTAL | wxGA_SMOOTH);
|
||||
|
||||
auto *label_status = new wxStaticText(panel, wxID_ANY, _(L("Status:")));
|
||||
p->txt_status = new wxStaticText(panel, wxID_ANY, _(L("Ready")));
|
||||
p->txt_status->SetFont(status_font);
|
||||
|
||||
auto *grid = new wxFlexGridSizer(2, SPACING, SPACING);
|
||||
grid->AddGrowableCol(1);
|
||||
|
||||
grid->Add(label_hex_picker, 0, wxALIGN_CENTER_VERTICAL);
|
||||
grid->Add(p->hex_picker, 0, wxEXPAND);
|
||||
|
||||
grid->Add(label_port_picker, 0, wxALIGN_CENTER_VERTICAL);
|
||||
grid->Add(port_sizer, 0, wxEXPAND);
|
||||
|
||||
grid->Add(label_progress, 0, wxALIGN_CENTER_VERTICAL);
|
||||
grid->Add(p->progressbar, 1, wxEXPAND | wxALIGN_CENTER_VERTICAL);
|
||||
|
||||
grid->Add(label_status, 0, wxALIGN_CENTER_VERTICAL);
|
||||
grid->Add(p->txt_status, 0, wxEXPAND);
|
||||
|
||||
vsizer->Add(grid, 0, wxEXPAND | wxTOP | wxBOTTOM, SPACING);
|
||||
|
||||
p->spoiler = new wxCollapsiblePane(panel, wxID_ANY, _(L("Advanced: Output log")), wxDefaultPosition, wxDefaultSize, wxCP_DEFAULT_STYLE | wxCP_NO_TLW_RESIZE);
|
||||
auto *spoiler_pane = p->spoiler->GetPane();
|
||||
auto *spoiler_sizer = new wxBoxSizer(wxVERTICAL);
|
||||
p->txt_stdout = new wxTextCtrl(spoiler_pane, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE | wxTE_READONLY);
|
||||
p->txt_stdout->SetFont(mono_font);
|
||||
spoiler_sizer->Add(p->txt_stdout, 1, wxEXPAND);
|
||||
spoiler_pane->SetSizer(spoiler_sizer);
|
||||
// The doc says proportion need to be 0 for wxCollapsiblePane.
|
||||
// Experience says it needs to be 1, otherwise things won't get sized properly.
|
||||
vsizer->Add(p->spoiler, 1, wxEXPAND | wxBOTTOM, SPACING);
|
||||
|
||||
p->btn_close = new wxButton(panel, wxID_CLOSE, _(L("Close"))); // Note: The label needs to be present, otherwise we get accelerator bugs on Mac
|
||||
p->btn_flash = new wxButton(panel, wxID_ANY, p->btn_flash_label_ready);
|
||||
p->btn_flash->Disable();
|
||||
auto *bsizer = new wxBoxSizer(wxHORIZONTAL);
|
||||
bsizer->Add(p->btn_close);
|
||||
bsizer->AddStretchSpacer();
|
||||
bsizer->Add(p->btn_flash);
|
||||
vsizer->Add(bsizer, 0, wxEXPAND);
|
||||
|
||||
GUI::wxGetApp().UpdateDlgDarkUI(this);
|
||||
|
||||
auto *topsizer = new wxBoxSizer(wxVERTICAL);
|
||||
topsizer->Add(panel, 1, wxEXPAND | wxALL, DIALOG_MARGIN);
|
||||
SetMinSize(wxSize(p->min_width, p->min_height));
|
||||
SetSizerAndFit(topsizer);
|
||||
const auto size = GetSize();
|
||||
SetSize(std::max(size.GetWidth(), static_cast<int>(p->min_width)), std::max(size.GetHeight(), static_cast<int>(p->min_height)));
|
||||
Layout();
|
||||
|
||||
SetEscapeId(wxID_CLOSE); // To close the dialog using "Esc" button
|
||||
|
||||
// Bind events
|
||||
|
||||
p->hex_picker->Bind(wxEVT_FILEPICKER_CHANGED, [this](wxFileDirPickerEvent& evt) {
|
||||
if (wxFileExists(evt.GetPath())) {
|
||||
this->p->load_hex_file(evt.GetPath());
|
||||
}
|
||||
p->update_flash_enabled();
|
||||
});
|
||||
|
||||
p->port_picker->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &) { p->update_flash_enabled(); });
|
||||
p->port_picker->Bind(wxEVT_TEXT, [this](wxCommandEvent &) { p->update_flash_enabled(); });
|
||||
|
||||
p->spoiler->Bind(wxEVT_COLLAPSIBLEPANE_CHANGED, [=](wxCollapsiblePaneEvent &evt) {
|
||||
if (evt.GetCollapsed()) {
|
||||
this->SetMinSize(wxSize(p->min_width, p->min_height));
|
||||
const auto new_height = this->GetSize().GetHeight() - this->p->txt_stdout->GetSize().GetHeight();
|
||||
this->SetSize(this->GetSize().GetWidth(), new_height);
|
||||
} else {
|
||||
this->SetMinSize(wxSize(p->min_width, p->min_height_expanded));
|
||||
}
|
||||
|
||||
this->Layout();
|
||||
this->p->fit_no_shrink();
|
||||
});
|
||||
|
||||
p->btn_rescan->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) { this->p->find_serial_ports(); });
|
||||
|
||||
p->btn_flash->Bind(wxEVT_BUTTON, [this](wxCommandEvent &) {
|
||||
if (this->p->avrdude) {
|
||||
// Flashing is in progress, ask the user if they're really sure about canceling it
|
||||
//wxMessageDialog dlg(this,
|
||||
GUI::MessageDialog dlg(this,
|
||||
_(L("Are you sure you want to cancel firmware flashing?\nThis could leave your printer in an unusable state!")),
|
||||
_(L("Confirmation")),
|
||||
wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION);
|
||||
if (dlg.ShowModal() == wxID_YES) {
|
||||
this->p->set_txt_status(_(L("Cancelling...")));
|
||||
this->p->user_cancel();
|
||||
}
|
||||
} else {
|
||||
// Start a flashing task
|
||||
this->p->perform_upload();
|
||||
}
|
||||
});
|
||||
|
||||
Bind(wxEVT_TIMER, [this](wxTimerEvent &evt) { this->p->progressbar->Pulse(); });
|
||||
|
||||
Bind(EVT_AVRDUDE, [this](wxCommandEvent &evt) { this->p->on_avrdude(evt); });
|
||||
Bind(EVT_ASYNC_DIALOG, [this](wxCommandEvent &evt) { this->p->on_async_dialog(evt); });
|
||||
|
||||
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent &evt) {
|
||||
if (this->p->avrdude) {
|
||||
evt.Veto();
|
||||
} else {
|
||||
this->EndModal(wxID_CLOSE);
|
||||
evt.Skip();
|
||||
}
|
||||
});
|
||||
|
||||
p->find_serial_ports();
|
||||
}
|
||||
|
||||
FirmwareDialog::~FirmwareDialog()
|
||||
{
|
||||
// Needed bacuse of forward defs
|
||||
}
|
||||
|
||||
void FirmwareDialog::run(wxWindow *parent)
|
||||
{
|
||||
FirmwareDialog dialog(parent);
|
||||
dialog.ShowModal();
|
||||
}
|
||||
|
||||
void FirmwareDialog::on_dpi_changed(const wxRect &suggested_rect)
|
||||
{
|
||||
const int& em = em_unit();
|
||||
|
||||
msw_buttons_rescale(this, em, { p->btn_close->GetId(),
|
||||
p->btn_rescan->GetId(),
|
||||
p->btn_flash->GetId(),
|
||||
p->hex_picker->GetPickerCtrl()->GetId()
|
||||
});
|
||||
|
||||
p->min_width = MIN_WIDTH * em;
|
||||
p->min_height = MIN_HEIGHT * em;
|
||||
p->min_height_expanded = MIN_HEIGHT_EXPANDED * em;
|
||||
|
||||
const int min_height = p->spoiler->IsExpanded() ? p->min_height_expanded : p->min_height;
|
||||
SetMinSize(wxSize(p->min_width, min_height));
|
||||
Fit();
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
}
|
|
@ -1,43 +0,0 @@
|
|||
#ifndef slic3r_FirmwareDialog_hpp_
|
||||
#define slic3r_FirmwareDialog_hpp_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include <wx/dialog.h>
|
||||
#include "GUI_Utils.hpp"
|
||||
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
|
||||
class FirmwareDialog: public GUI::DPIDialog
|
||||
{
|
||||
enum {
|
||||
DIALOG_MARGIN = 15,
|
||||
SPACING = 10,
|
||||
MIN_WIDTH = 50,
|
||||
MIN_HEIGHT = /*18*/25,
|
||||
MIN_HEIGHT_EXPANDED = 40,
|
||||
};
|
||||
|
||||
public:
|
||||
FirmwareDialog(wxWindow *parent);
|
||||
FirmwareDialog(FirmwareDialog &&) = delete;
|
||||
FirmwareDialog(const FirmwareDialog &) = delete;
|
||||
FirmwareDialog &operator=(FirmwareDialog &&) = delete;
|
||||
FirmwareDialog &operator=(const FirmwareDialog &) = delete;
|
||||
~FirmwareDialog();
|
||||
|
||||
static void run(wxWindow *parent);
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect &suggested_rect) override;
|
||||
private:
|
||||
struct priv;
|
||||
std::unique_ptr<priv> p;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
File diff suppressed because it is too large
Load diff
|
@ -1,227 +0,0 @@
|
|||
#ifndef slic3r_GUI_ObjectManipulation_hpp_
|
||||
#define slic3r_GUI_ObjectManipulation_hpp_
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "GUI_ObjectSettings.hpp"
|
||||
#include "GUI_ObjectList.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
#include <float.h>
|
||||
|
||||
#ifdef __WXOSX__
|
||||
class wxBitmapComboBox;
|
||||
#else
|
||||
class wxComboBox;
|
||||
#endif // __WXOSX__
|
||||
class wxStaticText;
|
||||
class LockButton;
|
||||
class wxStaticBitmap;
|
||||
class wxCheckBox;
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
#ifdef _WIN32
|
||||
class BitmapComboBox;
|
||||
#endif
|
||||
|
||||
#ifdef __WXOSX__
|
||||
static_assert(wxMAJOR_VERSION >= 3, "Use of wxBitmapComboBox on Manipulation panel requires wxWidgets 3.0 and newer");
|
||||
using choice_ctrl = wxBitmapComboBox;
|
||||
#else
|
||||
#ifdef _WIN32
|
||||
using choice_ctrl = BitmapComboBox;
|
||||
#else
|
||||
using choice_ctrl = wxComboBox;
|
||||
#endif
|
||||
#endif // __WXOSX__
|
||||
|
||||
class Selection;
|
||||
|
||||
class ObjectManipulation;
|
||||
class ManipulationEditor : public wxTextCtrl
|
||||
{
|
||||
std::string m_opt_key;
|
||||
int m_axis;
|
||||
bool m_enter_pressed { false };
|
||||
wxString m_valid_value {wxEmptyString};
|
||||
|
||||
std::string m_full_opt_name;
|
||||
|
||||
public:
|
||||
ManipulationEditor(ObjectManipulation* parent, const std::string& opt_key, int axis);
|
||||
~ManipulationEditor() {}
|
||||
|
||||
void msw_rescale();
|
||||
void sys_color_changed(ObjectManipulation* parent);
|
||||
void set_value(const wxString& new_value);
|
||||
void kill_focus(ObjectManipulation *parent);
|
||||
|
||||
private:
|
||||
double get_value();
|
||||
};
|
||||
|
||||
|
||||
class ObjectManipulation : public OG_Settings
|
||||
{
|
||||
public:
|
||||
static const double in_to_mm;
|
||||
static const double mm_to_in;
|
||||
|
||||
private:
|
||||
struct Cache
|
||||
{
|
||||
Vec3d position;
|
||||
Vec3d position_rounded;
|
||||
Vec3d rotation;
|
||||
Vec3d rotation_rounded;
|
||||
Vec3d scale;
|
||||
Vec3d scale_rounded;
|
||||
Vec3d size;
|
||||
Vec3d size_rounded;
|
||||
|
||||
wxString move_label_string;
|
||||
wxString rotate_label_string;
|
||||
wxString scale_label_string;
|
||||
|
||||
Cache() { reset(); }
|
||||
void reset()
|
||||
{
|
||||
position = position_rounded = Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
rotation = rotation_rounded = Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
scale = scale_rounded = Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
size = size_rounded = Vec3d(DBL_MAX, DBL_MAX, DBL_MAX);
|
||||
move_label_string = wxString();
|
||||
rotate_label_string = wxString();
|
||||
scale_label_string = wxString();
|
||||
}
|
||||
bool is_valid() const { return position != Vec3d(DBL_MAX, DBL_MAX, DBL_MAX); }
|
||||
};
|
||||
|
||||
Cache m_cache;
|
||||
|
||||
wxStaticText* m_move_Label = nullptr;
|
||||
wxStaticText* m_scale_Label = nullptr;
|
||||
wxStaticText* m_rotate_Label = nullptr;
|
||||
|
||||
bool m_imperial_units { false };
|
||||
bool m_use_colors { false };
|
||||
wxStaticText* m_position_unit { nullptr };
|
||||
wxStaticText* m_size_unit { nullptr };
|
||||
|
||||
wxStaticText* m_item_name = nullptr;
|
||||
wxStaticText* m_empty_str = nullptr;
|
||||
|
||||
// Non-owning pointers to the reset buttons, so we can hide and show them.
|
||||
ScalableButton* m_reset_scale_button = nullptr;
|
||||
ScalableButton* m_reset_rotation_button = nullptr;
|
||||
ScalableButton* m_drop_to_bed_button = nullptr;
|
||||
|
||||
wxCheckBox* m_check_inch {nullptr};
|
||||
|
||||
// Mirroring buttons and their current state
|
||||
enum MirrorButtonState {
|
||||
mbHidden,
|
||||
mbShown,
|
||||
mbActive
|
||||
};
|
||||
std::array<std::pair<ScalableButton*, MirrorButtonState>, 3> m_mirror_buttons;
|
||||
|
||||
// Bitmaps for the mirroring buttons.
|
||||
ScalableBitmap m_mirror_bitmap_on;
|
||||
ScalableBitmap m_mirror_bitmap_off;
|
||||
ScalableBitmap m_mirror_bitmap_hidden;
|
||||
|
||||
// Needs to be updated from OnIdle?
|
||||
bool m_dirty = false;
|
||||
// Cached labels for the delayed update, not localized!
|
||||
std::string m_new_move_label_string;
|
||||
std::string m_new_rotate_label_string;
|
||||
std::string m_new_scale_label_string;
|
||||
Vec3d m_new_position;
|
||||
Vec3d m_new_rotation;
|
||||
Vec3d m_new_scale;
|
||||
Vec3d m_new_size;
|
||||
bool m_new_enabled {true};
|
||||
bool m_uniform_scale {true};
|
||||
// Does the object manipulation panel work in World or Local coordinates?
|
||||
bool m_world_coordinates = true;
|
||||
LockButton* m_lock_bnt{ nullptr };
|
||||
choice_ctrl* m_word_local_combo { nullptr };
|
||||
|
||||
ScalableBitmap m_manifold_warning_bmp;
|
||||
wxStaticBitmap* m_fix_throught_netfab_bitmap;
|
||||
|
||||
#ifndef __APPLE__
|
||||
// Currently focused editor (nullptr if none)
|
||||
ManipulationEditor* m_focused_editor {nullptr};
|
||||
#endif // __APPLE__
|
||||
|
||||
wxFlexGridSizer* m_main_grid_sizer;
|
||||
wxFlexGridSizer* m_labels_grid_sizer;
|
||||
|
||||
// sizers, used for msw_rescale
|
||||
wxBoxSizer* m_word_local_combo_sizer;
|
||||
std::vector<wxBoxSizer*> m_rescalable_sizers;
|
||||
|
||||
std::vector<ManipulationEditor*> m_editors;
|
||||
|
||||
public:
|
||||
ObjectManipulation(wxWindow* parent);
|
||||
~ObjectManipulation() {}
|
||||
|
||||
void Show(const bool show) override;
|
||||
bool IsShown() override;
|
||||
void UpdateAndShow(const bool show) override;
|
||||
void update_ui_from_settings();
|
||||
bool use_colors() { return m_use_colors; }
|
||||
|
||||
void set_dirty() { m_dirty = true; }
|
||||
// Called from the App to update the UI if dirty.
|
||||
void update_if_dirty();
|
||||
|
||||
void set_uniform_scaling(const bool uniform_scale);
|
||||
bool get_uniform_scaling() const { return m_uniform_scale; }
|
||||
// Does the object manipulation panel work in World or Local coordinates?
|
||||
void set_world_coordinates(const bool world_coordinates) { m_world_coordinates = world_coordinates; this->UpdateAndShow(true); }
|
||||
bool get_world_coordinates() const { return m_world_coordinates; }
|
||||
|
||||
void reset_cache() { m_cache.reset(); }
|
||||
#ifndef __APPLE__
|
||||
// On Windows and Linux, emulates a kill focus event on the currently focused option (if any)
|
||||
// Used only in ObjectList wxEVT_DATAVIEW_SELECTION_CHANGED handler which is called before the regular kill focus event
|
||||
// bound to this class when changing selection in the objects list
|
||||
void emulate_kill_focus();
|
||||
#endif // __APPLE__
|
||||
|
||||
void update_item_name(const wxString &item_name);
|
||||
void update_warning_icon_state(const MeshErrorsInfo& warning);
|
||||
void msw_rescale();
|
||||
void sys_color_changed();
|
||||
void on_change(const std::string& opt_key, int axis, double new_value);
|
||||
void set_focused_editor(ManipulationEditor* focused_editor) {
|
||||
#ifndef __APPLE__
|
||||
m_focused_editor = focused_editor;
|
||||
#endif // __APPLE__
|
||||
}
|
||||
|
||||
private:
|
||||
void reset_settings_value();
|
||||
void update_settings_value(const Selection& selection);
|
||||
|
||||
// Show or hide scale/rotation reset buttons if needed
|
||||
void update_reset_buttons_visibility();
|
||||
//Show or hide mirror buttons
|
||||
void update_mirror_buttons_visibility();
|
||||
|
||||
// change values
|
||||
void change_position_value(int axis, double value);
|
||||
void change_rotation_value(int axis, double value);
|
||||
void change_scale_value(int axis, double value);
|
||||
void change_size_value(int axis, double value);
|
||||
void do_scale(int axis, const Vec3d &scale) const;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // slic3r_GUI_ObjectManipulation_hpp_
|
|
@ -1,600 +0,0 @@
|
|||
#include "GalleryDialog.hpp"
|
||||
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
#include <wx/sizer.h>
|
||||
#include <wx/stattext.h>
|
||||
#include <wx/textctrl.h>
|
||||
#include <wx/button.h>
|
||||
#include <wx/statbox.h>
|
||||
#include <wx/wupdlock.h>
|
||||
#include <wx/notebook.h>
|
||||
#include <wx/listctrl.h>
|
||||
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "format.hpp"
|
||||
#include "wxExtensions.hpp"
|
||||
#include "I18N.hpp"
|
||||
#include "Notebook.hpp"
|
||||
#include "3DScene.hpp"
|
||||
#include "GLCanvas3D.hpp"
|
||||
#include "Plater.hpp"
|
||||
#include "MsgDialog.hpp"
|
||||
#include "libslic3r/Utils.hpp"
|
||||
#include "libslic3r/AppConfig.hpp"
|
||||
#include "libslic3r/BuildVolume.hpp"
|
||||
#include "libslic3r/Model.hpp"
|
||||
#include "libslic3r/GCode/ThumbnailData.hpp"
|
||||
#include "libslic3r/Format/OBJ.hpp"
|
||||
#include "../Utils/MacDarkMode.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
#define BORDER_W 10
|
||||
#define IMG_PX_CNT 64
|
||||
|
||||
namespace fs = boost::filesystem;
|
||||
|
||||
// Gallery::DropTarget
|
||||
class GalleryDropTarget : public wxFileDropTarget
|
||||
{
|
||||
public:
|
||||
GalleryDropTarget(GalleryDialog* gallery_dlg) : gallery_dlg(gallery_dlg) { this->SetDefaultAction(wxDragCopy); }
|
||||
|
||||
bool OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames) override;
|
||||
|
||||
private:
|
||||
GalleryDialog* gallery_dlg {nullptr};
|
||||
};
|
||||
|
||||
bool GalleryDropTarget::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
|
||||
{
|
||||
#ifdef WIN32
|
||||
// hides the system icon
|
||||
this->MSWUpdateDragImageOnLeave();
|
||||
#endif // WIN32
|
||||
return gallery_dlg ? gallery_dlg->load_files(filenames) : false;
|
||||
}
|
||||
|
||||
|
||||
GalleryDialog::GalleryDialog(wxWindow* parent, bool modify_gallery/* = false*/) :
|
||||
DPIDialog(parent, wxID_ANY, _L("Shape Gallery"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
|
||||
#endif
|
||||
SetFont(wxGetApp().normal_font());
|
||||
|
||||
wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Select shape from the gallery") + ":");
|
||||
|
||||
m_list_ctrl = new wxListCtrl(this, wxID_ANY, wxDefaultPosition, wxSize(50 * wxGetApp().em_unit(), 35 * wxGetApp().em_unit()),
|
||||
wxLC_ICON | wxSIMPLE_BORDER);
|
||||
m_list_ctrl->Bind(wxEVT_LIST_ITEM_SELECTED, &GalleryDialog::select, this);
|
||||
m_list_ctrl->Bind(wxEVT_LIST_ITEM_DESELECTED, &GalleryDialog::deselect, this);
|
||||
m_list_ctrl->Bind(wxEVT_LIST_KEY_DOWN, &GalleryDialog::key_down, this);
|
||||
m_list_ctrl->Bind(wxEVT_LIST_ITEM_RIGHT_CLICK, &GalleryDialog::show_context_menu, this);
|
||||
m_list_ctrl->Bind(wxEVT_LIST_ITEM_ACTIVATED, [this](wxListEvent& event) {
|
||||
m_selected_items.clear();
|
||||
select(event);
|
||||
this->EndModal(wxID_OK);
|
||||
});
|
||||
#ifdef _WIN32
|
||||
this->Bind(wxEVT_SIZE, [this](wxSizeEvent& event) {
|
||||
event.Skip();
|
||||
m_list_ctrl->Arrange();
|
||||
});
|
||||
#endif
|
||||
|
||||
wxStdDialogButtonSizer* buttons = this->CreateStdDialogButtonSizer(wxOK | wxCLOSE);
|
||||
wxButton* ok_btn = static_cast<wxButton*>(FindWindowById(wxID_OK, this));
|
||||
ok_btn->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(!m_selected_items.empty()); });
|
||||
if (modify_gallery) {
|
||||
ok_btn->SetLabel(_L("Add to bed"));
|
||||
ok_btn->SetToolTip(_L("Add selected shape(s) to the bed"));
|
||||
}
|
||||
static_cast<wxButton*>(FindWindowById(wxID_CLOSE, this))->Bind(wxEVT_BUTTON, [this](wxCommandEvent&){ this->EndModal(wxID_CLOSE); });
|
||||
this->SetEscapeId(wxID_CLOSE);
|
||||
auto add_btn = [this, buttons]( size_t pos, int& ID, wxString title, wxString tooltip,
|
||||
void (GalleryDialog::* method)(wxEvent&),
|
||||
std::function<bool()> enable_fn = []() {return true; }) {
|
||||
ID = NewControlId();
|
||||
wxButton* btn = new wxButton(this, ID, title);
|
||||
btn->SetToolTip(tooltip);
|
||||
btn->Bind(wxEVT_UPDATE_UI, [enable_fn](wxUpdateUIEvent& evt) { evt.Enable(enable_fn()); });
|
||||
buttons->Insert(pos, btn, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT, BORDER_W);
|
||||
this->Bind(wxEVT_BUTTON, method, this, ID);
|
||||
};
|
||||
|
||||
size_t btn_pos = 0;
|
||||
add_btn(btn_pos++, ID_BTN_ADD_CUSTOM_SHAPE, _L("Add"), _L("Add one or more custom shapes"), &GalleryDialog::add_custom_shapes);
|
||||
add_btn(btn_pos++, ID_BTN_DEL_CUSTOM_SHAPE, _L("Delete"), _L("Delete one or more custom shape. You can't delete system shapes"), &GalleryDialog::del_custom_shapes, [this](){ return can_delete(); });
|
||||
//add_btn(btn_pos++, ID_BTN_REPLACE_CUSTOM_PNG, _L("Change thumbnail"), _L("Replace PNG for custom shape. You can't raplace thimbnail for system shape"), &GalleryDialog::change_thumbnail, [this](){ return can_change_thumbnail(); });
|
||||
buttons->InsertStretchSpacer(btn_pos, 2* BORDER_W);
|
||||
|
||||
load_label_icon_list();
|
||||
|
||||
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||
|
||||
topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W);
|
||||
topSizer->Add(m_list_ctrl, 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, BORDER_W);
|
||||
topSizer->Add(buttons , 0, wxEXPAND | wxALL, BORDER_W);
|
||||
|
||||
SetSizer(topSizer);
|
||||
topSizer->SetSizeHints(this);
|
||||
|
||||
wxGetApp().UpdateDlgDarkUI(this);
|
||||
this->CenterOnScreen();
|
||||
|
||||
this->SetDropTarget(new GalleryDropTarget(this));
|
||||
}
|
||||
|
||||
GalleryDialog::~GalleryDialog()
|
||||
{
|
||||
}
|
||||
|
||||
bool GalleryDialog::can_delete()
|
||||
{
|
||||
if (m_selected_items.empty())
|
||||
return false;
|
||||
for (const Item& item : m_selected_items)
|
||||
if (item.is_system)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool GalleryDialog::can_change_thumbnail()
|
||||
{
|
||||
return (m_selected_items.size() == 1 && !m_selected_items[0].is_system);
|
||||
}
|
||||
|
||||
void GalleryDialog::on_dpi_changed(const wxRect& suggested_rect)
|
||||
{
|
||||
const int& em = em_unit();
|
||||
|
||||
msw_buttons_rescale(this, em, { ID_BTN_ADD_CUSTOM_SHAPE, ID_BTN_DEL_CUSTOM_SHAPE, ID_BTN_REPLACE_CUSTOM_PNG, wxID_OK, wxID_CLOSE });
|
||||
|
||||
wxSize size = wxSize(50 * em, 35 * em);
|
||||
m_list_ctrl->SetMinSize(size);
|
||||
m_list_ctrl->SetSize(size);
|
||||
|
||||
Fit();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
static void add_lock(wxImage& image)
|
||||
{
|
||||
int lock_sz = 22;
|
||||
#ifdef __APPLE__
|
||||
lock_sz /= mac_max_scaling_factor();
|
||||
#endif
|
||||
wxBitmap bmp = create_scaled_bitmap("lock", nullptr, lock_sz);
|
||||
|
||||
wxImage lock_image = bmp.ConvertToImage();
|
||||
if (!lock_image.IsOk() || lock_image.GetWidth() == 0 || lock_image.GetHeight() == 0)
|
||||
return;
|
||||
|
||||
auto lock_px_data = (uint8_t*)lock_image.GetData();
|
||||
auto lock_a_data = (uint8_t*)lock_image.GetAlpha();
|
||||
int lock_width = lock_image.GetWidth();
|
||||
int lock_height = lock_image.GetHeight();
|
||||
|
||||
auto px_data = (uint8_t*)image.GetData();
|
||||
auto a_data = (uint8_t*)image.GetAlpha();
|
||||
|
||||
int width = image.GetWidth();
|
||||
int height = image.GetHeight();
|
||||
|
||||
size_t beg_x = width - lock_width;
|
||||
size_t beg_y = height - lock_height;
|
||||
for (size_t x = 0; x < (size_t)lock_width; ++x) {
|
||||
for (size_t y = 0; y < (size_t)lock_height; ++y) {
|
||||
const size_t lock_idx = (x + y * lock_width);
|
||||
if (lock_a_data && lock_a_data[lock_idx] == 0)
|
||||
continue;
|
||||
|
||||
const size_t idx = (beg_x + x + (beg_y + y) * width);
|
||||
if (a_data)
|
||||
a_data[idx] = lock_a_data[lock_idx];
|
||||
|
||||
const size_t idx_rgb = (beg_x + x + (beg_y + y) * width) * 3;
|
||||
const size_t lock_idx_rgb = (x + y * lock_width) * 3;
|
||||
px_data[idx_rgb] = lock_px_data[lock_idx_rgb];
|
||||
px_data[idx_rgb + 1] = lock_px_data[lock_idx_rgb + 1];
|
||||
px_data[idx_rgb + 2] = lock_px_data[lock_idx_rgb + 2];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void add_default_image(wxImageList* img_list, bool is_system)
|
||||
{
|
||||
int sz = IMG_PX_CNT;
|
||||
#ifdef __APPLE__
|
||||
sz /= mac_max_scaling_factor();
|
||||
#endif
|
||||
wxBitmap bmp = create_scaled_bitmap("cog", nullptr, sz, true);
|
||||
|
||||
if (is_system) {
|
||||
wxImage image = bmp.ConvertToImage();
|
||||
if (image.IsOk() && image.GetWidth() != 0 && image.GetHeight() != 0) {
|
||||
add_lock(image);
|
||||
bmp = wxBitmap(std::move(image));
|
||||
}
|
||||
}
|
||||
img_list->Add(bmp);
|
||||
};
|
||||
|
||||
static fs::path get_dir(bool sys_dir)
|
||||
{
|
||||
return fs::absolute(fs::path(sys_dir ? sys_shapes_dir() : custom_shapes_dir())).make_preferred();
|
||||
}
|
||||
|
||||
static std::string get_dir_path(bool sys_dir)
|
||||
{
|
||||
fs::path dir = get_dir(sys_dir);
|
||||
#ifdef __WXMSW__
|
||||
return dir.string() + "\\";
|
||||
#else
|
||||
return dir.string() + "/";
|
||||
#endif
|
||||
}
|
||||
|
||||
static void generate_thumbnail_from_model(const std::string& filename)
|
||||
{
|
||||
if (!boost::algorithm::iends_with(filename, ".stl") &&
|
||||
!boost::algorithm::iends_with(filename, ".obj")) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Found invalid file type in generate_thumbnail_from_model() [" << filename << "]";
|
||||
return;
|
||||
}
|
||||
|
||||
Model model;
|
||||
try {
|
||||
model = Model::read_from_file(filename);
|
||||
}
|
||||
catch (std::exception&) {
|
||||
BOOST_LOG_TRIVIAL(error) << "Error loading model from " << filename << " in generate_thumbnail_from_model()";
|
||||
return;
|
||||
}
|
||||
|
||||
assert(model.objects.size() == 1);
|
||||
assert(model.objects[0]->volumes.size() == 1);
|
||||
assert(model.objects[0]->instances.size() == 1);
|
||||
|
||||
model.objects[0]->center_around_origin(false);
|
||||
model.objects[0]->ensure_on_bed(false);
|
||||
|
||||
model.center_instances_around_point(to_2d(wxGetApp().plater()->build_volume().bounding_volume().center()));
|
||||
|
||||
GLVolumeCollection volumes;
|
||||
volumes.volumes.push_back(new GLVolume());
|
||||
GLVolume* volume = volumes.volumes[0];
|
||||
volume->indexed_vertex_array.load_mesh(model.mesh());
|
||||
volume->indexed_vertex_array.finalize_geometry(true);
|
||||
volume->set_instance_transformation(model.objects[0]->instances[0]->get_transformation());
|
||||
volume->set_volume_transformation(model.objects[0]->volumes[0]->get_transformation());
|
||||
|
||||
ThumbnailData thumbnail_data;
|
||||
const ThumbnailsParams thumbnail_params = { {}, false, false, false, true };
|
||||
wxGetApp().plater()->canvas3D()->render_thumbnail(thumbnail_data, 256, 256, thumbnail_params, volumes, Camera::EType::Perspective);
|
||||
|
||||
if (thumbnail_data.width == 0 || thumbnail_data.height == 0)
|
||||
return;
|
||||
|
||||
wxImage image(thumbnail_data.width, thumbnail_data.height);
|
||||
image.InitAlpha();
|
||||
|
||||
for (unsigned int r = 0; r < thumbnail_data.height; ++r) {
|
||||
unsigned int rr = (thumbnail_data.height - 1 - r) * thumbnail_data.width;
|
||||
for (unsigned int c = 0; c < thumbnail_data.width; ++c) {
|
||||
unsigned char* px = (unsigned char*)thumbnail_data.pixels.data() + 4 * (rr + c);
|
||||
image.SetRGB((int)c, (int)r, px[0], px[1], px[2]);
|
||||
image.SetAlpha((int)c, (int)r, px[3]);
|
||||
}
|
||||
}
|
||||
|
||||
fs::path out_path = fs::path(filename);
|
||||
out_path.replace_extension("png");
|
||||
image.SaveFile(out_path.string(), wxBITMAP_TYPE_PNG);
|
||||
}
|
||||
|
||||
void GalleryDialog::load_label_icon_list()
|
||||
{
|
||||
// load names from files
|
||||
auto add_files_from_gallery = [](std::vector<Item>& items, bool is_sys_dir, std::string& dir_path)
|
||||
{
|
||||
fs::path dir = get_dir(is_sys_dir);
|
||||
if (!fs::exists(dir))
|
||||
return;
|
||||
|
||||
dir_path = get_dir_path(is_sys_dir);
|
||||
|
||||
std::vector<std::string> sorted_names;
|
||||
for (auto& dir_entry : fs::directory_iterator(dir)) {
|
||||
TriangleMesh mesh;
|
||||
if ((is_gallery_file(dir_entry, ".stl") && mesh.ReadSTLFile(dir_entry.path().string().c_str())) ||
|
||||
(is_gallery_file(dir_entry, ".obj") && load_obj(dir_entry.path().string().c_str(), &mesh) ) )
|
||||
sorted_names.push_back(dir_entry.path().filename().string());
|
||||
}
|
||||
|
||||
// sort the filename case insensitive
|
||||
std::sort(sorted_names.begin(), sorted_names.end(), [](const std::string& a, const std::string& b)
|
||||
{ return boost::algorithm::to_lower_copy(a) < boost::algorithm::to_lower_copy(b); });
|
||||
|
||||
for (const std::string& name : sorted_names)
|
||||
items.push_back(Item{ name, is_sys_dir });
|
||||
};
|
||||
|
||||
wxBusyCursor busy;
|
||||
|
||||
std::string m_sys_dir_path, m_cust_dir_path;
|
||||
std::vector<Item> list_items;
|
||||
add_files_from_gallery(list_items, true, m_sys_dir_path);
|
||||
add_files_from_gallery(list_items, false, m_cust_dir_path);
|
||||
|
||||
// Make an image list containing large icons
|
||||
|
||||
int px_cnt = (int)(em_unit() * IMG_PX_CNT * 0.1f + 0.5f);
|
||||
m_image_list = new wxImageList(px_cnt, px_cnt);
|
||||
|
||||
std::string ext = ".png";
|
||||
|
||||
for (const auto& item : list_items) {
|
||||
fs::path model_path = fs::path((item.is_system ? m_sys_dir_path : m_cust_dir_path) + item.name);
|
||||
std::string model_name = model_path.string();
|
||||
model_path.replace_extension("png");
|
||||
std::string img_name = model_path.string();
|
||||
|
||||
#if 0 // use "1" just in DEBUG mode to the generation of the thumbnails for the sistem shapes
|
||||
bool can_generate_thumbnail = true;
|
||||
#else
|
||||
bool can_generate_thumbnail = !item.is_system;
|
||||
#endif //DEBUG
|
||||
if (!fs::exists(img_name)) {
|
||||
if (can_generate_thumbnail)
|
||||
generate_thumbnail_from_model(model_name);
|
||||
else {
|
||||
add_default_image(m_image_list, item.is_system);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
wxImage image;
|
||||
if (!image.CanRead(from_u8(img_name)) ||
|
||||
!image.LoadFile(from_u8(img_name), wxBITMAP_TYPE_PNG) ||
|
||||
image.GetWidth() == 0 || image.GetHeight() == 0) {
|
||||
add_default_image(m_image_list, item.is_system);
|
||||
continue;
|
||||
}
|
||||
image.Rescale(px_cnt, px_cnt, wxIMAGE_QUALITY_BILINEAR);
|
||||
|
||||
if (item.is_system)
|
||||
add_lock(image);
|
||||
wxBitmap bmp = wxBitmap(std::move(image));
|
||||
m_image_list->Add(bmp);
|
||||
}
|
||||
|
||||
m_list_ctrl->SetImageList(m_image_list, wxIMAGE_LIST_NORMAL);
|
||||
|
||||
int img_cnt = m_image_list->GetImageCount();
|
||||
for (int i = 0; i < img_cnt; i++) {
|
||||
m_list_ctrl->InsertItem(i, from_u8(list_items[i].name), i);
|
||||
if (list_items[i].is_system)
|
||||
m_list_ctrl->SetItemFont(i, wxGetApp().bold_font());
|
||||
}
|
||||
}
|
||||
|
||||
void GalleryDialog::get_input_files(wxArrayString& input_files)
|
||||
{
|
||||
for (const Item& item : m_selected_items)
|
||||
input_files.Add(from_u8(get_dir_path(item.is_system) + item.name));
|
||||
}
|
||||
|
||||
void GalleryDialog::add_custom_shapes(wxEvent& event)
|
||||
{
|
||||
wxArrayString input_files;
|
||||
wxFileDialog dialog(this, _L("Choose one or more files (STL, OBJ):"),
|
||||
from_u8(wxGetApp().app_config->get_last_dir()), "",
|
||||
file_wildcards(FT_GALLERY), wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST);
|
||||
|
||||
if (dialog.ShowModal() == wxID_OK)
|
||||
dialog.GetPaths(input_files);
|
||||
|
||||
if (input_files.IsEmpty())
|
||||
return;
|
||||
|
||||
load_files(input_files);
|
||||
}
|
||||
|
||||
void GalleryDialog::del_custom_shapes()
|
||||
{
|
||||
auto custom_dir = get_dir(false);
|
||||
|
||||
auto remove_file = [custom_dir](const std::string& name) {
|
||||
if (!fs::exists(custom_dir / name))
|
||||
return;
|
||||
try {
|
||||
fs::remove(custom_dir / name);
|
||||
}
|
||||
catch (fs::filesystem_error const& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
for (const Item& item : m_selected_items) {
|
||||
remove_file(item.name);
|
||||
fs::path path = fs::path(item.name);
|
||||
path.replace_extension("png");
|
||||
remove_file(path.string());
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
static void show_warning(const wxString& title, const std::string& error_file_type)
|
||||
{
|
||||
const wxString msg_text = format_wxstr(_L("It looks like selected %1%-file has an error or is destructed.\n"
|
||||
"We can't load this file"), error_file_type);
|
||||
MessageDialog dialog(nullptr, msg_text, title, wxICON_WARNING | wxOK);
|
||||
dialog.ShowModal();
|
||||
}
|
||||
|
||||
void GalleryDialog::change_thumbnail()
|
||||
{
|
||||
if (m_selected_items.size() != 1 || m_selected_items[0].is_system)
|
||||
return;
|
||||
|
||||
wxFileDialog dialog(this, _L("Choose one PNG file:"),
|
||||
from_u8(wxGetApp().app_config->get_last_dir()), "",
|
||||
"PNG files (*.png)|*.png;*.PNG", wxFD_OPEN | wxFD_FILE_MUST_EXIST);
|
||||
if (dialog.ShowModal() != wxID_OK)
|
||||
return;
|
||||
|
||||
wxArrayString input_files;
|
||||
dialog.GetPaths(input_files);
|
||||
|
||||
if (input_files.IsEmpty())
|
||||
return;
|
||||
|
||||
if (wxImage image; !image.CanRead(input_files.Item(0))) {
|
||||
show_warning(_L("Replacing of the PNG"), "PNG");
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
fs::path png_path = fs::path(get_dir(false) / m_selected_items[0].name);
|
||||
png_path.replace_extension("png");
|
||||
|
||||
fs::path current = fs::path(into_u8(input_files.Item(0)));
|
||||
fs::copy_file(current, png_path, fs::copy_option::overwrite_if_exists);
|
||||
}
|
||||
catch (fs::filesystem_error const& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return;
|
||||
}
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
void GalleryDialog::select(wxListEvent& event)
|
||||
{
|
||||
int idx = event.GetIndex();
|
||||
Item item { into_u8(m_list_ctrl->GetItemText(idx)), m_list_ctrl->GetItemFont(idx).GetWeight() == wxFONTWEIGHT_BOLD };
|
||||
|
||||
m_selected_items.push_back(item);
|
||||
}
|
||||
|
||||
void GalleryDialog::deselect(wxListEvent& event)
|
||||
{
|
||||
if (m_list_ctrl->GetSelectedItemCount() == 0) {
|
||||
m_selected_items.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
std::string name = into_u8(m_list_ctrl->GetItemText(event.GetIndex()));
|
||||
m_selected_items.erase(std::remove_if(m_selected_items.begin(), m_selected_items.end(), [name](Item item) { return item.name == name; }));
|
||||
}
|
||||
|
||||
void GalleryDialog::show_context_menu(wxListEvent& event)
|
||||
{
|
||||
wxMenu* menu = new wxMenu();
|
||||
if (can_delete())
|
||||
append_menu_item(menu, wxID_ANY, _L("Delete"), "", [this](wxCommandEvent&) { del_custom_shapes(); });
|
||||
if (can_change_thumbnail())
|
||||
append_menu_item(menu, wxID_ANY, _L("Change thumbnail"), "", [this](wxCommandEvent&) { change_thumbnail(); });
|
||||
|
||||
this->PopupMenu(menu);
|
||||
}
|
||||
|
||||
void GalleryDialog::key_down(wxListEvent& event)
|
||||
{
|
||||
if (can_delete() && (event.GetKeyCode() == WXK_DELETE || event.GetKeyCode() == WXK_BACK))
|
||||
del_custom_shapes();
|
||||
}
|
||||
|
||||
void GalleryDialog::update()
|
||||
{
|
||||
m_selected_items.clear();
|
||||
m_image_list->RemoveAll();
|
||||
m_list_ctrl->ClearAll();
|
||||
load_label_icon_list();
|
||||
}
|
||||
|
||||
bool GalleryDialog::load_files(const wxArrayString& input_files)
|
||||
{
|
||||
auto dest_dir = get_dir(false);
|
||||
|
||||
try {
|
||||
if (!fs::exists(dest_dir))
|
||||
if (!fs::create_directory(dest_dir)) {
|
||||
std::cerr << "Unable to create destination directory" << dest_dir.string() << '\n' ;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (fs::filesystem_error const& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
// Iterate through the input files
|
||||
for (size_t i = 0; i < input_files.size(); ++i) {
|
||||
std::string input_file = into_u8(input_files.Item(i));
|
||||
|
||||
TriangleMesh mesh;
|
||||
if (is_gallery_file(input_file, ".stl") && !mesh.ReadSTLFile(input_file.c_str())) {
|
||||
show_warning(format_wxstr(_L("Loading of the \"%1%\""), input_file), "STL");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_gallery_file(input_file, ".obj") && !load_obj(input_file.c_str(), &mesh)) {
|
||||
show_warning(format_wxstr(_L("Loading of the \"%1%\""), input_file), "OBJ");
|
||||
continue;
|
||||
}
|
||||
|
||||
try {
|
||||
fs::path current = fs::path(input_file);
|
||||
if (!fs::exists(dest_dir / current.filename()))
|
||||
fs::copy_file(current, dest_dir / current.filename());
|
||||
else {
|
||||
std::string filename = current.stem().string();
|
||||
|
||||
int file_idx = 0;
|
||||
for (auto& dir_entry : fs::directory_iterator(dest_dir))
|
||||
if (is_gallery_file(dir_entry, ".stl") || is_gallery_file(dir_entry, ".obj")) {
|
||||
std::string name = dir_entry.path().stem().string();
|
||||
if (filename == name) {
|
||||
if (file_idx == 0)
|
||||
file_idx++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (name.find(filename) != 0 ||
|
||||
name[filename.size()] != ' ' || name[filename.size()+1] != '(' || name[name.size()-1] != ')')
|
||||
continue;
|
||||
std::string idx_str = name.substr(filename.size() + 2, name.size() - filename.size() - 3);
|
||||
if (int cur_idx = atoi(idx_str.c_str()); file_idx <= cur_idx)
|
||||
file_idx = cur_idx+1;
|
||||
}
|
||||
if (file_idx > 0) {
|
||||
filename += " (" + std::to_string(file_idx) + ")." + (is_gallery_file(input_file, ".stl") ? "stl" : "obj");
|
||||
fs::copy_file(current, dest_dir / filename);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (fs::filesystem_error const& e) {
|
||||
std::cerr << e.what() << '\n';
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
update();
|
||||
return true;
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GUI
|
|
@ -1,66 +0,0 @@
|
|||
#ifndef slic3r_GalleryDialog_hpp_
|
||||
#define slic3r_GalleryDialog_hpp_
|
||||
|
||||
#include "GUI_Utils.hpp"
|
||||
|
||||
class wxListCtrl;
|
||||
class wxImageList;
|
||||
class wxListEvent;
|
||||
|
||||
namespace Slic3r {
|
||||
|
||||
namespace GUI {
|
||||
|
||||
|
||||
//------------------------------------------
|
||||
// GalleryDialog
|
||||
//------------------------------------------
|
||||
|
||||
class GalleryDialog : public DPIDialog
|
||||
{
|
||||
wxListCtrl* m_list_ctrl { nullptr };
|
||||
wxImageList* m_image_list { nullptr };
|
||||
|
||||
struct Item {
|
||||
std::string name;
|
||||
bool is_system;
|
||||
};
|
||||
std::vector<Item> m_selected_items;
|
||||
|
||||
int ID_BTN_ADD_CUSTOM_SHAPE;
|
||||
int ID_BTN_DEL_CUSTOM_SHAPE;
|
||||
int ID_BTN_REPLACE_CUSTOM_PNG;
|
||||
|
||||
void load_label_icon_list();
|
||||
void add_custom_shapes(wxEvent& event);
|
||||
void del_custom_shapes();
|
||||
void del_custom_shapes(wxEvent& event) { del_custom_shapes(); }
|
||||
void change_thumbnail();
|
||||
void change_thumbnail(wxEvent& event) { change_thumbnail(); }
|
||||
void select(wxListEvent& event);
|
||||
void deselect(wxListEvent& event);
|
||||
void show_context_menu(wxListEvent& event);
|
||||
void key_down(wxListEvent& event);
|
||||
|
||||
bool can_delete();
|
||||
bool can_change_thumbnail();
|
||||
|
||||
void update();
|
||||
|
||||
public:
|
||||
GalleryDialog(wxWindow* parent, bool modify_gallery = false);
|
||||
~GalleryDialog();
|
||||
|
||||
void get_input_files(wxArrayString& input_files);
|
||||
bool load_files(const wxArrayString& input_files);
|
||||
|
||||
protected:
|
||||
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||
void on_sys_color_changed() override {};
|
||||
};
|
||||
|
||||
|
||||
} // namespace GUI
|
||||
} // namespace Slic3r
|
||||
|
||||
#endif //slic3r_GalleryDialog_hpp_
|
|
@ -1,292 +0,0 @@
|
|||
#include <algorithm>
|
||||
#include <wx/dcbuffer.h>
|
||||
|
||||
#include "RammingChart.hpp"
|
||||
#include "GUI.hpp"
|
||||
#include "GUI_App.hpp"
|
||||
#include "I18N.hpp"
|
||||
|
||||
wxDEFINE_EVENT(EVT_WIPE_TOWER_CHART_CHANGED, wxCommandEvent);
|
||||
|
||||
|
||||
void Chart::draw() {
|
||||
wxAutoBufferedPaintDC dc(this); // unbuffered DC caused flickering on win
|
||||
|
||||
dc.SetBrush(GetBackgroundColour());
|
||||
dc.SetPen(GetBackgroundColour());
|
||||
dc.DrawRectangle(GetClientRect()); // otherwise the background would end up black on windows
|
||||
|
||||
#ifdef _WIN32
|
||||
dc.SetPen(wxPen(GetForegroundColour()));
|
||||
dc.SetBrush(wxBrush(Slic3r::GUI::wxGetApp().get_highlight_default_clr()));
|
||||
#else
|
||||
dc.SetPen(*wxBLACK_PEN);
|
||||
dc.SetBrush(*wxWHITE_BRUSH);
|
||||
#endif
|
||||
dc.DrawRectangle(m_rect);
|
||||
|
||||
if (visible_area.m_width < 0.499) {
|
||||
dc.DrawText(_(L("NO RAMMING AT ALL")),wxPoint(m_rect.GetLeft()+m_rect.GetWidth()/2-legend_side,m_rect.GetBottom()-m_rect.GetHeight()/2));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (!m_line_to_draw.empty()) {
|
||||
for (unsigned int i=0;i<m_line_to_draw.size()-2;++i) {
|
||||
int color = 510*((m_rect.GetBottom()-(m_line_to_draw)[i])/double(m_rect.GetHeight()));
|
||||
dc.SetPen( wxPen( wxColor(std::min(255,color),255-std::max(color-255,0),0), 1 ) );
|
||||
dc.DrawLine(m_rect.GetLeft()+1+i,(m_line_to_draw)[i],m_rect.GetLeft()+1+i,m_rect.GetBottom());
|
||||
}
|
||||
#ifdef _WIN32
|
||||
dc.SetPen(wxPen(GetForegroundColour()));
|
||||
#else
|
||||
dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
|
||||
#endif
|
||||
for (unsigned int i=0;i<m_line_to_draw.size()-2;++i) {
|
||||
if (splines)
|
||||
dc.DrawLine(m_rect.GetLeft()+i,(m_line_to_draw)[i],m_rect.GetLeft()+i+1,(m_line_to_draw)[i+1]);
|
||||
else {
|
||||
dc.DrawLine(m_rect.GetLeft()+i,(m_line_to_draw)[i],m_rect.GetLeft()+i+1,(m_line_to_draw)[i]);
|
||||
dc.DrawLine(m_rect.GetLeft()+i+1,(m_line_to_draw)[i],m_rect.GetLeft()+i+1,(m_line_to_draw)[i+1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// draw draggable buttons
|
||||
dc.SetBrush(*wxBLUE_BRUSH);
|
||||
#ifdef _WIN32
|
||||
dc.SetPen(wxPen(GetForegroundColour()));
|
||||
#else
|
||||
dc.SetPen( wxPen( wxColor(0,0,0), 1 ) );
|
||||
#endif
|
||||
for (auto& button : m_buttons)
|
||||
//dc.DrawRectangle(math_to_screen(button.get_pos())-wxPoint(side/2.,side/2.), wxSize(side,side));
|
||||
dc.DrawCircle(math_to_screen(button.get_pos()),side/2.);
|
||||
//dc.DrawRectangle(math_to_screen(button.get_pos()-wxPoint2DDouble(0.125,0))-wxPoint(0,5),wxSize(50,10));
|
||||
|
||||
// draw x-axis:
|
||||
float last_mark = -10000;
|
||||
for (float math_x=int(visible_area.m_x*10)/10 ; math_x < (visible_area.m_x+visible_area.m_width) ; math_x+=0.1f) {
|
||||
int x = math_to_screen(wxPoint2DDouble(math_x,visible_area.m_y)).x;
|
||||
int y = m_rect.GetBottom();
|
||||
if (x-last_mark < legend_side) continue;
|
||||
dc.DrawLine(x,y+3,x,y-3);
|
||||
dc.DrawText(wxString().Format(wxT("%.1f"), math_x),wxPoint(x-scale_unit,y+0.5*scale_unit));
|
||||
last_mark = x;
|
||||
}
|
||||
|
||||
// draw y-axis:
|
||||
last_mark=10000;
|
||||
for (int math_y=visible_area.m_y ; math_y < (visible_area.m_y+visible_area.m_height) ; math_y+=1) {
|
||||
int y = math_to_screen(wxPoint2DDouble(visible_area.m_x,math_y)).y;
|
||||
int x = m_rect.GetLeft();
|
||||
if (last_mark-y < legend_side) continue;
|
||||
dc.DrawLine(x-3,y,x+3,y);
|
||||
dc.DrawText(wxString()<<math_y,wxPoint(x-2*scale_unit,y-0.5*scale_unit));
|
||||
last_mark = y;
|
||||
}
|
||||
|
||||
// axis labels:
|
||||
wxString label = _(L("Time")) + " ("+_(L("s"))+")";
|
||||
int text_width = 0;
|
||||
int text_height = 0;
|
||||
dc.GetTextExtent(label,&text_width,&text_height);
|
||||
dc.DrawText(label,wxPoint(0.5*(m_rect.GetRight()+m_rect.GetLeft())-text_width/2.f, m_rect.GetBottom()+0.5*legend_side));
|
||||
label = _(L("Volumetric speed")) + " (" + _(L("mm³/s")) + ")";
|
||||
dc.GetTextExtent(label,&text_width,&text_height);
|
||||
dc.DrawRotatedText(label,wxPoint(0,0.5*(m_rect.GetBottom()+m_rect.GetTop())+text_width/2.f),90);
|
||||
}
|
||||
|
||||
void Chart::mouse_right_button_clicked(wxMouseEvent& event) {
|
||||
if (!manual_points_manipulation)
|
||||
return;
|
||||
wxPoint point = event.GetPosition();
|
||||
int button_index = which_button_is_clicked(point);
|
||||
if (button_index != -1 && m_buttons.size()>2) {
|
||||
m_buttons.erase(m_buttons.begin()+button_index);
|
||||
recalculate_line();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Chart::mouse_clicked(wxMouseEvent& event) {
|
||||
wxPoint point = event.GetPosition();
|
||||
int button_index = which_button_is_clicked(point);
|
||||
if ( button_index != -1) {
|
||||
m_dragged = &m_buttons[button_index];
|
||||
m_previous_mouse = point;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Chart::mouse_moved(wxMouseEvent& event) {
|
||||
if (!event.Dragging() || !m_dragged) return;
|
||||
wxPoint pos = event.GetPosition();
|
||||
wxRect rect = m_rect;
|
||||
rect.Deflate(side/2.);
|
||||
if (!(rect.Contains(pos))) { // the mouse left chart area
|
||||
mouse_left_window(event);
|
||||
return;
|
||||
}
|
||||
int delta_x = pos.x - m_previous_mouse.x;
|
||||
int delta_y = pos.y - m_previous_mouse.y;
|
||||
m_dragged->move(fixed_x?0:double(delta_x)/m_rect.GetWidth() * visible_area.m_width,-double(delta_y)/m_rect.GetHeight() * visible_area.m_height);
|
||||
m_previous_mouse = pos;
|
||||
recalculate_line();
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Chart::mouse_double_clicked(wxMouseEvent& event) {
|
||||
if (!manual_points_manipulation)
|
||||
return;
|
||||
wxPoint point = event.GetPosition();
|
||||
if (!m_rect.Contains(point)) // the click is outside the chart
|
||||
return;
|
||||
m_buttons.push_back(screen_to_math(point));
|
||||
std::sort(m_buttons.begin(),m_buttons.end());
|
||||
recalculate_line();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void Chart::recalculate_line() {
|
||||
m_line_to_draw.clear();
|
||||
m_total_volume = 0.f;
|
||||
|
||||
std::vector<wxPoint> points;
|
||||
for (auto& but : m_buttons) {
|
||||
points.push_back(wxPoint(math_to_screen(but.get_pos())));
|
||||
if (points.size()>1 && points.back().x==points[points.size()-2].x) points.pop_back();
|
||||
if (points.size()>1 && points.back().x > m_rect.GetRight()) {
|
||||
points.pop_back();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// The calculation wouldn't work in case the ramming is to be turned off completely.
|
||||
if (points.size()>1) {
|
||||
std::sort(points.begin(),points.end(),[](wxPoint& a,wxPoint& b) { return a.x < b.x; });
|
||||
|
||||
// Cubic spline interpolation: see https://en.wikiversity.org/wiki/Cubic_Spline_Interpolation#Methods
|
||||
const bool boundary_first_derivative = true; // true - first derivative is 0 at the leftmost and rightmost point
|
||||
// false - second ---- || -------
|
||||
const int N = points.size()-1; // last point can be accessed as N, we have N+1 total points
|
||||
std::vector<float> diag(N+1);
|
||||
std::vector<float> mu(N+1);
|
||||
std::vector<float> lambda(N+1);
|
||||
std::vector<float> h(N+1);
|
||||
std::vector<float> rhs(N+1);
|
||||
|
||||
// let's fill in inner equations
|
||||
for (int i=1;i<=N;++i) h[i] = points[i].x-points[i-1].x;
|
||||
std::fill(diag.begin(),diag.end(),2.f);
|
||||
for (int i=1;i<=N-1;++i) {
|
||||
mu[i] = h[i]/(h[i]+h[i+1]);
|
||||
lambda[i] = 1.f - mu[i];
|
||||
rhs[i] = 6 * ( float(points[i+1].y-points[i].y )/(h[i+1]*(points[i+1].x-points[i-1].x)) -
|
||||
float(points[i].y -points[i-1].y)/(h[i] *(points[i+1].x-points[i-1].x)) );
|
||||
}
|
||||
|
||||
// now fill in the first and last equations, according to boundary conditions:
|
||||
if (boundary_first_derivative) {
|
||||
const float endpoints_derivative = 0;
|
||||
lambda[0] = 1;
|
||||
mu[N] = 1;
|
||||
rhs[0] = (6.f/h[1]) * (float(points[0].y-points[1].y)/(points[0].x-points[1].x) - endpoints_derivative);
|
||||
rhs[N] = (6.f/h[N]) * (endpoints_derivative - float(points[N-1].y-points[N].y)/(points[N-1].x-points[N].x));
|
||||
}
|
||||
else {
|
||||
lambda[0] = 0;
|
||||
mu[N] = 0;
|
||||
rhs[0] = 0;
|
||||
rhs[N] = 0;
|
||||
}
|
||||
|
||||
// the trilinear system is ready to be solved:
|
||||
for (int i=1;i<=N;++i) {
|
||||
float multiple = mu[i]/diag[i-1]; // let's subtract proper multiple of above equation
|
||||
diag[i]-= multiple * lambda[i-1];
|
||||
rhs[i] -= multiple * rhs[i-1];
|
||||
}
|
||||
// now the back substitution (vector mu contains invalid values from now on):
|
||||
rhs[N] = rhs[N]/diag[N];
|
||||
for (int i=N-1;i>=0;--i)
|
||||
rhs[i] = (rhs[i]-lambda[i]*rhs[i+1])/diag[i];
|
||||
|
||||
unsigned int i=1;
|
||||
float y=0.f;
|
||||
for (int x=m_rect.GetLeft(); x<=m_rect.GetRight() ; ++x) {
|
||||
if (splines) {
|
||||
if (i<points.size()-1 && points[i].x < x ) {
|
||||
++i;
|
||||
}
|
||||
if (points[0].x > x)
|
||||
y = points[0].y;
|
||||
else
|
||||
if (points[N].x < x)
|
||||
y = points[N].y;
|
||||
else
|
||||
y = (rhs[i-1]*pow(points[i].x-x,3)+rhs[i]*pow(x-points[i-1].x,3)) / (6*h[i]) +
|
||||
(points[i-1].y-rhs[i-1]*h[i]*h[i]/6.f) * (points[i].x-x)/h[i] +
|
||||
(points[i].y -rhs[i] *h[i]*h[i]/6.f) * (x-points[i-1].x)/h[i];
|
||||
m_line_to_draw.push_back(y);
|
||||
}
|
||||
else {
|
||||
float x_math = screen_to_math(wxPoint(x,0)).m_x;
|
||||
if (i+2<=points.size() && m_buttons[i+1].get_pos().m_x-0.125 < x_math)
|
||||
++i;
|
||||
m_line_to_draw.push_back(math_to_screen(wxPoint2DDouble(x_math,m_buttons[i].get_pos().m_y)).y);
|
||||
}
|
||||
|
||||
m_line_to_draw.back() = std::max(m_line_to_draw.back(), m_rect.GetTop()-1);
|
||||
m_line_to_draw.back() = std::min(m_line_to_draw.back(), m_rect.GetBottom()-1);
|
||||
m_total_volume += (m_rect.GetBottom() - m_line_to_draw.back()) * (visible_area.m_width / m_rect.GetWidth()) * (visible_area.m_height / m_rect.GetHeight());
|
||||
}
|
||||
}
|
||||
|
||||
wxPostEvent(this->GetParent(), wxCommandEvent(EVT_WIPE_TOWER_CHART_CHANGED));
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
|
||||
std::vector<float> Chart::get_ramming_speed(float sampling) const {
|
||||
std::vector<float> speeds_out;
|
||||
|
||||
const int number_of_samples = std::round( visible_area.m_width / sampling);
|
||||
if (number_of_samples>0) {
|
||||
const int dx = (m_line_to_draw.size()-1) / number_of_samples;
|
||||
for (int j=0;j<number_of_samples;++j) {
|
||||
float left = screen_to_math(wxPoint(0,m_line_to_draw[j*dx])).m_y;
|
||||
float right = screen_to_math(wxPoint(0,m_line_to_draw[(j+1)*dx])).m_y;
|
||||
speeds_out.push_back((left+right)/2.f);
|
||||
}
|
||||
}
|
||||
return speeds_out;
|
||||
}
|
||||
|
||||
|
||||
std::vector<std::pair<float,float>> Chart::get_buttons() const {
|
||||
std::vector<std::pair<float, float>> buttons_out;
|
||||
for (const auto& button : m_buttons)
|
||||
buttons_out.push_back(std::make_pair(float(button.get_pos().m_x),float(button.get_pos().m_y)));
|
||||
return buttons_out;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BEGIN_EVENT_TABLE(Chart, wxWindow)
|
||||
EVT_MOTION(Chart::mouse_moved)
|
||||
EVT_LEFT_DOWN(Chart::mouse_clicked)
|
||||
EVT_LEFT_UP(Chart::mouse_released)
|
||||
EVT_LEFT_DCLICK(Chart::mouse_double_clicked)
|
||||
EVT_RIGHT_DOWN(Chart::mouse_right_button_clicked)
|
||||
EVT_LEAVE_WINDOW(Chart::mouse_left_window)
|
||||
EVT_PAINT(Chart::paint_event)
|
||||
END_EVENT_TABLE()
|
|
@ -1,120 +0,0 @@
|
|||
#ifndef RAMMING_CHART_H_
|
||||
#define RAMMING_CHART_H_
|
||||
|
||||
#include <vector>
|
||||
#include <wx/wxprec.h>
|
||||
#ifndef WX_PRECOMP
|
||||
#include <wx/wx.h>
|
||||
#endif
|
||||
|
||||
wxDECLARE_EVENT(EVT_WIPE_TOWER_CHART_CHANGED, wxCommandEvent);
|
||||
|
||||
|
||||
class Chart : public wxWindow {
|
||||
|
||||
public:
|
||||
Chart(wxWindow* parent, wxRect rect,const std::vector<std::pair<float,float>>& initial_buttons,int ramming_speed_size, float sampling, int scale_unit=10) :
|
||||
wxWindow(parent,wxID_ANY,rect.GetTopLeft(),rect.GetSize()),
|
||||
scale_unit(scale_unit), legend_side(5*scale_unit)
|
||||
{
|
||||
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
||||
m_rect = wxRect(wxPoint(legend_side,0),rect.GetSize()-wxSize(legend_side,legend_side));
|
||||
visible_area = wxRect2DDouble(0.0, 0.0, sampling*ramming_speed_size, 20.);
|
||||
m_buttons.clear();
|
||||
if (initial_buttons.size()>0)
|
||||
for (const auto& pair : initial_buttons)
|
||||
m_buttons.push_back(wxPoint2DDouble(pair.first,pair.second));
|
||||
recalculate_line();
|
||||
}
|
||||
void set_xy_range(float x,float y) {
|
||||
x = int(x/0.5) * 0.5;
|
||||
if (x>=0) visible_area.SetRight(x);
|
||||
if (y>=0) visible_area.SetBottom(y);
|
||||
recalculate_line();
|
||||
}
|
||||
float get_volume() const { return m_total_volume; }
|
||||
float get_time() const { return visible_area.m_width; }
|
||||
|
||||
std::vector<float> get_ramming_speed(float sampling) const; //returns sampled ramming speed
|
||||
std::vector<std::pair<float,float>> get_buttons() const; // returns buttons position
|
||||
|
||||
void draw();
|
||||
|
||||
void mouse_clicked(wxMouseEvent& event);
|
||||
void mouse_right_button_clicked(wxMouseEvent& event);
|
||||
void mouse_moved(wxMouseEvent& event);
|
||||
void mouse_double_clicked(wxMouseEvent& event);
|
||||
void mouse_left_window(wxMouseEvent&) { m_dragged = nullptr; }
|
||||
void mouse_released(wxMouseEvent&) { m_dragged = nullptr; }
|
||||
void paint_event(wxPaintEvent&) { draw(); }
|
||||
DECLARE_EVENT_TABLE()
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
static const bool fixed_x = true;
|
||||
static const bool splines = true;
|
||||
static const bool manual_points_manipulation = false;
|
||||
static const int side = 10; // side of draggable button
|
||||
|
||||
const int scale_unit;
|
||||
int legend_side;
|
||||
|
||||
class ButtonToDrag {
|
||||
public:
|
||||
bool operator<(const ButtonToDrag& a) const { return m_pos.m_x < a.m_pos.m_x; }
|
||||
ButtonToDrag(wxPoint2DDouble pos) : m_pos{pos} {};
|
||||
wxPoint2DDouble get_pos() const { return m_pos; }
|
||||
void move(double x,double y) { m_pos.m_x+=x; m_pos.m_y+=y; }
|
||||
private:
|
||||
wxPoint2DDouble m_pos; // position in math coordinates
|
||||
};
|
||||
|
||||
|
||||
|
||||
wxPoint math_to_screen(const wxPoint2DDouble& math) const {
|
||||
wxPoint screen;
|
||||
screen.x = (math.m_x-visible_area.m_x) * (m_rect.GetWidth() / visible_area.m_width );
|
||||
screen.y = (math.m_y-visible_area.m_y) * (m_rect.GetHeight() / visible_area.m_height );
|
||||
screen.y *= -1;
|
||||
screen += m_rect.GetLeftBottom();
|
||||
return screen;
|
||||
}
|
||||
wxPoint2DDouble screen_to_math(const wxPoint& screen) const {
|
||||
wxPoint2DDouble math = screen;
|
||||
math -= m_rect.GetLeftBottom();
|
||||
math.m_y *= -1;
|
||||
math.m_x *= visible_area.m_width / m_rect.GetWidth(); // scales to [0;1]x[0,1]
|
||||
math.m_y *= visible_area.m_height / m_rect.GetHeight();
|
||||
return (math+visible_area.GetLeftTop());
|
||||
}
|
||||
|
||||
int which_button_is_clicked(const wxPoint& point) const {
|
||||
if (!m_rect.Contains(point))
|
||||
return -1;
|
||||
for (unsigned int i=0;i<m_buttons.size();++i) {
|
||||
wxRect rect(math_to_screen(m_buttons[i].get_pos())-wxPoint(side/2.,side/2.),wxSize(side,side)); // bounding rectangle of this button
|
||||
if ( rect.Contains(point) )
|
||||
return i;
|
||||
}
|
||||
return (-1);
|
||||
}
|
||||
|
||||
|
||||
void recalculate_line();
|
||||
void recalculate_volume();
|
||||
|
||||
|
||||
wxRect m_rect; // rectangle on screen the chart is mapped into (screen coordinates)
|
||||
wxPoint m_previous_mouse;
|
||||
std::vector<ButtonToDrag> m_buttons;
|
||||
std::vector<int> m_line_to_draw;
|
||||
wxRect2DDouble visible_area;
|
||||
ButtonToDrag* m_dragged = nullptr;
|
||||
float m_total_volume = 0.f;
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif // RAMMING_CHART_H_
|
Loading…
Add table
Add a link
Reference in a new issue