[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2386] Cursor Control 0.7.0

Morgan Mörtsell morgan at mortsell.com
Sun Oct 2 19:02:02 CEST 2011


Revision: 2386
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2386
Author:   seminumerical
Date:     2011-10-02 17:02:02 +0000 (Sun, 02 Oct 2011)
Log Message:
-----------
Cursor Control 0.7.0
Refactoring: Merged from three into one addon
Refactoring: Renamed module 'Control' to 'Target'
New features: Added 'Cursor Delta'
Bugfix: Cursor History now tracks even when its panel is folded.

Modified Paths:
--------------
    trunk/py/scripts/addons/modules/geometry_utils.py

Added Paths:
-----------
    contrib/py/scripts/addons/cursor_control/
    contrib/py/scripts/addons/cursor_control/__init__.py
    contrib/py/scripts/addons/cursor_control/data.py
    contrib/py/scripts/addons/cursor_control/history.py
    contrib/py/scripts/addons/cursor_control/memory.py
    contrib/py/scripts/addons/cursor_control/operators.py
    contrib/py/scripts/addons/cursor_control/ui.py

Removed Paths:
-------------
    contrib/py/scripts/addons/space_3dview_cursor_control.py
    contrib/py/scripts/addons/space_3dview_cursor_history.py
    contrib/py/scripts/addons/space_3dview_cursor_memory.py

Added: contrib/py/scripts/addons/cursor_control/__init__.py
===================================================================
--- contrib/py/scripts/addons/cursor_control/__init__.py	                        (rev 0)
+++ contrib/py/scripts/addons/cursor_control/__init__.py	2011-10-02 17:02:02 UTC (rev 2386)
@@ -0,0 +1,73 @@
+# -*- coding: utf-8 -*-
+# ##### 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 #####
+
+
+
+# Blender Add-Ons menu registration (in User Prefs)
+bl_info = {
+    'name': 'Cursor Control',
+    'author': 'Morgan Mörtsell (Seminumerical)',
+    'version': (0, 7, 0),
+    'blender': (2, 5, 9),
+    'api': 39307,
+    'location': 'View3D > Properties > Cursor',
+    'description': 'Control the Cursor',
+    'warning': '', # used for warning icon and text in addons panel
+    'wiki_url': 'http://blenderpythonscripts.wordpress.com/',
+    'tracker_url': '',
+    'category': '3D View'}
+
+
+
+import bpy
+
+# To support reload properly, try to access a package var, if it's there, reload everything
+if "local_var" in locals():
+    import imp
+    imp.reload(data)
+    imp.reload(ui)
+    imp.reload(operators)
+    imp.reload(history)
+    imp.reload(memory)
+else:
+    from cursor_control import data
+    from cursor_control import ui
+    from cursor_control import operators
+    from cursor_control import history
+    from cursor_control import memory
+
+local_var = True
+
+def register():
+    bpy.utils.register_module(__name__)
+    # Register Cursor Control Structure
+    bpy.types.Scene.cursor_control = bpy.props.PointerProperty(type=data.CursorControlData, name="")
+    bpy.types.Scene.cursor_history = bpy.props.PointerProperty(type=history.CursorHistoryData, name="")
+    bpy.types.Scene.cursor_memory  = bpy.props.PointerProperty(type=memory.CursorMemoryData, name="")
+    # Register menu
+    bpy.types.VIEW3D_MT_snap.append(ui.menu_callback)
+
+def unregister():
+    # Register menu
+    bpy.types.VIEW3D_MT_snap.remove(ui.menu_callback)
+    bpy.utils.unregister_module(__name__)
+
+
+if __name__ == "__main__":
+    register()

Added: contrib/py/scripts/addons/cursor_control/data.py
===================================================================
--- contrib/py/scripts/addons/cursor_control/data.py	                        (rev 0)
+++ contrib/py/scripts/addons/cursor_control/data.py	2011-10-02 17:02:02 UTC (rev 2386)
@@ -0,0 +1,120 @@
+# -*- coding: utf-8 -*-
+# ##### 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 #####
+
+
+
+"""
+  TODO:
+
+      IDEAS:
+
+      LATER:
+
+      ISSUES:
+          Bugs:
+          Mites:
+
+      QUESTIONS:
+
+
+"""
+
+
+
+import bpy
+import bgl
+import math
+from mathutils import Vector, Matrix
+from mathutils import geometry
+from misc_utils import *
+from constants_utils import *
+from cursor_utils import *
+from ui_utils import *
+from geometry_utils import *
+
+
+PRECISION = 4
+
+
+class CursorControlData(bpy.types.PropertyGroup):
+    # Step length properties
+    stepLengthEnable = bpy.props.BoolProperty(name="Use step length",description="Use step length",default=0)
+    stepLengthMode = bpy.props.EnumProperty(items=[
+        ("Mode", "Mode", "Mode"),
+        ("Absolute", "Absolute", "Absolute"),
+        ("Proportional", "Proportional", "Proportional")],
+        default="Proportional")
+    stepLengthValue = bpy.props.FloatProperty(name="",precision=PRECISION,default=PHI)
+    # Property for linex result select...
+    linexChoice = bpy.props.IntProperty(name="",default=-1)
+    deltaVector = bpy.props.FloatVectorProperty(name="",precision=PRECISION,default=(1,0,0))
+
+    def hideLinexChoice(self):
+        self.linexChoice = -1
+
+    def cycleLinexCoice(self,limit):
+        qc = self.linexChoice + 1
+        if qc<0:
+            qc = 1
+        if qc>=limit:
+            qc = 0
+        self.linexChoice = qc
+  
+    def setCursor(self,v):
+        if self.stepLengthEnable:
+            c = CursorAccess.getCursor()
+            if((Vector(c)-Vector(v)).length>0):
+                if self.stepLengthMode=='Absolute':
+                    v = Vector(v)-Vector(c)
+                    v.normalize()
+                    v = v*self.stepLengthValue + Vector(c)
+                if self.stepLengthMode=='Proportional':
+                    v = (Vector(v)-Vector(c))*self.stepLengthValue + Vector(c)
+        CursorAccess.setCursor(Vector(v))
+        
+    def guiStates(self,context):
+        tvs = 0
+        tes = 0
+        tfs = 0
+        edit_mode = False
+        obj = context.active_object
+        if (context.mode == 'EDIT_MESH'):
+            if (obj and obj.type=='MESH' and obj.data):
+                tvs = obj.data.total_vert_sel
+
+                tes = obj.data.total_edge_sel
+                tfs = obj.data.total_face_sel
+                edit_mode = True
+        return (tvs, tes, tfs, edit_mode)
+
+    def invertDeltaVector(self):
+      self.deltaVector = Vector([0,0,0])-Vector(self.deltaVector)
+
+    def normalizeDeltaVector(self):
+      q = Vector(self.deltaVector)
+      q.normalize()
+      self.deltaVector = q
+
+    def addDeltaVectorToCursor(self):
+      c = CursorAccess.getCursor()
+      CursorAccess.setCursor(Vector(c)+Vector(self.deltaVector))
+
+    def subDeltaVectorToCursor(self):
+      c = CursorAccess.getCursor()
+      CursorAccess.setCursor(Vector(c)-Vector(self.deltaVector))

Added: contrib/py/scripts/addons/cursor_control/history.py
===================================================================
--- contrib/py/scripts/addons/cursor_control/history.py	                        (rev 0)
+++ contrib/py/scripts/addons/cursor_control/history.py	2011-10-02 17:02:02 UTC (rev 2386)
@@ -0,0 +1,288 @@
+# -*- coding: utf-8 -*-
+# ##### 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 #####
+
+
+
+"""
+  TODO:
+
+      IDEAS:
+
+      LATER:
+
+      ISSUES:
+          Bugs:
+              Seg-faults when unregistering addon...
+          Mites:
+            * History back button does not light up on first cursor move.
+              It does light up on the second, or when mouse enters the tool-area
+            * Switching between local and global view triggers new cursor position in history trace.
+            * Each consecutive click on the linex operator triggers new cursor position in history trace.
+                 (2011-01-16) Was not able to fix this because of some strange script behaviour
+                              while trying to clear linexChoice from addHistoryLocation
+
+      QUESTIONS:
+
+
+
+"""
+
+
+
+import bpy
+import bgl
+import math
+from mathutils import Vector, Matrix
+from mathutils import geometry
+from misc_utils import *
+from constants_utils import *
+from cursor_utils import *
+from ui_utils import *
+
+
+
+class CursorHistoryData(bpy.types.PropertyGroup):
+    # History tracker
+    historyDraw = bpy.props.BoolProperty(description="Draw history trace in 3D view",default=1)
+    historyDepth = 144
+    historyWindow = 12
+    historyPosition = [-1] # Integer must be in a list or else it can not be written to
+    historyLocation = []
+    #historySuppression = [False] # Boolean must be in a list or else it can not be written to
+
+    def addHistoryLocation(self, l):
+        if(self.historyPosition[0]==-1):
+            self.historyLocation.append(l.copy())
+            self.historyPosition[0]=0
+            return
+        if(l==self.historyLocation[self.historyPosition[0]]):
+            return
+        #if self.historySuppression[0]:
+            #self.historyPosition[0] = self.historyPosition[0] - 1
+        #else:
+            #self.hideLinexChoice()
+        while(len(self.historyLocation)>self.historyPosition[0]+1):
+            self.historyLocation.pop(self.historyPosition[0]+1)
+        #self.historySuppression[0] = False
+        self.historyLocation.append(l.copy())
+        if(len(self.historyLocation)>self.historyDepth):
+            self.historyLocation.pop(0)
+        self.historyPosition[0] = len(self.historyLocation)-1
+        #print (self.historyLocation)
+
+    #def enableHistorySuppression(self):
+        #self.historySuppression[0] = True
+
+    def previousLocation(self):
+        if(self.historyPosition[0]<=0):
+            return

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list