Merge branch 'dev_native' of https://github.com/prusa3d/Slic3r into dev_native

This commit is contained in:
bubnikv 2018-11-01 14:26:41 +01:00
commit 85597a4039
25 changed files with 235 additions and 2522 deletions

View File

@ -1329,11 +1329,18 @@ namespace Slic3r {
void _3MF_Importer::_apply_transform(ModelInstance& instance, const Transform3d& transform)
{
#if ENABLE_MODELVOLUME_TRANSFORM
Slic3r::Geometry::Transformation t(transform);
// invalid scale value, return
if (!t.get_scaling_factor().all())
return;
instance.set_transformation(t);
#else
// translation
Vec3d offset = transform.matrix().block(0, 3, 3, 1);
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
#if ENABLE_MIRROR
// mirror
// it is impossible to reconstruct the original mirroring factors from a matrix,
// we can only detect if the matrix contains a left handed reference system
@ -1347,7 +1354,6 @@ namespace Slic3r {
}
// scale
#endif // ENABLE_MIRROR
Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm());
// invalid scale value, return
@ -1364,9 +1370,8 @@ namespace Slic3r {
instance.set_offset(offset);
instance.set_scaling_factor(scale);
instance.set_rotation(rotation);
#if ENABLE_MIRROR
instance.set_mirror(mirror);
#endif // ENABLE_MIRROR
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)
@ -1823,7 +1828,7 @@ namespace Slic3r {
stream << " </" << COMPONENTS_TAG << ">\n";
}
Transform3d t = instance->world_matrix();
Transform3d t = instance->get_matrix();
build_items.emplace_back(instance_id, t);
stream << " </" << OBJECT_TAG << ">\n";

View File

@ -32,9 +32,7 @@
// 2 : Added z component of offset
// Added x and y components of rotation
// Added x, y and z components of scale
#if ENABLE_MIRROR
// Added x, y and z components of mirror
#endif // ENABLE_MIRROR
const unsigned int VERSION_AMF = 2;
const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version";
@ -132,24 +130,18 @@ struct AMFParserContext
NODE_TYPE_SCALEX, // amf/constellation/instance/scalex
NODE_TYPE_SCALEY, // amf/constellation/instance/scaley
NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez
#if ENABLE_MIRROR
NODE_TYPE_MIRRORX, // amf/constellation/instance/mirrorx
NODE_TYPE_MIRRORY, // amf/constellation/instance/mirrory
NODE_TYPE_MIRRORZ, // amf/constellation/instance/mirrorz
#endif // ENABLE_MIRROR
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
};
struct Instance {
#if ENABLE_MIRROR
Instance()
: deltax_set(false), deltay_set(false), deltaz_set(false)
, rx_set(false), ry_set(false), rz_set(false)
, scalex_set(false), scaley_set(false), scalez_set(false)
, mirrorx_set(false), mirrory_set(false), mirrorz_set(false) {}
#else
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scalex_set(false), scaley_set(false), scalez_set(false) {}
#endif // ENABLE_MIRROR
// Shift in the X axis.
float deltax;
bool deltax_set;
@ -175,7 +167,6 @@ struct AMFParserContext
bool scaley_set;
float scalez;
bool scalez_set;
#if ENABLE_MIRROR
// Mirroring factors
float mirrorx;
bool mirrorx_set;
@ -183,7 +174,6 @@ struct AMFParserContext
bool mirrory_set;
float mirrorz;
bool mirrorz_set;
#endif // ENABLE_MIRROR
};
struct Object {
@ -314,14 +304,12 @@ void AMFParserContext::startElement(const char *name, const char **atts)
node_type_new = NODE_TYPE_SCALEZ;
else if (strcmp(name, "scale") == 0)
node_type_new = NODE_TYPE_SCALE;
#if ENABLE_MIRROR
else if (strcmp(name, "mirrorx") == 0)
node_type_new = NODE_TYPE_MIRRORX;
else if (strcmp(name, "mirrory") == 0)
node_type_new = NODE_TYPE_MIRRORY;
else if (strcmp(name, "mirrorz") == 0)
node_type_new = NODE_TYPE_MIRRORZ;
#endif // ENABLE_MIRROR
}
break;
case 4:
@ -387,14 +375,10 @@ void AMFParserContext::characters(const XML_Char *s, int len)
m_path.back() == NODE_TYPE_SCALEX ||
m_path.back() == NODE_TYPE_SCALEY ||
m_path.back() == NODE_TYPE_SCALEZ ||
#if ENABLE_MIRROR
m_path.back() == NODE_TYPE_SCALE ||
m_path.back() == NODE_TYPE_MIRRORX ||
m_path.back() == NODE_TYPE_MIRRORY ||
m_path.back() == NODE_TYPE_MIRRORZ)
#else
m_path.back() == NODE_TYPE_SCALE)
#endif // ENABLE_MIRROR
m_value[0].append(s, len);
break;
case 6:
@ -486,7 +470,6 @@ void AMFParserContext::endElement(const char * /* name */)
m_instance->scalez_set = true;
m_value[0].clear();
break;
#if ENABLE_MIRROR
case NODE_TYPE_MIRRORX:
assert(m_instance);
m_instance->mirrorx = float(atof(m_value[0].c_str()));
@ -505,7 +488,6 @@ void AMFParserContext::endElement(const char * /* name */)
m_instance->mirrorz_set = true;
m_value[0].clear();
break;
#endif // ENABLE_MIRROR
// Object vertices:
case NODE_TYPE_VERTEX:
@ -665,9 +647,7 @@ void AMFParserContext::endDocument()
mi->set_offset(Vec3d(instance.deltax_set ? (double)instance.deltax : 0.0, instance.deltay_set ? (double)instance.deltay : 0.0, instance.deltaz_set ? (double)instance.deltaz : 0.0));
mi->set_rotation(Vec3d(instance.rx_set ? (double)instance.rx : 0.0, instance.ry_set ? (double)instance.ry : 0.0, instance.rz_set ? (double)instance.rz : 0.0));
mi->set_scaling_factor(Vec3d(instance.scalex_set ? (double)instance.scalex : 1.0, instance.scaley_set ? (double)instance.scaley : 1.0, instance.scalez_set ? (double)instance.scalez : 1.0));
#if ENABLE_MIRROR
mi->set_mirror(Vec3d(instance.mirrorx_set ? (double)instance.mirrorx : 1.0, instance.mirrory_set ? (double)instance.mirrory : 1.0, instance.mirrorz_set ? (double)instance.mirrorz : 1.0));
#endif // ENABLE_MIRROR
}
}
}
@ -987,11 +967,9 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
" <scalex>%lf</scalex>\n"
" <scaley>%lf</scaley>\n"
" <scalez>%lf</scalez>\n"
#if ENABLE_MIRROR
" <mirrorx>%lf</mirrorx>\n"
" <mirrory>%lf</mirrory>\n"
" <mirrorz>%lf</mirrorz>\n"
#endif // ENABLE_MIRROR
" </instance>\n",
object_id,
instance->get_offset(X),
@ -1002,14 +980,10 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
instance->get_rotation(Z),
instance->get_scaling_factor(X),
instance->get_scaling_factor(Y),
#if ENABLE_MIRROR
instance->get_scaling_factor(Z),
instance->get_mirror(X),
instance->get_mirror(Y),
instance->get_mirror(Z));
#else
instance->get_scaling_factor(Z));
#endif // ENABLE_MIRROR
//FIXME missing instance->scaling_factor
instances.append(buf);

View File

@ -1161,11 +1161,7 @@ MedialAxis::retrieve_endpoint(const VD::cell_type* cell) const
}
}
#if ENABLE_MIRROR
void assemble_transform(Transform3d& transform, const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale, const Vec3d& mirror)
#else
void assemble_transform(Transform3d& transform, const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale)
#endif // ENABLE_MIRROR
{
transform = Transform3d::Identity();
transform.translate(translation);
@ -1173,23 +1169,13 @@ void assemble_transform(Transform3d& transform, const Vec3d& translation, const
transform.rotate(Eigen::AngleAxisd(rotation(1), Vec3d::UnitY()));
transform.rotate(Eigen::AngleAxisd(rotation(0), Vec3d::UnitX()));
transform.scale(scale);
#if ENABLE_MIRROR
transform.scale(mirror);
#endif // ENABLE_MIRROR
}
#if ENABLE_MIRROR
Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale, const Vec3d& mirror)
#else
Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale)
#endif // ENABLE_MIRROR
{
Transform3d transform;
#if ENABLE_MIRROR
assemble_transform(transform, translation, rotation, scale, mirror);
#else
assemble_transform(transform, translation, rotation, scale);
#endif // ENABLE_MIRROR
return transform;
}
@ -1232,13 +1218,10 @@ Transformation::Flags::Flags()
: dont_translate(true)
, dont_rotate(true)
, dont_scale(true)
#if ENABLE_MIRROR
, dont_mirror(true)
#endif // ENABLE_MIRROR
{
}
#if ENABLE_MIRROR
bool Transformation::Flags::needs_update(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
{
return (this->dont_translate != dont_translate) || (this->dont_rotate != dont_rotate) || (this->dont_scale != dont_scale) || (this->dont_mirror != dont_mirror);
@ -1251,32 +1234,22 @@ void Transformation::Flags::set(bool dont_translate, bool dont_rotate, bool dont
this->dont_scale = dont_scale;
this->dont_mirror = dont_mirror;
}
#else
bool Transformation::Flags::needs_update(bool dont_translate, bool dont_rotate, bool dont_scale) const
{
return (this->dont_translate != dont_translate) || (this->dont_rotate != dont_rotate) || (this->dont_scale != dont_scale);
}
void Transformation::Flags::set(bool dont_translate, bool dont_rotate, bool dont_scale)
{
this->dont_translate = dont_translate;
this->dont_rotate = dont_rotate;
this->dont_scale = dont_scale;
}
#endif // ENABLE_MIRROR
Transformation::Transformation()
: m_offset(Vec3d::Zero())
, m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones())
#if ENABLE_MIRROR
, m_mirror(Vec3d::Ones())
#endif // ENABLE_MIRROR
, m_matrix(Transform3d::Identity())
, m_dirty(false)
{
}
Transformation::Transformation(const Transform3d& transform)
{
set_from_transform(transform);
}
void Transformation::set_offset(const Vec3d& offset)
{
set_offset(X, offset(0));
@ -1304,7 +1277,7 @@ void Transformation::set_rotation(Axis axis, double rotation)
{
rotation = angle_to_0_2PI(rotation);
if (m_rotation(axis) = rotation)
if (m_rotation(axis) != rotation)
{
m_rotation(axis) = rotation;
m_dirty = true;
@ -1349,39 +1322,67 @@ void Transformation::set_mirror(Axis axis, double mirror)
}
}
#if ENABLE_MIRROR
const Transform3d& Transformation::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
#else
const Transform3d& Transformation::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
#endif // ENABLE_MIRROR
void Transformation::set_from_transform(const Transform3d& transform)
{
#if ENABLE_MIRROR
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale, dont_mirror))
#else
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale))
#endif // ENABLE_MIRROR
{
Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset;
Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation;
Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor;
#if ENABLE_MIRROR
Vec3d mirror = dont_mirror ? Vec3d::Ones() : m_mirror;
m_matrix = Geometry::assemble_transform(translation, rotation, scale, mirror);
#else
m_matrix = Geometry::assemble_transform(translation, rotation, scale);
#endif // ENABLE_MIRROR
// offset
set_offset(transform.matrix().block(0, 3, 3, 1));
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
// mirror
// it is impossible to reconstruct the original mirroring factors from a matrix,
// we can only detect if the matrix contains a left handed reference system
// in which case we reorient it back to right handed by mirroring the x axis
Vec3d mirror = Vec3d::Ones();
if (m3x3.col(0).dot(m3x3.col(1).cross(m3x3.col(2))) < 0.0)
{
mirror(0) = -1.0;
// remove mirror
m3x3.col(0) *= -1.0;
}
set_mirror(mirror);
// scale
set_scaling_factor(Vec3d(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm()));
// remove scale
m3x3.col(0).normalize();
m3x3.col(1).normalize();
m3x3.col(2).normalize();
// rotation
set_rotation(extract_euler_angles(m3x3));
// forces matrix recalculation matrix
m_matrix = get_matrix();
// // debug check
// if (!m_matrix.isApprox(transform))
// std::cout << "something went wrong in extracting data from matrix" << std::endl;
}
const Transform3d& Transformation::get_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
{
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale, dont_mirror))
{
m_matrix = Geometry::assemble_transform(
dont_translate ? Vec3d::Zero() : m_offset,
dont_rotate ? Vec3d::Zero() : m_rotation,
dont_scale ? Vec3d::Ones() : m_scaling_factor,
dont_mirror ? Vec3d::Ones() : m_mirror
);
#if ENABLE_MIRROR
m_flags.set(dont_translate, dont_rotate, dont_scale, dont_mirror);
#else
m_flags.set(dont_translate, dont_rotate, dont_scale);
#endif // ENABLE_MIRROR
m_dirty = false;
}
return m_matrix;
}
Transformation Transformation::operator * (const Transformation& other) const
{
return Transformation(get_matrix() * other.get_matrix());
}
#endif // ENABLE_MODELVOLUME_TRANSFORM
} }

View File

@ -172,7 +172,6 @@ class MedialAxis {
};
// Sets the given transform by assembling the given transformations in the following order:
#if ENABLE_MIRROR
// 1) mirror
// 2) scale
// 3) rotate X
@ -180,17 +179,8 @@ class MedialAxis {
// 5) rotate Z
// 6) translate
void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones(), const Vec3d& mirror = Vec3d::Ones());
#else
// 1) scale
// 2) rotate X
// 3) rotate Y
// 4) rotate Z
// 5) translate
void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones());
#endif // ENABLE_MIRROR
// Returns the transform obtained by assembling the given transformations in the following order:
#if ENABLE_MIRROR
// 1) mirror
// 2) scale
// 3) rotate X
@ -198,14 +188,6 @@ void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d
// 5) rotate Z
// 6) translate
Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones(), const Vec3d& mirror = Vec3d::Ones());
#else
// 1) scale
// 2) rotate X
// 3) rotate Y
// 4) rotate Z
// 5) translate
Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones());
#endif // ENABLE_MIRROR
// Returns the euler angles extracted from the given rotation matrix
// Warning -> The matrix should not contain any scale or shear !!!
@ -223,34 +205,26 @@ class Transformation
bool dont_translate;
bool dont_rotate;
bool dont_scale;
#if ENABLE_MIRROR
bool dont_mirror;
#endif // ENABLE_MIRROR
Flags();
#if ENABLE_MIRROR
bool needs_update(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const;
void set(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror);
#else
bool needs_update(bool dont_translate, bool dont_rotate, bool dont_scale) const;
void set(bool dont_translate, bool dont_rotate, bool dont_scale);
#endif // ENABLE_MIRROR
};
Vec3d m_offset; // In unscaled coordinates
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
Vec3d m_scaling_factor; // Scaling factors along the three axes
#if ENABLE_MIRROR
Vec3d m_mirror; // Mirroring along the three axes
#endif // ENABLE_MIRROR
mutable Transform3d m_matrix;
mutable Transform3d m_matrix;
mutable Flags m_flags;
mutable bool m_dirty;
public:
Transformation();
explicit Transformation(const Transform3d& transform);
const Vec3d& get_offset() const { return m_offset; }
double get_offset(Axis axis) const { return m_offset(axis); }
@ -267,7 +241,6 @@ public:
Vec3d get_scaling_factor() const { return m_scaling_factor; }
double get_scaling_factor(Axis axis) const { return m_scaling_factor(axis); }
#if ENABLE_MIRROR
void set_scaling_factor(const Vec3d& scaling_factor);
void set_scaling_factor(Axis axis, double scaling_factor);
@ -277,13 +250,11 @@ public:
void set_mirror(const Vec3d& mirror);
void set_mirror(Axis axis, double mirror);
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
#else
void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; }
void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; }
void set_from_transform(const Transform3d& transform);
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const;
#endif // ENABLE_MIRROR
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
Transformation operator * (const Transformation& other) const;
};
#endif // ENABLE_MODELVOLUME_TRANSFORM

View File

@ -693,23 +693,12 @@ void ModelObject::center_around_origin()
if (v->is_model_part())
bb.merge(v->mesh.bounding_box());
#if ENABLE_EXTENDED_SELECTION
// Shift is the vector from the center of the bounding box to the origin
Vec3d shift = -bb.center();
#else
// 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);
#endif // ENABLE_EXTENDED_SELECTION
this->translate(shift);
this->origin_translation += shift;
#if !ENABLE_EXTENDED_SELECTION
// set z to zero, translation in z has already been done within the mesh
shift(2) = 0.0;
#endif // !ENABLE_EXTENDED_SELECTION
if (!this->instances.empty()) {
for (ModelInstance *i : this->instances) {
i->set_offset(i->get_offset() - shift);
@ -738,7 +727,7 @@ void ModelObject::translate_instance(size_t instance_idx, const Vec3d& vector)
invalidate_bounding_box();
}
void ModelObject::translate(coordf_t x, coordf_t y, coordf_t z)
void ModelObject::translate(double x, double y, double z)
{
for (ModelVolume *v : this->volumes)
{
@ -929,7 +918,7 @@ double ModelObject::get_instance_min_z(size_t instance_idx) const
double min_z = DBL_MAX;
ModelInstance* inst = instances[instance_idx];
const Transform3d& m = inst->world_matrix(true);
const Transform3d& m = inst->get_matrix(true);
for (ModelVolume *v : volumes)
{
@ -956,7 +945,7 @@ unsigned int ModelObject::check_instances_print_volume_state(const BoundingBoxf3
unsigned int inside_outside = 0;
for (const ModelVolume *vol : this->volumes)
if (vol->is_model_part()) {
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(model_instance->world_matrix());
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(model_instance->get_matrix());
if (print_volume.contains(bb))
inside_outside |= INSIDE;
else if (print_volume.intersects(bb))
@ -1053,11 +1042,6 @@ const TriangleMesh& ModelVolume::get_convex_hull() const
return m_convex_hull;
}
TriangleMesh& ModelVolume::get_convex_hull()
{
return m_convex_hull;
}
ModelVolume::Type ModelVolume::type_from_string(const std::string &s)
{
// Legacy support
@ -1124,6 +1108,17 @@ size_t ModelVolume::split(unsigned int max_extruders)
return idx;
}
void ModelVolume::translate(double x, double y, double z)
{
translate(Vec3d(x, y, z));
}
void ModelVolume::translate(const Vec3d& displacement)
{
mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
}
#if !ENABLE_MODELVOLUME_TRANSFORM
void ModelInstance::set_rotation(const Vec3d& rotation)
{
@ -1146,7 +1141,6 @@ void ModelInstance::set_rotation(Axis axis, double rotation)
m_rotation(axis) = rotation;
}
#if ENABLE_MIRROR
void ModelInstance::set_scaling_factor(const Vec3d& scaling_factor)
{
set_scaling_factor(X, scaling_factor(0));
@ -1176,23 +1170,18 @@ void ModelInstance::set_mirror(Axis axis, double mirror)
m_mirror(axis) = mirror;
}
#endif // ENABLE_MIRROR
#endif // !ENABLE_MODELVOLUME_TRANSFORM
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
{
mesh->transform(world_matrix(dont_translate).cast<float>());
mesh->transform(get_matrix(dont_translate).cast<float>());
}
BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const
{
// Rotate around mesh origin.
TriangleMesh copy(*mesh);
#if ENABLE_MIRROR
copy.transform(world_matrix(true, false, true, true).cast<float>());
#else
copy.transform(world_matrix(true, false, true).cast<float>());
#endif // ENABLE_MIRROR
copy.transform(get_matrix(true, false, true, true).cast<float>());
BoundingBoxf3 bbox = copy.bounding_box();
if (!empty(bbox)) {
@ -1229,12 +1218,12 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
{
return bbox.transformed(world_matrix(dont_translate));
return bbox.transformed(get_matrix(dont_translate));
}
Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
{
return world_matrix(dont_translate) * v;
return get_matrix(dont_translate) * v;
}
void ModelInstance::transform_polygon(Polygon* polygon) const
@ -1253,21 +1242,13 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
}
#if !ENABLE_MODELVOLUME_TRANSFORM
#if ENABLE_MIRROR
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
#else
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
#endif // ENABLE_MIRROR
{
Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset;
Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation;
Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor;
#if ENABLE_MIRROR
Vec3d mirror = dont_mirror ? Vec3d::Ones() : m_mirror;
return Geometry::assemble_transform(translation, rotation, scale, mirror);
#else
return Geometry::assemble_transform(translation, rotation, scale);
#endif // ENABLE_MIRROR
}
#endif // !ENABLE_MODELVOLUME_TRANSFORM

View File

@ -160,7 +160,7 @@ public:
void translate_instances(const Vec3d& vector);
void translate_instance(size_t instance_idx, const Vec3d& vector);
void translate(const Vec3d &vector) { this->translate(vector(0), vector(1), vector(2)); }
void translate(coordf_t x, coordf_t y, coordf_t z);
void translate(double x, double y, double z);
void scale(const Vec3d &versor);
void scale(const double s) { this->scale(Vec3d(s, s, s)); }
void rotate(float angle, const Axis &axis);
@ -210,13 +210,6 @@ class ModelVolume : public ModelBase
{
friend class ModelObject;
// The convex hull of this model's mesh.
TriangleMesh m_convex_hull;
#if ENABLE_MODELVOLUME_TRANSFORM
Geometry::Transformation m_transformation;
#endif // ENABLE_MODELVOLUME_TRANSFORM
public:
std::string name;
// The triangular model.
@ -253,18 +246,22 @@ public:
// Return the number of volumes created from this one.
// This is useful to assign different materials to different volumes of an object.
size_t split(unsigned int max_extruders);
void translate(double x, double y, double z);
void translate(const Vec3d& displacement);
ModelMaterial* assign_unique_material();
void calculate_convex_hull();
const TriangleMesh& get_convex_hull() const;
TriangleMesh& get_convex_hull();
// Helpers for loading / storing into AMF / 3MF files.
static Type type_from_string(const std::string &s);
static std::string type_to_string(const Type t);
#if ENABLE_MODELVOLUME_TRANSFORM
const Geometry::Transformation& get_transformation() const { return m_transformation; }
void set_transformation(const Geometry::Transformation& transformation) { m_transformation = transformation; }
const Vec3d& get_offset() const { return m_transformation.get_offset(); }
double get_offset(Axis axis) const { return m_transformation.get_offset(axis); }
@ -283,13 +280,13 @@ public:
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); }
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); }
#if ENABLE_MIRROR
const Vec3d& get_mirror() const { return m_transformation.get_mirror(); }
double get_mirror(Axis axis) const { return m_transformation.get_mirror(axis); }
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); }
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); }
#endif // ENABLE_MIRROR
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
#endif // ENABLE_MODELVOLUME_TRANSFORM
private:
@ -298,7 +295,12 @@ private:
// Is it an object to be printed, or a modifier volume?
Type m_type;
t_model_material_id m_material_id;
// The convex hull of this model's mesh.
TriangleMesh m_convex_hull;
#if ENABLE_MODELVOLUME_TRANSFORM
Geometry::Transformation m_transformation;
#endif // ENABLE_MODELVOLUME_TRANSFORM
ModelVolume(ModelObject *object, const TriangleMesh &mesh) : mesh(mesh), m_type(MODEL_PART), object(object)
{
if (mesh.stl.stats.number_of_facets > 1)
@ -347,9 +349,7 @@ private:
Vec3d m_offset; // in unscaled coordinates
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
Vec3d m_scaling_factor; // Scaling factors along the three axes
#if ENABLE_MIRROR
Vec3d m_mirror; // Mirroring along the three axes
#endif // ENABLE_MIRROR
#endif // ENABLE_MODELVOLUME_TRANSFORM
public:
@ -380,13 +380,11 @@ public:
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); }
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); }
#if ENABLE_MIRROR
const Vec3d& get_mirror() const { return m_transformation.get_mirror(); }
double get_mirror(Axis axis) const { return m_transformation.get_mirror(axis); }
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); }
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); }
#endif // ENABLE_MIRROR
#else
const Vec3d& get_offset() const { return m_offset; }
double get_offset(Axis axis) const { return m_offset(axis); }
@ -403,21 +401,14 @@ public:
Vec3d get_scaling_factor() const { return m_scaling_factor; }
double get_scaling_factor(Axis axis) const { return m_scaling_factor(axis); }
#if ENABLE_MIRROR
void set_scaling_factor(const Vec3d& scaling_factor);
void set_scaling_factor(Axis axis, double scaling_factor);
#else
void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; }
void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; }
#endif // ENABLE_MIRROR
#if ENABLE_MIRROR
const Vec3d& get_mirror() const { return m_mirror; }
double get_mirror(Axis axis) const { return m_mirror(axis); }
void set_mirror(const Vec3d& mirror);
void set_mirror(Axis axis, double mirror);
#endif // ENABLE_MIRROR
#endif // ENABLE_MODELVOLUME_TRANSFORM
// To be called on an external mesh
@ -432,17 +423,9 @@ public:
void transform_polygon(Polygon* polygon) const;
#if ENABLE_MODELVOLUME_TRANSFORM
#if ENABLE_MIRROR
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.world_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
#else
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const { return m_transformation.world_matrix(dont_translate, dont_rotate, dont_scale); }
#endif // ENABLE_MIRROR
#else
#if ENABLE_MIRROR
Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
#else
Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const;
#endif // ENABLE_MIRROR
Transform3d get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
#endif // ENABLE_MODELVOLUME_TRANSFORM
bool is_printable() const { return print_volume_state == PVS_Inside; }
@ -456,15 +439,9 @@ private:
ModelInstance(ModelObject *object, const ModelInstance &other) :
m_transformation(other.m_transformation), object(object), print_volume_state(PVS_Inside) {}
#else
#if ENABLE_MIRROR
ModelInstance(ModelObject *object) : m_offset(Vec3d::Zero()), m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_mirror(Vec3d::Ones()), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object, const ModelInstance &other) :
m_offset(other.m_offset), m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_mirror(other.m_mirror), object(object), print_volume_state(PVS_Inside) {}
#else
ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
ModelInstance(ModelObject *object, const ModelInstance &other) :
m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
#endif // ENABLE_MIRROR
#endif // ENABLE_MODELVOLUME_TRANSFORM
explicit ModelInstance(ModelInstance &rhs) = delete;

View File

@ -412,7 +412,7 @@ void Print::add_model_object(ModelObject* model_object, int idx)
// Set the transformation matrix without translation from the first instance.
if (! model_object->instances.empty()) {
// Trafo and bounding box, both in world coordinate system.
Transform3d trafo = model_object->instances.front()->world_matrix();
Transform3d trafo = model_object->instances.front()->get_matrix();
BoundingBoxf3 bbox = model_object->instance_bounding_box(0);
// Now shift the object up to align it with the print bed.
trafo.data()[14] -= bbox.min(2);
@ -695,7 +695,7 @@ static std::vector<PrintInstances> print_objects_from_model_object(const ModelOb
trafo.copies.assign(1, Point());
for (ModelInstance *model_instance : model_object.instances)
if (model_instance->is_printable()) {
trafo.trafo = model_instance->world_matrix();
trafo.trafo = model_instance->get_matrix();
// Set the Z axis of the transformation.
trafo.copies.front() = Point::new_scale(trafo.trafo.data()[12], trafo.trafo.data()[13]);
trafo.trafo.data()[12] = 0;

View File

@ -1,27 +1,24 @@
#ifndef _technologies_h_
#define _technologies_h_
//==============
//============
// debug techs
//==============
//============
// Shows camera target in the 3D scene
#define ENABLE_SHOW_CAMERA_TARGET 1
//==============
//=============
// 1.42.0 techs
//==============
//=============
#define ENABLE_1_42_0 1
// Add double click on gizmo grabbers to reset transformation components to their default value
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
// Uses a unique opengl context
#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0)
// New selections
#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0)
#define DISABLE_INSTANCES_SYNCH (1 && ENABLE_EXTENDED_SELECTION)
// Add mirror components along the three axes in ModelInstance and GLVolume
#define ENABLE_MIRROR (1 && ENABLE_1_42_0)
// Disable synchronization of unselected instances
#define DISABLE_INSTANCES_SYNCH (1 && ENABLE_1_42_0)
// Modified camera target behavior
#define ENABLE_MODIFIED_CAMERA_TARGET (1 && ENABLE_1_42_0)
// Add Geometry::Transformation class and use it into ModelInstance, ModelVolume and GLVolume

View File

@ -201,9 +201,7 @@ GLVolume::GLVolume(float r, float g, float b, float a)
: m_offset(Vec3d::Zero())
, m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones())
#if ENABLE_MIRROR
, m_mirror(Vec3d::Ones())
#endif // ENABLE_MIRROR
, m_world_matrix(Transform3f::Identity())
, m_world_matrix_dirty(true)
, m_transformed_bounding_box_dirty(true)
@ -211,10 +209,6 @@ GLVolume::GLVolume(float r, float g, float b, float a)
, m_transformed_convex_hull_bounding_box_dirty(true)
, m_convex_hull(nullptr)
, composite_id(-1)
#if !ENABLE_EXTENDED_SELECTION
, select_group_id(-1)
, drag_group_id(-1)
#endif // !ENABLE_EXTENDED_SELECTION
, extruder_id(0)
, selected(false)
, is_active(true)
@ -272,14 +266,11 @@ const Vec3d& GLVolume::get_rotation() const
void GLVolume::set_rotation(const Vec3d& rotation)
{
#if ENABLE_EXTENDED_SELECTION
static const double TWO_PI = 2.0 * (double)PI;
#endif // ENABLE_EXTENDED_SELECTION
if (m_rotation != rotation)
{
m_rotation = rotation;
#if ENABLE_EXTENDED_SELECTION
for (int i = 0; i < 3; ++i)
{
while (m_rotation(i) < 0.0)
@ -291,7 +282,6 @@ void GLVolume::set_rotation(const Vec3d& rotation)
m_rotation(i) -= TWO_PI;
}
}
#endif // ENABLE_EXTENDED_SELECTION
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
@ -314,12 +304,10 @@ void GLVolume::set_offset(const Vec3d& offset)
}
}
#if ENABLE_EXTENDED_SELECTION
const Vec3d& GLVolume::get_scaling_factor() const
{
return m_scaling_factor;
}
#endif // ENABLE_EXTENDED_SELECTION
void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
{
@ -332,7 +320,6 @@ void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
}
}
#if ENABLE_MIRROR
const Vec3d& GLVolume::get_mirror() const
{
return m_mirror;
@ -364,7 +351,6 @@ void GLVolume::set_mirror(Axis axis, double mirror)
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // ENABLE_MIRROR
#endif // !ENABLE_MODELVOLUME_TRANSFORM
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
@ -372,36 +358,12 @@ void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
m_convex_hull = &convex_hull;
}
#if !ENABLE_EXTENDED_SELECTION
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;
}
void GLVolume::set_drag_group_id(const std::string& drag_by)
{
if (drag_by == "object")
drag_group_id = object_idx() * 1000;
else if (drag_by == "instance")
drag_group_id = object_idx() * 1000 + instance_idx();
}
#endif // !ENABLE_EXTENDED_SELECTION
#if !ENABLE_MODELVOLUME_TRANSFORM
const Transform3f& GLVolume::world_matrix() const
{
if (m_world_matrix_dirty)
{
#if ENABLE_MIRROR
m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor, m_mirror).cast<float>();
#else
m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast<float>();
#endif // ENABLE_MIRROR
m_world_matrix_dirty = false;
}
return m_world_matrix;
@ -730,23 +692,12 @@ void GLVolume::generate_layer_height_texture(const PrintObject *print_object, bo
#define LAYER_HEIGHT_TEXTURE_WIDTH 1024
#define LAYER_HEIGHT_TEXTURE_HEIGHT 1024
#if ENABLE_EXTENDED_SELECTION
std::vector<int> GLVolumeCollection::load_object(
const ModelObject *model_object,
int obj_idx,
const std::vector<int> &instance_idxs,
const std::string &color_by,
bool use_VBOs)
#else
std::vector<int> GLVolumeCollection::load_object(
const ModelObject *model_object,
int obj_idx,
const std::vector<int> &instance_idxs,
const std::string &color_by,
const std::string &select_by,
const std::string &drag_by,
bool use_VBOs)
#endif // ENABLE_EXTENDED_SELECTION
{
static float colors[4][4] = {
{ 1.0f, 1.0f, 0.0f, 1.f },
@ -797,10 +748,6 @@ 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 !ENABLE_EXTENDED_SELECTION
v.set_select_group_id(select_by);
v.set_drag_group_id(drag_by);
#endif // !ENABLE_EXTENDED_SELECTION
if (model_volume->is_model_part())
{
v.set_convex_hull(model_volume->get_convex_hull());
@ -816,9 +763,7 @@ std::vector<int> GLVolumeCollection::load_object(
v.set_offset(instance->get_offset());
v.set_rotation(instance->get_rotation());
v.set_scaling_factor(instance->get_scaling_factor());
#if ENABLE_MIRROR
v.set_mirror(instance->get_mirror());
#endif // ENABLE_MIRROR
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
}
@ -894,10 +839,6 @@ int GLVolumeCollection::load_wipe_tower_preview(
v.bounding_box = v.indexed_vertex_array.bounding_box();
v.indexed_vertex_array.finalize_geometry(use_VBOs);
v.composite_id = obj_idx * 1000000;
#if !ENABLE_EXTENDED_SELECTION
v.select_group_id = obj_idx * 1000000;
v.drag_group_id = obj_idx * 1000;
#endif // !ENABLE_EXTENDED_SELECTION
v.is_wipe_tower = true;
v.shader_outside_printer_detection_enabled = ! size_unknown;
return int(this->volumes.size() - 1);
@ -1093,26 +1034,6 @@ void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* con
}
}
#if !ENABLE_EXTENDED_SELECTION
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);
}
}
void GLVolumeCollection::set_drag_by(const std::string& drag_by)
{
for (GLVolume *vol : this->volumes)
{
if (vol != nullptr)
vol->set_drag_group_id(drag_by);
}
}
#endif // !ENABLE_EXTENDED_SELECTION
std::vector<double> GLVolumeCollection::get_current_print_zs(bool active_only) const
{
// Collect layer top positions of all volumes.
@ -1884,23 +1805,6 @@ void _3DScene::reset_volumes(wxGLCanvas* canvas)
s_canvas_mgr.reset_volumes(canvas);
}
#if !ENABLE_EXTENDED_SELECTION
void _3DScene::deselect_volumes(wxGLCanvas* canvas)
{
s_canvas_mgr.deselect_volumes(canvas);
}
void _3DScene::select_volume(wxGLCanvas* canvas, unsigned int id)
{
s_canvas_mgr.select_volume(canvas, id);
}
void _3DScene::update_volumes_selection(wxGLCanvas* canvas, const std::vector<int>& selections)
{
s_canvas_mgr.update_volumes_selection(canvas, selections);
}
#endif // !ENABLE_EXTENDED_SELECTION
int _3DScene::check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config)
{
return s_canvas_mgr.check_volumes_outside_state(canvas, config);
@ -1916,17 +1820,10 @@ bool _3DScene::move_volume_down(wxGLCanvas* canvas, unsigned int id)
return s_canvas_mgr.move_volume_down(canvas, id);
}
#if ENABLE_EXTENDED_SELECTION
GUI::GLCanvas3D* _3DScene::get_canvas(wxGLCanvas* canvas)
{
return s_canvas_mgr.get_canvas(canvas);
}
#else
void _3DScene::set_objects_selections(wxGLCanvas* canvas, const std::vector<int>& selections)
{
s_canvas_mgr.set_objects_selections(canvas, selections);
}
#endif // ENABLE_EXTENDED_SELECTION
void _3DScene::set_config(wxGLCanvas* canvas, DynamicPrintConfig* config)
{
@ -1973,23 +1870,6 @@ void _3DScene::set_color_by(wxGLCanvas* canvas, const std::string& value)
s_canvas_mgr.set_color_by(canvas, value);
}
#if !ENABLE_EXTENDED_SELECTION
void _3DScene::set_select_by(wxGLCanvas* canvas, const std::string& value)
{
s_canvas_mgr.set_select_by(canvas, value);
}
void _3DScene::set_drag_by(wxGLCanvas* canvas, const std::string& 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);
}
#endif // !ENABLE_EXTENDED_SELECTION
bool _3DScene::is_layers_editing_enabled(wxGLCanvas* canvas)
{
return s_canvas_mgr.is_layers_editing_enabled(canvas);
@ -2167,14 +2047,10 @@ int _3DScene::get_in_object_volume_id(wxGLCanvas* canvas, int scene_vol_idx)
return s_canvas_mgr.get_in_object_volume_id(canvas, scene_vol_idx);
}
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
void _3DScene::mirror_selection(wxGLCanvas* canvas, Axis axis)
{
s_canvas_mgr.mirror_selection(canvas, axis);
}
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MIRROR
void _3DScene::reload_scene(wxGLCanvas* canvas, bool force)
{

View File

@ -263,10 +263,8 @@ private:
Vec3d m_rotation;
// Scale factor along the three axes of the volume to be rendered.
Vec3d m_scaling_factor;
#if ENABLE_MIRROR
// Mirroring along the three axes of the volume to be rendered.
Vec3d m_mirror;
#endif // ENABLE_MIRROR
// World matrix of the volume to be rendered.
mutable Transform3f m_world_matrix;
// Whether or not is needed to recalculate the world matrix.
@ -292,12 +290,6 @@ public:
float render_color[4];
// An ID containing the object ID, volume ID and instance ID.
int composite_id;
#if !ENABLE_EXTENDED_SELECTION
// An ID for group selection. It may be the same for all meshes of all object instances, or for just a single object instance.
int select_group_id;
// An ID for group dragging. It may be the same for all meshes of all object instances, or for just a single object instance.
int drag_group_id;
#endif // !ENABLE_EXTENDED_SELECTION
// An ID containing the extruder ID (used to select color).
int extruder_id;
// Is this object selected?
@ -358,28 +350,22 @@ public:
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); set_bounding_boxes_as_dirty(); }
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); set_bounding_boxes_as_dirty(); }
#if ENABLE_MIRROR
const Vec3d& get_mirror() const { return m_transformation.get_mirror(); }
double get_mirror(Axis axis) const { return m_transformation.get_mirror(axis); }
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); set_bounding_boxes_as_dirty(); }
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); set_bounding_boxes_as_dirty(); }
#endif // ENABLE_MIRROR
#else
const Vec3d& get_rotation() const;
void set_rotation(const Vec3d& rotation);
#if ENABLE_EXTENDED_SELECTION
const Vec3d& get_scaling_factor() const;
#endif // ENABLE_EXTENDED_SELECTION
void set_scaling_factor(const Vec3d& scaling_factor);
#if ENABLE_MIRROR
const Vec3d& get_mirror() const;
double get_mirror(Axis axis) const;
void set_mirror(const Vec3d& mirror);
void set_mirror(Axis axis, double mirror);
#endif // ENABLE_MIRROR
const Vec3d& get_offset() const;
void set_offset(const Vec3d& offset);
@ -387,17 +373,12 @@ public:
void set_convex_hull(const TriangleMesh& convex_hull);
#if !ENABLE_EXTENDED_SELECTION
void set_select_group_id(const std::string& select_by);
void set_drag_group_id(const std::string& drag_by);
#endif // !ENABLE_EXTENDED_SELECTION
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; }
#if ENABLE_MODELVOLUME_TRANSFORM
const Transform3d& world_matrix() const { return m_transformation.world_matrix(); }
const Transform3d& world_matrix() const { return m_transformation.get_matrix(); }
#else
const Transform3f& world_matrix() const;
#endif // ENABLE_MODELVOLUME_TRANSFORM
@ -456,9 +437,7 @@ public:
#endif // ENABLE_MODELVOLUME_TRANSFORM
};
#if ENABLE_EXTENDED_SELECTION
typedef std::vector<GLVolume*> GLVolumePtrs;
#endif // ENABLE_EXTENDED_SELECTION
class GLVolumeCollection
{
@ -467,32 +446,17 @@ class GLVolumeCollection
float print_box_max[3];
public:
#if ENABLE_EXTENDED_SELECTION
GLVolumePtrs volumes;
#else
std::vector<GLVolume*> volumes;
#endif // ENABLE_EXTENDED_SELECTION
GLVolumeCollection() {};
~GLVolumeCollection() { clear(); };
#if ENABLE_EXTENDED_SELECTION
std::vector<int> load_object(
const ModelObject *model_object,
int obj_idx,
const std::vector<int> &instance_idxs,
const std::string &color_by,
bool use_VBOs);
#else
std::vector<int> load_object(
const ModelObject *model_object,
int obj_idx,
const std::vector<int> &instance_idxs,
const std::string &color_by,
const std::string &select_by,
const std::string &drag_by,
bool use_VBOs);
#endif // ENABLE_EXTENDED_SELECTION
int load_wipe_tower_preview(
int obj_idx, float pos_x, float pos_y, float width, float depth, float height, float rotation_angle, bool use_VBOs, bool size_unknown, float brim_width);
@ -526,11 +490,6 @@ public:
void update_colors_by_extruder(const DynamicPrintConfig* config);
#if !ENABLE_EXTENDED_SELECTION
void set_select_by(const std::string& select_by);
void set_drag_by(const std::string& drag_by);
#endif // !ENABLE_EXTENDED_SELECTION
// 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;
@ -558,20 +517,11 @@ public:
static unsigned int get_volumes_count(wxGLCanvas* canvas);
static void reset_volumes(wxGLCanvas* canvas);
#if !ENABLE_EXTENDED_SELECTION
static void deselect_volumes(wxGLCanvas* canvas);
static void select_volume(wxGLCanvas* canvas, unsigned int id);
static void update_volumes_selection(wxGLCanvas* canvas, const std::vector<int>& selections);
#endif // !ENABLE_EXTENDED_SELECTION
static int check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config);
static bool move_volume_up(wxGLCanvas* canvas, unsigned int id);
static bool move_volume_down(wxGLCanvas* canvas, unsigned int id);
#if ENABLE_EXTENDED_SELECTION
static GUI::GLCanvas3D* get_canvas(wxGLCanvas* canvas);
#else
static void set_objects_selections(wxGLCanvas* canvas, const std::vector<int>& selections);
#endif // ENABLE_EXTENDED_SELECTION
static void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config);
static void set_print(wxGLCanvas* canvas, Print* print);
@ -587,12 +537,6 @@ public:
static void set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons);
static void set_color_by(wxGLCanvas* canvas, const std::string& value);
#if !ENABLE_EXTENDED_SELECTION
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);
#endif // !ENABLE_EXTENDED_SELECTION
static bool is_layers_editing_enabled(wxGLCanvas* canvas);
static bool is_layers_editing_allowed(wxGLCanvas* canvas);
@ -634,11 +578,7 @@ public:
static int get_first_volume_id(wxGLCanvas* canvas, int obj_idx);
static int get_in_object_volume_id(wxGLCanvas* canvas, int scene_vol_idx);
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
static void mirror_selection(wxGLCanvas* canvas, Axis axis);
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MIRROR
static void reload_scene(wxGLCanvas* canvas, bool force);

View File

@ -79,7 +79,7 @@ void Field::on_kill_focus(wxEvent& event)
void Field::on_change_field()
{
std::cerr << "calling Field::_on_change \n";
// std::cerr << "calling Field::_on_change \n";
if (m_on_change != nullptr && !m_disable_change_event)
m_on_change(m_opt_id, get_value());
}

File diff suppressed because it is too large Load Diff

View File

@ -82,21 +82,7 @@ public:
void set_bottom(float bottom);
};
#if ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, SimpleEvent);
#else
struct ObjectSelectEvent;
wxDECLARE_EVENT(EVT_GLCANVAS_OBJECT_SELECT, ObjectSelectEvent);
struct ObjectSelectEvent : public ArrayEvent<ptrdiff_t, 2>
{
ObjectSelectEvent(ptrdiff_t object_id, ptrdiff_t volume_id, wxObject *origin = nullptr)
: ArrayEvent(EVT_GLCANVAS_OBJECT_SELECT, {object_id, volume_id}, origin)
{}
ptrdiff_t object_id() const { return data[0]; }
ptrdiff_t volume_id() const { return data[1]; }
};
#endif // ENABLE_EXTENDED_SELECTION
using Vec2dEvent = Event<Vec2d>;
template <size_t N> using Vec2dsEvent = ArrayEvent<Vec2d, N>;
@ -106,30 +92,16 @@ template <size_t N> using Vec3dsEvent = ArrayEvent<Vec3d, N>;
wxDECLARE_EVENT(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_VIEWPORT_CHANGED, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLCANVAS_DOUBLE_CLICK, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLCANVAS_RIGHT_CLICK, Vec2dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_MODEL_UPDATE, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_REMOVE_OBJECT, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ARRANGE, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLCANVAS_ROTATE_OBJECT, Event<int>); // data: -1 => rotate left, +1 => rotate right
wxDECLARE_EVENT(EVT_GLCANVAS_SCALE_UNIFORMLY, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLCANVAS_INCREASE_INSTANCES, Event<int>); // data: +1 => increase, -1 => decrease
wxDECLARE_EVENT(EVT_GLCANVAS_INSTANCE_MOVED, SimpleEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_WIPETOWER_MOVED, Vec3dEvent);
wxDECLARE_EVENT(EVT_GLCANVAS_ENABLE_ACTION_BUTTONS, Event<bool>);
wxDECLARE_EVENT(EVT_GLCANVAS_UPDATE_GEOMETRY, Vec3dsEvent<2>);
#if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GIZMO_SCALE, Vec3dEvent);
wxDECLARE_EVENT(EVT_GIZMO_ROTATE, Vec3dEvent);
wxDECLARE_EVENT(EVT_GIZMO_FLATTEN, Vec3dEvent);
#endif // !ENABLE_EXTENDED_SELECTION
class GLCanvas3D
{
struct GCodePreviewVolumeIndex
@ -356,15 +328,7 @@ class GLCanvas3D
Point start_position_2D;
Vec3d start_position_3D;
#if !ENABLE_EXTENDED_SELECTION
Vec3d volume_center_offset;
bool move_with_shift;
#endif // !ENABLE_EXTENDED_SELECTION
int move_volume_idx;
#if !ENABLE_EXTENDED_SELECTION
int gizmo_volume_idx;
#endif // !ENABLE_EXTENDED_SELECTION
public:
Drag();
@ -386,7 +350,6 @@ class GLCanvas3D
bool is_start_position_3D_defined() const;
};
#if ENABLE_EXTENDED_SELECTION
public:
class Selection
{
@ -504,9 +467,7 @@ public:
void translate(const Vec3d& displacement);
void rotate(const Vec3d& rotation);
void scale(const Vec3d& scale);
#if ENABLE_MIRROR
void mirror(Axis axis);
#endif // ENABLE_MIRROR
void translate(unsigned int object_idx, const Vec3d& displacement);
void translate(unsigned int object_idx, unsigned int instance_idx, const Vec3d& displacement);
@ -531,8 +492,6 @@ public:
};
private:
#endif // ENABLE_EXTENDED_SELECTION
class Gizmos
{
static const float OverlayTexturesScale;
@ -566,20 +525,13 @@ private:
bool is_enabled() const;
void set_enabled(bool enable);
#if ENABLE_EXTENDED_SELECTION
std::string update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection);
void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos, const Selection& selection);
void update_on_off_state(const Selection& selection);
#else
void update_hover_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos);
void update_on_off_state(const GLCanvas3D& canvas, const Vec2d& mouse_pos);
#endif // ENABLE_EXTENDED_SELECTION
void reset_all_states();
void set_hover_id(int id);
#if ENABLE_EXTENDED_SELECTION
void enable_grabber(EType type, unsigned int id, bool enable);
#endif // ENABLE_EXTENDED_SELECTION
bool overlay_contains_mouse(const GLCanvas3D& canvas, const Vec2d& mouse_pos) const;
bool grabber_contains_mouse() const;
@ -593,19 +545,10 @@ private:
bool is_running() const;
bool is_dragging() const;
#if ENABLE_EXTENDED_SELECTION
void start_dragging(const Selection& selection);
#else
void start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
void stop_dragging();
#if ENABLE_EXTENDED_SELECTION
Vec3d get_displacement() const;
#else
Vec3d get_position() const;
void set_position(const Vec3d& position);
#endif // ENABLE_EXTENDED_SELECTION
Vec3d get_scale() const;
void set_scale(const Vec3d& scale);
@ -621,13 +564,8 @@ private:
void clicked_on_object(const Vec2d& mouse_position);
void delete_current_grabber(bool delete_all = false);
#if ENABLE_EXTENDED_SELECTION
void render_current_gizmo(const Selection& selection) const;
void render_current_gizmo_for_picking_pass(const Selection& selection) const;
#else
void render_current_gizmo(const BoundingBoxf3& box) const;
void render_current_gizmo_for_picking_pass(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
void render_overlay(const GLCanvas3D& canvas) const;
@ -635,11 +573,7 @@ private:
void _reset();
void _render_overlay(const GLCanvas3D& canvas) const;
#if ENABLE_EXTENDED_SELECTION
void _render_current_gizmo(const Selection& selection) const;
#else
void _render_current_gizmo(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
float _get_total_overlay_height() const;
GLGizmoBase* _get_current() const;
@ -699,9 +633,7 @@ private:
mutable GLToolbar m_toolbar;
mutable GLVolumeCollection m_volumes;
#if ENABLE_EXTENDED_SELECTION
Selection m_selection;
#endif // ENABLE_EXTENDED_SELECTION
DynamicPrintConfig* m_config;
Print* m_print;
Model* m_model;
@ -720,21 +652,11 @@ private:
bool m_shader_enabled;
bool m_dynamic_background_enabled;
bool m_multisample_allowed;
#if ENABLE_EXTENDED_SELECTION
bool m_regenerate_volumes;
#endif // ENABLE_EXTENDED_SELECTION
std::string m_color_by;
#if !ENABLE_EXTENDED_SELECTION
std::string m_select_by;
std::string m_drag_by;
#endif // !ENABLE_EXTENDED_SELECTION
bool m_reload_delayed;
#if !ENABLE_EXTENDED_SELECTION
std::vector<std::vector<int>> m_objects_volumes_idxs;
std::vector<int> m_objects_selections;
#endif // !ENABLE_EXTENDED_SELECTION
GCodePreviewVolumeIndex m_gcode_preview_volume_index;
@ -761,27 +683,16 @@ public:
unsigned int get_volumes_count() const;
void reset_volumes();
#if !ENABLE_EXTENDED_SELECTION
void deselect_volumes();
void select_volume(unsigned int id);
void update_volumes_selection(const std::vector<int>& selections);
#endif // !ENABLE_EXTENDED_SELECTION
int check_volumes_outside_state(const DynamicPrintConfig* config) const;
bool move_volume_up(unsigned int id);
bool move_volume_down(unsigned int id);
#if !ENABLE_EXTENDED_SELECTION
void set_objects_selections(const std::vector<int>& selections);
#endif // !ENABLE_EXTENDED_SELECTION
void set_config(DynamicPrintConfig* config);
void set_print(Print* print);
void set_model(Model* model);
#if ENABLE_EXTENDED_SELECTION
const Selection& get_selection() const { return m_selection; }
Selection& get_selection() { return m_selection; }
#endif // ENABLE_EXTENDED_SELECTION
// Set the bed shape to a single closed 2D polygon(array of two element arrays),
// triangulate the bed and store the triangles into m_bed.m_triangles,
@ -796,13 +707,6 @@ public:
void set_cutting_plane(float z, const ExPolygons& polygons);
void set_color_by(const std::string& value);
#if !ENABLE_EXTENDED_SELECTION
void set_select_by(const std::string& value);
void set_drag_by(const std::string& value);
const std::string& get_select_by() const;
const std::string& get_drag_by() const;
#endif // !ENABLE_EXTENDED_SELECTION
float get_camera_zoom() const;
@ -832,9 +736,7 @@ public:
void zoom_to_bed();
void zoom_to_volumes();
#if ENABLE_MODIFIED_CAMERA_TARGET
#if ENABLE_EXTENDED_SELECTION
void zoom_to_selection();
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MODIFIED_CAMERA_TARGET
void select_view(const std::string& direction);
void set_viewport_from_scene(const GLCanvas3D& other);
@ -855,11 +757,7 @@ public:
int get_first_volume_id(int obj_idx) const;
int get_in_object_volume_id(int scene_vol_idx) const;
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
void mirror_selection(Axis axis);
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MIRROR
void reload_scene(bool force);
@ -897,9 +795,6 @@ private:
void _resize(unsigned int w, unsigned int h);
BoundingBoxf3 _max_bounding_box() const;
#if !ENABLE_EXTENDED_SELECTION
BoundingBoxf3 _selected_volumes_bounding_box() const;
#endif // !ENABLE_EXTENDED_SELECTION
void _zoom_to_bounding_box(const BoundingBoxf3& bbox);
float _get_zoom_to_bounding_box_factor(const BoundingBoxf3& bbox) const;
@ -913,9 +808,7 @@ private:
void _render_bed(float theta) const;
void _render_axes(bool depth_test) const;
void _render_objects() const;
#if ENABLE_EXTENDED_SELECTION
void _render_selection() const;
#endif // ENABLE_EXTENDED_SELECTION
void _render_cutting_plane() const;
void _render_warning_texture() const;
void _render_legend_texture() const;
@ -928,9 +821,7 @@ private:
void _render_camera_target() const;
#endif // ENABLE_SHOW_CAMERA_TARGET
#if ENABLE_EXTENDED_SELECTION
void _update_volumes_hover_state() const;
#endif // ENABLE_EXTENDED_SELECTION
float _get_layers_editing_cursor_z_relative() const;
void _perform_layer_editing_action(wxMouseEvent* evt = nullptr);
@ -948,11 +839,6 @@ private:
void _start_timer();
void _stop_timer();
#if !ENABLE_EXTENDED_SELECTION
int _get_first_selected_object_id() const;
int _get_first_selected_volume_id(int object_id) const;
#endif // !ENABLE_EXTENDED_SELECTION
// Create 3D thick extrusion lines for a skirt and brim.
// Adds a new Slic3r::GUI::3DScene::Volume to volumes.
void _load_print_toolpaths();
@ -981,20 +867,11 @@ private:
void _update_toolpath_volumes_outside_state();
void _show_warning_texture_if_needed();
#if ENABLE_EXTENDED_SELECTION
void _on_move();
void _on_rotate();
void _on_scale();
void _on_flatten();
#if ENABLE_MIRROR
void _on_mirror();
#endif // ENABLE_MIRROR
#else
void _on_move(const std::vector<int>& volume_idxs);
#endif // ENABLE_EXTENDED_SELECTION
#if !ENABLE_EXTENDED_SELECTION
void _on_select(int volume_idx, int object_idx);
#endif // !ENABLE_EXTENDED_SELECTION
// 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);

View File

@ -246,29 +246,6 @@ void GLCanvas3DManager::reset_volumes(wxGLCanvas* canvas)
it->second->reset_volumes();
}
#if !ENABLE_EXTENDED_SELECTION
void GLCanvas3DManager::deselect_volumes(wxGLCanvas* canvas)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->deselect_volumes();
}
void GLCanvas3DManager::select_volume(wxGLCanvas* canvas, unsigned int id)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->select_volume(id);
}
void GLCanvas3DManager::update_volumes_selection(wxGLCanvas* canvas, const std::vector<int>& selections)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->update_volumes_selection(selections);
}
#endif // !ENABLE_EXTENDED_SELECTION
int GLCanvas3DManager::check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
@ -287,20 +264,11 @@ bool GLCanvas3DManager::move_volume_down(wxGLCanvas* canvas, unsigned int id)
return (it != m_canvases.end()) ? it->second->move_volume_down(id) : false;
}
#if ENABLE_EXTENDED_SELECTION
GLCanvas3D* GLCanvas3DManager::get_canvas(wxGLCanvas* canvas)
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
return (it != m_canvases.end()) ? it->second : nullptr;
}
#else
void GLCanvas3DManager::set_objects_selections(wxGLCanvas* canvas, const std::vector<int>& selections)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_objects_selections(selections);
}
#endif // ENABLE_EXTENDED_SELECTION
void GLCanvas3DManager::set_config(wxGLCanvas* canvas, DynamicPrintConfig* config)
{
@ -364,28 +332,6 @@ void GLCanvas3DManager::set_color_by(wxGLCanvas* canvas, const std::string& valu
it->second->set_color_by(value);
}
#if !ENABLE_EXTENDED_SELECTION
void GLCanvas3DManager::set_select_by(wxGLCanvas* canvas, const std::string& value)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->set_select_by(value);
}
void GLCanvas3DManager::set_drag_by(wxGLCanvas* canvas, const std::string& value)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
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() : "";
}
#endif // !ENABLE_EXTENDED_SELECTION
bool GLCanvas3DManager::is_layers_editing_enabled(wxGLCanvas* canvas) const
{
CanvasesMap::const_iterator it = _get_canvas(canvas);
@ -596,16 +542,12 @@ int GLCanvas3DManager::get_in_object_volume_id(wxGLCanvas* canvas, int scene_vol
return (it != m_canvases.end()) ? it->second->get_in_object_volume_id(scene_vol_idx) : -1;
}
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
void GLCanvas3DManager::mirror_selection(wxGLCanvas* canvas, Axis axis)
{
CanvasesMap::iterator it = _get_canvas(canvas);
if (it != m_canvases.end())
it->second->mirror_selection(axis);
}
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MIRROR
void GLCanvas3DManager::reload_scene(wxGLCanvas* canvas, bool force)
{

View File

@ -87,20 +87,11 @@ public:
unsigned int get_volumes_count(wxGLCanvas* canvas) const;
void reset_volumes(wxGLCanvas* canvas);
#if !ENABLE_EXTENDED_SELECTION
void deselect_volumes(wxGLCanvas* canvas);
void select_volume(wxGLCanvas* canvas, unsigned int id);
void update_volumes_selection(wxGLCanvas* canvas, const std::vector<int>& selections);
#endif // !ENABLE_EXTENDED_SELECTION
int check_volumes_outside_state(wxGLCanvas* canvas, const DynamicPrintConfig* config) const;
bool move_volume_up(wxGLCanvas* canvas, unsigned int id);
bool move_volume_down(wxGLCanvas* canvas, unsigned int id);
#if ENABLE_EXTENDED_SELECTION
GLCanvas3D* get_canvas(wxGLCanvas* canvas);
#else
void set_objects_selections(wxGLCanvas* canvas, const std::vector<int>& selections);
#endif // ENABLE_EXTENDED_SELECTION
void set_config(wxGLCanvas* canvas, DynamicPrintConfig* config);
void set_print(wxGLCanvas* canvas, Print* print);
@ -116,12 +107,6 @@ public:
void set_cutting_plane(wxGLCanvas* canvas, float z, const ExPolygons& polygons);
void set_color_by(wxGLCanvas* canvas, const std::string& value);
#if !ENABLE_EXTENDED_SELECTION
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;
#endif // !ENABLE_EXTENDED_SELECTION
bool is_layers_editing_enabled(wxGLCanvas* canvas) const;
bool is_layers_editing_allowed(wxGLCanvas* canvas) const;
@ -163,11 +148,7 @@ public:
int get_first_volume_id(wxGLCanvas* canvas, int obj_idx) const;
int get_in_object_volume_id(wxGLCanvas* canvas, int scene_vol_idx) const;
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
void mirror_selection(wxGLCanvas* canvas, Axis axis);
#endif // ENABLE_EXTENDED_SELECTION
#endif // ENABLE_MIRROR
void reload_scene(wxGLCanvas* canvas, bool force);

View File

@ -4,9 +4,6 @@
#include "GUI.hpp"
#include "../../libslic3r/Utils.hpp"
#if !ENABLE_EXTENDED_SELECTION
#include "../../slic3r/GUI/GLCanvas3D.hpp"
#endif // !ENABLE_EXTENDED_SELECTION
#include <Eigen/Dense>
#include "../../libslic3r/Geometry.hpp"
@ -26,91 +23,6 @@ static const float AXES_COLOR[3][3] = { { 1.0f, 0.0f, 0.0f }, { 0.0f, 1.0f, 0.0f
namespace Slic3r {
namespace GUI {
#if !ENABLE_EXTENDED_SELECTION
// 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;
}
#endif // !ENABLE_EXTENDED_SELECTION
const float GLGizmoBase::Grabber::SizeFactor = 0.025f;
const float GLGizmoBase::Grabber::MinHalfSize = 1.5f;
const float GLGizmoBase::Grabber::DraggingScaleFactor = 1.25f;
@ -262,11 +174,7 @@ void GLGizmoBase::disable_grabber(unsigned int id)
on_disable_grabber(id);
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoBase::start_dragging(const GLCanvas3D::Selection& selection)
#else
void GLGizmoBase::start_dragging(const BoundingBoxf3& box)
#endif // ENABLE_EXTENDED_SELECTION
{
m_dragging = true;
@ -275,11 +183,7 @@ void GLGizmoBase::start_dragging(const BoundingBoxf3& box)
m_grabbers[i].dragging = (m_hover_id == i);
}
#if ENABLE_EXTENDED_SELECTION
on_start_dragging(selection);
#else
on_start_dragging(box);
#endif // ENABLE_EXTENDED_SELECTION
}
void GLGizmoBase::stop_dragging()
@ -385,15 +289,9 @@ bool GLGizmoRotate::on_init()
return true;
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoRotate::on_start_dragging(const GLCanvas3D::Selection& selection)
#else
void GLGizmoRotate::on_start_dragging(const BoundingBoxf3& box)
#endif // ENABLE_EXTENDED_SELECTION
{
#if ENABLE_EXTENDED_SELECTION
const BoundingBoxf3& box = selection.get_bounding_box();
#endif // ENABLE_EXTENDED_SELECTION
m_center = box.center();
m_radius = Offset + box.radius();
m_snap_coarse_in_radius = m_radius / 3.0f;
@ -437,16 +335,11 @@ void GLGizmoRotate::on_update(const Linef3& mouse_ray, const Point* mouse_positi
m_angle = theta;
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoRotate::on_render(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
if (!m_grabbers[0].enabled)
return;
#if ENABLE_EXTENDED_SELECTION
const BoundingBoxf3& box = selection.get_bounding_box();
bool single_instance = selection.is_single_full_instance();
@ -460,10 +353,6 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
if ((single_instance && (m_hover_id == 0)) || m_dragging)
set_tooltip(axis + format((float)Geometry::rad2deg(m_angle), 4) + "\u00B0");
#else
if (m_dragging)
set_tooltip(format(m_angle * 180.0f / (float)PI, 4));
#endif // ENABLE_EXTENDED_SELECTION
else
{
m_center = box.center();
@ -501,22 +390,14 @@ void GLGizmoRotate::on_render(const BoundingBoxf3& box) const
::glPopMatrix();
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoRotate::on_render_for_picking(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoRotate::on_render_for_picking(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
::glDisable(GL_DEPTH_TEST);
::glPushMatrix();
transform_to_local();
#if ENABLE_EXTENDED_SELECTION
render_grabbers_for_picking(selection.get_bounding_box());
#else
render_grabbers_for_picking(box);
#endif // ENABLE_EXTENDED_SELECTION
::glPopMatrix();
}
@ -733,19 +614,11 @@ std::string GLGizmoRotate3D::on_get_name() const
return L("Rotate");
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoRotate3D::on_start_dragging(const GLCanvas3D::Selection& selection)
{
if ((0 <= m_hover_id) && (m_hover_id < 3))
m_gizmos[m_hover_id].start_dragging(selection);
}
#else
void GLGizmoRotate3D::on_start_dragging(const BoundingBoxf3& box)
{
if ((0 <= m_hover_id) && (m_hover_id < 3))
m_gizmos[m_hover_id].start_dragging(box);
}
#endif // ENABLE_EXTENDED_SELECTION
void GLGizmoRotate3D::on_stop_dragging()
{
@ -753,7 +626,6 @@ void GLGizmoRotate3D::on_stop_dragging()
m_gizmos[m_hover_id].stop_dragging();
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoRotate3D::on_render(const GLCanvas3D::Selection& selection) const
{
if ((m_hover_id == -1) || (m_hover_id == 0))
@ -765,24 +637,8 @@ void GLGizmoRotate3D::on_render(const GLCanvas3D::Selection& selection) const
if ((m_hover_id == -1) || (m_hover_id == 2))
m_gizmos[Z].render(selection);
}
#else
void GLGizmoRotate3D::on_render(const BoundingBoxf3& box) const
{
if ((m_hover_id == -1) || (m_hover_id == 0))
m_gizmos[X].render(box);
if ((m_hover_id == -1) || (m_hover_id == 1))
m_gizmos[Y].render(box);
if ((m_hover_id == -1) || (m_hover_id == 2))
m_gizmos[Z].render(box);
}
#endif // ENABLE_EXTENDED_SELECTION
const float GLGizmoScale3D::Offset = 5.0f;
#if !ENABLE_EXTENDED_SELECTION
const Vec3d GLGizmoScale3D::OffsetVec = (double)GLGizmoScale3D::Offset * Vec3d::Ones();
#endif // !ENABLE_EXTENDED_SELECTION
GLGizmoScale3D::GLGizmoScale3D(GLCanvas3D& parent)
: GLGizmoBase(parent)
@ -830,20 +686,12 @@ std::string GLGizmoScale3D::on_get_name() const
return L("Scale");
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoScale3D::on_start_dragging(const GLCanvas3D::Selection& selection)
#else
void GLGizmoScale3D::on_start_dragging(const BoundingBoxf3& box)
#endif // ENABLE_EXTENDED_SELECTION
{
if (m_hover_id != -1)
{
m_starting_drag_position = m_grabbers[m_hover_id].center;
#if ENABLE_EXTENDED_SELECTION
m_starting_box = selection.get_bounding_box();
#else
m_starting_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec);
#endif // ENABLE_EXTENDED_SELECTION
}
}
@ -867,13 +715,8 @@ void GLGizmoScale3D::on_process_double_click()
}
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
void GLGizmoScale3D::on_render(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
#if ENABLE_EXTENDED_SELECTION
bool single_instance = selection.is_single_full_instance();
Vec3f scale = single_instance ? 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_scaling_factor().cast<float>() : 100.0f * m_scale.cast<float>();
@ -891,25 +734,9 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
tooltip += "Z: " + format(scale(2), 4) + "%";
set_tooltip(tooltip);
}
#else
if (m_grabbers[0].dragging || m_grabbers[1].dragging)
set_tooltip("X: " + format(100.0f * m_scale(0), 4) + "%");
else if (m_grabbers[2].dragging || m_grabbers[3].dragging)
set_tooltip("Y: " + format(100.0f * m_scale(1), 4) + "%");
else if (m_grabbers[4].dragging || m_grabbers[5].dragging)
set_tooltip("Z: " + format(100.0f * m_scale(2), 4) + "%");
else if (m_grabbers[6].dragging || m_grabbers[7].dragging || m_grabbers[8].dragging || m_grabbers[9].dragging)
{
std::string tooltip = "X: " + format(100.0f * m_scale(0), 4) + "%\n";
tooltip += "Y: " + format(100.0f * m_scale(1), 4) + "%\n";
tooltip += "Z: " + format(100.0f * m_scale(2), 4) + "%";
set_tooltip(tooltip);
}
#endif // ENABLE_EXTENDED_SELECTION
::glEnable(GL_DEPTH_TEST);
#if ENABLE_EXTENDED_SELECTION
BoundingBoxf3 box;
Transform3d transform = Transform3d::Identity();
Vec3d angles = Vec3d::Zero();
@ -935,86 +762,52 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
// gets angles from first selected volume
angles = v->get_rotation();
#if ENABLE_MIRROR
// consider rotation+mirror only components of the transform for offsets
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles, Vec3d::Ones(), v->get_mirror());
#else
// set rotation-only component of transform
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles);
#endif // ENABLE_MIRROR
}
else
box = selection.get_bounding_box();
m_box = box;
#else
m_box = BoundingBoxf3(box.min - OffsetVec, box.max + OffsetVec);
#endif // ENABLE_EXTENDED_SELECTION
const Vec3d& center = m_box.center();
#if ENABLE_EXTENDED_SELECTION
Vec3d offset_x = offsets_transform * Vec3d((double)Offset, 0.0, 0.0);
Vec3d offset_y = offsets_transform * Vec3d(0.0, (double)Offset, 0.0);
Vec3d offset_z = offsets_transform * Vec3d(0.0, 0.0, (double)Offset);
#endif // ENABLE_EXTENDED_SELECTION
// x axis
#if ENABLE_EXTENDED_SELECTION
m_grabbers[0].center = transform * Vec3d(m_box.min(0), center(1), center(2)) - offset_x;
m_grabbers[1].center = transform * Vec3d(m_box.max(0), center(1), center(2)) + offset_x;
#else
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));
#endif // ENABLE_EXTENDED_SELECTION
::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
#if ENABLE_EXTENDED_SELECTION
m_grabbers[2].center = transform * Vec3d(center(0), m_box.min(1), center(2)) - offset_y;
m_grabbers[3].center = transform * Vec3d(center(0), m_box.max(1), center(2)) + offset_y;
#else
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));
#endif // ENABLE_EXTENDED_SELECTION
::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
#if ENABLE_EXTENDED_SELECTION
m_grabbers[4].center = transform * Vec3d(center(0), center(1), m_box.min(2)) - offset_z;
m_grabbers[5].center = transform * Vec3d(center(0), center(1), m_box.max(2)) + offset_z;
#else
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));
#endif // ENABLE_EXTENDED_SELECTION
::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
#if ENABLE_EXTENDED_SELECTION
m_grabbers[6].center = transform * Vec3d(m_box.min(0), m_box.min(1), center(2)) - offset_x - offset_y;
m_grabbers[7].center = transform * Vec3d(m_box.max(0), m_box.min(1), center(2)) + offset_x - offset_y;
m_grabbers[8].center = transform * Vec3d(m_box.max(0), m_box.max(1), center(2)) + offset_x + offset_y;
m_grabbers[9].center = transform * Vec3d(m_box.min(0), m_box.max(1), center(2)) - offset_x + offset_y;
#else
m_grabbers[6].center = Vec3d(m_box.min(0), m_box.min(1), center(2));
m_grabbers[7].center = Vec3d(m_box.max(0), m_box.min(1), center(2));
m_grabbers[8].center = Vec3d(m_box.max(0), m_box.max(1), center(2));
m_grabbers[9].center = Vec3d(m_box.min(0), m_box.max(1), center(2));
#endif // ENABLE_EXTENDED_SELECTION
for (int i = 6; i < 10; ++i)
{
::memcpy((void*)m_grabbers[i].color, (const void*)m_highlight_color, 3 * sizeof(float));
}
#if ENABLE_EXTENDED_SELECTION
// sets grabbers orientation
for (int i = 0; i < 10; ++i)
{
m_grabbers[i].angles = angles;
}
#endif // ENABLE_EXTENDED_SELECTION
::glLineWidth((m_hover_id != -1) ? 2.0f : 1.5f);
@ -1089,21 +882,12 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
}
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoScale3D::on_render_for_picking(const GLCanvas3D::Selection& selection) const
{
::glDisable(GL_DEPTH_TEST);
render_grabbers_for_picking(selection.get_bounding_box());
}
#else
void GLGizmoScale3D::on_render_for_picking(const BoundingBoxf3& box) const
{
::glDisable(GL_DEPTH_TEST);
render_grabbers_for_picking(box);
}
#endif // ENABLE_EXTENDED_SELECTION
void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int id_2) const
{
@ -1119,11 +903,7 @@ void GLGizmoScale3D::render_grabbers_connection(unsigned int id_1, unsigned int
void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
{
#if ENABLE_EXTENDED_SELECTION
double ratio = calc_ratio(mouse_ray);
#else
double ratio = calc_ratio(1, mouse_ray, m_starting_box.center());
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
m_scale(0) = m_starting_scale(0) * ratio;
@ -1131,11 +911,7 @@ void GLGizmoScale3D::do_scale_x(const Linef3& mouse_ray)
void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
{
#if ENABLE_EXTENDED_SELECTION
double ratio = calc_ratio(mouse_ray);
#else
double ratio = calc_ratio(2, mouse_ray, m_starting_box.center());
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
m_scale(1) = m_starting_scale(1) * ratio;
@ -1143,11 +919,7 @@ void GLGizmoScale3D::do_scale_y(const Linef3& mouse_ray)
void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
{
#if ENABLE_EXTENDED_SELECTION
double ratio = calc_ratio(mouse_ray);
#else
double ratio = calc_ratio(1, mouse_ray, m_starting_box.center());
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
m_scale(2) = m_starting_scale(2) * ratio;
@ -1155,19 +927,12 @@ void GLGizmoScale3D::do_scale_z(const Linef3& mouse_ray)
void GLGizmoScale3D::do_scale_uniform(const Linef3& mouse_ray)
{
#if ENABLE_EXTENDED_SELECTION
double ratio = calc_ratio(mouse_ray);
#else
Vec3d center = m_starting_box.center();
center(2) = m_box.min(2);
double ratio = calc_ratio(0, mouse_ray, center);
#endif // ENABLE_EXTENDED_SELECTION
if (ratio > 0.0)
m_scale = m_starting_scale * ratio;
}
#if ENABLE_EXTENDED_SELECTION
double GLGizmoScale3D::calc_ratio(const Linef3& mouse_ray) const
{
double ratio = 0.0;
@ -1194,53 +959,12 @@ double GLGizmoScale3D::calc_ratio(const Linef3& mouse_ray) const
return ratio;
}
#else
double GLGizmoScale3D::calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const
{
double ratio = 0.0;
Vec3d starting_vec = m_starting_drag_position - center;
double len_starting_vec = starting_vec.norm();
if (len_starting_vec == 0.0)
return ratio;
Vec3d starting_vec_dir = starting_vec.normalized();
Vec3d mouse_dir = mouse_ray.unit_vector();
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:
{
ratio = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, center)) / len_starting_vec;
break;
}
case 1:
{
ratio = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, center)) / len_starting_vec;
break;
}
case 2:
{
ratio = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, center)) / len_starting_vec;
break;
}
}
return ratio;
}
#endif // ENABLE_EXTENDED_SELECTION
const double GLGizmoMove3D::Offset = 10.0;
GLGizmoMove3D::GLGizmoMove3D(GLCanvas3D& parent)
: GLGizmoBase(parent)
#if ENABLE_EXTENDED_SELECTION
, m_displacement(Vec3d::Zero())
#else
, m_position(Vec3d::Zero())
#endif // ENABLE_EXTENDED_SELECTION
, m_starting_drag_position(Vec3d::Zero())
, m_starting_box_center(Vec3d::Zero())
, m_starting_box_bottom_center(Vec3d::Zero())
@ -1276,18 +1000,12 @@ std::string GLGizmoMove3D::on_get_name() const
return L("Move");
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoMove3D::on_start_dragging(const GLCanvas3D::Selection& selection)
#else
void GLGizmoMove3D::on_start_dragging(const BoundingBoxf3& box)
#endif // ENABLE_EXTENDED_SELECTION
{
if (m_hover_id != -1)
{
#if ENABLE_EXTENDED_SELECTION
m_displacement = Vec3d::Zero();
const BoundingBoxf3& box = selection.get_bounding_box();
#endif // ENABLE_EXTENDED_SELECTION
m_starting_drag_position = m_grabbers[m_hover_id].center;
m_starting_box_center = box.center();
m_starting_box_bottom_center = box.center();
@ -1295,39 +1013,23 @@ void GLGizmoMove3D::on_start_dragging(const BoundingBoxf3& box)
}
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoMove3D::on_stop_dragging()
{
m_displacement = Vec3d::Zero();
}
#endif // ENABLE_EXTENDED_SELECTION
void GLGizmoMove3D::on_update(const Linef3& mouse_ray, const Point* mouse_pos)
{
#if ENABLE_EXTENDED_SELECTION
if (m_hover_id == 0)
m_displacement(0) = calc_projection(mouse_ray);
else if (m_hover_id == 1)
m_displacement(1) = calc_projection(mouse_ray);
else if (m_hover_id == 2)
m_displacement(2) = calc_projection(mouse_ray);
#else
if (m_hover_id == 0)
m_position(0) = 2.0 * m_starting_box_center(0) + calc_projection(X, 1, mouse_ray) - m_starting_drag_position(0);
else if (m_hover_id == 1)
m_position(1) = 2.0 * m_starting_box_center(1) + calc_projection(Y, 2, mouse_ray) - m_starting_drag_position(1);
else if (m_hover_id == 2)
m_position(2) = 2.0 * m_starting_box_bottom_center(2) + calc_projection(Z, 1, mouse_ray) - m_starting_drag_position(2);
#endif // ENABLE_EXTENDED_SELECTION
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoMove3D::on_render(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
#if ENABLE_EXTENDED_SELECTION
bool show_position = selection.is_single_full_instance();
const Vec3d& position = selection.get_bounding_box().center();
@ -1337,20 +1039,10 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
set_tooltip("Y: " + format(show_position ? position(1) : m_displacement(1), 2));
else if ((show_position && (m_hover_id == 2)) || m_grabbers[2].dragging)
set_tooltip("Z: " + format(show_position ? position(2) : m_displacement(2), 2));
#else
if (m_grabbers[0].dragging)
set_tooltip("X: " + format(m_position(0), 2));
else if (m_grabbers[1].dragging)
set_tooltip("Y: " + format(m_position(1), 2));
else if (m_grabbers[2].dragging)
set_tooltip("Z: " + format(m_position(2), 2));
#endif // ENABLE_EXTENDED_SELECTION
::glEnable(GL_DEPTH_TEST);
#if ENABLE_EXTENDED_SELECTION
const BoundingBoxf3& box = selection.get_bounding_box();
#endif // ENABLE_EXTENDED_SELECTION
const Vec3d& center = box.center();
// x axis
@ -1399,23 +1091,13 @@ void GLGizmoMove3D::on_render(const BoundingBoxf3& box) const
}
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoMove3D::on_render_for_picking(const GLCanvas3D::Selection& selection) const
{
::glDisable(GL_DEPTH_TEST);
render_grabbers_for_picking(selection.get_bounding_box());
}
#else
void GLGizmoMove3D::on_render_for_picking(const BoundingBoxf3& box) const
{
::glDisable(GL_DEPTH_TEST);
render_grabbers_for_picking(box);
}
#endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
double GLGizmoMove3D::calc_projection(const Linef3& mouse_ray) const
{
double projection = 0.0;
@ -1438,43 +1120,6 @@ double GLGizmoMove3D::calc_projection(const Linef3& mouse_ray) const
}
return projection;
}
#else
double GLGizmoMove3D::calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const
{
double projection = 0.0;
Vec3d starting_vec = (axis == Z) ? m_starting_drag_position - m_starting_box_bottom_center : m_starting_drag_position - m_starting_box_center;
double len_starting_vec = starting_vec.norm();
if (len_starting_vec == 0.0)
return projection;
Vec3d starting_vec_dir = starting_vec.normalized();
Vec3d mouse_dir = mouse_ray.unit_vector();
unsigned int plane_id = select_best_plane(mouse_dir, preferred_plane_id);
switch (plane_id)
{
case 0:
{
projection = starting_vec_dir.dot(intersection_on_plane_xy(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
case 1:
{
projection = starting_vec_dir.dot(intersection_on_plane_xz(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
case 2:
{
projection = starting_vec_dir.dot(intersection_on_plane_yz(mouse_ray, (axis == Z) ? m_starting_box_bottom_center : m_starting_box_center));
break;
}
}
return projection;
}
#endif // ENABLE_EXTENDED_SELECTION
GLGizmoFlatten::GLGizmoFlatten(GLCanvas3D& parent)
: GLGizmoBase(parent)
@ -1507,42 +1152,24 @@ std::string GLGizmoFlatten::on_get_name() const
return L("Flatten");
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoFlatten::on_start_dragging(const GLCanvas3D::Selection& selection)
#else
void GLGizmoFlatten::on_start_dragging(const BoundingBoxf3& box)
#endif // ENABLE_EXTENDED_SELECTION
{
if (m_hover_id != -1)
{
m_normal = m_planes[m_hover_id].normal;
#if ENABLE_EXTENDED_SELECTION
m_starting_center = selection.get_bounding_box().center();
#else
m_starting_center = box.center();
#endif // ENABLE_EXTENDED_SELECTION
}
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoFlatten::on_render(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
// 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.
Vec3d dragged_offset(Vec3d::Zero());
#if ENABLE_EXTENDED_SELECTION
if (m_starting_center == Vec3d::Zero())
m_starting_center = selection.get_bounding_box().center();
dragged_offset = selection.get_bounding_box().center() - m_starting_center;
#else
if (m_starting_center == Vec3d::Zero())
m_starting_center = box.center();
dragged_offset = box.center() - m_starting_center;
#endif // ENABLE_EXTENDED_SELECTION
::glEnable(GL_BLEND);
::glEnable(GL_DEPTH_TEST);
@ -1554,11 +1181,10 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
else
::glColor4f(0.9f, 0.9f, 0.9f, 0.5f);
#if ENABLE_EXTENDED_SELECTION
int instance_idx = selection.get_instance_idx();
if ((instance_idx != -1) && (m_model_object != nullptr))
{
Transform3d m = m_model_object->instances[instance_idx]->world_matrix();
Transform3d m = m_model_object->instances[instance_idx]->get_matrix();
m.pretranslate(dragged_offset);
::glPushMatrix();
::glMultMatrixd(m.data());
@ -1570,30 +1196,13 @@ void GLGizmoFlatten::on_render(const BoundingBoxf3& box) const
::glEnd();
::glPopMatrix();
}
#else
for (const InstanceData& inst : m_instances) {
Transform3d m = inst.matrix;
m.pretranslate(dragged_offset);
::glPushMatrix();
::glMultMatrixd(m.data());
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data());
::glEnd();
::glPopMatrix();
}
#endif // ENABLE_EXTENDED_SELECTION
}
::glEnable(GL_CULL_FACE);
::glDisable(GL_BLEND);
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoFlatten::on_render_for_picking(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
#endif // ENABLE_EXTENDED_SELECTION
{
::glEnable(GL_DEPTH_TEST);
::glDisable(GL_CULL_FACE);
@ -1601,12 +1210,11 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
for (unsigned int i = 0; i < m_planes.size(); ++i)
{
::glColor3f(1.0f, 1.0f, picking_color_component(i));
#if ENABLE_EXTENDED_SELECTION
int instance_idx = selection.get_instance_idx();
if ((instance_idx != -1) && (m_model_object != nullptr))
{
::glPushMatrix();
::glMultMatrixd(m_model_object->instances[instance_idx]->world_matrix().data());
::glMultMatrixd(m_model_object->instances[instance_idx]->get_matrix().data());
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
{
@ -1615,17 +1223,6 @@ void GLGizmoFlatten::on_render_for_picking(const BoundingBoxf3& box) const
::glEnd();
::glPopMatrix();
}
#else
for (const InstanceData& inst : m_instances) {
::glPushMatrix();
::glMultMatrixd(inst.matrix.data());
::glBegin(GL_POLYGON);
for (const Vec3d& vertex : m_planes[i].vertices)
::glVertex3dv(vertex.data());
::glEnd();
::glPopMatrix();
}
#endif // ENABLE_EXTENDED_SELECTION
}
::glEnable(GL_CULL_FACE);
@ -1636,15 +1233,6 @@ void GLGizmoFlatten::set_flattening_data(const ModelObject* model_object)
m_starting_center = Vec3d::Zero();
m_model_object = model_object;
#if !ENABLE_EXTENDED_SELECTION
// ...and save the updated positions of the object instances:
if (m_model_object && !m_model_object->instances.empty()) {
m_instances.clear();
for (const auto* instance : m_model_object->instances)
m_instances.emplace_back(instance->world_matrix());
}
#endif // !ENABLE_EXTENDED_SELECTION
if (is_plane_update_necessary())
update_planes();
}
@ -1851,7 +1439,7 @@ bool GLGizmoFlatten::is_plane_update_necessary() const
Vec3d GLGizmoFlatten::get_flattening_rotation() const
{
// calculates the rotations in model space, taking in account the scaling factors
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m = m_model_object->instances.front()->world_matrix(true, true).matrix().block(0, 0, 3, 3).inverse().transpose();
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m = m_model_object->instances.front()->get_matrix(true, true).matrix().block(0, 0, 3, 3).inverse().transpose();
Eigen::Quaterniond q;
Vec3d angles = Geometry::extract_euler_angles(q.setFromTwoVectors(m * m_normal, -Vec3d::UnitZ()).toRotationMatrix());
m_normal = Vec3d::Zero();
@ -1890,16 +1478,12 @@ void GLGizmoSlaSupports::set_model_object_ptr(ModelObject* model_object)
{
m_starting_center = Vec3d::Zero();
m_model_object = model_object;
m_model_object_matrix = model_object->instances.front()->world_matrix();
m_model_object_matrix = model_object->instances.front()->get_matrix();
if (is_mesh_update_necessary())
update_mesh();
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoSlaSupports::on_render(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const
#endif
{
::glEnable(GL_BLEND);
::glEnable(GL_DEPTH_TEST);
@ -1908,15 +1492,9 @@ void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const
// with the gizmo being on. This is reset in set_flattening_data and
// does not work correctly when there are multiple copies.
#if ENABLE_EXTENDED_SELECTION
if (m_starting_center == Vec3d::Zero())
m_starting_center = selection.get_bounding_box().center();
Vec3d dragged_offset = selection.get_bounding_box().center() - m_starting_center;
#else
if (m_starting_center == Vec3d::Zero())
m_starting_center = box.center();
Vec3d dragged_offset(box.center() - m_starting_center);
#endif // ENABLE_EXTENDED_SELECTION
for (auto& g : m_grabbers) {
g.color[0] = 1.f;
@ -1934,11 +1512,7 @@ void GLGizmoSlaSupports::on_render(const BoundingBoxf3& box) const
}
#if ENABLE_EXTENDED_SELECTION
void GLGizmoSlaSupports::on_render_for_picking(const GLCanvas3D::Selection& selection) const
#else
void GLGizmoSlaSupports::on_render_for_picking(const BoundingBoxf3& box) const
#endif
{
::glEnable(GL_DEPTH_TEST);
for (unsigned int i=0; i<m_grabbers.size(); ++i) {
@ -1986,13 +1560,7 @@ bool GLGizmoSlaSupports::is_mesh_update_necessary() const
if (m_state != On || !m_model_object || m_model_object->instances.empty())
return false;
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if ((m_model_object->instances.front()->world_matrix() * m_source_data.matrix.inverse() * Vec3d(1., 1., 1.) - Vec3d(1., 1., 1.)).norm() > 0.001 )
#else
if (m_model_object->instances.front()->get_scaling_factor() != m_source_data.scaling_factor
|| m_model_object->instances.front()->get_rotation() != m_source_data.rotation
|| m_model_object->instances.front()->get_offset() != m_source_data.offset)
#endif // ENABLE_MODELINSTANCE_3D_ROTATION
if ((m_model_object->instances.front()->get_matrix() * m_source_data.matrix.inverse() * Vec3d(1., 1., 1.) - Vec3d(1., 1., 1.)).norm() > 0.001)
return true;
// following should detect direct mesh changes (can be removed after the mesh is made completely immutable):
@ -2020,13 +1588,7 @@ void GLGizmoSlaSupports::update_mesh()
F(i, 1) = 3*i+1;
F(i, 2) = 3*i+2;
}
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_source_data.scaling_factor = m_model_object->instances.front()->get_scaling_factor();
m_source_data.rotation = m_model_object->instances.front()->get_rotation();
m_source_data.offset = m_model_object->instances.front()->get_offset();
#else
m_source_data.matrix = m_model_object->instances.front()->world_matrix();
#endif
m_source_data.matrix = m_model_object->instances.front()->get_matrix();
const float* first_vertex = m_model_object->volumes.front()->get_convex_hull().first_vertex();
m_source_data.mesh_first_point = Vec3d((double)first_vertex[0], (double)first_vertex[1], (double)first_vertex[2]);
// we'll now reload Grabbers (selection might have changed):
@ -2067,7 +1629,7 @@ Vec3f GLGizmoSlaSupports::unproject_on_mesh(const Vec2d& mouse_pos)
const Vec3f& b = m_V.row(m_F(fid, 1));
const Vec3f& c = m_V.row(m_F(fid, 2));
Vec3f point = bc(0)*a + bc(1)*b + bc(2)*c;
return m_model_object->instances.front()->world_matrix().inverse().cast<float>() * point;
return m_model_object->instances.front()->get_matrix().inverse().cast<float>() * point;
}
void GLGizmoSlaSupports::clicked_on_object(const Vec2d& mouse_position)

View File

@ -2,9 +2,7 @@
#define slic3r_GLGizmo_hpp_
#include "../../slic3r/GUI/GLTexture.hpp"
#if ENABLE_EXTENDED_SELECTION
#include "../../slic3r/GUI/GLCanvas3D.hpp"
#endif // ENABLE_EXTENDED_SELECTION
#include "../../libslic3r/Point.hpp"
#include "../../libslic3r/BoundingBox.hpp"
@ -82,9 +80,7 @@ public:
EState get_state() const { return m_state; }
void set_state(EState state) { m_state = state; on_set_state(); }
#if ENABLE_EXTENDED_SELECTION
bool is_activable(const GLCanvas3D::Selection& selection) const { return on_is_activable(selection); }
#endif // ENABLE_EXTENDED_SELECTION
unsigned int get_texture_id() const { return m_textures[m_state].get_id(); }
int get_textures_size() const { return m_textures[Off].get_width(); }
@ -97,11 +93,7 @@ public:
void enable_grabber(unsigned int id);
void disable_grabber(unsigned int id);
#if ENABLE_EXTENDED_SELECTION
void start_dragging(const GLCanvas3D::Selection& selection);
#else
void start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
void stop_dragging();
bool is_dragging() const { return m_dragging; }
@ -111,41 +103,25 @@ public:
void process_double_click() { on_process_double_click(); }
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
void render(const GLCanvas3D::Selection& selection) const { on_render(selection); }
void render_for_picking(const GLCanvas3D::Selection& selection) const { on_render_for_picking(selection); }
#else
void render(const BoundingBoxf3& box) const { on_render(box); }
void render_for_picking(const BoundingBoxf3& box) const { on_render_for_picking(box); }
#endif // ENABLE_EXTENDED_SELECTION
protected:
virtual bool on_init() = 0;
virtual std::string on_get_name() const = 0;
virtual void on_set_state() {}
virtual void on_set_hover_id() {}
#if ENABLE_EXTENDED_SELECTION
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return true; }
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_enable_grabber(unsigned int id) {}
virtual void on_disable_grabber(unsigned int id) {}
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection) {}
#else
virtual void on_start_dragging(const BoundingBoxf3& box) {}
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_stop_dragging() {}
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos) = 0;
#if ENABLE_GIZMOS_RESET
virtual void on_process_double_click() {}
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const = 0;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const = 0;
#else
virtual void on_render(const BoundingBoxf3& box) const = 0;
virtual void on_render_for_picking(const BoundingBoxf3& box) const = 0;
#endif // ENABLE_EXTENDED_SELECTION
float picking_color_component(unsigned int id) const;
void render_grabbers(const BoundingBoxf3& box) const;
@ -196,22 +172,13 @@ public:
protected:
virtual bool on_init();
virtual std::string on_get_name() const { return ""; }
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
#else
virtual void on_start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos);
#if ENABLE_GIZMOS_RESET
virtual void on_process_double_click() { m_angle = 0.0; }
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
private:
void render_circle() const;
@ -253,9 +220,7 @@ protected:
m_gizmos[i].set_hover_id((m_hover_id == i) ? 0 : -1);
}
}
#if ENABLE_EXTENDED_SELECTION
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return !selection.is_wipe_tower(); }
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_enable_grabber(unsigned int id)
{
if ((0 <= id) && (id < 3))
@ -266,11 +231,7 @@ protected:
if ((0 <= id) && (id < 3))
m_gizmos[id].disable_grabber(0);
}
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
#else
virtual void on_start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_stop_dragging();
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos)
{
@ -286,7 +247,6 @@ protected:
m_gizmos[m_hover_id].process_double_click();
}
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const
{
@ -295,24 +255,11 @@ protected:
g.render_for_picking(selection);
}
}
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const
{
for (const GLGizmoRotate& g : m_gizmos)
{
g.render_for_picking(box);
}
}
#endif // ENABLE_EXTENDED_SELECTION
};
class GLGizmoScale3D : public GLGizmoBase
{
static const float Offset;
#if !ENABLE_EXTENDED_SELECTION
static const Vec3d OffsetVec;
#endif // !ENABLE_EXTENDED_SELECTION
mutable BoundingBoxf3 m_box;
@ -326,34 +273,19 @@ public:
explicit GLGizmoScale3D(GLCanvas3D& parent);
const Vec3d& get_scale() const { return m_scale; }
#if ENABLE_EXTENDED_SELECTION
void set_scale(const Vec3d& scale) { m_starting_scale = scale; m_scale = scale; }
#else
void set_scale(const Vec3d& scale) { m_starting_scale = scale; }
#endif // ENABLE_EXTENDED_SELECTION
protected:
virtual bool on_init();
virtual std::string on_get_name() const;
#if ENABLE_EXTENDED_SELECTION
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return !selection.is_wipe_tower(); }
#endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
#else
virtual void on_start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos);
#if ENABLE_GIZMOS_RESET
virtual void on_process_double_click();
#endif // ENABLE_GIZMOS_RESET
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
private:
void render_grabbers_connection(unsigned int id_1, unsigned int id_2) const;
@ -363,22 +295,14 @@ private:
void do_scale_z(const Linef3& mouse_ray);
void do_scale_uniform(const Linef3& mouse_ray);
#if ENABLE_EXTENDED_SELECTION
double calc_ratio(const Linef3& mouse_ray) const;
#else
double calc_ratio(unsigned int preferred_plane_id, const Linef3& mouse_ray, const Vec3d& center) const;
#endif // ENABLE_EXTENDED_SELECTION
};
class GLGizmoMove3D : public GLGizmoBase
{
static const double Offset;
#if ENABLE_EXTENDED_SELECTION
Vec3d m_displacement;
#else
Vec3d m_position;
#endif // ENABLE_EXTENDED_SELECTION
Vec3d m_starting_drag_position;
Vec3d m_starting_box_center;
Vec3d m_starting_box_bottom_center;
@ -386,37 +310,19 @@ class GLGizmoMove3D : public GLGizmoBase
public:
explicit GLGizmoMove3D(GLCanvas3D& parent);
#if ENABLE_EXTENDED_SELECTION
const Vec3d& get_displacement() const { return m_displacement; }
#else
const Vec3d& get_position() const { return m_position; }
void set_position(const Vec3d& position) { m_position = position; }
#endif // ENABLE_EXTENDED_SELECTION
protected:
virtual bool on_init();
virtual std::string on_get_name() const;
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
virtual void on_stop_dragging();
#else
virtual void on_start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos);
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
private:
#if ENABLE_EXTENDED_SELECTION
double calc_projection(const Linef3& mouse_ray) const;
#else
double calc_projection(Axis axis, unsigned int preferred_plane_id, const Linef3& mouse_ray) const;
#endif // ENABLE_EXTENDED_SELECTION
};
class GLGizmoFlatten : public GLGizmoBase
@ -440,14 +346,6 @@ private:
SourceDataSummary m_source_data;
std::vector<PlaneData> m_planes;
#if !ENABLE_EXTENDED_SELECTION
struct InstanceData
{
Transform3d matrix;
InstanceData(const Transform3d& matrix) : matrix(matrix) {}
};
std::vector<InstanceData> m_instances;
#endif // !ENABLE_EXTENDED_SELECTION
mutable Vec3d m_starting_center;
const ModelObject* m_model_object = nullptr;
@ -463,22 +361,11 @@ public:
protected:
virtual bool on_init();
virtual std::string on_get_name() const;
#if ENABLE_EXTENDED_SELECTION
virtual bool on_is_activable(const GLCanvas3D::Selection& selection) const { return selection.is_single_full_instance(); }
#endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
virtual void on_start_dragging(const GLCanvas3D::Selection& selection);
#else
virtual void on_start_dragging(const BoundingBoxf3& box);
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_update(const Linef3& mouse_ray, const Point* mouse_pos) {}
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
virtual void on_set_state()
{
if (m_state == On && is_plane_update_necessary())
@ -497,13 +384,7 @@ private:
Eigen::MatrixXi m_F; // facets indices
struct SourceDataSummary {
BoundingBoxf3 bounding_box;
#if !ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
Vec3d scaling_factor;
Vec3d rotation;
Vec3d offset;
#else
Transform3d matrix;
#endif
Vec3d mesh_first_point;
};
@ -521,13 +402,8 @@ public:
private:
bool on_init();
void on_update(const Linef3& mouse_ray, const Point* mouse_pos);
#if ENABLE_EXTENDED_SELECTION
virtual void on_render(const GLCanvas3D::Selection& selection) const;
virtual void on_render_for_picking(const GLCanvas3D::Selection& selection) const;
#else
virtual void on_render(const BoundingBoxf3& box) const;
virtual void on_render_for_picking(const BoundingBoxf3& box) const;
#endif // ENABLE_EXTENDED_SELECTION
void render_grabbers(bool picking = false) const;
void render_tooltip_texture() const;

View File

@ -25,13 +25,7 @@ wxDEFINE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SPLIT_OBJECTS, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_SPLIT_VOLUMES, SimpleEvent);
wxDEFINE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDEFINE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
wxDEFINE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDEFINE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
GLToolbarItem::Data::Data()

View File

@ -25,13 +25,7 @@ wxDECLARE_EVENT(EVT_GLTOOLBAR_FEWER, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT_OBJECTS, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_SPLIT_VOLUMES, SimpleEvent);
wxDECLARE_EVENT(EVT_GLTOOLBAR_CUT, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLTOOLBAR_SETTINGS, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLTOOLBAR_LAYERSEDITING, SimpleEvent);
#if !ENABLE_EXTENDED_SELECTION
wxDECLARE_EVENT(EVT_GLTOOLBAR_SELECTBYPARTS, SimpleEvent);
#endif // !ENABLE_EXTENDED_SELECTION
class GLToolbarItem
{

View File

@ -18,6 +18,8 @@ namespace Slic3r
namespace GUI
{
wxDEFINE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
ObjectList::ObjectList(wxWindow* parent) :
wxDataViewCtrl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxDV_MULTIPLE)
{
@ -234,6 +236,13 @@ void ObjectList::selection_changed()
// update object selection on Plater
update_selections_on_canvas();
// to update the toolbar and info sizer
if (!GetSelection() || m_objects_model->GetItemType(GetSelection()) == itObject) {
auto event = SimpleEvent(EVT_OBJ_LIST_OBJECT_SELECT);
event.SetEventObject(this);
wxPostEvent(this, event);
}
part_selection_changed();
#ifdef __WXOSX__
@ -720,10 +729,7 @@ void ObjectList::load_part( ModelObject* model_object,
part_names.Add(new_volume->name);
if (delta != Vec3d::Zero())
{
new_volume->mesh.translate((float)delta(0), (float)delta(1), (float)delta(2));
new_volume->get_convex_hull().translate((float)delta(0), (float)delta(1), (float)delta(2));
}
new_volume->translate(delta);
// set a default extruder value, since user can't add it manually
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
@ -960,10 +966,8 @@ void ObjectList::split(const bool split_part)
m_parts_changed = true;
parts_changed(m_selected_object_id);
#if ENABLE_EXTENDED_SELECTION
// restores selection
_3DScene::get_canvas(wxGetApp().canvas3D())->get_selection().add_object(m_selected_object_id);
#endif // ENABLE_EXTENDED_SELECTION
}
bool ObjectList::get_volume_by_item(const bool split_part, const wxDataViewItem& item, ModelVolume*& volume)
@ -1071,11 +1075,7 @@ void ObjectList::part_selection_changed()
m_selected_object_id = obj_idx;
#if ENABLE_EXTENDED_SELECTION
wxGetApp().obj_manipul()->update_settings_value(_3DScene::get_canvas(wxGetApp().canvas3D())->get_selection());
#else
wxGetApp().obj_manipul()->update_values();
#endif // ENABLE_EXTENDED_SELECTION
}
void ObjectList::update_manipulation_sizer(const bool is_simple_mode)
@ -1094,9 +1094,6 @@ void ObjectList::add_object_to_list(size_t obj_idx)
auto model_object = (*m_objects)[obj_idx];
wxString item_name = model_object->name;
auto item = m_objects_model->Add(item_name);
#if !ENABLE_EXTENDED_SELECTION
/*Select*/select_item(item);
#endif // !ENABLE_EXTENDED_SELECTION
// Add error icon if detected auto-repaire
auto stats = model_object->volumes[0]->mesh.stl.stats;
@ -1224,7 +1221,6 @@ bool ObjectList::multiple_selection() const
void ObjectList::update_selections()
{
#if ENABLE_EXTENDED_SELECTION
auto& selection = _3DScene::get_canvas(wxGetApp().canvas3D())->get_selection();
wxDataViewItemArray sels;
@ -1234,13 +1230,10 @@ void ObjectList::update_selections()
sels.Add(m_objects_model->GetItemByVolumeId(gl_vol->object_idx(), gl_vol->volume_idx()));
}
select_items(sels);
#endif // ENABLE_EXTENDED_SELECTION
}
void ObjectList::update_selections_on_canvas()
{
#if ENABLE_EXTENDED_SELECTION
auto& selection = _3DScene::get_canvas(wxGetApp().canvas3D())->get_selection();
const int sel_cnt = GetSelectedItemsCount();
@ -1288,8 +1281,6 @@ void ObjectList::update_selections_on_canvas()
add_to_selection(item, selection, false);
_3DScene::render(wxGetApp().canvas3D());
#endif // ENABLE_EXTENDED_SELECTION
}
void ObjectList::select_item(const wxDataViewItem& item)

View File

@ -5,6 +5,7 @@
#include <wx/dataview.h>
#include <map>
#include <vector>
#include "Event.hpp"
class wxBoxSizer;
class PrusaObjectDataViewModel;
@ -17,6 +18,8 @@ class ModelVolume;
namespace GUI {
wxDECLARE_EVENT(EVT_OBJ_LIST_OBJECT_SELECT, SimpleEvent);
class ObjectList : public wxDataViewCtrl
{
wxBoxSizer *m_sizer {nullptr};

View File

@ -266,7 +266,6 @@ void ObjectManipulation::update_settings_list()
parent->GetParent()->Layout();
}
#if ENABLE_EXTENDED_SELECTION
void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& selection)
{
if (selection.is_single_full_object())
@ -344,7 +343,6 @@ void ObjectManipulation::reset_scale_value()
m_og->set_value("scale_y", 100);
m_og->set_value("scale_z", 100);
}
#endif // ENABLE_EXTENDED_SELECTION
void ObjectManipulation::update_values()
{

View File

@ -6,9 +6,7 @@
#include <wx/panel.h>
#include "Preset.hpp"
#if ENABLE_EXTENDED_SELECTION
#include "GLCanvas3D.hpp"
#endif // ENABLE_EXTENDED_SELECTION
class wxBoxSizer;
@ -16,7 +14,6 @@ namespace Slic3r {
namespace GUI {
class ConfigOptionsGroup;
class OG_Settings
{
protected:
@ -47,13 +44,11 @@ public:
int ol_selection();
void update_settings_list();
#if ENABLE_EXTENDED_SELECTION
void update_settings_value(const GLCanvas3D::Selection& selection);
void reset_settings_value();
void reset_position_value();
void reset_rotation_value();
void reset_scale_value();
#endif // ENABLE_EXTENDED_SELECTION
void update_values();
// update position values displacements or "gizmos"

View File

@ -85,12 +85,13 @@ public:
ObjectInfo(wxWindow *parent);
wxStaticBitmap *manifold_warning_icon;
private:
wxStaticText *info_size;
wxStaticText *info_volume;
wxStaticText *info_facets;
wxStaticText *info_materials;
wxStaticText *info_manifold;
bool showing_manifold_warning_icon;
void show_sizer(bool show);
};
ObjectInfo::ObjectInfo(wxWindow *parent) :
@ -112,12 +113,13 @@ ObjectInfo::ObjectInfo(wxWindow *parent) :
grid_sizer->Add(*info_label, 0);
};
init_info_label(&info_size, _(L("Size")));
init_info_label(&info_volume, _(L("Volume")));
init_info_label(&info_facets, _(L("Facets")));
init_info_label(&info_materials, _(L("Materials")));
init_info_label(&info_size, _(L("Size:")));
init_info_label(&info_volume, _(L("Volume:")));
init_info_label(&info_facets, _(L("Facets:")));
init_info_label(&info_materials, _(L("Materials:")));
Add(grid_sizer, 0, wxEXPAND);
auto *info_manifold_text = new wxStaticText(parent, wxID_ANY, _(L("Manifold")));
auto *info_manifold_text = new wxStaticText(parent, wxID_ANY, _(L("Manifold:")));
info_manifold_text->SetFont(wxGetApp().small_font());
info_manifold = new wxStaticText(parent, wxID_ANY, "");
info_manifold->SetFont(wxGetApp().small_font());
@ -127,9 +129,14 @@ ObjectInfo::ObjectInfo(wxWindow *parent) :
sizer_manifold->Add(info_manifold_text, 0);
sizer_manifold->Add(manifold_warning_icon, 0, wxLEFT, 2);
sizer_manifold->Add(info_manifold, 0, wxLEFT, 2);
grid_sizer->Add(sizer_manifold, 0, wxEXPAND | wxTOP, 4);
Add(sizer_manifold, 0, wxEXPAND | wxTOP, 4);
}
Add(grid_sizer, 0, wxEXPAND);
void ObjectInfo::show_sizer(bool show)
{
Show(show);
if (show)
manifold_warning_icon->Show(showing_manifold_warning_icon && show);
}
enum SlisedInfoIdx
@ -432,10 +439,6 @@ struct Sidebar::priv
priv(Plater *plater) : plater(plater) {}
bool show_manifold_warning_icon = false;
bool show_print_info = false;
void show_preset_comboboxes();
};
@ -663,15 +666,63 @@ void Sidebar::update_objects_list_extruder_column(int extruders_count)
void Sidebar::show_info_sizers(const bool show)
{
p->object_info->Show(show);
p->object_info->manifold_warning_icon->Show(show && p->show_manifold_warning_icon); // where is g_show_manifold_warning_icon updating? #ys_FIXME
// p->sliced_info->Show(show && p->show_print_info);
p->object_info->show_sizer(show);
}
void Sidebar::show_info_sizer()
{
wxWindowUpdateLocker freeze_guard(p->plater);
int obj_idx = p->plater->get_selected_object_idx();
if (obj_idx < 0) {
p->object_info->Show(false);
return;
}
const ModelObject* model_object = (*wxGetApp().model_objects())[obj_idx];
const ModelInstance* model_instance = !model_object->instances.empty() ? model_object->instances.front() : nullptr;
auto size = model_object->instance_bounding_box(0).size();
p->object_info->info_size->SetLabel(wxString::Format("%.2f x %.2f x %.2f",size(0), size(1), size(2)));
p->object_info->info_materials->SetLabel(wxString::Format("%d", static_cast<int>(model_object->materials_count())));
auto& stats = model_object->volumes[0]->mesh.stl.stats;
auto sf = model_instance->get_scaling_factor();
p->object_info->info_volume->SetLabel(wxString::Format("%.2f", stats.volume * sf(0) * sf(1) * sf(2)));
p->object_info->info_facets->SetLabel(wxString::Format(_(L("%d (%d shells)")), static_cast<int>(model_object->facets_count()), stats.number_of_parts));
int errors = stats.degenerate_facets + stats.edges_fixed + stats.facets_removed +
stats.facets_added + stats.facets_reversed + stats.backwards_edges;
if (errors > 0) {
wxString tooltip = wxString::Format(_(L("Auto-repaired (%d errors)")), errors);
p->object_info->info_manifold->SetLabel(tooltip);
tooltip += wxString::Format(_(L(":\n%d degenerate facets, %d edges fixed, %d facets removed, "
"%d facets added, %d facets reversed, %d backwards edges")),
stats.degenerate_facets, stats.edges_fixed, stats.facets_removed,
stats.facets_added, stats.facets_reversed, stats.backwards_edges);
p->object_info->showing_manifold_warning_icon = true;
p->object_info->info_manifold->SetToolTip(tooltip);
p->object_info->manifold_warning_icon->SetToolTip(tooltip);
}
else {
p->object_info->info_manifold->SetLabel(L("Yes"));
p->object_info->showing_manifold_warning_icon = false;
p->object_info->info_manifold->SetToolTip("");
p->object_info->manifold_warning_icon->SetToolTip("");
}
p->object_info->show_sizer(true);
p->scrolled->Layout();
p->plater->Layout();
}
void Sidebar::show_sliced_info_sizer(const bool show)
{
p->plater->Freeze();
// p->show_print_info = show;
wxWindowUpdateLocker freeze_guard(p->plater);
p->sliced_info->Show(show);
if (show) {
const PrintStatistics& ps = p->plater->print().print_statistics();
@ -701,7 +752,6 @@ void Sidebar::show_sliced_info_sizer(const bool show)
p->scrolled->Layout();
p->plater->Layout();
p->plater->Thaw();
}
void Sidebar::show_buttons(const bool show)
@ -754,18 +804,6 @@ std::vector<PresetComboBox*>& Sidebar::combos_filament()
return p->combos_filament;
}
#if !ENABLE_EXTENDED_SELECTION
// Plater::Object
struct PlaterObject
{
std::string name;
bool selected;
PlaterObject(std::string name) : name(std::move(name)), selected(false) {}
};
#endif // !ENABLE_EXTENDED_SELECTION
// Plater::DropTarget
class PlaterDropTarget : public wxFileDropTarget
@ -817,9 +855,6 @@ struct Plater::priv
Slic3r::Print print;
Slic3r::Model model;
Slic3r::GCodePreviewData gcode_preview_data;
#if !ENABLE_EXTENDED_SELECTION
std::vector<PlaterObject> objects;
#endif // !ENABLE_EXTENDED_SELECTION
// GUI elements
wxNotebook *notebook;
@ -835,9 +870,6 @@ struct Plater::priv
priv(Plater *q, MainFrame *main_frame);
#if !ENABLE_EXTENDED_SELECTION
std::vector<int> collect_selections();
#endif // !ENABLE_EXTENDED_SELECTION
void update(bool force_autocenter = false);
void select_view(const std::string& direction);
void update_ui_from_settings();
@ -849,30 +881,15 @@ struct Plater::priv
std::vector<size_t> load_model_objects(const ModelObjectPtrs &model_objects);
std::unique_ptr<CheckboxFileDialog> get_export_file(GUI::FileType file_type);
#if ENABLE_EXTENDED_SELECTION
const GLCanvas3D::Selection& get_selection() const;
GLCanvas3D::Selection& get_selection();
int get_selected_object_idx() const;
#else
void select_object(optional<size_t> obj_idx);
void select_object_from_cpp();
optional<size_t> selected_object() const;
#endif // ENABLE_EXTENDED_SELECTION
void selection_changed();
void object_list_changed();
#if !ENABLE_EXTENDED_SELECTION
void select_view();
#endif // !ENABLE_EXTENDED_SELECTION
void remove(size_t obj_idx);
void reset();
#if !ENABLE_EXTENDED_SELECTION
void rotate();
#endif // !ENABLE_EXTENDED_SELECTION
void mirror(Axis axis);
#if !ENABLE_EXTENDED_SELECTION
void scale();
#endif // !ENABLE_EXTENDED_SELECTION
void arrange();
void split_object();
void split_volume();
@ -896,25 +913,12 @@ struct Plater::priv
void on_action_split_objects(SimpleEvent&);
void on_action_split_volumes(SimpleEvent&);
void on_action_cut(SimpleEvent&);
#if !ENABLE_EXTENDED_SELECTION
void on_action_settings(SimpleEvent&);
#endif // !ENABLE_EXTENDED_SELECTION
void on_action_layersediting(SimpleEvent&);
#if !ENABLE_EXTENDED_SELECTION
void on_action_selectbyparts(SimpleEvent&);
#endif // !ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
void on_object_select(SimpleEvent&);
#else
void on_object_select(ObjectSelectEvent&);
#endif // ENABLE_EXTENDED_SELECTION
void on_viewport_changed(SimpleEvent&);
void on_right_click(Vec2dEvent&);
void on_model_update(SimpleEvent&);
#if !ENABLE_EXTENDED_SELECTION
void on_scale_uniformly(SimpleEvent&);
#endif // !ENABLE_EXTENDED_SELECTION
void on_wipetower_moved(Vec3dEvent&);
void on_enable_action_buttons(Event<bool>&);
void on_update_geometry(Vec3dsEvent<2>&);
@ -922,7 +926,6 @@ struct Plater::priv
private:
bool init_object_menu();
#if ENABLE_EXTENDED_SELECTION
bool can_delete_object() const;
bool can_increase_instances() const;
bool can_decrease_instances() const;
@ -932,10 +935,7 @@ private:
bool layers_height_allowed() const;
bool can_delete_all() const;
bool can_arrange() const;
#if ENABLE_MIRROR
bool can_mirror() const;
#endif // ENABLE_MIRROR
#endif // ENABLE_EXTENDED_SELECTION
};
const std::regex Plater::priv::pattern_bundle(".*[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)", std::regex::icase);
@ -978,10 +978,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
_3DScene::enable_picking(canvas3D, true);
_3DScene::enable_moving(canvas3D, true);
// XXX: more config from 3D.pm
#if !ENABLE_EXTENDED_SELECTION
_3DScene::set_select_by(canvas3D, "object");
_3DScene::set_drag_by(canvas3D, "instance");
#endif // !ENABLE_EXTENDED_SELECTION
_3DScene::set_model(canvas3D, &model);
_3DScene::set_print(canvas3D, &print);
_3DScene::set_config(canvas3D, config);
@ -1015,21 +1011,16 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
// Preset change event
sidebar->Bind(wxEVT_COMBOBOX, &priv::on_select_preset, this);
sidebar->Bind(EVT_OBJ_LIST_OBJECT_SELECT, [this](wxEvent&) { priv::selection_changed(); });
// 3DScene events:
canvas3D->Bind(EVT_GLCANVAS_SCHEDULE_BACKGROUND_PROCESS, &priv::on_schedule_background_process, this);
canvas3D->Bind(EVT_GLCANVAS_OBJECT_SELECT, &priv::on_object_select, this);
canvas3D->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
#if !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLCANVAS_DOUBLE_CLICK, [](SimpleEvent&) {}); // XXX: remove?
#endif // !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLCANVAS_RIGHT_CLICK, &priv::on_right_click, this);
canvas3D->Bind(EVT_GLCANVAS_MODEL_UPDATE, &priv::on_model_update, this);
canvas3D->Bind(EVT_GLCANVAS_REMOVE_OBJECT, [q](SimpleEvent&) { q->remove_selected(); });
canvas3D->Bind(EVT_GLCANVAS_ARRANGE, [this](SimpleEvent&) { arrange(); });
#if !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLCANVAS_ROTATE_OBJECT, [this](Event<int> &evt) { /*TODO: call rotate */ });
canvas3D->Bind(EVT_GLCANVAS_SCALE_UNIFORMLY, [this](SimpleEvent&) { this->scale(); });
#endif // !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLCANVAS_INCREASE_INSTANCES, [q](Event<int> &evt) { evt.data == 1 ? q->increase_instances() : q->decrease_instances(); });
canvas3D->Bind(EVT_GLCANVAS_INSTANCE_MOVED, [this](SimpleEvent&) { update(); });
canvas3D->Bind(EVT_GLCANVAS_WIPETOWER_MOVED, &priv::on_wipetower_moved, this);
@ -1045,13 +1036,7 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
canvas3D->Bind(EVT_GLTOOLBAR_SPLIT_OBJECTS, &priv::on_action_split_objects, this);
canvas3D->Bind(EVT_GLTOOLBAR_SPLIT_VOLUMES, &priv::on_action_split_volumes, this);
canvas3D->Bind(EVT_GLTOOLBAR_CUT, &priv::on_action_cut, this);
#if !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLTOOLBAR_SETTINGS, &priv::on_action_settings, this);
#endif // !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLTOOLBAR_LAYERSEDITING, &priv::on_action_layersediting, this);
#if !ENABLE_EXTENDED_SELECTION
canvas3D->Bind(EVT_GLTOOLBAR_SELECTBYPARTS, &priv::on_action_selectbyparts, this);
#endif // !ENABLE_EXTENDED_SELECTION
// Preview events:
preview->get_wxglcanvas()->Bind(EVT_GLCANVAS_VIEWPORT_CHANGED, &priv::on_viewport_changed, this);
@ -1066,17 +1051,6 @@ Plater::priv::priv(Plater *q, MainFrame *main_frame) :
q->Layout();
}
#if !ENABLE_EXTENDED_SELECTION
std::vector<int> Plater::priv::collect_selections()
{
std::vector<int> res;
for (const auto &obj : objects) {
res.push_back(obj.selected);
}
return res;
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::update(bool force_autocenter)
{
wxWindowUpdateLocker freeze_guard(q);
@ -1088,10 +1062,6 @@ void Plater::priv::update(bool force_autocenter)
model.center_instances_around_point(bed_center);
}
#if !ENABLE_EXTENDED_SELECTION
const auto selections = collect_selections();
_3DScene::set_objects_selections(canvas3D, selections);
#endif // !ENABLE_EXTENDED_SELECTION
_3DScene::reload_scene(canvas3D, false);
preview->reset_gcode_preview_data();
preview->reload_print();
@ -1263,19 +1233,12 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
bool need_arrange = false;
bool scaled_down = false;
std::vector<size_t> obj_idxs;
#if ENABLE_EXTENDED_SELECTION
unsigned int obj_count = model.objects.size();
#endif // ENABLE_EXTENDED_SELECTION
for (ModelObject *model_object : model_objects) {
auto *object = model.add_object(*model_object);
std::string object_name = object->name.empty() ? fs::path(object->input_file).filename().string() : object->name;
#if ENABLE_EXTENDED_SELECTION
obj_idxs.push_back(obj_count++);
#else
objects.emplace_back(std::move(object_name));
obj_idxs.push_back(objects.size() - 1);
#endif // ENABLE_EXTENDED_SELECTION
if (model_object->instances.empty()) {
// if object has no defined position(s) we need to rearrange everything after loading
@ -1387,7 +1350,6 @@ std::unique_ptr<CheckboxFileDialog> Plater::priv::get_export_file(GUI::FileType
return dlg;
}
#if ENABLE_EXTENDED_SELECTION
const GLCanvas3D::Selection& Plater::priv::get_selection() const
{
return _3DScene::get_canvas(canvas3D)->get_selection();
@ -1403,43 +1365,9 @@ int Plater::priv::get_selected_object_idx() const
int idx = get_selection().get_object_idx();
return ((0 <= idx) && (idx < 1000)) ? idx : -1;
}
#else
void Plater::priv::select_object(optional<size_t> obj_idx)
{
for (auto &obj : objects) {
obj.selected = false;
}
if (obj_idx) {
objects[*obj_idx].selected = true;
}
selection_changed();
}
void Plater::priv::select_object_from_cpp()
{
// TODO
}
optional<size_t> Plater::priv::selected_object() const
{
for (size_t i = 0; i < objects.size(); i++) {
if (objects[i].selected) { return i; }
}
return boost::none;
}
#endif // ENABLE_EXTENDED_SELECTION
void Plater::priv::selection_changed()
{
#if !ENABLE_EXTENDED_SELECTION
const auto obj_idx = selected_object();
const bool have_sel = !!obj_idx;
#endif // !ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
_3DScene::enable_toolbar_item(canvas3D, "delete", can_delete_object());
_3DScene::enable_toolbar_item(canvas3D, "more", can_increase_instances());
_3DScene::enable_toolbar_item(canvas3D, "fewer", can_decrease_instances());
@ -1449,117 +1377,23 @@ void Plater::priv::selection_changed()
_3DScene::enable_toolbar_item(canvas3D, "layersediting", layers_height_allowed());
// forces a frame render to update the view (to avoid a missed update if, for example, the context menu appears)
_3DScene::render(canvas3D);
#else
_3DScene::enable_toolbar_item(canvas3D, "fewer", have_sel);
_3DScene::enable_toolbar_item(canvas3D, "splitobjects", have_sel);
_3DScene::enable_toolbar_item(canvas3D, "splitvolumes", have_sel);
_3DScene::enable_toolbar_item(canvas3D, "cut", have_sel);
_3DScene::enable_toolbar_item(canvas3D, "settings", have_sel);
_3DScene::enable_toolbar_item(canvas3D, "layersediting", have_sel && config->opt_bool("variable_layer_height") && _3DScene::is_layers_editing_allowed(canvas3D));
#endif // ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
int obj_idx = get_selected_object_idx();
bool have_sel = (obj_idx != -1);
#else
bool can_select_by_parts = false;
if (have_sel) {
const auto *model_object = model.objects[*obj_idx];
// XXX: ?
can_select_by_parts = *obj_idx < 1000 && model_object->volumes.size() > 1;
_3DScene::enable_toolbar_item(canvas3D, "fewer", model_object->instances.size() > 1);
}
if (can_select_by_parts) {
// first disable to let the item in the toolbar to switch to the unpressed state // XXX: ?
_3DScene::enable_toolbar_item(canvas3D, "selectbyparts", false);
_3DScene::enable_toolbar_item(canvas3D, "selectbyparts", true);
} else {
_3DScene::enable_toolbar_item(canvas3D, "selectbyparts", false);
_3DScene::set_select_by(canvas3D, "object");
}
#endif // ENABLE_EXTENDED_SELECTION
wxWindowUpdateLocker freeze_guard(sidebar);
if (have_sel) {
#if ENABLE_EXTENDED_SELECTION
const ModelObject* model_object = model.objects[obj_idx];
#else
const auto *model_object = model.objects[*obj_idx];
#endif // ENABLE_EXTENDED_SELECTION
// FIXME print_info runs model fixing in two rounds, it is very slow, it should not be performed here!
// # $model_object->print_info;
const ModelInstance* model_instance = !model_object->instances.empty() ? model_object->instances.front() : nullptr;
// TODO
// $self->{object_info_size}->SetLabel(sprintf("%.2f x %.2f x %.2f", @{$model_object->instance_bounding_box(0)->size}));
// $self->{object_info_materials}->SetLabel($model_object->materials_count);
// if (my $stats = $model_object->mesh_stats) {
// $self->{object_info_volume}->SetLabel(sprintf('%.2f', $stats->{volume} * ($model_instance->scaling_factor**3)));
// $self->{object_info_facets}->SetLabel(sprintf(L('%d (%d shells)'), $model_object->facets_count, $stats->{number_of_parts}));
// if (my $errors = sum(@$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)})) {
// $self->{object_info_manifold}->SetLabel(sprintf(L("Auto-repaired (%d errors)"), $errors));
// #$self->{object_info_manifold_warning_icon}->Show;
// $self->{"object_info_manifold_warning_icon_show"}->(1);
// # we don't show normals_fixed because we never provide normals
// # to admesh, so it generates normals for all facets
// my $message = sprintf L('%d degenerate facets, %d edges fixed, %d facets removed, %d facets added, %d facets reversed, %d backwards edges'),
// @$stats{qw(degenerate_facets edges_fixed facets_removed facets_added facets_reversed backwards_edges)};
// $self->{object_info_manifold}->SetToolTipString($message);
// $self->{object_info_manifold_warning_icon}->SetToolTipString($message);
// } else {
// $self->{object_info_manifold}->SetLabel(L("Yes"));
// #$self->{object_info_manifold_warning_icon}->Hide;
// $self->{"object_info_manifold_warning_icon_show"}->(0);
// $self->{object_info_manifold}->SetToolTipString("");
// $self->{object_info_manifold_warning_icon}->SetToolTipString("");
// }
// } else {
// $self->{object_info_facets}->SetLabel($object->facets);
// }
} else {
// $self->{"object_info_$_"}->SetLabel("") for qw(size volume facets materials manifold);
// $self->{"object_info_manifold_warning_icon_show"}->(0);
// $self->{object_info_manifold}->SetToolTipString("");
// $self->{object_info_manifold_warning_icon}->SetToolTipString("");
}
q->Layout();
sidebar->show_info_sizer();
}
void Plater::priv::object_list_changed()
{
// Enable/disable buttons depending on whether there are any objects on the platter.
#if ENABLE_EXTENDED_SELECTION
_3DScene::enable_toolbar_item(canvas3D, "deleteall", can_delete_all());
_3DScene::enable_toolbar_item(canvas3D, "arrange", can_arrange());
#else
const bool have_objects = !objects.empty();
_3DScene::enable_toolbar_item(canvas3D, "deleteall", have_objects);
_3DScene::enable_toolbar_item(canvas3D, "arrange", have_objects);
#endif // ENABLE_EXTENDED_SELECTION
const bool export_in_progress = this->background_process.is_export_scheduled(); // || ! send_gcode_file.empty());
// XXX: is this right?
const bool model_fits = _3DScene::check_volumes_outside_state(canvas3D, config) == ModelInstance::PVS_Inside;
#if ENABLE_EXTENDED_SELECTION
sidebar->enable_buttons(!model.objects.empty() && !export_in_progress && model_fits);
#else
sidebar->enable_buttons(have_objects && !export_in_progress && model_fits);
#endif // ENABLE_EXTENDED_SELECTION
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::select_view()
{
// TODO
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::remove(size_t obj_idx)
{
// Prevent toolpaths preview from rendering while we modify the Print object
@ -1568,19 +1402,12 @@ void Plater::priv::remove(size_t obj_idx)
if (_3DScene::is_layers_editing_enabled(canvas3D))
_3DScene::enable_layers_editing(canvas3D, false);
#if !ENABLE_EXTENDED_SELECTION
objects.erase(objects.begin() + obj_idx);
#endif // !ENABLE_EXTENDED_SELECTION
model.delete_object(obj_idx);
// print.delete_object(obj_idx);
// Delete object from Sidebar list
sidebar->obj_list()->delete_object_from_list(obj_idx);
object_list_changed();
#if !ENABLE_EXTENDED_SELECTION
select_object(boost::none);
#endif // !ENABLE_EXTENDED_SELECTION
update();
}
@ -1592,72 +1419,20 @@ void Plater::priv::reset()
if (_3DScene::is_layers_editing_enabled(canvas3D))
_3DScene::enable_layers_editing(canvas3D, false);
#if !ENABLE_EXTENDED_SELECTION
objects.clear();
#endif // !ENABLE_EXTENDED_SELECTION
model.clear_objects();
// print.clear_objects();
// Delete all objects from list on c++ side
sidebar->obj_list()->delete_all_objects_from_list();
object_list_changed();
#if !ENABLE_EXTENDED_SELECTION
select_object(boost::none);
#endif // !ENABLE_EXTENDED_SELECTION
update();
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::rotate()
{
// TODO
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::mirror(Axis axis)
{
#if ENABLE_MIRROR
#if ENABLE_EXTENDED_SELECTION
_3DScene::mirror_selection(canvas3D, axis);
#endif // ENABLE_EXTENDED_SELECTION
#else
#if ENABLE_EXTENDED_SELECTION
int obj_idx = get_selected_object_idx();
if (obj_idx == -1)
return;
ModelObject* model_object = model.objects[obj_idx];
ModelInstance* model_instance = model_object->instances.front();
#else
const auto obj_idx = selected_object();
if (! obj_idx) { return; }
auto *model_object = model.objects[*obj_idx];
auto *model_instance = model_object->instances[0];
#endif // ENABLE_EXTENDED_SELECTION
// XXX: ?
// # apply Z rotation before mirroring
// if ($model_instance->rotation != 0) {
// $model_object->rotate($model_instance->rotation, Slic3r::Pointf3->new(0, 0, 1));
// $_->set_rotation(0) for @{ $model_object->instances };
// }
model_object->mirror(axis);
selection_changed();
update();
#endif // ENABLE_MIRROR
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::scale()
{
// TODO
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::arrange()
{
main_frame->app_controller()->arrange_model();
@ -1670,7 +1445,6 @@ void Plater::priv::arrange()
void Plater::priv::split_object()
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = get_selected_object_idx();
if (obj_idx == -1)
return;
@ -1714,7 +1488,6 @@ void Plater::priv::split_object()
get_selection().add_object((unsigned int)idx, false);
}
}
#endif // ENABLE_EXTENDED_SELECTION
}
void Plater::priv::split_volume()
@ -1754,11 +1527,9 @@ void Plater::priv::async_apply_config()
this->preview->reload_print();
// We also need to reload 3D scene because of the wipe tower preview box
if (this->config->opt_bool("wipe_tower")) {
#if !ENABLE_EXTENDED_SELECTION
std::vector<int> selections = this->collect_selections();
Slic3r::_3DScene::set_objects_selections(this->canvas3D, selections);
Slic3r::_3DScene::reload_scene(this->canvas3D, 1);
#endif /* !ENABLE_EXTENDED_SELECTION */
// std::vector<int> selections = this->collect_selections();
// Slic3r::_3DScene::set_objects_selections(this->canvas3D, selections);
// Slic3r::_3DScene::reload_scene(this->canvas3D, 1);
}
}
if (invalidated != Print::APPLY_STATUS_UNCHANGED && this->get_config("background_processing") == "1" &&
@ -1832,9 +1603,6 @@ void Plater::priv::on_notebook_changed(wxBookCtrlEvent&)
const auto current_id = notebook->GetCurrentPage()->GetId();
if (current_id == canvas3D->GetId()) {
if (_3DScene::is_reload_delayed(canvas3D)) {
#if !ENABLE_EXTENDED_SELECTION
_3DScene::set_objects_selections(canvas3D, collect_selections());
#endif // !ENABLE_EXTENDED_SELECTION
_3DScene::reload_scene(canvas3D, true);
}
// sets the canvas as dirty to force a render at the 1st idle event (wxWidgets IsShownOnScreen() is buggy and cannot be used reliably)
@ -1896,12 +1664,10 @@ void Plater::priv::on_update_print_preview(wxCommandEvent &)
if (this->preview != nullptr)
this->preview->reload_print();
// in case this was MM print, wipe tower bounding box on 3D tab might need redrawing with exact depth:
#if !ENABLE_EXTENDED_SELECTION
auto selections = collect_selections();
_3DScene::set_objects_selections(canvas3D, selections);
if (canvas3D)
_3DScene::reload_scene(canvas3D, true);
#endif // !ENABLE_EXTENDED_SELECTION
// auto selections = collect_selections();
// _3DScene::set_objects_selections(canvas3D, selections);
// if (canvas3D)
// _3DScene::reload_scene(canvas3D, true);
}
void Plater::priv::on_process_completed(wxCommandEvent &evt)
@ -1973,13 +1739,6 @@ void Plater::priv::on_action_cut(SimpleEvent&)
// TODO
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_action_settings(SimpleEvent&)
{
// TODO
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_action_layersediting(SimpleEvent&)
{
bool enable = !_3DScene::is_layers_editing_enabled(canvas3D);
@ -1988,31 +1747,11 @@ void Plater::priv::on_action_layersediting(SimpleEvent&)
_3DScene::enable_toolbar_item(canvas3D, "layersediting", false);
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_action_selectbyparts(SimpleEvent&)
{
// TODO
}
#endif // !ENABLE_EXTENDED_SELECTION
#if ENABLE_EXTENDED_SELECTION
void Plater::priv::on_object_select(SimpleEvent& evt)
{
selection_changed();
wxGetApp().obj_list()->update_selections();
}
#else
void Plater::priv::on_object_select(ObjectSelectEvent &evt)
{
const auto obj_idx = evt.object_id();
const auto vol_idx = evt.volume_id();
if (obj_idx >= 0 && obj_idx < 1000 && vol_idx == -1) {
// Ignore the special objects (the wipe tower proxy and such).
select_object(obj_idx);
}
}
#endif // ENABLE_EXTENDED_SELECTION
void Plater::priv::on_viewport_changed(SimpleEvent& evt)
{
@ -2025,16 +1764,12 @@ void Plater::priv::on_viewport_changed(SimpleEvent& evt)
void Plater::priv::on_right_click(Vec2dEvent& evt)
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = get_selected_object_idx();
if (obj_idx == -1)
return;
if (q != nullptr)
q->PopupMenu(&object_menu, (int)evt.data.x(), (int)evt.data.y());
#else
// TODO
#endif // ENABLE_EXTENDED_SELECTION
}
void Plater::priv::on_model_update(SimpleEvent&)
@ -2042,42 +1777,6 @@ void Plater::priv::on_model_update(SimpleEvent&)
// TODO
}
#if !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_scale_uniformly(SimpleEvent&)
{
// my ($scale) = @_;
// my ($obj_idx, $object) = $self->selected_object;
const auto obj_idx = selected_object();
if (! obj_idx) { return; }
// return if !defined $obj_idx;
// my $model_object = $self->{model}->objects->[$obj_idx];
// my $model_instance = $model_object->instances->[0];
// my $variation = $scale / $model_instance->scaling_factor;
// #FIXME Scale the layer height profile?
// foreach my $range (@{ $model_object->layer_height_ranges }) {
// $range->[0] *= $variation;
// $range->[1] *= $variation;
// }
// $_->set_scaling_factor($scale) for @{ $model_object->instances };
// # Set object scale on c++ side
// # Slic3r::GUI::set_object_scale($obj_idx, $model_object->instances->[0]->scaling_factor * 100);
// # $object->transform_thumbnail($self->{model}, $obj_idx);
// #update print and start background processing
// $self->{print}->add_model_object($model_object, $obj_idx);
// $self->selection_changed(1); # refresh info (size, volume etc.)
// $self->update;
this->schedule_background_process();
}
#endif // !ENABLE_EXTENDED_SELECTION
void Plater::priv::on_wipetower_moved(Vec3dEvent &evt)
{
DynamicPrintConfig cfg;
@ -2109,7 +1808,6 @@ bool Plater::priv::init_object_menu()
object_menu.AppendSeparator();
#if ENABLE_MIRROR
wxMenu* mirror_menu = new wxMenu();
if (mirror_menu == nullptr)
return false;
@ -2122,7 +1820,6 @@ bool Plater::priv::init_object_menu()
[this](wxCommandEvent&) { mirror(Z); }, "bullet_blue.png", &object_menu);
wxMenuItem* item_mirror = append_submenu(&object_menu, mirror_menu, wxID_ANY, _(L("Mirror")), _(L("Mirror the selected object")));
#endif // ENABLE_MIRROR
wxMenu* split_menu = new wxMenu();
if (split_menu == nullptr)
@ -2135,13 +1832,10 @@ bool Plater::priv::init_object_menu()
wxMenuItem* item_split = append_submenu(&object_menu, split_menu, wxID_ANY, _(L("Split")), _(L("Split the selected object")), "shape_ungroup.png");
#if ENABLE_EXTENDED_SELECTION
// ui updates needs to be binded to the parent panel
if (q != nullptr)
{
#if ENABLE_MIRROR
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_mirror()); }, item_mirror->GetId());
#endif // ENABLE_MIRROR
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_delete_object()); }, item_delete->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_increase_instances()); }, item_increase->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_decrease_instances()); }, item_decrease->GetId());
@ -2150,12 +1844,10 @@ bool Plater::priv::init_object_menu()
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_objects()); }, item_split_objects->GetId());
q->Bind(wxEVT_UPDATE_UI, [this](wxUpdateUIEvent& evt) { evt.Enable(can_split_to_volumes()); }, item_split_volumes->GetId());
}
#endif // ENABLE_EXTENDED_SELECTION
return true;
}
#if ENABLE_EXTENDED_SELECTION
bool Plater::priv::can_delete_object() const
{
int obj_idx = get_selected_object_idx();
@ -2208,13 +1900,10 @@ bool Plater::priv::can_arrange() const
return !model.objects.empty();
}
#if ENABLE_MIRROR
bool Plater::priv::can_mirror() const
{
return get_selection().is_from_single_instance();
}
#endif // ENABLE_MIRROR
#endif // ENABLE_EXTENDED_SELECTION
// Plater / Public
@ -2255,51 +1944,28 @@ void Plater::remove(size_t obj_idx) { p->remove(obj_idx); }
void Plater::remove_selected()
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = p->get_selected_object_idx();
if (obj_idx != -1)
remove((size_t)obj_idx);
#else
const auto selected = p->selected_object();
if (selected) {
remove(*selected);
}
#endif // ENABLE_EXTENDED_SELECTION
}
void Plater::increase_instances(size_t num)
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = p->get_selected_object_idx();
if (obj_idx == -1)
return;
ModelObject* model_object = p->model.objects[obj_idx];
ModelInstance* model_instance = model_object->instances.back();
#else
const auto obj_idx = p->selected_object();
if (! obj_idx) { return; }
auto *model_object = p->model.objects[*obj_idx];
auto *model_instance = model_object->instances[model_object->instances.size() - 1];
#endif // ENABLE_EXTENDED_SELECTION
float offset = 10.0;
for (size_t i = 0; i < num; i++, offset += 10.0) {
Vec3d offset_vec = model_instance->get_offset() + Vec3d(offset, offset, 0.0);
model_object->add_instance(offset_vec, model_instance->get_scaling_factor(), model_instance->get_rotation());
#if ENABLE_EXTENDED_SELECTION
// p->print.get_object(obj_idx)->add_copy(Slic3r::to_2d(offset_vec));
#else
// p->print.get_object(*obj_idx)->add_copy(Slic3r::to_2d(offset_vec));
#endif // ENABLE_EXTENDED_SELECTION
}
#if ENABLE_EXTENDED_SELECTION
sidebar().obj_list()->increase_object_instances(obj_idx, num);
#else
sidebar().obj_list()->increase_object_instances(*obj_idx, num);
#endif // ENABLE_EXTENDED_SELECTION
if (p->get_config("autocenter") == "1") {
p->arrange();
@ -2307,9 +1973,7 @@ void Plater::increase_instances(size_t num)
p->update();
}
#if ENABLE_EXTENDED_SELECTION
p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1);
#endif // ENABLE_EXTENDED_SELECTION
p->selection_changed();
@ -2318,47 +1982,26 @@ void Plater::increase_instances(size_t num)
void Plater::decrease_instances(size_t num)
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = p->get_selected_object_idx();
if (obj_idx == -1)
return;
ModelObject* model_object = p->model.objects[obj_idx];
#else
const auto obj_idx = p->selected_object();
if (! obj_idx) { return; }
auto *model_object = p->model.objects[*obj_idx];
#endif // ENABLE_EXTENDED_SELECTION
if (model_object->instances.size() > num) {
for (size_t i = 0; i < num; i++) {
model_object->delete_last_instance();
#if ENABLE_EXTENDED_SELECTION
// p->print.get_object(obj_idx)->delete_last_copy();
#else
// p->print.get_object(*obj_idx)->delete_last_copy();
#endif // ENABLE_EXTENDED_SELECTION
}
#if ENABLE_EXTENDED_SELECTION
sidebar().obj_list()->decrease_object_instances(obj_idx, num);
#else
sidebar().obj_list()->decrease_object_instances(*obj_idx, num);
#endif // ENABLE_EXTENDED_SELECTION
}
else {
#if ENABLE_EXTENDED_SELECTION
remove(obj_idx);
#else
remove(*obj_idx);
#endif // ENABLE_EXTENDED_SELECTION
}
p->update();
#if ENABLE_EXTENDED_SELECTION
if (!model_object->instances.empty())
p->get_selection().add_instance(obj_idx, (int)model_object->instances.size() - 1);
#endif // ENABLE_EXTENDED_SELECTION
p->selection_changed();
this->p->schedule_background_process();
@ -2366,18 +2009,11 @@ void Plater::decrease_instances(size_t num)
void Plater::set_number_of_copies(/*size_t num*/)
{
#if ENABLE_EXTENDED_SELECTION
int obj_idx = p->get_selected_object_idx();
if (obj_idx == -1)
return;
ModelObject* model_object = p->model.objects[obj_idx];
#else
const auto obj_idx = p->selected_object();
if (! obj_idx) { return; }
auto *model_object = p->model.objects[*obj_idx];
#endif // ENABLE_EXTENDED_SELECTION
const auto num = wxGetNumberFromUser( " ", _("Enter the number of copies:"),
_("Copies of the selected object"), model_object->instances.size(), 0, 1000, this );
@ -2393,13 +2029,8 @@ void Plater::set_number_of_copies(/*size_t num*/)
void Plater::export_gcode(fs::path output_path)
{
#if ENABLE_EXTENDED_SELECTION
if (p->model.objects.empty())
return;
#else
if (p->objects.empty())
return;
#endif // ENABLE_EXTENDED_SELECTION
if (this->p->background_process.is_export_scheduled()) {
GUI::show_error(this, _(L("Another export job is currently running.")));
@ -2451,11 +2082,7 @@ void Plater::export_gcode(fs::path output_path)
void Plater::export_stl()
{
#if ENABLE_EXTENDED_SELECTION
if (p->model.objects.empty()) { return; }
#else
if (p->objects.empty()) { return; }
#endif // ENABLE_EXTENDED_SELECTION
auto dialog = p->get_export_file(FT_STL);
if (! dialog) { return; }
@ -2470,11 +2097,7 @@ void Plater::export_stl()
void Plater::export_amf()
{
#if ENABLE_EXTENDED_SELECTION
if (p->model.objects.empty()) { return; }
#else
if (p->objects.empty()) { return; }
#endif // ENABLE_EXTENDED_SELECTION
auto dialog = p->get_export_file(FT_AMF);
if (! dialog) { return; }
@ -2493,11 +2116,7 @@ void Plater::export_amf()
void Plater::export_3mf()
{
#if ENABLE_EXTENDED_SELECTION
if (p->model.objects.empty()) { return; }
#else
if (p->objects.empty()) { return; }
#endif // ENABLE_EXTENDED_SELECTION
auto dialog = p->get_export_file(FT_3MF);
if (! dialog) { return; }
@ -2612,6 +2231,11 @@ void Plater::on_config_change(const DynamicPrintConfig &config)
this->p->schedule_background_process();
}
int Plater::get_selected_object_idx()
{
return p->get_selected_object_idx();
}
wxGLCanvas* Plater::canvas3D()
{
return p->canvas3D;
@ -2637,11 +2261,6 @@ void Plater::changed_object(int obj_idx)
// update print
if (list->is_parts_changed() || list->is_part_settings_changed()) {
this->p->schedule_background_process();
#if !ENABLE_EXTENDED_SELECTION
if (p->canvas3D) _3DScene::reload_scene(p->canvas3D, true);
auto selections = p->collect_selections();
_3DScene::set_objects_selections(p->canvas3D, selections);
#endif // !ENABLE_EXTENDED_SELECTION
#if !ENABLE_MODIFIED_CAMERA_TARGET
_3DScene::zoom_to_volumes(p->canvas3D);
#endif // !ENABLE_MODIFIED_CAMERA_TARGET

View File

@ -78,6 +78,7 @@ public:
wxButton* get_wiping_dialog_button();
void update_objects_list_extruder_column(int extruders_count);
void show_info_sizers(const bool show);
void show_info_sizer();
void show_sliced_info_sizer(const bool show);
void show_buttons(const bool show);
void show_button(ButtonAction but_action, bool show);
@ -129,6 +130,8 @@ public:
void on_extruders_change(int extruders_count);
void on_config_change(const DynamicPrintConfig &config);
int get_selected_object_idx();
wxGLCanvas* canvas3D();
private:
struct priv;