Cleanup: camera_turnaround (pep8)
[blender-addons.git] / io_mesh_atomic / xyz_gui.py
blobe66a071af0870f74ae5174930196a82e0f98711f
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.xyz_import import import_xyz
31 from io_mesh_atomic.xyz_import import ALL_FRAMES
32 from io_mesh_atomic.xyz_import import ELEMENTS
33 from io_mesh_atomic.xyz_import import STRUCTURE
34 from io_mesh_atomic.xyz_import import build_frames
35 from io_mesh_atomic.xyz_export import export_xyz
37 # -----------------------------------------------------------------------------
38 # Operators
40 # This is the class for the file dialog.
41 class IMPORT_OT_xyz(Operator, ImportHelper):
42 bl_idname = "import_mesh.xyz"
43 bl_label = "Import XYZ (*.xyz)"
44 bl_options = {'PRESET', 'UNDO'}
46 filename_ext = ".xyz"
47 filter_glob: StringProperty(default="*.xyz", options={'HIDDEN'},)
49 use_camera: BoolProperty(
50 name="Camera", default=False,
51 description="Do you need a camera?")
52 use_lamp: BoolProperty(
53 name="Lamp", default=False,
54 description = "Do you need a lamp?")
55 ball: EnumProperty(
56 name="Type of ball",
57 description="Choose ball",
58 items=(('0', "NURBS", "NURBS balls"),
59 ('1', "Mesh" , "Mesh balls"),
60 ('2', "Meta" , "Metaballs")),
61 default='0',)
62 mesh_azimuth: IntProperty(
63 name = "Azimuth", default=32, min=1,
64 description = "Number of sectors (azimuth)")
65 mesh_zenith: IntProperty(
66 name = "Zenith", default=32, min=1,
67 description = "Number of sectors (zenith)")
68 scale_ballradius: FloatProperty(
69 name = "Balls", default=1.0, min=0.0001,
70 description = "Scale factor for all atom radii")
71 scale_distances: FloatProperty (
72 name = "Distances", default=1.0, min=0.0001,
73 description = "Scale factor for all distances")
74 atomradius: EnumProperty(
75 name="Type of radius",
76 description="Choose type of atom radius",
77 items=(('0', "Pre-defined", "Use pre-defined radius"),
78 ('1', "Atomic", "Use atomic radius"),
79 ('2', "van der Waals", "Use van der Waals radius")),
80 default='0',)
81 use_center: BoolProperty(
82 name = "Object to origin (first frames)", default=False,
83 description = "Put the object into the global origin, the first frame only")
84 use_center_all: BoolProperty(
85 name = "Object to origin (all frames)", default=True,
86 description = "Put the object into the global origin, all frames")
87 datafile: StringProperty(
88 name = "", description="Path to your custom data file",
89 maxlen = 256, default = "", subtype='FILE_PATH')
90 use_frames: BoolProperty(
91 name = "Load all frames?", default=False,
92 description = "Do you want to load all frames?")
93 skip_frames: IntProperty(
94 name="", default=0, min=0,
95 description="Number of frames you want to skip.")
96 images_per_key: IntProperty(
97 name="", default=1, min=1,
98 description="Choose the number of images between 2 keys.")
100 # This thing here just guarantees that the menu entry is not active when the
101 # check box in the addon preferences is not activated! See __init__.py
102 @classmethod
103 def poll(cls, context):
104 pref = context.preferences
105 return pref.addons[__package__].preferences.bool_xyz
107 def draw(self, context):
108 layout = self.layout
109 row = layout.row()
110 row.prop(self, "use_camera")
111 row.prop(self, "use_lamp")
112 row = layout.row()
113 row.prop(self, "use_center")
114 row = layout.row()
115 row.prop(self, "use_center_all")
116 # Balls
117 box = layout.box()
118 row = box.row()
119 row.label(text="Balls / atoms")
120 row = box.row()
121 col = row.column()
122 col.prop(self, "ball")
123 row = box.row()
124 row.active = (self.ball == "1")
125 col = row.column(align=True)
126 col.prop(self, "mesh_azimuth")
127 col.prop(self, "mesh_zenith")
128 row = box.row()
129 col = row.column()
130 col.label(text="Scaling factors")
131 col = row.column(align=True)
132 col.prop(self, "scale_ballradius")
133 col.prop(self, "scale_distances")
134 row = box.row()
135 row.prop(self, "atomradius")
136 # Frames
137 box = layout.box()
138 row = box.row()
139 row.label(text="Frames")
140 row = box.row()
141 row.prop(self, "use_frames")
142 row = box.row()
143 row.active = self.use_frames
144 col = row.column()
145 col.label(text="Skip frames")
146 col = row.column()
147 col.prop(self, "skip_frames")
148 row = box.row()
149 row.active = self.use_frames
150 col = row.column()
151 col.label(text="Frames/key")
152 col = row.column()
153 col.prop(self, "images_per_key")
155 def execute(self, context):
157 del ALL_FRAMES[:]
158 del ELEMENTS[:]
159 del STRUCTURE[:]
161 # This is to determine the path.
162 filepath_xyz = bpy.path.abspath(self.filepath)
164 # Execute main routine
165 import_xyz(self.ball,
166 self.mesh_azimuth,
167 self.mesh_zenith,
168 self.scale_ballradius,
169 self.atomradius,
170 self.scale_distances,
171 self.use_center,
172 self.use_center_all,
173 self.use_camera,
174 self.use_lamp,
175 filepath_xyz)
177 # Load frames
178 if len(ALL_FRAMES) > 1 and self.use_frames:
180 build_frames(self.images_per_key, self.skip_frames)
182 return {'FINISHED'}
185 # This is the class for the file dialog of the exporter.
186 class EXPORT_OT_xyz(Operator, ExportHelper):
187 bl_idname = "export_mesh.xyz"
188 bl_label = "Export XYZ (*.xyz)"
189 filename_ext = ".xyz"
191 filter_glob: StringProperty(
192 default="*.xyz", options={'HIDDEN'},)
194 atom_xyz_export_type: EnumProperty(
195 name="Type of Objects",
196 description="Choose type of objects",
197 items=(('0', "All", "Export all active objects"),
198 ('1', "Elements", "Export only those active objects which have"
199 " a proper element name")),
200 default='1',)
202 # This thing here just guarantees that the menu entry is not active when the
203 # check box in the addon preferences is not activated! See __init__.py
204 @classmethod
205 def poll(cls, context):
206 pref = context.preferences
207 return pref.addons[__package__].preferences.bool_xyz
209 def draw(self, context):
210 layout = self.layout
211 row = layout.row()
212 row.prop(self, "atom_xyz_export_type")
214 def execute(self, context):
215 export_xyz(self.atom_xyz_export_type, bpy.path.abspath(self.filepath))
217 return {'FINISHED'}