[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3787] branches/protopipe: List View UI

Aurel W aurel.w at gmail.com
Mon Sep 24 02:18:29 CEST 2012


Revision: 3787
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3787
Author:   aurel
Date:     2012-09-24 00:18:27 +0000 (Mon, 24 Sep 2012)
Log Message:
-----------
List View UI

Modified Paths:
--------------
    branches/protopipe/__init__.py
    branches/protopipe/jointproto.py
    branches/protopipe/modelbuilder.py
    branches/protopipe/parts.py
    branches/protopipe/pipeproto.py
    branches/protopipe/ppapp.py
    branches/protopipe/ui.py

Added Paths:
-----------
    branches/protopipe/NOTES

Added: branches/protopipe/NOTES
===================================================================
--- branches/protopipe/NOTES	                        (rev 0)
+++ branches/protopipe/NOTES	2012-09-24 00:18:27 UTC (rev 3787)
@@ -0,0 +1,4 @@
+Examples and Snippets:
+    * Screencast Addon for gl drawing
+    * material tools/menu for simple view3d menu
+    * bpy.props.CollectionPropertie for all available providers

Modified: branches/protopipe/__init__.py
===================================================================
--- branches/protopipe/__init__.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/__init__.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -48,6 +48,7 @@
 from protopipe import ui
 from protopipe.ppapp import ppApp
 
+
 print("|====| Init ProtoPipe |====| (r12)")
 
 
@@ -64,9 +65,7 @@
     bpy.app.handlers.load_post.append(postLoad)
 
     ### register ui elemtents and operators ###
-    bpy.utils.register_class(ui.ToolPanel)
-    bpy.utils.register_class(ui.VIEW3D_OT_BuildOnObject)
-    bpy.utils.register_class(ui.VIEW3D_OT_RemoveParts)
+    ui.register()
 
 
 def unregister():

Modified: branches/protopipe/jointproto.py
===================================================================
--- branches/protopipe/jointproto.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/jointproto.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -213,7 +213,7 @@
     modelInstance - A mesh object for the joint.
     """
 
-    def __init__(self, jproto, descriptor, rot_mat, mapping, modelInstance=None, part=Part()):
+    def __init__(self, jproto, descriptor, rot_mat, mapping, modelInstance=None, part=None):
         self.rot_mat = rot_mat
         self.mapping = mapping
         self.jproto = jproto
@@ -340,6 +340,7 @@
 
 
     def loadPart(self, jr):
+        jr.part = Part()
         jr.part.partType = PartType.JOINT
         if 'pp_mass' in jr.jproto.model.id_data:
             jr.part.mass = jr.jproto.model["pp_mass"]

Modified: branches/protopipe/modelbuilder.py
===================================================================
--- branches/protopipe/modelbuilder.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/modelbuilder.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -42,7 +42,6 @@
 
 class ModelBuilder:
 
-    nextID = 0
 
     def __init__(self, obj):
         # the object to build 
@@ -56,12 +55,11 @@
 
         # an id which is used to reference this instance
         #FIXME proper generator
-        self.uID = ModelBuilder.nextID
-        ModelBuilder.nextID += 1
+        self.uID = ModelBuilder.nextID()
 
         # generating the name for new objects
-        self.nextJointName = self.nextJointNameGen().__next__
-        self.nextPipeName = self.nextPipeNameGen().__next__
+        self.nJointI = 0
+        self.nPipeI = 0
 
 
     def uniqueID(self):
@@ -108,7 +106,10 @@
         ### for every edge try to add a pipe ###
         for edge in bm.edges:
             # the physical length of the pipe:
-            plength = edge.calc_length() - sum(pipeLengths[edge.index])
+            sub = 0
+            if edge.index in pipeLengths.keys():
+                sub = sum(pipeLengths[edge.index])
+            plength = edge.calc_length() - sub
             #FIXME handle minimum length
             vert = edge.verts[0]
             vec = edge.verts[1].co - vert.co
@@ -124,6 +125,7 @@
 
         ### process the partlist ###
         self.partList.computeStats()
+        self.partList.exportToSceneProperty()
         print("Build Mass: ", self.partList.mass, "g") 
         print("Build Cost: ", self.partList.cost, "€") 
             
@@ -142,6 +144,7 @@
         model.rotation_euler = bmat.to_euler()
         # set the name
         model.name = self.nextJointName()
+        jr.part.partName = model.name
         self.modelObjects.append(model)
         self.partList.addPart(jr.part)
         # add am id to reference the model builder of origin
@@ -165,6 +168,7 @@
         model.rotation_axis_angle = [aangle, aavec[0], aavec[1], aavec[2]]
         # - Bake that Cake!
         model.name = self.nextPipeName()
+        pipeReg.part.partName = model.name
         self.modelObjects.append(model)
         self.partList.addPart(pipeReg.part)
         # add am id to reference the model builder of origin
@@ -173,8 +177,13 @@
 
     def clear(self):
         # clear partlist
+        self.partList.clearSceneProperty()
         self.partList = PartList()
 
+        # clear name gernators
+        self.nJointI = 0
+        self.nPipeI = 0
+
         # delete all the models 
         for obj in self.modelObjects:
             bpy.context.scene.objects.unlink(obj)
@@ -182,18 +191,23 @@
         self.modelObjects = []
 
 
+    def nextJointName(self):
+        s = self.baseObj.name + "_j" + str(self.nJointI)
+        self.nJointI += 1
+        return s
 
-    def nextJointNameGen(self):
-        i = 0
-        while True:
-            yield self.baseObj.name + "_j" + str(i)
-            i += 1
 
+    def nextPipeName(self):
+        s =  self.baseObj.name + "_p" + str(self.nPipeI)
+        self.nPipeI += 1
+        return s
 
-    def nextPipeNameGen(self):
+
+    def nextIDGen():
         i = 0
         while True:
-            yield self.baseObj.name + "_p" + str(i)
+            yield i
             i += 1
+    nextID = nextIDGen().__next__
 
 

Modified: branches/protopipe/parts.py
===================================================================
--- branches/protopipe/parts.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/parts.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -16,6 +16,8 @@
 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 #
 
+import bpy
+
 class PartType:
     NONE = 0
     JOINT = 1
@@ -53,6 +55,8 @@
 
     def addPart(self, part):
         self.parts.append(part)
+        self.mass = 0.0
+        self.cost = 0.0
 
 
     def computeStats(self):
@@ -68,4 +72,37 @@
         return compactList
 
 
+    def exportToSceneProperty(self):
+        self.clearSceneProperty()
+        for part in self.parts:
+            pListItem = bpy.context.scene.pp_part_list.add()
+            pListItem.name = self.partNameToUiName(part.partName)
+            pListItem.proto_name = part.protoName
+            pListItem.cost = part.cost
+            pListItem.mass = part.mass
+            pListItem.length = part.length
 
+
+    def clearSceneProperty(self):
+        bpy.context.scene.pp_part_list.clear()
+
+
+    def partNameToUiName(self, name):
+        return name.split("_").pop()
+
+
+    def getPartIndex(self, obj):
+        if "pp_modelBuilder_id" in obj:
+            for (i, part) in enumerate(self.parts):
+                if part.partName == obj.name:
+                    return i
+        return -1
+
+
+    def getNameFromIndex(self, idx):
+        return self.parts[idx].partName
+            
+        
+
+
+

Modified: branches/protopipe/pipeproto.py
===================================================================
--- branches/protopipe/pipeproto.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/pipeproto.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -71,7 +71,7 @@
     No transformation to a mesh-edge is specified.
     """
 
-    def __init__(self, pipeProto, descriptor, modelInstance=None, part=Part()):
+    def __init__(self, pipeProto, descriptor, modelInstance=None, part=None):
         self.descriptor = descriptor
         self.pipeProto = pipeProto
         self.modeInstance = modelInstance
@@ -103,12 +103,13 @@
         pReg.modelInstance = pReg.pipeProto.model
         if isreg:
             ### process the registration further in terms of the generator ###ä
+            pReg.part = Part()
             pReg.part.partType = PartType.PIPE
             pReg.part.length = descriptor.length
             #FIXME compute this properly from physical properties
             #FIXME query pipeRegister rather than descriptor
             pReg.part.cost = descriptor.length * 0.5
-            pReg.part.weight = descriptor.length * 70
+            pReg.part.mass = descriptor.length * 70
             pReg.part.protoName = pReg.pipeProto.name
 
             return (True, pReg)

Modified: branches/protopipe/ppapp.py
===================================================================
--- branches/protopipe/ppapp.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/ppapp.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -63,25 +63,33 @@
 
     def buildOnObject(self, obj):
         # the model builder
-        mb = None
-        if "pp_modelBuilder_id" in obj:
-            mb_id = obj['pp_modelBuilder_id']
-            mb = self.modelBuilders[mb_id]
+        mb = self.getModelBuilder(obj)
+        if mb != None:
             mb.buildOnMesh()
-        else:
-            mb = modelbuilder.ModelBuilder(obj)
-            self.modelBuilders[mb.uniqueID()] = mb
-            obj['pp_modelBuilder_id'] = mb.uniqueID()
-            obj['pp_modelBuilder_isBase'] = True
-            mb.buildOnMesh()
+            return
 
+        mb = modelbuilder.ModelBuilder(obj)
+        self.modelBuilders[mb.uniqueID()] = mb
+        obj['pp_modelBuilder_id'] = mb.uniqueID()
+        obj['pp_modelBuilder_isBase'] = True
+        mb.buildOnMesh()
 
+
     def removeParts(self, obj):
+        mb = self.getModelBuilder(obj)
+        if mb != None:
+            mb.clear()
 
+
+    def getModelBuilder(self, obj):
+        mb = None
         if "pp_modelBuilder_id" in obj:
-            mb = self.modelBuilders[obj['pp_modelBuilder_id']]
-            mb.clear()
+            mb_id = obj['pp_modelBuilder_id']
+            if mb_id in self.modelBuilders.keys():
+                mb = self.modelBuilders[mb_id]
+        return mb
 
 
+
 #global instance for app object
 ppApp = PPApp()

Modified: branches/protopipe/ui.py
===================================================================
--- branches/protopipe/ui.py	2012-09-21 18:18:30 UTC (rev 3786)
+++ branches/protopipe/ui.py	2012-09-24 00:18:27 UTC (rev 3787)
@@ -18,7 +18,10 @@
 
 
 import bpy
+from bpy.props import *
+from bpy.app.handlers import persistent
 
+
 from protopipe.ppapp import ppApp
 
 
@@ -31,10 +34,40 @@
         layout = self.layout
         layout.operator("protopipe.build_on_object", text='Build')
         layout.operator("protopipe.remove_parts", text='Remove Parts')
+        #layout.operator("protopipe.detail_view", text='Details')
+        
+        row = layout.row()
 
 
 
+class DetailPanel(bpy.types.Panel):
+    bl_label = "ProtoPipe"
+    bl_space_type = "PROPERTIES"

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list