Cleanup: quiet float argument to in type warning
[blender-addons.git] / io_mesh_atomic / utility_gui.py
blob081dc3c6682deed9bc9e1808827f4d1252be53cb
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.types import Operator, Panel
5 from bpy.props import (StringProperty,
6 EnumProperty,
7 FloatProperty,
8 BoolProperty)
10 from io_mesh_atomic.utility_panel import choose_objects
11 from io_mesh_atomic.utility_panel import custom_datafile
12 from io_mesh_atomic.utility_panel import custom_datafile_change_atom_props
13 from io_mesh_atomic.utility_panel import separate_atoms
14 from io_mesh_atomic.utility_panel import distance
17 # -----------------------------------------------------------------------------
18 # GUI
20 # The panel.
21 class PANEL_PT_prepare(Panel):
22 bl_label = "Atomic Blender Utilities"
23 bl_space_type = "VIEW_3D"
24 bl_region_type = "UI"
25 bl_options = {'DEFAULT_CLOSED'}
26 bl_category = "Create"
27 bl_idname = "ATOMIC_PT_utilities"
30 # This thing here just guarantees that the panel is NOT opened when the
31 # check box in the addon preferences is not activated! See __init__.py
32 @classmethod
33 def poll(cls, context):
34 pref = context.preferences
35 return pref.addons[__package__].preferences.bool_utility
37 def draw(self, context):
38 layout = self.layout
39 scn = context.scene.atom_blend
41 box = layout.box()
42 col = box.column(align=True)
43 col.label(text="Custom data file")
44 col.prop(scn, "datafile")
45 col.operator("atom_blend.datafile_apply")
47 box = layout.box()
48 col = box.column(align=True)
49 col.label(text="Measure distances")
50 col.operator("atom_blend.button_distance")
51 col.prop(scn, "distance")
53 box = layout.box()
54 col = box.column(align=True)
55 col.label(text="Change atom size")
56 col.label(text="1. Type of radii")
57 col.prop(scn, "radius_type")
58 col2 = col.column()
59 col2.active = (scn.radius_type == '3')
60 col2.prop(scn, "radius_type_ionic")
61 col = box.column(align=True)
62 col.label(text="2. Radii in pm")
63 col.prop(scn, "radius_pm_name")
64 col.prop(scn, "radius_pm")
65 col = box.column(align=True)
66 col.label(text="3. Radii by scale")
67 col.prop(scn, "radius_all")
68 row = col.row()
69 row.operator("atom_blend.radius_all_smaller")
70 row.operator("atom_blend.radius_all_bigger")
72 box = layout.box()
73 col = box.column(align=True)
74 col.label(text="Change stick size")
75 col.prop(scn, "sticks_all")
76 row = col.row()
77 row.operator("atom_blend.sticks_all_smaller")
78 row.operator("atom_blend.sticks_all_bigger")
80 box = layout.box()
81 col = box.column(align=True)
82 col.label(text="Change atom shape")
83 col2 = col.column()
84 col2.active = (scn.replace_objs_special == '0')
85 col2.prop(scn, "replace_objs")
86 col2.prop(scn, "replace_objs_material")
87 col.prop(scn, "replace_objs_special")
88 col.operator("atom_blend.replace_atom")
89 col.label(text="Default values")
90 col.operator("atom_blend.default_atoms")
92 box = layout.box()
93 col = box.column(align=True)
94 col.label(text="Separate atoms")
95 col3 = col.column()
96 col3.active = (bpy.context.mode == 'EDIT_MESH')
97 col3.operator("atom_blend.separate_atom")
100 # The properties of buttons etc. in the panel.
101 class PanelProperties(bpy.types.PropertyGroup):
103 def Callback_radius_type(self, context):
104 scn = bpy.context.scene.atom_blend
105 choose_objects("ATOM_RADIUS_TYPE",
106 None,
107 None,
108 scn.radius_type,
109 scn.radius_type_ionic,
110 None)
111 def Callback_radius_pm(self, context):
112 scn = bpy.context.scene.atom_blend
113 choose_objects("ATOM_RADIUS_PM",
114 None,
115 [scn.radius_pm_name,
116 scn.radius_pm],
117 None,
118 None,
119 None)
121 datafile: StringProperty(
122 name = "", description="Path to your custom data file",
123 maxlen = 256, default = "", subtype='FILE_PATH')
124 XYZ_file: StringProperty(
125 name = "Path to file", default="",
126 description = "Path of the XYZ file")
127 number_atoms: StringProperty(name="",
128 default="Number", description = "This output shows "
129 "the number of atoms which have been loaded")
130 distance: StringProperty(
131 name="", default="Distance (A)",
132 description="Distance of 2 objects in Angstrom")
133 replace_objs: EnumProperty(
134 name="Shape",
135 description="Choose a different atom shape",
136 items=(('0',"Unchanged", "Do not change the shape"),
137 ('1a',"Sphere (Mesh)", "Replace with a sphere (Mesh)"),
138 ('1b',"Sphere (NURBS)", "Replace with a sphere (NURBS)"),
139 ('2',"Cube", "Replace with a cube"),
140 ('3',"Plane", "Replace with a plane"),
141 ('4a',"Circle (Mesh)", "Replace with a circle (Mesh)"),
142 ('4b',"Circle (NURBS)", "Replace with a circle (NURBS)"),
143 ('5a',"Icosphere 1", "Replace with a icosphere, subd=1"),
144 ('5b',"Icosphere 2", "Replace with a icosphere, subd=2"),
145 ('5c',"Icosphere 3", "Replace with a icosphere, subd=3"),
146 ('5d',"Icosphere 4", "Replace with a icosphere, subd=4"),
147 ('5e',"Icosphere 5", "Replace with a icosphere, subd=5"),
148 ('6a',"Cylinder (Mesh)", "Replace with a cylinder (Mesh)"),
149 ('6b',"Cylinder (NURBS)", "Replace with a cylinder (NURBS)"),
150 ('7',"Cone", "Replace with a cone"),
151 ('8a',"Torus (Mesh)", "Replace with a torus (Mesh)"),
152 ('8b',"Torus (NURBS)", "Replace with a torus (NURBS)")),
153 default='0',)
154 replace_objs_material: EnumProperty(
155 name="Material",
156 description="Choose a different material",
157 items=(('0',"Unchanged", "Leave the material unchanged"),
158 ('1',"Normal", "Use normal material (no transparency and reflection)"),
159 ('2',"Transparent", "Use transparent material"),
160 ('3',"Reflecting", "Use reflecting material"),
161 ('4',"Transparent + reflecting", "Use transparent and reflecting material")),
162 default='0',)
163 replace_objs_special: EnumProperty(
164 name="Special",
165 description="Choose a special atom shape",
166 items=(('0',"None", "Use no special shape."),
167 ('1',"F2+ center", "Replace with a F2+ center"),
168 ('2',"F+ center", "Replace with a F+ center"),
169 ('3',"F0 center", "Replace with a F0 center")),
170 default='0',)
171 radius_type: EnumProperty(
172 name="Type",
173 description="Which type of atom radii?",
174 items=(('0',"predefined", "Use pre-defined radii"),
175 ('1',"atomic", "Use atomic radii"),
176 ('2',"van der Waals","Use van der Waals radii"),
177 ('3',"ionic radii", "Use ionic radii")),
178 default='0',update=Callback_radius_type)
179 radius_type_ionic: EnumProperty(
180 name="Charge",
181 description="Charge state of the ions if existing",
182 items=(('0',"-4", "Charge state -4"),
183 ('1',"-3", "Charge state -3"),
184 ('2',"-2", "Charge state -2"),
185 ('3',"-1", "Charge state -1"),
186 ('4'," 0", "Charge state 0: nothing is done"),
187 ('5',"+1", "Charge state +1"),
188 ('6',"+2", "Charge state +2"),
189 ('7',"+3", "Charge state +3"),
190 ('8',"+4", "Charge state +4"),
191 ('9',"+5", "Charge state +5"),
192 ('10',"+6", "Charge state +6"),
193 ('11',"+7", "Charge state +7")),
194 default='4',update=Callback_radius_type)
195 radius_pm_name: StringProperty(
196 name="", default="Atom name",
197 description="Put in the name of the atom (e.g. Hydrogen)")
198 radius_pm: FloatProperty(
199 name="", default=100.0, min=0.0,
200 description="Put in the radius of the atom (in pm)",
201 update=Callback_radius_pm)
202 radius_all: FloatProperty(
203 name="Scale", default = 1.05, min=1.0, max=5.0,
204 description="Put in the scale factor")
205 sticks_all: FloatProperty(
206 name="Scale", default = 1.05, min=1.0, max=5.0,
207 description="Put in the scale factor")
210 # Button loading a custom data file
211 class DatafileApply(Operator):
212 bl_idname = "atom_blend.datafile_apply"
213 bl_label = "Apply"
214 bl_description = "Use color and radii values stored in the custom file"
216 def execute(self, context):
217 scn = bpy.context.scene.atom_blend
219 if scn.datafile == "":
220 return {'FINISHED'}
222 custom_datafile(scn.datafile)
223 custom_datafile_change_atom_props()
225 return {'FINISHED'}
228 # Button for separating single atoms from a dupliverts structure
229 class DefaultAtom(Operator):
230 bl_idname = "atom_blend.default_atoms"
231 bl_label = "Default"
232 bl_description = ("Use default shapes and colors for atoms")
234 # Are we in the OBJECT mode?
235 @classmethod
236 def poll(self, context):
237 if bpy.context.mode == 'OBJECT':
238 return True
239 else:
240 return False
242 def execute(self, context):
243 scn = bpy.context.scene.atom_blend
244 choose_objects("ATOM_DEFAULT_OBJ",
245 None,
246 None,
247 None,
248 None,
249 None)
250 return {'FINISHED'}
253 # Button for separating single atoms from a dupliverts structure
254 class ReplaceAtom(Operator):
255 bl_idname = "atom_blend.replace_atom"
256 bl_label = "Replace"
257 bl_description = ("Replace selected atoms with atoms of different shape")
259 # Are we in the OBJECT mode?
260 @classmethod
261 def poll(self, context):
262 if bpy.context.mode == 'OBJECT':
263 return True
264 else:
265 return False
267 def execute(self, context):
268 scn = bpy.context.scene.atom_blend
269 choose_objects("ATOM_REPLACE_OBJ",
270 None,
271 None,
272 None,
273 None,
274 None)
275 return {'FINISHED'}
278 # Button for separating single atoms from a dupliverts structure
279 class SeparateAtom(Operator):
280 bl_idname = "atom_blend.separate_atom"
281 bl_label = "Separate"
282 bl_description = ("Separate selected atoms in a dupliverts structure. "
283 "You have to be in the 'Edit Mode'")
285 # Are we in the EDIT mode?
286 @classmethod
287 def poll(self, context):
288 if bpy.context.mode == 'EDIT_MESH':
289 return True
290 else:
291 return False
293 def execute(self, context):
294 scn = bpy.context.scene.atom_blend
296 separate_atoms(scn)
298 return {'FINISHED'}
301 # Button for measuring the distance of active objects
302 class DistanceButton(Operator):
303 bl_idname = "atom_blend.button_distance"
304 bl_label = "Measure ..."
305 bl_description = "Measure the distance between two atoms (objects)"
307 def execute(self, context):
308 scn = bpy.context.scene.atom_blend
309 dist = distance()
311 # Put the distance into the string of the output field.
312 scn.distance = dist
313 return {'FINISHED'}
316 # Button for increasing the radii of all selected atoms
317 class RadiusAllBiggerButton(Operator):
318 bl_idname = "atom_blend.radius_all_bigger"
319 bl_label = "Bigger ..."
320 bl_description = "Increase the radii of selected atoms"
322 def execute(self, context):
323 scn = bpy.context.scene.atom_blend
324 choose_objects("ATOM_RADIUS_ALL",
325 scn.radius_all,
326 None,
327 None,
328 None,
329 None)
330 return {'FINISHED'}
333 # Button for decreasing the radii of all selected atoms
334 class RadiusAllSmallerButton(Operator):
335 bl_idname = "atom_blend.radius_all_smaller"
336 bl_label = "Smaller ..."
337 bl_description = "Decrease the radii of selected atoms"
339 def execute(self, context):
340 scn = bpy.context.scene.atom_blend
341 choose_objects("ATOM_RADIUS_ALL",
342 1.0/scn.radius_all,
343 None,
344 None,
345 None,
346 None)
347 return {'FINISHED'}
350 # Button for increasing the radii of all selected sticks
351 class SticksAllBiggerButton(Operator):
352 bl_idname = "atom_blend.sticks_all_bigger"
353 bl_label = "Bigger ..."
354 bl_description = "Increase the radii of selected sticks"
356 def execute(self, context):
357 scn = bpy.context.scene.atom_blend
358 choose_objects("STICKS_RADIUS_ALL",
359 None,
360 None,
361 None,
362 None,
363 scn.sticks_all)
364 return {'FINISHED'}
367 # Button for decreasing the radii of all selected sticks
368 class SticksAllSmallerButton(Operator):
369 bl_idname = "atom_blend.sticks_all_smaller"
370 bl_label = "Smaller ..."
371 bl_description = "Decrease the radii of selected sticks"
373 def execute(self, context):
374 scn = bpy.context.scene.atom_blend
375 choose_objects("STICKS_RADIUS_ALL",
376 None,
377 None,
378 None,
379 None,
380 1.0/scn.sticks_all)
381 return {'FINISHED'}