mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 10:06:47 +00:00
Update IfcSverchok loading based on latest Sverchok master
This commit is contained in:
+51
-75
@@ -1,5 +1,5 @@
|
|||||||
# IfcSverchok - IFC Sverchok extension
|
# IfcSverchok - IFC Sverchok extension
|
||||||
# Copyright (C) 2022 Martina Jakubowska <martina@jakubowska.dk>
|
# Copyright (C) 2022, 2023 Martina Jakubowska <martina@jakubowska.dk>
|
||||||
#
|
#
|
||||||
# This file is part of IfcSverchok.
|
# This file is part of IfcSverchok.
|
||||||
#
|
#
|
||||||
@@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
bl_info = {
|
bl_info = {
|
||||||
"name": "IFC for Sverchok",
|
"name": "IFC for Sverchok",
|
||||||
"author": "Dion Moult",
|
"author": "Martina Jakubowska, Dion Moult",
|
||||||
"version": (0, 0, 999999),
|
"version": (0, 0, 999999),
|
||||||
"blender": (2, 90, 0),
|
"blender": (2, 90, 0),
|
||||||
"location": "Node Editor",
|
"location": "Node Editor",
|
||||||
@@ -29,16 +29,8 @@ bl_info = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
import importlib
|
import importlib
|
||||||
import nodeitems_utils
|
|
||||||
from sverchok.core import make_node_list
|
|
||||||
from sverchok.utils import auto_gather_node_classes, get_node_class_reference
|
|
||||||
from sverchok.menu import SverchNodeItem, SverchNodeCategory
|
|
||||||
from sverchok.utils.extra_categories import (
|
|
||||||
register_extra_category_provider,
|
|
||||||
unregister_extra_category_provider,
|
|
||||||
)
|
|
||||||
from sverchok.ui.nodeview_space_menu import make_extra_category_menus
|
|
||||||
from sverchok.utils.logging import info, debug
|
from sverchok.utils.logging import info, debug
|
||||||
|
from sverchok.ui.nodeview_space_menu import add_node_menu
|
||||||
|
|
||||||
|
|
||||||
def nodes_index():
|
def nodes_index():
|
||||||
@@ -76,6 +68,39 @@ def nodes_index():
|
|||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
node_categories = [
|
||||||
|
{
|
||||||
|
"IFC": [
|
||||||
|
"SvIfcCreateFile",
|
||||||
|
"SvIfcReadFile",
|
||||||
|
"SvIfcWriteFile",
|
||||||
|
"SvIfcCreateEntity",
|
||||||
|
"SvIfcCreateShape",
|
||||||
|
"SvIfcReadEntity",
|
||||||
|
"SvIfcPickIfcClass",
|
||||||
|
"SvIfcById",
|
||||||
|
"SvIfcByGuid",
|
||||||
|
"SvIfcByType",
|
||||||
|
"SvIfcByQuery",
|
||||||
|
"SvIfcAdd",
|
||||||
|
"SvIfcAddPset",
|
||||||
|
"SvIfcAddSpatialElement",
|
||||||
|
"SvIfcRemove",
|
||||||
|
"SvIfcGenerateGuid",
|
||||||
|
"SvIfcGetProperty",
|
||||||
|
"SvIfcGetAttribute",
|
||||||
|
"SvIfcSelectBlenderObjects",
|
||||||
|
"SvIfcApi",
|
||||||
|
"SvIfcApiWIP",
|
||||||
|
"SvIfcBMeshToIfcRepr",
|
||||||
|
"SvIfcSverchokToIfcRepr",
|
||||||
|
"SvIfcCreateProject",
|
||||||
|
"SvIfcQuickProjectSetup",
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
def make_node_list():
|
def make_node_list():
|
||||||
modules = []
|
modules = []
|
||||||
base_name = "ifcsverchok.nodes"
|
base_name = "ifcsverchok.nodes"
|
||||||
@@ -107,8 +132,8 @@ class IFC_Sv_UpdateCurrent(bpy.types.Operator):
|
|||||||
node_group: bpy.props.StringProperty(default="")
|
node_group: bpy.props.StringProperty(default="")
|
||||||
force_mode: bpy.props.BoolProperty(default=False)
|
force_mode: bpy.props.BoolProperty(default=False)
|
||||||
|
|
||||||
# FIXME For now it's fine to center around buildings.
|
# FIXME For now it's fine to center around buildings.
|
||||||
# But for the future it'd be good to also allow other
|
# But for the future it'd be good to also allow other
|
||||||
# infra-related spatial structure elements, such as IfcBridge.
|
# infra-related spatial structure elements, such as IfcBridge.
|
||||||
# https://github.com/IfcOpenShell/IfcOpenShell/pull/2576#discussion_r1016261407
|
# https://github.com/IfcOpenShell/IfcOpenShell/pull/2576#discussion_r1016261407
|
||||||
def execute(self, context):
|
def execute(self, context):
|
||||||
@@ -233,42 +258,6 @@ class IFC_PT_write_file_panel(bpy.types.Panel):
|
|||||||
CLASSES = [IFC_Sv_UpdateCurrent, IFC_Sv_write_file, IFC_PT_write_file_panel]
|
CLASSES = [IFC_Sv_UpdateCurrent, IFC_Sv_write_file, IFC_PT_write_file_panel]
|
||||||
|
|
||||||
|
|
||||||
def register_nodes():
|
|
||||||
node_modules = make_node_list()
|
|
||||||
for module in node_modules:
|
|
||||||
module.register()
|
|
||||||
info("Registered %s nodes", len(node_modules))
|
|
||||||
|
|
||||||
|
|
||||||
def unregister_nodes():
|
|
||||||
global imported_modules
|
|
||||||
for module in reversed(imported_modules):
|
|
||||||
module.unregister()
|
|
||||||
|
|
||||||
|
|
||||||
def make_menu():
|
|
||||||
menu = []
|
|
||||||
index = nodes_index()
|
|
||||||
for category, items in index:
|
|
||||||
identifier = "IFCSVERCHOK_" + category.replace(" ", "_")
|
|
||||||
node_items = []
|
|
||||||
for item in items:
|
|
||||||
nodetype = item[1]
|
|
||||||
rna = get_node_class_reference(nodetype)
|
|
||||||
if not rna:
|
|
||||||
info(
|
|
||||||
"Node `%s' is not available (probably due to missing dependencies).",
|
|
||||||
nodetype,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
node_item = SverchNodeItem.new(nodetype)
|
|
||||||
node_items.append(node_item)
|
|
||||||
if node_items:
|
|
||||||
cat = SverchNodeCategory(identifier, category, items=node_items)
|
|
||||||
menu.append(cat)
|
|
||||||
return menu
|
|
||||||
|
|
||||||
|
|
||||||
class SvExCategoryProvider(object):
|
class SvExCategoryProvider(object):
|
||||||
def __init__(self, identifier, menu):
|
def __init__(self, identifier, menu):
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
@@ -280,34 +269,21 @@ class SvExCategoryProvider(object):
|
|||||||
|
|
||||||
our_menu_classes = []
|
our_menu_classes = []
|
||||||
|
|
||||||
|
add_node_menu.append_from_config(node_categories)
|
||||||
|
|
||||||
|
|
||||||
def register():
|
def register():
|
||||||
global our_menu_classes
|
node_modules = make_node_list()
|
||||||
|
for module in node_modules:
|
||||||
debug("Registering ifcsverchok")
|
module.register()
|
||||||
for klass in CLASSES:
|
for cls in CLASSES:
|
||||||
bpy.utils.register_class(klass)
|
bpy.utils.register_class(cls)
|
||||||
register_nodes()
|
add_node_menu.register()
|
||||||
extra_nodes = importlib.import_module(".nodes", "ifcsverchok")
|
|
||||||
auto_gather_node_classes(extra_nodes)
|
|
||||||
menu = make_menu()
|
|
||||||
menu_category_provider = SvExCategoryProvider("IFCSVERCHOK", menu)
|
|
||||||
register_extra_category_provider(menu_category_provider) # if 'IFCSVERCHOK' in nodeitems_utils._node_categories:
|
|
||||||
nodeitems_utils.register_node_categories("IFCSVERCHOK", menu)
|
|
||||||
our_menu_classes = make_extra_category_menus()
|
|
||||||
|
|
||||||
|
|
||||||
def unregister():
|
def unregister():
|
||||||
global our_menu_classes
|
global imported_modules
|
||||||
if "IFCSVERCHOK" in nodeitems_utils._node_categories:
|
for module in reversed(imported_modules):
|
||||||
nodeitems_utils.unregister_node_categories("IFCSVERCHOK")
|
module.unregister()
|
||||||
for clazz in our_menu_classes:
|
for cls in reversed(CLASSES):
|
||||||
try:
|
bpy.utils.unregister_class(cls)
|
||||||
bpy.utils.unregister_class(clazz)
|
|
||||||
except Exception as e:
|
|
||||||
print("Can't unregister menu class %s" % clazz)
|
|
||||||
print(e)
|
|
||||||
unregister_extra_category_provider("IFCSVERCHOK")
|
|
||||||
unregister_nodes()
|
|
||||||
for klass in CLASSES:
|
|
||||||
bpy.utils.unregister_class(klass)
|
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ class SvIfcCreateEntity(
|
|||||||
self.file,
|
self.file,
|
||||||
ifc_class=self.ifc_class,
|
ifc_class=self.ifc_class,
|
||||||
name=self.names[i][j],
|
name=self.names[i][j],
|
||||||
description=self.descriptions[i][j],
|
#description=self.descriptions[i][j],
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
for repr in self.representations[i][j]:
|
for repr in self.representations[i][j]:
|
||||||
|
|||||||
Reference in New Issue
Block a user