Cleanup: simplify file name incrementing logic
[blender-addons.git] / io_mesh_atomic / pdb_gui.py
blob00a4ca97efd0951ca12a19a9c6a7649715e9393f
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import bpy
20 from bpy.types import Operator, AddonPreferences
21 from bpy_extras.io_utils import ImportHelper, ExportHelper
22 from bpy.props import (
23 StringProperty,
24 BoolProperty,
25 EnumProperty,
26 IntProperty,
27 FloatProperty,
30 from io_mesh_atomic.pdb_import import import_pdb
31 from io_mesh_atomic.pdb_export import export_pdb
33 # -----------------------------------------------------------------------------
34 # Operators
36 # This is the class for the file dialog of the importer.
37 class IMPORT_OT_pdb(Operator, ImportHelper):
38 bl_idname = "import_mesh.pdb"
39 bl_label = "Import Protein Data Bank(*.pdb)"
40 bl_options = {'PRESET', 'UNDO'}
42 filename_ext = ".pdb"
43 filter_glob: StringProperty(default="*.pdb", options={'HIDDEN'},)
45 use_center: BoolProperty(
46 name = "Object to origin", default=True,
47 description = "Put the object into the global origin")
48 use_camera: BoolProperty(
49 name="Camera", default=False,
50 description="Do you need a camera?")
51 use_light: BoolProperty(
52 name="Lamp", default=False,
53 description = "Do you need a lamp?")
54 ball: EnumProperty(
55 name="Type of ball",
56 description="Choose ball",
57 items=(('0', "NURBS", "NURBS balls"),
58 ('1', "Mesh" , "Mesh balls"),
59 ('2', "Meta" , "Metaballs")),
60 default='0',)
61 mesh_azimuth: IntProperty(
62 name = "Azimuth", default=32, min=1,
63 description = "Number of sectors (azimuth)")
64 mesh_zenith: IntProperty(
65 name = "Zenith", default=32, min=1,
66 description = "Number of sectors (zenith)")
67 scale_ballradius: FloatProperty(
68 name = "Balls", default=1.0, min=0.0001,
69 description = "Scale factor for all atom radii")
70 scale_distances: FloatProperty (
71 name = "Distances", default=1.0, min=0.0001,
72 description = "Scale factor for all distances")
73 atomradius: EnumProperty(
74 name="Type",
75 description="Choose type of atom radius",
76 items=(('0', "Pre-defined", "Use pre-defined radius"),
77 ('1', "Atomic", "Use atomic radius"),
78 ('2', "van der Waals", "Use van der Waals radius")),
79 default='0',)
80 use_sticks: BoolProperty(
81 name="Use sticks", default=True,
82 description="Do you want to display the sticks?")
83 use_sticks_type: EnumProperty(
84 name="Type",
85 description="Choose type of stick",
86 items=(('0', "Dupliverts", "Use dupliverts structures"),
87 ('1', "Skin", "Use skin and subdivision modifier"),
88 ('2', "Normal", "Use simple cylinders")),
89 default='0',)
90 sticks_subdiv_view: IntProperty(
91 name = "SubDivV", default=2, min=1,
92 description="Number of subdivisions (view)")
93 sticks_subdiv_render: IntProperty(
94 name = "SubDivR", default=2, min=1,
95 description="Number of subdivisions (render)")
96 sticks_sectors: IntProperty(
97 name = "Sector", default=20, min=1,
98 description="Number of sectors of a stick")
99 sticks_radius: FloatProperty(
100 name = "Radius", default=0.2, min=0.0001,
101 description ="Radius of a stick")
102 sticks_unit_length: FloatProperty(
103 name = "Unit", default=0.05, min=0.0001,
104 description = "Length of the unit of a stick in Angstrom")
105 use_sticks_color: BoolProperty(
106 name="Color", default=True,
107 description="The sticks appear in the color of the atoms")
108 use_sticks_smooth: BoolProperty(
109 name="Smooth", default=True,
110 description="The sticks are round (sectors are not visible)")
111 use_sticks_bonds: BoolProperty(
112 name="Bonds", default=False,
113 description="Show double and triple bonds")
114 sticks_dist: FloatProperty(
115 name="", default = 1.1, min=1.0, max=3.0,
116 description="Distance between sticks measured in stick diameter")
117 use_sticks_one_object: BoolProperty(
118 name="One object", default=False,
119 description="All sticks are one object")
120 use_sticks_one_object_nr: IntProperty(
121 name = "No.", default=200, min=10,
122 description="Number of sticks to be grouped at once")
123 datafile: StringProperty(
124 name = "", description="Path to your custom data file",
125 maxlen = 256, default = "", subtype='FILE_PATH')
127 # This thing here just guarantees that the menu entry is not active when the
128 # check box in the addon preferences is not activated! See __init__.py
129 @classmethod
130 def poll(cls, context):
131 pref = context.preferences
132 return pref.addons[__package__].preferences.bool_pdb
134 def draw(self, context):
135 layout = self.layout
136 row = layout.row()
137 row.prop(self, "use_camera")
138 row.prop(self, "use_light")
139 row = layout.row()
140 row.prop(self, "use_center")
141 # Balls
142 box = layout.box()
143 row = box.row()
144 row.label(text="Balls / atoms")
145 row = box.row()
146 col = row.column()
147 col.prop(self, "ball")
148 row = box.row()
149 row.active = (self.ball == "1")
150 col = row.column(align=True)
151 col.prop(self, "mesh_azimuth")
152 col.prop(self, "mesh_zenith")
153 row = box.row()
154 col = row.column()
155 col.label(text="Scaling factors")
156 col = row.column(align=True)
157 col.prop(self, "scale_ballradius")
158 col.prop(self, "scale_distances")
159 row = box.row()
160 row.prop(self, "atomradius")
161 # Sticks
162 box = layout.box()
163 row = box.row()
164 row.label(text="Sticks / bonds")
165 row = box.row()
166 row.prop(self, "use_sticks")
167 row = box.row()
168 row.active = self.use_sticks
169 row.prop(self, "use_sticks_type")
170 row = box.row()
171 row.active = self.use_sticks
172 col = row.column()
173 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
174 col.prop(self, "sticks_sectors")
175 col.prop(self, "sticks_radius")
176 if self.use_sticks_type == '1':
177 row = box.row()
178 row.active = self.use_sticks
179 row.prop(self, "sticks_subdiv_view")
180 row.prop(self, "sticks_subdiv_render")
181 row = box.row()
182 row.active = self.use_sticks
183 if self.use_sticks_type == '0':
184 col.prop(self, "sticks_unit_length")
185 col = row.column(align=True)
186 if self.use_sticks_type == '0':
187 col.prop(self, "use_sticks_color")
188 col.prop(self, "use_sticks_smooth")
189 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
190 col.prop(self, "use_sticks_bonds")
191 row = box.row()
192 if self.use_sticks_type == '0':
193 row.active = self.use_sticks and self.use_sticks_bonds
194 row.label(text="Distance")
195 row.prop(self, "sticks_dist")
196 if self.use_sticks_type == '2':
197 row.active = self.use_sticks
198 col = row.column()
199 col.prop(self, "use_sticks_one_object")
200 col = row.column()
201 col.active = self.use_sticks_one_object
202 col.prop(self, "use_sticks_one_object_nr")
205 def execute(self, context):
206 # This is in order to solve this strange 'relative path' thing.
207 filepath_pdb = bpy.path.abspath(self.filepath)
209 # Execute main routine
210 import_pdb(self.ball,
211 self.mesh_azimuth,
212 self.mesh_zenith,
213 self.scale_ballradius,
214 self.atomradius,
215 self.scale_distances,
216 self.use_sticks,
217 self.use_sticks_type,
218 self.sticks_subdiv_view,
219 self.sticks_subdiv_render,
220 self.use_sticks_color,
221 self.use_sticks_smooth,
222 self.use_sticks_bonds,
223 self.use_sticks_one_object,
224 self.use_sticks_one_object_nr,
225 self.sticks_unit_length,
226 self.sticks_dist,
227 self.sticks_sectors,
228 self.sticks_radius,
229 self.use_center,
230 self.use_camera,
231 self.use_light,
232 filepath_pdb)
234 return {'FINISHED'}
237 # This is the class for the file dialog of the exporter.
238 class EXPORT_OT_pdb(Operator, ExportHelper):
239 bl_idname = "export_mesh.pdb"
240 bl_label = "Export Protein Data Bank(*.pdb)"
241 filename_ext = ".pdb"
243 filter_glob: StringProperty(
244 default="*.pdb", options={'HIDDEN'},)
246 atom_pdb_export_type: EnumProperty(
247 name="Type of Objects",
248 description="Choose type of objects",
249 items=(('0', "All", "Export all active objects"),
250 ('1', "Elements", "Export only those active objects which have"
251 " a proper element name")),
252 default='1',)
254 # This thing here just guarantees that the menu entry is not active when the
255 # check box in the addon preferences is not activated! See __init__.py
256 @classmethod
257 def poll(cls, context):
258 pref = context.preferences
259 return pref.addons[__package__].preferences.bool_pdb
261 def draw(self, context):
262 layout = self.layout
263 row = layout.row()
264 row.prop(self, "atom_pdb_export_type")
266 def execute(self, context):
267 export_pdb(self.atom_pdb_export_type,
268 bpy.path.abspath(self.filepath))
270 return {'FINISHED'}