Refactor properties to have prefix to prevent name clashes with other addons

This commit is contained in:
Dion Moult
2019-10-21 14:56:40 +11:00
parent e2ada7ce90
commit 1bdb64d9e7
4 changed files with 60 additions and 60 deletions
+11 -11
View File
@@ -45,9 +45,9 @@ classes = (
ui.TargetCRS,
ui.Attribute,
ui.Pset,
ui.ObjectProperties,
ui.MaterialProperties,
ui.MeshProperties,
ui.BIMObjectProperties,
ui.BIMMaterialProperties,
ui.BIMMeshProperties,
ui.GISPanel,
ui.BIMPanel,
ui.MVDPanel,
@@ -72,10 +72,10 @@ def register():
bpy.types.Scene.BIMProperties = bpy.props.PointerProperty(type=ui.BIMProperties)
bpy.types.Scene.MapConversion = bpy.props.PointerProperty(type=ui.MapConversion)
bpy.types.Scene.TargetCRS = bpy.props.PointerProperty(type=ui.TargetCRS)
bpy.types.Object.ObjectProperties = bpy.props.PointerProperty(type=ui.ObjectProperties)
bpy.types.Collection.ObjectProperties = bpy.props.PointerProperty(type=ui.ObjectProperties)
bpy.types.Material.MaterialProperties = bpy.props.PointerProperty(type=ui.MaterialProperties)
bpy.types.Mesh.MeshProperties = bpy.props.PointerProperty(type=ui.MeshProperties)
bpy.types.Object.BIMObjectProperties = bpy.props.PointerProperty(type=ui.BIMObjectProperties)
bpy.types.Collection.BIMObjectProperties = bpy.props.PointerProperty(type=ui.BIMObjectProperties)
bpy.types.Material.BIMMaterialProperties = bpy.props.PointerProperty(type=ui.BIMMaterialProperties)
bpy.types.Mesh.BIMMeshProperties = bpy.props.PointerProperty(type=ui.BIMMeshProperties)
def unregister():
for cls in reversed(classes):
@@ -85,10 +85,10 @@ def unregister():
del(bpy.types.Scene.BIMProperties)
del(bpy.types.Scene.MapConversion)
del(bpy.types.Scene.TargetCRS)
del(bpy.types.Object.ObjectProperties)
del(bpy.types.Collection.ObjectProperties)
del(bpy.types.Material.MaterialProperties)
del(bpy.types.Mesh.MeshProperties)
del(bpy.types.Object.BIMObjectProperties)
del(bpy.types.Collection.BIMObjectProperties)
del(bpy.types.Material.BIMMaterialProperties)
del(bpy.types.Mesh.BIMMeshProperties)
if __name__ == "__main__":
register()
@@ -175,11 +175,11 @@ class IfcParser():
def get_object_attributes(self, object):
attributes = { 'Name': self.get_ifc_name(object.name) }
if object.ObjectProperties.attributes.find('GlobalId') == -1:
global_id = object.ObjectProperties.attributes.add()
if object.BIMObjectProperties.attributes.find('GlobalId') == -1:
global_id = object.BIMObjectProperties.attributes.add()
global_id.name = 'GlobalId'
global_id.string_value = ifcopenshell.guid.new()
attributes.update({ a.name: a.string_value for a in object.ObjectProperties.attributes})
attributes.update({ a.name: a.string_value for a in object.BIMObjectProperties.attributes})
return attributes
def get_products(self):
@@ -271,7 +271,7 @@ class IfcParser():
if object.name in self.qtos:
self.rel_defines_by_qto.setdefault(object.name, []).append(product)
for pset in object.ObjectProperties.psets:
for pset in object.BIMObjectProperties.psets:
self.rel_defines_by_pset.setdefault(
'{}/{}'.format(pset.name, pset.file), []).append(product)
@@ -550,8 +550,8 @@ class IfcParser():
'raw_object': object,
'context': context,
'subcontext': subcontext,
'is_wireframe': mesh.MeshProperties.is_wireframe,
'is_swept_solid': mesh.MeshProperties.is_swept_solid,
'is_wireframe': mesh.BIMMeshProperties.is_wireframe,
'is_swept_solid': mesh.BIMMeshProperties.is_swept_solid,
'is_generated': is_generated,
'attributes': { 'Name': mesh.name }
}
@@ -653,7 +653,7 @@ class IfcParser():
'up_axis': object.matrix_world.to_quaternion() @ Vector((0, 0, 1)),
'forward_axis': object.matrix_world.to_quaternion() @ Vector((1, 0, 0)),
'psets': ['{}/{}'.format(pset.name, pset.file) for pset in
object.ObjectProperties.psets],
object.BIMObjectProperties.psets],
'class': self.get_ifc_class(object.name),
'representations': self.get_object_representation_names(object),
'attributes': self.get_object_attributes(object)
@@ -1082,7 +1082,7 @@ class IfcExporter():
def create_styled_item(self, item, representation_item=None):
styles = []
styles.append(self.create_surface_style_rendering(item))
if item['raw'].MaterialProperties.is_external:
if item['raw'].BIMMaterialProperties.is_external:
styles.append(self.file.create_entity('IfcExternallyDefinedSurfaceStyle',
**self.get_material_external_definition(item['raw'])))
surface_style = self.file.createIfcSurfaceStyle(None, 'BOTH', styles)
@@ -1123,9 +1123,9 @@ class IfcExporter():
def get_material_external_definition(self, material):
return {
'Location': material.MaterialProperties.location,
'Identification': material.MaterialProperties.identification if material.MaterialProperties.identification else material.name,
'Name': material.MaterialProperties.name if material.MaterialProperties.name else material.name
'Location': material.BIMMaterialProperties.location,
'Identification': material.BIMMaterialProperties.identification if material.BIMMaterialProperties.identification else material.name,
'Name': material.BIMMaterialProperties.name if material.BIMMaterialProperties.name else material.name
}
def create_colour_rgb(self, colour):
+23 -23
View File
@@ -67,9 +67,9 @@ class SelectGlobalId(bpy.types.Operator):
def execute(self, context):
for object in bpy.context.visible_objects:
index = object.ObjectProperties.attributes.find('GlobalId')
index = object.BIMObjectProperties.attributes.find('GlobalId')
if index != -1 \
and object.ObjectProperties.attributes[index].string_value == bpy.context.scene.BIMProperties.global_id:
and object.BIMObjectProperties.attributes[index].string_value == bpy.context.scene.BIMProperties.global_id:
object.select_set(True)
break
return {'FINISHED'}
@@ -92,18 +92,18 @@ class AssignClass(bpy.types.Operator):
object.name = '{}/{}'.format(
bpy.context.scene.BIMProperties.ifc_class,
object.name)
predefined_type_index = object.ObjectProperties.attributes.find('PredefinedType')
predefined_type_index = object.BIMObjectProperties.attributes.find('PredefinedType')
if predefined_type_index >= 0:
object.ObjectProperties.attributes.remove(predefined_type_index)
object_type_index = object.ObjectProperties.attributes.find('ObjectType')
object.BIMObjectProperties.attributes.remove(predefined_type_index)
object_type_index = object.BIMObjectProperties.attributes.find('ObjectType')
if object_type_index >= 0:
object.ObjectProperties.attributes.remove(object_type_index)
object.BIMObjectProperties.attributes.remove(object_type_index)
if bpy.context.scene.BIMProperties.ifc_predefined_type:
predefined_type = object.ObjectProperties.attributes.add()
predefined_type = object.BIMObjectProperties.attributes.add()
predefined_type.name = 'PredefinedType'
predefined_type.string_value = bpy.context.scene.BIMProperties.ifc_predefined_type # TODO: make it an enum
if bpy.context.scene.BIMProperties.ifc_predefined_type == 'USERDEFINED':
object_type = object.ObjectProperties.attributes.add()
object_type = object.BIMObjectProperties.attributes.add()
object_type.name = 'ObjectType'
object_type.string_value = bpy.context.scene.BIMProperties.ifc_userdefined_type
return {'FINISHED'}
@@ -242,11 +242,11 @@ class AssignPset(bpy.types.Operator):
def execute(self, context):
for object in bpy.context.selected_objects:
index = object.ObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
index = object.BIMObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
if index >= 0:
global_id = object.ObjectProperties.psets[index]
global_id = object.BIMObjectProperties.psets[index]
else:
global_id = object.ObjectProperties.psets.add()
global_id = object.BIMObjectProperties.psets.add()
global_id.name = bpy.context.scene.BIMProperties.pset_name
global_id.file = bpy.context.scene.BIMProperties.pset_file
return {'FINISHED'}
@@ -257,9 +257,9 @@ class UnassignPset(bpy.types.Operator):
def execute(self, context):
for object in bpy.context.selected_objects:
index = object.ObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
index = object.BIMObjectProperties.psets.find(bpy.context.scene.BIMProperties.pset_name)
if index != -1:
object.ObjectProperties.psets.remove(index)
object.BIMObjectProperties.psets.remove(index)
return {'FINISHED'}
class AddPset(bpy.types.Operator):
@@ -268,7 +268,7 @@ class AddPset(bpy.types.Operator):
# This is a temporary measure until we get a better UI
def execute(self, context):
bpy.context.active_object.ObjectProperties.psets.add()
bpy.context.active_object.BIMObjectProperties.psets.add()
return {'FINISHED'}
class RemovePset(bpy.types.Operator):
@@ -277,7 +277,7 @@ class RemovePset(bpy.types.Operator):
pset_index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.active_object.ObjectProperties.psets.remove(self.pset_index)
bpy.context.active_object.BIMObjectProperties.psets.remove(self.pset_index)
return {'FINISHED'}
class GenerateGlobalId(bpy.types.Operator):
@@ -285,11 +285,11 @@ class GenerateGlobalId(bpy.types.Operator):
bl_label = 'Generate GlobalId'
def execute(self, context):
index = bpy.context.active_object.ObjectProperties.attributes.find('GlobalId')
index = bpy.context.active_object.BIMObjectProperties.attributes.find('GlobalId')
if index >= 0:
global_id = bpy.context.active_object.ObjectProperties.attributes[index]
global_id = bpy.context.active_object.BIMObjectProperties.attributes[index]
else:
global_id = bpy.context.active_object.ObjectProperties.attributes.add()
global_id = bpy.context.active_object.BIMObjectProperties.attributes.add()
global_id.name = 'GlobalId'
global_id.data_type = 'string'
global_id.string_value = ifcopenshell.guid.new()
@@ -300,9 +300,9 @@ class AddAttribute(bpy.types.Operator):
bl_label = 'Add Attribute'
def execute(self, context):
if bpy.context.active_object.ObjectProperties.applicable_attributes:
attribute = bpy.context.active_object.ObjectProperties.attributes.add()
attribute.name = bpy.context.active_object.ObjectProperties.applicable_attributes
if bpy.context.active_object.BIMObjectProperties.applicable_attributes:
attribute = bpy.context.active_object.BIMObjectProperties.attributes.add()
attribute.name = bpy.context.active_object.BIMObjectProperties.applicable_attributes
return {'FINISHED'}
class RemoveAttribute(bpy.types.Operator):
@@ -311,7 +311,7 @@ class RemoveAttribute(bpy.types.Operator):
attribute_index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.active_object.ObjectProperties.attributes.remove(self.attribute_index)
bpy.context.active_object.BIMObjectProperties.attributes.remove(self.attribute_index)
return {'FINISHED'}
class AssignSweptSolidProfile(bpy.types.Operator):
@@ -352,7 +352,7 @@ class SelectExternalMaterialDir(bpy.types.Operator):
filepath: bpy.props.StringProperty(subtype="FILE_PATH")
def execute(self, context):
bpy.context.active_object.active_material.MaterialProperties.location = self.filepath
bpy.context.active_object.active_material.BIMMaterialProperties.location = self.filepath
return {'FINISHED'}
def invoke(self, context, event):
+15 -15
View File
@@ -78,26 +78,26 @@ class Pset(bpy.types.PropertyGroup):
name: bpy.props.StringProperty(name="Name")
file: bpy.props.StringProperty(name="File")
class ObjectProperties(bpy.types.PropertyGroup):
class BIMObjectProperties(bpy.types.PropertyGroup):
def getApplicableAttributes(self, context):
if '/' in bpy.context.active_object.name \
and bpy.context.active_object.name.split('/')[0] in ifc_schema.elements:
return [(a['name'], a['name'], '') for a in
ifc_schema.elements[bpy.context.active_object.name.split('/')[0]]['attributes']
if bpy.context.active_object.ObjectProperties.attributes.find(a['name']) == -1]
if bpy.context.active_object.BIMObjectProperties.attributes.find(a['name']) == -1]
return []
attributes: bpy.props.CollectionProperty(name="Attributes", type=Attribute)
psets: bpy.props.CollectionProperty(name="Psets", type=Pset)
applicable_attributes: bpy.props.EnumProperty(items=getApplicableAttributes, name="Attribute Names")
class MaterialProperties(bpy.types.PropertyGroup):
class BIMMaterialProperties(bpy.types.PropertyGroup):
is_external: bpy.props.BoolProperty(name="Has External Definition")
location: bpy.props.StringProperty(name="Location")
identification: bpy.props.StringProperty(name="Identification")
name: bpy.props.StringProperty(name="Name")
class MeshProperties(bpy.types.PropertyGroup):
class BIMMeshProperties(bpy.types.PropertyGroup):
is_wireframe: bpy.props.BoolProperty(name="Is Wireframe")
is_swept_solid: bpy.props.BoolProperty(name="Is Swept Solid")
@@ -118,30 +118,30 @@ class ObjectPanel(bpy.types.Panel):
layout.label(text="Attributes:")
row = layout.row(align=True)
row.prop(bpy.context.active_object.ObjectProperties, 'applicable_attributes', text='')
row.prop(bpy.context.active_object.BIMObjectProperties, 'applicable_attributes', text='')
row.operator('bim.add_attribute')
for index, attribute in enumerate(bpy.context.active_object.ObjectProperties.attributes):
for index, attribute in enumerate(bpy.context.active_object.BIMObjectProperties.attributes):
row = layout.row(align=True)
row.prop(attribute, 'name', text='')
row.prop(attribute, 'string_value', text='')
row.operator('bim.remove_attribute', icon='CANCEL', text='').attribute_index = index
row = layout.row()
row.prop(bpy.context.active_object.ObjectProperties, 'attributes')
row.prop(bpy.context.active_object.BIMObjectProperties, 'attributes')
layout.label(text="Property Sets:")
row = layout.row()
row.operator('bim.add_pset')
for index, pset in enumerate(bpy.context.active_object.ObjectProperties.psets):
for index, pset in enumerate(bpy.context.active_object.BIMObjectProperties.psets):
row = layout.row(align=True)
row.prop(pset, 'name', text='')
row.prop(pset, 'file', text='')
row.operator('bim.remove_pset', icon='CANCEL', text='').pset_index = index
row = layout.row()
row.prop(bpy.context.active_object.ObjectProperties, 'psets')
row.prop(bpy.context.active_object.BIMObjectProperties, 'psets')
class MeshPanel(bpy.types.Panel):
bl_label = 'IFC Representations'
@@ -155,9 +155,9 @@ class MeshPanel(bpy.types.Panel):
return
layout = self.layout
row = layout.row()
row.prop(bpy.context.active_object.data.MeshProperties, 'is_wireframe')
row.prop(bpy.context.active_object.data.BIMMeshProperties, 'is_wireframe')
row = layout.row()
row.prop(bpy.context.active_object.data.MeshProperties, 'is_swept_solid')
row.prop(bpy.context.active_object.data.BIMMeshProperties, 'is_swept_solid')
row = layout.row(align=True)
row.operator('bim.assign_swept_solid_profile')
row.operator('bim.assign_swept_solid_extrusion')
@@ -174,14 +174,14 @@ class MaterialPanel(bpy.types.Panel):
return
layout = self.layout
row = layout.row()
row.prop(bpy.context.active_object.active_material.MaterialProperties, 'is_external')
row.prop(bpy.context.active_object.active_material.BIMMaterialProperties, 'is_external')
row = layout.row(align=True)
row.prop(bpy.context.active_object.active_material.MaterialProperties, 'location')
row.prop(bpy.context.active_object.active_material.BIMMaterialProperties, 'location')
row.operator('bim.select_external_material_dir', icon="FILE_FOLDER", text="")
row = layout.row()
row.prop(bpy.context.active_object.active_material.MaterialProperties, 'identification')
row.prop(bpy.context.active_object.active_material.BIMMaterialProperties, 'identification')
row = layout.row()
row.prop(bpy.context.active_object.active_material.MaterialProperties, 'name')
row.prop(bpy.context.active_object.active_material.BIMMaterialProperties, 'name')
class GISPanel(bpy.types.Panel):
bl_label = 'IFC Georeferencing'