created new singleton class SvIfcStore, created new 'create_entity2' node

This commit is contained in:
martinaCodes
2022-09-08 01:18:20 +02:00
committed by Dion Moult
parent 3684be1936
commit 25460661ab
3 changed files with 197 additions and 5 deletions
+15 -5
View File
@@ -1,4 +1,3 @@
# IfcSverchok - IFC Sverchok extension
# Copyright (C) 2020, 2021 Dion Moult <dion@thinkmoult.com>
#
@@ -36,7 +35,10 @@ import sverchok
from sverchok.core import sv_registration_utils, make_node_list
from sverchok.utils import auto_gather_node_classes, get_node_class_reference
from sverchok.menu import SverchNodeItem, SverchNodeCategory, register_node_panels
from sverchok.utils.extra_categories import register_extra_category_provider, unregister_extra_category_provider
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
@@ -50,6 +52,7 @@ def nodes_index():
("ifc.read_file", "SvIfcReadFile"),
("ifc.write_file", "SvIfcWriteFile"),
("ifc.create_entity", "SvIfcCreateEntity"),
("ifc.create_entity2", "SvIfcCreateEntity2"),
("ifc.create_shape", "SvIfcCreateShape"),
("ifc.read_entity", "SvIfcReadEntity"),
("ifc.by_id", "SvIfcById"),
@@ -63,8 +66,10 @@ def nodes_index():
("ifc.get_attribute", "SvIfcGetAttribute"),
("ifc.select_blender_objects", "SvIfcSelectBlenderObjects"),
("ifc.api", "SvIfcApi"),
("ifc.api_WIP", "SvIfcApiWIP"),
("ifc.bmesh_to_ifc", "SvIfcBMeshToIfcGeo"),
("ifc.create_project", "SvIfcCreateProject"),
("ifc.quick_project_setup", "SvIfcQuickProjectSetup")
],
)
@@ -112,7 +117,10 @@ def make_menu():
nodetype = item[1]
rna = get_node_class_reference(nodetype)
if not rna:
info("Node `%s' is not available (probably due to missing dependencies).", nodetype)
info(
"Node `%s' is not available (probably due to missing dependencies).",
nodetype,
)
else:
node_item = SverchNodeItem.new(nodetype)
node_items.append(node_item)
@@ -144,7 +152,9 @@ def register():
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:
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()
@@ -160,4 +170,4 @@ def unregister():
print("Can't unregister menu class %s" % clazz)
print(e)
unregister_extra_category_provider("IFCSVERCHOK")
unregister_nodes()
unregister_nodes()
+96
View File
@@ -0,0 +1,96 @@
# import os
import bpy
# import uuid
# import hashlib
# import zipfile
# import tempfile
import ifcopenshell
from ifcopenshell import template
# import blenderbim.bim.handler
# from pathlib import Path
class SvIfcStore:
path = ""
file = None
schema = None
cache = None
cache_path = None
id_map = {}
guid_map = {}
deleted_ids = set()
edited_objs = set()
pset_template_path = ""
pset_template_file = None
library_path = ""
library_file = None
element_listeners = set()
undo_redo_stack_objects = set()
undo_redo_stack_object_names = {}
current_transaction = ""
last_transaction = ""
history = []
future = []
schema_identifiers = ["IFC4", "IFC2X3"]
@staticmethod
def purge():
SvIfcStore.path = ""
SvIfcStore.file = None
SvIfcStore.schema = None
SvIfcStore.cache = None
SvIfcStore.cache_path = None
SvIfcStore.id_map = {}
SvIfcStore.guid_map = {}
SvIfcStore.deleted_ids = set()
SvIfcStore.edited_objs = set()
SvIfcStore.pset_template_path = ""
SvIfcStore.pset_template_file = None
SvIfcStore.library_path = ""
SvIfcStore.library_file = None
SvIfcStore.last_transaction = ""
SvIfcStore.history = []
SvIfcStore.future = []
SvIfcStore.schema_identifiers = ["IFC4", "IFC2X3"]
@staticmethod
def create_boilerplate():
file = template.create(
filename="IfcSverchokDemoFile",
organization=None,
creator=None,
project_name="IfcSverchokDemoProject",
)
if bpy.context.scene.unit_settings.system == 'IMPERIAL':
#TODO change units to imperial
pass
model = ifcopenshell.api.run("context.add_context", file, context_type="Model")
context = ifcopenshell.api.run(
"context.add_context",
file,
context_type="Model",
context_identifier="Body",
target_view="MODEL_VIEW",
parent=model,
)
site = ifcopenshell.api.run("root.create_entity", file, ifc_class="IfcSite", name="My Site")
building = ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcBuilding", name="My Building"
)
building_storey = ifcopenshell.api.run(
"root.create_entity", file, ifc_class="IfcBuildingStorey", name="My Storey"
)
ifcopenshell.api.run("aggregate.assign_object", file, product=site, relating_object=file.by_type("IfcProject")[0])
ifcopenshell.api.run("aggregate.assign_object", file, product=building, relating_object=site)
ifcopenshell.api.run("aggregate.assign_object", file, product=building_storey, relating_object=building)
SvIfcStore.file = file
return SvIfcStore.file
@staticmethod
def get_file():
return SvIfcStore.file
@@ -0,0 +1,86 @@
import bpy
# from helper import SayHello
import ifcopenshell
import ifcsverchok.helper
from ifcsverchok.ifcstore import SvIfcStore
# import ifcsverchok.ifc_store
# from bpy.props import StringProperty
# from sverchok.node_tree import SverchCustomTreeNode
# from sverchok.data_structure import updateNode
import bpy
import ifcopenshell
from bpy.props import StringProperty
from sverchok.node_tree import SverchCustomTreeNode
from sverchok.data_structure import updateNode
class SvIfcCreateEntity2(bpy.types.Node, SverchCustomTreeNode, ifcsverchok.helper.SvIfcCore):
bl_idname = "SvIfcCreateEntity2"
bl_label = "IFC Create Entity2"
Name: StringProperty(name="Name", update=updateNode)
Description: StringProperty(name="Description", update=updateNode)
ifc_class: StringProperty(name="ifc_class", update=updateNode)
representation: StringProperty(name="representation", update=updateNode)
def sv_init(self, context):
self.inputs.new("SvStringsSocket", "Name").prop_name = "Name"
self.inputs.new("SvTextSocket", "Description").prop_name = "Description"
self.inputs.new("SvStringsSocket", "IfcClass").prop_name = "ifc_class"
self.inputs.new("SvStringsSocket", "Representation").prop_name = "representation"
self.outputs.new("SvStringsSocket", "entity")
self.outputs.new("SvStringsSocket", "file") #only for testing
def process(self):
if not any(socket.is_linked for socket in self.outputs):
return
name = self.inputs["Name"].sv_get()[0][0]
description = self.inputs['Description'].sv_get()[0][0]
ifc_class = self.inputs['IfcClass'].sv_get()[0][0]
representation = self.inputs['Representation'].sv_get()[0][0]
if SvIfcStore.file is None:
self.file = SvIfcStore.create_boilerplate()
else:
self.file = SvIfcStore.get_file()
print("file: " , self.file)
if self.node_id not in SvIfcStore.id_map.values():
self.process_ifc(name, description, ifc_class, representation)
else:
entity_id = list(SvIfcStore.id_map.keys())[list(SvIfcStore.id_map.values()).index(self.node_id)]
self.entity = self.file.by_id(entity_id)
self.entity.Name = name
self.entity.Description = description
self.entity.Representation = representation
SvIfcStore.file = self.file
self.outputs["entity"].sv_set([[self.entity]])
self.outputs["file"].sv_set([[self.file]]) #only for testing
def process_ifc(self, name, description, ifc_class, representation):
data = {
'GlobalId': ifcopenshell.guid.new(),
'Name': name,
'Description': description,
'Representation': representation
}
self.entity = self.file.create_entity(str(ifc_class), **data)
print("entity: ", self.entity)
SvIfcStore.id_map[self.entity.id()] = self.node_id
print("id_map: ", SvIfcStore.id_map)
def register():
bpy.utils.register_class(SvIfcCreateEntity2)
def unregister():
bpy.utils.unregister_class(SvIfcCreateEntity2)
SvIfcStore.purge()