bugfix [#25595] Adding Torus when in edit mode strange behavior.
authorCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jan 2011 15:45:00 +0000 (15:45 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Wed, 12 Jan 2011 15:45:00 +0000 (15:45 +0000)
also added Align View option and made local view cursor work.

release/scripts/modules/add_object_utils.py
release/scripts/op/add_mesh_torus.py
source/blender/editors/mesh/mesh_data.c

index 20f0ffdbe60bfce626d591f45c3672ab6a9a6d17..8c52a63bf131743661930d1b2a00b1995f06a5a8 100644 (file)
@@ -23,22 +23,41 @@ import mathutils
 
 
 def add_object_align_init(context, operator):
+    space_data = context.space_data
+    if space_data.type != 'VIEW_3D':
+        space_data = None
 
-    if operator and operator.properties.is_property_set("location") and operator.properties.is_property_set("rotation"):
+    # location
+    if operator and operator.properties.is_property_set("location"):
         location = mathutils.Matrix.Translation(mathutils.Vector(operator.properties.location))
-        rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4()
     else:
-        # TODO, local view cursor!
-        location = mathutils.Matrix.Translation(context.scene.cursor_location)
+        if space_data:  # local view cursor is detected below
+            location = mathutils.Matrix.Translation(space_data.cursor_location)
+        else:
+            location = mathutils.Matrix.Translation(context.scene.cursor_location)
+
+        if operator:
+            operator.properties.location = location.translation_part()
 
-        if context.user_preferences.edit.object_align == 'VIEW' and context.space_data.type == 'VIEW_3D':
-            rotation = context.space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
+    # rotation
+    view_align = (context.user_preferences.edit.object_align == 'VIEW')
+    view_align_force = False
+    if operator:
+        if operator.properties.is_property_set("view_align"):
+            view_align = view_align_force = operator.view_align
+        else:
+            operator.properties.view_align = view_align
+
+    if operator.properties.is_property_set("rotation") and not view_align_force:
+        rotation = mathutils.Euler(operator.properties.rotation).to_matrix().resize4x4()
+    else:
+        if view_align and space_data:
+            rotation = space_data.region_3d.view_matrix.rotation_part().invert().resize4x4()
         else:
             rotation = mathutils.Matrix()
 
         # set the operator properties
         if operator:
-            operator.properties.location = location.translation_part()
             operator.properties.rotation = rotation.to_euler()
 
     return location * rotation
@@ -65,6 +84,7 @@ def object_data_add(context, obdata, operator=None):
     obj_act = scene.objects.active
 
     if obj_act and obj_act.mode == 'EDIT' and obj_act.type == obj_new.type:
+        bpy.ops.mesh.select_all(action='DESELECT')
         bpy.ops.object.mode_set(mode='OBJECT')
 
         obj_act.select = True
index eee30dabb1d9fe1990ad29edd9094c21bfecf3ae..0fb08947994121dbc2742548187211364a77b321 100644 (file)
@@ -26,8 +26,8 @@ def add_torus(major_rad, minor_rad, major_seg, minor_seg):
     Vector = mathutils.Vector
     Quaternion = mathutils.Quaternion
 
-    PI_2 = pi * 2
-    z_axis = (0, 0, 1)
+    PI_2 = pi * 2.0
+    z_axis = 0.0, 0.0, 1.0
 
     verts = []
     faces = []
@@ -103,9 +103,12 @@ class AddTorus(bpy.types.Operator):
             default=0.5, min=0.01, max=100.0)
 
     # generic transform props
+    view_align = BoolProperty(name="Align to View",
+            default=False)
     location = FloatVectorProperty(name="Location")
     rotation = FloatVectorProperty(name="Rotation")
 
+
     def execute(self, context):
 
         if self.use_abso == True:
index 7dd5196d32d77f8a2f6c352679e7b9750d122f8b..424d2b273e6a4e13d24159aa101b755cb1eccd37 100644 (file)
@@ -593,7 +593,7 @@ static void mesh_calc_edges(Mesh *mesh, int update)
                        *med= *med_orig; /* copy from the original */
                } else {
                        BLI_edgehashIterator_getKey(ehi, (int*)&med->v1, (int*)&med->v2);
-                       med->flag = ME_EDGEDRAW|ME_EDGERENDER;
+                       med->flag = ME_EDGEDRAW|ME_EDGERENDER|SELECT; /* select for newly created meshes which are selected [#25595] */
                }
        }
        BLI_edgehashIterator_free(ehi);