[Bf-blender-cvs] [f3a3a976b7d] master: Refactor: move `Library`-specific functions into proper `BKE_library` file.

Bastien Montagne noreply at git.blender.org
Mon Feb 10 17:12:10 CET 2020


Commit: f3a3a976b7ddaca77560040e9bea7e9303e4eead
Author: Bastien Montagne
Date:   Mon Feb 10 17:10:17 2020 +0100
Branches: master
https://developer.blender.org/rBf3a3a976b7ddaca77560040e9bea7e9303e4eead

Refactor: move `Library`-specific functions into proper `BKE_library` file.

Even though we do not have much of those, this might change in the
future, and in any case having specific functions for this ID type in
generic `BKE_lib` area was really confusing.

===================================================================

M	source/blender/blenkernel/BKE_lib_id.h
A	source/blender/blenkernel/BKE_library.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/bpath.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c
A	source/blender/blenkernel/intern/library.c
M	source/blender/blenloader/intern/blend_validate.c
M	source/blender/editors/space_outliner/outliner_draw.c
M	source/blender/makesrna/intern/rna_ID.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_lib_id.h b/source/blender/blenkernel/BKE_lib_id.h
index 2ff2644684a..7d00e98f239 100644
--- a/source/blender/blenkernel/BKE_lib_id.h
+++ b/source/blender/blenkernel/BKE_lib_id.h
@@ -182,7 +182,6 @@ void BKE_libblock_management_usercounts_clear(struct Main *bmain, void *idv);
 void BKE_id_lib_local_paths(struct Main *bmain, struct Library *lib, struct ID *id);
 void id_lib_extern(struct ID *id);
 void id_lib_indirect_weak_link(struct ID *id);
-void BKE_library_filepath_set(struct Main *bmain, struct Library *lib, const char *filepath);
 void id_us_ensure_real(struct ID *id);
 void id_us_clear_real(struct ID *id);
 void id_us_plus_no_lib(struct ID *id);
@@ -241,8 +240,6 @@ void BKE_id_full_name_ui_prefix_get(char name[MAX_ID_FULL_NAME_UI], const struct
 
 char *BKE_id_to_unique_string_key(const struct ID *id);
 
-void BKE_library_free(struct Library *lib);
-
 void BKE_library_make_local(struct Main *bmain,
                             const struct Library *lib,
                             struct GHash *old_to_new_ids,
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
new file mode 100644
index 00000000000..1324e4ebf90
--- /dev/null
+++ b/source/blender/blenkernel/BKE_library.h
@@ -0,0 +1,45 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+#ifndef __BKE_LIBRARY_H__
+#define __BKE_LIBRARY_H__
+
+/** \file
+ * \ingroup bke
+ *
+ * API to manage `Library` data-blocks.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "BLI_compiler_attrs.h"
+
+struct Library;
+struct Main;
+
+void BKE_library_free(struct Library *lib);
+
+void BKE_library_filepath_set(struct Main *bmain, struct Library *lib, const char *filepath);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_LIBRARY_H__ */
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index e2be61269f9..f536b8d94fc 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -140,6 +140,7 @@ set(SRC
   intern/lib_override.c
   intern/lib_query.c
   intern/lib_remap.c
+  intern/library.c
   intern/light.c
   intern/lightprobe.c
   intern/linestyle.c
@@ -303,6 +304,7 @@ set(SRC
   BKE_lib_override.h
   BKE_lib_query.h
   BKE_lib_remap.h
+  BKE_library.h
   BKE_light.h
   BKE_lightprobe.h
   BKE_linestyle.h
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index 835fd645e25..3743a340a53 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -67,6 +67,7 @@
 
 #include "BKE_font.h"
 #include "BKE_lib_id.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_node.h"
 #include "BKE_report.h"
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 9a1ade90367..d1dd325a4df 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -1532,13 +1532,6 @@ void *BKE_libblock_copy_for_localize(const ID *id)
   return idn;
 }
 
-void BKE_library_free(Library *lib)
-{
-  if (lib->packedfile) {
-    BKE_packedfile_free(lib->packedfile);
-  }
-}
-
 /* ***************** ID ************************ */
 ID *BKE_libblock_find_name(struct Main *bmain, const short type, const char *name)
 {
@@ -2504,31 +2497,6 @@ char *BKE_id_to_unique_string_key(const struct ID *id)
   }
 }
 
-void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
-{
-  /* in some cases this is used to update the absolute path from the
-   * relative */
-  if (lib->name != filepath) {
-    BLI_strncpy(lib->name, filepath, sizeof(lib->name));
-  }
-
-  BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
-
-  /* not essential but set filepath is an absolute copy of value which
-   * is more useful if its kept in sync */
-  if (BLI_path_is_rel(lib->filepath)) {
-    /* note that the file may be unsaved, in this case, setting the
-     * filepath on an indirectly linked path is not allowed from the
-     * outliner, and its not really supported but allow from here for now
-     * since making local could cause this to be directly linked - campbell
-     */
-    /* Never make paths relative to parent lib - reading code (blenloader) always set *all*
-     * lib->name relative to current main, not to their parent for indirectly linked ones. */
-    const char *basepath = BKE_main_blendfile_path(bmain);
-    BLI_path_abs(lib->filepath, basepath);
-  }
-}
-
 void BKE_id_tag_set_atomic(ID *id, int tag)
 {
   atomic_fetch_and_or_int32(&id->tag, tag);
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index fcca12a564a..1be2a44cbb9 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -78,6 +78,7 @@
 #include "BKE_lib_id.h"
 #include "BKE_lib_override.h"
 #include "BKE_lib_remap.h"
+#include "BKE_library.h"
 #include "BKE_linestyle.h"
 #include "BKE_mesh.h"
 #include "BKE_material.h"
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
new file mode 100644
index 00000000000..376d5aacbf5
--- /dev/null
+++ b/source/blender/blenkernel/intern/library.c
@@ -0,0 +1,75 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup bke
+ *
+ * Contains code specific to the `Library` ID type.
+ */
+
+#include "CLG_log.h"
+
+#include "MEM_guardedalloc.h"
+
+/* all types are needed here, in order to do memory operations */
+#include "DNA_ID.h"
+
+#include "BLI_utildefines.h"
+
+#include "BLI_blenlib.h"
+
+#include "BKE_lib_id.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_packedFile.h"
+
+/* Unused currently. */
+// static CLG_LogRef LOG = {.identifier = "bke.library"};
+
+void BKE_library_free(Library *lib)
+{
+  if (lib->packedfile) {
+    BKE_packedfile_free(lib->packedfile);
+  }
+}
+
+void BKE_library_filepath_set(Main *bmain, Library *lib, const char *filepath)
+{
+  /* in some cases this is used to update the absolute path from the
+   * relative */
+  if (lib->name != filepath) {
+    BLI_strncpy(lib->name, filepath, sizeof(lib->name));
+  }
+
+  BLI_strncpy(lib->filepath, filepath, sizeof(lib->filepath));
+
+  /* not essential but set filepath is an absolute copy of value which
+   * is more useful if its kept in sync */
+  if (BLI_path_is_rel(lib->filepath)) {
+    /* note that the file may be unsaved, in this case, setting the
+     * filepath on an indirectly linked path is not allowed from the
+     * outliner, and its not really supported but allow from here for now
+     * since making local could cause this to be directly linked - campbell
+     */
+    /* Never make paths relative to parent lib - reading code (blenloader) always set *all*
+     * lib->name relative to current main, not to their parent for indirectly linked ones. */
+    const char *basepath = BKE_main_blendfile_path(bmain);
+    BLI_path_abs(lib->filepath, basepath);
+  }
+}
diff --git a/source/blender/blenloader/intern/blend_validate.c b/source/blender/blenloader/intern/blend_validate.c
index 53bf70acb1c..cc447196507 100644
--- a/source/blender/blenloader/intern/blend_validate.c
+++ b/source/blender/blenloader/intern/blend_validate.c
@@ -38,6 +38,7 @@
 
 #include "BKE_key.h"
 #include "BKE_lib_id.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_report.h"
 
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index c2b47d94af6..12704777b05 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -49,6 +49,7 @@
 #include "BKE_idcode.h"
 #include "BKE_layer.h"
 #include "BKE_lib_id.h"
+#include "BKE_library.h"
 #include "BKE_main.h"
 #include "BKE_modifier.h"
 #include "BKE_object.h"
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index 7de6b651900..8a216579c80 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -93,6 +93,7 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
 #  include "BKE_lib_query.h"
 #  include "BKE_lib_override.h"
 #  include "BKE_lib_remap.h"
+#  include "BKE_library.h"
 #  include "BKE_animsys.h"
 #  include "BKE_material.h"
 #  include "BKE_global.h" /* XXX, remove me */



More information about the Bf-blender-cvs mailing list