ui and decorator handler

This commit is contained in:
QwiglyDee
2020-12-10 23:49:35 +07:00
committed by Dion Moult
parent 14193fb486
commit 33bf7054bf
4 changed files with 64 additions and 2 deletions
@@ -0,0 +1,2 @@
# addon writes tmp stuff directly to its dir
/data/
@@ -0,0 +1,47 @@
"""Viewport decorations"""
from bpy.types import SpaceView3D
import bpy
import blf
class ViewDecorator(object):
# class var for single handler
installed = None
@classmethod
def install(cls, *args, **kwargs):
handler = cls(*args, **kwargs)
cls.installed = SpaceView3D.draw_handler_add(handler, (), 'WINDOW', 'POST_PIXEL')
@classmethod
def uninstall(cls):
SpaceView3D.draw_handler_remove(cls.installed, 'WINDOW')
cls.installed = None
class DimensionDecorator(ViewDecorator):
"""Decorates dimension curves
- outlines each segment with an arrow
- puts metric text next to each segment
"""
def __init__(self, scene, context):
self.scene = scene
self.context = context
self.font_id = 0
self.dpi = context.preferences.system.dpi
print("Created decorator", scene)
def __call__(self):
# get active drawing, if any
if self.scene.active_drawing_index is None or len(self.scene.drawings) == 0:
return
drawing = self.scene.drawings[self.scene.active_drawing_index]
collection = bpy.data.collections.get("IfcGroup/" + drawing.name)
if 'IfcAnnotation/Dimension' not in collection.all_objects:
return
curve = collection.all_objects['IfcAnnotation/Dimension'].data
text = repr(curve)
blf.position(self.font_id, 100, 100, 0)
blf.size(self.font_id, 10, self.dpi)
blf.draw(self.font_id, text)
@@ -8,6 +8,7 @@ from . import schema
from . import bcf
from . import ifc
from . import annotation
from . import decoration
import bpy
from bpy.types import PropertyGroup
from bpy.app.handlers import persistent
@@ -357,6 +358,14 @@ def refreshTitleblocks(self, context):
getTitleblocks(self, context)
def toggleDimDecorations(self, context):
toggle = self.dim_decorations
if toggle:
decoration.DimensionDecorator.install(self, context)
else:
decoration.DimensionDecorator.uninstall()
def getScenarios(self, context):
global scenarios_enum
if len(scenarios_enum) < 1:
@@ -668,6 +677,7 @@ class DocProperties(PropertyGroup):
active_sheet_index: IntProperty(name="Active Sheet Index")
ifc_files: CollectionProperty(name="IFCs", type=StrProperty)
drawing_styles: CollectionProperty(name="Drawing Styles", type=DrawingStyle)
dim_decorations: BoolProperty(name="Decorate dimentions", update=toggleDimDecorations)
class BIMCameraProperties(PropertyGroup):
+5 -2
View File
@@ -2352,6 +2352,9 @@ class BIM_PT_annotation_utilities(Panel):
row.operator("bim.remove_drawing", icon="X", text="").index = props.active_drawing_index
layout.template_list("BIM_UL_generic", "", props, "drawings", props, "active_drawing_index")
row = layout.row()
row.prop(props, 'dim_decorations')
class BIM_PT_qto_utilities(Panel):
bl_idname = "BIM_PT_qto_utilities"
@@ -2396,7 +2399,7 @@ class BIM_PT_clash_manager(Panel):
row = layout.row()
layout.label(text="Select output path for smart-grouped clashes:")
row = layout.row(align=True)
row.prop(props, "smart_grouped_clashes_path", text="")
op = row.operator("bim.select_smart_grouped_clashes_path", icon="FILE_FOLDER", text="")
@@ -2409,7 +2412,7 @@ class BIM_PT_clash_manager(Panel):
row = layout.row(align=True)
row.operator("bim.load_smart_groups_for_active_clash_set")
layout.template_list('BIM_UL_smart_groups', '', props, 'smart_clash_groups', props, 'active_smart_group_index')
row = layout.row(align=True)