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