Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 33bf705

Browse files
qwiglydeeMoult
authored andcommitted
ui and decorator handler
1 parent 14193fb commit 33bf705

4 files changed

Lines changed: 64 additions & 2 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# addon writes tmp stuff directly to its dir
2+
/data/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
"""Viewport decorations"""
2+
from bpy.types import SpaceView3D
3+
import bpy
4+
import blf
5+
6+
7+
class ViewDecorator(object):
8+
# class var for single handler
9+
installed = None
10+
11+
@classmethod
12+
def install(cls, *args, **kwargs):
13+
handler = cls(*args, **kwargs)
14+
cls.installed = SpaceView3D.draw_handler_add(handler, (), 'WINDOW', 'POST_PIXEL')
15+
16+
@classmethod
17+
def uninstall(cls):
18+
SpaceView3D.draw_handler_remove(cls.installed, 'WINDOW')
19+
cls.installed = None
20+
21+
22+
class DimensionDecorator(ViewDecorator):
23+
"""Decorates dimension curves
24+
- outlines each segment with an arrow
25+
- puts metric text next to each segment
26+
"""
27+
28+
def __init__(self, scene, context):
29+
self.scene = scene
30+
self.context = context
31+
self.font_id = 0
32+
self.dpi = context.preferences.system.dpi
33+
print("Created decorator", scene)
34+
35+
def __call__(self):
36+
# get active drawing, if any
37+
if self.scene.active_drawing_index is None or len(self.scene.drawings) == 0:
38+
return
39+
drawing = self.scene.drawings[self.scene.active_drawing_index]
40+
collection = bpy.data.collections.get("IfcGroup/" + drawing.name)
41+
if 'IfcAnnotation/Dimension' not in collection.all_objects:
42+
return
43+
curve = collection.all_objects['IfcAnnotation/Dimension'].data
44+
text = repr(curve)
45+
blf.position(self.font_id, 100, 100, 0)
46+
blf.size(self.font_id, 10, self.dpi)
47+
blf.draw(self.font_id, text)

src/ifcblenderexport/blenderbim/bim/prop.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from . import bcf
99
from . import ifc
1010
from . import annotation
11+
from . import decoration
1112
import bpy
1213
from bpy.types import PropertyGroup
1314
from bpy.app.handlers import persistent
@@ -357,6 +358,14 @@ def refreshTitleblocks(self, context):
357358
getTitleblocks(self, context)
358359

359360

361+
def toggleDimDecorations(self, context):
362+
toggle = self.dim_decorations
363+
if toggle:
364+
decoration.DimensionDecorator.install(self, context)
365+
else:
366+
decoration.DimensionDecorator.uninstall()
367+
368+
360369
def getScenarios(self, context):
361370
global scenarios_enum
362371
if len(scenarios_enum) < 1:
@@ -668,6 +677,7 @@ class DocProperties(PropertyGroup):
668677
active_sheet_index: IntProperty(name="Active Sheet Index")
669678
ifc_files: CollectionProperty(name="IFCs", type=StrProperty)
670679
drawing_styles: CollectionProperty(name="Drawing Styles", type=DrawingStyle)
680+
dim_decorations: BoolProperty(name="Decorate dimentions", update=toggleDimDecorations)
671681

672682

673683
class BIMCameraProperties(PropertyGroup):

src/ifcblenderexport/blenderbim/bim/ui.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,6 +2352,9 @@ def draw(self, context):
23522352
row.operator("bim.remove_drawing", icon="X", text="").index = props.active_drawing_index
23532353
layout.template_list("BIM_UL_generic", "", props, "drawings", props, "active_drawing_index")
23542354

2355+
row = layout.row()
2356+
row.prop(props, 'dim_decorations')
2357+
23552358

23562359
class BIM_PT_qto_utilities(Panel):
23572360
bl_idname = "BIM_PT_qto_utilities"
@@ -2396,7 +2399,7 @@ def draw(self, context):
23962399

23972400
row = layout.row()
23982401
layout.label(text="Select output path for smart-grouped clashes:")
2399-
2402+
24002403
row = layout.row(align=True)
24012404
row.prop(props, "smart_grouped_clashes_path", text="")
24022405
op = row.operator("bim.select_smart_grouped_clashes_path", icon="FILE_FOLDER", text="")
@@ -2409,7 +2412,7 @@ def draw(self, context):
24092412

24102413
row = layout.row(align=True)
24112414
row.operator("bim.load_smart_groups_for_active_clash_set")
2412-
2415+
24132416
layout.template_list('BIM_UL_smart_groups', '', props, 'smart_clash_groups', props, 'active_smart_group_index')
24142417

24152418
row = layout.row(align=True)

0 commit comments

Comments
 (0)