Plater2DObject->PlaterObject

This commit is contained in:
Joseph Lenox 2018-05-01 21:50:30 -05:00
parent 14097656e9
commit 5f405b60e9
7 changed files with 92 additions and 21 deletions

View File

@ -187,6 +187,7 @@ IF(wxWidgets_FOUND)
${GUI_LIBDIR}/MainFrame.cpp
${GUI_LIBDIR}/Plater.cpp
${GUI_LIBDIR}/Plater/Plate2D.cpp
${GUI_LIBDIR}/Plater/PlaterObject.cpp
${GUI_LIBDIR}/Settings.cpp
${GUI_LIBDIR}/misc_ui.cpp
)

View File

@ -14,7 +14,7 @@
#include "Print.hpp"
#include "Config.hpp"
#include "Plater/Plater2DObject.hpp"
#include "Plater/PlaterObject.hpp"
#include "Plater/Plate2D.hpp"
#include "Settings.hpp"
@ -23,7 +23,7 @@ namespace Slic3r { namespace GUI {
using UndoOperation = int;
using obj_index = unsigned int;
class Plater2DObject;
class PlaterObject;
class Plate2D;
class Plater : public wxPanel
@ -44,7 +44,7 @@ private:
bool processed {false};
std::vector<Plater2DObject> objects {};
std::vector<PlaterObject> objects {};
std::stack<UndoOperation> undo {};
std::stack<UndoOperation> redo {};

View File

@ -12,7 +12,7 @@
namespace Slic3r { namespace GUI {
Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector<Plater2DObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings) :
Plate2D::Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings) :
wxPanel(parent, wxID_ANY, wxDefaultPosition, size, wxTAB_TRAVERSAL), objects(_objects), model(_model), config(_config), settings(_settings)
{

View File

@ -11,7 +11,7 @@
#include "Plater.hpp"
#include "ColorScheme.hpp"
#include "Settings.hpp"
#include "Plater/Plater2DObject.hpp"
#include "Plater/PlaterObject.hpp"
#include "misc_ui.hpp"
#include "Log.hpp"
@ -31,12 +31,12 @@ enum class MoveDirection {
class Plate2D : public wxPanel {
public:
Plate2D(wxWindow* parent, const wxSize& size, std::vector<Plater2DObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
Plate2D(wxWindow* parent, const wxSize& size, std::vector<PlaterObject>& _objects, std::shared_ptr<Model> _model, std::shared_ptr<Config> _config, std::shared_ptr<Settings> _settings);
// std::function<> on_select_object {};
private:
std::vector<Plater2DObject>& objects;
std::vector<PlaterObject>& objects;
std::shared_ptr<Slic3r::Model> model;
std::shared_ptr<Slic3r::Config> config;
std::shared_ptr<Settings> settings;

View File

@ -1,14 +0,0 @@
#ifndef PLATER2DOBJECT_HPP
#define PLATER2DOBJECT_HPP
namespace Slic3r { namespace GUI {
// 2D Preview of an object
class Plater2DObject {
public:
std::string name {""};
std::string identifier {""};
bool selected {false};
int selected_instance {-1};
};
} } // Namespace Slic3r::GUI
#endif

View File

@ -0,0 +1,50 @@
#include "Plater/PlaterObject.hpp"
#include "Geometry.hpp"
#include "ExPolygon.hpp"
namespace Slic3r { namespace GUI {
Slic3r::ExPolygonCollection& PlaterObject::make_thumbnail(const Slic3r::Model& model, int obj_index) {
// make method idempotent
this->thumbnail.clear();
auto mesh {model.objects[obj_index]->raw_mesh()};
auto model_instance {model.objects[obj_idx]->instances[0]};
// Apply any x/y rotations and scaling vector if this came from a 3MF object.
mesh.rotate_x(model_instance.x_rotation);
mesh.rotate_y(model_instance.y_rotation);
mesh.scale_xyz(model_instance.scaling_vector);
if (mesh.facets_count <= 5000) {
auto area_threshold {Slic3r::Geometry::scale(1)};
ExPolygons tmp {};
std::copy_if(tmp.end(), mesh.horizontal_projection().begin(), mesh.horizontal_projection().end(), [=](const ExPolygon& p) { return p.area() >= area_threshold; } ); // return all polys bigger than the area
this->thumbnail.append(tmp);
this->thumbnail.simplify(0.5);
} else {
auto convex_hull {Slic3r::ExPolygon(mesh.convex_hull)};
this->thumbnail.append(convex_hull);
}
return this->thumbnail;
}
Slic3r::ExPolygonCollection& PlaterObject::transform_thumbnail(Slic3r::Model model, int obj_idx) {
if (this->thumbnail.expolygons.size() == 0) return this->thumbnail;
const auto& model_object {model.objects[obj_idx] };
const auto& model_instance {model_object.instances[0]};
// the order of these transformations MUST be the same everywhere, including
// in Slic3r::Print->add_model_object()
auto t {this->thumbnail};
t.rotate(model_instance.rotation(), Slic3r::Point(0,0));
t.scale(model_instance.scaling_factor());
this->transformed_thumbnail = t;
}
} } // Namespace Slic3r::GUI

View File

@ -0,0 +1,34 @@
#ifndef PLATEROBJECT_HPP
#define PLATEROBJECT_HPP
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include "ExPolygonCollection.hpp"
namespace Slic3r { namespace GUI {
class PlaterObject {
public:
wxString name {L""};
wxString identifier {L""};
wxString input_file {L""};
int input_file_obj_idx {-1};
Slic3r::ExPolygonCollection thumbnail;
Slic3r::ExPolygonCollection transformed_thumbnail;
// read only
std::vector<Slic3r::ExPolygonCollection> instance_thumbnails;
bool selected {false};
int selected_instance {-1};
Slic3r::ExPolygonCollection& make_thumbnail(Slic3r::Model model, int obj_index);
Slic3r::ExPolygonCollection& transform_thumbnail(Slic3r::Model model, int obj_index);
};
}} // Namespace Slic3r::GUI
#endif