Skip to content

Commit

Permalink
DiffPresetDialog, non modal to compare two presets.
Browse files Browse the repository at this point in the history
Added menu item "Window->Compare presets" to compare more than one type
of presets.
Code refactoring for PresetComboBox: Use suffix "modified" just for
PlaterPresetComboBox and TabPresetComboBox
Code refactoring. wxDataViewCtrl and related functions extracted from
DiffPresetDialog and UnsavedChangesDialog to the separate class
DiffViewCtrl
Code refactoring, Tab.cpp: Build all unregular pages on a first build of
the Printer Settings

Squashed commit of the following:

commit 91f45a8a2d97d252337c7306dd02db607fd79c00
Author: Vojtech Bubnik <[email protected]>
Date:   Thu Feb 4 09:34:29 2021 +0100

    Fixed after merge

commit 09aa502498b08c059ecdf334f5db1567739b4520
Merge: 6df8e83 0baa92f
Author: Vojtech Bubnik <[email protected]>
Date:   Thu Feb 4 09:31:43 2021 +0100

    Merge remote-tracking branch 'remotes/origin/master' into ys_diff_dlg

commit 6df8e83
Author: Vojtech Bubnik <[email protected]>
Date:   Thu Feb 4 09:29:53 2021 +0100

    Tiny beautification.

commit e781cea
Author: Vojtech Bubnik <[email protected]>
Date:   Wed Feb 3 18:05:19 2021 +0100

    Reworked copying of PresetBundles:
    1) Simplified by using the default copy constructors and copy operators.
    2) Made safer by not allowing PresetCollection and PhysicalPrinterPresetCollection
       to be copied or instantiated outside of PresetBundle.
    3) Fixed Preset::vendor pointers after copying PresetBundle.

commit a8f0b7a
Author: YuSanka <[email protected]>
Date:   Mon Jan 25 16:13:53 2021 +0100

    DiffPresetsDialog: Show compatibility to print/printer presets selected in DiffPresetDialog

commit 597451f
Merge: cce5b57 59017a7
Author: YuSanka <[email protected]>
Date:   Thu Jan 21 12:14:48 2021 +0100

    Merge remote-tracking branch 'origin/master' into ys_diff_dlg

commit cce5b57
Author: YuSanka <[email protected]>
Date:   Thu Jan 21 12:11:40 2021 +0100

    DiffPresetDialog: Fixed crash on ASAN build

commit ad8d728
Author: YuSanka <[email protected]>
Date:   Wed Jan 20 16:38:28 2021 +0100

    FullCompareDialog improvements

commit 316bafb
Author: YuSanka <[email protected]>
Date:   Wed Jan 20 09:25:46 2021 +0100

    DiffPresetDialog improvements:
    * Update presets lists after save changes in edited preset or change printer_technology
    * Tab.cpp: Build all unregular pages on a first build of the Printer Settings

commit 01171c8
Author: YuSanka <[email protected]>
Date:   Tue Jan 19 17:26:28 2021 +0100

    DiffPresetDialog : improvements
    * This dialog is non-modal now
    * "Compare presets" menu item is moved from "View" to the "Window" menu group
    * Added info tooltips for the bitmap buttons between presets
    * Added "Show all presets" checkbox
    * Show full difference between printer presets with different count of extruders

commit 3d38b62
Merge: e50fe6d 9a2310a
Author: YuSanka <[email protected]>
Date:   Mon Jan 18 10:00:18 2021 +0100

    Merge remote-tracking branch 'origin/master' into ys_diff_dlg

commit e50fe6d
Author: YuSanka <[email protected]>
Date:   Sat Jan 16 02:27:24 2021 +0100

    DiffPresetDialog improvements
    Added menu item "View->Compare presets" to compare more than one type of presets

commit bf08b7c
Author: YuSanka <[email protected]>
Date:   Sat Jan 16 00:28:39 2021 +0100

    Code refactoring. wxDataViewCtrl and related functions extracted from DiffPresetDialog and UnsavedChangesDialog to the separate class DiffViewCtrl

commit 7aeb630
Author: YuSanka <[email protected]>
Date:   Fri Jan 15 21:35:43 2021 +0100

    DiffPresetDialog: first implementation

commit 2f23d5a
Author: YuSanka <[email protected]>
Date:   Thu Jan 14 16:28:43 2021 +0100

    Code refactoring for PresetComboBox.
    Use suffix "modified" just for PlaterPresetComboBox and TabPresetComboBox
  • Loading branch information
bubnikv committed Feb 4, 2021
1 parent 0baa92f commit 4cdcfe6
Show file tree
Hide file tree
Showing 17 changed files with 1,149 additions and 314 deletions.
30 changes: 30 additions & 0 deletions resources/icons/compare.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions resources/icons/equal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions resources/icons/not_equal.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 12 additions & 4 deletions src/libslic3r/Preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,10 +616,6 @@ PresetCollection::PresetCollection(Preset::Type type, const std::vector<std::str
m_edited_preset.config.apply(m_presets.front().config);
}

PresetCollection::~PresetCollection()
{
}

void PresetCollection::reset(bool delete_files)
{
if (m_presets.size() > m_num_default_presets) {
Expand Down Expand Up @@ -1278,6 +1274,18 @@ std::vector<std::string> PresetCollection::merge_presets(PresetCollection &&othe
return duplicates;
}

void PresetCollection::update_vendor_ptrs_after_copy(const VendorMap &new_vendors)
{
for (Preset &preset : m_presets)
if (preset.vendor != nullptr) {
assert(! preset.is_default && ! preset.is_external);
// Re-assign a pointer to the vendor structure in the new PresetBundle.
auto it = new_vendors.find(preset.vendor->id);
assert(it != new_vendors.end());
preset.vendor = &it->second;
}
}

void PresetCollection::update_map_alias_to_profile_name()
{
m_map_alias_to_profile_name.clear();
Expand Down
40 changes: 27 additions & 13 deletions src/libslic3r/Preset.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,11 @@ class Preset
TYPE_COUNT,
};

Preset(Type type, const std::string &name, bool is_default = false) : type(type), is_default(is_default), name(name) {}

Type type = TYPE_INVALID;

// The preset represents a "default" set of properties,
// pulled from the default values of the PrintConfig (see PrintConfigDef for their definitions).
bool is_default;
bool is_default = false;
// External preset points to a configuration, which has been loaded but not imported
// into the Slic3r default configuration location.
bool is_external = false;
Expand Down Expand Up @@ -233,6 +231,9 @@ class Preset
static std::string remove_invalid_keys(DynamicPrintConfig &config, const DynamicPrintConfig &default_config);

protected:
Preset(Type type, const std::string &name, bool is_default = false) : type(type), is_default(is_default), name(name) {}
Preset() = default;

friend class PresetCollection;
friend class PresetBundle;
};
Expand All @@ -256,7 +257,6 @@ class PresetCollection
public:
// Initialize the PresetCollection with the "- default -" preset.
PresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -");
~PresetCollection();

typedef std::deque<Preset>::iterator Iterator;
typedef std::deque<Preset>::const_iterator ConstIterator;
Expand Down Expand Up @@ -460,6 +460,15 @@ class PresetCollection
size_t num_default_presets() { return m_num_default_presets; }

protected:
PresetCollection() = default;
// Copy constructor and copy operators are not to be used from outside PresetBundle,
// as the Profile::vendor points to an instance of VendorProfile stored at parent PresetBundle!
PresetCollection(const PresetCollection &other) = default;
PresetCollection& operator=(const PresetCollection &other) = default;
// After copying a collection with the default operators above, call this function
// to adjust Profile::vendor pointers.
void update_vendor_ptrs_after_copy(const VendorMap &vendors);

// Select a preset, if it exists. If it does not exist, select an invalid (-1) index.
// This is a temporary state, which shall be fixed immediately by the following step.
bool select_preset_by_name_strict(const std::string &name);
Expand All @@ -474,10 +483,6 @@ class PresetCollection
void update_map_system_profile_renamed();

private:
PresetCollection();
PresetCollection(const PresetCollection &other);
PresetCollection& operator=(const PresetCollection &other);

// Find a preset position in the sorted list of presets.
// The "-- default -- " preset is always the first, so it needs
// to be handled differently.
Expand Down Expand Up @@ -507,9 +512,9 @@ class PresetCollection
{ return const_cast<PresetCollection*>(this)->find_preset_renamed(name); }

size_t update_compatible_internal(const PresetWithVendorProfile &active_printer, const PresetWithVendorProfile *active_print, PresetSelectCompatibleType unselect_if_incompatible);

public:
static std::vector<std::string> dirty_options(const Preset *edited, const Preset *reference, const bool is_printer_type = false);

private:
// Type of this PresetCollection: TYPE_PRINT, TYPE_FILAMENT or TYPE_PRINTER.
Preset::Type m_type;
// List of presets, starting with the "- default -" preset.
Expand All @@ -531,7 +536,7 @@ class PresetCollection
// Path to the directory to store the config files into.
std::string m_dir_path;

// to access select_preset_by_name_strict()
// to access select_preset_by_name_strict() and the default & copy constructors.
friend class PresetBundle;
};

Expand All @@ -542,9 +547,17 @@ class PrinterPresetCollection : public PresetCollection
public:
PrinterPresetCollection(Preset::Type type, const std::vector<std::string> &keys, const Slic3r::StaticPrintConfig &defaults, const std::string &default_name = "- default -") :
PresetCollection(type, keys, defaults, default_name) {}

const Preset& default_preset_for(const DynamicPrintConfig &config) const override;

const Preset* find_by_model_id(const std::string &model_id) const;

private:
PrinterPresetCollection() = default;
PrinterPresetCollection(const PrinterPresetCollection &other) = default;
PrinterPresetCollection& operator=(const PrinterPresetCollection &other) = default;

friend class PresetBundle;
};

namespace PresetUtils {
Expand Down Expand Up @@ -634,7 +647,6 @@ class PhysicalPrinterCollection
{
public:
PhysicalPrinterCollection(const std::vector<std::string>& keys);
~PhysicalPrinterCollection() {}

typedef std::deque<PhysicalPrinter>::iterator Iterator;
typedef std::deque<PhysicalPrinter>::const_iterator ConstIterator;
Expand Down Expand Up @@ -725,7 +737,9 @@ class PhysicalPrinterCollection
const DynamicPrintConfig& default_config() const { return m_default_config; }

private:
PhysicalPrinterCollection& operator=(const PhysicalPrinterCollection& other);
friend class PresetBundle;
PhysicalPrinterCollection() = default;
PhysicalPrinterCollection& operator=(const PhysicalPrinterCollection& other) = default;

// Find a physical printer position in the sorted list of printers.
// The name of a printer should be unique and case insensitive
Expand Down
27 changes: 26 additions & 1 deletion src/libslic3r/PresetBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,33 @@ PresetBundle::PresetBundle() :
this->project_config.apply_only(FullPrintConfig::defaults(), s_project_options);
}

PresetBundle::~PresetBundle()
PresetBundle::PresetBundle(const PresetBundle &rhs)
{
*this = rhs;
}

PresetBundle& PresetBundle::operator=(const PresetBundle &rhs)
{
prints = rhs.prints;
sla_prints = rhs.sla_prints;
filaments = rhs.filaments;
sla_materials = rhs.sla_materials;
printers = rhs.printers;
physical_printers = rhs.physical_printers;

filament_presets = rhs.filament_presets;
project_config = rhs.project_config;
vendors = rhs.vendors;
obsolete_presets = rhs.obsolete_presets;

// Adjust Preset::vendor pointers to point to the copied vendors map.
prints .update_vendor_ptrs_after_copy(this->vendors);
sla_prints .update_vendor_ptrs_after_copy(this->vendors);
filaments .update_vendor_ptrs_after_copy(this->vendors);
sla_materials.update_vendor_ptrs_after_copy(this->vendors);
printers .update_vendor_ptrs_after_copy(this->vendors);

return *this;
}

void PresetBundle::reset(bool delete_files)
Expand Down
3 changes: 2 additions & 1 deletion src/libslic3r/PresetBundle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class PresetBundle
{
public:
PresetBundle();
~PresetBundle();
PresetBundle(const PresetBundle &rhs);
PresetBundle& operator=(const PresetBundle &rhs);

// Remove all the presets but the "-- default --".
// Optionally remove all the files referenced by the presets from the user profile directory.
Expand Down
5 changes: 5 additions & 0 deletions src/slic3r/GUI/MainFrame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <string_view>

#include "GUI_App.hpp"
#include "UnsavedChangesDialog.hpp"

#ifdef _WIN32
#include <dbt.h>
Expand Down Expand Up @@ -1190,6 +1191,10 @@ void MainFrame::init_menubar_as_editor()
windowMenu->AppendSeparator();
append_menu_item(windowMenu, wxID_ANY, _L("Open new instance") + "\tCtrl+Shift+I", _L("Open a new PrusaSlicer instance"),
[this](wxCommandEvent&) { start_new_slicer(); }, "", nullptr, [this]() {return m_plater != nullptr && wxGetApp().app_config->get("single_instance") != "1"; }, this);

windowMenu->AppendSeparator();
append_menu_item(windowMenu, wxID_ANY, _L("Compare presets")/* + "\tCtrl+F"*/, _L("Compare presets"),
[this](wxCommandEvent&) { diff_dialog.show();}, "compare", nullptr, []() {return true; }, this);
}

// View menu
Expand Down
2 changes: 2 additions & 0 deletions src/slic3r/GUI/MainFrame.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "GUI_Utils.hpp"
#include "Event.hpp"
#include "UnsavedChangesDialog.hpp"

class wxNotebook;
class wxProgressDialog;
Expand Down Expand Up @@ -190,6 +191,7 @@ class MainFrame : public DPIFrame
Plater* m_plater { nullptr };
wxNotebook* m_tabpanel { nullptr };
SettingsDialog m_settings_dialog;
DiffPresetDialog diff_dialog;
wxWindow* m_plater_page{ nullptr };
wxProgressDialog* m_progress_dialog { nullptr };
PrintHostQueueDialog* m_printhost_queue_dlg;
Expand Down
Loading

0 comments on commit 4cdcfe6

Please sign in to comment.