Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Brush sets (#143): switch the bottom shelf and its brushes' keys in one step
islandmed106079a5ed90
diff --git a/CMakeLists.txt b/CMakeLists.txtindex a76585ab..a6e1e523 100644--- a/CMakeLists.txt+++ b/CMakeLists.txt@@ -77,6 +77,7 @@ add_library(sculptforge_core STATICsrc/core/Json.cppsrc/core/BrushRecipe.cppsrc/core/BrushPacks.cpp+ src/core/BrushSets.cppsrc/core/BrushSettings.cppsrc/core/AlphaOptions.cppsrc/core/BrushLibrary.cpp@@ -412,6 +413,7 @@ if(SCULPTFORGE_BUILD_APP)src/app/PanelBrushGallery.cppsrc/app/PanelVertexPaint.cppsrc/app/PanelPacks.cpp+ src/app/PanelBrushSets.cppsrc/app/MemoryConfirm.cppsrc/app/PanelPaintLayers.cppsrc/app/PanelTexture.cppdiff --git a/changes/feat-brush-sets.md b/changes/feat-brush-sets.mdnew file mode 100644index 00000000..14a15ce4--- /dev/null+++ b/changes/feat-brush-sets.md@@ -0,0 +1,18 @@+---+whats_new: **Brush sets**: save the bottom shelf and its brushes' keys as a named set (Wood, Metal, Stone...) and swap+ both in one step from **Brush > Brush set**, the shelf's right-click menu or <kbd>F3</kbd>. Asked for by @NicTanghe.+highlight: Brush sets: swap the whole bottom shelf and its keys in one step+added: **Brush sets** (#143, asked for by @NicTanghe): **Brush > Brush set > Save** keeps the bottom shelf's brushes, in+ order, and their keys as a named set in your brush library; picking a set (the Brush palette, the bottom shelf's+ right-click menu **Brush set**, or **Brush Set: Wood** in the command palette) swaps the shelf and the keys in one+ step, and the set you switched to comes back at the next start. Custom and pack brushes on the bottom shelf can now+ hold a key too (<kbd>Ctrl</kbd>+<kbd>Alt</kbd>+click the tile, then press the key). Commands: `brush_set`,+ `brush_set_save`, `brush_set_delete`.+testers:+ - Any OS: add a pack brush to the bottom shelf with +, Ctrl+Alt+click it and press J; Brush > Brush set > Save as+ "Wood". Remove a few brushes, give another brush J, save as "Metal". Switch between them from the Brush set menu:+ the shelf and J follow each time.+ - Any OS: switch to a set, restart SculptForge; the shelf and its keys are that set's.+ - Windows at 150 % or 200 % scaling: the Brush set row and its menu fit, nothing clipped.+---+Sets are `.sfset` JSON files in `<brush library>/sets/` (core/BrushSets.h). Tested by `ui_brush_sets` and `brush_sets_*`.diff --git a/docs/guide/interface.md b/docs/guide/interface.mdindex 63dd37c0..f6fd31d0 100644--- a/docs/guide/interface.md+++ b/docs/guide/interface.md@@ -284,6 +284,14 @@ The active brush is outlined in the accent colour.- **Bigger or smaller tiles**: right-click any brush on the shelf and choose **Tile size**: Small, Medium (thedefault) or Large. The same setting is in **Edit > Preferences > Interface > Shelf tiles**. Small leaves the mostroom for the model on a laptop screen.+- **A key for any brush on the shelf**: hold <kbd>Ctrl</kbd>+<kbd>Alt</kbd>, click its tile, then press the key.+ Custom and pack brushes show their key in the top-right corner.+- **Brush sets**: keep the shelf as it is now, with the keys of its brushes, as a named set (Wood, Metal,+ Stone...): **Brush > Brush set > Save**, or right-click the shelf and choose **Brush set > Save Shelf as Brush+ Set...**. Pick a set from either menu, or type **Brush Set** in the command palette (<kbd>F3</kbd>), to swap the+ whole shelf and its keys in one step. The set you switched to comes back the next time you start SculptForge.+ Sets are saved in your brush library (a `sets` folder next to your brushes); deleting a set leaves the brushes+ and the shelf as they are.## Pop-up pickersdiff --git a/src/app/App.cpp b/src/app/App.cppindex 6bddfecc..7f40acf3 100644--- a/src/app/App.cpp+++ b/src/app/App.cpp@@ -2998,6 +2998,7 @@ void App::drawUi() {}drawSupportUi(); // the first-run welcome, the one support reminder (PanelSupport.cpp)guide_.draw(*this); // Help > User Guide+ drawBrushSetSave(); // Save Shelf as Brush Set, Delete Brush Set (PanelBrushSets.cpp)drawPacksUi(); // pack review, New Pack, macro confirmation and editor (PanelPacks.cpp)drawMemoryConfirm(); // "Not enough free memory" before a big mesh (MemoryConfirm.cpp)drawAiLink(); // live mode: Approve / Allow dialogs, the "AI connected" badge (PanelAiLink.cpp)diff --git a/src/app/App.h b/src/app/App.hindex ce5edfe2..c64fc1e1 100644--- a/src/app/App.h+++ b/src/app/App.h@@ -21,6 +21,7 @@#include "app/UserGuide.h"#include "ai/ComfyUI.h"#include "ai/ImageTo3DService.h"+#include "core/BrushSets.h"#include "core/BrushSettings.h"#include "core/Commands.h"#include "core/Image.h"@@ -2124,6 +2125,36 @@ private:bool lastOk = false, lastOneStep = false;} macros_;// ---- end Packs and macros ----+ // ---- Brush sets (PanelBrushSets.cpp, core/BrushSets.h, #143) ----+ // Named bottom shelves with their keys: switching swaps the shelf's brushes and the keys of the brushes on it in+ // one step (the Brush palette's Brush set menu, the bottom shelf's right-click menu, the command palette, the+ // brush_set command). Save Shelf as Brush Set keeps the current shelf and keys; sets live in the user library.+public:+ void drawBrushSetRow(); // the Brush palette's row: the set menu and Save+ void drawBrushSetMenu(); // the set list, Save, Delete (in a menu)+ const std::vector<BrushSet>& brushSets() const { return brushSets_.list; }+ int matchingBrushSet() const; // the set whose shelf is the bottom shelf now, or -1++private:+ void registerBrushSets(); // commands, actions, the sets, the active set's shelf back (initActions)+ void refreshBrushSets(); // reads the sets folder; one action per set+ void restoreBrushSet(); // the set last switched to (uiPrefs_.brushSet): its shelf, at start+ void syncShelfBrushActions(); // per frame: an action for each custom brush on the bottom shelf, so it can hold a key+ bool applyBrushSet(const std::string& name, std::string& message);+ bool saveShelfAsBrushSet(const std::string& name, std::string& message);+ bool deleteBrushSet(const std::string& name, std::string& message);+ void openBrushSetSave();+ void drawBrushSetSave(); // the Save Shelf as Brush Set window+ struct BrushSetsUi {+ std::vector<BrushSet> list;+ std::vector<std::string> shelfSeen; // the bottom shelf when its brushes' actions were last made+ bool saveOpen = false, saveFocus = false, deleteOpen = false;+ char name[65] = "";+ std::string error; // why the last Save didn't work+ std::string deleting; // the set Delete asks about+ std::string pending; // a set's action ran: switched to at the start of the next frame+ } brushSets_;+ // ---- end Brush sets ----// ---- Radial menus (RadialMenu.cpp, core/RadialMenu.h, #45) ----// Up to eight pie menus of up to eight actions each. A menu's key (action radial.menuN, set in the keymap like// any other) or its mouse / pen button, held: the pie shows at the cursor, a flick toward a slot and letting godiff --git a/src/app/Config.cpp b/src/app/Config.cppindex f4631743..4b41a2c1 100644--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@ -97,6 +97,7 @@ Json toJson(const UiPrefs& p) {j.set("alphaSort", p.alphaSort);j.set("materialSort", p.materialSort);j.set("librarySort", p.librarySort);+ if (!p.brushSet.empty()) j.set("brushSet", p.brushSet);j.set("spaceCamera", p.spaceCamera);j.set("emulate3Button", p.emulate3Button);j.set("mayaZoomHorizontal", p.mayaZoomHorizontal);@@ -173,6 +174,7 @@ void fromJson(const Json& j, UiPrefs& p) {for (auto [key, v] : {std::pair{"brushSort", &p.brushSort}, std::pair{"alphaSort", &p.alphaSort},std::pair{"materialSort", &p.materialSort}, std::pair{"librarySort", &p.librarySort}})if (j[key].isString()) *v = listSortId(listSortFromId(j[key].asString()));+ if (j["brushSet"].isString() && j["brushSet"].asString().size() <= 64) p.brushSet = j["brushSet"].asString();p.spaceCamera = j["spaceCamera"].asBool(p.spaceCamera);p.emulate3Button = j["emulate3Button"].asBool(p.emulate3Button);p.mayaZoomHorizontal = j["mayaZoomHorizontal"].asBool(p.mayaZoomHorizontal);@@ -776,6 +778,7 @@ void App::initActions() {registerInputActions(); // the Classic sculpting keys: U I O, Space, L, V, Ctrl+A / I / H / W..., the input style (Input.cpp)registerTimelineUiActions(); // Sculpt Timeline, timelapse, Help > Benchmark (PanelTimeline.cpp)+ registerBrushSets(); // brush set commands and actions; the active set's shelf back (PanelBrushSets.cpp)// Every command, so the command palette finds anything scriptable.actions_.registerCommands(commands_, [this](const std::string& name) { runCommand(name); },@@ -978,6 +981,7 @@ void App::restartPrefsForTest(const std::string& uiJson) {std::string err;if (fileExists(uiConfigPath()) && !readUiConfig(uiConfigPath(), err, true)) status_ = err;applyInputStyle();+ restoreBrushSet();layoutBaseline_ = layoutKey();prefsSavedKey_ = prefsKey();prefsSaveAt_ = 0.0;@@ -1192,6 +1196,7 @@ void App::drawHintsSection() {}void App::watchLayoutChanges() {+ syncShelfBrushActions();autosavePrefs();if (layoutHintShown_ || uiConfigDeterministic_ || ++layoutCheckFrame_ % 20 != 0) return;if (layoutKey() == layoutBaseline_) return;diff --git a/src/app/Config.h b/src/app/Config.hindex 15d308f7..4cd0e273 100644--- a/src/app/Config.h+++ b/src/app/Config.h@@ -43,6 +43,7 @@ struct UiPrefs {bool emulateNumpad = false; // Blender style: the 1-9 and 0 keys above the letters act as the numpad (laptops)// The order of the asset lists (core/ListSort.h ids "az", "recent", "pack"): brushes, alphas, materials, Library.std::string brushSort = "az", alphaSort = "az", materialSort = "az", librarySort = "az";+ std::string brushSet; // the brush set last switched to (#143): its shelf comes back at the next start; "" = nonebool rightClickQuickMenu = true; // a right click on the canvas (no drag) opens the QuickMenu (#22)bool spaceCamera = false; // hold Space and drag to move the camera (#43; off: Space opens the QuickMenu)// Blender style (#77): off, as Blender 5.1+'s default keymap, Alt+left-drag on the model masks (Ctrl+Alt unmasks)diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cppindex 542a065f..d2b8f909 100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@ -331,6 +331,7 @@ void App::drawPalette_Brush() {actionRow(*this, {"brush.paste"});actionRow(*this, {"brush.save_settings"}); // this brush's own settings (#78); one per row so the labels fitactionRow(*this, {"brush.reset_settings"});+ drawBrushSetRow(); // named bottom shelves with their keys (PanelBrushSets.cpp, #143)drawCustomBrushes();drawPenPressureSwitches("brush_pen"); // this brush's own (#122)ImGui::Checkbox(tr("Front faces only"), &frontFacesOnly_);diff --git a/src/app/PanelBrushSets.cpp b/src/app/PanelBrushSets.cppnew file mode 100644index 00000000..cea7ebd9--- /dev/null+++ b/src/app/PanelBrushSets.cpp@@ -0,0 +1,405 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Brush sets (#143): named bottom shelves with their keys, switched in one step from the Brush palette, the bottom+// shelf's right-click menu, the command palette or the brush_set command. The files are core/BrushSets.cpp's.+#include "app/App.h"++#include "app/I18n.h"+#include "app/Ui.h"++#include <IconsLucide.h>++#include <algorithm>+#include <cctype>+#include <cstdio>++namespace sf {++namespace {++constexpr const char* kSavePopup = "Save Brush Set##brushset";+constexpr const char* kDeletePopup = "Delete Brush Set?##brushset";+constexpr const char* kRecipePrefix = "brush.recipe.";++std::string lowerText(std::string s) {+ for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));+ return s;+}++// "Wood Carving" -> "wood_carving": a stable piece of an action id.+std::string slug(const std::string& s) {+ std::string out;+ for (unsigned char c : s) {+ if (std::isalnum(c)) out += char(std::tolower(c));+ else if (c >= 0x80) out += char(c); // (names in other scripts stay apart)+ else if (!out.empty() && out.back() != '_') out += '_';+ }+ while (!out.empty() && out.back() == '_') out.pop_back();+ return out.empty() ? "set" : out;+}++// The shelf a set puts up: its items, with the [+] tile at the end when the file left it out.+std::vector<std::string> shelfOf(const BrushSet& set) {+ std::vector<std::string> shelf = set.shelf;+ if (std::find(shelf.begin(), shelf.end(), "widget.add_brush") == shelf.end()) shelf.push_back("widget.add_brush");+ return shelf;+}++// The action a shelf item runs when it is a brush (the one whose key a set keeps), or "".+std::string brushKeyAction(const std::string& item) {+ if (item == "brush.paint") return "draw.paint";+ if (item.rfind("brush.", 0) == 0 && item.rfind("brush.file.", 0) != 0) return item;+ return {};+}++int countBrushes(const std::vector<std::string>& shelf) {+ return int(std::count_if(shelf.begin(), shelf.end(), [](const std::string& i) { return !brushKeyAction(i).empty(); }));+}++int findSet(const std::vector<BrushSet>& list, const std::string& name) {+ for (size_t i = 0; i < list.size(); ++i)+ if (list[i].name == name) return int(i);+ for (size_t i = 0; i < list.size(); ++i) // then ignoring case ("wood" for Wood)+ if (lowerText(list[i].name) == lowerText(name)) return int(i);+ return -1;+}++std::string trimmed(const std::string& s) {+ const size_t a = s.find_first_not_of(" \t"), b = s.find_last_not_of(" \t");+ return a == std::string::npos ? std::string() : s.substr(a, b - a + 1);+}++} // namespace++void App::registerBrushSets() {+ const auto nameParam = [](const char* what) {+ return std::vector<ParamSpec>{{"name", ParamSpec::Type::String, what, true}};+ };+ commands_.add({"brush_set",+ "Switch to a brush set (Brush > Brush set): the bottom shelf's brushes and their keys, in one step.",+ nameParam("The set's name, as Save Shelf as Brush Set named it."),+ [this](Document&, const Args& a) -> CommandResult {+ std::string msg;+ const bool ok = applyBrushSet(argString(a, "name"), msg);+ return {ok, msg};+ }});+ commands_.add({"brush_set_save",+ "Save the bottom shelf and the keys of its brushes as a brush set (replaces a set of that name).",+ nameParam("A name for the set (1 to 64 characters), e.g. Wood, Metal or Stone."),+ [this](Document&, const Args& a) -> CommandResult {+ std::string msg;+ const bool ok = saveShelfAsBrushSet(argString(a, "name"), msg);+ return {ok, msg};+ }});+ commands_.add({"brush_set_delete", "Delete a brush set. The brushes and the shelf stay as they are.",+ nameParam("The set's name."), [this](Document&, const Args& a) -> CommandResult {+ std::string msg;+ const bool ok = deleteBrushSet(argString(a, "name"), msg);+ return {ok, msg};+ }});+ Action save;+ save.id = "brushset.save";+ save.label = "Save Shelf as Brush Set...";+ save.icon = ICON_LC_BOOKMARK_PLUS;+ save.palette = "Brush";+ save.description = "Keep the bottom shelf's brushes and their keys as a named set (Wood, Metal, Stone...). Switch "+ "between sets in one step from Brush > Brush set, the bottom shelf's right-click menu or here.";+ save.run = [this] { openBrushSetSave(); };+ actions_.add(std::move(save));+ refreshBrushSets();+ restoreBrushSet();+ syncShelfBrushActions();+}++void App::refreshBrushSets() {+ actions_.removePrefix("brushset.use.");+ std::vector<std::string> messages;+ brushSets_.list = loadBrushSets(brushSetsDir(), &messages);+ for (const std::string& m : messages) SDL_Log("Brush sets: %s", m.c_str());+ for (const BrushSet& set : brushSets_.list) {+ Action a;+ a.id = "brushset.use." + slug(set.name);+ a.label = "Brush Set: " + set.name;+ a.icon = ICON_LC_LIBRARY_BIG;+ a.palette = "Brush";+ a.description = "Switch the bottom shelf to the brush set " + set.name + " (" ++ std::to_string(countBrushes(set.shelf)) + " brushes) and give its brushes their keys.";+ // Next frame: running an action must not change the action list under it.+ a.run = [this, name = set.name] { brushSets_.pending = name; };+ a.checked = [this, name = set.name] {+ const int i = matchingBrushSet();+ return i >= 0 && brushSets_.list[size_t(i)].name == name;+ };+ actions_.add(std::move(a));+ }+}++int App::matchingBrushSet() const {+ // The set switched to last first: two sets may share a shelf and differ only in keys.+ const int last = findSet(brushSets_.list, uiPrefs_.brushSet);+ if (last >= 0 && shelfOf(brushSets_.list[size_t(last)]) == layout_.bottomShelf) return last;+ for (size_t i = 0; i < brushSets_.list.size(); ++i)+ if (shelfOf(brushSets_.list[i]) == layout_.bottomShelf) return int(i);+ return -1;+}++void App::restoreBrushSet() {+ if (uiPrefs_.brushSet.empty()) return;+ const int i = findSet(brushSets_.list, uiPrefs_.brushSet);+ if (i < 0) {+ uiPrefs_.brushSet.clear(); // deleted outside the app+ return;+ }+ // Its keys are in the saved shortcuts already; the shelf waits for Save Layout otherwise.+ layout_.bottomShelf = shelfOf(brushSets_.list[size_t(i)]);+}++void App::syncShelfBrushActions() {+ if (!brushSets_.pending.empty()) {+ std::string msg;+ applyBrushSet(std::exchange(brushSets_.pending, std::string()), msg);+ status_ = msg;+ }+ if (layout_.bottomShelf == brushSets_.shelfSeen) return;+ brushSets_.shelfSeen = layout_.bottomShelf;+ // A set switched to and then edited by hand is no longer the set: the next start keeps the saved layout.+ if (!uiPrefs_.brushSet.empty() && matchingBrushSet() < 0) uiPrefs_.brushSet.clear();+ // Custom brushes on the shelf get an action each, so they can hold a key like the built-in ones.+ std::vector<std::string> had;+ for (const Action& a : actions_.all())+ if (a.id.rfind(kRecipePrefix, 0) == 0) had.push_back(a.id);+ actions_.removePrefix(kRecipePrefix);+ for (const std::string& item : layout_.bottomShelf) {+ if (item.rfind(kRecipePrefix, 0) != 0 || actions_.find(item)) continue;+ const std::string name = item.substr(std::char_traits<char>::length(kRecipePrefix));+ Action a;+ a.id = item;+ a.label = name;+ a.icon = ICON_LC_BRUSH;+ a.palette = "Brush";+ a.description = "Sculpt with the " + name + " brush.";+ a.run = [this, name] {+ for (int i = 0; i < int(doc_.brushes.size()); ++i)+ if (doc_.brushes[size_t(i)].name == name) {+ doc_.activeBrush = i;+ paintMode_ = false;+ guidesMode_ = false;+ maskBrush_.on = false;+ }+ };+ a.checked = [this, name] {+ return doc_.activeBrush >= 0 && doc_.activeBrush < int(doc_.brushes.size()) && !paintMode_ &&+ doc_.brushes[size_t(doc_.activeBrush)].name == name;+ };+ actions_.add(std::move(a));+ // Back on the shelf after a while: a key it kept that another action took since goes to that action.+ if (std::find(had.begin(), had.end(), item) == had.end()) {+ std::string keep;+ for (const Chord& c : parseChords(actions_.shortcutText(item))) {+ const Action* other = actions_.actionForChord(c);+ if (!other || other->id == item) keep += (keep.empty() ? "" : " / ") + chordText(c);+ }+ if (keep != actions_.shortcutText(item)) actions_.setShortcut(item, keep);+ }+ }+}++bool App::applyBrushSet(const std::string& name, std::string& message) {+ const int i = findSet(brushSets_.list, name);+ if (i < 0) {+ message = brushSets_.list.empty() ? "No brush sets yet: Save Shelf as Brush Set makes one"+ : "No brush set called " + name;+ return false;+ }+ const BrushSet set = brushSets_.list[size_t(i)];+ layout_.bottomShelf = shelfOf(set);+ syncShelfBrushActions(); // its custom brushes' actions first, so their keys can be taken from others+ int keys = 0;+ for (const auto& [id, text] : set.keys) {+ const std::vector<Chord> chords = parseChords(text);+ if (chords.empty()) {+ actions_.setShortcut(id, "");+ continue;+ }+ for (size_t c = 0; c < chords.size(); ++c) actions_.assignShortcut(id, chordText(chords[c]), c > 0);+ ++keys;+ }+ uiPrefs_.brushSet = set.name;+ message = "Brush set: " + set.name + " (" + std::to_string(countBrushes(set.shelf)) + " brushes, " ++ std::to_string(keys) + (keys == 1 ? " key)" : " keys)");+ return true;+}++bool App::saveShelfAsBrushSet(const std::string& rawName, std::string& message) {+ const std::string name = trimmed(rawName);+ if (name.empty() || name.size() > kMaxBrushSetName) {+ message = "A brush set's name must be 1 to 64 characters";+ return false;+ }+ BrushSet set;+ set.name = name;+ set.shelf = layout_.bottomShelf;+ for (const std::string& item : set.shelf) {+ const std::string id = brushKeyAction(item);+ if (!id.empty() && actions_.find(id)) set.keys.emplace_back(id, actions_.shortcutText(id));+ }+ const bool replaced = std::any_of(brushSets_.list.begin(), brushSets_.list.end(), [&](const BrushSet& b) { return b.name == name; });+ std::string err;+ if (!saveBrushSet(brushSetsDir(), set, err)) {+ message = err;+ return false;+ }+ refreshBrushSets();+ uiPrefs_.brushSet = name;+ const int keys = int(std::count_if(set.keys.begin(), set.keys.end(), [](const auto& k) { return !k.second.empty(); }));+ message = std::string(replaced ? "Brush set updated: " : "Brush set saved: ") + name + " (" ++ std::to_string(countBrushes(set.shelf)) + " brushes, " + std::to_string(keys) + (keys == 1 ? " key)" : " keys)");+ return true;+}++bool App::deleteBrushSet(const std::string& name, std::string& message) {+ const int i = findSet(brushSets_.list, name);+ if (i < 0) {+ message = "No brush set called " + name;+ return false;+ }+ const std::string gone = brushSets_.list[size_t(i)].name;+ std::string err;+ if (!deleteBrushSetFile(brushSets_.list[size_t(i)], err)) {+ message = err;+ return false;+ }+ if (uiPrefs_.brushSet == gone) uiPrefs_.brushSet.clear();+ refreshBrushSets();+ message = "Brush set deleted: " + gone + " (the shelf stays as it is)";+ return true;+}++void App::openBrushSetSave() {+ const int i = matchingBrushSet();+ std::snprintf(brushSets_.name, sizeof brushSets_.name, "%s", i >= 0 ? brushSets_.list[size_t(i)].name.c_str() : "");+ brushSets_.saveOpen = true;+}++void App::drawBrushSetMenu() {+ const int current = matchingBrushSet();+ if (brushSets_.list.empty()) ImGui::TextDisabled("%s", tr("No brush sets yet"));+ for (size_t i = 0; i < brushSets_.list.size(); ++i) {+ const BrushSet& set = brushSets_.list[i];+ const int n = countBrushes(set.shelf);+ const std::string count = std::to_string(n) + (n == 1 ? " brush" : " brushes");+ const std::string label = set.name + "##brushset" + std::to_string(i);+ if (ImGui::MenuItem(label.c_str(), count.c_str(), int(i) == current)) runCommand("brush_set", {{"name", set.name}});+ ui::HelpText(set.name.c_str(), actions_.shortcutText("brushset.use." + slug(set.name)).c_str(),+ ("Switch the bottom shelf to this set's " + count + " and give them the set's keys.").c_str(),+ "Brush > Brush set");+ }+ ImGui::Separator();+ if (ImGui::MenuItem(tr("Save Shelf as Brush Set...##brushsetmenu"))) openBrushSetSave();+ ui::HelpAction(*this, "brushset.save");+ if (current >= 0) {+ const std::string label = std::string(tr("Delete")) + " " + brushSets_.list[size_t(current)].name + "...##brushsetmenu";+ if (ImGui::MenuItem(label.c_str())) {+ brushSets_.deleting = brushSets_.list[size_t(current)].name;+ brushSets_.deleteOpen = true;+ }+ ui::HelpText("Delete brush set", nullptr, "Delete this brush set. The brushes and the shelf stay as they are.",+ "Brush > Brush set");+ }+}++void App::drawBrushSetRow() {+ const float s = uiScale_;+ const int current = matchingBrushSet();+ const std::string preview = std::string(tr("Brush set:")) + " " ++ (current >= 0 ? brushSets_.list[size_t(current)].name+ : brushSets_.list.empty() ? std::string(tr("none yet"))+ : std::string(tr("this shelf (not saved)")));+ const float saveW = ImGui::CalcTextSize(tr("Save")).x + ImGui::GetStyle().FramePadding.x * 2.0f + 12.0f * s;+ ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - saveW - ImGui::GetStyle().ItemSpacing.x);+ if (ImGui::BeginCombo("##brushset", preview.c_str(), ImGuiComboFlags_HeightLarge)) {+ drawBrushSetMenu();+ ImGui::EndCombo();+ }+ ui::HelpText("Brush set", nullptr,+ "Named bottom shelves with their keys (Wood, Metal, Stone...): pick one to swap the shelf's brushes and "+ "their keys in one step. Save keeps the shelf as it is now, with its keys, as a set. Sets live in your "+ "brush library; F3 finds them too.",+ "Brush");+ ImGui::SameLine();+ if (ImGui::Button(tr("Save##brushsetsave"), ImVec2(saveW, 0)))+ openBrushSetSave();+ ui::HelpAction(*this, "brushset.save");+}++void App::drawBrushSetSave() {+ if (brushSets_.saveOpen) {+ ImGui::OpenPopup(kSavePopup);+ brushSets_.saveOpen = false;+ brushSets_.saveFocus = true;+ }+ if (brushSets_.deleteOpen) {+ ImGui::OpenPopup(kDeletePopup);+ brushSets_.deleteOpen = false;+ }+ const float s = uiScale_;+ const ImVec2 center = ImGui::GetMainViewport()->GetCenter();+ const ImVec2 button(110 * s, 0);++ ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));+ if (ImGui::BeginPopupModal(kSavePopup, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings)) {+ std::string& error = brushSets_.error;+ if (brushSets_.saveFocus) {+ error.clear();+ ImGui::SetKeyboardFocusHere();+ brushSets_.saveFocus = false;+ }+ ImGui::SetNextItemWidth(320 * s);+ bool ok = ImGui::InputTextWithHint("##brushsetname", tr("Name, e.g. Wood, Metal or Stone"), brushSets_.name,+ sizeof brushSets_.name, ImGuiInputTextFlags_EnterReturnsTrue);+ const int brushes = countBrushes(layout_.bottomShelf);+ ImGui::PushTextWrapPos(320 * s);+ ImGui::TextDisabled("%s", ("The bottom shelf's " + std::to_string(brushes) ++ " brushes, in order, and their keys. Switching to the set later puts both back.")+ .c_str());+ const std::string name = trimmed(brushSets_.name);+ const int existing = name.empty() ? -1 : findSet(brushSets_.list, name);+ if (existing >= 0 && brushSets_.list[size_t(existing)].name == name)+ ImGui::TextColored(ImVec4(0.94f, 0.53f, 0.18f, 1.0f), "%s", ("Replaces the set " + name + ".").c_str());+ ImGui::PopTextWrapPos();+ if (!error.empty()) ImGui::TextColored(ImVec4(1.0f, 0.45f, 0.45f, 1.0f), "%s", error.c_str());+ ImGui::BeginDisabled(name.empty());+ ok |= ImGui::Button(tr("Save##brushsetsave_ok"), button);+ ImGui::EndDisabled();+ ImGui::SameLine();+ if (ImGui::Button(tr("Cancel##brushsetsave_cancel"), button) || ImGui::IsKeyPressed(ImGuiKey_Escape)) {+ ImGui::CloseCurrentPopup();+ } else if (ok && !name.empty()) {+ runCommand("brush_set_save", {{"name", name}});+ if (lastCommandOk_) ImGui::CloseCurrentPopup();+ else error = status_;+ }+ ImGui::EndPopup();+ }++ ImGui::SetNextWindowPos(center, ImGuiCond_Appearing, ImVec2(0.5f, 0.5f));+ if (ImGui::BeginPopupModal(kDeletePopup, nullptr, ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings)) {+ ImGui::Text("%s", ("Delete the brush set " + brushSets_.deleting + "?").c_str());+ ImGui::TextDisabled("%s", tr("Only the set goes: the brushes and the shelf stay as they are."));+ bool close = false;+ if (ImGui::Button(tr("Delete##brushsetdelete_ok"), button)) {+ runCommand("brush_set_delete", {{"name", brushSets_.deleting}});+ close = true;+ }+ ImGui::SameLine();+ if (ImGui::Button(tr("Cancel##brushsetdelete_cancel"), button) || ImGui::IsKeyPressed(ImGuiKey_Escape)) close = true;+ if (close) {+ brushSets_.deleting.clear();+ ImGui::CloseCurrentPopup();+ }+ ImGui::EndPopup();+ }+}++} // namespace sfdiff --git a/src/app/Shell.cpp b/src/app/Shell.cppindex 17fc28b7..11fa73cb 100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@ -2308,14 +2308,22 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertelse drawBrushIcon(dl, c, pic * 0.36f, int(BrushType::Standard));dl->AddText(fontSmall_, fontSmall_ ? fontSmall_->FontSize : 12.0f, ImVec2(a.x + 2.0f * s, a.y), theme::u32(theme::accent),ICON_LC_SPARKLE);+ // Its key (a brush set gives it one, #143) in the other corner, as the built-in tiles show theirs.+ const std::string chord = actions_.shortcutText(item);+ if (chord.size() == 1 && fontSmall_) {+ const float kw = fontSmall_->CalcTextSizeA(fontSmall_->FontSize, FLT_MAX, 0.0f, chord.c_str()).x;+ dl->AddText(fontSmall_, fontSmall_->FontSize, ImVec2(b.x - kw - 3.0f * s, a.y + 1.0f * s), theme::u32(theme::textDim), chord.c_str());+ }if (on) dl->AddRect(a, b, theme::u32(theme::accent), theme::rounding(4.0f * s), 0, 2.0f * s);centredText(dl, fontSmall_, ImVec2(a.x, b.y - capH), b, theme::u32(found < 0 ? theme::textDim : on ? theme::accent : theme::text),elide(fontSmall_ ? fontSmall_ : ImGui::GetFont(), name, size.x).c_str());- if (clicked && found >= 0) {+ if (clicked && ui::CtrlHeld() && ui::AltHeld()) {+ if (!layout_.customize) beginShortcutCapture(item); // Ctrl+Alt+click: a key for it, as the other tiles+ } else if (clicked && found >= 0) {doc_.activeBrush = found;paintMode_ = false;}- ui::HelpText(name.c_str(), nullptr,+ ui::HelpText(name.c_str(), chord.empty() ? nullptr : chord.c_str(),found >= 0 && !doc_.brushes[size_t(found)].description.empty() ? doc_.brushes[size_t(found)].description.c_str(): "One of your custom brushes.","Bottom shelf");@@ -2366,6 +2374,10 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertif (index < int(list.size()) && list[size_t(index)] == item) list.erase(list.begin() + index);noteLayoutChanged();}+ if (shelf == kShelfBottom && ImGui::BeginMenu(tr("Brush set"))) { // also the Brush palette's (#143)+ drawBrushSetMenu();+ ImGui::EndMenu();+ }if (shelf == kShelfBottom && ImGui::BeginMenu(tr("Tile size"))) { // also in Preferences > Interfacestatic const char* kTiles[] = {"Small", "Medium", "Large"};for (int i = 0; i < 3; ++i)@@ -2375,7 +2387,7 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertImGui::EndPopup();}// Customize mode: widgets (sliders, tiles, readouts) are Ctrl+Alt drag sources too.- if (item != "sep" && !actions_.find(item)) {+ if (item != "sep" && (!actions_.find(item) || item.rfind("brush.recipe.", 0) == 0)) { // (custom brushes have actions, #143)ui::SetNextItemOrigin(shelf, index);ui::UiItemDragSource(*this, item.c_str(), item.c_str());}diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cppindex 80a269f7..f86c32af 100644--- a/src/app/UiTest.cpp+++ b/src/app/UiTest.cpp@@ -757,6 +757,9 @@ double Demo::query(const std::string& name, bool& known) const {if (name == "turntable") return app_.uiPrefs_.turntable ? 1.0 : 0.0;if (name == "camera_ortho") return app_.camera_.ortho ? 1.0 : 0.0;if (name == "mask_brush") return app_.maskBrushActive() ? 1.0 : 0.0;+ if (name == "brush_sets") return double(app_.brushSets().size()); // brush sets in the library (#143)+ if (name == "brush_set_active") return double(app_.matchingBrushSet()); // the set the bottom shelf is, -1 none+ if (name == "bottom_shelf_items") return double(app_.layout_.bottomShelf.size());if (name == "shortcut_conflicts") { // keys that two actions claim (only the first would ever run)int conflicts = 0;std::vector<Chord> seen;diff --git a/src/core/BrushSets.cpp b/src/core/BrushSets.cppnew file mode 100644index 00000000..daf76dfb--- /dev/null+++ b/src/core/BrushSets.cpp@@ -0,0 +1,186 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+#include "core/BrushSets.h"++#include <algorithm>+#include <cctype>+#include <filesystem>+#include <fstream>+#include <iterator>++namespace sf {++namespace fs = std::filesystem;++namespace {++fs::path u8path(const std::string& p) { return fs::path(std::u8string(p.begin(), p.end())); }+std::string u8str(const fs::path& p) {+ const std::u8string s = p.u8string();+ return std::string(s.begin(), s.end());+}+std::string lowerAscii(std::string s) {+ for (char& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));+ return s;+}++constexpr size_t kMaxItemId = 512;++bool readBrushSetFile(const fs::path& p, BrushSet& out, std::string& error) {+ std::error_code ec;+ const auto size = fs::file_size(p, ec);+ if (ec || size > kMaxBrushSetFileSize) {+ error = ec ? "can't read it" : "larger than 64 KB";+ return false;+ }+ std::ifstream f(p, std::ios::binary);+ if (!f) {+ error = "can't read it";+ return false;+ }+ const std::string text((std::istreambuf_iterator<char>(f)), std::istreambuf_iterator<char>());+ Json j;+ if (!Json::parseStrict(text, j, error) || !brushSetFromJson(j, out, error)) return false;+ out.path = u8str(p);+ return true;+}++} // namespace++std::string brushSetsDir(const BrushLibraryPaths& paths) {+ return paths.userDir.empty() ? std::string() : u8str(u8path(paths.userDir) / "sets");+}++Json toJson(const BrushSet& set) {+ Json j = Json::object();+ j.set("format", "sculptforge.brushset");+ j.set("version", 1);+ j.set("name", set.name);+ Json shelf = Json::array();+ for (const std::string& id : set.shelf) shelf.push(id);+ j.set("shelf", std::move(shelf));+ Json keys = Json::object();+ for (const auto& [id, chord] : set.keys) keys.set(id, chord);+ j.set("keys", std::move(keys));+ return j;+}++bool brushSetFromJson(const Json& j, BrushSet& out, std::string& error) {+ if (!j.isObject() || j["format"].asString() != "sculptforge.brushset") {+ error = "not a SculptForge brush set";+ return false;+ }+ if (j["version"].asNumber(0) > 1) {+ error = "made by a newer SculptForge";+ return false;+ }+ BrushSet s;+ s.name = j["name"].asString();+ if (s.name.empty() || s.name.size() > kMaxBrushSetName) {+ error = "the name must be 1 to 64 characters";+ return false;+ }+ if (!j["shelf"].isArray() || j["shelf"].size() > kMaxBrushSetItems) {+ error = "the shelf must be a list of up to 256 items";+ return false;+ }+ for (const Json& id : j["shelf"].items()) {+ if (!id.isString() || id.asString().empty() || id.asString().size() > kMaxItemId) {+ error = "a shelf item isn't a valid id";+ return false;+ }+ s.shelf.push_back(id.asString());+ }+ if (j.has("keys") && (!j["keys"].isObject() || j["keys"].members().size() > kMaxBrushSetItems)) {+ error = "the keys must be an object of up to 256 entries";+ return false;+ }+ for (const auto& [id, chord] : j["keys"].members()) {+ if (id.empty() || id.size() > kMaxItemId || !chord.isString() || chord.asString().size() > 64) {+ error = "a key entry isn't valid";+ return false;+ }+ s.keys.emplace_back(id, chord.asString());+ }+ out = std::move(s);+ return true;+}++std::vector<BrushSet> loadBrushSets(const std::string& dir, std::vector<std::string>* messages) {+ std::vector<BrushSet> out;+ if (dir.empty()) return out;+ std::error_code ec;+ for (fs::directory_iterator it(u8path(dir), ec), end; !ec && it != end; it.increment(ec)) {+ std::error_code e2;+ if (!it->is_regular_file(e2) || lowerAscii(u8str(it->path().extension())) != kBrushSetExtension) continue;+ BrushSet s;+ std::string err;+ if (!readBrushSetFile(it->path(), s, err)) {+ if (messages) messages->push_back(u8str(it->path().filename()) + ": " + err);+ continue;+ }+ // Two files with one name (copied in by hand): the first A-Z file wins.+ auto same = std::find_if(out.begin(), out.end(), [&](const BrushSet& o) { return o.name == s.name; });+ if (same == out.end()) out.push_back(std::move(s));+ else if (s.path < same->path) *same = std::move(s);+ }+ std::sort(out.begin(), out.end(), [](const BrushSet& a, const BrushSet& b) {+ const std::string x = lowerAscii(a.name), y = lowerAscii(b.name);+ return x != y ? x < y : a.name < b.name;+ });+ return out;+}++bool saveBrushSet(const std::string& dir, BrushSet& set, std::string& error) {+ if (dir.empty()) {+ error = "No brush library folder to save brush sets in";+ return false;+ }+ if (set.name.empty() || set.name.size() > kMaxBrushSetName) {+ error = "A brush set's name must be 1 to 64 characters";+ return false;+ }+ std::error_code ec;+ fs::create_directories(u8path(dir), ec);+ // The set's own file when one of that name exists; otherwise a free file name from the set's name.+ fs::path target;+ for (const BrushSet& s : loadBrushSets(dir))+ if (s.name == set.name) target = u8path(s.path);+ if (target.empty()) {+ std::string stem = brushFileName(set.name);+ stem.resize(stem.size() - std::char_traits<char>::length(".sfbrush"));+ for (int n = 1; n <= 1000; ++n) {+ target = u8path(dir) / u8path(n == 1 ? stem + kBrushSetExtension : stem + " " + std::to_string(n) + kBrushSetExtension);+ if (!fs::exists(target, ec)) break;+ }+ }+ // Next to it, then renamed over it: a crash never leaves half a set behind.+ const fs::path tmp = u8path(u8str(target) + ".tmp");+ {+ std::ofstream f(tmp, std::ios::binary | std::ios::trunc);+ f << toJson(set).dump(true) << '\n';+ if (!f) {+ error = "Can't write " + u8str(tmp);+ return false;+ }+ }+ fs::rename(tmp, target, ec);+ if (ec) {+ fs::remove(tmp, ec);+ error = "Can't write " + u8str(target);+ return false;+ }+ set.path = u8str(target);+ return true;+}++bool deleteBrushSetFile(const BrushSet& set, std::string& error) {+ std::error_code ec;+ if (set.path.empty() || !fs::remove(u8path(set.path), ec) || ec) {+ error = "Can't delete " + (set.path.empty() ? set.name : set.path);+ return false;+ }+ return true;+}++} // namespace sfdiff --git a/src/core/BrushSets.h b/src/core/BrushSets.hnew file mode 100644index 00000000..47b6c107--- /dev/null+++ b/src/core/BrushSets.h@@ -0,0 +1,43 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Brush sets (#143): named bottom shelves with their keys ("Wood", "Metal", "Stone"). A set is the bottom shelf's+// items in order plus the key of every brush on it; switching to a set swaps both in one step. Each set is one+// .sfset file (JSON) in the user library's sets/ folder, next to the user's brushes.+#pragma once++#include "core/BrushLibrary.h"+#include "core/Json.h"++#include <string>+#include <utility>+#include <vector>++namespace sf {++struct BrushSet {+ std::string name;+ std::vector<std::string> shelf; // the bottom shelf's item ids ("brush.clay", "brush.recipe.Rivet Row", ...)+ // The key of each brush on the shelf when it was saved, as the shortcut text ("1", "Shift+W / W"); "" = no key.+ std::vector<std::pair<std::string, std::string>> keys;+ std::string path; // the file it was read from or saved to+};++constexpr size_t kMaxBrushSetFileSize = 64 * 1024;+constexpr size_t kMaxBrushSetItems = 256;+constexpr size_t kMaxBrushSetName = 64;+constexpr const char* kBrushSetExtension = ".sfset";++// <user library>/sets ("" when there is no user library: renders and demo recordings save nothing).+std::string brushSetsDir(const BrushLibraryPaths& paths = brushLibraryPaths());++Json toJson(const BrushSet& set);+// Checks the name, the item count and lengths; false with `error` for anything else than a brush set.+bool brushSetFromJson(const Json& j, BrushSet& out, std::string& error);+// Every readable set in `dir`, A-Z by name (case-insensitive); unreadable files are skipped with a message.+std::vector<BrushSet> loadBrushSets(const std::string& dir, std::vector<std::string>* messages = nullptr);+// Writes `set` into `dir`, replacing the set of the same name (its file); sets `set.path`.+bool saveBrushSet(const std::string& dir, BrushSet& set, std::string& error);+bool deleteBrushSetFile(const BrushSet& set, std::string& error);++} // namespace sfdiff --git a/src/link/AiLinkSession.cpp b/src/link/AiLinkSession.cppindex 1ca6b6c0..28d513b0 100644--- a/src/link/AiLinkSession.cpp+++ b/src/link/AiLinkSession.cpp@@ -114,7 +114,8 @@ AiDecision AiLinkPolicy::classify(const Command* cmd, const std::string& name, cif (name == "macro_run" || name.rfind("script", 0) == 0 || name.rfind("python", 0) == 0)return confirmBecause("Runs a macro or script");if (name == "splat_train") return confirmBecause("Runs outside programs (splat training)");- if (name == "brush_delete" || name == "vdm_delete") return confirmBecause("Deletes a file from your library");+ if (name == "brush_delete" || name == "vdm_delete" || name == "brush_set_delete")+ return confirmBecause("Deletes a file from your library");const bool writer = writes(name);for (const auto& [key, value] : args) {diff --git a/tests/test_ai_link.cpp b/tests/test_ai_link.cppindex a518f72c..8fcef11e 100644--- a/tests/test_ai_link.cpp+++ b/tests/test_ai_link.cpp@@ -153,6 +153,7 @@ TEST(ai_link_policy) {CHECK(verdict("macro_run", {{"name", std::string("x")}}) == AiVerdict::Confirm);CHECK(AiLinkPolicy{}.classify(reg.find("mesh_info"), "image_to_3d", {}).verdict == AiVerdict::Confirm);CHECK(verdict("brush_delete", {{"name", std::string("x")}}) == AiVerdict::Confirm);+ CHECK(AiLinkPolicy{}.classify(reg.find("mesh_info"), "brush_set_delete", {}).verdict == AiVerdict::Confirm); // (an app command)CHECK(AiLinkPolicy{}.classify(reg.find("mesh_info"), "anything", {{"url", std::string("http://x")}}).verdict == AiVerdict::Confirm);// No project: a relative path can't be placed, so it asks.AiLinkPolicy none;diff --git a/tests/test_brush_sets.cpp b/tests/test_brush_sets.cppnew file mode 100644index 00000000..9837968b--- /dev/null+++ b/tests/test_brush_sets.cpp@@ -0,0 +1,109 @@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// Brush sets (core/BrushSets.h, #143): the .sfset files in the user library's sets/ folder.+#include "TestHarness.h"++#include "core/BrushSets.h"++#include <filesystem>+#include <fstream>++using namespace sf;+namespace fs = std::filesystem;++namespace {++struct SetsDir {+ fs::path root;+ explicit SetsDir(const char* name) : root(fs::temp_directory_path() / (std::string("sculptforge_brushsets_") + name)) {+ fs::remove_all(root);+ }+ ~SetsDir() {+ std::error_code ec;+ fs::remove_all(root, ec);+ }+ std::string dir() const { return (root / "sets").string(); }+};++BrushSet woodSet() {+ BrushSet s;+ s.name = "Wood";+ s.shelf = {"brush.clay", "brush.recipe.Rivet Row", "brush.paint", "widget.add_brush"};+ s.keys = {{"brush.clay", "1"}, {"brush.recipe.Rivet Row", "Shift+W / W"}, {"draw.paint", ""}};+ return s;+}++} // namespace++TEST(brush_sets_round_trip) {+ SetsDir d("round_trip");+ CHECK(brushSetsDir({}).empty()); // no user library: nothing is saved+ CHECK(brushSetsDir({(d.root / "lib").string(), {}, {}}) == (d.root / "lib" / "sets").string());+ BrushSet wood = woodSet();+ std::string err;+ CHECK(saveBrushSet(d.dir(), wood, err));+ CHECK(fs::path(wood.path).filename() == "Wood.sfset");+ BrushSet metal = woodSet();+ metal.name = "metal";+ metal.shelf = {"brush.flatten"};+ metal.keys.clear();+ CHECK(saveBrushSet(d.dir(), metal, err));+ const std::vector<BrushSet> sets = loadBrushSets(d.dir());+ CHECK(sets.size() == 2);+ CHECK(sets[0].name == "metal"); // A-Z, ignoring case+ CHECK(sets[1].name == "Wood");+ CHECK(sets[1].shelf == woodSet().shelf);+ CHECK(sets[1].keys == woodSet().keys);++ // Saving under the same name replaces the set (its file), never adds a second one.+ wood.shelf = {"brush.move"};+ CHECK(saveBrushSet(d.dir(), wood, err));+ CHECK(loadBrushSets(d.dir()).size() == 2);+ CHECK(loadBrushSets(d.dir())[1].shelf == std::vector<std::string>{"brush.move"});++ // Names that make the same file name ("A/B" and "A_B") get files of their own.+ BrushSet slash = metal, underscore = metal;+ slash.name = "A/B";+ underscore.name = "A_B";+ CHECK(saveBrushSet(d.dir(), slash, err));+ CHECK(saveBrushSet(d.dir(), underscore, err));+ CHECK(slash.path != underscore.path);+ CHECK(loadBrushSets(d.dir()).size() == 4);++ CHECK(deleteBrushSetFile(slash, err));+ CHECK(loadBrushSets(d.dir()).size() == 3);+ CHECK(!deleteBrushSetFile(slash, err));+}++TEST(brush_sets_reject_bad_files) {+ SetsDir d("bad_files");+ BrushSet s = woodSet();+ std::string err;+ s.name = "";+ CHECK(!saveBrushSet(d.dir(), s, err));+ s.name = std::string(65, 'x');+ CHECK(!saveBrushSet(d.dir(), s, err));+ BrushSet fine = woodSet();+ CHECK(!saveBrushSet("", fine, err)); // no library folder++ fs::create_directories(d.dir());+ const auto write = [&](const char* file, const std::string& text) { std::ofstream(fs::path(d.dir()) / file, std::ios::binary) << text; };+ write("a.sfset", "not json");+ write("b.sfset", R"({"format":"sculptforge.brush","name":"X","shelf":[]})");+ write("c.sfset", R"({"format":"sculptforge.brushset","version":1,"name":"X","shelf":[1]})");+ write("d.sfset", R"({"format":"sculptforge.brushset","version":1,"name":"X","shelf":[],"keys":{"brush.clay":3}})");+ write("e.sfset", R"({"format":"sculptforge.brushset","version":2,"name":"X","shelf":[]})");+ write("f.sfset", R"({"format":"sculptforge.brushset","version":1,"name":"X","name":"Y","shelf":[]})"); // strict JSON+ write("g.sfset", std::string(kMaxBrushSetFileSize + 1, ' '));+ write("ok.sfset", R"({"format":"sculptforge.brushset","version":1,"name":"Stone","shelf":["brush.trim"]})");+ write("notes.txt", "ignored");+ std::vector<std::string> messages;+ const std::vector<BrushSet> sets = loadBrushSets(d.dir(), &messages);+ CHECK(sets.size() == 1);+ CHECK(sets[0].name == "Stone");+ CHECK(sets[0].keys.empty());+ CHECK(messages.size() == 7);+ CHECK(loadBrushSets("").empty());+ CHECK(loadBrushSets((d.root / "missing").string()).empty());+}diff --git a/tests/ui/brush_sets.sfui b/tests/ui/brush_sets.sfuinew file mode 100644index 00000000..d364d5eb--- /dev/null+++ b/tests/ui/brush_sets.sfui@@ -0,0 +1,127 @@+# Brush sets (#143): the bottom shelf and its brushes' keys saved as a named set (Wood, Metal...), switched in one+# step from the Brush palette, the shelf's right-click menu or F3; a pack brush on the shelf holds a key like the+# built-in ones; the set switched to comes back after a restart; Delete removes only the set.+run ui_look look=classic layout=classic+run new_sphere subdivisions=5+expect_value brush_sets == 0++# Wood: Rivet Row on the shelf, with J (Ctrl+Alt+click its tile, then the key), and K on Clay.+click "##addbrush"+click "Rivet Row"+expect "Rivet Row##brush.recipe.Rivet Row"+hold ctrl+alt+click "Rivet Row##brush.recipe.Rivet Row"+hold none+key j+expect_shortcut "brush.recipe.Rivet Row" J+hold ctrl+alt+click "Clay##brush.clay"+hold none+key k+expect_shortcut brush.clay K+key j+expect_value brush_type == -1+key k+expect_value brush_type == 1+click "Brush##palette.brush"+expect_text Brush set: none yet+hold ctrl+hover "##brushset"+expect_help swap the shelf's brushes+hold none+click "Save##brushsetsave"+type "##brushsetname" Wood+wait_idle 30+shot save_dialog+click "Save##brushsetsave_ok"+expect_status Brush set saved: Wood+expect_value brush_sets == 1+expect_value brush_set_active == 0++# Metal: no Rivet Row, no Clay on the shelf, and J on Flatten (taken from Rivet Row).+right_click "Rivet Row##brush.recipe.Rivet Row"+click "Remove from shelf"+right_click "Clay##brush.clay"+click "Remove from shelf"+expect_value brush_set_active == -1+hold ctrl+alt+click "Flatten##brush.flatten"+hold none+key j+expect_shortcut brush.flatten J+run brush_set_save name=Metal+expect_value brush_sets == 2+click "Brush##palette.brush"+expect_text Brush set: Metal++# One step back to Wood (the Brush palette's menu): its shelf and its keys.+click "##brushset"+expect "Metal##brushset0"+wait_idle 30+shot set_menu+click "Wood##brushset1"+expect_status Brush set: Wood+expect "Rivet Row##brush.recipe.Rivet Row"+expect "Clay##brush.clay"+expect_shortcut "brush.recipe.Rivet Row" J+expect_shortcut brush.clay K+expect_value shortcut_conflicts == 0+key j+expect_value brush_type == -1++# Metal again from the bottom shelf's right-click menu.+right_click "Flatten##brush.flatten"+hover "Brush set"+wait 0.2+expect "Metal##brushset0"+wait_idle 30+shot shelf_menu+click "Metal##brushset0"+expect_not "Rivet Row##brush.recipe.Rivet Row"+expect_not "Clay##brush.clay"+expect_shortcut brush.flatten J+expect_value shortcut_conflicts == 0+key j+expect_value brush_type == 6++# F3 finds every set.+key f3+type "##Command palette" "brush set: wood"+expect_text "Brush Set: Wood"+key enter+wait 0.2+expect_value brush_set_active == 1+expect "Rivet Row##brush.recipe.Rivet Row"++# The set switched to comes back at the next start (shelf and keys).+restart+expect_value brush_sets == 2+expect_value brush_set_active == 1+expect "Rivet Row##brush.recipe.Rivet Row"+expect_shortcut "brush.recipe.Rivet Row" J+click "Brush##palette.brush"+expect_text Brush set: Wood+wait_idle 60+shot palette++# Delete asks first and leaves the shelf as it is.+click "##brushset"+click "Delete Wood...##brushsetmenu"+expect_text Delete the brush set Wood?+click "Delete##brushsetdelete_ok"+expect_value brush_sets == 1+expect "Rivet Row##brush.recipe.Rivet Row"+expect_value brush_set_active == -1+click "Brush##palette.brush"+expect_text this shelf (not saved)+run_fails brush_set name=Wood+run_fails brush_set_save name=""++# HiDPI: the row and the menu at 200 %.+ui_scale 200+wait_idle 60+click "##brushset"+expect "Metal##brushset0"+wait_idle 30+shot set_menu_hidpi+key escape