[Bf-blender-cvs] [2b2695f3b00] temp-mesh-cpp: Cleanup: Move object_transform.c to C++
Hans Goudey
noreply at git.blender.org
Fri Mar 18 19:51:43 CET 2022
Commit: 2b2695f3b0026c94d3fe25eb3e1b3ecef5558bf5
Author: Hans Goudey
Date: Fri Mar 18 13:51:33 2022 -0500
Branches: temp-mesh-cpp
https://developer.blender.org/rB2b2695f3b0026c94d3fe25eb3e1b3ecef5558bf5
Cleanup: Move object_transform.c to C++
===================================================================
M source/blender/editors/armature/pose_transform.c
M source/blender/editors/object/CMakeLists.txt
M source/blender/editors/object/object_intern.h
R086 source/blender/editors/object/object_transform.c source/blender/editors/object/object_transform.cc
===================================================================
diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index 90d4ef60598..f0b0218d7e0 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -1100,7 +1100,7 @@ static void pchan_clear_rot(bPoseChannel *pchan)
copy_v3_v3(pchan->eul, eul);
}
}
- } /* Duplicated in source/blender/editors/object/object_transform.c */
+ } /* Duplicated in source/blender/editors/object/object_transform.cc */
else {
if (pchan->rotmode == ROT_MODE_QUAT) {
unit_qt(pchan->quat);
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index 6f8763fa2bb..02feccc211a 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -51,7 +51,7 @@ set(SRC
object_select.c
object_shader_fx.c
object_shapekey.c
- object_transform.c
+ object_transform.cc
object_utils.c
object_vgroup.c
object_volume.c
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index 60a49fa6945..490c495dad5 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -28,7 +28,7 @@ enum eObject_Hook_Add_Mode {
/* internal exports only */
-/* object_transform.c */
+/* object_transform.cc */
void OBJECT_OT_location_clear(struct wmOperatorType *ot);
void OBJECT_OT_rotation_clear(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.cc
similarity index 86%
rename from source/blender/editors/object/object_transform.c
rename to source/blender/editors/object/object_transform.cc
index 9e82abf4d07..1970851c326 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.cc
@@ -5,8 +5,8 @@
* \ingroup edobj
*/
-#include <stdlib.h>
-#include <string.h>
+#include <cstdlib>
+#include <cstring>
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
@@ -19,10 +19,12 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "BLI_array.h"
+#include "BLI_array.hh"
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_math_vector.hh"
#include "BLI_utildefines.h"
+#include "BLI_vector.hh"
#include "BKE_armature.h"
#include "BKE_context.h"
@@ -64,6 +66,10 @@
#include "object_intern.h"
+using blender::Array;
+using blender::float2;
+using blender::Vector;
+
/* -------------------------------------------------------------------- */
/** \name Clear Transformation Utilities
* \{ */
@@ -283,25 +289,20 @@ static int object_clear_transform_generic_exec(bContext *C,
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
ViewLayer *view_layer = CTX_data_view_layer(C);
- /* May be NULL. */
+ /* May be null. */
View3D *v3d = CTX_wm_view3d(C);
KeyingSet *ks;
const bool clear_delta = RNA_boolean_get(op->ptr, "clear_delta");
- BLI_assert(!ELEM(NULL, clear_func, default_ksName));
+ BLI_assert(!ELEM(nullptr, clear_func, default_ksName));
- Object **objects = NULL;
- uint objects_len = 0;
- {
- BLI_array_declare(objects);
- FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer, v3d, ob) {
- BLI_array_append(objects, ob);
- }
- FOREACH_SELECTED_EDITABLE_OBJECT_END;
- objects_len = BLI_array_len(objects);
+ Vector<Object *> objects;
+ FOREACH_SELECTED_EDITABLE_OBJECT_BEGIN (view_layer, v3d, ob) {
+ objects.append(ob);
}
+ FOREACH_SELECTED_EDITABLE_OBJECT_END;
- if (objects == NULL) {
+ if (objects.is_empty()) {
return OPERATOR_CANCELLED;
}
@@ -310,14 +311,14 @@ static int object_clear_transform_generic_exec(bContext *C,
SCE_XFORM_SKIP_CHILDREN);
const bool use_transform_data_origin = (scene->toolsettings->transform_flag &
SCE_XFORM_DATA_ORIGIN);
- struct XFormObjectSkipChild_Container *xcs = NULL;
- struct XFormObjectData_Container *xds = NULL;
+ struct XFormObjectSkipChild_Container *xcs = nullptr;
+ struct XFormObjectData_Container *xds = nullptr;
if (use_transform_skip_children) {
BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
xcs = ED_object_xform_skip_child_container_create();
ED_object_xform_skip_child_container_item_ensure_from_array(
- xcs, view_layer, objects, objects_len);
+ xcs, view_layer, objects.data(), objects.size());
}
if (use_transform_data_origin) {
BKE_scene_graph_evaluated_ensure(depsgraph, bmain);
@@ -327,9 +328,7 @@ static int object_clear_transform_generic_exec(bContext *C,
/* get KeyingSet to use */
ks = ANIM_get_keyingset_for_autokeying(scene, default_ksName);
- for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
- Object *ob = objects[ob_index];
-
+ for (Object *ob : objects) {
if (use_transform_data_origin) {
ED_object_data_xform_container_item_ensure(xds, ob);
}
@@ -342,7 +341,6 @@ static int object_clear_transform_generic_exec(bContext *C,
/* tag for updates */
DEG_id_tag_update(&ob->id, ID_RECALC_TRANSFORM);
}
- MEM_freeN(objects);
if (use_transform_skip_children) {
ED_object_xform_skip_child_container_update_all(xcs, bmain, depsgraph);
@@ -355,7 +353,7 @@ static int object_clear_transform_generic_exec(bContext *C,
}
/* this is needed so children are also updated */
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, nullptr);
return OPERATOR_FINISHED;
}
@@ -488,7 +486,7 @@ static int object_origin_clear_exec(bContext *C, wmOperator *UNUSED(op))
}
CTX_DATA_END;
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, nullptr);
return OPERATOR_FINISHED;
}
@@ -519,12 +517,11 @@ void OBJECT_OT_origin_clear(wmOperatorType *ot)
static void ignore_parent_tx(Main *bmain, Depsgraph *depsgraph, Scene *scene, Object *ob)
{
Object workob;
- Object *ob_child;
Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
/* a change was made, adjust the children to compensate */
- for (ob_child = bmain->objects.first; ob_child; ob_child = ob_child->id.next) {
+ LISTBASE_FOREACH (Object *, ob_child, &bmain->objects) {
if (ob_child->parent == ob) {
Object *ob_child_eval = DEG_get_evaluated_object(depsgraph, ob_child);
BKE_object_apply_mat4(ob_child_eval, ob_child_eval->obmat, true, false);
@@ -549,7 +546,7 @@ static void append_sorted_object_parent_hierarchy(Object *root_object,
Object **sorted_objects,
int *object_index)
{
- if (!ELEM(object->parent, NULL, root_object)) {
+ if (!ELEM(object->parent, nullptr, root_object)) {
append_sorted_object_parent_hierarchy(
root_object, object->parent, sorted_objects, object_index);
}
@@ -560,7 +557,7 @@ static void append_sorted_object_parent_hierarchy(Object *root_object,
}
}
-static Object **sorted_selected_editable_objects(bContext *C, int *r_num_objects)
+static Array<Object *> sorted_selected_editable_objects(bContext *C)
{
Main *bmain = CTX_data_main(C);
@@ -573,23 +570,20 @@ static Object **sorted_selected_editable_objects(bContext *C, int *r_num_objects
}
CTX_DATA_END;
if (num_objects == 0) {
- *r_num_objects = 0;
- return NULL;
+ return {};
}
/* Append all the objects. */
- Object **sorted_objects = MEM_malloc_arrayN(num_objects, sizeof(Object *), "sorted objects");
+ Array<Object *> sorted_objects(num_objects);
int object_index = 0;
CTX_DATA_BEGIN (C, Object *, object, selected_editable_objects) {
if ((object->id.tag & LIB_TAG_DOIT) == 0) {
continue;
}
- append_sorted_object_parent_hierarchy(object, object, sorted_objects, &object_index);
+ append_sorted_object_parent_hierarchy(object, object, sorted_objects.data(), &object_index);
}
CTX_DATA_END;
- *r_num_objects = num_objects;
-
return sorted_objects;
}
@@ -617,11 +611,11 @@ static int apply_objects_internal(bContext *C,
OB_SURF,
OB_FONT,
OB_GPENCIL)) {
- ID *obdata = ob->data;
+ ID *obdata = static_cast<ID *>(ob->data);
if (ID_REAL_USERS(obdata) > 1) {
BKE_reportf(reports,
RPT_ERROR,
- "Cannot apply to a multi user: Object \"%s\", %s \"%s\", aborting",
+ R"(Cannot apply to a multi user: Object "%s", %s "%s", aborting)",
ob->id.name + 2,
BKE_idtype_idcode_to_name(GS(obdata->name)),
obdata->name + 2);
@@ -631,7 +625,7 @@ static int apply_objects_internal(bContext *C,
if (ID_IS_LINKED(obdata)) {
BKE_reportf(reports,
RPT_ERROR,
- "Cannot apply to library data: Object \"%s\", %s \"%s\", aborting",
+ R"(Cannot apply to library data: Object "%s", %s "%s", aborting)",
ob->id.name + 2,
BKE_idtype_idcode_to_name(GS(obdata->name)),
obdata->name + 2);
@@ -640,16 +634,14 @@ static int apply_objects_internal(bContext *C,
}
if (ELEM(ob->type, OB_CURVES_LEGACY, OB_SURF)) {
- ID *obdata = ob->data;
- Curve *cu;
-
- cu = ob->data;
+ ID *obdata = static_cast<ID *>(ob->data);
+ Curve *cu = static_cast<Curve *>(ob->data);
if (((ob->type == OB_CURVES_LEGACY) && !(cu->flag & CU_3D)) && (apply_rot || apply_loc)) {
BKE_reportf(
reports,
RPT_ERROR,
- "Rotation/Location can't apply to a 2D curve: Object \"%s\", %s \"%s\", aborting",
+ R"(Rotation/Location can't apply to a 2D curve: Object "%s", %s "%s", aborting)",
ob->id.name + 2,
BKE_idtype_idcode_to_name(GS(obdata->name)),
obdata->name + 2);
@@ -658,7 +650,7 @@ static int apply_objects_internal(bCon
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list