1 # SPDX-FileCopyrightText: 2018-2022 Blender Foundation
3 # SPDX-License-Identifier: GPL-2.0-or-later
7 from bpy
.props
import (
16 from bpy
.app
.translations
import contexts
as i18n_contexts
21 class SnapUtilitiesPreferences(bpy
.types
.AddonPreferences
):
22 # this must match the addon name, use '__package__'
23 # when defining this in a submodule of a python package.
24 bl_idname
= __package__
26 intersect
: BoolProperty(
28 description
="intersects created line with the existing edges, even if the lines do not intersect",
31 create_face
: BoolProperty(name
="Create faces",
32 description
="Create faces defined by enclosed edges",
35 outer_verts
: BoolProperty(name
="Snap to outer vertices",
36 description
="The vertices of the objects are not activated also snapped",
39 increments_grid
: BoolProperty(name
="Increments of Grid",
40 description
="Snap to increments of grid",
43 auto_constrain
: BoolProperty(name
="Automatic Constraint",
44 description
="Detects a direction to constrain depending on the position of the mouse",
47 incremental
: FloatProperty(name
="Incremental",
48 description
="Snap in defined increments",
54 relative_scale
: FloatProperty(name
="Relative Scale",
55 description
="Value that divides the global scale",
61 out_color
: FloatVectorProperty(name
="Floor",
62 default
=(0.0, 0.0, 0.0, 0.5),
68 face_color
: FloatVectorProperty(name
="Face Highlighted",
69 default
=(1.0, 0.8, 0.0, 0.5),
75 edge_color
: FloatVectorProperty(name
="Edge Highlighted",
76 default
=(0.0, 0.8, 1.0, 0.5),
82 vert_color
: FloatVectorProperty(name
="Vertex Highlighted",
83 default
=(1.0, 0.5, 0.0, 0.5),
84 size
=4, subtype
="COLOR",
88 center_color
: FloatVectorProperty(name
="Middle of the Edge",
89 default
=(1.0, 0.0, 1.0, 1.0),
95 perpendicular_color
: FloatVectorProperty(name
="Perpendicular Point",
96 default
=(0.1, 0.5, 0.5, 1.0),
102 constrain_shift_color
: FloatVectorProperty(name
="Shift Constrain",
103 default
=(0.8, 0.5, 0.4, 1.0),
109 tabs
: EnumProperty(name
="Tabs",
110 items
=[("GENERAL", "General", ""),
111 ("KEYMAPS", "Keymaps", ""),
112 ("COLORS", "Colors", ""),
113 ("HELP", "Links", ""), ],
116 def draw(self
, context
):
121 row
.prop(self
, "tabs", expand
=True)
125 if self
.tabs
== "GENERAL":
126 self
.draw_general(box
)
128 elif self
.tabs
== "COLORS":
129 self
.draw_snap_utilities_colors(box
)
131 elif self
.tabs
== "KEYMAPS":
132 self
.draw_snap_utilities_keymaps(context
, box
)
134 elif self
.tabs
== "HELP":
135 self
.draw_snap_utilities_help(box
)
137 def draw_general(self
, layout
):
141 col
.label(text
="Snap Properties:")
142 col
.prop(self
, "incremental")
143 col
.prop(self
, "increments_grid")
144 if self
.increments_grid
:
145 col
.prop(self
, "relative_scale")
147 col
.prop(self
, "outer_verts")
151 col
.label(text
="Line Tool:")
152 col
.prop(self
, "intersect")
153 col
.prop(self
, "create_face")
155 def draw_snap_utilities_colors(self
, layout
):
156 layout
.use_property_split
= True
158 flow
= layout
.grid_flow(
159 row_major
=False, columns
=0, even_columns
=True, even_rows
=False, align
=False)
161 flow
.prop(self
, "out_color")
162 flow
.prop(self
, "constrain_shift_color")
163 flow
.prop(self
, "face_color")
164 flow
.prop(self
, "edge_color")
165 flow
.prop(self
, "vert_color")
166 flow
.prop(self
, "center_color")
167 flow
.prop(self
, "perpendicular_color")
169 def draw_snap_utilities_help(self
, layout
):
170 # layout.operator("wm.url_open", text="Gumroad Page", icon='HELP',).url = "https://gum.co/IaqQf"
171 # layout.operator("wm.url_open", text="Blender Market Page", icon='HELP',).url = "https://blendermarket.com/products/snap-utilities"
172 layout
.operator("wm.url_open", text
="Wiki", icon
='HELP',
173 ).url
= "https://github.com/Mano-Wii/Addon-Snap-Utilities-Line/wiki"
174 layout
.operator("wm.url_open", text
="Forum", icon
='HELP',
175 ).url
= "https://blenderartists.org/t/cad-snap-utilities"
177 def draw_snap_utilities_keymaps(self
, context
, layout
):
179 generate_snap_utilities_global_keymaps
,
180 generate_snap_utilities_tools_keymaps
,
183 wm
= context
.window_manager
184 # kc = wm.keyconfigs.addon
185 kc
= wm
.keyconfigs
.user
187 layout
.label(text
="Global:")
189 for km_name
, km_args
, km_content
in generate_snap_utilities_global_keymaps():
190 km
= kc
.keymaps
.get(km_name
)
192 self
.draw_snap_utilities_km(kc
, km
, layout
)
194 layout
.label(text
="Tools:")
196 for km_name
, km_args
, km_content
in generate_snap_utilities_tools_keymaps():
197 km
= kc
.keymaps
.get(km_name
)
199 self
.draw_snap_utilities_km(kc
, km
, layout
)
202 def draw_snap_utilities_km(kc
, km
, layout
):
203 layout
.context_pointer_set("keymap", km
)
206 row
.prop(km
, "show_expanded_items", text
="", emboss
=False)
207 row
.label(text
=km
.name
, text_ctxt
=i18n_contexts
.id_windowmanager
)
209 if km
.show_expanded_items
:
210 col
= layout
.column()
212 for kmi
in km
.keymap_items
:
213 if "snap_utilities" in kmi
.idname
:
214 rna_keymap_ui
.draw_kmi(
215 ["ADDON", "USER", "DEFAULT"], kc
, km
, kmi
, col
, 0)