mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-20 15:21:21 -06:00
Merge remote-tracking branch 'origin/dev' into feature_arrange_with_libnest2d
This commit is contained in:
commit
3c6afedcb1
36 changed files with 862 additions and 469 deletions
|
@ -173,6 +173,7 @@ extern void stl_mirror_xy(stl_file *stl);
|
|||
extern void stl_mirror_yz(stl_file *stl);
|
||||
extern void stl_mirror_xz(stl_file *stl);
|
||||
extern void stl_transform(stl_file *stl, float *trafo3x4);
|
||||
extern void stl_transform(stl_file *stl, const Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign>& t);
|
||||
extern void stl_open_merge(stl_file *stl, char *file);
|
||||
extern void stl_invalidate_shared_vertices(stl_file *stl);
|
||||
extern void stl_generate_shared_vertices(stl_file *stl);
|
||||
|
|
|
@ -286,7 +286,7 @@ void stl_read(stl_file *stl, int first_facet, bool first) {
|
|||
{
|
||||
// skip solid/endsolid
|
||||
// (in this order, otherwise it won't work when they are paired in the middle of a file)
|
||||
fscanf(stl->fp, "endsolid\n");
|
||||
fscanf(stl->fp, "endsolid%*[^\n]\n");
|
||||
fscanf(stl->fp, "solid%*[^\n]\n"); // name might contain spaces so %*s doesn't work and it also can be empty (just "solid")
|
||||
// Leading space in the fscanf format skips all leading white spaces including numerous new lines and tabs.
|
||||
int res_normal = fscanf(stl->fp, " facet normal %31s %31s %31s", normal_buf[0], normal_buf[1], normal_buf[2]);
|
||||
|
|
|
@ -155,6 +155,47 @@ void stl_transform(stl_file *stl, float *trafo3x4) {
|
|||
calculate_normals(stl);
|
||||
}
|
||||
|
||||
void stl_transform(stl_file *stl, const Eigen::Transform<float, 3, Eigen::Affine, Eigen::DontAlign>& t)
|
||||
{
|
||||
if (stl->error)
|
||||
return;
|
||||
|
||||
unsigned int vertices_count = 3 * (unsigned int)stl->stats.number_of_facets;
|
||||
if (vertices_count == 0)
|
||||
return;
|
||||
|
||||
Eigen::MatrixXf src_vertices(3, vertices_count);
|
||||
stl_facet* facet_ptr = stl->facet_start;
|
||||
unsigned int v_id = 0;
|
||||
while (facet_ptr < stl->facet_start + stl->stats.number_of_facets)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
::memcpy((void*)src_vertices.col(v_id).data(), (const void*)&facet_ptr->vertex[i], 3 * sizeof(float));
|
||||
++v_id;
|
||||
}
|
||||
facet_ptr += 1;
|
||||
}
|
||||
|
||||
Eigen::MatrixXf dst_vertices(3, vertices_count);
|
||||
dst_vertices = t * src_vertices.colwise().homogeneous();
|
||||
|
||||
facet_ptr = stl->facet_start;
|
||||
v_id = 0;
|
||||
while (facet_ptr < stl->facet_start + stl->stats.number_of_facets)
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
::memcpy((void*)&facet_ptr->vertex[i], (const void*)dst_vertices.col(v_id).data(), 3 * sizeof(float));
|
||||
++v_id;
|
||||
}
|
||||
facet_ptr += 1;
|
||||
}
|
||||
|
||||
stl_get_size(stl);
|
||||
calculate_normals(stl);
|
||||
}
|
||||
|
||||
void
|
||||
stl_rotate_x(stl_file *stl, float angle) {
|
||||
int i;
|
||||
|
|
|
@ -1738,10 +1738,7 @@ namespace Slic3r {
|
|||
stream << " </" << COMPONENTS_TAG << ">\n";
|
||||
}
|
||||
|
||||
Transform3d t = Transform3d::Identity();
|
||||
t.translate(Vec3d(instance->offset(0), instance->offset(1), 0.0));
|
||||
t.rotate(Eigen::AngleAxisd(instance->rotation, Vec3d::UnitZ()));
|
||||
t.scale(instance->scaling_factor);
|
||||
Transform3d t = instance->world_matrix();
|
||||
build_items.emplace_back(instance_id, t);
|
||||
|
||||
stream << " </" << OBJECT_TAG << ">\n";
|
||||
|
|
|
@ -665,6 +665,14 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
|
|||
_write_format(file, "\n");
|
||||
}
|
||||
|
||||
// adds tags for time estimators
|
||||
if (print.config.remaining_times.value)
|
||||
{
|
||||
_writeln(file, GCodeTimeEstimator::Normal_First_M73_Output_Placeholder_Tag);
|
||||
if (m_silent_time_estimator_enabled)
|
||||
_writeln(file, GCodeTimeEstimator::Silent_First_M73_Output_Placeholder_Tag);
|
||||
}
|
||||
|
||||
// Prepare the helper object for replacing placeholders in custom G-code and output filename.
|
||||
m_placeholder_parser = print.placeholder_parser;
|
||||
m_placeholder_parser.update_timestamp();
|
||||
|
@ -724,7 +732,6 @@ void GCode::_do_export(Print &print, FILE *file, GCodePreviewData *preview_data)
|
|||
m_placeholder_parser.set("has_wipe_tower", has_wipe_tower);
|
||||
m_placeholder_parser.set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config.single_extruder_multi_material_priming);
|
||||
std::string start_gcode = this->placeholder_parser_process("start_gcode", print.config.start_gcode.value, initial_extruder_id);
|
||||
|
||||
// Set bed temperature if the start G-code does not contain any bed temp control G-codes.
|
||||
this->_print_first_layer_bed_temperature(file, print, start_gcode, initial_extruder_id, true);
|
||||
// Set extruder(s) temperature before and after start G-code.
|
||||
|
|
|
@ -168,6 +168,9 @@ namespace Slic3r {
|
|||
}
|
||||
#endif // ENABLE_MOVE_STATS
|
||||
|
||||
const std::string GCodeTimeEstimator::Normal_First_M73_Output_Placeholder_Tag = "; NORMAL_FIRST_M73_OUTPUT_PLACEHOLDER";
|
||||
const std::string GCodeTimeEstimator::Silent_First_M73_Output_Placeholder_Tag = "; SILENT_FIRST_M73_OUTPUT_PLACEHOLDER";
|
||||
|
||||
GCodeTimeEstimator::GCodeTimeEstimator(EMode mode)
|
||||
: _mode(mode)
|
||||
{
|
||||
|
@ -294,7 +297,15 @@ namespace Slic3r {
|
|||
throw std::runtime_error(std::string("Remaining times export failed.\nError while reading from file.\n"));
|
||||
}
|
||||
|
||||
gcode_line += "\n";
|
||||
// replaces placeholders for initial line M73 with the real lines
|
||||
if (((_mode == Normal) && (gcode_line == Normal_First_M73_Output_Placeholder_Tag)) ||
|
||||
((_mode == Silent) && (gcode_line == Silent_First_M73_Output_Placeholder_Tag)))
|
||||
{
|
||||
sprintf(time_line, time_mask.c_str(), std::to_string(0), _get_time_minutes(_time).c_str());
|
||||
gcode_line = time_line;
|
||||
}
|
||||
else
|
||||
gcode_line += "\n";
|
||||
|
||||
// add remaining time lines where needed
|
||||
_parser.parse_line(gcode_line,
|
||||
|
|
|
@ -17,6 +17,9 @@ namespace Slic3r {
|
|||
class GCodeTimeEstimator
|
||||
{
|
||||
public:
|
||||
static const std::string Normal_First_M73_Output_Placeholder_Tag;
|
||||
static const std::string Silent_First_M73_Output_Placeholder_Tag;
|
||||
|
||||
enum EMode : unsigned char
|
||||
{
|
||||
Normal,
|
||||
|
|
|
@ -237,7 +237,6 @@ BoundingBoxf3 Model::bounding_box() const
|
|||
|
||||
void Model::center_instances_around_point(const Vec2d &point)
|
||||
{
|
||||
// BoundingBoxf3 bb = this->bounding_box();
|
||||
BoundingBoxf3 bb;
|
||||
for (ModelObject *o : this->objects)
|
||||
for (size_t i = 0; i < o->instances.size(); ++ i)
|
||||
|
@ -670,22 +669,19 @@ void ModelObject::center_around_origin()
|
|||
if (! v->modifier)
|
||||
bb.merge(v->mesh.bounding_box());
|
||||
|
||||
// First align to origin on XYZ, then center it on XY.
|
||||
Vec3d size = bb.size();
|
||||
size(2) = 0.;
|
||||
Vec3d shift3 = - bb.min - 0.5 * size;
|
||||
// Unaligned vector, for the Rotation2D to work on Visual Studio 2013.
|
||||
Eigen::Vector2d shift2 = to_2d(shift3);
|
||||
|
||||
this->translate(shift3);
|
||||
this->origin_translation += shift3;
|
||||
|
||||
// Shift is the vector from the center of the bottom face of the bounding box to the origin
|
||||
Vec3d shift = -bb.center();
|
||||
shift(2) = -bb.min(2);
|
||||
|
||||
this->translate(shift);
|
||||
this->origin_translation += shift;
|
||||
|
||||
if (!this->instances.empty()) {
|
||||
for (ModelInstance *i : this->instances) {
|
||||
// apply rotation and scaling to vector as well before translating instance,
|
||||
// in order to leave final position unaltered
|
||||
Eigen::Rotation2Dd rot(i->rotation);
|
||||
i->offset -= rot * shift2 * i->scaling_factor;
|
||||
Vec3d i_shift = i->world_matrix(true) * shift;
|
||||
i->offset -= to_2d(i_shift);
|
||||
}
|
||||
this->invalidate_bounding_box();
|
||||
}
|
||||
|
@ -861,12 +857,7 @@ void ModelObject::check_instances_print_volume_state(const BoundingBoxf3& print_
|
|||
{
|
||||
for (ModelInstance* inst : this->instances)
|
||||
{
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.translate(Vec3d(inst->offset(0), inst->offset(1), 0.0));
|
||||
m.rotate(Eigen::AngleAxisd(inst->rotation, Vec3d::UnitZ()));
|
||||
m.scale(inst->scaling_factor);
|
||||
|
||||
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(m);
|
||||
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(inst->world_matrix());
|
||||
|
||||
if (print_volume.contains(bb))
|
||||
inst->print_volume_state = ModelInstance::PVS_Inside;
|
||||
|
@ -995,26 +986,17 @@ size_t ModelVolume::split(unsigned int max_extruders)
|
|||
|
||||
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->rotate_z(this->rotation); // rotate around mesh origin
|
||||
mesh->scale(this->scaling_factor); // scale around mesh origin
|
||||
if (!dont_translate)
|
||||
mesh->translate(this->offset(0), this->offset(1), 0);
|
||||
mesh->transform(world_matrix(dont_translate).cast<float>());
|
||||
}
|
||||
|
||||
BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
// Rotate around mesh origin.
|
||||
double c = cos(this->rotation);
|
||||
double s = sin(this->rotation);
|
||||
BoundingBoxf3 bbox;
|
||||
for (int i = 0; i < mesh->stl.stats.number_of_facets; ++ i) {
|
||||
const stl_facet &facet = mesh->stl.facet_start[i];
|
||||
for (int j = 0; j < 3; ++ j) {
|
||||
const stl_vertex &v = facet.vertex[j];
|
||||
bbox.merge(Vec3d(c * v(0) - s * v(1), s * v(0) + c * v(1), v(2)));
|
||||
}
|
||||
}
|
||||
if (! empty(bbox)) {
|
||||
TriangleMesh copy(*mesh);
|
||||
copy.transform(world_matrix(true, false, true).cast<float>());
|
||||
BoundingBoxf3 bbox = copy.bounding_box();
|
||||
|
||||
if (!empty(bbox)) {
|
||||
// Scale the bounding box uniformly.
|
||||
if (std::abs(this->scaling_factor - 1.) > EPSILON) {
|
||||
bbox.min *= this->scaling_factor;
|
||||
|
@ -1031,13 +1013,12 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
|
|||
|
||||
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
||||
{
|
||||
Transform3d matrix = Transform3d::Identity();
|
||||
if (!dont_translate)
|
||||
matrix.translate(Vec3d(offset(0), offset(1), 0.0));
|
||||
return bbox.transformed(world_matrix(dont_translate));
|
||||
}
|
||||
|
||||
matrix.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ()));
|
||||
matrix.scale(scaling_factor);
|
||||
return bbox.transformed(matrix);
|
||||
Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
|
||||
{
|
||||
return world_matrix(dont_translate) * v;
|
||||
}
|
||||
|
||||
void ModelInstance::transform_polygon(Polygon* polygon) const
|
||||
|
@ -1046,4 +1027,20 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
|
|||
polygon->scale(this->scaling_factor); // scale around polygon origin
|
||||
}
|
||||
|
||||
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
|
||||
{
|
||||
Transform3d m = Transform3d::Identity();
|
||||
|
||||
if (!dont_translate)
|
||||
m.translate(Vec3d(offset(0), offset(1), 0.0));
|
||||
|
||||
if (!dont_rotate)
|
||||
m.rotate(Eigen::AngleAxisd(rotation, Vec3d::UnitZ()));
|
||||
|
||||
if (!dont_scale)
|
||||
m.scale(scaling_factor);
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -224,7 +224,6 @@ public:
|
|||
|
||||
friend class ModelObject;
|
||||
|
||||
// Transform3d transform;
|
||||
double rotation; // Rotation around the Z axis, in radians around mesh center point
|
||||
double scaling_factor;
|
||||
Vec2d offset; // in unscaled coordinates
|
||||
|
@ -240,9 +239,13 @@ public:
|
|||
BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate = false) const;
|
||||
// Transform an external bounding box.
|
||||
BoundingBoxf3 transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate = false) const;
|
||||
// Transform an external vector.
|
||||
Vec3d transform_vector(const Vec3d& v, bool dont_translate = false) const;
|
||||
// To be called on an external polygon. It does not translate the polygon, only rotates and scales.
|
||||
void transform_polygon(Polygon* polygon) const;
|
||||
|
||||
Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const;
|
||||
|
||||
bool is_printable() const { return print_volume_state == PVS_Inside; }
|
||||
|
||||
private:
|
||||
|
|
|
@ -264,7 +264,7 @@ void TriangleMesh::rotate(float angle, const Vec3d& axis)
|
|||
Vec3f axis_norm = axis.cast<float>().normalized();
|
||||
Transform3f m = Transform3f::Identity();
|
||||
m.rotate(Eigen::AngleAxisf(angle, axis_norm));
|
||||
stl_transform(&stl, (float*)m.data());
|
||||
stl_transform(&stl, m);
|
||||
}
|
||||
|
||||
void TriangleMesh::mirror(const Axis &axis)
|
||||
|
@ -279,6 +279,11 @@ void TriangleMesh::mirror(const Axis &axis)
|
|||
stl_invalidate_shared_vertices(&this->stl);
|
||||
}
|
||||
|
||||
void TriangleMesh::transform(const Transform3f& t)
|
||||
{
|
||||
stl_transform(&stl, t);
|
||||
}
|
||||
|
||||
void TriangleMesh::align_to_origin()
|
||||
{
|
||||
this->translate(
|
||||
|
@ -523,9 +528,9 @@ BoundingBoxf3 TriangleMesh::transformed_bounding_box(const Transform3d& t) const
|
|||
src_vertices(0, v_id) = (double)facet_ptr->vertex[i](0);
|
||||
src_vertices(1, v_id) = (double)facet_ptr->vertex[i](1);
|
||||
src_vertices(2, v_id) = (double)facet_ptr->vertex[i](2);
|
||||
++v_id;
|
||||
}
|
||||
facet_ptr += 1;
|
||||
++v_id;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ public:
|
|||
void mirror_x() { this->mirror(X); }
|
||||
void mirror_y() { this->mirror(Y); }
|
||||
void mirror_z() { this->mirror(Z); }
|
||||
void transform(const Transform3f& t);
|
||||
void align_to_origin();
|
||||
void rotate(double angle, Point* center);
|
||||
TriangleMeshPtrs split() const;
|
||||
|
|
|
@ -97,8 +97,9 @@ public:
|
|||
void call(int i) const;
|
||||
void call(int i, int j) const;
|
||||
void call(const std::vector<int>& ints) const;
|
||||
void call(double d) const;
|
||||
void call(double a) const;
|
||||
void call(double a, double b) const;
|
||||
void call(double a, double b, double c) const;
|
||||
void call(double a, double b, double c, double d) const;
|
||||
void call(bool b) const;
|
||||
private:
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
#include <boost/thread.hpp>
|
||||
|
||||
#define SLIC3R_FORK_NAME "Slic3r Prusa Edition"
|
||||
#define SLIC3R_VERSION "1.41.0-beta2"
|
||||
#define SLIC3R_VERSION "1.41.0"
|
||||
#define SLIC3R_BUILD "UNKNOWN"
|
||||
|
||||
typedef int32_t coord_t;
|
||||
|
|
|
@ -251,7 +251,7 @@ void PerlCallback::call(const std::vector<int>& ints) const
|
|||
LEAVE;
|
||||
}
|
||||
|
||||
void PerlCallback::call(double d) const
|
||||
void PerlCallback::call(double a) const
|
||||
{
|
||||
if (!m_callback)
|
||||
return;
|
||||
|
@ -259,7 +259,7 @@ void PerlCallback::call(double d) const
|
|||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
XPUSHs(sv_2mortal(newSVnv(d)));
|
||||
XPUSHs(sv_2mortal(newSVnv(a)));
|
||||
PUTBACK;
|
||||
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
|
||||
FREETMPS;
|
||||
|
@ -282,6 +282,23 @@ void PerlCallback::call(double a, double b) const
|
|||
LEAVE;
|
||||
}
|
||||
|
||||
void PerlCallback::call(double a, double b, double c) const
|
||||
{
|
||||
if (!m_callback)
|
||||
return;
|
||||
dSP;
|
||||
ENTER;
|
||||
SAVETMPS;
|
||||
PUSHMARK(SP);
|
||||
XPUSHs(sv_2mortal(newSVnv(a)));
|
||||
XPUSHs(sv_2mortal(newSVnv(b)));
|
||||
XPUSHs(sv_2mortal(newSVnv(c)));
|
||||
PUTBACK;
|
||||
perl_call_sv(SvRV((SV*)m_callback), G_DISCARD);
|
||||
FREETMPS;
|
||||
LEAVE;
|
||||
}
|
||||
|
||||
void PerlCallback::call(double a, double b, double c, double d) const
|
||||
{
|
||||
if (!m_callback)
|
||||
|
|
|
@ -195,9 +195,9 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f };
|
|||
const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f };
|
||||
|
||||
GLVolume::GLVolume(float r, float g, float b, float a)
|
||||
: m_origin(0, 0, 0)
|
||||
, m_angle_z(0.0f)
|
||||
, m_scale_factor(1.0f)
|
||||
: m_offset(Vec3d::Zero())
|
||||
, m_rotation(0.0)
|
||||
, m_scaling_factor(1.0)
|
||||
, m_world_matrix(Transform3f::Identity())
|
||||
, m_world_matrix_dirty(true)
|
||||
, m_transformed_bounding_box_dirty(true)
|
||||
|
@ -255,43 +255,43 @@ void GLVolume::set_render_color()
|
|||
set_render_color(color, 4);
|
||||
}
|
||||
|
||||
const Vec3d& GLVolume::get_origin() const
|
||||
double GLVolume::get_rotation()
|
||||
{
|
||||
return m_origin;
|
||||
return m_rotation;
|
||||
}
|
||||
|
||||
float GLVolume::get_angle_z()
|
||||
void GLVolume::set_rotation(double rotation)
|
||||
{
|
||||
return m_angle_z;
|
||||
}
|
||||
|
||||
void GLVolume::set_origin(const Vec3d& origin)
|
||||
{
|
||||
if (m_origin != origin)
|
||||
if (m_rotation != rotation)
|
||||
{
|
||||
m_origin = origin;
|
||||
m_rotation = rotation;
|
||||
m_world_matrix_dirty = true;
|
||||
m_transformed_bounding_box_dirty = true;
|
||||
m_transformed_convex_hull_bounding_box_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GLVolume::set_angle_z(float angle_z)
|
||||
const Vec3d& GLVolume::get_offset() const
|
||||
{
|
||||
if (m_angle_z != angle_z)
|
||||
return m_offset;
|
||||
}
|
||||
|
||||
void GLVolume::set_offset(const Vec3d& offset)
|
||||
{
|
||||
if (m_offset != offset)
|
||||
{
|
||||
m_angle_z = angle_z;
|
||||
m_offset = offset;
|
||||
m_world_matrix_dirty = true;
|
||||
m_transformed_bounding_box_dirty = true;
|
||||
m_transformed_convex_hull_bounding_box_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
void GLVolume::set_scale_factor(float scale_factor)
|
||||
void GLVolume::set_scaling_factor(double factor)
|
||||
{
|
||||
if (m_scale_factor != scale_factor)
|
||||
if (m_scaling_factor != factor)
|
||||
{
|
||||
m_scale_factor = scale_factor;
|
||||
m_scaling_factor = factor;
|
||||
m_world_matrix_dirty = true;
|
||||
m_transformed_bounding_box_dirty = true;
|
||||
m_transformed_convex_hull_bounding_box_dirty = true;
|
||||
|
@ -303,14 +303,24 @@ void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
|
|||
m_convex_hull = &convex_hull;
|
||||
}
|
||||
|
||||
void GLVolume::set_select_group_id(const std::string& select_by)
|
||||
{
|
||||
if (select_by == "object")
|
||||
select_group_id = object_idx() * 1000000;
|
||||
else if (select_by == "volume")
|
||||
select_group_id = object_idx() * 1000000 + volume_idx() * 1000;
|
||||
else if (select_by == "instance")
|
||||
select_group_id = composite_id;
|
||||
}
|
||||
|
||||
const Transform3f& GLVolume::world_matrix() const
|
||||
{
|
||||
if (m_world_matrix_dirty)
|
||||
{
|
||||
m_world_matrix = Transform3f::Identity();
|
||||
m_world_matrix.translate(Vec3f((float)m_origin(0), (float)m_origin(1), (float)m_origin(2)));
|
||||
m_world_matrix.rotate(Eigen::AngleAxisf(m_angle_z, Vec3f::UnitZ()));
|
||||
m_world_matrix.scale(m_scale_factor);
|
||||
m_world_matrix.translate(m_offset.cast<float>());
|
||||
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
|
||||
m_world_matrix.scale((float)m_scaling_factor);
|
||||
m_world_matrix_dirty = false;
|
||||
}
|
||||
return m_world_matrix;
|
||||
|
@ -384,9 +394,9 @@ void GLVolume::render() const
|
|||
|
||||
::glCullFace(GL_BACK);
|
||||
::glPushMatrix();
|
||||
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
|
||||
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
|
||||
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
|
||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||
if (this->indexed_vertex_array.indexed())
|
||||
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
|
||||
else
|
||||
|
@ -510,9 +520,9 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
|
|||
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), nullptr);
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
|
||||
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
|
||||
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
|
||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||
|
||||
if (n_triangles > 0)
|
||||
{
|
||||
|
@ -555,9 +565,9 @@ void GLVolume::render_legacy() const
|
|||
::glNormalPointer(GL_FLOAT, 6 * sizeof(float), indexed_vertex_array.vertices_and_normals_interleaved.data());
|
||||
|
||||
::glPushMatrix();
|
||||
::glTranslated(m_origin(0), m_origin(1), m_origin(2));
|
||||
::glRotatef(m_angle_z * 180.0f / PI, 0.0f, 0.0f, 1.0f);
|
||||
::glScalef(m_scale_factor, m_scale_factor, m_scale_factor);
|
||||
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
|
||||
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
|
||||
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
|
||||
|
||||
if (n_triangles > 0)
|
||||
::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first);
|
||||
|
@ -655,12 +665,7 @@ std::vector<int> GLVolumeCollection::load_object(
|
|||
v.bounding_box = v.indexed_vertex_array.bounding_box();
|
||||
v.indexed_vertex_array.finalize_geometry(use_VBOs);
|
||||
v.composite_id = obj_idx * 1000000 + volume_idx * 1000 + instance_idx;
|
||||
if (select_by == "object")
|
||||
v.select_group_id = obj_idx * 1000000;
|
||||
else if (select_by == "volume")
|
||||
v.select_group_id = obj_idx * 1000000 + volume_idx * 1000;
|
||||
else if (select_by == "instance")
|
||||
v.select_group_id = v.composite_id;
|
||||
v.set_select_group_id(select_by);
|
||||
if (drag_by == "object")
|
||||
v.drag_group_id = obj_idx * 1000;
|
||||
else if (drag_by == "instance")
|
||||
|
@ -675,9 +680,9 @@ std::vector<int> GLVolumeCollection::load_object(
|
|||
}
|
||||
v.is_modifier = model_volume->modifier;
|
||||
v.shader_outside_printer_detection_enabled = !model_volume->modifier;
|
||||
v.set_origin(Vec3d(instance->offset(0), instance->offset(1), 0.0));
|
||||
v.set_angle_z(instance->rotation);
|
||||
v.set_scale_factor(instance->scaling_factor);
|
||||
v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0));
|
||||
v.set_rotation(instance->rotation);
|
||||
v.set_scaling_factor(instance->scaling_factor);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -746,7 +751,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
|
|||
else
|
||||
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
|
||||
|
||||
v.set_origin(Vec3d(pos_x, pos_y, 0.));
|
||||
v.set_offset(Vec3d(pos_x, pos_y, 0.0));
|
||||
|
||||
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
|
||||
v.bounding_box = v.indexed_vertex_array.bounding_box();
|
||||
|
@ -949,6 +954,15 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con
|
|||
}
|
||||
}
|
||||
|
||||
void GLVolumeCollection::set_select_by(const std::string& select_by)
|
||||
{
|
||||
for (GLVolume *vol : this->volumes)
|
||||
{
|
||||
if (vol != nullptr)
|
||||
vol->set_select_group_id(select_by);
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<double> GLVolumeCollection::get_current_print_zs(bool active_only) const
|
||||
{
|
||||
// Collect layer top positions of all volumes.
|
||||
|
@ -1190,7 +1204,7 @@ static void thick_lines_to_indexed_vertex_array(
|
|||
b1_prev = b1;
|
||||
v_prev = v;
|
||||
|
||||
if (bottom_z_different)
|
||||
if (bottom_z_different && (closed || (!is_first && !is_last)))
|
||||
{
|
||||
// Found a change of the layer thickness -> Add a cap at the beginning of this segment.
|
||||
volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]);
|
||||
|
@ -1198,10 +1212,10 @@ static void thick_lines_to_indexed_vertex_array(
|
|||
|
||||
if (! closed) {
|
||||
// Terminate open paths with caps.
|
||||
if (is_first && !bottom_z_different)
|
||||
if (is_first)
|
||||
volume.push_quad(idx_a[BOTTOM], idx_a[RIGHT], idx_a[TOP], idx_a[LEFT]);
|
||||
// We don't use 'else' because both cases are true if we have only one line.
|
||||
if (is_last && !bottom_z_different)
|
||||
if (is_last)
|
||||
volume.push_quad(idx_b[BOTTOM], idx_b[LEFT], idx_b[TOP], idx_b[RIGHT]);
|
||||
}
|
||||
|
||||
|
@ -1772,12 +1786,12 @@ void _3DScene::set_model(wxGLCanvas* canvas, Model* model)
|
|||
|
||||
void _3DScene::set_bed_shape(wxGLCanvas* canvas, const Pointfs& shape)
|
||||
{
|
||||
return s_canvas_mgr.set_bed_shape(canvas, shape);
|
||||
s_canvas_mgr.set_bed_shape(canvas, shape);
|
||||
}
|
||||
|
||||
void _3DScene::set_auto_bed_shape(wxGLCanvas* canvas)
|
||||
{
|
||||
return s_canvas_mgr.set_auto_bed_shape(canvas);
|
||||
s_canvas_mgr.set_auto_bed_shape(canvas);
|
||||
}
|
||||
|
||||
BoundingBoxf3 _3DScene::get_volumes_bounding_box(wxGLCanvas* canvas)
|
||||
|
@ -1792,22 +1806,27 @@ void _3DScene::set_axes_length(wxGLCanvas* canvas, float length)
|
|||
|
||||
void _3DScene::set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons)
|
||||
{
|
||||
return s_canvas_mgr.set_cutting_plane(canvas, z, polygons);
|
||||
s_canvas_mgr.set_cutting_plane(canvas, z, polygons);
|
||||
}
|
||||
|
||||
void _3DScene::set_color_by(wxGLCanvas* canvas, const std::string& value)
|
||||
{
|
||||
return s_canvas_mgr.set_color_by(canvas, value);
|
||||
s_canvas_mgr.set_color_by(canvas, value);
|
||||
}
|
||||
|
||||
void _3DScene::set_select_by(wxGLCanvas* canvas, const std::string& value)
|
||||
{
|
||||
return s_canvas_mgr.set_select_by(canvas, value);
|
||||
s_canvas_mgr.set_select_by(canvas, value);
|
||||
}
|
||||
|
||||
void _3DScene::set_drag_by(wxGLCanvas* canvas, const std::string& value)
|
||||
{
|
||||
return s_canvas_mgr.set_drag_by(canvas, value);
|
||||
s_canvas_mgr.set_drag_by(canvas, value);
|
||||
}
|
||||
|
||||
std::string _3DScene::get_select_by(wxGLCanvas* canvas)
|
||||
{
|
||||
return s_canvas_mgr.get_select_by(canvas);
|
||||
}
|
||||
|
||||
bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas)
|
||||
|
@ -2080,6 +2099,11 @@ void _3DScene::register_action_layersediting_callback(wxGLCanvas* canvas, void*
|
|||
s_canvas_mgr.register_action_layersediting_callback(canvas, callback);
|
||||
}
|
||||
|
||||
void _3DScene::register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
s_canvas_mgr.register_action_selectbyparts_callback(canvas, callback);
|
||||
}
|
||||
|
||||
static inline int hex_digit_to_int(const char c)
|
||||
{
|
||||
return
|
||||
|
@ -2117,6 +2141,11 @@ std::vector<int> _3DScene::load_object(wxGLCanvas* canvas, const Model* model, i
|
|||
return s_canvas_mgr.load_object(canvas, model, obj_idx);
|
||||
}
|
||||
|
||||
int _3DScene::get_first_volume_id(wxGLCanvas* canvas, int obj_idx)
|
||||
{
|
||||
return s_canvas_mgr.get_first_volume_id(canvas, obj_idx);
|
||||
}
|
||||
|
||||
void _3DScene::reload_scene(wxGLCanvas* canvas, bool force)
|
||||
{
|
||||
s_canvas_mgr.reload_scene(canvas, force);
|
||||
|
|
|
@ -255,11 +255,11 @@ public:
|
|||
|
||||
private:
|
||||
// Offset of the volume to be rendered.
|
||||
Vec3d m_origin;
|
||||
Vec3d m_offset;
|
||||
// Rotation around Z axis of the volume to be rendered.
|
||||
float m_angle_z;
|
||||
double m_rotation;
|
||||
// Scale factor of the volume to be rendered.
|
||||
float m_scale_factor;
|
||||
double m_scaling_factor;
|
||||
// World matrix of the volume to be rendered.
|
||||
mutable Transform3f m_world_matrix;
|
||||
// Whether or not is needed to recalculate the world matrix.
|
||||
|
@ -327,13 +327,18 @@ public:
|
|||
// Sets render color in dependence of current state
|
||||
void set_render_color();
|
||||
|
||||
float get_angle_z();
|
||||
const Vec3d& get_origin() const;
|
||||
void set_origin(const Vec3d& origin);
|
||||
void set_angle_z(float angle_z);
|
||||
void set_scale_factor(float scale_factor);
|
||||
double get_rotation();
|
||||
void set_rotation(double rotation);
|
||||
|
||||
const Vec3d& get_offset() const;
|
||||
void set_offset(const Vec3d& offset);
|
||||
|
||||
void set_scaling_factor(double factor);
|
||||
|
||||
void set_convex_hull(const TriangleMesh& convex_hull);
|
||||
|
||||
void set_select_group_id(const std::string& select_by);
|
||||
|
||||
int object_idx() const { return this->composite_id / 1000000; }
|
||||
int volume_idx() const { return (this->composite_id / 1000) % 1000; }
|
||||
int instance_idx() const { return this->composite_id % 1000; }
|
||||
|
@ -443,6 +448,8 @@ public:
|
|||
|
||||
void update_colors_by_extruder(const DynamicPrintConfig* config);
|
||||
|
||||
void set_select_by(const std::string& select_by);
|
||||
|
||||
// Returns a vector containing the sorted list of all the print_zs of the volumes contained in this collection
|
||||
std::vector<double> get_current_print_zs(bool active_only) const;
|
||||
|
||||
|
@ -496,6 +503,8 @@ public:
|
|||
static void set_select_by(wxGLCanvas* canvas, const std::string& value);
|
||||
static void set_drag_by(wxGLCanvas* canvas, const std::string& value);
|
||||
|
||||
static std::string get_select_by(wxGLCanvas* canvas);
|
||||
|
||||
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
|
||||
static bool is_layers_editing_allowed(wxGLCanvas* canvas);
|
||||
static bool is_shader_enabled(wxGLCanvas* canvas);
|
||||
|
@ -559,10 +568,13 @@ public:
|
|||
static void register_action_cut_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_action_settings_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback);
|
||||
static void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
static std::vector<int> load_object(wxGLCanvas* canvas, const ModelObject* model_object, int obj_idx, std::vector<int> instance_idxs);
|
||||
static std::vector<int> load_object(wxGLCanvas* canvas, const Model* model, int obj_idx);
|
||||
|
||||
static int get_first_volume_id(wxGLCanvas* canvas, int obj_idx);
|
||||
|
||||
static void reload_scene(wxGLCanvas* canvas, bool force);
|
||||
|
||||
static void load_gcode_preview(wxGLCanvas* canvas, const GCodePreviewData* preview_data, const std::vector<std::string>& str_tool_colors);
|
||||
|
|
|
@ -228,24 +228,20 @@ namespace Slic3r { namespace GUI {
|
|||
}), temp->GetId());
|
||||
#endif // __WXGTK__
|
||||
|
||||
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent)
|
||||
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt)
|
||||
{
|
||||
#ifdef __WXGTK__
|
||||
bChangedValueEvent = true;
|
||||
#else
|
||||
on_change_field();
|
||||
if (bChangedValueEvent)
|
||||
#endif //__WXGTK__
|
||||
on_change_field();
|
||||
}), temp->GetId());
|
||||
|
||||
#ifdef __WXGTK__
|
||||
temp->Bind(wxEVT_KEY_UP, [this](wxKeyEvent& event)
|
||||
{
|
||||
if (bChangedValueEvent) {
|
||||
on_change_field();
|
||||
bChangedValueEvent = false;
|
||||
}
|
||||
event.Skip();
|
||||
});
|
||||
// to correct value updating on GTK we should:
|
||||
// call on_change_field() on wxEVT_KEY_UP instead of wxEVT_TEXT
|
||||
// and prevent value updating on wxEVT_KEY_DOWN
|
||||
temp->Bind(wxEVT_KEY_DOWN, &TextCtrl::change_field_value, this);
|
||||
temp->Bind(wxEVT_KEY_UP, &TextCtrl::change_field_value, this);
|
||||
#endif //__WXGTK__
|
||||
|
||||
// select all text using Ctrl+A
|
||||
|
@ -271,6 +267,15 @@ namespace Slic3r { namespace GUI {
|
|||
void TextCtrl::enable() { dynamic_cast<wxTextCtrl*>(window)->Enable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(true); }
|
||||
void TextCtrl::disable() { dynamic_cast<wxTextCtrl*>(window)->Disable(); dynamic_cast<wxTextCtrl*>(window)->SetEditable(false); }
|
||||
|
||||
#ifdef __WXGTK__
|
||||
void TextCtrl::change_field_value(wxEvent& event)
|
||||
{
|
||||
if (bChangedValueEvent = event.GetEventType()==wxEVT_KEY_UP)
|
||||
on_change_field();
|
||||
event.Skip();
|
||||
};
|
||||
#endif //__WXGTK__
|
||||
|
||||
void CheckBox::BUILD() {
|
||||
auto size = wxSize(wxDefaultSize);
|
||||
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
|
||||
|
|
|
@ -235,7 +235,8 @@ inline bool is_sizer_field(const t_field& obj) { return !is_bad_field(obj) && ob
|
|||
class TextCtrl : public Field {
|
||||
using Field::Field;
|
||||
#ifdef __WXGTK__
|
||||
bool bChangedValueEvent = false;
|
||||
bool bChangedValueEvent = true;
|
||||
void change_field_value(wxEvent& event);
|
||||
#endif //__WXGTK__
|
||||
public:
|
||||
TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
|
||||
|
|
|
@ -1320,16 +1320,6 @@ void GLCanvas3D::Gizmos::update(const Linef3& mouse_ray)
|
|||
curr->update(mouse_ray);
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::refresh()
|
||||
{
|
||||
if (!m_enabled)
|
||||
return;
|
||||
|
||||
GLGizmoBase* curr = _get_current();
|
||||
if (curr != nullptr)
|
||||
curr->refresh();
|
||||
}
|
||||
|
||||
GLCanvas3D::Gizmos::EType GLCanvas3D::Gizmos::get_current_type() const
|
||||
{
|
||||
return m_current;
|
||||
|
@ -1349,12 +1339,12 @@ bool GLCanvas3D::Gizmos::is_dragging() const
|
|||
return m_dragging;
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::start_dragging()
|
||||
void GLCanvas3D::Gizmos::start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
m_dragging = true;
|
||||
GLGizmoBase* curr = _get_current();
|
||||
if (curr != nullptr)
|
||||
curr->start_dragging();
|
||||
curr->start_dragging(box);
|
||||
}
|
||||
|
||||
void GLCanvas3D::Gizmos::stop_dragging()
|
||||
|
@ -2018,6 +2008,9 @@ void GLCanvas3D::update_volumes_selection(const std::vector<int>& selections)
|
|||
if (m_model == nullptr)
|
||||
return;
|
||||
|
||||
if (selections.empty())
|
||||
return;
|
||||
|
||||
for (unsigned int obj_idx = 0; obj_idx < (unsigned int)m_model->objects.size(); ++obj_idx)
|
||||
{
|
||||
if ((selections[obj_idx] == 1) && (obj_idx < (unsigned int)m_objects_volumes_idxs.size()))
|
||||
|
@ -2144,6 +2137,7 @@ void GLCanvas3D::set_color_by(const std::string& value)
|
|||
void GLCanvas3D::set_select_by(const std::string& value)
|
||||
{
|
||||
m_select_by = value;
|
||||
m_volumes.set_select_by(value);
|
||||
}
|
||||
|
||||
void GLCanvas3D::set_drag_by(const std::string& value)
|
||||
|
@ -2151,6 +2145,11 @@ void GLCanvas3D::set_drag_by(const std::string& value)
|
|||
m_drag_by = value;
|
||||
}
|
||||
|
||||
const std::string& GLCanvas3D::get_select_by() const
|
||||
{
|
||||
return m_select_by;
|
||||
}
|
||||
|
||||
float GLCanvas3D::get_camera_zoom() const
|
||||
{
|
||||
return m_camera.zoom;
|
||||
|
@ -2432,6 +2431,17 @@ std::vector<int> GLCanvas3D::load_object(const Model& model, int obj_idx)
|
|||
return std::vector<int>();
|
||||
}
|
||||
|
||||
int GLCanvas3D::get_first_volume_id(int obj_idx) const
|
||||
{
|
||||
for (int i = 0; i < (int)m_volumes.volumes.size(); ++i)
|
||||
{
|
||||
if ((m_volumes.volumes[i] != nullptr) && (m_volumes.volumes[i]->object_idx() == obj_idx))
|
||||
return i;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void GLCanvas3D::reload_scene(bool force)
|
||||
{
|
||||
if ((m_canvas == nullptr) || (m_config == nullptr) || (m_model == nullptr))
|
||||
|
@ -2467,8 +2477,6 @@ void GLCanvas3D::reload_scene(bool force)
|
|||
if (!m_objects_selections.empty())
|
||||
update_gizmos_data();
|
||||
|
||||
m_gizmos.refresh();
|
||||
|
||||
if (m_config->has("nozzle_diameter"))
|
||||
{
|
||||
// Should the wipe tower be visualized ?
|
||||
|
@ -2757,6 +2765,12 @@ void GLCanvas3D::register_action_layersediting_callback(void* callback)
|
|||
m_action_layersediting_callback.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::register_action_selectbyparts_callback(void* callback)
|
||||
{
|
||||
if (callback != nullptr)
|
||||
m_action_selectbyparts_callback.register_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3D::bind_event_handlers()
|
||||
{
|
||||
if (m_canvas != nullptr)
|
||||
|
@ -2952,7 +2966,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
m_mouse.position = Vec2d(-1.0, -1.0);
|
||||
m_dirty = true;
|
||||
}
|
||||
else if (evt.LeftDClick() && (m_hover_volume_id != -1))
|
||||
else if (evt.LeftDClick() && (m_hover_volume_id != -1) && !gizmos_overlay_contains_mouse && (toolbar_contains_mouse == -1))
|
||||
m_on_double_click_callback.call();
|
||||
else if (evt.LeftDClick() && (toolbar_contains_mouse != -1))
|
||||
{
|
||||
|
@ -2993,15 +3007,15 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
else if ((selected_object_idx != -1) && m_gizmos.grabber_contains_mouse())
|
||||
{
|
||||
update_gizmos_data();
|
||||
m_gizmos.start_dragging();
|
||||
m_gizmos.start_dragging(_selected_volumes_bounding_box());
|
||||
m_mouse.drag.gizmo_volume_idx = _get_first_selected_volume_id(selected_object_idx);
|
||||
|
||||
if (m_gizmos.get_current_type() == Gizmos::Flatten) {
|
||||
// Rotate the object so the normal points downward:
|
||||
Vec3d normal = m_gizmos.get_flattening_normal();
|
||||
if (normal != Vec3d::Zero()) {
|
||||
Vec3d axis = normal(2) > 0.999f ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ());
|
||||
float angle = -acos(-normal(2));
|
||||
if (normal(0) != 0.0 || normal(1) != 0.0 || normal(2) != 0.0) {
|
||||
Vec3d axis = normal(2) > 0.999 ? Vec3d::UnitX() : normal.cross(-Vec3d::UnitZ()).normalized();
|
||||
float angle = acos(clamp(-1.0, 1.0, -normal(2)));
|
||||
m_on_gizmo_rotate_callback.call(angle, (float)axis(0), (float)axis(1), (float)axis(2));
|
||||
}
|
||||
}
|
||||
|
@ -3036,14 +3050,13 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
}
|
||||
|
||||
update_gizmos_data();
|
||||
m_gizmos.refresh();
|
||||
m_dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
// propagate event through callback
|
||||
if (m_picking_enabled && (volume_idx != -1))
|
||||
_on_select(volume_idx);
|
||||
_on_select(volume_idx, selected_object_idx);
|
||||
|
||||
if (volume_idx != -1)
|
||||
{
|
||||
|
@ -3126,10 +3139,12 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
|
||||
// Apply new temporary volume origin and ignore Z.
|
||||
for (GLVolume* v : volumes)
|
||||
v->set_origin(v->get_origin() + Vec3d(vector(0), vector(1), 0.0));
|
||||
{
|
||||
v->set_offset(v->get_offset() + Vec3d(vector(0), vector(1), 0.0));
|
||||
}
|
||||
|
||||
update_position_values(volume->get_offset());
|
||||
m_mouse.drag.start_position_3D = cur_pos;
|
||||
m_gizmos.refresh();
|
||||
|
||||
m_dirty = true;
|
||||
}
|
||||
|
@ -3166,7 +3181,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
float scale_factor = m_gizmos.get_scale();
|
||||
for (GLVolume* v : volumes)
|
||||
{
|
||||
v->set_scale_factor(scale_factor);
|
||||
v->set_scaling_factor((double)scale_factor);
|
||||
update_scale_values((double)scale_factor);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3176,7 +3192,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
float angle_z = m_gizmos.get_angle_z();
|
||||
for (GLVolume* v : volumes)
|
||||
{
|
||||
v->set_angle_z(angle_z);
|
||||
v->set_rotation((double)angle_z);
|
||||
update_rotation_value((double)angle_z, Z);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -3193,13 +3210,8 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
}
|
||||
const Vec3d& size = bb.size();
|
||||
m_on_update_geometry_info_callback.call(size(0), size(1), size(2), m_gizmos.get_scale());
|
||||
update_scale_values(size, m_gizmos.get_scale());
|
||||
update_rotation_value(volumes[0]->get_angle_z(), "z");
|
||||
}
|
||||
|
||||
if ((m_gizmos.get_current_type() != Gizmos::Rotate) && (volumes.size() > 1))
|
||||
m_gizmos.refresh();
|
||||
|
||||
m_dirty = true;
|
||||
}
|
||||
else if (evt.Dragging() && !gizmos_overlay_contains_mouse)
|
||||
|
@ -3284,7 +3296,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
if (m_picking_enabled && !m_toolbar_action_running)
|
||||
{
|
||||
deselect_volumes();
|
||||
_on_select(-1);
|
||||
_on_select(-1, -1);
|
||||
update_gizmos_data();
|
||||
}
|
||||
}
|
||||
|
@ -3295,7 +3307,6 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
case Gizmos::Scale:
|
||||
{
|
||||
m_on_gizmo_scale_uniformly_callback.call((double)m_gizmos.get_scale());
|
||||
Slic3r::GUI::update_settings_value();
|
||||
break;
|
||||
}
|
||||
case Gizmos::Rotate:
|
||||
|
@ -3307,6 +3318,7 @@ void GLCanvas3D::on_mouse(wxMouseEvent& evt)
|
|||
break;
|
||||
}
|
||||
m_gizmos.stop_dragging();
|
||||
Slic3r::GUI::update_settings_value();
|
||||
}
|
||||
|
||||
m_mouse.drag.move_volume_idx = -1;
|
||||
|
@ -3509,6 +3521,17 @@ bool GLCanvas3D::_init_toolbar()
|
|||
if (!m_toolbar.add_item(item))
|
||||
return false;
|
||||
|
||||
if (!m_toolbar.add_separator())
|
||||
return false;
|
||||
|
||||
item.name = "selectbyparts";
|
||||
item.tooltip = GUI::L_str("Select by parts");
|
||||
item.sprite_id = 10;
|
||||
item.is_toggable = true;
|
||||
item.action_callback = &m_action_selectbyparts_callback;
|
||||
if (!m_toolbar.add_item(item))
|
||||
return false;
|
||||
|
||||
enable_toolbar_item("add", true);
|
||||
|
||||
return true;
|
||||
|
@ -3748,6 +3771,7 @@ void GLCanvas3D::_deregister_callbacks()
|
|||
m_action_cut_callback.deregister_callback();
|
||||
m_action_settings_callback.deregister_callback();
|
||||
m_action_layersediting_callback.deregister_callback();
|
||||
m_action_selectbyparts_callback.deregister_callback();
|
||||
}
|
||||
|
||||
void GLCanvas3D::_mark_volumes_for_layer_height() const
|
||||
|
@ -5219,7 +5243,7 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
|
|||
|
||||
std::set<std::string> done; // prevent moving instances twice
|
||||
bool object_moved = false;
|
||||
Vec3d wipe_tower_origin(0.0, 0.0, 0.0);
|
||||
Vec3d wipe_tower_origin = Vec3d::Zero();
|
||||
for (int volume_idx : volume_idxs)
|
||||
{
|
||||
GLVolume* volume = m_volumes.volumes[volume_idx];
|
||||
|
@ -5238,34 +5262,56 @@ void GLCanvas3D::_on_move(const std::vector<int>& volume_idxs)
|
|||
{
|
||||
// Move a regular object.
|
||||
ModelObject* model_object = m_model->objects[obj_idx];
|
||||
const Vec3d& origin = volume->get_origin();
|
||||
model_object->instances[instance_idx]->offset = Vec2d(origin(0), origin(1));
|
||||
model_object->invalidate_bounding_box();
|
||||
object_moved = true;
|
||||
if (model_object != nullptr)
|
||||
{
|
||||
const Vec3d& offset = volume->get_offset();
|
||||
model_object->instances[instance_idx]->offset = Vec2d(offset(0), offset(1));
|
||||
model_object->invalidate_bounding_box();
|
||||
update_position_values();
|
||||
object_moved = true;
|
||||
}
|
||||
}
|
||||
else if (obj_idx == 1000)
|
||||
// Move a wipe tower proxy.
|
||||
wipe_tower_origin = volume->get_origin();
|
||||
wipe_tower_origin = volume->get_offset();
|
||||
}
|
||||
|
||||
if (object_moved)
|
||||
m_on_instance_moved_callback.call();
|
||||
|
||||
if (wipe_tower_origin != Vec3d(0.0, 0.0, 0.0))
|
||||
if (wipe_tower_origin != Vec3d::Zero())
|
||||
m_on_wipe_tower_moved_callback.call(wipe_tower_origin(0), wipe_tower_origin(1));
|
||||
}
|
||||
|
||||
void GLCanvas3D::_on_select(int volume_idx)
|
||||
void GLCanvas3D::_on_select(int volume_idx, int object_idx)
|
||||
{
|
||||
int id = -1;
|
||||
int vol_id = -1;
|
||||
int obj_id = -1;
|
||||
|
||||
if ((volume_idx != -1) && (volume_idx < (int)m_volumes.volumes.size()))
|
||||
{
|
||||
if (m_select_by == "volume")
|
||||
id = m_volumes.volumes[volume_idx]->volume_idx();
|
||||
{
|
||||
if (m_volumes.volumes[volume_idx]->object_idx() != object_idx)
|
||||
{
|
||||
set_select_by("object");
|
||||
obj_id = m_volumes.volumes[volume_idx]->object_idx();
|
||||
vol_id = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj_id = object_idx;
|
||||
vol_id = m_volumes.volumes[volume_idx]->volume_idx();
|
||||
}
|
||||
}
|
||||
else if (m_select_by == "object")
|
||||
id = m_volumes.volumes[volume_idx]->object_idx();
|
||||
{
|
||||
obj_id = m_volumes.volumes[volume_idx]->object_idx();
|
||||
vol_id = -1;
|
||||
}
|
||||
}
|
||||
m_on_select_object_callback.call(id);
|
||||
|
||||
m_on_select_object_callback.call(obj_id, vol_id);
|
||||
}
|
||||
|
||||
std::vector<float> GLCanvas3D::_parse_colors(const std::vector<std::string>& colors)
|
||||
|
|
|
@ -367,14 +367,13 @@ public:
|
|||
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const;
|
||||
bool grabber_contains_mouse() const;
|
||||
void update(const Linef3& mouse_ray);
|
||||
void refresh();
|
||||
|
||||
EType get_current_type() const;
|
||||
|
||||
bool is_running() const;
|
||||
|
||||
bool is_dragging() const;
|
||||
void start_dragging();
|
||||
void start_dragging(const BoundingBoxf3& box);
|
||||
void stop_dragging();
|
||||
|
||||
float get_scale() const;
|
||||
|
@ -514,6 +513,7 @@ private:
|
|||
PerlCallback m_action_cut_callback;
|
||||
PerlCallback m_action_settings_callback;
|
||||
PerlCallback m_action_layersediting_callback;
|
||||
PerlCallback m_action_selectbyparts_callback;
|
||||
|
||||
public:
|
||||
GLCanvas3D(wxGLCanvas* canvas);
|
||||
|
@ -556,6 +556,8 @@ public:
|
|||
void set_select_by(const std::string& value);
|
||||
void set_drag_by(const std::string& value);
|
||||
|
||||
const std::string& get_select_by() const;
|
||||
|
||||
float get_camera_zoom() const;
|
||||
|
||||
BoundingBoxf3 volumes_bounding_box() const;
|
||||
|
@ -597,6 +599,8 @@ public:
|
|||
std::vector<int> load_object(const ModelObject& model_object, int obj_idx, std::vector<int> instance_idxs);
|
||||
std::vector<int> load_object(const Model& model, int obj_idx);
|
||||
|
||||
int get_first_volume_id(int obj_idx) const;
|
||||
|
||||
void reload_scene(bool force);
|
||||
|
||||
void load_gcode_preview(const GCodePreviewData& preview_data, const std::vector<std::string>& str_tool_colors);
|
||||
|
@ -631,6 +635,7 @@ public:
|
|||
void register_action_cut_callback(void* callback);
|
||||
void register_action_settings_callback(void* callback);
|
||||
void register_action_layersediting_callback(void* callback);
|
||||
void register_action_selectbyparts_callback(void* callback);
|
||||
|
||||
void bind_event_handlers();
|
||||
void unbind_event_handlers();
|
||||
|
@ -733,7 +738,7 @@ private:
|
|||
void _show_warning_texture_if_needed();
|
||||
|
||||
void _on_move(const std::vector<int>& volume_idxs);
|
||||
void _on_select(int volume_idx);
|
||||
void _on_select(int volume_idx, int object_idx);
|
||||
|
||||
// generates the legend texture in dependence of the current shown view type
|
||||
void _generate_legend_texture(const GCodePreviewData& preview_data, const std::vector<float>& tool_colors);
|
||||
|
|
|
@ -338,6 +338,12 @@ void GLCanvas3DManager::set_drag_by(wxGLCanvas* canvas, const std::string& value
|
|||
it->second->set_drag_by(value);
|
||||
}
|
||||
|
||||
std::string GLCanvas3DManager::get_select_by(wxGLCanvas* canvas) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->get_select_by() : "";
|
||||
}
|
||||
|
||||
bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
|
@ -536,6 +542,12 @@ std::vector<int> GLCanvas3DManager::load_object(wxGLCanvas* canvas, const Model*
|
|||
return (it != m_canvases.end()) ? it->second->load_object(*model, obj_idx) : std::vector<int>();
|
||||
}
|
||||
|
||||
int GLCanvas3DManager::get_first_volume_id(wxGLCanvas* canvas, int obj_idx) const
|
||||
{
|
||||
CanvasesMap::const_iterator it = _get_canvas(canvas);
|
||||
return (it != m_canvases.end()) ? it->second->get_first_volume_id(obj_idx) : -1;
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::reload_scene(wxGLCanvas* canvas, bool force)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
|
@ -765,6 +777,13 @@ void GLCanvas3DManager::register_action_layersediting_callback(wxGLCanvas* canva
|
|||
it->second->register_action_layersediting_callback(callback);
|
||||
}
|
||||
|
||||
void GLCanvas3DManager::register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback)
|
||||
{
|
||||
CanvasesMap::iterator it = _get_canvas(canvas);
|
||||
if (it != m_canvases.end())
|
||||
it->second->register_action_selectbyparts_callback(callback);
|
||||
}
|
||||
|
||||
GLCanvas3DManager::CanvasesMap::iterator GLCanvas3DManager::_get_canvas(wxGLCanvas* canvas)
|
||||
{
|
||||
return (canvas == nullptr) ? m_canvases.end() : m_canvases.find(canvas);
|
||||
|
|
|
@ -98,6 +98,8 @@ public:
|
|||
void set_select_by(wxGLCanvas* canvas, const std::string& value);
|
||||
void set_drag_by(wxGLCanvas* canvas, const std::string& value);
|
||||
|
||||
std::string get_select_by(wxGLCanvas* canvas) const;
|
||||
|
||||
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
|
||||
bool is_layers_editing_allowed(wxGLCanvas* canvas) const;
|
||||
bool is_shader_enabled(wxGLCanvas* canvas) const;
|
||||
|
@ -135,6 +137,8 @@ public:
|
|||
std::vector<int> load_object(wxGLCanvas* canvas, const ModelObject* model_object, int obj_idx, std::vector<int> instance_idxs);
|
||||
std::vector<int> load_object(wxGLCanvas* canvas, const Model* model, int obj_idx);
|
||||
|
||||
int get_first_volume_id(wxGLCanvas* canvas, int obj_idx) const;
|
||||
|
||||
void reload_scene(wxGLCanvas* canvas, bool force);
|
||||
|
||||
void load_gcode_preview(wxGLCanvas* canvas, const GCodePreviewData* preview_data, const std::vector<std::string>& str_tool_colors);
|
||||
|
@ -171,6 +175,7 @@ public:
|
|||
void register_action_cut_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_action_settings_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_action_layersediting_callback(wxGLCanvas* canvas, void* callback);
|
||||
void register_action_selectbyparts_callback(wxGLCanvas* canvas, void* callback);
|
||||
|
||||
private:
|
||||
CanvasesMap::iterator _get_canvas(wxGLCanvas* canvas);
|
||||
|
|
|
@ -15,14 +15,95 @@ static const float DEFAULT_BASE_COLOR[3] = { 0.625f, 0.625f, 0.625f };
|
|||
static const float DEFAULT_DRAG_COLOR[3] = { 1.0f, 1.0f, 1.0f };
|
||||
static const float DEFAULT_HIGHLIGHT_COLOR[3] = { 1.0f, 0.38f, 0.0f };
|
||||
|
||||
static const float RED[3] = { 1.0f, 0.0f, 0.0f };
|
||||
static const float GREEN[3] = { 0.0f, 1.0f, 0.0f };
|
||||
static const float BLUE[3] = { 0.0f, 0.0f, 1.0f };
|
||||
static const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 1.0f } };
|
||||
|
||||
namespace Slic3r {
|
||||
namespace GUI {
|
||||
|
||||
const float GLGizmoBase::Grabber::HalfSize = 2.0f;
|
||||
// returns the intersection of the given ray with the plane parallel to plane XY and passing through the given center
|
||||
// coordinates are local to the plane
|
||||
Vec3d intersection_on_plane_xy(const Linef3& ray, const Vec3d& center)
|
||||
{
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0));
|
||||
return Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0);
|
||||
}
|
||||
|
||||
// returns the intersection of the given ray with the plane parallel to plane XZ and passing through the given center
|
||||
// coordinates are local to the plane
|
||||
Vec3d intersection_on_plane_xz(const Linef3& ray, const Vec3d& center)
|
||||
{
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX()));
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0));
|
||||
return Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1));
|
||||
}
|
||||
|
||||
// returns the intersection of the given ray with the plane parallel to plane YZ and passing through the given center
|
||||
// coordinates are local to the plane
|
||||
Vec3d intersection_on_plane_yz(const Linef3& ray, const Vec3d& center)
|
||||
{
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY()));
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(ray, m).intersect_plane(0.0));
|
||||
|
||||
return Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0));
|
||||
}
|
||||
|
||||
// return an index:
|
||||
// 0 for plane XY
|
||||
// 1 for plane XZ
|
||||
// 2 for plane YZ
|
||||
// which indicates which plane is best suited for intersecting the given unit vector
|
||||
// giving precedence to the plane with the given index
|
||||
unsigned int select_best_plane(const Vec3d& unit_vector, unsigned int preferred_plane)
|
||||
{
|
||||
unsigned int ret = preferred_plane;
|
||||
|
||||
// 1st checks if the given vector is not parallel to the given preferred plane
|
||||
double dot_to_normal = 0.0;
|
||||
switch (ret)
|
||||
{
|
||||
case 0: // plane xy
|
||||
{
|
||||
dot_to_normal = std::abs(unit_vector.dot(Vec3d::UnitZ()));
|
||||
break;
|
||||
}
|
||||
case 1: // plane xz
|
||||
{
|
||||
dot_to_normal = std::abs(unit_vector.dot(-Vec3d::UnitY()));
|
||||
break;
|
||||
}
|
||||
case 2: // plane yz
|
||||
{
|
||||
dot_to_normal = std::abs(unit_vector.dot(Vec3d::UnitX()));
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// if almost parallel, select the plane whose normal direction is closest to the given vector direction,
|
||||
// otherwise return the given preferred plane index
|
||||
if (dot_to_normal < 0.1)
|
||||
{
|
||||
typedef std::map<double, unsigned int> ProjsMap;
|
||||
ProjsMap projs_map;
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(Vec3d::UnitZ())), 0)); // plane xy
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(-Vec3d::UnitY())), 1)); // plane xz
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(unit_vector.dot(Vec3d::UnitX())), 2)); // plane yz
|
||||
ret = projs_map.rbegin()->second;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
const float GLGizmoBase::Grabber::HalfSize = 2.0f;
|
||||
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
|
||||
|
||||
GLGizmoBase::Grabber::Grabber()
|
||||
|
@ -131,6 +212,7 @@ GLGizmoBase::GLGizmoBase(GLCanvas3D& parent)
|
|||
, m_group_id(-1)
|
||||
, m_state(Off)
|
||||
, m_hover_id(-1)
|
||||
, m_dragging(false)
|
||||
{
|
||||
::memcpy((void*)m_base_color, (const void*)DEFAULT_BASE_COLOR, 3 * sizeof(float));
|
||||
::memcpy((void*)m_drag_color, (const void*)DEFAULT_DRAG_COLOR, 3 * sizeof(float));
|
||||
|
@ -152,18 +234,21 @@ void GLGizmoBase::set_highlight_color(const float* color)
|
|||
::memcpy((void*)m_highlight_color, (const void*)color, 3 * sizeof(float));
|
||||
}
|
||||
|
||||
void GLGizmoBase::start_dragging()
|
||||
void GLGizmoBase::start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
m_dragging = true;
|
||||
|
||||
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
||||
{
|
||||
m_grabbers[i].dragging = (m_hover_id == i);
|
||||
}
|
||||
|
||||
on_start_dragging();
|
||||
on_start_dragging(box);
|
||||
}
|
||||
|
||||
void GLGizmoBase::stop_dragging()
|
||||
{
|
||||
m_dragging = false;
|
||||
set_tooltip("");
|
||||
|
||||
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
||||
|
@ -199,8 +284,11 @@ void GLGizmoBase::render_grabbers() const
|
|||
|
||||
void GLGizmoBase::render_grabbers_for_picking() const
|
||||
{
|
||||
for (int i = 0; i < (int)m_grabbers.size(); ++i)
|
||||
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i)
|
||||
{
|
||||
m_grabbers[i].color[0] = 1.0f;
|
||||
m_grabbers[i].color[1] = 1.0f;
|
||||
m_grabbers[i].color[2] = picking_color_component(i);
|
||||
m_grabbers[i].render_for_picking();
|
||||
}
|
||||
}
|
||||
|
@ -234,7 +322,6 @@ GLGizmoRotate::GLGizmoRotate(GLCanvas3D& parent, GLGizmoRotate::Axis axis)
|
|||
, m_angle(0.0)
|
||||
, m_center(0.0, 0.0, 0.0)
|
||||
, m_radius(0.0f)
|
||||
, m_keep_initial_values(false)
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -252,6 +339,12 @@ bool GLGizmoRotate::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
m_center = box.center();
|
||||
m_radius = Offset + box.radius();
|
||||
}
|
||||
|
||||
void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
Vec2d mouse_pos = to_2d(mouse_position_in_local_plane(mouse_ray));
|
||||
|
@ -293,18 +386,16 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray)
|
|||
|
||||
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
if (m_grabbers[0].dragging)
|
||||
if (m_dragging)
|
||||
set_tooltip(format(m_angle * 180.0f / (float)PI, 4));
|
||||
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
|
||||
if (!m_keep_initial_values)
|
||||
else
|
||||
{
|
||||
m_center = box.center();
|
||||
m_radius = Offset + box.radius();
|
||||
m_keep_initial_values = true;
|
||||
}
|
||||
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
|
||||
::glPushMatrix();
|
||||
transform_to_local();
|
||||
|
||||
|
@ -335,12 +426,8 @@ void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const
|
|||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
::glPushMatrix();
|
||||
|
||||
transform_to_local();
|
||||
|
||||
m_grabbers[0].color[0] = 1.0f;
|
||||
m_grabbers[0].color[1] = 1.0f;
|
||||
m_grabbers[0].color[2] = picking_color_component(0);
|
||||
|
||||
render_grabbers_for_picking();
|
||||
|
||||
::glPopMatrix();
|
||||
|
@ -512,23 +599,29 @@ Vec3d GLGizmoRotate::mouse_position_in_local_plane(const Linef3& mouse_ray) cons
|
|||
|
||||
GLGizmoRotate3D::GLGizmoRotate3D(GLCanvas3D& parent)
|
||||
: GLGizmoBase(parent)
|
||||
, m_x(parent, GLGizmoRotate::X)
|
||||
, m_y(parent, GLGizmoRotate::Y)
|
||||
, m_z(parent, GLGizmoRotate::Z)
|
||||
{
|
||||
m_x.set_group_id(0);
|
||||
m_y.set_group_id(1);
|
||||
m_z.set_group_id(2);
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::X);
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::Y);
|
||||
m_gizmos.emplace_back(parent, GLGizmoRotate::Z);
|
||||
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
{
|
||||
m_gizmos[i].set_group_id(i);
|
||||
}
|
||||
}
|
||||
|
||||
bool GLGizmoRotate3D::on_init()
|
||||
{
|
||||
if (!m_x.init() || !m_y.init() || !m_z.init())
|
||||
return false;
|
||||
for (GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
if (!g.init())
|
||||
return false;
|
||||
}
|
||||
|
||||
m_x.set_highlight_color(RED);
|
||||
m_y.set_highlight_color(GREEN);
|
||||
m_z.set_highlight_color(BLUE);
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
{
|
||||
m_gizmos[i].set_highlight_color(AXES_COLOR[i]);
|
||||
}
|
||||
|
||||
std::string path = resources_dir() + "/icons/overlay/";
|
||||
|
||||
|
@ -547,68 +640,28 @@ bool GLGizmoRotate3D::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_start_dragging()
|
||||
void GLGizmoRotate3D::on_start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
switch (m_hover_id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_x.start_dragging();
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_y.start_dragging();
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
m_z.start_dragging();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((0 <= m_hover_id) && (m_hover_id < 3))
|
||||
m_gizmos[m_hover_id].start_dragging(box);
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_stop_dragging()
|
||||
{
|
||||
switch (m_hover_id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
m_x.stop_dragging();
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
m_y.stop_dragging();
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
m_z.stop_dragging();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ((0 <= m_hover_id) && (m_hover_id < 3))
|
||||
m_gizmos[m_hover_id].stop_dragging();
|
||||
}
|
||||
|
||||
void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const
|
||||
{
|
||||
if ((m_hover_id == -1) || (m_hover_id == 0))
|
||||
m_x.render(box);
|
||||
m_gizmos[X].render(box);
|
||||
|
||||
if ((m_hover_id == -1) || (m_hover_id == 1))
|
||||
m_y.render(box);
|
||||
m_gizmos[Y].render(box);
|
||||
|
||||
if ((m_hover_id == -1) || (m_hover_id == 2))
|
||||
m_z.render(box);
|
||||
m_gizmos[Z].render(box);
|
||||
}
|
||||
|
||||
const float GLGizmoScale3D::Offset = 5.0f;
|
||||
|
@ -655,13 +708,13 @@ bool GLGizmoScale3D::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoScale3D::on_start_dragging()
|
||||
void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
if (m_hover_id != -1)
|
||||
{
|
||||
m_starting_drag_position = m_grabbers[m_hover_id].center;
|
||||
m_show_starting_box = true;
|
||||
m_starting_box = m_box;
|
||||
m_starting_box = box;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -703,20 +756,20 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
|||
// x axis
|
||||
m_grabbers[0].center = Vec3d(m_box.min(0), center(1), center(2));
|
||||
m_grabbers[1].center = Vec3d(m_box.max(0), center(1), center(2));
|
||||
::memcpy((void*)m_grabbers[0].color, (const void*)RED, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[1].color, (const void*)RED, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[0].color, (const void*)&AXES_COLOR[0], 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[1].color, (const void*)&AXES_COLOR[0], 3 * sizeof(float));
|
||||
|
||||
// y axis
|
||||
m_grabbers[2].center = Vec3d(center(0), m_box.min(1), center(2));
|
||||
m_grabbers[3].center = Vec3d(center(0), m_box.max(1), center(2));
|
||||
::memcpy((void*)m_grabbers[2].color, (const void*)GREEN, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[3].color, (const void*)GREEN, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[2].color, (const void*)&AXES_COLOR[1], 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[3].color, (const void*)&AXES_COLOR[1], 3 * sizeof(float));
|
||||
|
||||
// z axis
|
||||
m_grabbers[4].center = Vec3d(center(0), center(1), m_box.min(2));
|
||||
m_grabbers[5].center = Vec3d(center(0), center(1), m_box.max(2));
|
||||
::memcpy((void*)m_grabbers[4].color, (const void*)BLUE, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[5].color, (const void*)BLUE, 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[4].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float));
|
||||
::memcpy((void*)m_grabbers[5].color, (const void*)&AXES_COLOR[2], 3 * sizeof(float));
|
||||
|
||||
// uniform
|
||||
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), m_box.min(2));
|
||||
|
@ -735,6 +788,13 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
|||
// draw box
|
||||
::glColor3fv(m_base_color);
|
||||
render_box(m_box);
|
||||
// draw connections
|
||||
::glColor3fv(m_grabbers[0].color);
|
||||
render_grabbers_connection(0, 1);
|
||||
::glColor3fv(m_grabbers[2].color);
|
||||
render_grabbers_connection(2, 3);
|
||||
::glColor3fv(m_grabbers[4].color);
|
||||
render_grabbers_connection(4, 5);
|
||||
// draw grabbers
|
||||
render_grabbers();
|
||||
}
|
||||
|
@ -815,13 +875,6 @@ void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
|
|||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
|
||||
for (unsigned int i = 0; i < (unsigned int)m_grabbers.size(); ++i)
|
||||
{
|
||||
m_grabbers[i].color[0] = 1.0f;
|
||||
m_grabbers[i].color[1] = 1.0f;
|
||||
m_grabbers[i].color[2] = picking_color_component(i);
|
||||
}
|
||||
|
||||
render_grabbers_for_picking();
|
||||
}
|
||||
|
||||
|
@ -911,77 +964,24 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
|
|||
|
||||
Vec3d starting_vec_dir = starting_vec.normalized();
|
||||
Vec3d mouse_dir = mouse_ray.unit_vector();
|
||||
unsigned int plane_id = preferred_plane_id;
|
||||
|
||||
// 1st try to see if the mouse direction is close enough to the preferred plane normal
|
||||
double dot_to_normal = 0.0;
|
||||
unsigned int plane_id = select_best_plane(mouse_dir, preferred_plane_id);
|
||||
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
||||
switch (plane_id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitZ()));
|
||||
ratio = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, center)) / len_starting_vec;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
dot_to_normal = std::abs(mouse_dir.dot(-Vec3d::UnitY()));
|
||||
ratio = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, center)) / len_starting_vec;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
dot_to_normal = std::abs(mouse_dir.dot(Vec3d::UnitX()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (dot_to_normal < 0.1)
|
||||
{
|
||||
// if not, select the plane who's normal is closest to the mouse direction
|
||||
|
||||
typedef std::map<double, unsigned int> ProjsMap;
|
||||
ProjsMap projs_map;
|
||||
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitZ())), 0)); // plane xy
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(-Vec3d::UnitY())), 1)); // plane xz
|
||||
projs_map.insert(ProjsMap::value_type(std::abs(mouse_dir.dot(Vec3d::UnitX())), 2)); // plane yz
|
||||
plane_id = projs_map.rbegin()->second;
|
||||
}
|
||||
|
||||
switch (plane_id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XY and passing through the given center
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
||||
|
||||
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
||||
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), mouse_pos_2d(1), 0.0)) / len_starting_vec;
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane XZ and passing through the given center
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-0.5 * (double)PI, Vec3d::UnitX()));
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
||||
|
||||
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
||||
ratio = starting_vec_dir.dot(Vec3d(mouse_pos_2d(0), 0.0, mouse_pos_2d(1))) / len_starting_vec;
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
// calculates the intersection of the mouse ray with the plane parallel to plane YZ and passing through the given center
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-0.5f * (double)PI, Vec3d::UnitY()));
|
||||
m.translate(-center);
|
||||
Vec2d mouse_pos_2d = to_2d(transform(mouse_ray, m).intersect_plane(0.0));
|
||||
|
||||
// ratio is given by the projection of the calculated intersection on the starting vector divided by the starting vector length
|
||||
ratio = starting_vec_dir.dot(Vec3d(0.0, mouse_pos_2d(1), -mouse_pos_2d(0))) / len_starting_vec;
|
||||
ratio = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, center)) / len_starting_vec;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -992,7 +992,8 @@ double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3&
|
|||
|
||||
GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent)
|
||||
: GLGizmoBase(parent)
|
||||
, m_normal(0.0, 0.0, 0.0)
|
||||
, m_normal(Vec3d::Zero())
|
||||
, m_starting_center(Vec3d::Zero())
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -1015,10 +1016,13 @@ bool GLGizmoFlatten::on_init()
|
|||
return true;
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_start_dragging()
|
||||
void GLGizmoFlatten::on_start_dragging(const BoundingBoxf3& box)
|
||||
{
|
||||
if (m_hover_id != -1)
|
||||
{
|
||||
m_normal = m_planes[m_hover_id].normal;
|
||||
m_starting_center = box.center();
|
||||
}
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
||||
|
@ -1026,13 +1030,10 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
|||
// the dragged_offset is a vector measuring where was the object moved
|
||||
// with the gizmo being on. This is reset in set_flattening_data and
|
||||
// does not work correctly when there are multiple copies.
|
||||
if (!m_center) // this is the first bounding box that we see
|
||||
m_center.reset(new Vec3d(box.center()));
|
||||
Vec3d dragged_offset(Vec3d::Zero());
|
||||
if (m_dragging)
|
||||
dragged_offset = box.center() - m_starting_center;
|
||||
|
||||
Vec3d dragged_offset = box.center() - *m_center;
|
||||
|
||||
bool blending_was_enabled = ::glIsEnabled(GL_BLEND);
|
||||
bool depth_test_was_enabled = ::glIsEnabled(GL_DEPTH_TEST);
|
||||
::glEnable(GL_BLEND);
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
|
||||
|
@ -1054,20 +1055,15 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
|
|||
}
|
||||
}
|
||||
|
||||
if (!blending_was_enabled)
|
||||
::glDisable(GL_BLEND);
|
||||
if (!depth_test_was_enabled)
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
::glDisable(GL_BLEND);
|
||||
}
|
||||
|
||||
void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
::glDisable(GL_DEPTH_TEST);
|
||||
::glEnable(GL_DEPTH_TEST);
|
||||
|
||||
for (unsigned int i = 0; i < m_planes.size(); ++i)
|
||||
{
|
||||
// FIXME: the color assignement will fail if the planes count is greater than 254
|
||||
// use the other color components in that case !!
|
||||
::glColor3f(1.0f, 1.0f, picking_color_component(i));
|
||||
for (const Vec2d& offset : m_instances_positions) {
|
||||
::glPushMatrix();
|
||||
|
@ -1083,7 +1079,6 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
|
|||
|
||||
void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
|
||||
{
|
||||
m_center.release(); // object is not being dragged (this would not be called otherwise) - we must forget about the bounding box position...
|
||||
m_model_object = model_object;
|
||||
|
||||
// ...and save the updated positions of the object instances:
|
||||
|
@ -1245,9 +1240,9 @@ void GLGizmoFlatten::update_planes()
|
|||
polygon = transform(polygon, m);
|
||||
}
|
||||
|
||||
// We'll sort the planes by area and only keep the 255 largest ones (because of the picking pass limitations):
|
||||
// We'll sort the planes by area and only keep the 254 largest ones (because of the picking pass limitations):
|
||||
std::sort(m_planes.rbegin(), m_planes.rend(), [](const PlaneData& a, const PlaneData& b) { return a.area < b.area; });
|
||||
m_planes.resize(std::min((int)m_planes.size(), 255));
|
||||
m_planes.resize(std::min((int)m_planes.size(), 254));
|
||||
|
||||
// Planes are finished - let's save what we calculated it from:
|
||||
m_source_data.bounding_boxes.clear();
|
||||
|
@ -1285,11 +1280,9 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
|
|||
}
|
||||
|
||||
Vec3d GLGizmoFlatten::get_flattening_normal() const {
|
||||
Transform3d m = Transform3d::Identity();
|
||||
m.rotate(Eigen::AngleAxisd(-m_model_object->instances.front()->rotation, Vec3d::UnitZ()));
|
||||
Vec3d normal = m * m_normal;
|
||||
Vec3d normal = m_model_object->instances.front()->world_matrix(true).matrix().block(0, 0, 3, 3).inverse() * m_normal;
|
||||
m_normal = Vec3d::Zero();
|
||||
return normal;
|
||||
return normal.normalized();
|
||||
}
|
||||
|
||||
} // namespace GUI
|
||||
|
|
|
@ -57,6 +57,7 @@ protected:
|
|||
// textures are assumed to be square and all with the same size in pixels, no internal check is done
|
||||
GLTexture m_textures[Num_States];
|
||||
int m_hover_id;
|
||||
bool m_dragging;
|
||||
float m_base_color[3];
|
||||
float m_drag_color[3];
|
||||
float m_highlight_color[3];
|
||||
|
@ -82,10 +83,11 @@ public:
|
|||
|
||||
void set_highlight_color(const float* color);
|
||||
|
||||
void start_dragging();
|
||||
void start_dragging(const BoundingBoxf3& box);
|
||||
void stop_dragging();
|
||||
bool is_dragging() const { return m_dragging; }
|
||||
|
||||
void update(const Linef3& mouse_ray);
|
||||
void refresh() { on_refresh(); }
|
||||
|
||||
void render(const BoundingBoxf3& box) const { on_render(box); }
|
||||
void render_for_picking(const BoundingBoxf3& box) const { on_render_for_picking(box); }
|
||||
|
@ -94,10 +96,9 @@ protected:
|
|||
virtual bool on_init() = 0;
|
||||
virtual void on_set_state() {}
|
||||
virtual void on_set_hover_id() {}
|
||||
virtual void on_start_dragging() {}
|
||||
virtual void on_start_dragging(const BoundingBoxf3& box) {}
|
||||
virtual void on_stop_dragging() {}
|
||||
virtual void on_update(const Linef3& mouse_ray) = 0;
|
||||
virtual void on_refresh() {}
|
||||
virtual void on_render(const BoundingBoxf3& box) const = 0;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
|
||||
|
||||
|
@ -136,7 +137,6 @@ private:
|
|||
|
||||
mutable Vec3d m_center;
|
||||
mutable float m_radius;
|
||||
mutable bool m_keep_initial_values;
|
||||
|
||||
public:
|
||||
GLGizmoRotate(GLCanvas3D& parent, Axis axis);
|
||||
|
@ -146,9 +146,8 @@ public:
|
|||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_set_state() { m_keep_initial_values = (m_state == On) ? false : true; }
|
||||
virtual void on_start_dragging(const BoundingBoxf3& box);
|
||||
virtual void on_update(const Linef3& mouse_ray);
|
||||
virtual void on_refresh() { m_keep_initial_values = false; }
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
|
||||
|
@ -167,56 +166,52 @@ private:
|
|||
|
||||
class GLGizmoRotate3D : public GLGizmoBase
|
||||
{
|
||||
GLGizmoRotate m_x;
|
||||
GLGizmoRotate m_y;
|
||||
GLGizmoRotate m_z;
|
||||
std::vector<GLGizmoRotate> m_gizmos;
|
||||
|
||||
public:
|
||||
explicit GLGizmoRotate3D(GLCanvas3D& parent);
|
||||
|
||||
double get_angle_x() const { return m_x.get_angle(); }
|
||||
void set_angle_x(double angle) { m_x.set_angle(angle); }
|
||||
double get_angle_x() const { return m_gizmos[X].get_angle(); }
|
||||
void set_angle_x(double angle) { m_gizmos[X].set_angle(angle); }
|
||||
|
||||
double get_angle_y() const { return m_y.get_angle(); }
|
||||
void set_angle_y(double angle) { m_y.set_angle(angle); }
|
||||
double get_angle_y() const { return m_gizmos[Y].get_angle(); }
|
||||
void set_angle_y(double angle) { m_gizmos[Y].set_angle(angle); }
|
||||
|
||||
double get_angle_z() const { return m_z.get_angle(); }
|
||||
void set_angle_z(double angle) { m_z.set_angle(angle); }
|
||||
double get_angle_z() const { return m_gizmos[Z].get_angle(); }
|
||||
void set_angle_z(double angle) { m_gizmos[Z].set_angle(angle); }
|
||||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_set_state()
|
||||
{
|
||||
m_x.set_state(m_state);
|
||||
m_y.set_state(m_state);
|
||||
m_z.set_state(m_state);
|
||||
for (GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
g.set_state(m_state);
|
||||
}
|
||||
}
|
||||
virtual void on_set_hover_id()
|
||||
{
|
||||
m_x.set_hover_id(m_hover_id == 0 ? 0 : -1);
|
||||
m_y.set_hover_id(m_hover_id == 1 ? 0 : -1);
|
||||
m_z.set_hover_id(m_hover_id == 2 ? 0 : -1);
|
||||
for (unsigned int i = 0; i < 3; ++i)
|
||||
{
|
||||
m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1);
|
||||
}
|
||||
}
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_start_dragging(const BoundingBoxf3& box);
|
||||
virtual void on_stop_dragging();
|
||||
virtual void on_update(const Linef3& mouse_ray)
|
||||
{
|
||||
m_x.update(mouse_ray);
|
||||
m_y.update(mouse_ray);
|
||||
m_z.update(mouse_ray);
|
||||
}
|
||||
virtual void on_refresh()
|
||||
{
|
||||
m_x.refresh();
|
||||
m_y.refresh();
|
||||
m_z.refresh();
|
||||
for (GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
g.update(mouse_ray);
|
||||
}
|
||||
}
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const
|
||||
{
|
||||
m_x.render_for_picking(box);
|
||||
m_y.render_for_picking(box);
|
||||
m_z.render_for_picking(box);
|
||||
for (const GLGizmoRotate& g : m_gizmos)
|
||||
{
|
||||
g.render_for_picking(box);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -249,7 +244,7 @@ public:
|
|||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_start_dragging(const BoundingBoxf3& box);
|
||||
virtual void on_stop_dragging() { m_show_starting_box = false; }
|
||||
virtual void on_update(const Linef3& mouse_ray);
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
|
@ -291,7 +286,7 @@ private:
|
|||
|
||||
std::vector<PlaneData> m_planes;
|
||||
std::vector<Vec2d> m_instances_positions;
|
||||
mutable std::unique_ptr<Vec3d> m_center = nullptr;
|
||||
Vec3d m_starting_center;
|
||||
const ModelObject* m_model_object = nullptr;
|
||||
|
||||
void update_planes();
|
||||
|
@ -305,11 +300,12 @@ public:
|
|||
|
||||
protected:
|
||||
virtual bool on_init();
|
||||
virtual void on_start_dragging();
|
||||
virtual void on_start_dragging(const BoundingBoxf3& box);
|
||||
virtual void on_update(const Linef3& mouse_ray) {}
|
||||
virtual void on_render(const BoundingBoxf3& box) const;
|
||||
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
|
||||
virtual void on_set_state() {
|
||||
virtual void on_set_state()
|
||||
{
|
||||
if (m_state == On && is_plane_update_necessary())
|
||||
update_planes();
|
||||
}
|
||||
|
|
|
@ -1368,13 +1368,20 @@ void update_settings_value()
|
|||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
if (m_selected_object_id < 0 || m_objects->size() <= m_selected_object_id) {
|
||||
og->set_value("scale_x", 0);
|
||||
og->set_value("position_x", 0);
|
||||
og->set_value("position_y", 0);
|
||||
og->set_value("position_z", 0);
|
||||
og->set_value("scale_x", 0);
|
||||
og->set_value("scale_y", 0);
|
||||
og->set_value("scale_z", 0);
|
||||
og->set_value("rotation_x", 0);
|
||||
og->set_value("rotation_y", 0);
|
||||
og->set_value("rotation_z", 0);
|
||||
og->disable();
|
||||
return;
|
||||
}
|
||||
g_is_percent_scale = boost::any_cast<wxString>(og->get_value("scale_unit")) == _("%");
|
||||
update_position_values();
|
||||
update_scale_values();
|
||||
update_rotation_values();
|
||||
og->enable();
|
||||
|
@ -1534,50 +1541,94 @@ void update_extruder_in_config(const wxString& selection)
|
|||
}
|
||||
|
||||
void update_scale_values()
|
||||
{
|
||||
update_scale_values((*m_objects)[m_selected_object_id]->instance_bounding_box(0).size(),
|
||||
(*m_objects)[m_selected_object_id]->instances[0]->scaling_factor);
|
||||
}
|
||||
|
||||
void update_scale_values(const Vec3d& size, float scaling_factor)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
|
||||
auto size = (*m_objects)[m_selected_object_id]->instance_bounding_box(0).size();
|
||||
|
||||
if (g_is_percent_scale) {
|
||||
auto scale = scaling_factor * 100;
|
||||
auto scale = instance->scaling_factor * 100.0;
|
||||
og->set_value("scale_x", int(scale));
|
||||
og->set_value("scale_y", int(scale));
|
||||
og->set_value("scale_z", int(scale));
|
||||
}
|
||||
else {
|
||||
og->set_value("scale_x", int(size(0) + 0.5));
|
||||
og->set_value("scale_y", int(size(1) + 0.5));
|
||||
og->set_value("scale_z", int(size(2) + 0.5));
|
||||
og->set_value("scale_x", int(instance->scaling_factor * size(0) + 0.5));
|
||||
og->set_value("scale_y", int(instance->scaling_factor * size(1) + 0.5));
|
||||
og->set_value("scale_z", int(instance->scaling_factor * size(2) + 0.5));
|
||||
}
|
||||
}
|
||||
|
||||
void update_position_values()
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
|
||||
|
||||
og->set_value("position_x", int(instance->offset(0)));
|
||||
og->set_value("position_y", int(instance->offset(1)));
|
||||
og->set_value("position_z", 0);
|
||||
}
|
||||
|
||||
void update_position_values(const Vec3d& position)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
og->set_value("position_x", int(position(0)));
|
||||
og->set_value("position_y", int(position(1)));
|
||||
og->set_value("position_z", int(position(2)));
|
||||
}
|
||||
|
||||
void update_scale_values(double scaling_factor)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
// this is temporary
|
||||
// to be able to update the values as size
|
||||
// we need to store somewhere the original size
|
||||
// or have it passed as parameter
|
||||
if (!g_is_percent_scale)
|
||||
og->set_value("scale_unit", _("%"));
|
||||
|
||||
auto scale = scaling_factor * 100.0;
|
||||
og->set_value("scale_x", int(scale));
|
||||
og->set_value("scale_y", int(scale));
|
||||
og->set_value("scale_z", int(scale));
|
||||
}
|
||||
|
||||
void update_rotation_values()
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
auto instance = (*m_objects)[m_selected_object_id]->instances.front();
|
||||
og->set_value("rotation_x", 0);
|
||||
og->set_value("rotation_y", 0);
|
||||
|
||||
auto rotation_z = (*m_objects)[m_selected_object_id]->instances[0]->rotation;
|
||||
auto deg = int(Geometry::rad2deg(rotation_z));
|
||||
// if (deg > 180) deg -= 360;
|
||||
|
||||
og->set_value("rotation_z", deg);
|
||||
og->set_value("rotation_z", int(Geometry::rad2deg(instance->rotation)));
|
||||
}
|
||||
|
||||
void update_rotation_value(const double angle, const std::string& axis)
|
||||
void update_rotation_value(double angle, Axis axis)
|
||||
{
|
||||
auto og = get_optgroup(ogFrequentlyObjectSettings);
|
||||
|
||||
int deg = int(Geometry::rad2deg(angle));
|
||||
// if (deg>180) deg -= 360;
|
||||
|
||||
og->set_value("rotation_"+axis, deg);
|
||||
std::string axis_str;
|
||||
switch (axis)
|
||||
{
|
||||
case X:
|
||||
{
|
||||
axis_str = "rotation_x";
|
||||
break;
|
||||
}
|
||||
case Y:
|
||||
{
|
||||
axis_str = "rotation_y";
|
||||
break;
|
||||
}
|
||||
case Z:
|
||||
{
|
||||
axis_str = "rotation_z";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
og->set_value(axis_str, int(Geometry::rad2deg(angle)));
|
||||
}
|
||||
|
||||
void set_uniform_scaling(const bool uniform_scale)
|
||||
|
|
|
@ -107,13 +107,16 @@ void update_settings_value();
|
|||
void set_extruder_column_hidden(bool hide);
|
||||
// update extruder in current config
|
||||
void update_extruder_in_config(const wxString& selection);
|
||||
// update position values displacements or "gizmos"
|
||||
void update_position_values();
|
||||
void update_position_values(const Vec3d& position);
|
||||
// update scale values after scale unit changing or "gizmos"
|
||||
void update_scale_values();
|
||||
void update_scale_values(const Vec3d& size, float scale);
|
||||
void update_scale_values(double scaling_factor);
|
||||
// update rotation values object selection changing
|
||||
void update_rotation_values();
|
||||
// update rotation value after "gizmos"
|
||||
void update_rotation_value(const double angle, const std::string& axis);
|
||||
void update_rotation_value(double angle, Axis axis);
|
||||
void set_uniform_scaling(const bool uniform_scale);
|
||||
|
||||
void on_begin_drag(wxDataViewEvent &event);
|
||||
|
|
|
@ -197,7 +197,7 @@ std::string Duet::get_upload_url(const std::string &filename) const
|
|||
{
|
||||
return (boost::format("%1%rr_upload?name=0:/gcodes/%2%&%3%")
|
||||
% get_base_url()
|
||||
% filename
|
||||
% Http::url_encode(filename)
|
||||
% timestamp_str()).str();
|
||||
}
|
||||
|
||||
|
@ -230,7 +230,7 @@ std::string Duet::timestamp_str() const
|
|||
auto tm = *std::localtime(&t);
|
||||
|
||||
char buffer[BUFFER_SIZE];
|
||||
std::strftime(buffer, BUFFER_SIZE, "time=%Y-%d-%mT%H:%M:%S", &tm);
|
||||
std::strftime(buffer, BUFFER_SIZE, "time=%Y-%m-%dT%H:%M:%S", &tm);
|
||||
|
||||
return std::string(buffer);
|
||||
}
|
||||
|
@ -248,9 +248,10 @@ wxString Duet::format_error(const std::string &body, const std::string &error, u
|
|||
bool Duet::start_print(wxString &msg, const std::string &filename) const
|
||||
{
|
||||
bool res = false;
|
||||
|
||||
auto url = (boost::format("%1%rr_gcode?gcode=M32%%20\"%2%\"")
|
||||
% get_base_url()
|
||||
% filename).str();
|
||||
% Http::url_encode(filename)).str();
|
||||
|
||||
auto http = Http::get(std::move(url));
|
||||
http.on_error([&](std::string body, std::string error, unsigned status) {
|
||||
|
@ -275,5 +276,4 @@ int Duet::get_err_code_from_body(const std::string &body) const
|
|||
return root.get<int>("err", 0);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -421,6 +421,21 @@ bool Http::ca_file_supported()
|
|||
return res;
|
||||
}
|
||||
|
||||
std::string Http::url_encode(const std::string &str)
|
||||
{
|
||||
::CURL *curl = ::curl_easy_init();
|
||||
if (curl == nullptr) {
|
||||
return str;
|
||||
}
|
||||
char *ce = ::curl_easy_escape(curl, str.c_str(), str.length());
|
||||
std::string encoded = std::string(ce);
|
||||
|
||||
::curl_free(ce);
|
||||
::curl_easy_cleanup(curl);
|
||||
|
||||
return encoded;
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &os, const Http::Progress &progress)
|
||||
{
|
||||
os << "Http::Progress("
|
||||
|
|
|
@ -98,6 +98,9 @@ public:
|
|||
|
||||
// Tells whether current backend supports seting up a CA file using ca_file()
|
||||
static bool ca_file_supported();
|
||||
|
||||
// converts the given string to an url_encoded_string
|
||||
static std::string url_encode(const std::string &str);
|
||||
private:
|
||||
Http(const std::string &url);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue