This commit is contained in:
Andrej730
2025-04-22 16:46:20 +05:00
parent f9bf8897bc
commit 4b3ca11c12
5 changed files with 15 additions and 8 deletions
@@ -95,7 +95,7 @@ classes = (
)
addon_keymaps = []
addon_keymaps: list[tuple[bpy.types.KeyMap, bpy.types.KeyMapItem]] = []
@persistent
@@ -73,12 +73,13 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
def _execute(self, context):
obj = context.active_object
assert obj
if tool.Geometry.is_representation_item(obj):
self.separate_item(context, obj)
elif element := tool.Ifc.get_entity(obj):
self.separate_element(element)
def separate_item(self, context, obj):
def separate_item(self, context: bpy.types.Context, obj: bpy.types.Object) -> None:
item = tool.Geometry.get_active_representation(obj)
assert item
if tool.Geometry.is_meshlike_item(item):
@@ -126,7 +127,7 @@ class OverrideMeshSeparate(bpy.types.Operator, tool.Ifc.Operator):
tool.Ifc.link(item, obj)
props.add_item_object(obj, item)
def separate_element(self, element):
def separate_element(self, element: ifcopenshell.entity_instance) -> None:
# You cannot separate meshes if the representation is mapped.
relating_type = tool.Root.get_element_type(element)
if relating_type and tool.Root.does_type_have_representations(relating_type):
+3 -1
View File
@@ -42,6 +42,7 @@ from typing import Any, Optional, Union, Literal, Iterable, Callable, TypeVar, G
from typing_extensions import assert_never
if TYPE_CHECKING:
import bpy._typing.rna_enums as rna_enums
from bonsai.bim.prop import BIMProperties, BIMObjectProperties
from bonsai.bim.module.attribute.prop import BIMAttributeProperties
from bonsai.bim.module.csv.prop import CsvProperties
@@ -879,7 +880,8 @@ class Blender(bonsai.core.tool.Blender):
return results
@classmethod
def toggle_edit_mode(cls, context: bpy.types.Context) -> set[str]:
def toggle_edit_mode(cls, context: bpy.types.Context) -> set[rna_enums.OperatorReturnItems]:
"""Run ``object.mode_set(EDIT)``."""
ao = context.active_object
if not ao:
return {"CANCELLED"}
+7 -3
View File
@@ -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 numpy as np
@@ -28,7 +29,10 @@ import bonsai.bim.handler
import bonsai.tool as tool
from pathlib import Path
from bonsai.bim.ifc import IfcStore, IFC_CONNECTED_TYPE
from typing import Optional, Union, Any, final, Literal
from typing import Optional, Union, Any, final, Literal, TYPE_CHECKING
if TYPE_CHECKING:
from bpy._typing import rna_enums
class Ifc(bonsai.core.tool.Ifc):
@@ -317,11 +321,11 @@ class Ifc(bonsai.core.tool.Ifc):
transaction_data: Union[Any, None] = None
@final
def execute(self, context):
def execute(self, context) -> set[rna_enums.OperatorReturnItems]:
IfcStore.execute_ifc_operator(self, context)
return {"FINISHED"}
# NOTE: this class can't inherit from abc.ABC to use abc.abstractmethod
# because it conflicts with bpy.types.Operator.
def _execute(self, context: bpy.types.Context) -> None:
def _execute(self, context: bpy.types.Context) -> Union[None, set[rna_enums.OperatorReturnItems]]:
raise NotImplementedError("IFC operator must implement _execute method.")
+1 -1
View File
@@ -70,7 +70,7 @@ class Root(bonsai.core.tool.Root):
def copy_representation(
cls, source: ifcopenshell.entity_instance, dest: ifcopenshell.entity_instance
) -> dict[int, ifcopenshell.entity_instance]:
def exclude_callback(attribute):
def exclude_callback(attribute: ifcopenshell.entity_instance) -> bool:
return attribute.is_a("IfcProfileDef") and attribute.ProfileName
copied_entities: dict[int, ifcopenshell.entity_instance] = {}