Merge branch 'cppgui' of https://github.com/lordofhyphens/slic3r into cppgui

This commit is contained in:
Joseph Lenox 2018-05-06 20:46:14 -05:00
commit 6ad3383584
9 changed files with 83 additions and 18 deletions

View File

@ -119,7 +119,7 @@ void Plater::add() {
const auto& input_files{open_model(this, *(this->settings), wxTheApp->GetTopWindow())};
for (const auto& f : input_files) {
Log::info(LogChannel, (wxString(L"Calling Load File for ") + f).ToStdWstring());
this->load_file(f);
this->load_file(f.ToStdString());
}
// abort if no objects actually added.
@ -144,7 +144,7 @@ void Plater::add() {
}
std::vector<int> Plater::load_file(const wxString& file, const int obj_idx_to_load) {
std::vector<int> Plater::load_file(const std::string file, const int obj_idx_to_load) {
auto input_file {wxFileName(file)};
settings->skein_directory = input_file.GetPath();
@ -158,7 +158,7 @@ std::vector<int> Plater::load_file(const wxString& file, const int obj_idx_to_lo
progress_dialog->Pulse();
//TODO: Add a std::wstring so we can handle non-roman characters as file names.
try {
model = Slic3r::Model::read_from_file(file.ToStdString());
model = Slic3r::Model::read_from_file(file);
} catch (std::runtime_error& e) {
show_error(this, e.what());
Slic3r::Log::error(LogChannel, LOG_WSTRING(file << " failed to load: " << e.what()));
@ -177,10 +177,10 @@ std::vector<int> Plater::load_file(const wxString& file, const int obj_idx_to_lo
for (auto i = 0U; i < model.objects.size(); i++) {
auto object {model.objects[i]};
object->input_file = file.ToStdString();
object->input_file = file;
for (auto j = 0U; j < object->volumes.size(); j++) {
auto volume {object->volumes.at(j)};
volume->input_file = file.ToStdString();
volume->input_file = file;
volume->input_file_obj_idx = i;
volume->input_file_vol_idx = j;
}
@ -199,8 +199,8 @@ std::vector<int> Plater::load_file(const wxString& file, const int obj_idx_to_lo
}
for (const auto &j : obj_idx) {
this->objects[j].input_file = file;
this->objects[j].input_file_obj_idx = i++;
this->objects.at(j).input_file = file;
this->objects.at(j).input_file_obj_idx = i++;
}
GetFrame()->statusbar->SetStatusText(_("Loaded ") + input_file.GetName());
@ -244,7 +244,7 @@ std::vector<int> Plater::load_model_objects(ModelObjectPtrs model_objects) {
tmpobj.identifier = (this->object_identifier)++;
this->objects.push_back(tmpobj);
obj_idx.push_back(this->objects.size());
obj_idx.push_back(this->objects.size() - 1);
Slic3r::Log::info(LogChannel, LOG_WSTRING("Object array new size: " << this->objects.size()));
Slic3r::Log::info(LogChannel, LOG_WSTRING("Instances: " << obj->instances.size()));

View File

@ -61,7 +61,7 @@ private:
Plate2D* canvas2D {}; //< 2D plater canvas
/// Handles the actual load of the file from the dialog handoff.
std::vector<int> load_file(const wxString& file, const int obj_idx_to_load = -1);
std::vector<int> load_file(const std::string file, const int obj_idx_to_load = -1);
const std::string LogChannel {"GUI_Plater"}; //< Which log these messages should go to.

View File

@ -76,11 +76,8 @@ void Plate2D::repaint(wxPaintEvent& e) {
dc->SetTextForeground(wxColor(0,0,0));
dc->SetFont(wxFont(10, wxFONTFAMILY_ROMAN, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL));
wxString val {};
val.Printf("X = %.0f", this->print_center.x);
dc->DrawLabel(val , wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
val.Printf("Y = %.0f", this->print_center.y);
dc->DrawRotatedText(val, 0, center.y + 15, 90);
dc->DrawLabel(wxString::Format("X = %.0f", this->print_center.x), wxRect(0,0, center.x*2, this->GetSize().GetHeight()), wxALIGN_CENTER_HORIZONTAL | wxALIGN_BOTTOM);
dc->DrawRotatedText(wxString::Format("Y = %.0f", this->print_center.y), 0, center.y + 15, 90);
}
}
@ -99,7 +96,38 @@ void Plate2D::repaint(wxPaintEvent& e) {
}
}
// Draw thumbnails
dc->SetPen(dark_pen);
this->clean_instance_thumbnails();
for (auto& obj : this->objects) {
auto model_object {this->model->objects.at(obj.identifier)};
if (obj.thumbnail.expolygons.size() == 0)
continue; // if there's no thumbnail move on
for (size_t instance_idx = 0U; instance_idx < model_object->instances.size(); instance_idx++) {
auto& instance {model_object->instances.at(instance_idx)};
if (obj.transformed_thumbnail.expolygons.size()) continue;
auto thumbnail {obj.transformed_thumbnail}; // starts in unscaled model coords
thumbnail.translate(Point::new_scale(instance->offset));
obj.instance_thumbnails.emplace_back(thumbnail);
for (auto& poly : obj.instance_thumbnails) {
for (const auto& points : poly.expolygons) {
auto poly { this->scaled_points_to_pixel(Polygon(points), 1) };
dc->DrawPolygon(poly.size(), poly.data(), 0, 0);
}
}
}
}
e.Skip();
}
void Plate2D::clean_instance_thumbnails() {
for (auto& obj : this->objects) {
obj.instance_thumbnails.clear();
}
}
void Plate2D::mouse_drag(wxMouseEvent& e) {

View File

@ -90,8 +90,8 @@ private:
void update_bed_size();
/// private class variables to stash bits for drawing the print bed area.
wxPoint bed_origin {};
wxPoint print_center {};
wxRealPoint bed_origin {};
wxRealPoint print_center {};
Slic3r::Polygon bed_polygon {};
std::vector<wxPoint> grid {};
@ -119,6 +119,9 @@ private:
return this->point_to_model_units(pt.x, pt.y);
}
/// Remove all instance thumbnails.
void clean_instance_thumbnails();
};
} } // Namespace Slic3r::GUI

View File

@ -12,9 +12,9 @@ namespace Slic3r { namespace GUI {
class PlaterObject {
public:
wxString name {L""};
std::string name {""};
size_t identifier {0U};
wxString input_file {L""};
std::string input_file {""};
int input_file_obj_idx {-1};

View File

@ -24,6 +24,8 @@ class ExPolygonCollection
operator ExPolygons&();
void scale(double factor);
void translate(double x, double y);
void translate(const Point offset) { translate(static_cast<coordf_t>(offset.x), static_cast<coordf_t>(offset.y)); }
void translate(const Pointf offset) { translate(offset.x, offset.y); }
void rotate(double angle, const Point &center);
template <class T> bool contains(const T &item) const;
bool contains_b(const Point &point) const;

View File

@ -2,6 +2,8 @@
#define slic3r_LOG_HPP
#include <string>
#include <vector>
#include <sstream>
namespace Slic3r {
@ -28,6 +30,28 @@ public:
};
/// Utility debug function to transform a std::vector of anything that
/// supports ostream& operator<<() into a std::string.
template <typename T>
std::string
log_string(const std::vector<T>& in)
{
std::stringstream ss;
bool first {true};
ss << "[ ";
for (auto& c : in) {
if (!first) {
ss << ", ";
}
ss << c;
first = false;
}
ss << " ]";
return ss.str();
}
}
#endif // slic3r_LOG_HPP

View File

@ -18,6 +18,11 @@ Point::operator==(const Point& rhs) const
return this->coincides_with(rhs);
}
Point
Point::new_scale(Pointf p) {
return Point(scale_(p.x), scale_(p.y));
}
std::string
Point::wkt() const
{

View File

@ -36,6 +36,9 @@ class Point
static Point new_scale(coordf_t x, coordf_t y) {
return Point(scale_(x), scale_(y));
};
/// Scale and create a Point from a Pointf.
static Point new_scale(Pointf p);
bool operator==(const Point& rhs) const;
std::string wkt() const;
std::string dump_perl() const;