This commit is contained in:
Andrej730
2024-04-30 12:17:23 +05:00
parent fc0ffd1c02
commit 137a306269
12 changed files with 50 additions and 23 deletions
@@ -29,7 +29,7 @@ EPSILON = 1e-6
class Usecase:
def __init__(self, file, **settings):
def __init__(self, file: ifcopenshell.file, **settings):
# TODO: This usecase currently depends on Blender's data model
self.file = file
self.settings = {
@@ -58,7 +58,7 @@ class Usecase:
for key, value in settings.items():
self.settings[key] = value
def execute(self):
def execute(self) -> ifcopenshell.entity_instance:
self.is_manifold = None
if (
isinstance(self.settings["geometry"], bpy.types.Mesh)
@@ -379,7 +379,7 @@ class Usecase:
Axis=self.file.createIfcDirection(polygon.normal),
))
def create_annotation_fill_areas(self, is_2d=False):
def create_annotation_fill_areas(self, is_2d=False) -> list[ifcopenshell.entity_instance]:
items = []
if self.file.schema != "IFC2X3":
points = self.create_cartesian_point_list_from_vertices(self.settings["geometry"].vertices, is_2d=is_2d)
@@ -391,7 +391,9 @@ class Usecase:
items.append(self.file.createIfcAnnotationFillArea(OuterBoundary=curve))
return items
def create_curve_from_polygon(self, points, polygon, is_2d=False):
def create_curve_from_polygon(
self, points: ifcopenshell.entity_instance, polygon: bpy.types.MeshPolygon, is_2d=False
) -> ifcopenshell.entity_instance:
indices = list(polygon.vertices)
indices.append(indices[0])
edge_loop = [self.file.createIfcLineIndex((v1 + 1, v2 + 1)) for v1, v2 in zip(indices, indices[1:])]
@@ -460,7 +462,7 @@ class Usecase:
return False
return True
def create_curves(self, should_exclude_faces=False, is_2d=False):
def create_curves(self, should_exclude_faces=False, is_2d=False, ignore_non_loose_edges=False):
geom_data = self.settings["geometry"]
if isinstance(geom_data, bpy.types.Mesh):
@@ -530,7 +532,9 @@ class Usecase:
bmesh.ops.remove_doubles(bm, verts=bm.verts, dist=0.0001)
tool.Blender.apply_bmesh(mesh, bm)
def create_curves_from_mesh_ifc2x3(self, should_exclude_faces=False, is_2d=False):
def create_curves_from_mesh_ifc2x3(
self, should_exclude_faces=False, is_2d=False
) -> list[ifcopenshell.entity_instance]:
geom_data = self.settings["geometry"].copy()
self.remove_doubles_from_mesh(geom_data)
curves = []
@@ -810,7 +814,7 @@ class Usecase:
z = self.convert_si_to_unit(z)
return self.file.createIfcCartesianPoint((x, y, z))
def create_cartesian_point_list_from_vertices(self, vertices, is_2d=False):
def create_cartesian_point_list_from_vertices(self, vertices: list[bpy.types.MeshVertex], is_2d=False):
if is_2d:
return self.file.createIfcCartesianPointList2D([self.convert_si_to_unit(v.co.xy) for v in vertices])
return self.file.createIfcCartesianPointList3D([self.convert_si_to_unit(v.co) for v in vertices])
@@ -15,10 +15,18 @@
#
# You should have received a copy of the GNU Lesser General Public License
# along with IfcOpenShell. If not, see <http://www.gnu.org/licenses/>.
import ifcopenshell
from typing import Optional
class Usecase:
def __init__(self, file, profile_set=None, material=None, profile=None):
def __init__(
self,
file: ifcopenshell.file,
profile_set: ifcopenshell.entity_instance,
material: Optional[ifcopenshell.entity_instance] = None,
profile: Optional[ifcopenshell.entity_instance] = None,
):
"""Add a new profile item to a profile set
A profile item in a profile set represents an extruded 2D profile curve
@@ -41,10 +49,10 @@ class Usecase:
how to add a profile set.
:type profile_set: ifcopenshell.entity_instance.entity_instance
:param material: The IfcMaterial that the profile item is made out of.
:type material: ifcopenshell.entity_instance.entity_instance
:type material: ifcopenshell.entity_instance.entity_instance, optional
:param profile: The IfcProfileDef that represents the 2D cross section
of the the profile item.
:type profile: ifcopenshell.entity_instance.entity_instance
:type profile: ifcopenshell.entity_instance.entity_instance, optional
:return: The newly created IfcMaterialProfile
:rtype: ifcopenshell.entity_instance.entity_instance
@@ -84,7 +92,7 @@ class Usecase:
self.file = file
self.settings = {"profile_set": profile_set, "material": material, "profile": profile}
def execute(self):
def execute(self) -> ifcopenshell.entity_instance:
profiles = list(self.settings["profile_set"].MaterialProfiles or [])
profile = self.file.create_entity("IfcMaterialProfile")
if self.settings["material"]:
@@ -21,10 +21,11 @@ import ifcopenshell
import ifcopenshell.api
import ifcopenshell.api.owner.settings
import ifcopenshell.util.element
from typing import Union
class Usecase:
def __init__(self, file, element=None):
def __init__(self, file: ifcopenshell.file, element: ifcopenshell.entity_instance):
"""Updates the owner that is assigned to an object
This ensures that the owner is tracked to have modified the object last,
@@ -60,7 +61,7 @@ class Usecase:
self.file = file
self.settings = {"element": element}
def execute(self):
def execute(self) -> Union[ifcopenshell.entity_instance, None]:
if not hasattr(self.settings["element"], "OwnerHistory"):
return
user = ifcopenshell.api.owner.settings.get_user(self.file)