This commit is contained in:
Andrej730
2025-02-21 14:45:17 +05:00
parent cf1647a451
commit e6d3396630
6 changed files with 44 additions and 34 deletions
+1 -1
View File
@@ -970,7 +970,7 @@ class IfcImporter:
object_type = element.ObjectType
return (
object_type in tool.Drawing.ANNOTATION_TYPES_DATA
and tool.Drawing.ANNOTATION_TYPES_DATA[object_type][3] == "curve"
and tool.Drawing.ANNOTATION_TYPES_DATA[object_type].data_type == "curve"
)
def get_drawing_group(self, element):
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import os
import bpy
import math
@@ -125,7 +126,9 @@ class Annotator:
return obj
@staticmethod
def get_annotation_obj(drawing: ifcopenshell.entity_instance, object_type: str, data_type: str) -> bpy.types.Object:
def get_annotation_obj(
drawing: ifcopenshell.entity_instance, object_type: str, data_type: tool.Drawing.ANNOTATION_DATA_TYPE
) -> bpy.types.Object:
camera = tool.Ifc.get_object(drawing)
co1, _, _, _ = Annotator.get_placeholder_coords(camera)
matrix_world = tool.Drawing.get_camera_matrix(camera)
@@ -683,7 +683,7 @@ class CopyRepresentation(bpy.types.Operator, tool.Ifc.Operator):
)
def lock_error_message(name):
def lock_error_message(name: str) -> str:
return f"'{name}' is locked. Unlock it via the Spatial panel in the Project Overview tab."
+28 -21
View File
@@ -51,7 +51,7 @@ from shapely.ops import unary_union
from lxml import etree
from mathutils import Vector, Matrix
from fractions import Fraction
from typing import Optional, Union, Iterable, Any, Literal, Sequence, TYPE_CHECKING
from typing import Optional, Union, Iterable, Any, Literal, Sequence, TYPE_CHECKING, NamedTuple
from pathlib import Path
if TYPE_CHECKING:
@@ -65,25 +65,32 @@ class Drawing(bonsai.core.tool.Drawing):
# ObjectType: annotation_name, description, icon, data_type
# fmt: off
ANNOTATION_TYPES_DATA = {
"DIMENSION": ("Dimension", "Add dimensions annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "FIXED_SIZE", "curve"),
"ANGLE": ("Angle", "", "DRIVER_ROTATIONAL_DIFFERENCE", "curve"),
"RADIUS": ("Radius", "", "FORWARD", "curve"),
"DIAMETER": ("Diameter", "Add diameter annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "ARROW_LEFTRIGHT", "curve"),
"TEXT": ("Text", "", "SMALL_CAPS", "empty"),
"TEXT_LEADER": ("Leader", "", "TRACKING_BACKWARDS", "curve"),
"STAIR_ARROW": ("Stair Arrow", "Add stair arrow annotation.\nIf you have IfcStairFlight object selected, it will be used as a reference for the annotation", "SCREEN_BACK", "curve"),
"PLAN_LEVEL": ("Level (Plan)", "", "SORTBYEXT", "curve"),
"SECTION_LEVEL": ("Level (Section)", "", "TRIA_DOWN", "curve"),
"BREAKLINE": ("Breakline", "", "FCURVE", "mesh"),
"SYMBOL": ("Symbol", "", "KEYFRAME", "empty"),
"MULTI_SYMBOL": ("Multi-Symbol", "", "OUTLINER_DATA_POINTCLOUD", "mesh"),
"LINEWORK": ("Line", "", "SNAP_MIDPOINT", "mesh"),
"BATTING": ("Batting", "Add batting annotation.\nThickness could be changed through Thickness property of BBIM_Batting property set", "FORCE_FORCE", "mesh"),
"REVISION_CLOUD":("Revision Cloud", "Add revision cloud", "VOLUME_DATA", "mesh"),
"FILL_AREA": ("Fill Area", "", "NODE_TEXTURE", "mesh"),
"FALL": ("Fall", "", "SORT_ASC", "curve"),
"IMAGE": ("Image", "Add reference image attached to the drawing", "TEXTURE", "mesh"),
class AnnotationObjectType(NamedTuple):
annotation_name: str
description: str
icon: str
data_type: Drawing.ANNOTATION_DATA_TYPE
ANNOTATION_TYPES_DATA: dict[str, AnnotationObjectType] = {
"DIMENSION": AnnotationObjectType("Dimension", "Add dimensions annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "FIXED_SIZE", "curve"),
"ANGLE": AnnotationObjectType("Angle", "", "DRIVER_ROTATIONAL_DIFFERENCE", "curve"),
"RADIUS": AnnotationObjectType("Radius", "", "FORWARD", "curve"),
"DIAMETER": AnnotationObjectType("Diameter", "Add diameter annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "ARROW_LEFTRIGHT", "curve"),
"TEXT": AnnotationObjectType("Text", "", "SMALL_CAPS", "empty"),
"TEXT_LEADER": AnnotationObjectType("Leader", "", "TRACKING_BACKWARDS", "curve"),
"STAIR_ARROW": AnnotationObjectType("Stair Arrow", "Add stair arrow annotation.\nIf you have IfcStairFlight object selected, it will be used as a reference for the annotation", "SCREEN_BACK", "curve"),
"PLAN_LEVEL": AnnotationObjectType("Level (Plan)", "", "SORTBYEXT", "curve"),
"SECTION_LEVEL": AnnotationObjectType("Level (Section)", "", "TRIA_DOWN", "curve"),
"BREAKLINE": AnnotationObjectType("Breakline", "", "FCURVE", "mesh"),
"SYMBOL": AnnotationObjectType("Symbol", "", "KEYFRAME", "empty"),
"MULTI_SYMBOL": AnnotationObjectType("Multi-Symbol", "", "OUTLINER_DATA_POINTCLOUD", "mesh"),
"LINEWORK": AnnotationObjectType("Line", "", "SNAP_MIDPOINT", "mesh"),
"BATTING": AnnotationObjectType("Batting", "Add batting annotation.\nThickness could be changed through Thickness property of BBIM_Batting property set", "FORCE_FORCE", "mesh"),
"REVISION_CLOUD":AnnotationObjectType("Revision Cloud", "Add revision cloud", "VOLUME_DATA", "mesh"),
"FILL_AREA": AnnotationObjectType("Fill Area", "", "NODE_TEXTURE", "mesh"),
"FALL": AnnotationObjectType("Fall", "", "SORT_ASC", "curve"),
"IMAGE": AnnotationObjectType("Image", "Add reference image attached to the drawing", "TEXTURE", "mesh"),
}
# fmt: on
@@ -112,7 +119,7 @@ class Drawing(bonsai.core.tool.Drawing):
@classmethod
def get_annotation_data_type(cls, object_type: str) -> ANNOTATION_DATA_TYPE:
return cls.ANNOTATION_TYPES_DATA[object_type][3]
return cls.ANNOTATION_TYPES_DATA[object_type].data_type
@classmethod
def create_annotation_object(cls, drawing: ifcopenshell.entity_instance, object_type: str) -> bpy.types.Object:
@@ -35,7 +35,7 @@ def add_surface_style(
style: ifcopenshell.entity_instance,
ifc_class: SURFACE_STYLE_TYPES = "IfcSurfaceStyleShading",
attributes: Optional[dict[str, Any]] = None,
) -> None:
) -> ifcopenshell.entity_instance:
"""Adds a new presentation item to a surface style
A surface style can have multiple different types of presentation items
@@ -123,20 +123,20 @@ def add_surface_style(
"SpecularHighlight": {"SpecularRoughness": 0.5}, # Roughness factor
})
"""
settings = {"style": style, "ifc_class": ifc_class, "attributes": attributes or {}}
attributes = attributes or {}
style_item = file.create_entity(ifc_class)
ifcopenshell.api.style.edit_surface_style(file, style=style_item, attributes=attributes)
styles: list[ifcopenshell.entity_instance]
styles = list(style.Styles or [])
style_item = file.create_entity(settings["ifc_class"])
ifcopenshell.api.style.edit_surface_style(file, style=style_item, attributes=settings["attributes"])
styles = list(settings["style"].Styles or [])
select_class = settings["ifc_class"]
select_class = ifc_class
if select_class == "IfcSurfaceStyleRendering":
select_class = "IfcSurfaceStyleShading"
duplicate_items = [s for s in styles if s.is_a(select_class)]
for duplicate_item in duplicate_items:
ifcopenshell.api.style.remove_surface_style(file, style=duplicate_item)
styles = list(settings["style"].Styles or [])
styles = list(style.Styles or [])
styles.append(style_item)
settings["style"].Styles = styles
style.Styles = styles
return style_item
@@ -454,7 +454,7 @@ def get_elements_by_pset(pset: ifcopenshell.entity_instance) -> set[ifcopenshell
return elements
def get_predefined_type(element: ifcopenshell.entity_instance) -> str:
def get_predefined_type(element: ifcopenshell.entity_instance) -> Union[str, None]:
"""Retrieves the PrefefinedType attribute of an element.
If the predefined type is user defined, the custom type (such as object