- add torus back from 2.4x as an operator
authorCampbell Barton <ideasman42@gmail.com>
Sat, 10 Oct 2009 21:23:20 +0000 (21:23 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Sat, 10 Oct 2009 21:23:20 +0000 (21:23 +0000)
  bpy.ops.mesh.primitive_torus_add(major_radius=1, minor_radius=0.25, major_segments=48, minor_segments=16)

- experemental dynamic menus, used for INFO_MT_file, INFO_MT_file_import, INFO_MT_file_export and INFO_MT_mesh_add. these can have items added from python.
eg.

- removed OBJECT_OT_mesh_add, use the python add menu instead.

- made mesh primitive ops -  MESH_OT_primitive_plane_add, ...cube_add, etc. work in object mode.

- RNA scene.active_object wrapped

- bugfix [#19466] 2.5: Tweak menu only available for mesh objects added within Edit Mode
  ED_object_exit_editmode was always doing an undo push, made this optional using the existing flag - EM_DO_UNDO, called everywhere except when adding primitives.

26 files changed:
release/scripts/io/add_mesh_torus.py [new file with mode: 0644]
release/scripts/io/export_3ds.py
release/scripts/io/export_fbx.py
release/scripts/io/export_mdd.py
release/scripts/io/export_obj.py
release/scripts/io/export_ply.py
release/scripts/io/export_x3d.py
release/scripts/io/import_3ds.py
release/scripts/io/import_obj.py
release/scripts/modules/dynamic_menu.py [new file with mode: 0644]
release/scripts/ui/space_info.py
source/blender/editors/curve/editcurve.c
source/blender/editors/include/ED_object.h
source/blender/editors/mesh/editmesh_add.c
source/blender/editors/mesh/mesh_ops.c
source/blender/editors/mesh/meshtools.c
source/blender/editors/object/object_add.c
source/blender/editors/object/object_edit.c
source/blender/editors/object/object_intern.h
source/blender/editors/object/object_ops.c
source/blender/editors/screen/screen_ops.c
source/blender/editors/space_outliner/outliner.c
source/blender/makesrna/intern/rna_scene.c
source/blender/makesrna/intern/rna_texture.c
source/blender/python/intern/bpy_operator_wrap.c
source/blender/windowmanager/intern/wm_files.c

diff --git a/release/scripts/io/add_mesh_torus.py b/release/scripts/io/add_mesh_torus.py
new file mode 100644 (file)
index 0000000..a0f41db
--- /dev/null
@@ -0,0 +1,98 @@
+
+import bpy, Mathutils
+from math import cos, sin, pi, radians
+
+
+def add_torus(PREF_MAJOR_RAD, PREF_MINOR_RAD, PREF_MAJOR_SEG, PREF_MINOR_SEG):
+       Vector = Mathutils.Vector
+       Quaternion = Mathutils.Quaternion
+       
+       PI_2= pi*2
+       Z_AXIS = 0,0,1
+       
+       verts = []
+       faces = []
+       i1 = 0
+       tot_verts = PREF_MAJOR_SEG * PREF_MINOR_SEG
+       for major_index in range(PREF_MAJOR_SEG):
+               verts_tmp = []
+               quat = Quaternion( Z_AXIS, (major_index/PREF_MAJOR_SEG)*PI_2)
+
+               for minor_index in range(PREF_MINOR_SEG):
+                       angle = 2*pi*minor_index/PREF_MINOR_SEG
+                       
+                       vec = Vector(PREF_MAJOR_RAD+(cos(angle)*PREF_MINOR_RAD), 0, (sin(angle)*PREF_MINOR_RAD)) * quat
+                       verts.extend([vec.x, vec.y, vec.z])
+                       
+                       if minor_index+1==PREF_MINOR_SEG:
+                               i2 = (major_index)*PREF_MINOR_SEG
+                               i3 = i1 + PREF_MINOR_SEG
+                               i4 = i2 + PREF_MINOR_SEG
+                               
+                       else:
+                               i2 = i1 + 1
+                               i3 = i1 + PREF_MINOR_SEG
+                               i4 = i3 + 1
+                       
+                       if i2>=tot_verts:       i2 = i2-tot_verts
+                       if i3>=tot_verts:       i3 = i3-tot_verts
+                       if i4>=tot_verts:       i4 = i4-tot_verts
+                       
+                       # stupid eekadoodle
+                       if i2:  faces.extend( [i1,i3,i4,i2] )
+                       else:   faces.extend( [i2,i1,i3,i4] )
+                               
+                       i1+=1
+       
+       return verts, faces
+
+
+class MESH_OT_primitive_torus_add(bpy.types.Operator):
+       '''Add a torus mesh.'''
+       __idname__ = "mesh.primitive_torus_add"
+       __label__ = "Add Torus"
+       __register__ = True
+       __undo__ = True
+       __props__ = [
+               bpy.props.FloatProperty(attr="major_radius", name="Major Radius", description="Number of segments for the main ring of the torus", default= 1.0, min= 0.01, max= 100.0),
+               bpy.props.FloatProperty(attr="minor_radius", name="Minor Radius", description="Number of segments for the minor ring of the torus", default= 0.25, min= 0.01, max= 100.0),
+               bpy.props.IntProperty(attr="major_segments", name="Major Segments", description="Number of segments for the main ring of the torus", default= 48, min= 3, max= 256),
+               bpy.props.IntProperty(attr="minor_segments", name="Minor Segments", description="Number of segments for the minor ring of the torus", default= 16, min= 3, max= 256),
+       ]
+       
+       def execute(self, context):
+               verts_loc, faces = add_torus(self.major_radius, self.minor_radius, self.major_segments, self.minor_segments)
+               
+               me= bpy.data.add_mesh("Torus")
+               
+               me.add_geometry(int(len(verts_loc)/3), 0, int(len(faces)/4))
+               me.verts.foreach_set("co", verts_loc)
+               me.faces.foreach_set("verts_raw", faces)
+               
+               sce = context.scene
+               
+               # ugh
+               for ob in sce.objects:
+                       ob.selected = False
+               
+               me.update()
+               ob= bpy.data.add_object('MESH', "Torus")
+               ob.data= me
+               context.scene.add_object(ob)
+               context.scene.active_object = ob
+               ob.selected = True
+               
+               ob.location = tuple(context.scene.cursor_location)
+               
+               return ('FINISHED',)
+
+# Register the operator
+bpy.ops.add(MESH_OT_primitive_torus_add)
+
+# Add to a menu
+import dynamic_menu
+import space_info
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_mesh_add, (lambda self, context: self.layout.itemO("mesh.primitive_torus_add", text="Add Torus")) )
+
+if __name__ == "__main__":
+       bpy.ops.mesh.primitive_torus_add()
\ No newline at end of file
index 2c1999c..5ca7d56 100644 (file)
@@ -1,12 +1,4 @@
-#!BPY
 # coding: utf-8
-""" 
-Name: '3D Studio (.3ds)...'
-Blender: 243
-Group: 'Export'
-Tooltip: 'Export to 3DS file format (.3ds).'
-"""
-
 __author__ = ["Campbell Barton", "Bob Holcomb", "Richard Lärkäng", "Damien McGinnes", "Mark Stijnman"]
 __url__ = ("blenderartists.org", "www.blender.org", "www.gametutorials.com", "lib3ds.sourceforge.net/")
 __version__ = "0.90a"
@@ -1100,9 +1092,7 @@ def save_3ds(filename, context):
 # # save_3ds('/test_b.3ds')
 
 class EXPORT_OT_3ds(bpy.types.Operator):
-       '''
-       3DS Exporter
-       '''
+       '''Export to 3DS file format (.3ds).'''
        __idname__ = "export.3ds"
        __label__ = 'Export 3DS'
        
@@ -1128,3 +1118,8 @@ class EXPORT_OT_3ds(bpy.types.Operator):
                return context.active_object != None
 
 bpy.ops.add(EXPORT_OT_3ds)
+
+# Add to a menu
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.3ds", text="Autodesk 3DS...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
index 21b1388..d159c65 100644 (file)
@@ -1,10 +1,3 @@
-#!BPY
-"""
-Name: 'Autodesk FBX (.fbx)...'
-Blender: 249
-Group: 'Export'
-Tooltip: 'Selection to an ASCII Autodesk FBX '
-"""
 __author__ = "Campbell Barton"
 __url__ = ['www.blender.org', 'blenderartists.org']
 __version__ = "1.2"
@@ -3341,9 +3334,7 @@ def write_ui():
        # GLOBALS.clear()
 
 class EXPORT_OT_fbx(bpy.types.Operator):
-       '''
-       Operator documentation text, will be used for the operator tooltip and python docs.
-       '''
+       '''Selection to an ASCII Autodesk FBX'''
        __idname__ = "export.fbx"
        __label__ = "Export FBX"
        
@@ -3451,3 +3442,10 @@ bpy.ops.add(EXPORT_OT_fbx)
 
 # SMALL or COSMETICAL
 # - find a way to get blender version, and put it in bpy.util?, old was Blender.Get('version')
+
+
+# Add to a menu
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.fbx", text="Autodesk FBX...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
index f0e366e..1336660 100644 (file)
@@ -1,11 +1,3 @@
-#!BPY
-
-"""
- Name: 'Vertex Keyframe Animation (.mdd)...'
- Blender: 242
- Group: 'Export'
- Tooltip: 'Animated mesh to MDD vertex keyframe file.'
-"""
 
 __author__ = "Bill L.Nieuwendorp"
 __bpydoc__ = """\
@@ -180,9 +172,13 @@ class EXPORT_OT_mdd(bpy.types.Operator):
 
 bpy.ops.add(EXPORT_OT_mdd)
 
+# Add to a menu
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.mdd", text="Vertex Keyframe Animation (.mdd)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
 if __name__=='__main__':
        #if not pack:
 #              Draw.PupMenu('Error%t|This script requires a full python install')
        #Blender.Window.FileSelector(mdd_export_ui, 'EXPORT MDD', sys.makename(ext='.mdd'))
        bpy.ops.EXPORT_OT_mdd(path="/tmp/test.mdd")
-
index 83b4008..1e8a152 100644 (file)
@@ -906,14 +906,16 @@ def do_export(filename, context,
 #      orig_scene.makeCurrent()
 #      Window.WaitCursor(0)
 
-
+       
+'''
+Currently the exporter lacks these features:
+* nurbs
+* multiple scene export (only active scene is written)
+* particles
+'''
 class EXPORT_OT_obj(bpy.types.Operator):
-       '''
-       Currently the exporter lacks these features:
-       * nurbs
-       * multiple scene export (only active scene is written)
-       * particles
-       '''
+       '''Save a Wavefront OBJ File'''
+       
        __idname__ = "export.obj"
        __label__ = 'Export OBJ'
        
@@ -984,6 +986,10 @@ class EXPORT_OT_obj(bpy.types.Operator):
 
 bpy.ops.add(EXPORT_OT_obj)
 
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.obj", text="Wavefront (.obj)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
 if __name__ == "__main__":
        bpy.ops.EXPORT_OT_obj(filename="/tmp/test.obj")
 
index 8e79c37..d74cc0e 100644 (file)
@@ -273,7 +273,9 @@ class EXPORT_OT_ply(bpy.types.Operator):
 
 bpy.ops.add(EXPORT_OT_ply)
 
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.ply", text="Stanford (.ply)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
 if __name__ == "__main__":
        bpy.ops.EXPORT_OT_ply(path="/tmp/test.ply")
-
-
index db29afc..2c6ca74 100644 (file)
@@ -1,10 +1,3 @@
-#!BPY
-""" Registration info for Blender menus:
-Name: 'X3D Extensible 3D (.x3d)...'
-Blender: 245
-Group: 'Export'
-Tooltip: 'Export selection to Extensible 3D file (.x3d)'
-"""
 
 __author__ = ("Bart", "Campbell Barton")
 __email__ = ["Bart, bart:neeneenee*de"]
@@ -1204,9 +1197,7 @@ def x3d_export_ui(filename):
 #      Blender.Window.FileSelector(x3d_export_ui,"Export X3D", Blender.Get('filename').replace('.blend', '.x3d'))
 
 class EXPORT_OT_x3d(bpy.types.Operator):
-       '''
-       X3D Exporter
-       '''
+       '''Export selection to Extensible 3D file (.x3d)'''
        __idname__ = "export.x3d"
        __label__ = 'Export X3D'
        
@@ -1229,12 +1220,12 @@ class EXPORT_OT_x3d(bpy.types.Operator):
                wm = context.manager
                wm.add_fileselect(self.__operator__)
                return ('RUNNING_MODAL',)
-       
-       def poll(self, context): # Poll isnt working yet
-               print("Poll")
-               return context.active_object != None
 
 bpy.ops.add(EXPORT_OT_x3d)
 
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("export.x3d", text="X3D Extensible 3D (.x3d)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_export, menu_func)
+
 # NOTES
 # - blender version is hardcoded 
index 339fac8..cbd9d89 100644 (file)
@@ -1,10 +1,3 @@
-#!BPY
-""" 
-Name: '3D Studio (.3ds)...'
-Blender: 244
-Group: 'Import'
-Tooltip: 'Import from 3DS file format (.3ds)'
-"""
 
 __author__= ['Bob Holcomb', 'Richard L?rk?ng', 'Damien McGinnes', 'Campbell Barton', 'Mario Lapin']
 __url__ = ("blenderartists.org", "www.blender.org", "www.gametutorials.com", "lib3ds.sourceforge.net/")
@@ -1130,9 +1123,7 @@ else:
 '''
 
 class IMPORT_OT_3ds(bpy.types.Operator):
-       '''
-       3DS Importer
-       '''
+       '''Import from 3DS file format (.3ds)'''
        __idname__ = "import.3ds"
        __label__ = 'Import 3DS'
        
@@ -1155,13 +1146,13 @@ class IMPORT_OT_3ds(bpy.types.Operator):
                wm = context.manager
                wm.add_fileselect(self.__operator__)
                return ('RUNNING_MODAL',)
-       '''
-       def poll(self, context):
-               print("Poll")
-               return context.active_object != None'''
 
 bpy.ops.add(IMPORT_OT_3ds)
 
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("import.3ds", text="3D Studio (.3ds)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_func)
+
 # NOTES:
 # why add 1 extra vertex? and remove it when done?
 # disabled scaling to size, this requires exposing bb (easy) and understanding how it works (needs some time)
index a762005..a557e44 100644 (file)
@@ -1,11 +1,3 @@
-#!BPY
-"""
-Name: 'Wavefront (.obj)...'
-Blender: 249
-Group: 'Import'
-Tooltip: 'Load a Wavefront OBJ File, Shift: batch import all dir.'
-"""
 
 __author__= "Campbell Barton", "Jiri Hnidek", "Paolo Ciccone"
 __url__= ['http://wiki.blender.org/index.php/Scripts/Manual/Import/wavefront_obj', 'blender.org', 'blenderartists.org']
@@ -1560,15 +1552,9 @@ else:
 
        print 'TOTAL TIME: %.6f' % (sys.time() - TIME)
 '''
-#load_obj('/test.obj')
-#load_obj('/fe/obj/mba1.obj')
-
-
 
 class IMPORT_OT_obj(bpy.types.Operator):
-       '''
-       Operator documentation text, will be used for the operator tooltip and python docs.
-       '''
+       '''Load a Wavefront OBJ File.'''
        __idname__ = "import.obj"
        __label__ = "Import OBJ"
        
@@ -1593,10 +1579,6 @@ class IMPORT_OT_obj(bpy.types.Operator):
                bpy.props.BoolProperty(attr="IMAGE_SEARCH", name="Image Search", description="Search subdirs for any assosiated images (Warning, may be slow)", default= True),
        ]
        
-       '''
-       def poll(self, context):
-               return True '''
-       
        def execute(self, context):
                # print("Selected: " + context.active_object.name)
 
@@ -1624,6 +1606,11 @@ class IMPORT_OT_obj(bpy.types.Operator):
 bpy.ops.add(IMPORT_OT_obj)
 
 
+import dynamic_menu
+menu_func = lambda self, context: self.layout.itemO("import.obj", text="Wavefront (.obj)...")
+menu_item = dynamic_menu.add(bpy.types.INFO_MT_file_import, menu_func)
+
+
 # NOTES (all line numbers refer to 2.4x import_obj.py, not this file)
 # check later: line 489
 # can convert now: edge flags, edges: lines 508-528
diff --git a/release/scripts/modules/dynamic_menu.py b/release/scripts/modules/dynamic_menu.py
new file mode 100644 (file)
index 0000000..ce51dc9
--- /dev/null
@@ -0,0 +1,95 @@
+import bpy
+
+def collect_baseclasses(_class, bases):
+       
+       if _class is type or _class is object:
+               return bases
+       
+       bases.append(_class)
+       for _superclass in _class.__bases__:
+               collect_baseclasses(_superclass, bases)
+       
+       return bases
+
+def collect_subclasses(_class, subs):
+       
+       if _class is type or _class is object:
+               return subs
+       
+       subs.append(_class)
+       for _subclass in _class.__subclasses__():
+               collect_subclasses(_subclass, subs)
+       
+       return subs
+
+class DynMenu(bpy.types.Menu):
+       
+       def draw(self, context):
+               '''
+               This is a draw function that is used to call all subclasses draw functions
+               starting from the registered classes draw function and working down.
+               
+               DynMenu.setup() must be called first.
+               
+               Sort/group classes could be nice
+               '''
+               
+               subclass_ls = []
+               collect_subclasses(self.__class__, subclass_ls)
+               # print(subclass_ls)
+               
+               for subclass in subclass_ls:
+                       # print("drawwing", subclass) # , dir(subclass))
+                       subclass.internal_draw(self, context)
+                       # print("subclass.internal_draw", subclass.internal_draw)
+
+def setup(menu_class):
+       '''
+       Setup subclasses (not needed when self.add() is used)
+       '''
+       bases = collect_baseclasses(menu_class, [])
+       
+       # Incase 'DynMenu' isnt last
+       while bases[-1] is not DynMenu:
+               bases.pop()
+       bases.pop() # remove 'DynMenu'
+       
+       root_class = bases[-1] # this is the registered class
+       
+       for subclass in collect_subclasses(root_class, []):
+               #print(subclass)
+               
+               draw = getattr(subclass, 'draw', None)
+               if draw and not hasattr(subclass, 'internal_draw'):
+                       # print("replace", subclass, draw)
+                       try:
+                               del subclass.draw
+                       except:
+                               pass
+                       subclass.internal_draw = draw
+                       
+       root_class.draw = DynMenu.draw
+
+def add(menu_class, func):
+       '''
+       Add a single function directly without having to make a class
+       
+       important that the returned value should be stored in the module that called it.
+       '''
+       
+       newclass = type('<menuclass>', (menu_class,), {})
+       newclass.internal_draw = func
+       setup(menu_class)
+       return newclass
+
+'''
+# so we dont need to import this module
+DynMenu.setup = setup
+DynMenu.add = add
+
+# Only so we can access as bpy.types.
+# dont ever use this directly!
+bpy.types.register(DynMenu)
+'''
+
+
index 4ab9902..5a7a3b6 100644 (file)
@@ -1,6 +1,9 @@
 
 import bpy
 
+import dynamic_menu
+# reload(dynamic_menu)
+
 class INFO_HT_header(bpy.types.Header):
        __space_type__ = 'INFO'
 
@@ -36,8 +39,9 @@ class INFO_HT_header(bpy.types.Header):
                layout.template_running_jobs()
 
                layout.itemL(text=scene.statistics())
-                       
-class INFO_MT_file(bpy.types.Menu):
+
+
+class INFO_MT_file(dynamic_menu.DynMenu):
        __label__ = "File"
 
        def draw(self, context):
@@ -76,27 +80,31 @@ class INFO_MT_file(bpy.types.Menu):
                layout.operator_context = "EXEC_AREA"
                layout.itemO("wm.exit_blender", text="Quit")
 
-class INFO_MT_file_import(bpy.types.Menu):
-       __label__ = "Import"
+
+# test for expanding menus
+'''
+class INFO_MT_file_more(INFO_MT_file):
+       __label__ = "File"
 
        def draw(self, context):
                layout = self.layout
-               
-               layout.itemO("import.3ds", text="3DS")
-               layout.itemO("import.obj", text="OBJ")
 
-class INFO_MT_file_export(bpy.types.Menu):
-       __label__ = "Export"
+               layout.itemO("wm.read_homefile", text="TESTING ")
+
+dynamic_menu.setup(INFO_MT_file_more)
+'''
+
+class INFO_MT_file_import(dynamic_menu.DynMenu):
+       __label__ = "Import"
 
        def draw(self, context):
-               layout = self.layout
+               pass # dynamic menu
+
+class INFO_MT_file_export(dynamic_menu.DynMenu):
+       __label__ = "Export"
 
-               layout.itemO("export.3ds", text="3DS")
-               layout.itemO("export.fbx", text="FBX")
-               layout.itemO("export.obj", text="OBJ")
-               layout.itemO("export.mdd", text="MDD")
-               layout.itemO("export.ply", text="PLY")
-               layout.itemO("export.x3d", text="X3D")
+       def draw(self, context):
+               pass # dynamic menu
 
 class INFO_MT_file_external_data(bpy.types.Menu):
        __label__ = "External Data"
@@ -114,6 +122,23 @@ class INFO_MT_file_external_data(bpy.types.Menu):
                layout.itemO("file.report_missing_files")
                layout.itemO("file.find_missing_files")
 
+
+class INFO_MT_mesh_add(dynamic_menu.DynMenu):
+       __label__ = "Add Mesh"
+       def draw(self, context):
+               layout = self.layout
+               layout.operator_context = 'INVOKE_REGION_WIN'
+               layout.itemO("mesh.primitive_plane_add", icon='ICON_MESH_PLANE')
+               layout.itemO("mesh.primitive_cube_add", icon='ICON_MESH_CUBE')
+               layout.itemO("mesh.primitive_circle_add", icon='ICON_MESH_CIRCLE')
+               layout.itemO("mesh.primitive_uv_sphere_add", icon='ICON_MESH_UVSPHERE')
+               layout.itemO("mesh.primitive_ico_sphere_add", icon='ICON_MESH_ICOSPHERE')
+               layout.itemO("mesh.primitive_cylinder_add", icon='ICON_MESH_TUBE')
+               layout.itemO("mesh.primitive_cone_add", icon='ICON_MESH_CONE')
+               layout.itemS()
+               layout.itemO("mesh.primitive_grid_add", icon='ICON_MESH_GRID')
+               layout.itemO("mesh.primitive_monkey_add", icon='ICON_MESH_MONKEY')
+
 class INFO_MT_add(bpy.types.Menu):
        __label__ = "Add"
 
@@ -122,7 +147,9 @@ class INFO_MT_add(bpy.types.Menu):
 
                layout.operator_context = "EXEC_SCREEN"
 
-               layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
+               # layout.item_menu_enumO("object.mesh_add", "type", text="Mesh", icon='ICON_OUTLINER_OB_MESH')
+               layout.itemM("INFO_MT_mesh_add", icon='ICON_OUTLINER_OB_MESH')
+               
                layout.item_menu_enumO("object.curve_add", "type", text="Curve", icon='ICON_OUTLINER_OB_CURVE')
                layout.item_menu_enumO("object.surface_add", "type", text="Surface", icon='ICON_OUTLINER_OB_SURFACE')
                layout.item_menu_enumO("object.metaball_add", "type", 'META', text="Metaball", icon='ICON_OUTLINER_OB_META')
@@ -143,6 +170,10 @@ class INFO_MT_add(bpy.types.Menu):
                
                layout.item_menu_enumO("object.effector_add", "type", 'EMPTY', text="Force Field", icon='ICON_OUTLINER_OB_EMPTY')
 
+               layout.itemS()          
+               
+               layout.item_menu_enumO("object.group_instance_add", "type", text="Group Instance", icon='ICON_OUTLINER_OB_EMPTY')
+
 class INFO_MT_game(bpy.types.Menu):
        __label__ = "Game"
 
@@ -199,6 +230,7 @@ bpy.types.register(INFO_MT_file_import)
 bpy.types.register(INFO_MT_file_export)
 bpy.types.register(INFO_MT_file_external_data)
 bpy.types.register(INFO_MT_add)
+bpy.types.register(INFO_MT_mesh_add)
 bpy.types.register(INFO_MT_game)
 bpy.types.register(INFO_MT_render)
 bpy.types.register(INFO_MT_help)
index a18815d..061a827 100644 (file)
@@ -4681,7 +4681,7 @@ int join_curve_exec(bContext *C, wmOperator *op)
        DAG_scene_sort(scene);  // because we removed object(s), call before editmode!
        
        ED_object_enter_editmode(C, EM_WAITCURSOR);
-       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR);
+       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO);
 
        WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
 
index ec763fe..7ea882b 100644 (file)
@@ -70,6 +70,7 @@ void ED_object_exit_editmode(struct bContext *C, int flag);
 void ED_object_enter_editmode(struct bContext *C, int flag);
 
 void ED_object_base_init_from_view(struct bContext *C, struct Base *base);
+struct Object *ED_object_add_type(struct bContext *C, int type);
 
 void ED_object_single_users(struct Scene *scene, int full);
 
index 4af5ddf..cb71765 100644 (file)
@@ -70,6 +70,7 @@
 #include "ED_transform.h"
 #include "ED_util.h"
 #include "ED_view3d.h"
+#include "ED_object.h"
 
 #include "mesh_intern.h"
 
@@ -1306,20 +1307,41 @@ static float new_primitive_matrix(bContext *C, float primmat[][4])
 
 /* ********* add primitive operators ************* */
 
-static int add_primitive_plane_exec(bContext *C, wmOperator *op)
+static void make_prim_ext(bContext *C, int type, int tot, int seg,
+               int subdiv, float dia, float depth, int ext, int fill)
 {
        Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       /* plane (diameter of 1.41 makes it unit size) */
-       dia*= sqrt(2.0f);
-       
-       make_prim(obedit, PRIM_PLANE, mat, 4, 0, 0, dia, 0.0f, 0, 1);
-       
+       int newob;
+       float mat[4][4];
+
+       if(obedit==NULL || obedit->type!=OB_MESH) {
+               /* create editmode */
+               ED_object_add_type(C, OB_MESH);
+               ED_object_enter_editmode(C, EM_DO_UNDO);
+               obedit= CTX_data_edit_object(C);
+               newob = 1;
+       }
+       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
+
+       dia *= new_primitive_matrix(C, mat);
+
+       make_prim(obedit, type, mat, tot, seg, subdiv, dia, depth, ext, fill);
+
        DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
        WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
+
+
+       /* userdef */
+       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
+               ED_object_exit_editmode(C, EM_FREEDATA); /* adding EM_DO_UNDO messes up operator redo */
+       }
+       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
+}
+
+static int add_primitive_plane_exec(bContext *C, wmOperator *op)
+{
+       /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
+       make_prim_ext(C, PRIM_PLANE, 4, 0, 0, sqrt(2.0f), 0.0f, 0, 1);
        return OPERATOR_FINISHED;       
 }
 
@@ -1332,7 +1354,7 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_plane_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1340,19 +1362,9 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot)
 
 static int add_primitive_cube_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       /* plane (diameter of 1.41 makes it unit size) */
-       dia*= sqrt(2.0f);
-       
-       make_prim(obedit, PRIM_CUBE, mat, 4, 0, 0, dia, 1.0f, 1, 1);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
-       return OPERATOR_FINISHED;       
+       /* sqrt(2.0f) - plane (diameter of 1.41 makes it unit size) */
+       make_prim_ext(C, PRIM_CUBE, 4, 0, 0, sqrt(2.0f), 1.0f, 1, 1);
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_cube_add(wmOperatorType *ot)
@@ -1364,7 +1376,7 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_cube_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1372,18 +1384,10 @@ void MESH_OT_primitive_cube_add(wmOperatorType *ot)
 
 static int add_primitive_circle_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia *= RNA_float_get(op->ptr,"radius");
-       
-       make_prim(obedit, PRIM_CIRCLE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 0.0f, 0, 
-                         RNA_boolean_get(op->ptr, "fill"));
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
+       make_prim_ext(C, PRIM_CIRCLE, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"), 0.0f, 0,
+                       RNA_boolean_get(op->ptr, "fill"));
+
        return OPERATOR_FINISHED;       
 }
 
@@ -1396,32 +1400,24 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_circle_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 3, 500);
-       RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
        RNA_def_boolean(ot->srna, "fill", 0, "Fill", "");
 }
 
 static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia *= RNA_float_get(op->ptr, "radius");
-       
-       make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
-                         RNA_float_get(op->ptr, "depth"), 1, 1);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
-       return OPERATOR_FINISHED;       
+       make_prim_ext(C, PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"),
+                       RNA_float_get(op->ptr, "depth"), 1, 1);
+
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
@@ -1433,31 +1429,23 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_cylinder_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
-       RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
-       RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
 }
 
 static int add_primitive_tube_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia *= RNA_float_get(op->ptr, "radius");
-       
-       make_prim(obedit, PRIM_CYLINDER, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
-                         RNA_float_get(op->ptr, "depth"), 1, 0);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
+       make_prim_ext(C, PRIM_CYLINDER, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"),
+                       RNA_float_get(op->ptr, "depth"), 1, 0);
+
        return OPERATOR_FINISHED;       
 }
 
@@ -1470,32 +1458,24 @@ void MESH_OT_primitive_tube_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_tube_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
-       RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
-       RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
 }
 
 static int add_primitive_cone_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia *= RNA_float_get(op->ptr, "radius");
-       
-       make_prim(obedit, PRIM_CONE, mat, RNA_int_get(op->ptr, "vertices"), 0, 0, dia, 
-                         RNA_float_get(op->ptr, "depth"), 0, RNA_boolean_get(op->ptr, "cap_end"));
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
-       return OPERATOR_FINISHED;       
+       make_prim_ext(C, PRIM_CONE, RNA_int_get(op->ptr, "vertices"), 0, 0,
+                       RNA_float_get(op->ptr,"radius"), RNA_float_get(op->ptr, "depth"),
+                       0, RNA_boolean_get(op->ptr, "cap_end"));
+
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_cone_add(wmOperatorType *ot)
@@ -1507,34 +1487,26 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_cone_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
        
        /* props */
        RNA_def_int(ot->srna, "vertices", 32, INT_MIN, INT_MAX, "Vertices", "", 2, 500);
-       RNA_def_float(ot->srna, "radius", 1.0f, -FLT_MAX, FLT_MAX, "Radius", "", 0.001, 100.00);
-       RNA_def_float(ot->srna, "depth", 1.0f, -FLT_MAX, FLT_MAX, "Depth", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "radius", 1.0f, 0.0, FLT_MAX, "Radius", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "depth", 1.0f, 0.0, FLT_MAX, "Depth", "", 0.001, 100.00);
        RNA_def_boolean(ot->srna, "cap_end", 0, "Cap End", "");
 
 }
 
 static int add_primitive_grid_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia*= RNA_float_get(op->ptr, "size");
-       
-       make_prim(obedit, PRIM_GRID, mat, RNA_int_get(op->ptr, "x_subdivisions"), 
-                         RNA_int_get(op->ptr, "y_subdivisions"), 0, dia, 0.0f, 0, 1);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
-       return OPERATOR_FINISHED;       
+       make_prim_ext(C, PRIM_GRID, RNA_int_get(op->ptr, "x_subdivisions"),
+                       RNA_int_get(op->ptr, "y_subdivisions"), 0,
+                       RNA_float_get(op->ptr,"size"), 0.0f, 0, 1);
+
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_grid_add(wmOperatorType *ot)
@@ -1546,7 +1518,7 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_grid_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1554,22 +1526,13 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
        /* props */
        RNA_def_int(ot->srna, "x_subdivisions", 10, INT_MIN, INT_MAX, "X Subdivisions", "", 3, 1000);
        RNA_def_int(ot->srna, "y_subdivisions", 10, INT_MIN, INT_MAX, "Y Subdivisons", "", 3, 1000);
-       RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, FLT_MAX);
+       RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, FLT_MAX);
 }
 
 static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float mat[4][4];
-       
-       new_primitive_matrix(C, mat);
-       
-       make_prim(obedit, PRIM_MONKEY, mat, 0, 0, 2, 0.0f, 0.0f, 0, 0);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
-       return OPERATOR_FINISHED;       
+       make_prim_ext(C, PRIM_MONKEY, 0, 0, 2, 0.0f, 0.0f, 0, 0);
+       return OPERATOR_FINISHED;
 }
 
 void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
@@ -1581,7 +1544,7 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_monkey_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1589,18 +1552,10 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
 
 static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia*= RNA_float_get(op->ptr, "size");
+       make_prim_ext(C, PRIM_UVSPHERE, RNA_int_get(op->ptr, "rings"),
+                       RNA_int_get(op->ptr, "segments"), 0,
+                       RNA_float_get(op->ptr,"size"), 0.0f, 0, 0);
 
-       make_prim(obedit, PRIM_UVSPHERE, mat, RNA_int_get(op->ptr, "rings"), 
-                         RNA_int_get(op->ptr, "segments"), 0, dia, 0.0f, 0, 0);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
        return OPERATOR_FINISHED;       
 }
 
@@ -1613,7 +1568,7 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_uvsphere_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
@@ -1621,23 +1576,14 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
        /* props */
        RNA_def_int(ot->srna, "segments", 32, INT_MIN, INT_MAX, "Segments", "", 3, 500);
        RNA_def_int(ot->srna, "rings", 24, INT_MIN, INT_MAX, "Rings", "", 3, 500);
-       RNA_def_float(ot->srna, "size", 1.0f, -FLT_MAX, FLT_MAX, "Size", "", 0.001, 100.00);
+       RNA_def_float(ot->srna, "size", 1.0f, 0.0, FLT_MAX, "Size", "", 0.001, 100.00);
 }
 
 static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
 {
-       Object *obedit= CTX_data_edit_object(C);
-       float dia, mat[4][4];
-       
-       dia= new_primitive_matrix(C, mat);
-       dia*= RNA_float_get(op->ptr, "size");
-       
-       make_prim(obedit, PRIM_ICOSPHERE, mat, 0, 0, 
-                         RNA_int_get(op->ptr, "subdivisions"), dia, 0.0f, 0, 0);
-       
-       DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-       WM_event_add_notifier(C, NC_GEOM|ND_DATA, obedit->data);
-       
+       make_prim_ext(C, PRIM_ICOSPHERE, 0, 0, RNA_int_get(op->ptr, "subdivisions"),
+                       RNA_float_get(op->ptr,"size"), 0.0f, 0, 0);
+
        return OPERATOR_FINISHED;       
 }
 
@@ -1650,7 +1596,7 @@ void MESH_OT_primitive_ico_sphere_add(wmOperatorType *ot)
        
        /* api callbacks */
        ot->exec= add_primitive_icosphere_exec;
-       ot->poll= ED_operator_editmesh;
+       ot->poll= ED_operator_scene_editable;
        
        /* flags */
        ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
index 6f94db3..0865455 100644 (file)
@@ -428,7 +428,10 @@ void ED_keymap_mesh(wmKeyConfig *keyconf)
        /* add/remove */
        WM_keymap_add_item(keymap, "MESH_OT_edge_face_add", FKEY, KM_PRESS, 0, 0);
        WM_keymap_add_item(keymap, "MESH_OT_duplicate_move", DKEY, KM_PRESS, KM_SHIFT, 0);
-       WM_keymap_add_item(keymap, "OBJECT_OT_mesh_add", AKEY, KM_PRESS, KM_SHIFT, 0);
+       
+       kmi= WM_keymap_add_item(keymap, "WM_OT_call_menu", AKEY, KM_PRESS, KM_SHIFT, 0);
+       RNA_string_set(kmi->ptr, "name", "INFO_MT_mesh_add");
+       
        WM_keymap_add_item(keymap, "MESH_OT_separate", PKEY, KM_PRESS, 0, 0);
                                                /* use KM_RELEASE because same key is used for tweaks */
        WM_keymap_add_item(keymap, "MESH_OT_dupli_extrude_cursor", LEFTMOUSE, KM_RELEASE, KM_CTRL, 0);
index 00893f1..fad73e1 100644 (file)
@@ -533,7 +533,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        DAG_scene_sort(scene);  // removed objects, need to rebuild dag before editmode call
        
        ED_object_enter_editmode(C, EM_WAITCURSOR);
-       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR);
+       ED_object_exit_editmode(C, EM_FREEDATA|EM_WAITCURSOR|EM_DO_UNDO);
 
        WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
 
index d79ec46..5f088f2 100644 (file)
@@ -144,14 +144,14 @@ void add_object_draw(Scene *scene, View3D *v3d, int type) /* for toolbox or menu
 }
 
 /* for object add primitive operators */
-static Object *object_add_type(bContext *C, int type)
+Object *ED_object_add_type(bContext *C, int type)
 {
        Scene *scene= CTX_data_scene(C);
        Object *ob;
        
        /* for as long scene has editmode... */
        if (CTX_data_edit_object(C)) 
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); /* freedata, and undo */
        
        /* deselects all, sets scene->basact */
        ob= add_object(scene, type);
@@ -169,7 +169,7 @@ static Object *object_add_type(bContext *C, int type)
 /* for object add operator */
 static int object_add_exec(bContext *C, wmOperator *op)
 {
-       object_add_type(C, RNA_enum_get(op->ptr, "type"));
+       ED_object_add_type(C, RNA_enum_get(op->ptr, "type"));
        
        return OPERATOR_FINISHED;
 }
@@ -224,7 +224,7 @@ static Object *effector_add_type(bContext *C, int type)
        
        /* for as long scene has editmode... */
        if (CTX_data_edit_object(C)) 
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); /* freedata, and undo */
        
        /* deselects all, sets scene->basact */
        if(type==PFIELD_GUIDE) {
@@ -232,7 +232,7 @@ static Object *effector_add_type(bContext *C, int type)
                ((Curve*)ob->data)->flag |= CU_PATH|CU_3D;
                ED_object_enter_editmode(C, 0);
                BLI_addtail(curve_get_editcurve(ob), add_nurbs_primitive(C, CU_NURBS|CU_PRIM_PATH, 1));
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
        }
        else
                ob=     add_object(scene, OB_EMPTY);
@@ -278,92 +278,6 @@ void OBJECT_OT_effector_add(wmOperatorType *ot)
 }
 
 /* ***************** add primitives *************** */
-/* ******  work both in and outside editmode ****** */
-
-static EnumPropertyItem prop_mesh_types[] = {
-       {0, "PLANE", ICON_MESH_PLANE, "Plane", ""},
-       {1, "CUBE", ICON_MESH_CUBE, "Cube", ""},
-       {2, "CIRCLE", ICON_MESH_CIRCLE, "Circle", ""},
-       {3, "UVSPHERE", ICON_MESH_UVSPHERE, "UVsphere", ""},
-       {4, "ICOSPHERE", ICON_MESH_ICOSPHERE, "Icosphere", ""},
-       {5, "CYLINDER", ICON_MESH_TUBE, "Cylinder", ""},
-       {6, "CONE", ICON_MESH_CONE, "Cone", ""},
-       {0, "", 0, NULL, NULL},
-       {7, "GRID", ICON_MESH_GRID, "Grid", ""},
-       {8, "MONKEY", ICON_MESH_MONKEY, "Monkey", ""},
-       {0, NULL, 0, NULL, NULL}
-};
-
-static int object_add_mesh_exec(bContext *C, wmOperator *op)
-{
-       Object *obedit= CTX_data_edit_object(C);
-       int newob= 0;
-       
-       if(obedit==NULL || obedit->type!=OB_MESH) {
-               object_add_type(C, OB_MESH);
-               ED_object_enter_editmode(C, EM_DO_UNDO);
-               newob = 1;
-       }
-       else DAG_id_flush_update(&obedit->id, OB_RECALC_DATA);
-
-       switch(RNA_enum_get(op->ptr, "type")) {
-               case 0:
-                       WM_operator_name_call(C, "MESH_OT_primitive_plane_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 1:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cube_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 2:
-                       WM_operator_name_call(C, "MESH_OT_primitive_circle_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 3:
-                       WM_operator_name_call(C, "MESH_OT_primitive_uv_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 4:
-                       WM_operator_name_call(C, "MESH_OT_primitive_ico_sphere_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 5:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cylinder_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 6:
-                       WM_operator_name_call(C, "MESH_OT_primitive_cone_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 7:
-                       WM_operator_name_call(C, "MESH_OT_primitive_grid_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-               case 8:
-                       WM_operator_name_call(C, "MESH_OT_primitive_monkey_add", WM_OP_INVOKE_REGION_WIN, NULL);
-                       break;
-       }
-       /* userdef */
-       if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
-       }
-       
-       WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
-       
-       return OPERATOR_FINISHED;
-}
-
-
-void OBJECT_OT_mesh_add(wmOperatorType *ot)
-{
-       /* identifiers */
-       ot->name= "Add Mesh";
-       ot->description = "Add a mesh object to the scene.";
-       ot->idname= "OBJECT_OT_mesh_add";
-       
-       /* api callbacks */
-       ot->invoke= WM_menu_invoke;
-       ot->exec= object_add_mesh_exec;
-       
-       ot->poll= ED_operator_scene_editable;
-       
-       /* 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", "");
-}
 
 static EnumPropertyItem prop_curve_types[] = {
        {CU_BEZIER|CU_PRIM_CURVE, "BEZIER_CURVE", ICON_CURVE_BEZCURVE, "Bezier Curve", ""},
@@ -382,7 +296,7 @@ static int object_add_curve_exec(bContext *C, wmOperator *op)
        int newob= 0;
        
        if(obedit==NULL || obedit->type!=OB_CURVE) {
-               object_add_type(C, OB_CURVE);
+               ED_object_add_type(C, OB_CURVE);
                ED_object_enter_editmode(C, 0);
                newob = 1;
        }
@@ -395,7 +309,7 @@ static int object_add_curve_exec(bContext *C, wmOperator *op)
        
        /* userdef */
        if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
        }
        
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
@@ -457,7 +371,7 @@ static int object_add_surface_exec(bContext *C, wmOperator *op)
        int newob= 0;
        
        if(obedit==NULL || obedit->type!=OB_SURF) {
-               object_add_type(C, OB_SURF);
+               ED_object_add_type(C, OB_SURF);
                ED_object_enter_editmode(C, 0);
                newob = 1;
        }
@@ -470,7 +384,7 @@ static int object_add_surface_exec(bContext *C, wmOperator *op)
        
        /* userdef */
        if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
        }
        
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
@@ -514,7 +428,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
        int newob= 0;
        
        if(obedit==NULL || obedit->type!=OB_MBALL) {
-               object_add_type(C, OB_MBALL);
+               ED_object_add_type(C, OB_MBALL);
                ED_object_enter_editmode(C, 0);
                newob = 1;
        }
@@ -527,7 +441,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
        
        /* userdef */
        if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
        }
        
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
@@ -576,7 +490,7 @@ static int object_add_text_exec(bContext *C, wmOperator *op)
        if(obedit && obedit->type==OB_FONT)
                return OPERATOR_CANCELLED;
 
-       object_add_type(C, OB_FONT);
+       ED_object_add_type(C, OB_FONT);
        obedit= CTX_data_active_object(C);
 
        if(U.flag & USER_ADD_EDITMODE)
@@ -610,7 +524,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
        int newob= 0;
        
        if ((obedit==NULL) || (obedit->type != OB_ARMATURE)) {
-               object_add_type(C, OB_ARMATURE);
+               ED_object_add_type(C, OB_ARMATURE);
                ED_object_enter_editmode(C, 0);
                newob = 1;
        }
@@ -624,7 +538,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
 
        /* userdef */
        if (newob && (U.flag & USER_ADD_EDITMODE)==0) {
-               ED_object_exit_editmode(C, EM_FREEDATA);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
        }
        
        WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, obedit);
@@ -652,7 +566,7 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op)
        Object *ob;
        int type= RNA_enum_get(op->ptr, "type");
 
-       ob= object_add_type(C, OB_LAMP);
+       ob= ED_object_add_type(C, OB_LAMP);
        if(ob && ob->data)
                ((Lamp*)ob->data)->type= type;
        
@@ -720,7 +634,7 @@ static int group_instance_add_exec(bContext *C, wmOperator *op)
        Group *group= BLI_findlink(&CTX_data_main(C)->group, RNA_enum_get(op->ptr, "type"));
 
        if(group) {
-               Object *ob= object_add_type(C, OB_EMPTY);
+               Object *ob= ED_object_add_type(C, OB_EMPTY);
                rename_id(&ob->id, group->id.name+2);
                ob->dup_group= group;
                ob->transflag |= OB_DUPLIGROUP;
index ac47556..9535a6e 100644 (file)
@@ -280,6 +280,8 @@ void OBJECT_OT_restrictview_set(wmOperatorType *ot)
 
 void ED_object_exit_editmode(bContext *C, int flag)
 {
+       /* Note! only in exceptional cases should 'EM_DO_UNDO' NOT be in the flag */
+
        Scene *scene= CTX_data_scene(C);
        Object *obedit= CTX_data_edit_object(C);
        int freedata = flag & EM_FREEDATA;
@@ -353,7 +355,8 @@ void ED_object_exit_editmode(bContext *C, int flag)
                /* also flush ob recalc, doesn't take much overhead, but used for particles */
                DAG_id_flush_update(&obedit->id, OB_RECALC_OB|OB_RECALC_DATA);
        
-               ED_undo_push(C, "Editmode");
+               if(flag & EM_DO_UNDO)
+                       ED_undo_push(C, "Editmode");
        
                if(flag & EM_WAITCURSOR) waitcursor(0);
        
@@ -481,7 +484,7 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
        if(!CTX_data_edit_object(C))
                ED_object_enter_editmode(C, EM_WAITCURSOR);
        else
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
        
        return OPERATOR_FINISHED;
 }
@@ -521,7 +524,7 @@ static int posemode_exec(bContext *C, wmOperator *op)
        
        if(base->object->type==OB_ARMATURE) {
                if(base->object==CTX_data_edit_object(C)) {
-                       ED_object_exit_editmode(C, EM_FREEDATA);
+                       ED_object_exit_editmode(C, EM_FREEDATA|EM_DO_UNDO);
                        ED_armature_enter_posemode(C, base);
                }
                else if(base->object->mode & OB_MODE_POSE)
@@ -558,7 +561,7 @@ void check_editmode(int type)
        
        if (obedit==NULL || obedit->type==type) return;
 
-// XXX ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR); /* freedata, and undo */
+// XXX ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO); /* freedata, and undo */
 }
 
 #if 0
index 3536225..dc7ae14 100644 (file)
@@ -83,7 +83,6 @@ void OBJECT_OT_select_name(struct wmOperatorType *ot);
 
 /* object_add.c */
 void OBJECT_OT_add(struct wmOperatorType *ot);
-void OBJECT_OT_mesh_add(struct wmOperatorType *ot);
 void OBJECT_OT_curve_add(struct wmOperatorType *ot);
 void OBJECT_OT_surface_add(struct wmOperatorType *ot);
 void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
index d75cf63..2b010f5 100644 (file)
@@ -110,7 +110,6 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(GROUP_OT_objects_remove_active);
 
        WM_operatortype_append(OBJECT_OT_delete);
-       WM_operatortype_append(OBJECT_OT_mesh_add);
        WM_operatortype_append(OBJECT_OT_curve_add);
        WM_operatortype_append(OBJECT_OT_text_add);
        WM_operatortype_append(OBJECT_OT_surface_add);
@@ -119,7 +118,6 @@ void ED_operatortypes_object(void)
        WM_operatortype_append(OBJECT_OT_add);
        WM_operatortype_append(OBJECT_OT_effector_add);
        WM_operatortype_append(OBJECT_OT_group_instance_add);
-       WM_operatortype_append(OBJECT_OT_mesh_add);
        WM_operatortype_append(OBJECT_OT_metaball_add);
        WM_operatortype_append(OBJECT_OT_duplicates_make_real);
        WM_operatortype_append(OBJECT_OT_duplicate);
index 30fdb5b..e160b85 100644 (file)
@@ -2934,7 +2934,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, wmEvent *event)
        multires_force_update(CTX_data_active_object(C));
        
        /* get editmode results */
-       ED_object_exit_editmode(C, 0);  /* 0 = does not exit editmode */
+       ED_object_exit_editmode(C, EM_DO_UNDO); /* 0 = does not exit editmode */
        
        // store spare
        // get view3d layer, local layer, make this nice api call to render
index 28fdc47..2612f8a 100644 (file)
@@ -1824,7 +1824,7 @@ static void tree_element_set_active_object(bContext *C, Scene *scene, SpaceOops
        }
        
        if(ob!=scene->obedit) 
-               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
        
        WM_event_add_notifier(C, NC_SCENE|ND_OB_ACTIVE, scene);
 
@@ -2173,7 +2173,7 @@ static int tree_element_active_pose(bContext *C, Scene *scene, TreeElement *te,
        
        if(set) {
                if(scene->obedit) 
-                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
                
                if(ob->mode & OB_MODE_POSE) 
                        ED_armature_exit_posemode(C, base);
@@ -2327,7 +2327,7 @@ static int do_outliner_item_activate(bContext *C, Scene *scene, ARegion *ar, Spa
                                else if(ELEM5(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
                                        Object *obedit= CTX_data_edit_object(C);
                                        if(obedit) 
-                                               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+                                               ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
                                        else {
                                                ED_object_enter_editmode(C, EM_WAITCURSOR);
                                                // XXX extern_set_butspace(F9KEY, 0);
@@ -3057,7 +3057,7 @@ static void object_delete_cb(bContext *C, Scene *scene, TreeElement *te, TreeSto
        if(base) {
                // check also library later
                if(scene->obedit==base->object) 
-                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR);
+                       ED_object_exit_editmode(C, EM_FREEDATA|EM_FREEUNDO|EM_WAITCURSOR|EM_DO_UNDO);
                
                ED_base_object_free_and_unlink(scene, base);
                te->directdata= NULL;
index f987c99..2683e17 100644 (file)
@@ -58,9 +58,11 @@ EnumPropertyItem prop_mode_items[] ={
 
 #include "DNA_anim_types.h"
 #include "DNA_node_types.h"
+#include "DNA_object_types.h"
 
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_scene.h"
 #include "BKE_node.h"
 #include "BKE_pointcache.h"
 
@@ -79,6 +81,22 @@ static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
        return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((Base*)internal->link)->object);
 }
 
+static PointerRNA rna_Scene_active_object_get(PointerRNA *ptr)
+{
+       Scene *scene= (Scene*)ptr->data;
+       return rna_pointer_inherit_refine(ptr, &RNA_Object, scene->basact ? scene->basact->object : NULL);
+}
+
+static void rna_Scene_active_object_set(PointerRNA *ptr, PointerRNA value)
+{
+       Scene *scene= (Scene*)ptr->data;
+       if(value.data)
+               scene->basact= object_in_scene((Object*)value.data, scene);
+       else
+               scene->basact= NULL;
+}
+
+
 static int layer_set(int lay, const int *values)
 {
        int i, tot= 0;
@@ -2051,6 +2069,13 @@ void RNA_def_scene(BlenderRNA *brna)
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "Camera", "Active camera used for rendering the scene.");
 
+       prop= RNA_def_property(srna, "active_object", PROP_POINTER, PROP_NONE);
+       RNA_def_property_struct_type(prop, "Object");
+       RNA_def_property_pointer_funcs(prop, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL);
+       RNA_def_property_flag(prop, PROP_EDITABLE);
+       RNA_def_property_ui_text(prop, "Object", "Object to use as projector transform.");
+
+
        prop= RNA_def_property(srna, "world", PROP_POINTER, PROP_NONE);
        RNA_def_property_flag(prop, PROP_EDITABLE);
        RNA_def_property_ui_text(prop, "World", "World used for rendering the scene.");
@@ -2081,7 +2106,7 @@ void RNA_def_scene(BlenderRNA *brna)
        prop= RNA_def_property(srna, "current_frame", PROP_INT, PROP_TIME);
        RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
        RNA_def_property_int_sdna(prop, NULL, "r.cfra");
-       RNA_def_property_range(prop, MINAFRAME, MAXFRAME);
+       RNA_def_property_range(prop, -MINAFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Current Frame", "");
        RNA_def_property_update(prop, NC_SCENE|ND_FRAME, "rna_Scene_frame_update");
        
@@ -2089,6 +2114,7 @@ void RNA_def_scene(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
        RNA_def_property_int_sdna(prop, NULL, "r.sfra");
        RNA_def_property_int_funcs(prop, NULL, "rna_Scene_start_frame_set", NULL);
+       RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Start Frame", "");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
@@ -2096,12 +2122,15 @@ void RNA_def_scene(BlenderRNA *brna)
        RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
        RNA_def_property_int_sdna(prop, NULL, "r.efra");
        RNA_def_property_int_funcs(prop, NULL, "rna_Scene_end_frame_set", NULL);
+       RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "End Frame", "");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
        prop= RNA_def_property(srna, "frame_step", PROP_INT, PROP_TIME);
        RNA_def_property_clear_flag(prop, PROP_ANIMATEABLE);
        RNA_def_property_int_sdna(prop, NULL, "frame_step");
+       RNA_def_property_range(prop, 0, MAXFRAME);
+       RNA_def_property_ui_range(prop, 0, 100, 1, 0);
        RNA_def_property_ui_text(prop, "Frame Step", "Number of frames to skip forward while rendering/playing back each frame");
        RNA_def_property_update(prop, NC_SCENE|ND_RENDER_OPTIONS, NULL);
        
index 428df15..c4fb9ea 100644 (file)
@@ -37,6 +37,7 @@
 #include "DNA_texture_types.h"
 #include "DNA_world_types.h"
 #include "DNA_node_types.h"
+#include "DNA_scene_types.h" /* MAXFRAME only */
 
 #include "BKE_node.h"
 
@@ -1579,7 +1580,7 @@ static void rna_def_texture_voxeldata(BlenderRNA *brna)
        
        prop= RNA_def_property(srna, "still_frame_number", PROP_INT, PROP_NONE);
        RNA_def_property_int_sdna(prop, NULL, "still_frame");
-       RNA_def_property_range(prop, 0, INT_MAX);
+       RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
        RNA_def_property_ui_text(prop, "Still Frame Number", "The frame number to always use");
        RNA_def_property_update(prop, 0, "rna_Texture_update");
        
index bb0cea9..769a833 100644 (file)
@@ -270,6 +270,9 @@ void PYTHON_OT_wrapper(wmOperatorType *ot, void *userdata)
        /* api callbacks, detailed checks dont on adding */ 
        if (PyObject_HasAttrString(py_class, "invoke"))
                ot->invoke= PYTHON_OT_invoke;
+       //else
+       //      ot->invoke= WM_operator_props_popup; /* could have an option for standard invokes */
+
        if (PyObject_HasAttrString(py_class, "execute"))
                ot->exec= PYTHON_OT_execute;
        if (PyObject_HasAttrString(py_class, "poll"))
index 1aca9a6..ff0e69b 100644 (file)
@@ -533,7 +533,7 @@ void WM_write_file(bContext *C, char *target, int compress, ReportList *reports)
                packAll(G.main, reports);
        }
        
-       ED_object_exit_editmode(C, 0);
+       ED_object_exit_editmode(C, EM_DO_UNDO);
 
        do_history(di, reports);