Skip to content

Commit ad8626c

Browse files
maciekgrochmtezzele
authored andcommitted
Add .step files handler, create base NURBS class, change tests (#101)
* Add .step files handler, create base NURBS class, change tests (#101) * Fix documentation, move extensions list from class to self * Fix tests
1 parent 77fd59c commit ad8626c

23 files changed

+5077
-398
lines changed

pygem/__init__.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
__all__ = [
22
'affine', 'filehandler', 'freeform', 'radial', 'openfhandler', 'params',
3-
'stlhandler', 'unvhandler', 'vtkhandler', 'igeshandler', 'utils', 'gui'
3+
'stlhandler', 'unvhandler', 'vtkhandler', 'nurbshandler', 'stephandler',
4+
'igeshandler', 'utils', 'gui'
45
]
56

67
from . import affine
7-
from . import freeform
8-
from . import radial
98
from . import filehandler
9+
from . import freeform
10+
from . import gui
11+
from . import igeshandler
12+
from . import nurbshandler
1013
from . import openfhandler
1114
from . import params
15+
from . import radial
16+
from . import stephandler
1217
from . import stlhandler
1318
from . import unvhandler
14-
from . import vtkhandler
15-
from . import igeshandler
1619
from . import utils
17-
from . import gui
20+
from . import vtkhandler

pygem/filehandler.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,23 @@ class FileHandler(object):
1010
1111
:cvar string infile: name of the input file to be processed.
1212
:cvar string outfile: name of the output file where to write in.
13-
:cvar string extension: extension of the input/output files. It is specific for each
13+
:cvar list extensions: extensions of the input/output files. It is specific for each
1414
subclass.
1515
"""
1616

1717
def __init__(self):
1818
self.infile = None
1919
self.outfile = None
20-
self.extension = None
20+
self.extensions = []
2121

2222
def parse(self, *args):
2323
"""
2424
Abstract method to parse a specific file.
2525
2626
Not implemented, it has to be implemented in subclasses.
2727
"""
28-
raise NotImplementedError("Subclass must implement abstract method " \
28+
raise NotImplementedError(
29+
"Subclass must implement abstract method " \
2930
+ self.__class__.__name__ + ".parse")
3031

3132
def write(self, *args):
@@ -34,21 +35,22 @@ def write(self, *args):
3435
3536
Not implemented, it has to be implemented in subclasses.
3637
"""
37-
raise NotImplementedError("Subclass must implement abstract method " \
38-
+ self.__class__.__name__ + ".write")
38+
raise NotImplementedError(
39+
"Subclass must implement abstract method " \
40+
+ self.__class__.__name__ + ".write")
3941

4042
def _check_extension(self, filename):
4143
"""
42-
This private method checks if the given `filename` has the proper `extension` set
44+
This private class method checks if the given `filename` has the proper `extension` set
4345
in the child class. If not it raises a ValueError.
4446
4547
:param string filename: file to check.
4648
"""
4749
__, file_ext = os.path.splitext(filename)
48-
if not file_ext in self.extension:
50+
if file_ext not in self.extensions:
4951
raise ValueError(
5052
'The input file does not have the proper extension. \
51-
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extension)
53+
It is {0!s}, instead of {1!s}.'.format(file_ext, self.extensions)
5254
)
5355

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

66-
@staticmethod
67-
def _check_infile_instantiation(infile):
68+
def _check_infile_instantiation(self):
6869
"""
69-
This private static method checks if the input file `infile` is instantiated. If not it means
70-
that nobody called the parse method, i.e. `self.infile` is None. If the check fails
70+
This private method checks if `self.infile` is instantiated. If not it means
71+
that nobody called the parse method and `self.infile` is None. If the check fails
7172
it raises a RuntimeError.
7273
73-
:param string infile: file to check.
7474
"""
75-
if not infile:
75+
if not self.infile:
7676
raise RuntimeError(
7777
"You can not write a file without having parsed one."
7878
)

pygem/gui.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _chose_geometry(self):
7373
"""
7474
self.filename_geometry = askopenfilename(filetypes=[("IGES File", ('*.iges', '*.igs')), \
7575
("OpenFOAM File", '*'), ('STL File', '*.stl'), ('UNV File', '*.unv'), \
76-
('VTK File', '*.vtk'), ('All', '*')])
76+
('VTK File', '*.vtk'), ('STEP File', ('*.step, *.stp')) ('All', '*')])
7777
self.print_geometry_path.set(self.filename_geometry)
7878
self.label_geo.configure(fg='green')
7979

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

9999
file_extension_in = os.path.splitext(self.filename_geometry)[-1]
100-
ext_handlers = {'.stl': pg.stlhandler.StlHandler(), \
101-
'.iges': pg.igeshandler.IgesHandler(), \
102-
'.igs': pg.igeshandler.IgesHandler(), \
103-
'.unv': pg.unvhandler.UnvHandler(), \
104-
'': pg.openfhandler.OpenFoamHandler(), \
105-
'.vtk': pg.vtkhandler.VtkHandler()}
100+
ext_handlers = {
101+
'.stl': pg.stlhandler.StlHandler(),
102+
'.iges': pg.igeshandler.IgesHandler(),
103+
'.igs': pg.igeshandler.IgesHandler(),
104+
'.unv': pg.unvhandler.UnvHandler(),
105+
'': pg.openfhandler.OpenFoamHandler(),
106+
'.vtk': pg.vtkhandler.VtkHandler(),
107+
'.stp': pg.stephandler.StepHandler(),
108+
'.step': pg.stephandler.StepHandler(),
109+
}
106110

107111
if file_extension_in in ext_handlers:
108112
geo_handler = ext_handlers[file_extension_in]

0 commit comments

Comments
 (0)