Fix error in rigify property generation
[blender-addons.git] / space_view3d_3d_navigation.py
blob937f546f3fd20e4d7046b94f03acd1649e96da04
1 # 3D NAVIGATION TOOLBAR v1.2 - 3Dview Addon - Blender 2.5x
3 # THIS SCRIPT IS LICENSED UNDER GPL,
4 # please read the license block.
6 # ##### BEGIN GPL LICENSE BLOCK #####
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software Foundation,
20 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 # ##### END GPL LICENSE BLOCK #####
23 # contributed to by: Demohero, uriel, jbelcik, meta-androcto
25 bl_info = {
26 "name": "3D Navigation",
27 "author": "Demohero, uriel",
28 "version": (1, 2, 6),
29 "blender": (2, 92, 0),
30 "location": "View3D > Sidebar > View Tab",
31 "description": "Navigate the Camera & 3D Viewport from the Sidebar",
32 "warning": "",
33 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/3d_navigation.html",
34 "category": "3D View",
37 import bpy
38 from bpy.types import (
39 AddonPreferences,
40 Operator,
41 Panel,
43 from bpy.props import StringProperty
46 # main class of this toolbar
48 # re-ordered (reversed) Orbit Operators
49 class VIEW3D_OT_OrbitUpView1(Operator):
50 bl_idname = "opr.orbit_up_view1"
51 bl_label = "Orbit Up View"
52 bl_description = "Orbit the view towards you"
54 def execute(self, context):
55 bpy.ops.view3d.view_orbit(type='ORBITUP')
56 return {'FINISHED'}
59 class VIEW3D_OT_OrbitLeftView1(Operator):
60 bl_idname = "opr.orbit_left_view1"
61 bl_label = "Orbit Left View"
62 bl_description = "Orbit the view around to your Right"
64 def execute(self, context):
65 bpy.ops.view3d.view_orbit(type='ORBITLEFT')
66 return {'FINISHED'}
69 class VIEW3D_OT_OrbitRightView1(Operator):
70 bl_idname = "opr.orbit_right_view1"
71 bl_label = "Orbit Right View"
72 bl_description = "Orbit the view around to your Left"
74 def execute(self, context):
75 bpy.ops.view3d.view_orbit(type='ORBITRIGHT')
76 return {'FINISHED'}
79 class VIEW3D_OT_OrbitDownView1(Operator):
80 bl_idname = "opr.orbit_down_view1"
81 bl_label = "Orbit Down View"
82 bl_description = "Orbit the view away from you"
84 def execute(self, context):
85 bpy.ops.view3d.view_orbit(type='ORBITDOWN')
86 return {'FINISHED'}
89 # re-ordered (reversed) Pan Operators
90 # just pass the enum from the VIEW3D_PT_pan_navigation1 Panel
91 class VIEW3D_OT_PanUpViewsAll(Operator):
92 bl_idname = "opr.pan_up_views_all"
93 bl_label = "Pan View"
94 bl_description = "Pan the 3D View"
96 panning: StringProperty(
97 default="PANUP",
98 options={"HIDDEN"}
101 def execute(self, context):
102 try:
103 bpy.ops.view3d.view_pan("INVOKE_REGION_WIN", type=self.panning)
104 except Exception as e:
105 self.report({"WARNING"},
106 "Pan Views could not be completed. Operation Cancelled")
107 print("\n[3D Navigation]\nOperator: opr.pan_up_views_all\n {}\n".format(e))
109 return {"CANCELLED"}
111 return {'FINISHED'}
114 # Zoom Operators
115 class VIEW3D_OT_ZoomInView1(Operator):
116 bl_idname = "opr.zoom_in_view1"
117 bl_label = "Zoom In View"
118 bl_description = "Zoom In the View/Camera View"
120 def execute(self, context):
121 bpy.ops.view3d.zoom(delta=1)
122 return {'FINISHED'}
125 class VIEW3D_OT_ZoomOutView1(Operator):
126 bl_idname = "opr.zoom_out_view1"
127 bl_label = "Zoom Out View"
128 bl_description = "Zoom out In the View/Camera View"
130 def execute(self, context):
131 bpy.ops.view3d.zoom(delta=-1)
132 return {'FINISHED'}
135 # Roll Operators
136 class VIEW3D_OT_RollLeftView1(Operator):
137 bl_idname = "opr.roll_left_view1"
138 bl_label = "Roll Left View"
139 bl_description = "Roll the view Left"
141 def execute(self, context):
142 bpy.ops.view3d.view_roll(angle=-0.261799)
143 return {'FINISHED'}
146 class VIEW3D_OT_RollRightView1(Operator):
147 bl_idname = "opr.roll_right_view1"
148 bl_label = "Roll Right View"
149 bl_description = "Roll the view Right"
151 def execute(self, context):
152 bpy.ops.view3d.view_roll(angle=0.261799)
153 return {'FINISHED'}
156 # View Operators
157 class VIEW3D_OT_LeftViewpoint1(Operator):
158 bl_idname = "opr.left_viewpoint1"
159 bl_label = "Left Viewpoint"
160 bl_description = "View from the Left"
162 def execute(self, context):
163 bpy.ops.view3d.view_axis(type='LEFT')
164 return {'FINISHED'}
167 class VIEW3D_OT_RightViewpoint1(Operator):
168 bl_idname = "opr.right_viewpoint1"
169 bl_label = "Right Viewpoint"
170 bl_description = "View from the Right"
172 def execute(self, context):
173 bpy.ops.view3d.view_axis(type='RIGHT')
174 return {'FINISHED'}
177 class VIEW3D_OT_FrontViewpoint1(Operator):
178 bl_idname = "opr.front_viewpoint1"
179 bl_label = "Front Viewpoint"
180 bl_description = "View from the Front"
182 def execute(self, context):
183 bpy.ops.view3d.view_axis(type='FRONT')
184 return {'FINISHED'}
187 class VIEW3D_OT_BackViewpoint1(Operator):
188 bl_idname = "opr.back_viewpoint1"
189 bl_label = "Back Viewpoint"
190 bl_description = "View from the Back"
192 def execute(self, context):
193 bpy.ops.view3d.view_axis(type='BACK')
194 return {'FINISHED'}
197 class VIEW3D_OT_TopViewpoint1(Operator):
198 bl_idname = "opr.top_viewpoint1"
199 bl_label = "Top Viewpoint"
200 bl_description = "View from the Top"
202 def execute(self, context):
203 bpy.ops.view3d.view_axis(type='TOP')
204 return {'FINISHED'}
207 class VIEW3D_OT_BottomViewpoint1(Operator):
208 bl_idname = "opr.bottom_viewpoint1"
209 bl_label = "Bottom Viewpoint"
210 bl_description = "View from the Bottom"
212 def execute(self, context):
213 bpy.ops.view3d.view_axis(type='BOTTOM')
214 return {'FINISHED'}
217 # Panel class of this toolbar
218 class VIEW3D_PT_3dnavigationPanel(Panel):
219 bl_space_type = "VIEW_3D"
220 bl_region_type = "UI"
221 bl_label = "3D Navigation"
222 bl_category = "View"
223 bl_options = {'DEFAULT_CLOSED'}
225 def draw(self, context):
226 layout = self.layout
227 view = context.space_data
229 # Triple buttons
230 col = layout.column(align=True)
231 col.operator("view3d.localview", text="View Global/Local")
232 col.operator("view3d.view_persportho", text="Perspective/Orthographic")
233 col.operator("view3d.view_camera", text="View Camera", icon='CAMERA_DATA')
235 # group of 6 buttons
236 col = layout.column(align=True)
237 col.label(text="Align view from:", icon="VIEW3D")
238 row = col.row()
239 row.operator("view3d.view_axis", text="Front").type = 'FRONT'
240 row.operator("view3d.view_axis", text="Back").type = 'BACK'
241 row = col.row()
242 row.operator("view3d.view_axis", text="Left").type = 'LEFT'
243 row.operator("view3d.view_axis", text="Right").type = 'RIGHT'
244 row = col.row()
245 row.operator("view3d.view_axis", text="Top").type = 'TOP'
246 row.operator("view3d.view_axis", text="Bottom").type = 'BOTTOM'
248 # group of 2 buttons
249 col = layout.column(align=True)
250 col.label(text="Lock View to Object:", icon="LOCKED")
251 col.prop(view, "lock_object", text="")
252 col.operator("view3d.view_selected", text="View to Selected")
254 col = layout.column(align=True)
255 col.label(text="Cursor:", icon='PIVOT_CURSOR')
256 row = col.row(align=True)
257 row.operator("view3d.snap_cursor_to_center", text="World Origin")
258 row.operator("view3d.view_center_cursor", text="View")
259 col.operator("view3d.snap_cursor_to_selected", text="Cursor to Selected")
262 class VIEW3D_PT_3dnavigationPanel2(Panel):
263 bl_space_type = "VIEW_3D"
264 bl_region_type = "UI"
265 bl_label = "Pan Orbit Zoom Roll"
266 bl_category = "View"
267 bl_options = {'DEFAULT_CLOSED'}
269 def draw(self, context):
270 layout = self.layout
271 layout.label(text="Screen View Perspective")
273 row = layout.row()
274 row.label(text="Pan:")
275 row = layout.row()
277 row.operator("opr.pan_up_views_all", text="Up",
278 icon="TRIA_UP").panning = "PANDOWN"
279 row.operator("opr.pan_up_views_all", text="Down",
280 icon="TRIA_DOWN").panning = "PANUP"
282 row = layout.row()
283 row.operator("opr.pan_up_views_all", text="Left",
284 icon="BACK").panning = "PANRIGHT"
285 row.operator("opr.pan_up_views_all", text="Right",
286 icon="FORWARD").panning = "PANLEFT"
288 row = layout.row()
289 row.label(text="Orbit:")
290 row = layout.row()
291 row.operator("opr.orbit_down_view1", text="Up", icon="TRIA_UP")
292 row.operator("opr.orbit_up_view1", text="Down", icon="TRIA_DOWN")
294 row = layout.row()
295 row.operator("opr.orbit_right_view1", text="Left", icon="BACK")
296 row.operator("opr.orbit_left_view1", text="Right", icon="FORWARD")
298 row = layout.row()
299 row.label(text="Zoom:")
300 row = layout.row()
301 row.operator("opr.zoom_in_view1", text="In", icon='ADD')
302 row.operator("opr.zoom_out_view1", text="Out", icon='REMOVE')
304 row = layout.row()
305 row.label(text="Roll:")
306 row = layout.row()
307 row.operator("opr.roll_left_view1", text="Left", icon="LOOP_BACK")
308 row.operator("opr.roll_right_view1", text="Right", icon="LOOP_FORWARDS")
311 # Add-ons Preferences Update Panel
313 # Define Panel classes for updating
314 panels = (
315 VIEW3D_PT_3dnavigationPanel,
316 VIEW3D_PT_3dnavigationPanel2,
320 def update_panel(self, context):
321 message = ": Updating Panel locations has failed"
322 try:
323 for panel in panels:
324 if "bl_rna" in panel.__dict__:
325 bpy.utils.unregister_class(panel)
327 for panel in panels:
328 panel.bl_category = context.preferences.addons[__name__].preferences.category
329 bpy.utils.register_class(panel)
331 except Exception as e:
332 print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
333 pass
336 class NavAddonPreferences(AddonPreferences):
337 # this must match the addon name, use '__package__'
338 # when defining this in a submodule of a python package.
339 bl_idname = __name__
341 category: StringProperty(
342 name="Tab Category",
343 description="Choose a name for the category of the panel",
344 default="View",
345 update=update_panel
348 def draw(self, context):
349 layout = self.layout
351 row = layout.row()
352 col = row.column()
353 col.label(text="Tab Category:")
354 col.prop(self, "category", text="")
357 classes = (
358 VIEW3D_PT_3dnavigationPanel,
359 VIEW3D_PT_3dnavigationPanel2,
360 VIEW3D_OT_OrbitUpView1,
361 VIEW3D_OT_OrbitLeftView1,
362 VIEW3D_OT_OrbitRightView1,
363 VIEW3D_OT_OrbitDownView1,
364 VIEW3D_OT_ZoomInView1,
365 VIEW3D_OT_ZoomOutView1,
366 VIEW3D_OT_RollLeftView1,
367 VIEW3D_OT_RollRightView1,
368 VIEW3D_OT_LeftViewpoint1,
369 VIEW3D_OT_RightViewpoint1,
370 VIEW3D_OT_FrontViewpoint1,
371 VIEW3D_OT_BackViewpoint1,
372 VIEW3D_OT_TopViewpoint1,
373 VIEW3D_OT_BottomViewpoint1,
374 VIEW3D_OT_PanUpViewsAll,
375 NavAddonPreferences,
379 # Register
380 def register():
381 for cls in classes:
382 bpy.utils.register_class(cls)
383 update_panel(None, bpy.context)
386 def unregister():
387 for cls in classes:
388 bpy.utils.unregister_class(cls)
391 if __name__ == "__main__":
392 register()