Set fine position
This commit is contained in:
parent
2bf876e96c
commit
378d8af7ac
6 changed files with 536 additions and 311 deletions
|
@ -1,6 +1,8 @@
|
|||
#include "CameraUtils.hpp"
|
||||
#include <igl/project.h> // projecting points
|
||||
|
||||
#include "slic3r/GUI/3DScene.hpp" // GLVolume
|
||||
|
||||
using namespace Slic3r;
|
||||
using namespace GUI;
|
||||
|
||||
|
@ -33,3 +35,18 @@ Points CameraUtils::project(const Camera & camera,
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
Slic3r::Polygon CameraUtils::create_hull2d(const Camera & camera,
|
||||
const GLVolume &volume)
|
||||
{
|
||||
const indexed_triangle_set &its = volume.convex_hull()->its;
|
||||
const Transform3d &trafoMat = volume.get_instance_transformation()
|
||||
.get_matrix();
|
||||
std::vector<Vec3d> vertices;
|
||||
vertices.reserve(its.vertices.size());
|
||||
for (const Vec3f &vertex : its.vertices)
|
||||
vertices.emplace_back(trafoMat * vertex.cast<double>());
|
||||
|
||||
Points vertices_2d = project(camera, vertices);
|
||||
return Geometry::convex_hull(vertices_2d);
|
||||
}
|
||||
|
|
|
@ -3,9 +3,11 @@
|
|||
|
||||
#include "Camera.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
class GLVolume;
|
||||
}
|
||||
|
||||
namespace Slic3r::GUI {
|
||||
|
||||
/// <summary>
|
||||
/// Help divide camera data and camera functions
|
||||
/// This utility work with camera data by static funtions
|
||||
|
@ -16,14 +18,22 @@ public:
|
|||
CameraUtils() = delete; // only static functions
|
||||
|
||||
/// <summary>
|
||||
/// project point throw camera to 2d coordinate into imgui window
|
||||
/// Project point throw camera to 2d coordinate into imgui window
|
||||
/// </summary>
|
||||
/// <param name="its">IN/OUT triangle mesh to be simplified.</param>
|
||||
/// <param name="its">IN/OUT triangle mesh to be simplified.</param>
|
||||
/// <param name="camera">Projection params</param>
|
||||
/// <param name="points">Point to project.</param>
|
||||
/// <returns>projected points by camera into coordinate of camera.
|
||||
/// x(from left to right), y(from top to bottom)</returns>
|
||||
static Points project(const Camera& camera, const std::vector<Vec3d> &points);
|
||||
|
||||
/// <summary>
|
||||
/// Create hull around GLVolume in 2d space of camera
|
||||
/// </summary>
|
||||
/// <param name="camera">Projection params</param>
|
||||
/// <param name="volume">Outline by 3d object</param>
|
||||
/// <returns>Polygon around object</returns>
|
||||
static Polygon create_hull2d(const Camera &camera, const GLVolume &volume);
|
||||
|
||||
};
|
||||
} // Slic3r::GUI
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -9,6 +9,7 @@
|
|||
#include "admesh/stl.h" // indexed_triangle_set
|
||||
#include <optional>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
#include "libslic3r/Emboss.hpp"
|
||||
#include "libslic3r/Point.hpp"
|
||||
|
@ -26,7 +27,7 @@ public:
|
|||
virtual ~GLGizmoEmboss();
|
||||
|
||||
void set_volume_type(ModelVolumeType volume_type);
|
||||
|
||||
void set_fine_position();
|
||||
protected:
|
||||
virtual bool on_init() override;
|
||||
virtual std::string on_get_name() const override;
|
||||
|
@ -91,7 +92,15 @@ private:
|
|||
int min_imgui_font_size = 18;
|
||||
int max_imgui_font_size = 60;
|
||||
|
||||
bool draw_advanced = false;
|
||||
ImVec2 minimal_window_size = ImVec2(174, 202);
|
||||
ImVec2 minimal_window_size_with_advance = ImVec2(174, 302);
|
||||
|
||||
// setted only when wanted to use - not all the time
|
||||
std::optional<ImVec2> offset;
|
||||
|
||||
// Zero means it is calculated in init function
|
||||
float advanced_input_width = 0.f;
|
||||
float combo_font_width = 0.f;
|
||||
float rename_pos_x = 0.f;
|
||||
float delete_pos_x = 0.f;
|
||||
|
|
|
@ -32,6 +32,11 @@
|
|||
#include "nanosvg/nanosvg.h"
|
||||
#include "nanosvg/nanosvgrast.h"
|
||||
|
||||
// suggest location
|
||||
#include "slic3r/GUI/GLCanvas3D.hpp"
|
||||
#include "slic3r/GUI/Plater.hpp"
|
||||
#include "slic3r/GUI/GUI_App.hpp"
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
|
@ -957,6 +962,74 @@ bool ImGuiWrapper::want_any_input() const
|
|||
return io.WantCaptureMouse || io.WantCaptureKeyboard || io.WantTextInput;
|
||||
}
|
||||
|
||||
ImVec2 ImGuiWrapper::suggest_location(const ImVec2 & dialog_size,
|
||||
const Slic3r::Polygon &interest)
|
||||
{
|
||||
Plater * plater = wxGetApp().plater();
|
||||
GLCanvas3D *canvas = plater->get_current_canvas3D();
|
||||
|
||||
// IMPROVE 1: do not select place over menu
|
||||
// BoundingBox top_menu;
|
||||
// GLGizmosManager &gizmo_mng = canvas->get_gizmos_manager();
|
||||
// BoundingBox side_menu; // gizmo_mng.get_size();
|
||||
// BoundingBox left_bottom_menu; // is permanent?
|
||||
// NotificationManager *notify_mng = plater->get_notification_manager();
|
||||
// BoundingBox notifications; // notify_mng->get_size();
|
||||
// m_window_width, m_window_height + position
|
||||
|
||||
// IMPROVE 2: use polygon of interest not only bounding box
|
||||
BoundingBox bb(interest.points);
|
||||
Point center = bb.center(); // interest.centroid();
|
||||
|
||||
// area size
|
||||
Size size = canvas->get_canvas_size();
|
||||
Point window_center(size.get_width() / 2, size.get_height() / 2);
|
||||
|
||||
// mov on side
|
||||
Point bb_half_size = (bb.max - bb.min) / 2;
|
||||
Point diff_center = window_center - center;
|
||||
Vec2d diff_norm(diff_center.x() / (double) bb_half_size.x(),
|
||||
diff_center.y() / (double) bb_half_size.y());
|
||||
if (diff_norm.x() > 1.) diff_norm.x() = 1.;
|
||||
if (diff_norm.x() < -1.) diff_norm.x() = -1.;
|
||||
if (diff_norm.y() > 1.) diff_norm.y() = 1.;
|
||||
if (diff_norm.y() < -1.) diff_norm.y() = -1.;
|
||||
|
||||
Vec2d abs_diff(abs(diff_norm.x()), abs(diff_norm.y()));
|
||||
if (abs_diff.x() < 1. && abs_diff.y() < 1.) {
|
||||
if (abs_diff.x() > abs_diff.y())
|
||||
diff_norm.x() = (diff_norm.x() < 0.) ? (-1.) : 1.;
|
||||
else
|
||||
diff_norm.y() = (diff_norm.y() < 0.) ? (-1.) : 1.;
|
||||
}
|
||||
|
||||
Point half_dialog_size(dialog_size.x / 2., dialog_size.y / 2.);
|
||||
Point move_size = bb_half_size + half_dialog_size;
|
||||
Point offseted_center = center - half_dialog_size;
|
||||
return ImVec2(offseted_center.x() + diff_norm.x() * move_size.x(),
|
||||
offseted_center.y() + diff_norm.y() * move_size.y());
|
||||
}
|
||||
|
||||
void ImGuiWrapper::draw(
|
||||
const Polygon &polygon,
|
||||
ImDrawList * draw_list /* = ImGui::GetOverlayDrawList()*/,
|
||||
ImU32 color /* = ImGui::GetColorU32(COL_ORANGE_LIGHT)*/,
|
||||
float thickness /* = 3.f*/)
|
||||
{
|
||||
// minimal one line consist of 2 points
|
||||
if (polygon.size() < 2) return;
|
||||
// need a place to draw
|
||||
if (draw_list == nullptr) return;
|
||||
|
||||
const Point *prev_point = &polygon.points.back();
|
||||
for (const Point &point : polygon.points) {
|
||||
ImVec2 p1(prev_point->x(), prev_point->y());
|
||||
ImVec2 p2(point.x(), point.y());
|
||||
draw_list->AddLine(p1, p2, color, thickness);
|
||||
prev_point = &point;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __APPLE__
|
||||
static const ImWchar ranges_keyboard_shortcuts[] =
|
||||
{
|
||||
|
|
|
@ -107,6 +107,31 @@ public:
|
|||
bool want_text_input() const;
|
||||
bool want_any_input() const;
|
||||
|
||||
/// <summary>
|
||||
/// Suggest loacation of dialog window,
|
||||
/// dependent on actual visible thing on platter
|
||||
/// like Gizmo menu size, notifications, ...
|
||||
/// To be near of polygon interest and not over it.
|
||||
/// And also not out of visible area.
|
||||
/// </summary>
|
||||
/// <param name="dialog_size">Define width and height of diaog window</param>
|
||||
/// <param name="interest">Area of interest. Result should be close to it</param>
|
||||
/// <returns>Suggestion for dialog offest</returns>
|
||||
static ImVec2 suggest_location(const ImVec2 & dialog_size,
|
||||
const Slic3r::Polygon &interest);
|
||||
|
||||
/// <summary>
|
||||
/// Visualization of polygon
|
||||
/// </summary>
|
||||
/// <param name="polygon">Define what to draw</param>
|
||||
/// <param name="draw_list">Define where to draw it</param>
|
||||
/// <param name="color">Color of polygon</param>
|
||||
/// <param name="thickness">Width of polygon line</param>
|
||||
static void draw(const Polygon &polygon,
|
||||
ImDrawList * draw_list = ImGui::GetOverlayDrawList(),
|
||||
ImU32 color = ImGui::GetColorU32(COL_ORANGE_LIGHT),
|
||||
float thickness = 3.f);
|
||||
|
||||
static const ImVec4 COL_GREY_DARK;
|
||||
static const ImVec4 COL_GREY_LIGHT;
|
||||
static const ImVec4 COL_ORANGE_DARK;
|
||||
|
|
Loading…
Add table
Reference in a new issue