Don't load OCC upon startup, in preparation for deprecation when IfcConvert can handle #1153. See #1400 and #1358.

This commit is contained in:
Dion Moult
2021-03-27 18:37:19 +11:00
parent ff7219b557
commit ca24838a3f
2 changed files with 81 additions and 66 deletions
+72 -62
View File
@@ -6,68 +6,71 @@ import numpy
import pickle import pickle
import multiprocessing import multiprocessing
try:
from OCC.Core import ( def load_occ():
gp, # Don't import until we really need to, as a temporary step before we can purge OCC
Geom, try:
Bnd, from OCC.Core import (
BRepBndLib, gp,
BRep, Geom,
BRepPrimAPI, Bnd,
BRepAlgoAPI, BRepBndLib,
BRepBuilderAPI, BRep,
TopOpeBRepTool, BRepPrimAPI,
TopOpeBRepBuild, BRepAlgoAPI,
ShapeExtend, BRepBuilderAPI,
GProp, TopOpeBRepTool,
BRepGProp, TopOpeBRepBuild,
GC, ShapeExtend,
ShapeAnalysis, GProp,
TopTools, BRepGProp,
TopExp, GC,
TopAbs, ShapeAnalysis,
HLRAlgo, TopTools,
HLRBRep, TopExp,
TopLoc, TopAbs,
Bnd, HLRAlgo,
BRepBndLib, HLRBRep,
BRepTools, TopLoc,
TopoDS, Bnd,
GeomLProp, BRepBndLib,
IntCurvesFace, BRepTools,
) TopoDS,
from OCC.Core.TopoDS import topods GeomLProp,
except ImportError: IntCurvesFace,
from OCC import ( )
gp, from OCC.Core.TopoDS import topods
Geom, except ImportError:
Bnd, from OCC import (
BRepBndLib, gp,
BRep, Geom,
BRepPrimAPI, Bnd,
BRepAlgoAPI, BRepBndLib,
BRepBuilderAPI, BRep,
TopOpeBRepTool, BRepPrimAPI,
TopOpeBRepBuild, BRepAlgoAPI,
ShapeExtend, BRepBuilderAPI,
GProp, TopOpeBRepTool,
BRepGProp, TopOpeBRepBuild,
GC, ShapeExtend,
ShapeAnalysis, GProp,
TopTools, BRepGProp,
TopExp, GC,
TopAbs, ShapeAnalysis,
HLRAlgo, TopTools,
HLRBRep, TopExp,
TopLoc, TopAbs,
Bnd, HLRAlgo,
BRepBndLib, HLRBRep,
BRepTools, TopLoc,
TopoDS, Bnd,
GeomLProp, BRepBndLib,
IntCurvesFace, BRepTools,
) TopoDS,
from OCC.TopoDS import topods GeomLProp,
IntCurvesFace,
)
from OCC.TopoDS import topods
import ifcopenshell import ifcopenshell
import ifcopenshell.geom import ifcopenshell.geom
@@ -79,6 +82,7 @@ this_file = os.path.join(cwd, "cut_ifc.py")
def get_booleaned_edges(shape): def get_booleaned_edges(shape):
load_occ()
edges = [] edges = []
exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE) exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE)
while exp.More(): while exp.More():
@@ -88,6 +92,7 @@ def get_booleaned_edges(shape):
def connect_edges_into_wires(unconnected_edges): def connect_edges_into_wires(unconnected_edges):
load_occ()
edges = TopTools.TopTools_HSequenceOfShape() edges = TopTools.TopTools_HSequenceOfShape()
edges_handle = TopTools.Handle_TopTools_HSequenceOfShape(edges) edges_handle = TopTools.Handle_TopTools_HSequenceOfShape(edges)
wires = TopTools.TopTools_HSequenceOfShape() wires = TopTools.TopTools_HSequenceOfShape()
@@ -101,6 +106,7 @@ def connect_edges_into_wires(unconnected_edges):
def do_cut(process_data): def do_cut(process_data):
load_occ()
global_id, shape, section, trsf_data = process_data global_id, shape, section, trsf_data = process_data
axis = gp.gp_Ax2( axis = gp.gp_Ax2(
@@ -320,6 +326,7 @@ class IfcCutter:
return False return False
def create_section_box(self): def create_section_box(self):
load_occ()
top_left_corner = 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],
@@ -350,6 +357,7 @@ class IfcCutter:
self.transformation.SetDisplacement(source, destination) self.transformation.SetDisplacement(source, destination)
def get_bbox(self, shape): def get_bbox(self, shape):
load_occ()
bbox = Bnd.Bnd_Box() bbox = Bnd.Bnd_Box()
BRepBndLib.brepbndlib_Add(shape, bbox) BRepBndLib.brepbndlib_Add(shape, bbox)
return bbox return bbox
@@ -361,6 +369,7 @@ class IfcCutter:
return zpos, zmax return zpos, zmax
def get_booleaned_edges(self, shape): def get_booleaned_edges(self, shape):
load_occ()
edges = [] edges = []
exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE) exp = TopExp.TopExp_Explorer(shape, TopAbs.TopAbs_EDGE)
while exp.More(): while exp.More():
@@ -377,6 +386,7 @@ class IfcCutter:
def get_annotation(self): def get_annotation(self):
import mathutils import mathutils
load_occ()
self.annotation_objs = [] self.annotation_objs = []
settings_2d = ifcopenshell.geom.settings() settings_2d = ifcopenshell.geom.settings()
+9 -4
View File
@@ -12,10 +12,13 @@ from mathutils import Vector
from mathutils import geometry from mathutils import geometry
from blenderbim.bim.ifc import IfcStore from blenderbim.bim.ifc import IfcStore
try:
from OCC.Core import BRep, BRepTools, TopExp, TopAbs def load_occ():
except ImportError: # Don't import until we really need to, as a temporary step before we can purge OCC
from OCC import BRep, BRepTools, TopExp, TopAbs try:
from OCC.Core import BRep, BRepTools, TopExp, TopAbs
except ImportError:
from OCC import BRep, BRepTools, TopExp, TopAbs
class External(svgwrite.container.Group): class External(svgwrite.container.Group):
@@ -599,6 +602,7 @@ class SvgWriter:
self.draw_polygon(polygon, "cut") self.draw_polygon(polygon, "cut")
def draw_polyline(self, element, position): def draw_polyline(self, element, position):
load_occ()
classes = self.get_classes(element["raw"], position) classes = self.get_classes(element["raw"], position)
exp = BRepTools.BRepTools_WireExplorer(element["geometry"]) exp = BRepTools.BRepTools_WireExplorer(element["geometry"])
points = [] points = []
@@ -609,6 +613,7 @@ class SvgWriter:
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):
load_occ()
classes = self.get_classes(element["raw"], position) classes = self.get_classes(element["raw"], position)
exp = TopExp.TopExp_Explorer(element["geometry"], TopAbs.TopAbs_VERTEX) exp = TopExp.TopExp_Explorer(element["geometry"], TopAbs.TopAbs_VERTEX)
points = [] points = []