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