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 #####
20 from bpy
.types
import Operator
, AddonPreferences
21 from bpy_extras
.io_utils
import ImportHelper
, ExportHelper
22 from bpy
.props
import (
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 # -----------------------------------------------------------------------------
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'}
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?")
57 description
="Choose ball",
58 items
=(('0', "NURBS", "NURBS balls"),
59 ('1', "Mesh" , "Mesh balls"),
60 ('2', "Meta" , "Metaballs")),
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")),
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
103 def poll(cls
, context
):
104 pref
= context
.preferences
105 return pref
.addons
[__package__
].preferences
.bool_xyz
107 def draw(self
, context
):
110 row
.prop(self
, "use_camera")
111 row
.prop(self
, "use_lamp")
113 row
.prop(self
, "use_center")
115 row
.prop(self
, "use_center_all")
119 row
.label(text
="Balls / atoms")
122 col
.prop(self
, "ball")
124 row
.active
= (self
.ball
== "1")
125 col
= row
.column(align
=True)
126 col
.prop(self
, "mesh_azimuth")
127 col
.prop(self
, "mesh_zenith")
130 col
.label(text
="Scaling factors")
131 col
= row
.column(align
=True)
132 col
.prop(self
, "scale_ballradius")
133 col
.prop(self
, "scale_distances")
135 row
.prop(self
, "atomradius")
139 row
.label(text
="Frames")
141 row
.prop(self
, "use_frames")
143 row
.active
= self
.use_frames
145 col
.label(text
="Skip frames")
147 col
.prop(self
, "skip_frames")
149 row
.active
= self
.use_frames
151 col
.label(text
="Frames/key")
153 col
.prop(self
, "images_per_key")
155 def execute(self
, context
):
161 # This is to determine the path.
162 filepath_xyz
= bpy
.path
.abspath(self
.filepath
)
164 # Execute main routine
165 import_xyz(self
.ball
,
168 self
.scale_ballradius
,
170 self
.scale_distances
,
178 if len(ALL_FRAMES
) > 1 and self
.use_frames
:
180 build_frames(self
.images_per_key
, self
.skip_frames
)
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")),
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
205 def poll(cls
, context
):
206 pref
= context
.preferences
207 return pref
.addons
[__package__
].preferences
.bool_xyz
209 def draw(self
, context
):
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
))