From af4363f6e88e42af6d4f9c40a4b6c62e1b918dfa Mon Sep 17 00:00:00 2001 From: Joseph Lenox Date: Sun, 13 May 2018 19:32:15 -0500 Subject: [PATCH] Implemented general rotate function for supplied function. --- src/GUI/Plater.cpp | 35 ++++++++++++++++++++++++++++++++++- src/GUI/Plater.hpp | 2 +- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/GUI/Plater.cpp b/src/GUI/Plater.cpp index 839394fe1..7532f6160 100644 --- a/src/GUI/Plater.cpp +++ b/src/GUI/Plater.cpp @@ -8,6 +8,7 @@ #include "Log.hpp" #include "MainFrame.hpp" #include "BoundingBox.hpp" +#include "Geometry.hpp" namespace Slic3r { namespace GUI { @@ -732,8 +733,40 @@ void Plater::decrease(size_t copies, bool dont_push) { this->on_model_change(); } -void Plater::rotate(double angle) { +void Plater::rotate(double angle, Axis axis, bool dont_push) { //TODO + ObjRef obj {this->selected_object()}; + if (obj == this->objects.end()) return; + + auto* model_object {this->model->objects.at(obj->identifier)}; + auto* model_instance {model_object->instances.front()}; + + if(obj->thumbnail.expolygons.size() == 0) { return; } + + if (axis == Z) { + for (auto* instance : model_object->instances) + instance->rotation += Geometry::deg2rad(angle); + obj->transform_thumbnail(this->model, obj->identifier); + } else { + model_object->transform_by_instance(*model_instance, true); + model_object->rotate(Geometry::deg2rad(angle), axis); + + // realign object to Z=0 + model_object->center_around_origin(); + this->make_thumbnail(obj->identifier); + } + + model_object->update_bounding_box(); + + this->print->add_model_object(model_object, obj->identifier); + + if (!dont_push) { + // TODO + } + + this->selection_changed(); + this->on_model_change(); + } void Plater::split_object() { diff --git a/src/GUI/Plater.hpp b/src/GUI/Plater.hpp index be6b27051..518931834 100644 --- a/src/GUI/Plater.hpp +++ b/src/GUI/Plater.hpp @@ -174,7 +174,7 @@ private: void decrease(size_t copies = 1, bool dont_push = false); /// Rotate the currently selected model. - void rotate(double angle); + void rotate(double angle, Axis axis = Z, bool dont_push = false); /// Separate a multipart model to its component interfaces. void split_object();