mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-08 15:37:30 -06:00
Add first impl of EditGCodeDialog
Only current issue is that the grabber for the resizeable window is currently white (ongoing issue for Orca) Original Commit: prusa3d/PrusaSlicer@a8307bf Co-authored-by: YuSanka <yusanka@gmail.com>
This commit is contained in:
parent
accdbb9661
commit
dd802764b9
5 changed files with 314 additions and 2 deletions
|
@ -212,6 +212,8 @@ set(SLIC3R_GUI_SOURCES
|
||||||
GUI/PresetComboBoxes.cpp
|
GUI/PresetComboBoxes.cpp
|
||||||
GUI/BitmapComboBox.hpp
|
GUI/BitmapComboBox.hpp
|
||||||
GUI/BitmapComboBox.cpp
|
GUI/BitmapComboBox.cpp
|
||||||
|
GUI/EditGCodeDialog.hpp
|
||||||
|
GUI/EditGCodeDialog.cpp
|
||||||
GUI/SavePresetDialog.hpp
|
GUI/SavePresetDialog.hpp
|
||||||
GUI/SavePresetDialog.cpp
|
GUI/SavePresetDialog.cpp
|
||||||
GUI/GUI_Colors.hpp
|
GUI/GUI_Colors.hpp
|
||||||
|
|
251
src/slic3r/GUI/EditGCodeDialog.cpp
Normal file
251
src/slic3r/GUI/EditGCodeDialog.cpp
Normal file
|
@ -0,0 +1,251 @@
|
||||||
|
#include "EditGCodeDialog.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include <wx/sizer.h>
|
||||||
|
#include <wx/stattext.h>
|
||||||
|
#include <wx/textctrl.h>
|
||||||
|
#include <wx/button.h>
|
||||||
|
#include <wx/listbox.h>
|
||||||
|
#include <wx/statbox.h>
|
||||||
|
#include <wx/wupdlock.h>
|
||||||
|
|
||||||
|
#include "GUI.hpp"
|
||||||
|
#include "GUI_App.hpp"
|
||||||
|
#include "MainFrame.hpp"
|
||||||
|
#include "format.hpp"
|
||||||
|
#include "Tab.hpp"
|
||||||
|
#include "wxExtensions.hpp"
|
||||||
|
#include "BitmapCache.hpp"
|
||||||
|
#include "MsgDialog.hpp"
|
||||||
|
|
||||||
|
#define BTN_GAP FromDIP(20)
|
||||||
|
#define BTN_SIZE wxSize(FromDIP(58), FromDIP(24))
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
static wxArrayString get_patterns_list()
|
||||||
|
{
|
||||||
|
wxArrayString patterns;
|
||||||
|
for (const wxString& item : {
|
||||||
|
";comment"//format_wxstr(";%1%",_L("comment"))
|
||||||
|
, "M862.3 P \"[printer_model]\" ; printer model check"
|
||||||
|
, "M862.1 P[nozzle_diameter]; nozzle diameter check"
|
||||||
|
, "M115 U3.12.2; tell printer latest fw version"
|
||||||
|
, "G90; use absolute coordinates"
|
||||||
|
, "M83; extruder relative mode"
|
||||||
|
, "M104 S[first_layer_temperature]; set extruder temp"
|
||||||
|
, "M140 S[first_layer_bed_temperature]; set bed temp"
|
||||||
|
, "M190 S[first_layer_bed_temperature]; wait for bed temp"
|
||||||
|
, "M109 S[first_layer_temperature]; wait for extruder temp"
|
||||||
|
, "G28 W; home all without mesh bed level"
|
||||||
|
, "G80; mesh bed leveling"
|
||||||
|
, "M403 E0 F {\n"
|
||||||
|
" + ((filament_type[0] == \"FLEX\") ? 1 : ((filament_type[0] == \"PVA\") ? 2 : 0))\n"
|
||||||
|
"}"
|
||||||
|
, "{if not OPTION}"
|
||||||
|
, "G1"
|
||||||
|
, "T[initial_tool]; select extruder"
|
||||||
|
, "G92 E0"
|
||||||
|
, "{endif}"
|
||||||
|
})
|
||||||
|
patterns.Add(item);
|
||||||
|
return patterns;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// EditGCodeDialog
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
EditGCodeDialog::EditGCodeDialog(wxWindow* parent, const std::string& key, const std::string& value) :
|
||||||
|
DPIDialog(parent, wxID_ANY, format_wxstr(_L("Edit Custom G-code (%1%)"), key), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
|
||||||
|
{
|
||||||
|
SetFont(wxGetApp().normal_font());
|
||||||
|
SetBackgroundColour(*wxWHITE);
|
||||||
|
wxGetApp().UpdateDarkUI(this);
|
||||||
|
|
||||||
|
int border = 10;
|
||||||
|
int em = em_unit();
|
||||||
|
|
||||||
|
wxStaticText* label_top = new wxStaticText(this, wxID_ANY, _L("Edit your custom G-code using patterns"));
|
||||||
|
label_top->SetFont(wxGetApp().bold_font());
|
||||||
|
|
||||||
|
auto* grid_sizer = new wxFlexGridSizer(1, 3, 5, 15);
|
||||||
|
grid_sizer->SetFlexibleDirection(wxBOTH);
|
||||||
|
|
||||||
|
m_patterns_list = new wxListBox(this, wxID_ANY, wxDefaultPosition, wxSize(em * 15, em * 30), get_patterns_list(), wxLB_SINGLE | wxLB_NEEDED_SB | wxLB_SORT
|
||||||
|
#ifdef _WIN32
|
||||||
|
| wxBORDER_SIMPLE
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
m_patterns_list->SetFont(wxGetApp().code_font());
|
||||||
|
wxGetApp().UpdateDarkUI(m_patterns_list);
|
||||||
|
|
||||||
|
m_add_btn = new ScalableButton(this, wxID_ANY, "add_copies");
|
||||||
|
m_add_btn->SetToolTip(_L("Add selected pettern to the G-code"));
|
||||||
|
|
||||||
|
m_gcode_editor = new wxTextCtrl(this, wxID_ANY, value, wxDefaultPosition, wxSize(em * 45, em * 30), wxTE_MULTILINE
|
||||||
|
#ifdef _WIN32
|
||||||
|
| wxBORDER_SIMPLE
|
||||||
|
#endif
|
||||||
|
);
|
||||||
|
m_gcode_editor->SetFont(wxGetApp().code_font());
|
||||||
|
wxGetApp().UpdateDarkUI(m_gcode_editor);
|
||||||
|
|
||||||
|
grid_sizer->Add(m_patterns_list, 1, wxEXPAND);
|
||||||
|
grid_sizer->Add(m_add_btn, 0, wxALIGN_CENTER_VERTICAL);
|
||||||
|
grid_sizer->Add(m_gcode_editor, 2, wxEXPAND);
|
||||||
|
|
||||||
|
grid_sizer->AddGrowableRow(0, 1);
|
||||||
|
grid_sizer->AddGrowableCol(0, 1);
|
||||||
|
grid_sizer->AddGrowableCol(2, 1);
|
||||||
|
|
||||||
|
auto btn_sizer = create_btn_sizer(wxOK | wxCANCEL);
|
||||||
|
for(auto btn : m_button_list)
|
||||||
|
wxGetApp().UpdateDarkUI(btn.second);
|
||||||
|
|
||||||
|
wxBoxSizer* topSizer = new wxBoxSizer(wxVERTICAL);
|
||||||
|
|
||||||
|
topSizer->Add(label_top , 0, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border);
|
||||||
|
topSizer->Add(grid_sizer , 1, wxEXPAND | wxLEFT | wxTOP | wxRIGHT, border);
|
||||||
|
topSizer->Add(btn_sizer , 0, wxEXPAND | wxALL, border);
|
||||||
|
|
||||||
|
SetSizer(topSizer);
|
||||||
|
topSizer->SetSizeHints(this);
|
||||||
|
|
||||||
|
this->Fit();
|
||||||
|
this->Layout();
|
||||||
|
|
||||||
|
this->CenterOnScreen();
|
||||||
|
|
||||||
|
wxGetApp().UpdateDlgDarkUI(this);
|
||||||
|
|
||||||
|
m_patterns_list->Bind(wxEVT_LISTBOX_DCLICK, [this](wxCommandEvent& evt) {
|
||||||
|
wxString val = m_patterns_list->GetString(m_patterns_list->GetSelection());
|
||||||
|
assert(!val.IsEmpty());
|
||||||
|
auto insert_to = m_gcode_editor->GetInsertionPoint();
|
||||||
|
m_gcode_editor->WriteText(val);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditGCodeDialog::on_dpi_changed(const wxRect&suggested_rect)
|
||||||
|
{
|
||||||
|
const int& em = em_unit();
|
||||||
|
|
||||||
|
//m_optgroup->msw_rescale();
|
||||||
|
|
||||||
|
// msw_buttons_rescale(this, em, { wxID_OK, wxID_CANCEL });
|
||||||
|
|
||||||
|
for (auto button_item : m_button_list)
|
||||||
|
{
|
||||||
|
if (button_item.first == wxRESET)
|
||||||
|
{
|
||||||
|
button_item.second->SetMinSize(wxSize(FromDIP(75), FromDIP(24)));
|
||||||
|
button_item.second->SetCornerRadius(FromDIP(12));
|
||||||
|
}
|
||||||
|
if (button_item.first == wxOK) {
|
||||||
|
button_item.second->SetMinSize(BTN_SIZE);
|
||||||
|
button_item.second->SetCornerRadius(FromDIP(12));
|
||||||
|
}
|
||||||
|
if (button_item.first == wxCANCEL) {
|
||||||
|
button_item.second->SetMinSize(BTN_SIZE);
|
||||||
|
button_item.second->SetCornerRadius(FromDIP(12));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const wxSize& size = wxSize(45 * em, 35 * em);
|
||||||
|
SetMinSize(size);
|
||||||
|
|
||||||
|
Fit();
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditGCodeDialog::on_sys_color_changed()
|
||||||
|
{
|
||||||
|
m_add_btn->sys_color_changed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditGCodeDialog::OnOK(wxEvent& event)
|
||||||
|
{
|
||||||
|
event.Skip();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Orca
|
||||||
|
wxBoxSizer* EditGCodeDialog::create_btn_sizer(long flags)
|
||||||
|
{
|
||||||
|
auto btn_sizer = new wxBoxSizer(wxHORIZONTAL);
|
||||||
|
btn_sizer->AddStretchSpacer();
|
||||||
|
|
||||||
|
StateColor ok_btn_bg(
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed),
|
||||||
|
std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor ok_btn_bd(
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor ok_btn_text(
|
||||||
|
std::pair<wxColour, int>(wxColour(255, 255, 254), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor cancel_btn_bg(
|
||||||
|
std::pair<wxColour, int>(wxColour(206, 206, 206), StateColor::Pressed),
|
||||||
|
std::pair<wxColour, int>(wxColour(238, 238, 238), StateColor::Hovered),
|
||||||
|
std::pair<wxColour, int>(wxColour(255, 255, 255), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor cancel_btn_bd_(
|
||||||
|
std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor cancel_btn_text(
|
||||||
|
std::pair<wxColour, int>(wxColour(38, 46, 48), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
StateColor calc_btn_bg(
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 137, 123), StateColor::Pressed),
|
||||||
|
std::pair<wxColour, int>(wxColour(38, 166, 154), StateColor::Hovered),
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor calc_btn_bd(
|
||||||
|
std::pair<wxColour, int>(wxColour(0, 150, 136), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
StateColor calc_btn_text(
|
||||||
|
std::pair<wxColour, int>(wxColour(255, 255, 254), StateColor::Normal)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (flags & wxOK) {
|
||||||
|
Button* ok_btn = new Button(this, _L("OK"));
|
||||||
|
ok_btn->SetMinSize(BTN_SIZE);
|
||||||
|
ok_btn->SetCornerRadius(FromDIP(12));
|
||||||
|
ok_btn->SetBackgroundColor(ok_btn_bg);
|
||||||
|
ok_btn->SetBorderColor(ok_btn_bd);
|
||||||
|
ok_btn->SetTextColor(ok_btn_text);
|
||||||
|
ok_btn->SetFocus();
|
||||||
|
ok_btn->SetId(wxID_OK);
|
||||||
|
btn_sizer->Add(ok_btn, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, BTN_GAP);
|
||||||
|
m_button_list[wxOK] = ok_btn;
|
||||||
|
}
|
||||||
|
if (flags & wxCANCEL) {
|
||||||
|
Button* cancel_btn = new Button(this, _L("Cancel"));
|
||||||
|
cancel_btn->SetMinSize(BTN_SIZE);
|
||||||
|
cancel_btn->SetCornerRadius(FromDIP(12));
|
||||||
|
cancel_btn->SetBackgroundColor(cancel_btn_bg);
|
||||||
|
cancel_btn->SetBorderColor(cancel_btn_bd_);
|
||||||
|
cancel_btn->SetTextColor(cancel_btn_text);
|
||||||
|
cancel_btn->SetId(wxID_CANCEL);
|
||||||
|
btn_sizer->Add(cancel_btn, 0, wxRIGHT | wxALIGN_CENTER_VERTICAL, BTN_GAP / 2);
|
||||||
|
m_button_list[wxCANCEL] = cancel_btn;
|
||||||
|
}
|
||||||
|
|
||||||
|
return btn_sizer;
|
||||||
|
}
|
||||||
|
|
||||||
|
}} // namespace Slic3r::GUI
|
51
src/slic3r/GUI/EditGCodeDialog.hpp
Normal file
51
src/slic3r/GUI/EditGCodeDialog.hpp
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
#ifndef slic3r_EditGCodeDialog_hpp_
|
||||||
|
#define slic3r_EditGCodeDialog_hpp_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <wx/gdicmn.h>
|
||||||
|
#include <slic3r/GUI/Widgets/Button.hpp>
|
||||||
|
|
||||||
|
#include "GUI_Utils.hpp"
|
||||||
|
|
||||||
|
class wxListBox;
|
||||||
|
class wxTextCtrl;
|
||||||
|
//class wxStaticText;
|
||||||
|
class ScalableButton;
|
||||||
|
//class wxBoxSizer;
|
||||||
|
|
||||||
|
namespace Slic3r {
|
||||||
|
|
||||||
|
namespace GUI {
|
||||||
|
|
||||||
|
class PresetComboBox;
|
||||||
|
|
||||||
|
//------------------------------------------
|
||||||
|
// EditGCodeDialog
|
||||||
|
//------------------------------------------
|
||||||
|
|
||||||
|
class EditGCodeDialog : public DPIDialog
|
||||||
|
{
|
||||||
|
wxListBox* m_patterns_list {nullptr};
|
||||||
|
ScalableButton* m_add_btn {nullptr};
|
||||||
|
wxTextCtrl* m_gcode_editor {nullptr};
|
||||||
|
|
||||||
|
void OnOK(wxEvent& event);
|
||||||
|
|
||||||
|
public:
|
||||||
|
EditGCodeDialog(wxWindow* parent, const std::string& key, const std::string& value);
|
||||||
|
~EditGCodeDialog() {}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
std::unordered_map<int, Button *> m_button_list;
|
||||||
|
|
||||||
|
void on_dpi_changed(const wxRect& suggested_rect) override;
|
||||||
|
void on_sys_color_changed() override;
|
||||||
|
wxBoxSizer* EditGCodeDialog::create_btn_sizer(long flags);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
} // namespace GUI
|
||||||
|
} // namespace Slic3r
|
||||||
|
|
||||||
|
#endif
|
|
@ -37,6 +37,7 @@
|
||||||
#include "format.hpp"
|
#include "format.hpp"
|
||||||
#include "UnsavedChangesDialog.hpp"
|
#include "UnsavedChangesDialog.hpp"
|
||||||
#include "SavePresetDialog.hpp"
|
#include "SavePresetDialog.hpp"
|
||||||
|
#include "EditGCodeDialog.hpp"
|
||||||
#include "MsgDialog.hpp"
|
#include "MsgDialog.hpp"
|
||||||
#include "Notebook.hpp"
|
#include "Notebook.hpp"
|
||||||
|
|
||||||
|
@ -2868,7 +2869,12 @@ static void validate_custom_gcode_cb(Tab* tab, ConfigOptionsGroupShp opt_group,
|
||||||
|
|
||||||
void Tab::edit_custom_gcode(const t_config_option_key& opt_key)
|
void Tab::edit_custom_gcode(const t_config_option_key& opt_key)
|
||||||
{
|
{
|
||||||
MessageDialog(this, format_wxstr("Edit gcode for %1%", opt_key), this->title()).ShowModal();
|
EditGCodeDialog(this, opt_key, m_config->opt_string(opt_key)).ShowModal();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TabFilament::edit_custom_gcode(const t_config_option_key& opt_key)
|
||||||
|
{
|
||||||
|
EditGCodeDialog(this, opt_key, m_config->opt_string(opt_key, unsigned(m_presets_choice->GetSelection()))).ShowModal();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabFilament::add_filament_overrides_page()
|
void TabFilament::add_filament_overrides_page()
|
||||||
|
|
|
@ -404,11 +404,12 @@ public:
|
||||||
void restore_last_select_item();
|
void restore_last_select_item();
|
||||||
|
|
||||||
static bool validate_custom_gcode(const wxString& title, const std::string& gcode);
|
static bool validate_custom_gcode(const wxString& title, const std::string& gcode);
|
||||||
void edit_custom_gcode(const t_config_option_key &opt_key);
|
|
||||||
bool validate_custom_gcodes();
|
bool validate_custom_gcodes();
|
||||||
bool validate_custom_gcodes_was_shown{ false };
|
bool validate_custom_gcodes_was_shown{ false };
|
||||||
void set_just_edit(bool just_edit);
|
void set_just_edit(bool just_edit);
|
||||||
|
|
||||||
|
virtual void edit_custom_gcode(const t_config_option_key &opt_key);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void create_line_with_widget(ConfigOptionsGroup* optgroup, const std::string& opt_key, const std::string& path, widget_t widget);
|
void create_line_with_widget(ConfigOptionsGroup* optgroup, const std::string& opt_key, const std::string& path, widget_t widget);
|
||||||
wxSizer* compatible_widget_create(wxWindow* parent, PresetDependencies &deps);
|
wxSizer* compatible_widget_create(wxWindow* parent, PresetDependencies &deps);
|
||||||
|
@ -561,6 +562,7 @@ public:
|
||||||
void update() override;
|
void update() override;
|
||||||
void clear_pages() override;
|
void clear_pages() override;
|
||||||
bool supports_printer_technology(const PrinterTechnology tech) const override { return tech == ptFFF; }
|
bool supports_printer_technology(const PrinterTechnology tech) const override { return tech == ptFFF; }
|
||||||
|
void edit_custom_gcode(const t_config_option_key& opt_key) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TabPrinter : public Tab
|
class TabPrinter : public Tab
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue