Made Add Surface Operator more atomic, now each primitive has own operator, but calli...
authorMichael Fox <mfoxdogg@gmail.com>
Sun, 13 Jun 2010 05:48:21 +0000 (05:48 +0000)
committerMichael Fox <mfoxdogg@gmail.com>
Sun, 13 Jun 2010 05:48:21 +0000 (05:48 +0000)
So they can me used in macros, and addons can use the menu  now, hope to see some very nice surface plugins

release/scripts/ui/space_info.py
source/blender/editors/curve/curve_intern.h
source/blender/editors/curve/curve_ops.c
source/blender/editors/curve/editcurve.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c

index d37190e..702dc97 100644 (file)
@@ -212,6 +212,19 @@ class INFO_MT_curve_add(bpy.types.Menu):
         layout.operator("curve.primitive_nurbs_circle_add", icon='CURVE_NCIRCLE', text="Nurbs Circle")
         layout.operator("curve.primitive_nurbs_path_add", icon='CURVE_PATH', text="Path")
 
+class INFO_MT_surface_add(bpy.types.Menu):
+    bl_idname = "INFO_MT_surface_add"
+    bl_label = "Surface"
+
+    def draw(self, context):
+        layout = self.layout
+        layout.operator_context = 'INVOKE_REGION_WIN'
+        layout.operator("surface.primitive_nurbs_surface_curve_add", icon='SURFACE_NCURVE', text="NURBS Curve")
+        layout.operator("surface.primitive_nurbs_surface_circle_add", icon='SURFACE_NCIRCLE', text="NURBS Circle")
+        layout.operator("surface.primitive_nurbs_surface_surface_add", icon='SURFACE_NSURFACE', text="NURBS Surface")
+        layout.operator("surface.primitive_nurbs_surface_tube_add", icon='SURFACE_NTUBE', text="NURBS Tube")
+        layout.operator("surface.primitive_nurbs_surface_sphere_add", icon='SURFACE_NSPHERE', text="NURBS Sphere")
+        layout.operator("surface.primitive_nurbs_surface_donut_add", icon='SURFACE_NDONUT', text="NURBS Torus")
 
 class INFO_MT_armature_add(bpy.types.Menu):
     bl_idname = "INFO_MT_armature_add"
@@ -236,7 +249,8 @@ class INFO_MT_add(bpy.types.Menu):
 
         #layout.operator_menu_enum("object.curve_add", "type", text="Curve", icon='OUTLINER_OB_CURVE')
         layout.menu("INFO_MT_curve_add", icon='OUTLINER_OB_CURVE')
-        layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
+        #layout.operator_menu_enum("object.surface_add", "type", text="Surface", icon='OUTLINER_OB_SURFACE')
+        layout.menu("INFO_MT_surface_add", icon='OUTLINER_OB_SURFACE')
         layout.operator_menu_enum("object.metaball_add", "type", text="Metaball", icon='OUTLINER_OB_META')
         layout.operator("object.text_add", text="Text", icon='OUTLINER_OB_FONT')
         layout.separator()
@@ -367,6 +381,7 @@ classes = [
     INFO_MT_add,
     INFO_MT_mesh_add,
     INFO_MT_curve_add,
+    INFO_MT_surface_add,
     INFO_MT_armature_add,
     INFO_MT_game,
     INFO_MT_render,
index ac0825a..dc07822 100644 (file)
@@ -91,6 +91,13 @@ void CURVE_OT_primitive_nurbs_curve_add(struct wmOperatorType *ot);
 void CURVE_OT_primitive_nurbs_circle_add(struct wmOperatorType *ot);
 void CURVE_OT_primitive_nurbs_path_add(struct wmOperatorType *ot);
 
+void SURFACE_OT_primitive_nurbs_surface_curve_add(struct wmOperatorType *ot);
+void SURFACE_OT_primitive_nurbs_surface_circle_add(struct wmOperatorType *ot);
+void SURFACE_OT_primitive_nurbs_surface_surface_add(struct wmOperatorType *ot);
+void SURFACE_OT_primitive_nurbs_surface_tube_add(struct wmOperatorType *ot);
+void SURFACE_OT_primitive_nurbs_surface_sphere_add(struct wmOperatorType *ot);
+void SURFACE_OT_primitive_nurbs_surface_donut_add(struct wmOperatorType *ot);
+
 void CURVE_OT_de_select_first(struct wmOperatorType *ot);
 void CURVE_OT_de_select_last(struct wmOperatorType *ot);
 void CURVE_OT_select_all(struct wmOperatorType *ot);
index 59e4490..7586023 100644 (file)
@@ -102,7 +102,14 @@ void ED_operatortypes_curve(void)
        WM_operatortype_append(CURVE_OT_primitive_nurbs_curve_add);
        WM_operatortype_append(CURVE_OT_primitive_nurbs_circle_add);
        WM_operatortype_append(CURVE_OT_primitive_nurbs_path_add);
-
+       
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_curve_add);
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_circle_add);
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_surface_add);
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_tube_add);
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_sphere_add);
+       WM_operatortype_append(SURFACE_OT_primitive_nurbs_surface_donut_add);
+       
        WM_operatortype_append(CURVE_OT_smooth);
        WM_operatortype_append(CURVE_OT_smooth_radius);
 
index 274b51f..40cf95d 100644 (file)
@@ -5281,8 +5281,13 @@ static int curve_prim_add(bContext *C, wmOperator *op, int type){
                if(type & CU_PRIM_PATH)
                        cu->flag |= CU_PATH|CU_3D;
        }
+       else if(obedit==NULL || obedit->type!=OB_SURF) {
+               obedit= ED_object_add_type(C, OB_SURF, loc, rot, TRUE, layer);
+               newob = 1;
+       }
        else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
        
+       
        ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
        
        nu= add_nurbs_primitive(C, mat, type, newob);
@@ -5298,6 +5303,7 @@ static int curve_prim_add(bContext *C, wmOperator *op, int type){
        
        return OPERATOR_FINISHED;
 }
+/* ******************** Curves ******************* */
 
 static int add_primitive_bezier_exec(bContext *C, wmOperator *op)
 {
@@ -5414,7 +5420,144 @@ void CURVE_OT_primitive_nurbs_path_add(wmOperatorType *ot)
        ED_object_add_generic_props(ot, TRUE);
 }
 
+/* **************** NURBS surfaces ********************** */
+static int add_primitive_nurbs_surface_curve_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_CURVE|CU_NURBS);
+}
 
+void SURFACE_OT_primitive_nurbs_surface_curve_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Curve";
+       ot->description= "Construct a Nurbs surface Curve";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_curve_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_curve_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_nurbs_surface_circle_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_CIRCLE|CU_NURBS);
+}
+
+void SURFACE_OT_primitive_nurbs_surface_circle_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Circle";
+       ot->description= "Construct a Nurbs surface Circle";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_circle_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_circle_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_nurbs_surface_surface_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_PATCH|CU_NURBS);
+}
+
+void SURFACE_OT_primitive_nurbs_surface_surface_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Patch";
+       ot->description= "Construct a Nurbs surface Patch";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_surface_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_surface_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_nurbs_surface_tube_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_TUBE|CU_NURBS);
+}
+
+void SURFACE_OT_primitive_nurbs_surface_tube_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Tube";
+       ot->description= "Construct a Nurbs surface Tube";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_tube_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_tube_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_nurbs_surface_sphere_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_SPHERE|CU_NURBS);
+}
+
+void SURFACE_OT_primitive_nurbs_surface_sphere_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Sphere";
+       ot->description= "Construct a Nurbs surface Sphere";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_sphere_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_sphere_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
+
+static int add_primitive_nurbs_surface_donut_exec(bContext *C, wmOperator *op)
+{
+       return curve_prim_add(C, op, CU_PRIM_DONUT|CU_NURBS);
+}
+
+void SURFACE_OT_primitive_nurbs_surface_donut_add(wmOperatorType *ot)
+{
+       /* identifiers */
+       ot->name= "Add Surface Donut";
+       ot->description= "Construct a Nurbs surface Donut";
+       ot->idname= "SURFACE_OT_primitive_nurbs_surface_donut_add";
+       
+       /* api callbacks */
+       ot->invoke= ED_object_add_generic_invoke;
+       ot->exec= add_primitive_nurbs_surface_donut_exec;
+       ot->poll= ED_operator_scene_editable;
+       
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       ED_object_add_generic_props(ot, TRUE);
+}
 
 /***************** clear tilt operator ********************/
 
index c6164fe..8bd0da3 100644 (file)
@@ -106,7 +106,6 @@ void OBJECT_OT_select_same_group(struct wmOperatorType *ot);
 /* object_add.c */
 void OBJECT_OT_add(struct wmOperatorType *ot);
 void OBJECT_OT_add_named(struct wmOperatorType *ot);
-void OBJECT_OT_surface_add(struct wmOperatorType *ot);
 void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
 void OBJECT_OT_text_add(struct wmOperatorType *ot);
 void OBJECT_OT_armature_add(struct wmOperatorType *ot);
index 09fcd94..6aeaf00 100644 (file)
@@ -113,7 +113,6 @@ void ED_operatortypes_object(void)
 
        WM_operatortype_append(OBJECT_OT_delete);
        WM_operatortype_append(OBJECT_OT_text_add);
-       WM_operatortype_append(OBJECT_OT_surface_add);
        WM_operatortype_append(OBJECT_OT_armature_add);
        WM_operatortype_append(OBJECT_OT_lamp_add);
        WM_operatortype_append(OBJECT_OT_camera_add);