[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3786] branches/protopipe: Started basic gui
Aurel W
aurel.w at gmail.com
Fri Sep 21 20:18:30 CEST 2012
Revision: 3786
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3786
Author: aurel
Date: 2012-09-21 18:18:30 +0000 (Fri, 21 Sep 2012)
Log Message:
-----------
Started basic gui
Multiple ModelBuilder instances at the same time
Object tagging
Delete model/parts
Modified Paths:
--------------
branches/protopipe/__init__.py
branches/protopipe/modelbuilder.py
branches/protopipe/ppapp.py
Added Paths:
-----------
branches/protopipe/ui.py
Modified: branches/protopipe/__init__.py
===================================================================
--- branches/protopipe/__init__.py 2012-09-21 10:33:58 UTC (rev 3785)
+++ branches/protopipe/__init__.py 2012-09-21 18:18:30 UTC (rev 3786)
@@ -23,8 +23,8 @@
bl_info = {
"name": "ProtoPipe",
"author": "Aurel Wildfellner",
- "version": (0, 0),
- "blender": (2, 6, 3),
+ "version": (0, 1),
+ "blender": (2, 6, 4),
"location": "View3D > Tool Panel",
"description": "An interactive CAM tool to build objects out of pipes.",
"warning": "",
@@ -34,22 +34,28 @@
}
-
+# to properly support reloads
if "bpy" in locals():
import imp
- imp.reload(bpy)
+ imp.reload(ppapp)
else:
- import bpy
+ from . import ppapp
-from . import ppapp
+
+import bpy
from bpy.app.handlers import persistent
+from protopipe import ui
+from protopipe.ppapp import ppApp
+print("|====| Init ProtoPipe |====| (r12)")
+
+
@persistent
def postLoad(arg):
""" Handler which gets called post blend load. """
print("ProtoPipe post load handler.")
- ppapp.initFactories()
+ ppApp.initFactories()
def register():
@@ -57,6 +63,10 @@
# after the blend file is loaded
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)
def unregister():
Modified: branches/protopipe/modelbuilder.py
===================================================================
--- branches/protopipe/modelbuilder.py 2012-09-21 10:33:58 UTC (rev 3785)
+++ branches/protopipe/modelbuilder.py 2012-09-21 18:18:30 UTC (rev 3786)
@@ -22,7 +22,9 @@
import math
-from protopipe import ppapp
+
+import protopipe.ppapp
+
from protopipe.utils import *
from protopipe.jointproto import JointProto
@@ -40,6 +42,8 @@
class ModelBuilder:
+ nextID = 0
+
def __init__(self, obj):
# the object to build
self.baseObj = obj
@@ -50,11 +54,20 @@
self.modelObjects = []
self.partList = PartList()
+ # an id which is used to reference this instance
+ #FIXME proper generator
+ self.uID = ModelBuilder.nextID
+ ModelBuilder.nextID += 1
+
# generating the name for new objects
self.nextJointName = self.nextJointNameGen().__next__
self.nextPipeName = self.nextPipeNameGen().__next__
+ def uniqueID(self):
+ return self.uID
+
+
def buildOnMesh(self):
bm = bmesh.new()
bm.from_mesh(self.baseObj.data)
@@ -69,7 +82,7 @@
for vert in bm.verts:
desc = JointDescriptor()
desc.buildFromVert(bm, vert.index)
- (reg, jr) = ppapp.jointFactory.getProto(desc)
+ (reg, jr) = protopipe.ppapp.jointFactory.getProto(desc)
if reg:
self.insertJoint(vert.co, jr)
@@ -106,7 +119,7 @@
desc = PipeDescriptor(plength, self.defaultDiameter)
# get a new pipe
- (isreg, pipeReg) = ppapp.pipeFactory.getProto(desc)
+ (isreg, pipeReg) = protopipe.ppapp.pipeFactory.getProto(desc)
self.insertPipe(vert.co, vec, pipeReg)
### process the partlist ###
@@ -131,6 +144,8 @@
model.name = self.nextJointName()
self.modelObjects.append(model)
self.partList.addPart(jr.part)
+ # add am id to reference the model builder of origin
+ model['pp_modelBuilder_id'] = self.uID
def insertPipe(self, co, vec, pipeReg):
@@ -152,8 +167,22 @@
model.name = self.nextPipeName()
self.modelObjects.append(model)
self.partList.addPart(pipeReg.part)
+ # add am id to reference the model builder of origin
+ model['pp_modelBuilder_id'] = self.uID
+ def clear(self):
+ # clear partlist
+ self.partList = PartList()
+
+ # delete all the models
+ for obj in self.modelObjects:
+ bpy.context.scene.objects.unlink(obj)
+ bpy.data.objects.remove(obj)
+ self.modelObjects = []
+
+
+
def nextJointNameGen(self):
i = 0
while True:
@@ -165,5 +194,6 @@
i = 0
while True:
yield self.baseObj.name + "_p" + str(i)
+ i += 1
Modified: branches/protopipe/ppapp.py
===================================================================
--- branches/protopipe/ppapp.py 2012-09-21 10:33:58 UTC (rev 3785)
+++ branches/protopipe/ppapp.py 2012-09-21 18:18:30 UTC (rev 3786)
@@ -26,6 +26,8 @@
from protopipe.pipeproto import PipeFactory
from protopipe.pipeproto import PipeGenerator
+from protopipe import modelbuilder
+
import protopipe.utils
@@ -34,22 +36,52 @@
pipeFactory = None
-def initFactories():
- global jointFactory, pipeFactory
- jointFactory = JointFactory()
- loadLibs()
+class PPApp:
- pipeFactory = PipeFactory()
- pipegen = PipeGenerator()
- pipeFactory.addPipeProvider(pipegen)
+ def __init__(self):
+ self.modelBuilders = {}
+ pass
+ def initFactories(self):
+ global jointFactory, pipeFactory
-def loadLibs():
- global jointFactory
- jointLib = ProtoLibrary()
- jointLib.loadFromScene("pp_40mmpvc")
- jointFactory.addJointProtoProvider(jointLib)
+ jointFactory = JointFactory()
+ self.loadLibs()
+ pipeFactory = PipeFactory()
+ pipegen = PipeGenerator()
+ pipeFactory.addPipeProvider(pipegen)
+ def loadLibs(self):
+ global jointFactory
+ jointLib = ProtoLibrary()
+ jointLib.loadFromScene("pp_40mmpvc")
+ jointFactory.addJointProtoProvider(jointLib)
+
+
+ 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.buildOnMesh()
+ else:
+ 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):
+
+ if "pp_modelBuilder_id" in obj:
+ mb = self.modelBuilders[obj['pp_modelBuilder_id']]
+ mb.clear()
+
+
+#global instance for app object
+ppApp = PPApp()
Added: branches/protopipe/ui.py
===================================================================
--- branches/protopipe/ui.py (rev 0)
+++ branches/protopipe/ui.py 2012-09-21 18:18:30 UTC (rev 3786)
@@ -0,0 +1,60 @@
+#
+# Copyright 2012, Aurel Wildfellner.
+#
+# 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.
+#
+
+
+import bpy
+
+from protopipe.ppapp import ppApp
+
+
+class ToolPanel(bpy.types.Panel):
+ bl_space_type = "VIEW_3D"
+ bl_region_type = "UI"
+ bl_label = "ProtoPipe"
+
+ def draw(self, context):
+ layout = self.layout
+ layout.operator("protopipe.build_on_object", text='Build')
+ layout.operator("protopipe.remove_parts", text='Remove Parts')
+
+
+
+
+class VIEW3D_OT_BuildOnObject(bpy.types.Operator):
+ bl_idname = "protopipe.build_on_object"
+ bl_label = "Build pipe proto on mesh object"
+
+ def execute(self, context):
+ obj = context.active_object
+ ppApp.buildOnObject(obj)
+
+ return {"FINISHED"}
+
+
+
+
+class VIEW3D_OT_RemoveParts(bpy.types.Operator):
+ bl_idname = "protopipe.remove_parts"
+ bl_label = "Remove all parts of the current build."
+
+ def execute(self, context):
+ obj = context.active_object
+ ppApp.removeParts(obj)
+
+ return {"FINISHED"}
+
More information about the Bf-extensions-cvs
mailing list