mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-18 22:33:33 +00:00
Defer pythonOCC imports in order not to break if unavailable
This commit is contained in:
@@ -1,2 +1,21 @@
|
|||||||
|
###############################################################################
|
||||||
|
# #
|
||||||
|
# This file is part of IfcOpenShell. #
|
||||||
|
# #
|
||||||
|
# IfcOpenShell is free software: you can redistribute it and/or modify #
|
||||||
|
# it under the terms of the Lesser GNU General Public License as published by #
|
||||||
|
# the Free Software Foundation, either version 3.0 of the License, or #
|
||||||
|
# (at your option) any later version. #
|
||||||
|
# #
|
||||||
|
# IfcOpenShell is distributed in the hope that it will be useful, #
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
||||||
|
# Lesser GNU General Public License for more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the Lesser GNU General Public License #
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. #
|
||||||
|
# #
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
from . import occ_utils as utils
|
from . import occ_utils as utils
|
||||||
from .main import *
|
from .main import *
|
||||||
|
|||||||
@@ -21,13 +21,6 @@ import random
|
|||||||
import operator
|
import operator
|
||||||
from collections import namedtuple, Iterable
|
from collections import namedtuple, Iterable
|
||||||
|
|
||||||
import OCC.gp
|
|
||||||
import OCC.V3d
|
|
||||||
import OCC.AIS
|
|
||||||
import OCC.Quantity
|
|
||||||
import OCC.BRepTools
|
|
||||||
import OCC.Display.SimpleGui
|
|
||||||
|
|
||||||
shape_tuple = namedtuple('shape_tuple', ('data', 'geometry', 'styles'))
|
shape_tuple = namedtuple('shape_tuple', ('data', 'geometry', 'styles'))
|
||||||
|
|
||||||
handle, main_loop, add_menu, add_function_to_menu = None, None, None, None
|
handle, main_loop, add_menu, add_function_to_menu = None, None, None, None
|
||||||
@@ -48,6 +41,9 @@ DEFAULT_STYLES = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def initialize_display():
|
def initialize_display():
|
||||||
|
import OCC.V3d
|
||||||
|
import OCC.Display.SimpleGui
|
||||||
|
|
||||||
global handle, main_loop, add_menu, add_function_to_menu
|
global handle, main_loop, add_menu, add_function_to_menu
|
||||||
handle, main_loop, add_menu, add_function_to_menu = OCC.Display.SimpleGui.init_display()
|
handle, main_loop, add_menu, add_function_to_menu = OCC.Display.SimpleGui.init_display()
|
||||||
|
|
||||||
@@ -76,12 +72,18 @@ def initialize_display():
|
|||||||
return handle
|
return handle
|
||||||
|
|
||||||
def yield_subshapes(shape):
|
def yield_subshapes(shape):
|
||||||
|
import OCC.TopoDS
|
||||||
|
|
||||||
it = OCC.TopoDS.TopoDS_Iterator(shape)
|
it = OCC.TopoDS.TopoDS_Iterator(shape)
|
||||||
while it.More():
|
while it.More():
|
||||||
yield it.Value()
|
yield it.Value()
|
||||||
it.Next()
|
it.Next()
|
||||||
|
|
||||||
def display_shape(shape, clr=None, viewer_handle=None):
|
def display_shape(shape, clr=None, viewer_handle=None):
|
||||||
|
import OCC.gp
|
||||||
|
import OCC.AIS
|
||||||
|
import OCC.Quantity
|
||||||
|
|
||||||
if viewer_handle is None: viewer_handle = handle
|
if viewer_handle is None: viewer_handle = handle
|
||||||
|
|
||||||
if isinstance(shape, shape_tuple):
|
if isinstance(shape, shape_tuple):
|
||||||
@@ -172,12 +174,16 @@ def set_shape_transparency(ais, t):
|
|||||||
|
|
||||||
|
|
||||||
def get_bounding_box_center(bbox):
|
def get_bounding_box_center(bbox):
|
||||||
|
import OCC.gp
|
||||||
|
|
||||||
bbmin = [0.]*3; bbmax = [0.]*3
|
bbmin = [0.]*3; bbmax = [0.]*3
|
||||||
bbmin[0], bbmin[1], bbmin[2], bbmax[0], bbmax[1], bbmax[2] = bbox.Get()
|
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)))
|
return OCC.gp.gp_Pnt(*map(lambda xy: (xy[0]+xy[1])/2., zip(bbmin, bbmax)))
|
||||||
|
|
||||||
|
|
||||||
def create_shape_from_serialization(brep_object):
|
def create_shape_from_serialization(brep_object):
|
||||||
|
import OCC.BRepTools
|
||||||
|
|
||||||
brep_data, occ_shape, styles = None, None, ()
|
brep_data, occ_shape, styles = None, None, ()
|
||||||
|
|
||||||
is_product_shape = True
|
is_product_shape = True
|
||||||
|
|||||||
Reference in New Issue
Block a user