diff options
author | Oleksandra Yushchenko <yusanka@gmail.com> | 2021-03-15 12:04:45 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-15 12:04:45 +0300 |
commit | e002f0066fd96f38a5241a429f2228278de28f1d (patch) | |
tree | d65aec716d2f314580c51718992daae52f208bf9 /src/slic3r/GUI/ObjectDataViewModel.cpp | |
parent | 95c5763b83a9f0cb85a62a12e8955825503b02ea (diff) |
Ys code refactoring (#6227)
* GUI_ObjectList code refactoring:
The MenuFactory structure contains functions related to the context menu and bitmaps used to different volume types.
The SettingsFactory structure contains functions to getting overridden options, its bundles and bitmaps used to setting categories.
Fixed bugs/crashes:
1. Add object -> Add Settings from 3D scene -> Right click on object => Part's Settings list instead of object's
(Same behavior if something else but Object is selected in ObjectList)
2. Add settings to the part -> Change part type to the "Support Blocker/Enforcer" -> Settings disappears (it's OK) but =>
Save Project -> Open project => Support Blocker/Enforcer has a settings
3. Add part for object -> Change type of part -> Change monitor DPI -> old type icon appears
4. Select all instances in ObjectList -> Context menu in 3D scene -> Add Settings -> Select some category -> Crash
* ObjectLayers: Fixed a crash on re-scaling, when some layer range is selected
* Fixed OSX build
* Added menu item "Split to Objects" for multipart objects
+ Fixed bug: Add 2 parts,
Add some settings for one part
Delete part without settings => Single part object without settings, but settings are applied for the object.
+ Next refactoring: use same menu for Plater and ObjectList
Diffstat (limited to 'src/slic3r/GUI/ObjectDataViewModel.cpp')
-rw-r--r-- | src/slic3r/GUI/ObjectDataViewModel.cpp | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/src/slic3r/GUI/ObjectDataViewModel.cpp b/src/slic3r/GUI/ObjectDataViewModel.cpp index 7de37fb48..80655352b 100644 --- a/src/slic3r/GUI/ObjectDataViewModel.cpp +++ b/src/slic3r/GUI/ObjectDataViewModel.cpp @@ -2,7 +2,7 @@ #include "wxExtensions.hpp" #include "BitmapCache.hpp" #include "GUI_App.hpp" -#include "GUI_ObjectList.hpp" +#include "GUI_Factories.hpp" #include "I18N.hpp" #include "libslic3r/Model.hpp" @@ -44,8 +44,9 @@ void ObjectDataViewModelNode::init_container() #endif //__WXGTK__ } -#define LAYER_ROOT_ICON "edit_layers_all" -#define LAYER_ICON "edit_layers_some" +static constexpr char LayerRootIcon[] = "edit_layers_all"; +static constexpr char LayerIcon[] = "edit_layers_some"; +static constexpr char WarningIcon[] = "exclamation"; ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent, const ItemType type) : m_parent(parent), @@ -65,7 +66,7 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent } else if (type == itLayerRoot) { - m_bmp = create_scaled_bitmap(LAYER_ROOT_ICON); // FIXME: pass window ptr + m_bmp = create_scaled_bitmap(LayerRootIcon); // FIXME: pass window ptr m_name = _(L("Layers")); } @@ -94,7 +95,7 @@ ObjectDataViewModelNode::ObjectDataViewModelNode(ObjectDataViewModelNode* parent } const std::string label_range = (boost::format(" %.2f-%.2f ") % layer_range.first % layer_range.second).str(); m_name = _(L("Range")) + label_range + "(" + _(L("mm")) + ")"; - m_bmp = create_scaled_bitmap(LAYER_ICON); // FIXME: pass window ptr + m_bmp = create_scaled_bitmap(LayerIcon); // FIXME: pass window ptr set_action_and_extruder_icons(); init_container(); @@ -140,17 +141,14 @@ void ObjectDataViewModelNode::update_settings_digest_bitmaps() { m_bmp = m_empty_bmp; - std::map<std::string, wxBitmap>& categories_icon = Slic3r::GUI::wxGetApp().obj_list()->CATEGORY_ICON; - std::string scaled_bitmap_name = m_name.ToUTF8().data(); scaled_bitmap_name += "-em" + std::to_string(wxGetApp().em_unit()) + (wxGetApp().dark_mode() ? "-dm" : ""); wxBitmap *bmp = m_bitmap_cache->find(scaled_bitmap_name); if (bmp == nullptr) { std::vector<wxBitmap> bmps; - for (auto& cat : m_opt_categories) - bmps.emplace_back( categories_icon.find(cat) == categories_icon.end() ? - wxNullBitmap : categories_icon.at(cat)); + for (auto& category : m_opt_categories) + bmps.emplace_back(SettingsFactory::get_category_bitmap(category)); bmp = m_bitmap_cache->insert(scaled_bitmap_name, bmps); } @@ -249,6 +247,9 @@ static int get_root_idx(ObjectDataViewModelNode *parent_node, const ItemType roo ObjectDataViewModel::ObjectDataViewModel() { m_bitmap_cache = new Slic3r::GUI::BitmapCache; + + m_volume_bmps = MenuFactory::get_volume_bitmaps(); + m_warning_bmp = create_scaled_bitmap(WarningIcon); } ObjectDataViewModel::~ObjectDataViewModel() @@ -267,7 +268,7 @@ wxDataViewItem ObjectDataViewModel::Add(const wxString &name, auto root = new ObjectDataViewModelNode(name, extruder_str); // Add error icon if detected auto-repaire if (has_errors) - root->m_bmp = *m_warning_bmp; + root->m_bmp = m_warning_bmp; m_objects.push_back(root); // notify control @@ -317,7 +318,7 @@ wxDataViewItem ObjectDataViewModel::AddVolumeChild( const wxDataViewItem &parent // if part with errors is added, but object wasn't marked, then mark it if (!obj_errors && has_errors) - root->SetBitmap(*m_warning_bmp); + root->SetBitmap(m_warning_bmp); // notify control const wxDataViewItem child((void*)node); @@ -1434,10 +1435,20 @@ void ObjectDataViewModel::SetVolumeType(const wxDataViewItem &item, const Slic3r return; ObjectDataViewModelNode *node = static_cast<ObjectDataViewModelNode*>(item.GetID()); - node->SetBitmap(*m_volume_bmps[int(type)]); + node->SetVolumeType(type); + node->SetBitmap(m_volume_bmps[int(type)]); ItemChanged(item); } +ModelVolumeType ObjectDataViewModel::GetVolumeType(const wxDataViewItem& item) +{ + if (!item.IsOk() || GetItemType(item) != itVolume) + return ModelVolumeType::INVALID; + + ObjectDataViewModelNode *node = static_cast<ObjectDataViewModelNode*>(item.GetID()); + return node->GetVolumeType(); +} + wxDataViewItem ObjectDataViewModel::SetPrintableState( PrintIndicator printable, int obj_idx, @@ -1480,6 +1491,9 @@ wxDataViewItem ObjectDataViewModel::SetObjectPrintableState( void ObjectDataViewModel::Rescale() { + m_volume_bmps = MenuFactory::get_volume_bitmaps(); + m_warning_bmp = create_scaled_bitmap(WarningIcon); + wxDataViewItemArray all_items; GetAllChildren(wxDataViewItem(0), all_items); @@ -1494,15 +1508,15 @@ void ObjectDataViewModel::Rescale() switch (node->m_type) { case itObject: - if (node->m_bmp.IsOk()) node->m_bmp = *m_warning_bmp; + if (node->m_bmp.IsOk()) node->m_bmp = m_warning_bmp; break; case itVolume: node->m_bmp = GetVolumeIcon(node->m_volume_type, node->m_bmp.GetWidth() != node->m_bmp.GetHeight()); break; case itLayerRoot: - node->m_bmp = create_scaled_bitmap(LAYER_ROOT_ICON); + node->m_bmp = create_scaled_bitmap(LayerRootIcon); case itLayer: - node->m_bmp = create_scaled_bitmap(LAYER_ICON); + node->m_bmp = create_scaled_bitmap(LayerIcon); break; default: break; } @@ -1514,7 +1528,7 @@ void ObjectDataViewModel::Rescale() wxBitmap ObjectDataViewModel::GetVolumeIcon(const Slic3r::ModelVolumeType vol_type, const bool is_marked/* = false*/) { if (!is_marked) - return *m_volume_bmps[static_cast<int>(vol_type)]; + return m_volume_bmps[static_cast<int>(vol_type)]; std::string scaled_bitmap_name = "warning" + std::to_string(static_cast<int>(vol_type)); scaled_bitmap_name += "-em" + std::to_string(Slic3r::GUI::wxGetApp().em_unit()); @@ -1523,8 +1537,8 @@ wxBitmap ObjectDataViewModel::GetVolumeIcon(const Slic3r::ModelVolumeType vol_ty if (bmp == nullptr) { std::vector<wxBitmap> bmps; - bmps.emplace_back(*m_warning_bmp); - bmps.emplace_back(*m_volume_bmps[static_cast<int>(vol_type)]); + bmps.emplace_back(m_warning_bmp); + bmps.emplace_back(m_volume_bmps[static_cast<int>(vol_type)]); bmp = m_bitmap_cache->insert(scaled_bitmap_name, bmps); } @@ -1543,7 +1557,7 @@ void ObjectDataViewModel::DeleteWarningIcon(const wxDataViewItem& item, const bo return; if (node->GetType() & itVolume) { - node->SetBitmap(*m_volume_bmps[static_cast<int>(node->volume_type())]); + node->SetBitmap(m_volume_bmps[static_cast<int>(node->volume_type())]); return; } |