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