Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/prusa/master' into masterPE
Browse files Browse the repository at this point in the history
  • Loading branch information
supermerill committed Jan 4, 2019
2 parents 733c7de + 567b367 commit 339531f
Show file tree
Hide file tree
Showing 29 changed files with 286 additions and 54 deletions.
Binary file added resources/models/mk2_bed.stl
Binary file not shown.
Binary file added resources/models/mk3_bed.stl
Binary file not shown.
4 changes: 2 additions & 2 deletions src/libslic3r/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ void ConfigBase::load_from_gcode_file(const std::string &file)

size_t key_value_pairs = load_from_gcode_string(data.data());
if (key_value_pairs < 80)
throw std::runtime_error((boost::format("Suspiciously low number of configuration values extracted from %1: %2") % file % key_value_pairs).str());
throw std::runtime_error((boost::format("Suspiciously low number of configuration values extracted from %1%: %2%") % file % key_value_pairs).str());
}

// Load the config keys from the given string.
Expand Down Expand Up @@ -536,7 +536,7 @@ void DynamicConfig::read_cli(const std::vector<std::string> &tokens, t_config_op
args.emplace_back(const_cast<char*>(""));
for (size_t i = 0; i < tokens.size(); ++ i)
args.emplace_back(const_cast<char *>(tokens[i].c_str()));
this->read_cli(args.size(), &args[0], extra);
this->read_cli(int(args.size()), &args[0], extra);
}

bool DynamicConfig::read_cli(int argc, char** argv, t_config_option_keys* extra)
Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,7 @@ void GCode::_do_export(Print &print, FILE *file)
}
} else {
for (const std::string &start_gcode : print.config().start_filament_gcode.values)
_writeln(file, this->placeholder_parser_process("start_gcode", start_gcode, (unsigned int)(&start_gcode - &print.config().start_filament_gcode.values.front())));
_writeln(file, this->placeholder_parser_process("start_filament_gcode", start_gcode, (unsigned int)(&start_gcode - &print.config().start_filament_gcode.values.front())));
}
this->_print_first_layer_extruder_temperatures(file, print, start_gcode, initial_extruder_id, true);
print.throw_if_canceled();
Expand Down
4 changes: 2 additions & 2 deletions src/libslic3r/Geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,9 +927,9 @@ Vec3d extract_euler_angles(const Eigen::Matrix<double, 3, 3, Eigen::DontAlign>&
}
else
{
angles(0) = ::atan2(-rotation_matrix(1, 2), rotation_matrix(1, 1));
angles(1) = 0.0;
angles(1) = ::atan2(-rotation_matrix(2, 0), sy);
angles(2) = 0.0;
angles(2) = (angles(1) >-0.0) ? ::atan2(rotation_matrix(1, 2), rotation_matrix(1, 1)) : ::atan2(-rotation_matrix(1, 2), rotation_matrix(1, 1));
}

return angles;
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/Model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -719,12 +719,13 @@ ModelInstance* ModelObject::add_instance(const ModelInstance &other)
return i;
}

ModelInstance* ModelObject::add_instance(const Vec3d &offset, const Vec3d &scaling_factor, const Vec3d &rotation)
ModelInstance* ModelObject::add_instance(const Vec3d &offset, const Vec3d &scaling_factor, const Vec3d &rotation, const Vec3d &mirror)
{
auto *instance = add_instance();
instance->set_offset(offset);
instance->set_scaling_factor(scaling_factor);
instance->set_rotation(rotation);
instance->set_mirror(mirror);
return instance;
}

Expand Down
2 changes: 1 addition & 1 deletion src/libslic3r/Model.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class ModelObject : public ModelBase

ModelInstance* add_instance();
ModelInstance* add_instance(const ModelInstance &instance);
ModelInstance* add_instance(const Vec3d &offset, const Vec3d &scaling_factor, const Vec3d &rotation);
ModelInstance* add_instance(const Vec3d &offset, const Vec3d &scaling_factor, const Vec3d &rotation, const Vec3d &mirror);
void delete_instance(size_t idx);
void delete_last_instance();
void clear_instances();
Expand Down
7 changes: 7 additions & 0 deletions src/libslic3r/PrintConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3416,6 +3416,13 @@ CLIConfigDef::CLIConfigDef()
const CLIConfigDef cli_config_def;
DynamicPrintAndCLIConfig::PrintAndCLIConfigDef DynamicPrintAndCLIConfig::s_def;

void DynamicPrintAndCLIConfig::handle_legacy(t_config_option_key &opt_key, std::string &value) const
{
if (cli_config_def.options.find(opt_key) == cli_config_def.options.end()) {
PrintConfigDef::handle_legacy(opt_key, value);
}
}

std::ostream& print_cli_options(std::ostream& out)
{
for (const auto& opt : cli_config_def.options) {
Expand Down
6 changes: 6 additions & 0 deletions src/libslic3r/PrintConfig.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1241,6 +1241,12 @@ class DynamicPrintAndCLIConfig : public DynamicPrintConfig
const ConfigDef* def() const override { return &s_def; }
t_config_option_keys keys() const override { return s_def.keys(); }

// Verify whether the opt_key has not been obsoleted or renamed.
// Both opt_key and value may be modified by handle_legacy().
// If the opt_key is no more valid in this version of Slic3r, opt_key is cleared by handle_legacy().
// handle_legacy() is called internally by set_deserialize().
void handle_legacy(t_config_option_key &opt_key, std::string &value) const override;

private:
class PrintAndCLIConfigDef : public ConfigDef
{
Expand Down
4 changes: 3 additions & 1 deletion src/libslic3r/Technologies.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@
//====================
#define ENABLE_1_42_0_ALPHA2 1

// Improves navigation between sidebar fields
#define ENABLE_IMPROVED_SIDEBAR_OBJECTS_MANIPULATION (1 && ENABLE_1_42_0_ALPHA2)

// Adds print bed models to 3D scene
#define ENABLE_PRINT_BED_MODELS (0 && ENABLE_1_42_0_ALPHA2)
#endif // _technologies_h_


82 changes: 74 additions & 8 deletions src/slic3r/GUI/3DScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#include "libslic3r/Slicing.hpp"
#include "libslic3r/GCode/Analyzer.hpp"
#include "slic3r/GUI/PresetBundle.hpp"
#if ENABLE_PRINT_BED_MODELS
#include "libslic3r/Format/STL.hpp"
#endif // ENABLE_PRINT_BED_MODELS

#include <stdio.h>
#include <stdlib.h>
Expand All @@ -20,6 +23,11 @@

#include <boost/log/trivial.hpp>

#if ENABLE_PRINT_BED_MODELS
#include <boost/filesystem/operations.hpp>
#include <boost/algorithm/string.hpp>
#endif // ENABLE_PRINT_BED_MODELS

#include <tbb/parallel_for.h>
#include <tbb/spin_mutex.h>

Expand Down Expand Up @@ -249,11 +257,7 @@ void GLVolume::set_render_color(float r, float g, float b, float a)

void GLVolume::set_render_color(const float* rgba, unsigned int size)
{
size = std::min((unsigned int)4, size);
for (unsigned int i = 0; i < size; ++i)
{
render_color[i] = rgba[i];
}
::memcpy((void*)render_color, (const void*)rgba, (size_t)(std::min((unsigned int)4, size) * sizeof(float)));
}

void GLVolume::set_render_color()
Expand Down Expand Up @@ -1790,17 +1794,27 @@ GUI::GLCanvas3DManager _3DScene::s_canvas_mgr;
#if ENABLE_SIDEBAR_VISUAL_HINTS
GLModel::GLModel()
: m_useVBOs(false)
#if ENABLE_PRINT_BED_MODELS
, m_filename("")
#endif // ENABLE_PRINT_BED_MODELS
{
m_volume.shader_outside_printer_detection_enabled = false;
}

GLModel::~GLModel()
{
#if ENABLE_PRINT_BED_MODELS
reset();
#else
m_volume.release_geometry();
#endif // ENABLE_PRINT_BED_MODELS
}

void GLModel::set_color(const float* color, unsigned int size)
{
#if ENABLE_PRINT_BED_MODELS
::memcpy((void*)m_volume.color, (const void*)color, (size_t)(std::min((unsigned int)4, size) * sizeof(float)));
#endif // ENABLE_PRINT_BED_MODELS
m_volume.set_render_color(color, size);
}

Expand Down Expand Up @@ -1834,6 +1848,14 @@ void GLModel::set_scale(const Vec3d& scale)
m_volume.set_volume_scaling_factor(scale);
}

#if ENABLE_PRINT_BED_MODELS
void GLModel::reset()
{
m_volume.release_geometry();
m_filename = "";
}
#endif // ENABLE_PRINT_BED_MODELS

void GLModel::render() const
{
if (m_useVBOs)
Expand All @@ -1854,9 +1876,7 @@ void GLModel::render_VBOs() const
GLint current_program_id;
::glGetIntegerv(GL_CURRENT_PROGRAM, &current_program_id);
GLint color_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "uniform_color") : -1;
GLint print_box_detection_id = (current_program_id > 0) ? glGetUniformLocation(current_program_id, "print_box.volume_detection") : -1;

m_volume.render_VBOs(color_id, print_box_detection_id, -1);
m_volume.render_VBOs(color_id, -1, -1);

::glBindBuffer(GL_ARRAY_BUFFER, 0);
::glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
Expand Down Expand Up @@ -2066,11 +2086,57 @@ bool GLCurvedArrow::on_init(bool useVBOs)
else
m_volume.indexed_vertex_array.load_mesh_flat_shading(TriangleMesh(vertices, triangles));

m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box();
m_volume.finalize_geometry(m_useVBOs);
return true;
}
#endif // ENABLE_SIDEBAR_VISUAL_HINTS

#if ENABLE_PRINT_BED_MODELS
bool GLBed::on_init_from_file(const std::string& filename, bool useVBOs)
{
reset();

if (!boost::filesystem::exists(filename))
return false;

if (!boost::algorithm::iends_with(filename, ".stl"))
return false;

Model model;
try
{
model = Model::read_from_file(filename);
}
catch (std::exception &e)
{
return false;
}

m_filename = filename;
m_useVBOs = useVBOs;

ModelObject* model_object = model.objects.front();
model_object->center_around_origin();

TriangleMesh mesh = model.mesh();
mesh.repair();

if (m_useVBOs)
m_volume.indexed_vertex_array.load_mesh_full_shading(mesh);
else
m_volume.indexed_vertex_array.load_mesh_flat_shading(mesh);

float color[4] = { 0.235f, 0.235, 0.235f, 1.0f };
set_color(color, 4);

m_volume.bounding_box = m_volume.indexed_vertex_array.bounding_box();
m_volume.finalize_geometry(m_useVBOs);

return true;
}
#endif // ENABLE_PRINT_BED_MODELS

std::string _3DScene::get_gl_info(bool format_as_html, bool extensions)
{
return s_canvas_mgr.get_gl_info(format_as_html, extensions);
Expand Down
27 changes: 27 additions & 0 deletions src/slic3r/GUI/3DScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -569,13 +569,20 @@ class GLModel
protected:
GLVolume m_volume;
bool m_useVBOs;
#if ENABLE_PRINT_BED_MODELS
std::string m_filename;
#endif // ENABLE_PRINT_BED_MODELS

public:
GLModel();
virtual ~GLModel();

bool init(bool useVBOs) { return on_init(useVBOs); }
#if ENABLE_PRINT_BED_MODELS
bool init_from_file(const std::string& filename, bool useVBOs) { return on_init_from_file(filename, useVBOs); }

void center_around(const Vec3d& center) { m_volume.set_volume_offset(center - m_volume.bounding_box.center()); }
#endif // ENABLE_PRINT_BED_MODELS
void set_color(const float* color, unsigned int size);

const Vec3d& get_offset() const;
Expand All @@ -585,10 +592,22 @@ class GLModel
const Vec3d& get_scale() const;
void set_scale(const Vec3d& scale);

#if ENABLE_PRINT_BED_MODELS
const std::string& get_filename() const { return m_filename; }
const BoundingBoxf3& get_bounding_box() const { return m_volume.bounding_box; }

void reset();
#endif // ENABLE_PRINT_BED_MODELS

void render() const;

protected:
#if ENABLE_PRINT_BED_MODELS
virtual bool on_init(bool useVBOs) { return false; }
virtual bool on_init_from_file(const std::string& filename, bool useVBOs) { return false; }
#else
virtual bool on_init(bool useVBOs) = 0;
#endif // ENABLE_PRINT_BED_MODELS

private:
void render_VBOs() const;
Expand All @@ -613,6 +632,14 @@ class GLCurvedArrow : public GLModel
};
#endif // ENABLE_SIDEBAR_VISUAL_HINTS

#if ENABLE_PRINT_BED_MODELS
class GLBed : public GLModel
{
protected:
virtual bool on_init_from_file(const std::string& filename, bool useVBOs);
};
#endif // ENABLE_PRINT_BED_MODELS

class _3DScene
{
static GUI::GLCanvas3DManager s_canvas_mgr;
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/BackgroundSlicingProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ template<> class LayerWriter<SLAZipFmt> {
}

inline std::string get_name() const {
return fpath.GetName().ToStdString();
return fpath.GetName().ToUTF8().data();
}

template<class T> inline LayerWriter& operator<<(const T& arg) {
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/BedShapeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ void BedShapePanel::load_stl()
dialog->GetPaths(input_file);
dialog->Destroy();

std::string file_name = input_file[0].ToStdString();
std::string file_name = input_file[0].ToUTF8().data();

Model model;
try {
Expand Down
3 changes: 1 addition & 2 deletions src/slic3r/GUI/ConfigWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ PrinterPicker::PrinterPicker(wxWindow *parent, const VendorProfile &vendor, cons
std::vector<wxPanel*> variants_panels;

for (const auto &model : models) {
auto bitmap_file = wxString::Format("printers/%s_%s.png", vendor.id, model.id);
wxBitmap bitmap(GUI::from_u8(Slic3r::var(bitmap_file.ToStdString())), wxBITMAP_TYPE_PNG);
wxBitmap bitmap(GUI::from_u8(Slic3r::var((boost::format("printers/%1%_%2%.png") % vendor.id % model.id).str())), wxBITMAP_TYPE_PNG);

auto *title = new wxStaticText(this, wxID_ANY, model.name, wxDefaultPosition, wxDefaultSize, wxALIGN_LEFT);
title->SetFont(namefont);
Expand Down
2 changes: 1 addition & 1 deletion src/slic3r/GUI/Field.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ void Field::get_value_by_opt_type(wxString& str)
}
}

m_value = str.ToStdString();
m_value = str.ToUTF8().data();
break; }
default:
break;
Expand Down
Loading

0 comments on commit 339531f

Please sign in to comment.