Cleanup: quiet warnings with descriptions ending with a '.'
[blender-addons.git] / io_mesh_atomic / xyz_gui.py
blob6475a22c9406f46fdc265fd280da81ae94651182
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 import bpy
4 from bpy.types import Operator, AddonPreferences
5 from bpy_extras.io_utils import ImportHelper, ExportHelper
6 from bpy.props import (
7 StringProperty,
8 BoolProperty,
9 EnumProperty,
10 IntProperty,
11 FloatProperty,
14 from io_mesh_atomic.xyz_import import import_xyz
15 from io_mesh_atomic.xyz_import import ALL_FRAMES
16 from io_mesh_atomic.xyz_import import ELEMENTS
17 from io_mesh_atomic.xyz_import import STRUCTURE
18 from io_mesh_atomic.xyz_import import build_frames
19 from io_mesh_atomic.xyz_export import export_xyz
21 # -----------------------------------------------------------------------------
22 # Operators
24 # This is the class for the file dialog.
25 class IMPORT_OT_xyz(Operator, ImportHelper):
26 bl_idname = "import_mesh.xyz"
27 bl_label = "Import XYZ (*.xyz)"
28 bl_options = {'PRESET', 'UNDO'}
30 filename_ext = ".xyz"
31 filter_glob: StringProperty(default="*.xyz", options={'HIDDEN'},)
33 use_camera: BoolProperty(
34 name="Camera", default=False,
35 description="Do you need a camera?")
36 use_lamp: BoolProperty(
37 name="Lamp", default=False,
38 description = "Do you need a lamp?")
39 ball: EnumProperty(
40 name="Type of ball",
41 description="Choose ball",
42 items=(('0', "NURBS", "NURBS balls"),
43 ('1', "Mesh" , "Mesh balls"),
44 ('2', "Meta" , "Metaballs")),
45 default='0',)
46 mesh_azimuth: IntProperty(
47 name = "Azimuth", default=32, min=1,
48 description = "Number of sectors (azimuth)")
49 mesh_zenith: IntProperty(
50 name = "Zenith", default=32, min=1,
51 description = "Number of sectors (zenith)")
52 scale_ballradius: FloatProperty(
53 name = "Balls", default=1.0, min=0.0001,
54 description = "Scale factor for all atom radii")
55 scale_distances: FloatProperty (
56 name = "Distances", default=1.0, min=0.0001,
57 description = "Scale factor for all distances")
58 atomradius: EnumProperty(
59 name="Type of radius",
60 description="Choose type of atom radius",
61 items=(('0', "Pre-defined", "Use pre-defined radius"),
62 ('1', "Atomic", "Use atomic radius"),
63 ('2', "van der Waals", "Use van der Waals radius")),
64 default='0',)
65 use_center: BoolProperty(
66 name = "Object to origin (first frames)", default=False,
67 description = "Put the object into the global origin, the first frame only")
68 use_center_all: BoolProperty(
69 name = "Object to origin (all frames)", default=True,
70 description = "Put the object into the global origin, all frames")
71 datafile: StringProperty(
72 name = "", description="Path to your custom data file",
73 maxlen = 256, default = "", subtype='FILE_PATH')
74 use_frames: BoolProperty(
75 name = "Load all frames?", default=False,
76 description = "Do you want to load all frames?")
77 skip_frames: IntProperty(
78 name="", default=0, min=0,
79 description="Number of frames you want to skip")
80 images_per_key: IntProperty(
81 name="", default=1, min=1,
82 description="Choose the number of images between 2 keys")
84 # This thing here just guarantees that the menu entry is not active when the
85 # check box in the addon preferences is not activated! See __init__.py
86 @classmethod
87 def poll(cls, context):
88 pref = context.preferences
89 return pref.addons[__package__].preferences.bool_xyz
91 def draw(self, context):
92 layout = self.layout
93 row = layout.row()
94 row.prop(self, "use_camera")
95 row.prop(self, "use_lamp")
96 row = layout.row()
97 row.prop(self, "use_center")
98 row = layout.row()
99 row.prop(self, "use_center_all")
100 # Balls
101 box = layout.box()
102 row = box.row()
103 row.label(text="Balls / atoms")
104 row = box.row()
105 col = row.column()
106 col.prop(self, "ball")
107 row = box.row()
108 row.active = (self.ball == "1")
109 col = row.column(align=True)
110 col.prop(self, "mesh_azimuth")
111 col.prop(self, "mesh_zenith")
112 row = box.row()
113 col = row.column()
114 col.label(text="Scaling factors")
115 col = row.column(align=True)
116 col.prop(self, "scale_ballradius")
117 col.prop(self, "scale_distances")
118 row = box.row()
119 row.prop(self, "atomradius")
120 # Frames
121 box = layout.box()
122 row = box.row()
123 row.label(text="Frames")
124 row = box.row()
125 row.prop(self, "use_frames")
126 row = box.row()
127 row.active = self.use_frames
128 col = row.column()
129 col.label(text="Skip frames")
130 col = row.column()
131 col.prop(self, "skip_frames")
132 row = box.row()
133 row.active = self.use_frames
134 col = row.column()
135 col.label(text="Frames/key")
136 col = row.column()
137 col.prop(self, "images_per_key")
139 def execute(self, context):
140 # Switch to 'OBJECT' mode when in 'EDIT' mode.
141 if bpy.context.mode == 'EDIT_MESH':
142 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
144 del ALL_FRAMES[:]
145 del ELEMENTS[:]
146 del STRUCTURE[:]
148 # This is to determine the path.
149 filepath_xyz = bpy.path.abspath(self.filepath)
151 # Execute main routine
152 import_xyz(self.ball,
153 self.mesh_azimuth,
154 self.mesh_zenith,
155 self.scale_ballradius,
156 self.atomradius,
157 self.scale_distances,
158 self.use_center,
159 self.use_center_all,
160 self.use_camera,
161 self.use_lamp,
162 filepath_xyz)
164 # Load frames
165 if len(ALL_FRAMES) > 1 and self.use_frames:
167 build_frames(self.images_per_key, self.skip_frames)
169 return {'FINISHED'}
172 # This is the class for the file dialog of the exporter.
173 class EXPORT_OT_xyz(Operator, ExportHelper):
174 bl_idname = "export_mesh.xyz"
175 bl_label = "Export XYZ (*.xyz)"
176 filename_ext = ".xyz"
178 filter_glob: StringProperty(
179 default="*.xyz", options={'HIDDEN'},)
181 atom_xyz_export_type: EnumProperty(
182 name="Type of Objects",
183 description="Choose type of objects",
184 items=(('0', "All", "Export all active objects"),
185 ('1', "Elements", "Export only those active objects which have"
186 " a proper element name")),
187 default='1',)
189 # This thing here just guarantees that the menu entry is not active when the
190 # check box in the addon preferences is not activated! See __init__.py
191 @classmethod
192 def poll(cls, context):
193 pref = context.preferences
194 return pref.addons[__package__].preferences.bool_xyz
196 def draw(self, context):
197 layout = self.layout
198 row = layout.row()
199 row.prop(self, "atom_xyz_export_type")
201 def execute(self, context):
202 export_xyz(self.atom_xyz_export_type, bpy.path.abspath(self.filepath))
204 return {'FINISHED'}