Drawing annotations now are stored in IFC using ObjectType conventions. See #1153.

This commit is contained in:
Dion Moult
2021-11-16 08:35:49 +11:00
parent 4b5907f5dd
commit b28d8b0cca
3 changed files with 60 additions and 43 deletions
@@ -18,6 +18,7 @@
import bpy
import os
import blenderbim.tool as tool
from mathutils import Vector
@@ -150,18 +151,30 @@ class Annotator:
return obj
@staticmethod
def get_annotation_obj(name, data_type, context):
def get_annotation_obj(object_type, data_type, context):
collection = context.scene.camera.users_collection[0]
for obj in collection.objects:
if name in obj.name:
return obj
if data_type == "mesh":
data = bpy.data.meshes.new(name)
elif data_type == "curve":
data = bpy.data.curves.new(name, type="CURVE")
if object_type == "TEXT":
obj = bpy.data.objects.new(object_type, None)
collection.objects.link(obj)
return obj
elif object_type == "TEXT_LEADER":
data = bpy.data.curves.new(object_type, type="CURVE")
data.dimensions = "3D"
data.resolution_u = 2
obj = bpy.data.objects.new(name, data)
obj = bpy.data.objects.new(object_type, data)
collection.objects.link(obj)
return obj
for obj in collection.objects:
element = tool.Ifc.get_entity(obj)
if element and element.ObjectType == object_type:
return obj
if data_type == "mesh":
data = bpy.data.meshes.new(object_type)
elif data_type == "curve":
data = bpy.data.curves.new(object_type, type="CURVE")
data.dimensions = "3D"
data.resolution_u = 2
obj = bpy.data.objects.new(object_type, data)
collection.objects.link(obj)
return obj
@@ -36,7 +36,7 @@ import blenderbim.bim.module.drawing.helper as helper
class BaseDecorator:
# base name of objects to decorate
basename = "IfcAnnotation/Something"
objecttype = "NOTDEFINED"
DEF_GLSL = """
#define PI 3.141592653589793
@@ -136,11 +136,18 @@ class BaseDecorator:
def get_objects(self, collection):
"""find relevant objects
using class.basename
using class.objecttype
returns: iterable of blender objects
"""
return filter(lambda o: self.basename in o.name, collection.all_objects)
results = []
for obj in collection.all_objects:
element = tool.Ifc.get_entity(obj)
if not element:
continue
if element.is_a("IfcAnnotation") and element.ObjectType == self.objecttype:
results.append(obj)
return results
def get_path_geom(self, obj, topo=True):
"""Parses path geometry into line segments
@@ -208,7 +215,7 @@ class BaseDecorator:
return vertices, indices
def decorate(self, context, object):
"""perform actuall drawing stuff"""
"""perform actual drawing stuff"""
raise NotImplementedError()
def draw_lines(self, context, obj, vertices, indices, topology=None):
@@ -311,7 +318,7 @@ class DimensionDecorator(BaseDecorator):
- puts metric text next to each segment
"""
basename = "IfcAnnotation/Dimension"
objecttype = "DIMENSION"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -406,7 +413,7 @@ class EqualityDecorator(DimensionDecorator):
- puts 'EQ' label
"""
basename = "IfcAnnotation/Equal"
objecttype = "EQUAL_DIMENSION"
def draw_labels(self, context, obj, vertices, indices):
region = context.region
@@ -423,12 +430,11 @@ class EqualityDecorator(DimensionDecorator):
class LeaderDecorator(BaseDecorator):
"""Decorating stairs
"""Decorating text with arrows
- head point with arrow
- middle points w/out decorations
"""
basename = "IfcAnnotation/Leader"
objecttype = "TEXT_LEADER"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -500,7 +506,7 @@ class StairDecorator(BaseDecorator):
- middle points w/out decorations
"""
basename = "IfcAnnotation/Stair"
objecttype = "STAIR_ARROW"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -583,7 +589,7 @@ class StairDecorator(BaseDecorator):
class HiddenDecorator(BaseDecorator):
basename = "IfcAnnotation/Hidden"
objecttype = "HIDDEN_LINE"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -649,7 +655,7 @@ class HiddenDecorator(BaseDecorator):
class MiscDecorator(HiddenDecorator):
basename = "IfcAnnotation/Misc"
objecttype = "MISC"
FRAG_GLSL = BaseDecorator.FRAG_GLSL
@@ -677,7 +683,7 @@ class LevelDecorator(BaseDecorator):
class PlanLevelDecorator(LevelDecorator):
basename = "IfcAnnotation/Plan Level"
objecttype = "PLAN_LEVEL"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -762,7 +768,7 @@ class PlanLevelDecorator(LevelDecorator):
class SectionLevelDecorator(LevelDecorator):
basename = "IfcAnnotation/Section Level"
objecttype = "SECTION_LEVEL"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -850,7 +856,7 @@ class BreakDecorator(BaseDecorator):
Uses first two vertices in verts list.
"""
basename = "IfcAnnotation/Break"
objecttype = "BREAKLINE"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -928,7 +934,7 @@ class BreakDecorator(BaseDecorator):
class GridDecorator(BaseDecorator):
basename = "IfcGridAxis/"
objecttype = "GRID"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -1045,7 +1051,7 @@ class GridDecorator(BaseDecorator):
class SectionViewDecorator(LevelDecorator):
basename = "IfcAnnotation/Section"
objecttype = "SECTION"
DEF_GLSL = (
BaseDecorator.DEF_GLSL
@@ -469,36 +469,34 @@ class CreateDrawing(bpy.types.Operator):
svg_writer.camera_projection = tuple(camera.matrix_world.to_quaternion() @ Vector((0, 0, -1)))
for obj in camera.users_collection[0].objects:
if "IfcAnnotation/" not in obj.name:
continue
element = tool.Ifc.get_entity(obj)
if element.ObjectType == "GRID":
svg_writer.annotations.setdefault("grid_objs", []).append(obj)
elif obj.type == "CAMERA":
continue
if "IfcAnnotation/" not in obj.name:
continue
if "Leader" in obj.name:
svg_writer.annotations["leader_obj"] = (obj, obj.data)
elif "Stair" in obj.name:
elif element.ObjectType == "TEXT_LEADER":
svg_writer.annotations.setdefault("leader_objs", []).append(obj)
elif element.ObjectType == "STAIR_ARROW":
svg_writer.annotations["stair_obj"] = obj
elif "Equal" in obj.name:
elif element.ObjectType == "EQUAL_DIMENSION":
svg_writer.annotations.setdefault("equal_objs", []).append(obj)
elif "Dimension" in obj.name:
elif element.ObjectType == "DIMENSION":
svg_writer.annotations.setdefault("dimension_objs", []).append(obj)
elif "Break" in obj.name:
elif element.ObjectType == "BREAKLINE":
svg_writer.annotations["break_obj"] = obj
elif "Hidden" in obj.name:
elif element.ObjectType == "HIDDEN_LINE":
svg_writer.annotations.setdefault("hidden_objs", []).append((obj, obj.data))
elif "Solid" in obj.name:
elif element.ObjectType == "SOLID_LINE":
svg_writer.annotations.setdefault("solid_objs", []).append((obj, obj.data))
elif "Plan Level" in obj.name:
elif element.ObjectType == "PLAN_LEVEL":
svg_writer.annotations["plan_level_obj"] = obj
elif "Section Level" in obj.name:
elif element.ObjectType == "SECTION_LEVEL":
svg_writer.annotations["section_level_obj"] = obj
elif obj.type == "FONT":
elif element.ObjectType == "TEXT":
svg_writer.annotations.setdefault("text_objs", []).append(obj)
else:
elif element.ObjectType == "MISC":
svg_writer.annotations.setdefault("misc_objs", []).append(obj)
svg_writer.annotations["attributes"] = [a.name for a in drawing_style.attributes]
@@ -558,7 +556,7 @@ class AddAnnotation(bpy.types.Operator):
bl_idname = "bim.add_annotation"
bl_label = "Add Annotation"
bl_options = {"REGISTER", "UNDO"}
obj_name: bpy.props.StringProperty()
object_type: bpy.props.StringProperty()
data_type: bpy.props.StringProperty()
@classmethod