autopep8 --in-place --recursive  --max-line-length=200 ifcopenshell
This commit is contained in:
thorade
2017-11-06 09:10:28 +01:00
committed by Thomas Krijnen
parent c357ab2c69
commit 80360c278d
9 changed files with 285 additions and 211 deletions
@@ -28,23 +28,34 @@ from .. import ifcopenshell_wrapper
from ..file import file
from ..entity_instance import entity_instance
def has_occ():
try: import OCC.BRepTools
except: return False
try:
import OCC.BRepTools
except:
return False
return True
has_occ = has_occ()
wrap_shape_creation = lambda settings, shape: shape
def wrap_shape_creation(settings, shape): return shape
if has_occ:
from . import occ_utils as utils
wrap_shape_creation = lambda settings, shape: utils.create_shape_from_serialization(shape) if getattr(settings, 'use_python_opencascade', False) else shape
def wrap_shape_creation(settings, shape): return utils.create_shape_from_serialization(shape) if getattr(settings, 'use_python_opencascade', False) else shape
# Subclass the settings module to provide an additional
# setting to enable pythonOCC when available
class settings(ifcopenshell_wrapper.settings):
if has_occ:
USE_PYTHON_OPENCASCADE = -1
def set(self, *args):
setting, value = args
if setting == settings.USE_PYTHON_OPENCASCADE:
@@ -54,11 +65,12 @@ class settings(ifcopenshell_wrapper.settings):
self.use_python_opencascade = value
else:
ifcopenshell_wrapper.settings.set(self, *args)
# Hide templating precision to the user by choosing based on Python's
# Hide templating precision to the user by choosing based on Python's
# internal float type. This is probably always going to be a double.
for ty in (ifcopenshell_wrapper.iterator_single_precision, ifcopenshell_wrapper.iterator_double_precision):
if ty.mantissa_size() == sys.float_info.mant_dig:
if ty.mantissa_size() == sys.float_info.mant_dig:
_iterator = ty
@@ -77,18 +89,18 @@ class iterator(_iterator):
class tree(ifcopenshell_wrapper.tree):
def __init__(self, file=None, settings=None):
args = [self]
if file is not None:
if file is not None:
args.append(file.wrapped_data)
if settings is not None:
args.append(settings)
ifcopenshell_wrapper.tree.__init__(*args)
def add_file(self, file, settings):
ifcopenshell_wrapper.tree.add_file(self, file.wrapped_data, settings)
def select(self, value, **kwargs):
def unwrap(value):
if isinstance(value, entity_instance):
@@ -104,7 +116,7 @@ class tree(ifcopenshell_wrapper.tree):
if isinstance(value, OCC.TopoDS.TopoDS_Shape):
args[1] = utils.serialize_shape(value)
return [entity_instance(e) for e in ifcopenshell_wrapper.tree.select(*args)]
def select_box(self, value, **kwargs):
def unwrap(value):
if isinstance(value, entity_instance):
@@ -120,14 +132,14 @@ class tree(ifcopenshell_wrapper.tree):
return [entity_instance(e) for e in ifcopenshell_wrapper.tree.select_box(*args)]
def create_shape(settings, inst, repr=None):
def create_shape(settings, inst, repr=None):
return wrap_shape_creation(
settings,
ifcopenshell_wrapper.create_shape(
settings,
settings,
inst.wrapped_data,
repr.wrapped_data if repr is not None else None
))
))
def iterate(settings, filename):
@@ -135,12 +147,15 @@ def iterate(settings, filename):
if it.initialize():
while True:
yield it.get()
if not it.next(): break
if not it.next():
break
def make_shape_function(fn):
entity_instance_or_none = lambda e: None if e is None else entity_instance(e)
def entity_instance_or_none(e): return None if e is None else entity_instance(e)
if has_occ:
import OCC.TopoDS
def _(string_or_shape, *args):
if isinstance(string_or_shape, OCC.TopoDS.TopoDS_Shape):
string_or_shape = utils.serialize_shape(string_or_shape)
@@ -149,6 +164,7 @@ def make_shape_function(fn):
def _(string, *args):
return entity_instance_or_none(fn(string, *args))
return _
serialise = make_shape_function(ifcopenshell_wrapper.serialise)
tesselate = make_shape_function(ifcopenshell_wrapper.tesselate)