mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-20 06:58:56 +00:00
Support for pythonocc-core 7.4.0
This commit is contained in:
committed by
Dion Moult
parent
21a4680811
commit
ab1f7337a5
@@ -5,34 +5,66 @@ import numpy
|
|||||||
import pickle
|
import pickle
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import OCC.gp
|
try:
|
||||||
import OCC.Geom
|
from OCC.Core import (
|
||||||
import OCC.Bnd
|
gp,
|
||||||
import OCC.BRepBndLib
|
Geom,
|
||||||
import OCC.BRep
|
Bnd,
|
||||||
import OCC.BRepPrimAPI
|
BRepBndLib,
|
||||||
import OCC.BRepAlgoAPI
|
BRep,
|
||||||
import OCC.BRepBuilderAPI
|
BRepPrimAPI,
|
||||||
import OCC.TopOpeBRepTool
|
BRepAlgoAPI,
|
||||||
import OCC.TopOpeBRepBuild
|
BRepBuilderAPI,
|
||||||
import OCC.ShapeExtend
|
TopOpeBRepTool,
|
||||||
import OCC.GProp
|
TopOpeBRepBuild,
|
||||||
import OCC.BRepGProp
|
ShapeExtend,
|
||||||
import OCC.GC
|
GProp,
|
||||||
import OCC.ShapeAnalysis
|
BRepGProp,
|
||||||
import OCC.TopTools
|
GC,
|
||||||
import OCC.TopExp
|
ShapeAnalysis,
|
||||||
import OCC.HLRAlgo
|
TopTools,
|
||||||
import OCC.HLRBRep
|
TopExp,
|
||||||
import OCC.TopLoc
|
HLRAlgo,
|
||||||
import OCC.Bnd
|
HLRBRep,
|
||||||
import OCC.BRepBndLib
|
TopLoc,
|
||||||
import OCC.BRepTools
|
Bnd,
|
||||||
import OCC.TopoDS
|
BRepBndLib,
|
||||||
import OCC.GeomLProp
|
BRepTools,
|
||||||
import OCC.IntCurvesFace
|
TopoDS,
|
||||||
|
GeomLProp,
|
||||||
from OCC.TopoDS import topods
|
IntCurvesFace,
|
||||||
|
)
|
||||||
|
from OCC.Core.TopoDS import topods
|
||||||
|
except ImportError:
|
||||||
|
from OCC import (
|
||||||
|
gp,
|
||||||
|
Geom,
|
||||||
|
Bnd,
|
||||||
|
BRepBndLib,
|
||||||
|
BRep,
|
||||||
|
BRepPrimAPI,
|
||||||
|
BRepAlgoAPI,
|
||||||
|
BRepBuilderAPI,
|
||||||
|
TopOpeBRepTool,
|
||||||
|
TopOpeBRepBuild,
|
||||||
|
ShapeExtend,
|
||||||
|
GProp,
|
||||||
|
BRepGProp,
|
||||||
|
GC,
|
||||||
|
ShapeAnalysis,
|
||||||
|
TopTools,
|
||||||
|
TopExp,
|
||||||
|
HLRAlgo,
|
||||||
|
HLRBRep,
|
||||||
|
TopLoc,
|
||||||
|
Bnd,
|
||||||
|
BRepBndLib,
|
||||||
|
BRepTools,
|
||||||
|
TopoDS,
|
||||||
|
GeomLProp,
|
||||||
|
IntCurvesFace,
|
||||||
|
)
|
||||||
|
from OCC.TopoDS import topods
|
||||||
|
|
||||||
import ifcopenshell
|
import ifcopenshell
|
||||||
import ifcopenshell.geom
|
import ifcopenshell.geom
|
||||||
@@ -42,51 +74,51 @@ this_file = os.path.join(cwd, 'cut_ifc.py')
|
|||||||
|
|
||||||
def get_booleaned_edges(shape):
|
def get_booleaned_edges(shape):
|
||||||
edges = []
|
edges = []
|
||||||
exp = OCC.TopExp.TopExp_Explorer(shape, OCC.TopAbs.TopAbs_EDGE)
|
exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE)
|
||||||
while exp.More():
|
while exp.More():
|
||||||
edges.append(topods.Edge(exp.Current()))
|
edges.append(topods.Edge(exp.Current()))
|
||||||
exp.Next()
|
exp.Next()
|
||||||
return edges
|
return edges
|
||||||
|
|
||||||
def connect_edges_into_wires(unconnected_edges):
|
def connect_edges_into_wires(unconnected_edges):
|
||||||
edges = OCC.TopTools.TopTools_HSequenceOfShape()
|
edges = TopTools.TopTools_HSequenceOfShape()
|
||||||
edges_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(edges)
|
edges_handle = TopTools.Handle_TopTools_HSequenceOfShape(edges)
|
||||||
wires = OCC.TopTools.TopTools_HSequenceOfShape()
|
wires = TopTools.TopTools_HSequenceOfShape()
|
||||||
wires_handle = OCC.TopTools.Handle_TopTools_HSequenceOfShape(wires)
|
wires_handle = TopTools.Handle_TopTools_HSequenceOfShape(wires)
|
||||||
|
|
||||||
for edge in unconnected_edges:
|
for edge in unconnected_edges:
|
||||||
edges.Append(edge)
|
edges.Append(edge)
|
||||||
|
|
||||||
OCC.ShapeAnalysis.ShapeAnalysis_FreeBounds.ConnectEdgesToWires(edges_handle, 1e-5, True, wires_handle)
|
ShapeAnalysis.ShapeAnalysis_FreeBounds.ConnectEdgesToWires(edges_handle, 1e-5, True, wires_handle)
|
||||||
return wires_handle.GetObject()
|
return wires_handle.GetObject()
|
||||||
|
|
||||||
def do_cut(process_data):
|
def do_cut(process_data):
|
||||||
global_id, shape, section, trsf_data = process_data
|
global_id, shape, section, trsf_data = process_data
|
||||||
|
|
||||||
axis = OCC.gp.gp_Ax2(
|
axis = gp.gp_Ax2(
|
||||||
OCC.gp.gp_Pnt(
|
gp.gp_Pnt(
|
||||||
trsf_data['top_left_corner'][0],
|
trsf_data['top_left_corner'][0],
|
||||||
trsf_data['top_left_corner'][1],
|
trsf_data['top_left_corner'][1],
|
||||||
trsf_data['top_left_corner'][2]),
|
trsf_data['top_left_corner'][2]),
|
||||||
OCC.gp.gp_Dir(
|
gp.gp_Dir(
|
||||||
trsf_data['projection'][0],
|
trsf_data['projection'][0],
|
||||||
trsf_data['projection'][1],
|
trsf_data['projection'][1],
|
||||||
trsf_data['projection'][2]),
|
trsf_data['projection'][2]),
|
||||||
OCC.gp.gp_Dir(
|
gp.gp_Dir(
|
||||||
trsf_data['x_axis'][0],
|
trsf_data['x_axis'][0],
|
||||||
trsf_data['x_axis'][1],
|
trsf_data['x_axis'][1],
|
||||||
trsf_data['x_axis'][2])
|
trsf_data['x_axis'][2])
|
||||||
)
|
)
|
||||||
source = OCC.gp.gp_Ax3(axis)
|
source = gp.gp_Ax3(axis)
|
||||||
destination = OCC.gp.gp_Ax3(
|
destination = gp.gp_Ax3(
|
||||||
OCC.gp.gp_Pnt(0, 0, 0),
|
gp.gp_Pnt(0, 0, 0),
|
||||||
OCC.gp.gp_Dir(0, 0, -1),
|
gp.gp_Dir(0, 0, -1),
|
||||||
OCC.gp.gp_Dir(1, 0, 0))
|
gp.gp_Dir(1, 0, 0))
|
||||||
transformation = OCC.gp.gp_Trsf()
|
transformation = gp.gp_Trsf()
|
||||||
transformation.SetDisplacement(source, destination)
|
transformation.SetDisplacement(source, destination)
|
||||||
|
|
||||||
cut_polygons = []
|
cut_polygons = []
|
||||||
section = OCC.BRepAlgoAPI.BRepAlgoAPI_Section(section, shape).Shape()
|
section = BRepAlgoAPI.BRepAlgoAPI_Section(section, shape).Shape()
|
||||||
section_edges = get_booleaned_edges(section)
|
section_edges = get_booleaned_edges(section)
|
||||||
if len(section_edges) <= 0:
|
if len(section_edges) <= 0:
|
||||||
return cut_polygons
|
return cut_polygons
|
||||||
@@ -94,17 +126,17 @@ def do_cut(process_data):
|
|||||||
for i in range(wires.Length()):
|
for i in range(wires.Length()):
|
||||||
wire_shape = wires.Value(i+1)
|
wire_shape = wires.Value(i+1)
|
||||||
|
|
||||||
transformed_wire = OCC.BRepBuilderAPI.BRepBuilderAPI_Transform(
|
transformed_wire = BRepBuilderAPI.BRepBuilderAPI_Transform(
|
||||||
wire_shape, transformation)
|
wire_shape, transformation)
|
||||||
wire_shape = transformed_wire.Shape()
|
wire_shape = transformed_wire.Shape()
|
||||||
|
|
||||||
wire = topods.Wire(wire_shape)
|
wire = topods.Wire(wire_shape)
|
||||||
face = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire).Face()
|
face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(wire).Face()
|
||||||
|
|
||||||
points = []
|
points = []
|
||||||
exp = OCC.BRepTools.BRepTools_WireExplorer(wire)
|
exp = BRepTools.BRepTools_WireExplorer(wire)
|
||||||
while exp.More():
|
while exp.More():
|
||||||
point = OCC.BRep.BRep_Tool.Pnt(exp.CurrentVertex())
|
point = BRep.BRep_Tool.Pnt(exp.CurrentVertex())
|
||||||
points.append((point.X(), -point.Y()))
|
points.append((point.X(), -point.Y()))
|
||||||
exp.Next()
|
exp.Next()
|
||||||
cut_polygons.append({ 'global_id': global_id, 'metadata': {}, 'points': points })
|
cut_polygons.append({ 'global_id': global_id, 'metadata': {}, 'points': points })
|
||||||
@@ -364,47 +396,47 @@ class IfcCutter:
|
|||||||
return
|
return
|
||||||
|
|
||||||
def create_section_box(self):
|
def create_section_box(self):
|
||||||
top_left_corner = OCC.gp.gp_Pnt(
|
top_left_corner = gp.gp_Pnt(
|
||||||
self.section_box['top_left_corner'][0],
|
self.section_box['top_left_corner'][0],
|
||||||
self.section_box['top_left_corner'][1],
|
self.section_box['top_left_corner'][1],
|
||||||
self.section_box['top_left_corner'][2])
|
self.section_box['top_left_corner'][2])
|
||||||
axis = OCC.gp.gp_Ax2(
|
axis = gp.gp_Ax2(
|
||||||
top_left_corner,
|
top_left_corner,
|
||||||
OCC.gp.gp_Dir(
|
gp.gp_Dir(
|
||||||
self.section_box['projection'][0],
|
self.section_box['projection'][0],
|
||||||
self.section_box['projection'][1],
|
self.section_box['projection'][1],
|
||||||
self.section_box['projection'][2]),
|
self.section_box['projection'][2]),
|
||||||
OCC.gp.gp_Dir(
|
gp.gp_Dir(
|
||||||
self.section_box['x_axis'][0],
|
self.section_box['x_axis'][0],
|
||||||
self.section_box['x_axis'][1],
|
self.section_box['x_axis'][1],
|
||||||
self.section_box['x_axis'][2])
|
self.section_box['x_axis'][2])
|
||||||
)
|
)
|
||||||
section_box = OCC.BRepPrimAPI.BRepPrimAPI_MakeBox(
|
section_box = BRepPrimAPI.BRepPrimAPI_MakeBox(
|
||||||
axis, self.section_box['x'], self.section_box['y'], self.section_box['z']
|
axis, self.section_box['x'], self.section_box['y'], self.section_box['z']
|
||||||
)
|
)
|
||||||
self.section_box['shape'] = section_box.Shape()
|
self.section_box['shape'] = section_box.Shape()
|
||||||
self.section_box['face'] = section_box.BottomFace()
|
self.section_box['face'] = section_box.BottomFace()
|
||||||
|
|
||||||
source = OCC.gp.gp_Ax3(axis)
|
source = gp.gp_Ax3(axis)
|
||||||
self.transformation_data = {
|
self.transformation_data = {
|
||||||
'top_left_corner': self.section_box['top_left_corner'],
|
'top_left_corner': self.section_box['top_left_corner'],
|
||||||
'projection': self.section_box['projection'],
|
'projection': self.section_box['projection'],
|
||||||
'x_axis': self.section_box['x_axis']
|
'x_axis': self.section_box['x_axis']
|
||||||
}
|
}
|
||||||
destination = OCC.gp.gp_Ax3(
|
destination = gp.gp_Ax3(
|
||||||
OCC.gp.gp_Pnt(0, 0, 0),
|
gp.gp_Pnt(0, 0, 0),
|
||||||
OCC.gp.gp_Dir(0, 0, -1),
|
gp.gp_Dir(0, 0, -1),
|
||||||
OCC.gp.gp_Dir(1, 0, 0))
|
gp.gp_Dir(1, 0, 0))
|
||||||
self.transformation_dest = destination
|
self.transformation_dest = destination
|
||||||
self.transformation = OCC.gp.gp_Trsf()
|
self.transformation = gp.gp_Trsf()
|
||||||
self.transformation.SetDisplacement(source, destination)
|
self.transformation.SetDisplacement(source, destination)
|
||||||
|
|
||||||
def get_background_elements(self):
|
def get_background_elements(self):
|
||||||
total_product_shapes = len(self.product_shapes)
|
total_product_shapes = len(self.product_shapes)
|
||||||
n = 0
|
n = 0
|
||||||
intersections = []
|
intersections = []
|
||||||
compound = OCC.TopoDS.TopoDS_Compound()
|
compound = TopoDS.TopoDS_Compound()
|
||||||
builder = OCC.BRep.BRep_Builder()
|
builder = BRep.BRep_Builder()
|
||||||
builder.MakeCompound(compound)
|
builder.MakeCompound(compound)
|
||||||
for product, shape in self.product_shapes:
|
for product, shape in self.product_shapes:
|
||||||
builder.Add(compound, shape)
|
builder.Add(compound, shape)
|
||||||
@@ -413,22 +445,22 @@ class IfcCutter:
|
|||||||
#print('Processing product {} '.format(product.Name))
|
#print('Processing product {} '.format(product.Name))
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
intersection = OCC.BRepAlgoAPI.BRepAlgoAPI_Common(self.section_box['shape'], shape).Shape()
|
intersection = BRepAlgoAPI.BRepAlgoAPI_Common(self.section_box['shape'], shape).Shape()
|
||||||
intersection_edges = self.get_booleaned_edges(intersection)
|
intersection_edges = self.get_booleaned_edges(intersection)
|
||||||
if len(intersection_edges) <= 0:
|
if len(intersection_edges) <= 0:
|
||||||
continue
|
continue
|
||||||
intersections.append(intersection)
|
intersections.append(intersection)
|
||||||
|
|
||||||
transformed_intersection = OCC.BRepBuilderAPI.BRepBuilderAPI_Transform(
|
transformed_intersection = BRepBuilderAPI.BRepBuilderAPI_Transform(
|
||||||
intersection, self.transformation)
|
intersection, self.transformation)
|
||||||
intersection = transformed_intersection.Shape()
|
intersection = transformed_intersection.Shape()
|
||||||
|
|
||||||
edge_face_map = OCC.TopTools.TopTools_IndexedDataMapOfShapeListOfShape()
|
edge_face_map = TopTools.TopTools_IndexedDataMapOfShapeListOfShape()
|
||||||
OCC.TopExp.topexp.MapShapesAndAncestors(
|
TopExp.topexp.MapShapesAndAncestors(
|
||||||
intersection, OCC.TopAbs.TopAbs_EDGE,
|
intersection, TopAbs.TopAbs_EDGE,
|
||||||
OCC.TopAbs.TopAbs_FACE, edge_face_map)
|
TopAbs.TopAbs_FACE, edge_face_map)
|
||||||
|
|
||||||
exp = OCC.TopExp.TopExp_Explorer(intersection, OCC.TopAbs.TopAbs_FACE)
|
exp = TopExp.TopExp_Explorer(intersection, TopAbs.TopAbs_FACE)
|
||||||
while exp.More():
|
while exp.More():
|
||||||
face = topods.Face(exp.Current())
|
face = topods.Face(exp.Current())
|
||||||
normal = self.get_normal(face)
|
normal = self.get_normal(face)
|
||||||
@@ -461,20 +493,20 @@ class IfcCutter:
|
|||||||
return hits
|
return hits
|
||||||
|
|
||||||
def raycast(self, shape, point):
|
def raycast(self, shape, point):
|
||||||
raycast = OCC.IntCurvesFace.IntCurvesFace_ShapeIntersector()
|
raycast = IntCurvesFace.IntCurvesFace_ShapeIntersector()
|
||||||
raycast.Load(shape, 0.01)
|
raycast.Load(shape, 0.01)
|
||||||
line = OCC.gp.gp_Lin(
|
line = gp.gp_Lin(
|
||||||
OCC.gp.gp_Pnt(float(point[0]), float(point[1]), float(point[2])),
|
gp.gp_Pnt(float(point[0]), float(point[1]), float(point[2])),
|
||||||
OCC.gp.gp_Dir( 0, 0, -1))
|
gp.gp_Dir( 0, 0, -1))
|
||||||
raycast.Perform(line, 0, self.section_box['z'])
|
raycast.Perform(line, 0, self.section_box['z'])
|
||||||
return raycast.NbPnt() != 0
|
return raycast.NbPnt() != 0
|
||||||
|
|
||||||
def raycast_at_projection_dir(self, shape, point):
|
def raycast_at_projection_dir(self, shape, point):
|
||||||
raycast = OCC.IntCurvesFace.IntCurvesFace_ShapeIntersector()
|
raycast = IntCurvesFace.IntCurvesFace_ShapeIntersector()
|
||||||
raycast.Load(shape, 0.01)
|
raycast.Load(shape, 0.01)
|
||||||
line = OCC.gp.gp_Lin(
|
line = gp.gp_Lin(
|
||||||
OCC.gp.gp_Pnt(float(point[0]), float(point[1]), float(point[2])),
|
gp.gp_Pnt(float(point[0]), float(point[1]), float(point[2])),
|
||||||
OCC.gp.gp_Dir(
|
gp.gp_Dir(
|
||||||
self.section_box['projection'][0],
|
self.section_box['projection'][0],
|
||||||
self.section_box['projection'][1],
|
self.section_box['projection'][1],
|
||||||
self.section_box['projection'][2]))
|
self.section_box['projection'][2]))
|
||||||
@@ -485,8 +517,8 @@ class IfcCutter:
|
|||||||
return { 'face': raycast.Face(1), 'z': raycast.WParameter(1) }
|
return { 'face': raycast.Face(1), 'z': raycast.WParameter(1) }
|
||||||
|
|
||||||
def get_bbox(self, shape):
|
def get_bbox(self, shape):
|
||||||
bbox = OCC.Bnd.Bnd_Box()
|
bbox = Bnd.Bnd_Box()
|
||||||
OCC.BRepBndLib.brepbndlib_Add(shape, bbox)
|
BRepBndLib.brepbndlib_Add(shape, bbox)
|
||||||
return bbox
|
return bbox
|
||||||
|
|
||||||
def calculate_face_zpos(self, face):
|
def calculate_face_zpos(self, face):
|
||||||
@@ -496,11 +528,11 @@ class IfcCutter:
|
|||||||
return zpos, zmax
|
return zpos, zmax
|
||||||
|
|
||||||
def get_split_edges(self, edge_face_map, face, zmax, product):
|
def get_split_edges(self, edge_face_map, face, zmax, product):
|
||||||
exp2 = OCC.TopExp.TopExp_Explorer(face, OCC.TopAbs.TopAbs_EDGE)
|
exp2 = TopExp.TopExp_Explorer(face, TopAbs.TopAbs_EDGE)
|
||||||
while exp2.More():
|
while exp2.More():
|
||||||
edge = topods.Edge(exp2.Current())
|
edge = topods.Edge(exp2.Current())
|
||||||
adjface = OCC.TopoDS.TopoDS_Face()
|
adjface = TopoDS.TopoDS_Face()
|
||||||
getadj = OCC.TopOpeBRepBuild.TopOpeBRepBuild_Tools.GetAdjacentFace(face, edge, edge_face_map, adjface)
|
getadj = TopOpeBRepBuild.TopOpeBRepBuild_Tools.GetAdjacentFace(face, edge, edge_face_map, adjface)
|
||||||
if getadj:
|
if getadj:
|
||||||
try:
|
try:
|
||||||
edge_angle = math.degrees(self.get_angle_between_faces(face, adjface))
|
edge_angle = math.degrees(self.get_angle_between_faces(face, adjface))
|
||||||
@@ -525,8 +557,8 @@ class IfcCutter:
|
|||||||
self.get_normal(f1), self.get_normal(f2)))
|
self.get_normal(f1), self.get_normal(f2)))
|
||||||
|
|
||||||
def get_normal(self, face):
|
def get_normal(self, face):
|
||||||
surface = OCC.Geom.Handle_Geom_Surface(OCC.BRep.BRep_Tool.Surface(face))
|
surface = Geom.Handle_Geom_Surface(BRep.BRep_Tool.Surface(face))
|
||||||
props = OCC.GeomLProp.GeomLProp_SLProps(surface, 0, 0, 1, .001)
|
props = GeomLProp.GeomLProp_SLProps(surface, 0, 0, 1, .001)
|
||||||
return props.Normal()
|
return props.Normal()
|
||||||
|
|
||||||
def get_dot_product_of_normals(self, n1, n2):
|
def get_dot_product_of_normals(self, n1, n2):
|
||||||
@@ -541,34 +573,34 @@ class IfcCutter:
|
|||||||
and p1.Z() == p2.Z()
|
and p1.Z() == p2.Z()
|
||||||
|
|
||||||
def build_new_edge(self, edge, zpos):
|
def build_new_edge(self, edge, zpos):
|
||||||
exp = OCC.TopExp.TopExp_Explorer(edge, OCC.TopAbs.TopAbs_VERTEX)
|
exp = TopExp.TopExp_Explorer(edge, TopAbs.TopAbs_VERTEX)
|
||||||
new_vertices = []
|
new_vertices = []
|
||||||
while exp.More():
|
while exp.More():
|
||||||
current_vertex = topods.Vertex(exp.Current())
|
current_vertex = topods.Vertex(exp.Current())
|
||||||
current_point = OCC.BRep.BRep_Tool.Pnt(current_vertex)
|
current_point = BRep.BRep_Tool.Pnt(current_vertex)
|
||||||
current_point.SetZ(zpos)
|
current_point.SetZ(zpos)
|
||||||
new_vertices.append(OCC.BRepBuilderAPI.BRepBuilderAPI_MakeVertex(current_point).Vertex())
|
new_vertices.append(BRepBuilderAPI.BRepBuilderAPI_MakeVertex(current_point).Vertex())
|
||||||
exp.Next()
|
exp.Next()
|
||||||
try:
|
try:
|
||||||
return OCC.BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
return BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
||||||
new_vertices[0], new_vertices[1]
|
new_vertices[0], new_vertices[1]
|
||||||
).Edge()
|
).Edge()
|
||||||
except:
|
except:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def build_new_face(self, face, zpos, product):
|
def build_new_face(self, face, zpos, product):
|
||||||
exp = OCC.TopExp.TopExp_Explorer(face, OCC.TopAbs.TopAbs_WIRE)
|
exp = TopExp.TopExp_Explorer(face, TopAbs.TopAbs_WIRE)
|
||||||
while exp.More():
|
while exp.More():
|
||||||
wireexp = OCC.BRepTools.BRepTools_WireExplorer(topods.Wire(exp.Current()))
|
wireexp = BRepTools.BRepTools_WireExplorer(topods.Wire(exp.Current()))
|
||||||
new_wire_builder = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeWire()
|
new_wire_builder = BRepBuilderAPI.BRepBuilderAPI_MakeWire()
|
||||||
first_vertex = None
|
first_vertex = None
|
||||||
previous_vertex = None
|
previous_vertex = None
|
||||||
while wireexp.More():
|
while wireexp.More():
|
||||||
current_vertex = wireexp.CurrentVertex()
|
current_vertex = wireexp.CurrentVertex()
|
||||||
current_point = OCC.BRep.BRep_Tool.Pnt(current_vertex)
|
current_point = BRep.BRep_Tool.Pnt(current_vertex)
|
||||||
# Dodgy technique to squash in Z axis
|
# Dodgy technique to squash in Z axis
|
||||||
current_point.SetZ(zpos)
|
current_point.SetZ(zpos)
|
||||||
current_vertex = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeVertex(current_point).Vertex()
|
current_vertex = BRepBuilderAPI.BRepBuilderAPI_MakeVertex(current_point).Vertex()
|
||||||
if not first_vertex:
|
if not first_vertex:
|
||||||
first_vertex = current_vertex
|
first_vertex = current_vertex
|
||||||
if not previous_vertex:
|
if not previous_vertex:
|
||||||
@@ -576,7 +608,7 @@ class IfcCutter:
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
new_wire_builder.Add(topods.Edge(
|
new_wire_builder.Add(topods.Edge(
|
||||||
OCC.BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
||||||
previous_vertex, current_vertex
|
previous_vertex, current_vertex
|
||||||
).Edge()))
|
).Edge()))
|
||||||
previous_vertex = current_vertex
|
previous_vertex = current_vertex
|
||||||
@@ -588,14 +620,14 @@ class IfcCutter:
|
|||||||
if not wireexp.More():
|
if not wireexp.More():
|
||||||
try:
|
try:
|
||||||
new_wire_builder.Add(topods.Edge(
|
new_wire_builder.Add(topods.Edge(
|
||||||
OCC.BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
BRepBuilderAPI.BRepBuilderAPI_MakeEdge(
|
||||||
current_vertex, first_vertex
|
current_vertex, first_vertex
|
||||||
).Edge()))
|
).Edge()))
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
try:
|
try:
|
||||||
new_wire = new_wire_builder.Wire()
|
new_wire = new_wire_builder.Wire()
|
||||||
new_face = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(new_wire).Face()
|
new_face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(new_wire).Face()
|
||||||
self.background_elements.append({
|
self.background_elements.append({
|
||||||
'raw': product,
|
'raw': product,
|
||||||
'geometry': new_wire,
|
'geometry': new_wire,
|
||||||
@@ -609,13 +641,13 @@ class IfcCutter:
|
|||||||
exp.Next()
|
exp.Next()
|
||||||
|
|
||||||
def get_area(self, shape):
|
def get_area(self, shape):
|
||||||
gprops = OCC.GProp.GProp_GProps()
|
gprops = GProp.GProp_GProps()
|
||||||
OCC.BRepGProp.brepgprop.SurfaceProperties(shape, gprops)
|
BRepGProp.brepgprop.SurfaceProperties(shape, gprops)
|
||||||
return gprops.Mass()
|
return gprops.Mass()
|
||||||
|
|
||||||
def get_booleaned_edges(self, shape):
|
def get_booleaned_edges(self, shape):
|
||||||
edges = []
|
edges = []
|
||||||
exp = OCC.TopExp.TopExp_Explorer(shape, OCC.TopAbs.TopAbs_EDGE)
|
exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE)
|
||||||
while exp.More():
|
while exp.More():
|
||||||
edges.append(topods.Edge(exp.Current()))
|
edges.append(topods.Edge(exp.Current()))
|
||||||
exp.Next()
|
exp.Next()
|
||||||
@@ -722,7 +754,7 @@ class IfcCutterDebug(IfcCutter):
|
|||||||
section_box_display = ifcopenshell.geom.utils.display_shape(self.section_box['shape'])
|
section_box_display = ifcopenshell.geom.utils.display_shape(self.section_box['shape'])
|
||||||
ifcopenshell.geom.utils.set_shape_transparency(section_box_display, 0.5)
|
ifcopenshell.geom.utils.set_shape_transparency(section_box_display, 0.5)
|
||||||
|
|
||||||
transformed_box = OCC.BRepBuilderAPI.BRepBuilderAPI_Transform(
|
transformed_box = BRepBuilderAPI.BRepBuilderAPI_Transform(
|
||||||
self.section_box['shape'], self.transformation)
|
self.section_box['shape'], self.transformation)
|
||||||
box_display = ifcopenshell.geom.utils.display_shape(transformed_box.Shape())
|
box_display = ifcopenshell.geom.utils.display_shape(transformed_box.Shape())
|
||||||
ifcopenshell.geom.utils.set_shape_transparency(box_display, 0.2)
|
ifcopenshell.geom.utils.set_shape_transparency(box_display, 0.2)
|
||||||
@@ -735,7 +767,7 @@ class IfcCutterDebug(IfcCutter):
|
|||||||
self.occ_display.EraseAll()
|
self.occ_display.EraseAll()
|
||||||
for polygon in self.cut_polygons:
|
for polygon in self.cut_polygons:
|
||||||
ifcopenshell.geom.utils.display_shape(polygon['geometry'], clr='BLACK')
|
ifcopenshell.geom.utils.display_shape(polygon['geometry'], clr='BLACK')
|
||||||
face = OCC.BRepBuilderAPI.BRepBuilderAPI_MakeFace(polygon['geometry']).Face()
|
face = BRepBuilderAPI.BRepBuilderAPI_MakeFace(polygon['geometry']).Face()
|
||||||
face_display = ifcopenshell.geom.utils.display_shape(face)
|
face_display = ifcopenshell.geom.utils.display_shape(face)
|
||||||
ifcopenshell.geom.utils.set_shape_transparency(face_display, 0.5)
|
ifcopenshell.geom.utils.set_shape_transparency(face_display, 0.5)
|
||||||
input('Debug: showing cut polygons.')
|
input('Debug: showing cut polygons.')
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import svgwrite
|
|||||||
from . import annotation
|
from . import annotation
|
||||||
from mathutils import Vector
|
from mathutils import Vector
|
||||||
from mathutils import geometry
|
from mathutils import geometry
|
||||||
|
from OCC.Core import BRep, BRepTools, TopExp, TopAbs
|
||||||
|
|
||||||
class External(svgwrite.container.Group):
|
class External(svgwrite.container.Group):
|
||||||
def __init__(self, xml, **extra):
|
def __init__(self, xml, **extra):
|
||||||
@@ -399,20 +400,20 @@ class SvgWriter():
|
|||||||
|
|
||||||
def draw_polyline(self, element, position):
|
def draw_polyline(self, element, position):
|
||||||
classes = self.get_classes(element['raw'], position)
|
classes = self.get_classes(element['raw'], position)
|
||||||
exp = OCC.BRepTools.BRepTools_WireExplorer(element['geometry'])
|
exp = BRepTools.BRepTools_WireExplorer(element['geometry'])
|
||||||
points = []
|
points = []
|
||||||
while exp.More():
|
while exp.More():
|
||||||
point = OCC.BRep.BRep_Tool.Pnt(exp.CurrentVertex())
|
point = BRep.BRep_Tool.Pnt(exp.CurrentVertex())
|
||||||
points.append((point.X() * self.scale, -point.Y() * self.scale))
|
points.append((point.X() * self.scale, -point.Y() * self.scale))
|
||||||
exp.Next()
|
exp.Next()
|
||||||
self.svg.add(self.svg.polyline(points=points, class_=' '.join(classes)))
|
self.svg.add(self.svg.polyline(points=points, class_=' '.join(classes)))
|
||||||
|
|
||||||
def draw_line(self, element, position):
|
def draw_line(self, element, position):
|
||||||
classes = self.get_classes(element['raw'], position)
|
classes = self.get_classes(element['raw'], position)
|
||||||
exp = OCC.TopExp.TopExp_Explorer(element['geometry'], OCC.TopAbs.TopAbs_VERTEX)
|
exp = TopExp.TopExp_Explorer(element['geometry'], TopAbs.TopAbs_VERTEX)
|
||||||
points = []
|
points = []
|
||||||
while exp.More():
|
while exp.More():
|
||||||
point = OCC.BRep.BRep_Tool.Pnt(topods.Vertex(exp.Current()))
|
point = BRep.BRep_Tool.Pnt(topods.Vertex(exp.Current()))
|
||||||
points.append((point.X() * self.scale, -point.Y() * self.scale))
|
points.append((point.X() * self.scale, -point.Y() * self.scale))
|
||||||
exp.Next()
|
exp.Next()
|
||||||
self.svg.add(self.svg.line(start=points[0], end=points[1], class_=' '.join(classes)))
|
self.svg.add(self.svg.line(start=points[0], end=points[1], class_=' '.join(classes)))
|
||||||
|
|||||||
Reference in New Issue
Block a user