Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/editors/lattice')
-rw-r--r--source/blender/editors/lattice/CMakeLists.txt2
-rw-r--r--source/blender/editors/lattice/editlattice_select.c149
-rw-r--r--source/blender/editors/lattice/editlattice_tools.c7
-rw-r--r--source/blender/editors/lattice/editlattice_undo.c80
4 files changed, 160 insertions, 78 deletions
diff --git a/source/blender/editors/lattice/CMakeLists.txt b/source/blender/editors/lattice/CMakeLists.txt
index 3bb954ddf46..2207e0fa736 100644
--- a/source/blender/editors/lattice/CMakeLists.txt
+++ b/source/blender/editors/lattice/CMakeLists.txt
@@ -22,10 +22,12 @@ set(INC
../include
../../blenkernel
../../blenlib
+ ../../depsgraph
../../makesdna
../../makesrna
../../render/extern/include
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
)
diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c
index d0d64b85195..6f1c864130d 100644
--- a/source/blender/editors/lattice/editlattice_select.c
+++ b/source/blender/editors/lattice/editlattice_select.c
@@ -50,6 +50,7 @@
#include "BKE_context.h"
#include "BKE_lattice.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
#include "ED_screen.h"
#include "ED_lattice.h"
@@ -58,6 +59,8 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "DEG_depsgraph.h"
+
#include "lattice_intern.h"
/* -------------------------------------------------------------------- */
@@ -84,36 +87,44 @@ static void bpoint_select_set(BPoint *bp, bool select)
static int lattice_select_random_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
-
const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
const int seed = WM_operator_properties_select_random_seed_increment_get(op);
const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
- RNG *rng = BLI_rng_new_srandom(seed);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
- int tot;
- BPoint *bp;
+ RNG *rng = BLI_rng_new_srandom(seed);
- tot = lt->pntsu * lt->pntsv * lt->pntsw;
- bp = lt->def;
- while (tot--) {
- if (!bp->hide) {
- if (BLI_rng_get_float(rng) < randfac) {
- bpoint_select_set(bp, select);
+ int tot;
+ BPoint *bp;
+
+ tot = lt->pntsu * lt->pntsv * lt->pntsw;
+ bp = lt->def;
+ while (tot--) {
+ if (!bp->hide) {
+ if (BLI_rng_get_float(rng) < randfac) {
+ bpoint_select_set(bp, select);
+ }
}
+ bp++;
}
- bp++;
- }
- if (select == false) {
- lt->actbp = LT_ACTBP_NONE;
- }
+ if (select == false) {
+ lt->actbp = LT_ACTBP_NONE;
+ }
- BLI_rng_free(rng);
+ BLI_rng_free(rng);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -183,18 +194,28 @@ static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool e
static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
const int axis_flag = RNA_enum_get(op->ptr, "axis");
const bool extend = RNA_boolean_get(op->ptr, "extend");
- for (int axis = 0; axis < 3; axis++) {
- if ((1 << axis) & axis_flag) {
- ed_lattice_select_mirrored(lt, axis, extend);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
+
+ for (int axis = 0; axis < 3; axis++) {
+ if ((1 << axis) & axis_flag) {
+ ed_lattice_select_mirrored(lt, axis, extend);
+ }
}
- }
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ /* TODO, only notify changes */
+ DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -278,6 +299,7 @@ static int lattice_select_more_less(bContext *C, const bool select)
MEM_freeN(selpoints);
+ DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
}
@@ -349,51 +371,56 @@ void ED_lattice_flags_set(Object *obedit, int flag)
static int lattice_select_all_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Lattice *lt = obedit->data;
- BPoint *bp;
- int a;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
int action = RNA_enum_get(op->ptr, "action");
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
if (action == SEL_TOGGLE) {
action = SEL_SELECT;
-
- bp = lt->editlatt->latt->def;
- a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
-
- while (a--) {
- if (bp->hide == 0) {
- if (bp->f1 & SELECT) {
- action = SEL_DESELECT;
- break;
- }
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt = obedit->data;
+ if (BKE_lattice_is_any_selected(lt->editlatt->latt)) {
+ action = SEL_DESELECT;
+ break;
}
- bp++;
}
}
- switch (action) {
- case SEL_SELECT:
- ED_lattice_flags_set(obedit, 1);
- break;
- case SEL_DESELECT:
- ED_lattice_flags_set(obedit, 0);
- break;
- case SEL_INVERT:
- bp = lt->editlatt->latt->def;
- a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
- lt->editlatt->latt->actbp = LT_ACTBP_NONE;
-
- while (a--) {
- if (bp->hide == 0) {
- bp->f1 ^= SELECT;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt;
+ BPoint *bp;
+ int a;
+
+ switch (action) {
+ case SEL_SELECT:
+ ED_lattice_flags_set(obedit, 1);
+ break;
+ case SEL_DESELECT:
+ ED_lattice_flags_set(obedit, 0);
+ break;
+ case SEL_INVERT:
+ lt = obedit->data;
+ bp = lt->editlatt->latt->def;
+ a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw;
+ lt->editlatt->latt->actbp = LT_ACTBP_NONE;
+
+ while (a--) {
+ if (bp->hide == 0) {
+ bp->f1 ^= SELECT;
+ }
+ bp++;
}
- bp++;
- }
- break;
+ break;
+ }
+ DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
+ MEM_freeN(objects);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
}
@@ -449,6 +476,7 @@ static int lattice_select_ungrouped_exec(bContext *C, wmOperator *op)
}
}
+ DEG_id_tag_update(obedit->data, DEG_TAG_SELECT_UPDATE);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
@@ -547,6 +575,7 @@ bool ED_lattice_select_pick(bContext *C, const int mval[2], bool extend, bool de
lt->actbp = LT_ACTBP_NONE;
}
+ DEG_id_tag_update(vc.obedit->data, DEG_TAG_SELECT_UPDATE);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
return true;
diff --git a/source/blender/editors/lattice/editlattice_tools.c b/source/blender/editors/lattice/editlattice_tools.c
index 8ecb182528a..c6ba0237a68 100644
--- a/source/blender/editors/lattice/editlattice_tools.c
+++ b/source/blender/editors/lattice/editlattice_tools.c
@@ -39,9 +39,10 @@
#include "RNA_define.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
+#include "DEG_depsgraph.h"
+
#include "ED_screen.h"
#include "WM_api.h"
@@ -80,7 +81,7 @@ static int make_regular_exec(bContext *C, wmOperator *UNUSED(op))
BKE_lattice_resize(lt, lt->pntsu, lt->pntsv, lt->pntsw, NULL);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
return OPERATOR_FINISHED;
@@ -306,7 +307,7 @@ static int lattice_flip_exec(bContext *C, wmOperator *op)
}
/* updates */
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 7a7372f5a6a..cbd89016b44 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -33,6 +33,8 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
#include "BLI_utildefines.h"
#include "BLI_array_utils.h"
@@ -42,11 +44,14 @@
#include "DNA_scene_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_lattice.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "WM_types.h"
@@ -54,6 +59,9 @@
#include "lattice_intern.h"
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.lattice"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -123,13 +131,19 @@ static Object *editlatt_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
-typedef struct LatticeUndoStep {
- UndoStep step;
- /* note: will split out into list for multi-object-editmode. */
+typedef struct LatticeUndoStep_Elem {
UndoRefID_Object obedit_ref;
UndoLattice data;
+} LatticeUndoStep_Elem;
+
+typedef struct LatticeUndoStep {
+ UndoStep step;
+ LatticeUndoStep_Elem *elems;
+ uint elems_len;
} LatticeUndoStep;
static bool lattice_undosys_poll(bContext *C)
@@ -140,10 +154,24 @@ static bool lattice_undosys_poll(bContext *C)
static bool lattice_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- us->obedit_ref.ptr = editlatt_object_from_context(C);
- Lattice *lt = us->obedit_ref.ptr->data;
- undolatt_from_editlatt(&us->data, lt->editlatt);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ Lattice *lt = ob->data;
+ undolatt_from_editlatt(&elem->data, lt->editlatt);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
@@ -154,25 +182,47 @@ static void lattice_undosys_step_decode(struct bContext *C, UndoStep *us_p, int
BLI_assert(lattice_undosys_poll(C));
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- Lattice *lt = obedit->data;
- EditLatt *editlatt = lt->editlatt;
- undolatt_to_editlatt(&us->data, editlatt);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ Lattice *lt = obedit->data;
+ if (lt->editlatt == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
+ us_p->name, obedit->id.name);
+ continue;
+ }
+ undolatt_to_editlatt(&elem->data, lt->editlatt);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void lattice_undosys_step_free(UndoStep *us_p)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- undolatt_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ undolatt_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
}
static void lattice_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
}
/* Export for ED_undo_sys. */