sun_position: fix warning from deleted prop in User Preferences
[blender-addons.git] / archipack / __init__.py
blob331afcc3eae4214680f30c0d60e29d95e358bb36
1 # -*- coding:utf-8 -*-
3 # ##### BEGIN GPL LICENSE BLOCK #####
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License
7 # as published by the Free Software Foundation; either version 2
8 # of the License, or (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software Foundation,
17 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 # ##### END GPL LICENSE BLOCK #####
21 # <pep8 compliant>
23 # ----------------------------------------------------------
24 # Author: Stephen Leger (s-leger)
26 # ----------------------------------------------------------
28 bl_info = {
29 'name': 'Archipack',
30 'description': 'Architectural objects',
31 'author': 's-leger',
32 'license': 'GPL',
33 'deps': '',
34 'version': (1, 2, 83),
35 'blender': (2, 80, 0),
36 'location': 'View3D > Sidebar > Create > Archipack',
37 'warning': '',
38 'wiki_url': 'https://github.com/s-leger/archipack/wiki',
39 'tracker_url': 'https://github.com/s-leger/archipack/issues',
40 'link': 'https://github.com/s-leger/archipack',
41 'support': 'COMMUNITY',
42 'category': 'Add Mesh'
45 import os
47 if "bpy" in locals():
48 import importlib as imp
49 imp.reload(archipack_material)
50 imp.reload(archipack_snap)
51 imp.reload(archipack_manipulator)
52 imp.reload(archipack_reference_point)
53 imp.reload(archipack_autoboolean)
54 imp.reload(archipack_door)
55 imp.reload(archipack_window)
56 imp.reload(archipack_stair)
57 imp.reload(archipack_wall2)
58 imp.reload(archipack_roof)
59 imp.reload(archipack_slab)
60 imp.reload(archipack_fence)
61 imp.reload(archipack_truss)
62 imp.reload(archipack_floor)
63 imp.reload(archipack_rendering)
65 # print("archipack: reload ready")
66 else:
67 from . import archipack_material
68 from . import archipack_snap
69 from . import archipack_manipulator
70 from . import archipack_reference_point
71 from . import archipack_autoboolean
72 from . import archipack_door
73 from . import archipack_window
74 from . import archipack_stair
75 from . import archipack_wall2
76 from . import archipack_roof
77 from . import archipack_slab
78 from . import archipack_fence
79 from . import archipack_truss
80 from . import archipack_floor
81 from . import archipack_rendering
82 # print("archipack: ready")
84 # noinspection PyUnresolvedReferences
85 import bpy
86 # noinspection PyUnresolvedReferences
87 from bpy.types import (
88 Panel, WindowManager, PropertyGroup,
89 AddonPreferences, Menu
91 from bpy.props import (
92 EnumProperty, PointerProperty,
93 StringProperty, BoolProperty,
94 IntProperty, FloatProperty, FloatVectorProperty
97 from bpy.utils import previews
98 icons_collection = {}
101 # ----------------------------------------------------
102 # Addon preferences
103 # ----------------------------------------------------
106 class Archipack_Pref(AddonPreferences):
107 bl_idname = __name__
109 create_submenu : BoolProperty(
110 name="Use Sub-menu",
111 description="Put Achipack's object into a sub menu (shift+a)",
112 default=True
114 max_style_draw_tool : BoolProperty(
115 name="Draw a wall use 3dsmax style",
116 description="Reverse clic / release & drag cycle for Draw a wall",
117 default=True
119 # Arrow sizes (world units)
120 arrow_size : FloatProperty(
121 name="Arrow",
122 description="Manipulators arrow size (blender units)",
123 default=0.05
125 # Handle area size (pixels)
126 handle_size : IntProperty(
127 name="Handle",
128 description="Manipulators handle sensitive area size (pixels)",
129 min=2,
130 default=10
132 constant_handle_size: BoolProperty(
133 name="Constant handle size",
134 description="When checked, handle size on scree remains constant (handle size pixels)",
135 default=False
137 text_size: IntProperty(
138 name="Manipulators",
139 description="Manipulator font size (pixels)",
140 min=2,
141 default=14
143 handle_colour_selected: FloatVectorProperty(
144 name="Selected handle colour",
145 description="Handle color when selected",
146 subtype='COLOR_GAMMA',
147 default=(0.0, 0.0, 0.7, 1.0),
148 size=4,
149 min=0, max=1
151 handle_colour_inactive: FloatVectorProperty(
152 name="Inactive handle colour",
153 description="Handle color when disabled",
154 subtype='COLOR_GAMMA',
155 default=(0.3, 0.3, 0.3, 1.0),
156 size=4,
157 min=0, max=1
159 handle_colour_normal: FloatVectorProperty(
160 name="Handle colour normal",
161 description="Base handle color when not selected",
162 subtype='COLOR_GAMMA',
163 default=(1.0, 1.0, 1.0, 1.0),
164 size=4,
165 min=0, max=1
167 handle_colour_hover: FloatVectorProperty(
168 name="Handle colour hover",
169 description="Handle color when mouse hover",
170 subtype='COLOR_GAMMA',
171 default=(1.0, 1.0, 0.0, 1.0),
172 size=4,
173 min=0, max=1
175 handle_colour_active: FloatVectorProperty(
176 name="Handle colour active",
177 description="Handle colour when moving",
178 subtype='COLOR_GAMMA',
179 default=(1.0, 0.0, 0.0, 1.0),
180 size=4,
181 min=0, max=1
183 matlib_path : StringProperty(
184 name="Folder path",
185 description="absolute path to material library folder",
186 default="",
187 subtype="DIR_PATH"
189 # Font sizes and basic colour scheme
190 feedback_size_main : IntProperty(
191 name="Main",
192 description="Main title font size (pixels)",
193 min=2,
194 default=16
196 feedback_size_title : IntProperty(
197 name="Title",
198 description="Tool name font size (pixels)",
199 min=2,
200 default=14
202 feedback_size_shortcut : IntProperty(
203 name="Shortcut",
204 description="Shortcuts font size (pixels)",
205 min=2,
206 default=11
208 feedback_shortcut_area : FloatVectorProperty(
209 name="Background Shortcut",
210 description="Shortcut area background color",
211 subtype='COLOR_GAMMA',
212 default=(0, 0.4, 0.6, 0.2),
213 size=4,
214 min=0, max=1
216 feedback_title_area : FloatVectorProperty(
217 name="Background Main",
218 description="Title area background color",
219 subtype='COLOR_GAMMA',
220 default=(0, 0.4, 0.6, 0.5),
221 size=4,
222 min=0, max=1
224 feedback_colour_main : FloatVectorProperty(
225 name="Font Main",
226 description="Title color",
227 subtype='COLOR_GAMMA',
228 default=(0.95, 0.95, 0.95, 1.0),
229 size=4,
230 min=0, max=1
232 feedback_colour_key : FloatVectorProperty(
233 name="Font Shortcut key",
234 description="KEY label color",
235 subtype='COLOR_GAMMA',
236 default=(0.67, 0.67, 0.67, 1.0),
237 size=4,
238 min=0, max=1
240 feedback_colour_shortcut : FloatVectorProperty(
241 name="Font Shortcut hint",
242 description="Shortcuts text color",
243 subtype='COLOR_GAMMA',
244 default=(0.51, 0.51, 0.51, 1.0),
245 size=4,
246 min=0, max=1
249 def draw(self, context):
250 layout = self.layout
251 box = layout.box()
252 row = box.row()
253 col = row.column()
254 col.label(text="Setup actions")
255 col.prop(self, "matlib_path", text="Material library")
256 box.label(text="Render presets Thumbnails")
257 box.operator("archipack.render_thumbs", icon='ERROR')
258 box = layout.box()
259 row = box.row()
260 col = row.column()
261 col.label(text="Add menu:")
262 col.prop(self, "create_submenu")
264 box = layout.box()
265 box.label(text="Features")
266 box.prop(self, "max_style_draw_tool")
267 box = layout.box()
268 row = box.row()
269 split = row.split(factor=0.5)
270 col = split.column()
271 col.label(text="Colors:")
272 row = col.row(align=True)
273 row.prop(self, "feedback_title_area")
274 row = col.row(align=True)
275 row.prop(self, "feedback_shortcut_area")
276 row = col.row(align=True)
277 row.prop(self, "feedback_colour_main")
278 row = col.row(align=True)
279 row.prop(self, "feedback_colour_key")
280 row = col.row(align=True)
281 row.prop(self, "feedback_colour_shortcut")
282 row = col.row(align=True)
283 row.prop(self, "handle_colour_normal")
284 row = col.row(align=True)
285 row.prop(self, "handle_colour_hover")
286 row = col.row(align=True)
287 row.prop(self, "handle_colour_active")
288 row = col.row(align=True)
289 row.prop(self, "handle_colour_selected")
290 row = col.row(align=True)
291 row.prop(self, "handle_colour_inactive")
292 col = split.column()
293 col.label(text="Font size:")
294 col.prop(self, "feedback_size_main")
295 col.prop(self, "feedback_size_title")
296 col.prop(self, "feedback_size_shortcut")
297 col.label(text="Manipulators:")
298 col.prop(self, "arrow_size")
299 col.prop(self, "handle_size")
300 col.prop(self, "text_size")
301 col.prop(self, "constant_handle_size")
303 # ----------------------------------------------------
304 # Archipack panel
305 # ----------------------------------------------------
307 class TOOLS_PT_Archipack_Create(Panel):
308 bl_label = "Archipack"
309 bl_idname = "TOOLS_PT_Archipack_Create"
310 bl_space_type = "VIEW_3D"
311 bl_region_type = "UI"
312 bl_category = "Create"
313 bl_context = "objectmode"
314 bl_options = {'DEFAULT_CLOSED'}
316 @classmethod
317 def poll(self, context):
318 return True
320 def draw(self, context):
321 global icons_collection
323 icons = icons_collection["main"]
324 layout = self.layout
325 box = layout.box()
326 box.operator("archipack.auto_boolean", text="Boolean", icon='AUTO').mode = 'HYBRID'
327 row = layout.row(align=True)
328 box = row.box()
329 box.label(text="Create")
330 row = box.row(align=True)
331 row.operator("archipack.window_preset_menu",
332 text="Window",
333 icon_value=icons["window"].icon_id
334 ).preset_operator = "archipack.window"
335 row.operator("archipack.window_preset_menu",
336 text="",
337 icon='GREASEPENCIL'
338 ).preset_operator = "archipack.window_draw"
339 row = box.row(align=True)
340 row.operator("archipack.door_preset_menu",
341 text="Door",
342 icon_value=icons["door"].icon_id
343 ).preset_operator = "archipack.door"
344 row.operator("archipack.door_preset_menu",
345 text="",
346 icon='GREASEPENCIL'
347 ).preset_operator = "archipack.door_draw"
348 row = box.row(align=True)
349 row.operator("archipack.stair_preset_menu",
350 text="Stair",
351 icon_value=icons["stair"].icon_id
352 ).preset_operator = "archipack.stair"
353 row = box.row(align=True)
354 row.operator("archipack.wall2",
355 icon_value=icons["wall"].icon_id
357 row.operator("archipack.wall2_draw", text="Draw", icon='GREASEPENCIL')
358 row.operator("archipack.wall2_from_curve", text="", icon='CURVE_DATA')
360 row = box.row(align=True)
361 row.operator("archipack.fence_preset_menu",
362 text="Fence",
363 icon_value=icons["fence"].icon_id
364 ).preset_operator = "archipack.fence"
365 row.operator("archipack.fence_from_curve", text="", icon='CURVE_DATA')
366 row = box.row(align=True)
367 row.operator("archipack.truss",
368 icon_value=icons["truss"].icon_id
370 row = box.row(align=True)
371 row.operator("archipack.slab_from_curve",
372 icon_value=icons["slab"].icon_id
374 row = box.row(align=True)
375 row.operator("archipack.wall2_from_slab",
376 icon_value=icons["wall"].icon_id)
377 row.operator("archipack.slab_from_wall",
378 icon_value=icons["slab"].icon_id
379 ).ceiling = False
380 row.operator("archipack.slab_from_wall",
381 text="->Ceiling",
382 icon_value=icons["slab"].icon_id
383 ).ceiling = True
384 row = box.row(align=True)
385 row.operator("archipack.roof_preset_menu",
386 text="Roof",
387 icon_value=icons["roof"].icon_id
388 ).preset_operator = "archipack.roof"
389 row = box.row(align=True)
390 row.operator("archipack.floor_preset_menu",
391 text="Floor",
392 icon_value=icons["floor"].icon_id
393 ).preset_operator = "archipack.floor"
394 row.operator("archipack.floor_preset_menu",
395 text="->Wall",
396 icon_value=icons["floor"].icon_id
397 ).preset_operator = "archipack.floor_from_wall"
398 row.operator("archipack.floor_preset_menu",
399 text="",
400 icon='CURVE_DATA').preset_operator = "archipack.floor_from_curve"
403 # ----------------------------------------------------
404 # ALT + A menu
405 # ----------------------------------------------------
408 def draw_menu(self, context):
409 global icons_collection
410 icons = icons_collection["main"]
411 layout = self.layout
412 layout.operator_context = 'INVOKE_REGION_WIN'
414 layout.operator("archipack.wall2",
415 text="Wall",
416 icon_value=icons["wall"].icon_id
418 layout.operator("archipack.window_preset_menu",
419 text="Window",
420 icon_value=icons["window"].icon_id
421 ).preset_operator = "archipack.window"
422 layout.operator("archipack.door_preset_menu",
423 text="Door",
424 icon_value=icons["door"].icon_id
425 ).preset_operator = "archipack.door"
426 layout.operator("archipack.stair_preset_menu",
427 text="Stair",
428 icon_value=icons["stair"].icon_id
429 ).preset_operator = "archipack.stair"
430 layout.operator("archipack.fence_preset_menu",
431 text="Fence",
432 icon_value=icons["fence"].icon_id
433 ).preset_operator = "archipack.fence"
434 layout.operator("archipack.truss",
435 text="Truss",
436 icon_value=icons["truss"].icon_id
438 layout.operator("archipack.floor_preset_menu",
439 text="Floor",
440 icon_value=icons["floor"].icon_id
441 ).preset_operator = "archipack.floor"
442 layout.operator("archipack.roof_preset_menu",
443 text="Roof",
444 icon_value=icons["roof"].icon_id
445 ).preset_operator = "archipack.roof"
448 class ARCHIPACK_MT_create(Menu):
449 bl_label = 'Archipack'
451 def draw(self, context):
452 draw_menu(self, context)
455 def menu_func(self, context):
456 layout = self.layout
457 layout.separator()
458 global icons_collection
459 icons = icons_collection["main"]
461 # either draw sub menu or right at end of this one
462 if context.preferences.addons[__name__].preferences.create_submenu:
463 layout.operator_context = 'INVOKE_REGION_WIN'
464 layout.menu("ARCHIPACK_MT_create", icon_value=icons["archipack"].icon_id)
465 else:
466 draw_menu(self, context)
469 def register():
470 global icons_collection
471 icons = previews.new()
472 icons_dir = os.path.join(os.path.dirname(__file__), "icons")
473 for icon in os.listdir(icons_dir):
474 name, ext = os.path.splitext(icon)
475 icons.load(name, os.path.join(icons_dir, icon), 'IMAGE')
476 icons_collection["main"] = icons
477 archipack_material.register()
478 archipack_snap.register()
479 archipack_manipulator.register()
480 archipack_reference_point.register()
481 archipack_autoboolean.register()
482 archipack_door.register()
483 archipack_window.register()
484 archipack_stair.register()
485 archipack_wall2.register()
486 archipack_roof.register()
487 archipack_slab.register()
488 archipack_fence.register()
489 archipack_truss.register()
490 archipack_floor.register()
491 archipack_rendering.register()
492 bpy.utils.register_class(Archipack_Pref)
493 bpy.utils.register_class(TOOLS_PT_Archipack_Create)
494 bpy.utils.register_class(ARCHIPACK_MT_create)
495 bpy.types.VIEW3D_MT_mesh_add.append(menu_func)
498 def unregister():
499 global icons_collection
500 bpy.types.VIEW3D_MT_mesh_add.remove(menu_func)
501 bpy.utils.unregister_class(ARCHIPACK_MT_create)
502 bpy.utils.unregister_class(TOOLS_PT_Archipack_Create)
503 bpy.utils.unregister_class(Archipack_Pref)
504 archipack_material.unregister()
505 archipack_snap.unregister()
506 archipack_manipulator.unregister()
507 archipack_reference_point.unregister()
508 archipack_autoboolean.unregister()
509 archipack_door.unregister()
510 archipack_window.unregister()
511 archipack_stair.unregister()
512 archipack_wall2.unregister()
513 archipack_roof.unregister()
514 archipack_slab.unregister()
515 archipack_fence.unregister()
516 archipack_truss.unregister()
517 archipack_floor.unregister()
518 archipack_rendering.unregister()
520 for icons in icons_collection.values():
521 previews.remove(icons)
522 icons_collection.clear()
525 if __name__ == "__main__":
526 register()