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

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

Inheritance diagram for Slic3r::GUI::Bed_2D:
Collaboration diagram for Slic3r::GUI::Bed_2D:

Public Member Functions

 Bed_2D (wxWindow *parent)
void repaint (const std::vector< Vec2d > &shape)

Static Public Member Functions

static int calculate_grid_step (const BoundingBox &bb, const double &scale)
static std::vector< Polylines > generate_grid (const ExPolygon &poly, const BoundingBox &pp_bbox, const Vec2d &origin, const double &step, const double &scale)

Private Member Functions

Point to_pixels (const Vec2d &point, int height)
Point to_pixels (const Point &point, int height)
void set_pos (const Vec2d &pos)

Private Attributes

bool m_user_drawn_background = true
double m_scale_factor
Vec2d m_shift = Vec2d::Zero()
Vec2d m_pos = Vec2d::Zero()

Static Private Attributes

static const int Border = 10

Detailed Description

Constructor & Destructor Documentation

◆ Bed_2D()

Slic3r::GUI::Bed_2D::Bed_2D ( wxWindow * parent)
explicit
38 :
39wxPanel(parent, wxID_ANY, wxDefaultPosition, wxSize(32 * wxGetApp().em_unit(), -1), wxTAB_TRAVERSAL)
40{
41#ifdef __APPLE__
43#else
44 SetBackgroundStyle(wxBG_STYLE_PAINT); // to avoid assert message after wxAutoBufferedPaintDC
45#endif /*__APPLE__*/
46}
bool m_user_drawn_background
Definition 2DBed.hpp:20
int em_unit(wxWindow *win)
Definition wxExtensions.cpp:424

References em_unit(), and m_user_drawn_background.

Here is the call graph for this function:

Member Function Documentation

◆ calculate_grid_step()

int Slic3r::GUI::Bed_2D::calculate_grid_step ( const BoundingBox & bb,
const double & scale )
static
49{
50 // Orca: use 500 x 500 bed size as baseline.
51 int min_edge = (bb.size() * (1 / scale)).minCoeff(); // Get short edge
52 // if the grid is too dense, we increase the step
53 return min_edge >= 6000 ? 100 // Short edge >= 6000mm Main Grid: 5 x 100 = 500mm
54 : min_edge >= 1200 ? 50 // Short edge >= 1200mm Main Grid: 5 x 50 = 250mm
55 : min_edge >= 600 ? 20 // Short edge >= 600mm Main Grid: 5 x 20 = 100mm
56 : 10; // Short edge < 600mm Main Grid: 5 x 10 = 50mm
57}
int scale(const int val)
Definition WipeTowerDialog.cpp:58

References scale(), and Slic3r::BoundingBoxBase< PointType, APointsType >::size().

Referenced by Slic3r::GUI::PartPlate::calc_gridlines(), and repaint().

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

◆ generate_grid()

std::vector< Polylines > Slic3r::GUI::Bed_2D::generate_grid ( const ExPolygon & poly,
const BoundingBox & pp_bbox,
const Vec2d & origin,
const double & step,
const double & scale )
static
60{
61 Polylines lines_thin, lines_bold;
62 int count = 0;
63
64 // ORCA draw grid lines relative to origin
65 for (coord_t x = origin.x(); x >= bb.min(0); x -= step) { // Negative X axis
66 (count % 5 ? lines_thin : lines_bold).push_back(Polyline(
67 Point(x, bb.min(1)),
68 Point(x, bb.max(1))
69 ));
70 count ++;
71 }
72 count = 0;
73 for (coord_t x = origin.x(); x <= bb.max(0); x += step) { // Positive X axis
74 (count % 5 ? lines_thin : lines_bold).push_back(Polyline(
75 Point(x, bb.min(1)),
76 Point(x, bb.max(1))
77 ));
78 count ++;
79 }
80 count = 0;
81 for (coord_t y = origin.y(); y >= bb.min(1); y -= step) { // Negative Y axis
82 (count % 5 ? lines_thin : lines_bold).push_back(Polyline(
83 Point(bb.min(0), y),
84 Point(bb.max(0), y)
85 ));
86 count ++;
87 }
88 count = 0;
89 for (coord_t y = origin.y(); y <= bb.max(1); y += step) { // Positive Y axis
90 (count % 5 ? lines_thin : lines_bold).push_back(Polyline(
91 Point(bb.min(0), y),
92 Point(bb.max(0), y)
93 ));
94 count ++;
95 }
96
97 std::vector<Polylines> grid;
98 // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped
99 auto scaled_poly = offset(poly, scale);
100 grid.push_back(intersection_pl(lines_thin, scaled_poly));
101 grid.push_back(intersection_pl(lines_bold, scaled_poly));
102 return grid;
103}
static unsigned int count
Definition AuxiliaryDataViewModel.cpp:246
int64_t coord_t
Definition libslic3r.h:48
Kernel::Point_3 Point
Definition MeshRepair.cpp:81
std::vector< Polyline > Polylines
Definition Polyline.hpp:22
Slic3r::Polygons offset(const Slic3r::Polygon &polygon, const float delta, JoinType joinType, double miterLimit)
Definition ClipperUtils.cpp:582
std::vector< ArithmeticOnly< T > > grid(const T &start, const T &stop, const T &stride)
A set of equidistant values starting from 'start' (inclusive), ending in the closest multiple of 'str...
Definition MTUtils.hpp:127
Slic3r::Polylines intersection_pl(const Slic3r::Polylines &subject, const Slic3r::Polygon &clip)
Definition ClipperUtils.cpp:1111

References count, Slic3r::grid(), Slic3r::intersection_pl(), Slic3r::BoundingBoxBase< PointType, APointsType >::max, Slic3r::BoundingBoxBase< PointType, APointsType >::min, Slic3r::offset(), and scale().

Referenced by Slic3r::GUI::PartPlate::calc_gridlines(), and repaint().

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

◆ repaint()

void Slic3r::GUI::Bed_2D::repaint ( const std::vector< Vec2d > & shape)
106{
107 wxAutoBufferedPaintDC dc(this);
108 auto cw = GetSize().GetWidth();
109 auto ch = GetSize().GetHeight();
110 // when canvas is not rendered yet, size is 0, 0
111 if (cw == 0) return ;
112 bool is_dark = wxGetApp().dark_mode();
113
115 // On all systems the AutoBufferedPaintDC() achieves double buffering.
116 // On MacOS the background is erased, on Windows the background is not erased
117 // and on Linux / GTK the background is erased to gray color.
118 // Fill DC with the background on Windows & Linux / GTK.
119 wxColour color;
120 if (is_dark) {// SetBackgroundColour
121 color = wxColour(45, 45, 49);
122 }
123 else {
124 color = *wxWHITE;
125 }
126 dc.SetPen(*new wxPen(color, 1, wxPENSTYLE_SOLID));
127 dc.SetBrush(*new wxBrush(color, wxBRUSHSTYLE_SOLID));
128 auto rect = GetUpdateRegion().GetBox();
129 dc.DrawRectangle(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight());
130 }
131
132 if (shape.empty())
133 return;
134
135 // reduce size to have some space around the drawn shape
136 cw -= (2 * Border);
137 ch -= (2 * Border);
138
139 auto cbb = BoundingBoxf(Vec2d(0, 0),Vec2d(cw, ch));
140 auto ccenter = cbb.center();
141
142 // get bounding box of bed shape in G - code coordinates
143 auto bb = BoundingBoxf(shape);
144 bb.merge(Vec2d(0, 0)); // origin needs to be in the visible area
145 auto bw = bb.size()(0);
146 auto bh = bb.size()(1);
147 auto bcenter = bb.center();
148
149 // calculate the scaling factor for fitting bed shape in canvas area
150 auto sfactor = std::min(cw/bw, ch/bh);
151 auto shift = Vec2d(
152 ccenter(0) - bcenter(0) * sfactor,
153 ccenter(1) - bcenter(1) * sfactor
154 );
155
156 m_scale_factor = sfactor;
157 m_shift = Vec2d(shift(0) + cbb.min(0), shift(1) - (cbb.max(1) - ch));
158
159 // ORCA match colors
161 std::string bed_color = encode_color(ColorRGBA(bed_rgba[0] * 0.8f, bed_rgba[1] * 0.8f,bed_rgba[2] * 0.8f, bed_rgba[3]));
163 std::string lines_bold_color = encode_color(grid_color);
164 std::string lines_thin_color = encode_color(grid_color * 0.85);
165 wxColour text_color = wxColour(lines_bold_color);
166
167 // draw bed fill
168 dc.SetBrush(wxBrush(wxColour(bed_color), wxBRUSHSTYLE_SOLID));
169 wxPointList pt_list;
170 for (auto pt : shape)
171 {
172 Point pt_pix = to_pixels(pt, ch);
173 pt_list.push_back(new wxPoint(pt_pix(0), pt_pix(1)));
174 }
175 dc.DrawPolygon(&pt_list, 0, 0);
176
177 ExPolygon bed_poly;
178 for (const Vec2d& p : shape)
179 bed_poly.contour.append({p(0), p(1)});
180 auto bed_bb = bed_poly.contour.bounding_box();
181 int step = calculate_grid_step(bed_bb, 1.00);
182 auto grid_lines = generate_grid(bed_poly, bed_bb, m_pos, step, 1.00);
183
184 // clip with a slightly grown expolygon because our lines lay on the contours and may get erroneously clipped
185 dc.SetPen(wxPen(wxColour(lines_thin_color), 1, wxPENSTYLE_SOLID));
186 for (auto pl : grid_lines[0]) {
187 for (size_t i = 0; i < pl.points.size() - 1; i++) {
188 Point pt1 = to_pixels(pl.points[i ], ch);
189 Point pt2 = to_pixels(pl.points[i+1], ch);
190 dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
191 }
192 }
193 dc.SetPen(wxPen(wxColour(lines_bold_color), 1, wxPENSTYLE_SOLID));
194 for (auto pl : grid_lines[1]) {
195 for (size_t i = 0; i < pl.points.size() - 1; i++) {
196 Point pt1 = to_pixels(pl.points[i ], ch);
197 Point pt2 = to_pixels(pl.points[i+1], ch);
198 dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
199 }
200 }
201
202 // draw bed contour
203 dc.SetPen( wxPen( wxColour(lines_bold_color), 1, wxPENSTYLE_SOLID));
204 dc.SetBrush(wxBrush(wxColour(lines_bold_color), wxBRUSHSTYLE_TRANSPARENT));
205 dc.DrawPolygon(&pt_list, 0, 0);
206
207 auto origin_px = to_pixels(Vec2d(0, 0), ch);
208
209 // draw axes
210 auto axes_len = 5 * wxGetApp().em_unit(); // scale axis
211 auto arrow_len = 6;
212 auto arrow_angle = Geometry::deg2rad(45.0);
213 dc.SetPen(wxPen(wxColour(encode_color(ColorRGB::X())), 2, wxPENSTYLE_SOLID)); // red // ORCA match axis colors
214 auto x_end = Vec2d(origin_px(0) + axes_len, origin_px(1));
215 dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(x_end(0), x_end(1)));
216 //for (auto angle : { -arrow_angle, arrow_angle }) { // ORCA dont draw arrows
217 // Vec2d end = Eigen::Translation2d(x_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- x_end) * Eigen::Vector2d(x_end(0) - arrow_len, x_end(1));
218 // dc.DrawLine(wxPoint(x_end(0), x_end(1)), wxPoint(end(0), end(1)));
219 //}
220
221 dc.SetPen(wxPen(wxColour(encode_color(ColorRGB::Y())), 2, wxPENSTYLE_SOLID)); // green // ORCA match axis colors
222 auto y_end = Vec2d(origin_px(0), origin_px(1) - axes_len);
223 dc.DrawLine(wxPoint(origin_px(0), origin_px(1)), wxPoint(y_end(0), y_end(1)));
224 //for (auto angle : { -arrow_angle, arrow_angle }) { // ORCA dont draw arrows
225 // Vec2d end = Eigen::Translation2d(y_end) * Eigen::Rotation2Dd(angle) * Eigen::Translation2d(- y_end) * Eigen::Vector2d(y_end(0), y_end(1) + arrow_len);
226 // dc.DrawLine(wxPoint(y_end(0), y_end(1)), wxPoint(end(0), end(1)));
227 //}
228
229 // draw origin
230 dc.SetPen(wxPen(wxColour(encode_color(ColorRGB::Z())), 1, wxPENSTYLE_SOLID)); // ORCA match axis colors
231 dc.SetBrush(wxBrush(wxColour(encode_color(ColorRGB::Z())), wxBRUSHSTYLE_SOLID)); // ORCA match axis colors
232 dc.DrawCircle(origin_px(0), origin_px(1), 3);
233
234 static const auto origin_label = wxString("(0,0)");
235 dc.SetTextForeground(wxColour("#FFFFFF"));
236 dc.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
237 auto extent = dc.GetTextExtent(origin_label);
238 const auto origin_label_x = origin_px(0) + 2; // ORCA always draw (0,0) text in axes bounding box
239 const auto origin_label_y = origin_px(1) - extent.GetHeight() - 2;
240 dc.SetPen( wxPen( wxColour(wxColour(bed_color)), 1, wxPENSTYLE_SOLID));
241 dc.SetBrush(wxBrush(wxColour(wxColour(bed_color)), wxBRUSHSTYLE_SOLID));
242 dc.DrawRectangle(wxPoint(origin_label_x, origin_label_y), extent); // ORCA draw a background to origin position text to improve readability when overlaps with grid
243 dc.DrawText(origin_label, origin_label_x, origin_label_y);
244
245 // ORCA add grid size value as information for large scale beds
246 auto grid_label = wxString::Format(_L("1x1 Grid: %d mm"), step);
247 Point draw_bb = to_pixels(Vec2d(
248 std::min(m_pos(0),bb.min(0)),
249 std::min(m_pos(1),bb.min(1))
250 ),ch);
251 dc.SetTextForeground(wxColour(StateColor::darkModeColorFor("#262E30")));
252 dc.SetFont(wxFont(10, wxFONTFAMILY_DEFAULT, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
253 dc.DrawText(grid_label, draw_bb(0), draw_bb(1) + 5);
254
255 // draw current position
256 if (m_pos!= Vec2d(0, 0)) {
257 auto pos_px = to_pixels(m_pos, ch);
258 dc.SetPen(wxPen(wxColour(200, 0, 0), 2, wxPENSTYLE_SOLID));
259 dc.SetBrush(wxBrush(wxColour(200, 0, 0), wxBRUSHSTYLE_TRANSPARENT));
260 dc.DrawCircle(pos_px(0), pos_px(1), 5);
261
262 dc.DrawLine(pos_px(0) - 15, pos_px(1), pos_px(0) + 15, pos_px(1));
263 dc.DrawLine(pos_px(0), pos_px(1) - 15, pos_px(0), pos_px(1) + 15);
264 }
265}
#define _L(s)
Definition OBJ.cpp:34
const wxColour text_color(107, 107, 107)
static bool is_dark()
Definition TextureImportDialog.cpp:85
static const ColorRGB X()
Definition Color.hpp:74
static const ColorRGB Z()
Definition Color.hpp:76
static const ColorRGB Y()
Definition Color.hpp:75
static ColorRGBA DEFAULT_MODEL_COLOR_DARK
Definition 3DBed.hpp:57
static ColorRGBA DEFAULT_MODEL_COLOR
Definition 3DBed.hpp:56
double m_scale_factor
Definition 2DBed.hpp:22
Vec2d m_shift
Definition 2DBed.hpp:23
static int calculate_grid_step(const BoundingBox &bb, const double &scale)
Definition 2DBed.cpp:48
Point to_pixels(const Vec2d &point, int height)
Definition 2DBed.cpp:269
static const int Border
Definition 2DBed.hpp:18
Vec2d m_pos
Definition 2DBed.hpp:24
static std::vector< Polylines > generate_grid(const ExPolygon &poly, const BoundingBox &pp_bbox, const Vec2d &origin, const double &step, const double &scale)
Definition 2DBed.cpp:59
static ColorRGBA LINE_TOP_SEL_COLOR
Definition PartPlate.hpp:314
static ColorRGBA LINE_TOP_SEL_DARK_COLOR
Definition PartPlate.hpp:315
static wxColour darkModeColorFor(wxColour const &color)
Definition StateColor.cpp:219
constexpr T deg2rad(const T angle)
Definition Geometry.hpp:312
std::string encode_color(const ColorRGB &color)
Definition Color.cpp:397
Eigen::Matrix< double, 2, 1, Eigen::DontAlign > Vec2d
Definition Point.hpp:67
void step(Coord &crd, const Dir d, const long n=1)
Definition MarchingSquares.hpp:213

References _L, Slic3r::MultiPoint::append(), Border, Slic3r::MultiPoint::bounding_box(), calculate_grid_step(), Slic3r::ExPolygon::contour, StateColor::darkModeColorFor(), Slic3r::GUI::Bed3D::DEFAULT_MODEL_COLOR, Slic3r::GUI::Bed3D::DEFAULT_MODEL_COLOR_DARK, Slic3r::Geometry::deg2rad(), Slic3r::encode_color(), generate_grid(), is_dark(), Slic3r::GUI::PartPlate::LINE_TOP_SEL_COLOR, Slic3r::GUI::PartPlate::LINE_TOP_SEL_DARK_COLOR, m_pos, m_scale_factor, m_shift, m_user_drawn_background, text_color(), to_pixels(), Slic3r::ColorRGB::X(), Slic3r::ColorRGB::Y(), and Slic3r::ColorRGB::Z().

Here is the call graph for this function:

◆ set_pos()

void Slic3r::GUI::Bed_2D::set_pos ( const Vec2d & pos)
private
282{
283 m_pos = pos;
284 Refresh();
285}
Vec3d pos(const Pt &p)
Definition ReprojectPointsOnMesh.hpp:16

References m_pos.

◆ to_pixels() [1/2]

Point Slic3r::GUI::Bed_2D::to_pixels ( const Point & point,
int height )
private
276{
277 Point p = point * m_scale_factor + Point(m_shift);
278 return Point(p(0) + Border, height - p(1) + Border);
279}

References Border, m_scale_factor, and m_shift.

◆ to_pixels() [2/2]

Point Slic3r::GUI::Bed_2D::to_pixels ( const Vec2d & point,
int height )
private
270{
271 Vec2d p = point * m_scale_factor + m_shift;
272 return Point(p(0) + Border, height - p(1) + Border);
273}

References Border, m_scale_factor, and m_shift.

Referenced by repaint().

Here is the caller graph for this function:

Member Data Documentation

◆ Border

const int Slic3r::GUI::Bed_2D::Border = 10
staticprivate

Referenced by repaint(), to_pixels(), and to_pixels().

◆ m_pos

Vec2d Slic3r::GUI::Bed_2D::m_pos = Vec2d::Zero()
private

Referenced by repaint(), and set_pos().

◆ m_scale_factor

double Slic3r::GUI::Bed_2D::m_scale_factor
private

Referenced by repaint(), to_pixels(), and to_pixels().

◆ m_shift

Vec2d Slic3r::GUI::Bed_2D::m_shift = Vec2d::Zero()
private

Referenced by repaint(), to_pixels(), and to_pixels().

◆ m_user_drawn_background

bool Slic3r::GUI::Bed_2D::m_user_drawn_background = true
private

Referenced by Bed_2D(), and repaint().


The documentation for this class was generated from the following files:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/2DBed.hpp
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/slic3r/GUI/2DBed.cpp