mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-16 10:02:12 +00:00
ENH:FilamentMapDialog add filament type
jira: nojira Change-Id: I08a3c037ffa6227602e71b97697a1bc61e3d5050 (cherry picked from commit 6621fd0e20bce4c32788a86a6fde018f3a7f41ef)
This commit is contained in:
@@ -8,6 +8,7 @@ struct CustomData
|
||||
{
|
||||
int filament_id;
|
||||
unsigned char r, g, b, a;
|
||||
std::string type;
|
||||
};
|
||||
|
||||
|
||||
@@ -35,12 +36,13 @@ wxColor Hex2Color(const std::string& str)
|
||||
class ColorDataObject : public wxCustomDataObject
|
||||
{
|
||||
public:
|
||||
ColorDataObject(const wxColour &color = *wxBLACK, int filament_id = 0)
|
||||
ColorDataObject(const wxColour &color = *wxBLACK, int filament_id = 0, const std::string &type = "PLA")
|
||||
: wxCustomDataObject(wxDataFormat("application/customize_format"))
|
||||
{
|
||||
std::memset(&m_data, 0, sizeof(m_data));
|
||||
set_custom_data_filament_id(filament_id);
|
||||
set_custom_data_color(color);
|
||||
set_custom_data_type(type);
|
||||
}
|
||||
|
||||
wxColour GetColor() const { return wxColor(m_data.r, m_data.g, m_data.b, m_data.a); }
|
||||
@@ -49,6 +51,13 @@ public:
|
||||
int GetFilament() const { return m_data.filament_id; }
|
||||
void SetFilament(int label) { set_custom_data_filament_id(label); }
|
||||
|
||||
std::string GetType() const { return m_data.type; }
|
||||
void SetType(const std::string &type) { set_custom_data_type(type); }
|
||||
|
||||
void set_custom_data_type(const std::string& type) {
|
||||
m_data.type = type;
|
||||
}
|
||||
|
||||
void set_custom_data_filament_id(int filament_id) {
|
||||
m_data.filament_id = filament_id;
|
||||
}
|
||||
@@ -81,8 +90,8 @@ private:
|
||||
|
||||
/////////////// ColorPanel start ////////////////////////
|
||||
// The UI panel of drag item
|
||||
ColorPanel::ColorPanel(DragDropPanel *parent, const wxColour &color, int filament_id)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(32, 40), wxBORDER_NONE), m_parent(parent), m_color(color), m_filament_id(filament_id)
|
||||
ColorPanel::ColorPanel(DragDropPanel *parent, const wxColour &color, int filament_id, const std::string &type)
|
||||
: wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(32, 40), wxBORDER_NONE), m_parent(parent), m_color(color), m_filament_id(filament_id), m_type(type)
|
||||
{
|
||||
Bind(wxEVT_LEFT_DOWN, &ColorPanel::OnLeftDown, this);
|
||||
Bind(wxEVT_LEFT_UP, &ColorPanel::OnLeftUp, this);
|
||||
@@ -92,7 +101,7 @@ ColorPanel::ColorPanel(DragDropPanel *parent, const wxColour &color, int filamen
|
||||
void ColorPanel::OnLeftDown(wxMouseEvent &event)
|
||||
{
|
||||
m_parent->set_is_draging(true);
|
||||
m_parent->DoDragDrop(this, GetColor(), GetFilamentId());
|
||||
m_parent->DoDragDrop(this, GetColor(), GetType(), GetFilamentId());
|
||||
}
|
||||
|
||||
void ColorPanel::OnLeftUp(wxMouseEvent &event) { m_parent->set_is_draging(false); }
|
||||
@@ -101,16 +110,38 @@ void ColorPanel::OnPaint(wxPaintEvent &event)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
wxSize size = GetSize();
|
||||
// If it matches the parent's width, it will not be displayed completely
|
||||
int svg_size = size.GetWidth() - FromDIP(3);
|
||||
int type_label_height = FromDIP(10);
|
||||
wxString type_label(m_type);
|
||||
int type_label_margin = FromDIP(6);
|
||||
|
||||
std::string replace_color = m_color.GetAsString(wxC2S_HTML_SYNTAX).ToStdString();
|
||||
std::string svg_name = "outlined_rect";
|
||||
if (replace_color == "#FFFFFF00") {
|
||||
svg_name = "outlined_rect_transparent";
|
||||
}
|
||||
wxBitmap bmp = ScalableBitmap(this, svg_name, 35, false, false, false, { replace_color }).bmp();
|
||||
dc.DrawBitmap(bmp, wxPoint(0,0));
|
||||
wxBitmap bmp = ScalableBitmap(this, svg_name, svg_size, false, false, false, { replace_color }).bmp();
|
||||
// ScalableBitmap is not drawn at position (0, 0) by default, why?
|
||||
dc.DrawBitmap(bmp, wxPoint(-FromDIP(3), -FromDIP(3)));
|
||||
|
||||
//dc.SetPen(wxPen(*wxBLACK, 1));
|
||||
//dc.DrawRectangle(0, 0, FromDIP(25), FromDIP(25));
|
||||
|
||||
wxString label = wxString::Format(wxT("%d"), m_filament_id);
|
||||
dc.SetTextForeground(m_color.GetLuminance() < 0.51 ? *wxWHITE : *wxBLACK); // set text color
|
||||
dc.DrawLabel(label, wxRect(2, -3, size.GetWidth(), size.GetHeight()), wxALIGN_CENTER);
|
||||
dc.DrawLabel(label, wxRect(0, 0, svg_size, svg_size), wxALIGN_CENTER);
|
||||
|
||||
dc.SetTextForeground(*wxBLACK);
|
||||
if (type_label.length() > 4) {
|
||||
// text is too long
|
||||
wxString first = type_label.Mid(0, 4);
|
||||
wxString rest = type_label.Mid(4);
|
||||
dc.DrawLabel(first, wxRect(0, svg_size + type_label_margin, svg_size, type_label_height), wxALIGN_CENTER);
|
||||
dc.DrawLabel(rest, wxRect(0, svg_size + type_label_height + type_label_margin, svg_size, type_label_height), wxALIGN_CENTER);
|
||||
}else {
|
||||
dc.DrawLabel(type_label, wxRect(0, svg_size + type_label_margin, svg_size, type_label_height), wxALIGN_CENTER);
|
||||
}
|
||||
}
|
||||
/////////////// ColorPanel end ////////////////////////
|
||||
|
||||
@@ -119,10 +150,11 @@ void ColorPanel::OnPaint(wxPaintEvent &event)
|
||||
class ColorDropSource : public wxDropSource
|
||||
{
|
||||
public:
|
||||
ColorDropSource(wxPanel *parent, wxPanel *color_block, const wxColour &color, int filament_id) : wxDropSource(parent)
|
||||
ColorDropSource(wxPanel *parent, wxPanel *color_block, const wxColour &color, const std::string& type, int filament_id) : wxDropSource(parent)
|
||||
{
|
||||
m_data.SetColor(color);
|
||||
m_data.SetFilament(filament_id);
|
||||
m_data.SetType(type);
|
||||
SetData(m_data); // Set drag source data
|
||||
}
|
||||
|
||||
@@ -157,7 +189,7 @@ wxDragResult ColorDropTarget::OnData(wxCoord x, wxCoord y, wxDragResult def)
|
||||
return wxDragNone;
|
||||
|
||||
ColorDataObject *dataObject = dynamic_cast<ColorDataObject *>(GetDataObject());
|
||||
m_panel->AddColorBlock(m_data->GetColor(), m_data->GetFilament());
|
||||
m_panel->AddColorBlock(m_data->GetColor(), m_data->GetType(), m_data->GetFilament());
|
||||
|
||||
return wxDragCopy;
|
||||
}
|
||||
@@ -184,10 +216,10 @@ DragDropPanel::DragDropPanel(wxWindow *parent, const wxString &label, bool is_au
|
||||
title_sizer->Add(static_text, 0, wxALIGN_CENTER | wxALL, FromDIP(5));
|
||||
|
||||
m_sizer->Add(title_panel, 0, wxEXPAND);
|
||||
m_sizer->AddSpacer(20);
|
||||
m_sizer->AddSpacer(10);
|
||||
|
||||
m_grid_item_sizer = new wxGridSizer(0, 6, FromDIP(4),FromDIP(4)); // row = 0, col = 3, 10 10 is space
|
||||
m_sizer->Add(m_grid_item_sizer, 1, wxEXPAND);
|
||||
m_grid_item_sizer = new wxGridSizer(0, 6, FromDIP(8), FromDIP(8)); // row = 0, col = 3, 10 10 is space
|
||||
m_sizer->Add(m_grid_item_sizer, 1, wxEXPAND | wxALL, FromDIP(8));
|
||||
|
||||
// set droptarget
|
||||
auto drop_target = new ColorDropTarget(this);
|
||||
@@ -198,10 +230,10 @@ DragDropPanel::DragDropPanel(wxWindow *parent, const wxString &label, bool is_au
|
||||
Fit();
|
||||
}
|
||||
|
||||
void DragDropPanel::AddColorBlock(const wxColour &color, int filament_id, bool update_ui)
|
||||
void DragDropPanel::AddColorBlock(const wxColour &color, const std::string &type, int filament_id, bool update_ui)
|
||||
{
|
||||
ColorPanel *panel = new ColorPanel(this, color, filament_id);
|
||||
panel->SetMinSize(wxSize(FromDIP(32), FromDIP(40)));
|
||||
ColorPanel *panel = new ColorPanel(this, color, filament_id, type);
|
||||
panel->SetMinSize(wxSize(FromDIP(30), FromDIP(60)));
|
||||
m_grid_item_sizer->Add(panel, 0);
|
||||
m_filament_blocks.push_back(panel);
|
||||
if (update_ui) {
|
||||
@@ -222,12 +254,12 @@ void DragDropPanel::RemoveColorBlock(ColorPanel *panel, bool update_ui)
|
||||
}
|
||||
}
|
||||
|
||||
void DragDropPanel::DoDragDrop(ColorPanel *panel, const wxColour &color, int filament_id)
|
||||
void DragDropPanel::DoDragDrop(ColorPanel *panel, const wxColour &color, const std::string &type, int filament_id)
|
||||
{
|
||||
if (m_is_auto)
|
||||
return;
|
||||
|
||||
ColorDropSource source(this, panel, color, filament_id);
|
||||
ColorDropSource source(this, panel, color, type, filament_id);
|
||||
if (source.DoDragDrop(wxDrag_CopyOnly) == wxDragResult::wxDragCopy) {
|
||||
this->RemoveColorBlock(panel);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user