mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-10 01:41:57 +00:00
improve core file for better zen
This commit is contained in:
@@ -16,14 +16,10 @@
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with BlenderBIM Add-on. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import os
|
||||
import bpy
|
||||
import bsdd
|
||||
import json
|
||||
import ifcopenshell
|
||||
import blenderbim.tool as tool
|
||||
from blenderbim.core import bsdd as core
|
||||
from blenderbim.tool.bsdd import Bsdd
|
||||
|
||||
|
||||
class LoadBSDDDomains(bpy.types.Operator):
|
||||
@@ -32,7 +28,7 @@ class LoadBSDDDomains(bpy.types.Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
core.load_bsdd(context.scene.BIMBSDDProperties, bsdd.Client(), Bsdd)
|
||||
core.load_bsdd(bsdd.Client(), tool.Bsdd)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -44,7 +40,7 @@ class SetActiveBSDDDictionary(bpy.types.Operator):
|
||||
uri: bpy.props.StringProperty()
|
||||
|
||||
def execute(self, context):
|
||||
core.set_active_bsdd_dictionary(context, self.name, self.uri)
|
||||
core.set_active_bsdd_dictionary(self.name, self.uri, tool.Bsdd)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -54,7 +50,8 @@ class SearchBSDDClass(bpy.types.Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
core.search_class(context, bsdd.Client(), tool.Bsdd, tool.Ifc)
|
||||
keyword = context.scene.BIMBSDDProperties.keyword
|
||||
core.search_class(keyword, bsdd.Client(), tool.Bsdd)
|
||||
return {"FINISHED"}
|
||||
|
||||
|
||||
@@ -64,5 +61,5 @@ class GetBSDDClassificationProperties(bpy.types.Operator):
|
||||
bl_options = {"REGISTER", "UNDO"}
|
||||
|
||||
def execute(self, context):
|
||||
core.get_class_properties(context, bsdd.Client(), tool.Bsdd)
|
||||
core.get_class_properties(bsdd.Client(), tool.Bsdd)
|
||||
return {"FINISHED"}
|
||||
|
||||
@@ -1,40 +1,30 @@
|
||||
def load_bsdd(props, client, bsdd):
|
||||
props.domains.clear()
|
||||
if props.load_preview_domains:
|
||||
def load_bsdd(client, bsdd):
|
||||
bsdd.clear_domains()
|
||||
if bsdd.should_load_preview_domains:
|
||||
dictionaries = bsdd.get_dictionaries(client)
|
||||
else:
|
||||
dictionaries = bsdd.get_dictionaries(client, "Active")
|
||||
if not props.load_preview_domains:
|
||||
dictionaries = filter(lambda d: d["status"] == "Active", dictionaries)
|
||||
for dictionary in sorted(dictionaries, key=lambda d: d["name"]):
|
||||
new = props.domains.add()
|
||||
bsdd.fill_dictionary_prop(new, dictionary)
|
||||
bsdd.create_dictionaries(dictionaries)
|
||||
|
||||
|
||||
def set_active_bsdd_dictionary(context, name, uri):
|
||||
props = context.scene.BIMBSDDProperties
|
||||
props.active_domain = name
|
||||
props.active_uri = uri
|
||||
def set_active_bsdd_dictionary(name: str, uri: str, bsdd):
|
||||
bsdd.set_active_bsdd(name, uri)
|
||||
|
||||
|
||||
def search_class(context, client, bsdd, ifc):
|
||||
props = context.scene.BIMBSDDProperties
|
||||
props.classifications.clear()
|
||||
if len(props.keyword) < 3:
|
||||
def search_class(keyword: str, client, bsdd):
|
||||
bsdd.clear_classes()
|
||||
if len(keyword) < 3:
|
||||
return
|
||||
related_entities = bsdd.get_related_ifc_entities(props.keyword, props.should_filter_ifc_class,
|
||||
context.active_object, ifc)
|
||||
response: dict = client.search_class(props.keyword, dictionary_uris=[props.active_uri],
|
||||
related_ifc_entities=related_entities)
|
||||
classes = response.get("classes", [])
|
||||
for _class in sorted(classes, key=lambda c: c["referenceCode"]):
|
||||
bsdd.fill_class_prop(props.classifications.add(), _class)
|
||||
related_entities = bsdd.get_related_ifc_entities(keyword)
|
||||
active_dictionary_uri = bsdd.get_active_dictionary_uri()
|
||||
classes: dict = bsdd.search_class(client, keyword, [active_dictionary_uri], related_entities)
|
||||
bsdd.create_classes(classes)
|
||||
|
||||
|
||||
def get_class_properties(context, client, bsdd):
|
||||
bprops = context.scene.BIMBSDDProperties
|
||||
data = bsdd.get_active_class_data(bprops, client)
|
||||
def get_class_properties(client, bsdd):
|
||||
bsdd.clear_class_psets()
|
||||
data = bsdd.get_active_class_data(client)
|
||||
pset_dict = bsdd.get_property_dict(data)
|
||||
if pset_dict is None:
|
||||
return
|
||||
bsdd.create_classification_psets(bprops, pset_dict)
|
||||
bsdd.create_class_psets(pset_dict)
|
||||
|
||||
@@ -137,19 +137,22 @@ class Brick:
|
||||
|
||||
|
||||
class Bsdd:
|
||||
def clear_domains(cls): pass
|
||||
def clear_classes(cls): pass
|
||||
def clear_class_psets(cls): pass
|
||||
def get_active_dictionary_uri(cls): pass
|
||||
def search_class(cls, client, keyword, dictionary_uris, related_ifc_entities): pass
|
||||
def should_load_preview_domains(cls): pass
|
||||
def get_dictionaries(cls, client): pass
|
||||
|
||||
def fill_dictionary_prop(cls, prop, dictionary): pass
|
||||
|
||||
def get_related_ifc_entities(cls, keyword, filter_ifc_class, active_object, ifc): pass
|
||||
|
||||
def fill_class_prop(cls, prop, _class): pass
|
||||
|
||||
def get_active_class_data(cls, prop, client): pass
|
||||
|
||||
def create_dictionaries(cls, dictionaries): pass
|
||||
def get_related_ifc_entities(cls, keyword): pass
|
||||
def create_classes(cls, class_dict): pass
|
||||
def get_active_class_data(cls, client): pass
|
||||
def get_property_dict(cls, class_data): pass
|
||||
def create_class_psets(cls, pset_dict): pass
|
||||
def set_active_bsdd(cls, name, uri): pass
|
||||
|
||||
|
||||
def create_classification_psets(cls, props, pset_dic): pass
|
||||
@interface
|
||||
class Collector:
|
||||
def assign(cls, obj): pass
|
||||
|
||||
@@ -1,8 +1,41 @@
|
||||
import blenderbim.core.tool
|
||||
import json
|
||||
import bpy
|
||||
import blenderbim.tool as tool
|
||||
|
||||
|
||||
class Bsdd(blenderbim.core.tool.Bsdd):
|
||||
|
||||
@classmethod
|
||||
def clear_domains(cls) -> None:
|
||||
bpy.context.scene.BIMBSDDProperties.domains.clear()
|
||||
|
||||
@classmethod
|
||||
def clear_classes(cls) -> None:
|
||||
bpy.context.scene.BIMBSDDProperties.classifications.clear()
|
||||
|
||||
@classmethod
|
||||
def clear_class_psets(cls) -> None:
|
||||
bpy.context.scene.BIMBSDDProperties.classification_psets.clear()
|
||||
|
||||
@classmethod
|
||||
def get_active_dictionary_uri(cls) -> str:
|
||||
return bpy.context.scene.BIMBSDDProperties.active_uri
|
||||
|
||||
@classmethod
|
||||
def search_class(cls, client, keyword, dictionary_uris, related_ifc_entities) -> dict:
|
||||
response = client.search_class(keyword, dictionary_uris=dictionary_uris,
|
||||
related_ifc_entities=related_ifc_entities)
|
||||
return response.get("classes", [])
|
||||
|
||||
@classmethod
|
||||
def should_load_preview_domains(cls) -> bool:
|
||||
return bpy.context.scene.BIMBSDDProperties.load_preview_domains
|
||||
|
||||
@classmethod
|
||||
def should_filter_ifc_class(cls) -> bool:
|
||||
return bpy.context.scene.BIMBSDDProperties.should_filter_ifc_class
|
||||
|
||||
@classmethod
|
||||
def get_dictionaries(cls, client, status=None) -> list:
|
||||
response = client.get_dictionary()
|
||||
@@ -12,38 +45,47 @@ class Bsdd(blenderbim.core.tool.Bsdd):
|
||||
return dicts
|
||||
|
||||
@classmethod
|
||||
def fill_dictionary_prop(cls, prop, dictionary):
|
||||
prop.name = dictionary["name"]
|
||||
prop.uri = dictionary["uri"]
|
||||
prop.default_language_code = dictionary["defaultLanguageCode"]
|
||||
prop.organization_name_owner = dictionary["organizationNameOwner"]
|
||||
prop.status = dictionary["status"]
|
||||
prop.version = dictionary["version"]
|
||||
def create_dictionaries(cls, dictionaries: dict):
|
||||
props = bpy.context.scene.BIMBSDDProperties
|
||||
for dictionary in sorted(dictionaries, key=lambda d: d["name"]):
|
||||
new = props.domains.add()
|
||||
new.name = dictionary["name"]
|
||||
new.uri = dictionary["uri"]
|
||||
new.default_language_code = dictionary["defaultLanguageCode"]
|
||||
new.organization_name_owner = dictionary["organizationNameOwner"]
|
||||
new.status = dictionary["status"]
|
||||
new.version = dictionary["version"]
|
||||
|
||||
@classmethod
|
||||
def get_related_ifc_entities(cls, keyword, filter_ifc_class: bool, active_object, ifc):
|
||||
def create_classes(cls, class_dict):
|
||||
props = bpy.context.scene.BIMBSDDProperties
|
||||
for _class in sorted(class_dict, key=lambda c: c["referenceCode"]):
|
||||
prop = props.classifications.add()
|
||||
prop.name = _class["name"]
|
||||
prop.reference_code = _class["referenceCode"]
|
||||
prop.description = _class.get("description", "")
|
||||
prop.uri = _class["uri"]
|
||||
prop.domain_name = _class["dictionaryName"]
|
||||
prop.domain_namespace_uri = _class["dictionaryUri"]
|
||||
|
||||
@classmethod
|
||||
def get_related_ifc_entities(cls, keyword):
|
||||
active_object = bpy.context.active_object
|
||||
related_ifc_entities = []
|
||||
if len(keyword) < 3:
|
||||
return {"FINISHED"}
|
||||
if filter_ifc_class and active_object:
|
||||
element = ifc.get_entity(active_object)
|
||||
if cls.should_filter_ifc_class() and active_object:
|
||||
element = tool.Ifc.get_entity(active_object)
|
||||
if element:
|
||||
related_ifc_entities = [element.is_a()]
|
||||
return related_ifc_entities
|
||||
|
||||
@classmethod
|
||||
def fill_class_prop(cls, prop, _class: dict):
|
||||
prop.name = _class["name"]
|
||||
prop.reference_code = _class["referenceCode"]
|
||||
prop.description = _class.get("description", "")
|
||||
prop.uri = _class["uri"]
|
||||
prop.domain_name = _class["dictionaryName"]
|
||||
prop.domain_namespace_uri = _class["dictionaryUri"]
|
||||
|
||||
@classmethod
|
||||
def get_active_class_data(cls, prop, client):
|
||||
prop.classification_psets.clear()
|
||||
def get_active_class_data(cls, client):
|
||||
prop = bpy.context.scene.BIMBSDDProperties
|
||||
bsdd_classification = prop.classifications[prop.active_classification_index]
|
||||
if not bsdd_classification:
|
||||
return {}
|
||||
return client.get_class(bsdd_classification.uri)
|
||||
|
||||
@classmethod
|
||||
@@ -72,7 +114,8 @@ class Bsdd(blenderbim.core.tool.Bsdd):
|
||||
return psets
|
||||
|
||||
@classmethod
|
||||
def create_classification_psets(cls, props, pset_dict: dict):
|
||||
def create_class_psets(cls, pset_dict: dict):
|
||||
props = bpy.context.scene.BIMBSDDProperties
|
||||
data_type_map = {
|
||||
"String": "string",
|
||||
"Real": "float",
|
||||
@@ -89,3 +132,9 @@ class Bsdd(blenderbim.core.tool.Bsdd):
|
||||
new2.data_type = "enum"
|
||||
else:
|
||||
new2.data_type = data_type_map[data["data_type"]]
|
||||
|
||||
@classmethod
|
||||
def set_active_bsdd(cls, name, uri):
|
||||
props = bpy.context.scene.BIMBSDDProperties
|
||||
props.active_domain = name
|
||||
props.active_uri = uri
|
||||
|
||||
Reference in New Issue
Block a user