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