mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 09:48:32 +00:00
Geometry serialization (#71)
Serialize geometry to IFC instances directly from a TopoDS_Shape
This commit is contained in:
@@ -21,6 +21,7 @@ import os
|
||||
import sys
|
||||
|
||||
from .. import ifcopenshell_wrapper
|
||||
from ..entity_instance import entity_instance
|
||||
|
||||
def has_occ():
|
||||
try: import OCC.BRepTools
|
||||
@@ -82,5 +83,19 @@ def iterate(settings, filename):
|
||||
while True:
|
||||
yield it.get()
|
||||
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)
|
||||
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)
|
||||
return entity_instance_or_none(fn(string_or_shape, *args))
|
||||
else:
|
||||
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)
|
||||
|
||||
@@ -180,7 +180,12 @@ def get_bounding_box_center(bbox):
|
||||
bbmin[0], bbmin[1], bbmin[2], bbmax[0], bbmax[1], bbmax[2] = bbox.Get()
|
||||
return OCC.gp.gp_Pnt(*map(lambda xy: (xy[0]+xy[1])/2., zip(bbmin, bbmax)))
|
||||
|
||||
|
||||
|
||||
def serialize_shape(shape):
|
||||
shapes = OCC.BRepTools.BRepTools_ShapeSet()
|
||||
shapes.Add(shape)
|
||||
return shapes.WriteToString()
|
||||
|
||||
def create_shape_from_serialization(brep_object):
|
||||
import OCC.BRepTools
|
||||
|
||||
|
||||
Reference in New Issue
Block a user