Newer
Older
# Add properties
scene = context.scene
mainobject = context.object
mylist = get_smart_selected(mainobject)
if len(mylist) < 1: # if not selected linked vertex
mylist = get_selected_vertex(mainobject)
if len(mylist) >= 1:
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
# -----------------------
# Only if not exist
# -----------------------
if exist_segment(mp, mylist[x], mylist[x], 12 + int(self.tag)) is False:
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
ms.gltype = 12 + int(self.tag)
ms.glpointa = mylist[x]
ms.glpointb = mylist[x]
ms.glarrow_a = scene.measureit_glarrow_a
ms.glarrow_b = scene.measureit_glarrow_b
ms.glarrow_s = scene.measureit_glarrow_s
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Sum group
ms.gltot = scene.measureit_sum
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'ERROR'},
"MeasureIt: Select at least one vertex for creating measure segment.")
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that adds an angle measure
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddAngle(Operator):
bl_idname = "measureit.addangle"
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
bl_label = "Angle"
bl_description = "(EDITMODE only) Add a new angle measure (select 3 vertices, 2nd is angle vertex)"
# ------------------------------
# Poll
# ------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
else:
if o.type == "MESH":
if bpy.context.mode == 'EDIT_MESH':
return True
else:
return False
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
scene = context.scene
mainobject = context.object
mylist = get_selected_vertex_history(mainobject)
if len(mylist) == 3:
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# -----------------------
# Only if not exist
# -----------------------
if exist_segment(mp, mylist[0], mylist[1], 9, mylist[2]) is False:
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
ms.gltype = 9
ms.glpointa = mylist[0]
ms.glpointb = mylist[1]
ms.glpointc = mylist[2]
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'ERROR'},
"MeasureIt: Select three vertices for creating angle measure")
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that adds an arc measure
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddArc(Operator):
bl_idname = "measureit.addarc"
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
bl_label = "Angle"
bl_description = "(EDITMODE only) Add a new arc measure (select 3 vertices of the arc," \
" vertices 1st and 3rd are arc extremes)"
# ------------------------------
# Poll
# ------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
else:
if o.type == "MESH":
if bpy.context.mode == 'EDIT_MESH':
return True
else:
return False
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
scene = context.scene
mainobject = context.object
mylist = get_selected_vertex_history(mainobject)
if len(mylist) == 3:
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# -----------------------
# Only if not exist
# -----------------------
if exist_segment(mp, mylist[0], mylist[1], 11, mylist[2]) is False:
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
ms.gltype = 11
ms.glpointa = mylist[0]
ms.glpointb = mylist[1]
ms.glpointc = mylist[2]
ms.glarrow_a = scene.measureit_glarrow_a
ms.glarrow_b = scene.measureit_glarrow_b
ms.glarrow_s = scene.measureit_glarrow_s
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'ERROR'},
"MeasureIt: Select three vertices for creating arc measure")
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that adds a label segment
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddLabel(Operator):
bl_idname = "measureit.addlabel"
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
bl_label = "Add"
bl_description = "(EDITMODE only) Add a new measure label (select 1 vertex)"
# ------------------------------
# Poll
# ------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
else:
if o.type == "MESH":
if bpy.context.mode == 'EDIT_MESH':
return True
else:
return False
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
scene = context.scene
mainobject = context.object
mylist = get_selected_vertex(mainobject)
if len(mylist) == 1:
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# -----------------------
# Only if not exist
# -----------------------
if exist_segment(mp, mylist[0], mylist[0], 2) is False: # Both equal
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
ms.gltype = 2
ms.glpointa = mylist[0]
ms.glpointb = mylist[0] # Equal
ms.glarrow_a = scene.measureit_glarrow_a
ms.glarrow_b = scene.measureit_glarrow_b
ms.glarrow_s = scene.measureit_glarrow_s
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'ERROR'},
"MeasureIt: Select one vertex for creating measure label")
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that adds a link
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddLink(Operator):
bl_idname = "measureit.addlink"
bl_label = "Add"
bl_description = "(OBJECT mode only) Add a new measure between objects (select 2 " \
"objects and optionally 1 or 2 vertices)"
# ------------------------------
# Poll
# ------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
else:
if o.type == "MESH" or o.type == "EMPTY" or o.type == "CAMERA" or o.type == "LIGHT":
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
if bpy.context.mode == 'OBJECT':
return True
else:
return False
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
scene = context.scene
mainobject = context.object
# -------------------------------
# Verify number of objects
# -------------------------------
if len(context.selected_objects) != 2:
self.report({'ERROR'},
"MeasureIt: Select two objects only, and optionally 1 vertex or 2 vertices "
"(one of each object)")
return {'FINISHED'}
# Locate other object
linkobject = None
for o in context.selected_objects:
if o.name != mainobject.name:
linkobject = o.name
# Verify destination vertex
lkobj = bpy.data.objects[linkobject]
mylinkvertex = get_selected_vertex(lkobj)
if len(mylinkvertex) > 1:
self.report({'ERROR'},
"MeasureIt: The destination object has more than one vertex selected. "
"Select only 1 or none")
return {'FINISHED'}
# Verify origin vertex
myobjvertex = get_selected_vertex(mainobject)
if len(mylinkvertex) > 1:
self.report({'ERROR'},
"MeasureIt: The active object has more than one vertex selected. Select only 1 or none")
return {'FINISHED'}
# -------------------------------
# Add properties
# -------------------------------
flag = False
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# if exist_segment(mp, mylist[0], mylist[0], 3) is False:
# flag = True
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
# -----------------------
# Vertex to Vertex
# -----------------------
if len(myobjvertex) == 1 and len(mylinkvertex) == 1:
ms.gltype = 3
ms.glpointa = myobjvertex[0]
ms.glpointb = mylinkvertex[0]
flag = True
# -----------------------
# Vertex to Object
# -----------------------
if len(myobjvertex) == 1 and len(mylinkvertex) == 0:
ms.gltype = 4
ms.glpointa = myobjvertex[0]
ms.glpointb = 0
flag = True
# -----------------------
# Object to Vertex
# -----------------------
if len(myobjvertex) == 0 and len(mylinkvertex) == 1:
ms.gltype = 5
ms.glpointa = 0
ms.glpointb = mylinkvertex[0]
flag = True
# -----------------------
# Object to Object
# -----------------------
if len(myobjvertex) == 0 and len(mylinkvertex) == 0:
ms.gltype = 8
ms.glpointa = 0
ms.glpointb = 0 # Equal
flag = True
# ------------------
# only if created
# ------------------
if flag is True:
ms.glarrow_a = scene.measureit_glarrow_a
ms.glarrow_b = scene.measureit_glarrow_b
ms.glarrow_s = scene.measureit_glarrow_s
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# link
ms.gllink = linkobject
# Add index
mp.measureit_num += 1
# -----------------------
# Only if not exist
# -----------------------
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that adds an origin segment
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddOrigin(Operator):
bl_idname = "measureit.addorigin"
bl_label = "Add"
bl_description = "(OBJECT mode only) Add a new measure to origin (select object and optionally 1 vertex)"
# ------------------------------
# Poll
# ------------------------------
@classmethod
def poll(cls, context):
o = context.object
if o is None:
return False
else:
if o.type == "MESH" or o.type == "EMPTY" or o.type == "CAMERA" or o.type == "LIGHT":
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
if bpy.context.mode == 'OBJECT':
return True
else:
return False
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
scene = context.scene
mainobject = context.object
mylist = get_selected_vertex(mainobject)
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# -----------------------
# Set values
# -----------------------
ms = mp.measureit_segments[mp.measureit_num]
flag = False
if len(mylist) > 0:
if len(mylist) == 1:
if exist_segment(mp, mylist[0], mylist[0], 6) is False: # Both equal
flag = True
# Vertex to origin
ms.gltype = 6
ms.glpointa = mylist[0]
ms.glpointb = mylist[0]
else:
self.report({'ERROR'},
"MeasureIt: Enter in EDITMODE and select one vertex only for creating "
"measure from vertex to origin")
return {'FINISHED'}
else:
# Object to origin
if exist_segment(mp, 0, 0, 7) is False: # Both equal
flag = True
ms.gltype = 7
ms.glpointa = 0
ms.glpointb = 0
# ------------------
# only if created
# ------------------
if flag is True:
ms.glarrow_a = scene.measureit_glarrow_a
ms.glarrow_b = scene.measureit_glarrow_b
ms.glarrow_s = scene.measureit_glarrow_s
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that deletes a measure segment
#
# -------------------------------------------------------------
class MEASUREIT_OT_DeleteSegment(Operator):
bl_idname = "measureit.deletesegment"
bl_label = "Delete"
bl_description = "Delete a measure"
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
mainobject = context.object
mp = mainobject.MeasureGenerator[0]
ms = mp.measureit_segments[self.tag]
ms.glfree = True
# Delete element
mp.measureit_segments.remove(self.tag)
mp.measureit_num -= 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that deletes all measure segments
#
# -------------------------------------------------------------
class MEASUREIT_OT_DeleteAllSegment(Operator):
bl_idname = "measureit.deleteallsegment"
bl_label = "Delete"
bl_description = "Delete all measures (it cannot be undone)"
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
mainobject = context.object
mp = mainobject.MeasureGenerator[0]
while len(mp.measureit_segments) > 0:
mp.measureit_segments.remove(0)
# reset size
mp.measureit_num = len(mp.measureit_segments)
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that deletes all measure segment sums
#
# -------------------------------------------------------------
class MEASUREIT_OT_DeleteAllSum(Operator):
bl_idname = "measureit.deleteallsum"
bl_label = "Delete"
bl_description = "Delete all sum groups"
# ------------------------------
# Execute button action
# ------------------------------
# noinspection PyMethodMayBeStatic
def execute(self, context):
if context.object is not None:
if 'MeasureGenerator' in context.object:
mp = context.object.MeasureGenerator[0]
ms = mp.measureit_segments[idx]
ms.gltot = '99'
return {'FINISHED'}
# -------------------------------------------------------------
# Defines button that expands all measure segments
#
# -------------------------------------------------------------
class MEASUREIT_OT_ExpandAllSegment(Operator):
bl_idname = "measureit.expandallsegment"
bl_label = "Expand"
bl_description = "Expand all measure properties"
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
mainobject = context.object
mp = mainobject.MeasureGenerator[0]
for i in mp.measureit_segments:
i.gladvance = True
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that collapses all measure segments
#
# -------------------------------------------------------------
class MEASUREIT_OT_CollapseAllSegment(Operator):
bl_idname = "measureit.collapseallsegment"
bl_label = "Collapse"
bl_description = "Collapses all measure properties"
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
# Add properties
mainobject = context.object
mp = mainobject.MeasureGenerator[0]
for i in mp.measureit_segments:
i.gladvance = False
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button for render option
#
# -------------------------------------------------------------
class MEASUREIT_OT_RenderSegment(Operator):
bl_idname = "measureit.rendersegment"
bl_label = "Render"
bl_description = "Create a render image with measures. Use UV/Image editor to view image generated"
# ------------------------------
# Execute button action
# ------------------------------
# noinspection PyMethodMayBeStatic,PyUnusedLocal
def execute(self, context):
scene = context.scene
msg = "New image created with measures. Open it in UV/image editor"
camera_msg = "Unable to render. No camera found"
# -----------------------------
# Check camera
# -----------------------------
if scene.camera is None:
self.report({'ERROR'}, camera_msg)
return {'FINISHED'}
# -----------------------------
# -----------------------------
if scene.measureit_render_type == "1":
# noinspection PyBroadException
if render_main(self, context) is True:
self.report({'INFO'}, msg)
# -----------------------------
# Animation
# -----------------------------
if scene.measureit_render_type == "2":
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
oldframe = scene.frame_current
flag = False
# loop frames
for frm in range(scene.frame_start, scene.frame_end + 1):
scene.frame_set(frm)
print("MeasureIt: Rendering frame %04d" % frm)
flag = render_main(self, context, True)
if flag is False:
break
scene.frame_current = oldframe
if flag is True:
self.report({'INFO'}, msg)
return {'FINISHED'}
# ---------------------
# Set cameraView
# ---------------------
# noinspection PyMethodMayBeStatic
def set_camera_view(self):
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
area.spaces[0].region_3d.view_perspective = 'CAMERA'
# -------------------------------------
# Set only render status
# -------------------------------------
# noinspection PyMethodMayBeStatic
def set_only_render(self, status):
screen = bpy.context.screen
v3d = False
s = None
# get spaceview_3d in current screen
for a in screen.areas:
if a.type == 'VIEW_3D':
for s in a.spaces:
if s.type == 'VIEW_3D':
v3d = s
break
if v3d is not False:
s.show_only_render = status
# -------------------------------------------------------------
# Defines a new note
#
# -------------------------------------------------------------
class MEASUREIT_OT_AddNote(Operator):
bl_idname = "measureit.addnote"
bl_label = "Note"
bl_description = "(OBJECT mode only) Add a new annotation"
# ------------------------------
# Poll
# ------------------------------
# noinspection PyUnusedLocal
@classmethod
def poll(cls, context):
if bpy.context.mode == 'OBJECT':
return True
else:
return False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
bpy.ops.object.empty_add(type='PLAIN_AXES')
myempty = bpy.data.objects[bpy.context.active_object.name]
myempty.location = bpy.context.scene.cursor.location
myempty.empty_display_size = 0.01
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
myempty.name = "Annotation"
# Add properties
scene = context.scene
mainobject = myempty
if 'MeasureGenerator' not in mainobject:
mainobject.MeasureGenerator.add()
mp = mainobject.MeasureGenerator[0]
# Create all array elements
for cont in range(len(mp.measureit_segments) - 1, mp.measureit_num):
mp.measureit_segments.add()
# Set values
ms = mp.measureit_segments[mp.measureit_num]
ms.gltype = 10
ms.glpointa = 0
ms.glpointb = 0 # Equal
# color
ms.glcolor = scene.measureit_default_color
# dist
ms.glspace = scene.measureit_hint_space
# text
ms.gltxt = scene.measureit_gl_txt
ms.glfont_size = scene.measureit_font_size
ms.glfont_align = scene.measureit_font_align
ms.glfont_rotat = scene.measureit_font_rotation
# Add index
mp.measureit_num += 1
# redraw
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Defines button that enables/disables the tip display
#
# -------------------------------------------------------------
class MEASUREIT_OT_RunHintDisplay(Operator):
bl_idname = "measureit.runopengl"
bl_label = "Display hint data manager"
bl_description = "Main control for enabling or disabling the display of measurements in the viewport"
_handle = None # keep function handler
# ----------------------------------
# Enable gl drawing adding handler
# ----------------------------------
@staticmethod
def handle_add(self, context):
if MEASUREIT_OT_RunHintDisplay._handle is None:
MEASUREIT_OT_RunHintDisplay._handle = SpaceView3D.draw_handler_add(draw_callback_px, (self, context),
context.window_manager.measureit_run_opengl = True
# ------------------------------------
# Disable gl drawing removing handler
# ------------------------------------
# noinspection PyUnusedLocal
@staticmethod
def handle_remove(self, context):
if MEASUREIT_OT_RunHintDisplay._handle is not None:
SpaceView3D.draw_handler_remove(MEASUREIT_OT_RunHintDisplay._handle, 'WINDOW')
MEASUREIT_OT_RunHintDisplay._handle = None
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
context.window_manager.measureit_run_opengl = False
# ------------------------------
# Execute button action
# ------------------------------
def execute(self, context):
if context.area.type == 'VIEW_3D':
if context.window_manager.measureit_run_opengl is False:
self.handle_add(self, context)
context.area.tag_redraw()
else:
self.handle_remove(self, context)
context.area.tag_redraw()
return {'FINISHED'}
else:
self.report({'WARNING'},
"View3D not found, cannot run operator")
return {'CANCELLED'}
# -------------------------------------------------------------
# Handle all draw routines (OpenGL main entry point)
#
# -------------------------------------------------------------
def draw_main(context):
region = bpy.context.region
# Detect if Quadview to get drawing area
if not context.space_data.region_quadviews:
rv3d = bpy.context.space_data.region_3d
else:
# verify area
if context.area.type != 'VIEW_3D' or context.space_data.type != 'VIEW_3D':
return
i = -1
for region in context.area.regions:
if region.type == 'WINDOW':
i += 1
if context.region.id == region.id:
break
else:
return
rv3d = context.space_data.region_quadviews[i]
scene = bpy.context.scene
# Display selected or all
if scene.measureit_gl_ghost is False:
objlist = context.selected_objects
else:
objlist = context.view_layer.objects
# Enable drawing
gpu.state.blend_set('ALPHA')
# ---------------------------------------
# Generate all OpenGL calls for measures
# ---------------------------------------
for myobj in objlist:
if myobj.visible_get() is True:
if 'MeasureGenerator' in myobj:
op = myobj.MeasureGenerator[0]
draw_segments(context, myobj, op, region, rv3d)
# ---------------------------------------
# Generate all OpenGL calls for debug
# ---------------------------------------
if scene.measureit_debug is True:
selobj = bpy.context.selected_objects
for myobj in selobj:
if scene.measureit_debug_objects is True:
draw_object(context, myobj, region, rv3d)
elif scene.measureit_debug_object_loc is True:
draw_object(context, myobj, region, rv3d)
if scene.measureit_debug_vertices is True:
draw_vertices(context, myobj, region, rv3d)
elif scene.measureit_debug_vert_loc is True:
draw_vertices(context, myobj, region, rv3d)
if scene.measureit_debug_edges is True:
draw_edges(context, myobj, region, rv3d)
if scene.measureit_debug_faces is True or scene.measureit_debug_normals is True:
draw_faces(context, myobj, region, rv3d)
# -----------------------
# -----------------------
gpu.state.blend_set('NONE')
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
# -------------------------------------------------------------
# Handler for drawing OpenGl
# -------------------------------------------------------------
# noinspection PyUnusedLocal
def draw_callback_px(self, context):
draw_main(context)
# -------------------------------------------------------------
# Check if the segment already exist
#
# -------------------------------------------------------------
def exist_segment(mp, pointa, pointb, typ=1, pointc=None):
# for ms in mp.measureit_segments[mp.measureit_num]
for ms in mp.measureit_segments:
if ms.gltype == typ and ms.glfree is False:
if typ != 9:
if ms.glpointa == pointa and ms.glpointb == pointb:
return True
if ms.glpointa == pointb and ms.glpointb == pointa:
return True
else:
if ms.glpointa == pointa and ms.glpointb == pointb and ms.glpointc == pointc:
return True
return False
# -------------------------------------------------------------
# Get vertex selected