Object Mode: move to workspace struct

- Read-only access can often use EvaluationContext.object_mode
- Write access to go to WorkSpace.object_mode.
- Some TODO's remain (marked as "TODO/OBMODE")
- Add-ons will need updating
  (context.active_object.mode -> context.workspace.object_mode)
- There will be small/medium issues that still need resolving
  this does work on a basic level though.

See D3037
This commit is contained in:
Campbell Barton
2018-02-08 21:14:26 +11:00
parent 14a19fed78
commit 345c6298e9
89 changed files with 691 additions and 516 deletions

View File

@@ -63,12 +63,13 @@ class SelectPattern(Operator):
pattern_match = (lambda a, b:
fnmatch.fnmatchcase(a.upper(), b.upper()))
is_ebone = False
workspace = context.workspace
obj = context.object
if obj and obj.mode == 'POSE':
if obj and workspace.object_mode == 'POSE':
items = obj.data.bones
if not self.extend:
bpy.ops.pose.select_all(action='DESELECT')
elif obj and obj.type == 'ARMATURE' and obj.mode == 'EDIT':
elif obj and obj.type == 'ARMATURE' and workspace.object_mode == 'EDIT':
items = obj.data.edit_bones
if not self.extend:
bpy.ops.armature.select_all(action='DESELECT')
@@ -248,6 +249,8 @@ class SubdivisionSet(Operator):
if not relative and level < 0:
self.level = level = 0
workspace = context.workspace
def set_object_subd(obj):
for mod in obj.modifiers:
if mod.type == 'MULTIRES':
@@ -257,18 +260,18 @@ class SubdivisionSet(Operator):
for i in range(sub):
bpy.ops.object.multires_subdivide(modifier="Multires")
if obj.mode == 'SCULPT':
if workspace.object_mode == 'SCULPT':
if mod.sculpt_levels != level:
mod.sculpt_levels = level
elif obj.mode == 'OBJECT':
elif workspace.object_mode == 'OBJECT':
if mod.levels != level:
mod.levels = level
return
else:
if obj.mode == 'SCULPT':
if workspace.object_mode == 'SCULPT':
if mod.sculpt_levels + level <= mod.total_levels:
mod.sculpt_levels += level
elif obj.mode == 'OBJECT':
elif workspace.object_mode == 'OBJECT':
if mod.levels + level <= mod.total_levels:
mod.levels += level
return
@@ -284,7 +287,7 @@ class SubdivisionSet(Operator):
# add a new modifier
try:
if obj.mode == 'SCULPT':
if workspace.object_mode == 'SCULPT':
mod = obj.modifiers.new("Multires", 'MULTIRES')
if level > 0:
for i in range(0, level):
@@ -467,8 +470,9 @@ class ShapeTransfer(Operator):
@classmethod
def poll(cls, context):
workspace = context.workspace
obj = context.active_object
return (obj and obj.mode != 'EDIT')
return (obj and workspace.object_mode != 'EDIT')
def execute(self, context):
ob_act = context.active_object
@@ -508,10 +512,11 @@ class JoinUVs(Operator):
def _main(self, context):
import array
workspace = context.workspace
obj = context.active_object
mesh = obj.data
is_editmode = (obj.mode == 'EDIT')
is_editmode = (workspace.object_mode == 'EDIT')
if is_editmode:
bpy.ops.object.mode_set(mode='OBJECT', toggle=False)