This commit is contained in:
Andrej
2025-05-30 12:08:02 +05:00
parent cc60794293
commit 92a222cda7
5 changed files with 20 additions and 12 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ import http.server
import os import os
import tempfile import tempfile
import time import time
import urllib import urllib.parse
import uuid import uuid
import webbrowser import webbrowser
from re import A from re import A
+1 -1
View File
@@ -19,7 +19,7 @@ from __future__ import annotations
import uuid import uuid
import time import time
import urllib import urllib.parse
import requests import requests
import webbrowser import webbrowser
import http.server import http.server
+2
View File
@@ -40,6 +40,8 @@ from .scriptCodeAster import CommandFileConstructor
class Ifc2CA: class Ifc2CA:
file: ifcopenshell.file
folder_path = None folder_path = None
salome_path = None salome_path = None
model_keys = ["id", "type", "GlobalId", "Name", "LoadedBy", "HasResults"] model_keys = ["id", "type", "GlobalId", "Name", "LoadedBy", "HasResults"]
+1
View File
@@ -559,6 +559,7 @@ if __name__ == "__main__":
) )
elif getattr(args, "import"): elif getattr(args, "import"):
ifc_csv = IfcCsv() ifc_csv = IfcCsv()
ifc_file: ifcopenshell.file
ifc_file = ifcopenshell.open(args.ifc) ifc_file = ifcopenshell.open(args.ifc)
ifc_csv.Import( ifc_csv.Import(
ifc_file, ifc_file,
+15 -10
View File
@@ -24,6 +24,7 @@ import time
import tempfile import tempfile
import typing import typing
import itertools import itertools
import logging
import numpy as np import numpy as np
import multiprocessing import multiprocessing
import ifcopenshell import ifcopenshell
@@ -62,8 +63,8 @@ DEFAULT_DATABASE_NAME = "database"
class Patcher: class Patcher:
def __init__( def __init__(
self, self,
file, file: ifcopenshell.file,
logger, logger: logging.Logger,
sql_type: SQLTypes = "SQLite", sql_type: SQLTypes = "SQLite",
host: str = "localhost", host: str = "localhost",
username: str = "root", username: str = "root",
@@ -140,7 +141,7 @@ class Patcher:
# Assume it's a filepath - existing or not. # Assume it's a filepath - existing or not.
pass pass
self.schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(self.file.schema_identifier) self.schema = ifcopenshell.schema_by_name(self.file.schema_identifier)
if self.sql_type == "sqlite": if self.sql_type == "sqlite":
self.db = sqlite3.connect(database) self.db = sqlite3.connect(database)
@@ -278,6 +279,8 @@ class Patcher:
PRIMARY KEY (`ifc_id`) PRIMARY KEY (`ifc_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
""" """
else:
assert False
self.c.execute(statement) self.c.execute(statement)
def create_metadata(self) -> None: def create_metadata(self) -> None:
@@ -353,6 +356,7 @@ class Patcher:
else: else:
statement += "ifc_id INTEGER PRIMARY KEY NOT NULL UNIQUE" statement += "ifc_id INTEGER PRIMARY KEY NOT NULL UNIQUE"
assert isinstance(declaration, ifcopenshell.ifcopenshell_wrapper.entity)
total_attributes = declaration.attribute_count() total_attributes = declaration.attribute_count()
if total_attributes: if total_attributes:
@@ -393,6 +397,7 @@ class Patcher:
statement = f"CREATE TABLE IF NOT EXISTS {ifc_class} (" statement = f"CREATE TABLE IF NOT EXISTS {ifc_class} ("
statement += "`ifc_id` int(10) unsigned NOT NULL," statement += "`ifc_id` int(10) unsigned NOT NULL,"
assert isinstance(declaration, ifcopenshell.ifcopenshell_wrapper.entity)
derived = declaration.derived() derived = declaration.derived()
for attribute in declaration.all_attributes(): for attribute in declaration.all_attributes():
primitive = ifcopenshell.util.attribute.get_primitive_type(attribute) primitive = ifcopenshell.util.attribute.get_primitive_type(attribute)
@@ -434,13 +439,13 @@ class Patcher:
def insert_data(self, ifc_class: str) -> None: def insert_data(self, ifc_class: str) -> None:
elements = self.file.by_type(ifc_class, include_subtypes=False) elements = self.file.by_type(ifc_class, include_subtypes=False)
rows = [] rows: list[Any] = []
id_map_rows = [] id_map_rows: list[tuple[int, str]] = []
pset_rows = [] pset_rows: list[tuple[int, str, str, Any]] = []
for element in elements: for element in elements:
nested_indices = [] nested_indices: list[int] = []
values = [element.id()] values: list[Any] = [element.id()]
for i, attribute in enumerate(element): for i, attribute in enumerate(element):
if isinstance(attribute, ifcopenshell.entity_instance): if isinstance(attribute, ifcopenshell.entity_instance):
if attribute.id(): if attribute.id():
@@ -473,7 +478,7 @@ class Patcher:
else: else:
rows.append(values) rows.append(values)
id_map_rows.append([element.id(), ifc_class]) id_map_rows.append((element.id(), ifc_class))
if self.should_get_psets: if self.should_get_psets:
psets = ifcopenshell.util.element.get_psets(element) psets = ifcopenshell.util.element.get_psets(element)
@@ -483,7 +488,7 @@ class Patcher:
continue continue
if isinstance(value, list): if isinstance(value, list):
value = json.dumps(value) value = json.dumps(value)
pset_rows.append([element.id(), pset_name, prop_name, value]) pset_rows.append((element.id(), pset_name, prop_name, value))
if self.should_get_geometry: if self.should_get_geometry:
if element.id() not in self.shape_rows and (placement := getattr(element, "ObjectPlacement", None)): if element.id() not in self.shape_rows and (placement := getattr(element, "ObjectPlacement", None)):