#ifndef slic3r_TextureLibrary_hpp_ #define slic3r_TextureLibrary_hpp_ #include #include #include #include namespace Slic3r::GUI { // One selectable height-map texture in the texture-displacement gizmo's texture picker. struct TextureLibraryEntry { std::string name; // display name (the file's stem, e.g. "Wood Grain") std::string path; // absolute path on disk bool is_user; // imported by the user, as opposed to shipped with OrcaSlicer }; // Every available height-map texture: the ones shipped in resources/textures/displacement first, sorted // by name, then the user's own from /textures/displacement - most recently used first (see // touch_user_texture()), then any never used, by name. // // The two live in separate directories deliberately: an app update replaces the resources tree // wholesale, so anything the user imported has to sit somewhere that update can never overwrite or // delete. `is_user` is what the picker uses to show them under separate headings. // // Scanned once and cached. Pass force_rescan after an import, or to pick up a file the user dropped // into either folder by hand while the app was running. const std::vector &texture_library(bool force_rescan = false); // Moves one of the user's own textures to the front of the recently-used order texture_library() lists // them in, and stores that order in the app config so it survives a restart. No-op for anything that is // not in user_texture_dir(). void touch_user_texture(const std::string &path); // Deletes one of the user's own imported textures from user_texture_dir() and forgets it. Anything outside // that folder is refused, so a shipped texture can never be removed this way. Layers already using the // texture are unaffected: they hold the image bytes themselves, and a project stores those. Returns false // with `error` set on failure. bool remove_user_texture(const std::string &path, std::string &error); // /textures/displacement, created if it does not exist yet. Empty string on failure. std::string user_texture_dir(); // Reads any image format wxWidgets can open, converts it to the 8-bit grayscale PNG that // libslic3r's decode_height_texture() understands, and saves it into user_texture_dir() (uniquified // if that name is taken). The conversion has to happen here rather than in libslic3r, which has no // image toolkit and so only ever handles the one already-normalized format. // // Returns the newly imported entry, or nullopt with `error` set. `source_path` is only read. std::optional import_texture_to_library(const std::string &source_path, std::string &error); // Encoded bytes of `path`, ready to hand to TextureDisplacementLayer::image_data. Files already in // the supported 8-bit grayscale PNG form (everything in the two library folders, by construction) // are passed through verbatim; anything else - e.g. a colour PNG the user copied into the folder // by hand - is converted on the fly, so a valid image never silently produces a blank layer. // Returns nullptr with `error` set if the file cannot be read or decoded at all. std::shared_ptr> load_texture_image_data(const std::string &path, std::string &error); } // namespace Slic3r::GUI #endif // slic3r_TextureLibrary_hpp_