diff --git a/src/compas_ifc/brep/tessellatedbrep.py b/src/compas_ifc/brep/tessellatedbrep.py index 4ff1c42e..8068c0cf 100644 --- a/src/compas_ifc/brep/tessellatedbrep.py +++ b/src/compas_ifc/brep/tessellatedbrep.py @@ -1,6 +1,6 @@ +import numpy as np from compas.geometry import Geometry from compas.geometry import transform_points_numpy -import numpy as np class TessellatedBrep(Geometry): diff --git a/src/compas_ifc/brep/tessellatedbrepobject.py b/src/compas_ifc/brep/tessellatedbrepobject.py index 7ab5b3dd..867c09cc 100644 --- a/src/compas_ifc/brep/tessellatedbrepobject.py +++ b/src/compas_ifc/brep/tessellatedbrepobject.py @@ -1,8 +1,9 @@ +import numpy as np +from compas.colors import Color +from compas.datastructures import Mesh from compas_viewer.scene import ViewerSceneObject + from .tessellatedbrep import TessellatedBrep -from compas.datastructures import Mesh -from compas.colors import Color -import numpy as np class TessellatedBrepObject(ViewerSceneObject): diff --git a/src/compas_ifc/entities/__init__.py b/src/compas_ifc/entities/__init__.py index 16f0a611..9c0d8159 100644 --- a/src/compas_ifc/entities/__init__.py +++ b/src/compas_ifc/entities/__init__.py @@ -49,7 +49,7 @@ .. code-block:: python for association in entity.HasAssociations: - if association.is_a('IfcRelAssociatesClassification'): + if association.is_a("IfcRelAssociatesClassification"): ... Material Associations @@ -66,14 +66,15 @@ .. code-block:: python for association in entity.HasAssociations: - if association.is_a('IfcRelAssociatesMaterial'): + if association.is_a("IfcRelAssociatesMaterial"): ... Object Composition ================== Objects may be composed into parts to indicate levels of detail, such as a building having multiple storeys, a framed wall having studs, or a task having subtasks. -Composition may form a hierarchy of multiple levels, where an object must have single parent, or if a top-level object then declared within the single project or a project library. +Composition may form a hierarchy of multiple levels, where an object must have single parent, +or if a top-level object then declared within the single project or a project library. Element Composition ------------------- diff --git a/src/compas_ifc/entities/buildingelements.py b/src/compas_ifc/entities/buildingelements.py index 30380458..09db03a2 100644 --- a/src/compas_ifc/entities/buildingelements.py +++ b/src/compas_ifc/entities/buildingelements.py @@ -85,9 +85,7 @@ def composite_body_with_opening(self): from compas_ifc.representation import entity_body_with_opening_geometry if not self._composite_body_with_opening: - self._composite_body_with_opening = entity_body_with_opening_geometry( - entity=self, bodies=self.composite_body, voids=self.composite_opening - ) + self._composite_body_with_opening = entity_body_with_opening_geometry(entity=self, bodies=self.composite_body, voids=self.composite_opening) return self._composite_body_with_opening @composite_body_with_opening.setter diff --git a/src/compas_ifc/entities/entity.py b/src/compas_ifc/entities/entity.py index b1dfe5ce..c3a00c9a 100644 --- a/src/compas_ifc/entities/entity.py +++ b/src/compas_ifc/entities/entity.py @@ -2,7 +2,6 @@ from typing import Union # from typing import Optional - import ifcopenshell import ifcopenshell.util.element import ifcopenshell.util.pset diff --git a/src/compas_ifc/entities/objectdefinition.py b/src/compas_ifc/entities/objectdefinition.py index 8414483c..4720cece 100644 --- a/src/compas_ifc/entities/objectdefinition.py +++ b/src/compas_ifc/entities/objectdefinition.py @@ -41,9 +41,7 @@ def is_decomposed_by(self): @property def children(self): - children = [ - entity for entity in self.model.get_entities_by_type("IfcObjectDefinition") if entity.parent == self - ] + children = [entity for entity in self.model.get_entities_by_type("IfcObjectDefinition") if entity.parent == self] for entity in self.model._new_entities: if entity.parent == self and entity not in children: children.append(entity) diff --git a/src/compas_ifc/entities/project.py b/src/compas_ifc/entities/project.py index 7fb0f696..9697edf7 100644 --- a/src/compas_ifc/entities/project.py +++ b/src/compas_ifc/entities/project.py @@ -4,6 +4,7 @@ from compas.geometry import Frame from compas.geometry import Vector + from compas_ifc.entities.objectdefinition import ObjectDefinition from compas_ifc.entities.site import Building from compas_ifc.entities.site import Site diff --git a/src/compas_ifc/model.py b/src/compas_ifc/model.py index 5cd8c230..ab1bfa0b 100644 --- a/src/compas_ifc/model.py +++ b/src/compas_ifc/model.py @@ -1,20 +1,21 @@ from typing import List -from compas_ifc.entities.element import Element -from compas_ifc.entities.product import Product +import ifcopenshell + from compas_ifc.entities.building import Building from compas_ifc.entities.buildingelements import BuildingElement -from compas_ifc.entities.geographicelement import GeographicElement from compas_ifc.entities.buildingelements import BuildingElementProxy from compas_ifc.entities.buildingstorey import BuildingStorey -from compas_ifc.entities.objectdefinition import ObjectDefinition +from compas_ifc.entities.element import Element from compas_ifc.entities.entity import Entity +from compas_ifc.entities.geographicelement import GeographicElement +from compas_ifc.entities.objectdefinition import ObjectDefinition +from compas_ifc.entities.product import Product from compas_ifc.entities.project import Project from compas_ifc.entities.site import Site from .reader import IFCReader from .writer import IFCWriter -import ifcopenshell class Model: @@ -60,9 +61,7 @@ class Model: """ - def __init__( - self, filepath: str = None, entity_types: dict = None, use_occ=False, schema=None, load_geometries=True - ) -> None: + def __init__(self, filepath: str = None, entity_types: dict = None, use_occ=False, schema=None, load_geometries=True) -> None: self.reader = IFCReader(model=self, entity_types=entity_types, use_occ=use_occ) self.writer = IFCWriter(model=self) self._new_entities = set() diff --git a/src/compas_ifc/reader.py b/src/compas_ifc/reader.py index b7a05448..81b34268 100644 --- a/src/compas_ifc/reader.py +++ b/src/compas_ifc/reader.py @@ -1,11 +1,11 @@ +import multiprocessing +import os +import time from typing import List import ifcopenshell -import os -import multiprocessing import numpy as np from compas.geometry import Transformation -import time from compas_ifc.entities.entity import Entity @@ -148,9 +148,7 @@ def load_geometries(self, include=None, exclude=None): if self.use_occ: settings.set(settings.USE_PYTHON_OPENCASCADE, True) - iterator = ifcopenshell.geom.iterator( - settings, self._file, multiprocessing.cpu_count(), include=include, exclude=exclude - ) + iterator = ifcopenshell.geom.iterator(settings, self._file, multiprocessing.cpu_count(), include=include, exclude=exclude) start = time.time() if iterator.initialize(): while True: diff --git a/src/compas_ifc/representation.py b/src/compas_ifc/representation.py index 24433c5b..fa4f4423 100644 --- a/src/compas_ifc/representation.py +++ b/src/compas_ifc/representation.py @@ -41,21 +41,21 @@ from operator import mul from typing import List +from compas.geometry import Box +from compas.geometry import Scale +from compas.geometry import Transformation from compas_occ.brep import OCCBrep from OCC.Core.BRep import BRep_Builder from OCC.Core.TopoDS import TopoDS_Compound -from compas.geometry import Box -from compas.geometry import Scale -from compas.geometry import Transformation -from compas_ifc.entities.entity import Entity from compas_ifc.brep import TessellatedBrep +from compas_ifc.entities.entity import Entity from compas_ifc.resources import IfcAxis2Placement3D_to_frame from compas_ifc.resources import IfcBoundingBox_to_box from compas_ifc.resources import IfcCartesianTransformationOperator3D_to_frame from compas_ifc.resources import IfcIndexedPolyCurve_to_lines -from compas_ifc.resources import IfcLocalPlacement_to_transformation from compas_ifc.resources import IfcLocalPlacement_to_frame +from compas_ifc.resources import IfcLocalPlacement_to_transformation from compas_ifc.resources import IfcShape_to_brep from compas_ifc.resources import IfcShape_to_tessellatedbrep @@ -87,7 +87,6 @@ def entity_transformation(entity: Entity): def _entity_transformation(_entity, scale=1.0): - if _entity.ObjectPlacement: scaled_placement = IfcLocalPlacement_to_transformation(_entity.ObjectPlacement, scale=scale) else: diff --git a/src/compas_ifc/resources/brep.py b/src/compas_ifc/resources/brep.py index c78f0da1..ddd4298c 100644 --- a/src/compas_ifc/resources/brep.py +++ b/src/compas_ifc/resources/brep.py @@ -1,13 +1,12 @@ +from typing import List + import ifcopenshell import numpy as np - -from typing import List from compas.tolerance import TOL -from .primities import point_to_ifc_cartesian_point -from .primities import occ_plane_to_frame from .primities import frame_to_ifc_plane - +from .primities import occ_plane_to_frame +from .primities import point_to_ifc_cartesian_point from .shapes import occ_cylinder_to_ifc_cylindrical_surface @@ -149,9 +148,7 @@ def get_ifc_curve(edge): if not IfcEdgeCurve: raise ValueError("Edge not found") - ifc_oriented_edge = file.create_entity( - "IFCORIENTEDEDGE", EdgeElement=IfcEdgeCurve, Orientation=oriented - ) + ifc_oriented_edge = file.create_entity("IFCORIENTEDEDGE", EdgeElement=IfcEdgeCurve, Orientation=oriented) ifc_oriented_edges.append(ifc_oriented_edge) edge_loop = file.create_entity("IfcEdgeLoop", ifc_oriented_edges) @@ -167,26 +164,18 @@ def get_ifc_curve(edge): occ_plane = face.occ_adaptor.Plane() frame = occ_plane_to_frame(occ_plane) ifc_plane = frame_to_ifc_plane(file, frame) - IfcAdvancedFace = file.create_entity( - "IfcAdvancedFace", face_bounds, ifc_plane, SameSense=same_sense - ) + IfcAdvancedFace = file.create_entity("IfcAdvancedFace", face_bounds, ifc_plane, SameSense=same_sense) elif face.is_cylinder: cylinder = face.occ_adaptor.Cylinder() IfcCylindricalSurface = occ_cylinder_to_ifc_cylindrical_surface(file, cylinder) - IfcAdvancedFace = file.create_entity( - "IfcAdvancedFace", face_bounds, IfcCylindricalSurface, SameSense=same_sense - ) + IfcAdvancedFace = file.create_entity("IfcAdvancedFace", face_bounds, IfcCylindricalSurface, SameSense=same_sense) else: control_points = np.array(face.nurbssurface.points.points, dtype=float) control_points = control_points.swapaxes(0, 1) ifc_control_points = [] - u_knots, u_mults = calculate_knots_and_multiplicities( - list(face.nurbssurface.occ_surface.UKnotSequence()) - ) - v_knots, v_mults = calculate_knots_and_multiplicities( - list(face.nurbssurface.occ_surface.VKnotSequence()) - ) + u_knots, u_mults = calculate_knots_and_multiplicities(list(face.nurbssurface.occ_surface.UKnotSequence())) + v_knots, v_mults = calculate_knots_and_multiplicities(list(face.nurbssurface.occ_surface.VKnotSequence())) for row in control_points: ifc_row = [] @@ -237,9 +226,7 @@ def get_ifc_curve(edge): WeightsData=ifc_weights, ) - IfcAdvancedFace = file.create_entity( - "IfcAdvancedFace", face_bounds, IfcBSplineSurfaceWithKnots, SameSense=same_sense - ) + IfcAdvancedFace = file.create_entity("IfcAdvancedFace", face_bounds, IfcBSplineSurfaceWithKnots, SameSense=same_sense) ifc_faces.append(IfcAdvancedFace) diff --git a/src/compas_ifc/resources/geometricmodel.py b/src/compas_ifc/resources/geometricmodel.py index 7cf3663e..6c9cea34 100644 --- a/src/compas_ifc/resources/geometricmodel.py +++ b/src/compas_ifc/resources/geometricmodel.py @@ -1,16 +1,17 @@ from typing import List +import ifcopenshell + # from compas.geometry import Polyline from compas.geometry import Box from compas.geometry import Line from compas.geometry import Point from compas.geometry import Transformation + from compas_ifc.resources.geometry import IfcAxis2Placement3D_to_frame from compas_ifc.resources.geometry import IfcDirection_to_vector from compas_ifc.resources.geometry import IfcProfileDef_to_curve -import ifcopenshell - def IfcAdvancedBrep_to_brep(advanced_brep): """ diff --git a/src/compas_ifc/resources/mesh.py b/src/compas_ifc/resources/mesh.py index 7d0b39d5..5868e865 100644 --- a/src/compas_ifc/resources/mesh.py +++ b/src/compas_ifc/resources/mesh.py @@ -1,5 +1,4 @@ import ifcopenshell - from compas.datastructures import Mesh diff --git a/src/compas_ifc/resources/primities.py b/src/compas_ifc/resources/primities.py index 111091b2..9df02771 100644 --- a/src/compas_ifc/resources/primities.py +++ b/src/compas_ifc/resources/primities.py @@ -1,7 +1,7 @@ import ifcopenshell - from compas.geometry import Frame from compas.geometry import Point + from .shapes import create_IfcAxis2Placement3D diff --git a/src/compas_ifc/resources/representation.py b/src/compas_ifc/resources/representation.py index 9df411da..f64798d1 100644 --- a/src/compas_ifc/resources/representation.py +++ b/src/compas_ifc/resources/representation.py @@ -1,10 +1,9 @@ -from ifcopenshell.api import run - from compas.datastructures import Mesh from compas.geometry import Box from compas.geometry import Cone from compas.geometry import Cylinder from compas.geometry import Sphere +from ifcopenshell.api import run from .brep import brep_to_ifc_advanced_brep from .mesh import mesh_to_IfcPolygonalFaceSet diff --git a/src/compas_ifc/resources/shapes.py b/src/compas_ifc/resources/shapes.py index a1f53772..36042114 100644 --- a/src/compas_ifc/resources/shapes.py +++ b/src/compas_ifc/resources/shapes.py @@ -1,5 +1,4 @@ import ifcopenshell - from compas.geometry import Box from compas.geometry import Cone from compas.geometry import Cylinder @@ -21,9 +20,7 @@ def create_IfcAxis2Placement3D(file, point=None, dir1=None, dir2=None): return axis2placement -def create_IfcShapeRepresentation( - file: ifcopenshell.file, item: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance -) -> ifcopenshell.entity_instance: +def create_IfcShapeRepresentation(file: ifcopenshell.file, item: ifcopenshell.entity_instance, context: ifcopenshell.entity_instance) -> ifcopenshell.entity_instance: """ Create an IFC Shape Representation from an IFC item and a context. """ diff --git a/src/compas_ifc/writer.py b/src/compas_ifc/writer.py index ba18353f..4c5f86c4 100644 --- a/src/compas_ifc/writer.py +++ b/src/compas_ifc/writer.py @@ -1,17 +1,17 @@ +import time + import ifcopenshell from ifcopenshell.api import run -from .entities.objectdefinition import ObjectDefinition from .entities.element import Element from .entities.entity import Entity +from .entities.objectdefinition import ObjectDefinition from .entities.product import Product from .entities.project import Project from .entities.root import Root from .resources.representation import write_body_representation from .resources.shapes import frame_to_ifc_axis2_placement_3d -import time - class IFCWriter(object): """ @@ -81,9 +81,7 @@ def default_body_context(self): def default_project(self): if not self._default_project: if not self.model.projects: - self._default_project = self.file.create_entity( - "IfcProject", GlobalId=self.create_guid(), Name="Default Project" - ) + self._default_project = self.file.create_entity("IfcProject", GlobalId=self.create_guid(), Name="Default Project") run("unit.assign_unit", self.file) else: self._default_project = self.write_entity(self.model.projects[0]) @@ -93,9 +91,7 @@ def default_project(self): def default_site(self): if not self._default_site: if not self.model.sites: - self._default_site = self.file.create_entity( - "IfcSite", Name="Default Site", GlobalId=self.create_guid() - ) + self._default_site = self.file.create_entity("IfcSite", Name="Default Site", GlobalId=self.create_guid()) self.file.create_entity( "IfcRelAggregates", GlobalId=self.create_guid(), @@ -110,9 +106,7 @@ def default_site(self): def default_building(self): if not self._default_building: if not self.model.buildings: - self._default_building = self.file.create_entity( - "IfcBuilding", GlobalId=self.create_guid(), Name="Default Building" - ) + self._default_building = self.file.create_entity("IfcBuilding", GlobalId=self.create_guid(), Name="Default Building") self.file.create_entity( "IfcRelAggregates", GlobalId=self.create_guid(), @@ -127,9 +121,7 @@ def default_building(self): def default_building_storey(self): if not self._default_building_storey: if not self.model.building_storeys: - self._default_building_storey = self.file.create_entity( - "IfcBuildingStorey", GlobalId=self.create_guid(), Name="Default Storey" - ) + self._default_building_storey = self.file.create_entity("IfcBuildingStorey", GlobalId=self.create_guid(), Name="Default Storey") self.file.create_entity( "IfcRelAggregates", GlobalId=self.create_guid(), @@ -142,15 +134,12 @@ def default_building_storey(self): @property def default_owner_history(self): - if not self._default_owner_history: import compas_ifc person = self.file.create_entity("IfcPerson") organization = self.file.create_entity("IfcOrganization", Name="compas.dev") - person_and_org = self.file.create_entity( - "IfcPersonAndOrganization", ThePerson=person, TheOrganization=organization - ) + person_and_org = self.file.create_entity("IfcPersonAndOrganization", ThePerson=person, TheOrganization=organization) application = self.file.create_entity( "IfcApplication", ApplicationDeveloper=organization, @@ -280,9 +269,7 @@ def create_new_relation(self, entity: ObjectDefinition): RelatedElements=[child], ) else: - self.file.create_entity( - "IfcRelAggregates", GlobalId=self.create_guid(), RelatingObject=parent, RelatedObjects=[child] - ) + self.file.create_entity("IfcRelAggregates", GlobalId=self.create_guid(), RelatingObject=parent, RelatedObjects=[child]) def write_entity(self, entity: Entity) -> None: """Writes the given entity recursively with all its referencing attributes to the ifc file.""" @@ -327,10 +314,8 @@ def write_entity_representation(self, entity: Entity): """Writes the representations of the given entity to the ifc file.""" if isinstance(entity, Product): if entity.body: - if not id(entity.body) in self._representationmap: - representation = write_body_representation( - self.file, entity.body, self._entitymap[entity], self.default_body_context - ) + if id(entity.body) not in self._representationmap: + representation = write_body_representation(self.file, entity.body, self._entitymap[entity], self.default_body_context) self._representationmap[id(entity.body)] = representation else: representation = self._representationmap[id(entity.body)]