mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-14 19:34:34 +00:00
typing
This commit is contained in:
@@ -22,16 +22,17 @@ import ifcopenshell.api.owner.settings
|
||||
import ifcopenshell.util.pset
|
||||
import ifcopenshell.util.element
|
||||
import ifcopenshell.util.unit
|
||||
from logging import Logger
|
||||
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, src, file, logger, unit="METERS"):
|
||||
def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, unit: str = "METERS"):
|
||||
"""Converts the length unit of a model to the specified unit
|
||||
|
||||
Allowed metric units include METERS, MILLIMETERS, CENTIMETERS, etc.
|
||||
Allowed imperial units include INCHES, FEET, MILES.
|
||||
|
||||
:param unit: The name of the desired unit.
|
||||
:param unit: The name of the desired unit, defaults to "METERS"
|
||||
:type unit: str
|
||||
|
||||
Example:
|
||||
@@ -48,7 +49,7 @@ class Patcher:
|
||||
self.file = file
|
||||
self.logger = logger
|
||||
self.unit = unit
|
||||
self.file_patched: ifcopenshell.file = None
|
||||
self.file_patched: ifcopenshell.file
|
||||
|
||||
def patch(self):
|
||||
self.file_patched = ifcopenshell.util.unit.convert_file_length_units(self.file, self.unit)
|
||||
|
||||
@@ -18,10 +18,12 @@
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.element
|
||||
from typing import Union
|
||||
from logging import Logger
|
||||
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, src, file, logger, filepath=None):
|
||||
def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, filepath: str):
|
||||
"""Merge two IFC models into one
|
||||
|
||||
Note that other than combining the two IfcProject elements into one, no
|
||||
@@ -46,18 +48,25 @@ class Patcher:
|
||||
|
||||
def patch(self):
|
||||
source = ifcopenshell.open(self.filepath)
|
||||
self.existing_contexts = self.file.by_type("IfcGeometricRepresentationContext")
|
||||
self.added_contexts = set()
|
||||
self.existing_contexts: list[ifcopenshell.entity_instance] = self.file.by_type(
|
||||
"IfcGeometricRepresentationContext"
|
||||
)
|
||||
self.added_contexts: set[ifcopenshell.entity_instance] = set()
|
||||
|
||||
original_project = self.file.by_type("IfcProject")[0]
|
||||
merged_project = self.file.add(source.by_type("IfcProject")[0])
|
||||
|
||||
for element in source.by_type("IfcGeometricRepresentationContext"):
|
||||
new = self.file.add(element)
|
||||
self.added_contexts.add(new)
|
||||
|
||||
for element in source:
|
||||
self.file.add(element)
|
||||
|
||||
for inverse in self.file.get_inverse(merged_project):
|
||||
ifcopenshell.util.element.replace_attribute(inverse, merged_project, original_project)
|
||||
self.file.remove(merged_project)
|
||||
|
||||
self.reuse_existing_contexts()
|
||||
|
||||
def reuse_existing_contexts(self):
|
||||
@@ -73,7 +82,9 @@ class Patcher:
|
||||
for added_context in to_delete:
|
||||
ifcopenshell.util.element.remove_deep2(self.file, added_context)
|
||||
|
||||
def get_equivalent_existing_context(self, added_context):
|
||||
def get_equivalent_existing_context(
|
||||
self, added_context: ifcopenshell.entity_instance
|
||||
) -> Union[ifcopenshell.entity_instance, None]:
|
||||
for context in self.existing_contexts:
|
||||
if context.is_a() != added_context.is_a():
|
||||
continue
|
||||
|
||||
@@ -18,10 +18,11 @@
|
||||
|
||||
import ifcopenshell
|
||||
import ifcopenshell.util.schema
|
||||
from logging import Logger
|
||||
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, src, file, logger, schema="IFC4"):
|
||||
def __init__(self, src: str, file: ifcopenshell.file, logger: Logger, schema: str = "IFC4"):
|
||||
"""Migrate from one IFC version to another
|
||||
|
||||
Note that this is experimental and will try to preserve as much data as
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
# along with IfcPatch. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import ifcopenshell
|
||||
from logging import Logger
|
||||
|
||||
|
||||
class Patcher:
|
||||
def __init__(self, src, file, logger):
|
||||
def __init__(self, src: str, file: ifcopenshell.file, logger: Logger):
|
||||
"""Purge IFC properties, relationships, and other data
|
||||
|
||||
In some rare cases (i.e. "resetting" a model or for security purposes)
|
||||
|
||||
Reference in New Issue
Block a user