This commit is contained in:
YuSanka 2019-12-12 13:49:30 +01:00
commit d028f804c4
10 changed files with 129 additions and 118 deletions

2
deps/CMakeLists.txt vendored
View file

@ -59,7 +59,7 @@ function(prusaslicer_add_cmake_project projectname)
set(_gen "")
set(_build_j "-j${NPROC}")
if (MSVC)
set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}")
set(_gen CMAKE_GENERATOR "${DEP_MSVC_GEN}" CMAKE_GENERATOR_PLATFORM "${DEP_PLATFORM}")
set(_build_j "/m")
endif ()

View file

@ -496,37 +496,37 @@ std::string WipeTowerIntegration::prime(GCode &gcodegen)
assert(m_layer_idx == 0);
std::string gcode;
if (&m_priming != nullptr) {
// Disable linear advance for the wipe tower operations.
//gcode += (gcodegen.config().gcode_flavor == gcfRepRap ? std::string("M572 D0 S0\n") : std::string("M900 K0\n"));
for (const WipeTower::ToolChangeResult& tcr : m_priming) {
if (!tcr.extrusions.empty())
gcode += append_tcr(gcodegen, tcr, tcr.new_tool);
// Disable linear advance for the wipe tower operations.
//gcode += (gcodegen.config().gcode_flavor == gcfRepRap ? std::string("M572 D0 S0\n") : std::string("M900 K0\n"));
for (const WipeTower::ToolChangeResult& tcr : m_priming) {
if (!tcr.extrusions.empty())
gcode += append_tcr(gcodegen, tcr, tcr.new_tool);
// Let the tool change be executed by the wipe tower class.
// Inform the G-code writer about the changes done behind its back.
//gcode += tcr.gcode;
// Let the m_writer know the current extruder_id, but ignore the generated G-code.
// unsigned int current_extruder_id = tcr.extrusions.back().tool;
// gcodegen.writer().toolchange(current_extruder_id);
// gcodegen.placeholder_parser().set("current_extruder", current_extruder_id);
// Let the tool change be executed by the wipe tower class.
// Inform the G-code writer about the changes done behind its back.
//gcode += tcr.gcode;
// Let the m_writer know the current extruder_id, but ignore the generated G-code.
// unsigned int current_extruder_id = tcr.extrusions.back().tool;
// gcodegen.writer().toolchange(current_extruder_id);
// gcodegen.placeholder_parser().set("current_extruder", current_extruder_id);
}
// A phony move to the end position at the wipe tower.
/* gcodegen.writer().travel_to_xy(Vec2d(m_priming.back().end_pos.x, m_priming.back().end_pos.y));
gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, m_priming.back().end_pos));
// Prepare a future wipe.
gcodegen.m_wipe.path.points.clear();
// Start the wipe at the current position.
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, m_priming.back().end_pos));
// Wipe end point: Wipe direction away from the closer tower edge to the further tower edge.
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen,
WipeTower::xy((std::abs(m_left - m_priming.back().end_pos.x) < std::abs(m_right - m_priming.back().end_pos.x)) ? m_right : m_left,
m_priming.back().end_pos.y)));*/
}
// A phony move to the end position at the wipe tower.
/* gcodegen.writer().travel_to_xy(Vec2d(m_priming.back().end_pos.x, m_priming.back().end_pos.y));
gcodegen.set_last_pos(wipe_tower_point_to_object_point(gcodegen, m_priming.back().end_pos));
// Prepare a future wipe.
gcodegen.m_wipe.path.points.clear();
// Start the wipe at the current position.
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen, m_priming.back().end_pos));
// Wipe end point: Wipe direction away from the closer tower edge to the further tower edge.
gcodegen.m_wipe.path.points.emplace_back(wipe_tower_point_to_object_point(gcodegen,
WipeTower::xy((std::abs(m_left - m_priming.back().end_pos.x) < std::abs(m_right - m_priming.back().end_pos.x)) ? m_right : m_left,
m_priming.back().end_pos.y)));*/
return gcode;
}

View file

@ -191,7 +191,6 @@ Bed3D::Bed3D()
: m_type(Custom)
, m_custom_texture("")
, m_custom_model("")
, m_requires_canvas_update(false)
, m_vbo_id(0)
, m_scale_factor(1.0f)
{
@ -438,6 +437,7 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D&
render_default(bottom);
return;
}
canvas.request_extra_frame();
}
// starts generating the main texture, compression will run asynchronously
@ -457,6 +457,7 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D&
render_default(bottom);
return;
}
canvas.request_extra_frame();
}
// starts generating the main texture, compression will run asynchronously
@ -481,13 +482,9 @@ void Bed3D::render_texture(const std::string& filename, bool bottom, GLCanvas3D&
if (m_temp_texture.get_id() != 0)
m_temp_texture.reset();
m_requires_canvas_update = true;
}
else if (m_requires_canvas_update && m_texture.all_compressed_data_sent_to_gpu())
m_requires_canvas_update = false;
canvas.request_extra_frame();
if (m_texture.all_compressed_data_sent_to_gpu() && canvas.is_keeping_dirty())
canvas.stop_keeping_dirty();
}
if (m_triangles.get_vertices_count() > 0)
{

View file

@ -86,8 +86,6 @@ private:
mutable GLTexture m_texture;
// temporary texture shown until the main texture has still no levels compressed
mutable GLTexture m_temp_texture;
// used to trigger 3D scene update once all compressed textures have been sent to GPU
mutable bool m_requires_canvas_update;
mutable Shader m_shader;
mutable unsigned int m_vbo_id;
mutable GLBed m_model;

View file

@ -1398,7 +1398,7 @@ GLCanvas3D::GLCanvas3D(wxGLCanvas* canvas, Bed3D& bed, Camera& camera, GLToolbar
, m_gizmos(*this)
, m_use_clipping_planes(false)
, m_sidebar_field("")
, m_keep_dirty(false)
, m_extra_frame_requested(false)
, m_config(nullptr)
, m_process(nullptr)
, m_model(nullptr)
@ -1636,8 +1636,6 @@ void GLCanvas3D::bed_shape_changed()
refresh_camera_scene_box();
m_camera.requires_zoom_to_bed = true;
m_dirty = true;
if (m_bed.is_prusa())
start_keeping_dirty();
}
void GLCanvas3D::set_color_by(const std::string& value)
@ -2632,10 +2630,11 @@ void GLCanvas3D::on_idle(wxIdleEvent& evt)
_refresh_if_shown_on_screen();
if (m_keep_dirty || mouse3d_controller_applied)
if (m_extra_frame_requested || mouse3d_controller_applied)
{
m_dirty = true;
evt.RequestMore();
m_extra_frame_requested = false;
}
else
m_dirty = false;

View file

@ -436,7 +436,9 @@ private:
bool m_use_clipping_planes;
mutable SlaCap m_sla_caps[2];
std::string m_sidebar_field;
bool m_keep_dirty;
// when true renders an extra frame by not resetting m_dirty to false
// see request_extra_frame()
bool m_extra_frame_requested;
mutable GLVolumeCollection m_volumes;
Selection m_selection;
@ -664,9 +666,7 @@ public:
void set_cursor(ECursorType type);
void msw_rescale();
bool is_keeping_dirty() const { return m_keep_dirty; }
void start_keeping_dirty() { m_keep_dirty = true; }
void stop_keeping_dirty() { m_keep_dirty = false; }
void request_extra_frame() { m_extra_frame_requested = true; }
int get_main_toolbar_item_id(const std::string& name) const { return m_main_toolbar.get_item_id(name); }
void force_main_toolbar_left_action(int item_id) { m_main_toolbar.force_left_action(item_id, *this); }

View file

@ -136,12 +136,25 @@ void GLGizmoCut::on_render_for_picking() const
void GLGizmoCut::on_render_input_window(float x, float y, float bottom_limit)
{
const float approx_height = m_imgui->scaled(11.0f);
y = std::min(y, bottom_limit - approx_height);
m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
static float last_y = 0.0f;
static float last_h = 0.0f;
m_imgui->begin(_(L("Cut")), ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse);
// adjust window position to avoid overlap the view toolbar
float win_h = ImGui::GetWindowHeight();
y = std::min(y, bottom_limit - win_h);
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
if ((last_h != win_h) || (last_y != y))
{
// ask canvas for another frame to render the window in the correct position
m_parent.request_extra_frame();
if (last_h != win_h)
last_h = win_h;
if (last_y != y)
last_y = y;
}
ImGui::AlignTextToFramePadding();
m_imgui->text("Z");
ImGui::SameLine();

View file

@ -686,6 +686,9 @@ void GLGizmoSlaSupports::make_line_segments() const
void GLGizmoSlaSupports::on_render_input_window(float x, float y, float bottom_limit)
{
static float last_y = 0.0f;
static float last_h = 0.0f;
if (!m_model_object)
return;
@ -697,11 +700,22 @@ RENDER_AGAIN:
//ImGui::SetNextWindowPos(ImVec2(x, y - std::max(0.f, y+window_size.y-bottom_limit) ));
//ImGui::SetNextWindowSize(ImVec2(window_size));
const float approx_height = m_imgui->scaled(18.0f);
y = std::min(y, bottom_limit - approx_height);
m_imgui->set_next_window_pos(x, y, ImGuiCond_Always);
m_imgui->begin(on_get_name(), ImGuiWindowFlags_NoMove | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse);
// adjust window position to avoid overlap the view toolbar
float win_h = ImGui::GetWindowHeight();
y = std::min(y, bottom_limit - win_h);
ImGui::SetWindowPos(ImVec2(x, y), ImGuiCond_Always);
if ((last_h != win_h) || (last_y != y))
{
// ask canvas for another frame to render the window in the correct position
m_parent.request_extra_frame();
if (last_h != win_h)
last_h = win_h;
if (last_y != y)
last_y = y;
}
// First calculate width of all the texts that are could possibly be shown. We will decide set the dialog width based on that:
const float settings_sliders_left = std::max(m_imgui->calc_text_size(m_desc.at("minimal_distance")).x, m_imgui->calc_text_size(m_desc.at("points_density")).x) + m_imgui->scaled(1.f);

View file

@ -20,10 +20,6 @@ GLGizmosManager::GLGizmosManager(GLCanvas3D& parent)
, m_enabled(false)
, m_icons_texture_dirty(true)
, m_current(Undefined)
, m_overlay_icons_size(Default_Icons_Size)
, m_overlay_scale(1.0f)
, m_overlay_border(5.0f)
, m_overlay_gap_y(5.0f)
, m_tooltip("")
, m_serializing(false)
{
@ -53,19 +49,18 @@ size_t GLGizmosManager::get_gizmo_idx_from_mouse(const Vec2d& mouse_pos) const
return Undefined;
float cnv_h = (float)m_parent.get_canvas_size().get_height();
float height = get_total_overlay_height();
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
float scaled_border = m_overlay_border * m_overlay_scale;
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
float top_y = 0.5f * (cnv_h - height) + scaled_border;
float height = get_scaled_total_height();
float icons_size = m_layout.scaled_icons_size();
float border = m_layout.scaled_border();
float stride_y = m_layout.scaled_stride_y();
float top_y = 0.5f * (cnv_h - height) + border;
// is mouse horizontally in the area?
if ((scaled_border <= (float)mouse_pos(0) && ((float)mouse_pos(0) <= scaled_border + scaled_icons_size))) {
if ((border <= (float)mouse_pos(0) && ((float)mouse_pos(0) <= border + icons_size))) {
// which icon is it on?
size_t from_top = (size_t)((float)mouse_pos(1) - top_y)/scaled_stride_y;
size_t from_top = (size_t)((float)mouse_pos(1) - top_y) / stride_y;
// is it really on the icon or already past the border?
if ((float)mouse_pos(1) <= top_y + from_top*scaled_stride_y + scaled_icons_size) {
if ((float)mouse_pos(1) <= top_y + from_top * stride_y + icons_size) {
std::vector<size_t> selectable = get_selectable_idxs();
if (from_top < selectable.size())
return selectable[from_top];
@ -110,18 +105,18 @@ bool GLGizmosManager::init()
void GLGizmosManager::set_overlay_icon_size(float size)
{
if (m_overlay_icons_size != size)
if (m_layout.icons_size != size)
{
m_overlay_icons_size = size;
m_layout.icons_size = size;
m_icons_texture_dirty = true;
}
}
void GLGizmosManager::set_overlay_scale(float scale)
{
if (m_overlay_scale != scale)
if (m_layout.scale != scale)
{
m_overlay_scale = scale;
m_layout.scale = scale;
m_icons_texture_dirty = true;
}
}
@ -851,26 +846,27 @@ void GLGizmosManager::do_render_overlay() const
float zoom = (float)m_parent.get_camera().get_zoom();
float inv_zoom = (zoom != 0.0f) ? 1.0f / zoom : 0.0f;
float height = get_total_overlay_height();
float width = get_total_overlay_width();
float scaled_border = m_overlay_border * m_overlay_scale * inv_zoom;
float height = get_scaled_total_height();
float width = get_scaled_total_width();
float zoomed_border = m_layout.scaled_border() * inv_zoom;
float top_x = (-0.5f * cnv_w) * inv_zoom;
float top_y = (0.5f * height) * inv_zoom;
float zoomed_top_x = (-0.5f * cnv_w) * inv_zoom;
float zoomed_top_y = (0.5f * height) * inv_zoom;
float left = top_x;
float top = top_y;
float right = left + width * inv_zoom;
float bottom = top - height * inv_zoom;
float zoomed_left = zoomed_top_x;
float zoomed_top = zoomed_top_y;
float zoomed_right = zoomed_left + width * inv_zoom;
float zoomed_bottom = zoomed_top - height * inv_zoom;
render_background(left, top, right, bottom, scaled_border);
render_background(zoomed_left, zoomed_top, zoomed_right, zoomed_bottom, zoomed_border);
top_x += scaled_border;
top_y -= scaled_border;
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale * inv_zoom;
zoomed_top_x += zoomed_border;
zoomed_top_y -= zoomed_border;
float icons_size = m_layout.scaled_icons_size();
float zoomed_icons_size = icons_size * inv_zoom;
float zoomed_stride_y = m_layout.scaled_stride_y() * inv_zoom;
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale * inv_zoom;
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
unsigned int icons_texture_id = m_icons_texture.get_id();
int tex_width = m_icons_texture.get_width();
int tex_height = m_icons_texture.get_height();
@ -891,53 +887,36 @@ void GLGizmosManager::do_render_overlay() const
int icon_idx = m_current == idx ? 2 : (m_hover == idx ? 1 : 0);
#endif // ENABLE_GIZMO_ICONS_NON_ACTIVABLE_STATE
float u_icon_size = m_overlay_icons_size * m_overlay_scale * inv_tex_width;
float v_icon_size = m_overlay_icons_size * m_overlay_scale * inv_tex_height;
float u_icon_size = icons_size * inv_tex_width;
float v_icon_size = icons_size * inv_tex_height;
float v_top = sprite_id * v_icon_size;
float u_left = icon_idx * u_icon_size;
float v_bottom = v_top + v_icon_size;
float u_right = u_left + u_icon_size;
GLTexture::render_sub_texture(icons_texture_id, top_x, top_x + scaled_icons_size, top_y - scaled_icons_size, top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
GLTexture::render_sub_texture(icons_texture_id, zoomed_top_x, zoomed_top_x + zoomed_icons_size, zoomed_top_y - zoomed_icons_size, zoomed_top_y, { { u_left, v_bottom }, { u_right, v_bottom }, { u_right, v_top }, { u_left, v_top } });
if (idx == m_current) {
float toolbar_top = cnv_h - m_parent.get_view_toolbar_height();
gizmo->render_input_window(width, 0.5f * cnv_h - top_y * zoom, toolbar_top);
gizmo->render_input_window(width, 0.5f * cnv_h - zoomed_top_y * zoom, toolbar_top);
}
top_y -= scaled_stride_y;
zoomed_top_y -= zoomed_stride_y;
}
}
float GLGizmosManager::get_total_overlay_height() const
float GLGizmosManager::get_scaled_total_height() const
{
float scaled_icons_size = m_overlay_icons_size * m_overlay_scale;
float scaled_border = m_overlay_border * m_overlay_scale;
float scaled_gap_y = m_overlay_gap_y * m_overlay_scale;
float scaled_stride_y = scaled_icons_size + scaled_gap_y;
float height = 2.0f * scaled_border;
/*for (size_t idx=0; idx<m_gizmos.size(); ++idx)
{
if ((m_gizmos[idx] == nullptr) || !m_gizmos[idx]->is_selectable())
continue;
height += scaled_stride_y;
}*/
height += get_selectable_idxs().size() * scaled_stride_y;
return height - scaled_gap_y;
return m_layout.scale * (2.0f * m_layout.border + (float)get_selectable_idxs().size() * m_layout.stride_y() - m_layout.gap_y);
}
float GLGizmosManager::get_total_overlay_width() const
float GLGizmosManager::get_scaled_total_width() const
{
return (2.0f * m_overlay_border + m_overlay_icons_size) * m_overlay_scale;
return 2.0f * m_layout.scaled_border() + m_layout.scaled_icons_size();
}
GLGizmoBase* GLGizmosManager::get_current() const
{
if (m_current==Undefined || m_gizmos.empty())
return nullptr;
else
return m_gizmos[m_current].get();
return ((m_current == Undefined) || m_gizmos.empty()) ? nullptr : m_gizmos[m_current].get();
}
bool GLGizmosManager::generate_icons_texture() const
@ -962,7 +941,7 @@ bool GLGizmosManager::generate_icons_texture() const
states.push_back(std::make_pair(2, false)); // Disabled
#endif // ENABLE_GIZMO_ICONS_NON_ACTIVABLE_STATE
unsigned int sprite_size_px = (unsigned int)(m_overlay_icons_size * m_overlay_scale);
unsigned int sprite_size_px = (unsigned int)m_layout.scaled_icons_size();
// // force even size
// if (sprite_size_px % 2 != 0)
// sprite_size_px += 1;

View file

@ -64,12 +64,28 @@ public:
};
private:
struct Layout
{
float scale{ 1.0f };
float icons_size{ Default_Icons_Size };
float border{ 5.0f };
float gap_y{ 5.0f };
float stride_y() const { return icons_size + gap_y;}
float scaled_icons_size() const { return scale * icons_size; }
float scaled_border() const { return scale * border; }
float scaled_gap_y() const { return scale * gap_y; }
float scaled_stride_y() const { return scale * stride_y(); }
};
GLCanvas3D& m_parent;
bool m_enabled;
std::vector<std::unique_ptr<GLGizmoBase>> m_gizmos;
mutable GLTexture m_icons_texture;
mutable bool m_icons_texture_dirty;
BackgroundTexture m_background_texture;
Layout m_layout;
EType m_current;
EType m_hover;
@ -79,11 +95,6 @@ private:
void activate_gizmo(EType type);
float m_overlay_icons_size;
float m_overlay_scale;
float m_overlay_border;
float m_overlay_gap_y;
struct MouseCapture
{
bool left;
@ -202,8 +213,8 @@ private:
void render_background(float left, float top, float right, float bottom, float border) const;
void do_render_overlay() const;
float get_total_overlay_height() const;
float get_total_overlay_width() const;
float get_scaled_total_height() const;
float get_scaled_total_width() const;
GLGizmoBase* get_current() const;