[Bf-blender-cvs] [8c21668ee17] master: Cleanup: Curve: Move to IDTypeInfo and remove unused BKE API.

Bastien Montagne noreply at git.blender.org
Fri Mar 6 16:23:29 CET 2020


Commit: 8c21668ee17411d71f2419b21ffa52d46c700e70
Author: Bastien Montagne
Date:   Fri Mar 6 15:51:31 2020 +0100
Branches: master
https://developer.blender.org/rB8c21668ee17411d71f2419b21ffa52d46c700e70

Cleanup: Curve: Move to IDTypeInfo and remove unused BKE API.

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

M	source/blender/blenkernel/BKE_curve.h
M	source/blender/blenkernel/BKE_idtype.h
M	source/blender/blenkernel/intern/curve.c
M	source/blender/blenkernel/intern/idtype.c
M	source/blender/blenkernel/intern/lib_id.c
M	source/blender/blenkernel/intern/lib_id_delete.c

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

diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index dd92ac181f9..6a11471064c 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -76,16 +76,10 @@ typedef struct CVKeyIndex {
   ((((cu)->flag & CU_3D) == 0) && (((cu)->flag & (CU_FRONT | CU_BACK)) != 0))
 
 /* ** Curve ** */
-void BKE_curve_free(struct Curve *cu);
 void BKE_curve_editfont_free(struct Curve *cu);
 void BKE_curve_init(struct Curve *cu, const short curve_type);
 struct Curve *BKE_curve_add(struct Main *bmain, const char *name, int type);
-void BKE_curve_copy_data(struct Main *bmain,
-                         struct Curve *cu_dst,
-                         const struct Curve *cu_src,
-                         const int flag);
 struct Curve *BKE_curve_copy(struct Main *bmain, const struct Curve *cu);
-void BKE_curve_make_local(struct Main *bmain, struct Curve *cu, const int flags);
 short BKE_curve_type_get(struct Curve *cu);
 void BKE_curve_type_test(struct Object *ob);
 void BKE_curve_curve_dimension_update(struct Curve *cu);
diff --git a/source/blender/blenkernel/BKE_idtype.h b/source/blender/blenkernel/BKE_idtype.h
index 8d97153468e..b84543c190c 100644
--- a/source/blender/blenkernel/BKE_idtype.h
+++ b/source/blender/blenkernel/BKE_idtype.h
@@ -128,7 +128,7 @@ extern IDTypeInfo IDType_ID_SCE;
 extern IDTypeInfo IDType_ID_LI;
 extern IDTypeInfo IDType_ID_OB;
 extern IDTypeInfo IDType_ID_ME;
-// extern IDTypeInfo IDType_ID_CU;
+extern IDTypeInfo IDType_ID_CU;
 // extern IDTypeInfo IDType_ID_MB;
 // extern IDTypeInfo IDType_ID_MA;
 // extern IDTypeInfo IDType_ID_TE;
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index a91e43792f7..95d9a7e883d 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -33,6 +33,8 @@
 #include "BLI_ghash.h"
 #include "BLI_linklist.h"
 
+#include "BLT_translation.h"
+
 #include "DNA_anim_types.h"
 #include "DNA_curve_types.h"
 #include "DNA_material_types.h"
@@ -48,6 +50,7 @@
 #include "BKE_curve.h"
 #include "BKE_displist.h"
 #include "BKE_font.h"
+#include "BKE_idtype.h"
 #include "BKE_key.h"
 #include "BKE_lib_id.h"
 #include "BKE_main.h"
@@ -64,6 +67,75 @@
 /* local */
 static CLG_LogRef LOG = {"bke.curve"};
 
+static void curve_init_data(ID *id)
+{
+  Curve *curve = (Curve *)id;
+
+  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(curve, id));
+
+  MEMCPY_STRUCT_AFTER(curve, DNA_struct_default_get(Curve), id);
+}
+
+static void curve_copy_data(Main *bmain, ID *id_dst, const ID *id_src, const int flag)
+{
+  Curve *curve_dst = (Curve *)id_dst;
+  const Curve *curve_src = (const Curve *)id_src;
+
+  BLI_listbase_clear(&curve_dst->nurb);
+  BKE_nurbList_duplicate(&(curve_dst->nurb), &(curve_src->nurb));
+
+  curve_dst->mat = MEM_dupallocN(curve_src->mat);
+
+  curve_dst->str = MEM_dupallocN(curve_src->str);
+  curve_dst->strinfo = MEM_dupallocN(curve_src->strinfo);
+  curve_dst->tb = MEM_dupallocN(curve_src->tb);
+  curve_dst->batch_cache = NULL;
+
+  if (curve_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
+    BKE_id_copy_ex(bmain, &curve_src->key->id, (ID **)&curve_dst->key, flag);
+    /* XXX This is not nice, we need to make BKE_id_copy_ex fully re-entrant... */
+    curve_dst->key->from = &curve_dst->id;
+  }
+
+  curve_dst->editnurb = NULL;
+  curve_dst->editfont = NULL;
+}
+
+static void curve_free_data(ID *id)
+{
+  Curve *curve = (Curve *)id;
+
+  BKE_animdata_free((ID *)curve, false);
+
+  BKE_curve_batch_cache_free(curve);
+
+  BKE_nurbList_free(&curve->nurb);
+  BKE_curve_editfont_free(curve);
+
+  BKE_curve_editNurb_free(curve);
+
+  MEM_SAFE_FREE(curve->mat);
+  MEM_SAFE_FREE(curve->str);
+  MEM_SAFE_FREE(curve->strinfo);
+  MEM_SAFE_FREE(curve->tb);
+}
+
+IDTypeInfo IDType_ID_CU = {
+    .id_code = ID_CU,
+    .id_filter = FILTER_ID_CU,
+    .main_listbase_index = INDEX_ID_CU,
+    .struct_size = sizeof(Curve),
+    .name = "Curve",
+    .name_plural = "curves",
+    .translation_context = BLT_I18NCONTEXT_ID_CURVE,
+    .flags = 0,
+
+    .init_data = curve_init_data,
+    .copy_data = curve_copy_data,
+    .free_data = curve_free_data,
+    .make_local = NULL,
+};
+
 static int cu_isectLL(const float v1[3],
                       const float v2[3],
                       const float v3[3],
@@ -127,29 +199,9 @@ void BKE_curve_editNurb_free(Curve *cu)
   }
 }
 
-/** Free (or release) any data used by this curve (does not free the curve itself). */
-void BKE_curve_free(Curve *cu)
-{
-  BKE_animdata_free((ID *)cu, false);
-
-  BKE_curve_batch_cache_free(cu);
-
-  BKE_nurbList_free(&cu->nurb);
-  BKE_curve_editfont_free(cu);
-
-  BKE_curve_editNurb_free(cu);
-
-  MEM_SAFE_FREE(cu->mat);
-  MEM_SAFE_FREE(cu->str);
-  MEM_SAFE_FREE(cu->strinfo);
-  MEM_SAFE_FREE(cu->tb);
-}
-
 void BKE_curve_init(Curve *cu, const short curve_type)
 {
-  BLI_assert(MEMCMP_STRUCT_AFTER_IS_ZERO(cu, id));
-
-  MEMCPY_STRUCT_AFTER(cu, DNA_struct_default_get(Curve), id);
+  curve_init_data(&cu->id);
 
   cu->type = curve_type;
 
@@ -181,38 +233,6 @@ Curve *BKE_curve_add(Main *bmain, const char *name, int type)
   return cu;
 }
 
-/**
- * Only copy internal data of Curve ID from source
- * to already allocated/initialized destination.
- * You probably never want to use that directly,
- * use #BKE_id_copy or #BKE_id_copy_ex for typical needs.
- *
- * WARNING! This function will not handle ID user count!
- *
- * \param flag: Copying options (see BKE_lib_id.h's LIB_ID_COPY_... flags for more).
- */
-void BKE_curve_copy_data(Main *bmain, Curve *cu_dst, const Curve *cu_src, const int flag)
-{
-  BLI_listbase_clear(&cu_dst->nurb);
-  BKE_nurbList_duplicate(&(cu_dst->nurb), &(cu_src->nurb));
-
-  cu_dst->mat = MEM_dupallocN(cu_src->mat);
-
-  cu_dst->str = MEM_dupallocN(cu_src->str);
-  cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
-  cu_dst->tb = MEM_dupallocN(cu_src->tb);
-  cu_dst->batch_cache = NULL;
-
-  if (cu_src->key && (flag & LIB_ID_COPY_SHAPEKEY)) {
-    BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, flag);
-    /* XXX This is not nice, we need to make BKE_id_copy_ex fully re-entrant... */
-    cu_dst->key->from = &cu_dst->id;
-  }
-
-  cu_dst->editnurb = NULL;
-  cu_dst->editfont = NULL;
-}
-
 Curve *BKE_curve_copy(Main *bmain, const Curve *cu)
 {
   Curve *cu_copy;
@@ -220,11 +240,6 @@ Curve *BKE_curve_copy(Main *bmain, const Curve *cu)
   return cu_copy;
 }
 
-void BKE_curve_make_local(Main *bmain, Curve *cu, const int flags)
-{
-  BKE_lib_id_make_local_generic(bmain, &cu->id, flags);
-}
-
 /* Get list of nurbs from editnurbs structure */
 ListBase *BKE_curve_editNurbs_get(Curve *cu)
 {
diff --git a/source/blender/blenkernel/intern/idtype.c b/source/blender/blenkernel/intern/idtype.c
index 403858ec407..49fc8ea55aa 100644
--- a/source/blender/blenkernel/intern/idtype.c
+++ b/source/blender/blenkernel/intern/idtype.c
@@ -55,7 +55,7 @@ static void id_type_init(void)
   INIT_TYPE(ID_LI);
   INIT_TYPE(ID_OB);
   INIT_TYPE(ID_ME);
-  // INIT_TYPE(ID_CU);
+  INIT_TYPE(ID_CU);
   // INIT_TYPE(ID_MB);
   // INIT_TYPE(ID_MA);
   // INIT_TYPE(ID_TE);
diff --git a/source/blender/blenkernel/intern/lib_id.c b/source/blender/blenkernel/intern/lib_id.c
index 8262da73262..9902987bd8e 100644
--- a/source/blender/blenkernel/intern/lib_id.c
+++ b/source/blender/blenkernel/intern/lib_id.c
@@ -476,9 +476,7 @@ bool BKE_lib_id_make_local(Main *bmain, ID *id, const bool test, const int flags
       BLI_assert(0);
       return true;
     case ID_CU:
-      if (!test) {
-        BKE_curve_make_local(bmain, (Curve *)id, flags);
-      }
+      BLI_assert(0);
       return true;
     case ID_MB:
       if (!test) {
@@ -719,7 +717,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag)
         BLI_assert(0);
         break;
       case ID_CU:
-        BKE_curve_copy_data(bmain, (Curve *)*r_newid, (Curve *)id, flag);
+        BLI_assert(0);
         break;
       case ID_MB:
         BKE_mball_copy_data(bmain, (MetaBall *)*r_newid, (MetaBall *)id, flag);
@@ -1340,7 +1338,7 @@ void BKE_libblock_init_empty(ID *id)
       BLI_assert(0);
       break;
     case ID_CU:
-      BKE_curve_init((Curve *)id, 0);
+      BLI_assert(0);
       break;
     case ID_MB:
       BKE_mball_init((MetaBall *)id);
diff --git a/source/blender/blenkernel/intern/lib_id_delete.c b/source/blender/blenkernel/intern/lib_id_delete.c
index 2714ba19463..e097ccf1ce6 100644
--- a/source/blender/blenkernel/intern/lib_id_delete.c
+++ b/source/blender/blenkernel/intern/lib_id_delete.c
@@ -149,7 +149,7 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
       BLI_assert(0);
       break;
     case ID_CU:
-      BKE_curve_free((Curve *)id);
+      BLI_assert(0);
       break;
     case ID_MB:
       BKE_mball_free((MetaBall *)id);



More information about the Bf-blender-cvs mailing list