Sun Position: fix error in HDRI mode when no env tex is selected
[blender-addons.git] / measureit / __init__.py
blob8868d8359aff50c3ecee5a9ee79a2fa5dda07fb8
1 # SPDX-License-Identifier: GPL-2.0-or-later
3 # ----------------------------------------------------------
4 # Author: Antonio Vazquez (antonioya)
5 # ----------------------------------------------------------
7 # ----------------------------------------------
8 # Define Addon info
9 # ----------------------------------------------
10 bl_info = {
11 "name": "MeasureIt",
12 "author": "Antonio Vazquez (antonioya)",
13 "location": "View3D > Sidebar > View Tab",
14 "version": (1, 8, 2),
15 "blender": (3, 0, 0),
16 "description": "Tools for measuring objects.",
17 "doc_url": "{BLENDER_MANUAL_URL}/addons/3d_view/measureit.html",
18 "category": "3D View"
22 # ----------------------------------------------
23 # Import modules
24 # ----------------------------------------------
25 if "bpy" in locals():
26 import importlib
28 importlib.reload(measureit_main)
29 # print("measureit: Reloaded multifiles")
30 else:
31 from . import measureit_main
32 # print("measureit: Imported multifiles")
34 # noinspection PyUnresolvedReferences
35 import bpy
36 from bpy.types import (
37 AddonPreferences,
38 Scene,
39 WindowManager,
41 from bpy.props import (
42 FloatVectorProperty,
43 IntProperty,
44 BoolProperty,
45 StringProperty,
46 FloatProperty,
47 EnumProperty,
50 # --------------------------------------------------------------
51 # Register all operators and panels
52 # --------------------------------------------------------------
54 # Add-ons Preferences Update Panel
56 # Define Panel classes for updating
57 panels = (
58 measureit_main.MEASUREIT_PT_Edit,
59 measureit_main.MEASUREIT_PT_Main,
60 measureit_main.MEASUREIT_PT_Conf,
61 measureit_main.MEASUREIT_PT_Render,
65 def update_panel(self, context):
66 message = "MeasureIt: Updating Panel locations has failed"
67 try:
68 for panel in panels:
69 if "bl_rna" in panel.__dict__:
70 bpy.utils.unregister_class(panel)
72 for panel in panels:
73 panel.bl_category = context.preferences.addons[__name__].preferences.category
74 bpy.utils.register_class(panel)
76 except Exception as e:
77 print("\n[{}]\n{}\n\nError:\n{}".format(__name__, message, e))
78 pass
81 class Measure_Pref(AddonPreferences):
82 # this must match the addon name, use '__package__'
83 # when defining this in a submodule of a python package.
84 bl_idname = __name__
86 category: StringProperty(
87 name="Tab Category",
88 description="Choose a name for the category of the panel",
89 default="Display",
90 update=update_panel
93 def draw(self, context):
94 layout = self.layout
96 row = layout.row()
97 col = row.column()
98 col.label(text="Tab Category:")
99 col.prop(self, "category", text="")
102 # Define menu
103 # noinspection PyUnusedLocal
104 classes = (
105 measureit_main.MEASUREIT_OT_RunHintDisplay,
106 measureit_main.MEASUREIT_OT_AddSegment,
107 measureit_main.MEASUREIT_OT_AddArea,
108 measureit_main.MEASUREIT_OT_AddSegmentOrto,
109 measureit_main.MEASUREIT_OT_AddAngle,
110 measureit_main.MEASUREIT_OT_AddArc,
111 measureit_main.MEASUREIT_OT_AddLabel,
112 measureit_main.MEASUREIT_OT_AddNote,
113 measureit_main.MEASUREIT_OT_AddLink,
114 measureit_main.MEASUREIT_OT_AddOrigin,
115 measureit_main.MEASUREIT_OT_DeleteSegment,
116 measureit_main.MEASUREIT_OT_DeleteAllSegment,
117 measureit_main.MEASUREIT_OT_DeleteAllSum,
118 measureit_main.MEASUREIT_OT_RenderSegment,
119 measureit_main.MEASUREIT_OT_ExpandAllSegment,
120 measureit_main.MEASUREIT_OT_CollapseAllSegment,
121 measureit_main.MEASUREIT_PT_Main,
122 measureit_main.MEASUREIT_PT_Edit,
123 measureit_main.MEASUREIT_PT_Conf,
124 measureit_main.MEASUREIT_PT_Render,
125 # Measure_Pref,
128 def register():
129 from bpy.utils import register_class
130 for cls in classes:
131 register_class(cls)
133 # Define properties
134 Scene.measureit_default_color = FloatVectorProperty(
135 name="Default color",
136 description="Default Color",
137 default=(0.173, 0.545, 1.0, 1.0),
138 min=0.1,
139 max=1,
140 subtype='COLOR',
141 size=4)
142 Scene.measureit_font_size = IntProperty(name="Text Size",
143 description="Default text size",
144 default=14, min=10, max=150)
145 Scene.measureit_hint_space = FloatProperty(name='Separation', min=0, max=100, default=0.1,
146 precision=3,
147 description="Default distance to display measure")
148 Scene.measureit_gl_ghost = BoolProperty(name="All",
149 description="Display measures for all objects,"
150 " not only selected",
151 default=True)
152 Scene.measureit_gl_txt = StringProperty(name="Text", maxlen=256,
153 description="Short description (use | for line break)")
155 Scene.measureit_gl_precision = IntProperty(name='Precision', min=0, max=5, default=2,
156 description="Number of decimal precision")
157 Scene.measureit_gl_show_d = BoolProperty(name="ShowDist",
158 description="Display distances",
159 default=True)
160 Scene.measureit_gl_show_n = BoolProperty(name="ShowName",
161 description="Display texts",
162 default=False)
163 Scene.measureit_scale = BoolProperty(name="Scale",
164 description="Use scale factor",
165 default=False)
166 Scene.measureit_scale_factor = FloatProperty(name='Factor', min=0.001, max=9999999,
167 default=1.0,
168 precision=3,
169 description="Scale factor 1:x")
170 Scene.measureit_scale_color = FloatVectorProperty(name="Scale color",
171 description="Scale Color",
172 default=(1, 1, 0, 1.0),
173 min=0.1,
174 max=1,
175 subtype='COLOR',
176 size=4)
177 Scene.measureit_scale_font = IntProperty(name="Font",
178 description="Text size",
179 default=14, min=10, max=150)
180 Scene.measureit_scale_pos_x = IntProperty(name="X Position",
181 description="Margin on the X axis",
182 default=5,
183 min=0,
184 max=100)
185 Scene.measureit_scale_pos_y = IntProperty(name="Y Position",
186 description="Margin on the Y axis",
187 default=5,
188 min=0,
189 max=100)
190 Scene.measureit_gl_scaletxt = StringProperty(name="ScaleText", maxlen=48,
191 description="Scale title",
192 default="Scale:")
193 Scene.measureit_scale_precision = IntProperty(name='Precision', min=0, max=5, default=0,
194 description="Number of decimal precision")
195 Scene.measureit_ovr = BoolProperty(name="Override",
196 description="Override colors and fonts",
197 default=False)
198 Scene.measureit_ovr_font = IntProperty(name="Font",
199 description="Override text size",
200 default=14, min=10, max=150)
201 Scene.measureit_ovr_color = FloatVectorProperty(name="Override color",
202 description="Override Color",
203 default=(1, 0, 0, 1.0),
204 min=0.1,
205 max=1,
206 subtype='COLOR',
207 size=4)
208 Scene.measureit_ovr_width = IntProperty(name='Override width', min=1, max=10, default=1,
209 description='override line width')
211 Scene.measureit_ovr_font_rotation = IntProperty(name='Rotate', min=0, max=360, default=0,
212 description="Text rotation in degrees")
213 Scene.measureit_ovr_font_align = EnumProperty(items=(('L', "Left Align", "Use current render"),
214 ('C', "Center Align", ""),
215 ('R', "Right Align", "")),
216 name="Align Font",
217 description="Set Font Alignment")
218 Scene.measureit_units = EnumProperty(items=(('1', "Automatic", "Use scene units"),
219 ('2', "Meters", ""),
220 ('3', "Centimeters", ""),
221 ('4', "Millimeters", ""),
222 ('5', "Feet", ""),
223 ('6', "Inches", "")),
224 name="Units",
225 default="2",
226 description="Units")
227 Scene.measureit_hide_units = BoolProperty(name="hide_units",
228 description="Do not display unit of measurement on viewport",
229 default=False)
230 Scene.measureit_render = BoolProperty(name="Render",
231 description="Save an image with measures over"
232 " render image",
233 default=False)
234 Scene.measureit_render_type = EnumProperty(items=(('1', "Frame", "Render current frame"),
235 ('2', "Animation", "")),
236 name="Render type",
237 description="Type of render image")
238 Scene.measureit_sum = EnumProperty(items=(('99', "-", "Select a group for sum"),
239 ('0', "A", ""),
240 ('1', "B", ""),
241 ('2', "C", ""),
242 ('3', "D", ""),
243 ('4', "E", ""),
244 ('5', "F", ""),
245 ('6', "G", ""),
246 ('7', "H", ""),
247 ('8', "I", ""),
248 ('9', "J", ""),
249 ('10', "K", ""),
250 ('11', "L", ""),
251 ('12', "M", ""),
252 ('13', "N", ""),
253 ('14', "O", ""),
254 ('15', "P", ""),
255 ('16', "Q", ""),
256 ('17', "R", ""),
257 ('18', "S", ""),
258 ('19', "T", ""),
259 ('20', "U", ""),
260 ('21', "V", ""),
261 ('22', "W", ""),
262 ('23', "X", ""),
263 ('24', "Y", ""),
264 ('25', "Z", "")),
265 name="Sum in Group",
266 description="Add segment length in selected group")
268 Scene.measureit_rf = BoolProperty(name="render_frame",
269 description="Add a frame in render output",
270 default=False)
271 Scene.measureit_rf_color = FloatVectorProperty(name="Fcolor",
272 description="Frame Color",
273 default=(0.9, 0.9, 0.9, 1.0),
274 min=0.1,
275 max=1,
276 subtype='COLOR',
277 size=4)
278 Scene.measureit_rf_border = IntProperty(name='fborder ', min=1, max=1000, default=10,
279 description='Frame space from border')
280 Scene.measureit_rf_line = IntProperty(name='fline', min=1, max=10, default=1,
281 description='Line width for border')
283 Scene.measureit_glarrow_a = EnumProperty(items=(('99', "--", "No arrow"),
284 ('1', "Line",
285 "The point of the arrow are lines"),
286 ('2', "Triangle",
287 "The point of the arrow is triangle"),
288 ('3', "TShape",
289 "The point of the arrow is a T")),
290 name="A end",
291 description="Add arrows to point A")
292 Scene.measureit_glarrow_b = EnumProperty(items=(('99', "--", "No arrow"),
293 ('1', "Line",
294 "The point of the arrow are lines"),
295 ('2', "Triangle",
296 "The point of the arrow is triangle"),
297 ('3', "TShape",
298 "The point of the arrow is a T")),
299 name="B end",
300 description="Add arrows to point B")
301 Scene.measureit_glarrow_s = IntProperty(name="Size",
302 description="Arrow size",
303 default=15, min=6, max=500)
305 Scene.measureit_debug = BoolProperty(name="Debug",
306 description="Display information for debugging"
307 " (expand/collapse for enabling or disabling)"
308 " this information is only rendered for "
309 "selected objects",
310 default=False)
311 Scene.measureit_debug_select = BoolProperty(name="Selected",
312 description="Display information "
313 "only for selected items",
314 default=False)
315 Scene.measureit_debug_vertices = BoolProperty(name="Vertices",
316 description="Display vertex index number",
317 default=True)
318 Scene.measureit_debug_objects = BoolProperty(name="Objects",
319 description="Display object scene index number",
320 default=False)
321 Scene.measureit_debug_vert_loc = BoolProperty(name="Location",
322 description="Display vertex location",
323 default=False)
324 Scene.measureit_debug_object_loc = BoolProperty(name="Location",
325 description="Display object location",
326 default=False)
327 Scene.measureit_debug_edges = BoolProperty(name="Edges",
328 description="Display edge index number",
329 default=False)
330 Scene.measureit_debug_faces = BoolProperty(name="Faces",
331 description="Display face index number",
332 default=False)
333 Scene.measureit_debug_normals = BoolProperty(name="Normals",
334 description="Display face normal "
335 "vector and creation order",
336 default=False)
337 Scene.measureit_debug_normal_details = BoolProperty(name="Details",
338 description="Display face normal details",
339 default=True)
340 Scene.measureit_debug_font = IntProperty(name="Font",
341 description="Debug text size",
342 default=14, min=10, max=150)
343 Scene.measureit_debug_vert_color = FloatVectorProperty(name="Debug color",
344 description="Debug Color",
345 default=(1, 0, 0, 1.0),
346 min=0.1,
347 max=1,
348 subtype='COLOR',
349 size=4)
350 Scene.measureit_debug_face_color = FloatVectorProperty(name="Debug face color",
351 description="Debug face Color",
352 default=(0, 1, 0, 1.0),
353 min=0.1,
354 max=1,
355 subtype='COLOR',
356 size=4)
357 Scene.measureit_debug_norm_color = FloatVectorProperty(name="Debug vector color",
358 description="Debug vector Color",
359 default=(1.0, 1.0, 0.1, 1.0),
360 min=0.1,
361 max=1,
362 subtype='COLOR',
363 size=4)
364 Scene.measureit_debug_edge_color = FloatVectorProperty(name="Debug vector color",
365 description="Debug vector Color",
366 default=(0.1, 1.0, 1.0, 1.0),
367 min=0.1,
368 max=1,
369 subtype='COLOR',
370 size=4)
371 Scene.measureit_debug_obj_color = FloatVectorProperty(name="Debug vector color",
372 description="Debug vector Color",
373 default=(1.0, 1.0, 1.0, 1.0),
374 min=0.1,
375 max=1,
376 subtype='COLOR',
377 size=4)
378 Scene.measureit_debug_normal_size = FloatProperty(name='Len', min=0.001, max=9,
379 default=0.5,
380 precision=2,
381 description="Normal arrow size")
382 Scene.measureit_debug_width = IntProperty(name='Debug width', min=1, max=10, default=2,
383 description='Vector line thickness')
384 Scene.measureit_debug_precision = IntProperty(name='Precision', min=0, max=5, default=1,
385 description="Number of decimal precision")
386 Scene.measureit_debug_vert_loc_toggle = EnumProperty(items=(('1', "Local",
387 "Uses local coordinates"),
388 ('2', "Global",
389 "Uses global coordinates")),
390 name="Coordinates",
391 description="Choose coordinate system")
392 Scene.measureit_font_rotation = IntProperty(name='Rotate', min=0, max=360, default=0,
393 description="Default text rotation in degrees")
394 Scene.measureit_font_align = EnumProperty(items=(('L', "Left Align", "Use current render"),
395 ('C', "Center Align", ""),
396 ('R', "Right Align", "")),
397 name="Align Font",
398 description="Set Font Alignment")
400 # OpenGL flag
401 wm = WindowManager
402 # register internal property
403 wm.measureit_run_opengl = BoolProperty(default=False)
406 def unregister():
407 from bpy.utils import unregister_class
408 for cls in reversed(classes):
409 unregister_class(cls)
411 # Remove properties
412 del Scene.measureit_default_color
413 del Scene.measureit_font_size
414 del Scene.measureit_hint_space
415 del Scene.measureit_gl_ghost
416 del Scene.measureit_gl_txt
417 del Scene.measureit_gl_precision
418 del Scene.measureit_gl_show_d
419 del Scene.measureit_gl_show_n
420 del Scene.measureit_scale
421 del Scene.measureit_scale_factor
422 del Scene.measureit_scale_color
423 del Scene.measureit_scale_font
424 del Scene.measureit_scale_pos_x
425 del Scene.measureit_scale_pos_y
426 del Scene.measureit_gl_scaletxt
427 del Scene.measureit_scale_precision
428 del Scene.measureit_ovr
429 del Scene.measureit_ovr_font
430 del Scene.measureit_ovr_color
431 del Scene.measureit_ovr_width
432 del Scene.measureit_ovr_font_rotation
433 del Scene.measureit_ovr_font_align
434 del Scene.measureit_units
435 del Scene.measureit_hide_units
436 del Scene.measureit_render
437 del Scene.measureit_render_type
438 del Scene.measureit_sum
439 del Scene.measureit_rf
440 del Scene.measureit_rf_color
441 del Scene.measureit_rf_border
442 del Scene.measureit_rf_line
443 del Scene.measureit_glarrow_a
444 del Scene.measureit_glarrow_b
445 del Scene.measureit_glarrow_s
446 del Scene.measureit_debug
447 del Scene.measureit_debug_select
448 del Scene.measureit_debug_vertices
449 del Scene.measureit_debug_objects
450 del Scene.measureit_debug_edges
451 del Scene.measureit_debug_faces
452 del Scene.measureit_debug_normals
453 del Scene.measureit_debug_normal_details
454 del Scene.measureit_debug_font
455 del Scene.measureit_debug_vert_color
456 del Scene.measureit_debug_face_color
457 del Scene.measureit_debug_norm_color
458 del Scene.measureit_debug_edge_color
459 del Scene.measureit_debug_obj_color
460 del Scene.measureit_debug_normal_size
461 del Scene.measureit_debug_width
462 del Scene.measureit_debug_precision
463 del Scene.measureit_debug_vert_loc
464 del Scene.measureit_debug_object_loc
465 del Scene.measureit_debug_vert_loc_toggle
466 del Scene.measureit_font_rotation
467 del Scene.measureit_font_align
469 # remove OpenGL data
470 measureit_main.MEASUREIT_OT_RunHintDisplay.handle_remove(measureit_main.MEASUREIT_OT_RunHintDisplay, bpy.context)
471 wm = bpy.context.window_manager
472 p = 'measureit_run_opengl'
473 if p in wm:
474 del wm[p]
477 if __name__ == '__main__':
478 register()