Skip to content

Commit

Permalink
Modifiers Gallery (#6703)
Browse files Browse the repository at this point in the history
* Added GalleryDialog

* GalleryDialog improvements:
* Added DnD functionality
* Added "Delete custom shapes" function
  • Loading branch information
YuSanka authored Jul 12, 2021
1 parent 569b7d7 commit d6fdf2d
Show file tree
Hide file tree
Showing 23 changed files with 528 additions and 7 deletions.
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

0 comments on commit d6fdf2d

Please sign in to comment.