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

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

Inheritance diagram for Slic3r::GUI::SkipPartCanvas:
Collaboration diagram for Slic3r::GUI::SkipPartCanvas:

Classes

union  SkipIdHelper
struct  SkipIdHelper.__unnamed0__

Public Member Functions

 SkipPartCanvas (wxWindow *parent, const wxGLAttributes &dispAttrs)
 ~SkipPartCanvas ()=default
void SetParentBackground (const ColorRGB &color)
void LoadPickImage (const std::string &path)
void ZoomIn (const int zoom_percent)
void ZoomOut (const int zoom_percent)
void SwitchDrag (const bool drag_on)
void UpdatePartsInfo (const PartsInfo &parts)
void SetZoomPercent (const int value)
void SetOffset (const wxPoint &value)

Public Attributes

wxTextCtrl * log_ctrl

Protected Member Functions

void OnPaint (wxPaintEvent &event)
void OnSize (wxSizeEvent &event)
void OnMouseLeftDown (wxMouseEvent &event)
void OnMouseLeftUp (wxMouseEvent &event)
void OnMouseRightDown (wxMouseEvent &event)
void OnMouseRightUp (wxMouseEvent &event)
void OnMouseMotion (wxMouseEvent &event)
void OnMouseWheel (wxMouseEvent &event)

Private Member Functions

void SendSelectEvent (int id, PartState state)
void SendZoomEvent (int zoom_percent)
double Zoom () const
wxPoint ViewPtToImagePt (const wxPoint &view_pt) const
uint32_t GetIdAtImagePt (const wxPoint &image_pt) const
uint32_t GetIdAtViewPt (const wxPoint &view_pt) const
void ProcessHover (const wxPoint &mouse_pt)
void AutoSetCursor ()
void StartDrag (const wxPoint &mouse_pt)
void ProcessDrag (const wxPoint &mouse_pt)
void EndDrag ()
void Render ()
void DebugLogLine (std::string str)

Private Attributes

wxGLContext * context_
cv::Mat pick_image_
std::unordered_map< uint32_t, std::vector< std::vector< FloatPoint > > > parts_triangles_
std::unordered_map< uint32_t, std::vector< std::vector< cv::Point > > > pick_parts_
std::unordered_map< uint32_t, PartState > parts_state_
int zoom_percent_ {100}
wxPoint offset_ {0,0}
wxPoint drag_start_offset_ {0,0}
wxPoint drag_start_pt_ {0,0}
bool is_draging_ {false}
bool fixed_draging_ {false}
bool left_down_ {false}
ColorRGB parent_color_ = ColorRGB()
int hover_id_ {-1}
double image_view_scale_ {1}

Detailed Description


Class Documentation

◆ Slic3r::GUI::SkipPartCanvas::SkipIdHelper.__unnamed0__

struct Slic3r::GUI::SkipPartCanvas::SkipIdHelper.__unnamed0__
Class Members
uint8_t _padding
uint8_t b
uint8_t g
uint8_t r

Constructor & Destructor Documentation

◆ SkipPartCanvas()

Slic3r::GUI::SkipPartCanvas::SkipPartCanvas ( wxWindow * parent,
const wxGLAttributes & dispAttrs )
45 : wxGLCanvas(parent, dispAttrs) {
46 context_ = new wxGLContext(this);
47 this->Bind(wxEVT_PAINT, &SkipPartCanvas::OnPaint, this);
48 this->Bind(wxEVT_MOUSEWHEEL, &SkipPartCanvas::OnMouseWheel, this);
49 this->Bind(wxEVT_LEFT_DOWN, &SkipPartCanvas::OnMouseLeftDown, this);
50 this->Bind(wxEVT_LEFT_DCLICK, &SkipPartCanvas::OnMouseLeftDown, this);
51 this->Bind(wxEVT_LEFT_UP, &SkipPartCanvas::OnMouseLeftUp, this);
52 this->Bind(wxEVT_RIGHT_DOWN, &SkipPartCanvas::OnMouseRightDown, this);
53 this->Bind(wxEVT_RIGHT_UP, &SkipPartCanvas::OnMouseRightUp, this);
54 this->Bind(wxEVT_SIZE, &SkipPartCanvas::OnSize, this);
55 this->Bind(wxEVT_MOTION, &SkipPartCanvas::OnMouseMotion, this);
56}
void OnPaint(wxPaintEvent &event)
Definition SkipPartCanvas.cpp:513
void OnMouseLeftDown(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:529
void OnMouseWheel(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:601
wxGLContext * context_
Definition SkipPartCanvas.hpp:97
void OnMouseLeftUp(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:542
void OnMouseMotion(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:591
void OnSize(wxSizeEvent &event)
Definition SkipPartCanvas.cpp:524
void OnMouseRightDown(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:569
void OnMouseRightUp(wxMouseEvent &event)
Definition SkipPartCanvas.cpp:580

References context_, OnMouseLeftDown(), OnMouseLeftUp(), OnMouseMotion(), OnMouseRightDown(), OnMouseRightUp(), OnMouseWheel(), OnPaint(), and OnSize().

Here is the call graph for this function:

◆ ~SkipPartCanvas()

Slic3r::GUI::SkipPartCanvas::~SkipPartCanvas ( )
default

Member Function Documentation

◆ AutoSetCursor()

void Slic3r::GUI::SkipPartCanvas::AutoSetCursor ( )
private
471{
473 SetCursor(wxCursor(wxCURSOR_HAND));
474 else
475 SetCursor(wxCursor(wxCURSOR_NONE));
476}
bool is_draging_
Definition SkipPartCanvas.hpp:106
bool fixed_draging_
Definition SkipPartCanvas.hpp:107

References fixed_draging_, and is_draging_.

Referenced by EndDrag(), StartDrag(), and SwitchDrag().

Here is the caller graph for this function:

◆ DebugLogLine()

void Slic3r::GUI::SkipPartCanvas::DebugLogLine ( std::string str)
private
402{
403 //if (!log_ctrl)
404 // return;
405 //log_ctrl->AppendText(str + "\n");
406}

Referenced by OnMouseLeftDown(), OnMouseLeftUp(), OnMouseRightDown(), OnMouseRightUp(), and SetZoomPercent().

Here is the caller graph for this function:

◆ EndDrag()

void Slic3r::GUI::SkipPartCanvas::EndDrag ( )
private
508{
509 is_draging_ = false;
511}
void AutoSetCursor()
Definition SkipPartCanvas.cpp:470

References AutoSetCursor(), and is_draging_.

Referenced by OnMouseLeftUp(), and OnMouseRightUp().

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

◆ GetIdAtImagePt()

uint32_t Slic3r::GUI::SkipPartCanvas::GetIdAtImagePt ( const wxPoint & image_pt) const
private
431{
432 if (image_pt.x >= 0 && image_pt.x < pick_image_.cols
433 && image_pt.y >= 0 && image_pt.y < pick_image_.rows) {
434 // at(row, col)=>at(y, x)
435 cv::Vec3b bgr = pick_image_.at<cv::Vec3b>(image_pt.y, image_pt.x);
436 SkipIdHelper helper{bgr[2], bgr[1], bgr[0]};
437 helper.reverse();
438 return helper.value;
439 } else {
440 return 0;
441 }
442}
cv::Mat pick_image_
Definition SkipPartCanvas.hpp:98
Definition SkipPartCanvas.hpp:45
void reverse()
Definition SkipPartCanvas.hpp:64

References pick_image_, and Slic3r::GUI::SkipPartCanvas::SkipIdHelper::reverse().

Referenced by GetIdAtViewPt().

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

◆ GetIdAtViewPt()

uint32_t Slic3r::GUI::SkipPartCanvas::GetIdAtViewPt ( const wxPoint & view_pt) const
inlineprivate
445{
446 wxPoint pt_at_image = ViewPtToImagePt(view_pt);
447 return GetIdAtImagePt(pt_at_image);
448}
uint32_t GetIdAtImagePt(const wxPoint &image_pt) const
Definition SkipPartCanvas.cpp:430
wxPoint ViewPtToImagePt(const wxPoint &view_pt) const
Definition SkipPartCanvas.cpp:425

References GetIdAtImagePt(), and ViewPtToImagePt().

Referenced by OnMouseLeftUp(), and ProcessHover().

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

◆ LoadPickImage()

void Slic3r::GUI::SkipPartCanvas::LoadPickImage ( const std::string & path)
59{
60 if(!std::filesystem::exists(path)) return;
61
62 auto ParseShapeId = [](cv::Mat image, const std::vector<std::vector<cv::Point>> &contours, const std::vector<cv::Vec4i> &hierarchy, int root_idx) -> uint32_t {
63 cv::Mat mask = cv::Mat::zeros(image.size(), CV_8UC1);
64
65 cv::drawContours(mask, contours, root_idx, 255, cv::FILLED);
66
67 int child = hierarchy[root_idx][2];
68 while (child != -1) {
69 cv::drawContours(mask, contours, child, 0, cv::FILLED);
70 child = hierarchy[child][0];
71 }
72 std::vector<cv::Vec3b> pixels;
73 for (int y = 0; y < image.rows; ++y) {
74 for (int x = 0; x < image.cols; ++x) {
75 if (mask.at<uchar>(y, x)) { pixels.push_back(image.at<cv::Vec3b>(y, x)); }
76 }
77 }
78
79 std::map<cv::Vec3b, int, std::function<bool(const cv::Vec3b &, const cv::Vec3b &)>> colorCount(
80 [](const cv::Vec3b &a, const cv::Vec3b &b) { return std::lexicographical_compare(a.val, a.val + 3, b.val, b.val + 3); });
81
82 for (auto &c : pixels) colorCount[c]++;
83
84 cv::Vec3b main_color;
85 int max_count = 0;
86 int total_count = 0;
87 for (const auto &kv : colorCount) {
88 if (kv.second > max_count) {
89 max_count = kv.second;
90 main_color = kv.first;
91 }
92 total_count += kv.second;
93 }
94
95 SkipIdHelper helper{main_color[2], main_color[1], main_color[0]};
96 helper.reverse();
97 return (max_count * 2 > total_count) ? helper.value : 0;
98 };
99
100 parts_state_.clear();
101 parts_triangles_.clear();
102 pick_parts_.clear();
103 int preffered_w{FromDIP(400)}, preffered_h{FromDIP(400)};
104 cv::Mat src_image = cv::imread(path, cv::IMREAD_UNCHANGED);
105 cv::cvtColor(src_image, src_image, cv::COLOR_BGRA2BGR); // remove alpha
106 float zoom_x{static_cast<float>(preffered_w) / src_image.cols};
107 float zoom_y{static_cast<float>(preffered_h) / src_image.rows};
108 float image_scale{0};
109 if (abs(zoom_x - 1) > abs(zoom_y - 1))
110 image_scale = zoom_x;
111 else
112 image_scale = zoom_y;
113 image_view_scale_ = 1 / image_scale;
114 pick_image_ = src_image;
115 std::vector<cv::Mat> channels;
116 cv::Mat gray; // convert to gray
117 cv::cvtColor(pick_image_, gray, cv::COLOR_BGR2GRAY);
118 cv::Mat mask; // convery to binary
119 cv::threshold(gray, mask, 0, 255, cv::THRESH_BINARY);
120 std::vector<std::vector<cv::Point>> pick_counters;
121 std::vector<cv::Vec4i> hierarchy;
122 cv::findContours(mask, pick_counters, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_TC89_KCOS);
123 auto compute_depth = [&](int idx) {
124 int depth = 0;
125 while (hierarchy[idx][3] != -1) {
126 depth++;
127 idx = hierarchy[idx][3];
128 }
129 return depth;
130 };
131 for (int i = 0; i < pick_counters.size(); ++i) {
132 int depth = compute_depth(i);
133 int parent = hierarchy[i][3];
134 if (parent != -1) continue;
135
136 auto id = ParseShapeId(pick_image_, pick_counters, hierarchy, i);
137 if (id > 0) {
138 std::vector<FloatPoint> flat_points;
139 std::vector<std::vector<FloatPoint>> polygon;
140
141 // part body
142 {
143 polygon.emplace_back();
144 for (const auto &pt : pick_counters[i]) {
145 FloatPoint fp{pt.x * 1.0f, pt.y * 1.0f};
146 polygon.back().push_back(fp);
147 flat_points.push_back(fp);
148 }
149 int child = hierarchy[i][2];
150 while (child != -1) {
151 polygon.emplace_back();
152 for (const auto &pt : pick_counters[child]) {
153 FloatPoint fp{pt.x * 1.0f, pt.y * 1.0f};
154 polygon.back().push_back(fp);
155 flat_points.push_back(fp);
156 }
157 child = hierarchy[child][0];
158 }
159 std::vector<uint32_t> indices = mapbox::earcut<uint32_t>(polygon);
160 std::vector<FloatPoint> final_counter;
161 for (size_t j = 0; j < indices.size(); j += 3) {
162 final_counter.push_back(flat_points[indices[j]]);
163 final_counter.push_back(flat_points[indices[j + 1]]);
164 final_counter.push_back(flat_points[indices[j + 2]]);
165 }
166
167 parts_triangles_[id].emplace_back(final_counter);
168 }
169 // part outlines
170 {
171 pick_parts_[id].emplace_back(pick_counters[i]);
172 int child = hierarchy[i][2];
173 while (child != -1) {
174 pick_parts_[id].emplace_back(pick_counters[child]);
175 child = hierarchy[child][0];
176 }
177 }
178 if (parts_state_.find(id) == parts_state_.end()) parts_state_.emplace(id, psUnCheck);
179 }
180 }
181}
std::unordered_map< uint32_t, PartState > parts_state_
Definition SkipPartCanvas.hpp:101
std::unordered_map< uint32_t, std::vector< std::vector< cv::Point > > > pick_parts_
Definition SkipPartCanvas.hpp:100
std::unordered_map< uint32_t, std::vector< std::vector< FloatPoint > > > parts_triangles_
Definition SkipPartCanvas.hpp:99
double image_view_scale_
Definition SkipPartCanvas.hpp:111
std::array< Coord, 2 > FloatPoint
Definition SkipPartCanvas.hpp:33
@ psUnCheck
Definition PartSkipCommon.hpp:10

References image_view_scale_, parts_state_, parts_triangles_, pick_image_, pick_parts_, Slic3r::GUI::psUnCheck, Slic3r::GUI::SkipPartCanvas::SkipIdHelper::reverse(), and Slic3r::GUI::SkipPartCanvas::SkipIdHelper::value.

Here is the call graph for this function:

◆ OnMouseLeftDown()

void Slic3r::GUI::SkipPartCanvas::OnMouseLeftDown ( wxMouseEvent & event)
protected
530{
531 DebugLogLine("OnMouseLeftDown");
532 if (!event.LeftIsDown()) {
533 event.Skip();
534 DebugLogLine("skip----OnMouseLeftDown");
535 return;
536 }
537 if (fixed_draging_)
538 StartDrag(wxPoint(event.GetX(), event.GetY()));
539 left_down_ = true;
540}
bool left_down_
Definition SkipPartCanvas.hpp:108
void StartDrag(const wxPoint &mouse_pt)
Definition SkipPartCanvas.cpp:478
void DebugLogLine(std::string str)
Definition SkipPartCanvas.cpp:401

References DebugLogLine(), fixed_draging_, left_down_, StartDrag(), and Slic3r::GUI::wxMouseEvent.

Referenced by SkipPartCanvas().

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

◆ OnMouseLeftUp()

void Slic3r::GUI::SkipPartCanvas::OnMouseLeftUp ( wxMouseEvent & event)
protected
543{
544 DebugLogLine("OnMouseLeftUp");
545 if (event.LeftIsDown() || !left_down_) {
546 event.Skip();
547 DebugLogLine("skip----OnMouseLeftUp");
548 return;
549 }
550 auto id_at_mouse = GetIdAtViewPt(wxPoint(event.GetX(), event.GetY()));
551 auto part_state = parts_state_.find(id_at_mouse);
552 if (part_state != parts_state_.end() && part_state->second != psSkipped) {
553 if (part_state->second == psUnCheck)
554 part_state = parts_state_.insert_or_assign(part_state->first, psChecked).first;
555 else
556 part_state = parts_state_.insert_or_assign(part_state->first, psUnCheck).first;
557 // if (select_callback_)
558 // select_callback_(part_state->first, part_state->second);
559 SendSelectEvent(part_state->first, part_state->second);
560 }
561 left_down_ = false;
562 if (fixed_draging_)
563 EndDrag();
564 else {
565 Refresh();
566 }
567}
uint32_t GetIdAtViewPt(const wxPoint &view_pt) const
Definition SkipPartCanvas.cpp:444
void SendSelectEvent(int id, PartState state)
Definition SkipPartCanvas.cpp:408
void EndDrag()
Definition SkipPartCanvas.cpp:507
@ psChecked
Definition PartSkipCommon.hpp:11
@ psSkipped
Definition PartSkipCommon.hpp:12

References DebugLogLine(), EndDrag(), fixed_draging_, GetIdAtViewPt(), left_down_, parts_state_, Slic3r::GUI::psChecked, Slic3r::GUI::psSkipped, Slic3r::GUI::psUnCheck, SendSelectEvent(), and Slic3r::GUI::wxMouseEvent.

Referenced by SkipPartCanvas().

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

◆ OnMouseMotion()

void Slic3r::GUI::SkipPartCanvas::OnMouseMotion ( wxMouseEvent & event)
protected
592{
593 ProcessHover(wxPoint(event.GetX(), event.GetY()));
594 if (!event.RightIsDown() && !(event.LeftIsDown() && fixed_draging_)) {
595 event.Skip();
596 return;
597 }
598 ProcessDrag(wxPoint(event.GetX(), event.GetY()));
599}
void ProcessHover(const wxPoint &mouse_pt)
Definition SkipPartCanvas.cpp:493
void ProcessDrag(const wxPoint &mouse_pt)
Definition SkipPartCanvas.cpp:486

References fixed_draging_, ProcessDrag(), ProcessHover(), and Slic3r::GUI::wxMouseEvent.

Referenced by SkipPartCanvas().

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

◆ OnMouseRightDown()

void Slic3r::GUI::SkipPartCanvas::OnMouseRightDown ( wxMouseEvent & event)
protected
570{
571 DebugLogLine("OnMouseRightDown");
572 if (!event.RightIsDown()) {
573 event.Skip();
574 DebugLogLine("skip----OnMouseRightDown");
575 return;
576 }
577 StartDrag(wxPoint(event.GetX(), event.GetY()));
578}

References DebugLogLine(), StartDrag(), and Slic3r::GUI::wxMouseEvent.

Referenced by SkipPartCanvas().

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

◆ OnMouseRightUp()

void Slic3r::GUI::SkipPartCanvas::OnMouseRightUp ( wxMouseEvent & event)
protected
581{
582 DebugLogLine("OnMouseRightUp");
583 if (event.RightIsDown() || !is_draging_) {
584 event.Skip();
585 DebugLogLine("skip----OnMouseRightUp");
586 return;
587 }
588 EndDrag();
589}

References DebugLogLine(), EndDrag(), is_draging_, and Slic3r::GUI::wxMouseEvent.

Referenced by SkipPartCanvas().

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

◆ OnMouseWheel()

void Slic3r::GUI::SkipPartCanvas::OnMouseWheel ( wxMouseEvent & event)
protected
602{
603 wxPoint view_mouse = wxPoint(event.GetX(), event.GetY());
604 auto pre_image_pos = ViewPtToImagePt(view_mouse);
605 SetZoomPercent(zoom_percent_ + 10 * (event.GetWheelRotation() / 120.0));
606 auto now_image_pos = ViewPtToImagePt(view_mouse);
607 SetOffset(offset_ - (now_image_pos - pre_image_pos));
608 Refresh();
609}
void SetZoomPercent(const int value)
Definition SkipPartCanvas.cpp:450
void SetOffset(const wxPoint &value)
Definition SkipPartCanvas.cpp:460
wxPoint offset_
Definition SkipPartCanvas.hpp:103
int zoom_percent_
Definition SkipPartCanvas.hpp:102

References offset_, SetOffset(), SetZoomPercent(), ViewPtToImagePt(), Slic3r::GUI::wxMouseEvent, and zoom_percent_.

Referenced by SkipPartCanvas().

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

◆ OnPaint()

void Slic3r::GUI::SkipPartCanvas::OnPaint ( wxPaintEvent & event)
protected
514 {
515 wxPaintDC dc(this);
516 if (!IsShown()) return;
517
518 SetCurrent(*context_);
519
520 Render();
521 SwapBuffers();
522 }
void Render()
Definition SkipPartCanvas.cpp:268

References context_, and Render().

Referenced by SkipPartCanvas().

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

◆ OnSize()

void Slic3r::GUI::SkipPartCanvas::OnSize ( wxSizeEvent & event)
protected
525{
526 event.Skip();
527}

Referenced by SkipPartCanvas().

Here is the caller graph for this function:

◆ ProcessDrag()

void Slic3r::GUI::SkipPartCanvas::ProcessDrag ( const wxPoint & mouse_pt)
private
487{
488 wxPoint drag_offset = (mouse_pt - drag_start_pt_) * image_view_scale_;
489 SetOffset(- wxPoint(drag_offset.x / Zoom(), drag_offset.y / Zoom()) + drag_start_offset_);
490 Refresh();
491}
wxPoint drag_start_offset_
Definition SkipPartCanvas.hpp:104
wxPoint drag_start_pt_
Definition SkipPartCanvas.hpp:105
double Zoom() const
Definition SkipPartCanvas.cpp:420

References drag_start_offset_, drag_start_pt_, image_view_scale_, SetOffset(), and Zoom().

Referenced by OnMouseMotion().

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

◆ ProcessHover()

void Slic3r::GUI::SkipPartCanvas::ProcessHover ( const wxPoint & mouse_pt)
private
494{
495 auto id_at_mouse = GetIdAtViewPt(mouse_pt);
496 int new_hover_id { -1 };
497 auto part_state = parts_state_.find(id_at_mouse);
498 if (part_state != parts_state_.end() && part_state->second == psUnCheck) {
499 new_hover_id = id_at_mouse;
500 };
501 if (new_hover_id != this->hover_id_) {
502 this->hover_id_ = new_hover_id;
503 Refresh();
504 }
505}
int hover_id_
Definition SkipPartCanvas.hpp:110

References GetIdAtViewPt(), hover_id_, parts_state_, and Slic3r::GUI::psUnCheck.

Referenced by OnMouseMotion().

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

◆ Render()

void Slic3r::GUI::SkipPartCanvas::Render ( )
private
269{
270 constexpr float border_w = 3.f;
271 constexpr int uncheckd_stencil =1;
272 constexpr int checkd_stencil = 2;
273 constexpr int skipped_stencil = 3;
274
275 SetCurrent(*context_);
277
278 int w, h;
279 GetClientSize(&w, &h);
280#if defined(__APPLE__)
281 double scale = GetDPIScaleFactor();
282 glViewport(0, 0, w * scale, h * scale);
283#else
284 glViewport(0, 0, w, h);
285#endif
288 auto view_rect = ViewPtToImagePt(wxPoint(w, h));
289 glOrtho(offset_.x, view_rect.x, view_rect.y, offset_.y, -1, 1);
292
295
296 float rx = offset_.x;
297 float ry = offset_.y;
298 float rw = view_rect.x - offset_.x;
299 float rh = view_rect.y - offset_.y;
300 float radius = std::min(rw, rh) * 0.05f;
301
302 DrawRoundedRect(rx, ry, rw, rh, radius, ColorRGB{0.9f, 0.9f, 0.9f});
303
311
312 auto draw_shape = [this](const int stencil, const PartState part_type, const ColorRGB& rgb) {
314 glStencilFunc(GL_ALWAYS, stencil, 0xFF);
316
317 for (const auto& contour : parts_triangles_) {
318 auto part_info = parts_state_.find(contour.first);
319 if (part_info == parts_state_.end() || part_info->second != part_type)
320 continue;
321 glColor3f(1, 1, 1);
322 for (const auto &contour_item : contour.second) {
324 for (size_t i = 0; i < contour_item.size(); i += 3) {
325 glVertex2f(contour_item[i][0], contour_item[i][1]);
326 glVertex2f(contour_item[i + 1][0], contour_item[i + 1][1]);
327 glVertex2f(contour_item[i + 2][0], contour_item[i + 2][1]);
328 }
329 glEnd();
330 }
331 }
332
333 for (const auto& contour : pick_parts_) {
334 if (contour.first != this->hover_id_) continue;
335 auto part_info = parts_state_.find(contour.first);
336 if (part_info == parts_state_.end() || part_info->second != part_type)
337 continue;
338
339 glColor3f(rgb.r(), rgb.g(), rgb.b());
340 glLineWidth(border_w);
341 for (const auto &contour_item : contour.second) {
343 for (const auto &pt : contour_item) { glVertex2f(pt.x, pt.y); }
344 glEnd();
345 }
346 }
347 };
348 // draw unchecked shapes
349 // stencil1 => unchecked
350 draw_shape(uncheckd_stencil, psUnCheck, ColorRGB{0, 174 / 255.f, 66 / 255.f});
351
352 // draw checked shapes
353 // stencil2 => checked
354 draw_shape(checkd_stencil, psChecked, ColorRGB{208 / 255.f, 27 / 255.f, 66 / 255.f});
355
356 // draw skipped shapes
357 // stencil3 => skipped
358 draw_shape(skipped_stencil, psSkipped, ColorRGB{95 / 255.f, 95 / 255.f, 95 / 255.f});
359
360 auto draw_mask = [this, view_rect](const int stencil, const PartState part_type,
361 const ColorRGB& background, const ColorRGB& line, const ColorRGB& bound) {
363 glStencilFunc(GL_EQUAL, stencil, 0xFF);
364 glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // Don't change stencil
365 glColor3f(background.r(), background.g(), background.b());
368 glVertex2f(offset_.x, view_rect.y);
369 glVertex2f(view_rect.x, view_rect.y);
370 glVertex2f(view_rect.x, offset_.y);
371 glEnd();
372 // draw main color
373 glColor3f(line.r(), line.g(), line.b());
374 // re-draw shape bound
375 for (const auto& contour : pick_parts_) {
376 auto part_info = parts_state_.find(contour.first);
377 if (part_info == parts_state_.end() || part_info->second != part_type)
378 continue;
379 glColor3f(bound.r(), bound.g(), bound.b());
380 glLineWidth(border_w);
381 for (const auto &contour_item : contour.second) {
383 for (const auto &pt : contour_item) { glVertex2f(pt.x, pt.y); }
384 glEnd();
385 }
386 }
387 };
388
389 draw_mask(checkd_stencil, psChecked, ColorRGB{239 / 255.f, 175 / 255.f, 175 / 255.f},
390 ColorRGB{225 / 255.f, 71 / 255.f, 71 / 255.f}, ColorRGB{208 / 255.f, 27 / 255.f, 27 / 255.f});
391
392 draw_mask(skipped_stencil, psSkipped, ColorRGB{159 / 255.f, 159 / 255.f, 159 / 255.f},
393 ColorRGB{95 / 255.f, 95 / 255.f, 95 / 255.f}, ColorRGB{95 / 255.f, 95 / 255.f, 95 / 255.f});
394
396
397 glPopAttrib();
398 glFlush();
399}
int scale(const int val)
Definition WipeTowerDialog.cpp:58
ColorRGB parent_color_
Definition SkipPartCanvas.hpp:109
#define GL_TRUE
Definition gl.h:1892
#define GL_ALWAYS
Definition gl.h:230
#define glVertex2f
Definition gl.h:5097
#define glClearColor
Definition gl.h:3373
#define GL_NICEST
Definition gl.h:1205
#define glColor3f
Definition gl.h:3415
#define glBegin
Definition gl.h:3255
#define glEnable
Definition gl.h:3667
#define GL_STENCIL_TEST
Definition gl.h:1664
#define GL_SRC_ALPHA
Definition gl.h:1621
#define GL_TRIANGLES
Definition gl.h:1887
#define glStencilOp
Definition gl.h:4783
#define glOrtho
Definition gl.h:4433
#define glColorMask
Definition gl.h:3471
#define GL_PROJECTION
Definition gl.h:1348
#define glStencilFunc
Definition gl.h:4775
#define GL_MODELVIEW
Definition gl.h:1189
#define GL_CULL_FACE
Definition gl.h:500
#define GL_COLOR_BUFFER_BIT
Definition gl.h:408
#define glMatrixMode
Definition gl.h:4267
#define glPopAttrib
Definition gl.h:4477
#define GL_ALL_ATTRIB_BITS
Definition gl.h:214
#define GL_BLEND
Definition gl.h:275
#define GL_MULTISAMPLE
Definition gl.h:1194
#define GL_ONE_MINUS_SRC_ALPHA
Definition gl.h:1239
#define glViewport
Definition gl.h:5333
#define GL_STENCIL_BUFFER_BIT
Definition gl.h:1646
#define GL_POLYGON
Definition gl.h:1313
#define glHint
Definition gl.h:4117
#define GL_EQUAL
Definition gl.h:640
#define glLineWidth
Definition gl.h:4215
#define GL_LINE_LOOP
Definition gl.h:937
#define glEnd
Definition gl.h:3677
#define glFlush
Definition gl.h:3719
#define GL_LINE_SMOOTH_HINT
Definition gl.h:940
#define glPushAttrib
Definition gl.h:4597
#define glDisable
Definition gl.h:3607
#define GL_REPLACE
Definition gl.h:1454
#define glLoadIdentity
Definition gl.h:4221
#define GL_LINE_SMOOTH
Definition gl.h:939
#define GL_KEEP
Definition gl.h:909
#define glBlendFunc
Definition gl.h:3325
#define glClear
Definition gl.h:3357
PartState
Definition PartSkipCommon.hpp:9
void DrawRoundedRect(float x, float y, float width, float height, float radius, const ColorRGB &color, int segments=16)
Definition SkipPartCanvas.cpp:211
const Polygon & contour(const ExPolygon &p)
Definition AGGRaster.hpp:30

References context_, Slic3r::contour(), Slic3r::GUI::DrawRoundedRect(), GL_ALL_ATTRIB_BITS, GL_ALWAYS, GL_BLEND, GL_COLOR_BUFFER_BIT, GL_CULL_FACE, GL_EQUAL, GL_KEEP, GL_LINE_LOOP, GL_LINE_SMOOTH, GL_LINE_SMOOTH_HINT, GL_MODELVIEW, GL_MULTISAMPLE, GL_NICEST, GL_ONE_MINUS_SRC_ALPHA, GL_POLYGON, GL_PROJECTION, GL_REPLACE, GL_SRC_ALPHA, GL_STENCIL_BUFFER_BIT, GL_STENCIL_TEST, GL_TRIANGLES, GL_TRUE, glBegin, glBlendFunc, glClear, glClearColor, glColor3f, glColorMask, glDisable, glEnable, glEnd, glFlush, glHint, glLineWidth, glLoadIdentity, glMatrixMode, glOrtho, glPopAttrib, glPushAttrib, glStencilFunc, glStencilOp, glVertex2f, glViewport, offset_, parent_color_, parts_state_, parts_triangles_, pick_parts_, Slic3r::GUI::psChecked, Slic3r::GUI::psSkipped, Slic3r::GUI::psUnCheck, scale(), and ViewPtToImagePt().

Referenced by OnPaint().

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

◆ SendSelectEvent()

void Slic3r::GUI::SkipPartCanvas::SendSelectEvent ( int id,
PartState state )
private
408 {
409 wxCommandEvent evt(EVT_CANVAS_PART);
410 evt.SetExtraLong(id);
411 evt.SetInt(static_cast<int>(state));
412 wxPostEvent(this, evt);
413}

Referenced by OnMouseLeftUp().

Here is the caller graph for this function:

◆ SendZoomEvent()

void Slic3r::GUI::SkipPartCanvas::SendZoomEvent ( int zoom_percent)
private
414 {
415 wxCommandEvent evt(EVT_ZOOM_PERCENT);
416 evt.SetInt(zoom_percent_);
417 wxPostEvent(this, evt);
418}

References zoom_percent_.

Referenced by SetZoomPercent().

Here is the caller graph for this function:

◆ SetOffset()

void Slic3r::GUI::SkipPartCanvas::SetOffset ( const wxPoint & value)
461{
462 int w, h;
463 GetClientSize(&w, &h);
464 int max_w = static_cast<int>(w * (1 - 1 / Zoom())) >= 0 ? static_cast<int>(w * (1 - 1 / Zoom())) : 0;
465 int max_h = static_cast<int>(w * (1 - 1 / Zoom())) >= 0 ? static_cast<int>(h * (1 - 1 / Zoom())) : 0;
466 offset_.x = std::clamp(value.x, 0, max_w);
467 offset_.y = std::clamp(value.y, 0, max_h);
468}

References offset_, and Zoom().

Referenced by OnMouseWheel(), and ProcessDrag().

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

◆ SetParentBackground()

void Slic3r::GUI::SkipPartCanvas::SetParentBackground ( const ColorRGB & color)
inline
74 {
75 parent_color_ = color;
76 }

References parent_color_.

◆ SetZoomPercent()

void Slic3r::GUI::SkipPartCanvas::SetZoomPercent ( const int value)
451{
452 zoom_percent_ = std::clamp(value, 100, 1000);
453 std::ostringstream oss;
454 oss << "zoom to " << zoom_percent_;
455 DebugLogLine(oss.str());
456
458}
void SendZoomEvent(int zoom_percent)
Definition SkipPartCanvas.cpp:414

References DebugLogLine(), SendZoomEvent(), and zoom_percent_.

Referenced by OnMouseWheel(), ZoomIn(), and ZoomOut().

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

◆ StartDrag()

void Slic3r::GUI::SkipPartCanvas::StartDrag ( const wxPoint & mouse_pt)
private
479{
480 drag_start_pt_ = mouse_pt;
482 is_draging_ = true;
484}

References AutoSetCursor(), drag_start_offset_, drag_start_pt_, is_draging_, and offset_.

Referenced by OnMouseLeftDown(), and OnMouseRightDown().

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

◆ SwitchDrag()

void Slic3r::GUI::SkipPartCanvas::SwitchDrag ( const bool drag_on)
196{
197 fixed_draging_ = drag_on;
199}

References AutoSetCursor(), and fixed_draging_.

Here is the call graph for this function:

◆ UpdatePartsInfo()

void Slic3r::GUI::SkipPartCanvas::UpdatePartsInfo ( const PartsInfo & parts)
203{
204 for (auto const& part : parts) {
205 if (auto res = parts_state_.find(part.first); res != parts_state_.end())
206 res->second = part.second;
207 }
208 Refresh();
209}

References parts_state_.

◆ ViewPtToImagePt()

wxPoint Slic3r::GUI::SkipPartCanvas::ViewPtToImagePt ( const wxPoint & view_pt) const
inlineprivate
426{
427 return wxPoint(view_pt.x * image_view_scale_ / Zoom(), view_pt.y * image_view_scale_ / Zoom()) + offset_;
428}

References image_view_scale_, offset_, and Zoom().

Referenced by GetIdAtViewPt(), OnMouseWheel(), and Render().

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

◆ Zoom()

double Slic3r::GUI::SkipPartCanvas::Zoom ( ) const
inlineprivate
421{
422 return zoom_percent_ / 100.0f;
423}

References zoom_percent_.

Referenced by ProcessDrag(), SetOffset(), and ViewPtToImagePt().

Here is the caller graph for this function:

◆ ZoomIn()

void Slic3r::GUI::SkipPartCanvas::ZoomIn ( const int zoom_percent)
184{
185 SetZoomPercent(zoom_percent_ + zoom_percent);
186 Refresh();
187}

References SetZoomPercent(), and zoom_percent_.

Here is the call graph for this function:

◆ ZoomOut()

void Slic3r::GUI::SkipPartCanvas::ZoomOut ( const int zoom_percent)
190{
191 SetZoomPercent(zoom_percent_ - zoom_percent);
192 Refresh();
193}

References SetZoomPercent(), and zoom_percent_.

Here is the call graph for this function:

Member Data Documentation

◆ context_

wxGLContext* Slic3r::GUI::SkipPartCanvas::context_
private

Referenced by SkipPartCanvas(), OnPaint(), and Render().

◆ drag_start_offset_

wxPoint Slic3r::GUI::SkipPartCanvas::drag_start_offset_ {0,0}
private
104{0,0};

Referenced by ProcessDrag(), and StartDrag().

◆ drag_start_pt_

wxPoint Slic3r::GUI::SkipPartCanvas::drag_start_pt_ {0,0}
private
105{0,0};

Referenced by ProcessDrag(), and StartDrag().

◆ fixed_draging_

bool Slic3r::GUI::SkipPartCanvas::fixed_draging_ {false}
private

◆ hover_id_

int Slic3r::GUI::SkipPartCanvas::hover_id_ {-1}
private
110{-1};

Referenced by ProcessHover().

◆ image_view_scale_

double Slic3r::GUI::SkipPartCanvas::image_view_scale_ {1}
private
111{1};

Referenced by LoadPickImage(), ProcessDrag(), and ViewPtToImagePt().

◆ is_draging_

bool Slic3r::GUI::SkipPartCanvas::is_draging_ {false}
private
106{false};

Referenced by AutoSetCursor(), EndDrag(), OnMouseRightUp(), and StartDrag().

◆ left_down_

bool Slic3r::GUI::SkipPartCanvas::left_down_ {false}
private
108{false};

Referenced by OnMouseLeftDown(), and OnMouseLeftUp().

◆ log_ctrl

wxTextCtrl* Slic3r::GUI::SkipPartCanvas::log_ctrl

◆ offset_

wxPoint Slic3r::GUI::SkipPartCanvas::offset_ {0,0}
private

◆ parent_color_

ColorRGB Slic3r::GUI::SkipPartCanvas::parent_color_ = ColorRGB()
private

Referenced by Render(), and SetParentBackground().

◆ parts_state_

std::unordered_map<uint32_t, PartState> Slic3r::GUI::SkipPartCanvas::parts_state_
private

◆ parts_triangles_

std::unordered_map< uint32_t, std::vector<std::vector<FloatPoint> > > Slic3r::GUI::SkipPartCanvas::parts_triangles_
private

Referenced by LoadPickImage(), and Render().

◆ pick_image_

cv::Mat Slic3r::GUI::SkipPartCanvas::pick_image_
private

Referenced by GetIdAtImagePt(), and LoadPickImage().

◆ pick_parts_

std::unordered_map< uint32_t, std::vector<std::vector<cv::Point> > > Slic3r::GUI::SkipPartCanvas::pick_parts_
private

Referenced by LoadPickImage(), and Render().

◆ zoom_percent_

int Slic3r::GUI::SkipPartCanvas::zoom_percent_ {100}
private

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