Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modifiers Gallery #6703

Merged
merged 2 commits into from
Jul 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file added resources/gallery/system/box.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gallery/system/box.stl
Binary file not shown.
Binary file added resources/gallery/system/bunny.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gallery/system/bunny.stl
Binary file not shown.
Binary file added resources/gallery/system/cylinder.stl
Binary file not shown.
Binary file not shown.
Binary file added resources/gallery/system/pyramid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gallery/system/pyramid.stl
Binary file not shown.
Binary file added resources/gallery/system/sphere.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/gallery/system/sphere.stl
Binary file not shown.
1 change: 1 addition & 0 deletions src/PrusaSlicer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,7 @@ bool CLI::setup(int argc, char **argv)
set_resources_dir(path_resources.string());
set_var_dir((path_resources / "icons").string());
set_local_dir((path_resources / "localization").string());
set_gallery_dir((path_resources / "gallery").string());

// Parse all command line options into a DynamicConfig.
// If any option is unsupported, print usage and abort immediately.
Expand Down
8 changes: 8 additions & 0 deletions src/libslic3r/Utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ void set_local_dir(const std::string &path);
// Return a full path to the localization directory.
const std::string& localization_dir();

// Set a path with shapes gallery files.
void set_gallery_dir(const std::string &path);
// Return a full path to the gallery directory.
const std::string& gallery_dir();

// Set a path with preset files.
void set_data_dir(const std::string &path);
// Return a full path to the GUI resource files.
Expand Down Expand Up @@ -91,6 +96,9 @@ extern bool is_plain_file(const boost::filesystem::directory_entry &path);
extern bool is_ini_file(const boost::filesystem::directory_entry &path);
extern bool is_idx_file(const boost::filesystem::directory_entry &path);
extern bool is_gcode_file(const std::string &path);
extern bool is_img_file(const std::string& path);
extern bool is_stl_file(const boost::filesystem::directory_entry& path);
extern bool is_stl_file(const std::string& path);

// File path / name / extension splitting utilities, working with UTF-8,
// to be published to Perl.
Expand Down
27 changes: 27 additions & 0 deletions src/libslic3r/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ const std::string& localization_dir()
return g_local_dir;
}

static std::string g_gallery_dir;

void set_gallery_dir(const std::string &dir)
{
g_gallery_dir = dir;
}

const std::string& gallery_dir()
{
return g_gallery_dir;
}

// Translate function callback, to call wxWidgets translate function to convert non-localized UTF8 string to a localized one.
Slic3r::I18N::translate_fn_type Slic3r::I18N::translate_fn = nullptr;

Expand Down Expand Up @@ -744,6 +756,21 @@ bool is_gcode_file(const std::string &path)
boost::iends_with(path, ".g") || boost::iends_with(path, ".ngc");
}

bool is_img_file(const std::string &path)
{
return boost::iends_with(path, ".png") || boost::iends_with(path, ".svg");
}

bool is_stl_file(const boost::filesystem::directory_entry& dir_entry)
{
return is_plain_file(dir_entry) && strcasecmp(dir_entry.path().extension().string().c_str(), ".stl") == 0;
}

bool is_stl_file(const std::string &path)
{
return boost::iends_with(path, ".stl");
}

} // namespace Slic3r

#ifdef WIN32
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ set(SLIC3R_GUI_SOURCES
GUI/GUI_Factories.hpp
GUI/GUI_ObjectList.cpp
GUI/GUI_ObjectList.hpp
GUI/GalleryDialog.cpp
GUI/GalleryDialog.hpp
GUI/GUI_ObjectManipulation.cpp
GUI/GUI_ObjectManipulation.hpp
GUI/GUI_ObjectSettings.cpp
Expand Down
6 changes: 6 additions & 0 deletions src/slic3r/GUI/GUI_Factories.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,12 @@ wxMenu* MenuFactory::append_submenu_add_generic(wxMenu* menu, ModelVolumeType ty
[type, item](wxCommandEvent&) { obj_list()->load_generic_subobject(item, type); }, "", menu);
}

if (wxGetApp().get_mode() == comExpert && type != ModelVolumeType::INVALID) {
sub_menu->AppendSeparator();
append_menu_item(sub_menu, wxID_ANY, _L("Gallery"), "",
[type](wxCommandEvent&) { obj_list()->load_subobject(type, true); }, "", menu);
}

return sub_menu;
}

Expand Down
25 changes: 20 additions & 5 deletions src/slic3r/GUI/GUI_ObjectList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "I18N.hpp"
#include "Plater.hpp"
#include "BitmapComboBox.hpp"
#include "GalleryDialog.hpp"
#if ENABLE_PROJECT_DIRTY_STATE
#include "MainFrame.hpp"
#endif // ENABLE_PROJECT_DIRTY_STATE
Expand Down Expand Up @@ -1337,7 +1338,7 @@ bool ObjectList::is_instance_or_object_selected()
return selection.is_single_full_instance() || selection.is_single_full_object();
}

void ObjectList::load_subobject(ModelVolumeType type)
void ObjectList::load_subobject(ModelVolumeType type, bool from_galery/* = false*/)
{
wxDataViewItem item = GetSelection();
// we can add volumes for Object or Instance
Expand All @@ -1351,10 +1352,14 @@ void ObjectList::load_subobject(ModelVolumeType type)
if (m_objects_model->GetItemType(item)&itInstance)
item = m_objects_model->GetItemById(obj_idx);

std::vector<ModelVolume*> volumes;
load_part((*m_objects)[obj_idx], volumes, type, from_galery);

if (volumes.empty())
return;

take_snapshot(_L("Load Part"));

std::vector<ModelVolume*> volumes;
load_part((*m_objects)[obj_idx], volumes, type);
wxDataViewItemArray items = reorder_volumes_and_get_selection(obj_idx, [volumes](const ModelVolume* volume) {
return std::find(volumes.begin(), volumes.end(), volume) != volumes.end(); });

Expand All @@ -1371,12 +1376,22 @@ void ObjectList::load_subobject(ModelVolumeType type)
selection_changed();
}

void ObjectList::load_part(ModelObject* model_object, std::vector<ModelVolume*>& added_volumes, ModelVolumeType type)
void ObjectList::load_part(ModelObject* model_object, std::vector<ModelVolume*>& added_volumes, ModelVolumeType type, bool from_galery/* = false*/)
{
wxWindow* parent = wxGetApp().tab_panel()->GetPage(0);

wxArrayString input_files;
wxGetApp().import_model(parent, input_files);

if (from_galery) {
GalleryDialog dlg(this);
if (dlg.ShowModal() == wxID_CANCEL)
return;
dlg.get_input_files(input_files);
if (input_files.IsEmpty())
return;
}
else
wxGetApp().import_model(parent, input_files);

wxProgressDialog dlg(_L("Loading") + dots, "", 100, wxGetApp().plater(), wxPD_AUTO_HIDE);
wxBusyCursor busy;
Expand Down
4 changes: 2 additions & 2 deletions src/slic3r/GUI/GUI_ObjectList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ class ObjectList : public wxDataViewCtrl
void show_settings(const wxDataViewItem settings_item);
bool is_instance_or_object_selected();

void load_subobject(ModelVolumeType type);
void load_part(ModelObject* model_object, std::vector<ModelVolume*> &added_volumes, ModelVolumeType type);
void load_subobject(ModelVolumeType type, bool from_galery = false);
void load_part(ModelObject* model_object, std::vector<ModelVolume*> &added_volumes, ModelVolumeType type, bool from_galery = false);
void load_generic_subobject(const std::string& type_name, const ModelVolumeType type);
void load_shape_object(const std::string &type_name);
void load_mesh_object(const TriangleMesh &mesh, const wxString &name, bool center = true);
Expand Down
Loading