106{
107 wxAutoBufferedPaintDC dc(this);
108 auto cw = GetSize().GetWidth();
109 auto ch = GetSize().GetHeight();
110
111 if (cw == 0) return ;
112 bool is_dark = wxGetApp().dark_mode();
113
115
116
117
118
119 wxColour color;
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
138
139 auto cbb = BoundingBoxf(
Vec2d(0, 0),
Vec2d(cw, ch));
140 auto ccenter = cbb.center();
141
142
143 auto bb = BoundingBoxf(shape);
144 bb.merge(
Vec2d(0, 0));
145 auto bw = bb.size()(0);
146 auto bh = bb.size()(1);
147 auto bcenter = bb.center();
148
149
150 auto sfactor = std::min(cw/bw, ch/bh);
152 ccenter(0) - bcenter(0) * sfactor,
153 ccenter(1) - bcenter(1) * sfactor
154 );
155
157 m_shift =
Vec2d(shift(0) + cbb.min(0), shift(1) - (cbb.max(1) - ch));
158
159
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
168 dc.SetBrush(wxBrush(wxColour(bed_color), wxBRUSHSTYLE_SOLID));
169 wxPointList pt_list;
170 for (auto pt : shape)
171 {
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();
183
184
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++) {
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++) {
198 dc.DrawLine(pt1(0), pt1(1), pt2(0), pt2(1));
199 }
200 }
201
202
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
208
209
210 auto axes_len = 5 * wxGetApp().em_unit();
211 auto arrow_len = 6;
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
217
218
219
220
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
225
226
227
228
229
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;
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);
243 dc.DrawText(origin_label, origin_label_x, origin_label_y);
244
245
246 auto grid_label = wxString::Format(
_L(
"1x1 Grid: %d mm"), step);
248 std::min(
m_pos(0),bb.min(0)),
249 std::min(
m_pos(1),bb.min(1))
250 ),ch);
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
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