-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoperators_sheets.py
More file actions
124 lines (96 loc) · 4.02 KB
/
Copy pathoperators_sheets.py
File metadata and controls
124 lines (96 loc) · 4.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import bpy
from mathutils import Vector
from . import sheet_composer
def _set_canonical_page_view(context, width=None, height=None):
"""Show XY page content from Blender's true Top view, upright."""
if context.area is None or context.area.type != 'VIEW_3D':
return
# Let Blender establish the canonical TOP orientation. Building the
# quaternion manually selected the opposite side of the XY plane in
# Blender 5.x, making text appear rotated/mirrored.
try:
bpy.ops.view3d.view_axis(type='TOP', align_active=False)
except RuntimeError:
# Fallback for unusual contexts: standard unrolled top orientation.
from mathutils import Quaternion
context.space_data.region_3d.view_rotation = Quaternion((1.0, 0.0, 0.0, 0.0))
r3d = context.space_data.region_3d
r3d.view_perspective = 'ORTHO'
r3d.view_location = (0.0, 0.0, 0.0)
if width is not None and height is not None:
r3d.view_distance = max(width, height) * 0.90
class EDITORIALGP_OT_generate_sheets(bpy.types.Operator):
bl_idname = "editorial_gp.generate_sheets"
bl_label = "Generate Sides"
bl_description = "Create the imposed physical sides as temporary collections"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
try:
plan = sheet_composer.generate_sides(context.scene)
except Exception as exc:
self.report({'ERROR'}, str(exc))
return {'CANCELLED'}
_set_canonical_page_view(context)
self.report({'INFO'}, f"Generated {len(plan.sides)} sides")
return {'FINISHED'}
class EDITORIALGP_OT_sheet_previous(bpy.types.Operator):
bl_idname = "editorial_gp.sheet_previous"
bl_label = "Previous Side"
bl_options = {'REGISTER'}
def execute(self, context):
sheet_composer.show_side(context.scene, context.scene.editorial_gp.current_sheet_side - 1)
_set_canonical_page_view(context)
return {'FINISHED'}
class EDITORIALGP_OT_sheet_next(bpy.types.Operator):
bl_idname = "editorial_gp.sheet_next"
bl_label = "Next Side"
bl_options = {'REGISTER'}
def execute(self, context):
sheet_composer.show_side(context.scene, context.scene.editorial_gp.current_sheet_side + 1)
_set_canonical_page_view(context)
return {'FINISHED'}
class EDITORIALGP_OT_return_to_pages(bpy.types.Operator):
bl_idname = "editorial_gp.return_to_pages"
bl_label = "Return to Pages"
bl_options = {'REGISTER'}
def execute(self, context):
sheet_composer.return_to_pages(context.scene)
_set_canonical_page_view(context)
return {'FINISHED'}
class EDITORIALGP_OT_delete_sheets(bpy.types.Operator):
bl_idname = "editorial_gp.delete_sheets"
bl_label = "Delete Generated Sides"
bl_options = {'REGISTER', 'UNDO'}
def execute(self, context):
sheet_composer.return_to_pages(context.scene)
sheet_composer.clear_generated_sheets(context.scene)
self.report({'INFO'}, "Generated sides deleted")
return {'FINISHED'}
class EDITORIALGP_OT_frame_sheet(bpy.types.Operator):
bl_idname = "editorial_gp.frame_sheet"
bl_label = "Frame Side"
def execute(self, context):
if context.area.type != 'VIEW_3D':
return {'CANCELLED'}
sides = sheet_composer.side_collections(context.scene)
if not sides:
return {'CANCELLED'}
side = sides[context.scene.editorial_gp.current_sheet_side]
width = float(side.get("sheet_width_mm", 1.0)) / 1000.0
height = float(side.get("sheet_height_mm", 1.0)) / 1000.0
_set_canonical_page_view(context, width, height)
return {'FINISHED'}
classes = (
EDITORIALGP_OT_generate_sheets,
EDITORIALGP_OT_sheet_previous,
EDITORIALGP_OT_sheet_next,
EDITORIALGP_OT_return_to_pages,
EDITORIALGP_OT_delete_sheets,
EDITORIALGP_OT_frame_sheet,
)
def register():
for cls in classes:
bpy.utils.register_class(cls)
def unregister():
for cls in reversed(classes):
bpy.utils.unregister_class(cls)