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

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

Inheritance diagram for Slic3r::GUI::MappingItem:
Collaboration diagram for Slic3r::GUI::MappingItem:

Public Member Functions

 MappingItem (wxWindow *parent)
 ~MappingItem ()
void update_data (TrayData data)
void send_event (int fliament_id)
void set_data (const wxString &tag_name, wxColour colour, wxString name, bool remain_detect, TrayData data, bool unmatch=false, std::optional< wxString > tooltip_opt=std::nullopt)
void set_checked (bool checked)
void set_tray_index (wxString t_index)
void msw_rescale ()

Public Attributes

wxWindow * send_win {nullptr}
wxString m_tray_index
wxColour m_coloul
wxString m_name
TrayData m_tray_data
ScalableBitmap m_transparent_mapping_item
ScalableBitmap mapping_item_checked
bool m_unmatch {false}
int m_ams_id {255}
int m_slot_id {255}

Private Member Functions

void paintEvent (wxPaintEvent &evt)
void render (wxDC &dc)
void doRender (wxDC &dc)
int get_remain_area_height () const

Private Attributes

bool m_checked = false
bool m_support_remain_detect = false
bool m_to_paint_remain = false

Detailed Description

Constructor & Destructor Documentation

◆ MappingItem()

Slic3r::GUI::MappingItem::MappingItem ( wxWindow * parent)
1352 : wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize)
1353{
1354#ifdef __WINDOWS__
1355 SetDoubleBuffered(true);
1356#endif //__WINDOWS__
1357
1358 m_transparent_mapping_item = ScalableBitmap(this, "transparent_mapping_item", FromDIP(60));
1359 mapping_item_checked = ScalableBitmap(this, "mapping_item_checked", FromDIP(20));
1360 SetBackgroundColour(StateColor::darkModeColorFor(*wxWHITE));
1361 Bind(wxEVT_PAINT, &MappingItem::paintEvent, this);
1362}
ScalableBitmap m_transparent_mapping_item
Definition AmsMappingPopup.hpp:206
void paintEvent(wxPaintEvent &evt)
Definition AmsMappingPopup.cpp:1391
ScalableBitmap mapping_item_checked
Definition AmsMappingPopup.hpp:207
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219

References StateColor::darkModeColorFor(), m_transparent_mapping_item, mapping_item_checked, and paintEvent().

Here is the call graph for this function:

◆ ~MappingItem()

Slic3r::GUI::MappingItem::~MappingItem ( )
1365{
1366}

Member Function Documentation

◆ doRender()

void Slic3r::GUI::MappingItem::doRender ( wxDC & dc)
private
1556{
1557 wxSize size = GetSize();
1558 wxColour color = m_coloul;
1559 change_the_opacity(color);
1560
1561 if (!IsThisEnabled()) { color = wxColour(0xEE, 0xEE, 0xEE); }
1562 dc.SetPen(color);
1563 dc.SetBrush(wxBrush(color));
1564
1565
1566 //draw a rectangle based on the material color, single color or muti color processing
1567 if (m_tray_data.material_cols.size() > 1 && !m_unmatch) {
1568 int left = 0;
1569 int gwidth = std::round(MAPPING_ITEM_REAL_SIZE.x / (m_tray_data.material_cols.size() - 1));
1570 //gradient
1571 if (m_tray_data.ctype == 0) {
1572 for (int i = 0; i < m_tray_data.material_cols.size() - 1; i++) {
1573 auto rect = wxRect(left, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + get_remain_area_height(), MAPPING_ITEM_REAL_SIZE.x, MAPPING_ITEM_REAL_SIZE.y);
1574 fill_gradient_rect_east(dc, rect, m_tray_data.material_cols[i], m_tray_data.material_cols[i + 1]);
1575 left += gwidth;
1576 }
1577 }
1578 else {
1579 int cols_size = m_tray_data.material_cols.size();
1580 for (int i = 0; i < cols_size; i++) {
1581 dc.SetBrush(wxBrush(m_tray_data.material_cols[i]));
1582 float x = (float)MAPPING_ITEM_REAL_SIZE.x * i / cols_size;
1583 dc.DrawRectangle(x, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + get_remain_area_height(), (float) MAPPING_ITEM_REAL_SIZE.x / cols_size, MAPPING_ITEM_REAL_SIZE.y);
1584 }
1585 }
1586 }
1587 else if (color.Alpha() == 0) {
1588 dc.DrawBitmap(m_transparent_mapping_item.bmp(), 0, (size.y - MAPPING_ITEM_REAL_SIZE.y) / 2 + get_remain_area_height());
1589 }
1590 else {
1592 }
1593
1594 wxColour side_colour = wxColour("#E4E4E4");
1595
1596 dc.SetPen(side_colour);
1597 dc.SetBrush(wxBrush(side_colour));
1598 dc.DrawRectangle(0, get_remain_area_height(), FromDIP(4), size.y);
1599 dc.DrawRectangle(size.x - FromDIP(4), get_remain_area_height(), FromDIP(4), size.y);
1600}
#define MAPPING_ITEM_REAL_SIZE
Definition AmsMappingPopup.cpp:77
wxColour m_coloul
Definition AmsMappingPopup.hpp:203
bool m_unmatch
Definition AmsMappingPopup.hpp:208
int get_remain_area_height() const
Definition AmsMappingPopup.cpp:1602
TrayData m_tray_data
Definition AmsMappingPopup.hpp:205
void fill_gradient_rect_east(wxDC &dc, const wxRect &rect, const wxColour &from, const wxColour &to)
Definition FilamentBitmapUtils.cpp:76
void change_the_opacity(wxColour &colour)
Definition DeviceManager.cpp:6154
@ left
Definition MarchingSquares.hpp:188

References Slic3r::change_the_opacity(), Slic3r::GUI::fill_gradient_rect_east(), get_remain_area_height(), m_coloul, m_transparent_mapping_item, m_tray_data, m_unmatch, and MAPPING_ITEM_REAL_SIZE.

Referenced by render().

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

◆ get_remain_area_height()

int Slic3r::GUI::MappingItem::get_remain_area_height ( ) const
private
1603{
1604 if (m_to_paint_remain) { return FromDIP(10);}
1605 return 0;
1606}
bool m_to_paint_remain
Definition AmsMappingPopup.hpp:232

References m_to_paint_remain.

Referenced by doRender(), and render().

Here is the caller graph for this function:

◆ msw_rescale()

void Slic3r::GUI::MappingItem::msw_rescale ( )
1385 {
1386 m_transparent_mapping_item.msw_rescale();
1387 mapping_item_checked.msw_rescale();
1388 Refresh();
1389 }

References m_transparent_mapping_item, and mapping_item_checked.

◆ paintEvent()

void Slic3r::GUI::MappingItem::paintEvent ( wxPaintEvent & evt)
private
1392{
1393 wxPaintDC dc(this);
1394 render(dc);
1395
1396 // PrepareDC(buffdc);
1397 // PrepareDC(dc);
1398}
void render(wxDC &dc)
Definition AmsMappingPopup.cpp:1432

References render().

Referenced by MappingItem().

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

◆ render()

void Slic3r::GUI::MappingItem::render ( wxDC & dc)
private
1433{
1434 wxSize size = GetSize();
1435
1436#ifdef __WXMSW__
1437 wxMemoryDC memdc;
1438 wxBitmap bmp(size.x, size.y);
1439 memdc.SelectObject(bmp);
1440 memdc.Blit({0, 0}, size, &dc, {0, 0});
1441
1442 {
1443 wxGCDC dc2(memdc);
1444 doRender(dc2);
1445 }
1446
1447 memdc.SelectObject(wxNullBitmap);
1448 dc.DrawBitmap(bmp, 0, 0);
1449#else
1450 doRender(dc);
1451#endif
1452
1453 /*remain*/
1454 auto top = 0;
1456 {
1458 top += get_remain_area_height();
1459 }
1460
1461 // checked
1462 if (m_checked)
1463 {
1464 dc.DrawBitmap(mapping_item_checked.bmp(), size.x - mapping_item_checked.GetBmpWidth() - FromDIP(4), top);
1465 }
1466 top += 0.5 * mapping_item_checked.GetBmpHeight();
1467
1468 // materials name
1469 dc.SetFont(::Label::Head_12);
1470
1471 auto txt_colour = m_coloul.GetLuminance() < 0.6 ? *wxWHITE : wxColour(0x26, 0x2E, 0x30);
1472
1473 if (m_unmatch || m_name == "-" ) { txt_colour = wxColour(0xCE, 0xCE, 0xCE); }
1474 // txt_colour = m_unmatch ? wxColour(0xCE, 0xCE, 0xCE) : txt_colour;
1475
1476 if (m_coloul.Alpha() == 0)
1477 txt_colour = wxColour(0x26, 0x2E, 0x30);
1478 if (!IsEnabled())
1479 txt_colour = wxColour(0xCE, 0xCE, 0xCE);
1480
1481 dc.SetTextForeground(txt_colour);
1482 //show a1
1483 auto txt_size = dc.GetTextExtent(m_tray_index);
1484 top += FromDIP(2);
1485 dc.DrawText(m_tray_index, wxPoint((GetSize().x - txt_size.x) / 2, top));
1486
1487 //show materials name
1488 top += txt_size.y + FromDIP(2);
1489 m_name.size() > 4 ? dc.SetFont(::Label::Body_9) : dc.SetFont(::Label::Body_12);
1490 if(m_name.size() > 5){
1491 m_name = m_name.substr(0,5) + "...";
1492 }
1493 txt_size = dc.GetTextExtent(m_name);
1494 dc.DrawText(m_name, wxPoint((GetSize().x - txt_size.x) / 2, top));
1495}
static wxFont Body_9
Definition Label.hpp:58
static wxFont Head_12
Definition Label.hpp:47
static wxFont Body_12
Definition Label.hpp:55
bool m_support_remain_detect
Definition AmsMappingPopup.hpp:231
bool m_checked
Definition AmsMappingPopup.hpp:230
wxString m_name
Definition AmsMappingPopup.hpp:204
wxString m_tray_index
Definition AmsMappingPopup.hpp:202
void doRender(wxDC &dc)
Definition AmsMappingPopup.cpp:1555
bool IsEnabled()
Definition dark_mode.cpp:32
static void _DrawRemainArea(const MappingItem *item, const TrayData &dd, bool support_remain_dect, wxDC &dc)
Definition AmsMappingPopup.cpp:1400

References Slic3r::GUI::_DrawRemainArea(), Label::Body_12, Label::Body_9, doRender(), get_remain_area_height(), Label::Head_12, m_checked, m_coloul, m_name, m_support_remain_detect, m_to_paint_remain, m_tray_data, m_tray_index, m_unmatch, and mapping_item_checked.

Referenced by paintEvent().

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

◆ send_event()

void Slic3r::GUI::MappingItem::send_event ( int fliament_id)
1370{
1371 wxCommandEvent event(EVT_SET_FINISH_MAPPING);
1372 event.SetInt(m_tray_data.id);
1373
1374 wxString param = wxString::Format("%d|%d|%d|%d|%s|%d|%d|%d", m_coloul.Red(), m_coloul.Green(), m_coloul.Blue(), m_coloul.Alpha(), m_tray_index, fliament_id,
1375 m_tray_data.ams_id, m_tray_data.slot_id);
1376 event.SetString(param);
1377
1378 if (send_win) {
1379 event.SetEventObject(send_win);
1380 wxPostEvent(send_win, event);
1381 }
1382}
wxWindow * send_win
Definition AmsMappingPopup.hpp:201

References m_coloul, m_tray_data, m_tray_index, and send_win.

Referenced by Slic3r::GUI::AmsMapingPopup::add_ams_mapping(), and Slic3r::GUI::AmsMapingPopup::add_ext_ams_mapping().

Here is the caller graph for this function:

◆ set_checked()

void Slic3r::GUI::MappingItem::set_checked ( bool checked)
1547{
1548 if (m_checked != checked)
1549 {
1550 m_checked = checked;
1551 Refresh();
1552 }
1553}

References m_checked.

◆ set_data()

void Slic3r::GUI::MappingItem::set_data ( const wxString & tag_name,
wxColour colour,
wxString name,
bool remain_detect,
TrayData data,
bool unmatch = false,
std::optional< wxString > tooltip_opt = std::nullopt )
1498{
1499 m_unmatch = unmatch;
1500 m_tray_data = data;
1501
1502 if (m_coloul != colour || m_name != name || (m_support_remain_detect != remain_dect)) {
1503 m_coloul = colour;
1504 m_name = name;
1505 m_support_remain_detect = remain_dect;
1507 Refresh();
1508 }
1509
1510 if (tooltip_opt.has_value())
1511 {
1512 SetToolTip(tooltip_opt.value());
1513 }
1514 else if (m_unmatch || (m_name == "-"))
1515 {
1516 if (m_unmatch) {
1517 bool is_external_spool = (m_tray_data.ams_id == VIRTUAL_TRAY_MAIN_ID || m_tray_data.ams_id == VIRTUAL_TRAY_DEPUTY_ID);
1518
1519 if (!m_name.IsEmpty() && (m_name != "-")) {
1520 wxString msg;
1521 if (is_external_spool) {
1522 msg = wxString::Format(_L("Tips: the filament type(%s) does not match with the filament type(%s) in the slicing file. "
1523 "If you want to use this slot, you can install %s instead of %s and change slot information on the 'Device' page."),
1524 m_name, tag_name, tag_name, m_name);
1525 } else {
1526 msg = wxString::Format(_L("Cannot select: the filament type(%s) does not match with the filament type(%s) in the slicing file. "
1527 "If you want to use this slot, you can install %s instead of %s and change slot information on the 'Device' page."),
1528 m_name, tag_name, tag_name, m_name);
1529 }
1530 SetToolTip(msg);
1531 } else {
1532 const wxString &msg = wxString::Format(_L("Cannot select: the slot is empty or undefined. If you want to use this slot, you can install %s and change slot information on the 'Device' page."), tag_name);
1533 SetToolTip(msg);
1534 }
1535
1536 } else {
1537 SetToolTip(_L("Cannot select: No filament loaded in current slot."));
1538 }
1539 }
1540 else
1541 {
1542 SetToolTip(wxEmptyString);
1543 }
1544}
#define VIRTUAL_TRAY_DEPUTY_ID
Definition DevDefs.h:90
#define VIRTUAL_TRAY_MAIN_ID
Definition DevDefs.h:89
#define _L(s)
Definition OBJ.cpp:34

References _L, m_coloul, m_name, m_support_remain_detect, m_to_paint_remain, m_tray_data, m_unmatch, VIRTUAL_TRAY_DEPUTY_ID, and VIRTUAL_TRAY_MAIN_ID.

Referenced by Slic3r::GUI::AmsMapingPopup::add_ams_mapping(), and Slic3r::GUI::AmsMapingPopup::add_ext_ams_mapping().

Here is the caller graph for this function:

◆ set_tray_index()

void Slic3r::GUI::MappingItem::set_tray_index ( wxString t_index)
inline
218{ m_tray_index = t_index; };

References m_tray_index.

Referenced by Slic3r::GUI::AmsMapingPopup::add_ams_mapping(), and Slic3r::GUI::AmsMapingPopup::add_ext_ams_mapping().

Here is the caller graph for this function:

◆ update_data()

void Slic3r::GUI::MappingItem::update_data ( TrayData data)

Member Data Documentation

◆ m_ams_id

int Slic3r::GUI::MappingItem::m_ams_id {255}

◆ m_checked

bool Slic3r::GUI::MappingItem::m_checked = false
private

Referenced by render(), and set_checked().

◆ m_coloul

wxColour Slic3r::GUI::MappingItem::m_coloul

Referenced by doRender(), render(), send_event(), and set_data().

◆ m_name

wxString Slic3r::GUI::MappingItem::m_name

Referenced by render(), and set_data().

◆ m_slot_id

int Slic3r::GUI::MappingItem::m_slot_id {255}

◆ m_support_remain_detect

bool Slic3r::GUI::MappingItem::m_support_remain_detect = false
private

Referenced by render(), and set_data().

◆ m_to_paint_remain

bool Slic3r::GUI::MappingItem::m_to_paint_remain = false
private

◆ m_transparent_mapping_item

ScalableBitmap Slic3r::GUI::MappingItem::m_transparent_mapping_item

Referenced by MappingItem(), doRender(), and msw_rescale().

◆ m_tray_data

TrayData Slic3r::GUI::MappingItem::m_tray_data

Referenced by doRender(), render(), send_event(), and set_data().

◆ m_tray_index

wxString Slic3r::GUI::MappingItem::m_tray_index

Referenced by render(), send_event(), and set_tray_index().

◆ m_unmatch

bool Slic3r::GUI::MappingItem::m_unmatch {false}
208{false};

Referenced by doRender(), render(), and set_data().

◆ mapping_item_checked

ScalableBitmap Slic3r::GUI::MappingItem::mapping_item_checked

Referenced by MappingItem(), msw_rescale(), and render().

◆ send_win

wxWindow* Slic3r::GUI::MappingItem::send_win {nullptr}

The documentation for this class was generated from the following files: