Import_3ds: Improved distance cue node setup
[blender-addons.git] / io_mesh_atomic / pdb_gui.py
blob284de872bb3d4434725ebed4ec14daf10046fef0
1 # SPDX-FileCopyrightText: 2019-2023 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.pdb_import import import_pdb
17 from io_mesh_atomic.pdb_export import export_pdb
19 # -----------------------------------------------------------------------------
20 # Operators
22 # This is the class for the file dialog of the importer.
23 class IMPORT_OT_pdb(Operator, ImportHelper):
24 bl_idname = "import_mesh.pdb"
25 bl_label = "Import Protein Data Bank(*.pdb)"
26 bl_options = {'PRESET', 'UNDO'}
28 filename_ext = ".pdb"
29 filter_glob: StringProperty(default="*.pdb", options={'HIDDEN'},)
31 use_center: BoolProperty(
32 name = "Object to origin", default=True,
33 description = "Put the object into the global origin")
34 use_camera: BoolProperty(
35 name="Camera", default=False,
36 description="Do you need a camera?")
37 use_light: BoolProperty(
38 name="Lamp", default=False,
39 description = "Do you need a lamp?")
40 ball: EnumProperty(
41 name="Type of ball",
42 description="Choose ball",
43 items=(('0', "NURBS", "NURBS balls"),
44 ('1', "Mesh" , "Mesh balls"),
45 ('2', "Meta" , "Metaballs")),
46 default='0',)
47 mesh_azimuth: IntProperty(
48 name = "Azimuth", default=32, min=1,
49 description = "Number of sectors (azimuth)")
50 mesh_zenith: IntProperty(
51 name = "Zenith", default=32, min=1,
52 description = "Number of sectors (zenith)")
53 scale_ballradius: FloatProperty(
54 name = "Balls", default=1.0, min=0.0001,
55 description = "Scale factor for all atom radii")
56 scale_distances: FloatProperty (
57 name = "Distances", default=1.0, min=0.0001,
58 description = "Scale factor for all distances")
59 atomradius: EnumProperty(
60 name="Type",
61 description="Choose type of atom radius",
62 items=(('0', "Pre-defined", "Use pre-defined radius"),
63 ('1', "Atomic", "Use atomic radius"),
64 ('2', "van der Waals", "Use van der Waals radius")),
65 default='0',)
66 use_sticks: BoolProperty(
67 name="Use sticks", default=True,
68 description="Do you want to display the sticks?")
69 use_sticks_type: EnumProperty(
70 name="Type",
71 description="Choose type of stick",
72 items=(('0', "Dupliverts", "Use dupliverts structures"),
73 ('1', "Skin", "Use skin and subdivision modifier"),
74 ('2', "Normal", "Use simple cylinders")),
75 default='0',)
76 sticks_subdiv_view: IntProperty(
77 name = "SubDivV", default=2, min=1,
78 description="Number of subdivisions (view)")
79 sticks_subdiv_render: IntProperty(
80 name = "SubDivR", default=2, min=1,
81 description="Number of subdivisions (render)")
82 sticks_sectors: IntProperty(
83 name = "Sector", default=20, min=1,
84 description="Number of sectors of a stick")
85 sticks_radius: FloatProperty(
86 name = "Radius", default=0.2, min=0.0001,
87 description ="Radius of a stick")
88 sticks_unit_length: FloatProperty(
89 name = "Unit", default=0.05, min=0.0001,
90 description = "Length of the unit of a stick in Angstrom")
91 use_sticks_color: BoolProperty(
92 name="Color", default=True,
93 description="The sticks appear in the color of the atoms")
94 use_sticks_smooth: BoolProperty(
95 name="Smooth", default=True,
96 description="The sticks are round (sectors are not visible)")
97 use_sticks_bonds: BoolProperty(
98 name="Bonds", default=False,
99 description="Show double and triple bonds")
100 sticks_dist: FloatProperty(
101 name="", default = 0.8, min=0.0, max=3.0,
102 description="Distance between sticks (double or tripple bonds) measured in stick diameter")
103 use_sticks_one_object: BoolProperty(
104 name="One object", default=False,
105 description="All sticks are one object")
106 use_sticks_one_object_nr: IntProperty(
107 name = "No.", default=200, min=10,
108 description="Number of sticks to be grouped at once")
109 datafile: StringProperty(
110 name = "", description="Path to your custom data file",
111 maxlen = 256, default = "", subtype='FILE_PATH')
113 # This thing here just guarantees that the menu entry is not active when the
114 # check box in the addon preferences is not activated! See __init__.py
115 @classmethod
116 def poll(cls, context):
117 pref = context.preferences
118 return pref.addons[__package__].preferences.bool_pdb
120 def draw(self, context):
121 layout = self.layout
122 row = layout.row()
123 row.prop(self, "use_camera")
124 row.prop(self, "use_light")
125 row = layout.row()
126 row.prop(self, "use_center")
127 # Balls
128 box = layout.box()
129 row = box.row()
130 row.label(text="Balls / atoms")
131 row = box.row()
132 col = row.column()
133 col.prop(self, "ball")
134 row = box.row()
135 row.active = (self.ball == "1")
136 col = row.column(align=True)
137 col.prop(self, "mesh_azimuth")
138 col.prop(self, "mesh_zenith")
139 row = box.row()
140 col = row.column()
141 col.label(text="Scaling factors")
142 col = row.column(align=True)
143 col.prop(self, "scale_ballradius")
144 col.prop(self, "scale_distances")
145 row = box.row()
146 row.prop(self, "atomradius")
147 # Sticks
148 box = layout.box()
149 row = box.row()
150 row.label(text="Sticks / bonds")
151 row = box.row()
152 row.prop(self, "use_sticks")
153 row = box.row()
154 row.active = self.use_sticks
155 row.prop(self, "use_sticks_type")
156 row = box.row()
157 row.active = self.use_sticks
158 col = row.column()
159 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
160 col.prop(self, "sticks_sectors")
161 col.prop(self, "sticks_radius")
162 if self.use_sticks_type == '1':
163 row = box.row()
164 row.active = self.use_sticks
165 row.prop(self, "sticks_subdiv_view")
166 row.prop(self, "sticks_subdiv_render")
167 row = box.row()
168 row.active = self.use_sticks
169 if self.use_sticks_type == '0':
170 col.prop(self, "sticks_unit_length")
171 col = row.column(align=True)
172 if self.use_sticks_type == '0':
173 col.prop(self, "use_sticks_color")
174 col.prop(self, "use_sticks_smooth")
175 if self.use_sticks_type == '0' or self.use_sticks_type == '2':
176 col.prop(self, "use_sticks_bonds")
177 row = box.row()
178 if self.use_sticks_type == '0':
179 row.active = self.use_sticks and self.use_sticks_bonds
180 row.label(text="Distance")
181 row.prop(self, "sticks_dist")
182 if self.use_sticks_type == '2':
183 row.active = self.use_sticks
184 col = row.column()
185 col.prop(self, "use_sticks_one_object")
186 col = row.column()
187 col.active = self.use_sticks_one_object
188 col.prop(self, "use_sticks_one_object_nr")
189 row = box.row()
190 row.active = self.use_sticks and self.use_sticks_bonds
191 row.label(text="Distance")
192 row.prop(self, "sticks_dist")
194 def execute(self, context):
195 # Switch to 'OBJECT' mode when in 'EDIT' mode.
196 if bpy.context.mode == 'EDIT_MESH':
197 bpy.ops.object.mode_set(mode='OBJECT', toggle=False)
199 # This is in order to solve this strange 'relative path' thing.
200 filepath_pdb = bpy.path.abspath(self.filepath)
202 # Execute main routine
203 import_pdb(self.ball,
204 self.mesh_azimuth,
205 self.mesh_zenith,
206 self.scale_ballradius,
207 self.atomradius,
208 self.scale_distances,
209 self.use_sticks,
210 self.use_sticks_type,
211 self.sticks_subdiv_view,
212 self.sticks_subdiv_render,
213 self.use_sticks_color,
214 self.use_sticks_smooth,
215 self.use_sticks_bonds,
216 self.use_sticks_one_object,
217 self.use_sticks_one_object_nr,
218 self.sticks_unit_length,
219 self.sticks_dist,
220 self.sticks_sectors,
221 self.sticks_radius,
222 self.use_center,
223 self.use_camera,
224 self.use_light,
225 filepath_pdb)
227 return {'FINISHED'}
230 # This is the class for the file dialog of the exporter.
231 class EXPORT_OT_pdb(Operator, ExportHelper):
232 bl_idname = "export_mesh.pdb"
233 bl_label = "Export Protein Data Bank(*.pdb)"
234 filename_ext = ".pdb"
236 filter_glob: StringProperty(
237 default="*.pdb", options={'HIDDEN'},)
239 atom_pdb_export_type: EnumProperty(
240 name="Type of Objects",
241 description="Choose type of objects",
242 items=(('0', "All", "Export all active objects"),
243 ('1', "Elements", "Export only those active objects which have"
244 " a proper element name")),
245 default='1',)
247 # This thing here just guarantees that the menu entry is not active when the
248 # check box in the addon preferences is not activated! See __init__.py
249 @classmethod
250 def poll(cls, context):
251 pref = context.preferences
252 return pref.addons[__package__].preferences.bool_pdb
254 def draw(self, context):
255 layout = self.layout
256 row = layout.row()
257 row.prop(self, "atom_pdb_export_type")
259 def execute(self, context):
260 export_pdb(self.atom_pdb_export_type,
261 bpy.path.abspath(self.filepath))
263 return {'FINISHED'}