[Bf-blender-cvs] [a943979db38] soc-2019-bevel-profiles: Profile Widget added to global ToolSettings struct and edit mode bevel tool.

Hans Goudey noreply at git.blender.org
Wed Jul 10 05:40:00 CEST 2019


Commit: a943979db3878de5ede16400ecb073c1a5562b01
Author: Hans Goudey
Date:   Tue Jul 9 23:35:23 2019 -0400
Branches: soc-2019-bevel-profiles
https://developer.blender.org/rBa943979db3878de5ede16400ecb073c1a5562b01

Profile Widget added to global ToolSettings struct and edit mode bevel tool.

Now the same profile widget should be accessible everywhere, so the changes
should carry over from one call to the next.

The tool settings for bevel are now drawn in a custom callback which also enables
some fancier hiding of properties when they're not being used, which I've also
taken advantage of in this commit.

There are still a couple bugs with the new redo panel but the bulk of the work is
finished for making the bevel tool work with custom profiles.

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

M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/versioning_defaults.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/bmesh/intern/bmesh_opdefines.c
M	source/blender/bmesh/intern/bmesh_operator_api.h
M	source/blender/bmesh/operators/bmo_bevel.c
M	source/blender/editors/interface/interface_draw.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/mesh/editmesh_bevel.c
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index a447b828bb1..38508851855 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -78,6 +78,7 @@
 #include "BKE_node.h"
 #include "BKE_object.h"
 #include "BKE_paint.h"
+#include "BKE_profile_widget.h"
 #include "BKE_rigidbody.h"
 #include "BKE_scene.h"
 #include "BKE_screen.h"
@@ -180,6 +181,8 @@ ToolSettings *BKE_toolsettings_copy(ToolSettings *toolsettings, const int flag)
   /* duplicate Grease Pencil multiframe fallof */
   ts->gp_sculpt.cur_falloff = curvemapping_copy(ts->gp_sculpt.cur_falloff);
   ts->gp_sculpt.cur_primitive = curvemapping_copy(ts->gp_sculpt.cur_primitive);
+
+  ts->prwdgt = profilewidget_copy(ts->prwdgt);
   return ts;
 }
 
@@ -222,6 +225,10 @@ void BKE_toolsettings_free(ToolSettings *toolsettings)
     curvemapping_free(toolsettings->gp_sculpt.cur_primitive);
   }
 
+  if (toolsettings->prwdgt) {
+    profilewidget_free(toolsettings->prwdgt);
+  }
+
   MEM_freeN(toolsettings);
 }
 
@@ -884,6 +891,10 @@ void BKE_scene_init(Scene *sce)
   sce->toolsettings->annotate_v3d_align = GP_PROJECT_VIEWSPACE | GP_PROJECT_CURSOR;
   sce->toolsettings->annotate_thickness = 3;
 
+  /* Profile Widget */
+  printf("(BKE_scene_init) Adding profilewidget to tool settings\n");
+  sce->toolsettings->prwdgt = profilewidget_add(PROF_PRESET_LINE);
+
   for (int i = 0; i < ARRAY_SIZE(sce->orientation_slots); i++) {
     sce->orientation_slots[i].index_custom = -1;
   }
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 34295840677..1202ca1c406 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -6758,6 +6758,12 @@ static void direct_link_scene(FileData *fd, Scene *sce)
     if (sce->toolsettings->gp_sculpt.cur_primitive) {
       direct_link_curvemapping(fd, sce->toolsettings->gp_sculpt.cur_primitive);
     }
+
+    /* Relink toolsettings profile widget */
+    sce->toolsettings->prwdgt = newdataadr(fd, sce->toolsettings->prwdgt);
+    if (sce->toolsettings->prwdgt) {
+      direct_link_profilewidget(fd, sce->toolsettings->prwdgt);
+    }
   }
 
   if (sce->ed) {
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 5d899ef73a6..d6136bef2bc 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -78,6 +78,7 @@
 #include "BKE_object.h"
 #include "BKE_paint.h"
 #include "BKE_pointcache.h"
+#include "BKE_profile_widget.h"
 #include "BKE_report.h"
 #include "BKE_rigidbody.h"
 #include "BKE_scene.h"
@@ -3509,5 +3510,16 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *bmain)
     LISTBASE_FOREACH (bArmature *, arm, &bmain->armatures) {
       arm->flag &= ~(ARM_FLAG_UNUSED_6);
     }
+
+    /* HANS-TODO: Versioning for bevel modifier and test it */
+    if (!DNA_struct_elem_find(
+            fd->filesdna, "ToolSettings", "ProfileWidget", "prwdgt")) {
+      for (Scene *scene = bmain->scenes.first; scene; scene = scene->id.next) {
+        ToolSettings *ts = scene->toolsettings;
+        if ((ts) && (ts->prwdgt == NULL)) {
+          ts->prwdgt = profilewidget_add(PROF_PRESET_LINE);
+        }
+      }
+    }
   }
 }
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 57c674ae1b1..16cbf06bb1b 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -51,6 +51,7 @@
 #include "BKE_screen.h"
 #include "BKE_studiolight.h"
 #include "BKE_workspace.h"
+#include "BKE_profile_widget.h"
 
 #include "BLO_readfile.h"
 
@@ -358,6 +359,11 @@ static void blo_update_defaults_scene(Main *bmain, Scene *scene)
                    CURVE_PRESET_BELL,
                    CURVEMAP_SLOPE_POSITIVE);
   }
+
+  /* Make sure that the profile widget is initialized */
+  if (ts->prwdgt == NULL) {
+    ts->prwdgt = profilewidget_add(PROF_PRESET_LINE);
+  }
 }
 
 /**
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 86383a18643..4cc442ed1b3 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -2538,6 +2538,10 @@ static void write_scene(WriteData *wd, Scene *sce)
   if (tos->gp_sculpt.cur_primitive) {
     write_curvemapping(wd, tos->gp_sculpt.cur_primitive);
   }
+  /* Write the profile widget to the file */
+  if (tos->prwdgt) {
+    write_profilewidget(wd, tos->prwdgt);
+  }
 
   write_paint(wd, &tos->imapaint.paint);
 
diff --git a/source/blender/bmesh/intern/bmesh_opdefines.c b/source/blender/bmesh/intern/bmesh_opdefines.c
index d54f12bdf34..0d14762f9c8 100644
--- a/source/blender/bmesh/intern/bmesh_opdefines.c
+++ b/source/blender/bmesh/intern/bmesh_opdefines.c
@@ -1778,8 +1778,7 @@ static BMOpDefine bmo_bevel_def = {
    {"smoothresh", BMO_OP_SLOT_FLT},       /* for passing mesh's smoothresh, used in hardening */
    {"use_custom_profile", BMO_OP_SLOT_BOOL}, /* Whether to use custom profile feature */
    /* the ProfileWiget struct for the custom profile shape */
-   {"prwdgt", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_WIDGET}},
-   /* HANS-TODO: Figure out how to get the struct through here using the required subtype */
+   {"prwdgt", BMO_OP_SLOT_PTR, {(int)BMO_OP_SLOT_SUBTYPE_PTR_STRUCT}},
    {"sample_straight_edges", BMO_OP_SLOT_BOOL},
    {{'\0'}},
   },
diff --git a/source/blender/bmesh/intern/bmesh_operator_api.h b/source/blender/bmesh/intern/bmesh_operator_api.h
index 274424ef486..91bce72a9e3 100644
--- a/source/blender/bmesh/intern/bmesh_operator_api.h
+++ b/source/blender/bmesh/intern/bmesh_operator_api.h
@@ -237,8 +237,8 @@ typedef enum eBMOpSlotSubType_Ptr {
   BMO_OP_SLOT_SUBTYPE_PTR_SCENE = 101,
   BMO_OP_SLOT_SUBTYPE_PTR_OBJECT = 102,
   BMO_OP_SLOT_SUBTYPE_PTR_MESH = 103,
-  BMO_OP_SLOT_SUBTYPE_PTR_WIDGET = 104,
-  /* HANS-TODO: Can I do it without adding this? Or add something more general? */
+  BMO_OP_SLOT_SUBTYPE_PTR_STRUCT = 104,
+  /* HANS-TODO: Should I do it without adding this? */
 } eBMOpSlotSubType_Ptr;
 typedef enum eBMOpSlotSubType_Int {
   BMO_OP_SLOT_SUBTYPE_INT_ENUM = 200,
diff --git a/source/blender/bmesh/operators/bmo_bevel.c b/source/blender/bmesh/operators/bmo_bevel.c
index 9c6107b64ac..31e5b474cd0 100644
--- a/source/blender/bmesh/operators/bmo_bevel.c
+++ b/source/blender/bmesh/operators/bmo_bevel.c
@@ -49,15 +49,9 @@ void bmo_bevel_exec(BMesh *bm, BMOperator *op)
   const float spread = BMO_slot_float_get(op->slots_in, "spread");
   const float smoothresh = BMO_slot_float_get(op->slots_in, "smoothresh");
   const bool use_custom_profile = BMO_slot_bool_get(op->slots_in, "use_custom_profile");
-  const struct ProfileWidget *prwdgt =
-      (const struct ProfileWidget *)BMO_slot_ptr_get(op->slots_in, "prwdgt");
+  const ProfileWidget *prwdgt = BMO_slot_ptr_get(op->slots_in, "prwdgt");
   const bool sample_straight_edges = BMO_slot_bool_get(op->slots_in, "sample_straight_edges");
 
-  if (!prwdgt) {
-    printf("(bmo_bevel_exec) prwdgt null, shouldn't happen\n");
-    prwdgt = profilewidget_add(PROF_PRESET_LINE);
-  }
-
   if (offset > 0) {
     BMOIter siter;
     BMEdge *e;
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 3bf204182e7..022abec52e7 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -2188,7 +2188,6 @@ void ui_draw_but_PROFILE(ARegion *ar, uiBut *but, const uiWidgetColors *wcol, co
 
   /* 0.25 step grid */
   gl_shaded_color((uchar *)wcol->inner, -16);
-  /* HANS-TODO: Tends to crash when very zoomed out. Wrong number of verts given to GPU */
   ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f);
   /* 1.0 step grid */
   gl_shaded_color((uchar *)wcol->inner, -24);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 5fe0c5d0b6d..152099b92b8 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -4683,6 +4683,9 @@ void uiTemplateProfileWidget(uiLayout *layout, PointerRNA *ptr, const char *prop
     return;
   }
 
+  /* HANS-QUESTION: I don't quite know what the goal of this is. It looks like it was created for
+   * the CurveMapping struct, but it's probably still useful here. It looks like it enables
+   * updating the property with the pointer? */
   cb = MEM_callocN(sizeof(RNAUpdateCb), "RNAUpdateCb");
   cb->ptr = *ptr;
   cb->prop = prop;
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index 69fad5044fb..2023e43a439 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -99,8 +99,11 @@ typedef struct {
   short gizmo_flag;
   short value_mode; /* Which value does mouse movement and numeric input affect? */
   float segments;   /* Segments as float so smooth mouse pan works in small increments */
+
+  ProfileWidget *prwdgt;
 } BevelData;
 
+
 enum {
   BEV_MODAL_CANCEL = 1,
   BEV_MODAL_CONFIRM,
@@ -217,8 +220,8 @@ static void edbm_bevel_update_header(bContext *C, wmOperator *op)
 
 static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
 {
-  printf("EDBM BEVEL INIT\n");
   Scene *scene = CTX_data_scene(C);
+  ToolSettings *ts = CTX_data_tool_settings(C);
   BevelData *opdata;
   ViewLayer *view_layer = CTX_data_view_layer(C);
   float pixels_per_inch;
@@ -233,6 +236,9 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
   uint objects_used_len = 0;
   opdata->max_obj_scale = FLT_MIN;
 
+  /* Put the Profile Widget from the toolsettings into the opdata struct */
+  opdata->prwdgt = ts->prwdgt;
+
   {
     uint ob_store_len = 0;
     Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(
@@ -301,8 +307,6 @@ static bool edbm_bevel_init(bCon

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list