2.5
authorTon Roosendaal <ton@blender.org>
Fri, 26 Jun 2009 15:48:09 +0000 (15:48 +0000)
committerTon Roosendaal <ton@blender.org>
Fri, 26 Jun 2009 15:48:09 +0000 (15:48 +0000)
Part one (of probably many :) of Operator review/validation.
Nothing final nor defined, it's reseach :)

- Added tool buttons in "Toolbar" (Tkey). Just four examples
  for objectmode, and six for mesh editmode.

(Review in progress is operator internal state vs context, what
do redo exactly, undo vs redo syncing, when op->invoke or not,
etc. This has to be pinned down exactly and frozen asap)

- On undo, clear redo-operator-stack for now (won't work)
- Added call to better detect active/current view3d region.
  ED_view3d_context_rv3d(C)
- Fixed some operators that missed correct redo (add-prim etc).

Later more fun!

12 files changed:
source/blender/editors/include/ED_object.h
source/blender/editors/include/ED_view3d.h
source/blender/editors/interface/interface_panel.c
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/mesh/editmesh_mods.c
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/object/object_edit.c
source/blender/editors/space_view3d/space_view3d.c
source/blender/editors/space_view3d/view3d_toolbar.c
source/blender/editors/util/undo.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm.c

index bfa819632c9fc22831bc4ebd267ed5bee3a45195..e4e4b1d048699376ba1efcfdd605fe472b6fcc71 100644 (file)
@@ -63,6 +63,7 @@ struct Base *ED_object_add_duplicate(struct Scene *scene, struct Base *base, int
 #define EM_FREEDATA            1
 #define EM_FREEUNDO            2
 #define EM_WAITCURSOR  4
+#define EM_DO_UNDO             8
 void ED_object_exit_editmode(struct bContext *C, int flag);
 void ED_object_enter_editmode(struct bContext *C, int flag);
 
index 38e52a8f59cfddc184cbfbbf335e42682c562567..b576299c1d07f511ae7b0ab21a5328f28b535a83 100644 (file)
@@ -132,6 +132,8 @@ int lasso_inside_edge(short mcords[][2], short moves, int x0, int y0, int x1, in
 
 /* modes */
 void ED_view3d_exit_paint_modes(struct bContext *C);
+/* get 3d region from context, also if mouse is in header or toolbar */
+struct RegionView3D *ED_view3d_context_rv3d(struct bContext *C);
 
 #endif /* ED_VIEW3D_H */
 
index 72076175ad5707a5833d4e4cc2744ab8f19036f4..06dc5d1e606a74861b78ee005146a4d67a2768d7 100644 (file)
@@ -104,7 +104,7 @@ static int panel_aligned(ScrArea *sa, ARegion *ar)
                SpaceButs *sbuts= sa->spacedata.first;
                return sbuts->align;
        }
-       else if(ar->regiontype==RGN_TYPE_UI)
+       else if(ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_TOOLS))
                return BUT_VERTICAL;
        
        return 0;
index 57fb2c19c75c5b606271383645318c3a0a596a53..8483aee52f48b9f0942724f851fac8b04d1bbf3b 100644 (file)
@@ -1276,7 +1276,7 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
        Object *obedit= CTX_data_edit_object(C);
        Scene *scene = CTX_data_scene(C);
        View3D *v3d =CTX_wm_view3d(C);
-       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
        float *curs, mat[3][3], vmat[3][3], cmat[3][3], imat[3][3];
        
        Mat4One(primmat);
index 7e9fcb10984ff8e3c09e4028ed7cc13be57ec019..70a0c6b82da91a77e926b49eb4d2515b8377c363 100644 (file)
@@ -3242,7 +3242,7 @@ static int toggle_select_all_exec(bContext *C, wmOperator *op)
 void MESH_OT_select_all_toggle(wmOperatorType *ot)
 {
        /* identifiers */
-       ot->name= "Select or Deselect All";
+       ot->name= "Select/Deselect All";
        ot->idname= "MESH_OT_select_all_toggle";
        
        /* api callbacks */
index b26fded4fb64a34a07196fa5a4119944f30f30fb..dc9c8c6b6d2a71e8fac4c49e568424d7b6c5c1b5 100644 (file)
@@ -787,7 +787,7 @@ static int extrude_repeat_mesh(bContext *C, wmOperator *op)
        Object *obedit= CTX_data_edit_object(C);
        EditMesh *em= BKE_mesh_get_editmesh((Mesh *)obedit->data);
 
-       RegionView3D *rv3d = CTX_wm_region_view3d(C);           
+       RegionView3D *rv3d = ED_view3d_context_rv3d(C);         
                
        int steps = RNA_int_get(op->ptr,"steps");
        
@@ -949,7 +949,7 @@ static int spin_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
-       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
        
        RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
        RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[2]);
@@ -1056,7 +1056,7 @@ static int screw_mesh_invoke(bContext *C, wmOperator *op, wmEvent *event)
 {
        Scene *scene = CTX_data_scene(C);
        View3D *v3d = CTX_wm_view3d(C);
-       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       RegionView3D *rv3d= ED_view3d_context_rv3d(C);
        
        RNA_float_set_array(op->ptr, "center", give_cursor(scene, v3d));
        RNA_float_set_array(op->ptr, "axis", rv3d->viewinv[1]);
index 7a75e3875ea10c48956d13e52c415c5e52e024ed..8102b1bfb9ca3ed934af41b694b9f70490085ba3 100644 (file)
@@ -340,7 +340,7 @@ static int object_add_mesh_exec(bContext *C, wmOperator *op)
        
        if(obedit==NULL || obedit->type!=OB_MESH) {
                object_add_type(C, OB_MESH);
-               ED_object_enter_editmode(C, 0);
+               ED_object_enter_editmode(C, EM_DO_UNDO);
                newob = 1;
        }
        else DAG_object_flush_update(CTX_data_scene(C), obedit, OB_RECALC_DATA);
@@ -398,8 +398,8 @@ void OBJECT_OT_mesh_add(wmOperatorType *ot)
        
        ot->poll= ED_operator_scene_editable;
        
-       /* flags */
-       ot->flag= 0;
+       /* flags: no register or undo, this operator calls operators */
+       ot->flag= 0; //OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_enum(ot->srna, "type", prop_mesh_types, 0, "Primitive", "");
 }
@@ -1395,7 +1395,8 @@ static int parent_clear_exec(bContext *C, wmOperator *op)
        
        DAG_scene_sort(CTX_data_scene(C));
        ED_anim_dag_flush_update(C);
-       
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
+
        return OPERATOR_FINISHED;
 }
 
@@ -2600,7 +2601,8 @@ static int parent_set_exec(bContext *C, wmOperator *op)
        CTX_DATA_END;
        
        DAG_scene_sort(CTX_data_scene(C));
-       ED_anim_dag_flush_update(C);    
+       ED_anim_dag_flush_update(C);
+       WM_event_add_notifier(C, NC_OBJECT|ND_TRANSFORM, NULL);
        
        return OPERATOR_FINISHED;
 }
@@ -2648,7 +2650,7 @@ void OBJECT_OT_parent_set(wmOperatorType *ot)
        ot->poll= ED_operator_object_active;
        
        /* flags */
-       ot->flag= 0;
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        RNA_def_enum(ot->srna, "type", prop_make_parent_types, 0, "Type", "");
 }
@@ -3349,6 +3351,7 @@ void ED_object_enter_editmode(bContext *C, int flag)
                WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, scene);
        }
        
+       if(flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
        if(flag & EM_WAITCURSOR) waitcursor(0);
 }
 
index 2d6a57d5a34673d6c098ec1a8f1aa085fa0827e6..625b1838951ae950a801dbd3125dfdbedd15e20a 100644 (file)
@@ -122,6 +122,24 @@ ARegion *view3d_has_tools_region(ScrArea *sa)
        return arnew;
 }
 
+/* ****************************************************** */
+
+/* function to always find a regionview3d context inside 3D window */
+RegionView3D *ED_view3d_context_rv3d(bContext *C)
+{
+       RegionView3D *rv3d= CTX_wm_region_view3d(C);
+       
+       if(rv3d==NULL) {
+               ScrArea *sa =CTX_wm_area(C);
+               if(sa->spacetype==SPACE_VIEW3D) {
+                       ARegion *ar;
+                       for(ar= sa->regionbase.first; ar; ar= ar->next)
+                               if(ar->regiontype==RGN_TYPE_WINDOW)
+                                       return ar->regiondata;
+               }
+       }
+       return rv3d;
+}
 
 
 /* ******************** default callbacks for view3d space ***************** */
index 15254ba505edfe958c6a76c47dba6a1c7bdd1018..88af60ac0f489e864d56074efc76edfc96a48851 100644 (file)
@@ -134,7 +134,7 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
        
        if(op==NULL)
                return;
-       if(op->type->poll && op->type->poll(C)==0)
+       if(op->type->poll && op->type->poll((bContext *)C)==0)
                return;
        
        uiBlockSetFunc(block, redo_cb, op, NULL);
@@ -148,10 +148,59 @@ static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
        uiDefAutoButsRNA(C, pa->layout, &ptr, 1);
 }
 
+static void view3d_panel_tools(const bContext *C, Panel *pa)
+{
+       Object *obedit= CTX_data_edit_object(C);
+//     Object *obact = CTX_data_active_object(C);
+       uiLayout *col;
+       
+       if(obedit) {
+               if(obedit->type==OB_MESH) {
+                       
+                       // void uiItemFullO(uiLayout *layout, char *name, int icon, char *idname, IDProperty *properties, int context)
+                       col= uiLayoutColumn(pa->layout, 1);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_delete", NULL, WM_OP_INVOKE_REGION_WIN);
+                       
+                       col= uiLayoutColumn(pa->layout, 1);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_subdivide", NULL, WM_OP_INVOKE_REGION_WIN);
+                       
+                       col= uiLayoutColumn(pa->layout, 1);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_primitive_monkey_add", NULL, WM_OP_INVOKE_REGION_WIN);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_primitive_uv_sphere_add", NULL, WM_OP_INVOKE_REGION_WIN);
+                       
+                       col= uiLayoutColumn(pa->layout, 1);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_select_all_toggle", NULL, WM_OP_INVOKE_REGION_WIN);
+                       
+                       col= uiLayoutColumn(pa->layout, 1);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_spin", NULL, WM_OP_INVOKE_REGION_WIN);
+                       uiItemFullO(col, NULL, 0, "MESH_OT_screw", NULL, WM_OP_INVOKE_REGION_WIN);
+                       
+               }
+       }
+       else {
+               
+               col= uiLayoutColumn(pa->layout, 1);
+               uiItemFullO(col, NULL, 0, "OBJECT_OT_delete", NULL, WM_OP_INVOKE_REGION_WIN);
+               uiItemFullO(col, NULL, 0, "OBJECT_OT_primitive_add", NULL, WM_OP_INVOKE_REGION_WIN);
+               
+               col= uiLayoutColumn(pa->layout, 1);
+               uiItemFullO(col, NULL, 0, "OBJECT_OT_parent_set", NULL, WM_OP_INVOKE_REGION_WIN);
+               uiItemFullO(col, NULL, 0, "OBJECT_OT_parent_clear", NULL, WM_OP_INVOKE_REGION_WIN);
+               
+       }
+}
+
+
 void view3d_toolbar_register(ARegionType *art)
 {
        PanelType *pt;
 
+       pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel tools");
+       strcpy(pt->idname, "VIEW3D_PT_tools");
+       strcpy(pt->label, "Tools");
+       pt->draw= view3d_panel_tools;
+       BLI_addtail(&art->paneltypes, pt);
+       
        pt= MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator");
        strcpy(pt->idname, "VIEW3D_PT_last_operator");
        strcpy(pt->label, "Last Operator");
index 62ce76a7614cce8549e2bc7c5a52d932438bc149..1d79c542fa91400c534c8ba6e1e05af2e8e2f9de 100644 (file)
@@ -183,6 +183,8 @@ void ED_undo_redo(bContext *C)
 
 static int ed_undo_exec(bContext *C, wmOperator *op)
 {
+       /* "last operator" should disappear, later we can tie ths with undo stack nicer */
+       WM_operator_stack_clear(C);
        return ed_undo_step(C, 1);
 }
 static int ed_redo_exec(bContext *C, wmOperator *op)
index 7acb2921bec39001b613f2c684d477ead67cf57f..92b71e9fff0068ecbae94ced32d1835edf3610d8 100644 (file)
@@ -129,6 +129,8 @@ int                 WM_operator_redo_popup  (struct bContext *C, struct wmOperator *op);
 
                /* operator api */
 void           WM_operator_free                (struct wmOperator *op);
+void           WM_operator_stack_clear(struct bContext *C);
+
 wmOperatorType *WM_operatortype_find(const char *idname);
 wmOperatorType *WM_operatortype_first(void);
 void           WM_operatortype_append  (void (*opfunc)(wmOperatorType*));
@@ -212,8 +214,8 @@ void                WM_jobs_stop(struct wmWindowManager *wm, void *owner);
 void           WM_jobs_stop_all(struct wmWindowManager *wm);
 
                        /* clipboard */
-char *WM_clipboard_text_get(int selection);
-void WM_clipboard_text_set(char *buf, int selection);
+char           *WM_clipboard_text_get(int selection);
+void           WM_clipboard_text_set(char *buf, int selection);
 
 
 #endif /* WM_API_H */
index 37fdc9fa2c5ff63a87713a238e99aee84df73b80..7dec14664ae1576433eb1e3516aafb70cff7b90e 100644 (file)
@@ -95,6 +95,18 @@ void wm_operator_register(wmWindowManager *wm, wmOperator *op)
 }
 
 
+void WM_operator_stack_clear(bContext *C)
+{
+       wmWindowManager *wm= CTX_wm_manager(C);
+       wmOperator *op;
+       
+       while((op= wm->operators.first)) {
+               BLI_remlink(&wm->operators, op);
+               WM_operator_free(op);
+       }
+       
+}
+
 /* ****************************************** */
 
 void wm_check(bContext *C)