[Bf-extensions-cvs] [487d7bad] master: space_view3d_stored_views: moved to contrib: T63750
meta-androcto
noreply at git.blender.org
Fri May 24 02:08:14 CEST 2019
Commit: 487d7bad9264707ea03b68f0636c048778025167
Author: meta-androcto
Date: Fri May 24 10:07:52 2019 +1000
Branches: master
https://developer.blender.org/rBAC487d7bad9264707ea03b68f0636c048778025167
space_view3d_stored_views: moved to contrib: T63750
===================================================================
A space_view3d_stored_views/__init__.py
A space_view3d_stored_views/core.py
A space_view3d_stored_views/io.py
A space_view3d_stored_views/operators.py
A space_view3d_stored_views/properties.py
A space_view3d_stored_views/ui.py
===================================================================
diff --git a/space_view3d_stored_views/__init__.py b/space_view3d_stored_views/__init__.py
new file mode 100644
index 00000000..aae9add7
--- /dev/null
+++ b/space_view3d_stored_views/__init__.py
@@ -0,0 +1,138 @@
+# ##### BEGIN GPL LICENSE BLOCK #####
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software Foundation,
+# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ##### END GPL LICENSE BLOCK #####
+
+bl_info = {
+ "name": "Stored Views",
+ "description": "Save and restore User defined views, pov, layers and display configs",
+ "author": "nfloyd, Francesco Siddi",
+ "version": (0, 3, 7),
+ "blender": (2, 78, 0),
+ "location": "View3D > Properties > Stored Views",
+ "warning": "",
+ "wiki_url": "https://wiki.blender.org/index.php/Extensions:2.5/"
+ "Py/Scripts/3D_interaction/stored_views",
+ "category": "3D View"
+}
+
+"""
+ACKNOWLEDGMENT
+==============
+import/export functionality is mostly based
+on Bart Crouch's Theme Manager Addon
+
+TODO: quadview complete support : investigate. Where's the data?
+TODO: lock_camera_and_layers. investigate usage
+TODO: list reordering
+
+NOTE: logging setup has to be provided by the user in a separate config file
+ as Blender will not try to configure logging by default in an add-on
+ The Config File should be in the Blender Config folder > /scripts/startup/config_logging.py
+ For setting up /location of the config folder see:
+ https://docs.blender.org/manual/en/dev/getting_started/
+ installing/configuration/directories.html
+ For configuring logging itself in the file, general Python documentation should work
+ As the logging calls are not configured, they can be kept in the other modules of this add-on
+ and will not have output until the logging configuration is set up
+"""
+
+if "bpy" in locals():
+ import importlib
+ importlib.reload(core)
+ importlib.reload(ui)
+ importlib.reload(properties)
+ importlib.reload(operators)
+ importlib.reload(io)
+else:
+ from . import core
+ from . import ui
+ from . import properties
+ from . import operators
+ from . import io
+
+import bpy
+from bpy.props import (
+ BoolProperty,
+ IntProperty,
+ PointerProperty,
+)
+from bpy.types import (
+ AddonPreferences,
+ Operator,
+)
+
+
+class VIEW3D_stored_views_initialize(Operator):
+ bl_idname = "view3d.stored_views_initialize"
+ bl_label = "Initialize"
+
+ @classmethod
+ def poll(cls, context):
+ return not hasattr(bpy.types.Scene, 'stored_views')
+
+ def execute(self, context):
+ bpy.types.Scene.stored_views = PointerProperty(
+ type=properties.StoredViewsData
+ )
+ scenes = bpy.data.scenes
+ for scene in scenes:
+ core.DataStore.sanitize_data(scene)
+ return {'FINISHED'}
+
+
+# Addon Preferences
+
+class VIEW3D_stored_views_preferences(AddonPreferences):
+ bl_idname = __name__
+
+ show_exporters: BoolProperty(
+ name="Enable I/O Operators",
+ default=False,
+ description="Enable Import/Export Operations in the UI:\n"
+ "Import Stored Views preset,\n"
+ "Export Stored Views preset and \n"
+ "Import stored views from scene",
+ )
+ view_3d_update_rate: IntProperty(
+ name="3D view update",
+ description="Update rate of the 3D view redraw\n"
+ "Increse the value if the UI feels sluggish",
+ min=1, max=10,
+ default=1
+ )
+
+ def draw(self, context):
+ layout = self.layout
+
+ row = layout.row(align=True)
+ row.prop(self, "view_3d_update_rate", toggle=True)
+ row.prop(self, "show_exporters", toggle=True)
+
+
+def register():
+ bpy.utils.register_module(__name__)
+
+
+def unregister():
+ ui.VIEW3D_stored_views_draw.handle_remove(bpy.context)
+ bpy.utils.unregister_module(__name__)
+ if hasattr(bpy.types.Scene, "stored_views"):
+ del bpy.types.Scene.stored_views
+
+
+if __name__ == "__main__":
+ register()
diff --git a/space_view3d_stored_views/core.py b/space_view3d_stored_views/core.py
new file mode 100644
index 00000000..d7fb72b8
--- /dev/null
+++ b/space_view3d_stored_views/core.py
@@ -0,0 +1,369 @@
+# gpl authors: nfloyd, Francesco Siddi
+
+
+import logging
+module_logger = logging.getLogger(__name__)
+
+import hashlib
+import bpy
+
+
+# Utility function get preferences setting for exporters
+def get_preferences():
+ # replace the key if the add-on name changes
+ addon = bpy.context.preferences.addons[__package__]
+ show_warn = (addon.preferences.show_exporters if addon else False)
+
+ return show_warn
+
+
+class StoredView():
+ def __init__(self, mode, index=None):
+ self.logger = logging.getLogger('%s.StoredView' % __name__)
+ self.scene = bpy.context.scene
+ self.view3d = bpy.context.space_data
+ self.index = index
+ self.data_store = DataStore(mode=mode)
+
+ def save(self):
+ if self.index == -1:
+ stored_view, self.index = self.data_store.create()
+ else:
+ stored_view = self.data_store.get(self.index)
+ self.from_v3d(stored_view)
+ self.logger.debug('index: %s name: %s' % (self.data_store.current_index, stored_view.name))
+
+ def set(self):
+ stored_view = self.data_store.get(self.index)
+ self.update_v3d(stored_view)
+ self.logger.debug('index: %s name: %s' % (self.data_store.current_index, stored_view.name))
+
+ def from_v3d(self, stored_view):
+ raise NotImplementedError("Subclass must implement abstract method")
+
+ def update_v3d(self, stored_view):
+ raise NotImplementedError("Subclass must implement abstract method")
+
+ @staticmethod
+ def is_modified(context, stored_view):
+ raise NotImplementedError("Subclass must implement abstract method")
+
+
+class POV(StoredView):
+ def __init__(self, index=None):
+ super().__init__(mode='POV', index=index)
+ self.logger = logging.getLogger('%s.POV' % __name__)
+
+ def from_v3d(self, stored_view):
+ view3d = self.view3d
+ region3d = view3d.region_3d
+
+ stored_view.distance = region3d.view_distance
+ stored_view.location = region3d.view_location
+ stored_view.rotation = region3d.view_rotation
+ stored_view.perspective_matrix_md5 = POV._get_perspective_matrix_md5(region3d)
+ stored_view.perspective = region3d.view_perspective
+ stored_view.lens = view3d.lens
+ stored_view.clip_start = view3d.clip_start
+ stored_view.clip_end = view3d.clip_end
+
+ if region3d.view_perspective == 'CAMERA':
+ stored_view.camera_type = view3d.camera.type # type : 'CAMERA' or 'MESH'
+ stored_view.camera_name = view3d.camera.name # store string instead of object
+ if view3d.lock_object is not None:
+ stored_view.lock_object_name = view3d.lock_object.name # idem
+ else:
+ stored_view.lock_object_name = ""
+ stored_view.lock_cursor = view3d.lock_cursor
+ stored_view.cursor_location = view3d.cursor_location
+
+ def update_v3d(self, stored_view):
+ view3d = self.view3d
+ region3d = view3d.region_3d
+ region3d.view_distance = stored_view.distance
+ region3d.view_location = stored_view.location
+ region3d.view_rotation = stored_view.rotation
+ region3d.view_perspective = stored_view.perspective
+ view3d.lens = stored_view.lens
+ view3d.clip_start = stored_view.clip_start
+ view3d.clip_end = stored_view.clip_end
+ view3d.lock_cursor = stored_view.lock_cursor
+ if stored_view.lock_cursor is True:
+ # update cursor only if view is locked to cursor
+ view3d.cursor_location = stored_view.cursor_location
+
+ if stored_view.perspective == "CAMERA":
+
+ lock_obj = self._get_object(stored_view.lock_object_name)
+ if lock_obj:
+ view3d.lock_object = lock_obj
+ else:
+ cam = self._get_object(stored_view.camera_name)
+ if cam:
+ view3d.camera = cam
+
+ @staticmethod
+ def _get_object(name, pointer=None):
+ return bpy.data.objects.get(name)
+
+ @staticmethod
+ def is_modified(context, stored_view):
+ # TODO: check for others param, currently only perspective
+ # and perspective_matrix are checked
+ POV.logger = logging.getLogger('%s.POV' % __name__)
+ view3d = context.space_data
+ region3d = view3d.region_3d
+ if region3d.view_perspective != stored_view.perspective:
+ POV.logger.debug('view_perspective')
+ return True
+
+ md5 = POV._get_perspective_matrix_md5(region3d)
+ if (md5 != stored_view.perspective_matrix_md5 and
+ region3d.view_perspective != "CAMERA"):
+ POV.logger.debug('perspective_matrix')
+ return True
+
+ return False
+
+ @staticmethod
+ def _get_perspective_matrix_md5(region3d):
+ md5 = hashlib.md5(str(region3d.perspective_matrix).encode('utf-8')).hexdigest()
+ return md5
+
+
+class Layers(StoredView):
+ def __init__(self, index=None):
+ super().__init__(mode='LAYERS', index=index)
+ self.logger = logging.getLogger('%s.Layers' % __name__)
+
+ def from_v3d(self, stored_view):
+ view3d = self.view3d
+ stored_view.view_layers =
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list