Fix T70724: PLY import fails with strings
[blender-addons.git] / mesh_snap_utilities_line / preferences.py
blob7f27507afcedd44c6341fc0fb8e8b5c27e7787b3
1 ### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 3
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 # ##### END GPL LICENSE BLOCK #####
17 import bpy
19 from bpy.props import (
20 EnumProperty,
21 StringProperty,
22 BoolProperty,
23 IntProperty,
24 FloatVectorProperty,
25 FloatProperty,
28 from bpy.app.translations import contexts as i18n_contexts
30 import rna_keymap_ui
33 class SnapUtilitiesPreferences(bpy.types.AddonPreferences):
34 # this must match the addon name, use '__package__'
35 # when defining this in a submodule of a python package.
36 bl_idname = __package__
38 intersect : BoolProperty(name="Intersect",
39 description="intersects created line with the existing edges, even if the lines do not intersect",
40 default=True)
42 create_face : BoolProperty(name="Create faces",
43 description="Create faces defined by enclosed edges",
44 default=False)
46 outer_verts : BoolProperty(name="Snap to outer vertices",
47 description="The vertices of the objects are not activated also snapped",
48 default=True)
50 increments_grid : BoolProperty(name="Increments of Grid",
51 description="Snap to increments of grid",
52 default=False)
54 auto_constrain : BoolProperty(name="Automatic Constraint",
55 description="Detects a direction to constrain depending on the position of the mouse.",
56 default=False)
58 incremental : FloatProperty(name="Incremental",
59 description="Snap in defined increments",
60 default=0,
61 min=0,
62 step=1,
63 precision=3)
65 relative_scale : FloatProperty(name="Relative Scale",
66 description="Value that divides the global scale",
67 default=1,
68 min=0,
69 step=1,
70 precision=3)
72 out_color : FloatVectorProperty(name="Floor",
73 default=(0.0, 0.0, 0.0, 0.5),
74 size=4,
75 subtype="COLOR",
76 min=0,
77 max=1)
79 face_color : FloatVectorProperty(name="Face Highlighted",
80 default=(1.0, 0.8, 0.0, 0.5),
81 size=4,
82 subtype="COLOR",
83 min=0,
84 max=1)
86 edge_color : FloatVectorProperty(name="Edge Highlighted",
87 default=(0.0, 0.8, 1.0, 0.5),
88 size=4,
89 subtype="COLOR",
90 min=0,
91 max=1)
93 vert_color : FloatVectorProperty(name="Vertex Highlighted",
94 default=(1.0, 0.5, 0.0, 0.5),
95 size=4, subtype="COLOR",
96 min=0,
97 max=1)
99 center_color : FloatVectorProperty(name="Middle of the Edge",
100 default=(1.0, 0.0, 1.0, 1.0),
101 size=4,
102 subtype="COLOR",
103 min=0,
104 max=1)
106 perpendicular_color : FloatVectorProperty(name="Perpendicular Point",
107 default=(0.1, 0.5, 0.5, 1.0),
108 size=4,
109 subtype="COLOR",
110 min=0,
111 max=1)
113 constrain_shift_color : FloatVectorProperty(name="Shift Constrain",
114 default=(0.8, 0.5, 0.4, 1.0),
115 size=4,
116 subtype="COLOR",
117 min=0,
118 max=1)
120 tabs : EnumProperty(name="Tabs",
121 items = [("GENERAL", "General", ""),
122 ("KEYMAPS", "Keymaps", ""),
123 ("COLORS", "Colors", ""),
124 ("HELP", "Links", ""),],
125 default="GENERAL")
127 def draw(self, context):
128 layout = self.layout
130 # TAB BAR
131 row = layout.row()
132 row.prop(self, "tabs", expand=True)
134 box = layout.box()
136 if self.tabs == "GENERAL":
137 self.draw_general(box)
139 elif self.tabs == "COLORS":
140 self.draw_snap_utilities_colors(box)
142 elif self.tabs == "KEYMAPS":
143 self.draw_snap_utilities_keymaps(context, box)
145 elif self.tabs == "HELP":
146 self.draw_snap_utilities_help(box)
148 def draw_general(self, layout):
149 row = layout.row()
150 col = row.column()
152 col.label(text="Snap Properties:")
153 col.prop(self, "incremental")
154 col.prop(self, "increments_grid")
155 if self.increments_grid:
156 col.prop(self, "relative_scale")
158 col.prop(self, "outer_verts")
159 row.separator()
161 col = row.column()
162 col.label(text="Line Tool:")
163 col.prop(self, "intersect")
164 col.prop(self, "create_face")
166 def draw_snap_utilities_colors(self, layout):
167 layout.use_property_split = True
169 flow = layout.grid_flow(row_major=False, columns=0, even_columns=True, even_rows=False, align=False)
171 flow.prop(self, "out_color")
172 flow.prop(self, "constrain_shift_color")
173 flow.prop(self, "face_color")
174 flow.prop(self, "edge_color")
175 flow.prop(self, "vert_color")
176 flow.prop(self, "center_color")
177 flow.prop(self, "perpendicular_color")
179 def draw_snap_utilities_help(self, layout):
180 #layout.operator("wm.url_open", text="Gumroad Page", icon='HELP',).url = "https://gum.co/IaqQf"
181 #layout.operator("wm.url_open", text="Blender Market Page", icon='HELP',).url = "https://blendermarket.com/products/snap-utilities"
182 layout.operator("wm.url_open", text="Wiki", icon='HELP',).url = "https://github.com/Mano-Wii/Addon-Snap-Utilities-Line/wiki"
183 layout.operator("wm.url_open", text="Forum", icon='HELP',).url = "https://blenderartists.org/t/cad-snap-utilities"
186 def draw_snap_utilities_keymaps(self, context, layout):
187 from .keys import (
188 generate_snap_utilities_global_keymaps,
189 generate_snap_utilities_tools_keymaps,
192 wm = context.window_manager
193 #kc = wm.keyconfigs.addon
194 kc = wm.keyconfigs.user
196 layout.label(text="Global:")
198 for km_name, km_args, km_content in generate_snap_utilities_global_keymaps():
199 km = kc.keymaps.get(km_name)
200 if km:
201 self.draw_snap_utilities_km(kc, km, layout)
203 layout.label(text="Tools:")
205 for km_name, km_args, km_content in generate_snap_utilities_tools_keymaps():
206 km = kc.keymaps.get(km_name)
207 if km:
208 self.draw_snap_utilities_km(kc, km, layout)
210 @staticmethod
211 def draw_snap_utilities_km(kc, km, layout):
212 layout.context_pointer_set("keymap", km)
214 row = layout.row()
215 row.prop(km, "show_expanded_items", text="", emboss=False)
216 row.label(text=km.name, text_ctxt=i18n_contexts.id_windowmanager)
218 if km.show_expanded_items:
219 col = layout.column()
221 for kmi in km.keymap_items:
222 if "snap_utilities" in kmi.idname:
223 rna_keymap_ui.draw_kmi(["ADDON", "USER", "DEFAULT"], kc, km, kmi, col, 0)