mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 06:39:13 +00:00
move ifc file handling logic to ifcopenshell.file
to reuse the same logic for both ifcopenshell.open and ifcopenshell.file.from_string()
This commit is contained in:
@@ -103,10 +103,6 @@ try:
|
|||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
READ_ERROR = ifcopenshell_wrapper.file_open_status.READ_ERROR
|
|
||||||
NO_HEADER = ifcopenshell_wrapper.file_open_status.NO_HEADER
|
|
||||||
UNSUPPORTED_SCHEMA = ifcopenshell_wrapper.file_open_status.UNSUPPORTED_SCHEMA
|
|
||||||
|
|
||||||
|
|
||||||
class Error(Exception):
|
class Error(Exception):
|
||||||
"""Error used when a generic problem occurs"""
|
"""Error used when a generic problem occurs"""
|
||||||
@@ -162,18 +158,7 @@ def open(path: Union[os.PathLike, str], format: Optional[str] = None, should_str
|
|||||||
if should_stream:
|
if should_stream:
|
||||||
return stream(path)
|
return stream(path)
|
||||||
f = ifcopenshell_wrapper.open(str(path.absolute()))
|
f = ifcopenshell_wrapper.open(str(path.absolute()))
|
||||||
if f.good():
|
return file(f)
|
||||||
return file(f)
|
|
||||||
else:
|
|
||||||
exc, msg = {
|
|
||||||
READ_ERROR: (IOError, "Unable to open file for reading"),
|
|
||||||
NO_HEADER: (Error, "Unable to parse IFC SPF header"),
|
|
||||||
UNSUPPORTED_SCHEMA: (
|
|
||||||
SchemaError,
|
|
||||||
"Unsupported schema: %s" % ",".join(f.header.file_schema.schema_identifiers),
|
|
||||||
),
|
|
||||||
}[f.good().value()]
|
|
||||||
raise exc(msg)
|
|
||||||
|
|
||||||
|
|
||||||
def create_entity(type, schema="IFC4", *args, **kwargs):
|
def create_entity(type, schema="IFC4", *args, **kwargs):
|
||||||
|
|||||||
@@ -175,6 +175,10 @@ class Transaction:
|
|||||||
|
|
||||||
file_dict = {}
|
file_dict = {}
|
||||||
|
|
||||||
|
READ_ERROR = ifcopenshell_wrapper.file_open_status.READ_ERROR
|
||||||
|
NO_HEADER = ifcopenshell_wrapper.file_open_status.NO_HEADER
|
||||||
|
UNSUPPORTED_SCHEMA = ifcopenshell_wrapper.file_open_status.UNSUPPORTED_SCHEMA
|
||||||
|
|
||||||
|
|
||||||
class file:
|
class file:
|
||||||
"""Base class for containing IFC files.
|
"""Base class for containing IFC files.
|
||||||
@@ -246,6 +250,18 @@ class file:
|
|||||||
else:
|
else:
|
||||||
schema = {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema)
|
schema = {"IFC4X3": "IFC4X3_ADD2"}.get(schema, schema)
|
||||||
if f is not None:
|
if f is not None:
|
||||||
|
if not f.good():
|
||||||
|
from . import Error, SchemaError
|
||||||
|
|
||||||
|
exc, msg = {
|
||||||
|
READ_ERROR: (IOError, "Unable to open file for reading"),
|
||||||
|
NO_HEADER: (Error, "Unable to parse IFC SPF header"),
|
||||||
|
UNSUPPORTED_SCHEMA: (
|
||||||
|
SchemaError,
|
||||||
|
"Unsupported schema: %s" % ",".join(f.header.file_schema.schema_identifiers),
|
||||||
|
),
|
||||||
|
}[f.good().value()]
|
||||||
|
raise exc(msg)
|
||||||
self.wrapped_data = f
|
self.wrapped_data = f
|
||||||
else:
|
else:
|
||||||
args = filter(None, [schema])
|
args = filter(None, [schema])
|
||||||
|
|||||||
Reference in New Issue
Block a user