[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4178] contrib/py/scripts/addons/ io_atomblend_utilities:

Clemens Barth barth at root-1.de
Sat Jan 19 22:36:39 CET 2013


Revision: 4178
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4178
Author:   blendphys
Date:     2013-01-19 21:36:32 +0000 (Sat, 19 Jan 2013)
Log Message:
-----------

1. New feature: The shape of the atoms (object types like sphere, cube, etc.) can
now be changed! Example: the PDB and XYZ importer always use spheres (mesh, 
NURBS or meta) for representing atoms. Now, these objects can be changed to:
cubes, spheres, icospheres, torus and many others. This is very nice since now 
there is much more freedom in representing atomic structures.

2. A 'hidden bug' could be removed: When accessing all selected objects via
bpy.context.selected_objects, BOTH, the parents AND children of dupliverts 
structures are in the list. This can be very dangerous, in particular if e.g.
something is modified (replaced, deleted etc.). - The list of 
bpy.context.selected_objects is now sorted, and only the parents are in the 
resulting list.

3. Code cleaning

Blendphys.

Modified Paths:
--------------
    contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
    contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py

Modified: contrib/py/scripts/addons/io_atomblend_utilities/__init__.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/__init__.py	2013-01-19 11:03:13 UTC (rev 4177)
+++ contrib/py/scripts/addons/io_atomblend_utilities/__init__.py	2013-01-19 21:36:32 UTC (rev 4178)
@@ -24,7 +24,7 @@
 #
 #  Start of project              : 2011-12-01 by Clemens Barth
 #  First publication in Blender  : 2012-11-03
-#  Last modified                 : 2013-01-18
+#  Last modified                 : 2013-01-19
 #
 #  Acknowledgements 
 #  ================
@@ -81,7 +81,7 @@
         col = box.column(align=True)   
         col.label(text="Measure distances")
         col.operator("atom_blend.button_distance")
-        col.prop(scn, "distance")
+        col.prop(scn, "distance")      
         
         box = layout.box()
         col = box.column(align=True)
@@ -117,6 +117,12 @@
 
         box = layout.box()
         col = box.column(align=True)
+        col.label(text="Change atom shape")
+        col.prop(scn, "replace_objs")
+        col.operator("atom_blend.replace_atom")  
+
+        box = layout.box()
+        col = box.column(align=True)
         col.label(text="Separate atoms")
         col2 = col.column()
         col2.active = (bpy.context.mode == 'EDIT_MESH')
@@ -129,7 +135,7 @@
 
     def Callback_radius_type(self, context):
         scn = bpy.context.scene.atom_blend
-        io_atomblend_utilities.choose_objects("radius_type", 
+        io_atomblend_utilities.choose_objects("ATOM_RADIUS_TYPE", 
                                               scn.obj_who, 
                                               None,
                                               None,
@@ -138,7 +144,7 @@
                                               None) 
     def Callback_radius_pm(self, context):
         scn = bpy.context.scene.atom_blend
-        io_atomblend_utilities.choose_objects("radius_pm", 
+        io_atomblend_utilities.choose_objects("ATOM_RADIUS_PM", 
                                               scn.obj_who, 
                                               None,
                                               [scn.radius_pm_name,
@@ -159,6 +165,30 @@
     distance = StringProperty(
         name="", default="Distance (A)",
         description="Distance of 2 objects in Angstrom")
+    replace_objs = EnumProperty(
+        name="Shape",
+        description="Choose a different shape.",
+        items=(('-1',"Unchanged", "Use again a ball"),
+               ('0a',"Sphere", "Replace with a sphere"),
+               ('0b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
+               ('1',"Cube", "Replace with a cube"),
+               ('2',"Plane", "Replace with a plane"),
+               ('3a',"Circle", "Replace with a circle"),
+               ('3b',"Circle (NURBS)", "Replace with a circle (NURBS)"),               
+               ('4a',"Icosphere 1", "Replace with a icosphere, subd=1"),  
+               ('4b',"Icosphere 2", "Replace with a icosphere, subd=2"),  
+               ('4c',"Icosphere 3", "Replace with a icosphere, subd=3"),                             
+               ('5a',"Cylinder", "Replace with a cylinder"),
+               ('5b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),               
+               ('6',"Cone", "Replace with a cone"),
+               ('7a',"Torus", "Replace with a torus"),
+               ('7b',"Torus (NURBS)", "Replace with a torus (NURBS)"),
+               ('8',"Transparent cube", "Replace with a transparent cube"),      
+               ('9',"Transparent sphere", "Replace with a transparent sphere"),
+               ('10',"Transparent sphere (NURBS)", 
+                                  "Replace with a transparent sphere (NURBS)"),               
+               ('11',"Halo cloud", "Replace with a halo cloud")),
+               default='-1',)          
     obj_who = EnumProperty(
         name="",
         description="Which objects shall be modified?",
@@ -204,8 +234,8 @@
         name="Scale", default = 1.05, min=1.0, max=5.0,
         description="Put in the scale factor")
     draw_objs = EnumProperty(
-        name="Type",
-        description="Replace the balls by another type of object.",
+        name="Shape",
+        description="Choose a different shape.",
         items=(('-1',"Unchanged", "Use again a ball"),
                ('0a',"Sphere", "Replace with a sphere"),
                ('0b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),        
@@ -248,6 +278,24 @@
 
 
 # Button for separating single atoms from a dupliverts structure
+class ReplaceAtom(Operator):
+    bl_idname = "atom_blend.replace_atom"
+    bl_label = "Replace"
+    bl_description = ("Replace selected atoms with atoms of different shape.")
+
+    def execute(self, context):
+        scn = bpy.context.scene.atom_blend
+        io_atomblend_utilities.choose_objects("ATOM_REPLACE_OBJ", 
+                                              scn.obj_who, 
+                                              None, 
+                                              None,
+                                              None,
+                                              None,
+                                              None) 
+        return {'FINISHED'}
+
+
+# Button for separating single atoms from a dupliverts structure
 class SeparateAtom(Operator):
     bl_idname = "atom_blend.separate_atom"
     bl_label = "Separate"
@@ -266,7 +314,7 @@
 class DistanceButton(Operator):
     bl_idname = "atom_blend.button_distance"
     bl_label = "Measure ..."
-    bl_description = "Measure the distance between two objects"
+    bl_description = "Measure the distance between two atoms (objects)."
 
     def execute(self, context):
         scn  = bpy.context.scene.atom_blend
@@ -281,11 +329,11 @@
 class RadiusAllBiggerButton(Operator):
     bl_idname = "atom_blend.radius_all_bigger"
     bl_label = "Bigger ..."
-    bl_description = "Increase the radii of the atoms"
+    bl_description = "Increase the radii of selected atoms"
 
     def execute(self, context):
         scn = bpy.context.scene.atom_blend     
-        io_atomblend_utilities.choose_objects("radius_all", 
+        io_atomblend_utilities.choose_objects("ATOM_RADIUS_ALL", 
                                               scn.obj_who, 
                                               scn.radius_all, 
                                               None,
@@ -299,11 +347,11 @@
 class RadiusAllSmallerButton(Operator):
     bl_idname = "atom_blend.radius_all_smaller"
     bl_label = "Smaller ..."
-    bl_description = "Decrease the radii of the atoms"
+    bl_description = "Decrease the radii of selected atoms"
 
     def execute(self, context):
         scn = bpy.context.scene.atom_blend
-        io_atomblend_utilities.choose_objects("radius_all", 
+        io_atomblend_utilities.choose_objects("ATOM_RADIUS_ALL", 
                                               scn.obj_who, 
                                               1.0/scn.radius_all, 
                                               None,
@@ -317,11 +365,11 @@
 class SticksAllBiggerButton(Operator):
     bl_idname = "atom_blend.sticks_all_bigger"
     bl_label = "Bigger ..."
-    bl_description = "Increase the radii of the sticks"
+    bl_description = "Increase the radii of selected sticks"
 
     def execute(self, context):
         scn = bpy.context.scene.atom_blend     
-        io_atomblend_utilities.choose_objects("sticks_all", 
+        io_atomblend_utilities.choose_objects("STICKS_RADIUS_ALL", 
                                               scn.obj_who, 
                                               None, 
                                               None,
@@ -335,11 +383,11 @@
 class SticksAllSmallerButton(Operator):
     bl_idname = "atom_blend.sticks_all_smaller"
     bl_label = "Smaller ..."
-    bl_description = "Decrease the radii of the sticks"
+    bl_description = "Decrease the radii of selected sticks"
 
     def execute(self, context):
         scn = bpy.context.scene.atom_blend
-        io_atomblend_utilities.choose_objects("sticks_all", 
+        io_atomblend_utilities.choose_objects("STICKS_RADIUS_ALL", 
                                               scn.obj_who, 
                                               None, 
                                               None,

Modified: contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py
===================================================================
--- contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py	2013-01-19 11:03:13 UTC (rev 4177)
+++ contrib/py/scripts/addons/io_atomblend_utilities/io_atomblend_utilities.py	2013-01-19 21:36:32 UTC (rev 4178)
@@ -204,13 +204,14 @@
     return dist
 
 
-def choose_objects(how, 
+def choose_objects(action_type, 
                    who, 
                    radius_all, 
                    radius_pm, 
                    radius_type, 
                    radius_type_ionic,
                    sticks_all):
+
     # For selected objects of all selected layers
     if who == "ALL_IN_LAYER":
         # Determine all selected layers.
@@ -220,18 +221,34 @@
                 layers.append(i)
                 
         # Put all objects, which are in the layers, into a list.
-        change_objects = []
+        change_objects_all = []
         for obj in bpy.context.scene.objects:
             for layer in layers:
                 if obj.layers[layer] == True:
+                    change_objects_all.append(obj)
+                    
+        # This is very important now: If there are dupliverts structures, note 
+        # only the parents and NOT the children! Otherwise the double work is 
+        # done or the system can even crash if objects are deleted. - The 
+        # chidlren are accessed anyways (see below).
+        change_objects = []
+        for obj in change_objects_all:
+            if obj.parent != None:
+                FLAG = False
+                for obj2 in change_objects:
+                    if obj2 == obj.parent:
+                        FLAG = True
+                if FLAG == False:        
                     change_objects.append(obj)
+            else:
+                change_objects.append(obj)
                     
         # Consider all objects, which are in the latter list.
         for obj in change_objects:

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list