1 # SPDX-License-Identifier: GPL-2.0-or-later
4 from bpy
.types
import Operator
, Panel
5 from bpy
.props
import (StringProperty
,
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 # -----------------------------------------------------------------------------
21 class PANEL_PT_prepare(Panel
):
22 bl_label
= "Atomic Blender Utilities"
23 bl_space_type
= "VIEW_3D"
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
33 def poll(cls
, context
):
34 pref
= context
.preferences
35 return pref
.addons
[__package__
].preferences
.bool_utility
37 def draw(self
, context
):
39 scn
= context
.scene
.atom_blend
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")
48 col
= box
.column(align
=True)
49 col
.label(text
="Measure distances")
50 col
.operator("atom_blend.button_distance")
51 col
.prop(scn
, "distance")
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")
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")
69 row
.operator("atom_blend.radius_all_smaller")
70 row
.operator("atom_blend.radius_all_bigger")
73 col
= box
.column(align
=True)
74 col
.label(text
="Change stick size")
75 col
.prop(scn
, "sticks_all")
77 row
.operator("atom_blend.sticks_all_smaller")
78 row
.operator("atom_blend.sticks_all_bigger")
81 col
= box
.column(align
=True)
82 col
.label(text
="Change atom shape")
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")
93 col
= box
.column(align
=True)
94 col
.label(text
="Separate atoms")
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",
109 scn
.radius_type_ionic
,
111 def Callback_radius_pm(self
, context
):
112 scn
= bpy
.context
.scene
.atom_blend
113 choose_objects("ATOM_RADIUS_PM",
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(
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)")),
154 replace_objs_material
: EnumProperty(
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")),
163 replace_objs_special
: EnumProperty(
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")),
171 radius_type
: EnumProperty(
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(
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"
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
== "":
222 custom_datafile(scn
.datafile
)
223 custom_datafile_change_atom_props()
228 # Button for separating single atoms from a dupliverts structure
229 class DefaultAtom(Operator
):
230 bl_idname
= "atom_blend.default_atoms"
232 bl_description
= ("Use default shapes and colors for atoms")
234 # Are we in the OBJECT mode?
236 def poll(self
, context
):
237 if bpy
.context
.mode
== 'OBJECT':
242 def execute(self
, context
):
243 scn
= bpy
.context
.scene
.atom_blend
244 choose_objects("ATOM_DEFAULT_OBJ",
253 # Button for separating single atoms from a dupliverts structure
254 class ReplaceAtom(Operator
):
255 bl_idname
= "atom_blend.replace_atom"
257 bl_description
= ("Replace selected atoms with atoms of different shape")
259 # Are we in the OBJECT mode?
261 def poll(self
, context
):
262 if bpy
.context
.mode
== 'OBJECT':
267 def execute(self
, context
):
268 scn
= bpy
.context
.scene
.atom_blend
269 choose_objects("ATOM_REPLACE_OBJ",
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?
287 def poll(self
, context
):
288 if bpy
.context
.mode
== 'EDIT_MESH':
293 def execute(self
, context
):
294 scn
= bpy
.context
.scene
.atom_blend
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
311 # Put the distance into the string of the output field.
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",
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",
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",
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",