mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-16 21:42:19 +00:00
Unify usage of spaces in Python library code
This commit is contained in:
@@ -24,35 +24,35 @@ import sys
|
|||||||
import platform
|
import platform
|
||||||
|
|
||||||
python_distribution = os.path.join(platform.system().lower(),
|
python_distribution = os.path.join(platform.system().lower(),
|
||||||
platform.architecture()[0],
|
platform.architecture()[0],
|
||||||
'python%s.%s' % platform.python_version_tuple()[:2])
|
'python%s.%s' % platform.python_version_tuple()[:2])
|
||||||
sys.path.append(os.path.abspath(os.path.join(
|
sys.path.append(os.path.abspath(os.path.join(
|
||||||
os.path.dirname(__file__),
|
os.path.dirname(__file__),
|
||||||
'lib', python_distribution)))
|
'lib', python_distribution)))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from . import ifcopenshell_wrapper
|
from . import ifcopenshell_wrapper
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
if int(platform.python_version_tuple()[0]) == 2:
|
if int(platform.python_version_tuple()[0]) == 2:
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
print('-' * 64)
|
print('-' * 64)
|
||||||
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)
|
raise ImportError("IfcOpenShell not built for '%s'" % python_distribution)
|
||||||
|
|
||||||
from . import guid
|
from . import guid
|
||||||
from .file import file
|
from .file import file
|
||||||
from .entity_instance import entity_instance
|
from .entity_instance import entity_instance
|
||||||
|
|
||||||
def open(fn=None):
|
def open(fn=None):
|
||||||
return file(ifcopenshell_wrapper.open(os.path.abspath(fn))) if fn else file()
|
return file(ifcopenshell_wrapper.open(os.path.abspath(fn))) if fn else file()
|
||||||
|
|
||||||
|
|
||||||
def create_entity(type,*args,**kwargs):
|
def create_entity(type,*args,**kwargs):
|
||||||
e = entity_instance(ifcopenshell_wrapper.entity_instance(type))
|
e = entity_instance(ifcopenshell_wrapper.entity_instance(type))
|
||||||
attrs = list(enumerate(args)) + \
|
attrs = list(enumerate(args)) + \
|
||||||
[(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
[(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
||||||
for idx, arg in attrs: e[idx] = arg
|
for idx, arg in attrs: e[idx] = arg
|
||||||
return e
|
return e
|
||||||
|
|
||||||
|
|
||||||
version = ifcopenshell_wrapper.version()
|
version = ifcopenshell_wrapper.version()
|
||||||
|
|||||||
@@ -24,64 +24,64 @@ import itertools
|
|||||||
from . import ifcopenshell_wrapper
|
from . import ifcopenshell_wrapper
|
||||||
|
|
||||||
class entity_instance(object):
|
class entity_instance(object):
|
||||||
def __init__(self, e):
|
def __init__(self, e):
|
||||||
super(entity_instance, self).__setattr__('wrapped_data', e)
|
super(entity_instance, self).__setattr__('wrapped_data', e)
|
||||||
def __getattr__(self, name):
|
def __getattr__(self, name):
|
||||||
INVALID, FORWARD, INVERSE = range(3)
|
INVALID, FORWARD, INVERSE = range(3)
|
||||||
attr_cat = self.wrapped_data.get_attribute_category(name)
|
attr_cat = self.wrapped_data.get_attribute_category(name)
|
||||||
if attr_cat == FORWARD:
|
if attr_cat == FORWARD:
|
||||||
return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name)))
|
return entity_instance.wrap_value(self.wrapped_data.get_argument(self.wrapped_data.get_argument_index(name)))
|
||||||
elif attr_cat == INVERSE:
|
elif attr_cat == INVERSE:
|
||||||
return entity_instance.wrap_value(self.wrapped_data.get_inverse(name))
|
return entity_instance.wrap_value(self.wrapped_data.get_inverse(name))
|
||||||
else: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name))
|
else: raise AttributeError("entity instance of type '%s' has no attribute '%s'"%(self.wrapped_data.is_a(), name))
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def walk(f, g, value):
|
def walk(f, g, value):
|
||||||
if isinstance(value, (tuple, list)): return tuple(map(functools.partial(entity_instance.walk, f, g), value))
|
if isinstance(value, (tuple, list)): return tuple(map(functools.partial(entity_instance.walk, f, g), value))
|
||||||
elif f(value): return g(value)
|
elif f(value): return g(value)
|
||||||
else: return value
|
else: return value
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def wrap_value(v):
|
def wrap_value(v):
|
||||||
wrap = lambda e: entity_instance(e)
|
wrap = lambda e: entity_instance(e)
|
||||||
is_instance = lambda e: isinstance(e, ifcopenshell_wrapper.entity_instance)
|
is_instance = lambda e: isinstance(e, ifcopenshell_wrapper.entity_instance)
|
||||||
return entity_instance.walk(is_instance, wrap, v)
|
return entity_instance.walk(is_instance, wrap, v)
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def unwrap_value(v):
|
def unwrap_value(v):
|
||||||
unwrap = lambda e: e.wrapped_data
|
unwrap = lambda e: e.wrapped_data
|
||||||
is_instance = lambda e: isinstance(e, entity_instance)
|
is_instance = lambda e: isinstance(e, entity_instance)
|
||||||
return entity_instance.walk(is_instance, unwrap, v)
|
return entity_instance.walk(is_instance, unwrap, v)
|
||||||
def attribute_type(self, attr):
|
def attribute_type(self, attr):
|
||||||
attr_idx = attr if isinstance(attr, numbers.Integral) else self.wrapped_data.get_argument_index(attr)
|
attr_idx = attr if isinstance(attr, numbers.Integral) else self.wrapped_data.get_argument_index(attr)
|
||||||
return self.wrapped_data.get_argument_type(attr_idx)
|
return self.wrapped_data.get_argument_type(attr_idx)
|
||||||
def attribute_name(self, attr_idx):
|
def attribute_name(self, attr_idx):
|
||||||
return self.wrapped_data.get_argument_name(attr_idx)
|
return self.wrapped_data.get_argument_name(attr_idx)
|
||||||
def __setattr__(self, key, value):
|
def __setattr__(self, key, value):
|
||||||
self[self.wrapped_data.get_argument_index(key)] = value
|
self[self.wrapped_data.get_argument_index(key)] = value
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
return entity_instance.wrap_value(self.wrapped_data.get_argument(key))
|
return entity_instance.wrap_value(self.wrapped_data.get_argument(key))
|
||||||
def __setitem__(self, idx, value):
|
def __setitem__(self, idx, value):
|
||||||
if value is None:
|
if value is None:
|
||||||
self.wrapped_data.setArgumentAsNull(idx)
|
self.wrapped_data.setArgumentAsNull(idx)
|
||||||
else:
|
else:
|
||||||
attr_type = self.attribute_type(idx).title().replace(' ', '')
|
attr_type = self.attribute_type(idx).title().replace(' ', '')
|
||||||
attr_type = attr_type.replace('Binary', 'String')
|
attr_type = attr_type.replace('Binary', 'String')
|
||||||
attr_type = attr_type.replace('Enumeration', 'String')
|
attr_type = attr_type.replace('Enumeration', 'String')
|
||||||
try:
|
try:
|
||||||
if isinstance(value, unicode): value = value.encode("utf-8")
|
if isinstance(value, unicode): value = value.encode("utf-8")
|
||||||
except: pass
|
except: pass
|
||||||
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
|
getattr(self.wrapped_data, "setArgumentAs%s" % attr_type)(idx, entity_instance.unwrap_value(value))
|
||||||
return value
|
return value
|
||||||
def __len__(self): return len(self.wrapped_data)
|
def __len__(self): return len(self.wrapped_data)
|
||||||
def __repr__(self): return repr(self.wrapped_data)
|
def __repr__(self): return repr(self.wrapped_data)
|
||||||
def is_a(self, *args): return self.wrapped_data.is_a(*args)
|
def is_a(self, *args): return self.wrapped_data.is_a(*args)
|
||||||
def id(self): return self.wrapped_data.id()
|
def id(self): return self.wrapped_data.id()
|
||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if type(self) != type(other): return False
|
if type(self) != type(other): return False
|
||||||
return self.wrapped_data == other.wrapped_data
|
return self.wrapped_data == other.wrapped_data
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
return hash((self.id(), self.wrapped_data.file_pointer()))
|
return hash((self.id(), self.wrapped_data.file_pointer()))
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
return sorted(set(itertools.chain(
|
return sorted(set(itertools.chain(
|
||||||
dir(type(self)),
|
dir(type(self)),
|
||||||
self.wrapped_data.get_attribute_names(),
|
self.wrapped_data.get_attribute_names(),
|
||||||
self.wrapped_data.get_inverse_attribute_names()
|
self.wrapped_data.get_inverse_attribute_names()
|
||||||
)))
|
)))
|
||||||
|
|||||||
@@ -24,38 +24,38 @@ from . import ifcopenshell_wrapper
|
|||||||
from .entity_instance import entity_instance
|
from .entity_instance import entity_instance
|
||||||
|
|
||||||
class file(object):
|
class file(object):
|
||||||
def __init__(self, f=None):
|
def __init__(self, f=None):
|
||||||
self.wrapped_data = f or ifcopenshell_wrapper.file(True)
|
self.wrapped_data = f or ifcopenshell_wrapper.file(True)
|
||||||
def create_entity(self,type,*args,**kwargs):
|
def create_entity(self,type,*args,**kwargs):
|
||||||
e = entity_instance(ifcopenshell_wrapper.entity_instance(type))
|
e = entity_instance(ifcopenshell_wrapper.entity_instance(type))
|
||||||
attrs = list(enumerate(args)) + \
|
attrs = list(enumerate(args)) + \
|
||||||
[(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
[(e.wrapped_data.get_argument_index(name), arg) for name, arg in kwargs.items()]
|
||||||
for idx, arg in attrs: e[idx] = arg
|
for idx, arg in attrs: e[idx] = arg
|
||||||
self.wrapped_data.add(e.wrapped_data)
|
self.wrapped_data.add(e.wrapped_data)
|
||||||
e.wrapped_data.this.disown()
|
e.wrapped_data.this.disown()
|
||||||
return e
|
return e
|
||||||
def __getattr__(self, attr):
|
def __getattr__(self, attr):
|
||||||
if attr[0:6] == 'create': return functools.partial(self.create_entity,attr[6:])
|
if attr[0:6] == 'create': return functools.partial(self.create_entity,attr[6:])
|
||||||
else: return getattr(self.wrapped_data, attr)
|
else: return getattr(self.wrapped_data, attr)
|
||||||
def __getitem__(self, key):
|
def __getitem__(self, key):
|
||||||
if isinstance(key, numbers.Integral):
|
if isinstance(key, numbers.Integral):
|
||||||
return entity_instance(self.wrapped_data.by_id(key))
|
return entity_instance(self.wrapped_data.by_id(key))
|
||||||
elif isinstance(key, str):
|
elif isinstance(key, str):
|
||||||
return entity_instance(self.wrapped_data.by_guid(key))
|
return entity_instance(self.wrapped_data.by_guid(key))
|
||||||
def by_id(self, id): return self[id]
|
def by_id(self, id): return self[id]
|
||||||
def by_guid(self, guid): return self[guid]
|
def by_guid(self, guid): return self[guid]
|
||||||
def add(self, inst):
|
def add(self, inst):
|
||||||
inst.wrapped_data.this.disown()
|
inst.wrapped_data.this.disown()
|
||||||
return entity_instance(self.wrapped_data.add(inst.wrapped_data))
|
return entity_instance(self.wrapped_data.add(inst.wrapped_data))
|
||||||
def by_type(self, type):
|
def by_type(self, type):
|
||||||
return [entity_instance(e) for e in self.wrapped_data.by_type(type)]
|
return [entity_instance(e) for e in self.wrapped_data.by_type(type)]
|
||||||
def traverse(self, inst, max_levels=None):
|
def traverse(self, inst, max_levels=None):
|
||||||
if max_levels is None:
|
if max_levels is None:
|
||||||
max_levels = -1
|
max_levels = -1
|
||||||
return [entity_instance(e) for e in self.wrapped_data.traverse(inst.wrapped_data, max_levels)]
|
return [entity_instance(e) for e in self.wrapped_data.traverse(inst.wrapped_data, max_levels)]
|
||||||
def get_inverse(self, inst):
|
def get_inverse(self, inst):
|
||||||
return [entity_instance(e) for e in self.wrapped_data.get_inverse(inst.wrapped_data)]
|
return [entity_instance(e) for e in self.wrapped_data.get_inverse(inst.wrapped_data)]
|
||||||
def remove(self, inst):
|
def remove(self, inst):
|
||||||
return self.wrapped_data.remove(inst.wrapped_data)
|
return self.wrapped_data.remove(inst.wrapped_data)
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return iter(self[id] for id in self.wrapped_data.entity_names())
|
return iter(self[id] for id in self.wrapped_data.entity_names())
|
||||||
|
|||||||
@@ -30,14 +30,14 @@ DEFAULT_STYLES = {
|
|||||||
"IfcWall" : (.8 , .8, .8 ),
|
"IfcWall" : (.8 , .8, .8 ),
|
||||||
"IfcSite" : (.75, .8, .65 ),
|
"IfcSite" : (.75, .8, .65 ),
|
||||||
"IfcSlab" : (.4 , .4, .4 ),
|
"IfcSlab" : (.4 , .4, .4 ),
|
||||||
"IfcWallStandardCase": (.9 , .9, .9 ),
|
"IfcWallStandardCase": (.9 , .9, .9 ),
|
||||||
"IfcWall" : (.9 , .9, .9 ),
|
"IfcWall" : (.9 , .9, .9 ),
|
||||||
"IfcWindow" : (.75, .8, .75, .3),
|
"IfcWindow" : (.75, .8, .75, .3),
|
||||||
"IfcDoor" : (.55, .3, .15 ),
|
"IfcDoor" : (.55, .3, .15 ),
|
||||||
"IfcBeam" : (.75, .7, .7 ),
|
"IfcBeam" : (.75, .7, .7 ),
|
||||||
"IfcRailing" : (.65, .6, .6 ),
|
"IfcRailing" : (.65, .6, .6 ),
|
||||||
"IfcMember" : (.65, .6, .6 ),
|
"IfcMember" : (.65, .6, .6 ),
|
||||||
"IfcPlate" : (.8 , .8, .8 )
|
"IfcPlate" : (.8 , .8, .8 )
|
||||||
}
|
}
|
||||||
|
|
||||||
def initialize_display():
|
def initialize_display():
|
||||||
|
|||||||
Reference in New Issue
Block a user