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 object_type = element.ObjectType
return ( return (
object_type in tool.Drawing.ANNOTATION_TYPES_DATA 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): def get_drawing_group(self, element):
@@ -16,6 +16,7 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with Bonsai. If not, see <http://www.gnu.org/licenses/>. # along with Bonsai. If not, see <http://www.gnu.org/licenses/>.
from __future__ import annotations
import os import os
import bpy import bpy
import math import math
@@ -125,7 +126,9 @@ class Annotator:
return obj return obj
@staticmethod @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) camera = tool.Ifc.get_object(drawing)
co1, _, _, _ = Annotator.get_placeholder_coords(camera) co1, _, _, _ = Annotator.get_placeholder_coords(camera)
matrix_world = tool.Drawing.get_camera_matrix(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." 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 lxml import etree
from mathutils import Vector, Matrix from mathutils import Vector, Matrix
from fractions import Fraction 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 from pathlib import Path
if TYPE_CHECKING: if TYPE_CHECKING:
@@ -65,25 +65,32 @@ class Drawing(bonsai.core.tool.Drawing):
# ObjectType: annotation_name, description, icon, data_type # ObjectType: annotation_name, description, icon, data_type
# fmt: off # 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"), class AnnotationObjectType(NamedTuple):
"ANGLE": ("Angle", "", "DRIVER_ROTATIONAL_DIFFERENCE", "curve"), annotation_name: str
"RADIUS": ("Radius", "", "FORWARD", "curve"), description: str
"DIAMETER": ("Diameter", "Add diameter annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "ARROW_LEFTRIGHT", "curve"), icon: str
"TEXT": ("Text", "", "SMALL_CAPS", "empty"), data_type: Drawing.ANNOTATION_DATA_TYPE
"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"), ANNOTATION_TYPES_DATA: dict[str, AnnotationObjectType] = {
"PLAN_LEVEL": ("Level (Plan)", "", "SORTBYEXT", "curve"), "DIMENSION": AnnotationObjectType("Dimension", "Add dimensions annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "FIXED_SIZE", "curve"),
"SECTION_LEVEL": ("Level (Section)", "", "TRIA_DOWN", "curve"), "ANGLE": AnnotationObjectType("Angle", "", "DRIVER_ROTATIONAL_DIFFERENCE", "curve"),
"BREAKLINE": ("Breakline", "", "FCURVE", "mesh"), "RADIUS": AnnotationObjectType("Radius", "", "FORWARD", "curve"),
"SYMBOL": ("Symbol", "", "KEYFRAME", "empty"), "DIAMETER": AnnotationObjectType("Diameter", "Add diameter annotation.\nMeasurement values can be hidden through ShowDescriptionOnly property\nof BBIM_Dimension property set", "ARROW_LEFTRIGHT", "curve"),
"MULTI_SYMBOL": ("Multi-Symbol", "", "OUTLINER_DATA_POINTCLOUD", "mesh"), "TEXT": AnnotationObjectType("Text", "", "SMALL_CAPS", "empty"),
"LINEWORK": ("Line", "", "SNAP_MIDPOINT", "mesh"), "TEXT_LEADER": AnnotationObjectType("Leader", "", "TRACKING_BACKWARDS", "curve"),
"BATTING": ("Batting", "Add batting annotation.\nThickness could be changed through Thickness property of BBIM_Batting property set", "FORCE_FORCE", "mesh"), "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"),
"REVISION_CLOUD":("Revision Cloud", "Add revision cloud", "VOLUME_DATA", "mesh"), "PLAN_LEVEL": AnnotationObjectType("Level (Plan)", "", "SORTBYEXT", "curve"),
"FILL_AREA": ("Fill Area", "", "NODE_TEXTURE", "mesh"), "SECTION_LEVEL": AnnotationObjectType("Level (Section)", "", "TRIA_DOWN", "curve"),
"FALL": ("Fall", "", "SORT_ASC", "curve"), "BREAKLINE": AnnotationObjectType("Breakline", "", "FCURVE", "mesh"),
"IMAGE": ("Image", "Add reference image attached to the drawing", "TEXTURE", "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 # fmt: on
@@ -112,7 +119,7 @@ class Drawing(bonsai.core.tool.Drawing):
@classmethod @classmethod
def get_annotation_data_type(cls, object_type: str) -> ANNOTATION_DATA_TYPE: 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 @classmethod
def create_annotation_object(cls, drawing: ifcopenshell.entity_instance, object_type: str) -> bpy.types.Object: 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, style: ifcopenshell.entity_instance,
ifc_class: SURFACE_STYLE_TYPES = "IfcSurfaceStyleShading", ifc_class: SURFACE_STYLE_TYPES = "IfcSurfaceStyleShading",
attributes: Optional[dict[str, Any]] = None, attributes: Optional[dict[str, Any]] = None,
) -> None: ) -> ifcopenshell.entity_instance:
"""Adds a new presentation item to a surface style """Adds a new presentation item to a surface style
A surface style can have multiple different types of presentation items 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 "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"]) select_class = 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"]
if select_class == "IfcSurfaceStyleRendering": if select_class == "IfcSurfaceStyleRendering":
select_class = "IfcSurfaceStyleShading" select_class = "IfcSurfaceStyleShading"
duplicate_items = [s for s in styles if s.is_a(select_class)] duplicate_items = [s for s in styles if s.is_a(select_class)]
for duplicate_item in duplicate_items: for duplicate_item in duplicate_items:
ifcopenshell.api.style.remove_surface_style(file, style=duplicate_item) 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) styles.append(style_item)
settings["style"].Styles = styles style.Styles = styles
return style_item return style_item
@@ -454,7 +454,7 @@ def get_elements_by_pset(pset: ifcopenshell.entity_instance) -> set[ifcopenshell
return elements 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. """Retrieves the PrefefinedType attribute of an element.
If the predefined type is user defined, the custom type (such as object If the predefined type is user defined, the custom type (such as object