Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove need for os import #185

Merged
merged 7 commits into from
May 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 25 additions & 29 deletions src/geouned/GEOUNED/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import logging
import typing
from datetime import datetime
from os import mkdir, path
from pathlib import Path
from typing import get_type_hints
from importlib.metadata import version
Expand Down Expand Up @@ -440,15 +439,15 @@ def set(self, kwrd, value):

def _load_step_file(
self,
step_file: str,
filename: str,
# TODO consider having discrete indexes (1,5,7) instead of range (1,7) as this offers more flexibility to the user
cell_range: typing.Union[type(None), typing.Tuple[int, int]] = None,
):
"""
Load STEP file(s) and extract solid volumes and enclosure volumes.

Args:
step_file (str): The path to the STEP file or a list of paths to multiple STEP files.
filename (str): The path to the STEP file or a list of paths to multiple STEP files.
cell_range (tuple[int, int], optional): A tuple representing the range of solids to select from the original STEP solids. Defaults to None.

Returns:
Expand All @@ -457,23 +456,20 @@ def _load_step_file(

logger.info("Start of step file loading phase")

if isinstance(step_file, (tuple, list)):
for stp in step_file:
if not path.isfile(stp):
raise FileNotFoundError(f"Step file {stp} not found.\nStop.")
if isinstance(filename, (list, tuple)):
step_files = filename
else:
if not path.isfile(step_file):
raise FileNotFoundError(f"Step file {step_file} not found.\nStop.")
step_files = [filename]

for step_file in step_files:
if not Path(step_file).is_file():
raise FileNotFoundError(f"Step file {step_file} not found.")

if isinstance(step_file, (list, tuple)):
step_files = step_file
else:
step_files = [step_file]
MetaChunk = []
EnclosureChunk = []
for stp in tqdm(step_files, desc="Loading CAD files"):
logger.info(f"read step file : {stp}")
Meta, Enclosure = Load.load_cad(stp, self.settings, self.options)
for step_file in tqdm(step_files, desc="Loading CAD files"):
logger.info(f"read step file : {step_file}")
Meta, Enclosure = Load.load_cad(step_file, self.settings, self.options)
MetaChunk.append(Meta)
EnclosureChunk.append(Enclosure)
self.meta_list = join_meta_lists(MetaChunk)
Expand Down Expand Up @@ -510,7 +506,7 @@ def start(self):
startTime = datetime.now()

# sets the self.meta_list and self.enclosure_list
self._load_step_file(step_file=self.stepFile, cell_range=self.settings.cellRange)
self._load_step_file(filename=self.stepFile, cell_range=self.settings.cellRange)

if self.settings.exportSolids:
self._export_solids(filename=self.settings.exportSolids)
Expand Down Expand Up @@ -733,13 +729,13 @@ def _decompose_solids(self, meta: bool):
continue
logger.info(f"Decomposing solid: {i + 1}/{totsolid}")
if self.settings.debug:
debug_output_folder = Path("debug")
logger.info(m.Comments)
if not path.exists("debug"):
mkdir("debug")
debug_output_folder.mkdir(parents=True, exist_ok=True)
if m.IsEnclosure:
m.Solids[0].exportStep(f"debug/origEnclosure_{i}.stp")
m.Solids[0].exportStep(str(debug_output_folder / f"origEnclosure_{i}.stp"))
else:
m.Solids[0].exportStep(f"debug/origSolid_{i}.stp")
m.Solids[0].exportStep(str(debug_output_folder / f"origSolid_{i}.stp"))

comsolid, err = Decom.SplitSolid(
Part.makeCompound(m.Solids),
Expand All @@ -750,22 +746,22 @@ def _decompose_solids(self, meta: bool):
)

if err != 0:
if not path.exists("Suspicious_solids"):
mkdir("Suspicious_solids")
sus_output_folder = Path("suspicious_solids")
sus_output_folder.mkdir(parents=True, exist_ok=True)
if m.IsEnclosure:
Part.CompSolid(m.Solids).exportStep(f"Suspicious_solids/Enclosure_original_{i}.stp")
comsolid.exportStep(f"Suspicious_solids/Enclosure_split_{i}.stp")
Part.CompSolid(m.Solids).exportStep(str(sus_output_folder / f"Enclosure_original_{i}.stp"))
comsolid.exportStep(str(sus_output_folder / f"Enclosure_split_{i}.stp"))
else:
Part.CompSolid(m.Solids).exportStep(f"Suspicious_solids/Solid_original_{i}.stp")
comsolid.exportStep(f"Suspicious_solids/Solid_split_{i}.stp")
Part.CompSolid(m.Solids).exportStep(str(sus_output_folder / f"Solid_original_{i}.stp"))
comsolid.exportStep(str(sus_output_folder / f"Solid_split_{i}.stp"))

warningSolids.append(i)

if self.settings.debug:
if m.IsEnclosure:
comsolid.exportStep(f"debug/compEnclosure_{i}.stp")
comsolid.exportStep(str(debug_output_folder / f"compEnclosure_{i}.stp"))
else:
comsolid.exportStep(f"debug/compSolid_{i}.stp")
comsolid.exportStep(str(debug_output_folder / f"compSolid_{i}.stp"))
self.Surfaces.extend(
Decom.extract_surfaces(
comsolid,
Expand Down