mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-22 14:13:57 -06:00
Merge branch 'master' of https://github.com/prusa3d/PrusaSlicer
This commit is contained in:
commit
688a559b5f
12 changed files with 449 additions and 154 deletions
|
@ -1747,101 +1747,114 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
|||
_set_current();
|
||||
|
||||
struct ModelVolumeState {
|
||||
ModelVolumeState(const GLVolume *volume) :
|
||||
model_volume(nullptr), geometry_id(volume->geometry_id), volume_idx(-1) {}
|
||||
ModelVolumeState(const ModelVolume *model_volume, const ObjectID &instance_id, const GLVolume::CompositeID &composite_id) :
|
||||
model_volume(model_volume), geometry_id(std::make_pair(model_volume->id().id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {}
|
||||
ModelVolumeState(const ObjectID &volume_id, const ObjectID &instance_id) :
|
||||
model_volume(nullptr), geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {}
|
||||
bool new_geometry() const { return this->volume_idx == size_t(-1); }
|
||||
const ModelVolume *model_volume;
|
||||
ModelVolumeState(const GLVolume* volume) :
|
||||
model_volume(nullptr), geometry_id(volume->geometry_id), volume_idx(-1) {}
|
||||
ModelVolumeState(const ModelVolume* model_volume, const ObjectID& instance_id, const GLVolume::CompositeID& composite_id) :
|
||||
model_volume(model_volume), geometry_id(std::make_pair(model_volume->id().id, instance_id.id)), composite_id(composite_id), volume_idx(-1) {}
|
||||
ModelVolumeState(const ObjectID& volume_id, const ObjectID& instance_id) :
|
||||
model_volume(nullptr), geometry_id(std::make_pair(volume_id.id, instance_id.id)), volume_idx(-1) {}
|
||||
bool new_geometry() const { return this->volume_idx == size_t(-1); }
|
||||
const ModelVolume* model_volume;
|
||||
// ObjectID of ModelVolume + ObjectID of ModelInstance
|
||||
// or timestamp of an SLAPrintObjectStep + ObjectID of ModelInstance
|
||||
std::pair<size_t, size_t> geometry_id;
|
||||
GLVolume::CompositeID composite_id;
|
||||
// Volume index in the new GLVolume vector.
|
||||
size_t volume_idx;
|
||||
size_t volume_idx;
|
||||
};
|
||||
std::vector<ModelVolumeState> model_volume_state;
|
||||
std::vector<ModelVolumeState> aux_volume_state;
|
||||
std::vector<ModelVolumeState> aux_volume_state;
|
||||
|
||||
struct GLVolumeState {
|
||||
GLVolumeState() :
|
||||
volume_idx(-1) {}
|
||||
GLVolumeState(const GLVolume* volume, unsigned int volume_idx) :
|
||||
composite_id(volume->composite_id), volume_idx(volume_idx) {}
|
||||
|
||||
GLVolume::CompositeID composite_id;
|
||||
// Volume index in the old GLVolume vector.
|
||||
size_t volume_idx;
|
||||
};
|
||||
|
||||
// SLA steps to pull the preview meshes for.
|
||||
typedef std::array<SLAPrintObjectStep, 2> SLASteps;
|
||||
SLASteps sla_steps = { slaposSupportTree, slaposPad };
|
||||
struct SLASupportState {
|
||||
std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step;
|
||||
std::array<PrintStateBase::StateWithTimeStamp, std::tuple_size<SLASteps>::value> step;
|
||||
};
|
||||
// State of the sla_steps for all SLAPrintObjects.
|
||||
std::vector<SLASupportState> sla_support_state;
|
||||
|
||||
std::vector<size_t> instance_ids_selected;
|
||||
std::vector<size_t> map_glvolume_old_to_new(m_volumes.volumes.size(), size_t(-1));
|
||||
std::vector<GLVolumeState> deleted_volumes;
|
||||
std::vector<GLVolume*> glvolumes_new;
|
||||
glvolumes_new.reserve(m_volumes.volumes.size());
|
||||
auto model_volume_state_lower = [](const ModelVolumeState &m1, const ModelVolumeState &m2) { return m1.geometry_id < m2.geometry_id; };
|
||||
auto model_volume_state_lower = [](const ModelVolumeState& m1, const ModelVolumeState& m2) { return m1.geometry_id < m2.geometry_id; };
|
||||
|
||||
m_reload_delayed = ! m_canvas->IsShown() && ! refresh_immediately && ! force_full_scene_refresh;
|
||||
m_reload_delayed = !m_canvas->IsShown() && !refresh_immediately && !force_full_scene_refresh;
|
||||
|
||||
PrinterTechnology printer_technology = m_process->current_printer_technology();
|
||||
PrinterTechnology printer_technology = m_process->current_printer_technology();
|
||||
int volume_idx_wipe_tower_old = -1;
|
||||
|
||||
// Release invalidated volumes to conserve GPU memory in case of delayed refresh (see m_reload_delayed).
|
||||
// First initialize model_volumes_new_sorted & model_instances_new_sorted.
|
||||
for (int object_idx = 0; object_idx < (int)m_model->objects.size(); ++ object_idx) {
|
||||
const ModelObject *model_object = m_model->objects[object_idx];
|
||||
for (int instance_idx = 0; instance_idx < (int)model_object->instances.size(); ++ instance_idx) {
|
||||
const ModelInstance *model_instance = model_object->instances[instance_idx];
|
||||
for (int volume_idx = 0; volume_idx < (int)model_object->volumes.size(); ++ volume_idx) {
|
||||
const ModelVolume *model_volume = model_object->volumes[volume_idx];
|
||||
model_volume_state.emplace_back(model_volume, model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx));
|
||||
for (int object_idx = 0; object_idx < (int)m_model->objects.size(); ++object_idx) {
|
||||
const ModelObject* model_object = m_model->objects[object_idx];
|
||||
for (int instance_idx = 0; instance_idx < (int)model_object->instances.size(); ++instance_idx) {
|
||||
const ModelInstance* model_instance = model_object->instances[instance_idx];
|
||||
for (int volume_idx = 0; volume_idx < (int)model_object->volumes.size(); ++volume_idx) {
|
||||
const ModelVolume* model_volume = model_object->volumes[volume_idx];
|
||||
model_volume_state.emplace_back(model_volume, model_instance->id(), GLVolume::CompositeID(object_idx, volume_idx, instance_idx));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (printer_technology == ptSLA) {
|
||||
const SLAPrint *sla_print = this->sla_print();
|
||||
#ifndef NDEBUG
|
||||
const SLAPrint* sla_print = this->sla_print();
|
||||
#ifndef NDEBUG
|
||||
// Verify that the SLAPrint object is synchronized with m_model.
|
||||
check_model_ids_equal(*m_model, sla_print->model());
|
||||
#endif /* NDEBUG */
|
||||
#endif /* NDEBUG */
|
||||
sla_support_state.reserve(sla_print->objects().size());
|
||||
for (const SLAPrintObject *print_object : sla_print->objects()) {
|
||||
for (const SLAPrintObject* print_object : sla_print->objects()) {
|
||||
SLASupportState state;
|
||||
for (size_t istep = 0; istep < sla_steps.size(); ++ istep) {
|
||||
state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]);
|
||||
if (state.step[istep].state == PrintStateBase::DONE) {
|
||||
if (! print_object->has_mesh(sla_steps[istep]))
|
||||
for (size_t istep = 0; istep < sla_steps.size(); ++istep) {
|
||||
state.step[istep] = print_object->step_state_with_timestamp(sla_steps[istep]);
|
||||
if (state.step[istep].state == PrintStateBase::DONE) {
|
||||
if (!print_object->has_mesh(sla_steps[istep]))
|
||||
// Consider the DONE step without a valid mesh as invalid for the purpose
|
||||
// of mesh visualization.
|
||||
state.step[istep].state = PrintStateBase::INVALID;
|
||||
else
|
||||
for (const ModelInstance *model_instance : print_object->model_object()->instances)
|
||||
// Only the instances, which are currently printable, will have the SLA support structures kept.
|
||||
// The instances outside the print bed will have the GLVolumes of their support structures released.
|
||||
if (model_instance->is_printable())
|
||||
for (const ModelInstance* model_instance : print_object->model_object()->instances)
|
||||
// Only the instances, which are currently printable, will have the SLA support structures kept.
|
||||
// The instances outside the print bed will have the GLVolumes of their support structures released.
|
||||
if (model_instance->is_printable())
|
||||
aux_volume_state.emplace_back(state.step[istep].timestamp, model_instance->id());
|
||||
}
|
||||
}
|
||||
sla_support_state.emplace_back(state);
|
||||
}
|
||||
sla_support_state.emplace_back(state);
|
||||
}
|
||||
}
|
||||
std::sort(model_volume_state.begin(), model_volume_state.end(), model_volume_state_lower);
|
||||
std::sort(aux_volume_state .begin(), aux_volume_state .end(), model_volume_state_lower);
|
||||
std::sort(aux_volume_state.begin(), aux_volume_state.end(), model_volume_state_lower);
|
||||
// Release all ModelVolume based GLVolumes not found in the current Model.
|
||||
for (size_t volume_id = 0; volume_id < m_volumes.volumes.size(); ++ volume_id) {
|
||||
GLVolume *volume = m_volumes.volumes[volume_id];
|
||||
for (size_t volume_id = 0; volume_id < m_volumes.volumes.size(); ++volume_id) {
|
||||
GLVolume* volume = m_volumes.volumes[volume_id];
|
||||
ModelVolumeState key(volume);
|
||||
ModelVolumeState *mvs = nullptr;
|
||||
ModelVolumeState* mvs = nullptr;
|
||||
if (volume->volume_idx() < 0) {
|
||||
auto it = std::lower_bound(aux_volume_state.begin(), aux_volume_state.end(), key, model_volume_state_lower);
|
||||
auto it = std::lower_bound(aux_volume_state.begin(), aux_volume_state.end(), key, model_volume_state_lower);
|
||||
if (it != aux_volume_state.end() && it->geometry_id == key.geometry_id)
|
||||
// This can be an SLA support structure that should not be rendered (in case someone used undo
|
||||
// to revert to before it was generated). We only reuse the volume if that's not the case.
|
||||
if (m_model->objects[volume->composite_id.object_id]->sla_points_status != sla::PointsStatus::NoPoints)
|
||||
mvs = &(*it);
|
||||
} else {
|
||||
auto it = std::lower_bound(model_volume_state.begin(), model_volume_state.end(), key, model_volume_state_lower);
|
||||
}
|
||||
else {
|
||||
auto it = std::lower_bound(model_volume_state.begin(), model_volume_state.end(), key, model_volume_state_lower);
|
||||
if (it != model_volume_state.end() && it->geometry_id == key.geometry_id)
|
||||
mvs = &(*it);
|
||||
mvs = &(*it);
|
||||
}
|
||||
// Emplace instance ID of the volume. Both the aux volumes and model volumes share the same instance ID.
|
||||
// The wipe tower has its own wipe_tower_instance_id().
|
||||
|
@ -1854,19 +1867,23 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
|||
assert(volume_idx_wipe_tower_old == -1);
|
||||
volume_idx_wipe_tower_old = (int)volume_id;
|
||||
}
|
||||
if (! m_reload_delayed)
|
||||
if (!m_reload_delayed)
|
||||
{
|
||||
deleted_volumes.emplace_back(volume, volume_id);
|
||||
delete volume;
|
||||
} else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// This GLVolume will be reused.
|
||||
volume->set_sla_shift_z(0.0);
|
||||
map_glvolume_old_to_new[volume_id] = glvolumes_new.size();
|
||||
mvs->volume_idx = glvolumes_new.size();
|
||||
glvolumes_new.emplace_back(volume);
|
||||
// Update color of the volume based on the current extruder.
|
||||
if (mvs->model_volume != nullptr) {
|
||||
int extruder_id = mvs->model_volume->extruder_id();
|
||||
if (extruder_id != -1)
|
||||
volume->extruder_id = extruder_id;
|
||||
if (mvs->model_volume != nullptr) {
|
||||
int extruder_id = mvs->model_volume->extruder_id();
|
||||
if (extruder_id != -1)
|
||||
volume->extruder_id = extruder_id;
|
||||
|
||||
volume->is_modifier = !mvs->model_volume->is_model_part();
|
||||
volume->set_color_from_model_volume(mvs->model_volume);
|
||||
|
@ -1884,6 +1901,16 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
|||
|
||||
bool update_object_list = false;
|
||||
|
||||
auto find_old_volume_id = [&deleted_volumes](const GLVolume::CompositeID& id) -> unsigned int {
|
||||
for (unsigned int i = 0; i < (unsigned int)deleted_volumes.size(); ++i)
|
||||
{
|
||||
const GLVolumeState& v = deleted_volumes[i];
|
||||
if (v.composite_id == id)
|
||||
return v.volume_idx;
|
||||
}
|
||||
return (unsigned int)-1;
|
||||
};
|
||||
|
||||
if (m_volumes.volumes != glvolumes_new)
|
||||
update_object_list = true;
|
||||
m_volumes.volumes = std::move(glvolumes_new);
|
||||
|
@ -1898,9 +1925,12 @@ void GLCanvas3D::reload_scene(bool refresh_immediately, bool force_full_scene_re
|
|||
assert(it != model_volume_state.end() && it->geometry_id == key.geometry_id);
|
||||
if (it->new_geometry()) {
|
||||
// New volume.
|
||||
unsigned int old_id = find_old_volume_id(it->composite_id);
|
||||
if (old_id != -1)
|
||||
map_glvolume_old_to_new[old_id] = m_volumes.volumes.size();
|
||||
m_volumes.load_object_volume(&model_object, obj_idx, volume_idx, instance_idx, m_color_by, m_initialized);
|
||||
m_volumes.volumes.back()->geometry_id = key.geometry_id;
|
||||
update_object_list = true;
|
||||
update_object_list = true;
|
||||
} else {
|
||||
// Recycling an old GLVolume.
|
||||
GLVolume &existing_volume = *m_volumes.volumes[it->volume_idx];
|
||||
|
|
|
@ -1571,6 +1571,12 @@ void ObjectList::append_menu_item_export_stl(wxMenu* menu) const
|
|||
menu->AppendSeparator();
|
||||
}
|
||||
|
||||
void ObjectList::append_menu_item_reload_from_disk(wxMenu* menu) const
|
||||
{
|
||||
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected volumes from disk")),
|
||||
[this](wxCommandEvent&) { wxGetApp().plater()->reload_from_disk(); }, "", menu, []() { return wxGetApp().plater()->can_reload_from_disk(); }, wxGetApp().plater());
|
||||
}
|
||||
|
||||
void ObjectList::append_menu_item_change_extruder(wxMenu* menu) const
|
||||
{
|
||||
const wxString name = _(L("Change extruder"));
|
||||
|
@ -1620,6 +1626,7 @@ void ObjectList::create_object_popupmenu(wxMenu *menu)
|
|||
append_menu_items_osx(menu);
|
||||
#endif // __WXOSX__
|
||||
|
||||
append_menu_item_reload_from_disk(menu);
|
||||
append_menu_item_export_stl(menu);
|
||||
append_menu_item_fix_through_netfabb(menu);
|
||||
append_menu_item_scale_selection_to_fit_print_volume(menu);
|
||||
|
@ -1643,6 +1650,7 @@ void ObjectList::create_sla_object_popupmenu(wxMenu *menu)
|
|||
append_menu_items_osx(menu);
|
||||
#endif // __WXOSX__
|
||||
|
||||
append_menu_item_reload_from_disk(menu);
|
||||
append_menu_item_export_stl(menu);
|
||||
append_menu_item_fix_through_netfabb(menu);
|
||||
// rest of a object_sla_menu will be added later in:
|
||||
|
@ -1655,8 +1663,9 @@ void ObjectList::create_part_popupmenu(wxMenu *menu)
|
|||
append_menu_items_osx(menu);
|
||||
#endif // __WXOSX__
|
||||
|
||||
append_menu_item_fix_through_netfabb(menu);
|
||||
append_menu_item_reload_from_disk(menu);
|
||||
append_menu_item_export_stl(menu);
|
||||
append_menu_item_fix_through_netfabb(menu);
|
||||
|
||||
append_menu_item_split(menu);
|
||||
|
||||
|
|
|
@ -237,7 +237,8 @@ public:
|
|||
wxMenuItem* append_menu_item_printable(wxMenu* menu, wxWindow* parent);
|
||||
void append_menu_items_osx(wxMenu* menu);
|
||||
wxMenuItem* append_menu_item_fix_through_netfabb(wxMenu* menu);
|
||||
void append_menu_item_export_stl(wxMenu* menu) const ;
|
||||
void append_menu_item_export_stl(wxMenu* menu) const;
|
||||
void append_menu_item_reload_from_disk(wxMenu* menu) const;
|
||||
void append_menu_item_change_extruder(wxMenu* menu) const;
|
||||
void append_menu_item_delete(wxMenu* menu);
|
||||
void append_menu_item_scale_selection_to_fit_print_volume(wxMenu* menu);
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <boost/algorithm/string.hpp>
|
||||
#include <boost/optional.hpp>
|
||||
#include <boost/filesystem/path.hpp>
|
||||
#include <boost/filesystem/operations.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
|
||||
#include <wx/sizer.h>
|
||||
|
@ -1913,6 +1914,7 @@ struct Plater::priv
|
|||
bool can_fix_through_netfabb() const;
|
||||
bool can_set_instance_to_object() const;
|
||||
bool can_mirror() const;
|
||||
bool can_reload_from_disk() const;
|
||||
|
||||
void msw_rescale_object_menu();
|
||||
|
||||
|
@ -1949,7 +1951,6 @@ private:
|
|||
* */
|
||||
std::string m_last_fff_printer_profile_name;
|
||||
std::string m_last_sla_printer_profile_name;
|
||||
bool m_update_objects_list_on_loading{ true };
|
||||
};
|
||||
|
||||
const std::regex Plater::priv::pattern_bundle(".*[.](amf|amf[.]xml|zip[.]amf|3mf|prusa)", std::regex::icase);
|
||||
|
@ -2475,11 +2476,8 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
|
|||
_(L("Object too large?")));
|
||||
}
|
||||
|
||||
if (m_update_objects_list_on_loading)
|
||||
{
|
||||
for (const size_t idx : obj_idxs) {
|
||||
wxGetApp().obj_list()->add_object_to_list(idx);
|
||||
}
|
||||
for (const size_t idx : obj_idxs) {
|
||||
wxGetApp().obj_list()->add_object_to_list(idx);
|
||||
}
|
||||
|
||||
update();
|
||||
|
@ -3103,88 +3101,110 @@ void Plater::priv::update_sla_scene()
|
|||
|
||||
void Plater::priv::reload_from_disk()
|
||||
{
|
||||
Plater::TakeSnapshot snapshot(q, _(L("Reload from Disk")));
|
||||
Plater::TakeSnapshot snapshot(q, _(L("Reload from disk")));
|
||||
|
||||
auto& selection = get_selection();
|
||||
const auto obj_orig_idx = selection.get_object_idx();
|
||||
if (selection.is_wipe_tower() || obj_orig_idx == -1) { return; }
|
||||
int instance_idx = selection.get_instance_idx();
|
||||
const Selection& selection = get_selection();
|
||||
|
||||
auto *object_orig = model.objects[obj_orig_idx];
|
||||
std::vector<fs::path> input_paths(1, object_orig->input_file);
|
||||
|
||||
// disable render to avoid to show intermediate states
|
||||
view3D->get_canvas3d()->enable_render(false);
|
||||
|
||||
// disable update of objects list while loading to avoid to show intermediate states
|
||||
m_update_objects_list_on_loading = false;
|
||||
|
||||
const auto new_idxs = load_files(input_paths, true, false);
|
||||
if (new_idxs.empty())
|
||||
{
|
||||
// error while loading
|
||||
view3D->get_canvas3d()->enable_render(true);
|
||||
if (selection.is_wipe_tower())
|
||||
return;
|
||||
}
|
||||
|
||||
for (const auto idx : new_idxs)
|
||||
// struct to hold selected ModelVolumes by their indices
|
||||
struct SelectedVolume
|
||||
{
|
||||
ModelObject *object = model.objects[idx];
|
||||
object->config.apply(object_orig->config);
|
||||
int object_idx;
|
||||
int volume_idx;
|
||||
|
||||
object->clear_instances();
|
||||
for (const ModelInstance *instance : object_orig->instances)
|
||||
// operators needed by std::algorithms
|
||||
bool operator < (const SelectedVolume& other) const { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); }
|
||||
bool operator == (const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); }
|
||||
};
|
||||
std::vector<SelectedVolume> selected_volumes;
|
||||
|
||||
// collects selected ModelVolumes
|
||||
const std::set<unsigned int>& selected_volumes_idxs = selection.get_volume_idxs();
|
||||
for (unsigned int idx : selected_volumes_idxs)
|
||||
{
|
||||
const GLVolume* v = selection.get_volume(idx);
|
||||
int o_idx = v->object_idx();
|
||||
int v_idx = v->volume_idx();
|
||||
selected_volumes.push_back({ o_idx, v_idx });
|
||||
}
|
||||
std::sort(selected_volumes.begin(), selected_volumes.end());
|
||||
selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end());
|
||||
|
||||
// collects paths of files to load
|
||||
std::vector<fs::path> input_paths;
|
||||
for (const SelectedVolume& v : selected_volumes)
|
||||
{
|
||||
const ModelVolume* volume = model.objects[v.object_idx]->volumes[v.volume_idx];
|
||||
if (!volume->source.input_file.empty() && boost::filesystem::exists(volume->source.input_file))
|
||||
input_paths.push_back(volume->source.input_file);
|
||||
}
|
||||
std::sort(input_paths.begin(), input_paths.end());
|
||||
input_paths.erase(std::unique(input_paths.begin(), input_paths.end()), input_paths.end());
|
||||
|
||||
// load one file at a time
|
||||
for (size_t i = 0; i < input_paths.size(); ++i)
|
||||
{
|
||||
const auto& path = input_paths[i].string();
|
||||
Model new_model;
|
||||
try
|
||||
{
|
||||
object->add_instance(*instance);
|
||||
}
|
||||
|
||||
for (const ModelVolume* v : object_orig->volumes)
|
||||
{
|
||||
if (v->is_modifier())
|
||||
object->add_volume(*v);
|
||||
}
|
||||
|
||||
Vec3d offset = object_orig->origin_translation - object->origin_translation;
|
||||
|
||||
if (object->volumes.size() == object_orig->volumes.size())
|
||||
{
|
||||
for (size_t i = 0; i < object->volumes.size(); i++)
|
||||
new_model = Model::read_from_file(path, nullptr, true, false);
|
||||
for (ModelObject* model_object : new_model.objects)
|
||||
{
|
||||
object->volumes[i]->config.apply(object_orig->volumes[i]->config);
|
||||
object->volumes[i]->translate(offset);
|
||||
model_object->center_around_origin();
|
||||
model_object->ensure_on_bed();
|
||||
}
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
// error while loading
|
||||
view3D->get_canvas3d()->enable_render(true);
|
||||
return;
|
||||
}
|
||||
|
||||
// XXX: Restore more: layer_height_ranges, layer_height_profile (?)
|
||||
// update the selected volumes whose source is the current file
|
||||
for (const SelectedVolume& old_v : selected_volumes)
|
||||
{
|
||||
ModelObject* old_model_object = model.objects[old_v.object_idx];
|
||||
ModelVolume* old_volume = old_model_object->volumes[old_v.volume_idx];
|
||||
int new_volume_idx = old_volume->source.volume_idx;
|
||||
int new_object_idx = old_volume->source.object_idx;
|
||||
|
||||
if (old_volume->source.input_file == path)
|
||||
{
|
||||
if (new_object_idx < (int)new_model.objects.size())
|
||||
{
|
||||
ModelObject* new_model_object = new_model.objects[new_object_idx];
|
||||
if (new_volume_idx < (int)new_model_object->volumes.size())
|
||||
{
|
||||
old_model_object->add_volume(*new_model_object->volumes[new_volume_idx]);
|
||||
ModelVolume* new_volume = old_model_object->volumes.back();
|
||||
new_volume->set_new_unique_id();
|
||||
new_volume->config.apply(old_volume->config);
|
||||
new_volume->set_type(old_volume->type());
|
||||
new_volume->set_material_id(old_volume->material_id());
|
||||
new_volume->set_transformation(old_volume->get_transformation());
|
||||
new_volume->translate(new_volume->get_transformation().get_matrix(true) * (new_volume->source.mesh_offset - old_volume->source.mesh_offset));
|
||||
std::swap(old_model_object->volumes[old_v.volume_idx], old_model_object->volumes.back());
|
||||
old_model_object->delete_volume(old_model_object->volumes.size() - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// re-enable update of objects list
|
||||
m_update_objects_list_on_loading = true;
|
||||
model.adjust_min_z();
|
||||
|
||||
// puts the new objects into the list
|
||||
for (const auto idx : new_idxs)
|
||||
{
|
||||
wxGetApp().obj_list()->add_object_to_list(idx);
|
||||
}
|
||||
|
||||
remove(obj_orig_idx);
|
||||
// update 3D scene
|
||||
update();
|
||||
|
||||
// new GLVolumes have been created at this point, so update their printable state
|
||||
for (size_t i = 0; i < model.objects.size(); ++i)
|
||||
{
|
||||
view3D->get_canvas3d()->update_instance_printable_state_for_object(i);
|
||||
}
|
||||
|
||||
// re-enable render
|
||||
view3D->get_canvas3d()->enable_render(true);
|
||||
|
||||
// the previous call to remove() clears the selection
|
||||
// select newly added objects
|
||||
selection.clear();
|
||||
for (const auto idx : new_idxs)
|
||||
{
|
||||
selection.add_instance((unsigned int)idx - 1, instance_idx, false);
|
||||
}
|
||||
}
|
||||
|
||||
void Plater::priv::fix_through_netfabb(const int obj_idx, const int vol_idx/* = -1*/)
|
||||
|
@ -3609,6 +3629,9 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
|
|||
append_menu_item(menu, wxID_ANY, _(L("Delete")) + "\tDel", _(L("Remove the selected object")),
|
||||
[this](wxCommandEvent&) { q->remove_selected(); }, "delete", nullptr, [this]() { return can_delete(); }, q);
|
||||
|
||||
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected volumes from disk")),
|
||||
[this](wxCommandEvent&) { q->reload_from_disk(); }, "", menu, [this]() { return can_reload_from_disk(); }, q);
|
||||
|
||||
sidebar->obj_list()->append_menu_item_export_stl(menu);
|
||||
}
|
||||
else {
|
||||
|
@ -3635,8 +3658,8 @@ bool Plater::priv::init_common_menu(wxMenu* menu, const bool is_part/* = false*/
|
|||
wxMenuItem* menu_item_printable = sidebar->obj_list()->append_menu_item_printable(menu, q);
|
||||
menu->AppendSeparator();
|
||||
|
||||
append_menu_item(menu, wxID_ANY, _(L("Reload from Disk")), _(L("Reload the selected file from Disk")),
|
||||
[this](wxCommandEvent&) { reload_from_disk(); });
|
||||
append_menu_item(menu, wxID_ANY, _(L("Reload from disk")), _(L("Reload the selected object from disk")),
|
||||
[this](wxCommandEvent&) { reload_from_disk(); }, "", nullptr, [this]() { return can_reload_from_disk(); }, q);
|
||||
|
||||
append_menu_item(menu, wxID_ANY, _(L("Export as STL")) + dots, _(L("Export the selected object as STL file")),
|
||||
[this](wxCommandEvent&) { q->export_stl(false, true); });
|
||||
|
@ -3791,6 +3814,48 @@ bool Plater::priv::can_mirror() const
|
|||
return get_selection().is_from_single_instance();
|
||||
}
|
||||
|
||||
bool Plater::priv::can_reload_from_disk() const
|
||||
{
|
||||
// struct to hold selected ModelVolumes by their indices
|
||||
struct SelectedVolume
|
||||
{
|
||||
int object_idx;
|
||||
int volume_idx;
|
||||
|
||||
// operators needed by std::algorithms
|
||||
bool operator < (const SelectedVolume& other) const { return (object_idx < other.object_idx) || ((object_idx == other.object_idx) && (volume_idx < other.volume_idx)); }
|
||||
bool operator == (const SelectedVolume& other) const { return (object_idx == other.object_idx) && (volume_idx == other.volume_idx); }
|
||||
};
|
||||
std::vector<SelectedVolume> selected_volumes;
|
||||
|
||||
const Selection& selection = get_selection();
|
||||
|
||||
// collects selected ModelVolumes
|
||||
const std::set<unsigned int>& selected_volumes_idxs = selection.get_volume_idxs();
|
||||
for (unsigned int idx : selected_volumes_idxs)
|
||||
{
|
||||
const GLVolume* v = selection.get_volume(idx);
|
||||
int o_idx = v->object_idx();
|
||||
int v_idx = v->volume_idx();
|
||||
selected_volumes.push_back({ o_idx, v_idx });
|
||||
}
|
||||
std::sort(selected_volumes.begin(), selected_volumes.end());
|
||||
selected_volumes.erase(std::unique(selected_volumes.begin(), selected_volumes.end()), selected_volumes.end());
|
||||
|
||||
// collects paths of files to load
|
||||
std::vector<fs::path> paths;
|
||||
for (const SelectedVolume& v : selected_volumes)
|
||||
{
|
||||
const ModelVolume* volume = model.objects[v.object_idx]->volumes[v.volume_idx];
|
||||
if (!volume->source.input_file.empty() && boost::filesystem::exists(volume->source.input_file))
|
||||
paths.push_back(volume->source.input_file);
|
||||
}
|
||||
std::sort(paths.begin(), paths.end());
|
||||
paths.erase(std::unique(paths.begin(), paths.end()), paths.end());
|
||||
|
||||
return !paths.empty();
|
||||
}
|
||||
|
||||
void Plater::priv::set_bed_shape(const Pointfs& shape, const std::string& custom_texture, const std::string& custom_model)
|
||||
{
|
||||
bool new_shape = bed.set_shape(shape, custom_texture, custom_model);
|
||||
|
@ -4573,6 +4638,11 @@ void Plater::export_3mf(const boost::filesystem::path& output_path)
|
|||
}
|
||||
}
|
||||
|
||||
void Plater::reload_from_disk()
|
||||
{
|
||||
p->reload_from_disk();
|
||||
}
|
||||
|
||||
bool Plater::has_toolpaths_to_export() const
|
||||
{
|
||||
return p->preview->get_canvas3d()->has_toolpaths_to_export();
|
||||
|
@ -5118,6 +5188,7 @@ bool Plater::can_copy_to_clipboard() const
|
|||
|
||||
bool Plater::can_undo() const { return p->undo_redo_stack().has_undo_snapshot(); }
|
||||
bool Plater::can_redo() const { return p->undo_redo_stack().has_redo_snapshot(); }
|
||||
bool Plater::can_reload_from_disk() const { return p->can_reload_from_disk(); }
|
||||
const UndoRedo::Stack& Plater::undo_redo_stack_main() const { return p->undo_redo_stack_main(); }
|
||||
void Plater::enter_gizmos_stack() { p->enter_gizmos_stack(); }
|
||||
void Plater::leave_gizmos_stack() { p->leave_gizmos_stack(); }
|
||||
|
|
|
@ -187,6 +187,7 @@ public:
|
|||
void export_stl(bool extended = false, bool selection_only = false);
|
||||
void export_amf();
|
||||
void export_3mf(const boost::filesystem::path& output_path = boost::filesystem::path());
|
||||
void reload_from_disk();
|
||||
bool has_toolpaths_to_export() const;
|
||||
void export_toolpaths_to_obj() const;
|
||||
void reslice();
|
||||
|
@ -253,6 +254,7 @@ public:
|
|||
bool can_copy_to_clipboard() const;
|
||||
bool can_undo() const;
|
||||
bool can_redo() const;
|
||||
bool can_reload_from_disk() const;
|
||||
|
||||
void msw_rescale();
|
||||
|
||||
|
|
|
@ -472,7 +472,7 @@ void Selection::volumes_changed(const std::vector<size_t> &map_volume_old_to_new
|
|||
for (unsigned int idx : m_list)
|
||||
if (map_volume_old_to_new[idx] != size_t(-1)) {
|
||||
unsigned int new_idx = (unsigned int)map_volume_old_to_new[idx];
|
||||
assert((*m_volumes)[new_idx]->selected);
|
||||
(*m_volumes)[new_idx]->selected = true;
|
||||
list_new.insert(new_idx);
|
||||
}
|
||||
m_list = std::move(list_new);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue