Skip to content

Commit

Permalink
Remove need for os import (#185)
Browse files Browse the repository at this point in the history
* removed os.path and os.mkdir

* format

* defined folder

* passing str to exportStep

* format

* corrected argmument name
  • Loading branch information
shimwell authored May 22, 2024
1 parent 7207755 commit cafe1a7
Showing 1 changed file with 25 additions and 29 deletions.
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 @@ -446,15 +445,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[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 @@ -463,23 +462,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 @@ -554,7 +550,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 @@ -774,13 +770,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 @@ -791,22 +787,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

0 comments on commit cafe1a7

Please sign in to comment.