Skip to content

Commit

Permalink
Add .step files handler, create base NURBS class, change tests (#101)
Browse files Browse the repository at this point in the history
* Add .step files handler, create base NURBS class, change tests (#101)

* Fix documentation, move extensions list from class to self

* Fix tests
  • Loading branch information
maciekgroch authored and mtezzele committed Nov 26, 2016
1 parent 77fd59c commit ad8626c
Show file tree
Hide file tree
Showing 23 changed files with 5,077 additions and 398 deletions.
15 changes: 9 additions & 6 deletions pygem/__init__.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
__all__ = [
'affine', 'filehandler', 'freeform', 'radial', 'openfhandler', 'params',
'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utils', 'gui'
'stlhandler', 'unvhandler', 'vtkhandler', 'nurbshandler', 'stephandler',
'igeshandler', 'utils', 'gui'
]

from . import affine
from . import freeform
from . import radial
from . import filehandler
from . import freeform
from . import gui
from . import igeshandler
from . import nurbshandler
from . import openfhandler
from . import params
from . import radial
from . import stephandler
from . import stlhandler
from . import unvhandler
from . import vtkhandler
from . import igeshandler
from . import utils
from . import gui
from . import vtkhandler
28 changes: 14 additions & 14 deletions pygem/filehandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ class FileHandler(object):
:cvar string infile: name of the input file to be processed.
:cvar string outfile: name of the output file where to write in.
:cvar string extension: extension of the input/output files. It is specific for each
:cvar list extensions: extensions of the input/output files. It is specific for each
subclass.
"""

def __init__(self):
self.infile = None
self.outfile = None
self.extension = None
self.extensions = []

def parse(self, *args):
"""
Abstract method to parse a specific file.
Not implemented, it has to be implemented in subclasses.
"""
raise NotImplementedError("Subclass must implement abstract method " \
raise NotImplementedError(
"Subclass must implement abstract method " \
+ self.__class__.__name__ + ".parse")

def write(self, *args):
Expand All @@ -34,21 +35,22 @@ def write(self, *args):
Not implemented, it has to be implemented in subclasses.
"""
raise NotImplementedError("Subclass must implement abstract method " \
+ self.__class__.__name__ + ".write")
raise NotImplementedError(
"Subclass must implement abstract method " \
+ self.__class__.__name__ + ".write")

def _check_extension(self, filename):
"""
This private method checks if the given `filename` has the proper `extension` set
This private class method checks if the given `filename` has the proper `extension` set
in the child class. If not it raises a ValueError.
:param string filename: file to check.
"""
__, file_ext = os.path.splitext(filename)
if not file_ext in self.extension:
if file_ext not in self.extensions:
raise ValueError(
'The input file does not have the proper extension. \
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extension)
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extensions)
)

@staticmethod
Expand All @@ -63,16 +65,14 @@ def _check_filename_type(filename):
'The given filename ({0!s}) must be a string'.format(filename)
)

@staticmethod
def _check_infile_instantiation(infile):
def _check_infile_instantiation(self):
"""
This private static method checks if the input file `infile` is instantiated. If not it means
that nobody called the parse method, i.e. `self.infile` is None. If the check fails
This private method checks if `self.infile` is instantiated. If not it means
that nobody called the parse method and `self.infile` is None. If the check fails
it raises a RuntimeError.
:param string infile: file to check.
"""
if not infile:
if not self.infile:
raise RuntimeError(
"You can not write a file without having parsed one."
)
18 changes: 11 additions & 7 deletions pygem/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _chose_geometry(self):
"""
self.filename_geometry = askopenfilename(filetypes=[("IGES File", ('*.iges', '*.igs')), \
("OpenFOAM File", '*'), ('STL File', '*.stl'), ('UNV File', '*.unv'), \
('VTK File', '*.vtk'), ('All', '*')])
('VTK File', '*.vtk'), ('STEP File', ('*.step, *.stp')) ('All', '*')])
self.print_geometry_path.set(self.filename_geometry)
self.label_geo.configure(fg='green')

Expand All @@ -97,12 +97,16 @@ def _run_simulation(self):
params.read_parameters(filename=self.filename_parameters)

file_extension_in = os.path.splitext(self.filename_geometry)[-1]
ext_handlers = {'.stl': pg.stlhandler.StlHandler(), \
'.iges': pg.igeshandler.IgesHandler(), \
'.igs': pg.igeshandler.IgesHandler(), \
'.unv': pg.unvhandler.UnvHandler(), \
'': pg.openfhandler.OpenFoamHandler(), \
'.vtk': pg.vtkhandler.VtkHandler()}
ext_handlers = {
'.stl': pg.stlhandler.StlHandler(),
'.iges': pg.igeshandler.IgesHandler(),
'.igs': pg.igeshandler.IgesHandler(),
'.unv': pg.unvhandler.UnvHandler(),
'': pg.openfhandler.OpenFoamHandler(),
'.vtk': pg.vtkhandler.VtkHandler(),
'.stp': pg.stephandler.StepHandler(),
'.step': pg.stephandler.StepHandler(),
}

if file_extension_in in ext_handlers:
geo_handler = ext_handlers[file_extension_in]
Expand Down
Loading

0 comments on commit ad8626c

Please sign in to comment.