Blender V5.3
BKE_blender_project.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#pragma once
10
12
13#include <concepts>
14#include <cstdint>
15#include <memory>
16#include <optional>
17
18#include "BLI_function_ref.hh"
19#include "BLI_string_ref.hh"
20#include "BLI_vector.hh"
21
22#include "DNA_ID.h"
23
24#include "BKE_idprop.hh"
25
26#define BLENDER_PROJECT_CONFIG_DIR ".blender_project"
27#define BLENDER_PROJECT_CONFIG_FILE "project.toml"
28
29namespace blender {
30
31struct Main;
32
33namespace bke {
34
46
55 /* These should be kept in sync with their counterparts in PropertySubType
56 * from RNA_types.hh. We don't include that header here because some places
57 * that include *this* header don't have access to it. */
58 NONE = 0, /* PropertySubType::PROP_NONE */
59 FILEPATH = 1, /* PropertySubType::PROP_FILEPATH */
60};
61
69 public:
71
73 ProjectVariable(const ProjectVariable &other) = delete;
74 ProjectVariable &operator=(const ProjectVariable &other) = delete;
75 ProjectVariable(ProjectVariable &&other) noexcept;
76 ProjectVariable &operator=(ProjectVariable &&other) noexcept;
77
90 {
91 return *this;
92 }
93 const IDProperty &prop() const
94 {
95 return *this;
96 }
97
108 StringRefNull name_get() const;
109
119
122
124 int value_int_get() const;
125 float value_float_get() const;
126
127 void value_set(StringRefNull value);
128 void value_set(int value);
129 void value_set(float value);
130
132 void description_set(StringRef description);
133};
134
142 std::string name_;
143
153 std::string root_path_;
154
158 std::string ocio_config_path_;
159
163 std::string splash_image_path_;
164
165 public:
168 /* The index of the selected project asset library in the UI. */
170
177 bool is_dirty = true;
178
183
191 void set_name(StringRef name);
192
200 void set_root_path(StringRef root_path);
201
205 void set_ocio_config_path(StringRef ocio_config_path);
206
210 void set_splash_image_path(StringRef splash_image_path);
211
212 StringRefNull get_name() const;
216
223
232
240
248 void move_variable(int from_index, int to_index);
249
257 void rename_variable(int variable_index, StringRef name);
258};
259
271
283
296
309
310} // namespace bke
311
322std::string BKE_is_path_inside_blender_project(const char *path);
323
345
365template<std::invocable<const bke::BlenderProject *> Fn>
366inline auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
367{
368 using T = std::invoke_result_t<Fn, const bke::BlenderProject *>;
369 if constexpr (std::is_void_v<T>) {
372 lambda(project);
373 });
374 }
375 else {
376 std::optional<T> result;
379 result = lambda(project);
380 });
381 BLI_assert(result.has_value());
382 return std::move(*result);
383 }
384}
385
400template<std::invocable<bke::BlenderProject *> Fn>
401inline auto BKE_blender_project_write_callback(const Main *bmain, Fn lambda)
402{
403 using T = std::invoke_result_t<Fn, bke::BlenderProject *>;
404 if constexpr (std::is_void_v<T>) {
407 lambda(project);
408 });
409 }
410 else {
411 std::optional<T> result;
414 result = lambda(project);
415 });
416 BLI_assert(result.has_value());
417 return std::move(*result);
418 }
419}
420
432
438void BKE_blender_project_refresh(Main *bmain, const char *filepath);
439
446
454 bool path_is_template,
456
463
469bool BKE_blender_project_init_from_root_path(Main *bmain, std::string project_root_path);
470
471/* Return whether the given path is a Blender Project or not. */
473
476 std::string path;
477 std::string name;
478};
479
483void BKE_blender_project_recent_update(const Main *bmain);
485void BKE_blender_project_recent_clear(bool only_missing);
486
487} // namespace blender
ID and Library types, which are fundamental for SDNA.
void set_root_path(StringRef root_path)
void rename_variable(int variable_index, StringRef name)
StringRefNull get_splash_image_path() const
void set_splash_image_path(StringRef splash_image_path)
Vector< std::unique_ptr< ProjectVariable > > variables
StringRefNull get_root_path() const
int find_variable_index(ProjectVariable *var)
StringRefNull get_ocio_config_path() const
void move_variable(int from_index, int to_index)
void set_ocio_config_path(StringRef ocio_config_path)
StringRefNull get_name() const
ProjectVariable * new_variable(StringRef name, ProjectVariableType type)
void set_name(StringRef name)
int remove_variable(ProjectVariable *var)
void string_subtype_set(ProjectVariableStringSubtype type)
ProjectVariable & operator=(const ProjectVariable &other)=delete
void description_set(StringRef description)
ProjectVariable(StringRef name, ProjectVariableType type)
StringRefNull description_get() const
ProjectVariable(const ProjectVariable &other)=delete
void value_set(StringRefNull value)
StringRefNull value_string_get() const
ProjectVariableStringSubtype string_subtype_get() const
ProjectVariableType type_get() const
const IDProperty & prop() const
StringRefNull name_get() const
#define T
void with_blender_project_write_lock(FunctionRef< void()> lambda)
std::string ensure_is_valid_project_variable_name(StringRef name)
void with_blender_project_read_lock(FunctionRef< void()> lambda)
bool is_valid_project_variable_name(StringRef name)
BMesh Iterators.
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
std::string BKE_blender_project_path_resolve(StringRef path, const bke::BlenderProject &project)
Vector< RecentProject > BKE_blender_project_recent_get()
void BKE_blender_project_recent_clear(bool only_missing)
void BKE_blender_project_config_autosave(Main *bmain)
bke::BlenderProject * BKE_blender_project_get(const Main *bmain)
void BKE_blender_project_refresh(Main *bmain, const char *filepath)
auto BKE_blender_project_read_callback(const Main *bmain, Fn lambda)
void BKE_blender_project_clear()
void BKE_blender_project_recent_update(const Main *bmain)
bool BKE_blender_project_config_file_write(Main *bmain)
std::string BKE_is_path_inside_blender_project(const char *path)
bool BKE_blender_project_init(blender::StringRef name, blender::StringRef root_path)
bool BKE_blender_project_dir_is_project(StringRef path)
bool BKE_blender_project_init_from_root_path(Main *bmain, std::string project_root_path)
auto BKE_blender_project_write_callback(const Main *bmain, Fn lambda)
std::string BKE_blender_project_path_make_relative(StringRef path, bool path_is_template, const bke::BlenderProject &project)
eIDPropertyType type
Definition DNA_ID.h:145