mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-12-05 03:08:00 -05:00
The toolbar layout gains a list of named groups of gizmo bar icons. Loading drops members that are not gizmo bar icons or that an earlier group already holds, drops groups left with fewer than two members, and keeps each group's members together in the bar order. Entries this build does not recognise as groups are kept on save.
81 lines
3.5 KiB
C++
81 lines
3.5 KiB
C++
#pragma once
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
#include <set>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
namespace Slic3r { namespace GUI {
|
|
|
|
// The user's order and hidden set for the Prepare canvas's main toolbar and gizmo bar, saved as one JSON
|
|
// string in AppConfig ([toolbar] layout). Ids are the toolbar item names and the gizmo ids below; the
|
|
// layout is always merged with the stock order so ids from other builds are dropped and new ones appear.
|
|
|
|
inline constexpr const char* TOOLBAR_SEPARATOR_ID = "|";
|
|
|
|
struct ToolbarGroupLayout
|
|
{
|
|
std::vector<std::string> order;
|
|
std::set<std::string> hidden;
|
|
|
|
bool operator==(const ToolbarGroupLayout& rhs) const { return order == rhs.order && hidden == rhs.hidden; }
|
|
bool operator!=(const ToolbarGroupLayout& rhs) const { return !(*this == rhs); }
|
|
};
|
|
|
|
// A user-made group of gizmo bar icons that share one bar button. Members are gizmo bar ids in their bar order.
|
|
struct ToolbarGizmoGroup
|
|
{
|
|
std::string name;
|
|
std::vector<std::string> members;
|
|
|
|
bool operator==(const ToolbarGizmoGroup& rhs) const { return name == rhs.name && members == rhs.members; }
|
|
bool operator!=(const ToolbarGizmoGroup& rhs) const { return !(*this == rhs); }
|
|
};
|
|
|
|
struct ToolbarLayout
|
|
{
|
|
int version = 1;
|
|
ToolbarGroupLayout main;
|
|
ToolbarGroupLayout gizmos;
|
|
// The user's gizmo groups, in bar order.
|
|
std::vector<ToolbarGizmoGroup> groups;
|
|
// Entries of the saved "groups" array that are not user groups, kept so a save does not drop them.
|
|
nlohmann::json other_groups = nlohmann::json::array();
|
|
// Top-level fields this build does not know (written by a newer one), kept so a save does not drop them.
|
|
nlohmann::json extra = nlohmann::json::object();
|
|
|
|
bool operator==(const ToolbarLayout& rhs) const
|
|
{
|
|
return version == rhs.version && main == rhs.main && gizmos == rhs.gizmos && groups == rhs.groups &&
|
|
other_groups == rhs.other_groups && extra == rhs.extra;
|
|
}
|
|
bool operator!=(const ToolbarLayout& rhs) const { return !(*this == rhs); }
|
|
};
|
|
|
|
// Main toolbar item names in stock order, with TOOLBAR_SEPARATOR_ID where the separator goes.
|
|
const std::vector<std::string>& stock_main_toolbar_ids();
|
|
// One id per GLGizmosManager::EType value, in enum order.
|
|
const std::vector<std::string>& gizmo_ids_in_etype_order();
|
|
// The gizmos that can sit in the bar, in stock order (svg and simplify never do).
|
|
const std::vector<std::string>& stock_gizmo_bar_ids();
|
|
|
|
// Keeps the saved ids that are in stock, in saved order, and inserts missing stock ids after their nearest
|
|
// stock predecessor. Hidden ids not in stock are dropped.
|
|
ToolbarGroupLayout merge_toolbar_group(const std::vector<std::string>& stock,
|
|
const std::vector<std::string>& saved_order,
|
|
const std::vector<std::string>& saved_hidden);
|
|
|
|
ToolbarLayout stock_toolbar_layout();
|
|
// Never throws; a value that is not a JSON object gives the stock layout.
|
|
ToolbarLayout parse_toolbar_layout(const std::string& value);
|
|
// Returns "" when the layout is stock and carries no unknown fields: the caller then erases the key.
|
|
std::string serialize_toolbar_layout(const ToolbarLayout& layout);
|
|
|
|
// Drops group members that are not gizmo bar ids or that an earlier group already has, and groups left with fewer
|
|
// than two members; then moves each group's members next to its first one in gizmos.order and keeps the groups and
|
|
// their members in bar order.
|
|
void normalize_gizmo_groups(ToolbarLayout& layout);
|
|
|
|
}} // namespace Slic3r::GUI
|