Add experimental UI to manage geometric contexts

This commit is contained in:
Dion Moult
2019-12-04 17:49:28 +11:00
parent 2d495e6124
commit f7116d70e7
4 changed files with 141 additions and 0 deletions
@@ -59,6 +59,12 @@ classes = (
operator.FetchLibraryInformation,
operator.FetchExternalMaterial,
operator.FetchObjectPassport,
operator.AddContext,
operator.RemoveContext,
operator.AddSubcontext,
operator.RemoveSubcontext,
prop.Subcontext,
prop.Context,
prop.BIMProperties,
prop.BIMLibrary,
prop.MapConversion,
@@ -73,6 +79,7 @@ classes = (
prop.SweptSolid,
prop.BIMMeshProperties,
ui.BIM_PT_bim,
ui.BIM_PT_context,
ui.BIM_PT_qa,
ui.BIM_PT_library,
ui.BIM_PT_gis,
@@ -706,3 +706,48 @@ class FetchObjectPassport(bpy.types.Operator):
directory=os.path.join(uri, 'Mesh')
)
bpy.context.active_object.data = bpy.data.meshes[identification]
class AddContext(bpy.types.Operator):
bl_idname = 'bim.add_context'
bl_label = 'Add Context'
def execute(self, context):
context = bpy.context.scene.BIMProperties.contexts.add()
context.name = bpy.context.scene.BIMProperties.available_contexts
return {'FINISHED'}
class RemoveContext(bpy.types.Operator):
bl_idname = 'bim.remove_context'
bl_label = 'Remove Context'
index: bpy.props.IntProperty()
def execute(self, context):
bpy.context.scene.BIMProperties.contexts.remove(self.index)
return {'FINISHED'}
class AddSubcontext(bpy.types.Operator):
bl_idname = 'bim.add_subcontext'
bl_label = 'Add Subcontext'
context_index: bpy.props.IntProperty()
def execute(self, context):
subcontext = bpy.context.scene.BIMProperties.contexts[self.context_index].subcontexts.add()
subcontext.name = bpy.context.scene.BIMProperties.available_subcontexts
subcontext.target_view = bpy.context.scene.BIMProperties.available_target_views
return {'FINISHED'}
class RemoveSubcontext(bpy.types.Operator):
bl_idname = 'bim.remove_subcontext'
bl_label = 'Remove Context'
indexes: bpy.props.StringProperty()
def execute(self, context):
context_index, subcontext_index = self.indexes.split('-')
context_index = int(context_index)
subcontext_index = int(subcontext_index)
bpy.context.scene.BIMProperties.contexts[context_index].subcontexts.remove(subcontext_index)
return {'FINISHED'}
+53
View File
@@ -2,6 +2,7 @@ import json
import os
import csv
from pathlib import Path
from . import export_ifc
from bpy.types import PropertyGroup
from bpy.props import (
StringProperty,
@@ -29,6 +30,9 @@ classification_enum = []
reference_enum = []
attributes_enum = []
documents_enum = []
contexts_enum = []
subcontexts_enum = []
target_views_enum = []
def getIfcPredefinedTypes(self, context):
global types_enum
@@ -64,11 +68,13 @@ def getPsetNames(self, context):
psetnames_enum.extend([(f, f, '') for f in files])
return psetnames_enum
def refreshPsetFiles(self, context):
global psetfiles_enum
psetfiles_enum.clear()
getPsetFiles(self, context)
def getPsetFiles(self, context):
global psetfiles_enum
if len(psetfiles_enum) < 1:
@@ -78,6 +84,7 @@ def getPsetFiles(self, context):
psetfiles_enum.extend([(f.replace('.csv', ''), f.replace('.csv', ''), '') for f in files])
return psetfiles_enum
def getClassifications(self, context):
global classification_enum
if len(classification_enum) < 1:
@@ -89,11 +96,13 @@ def getClassifications(self, context):
classification_enum.extend([(str(i), d[index], '') for i, d in enumerate(data)])
return classification_enum
def refreshReferences(self, context):
global reference_enum
reference_enum.clear()
getReferences(self, context)
def getReferences(self, context):
global reference_enum
if len(reference_enum) < 1:
@@ -106,6 +115,7 @@ def getReferences(self, context):
d[2] == self.classification.strip()])
return reference_enum
def getApplicableAttributes(self, context):
global attributes_enum
attributes_enum.clear()
@@ -116,6 +126,7 @@ def getApplicableAttributes(self, context):
if self.attributes.find(a['name']) == -1])
return attributes_enum
def getApplicableDocuments(self, context):
global documents_enum
documents_enum.clear()
@@ -126,6 +137,43 @@ def getApplicableDocuments(self, context):
return documents_enum
def getContexts(self, context):
global contexts_enum
contexts_enum.clear()
for context in export_ifc.IfcExportSettings().contexts:
contexts_enum.append((context, context, ''))
return contexts_enum
def getSubcontexts(self, context):
global subcontexts_enum
subcontexts_enum.clear()
# TODO: allow override of generated subcontexts?
subcontexts = export_ifc.IfcExportSettings().subcontexts
for subcontext in subcontexts:
subcontexts_enum.append((subcontext, subcontext, ''))
return subcontexts_enum
def getTargetViews(self, context):
global target_views_enum
target_views_enum.clear()
for target_view in export_ifc.IfcExportSettings().target_views:
target_views_enum.append((target_view, target_view, ''))
return target_views_enum
class Subcontext(PropertyGroup):
name: StringProperty(name='Name')
target_view: StringProperty(name='Target View')
class Context(PropertyGroup):
name: StringProperty(name='Name')
foobar: StringProperty(name='foobar')
subcontexts: CollectionProperty(name='Subcontexts', type=Subcontext)
class BIMProperties(PropertyGroup):
schema_dir: StringProperty(default=os.path.join(cwd ,'schema') + os.path.sep, name="Schema Directory")
data_dir: StringProperty(default=os.path.join(cwd, 'data') + os.path.sep, name="Data Directory")
@@ -152,6 +200,11 @@ class BIMProperties(PropertyGroup):
aggregate_name: StringProperty(name="Aggregate Name")
classification: EnumProperty(items=getClassifications, name="Classification", update=refreshReferences)
reference: EnumProperty(items=getReferences, name="Reference")
contexts: CollectionProperty(name="Contexts", type=Context)
available_contexts: EnumProperty(items=getContexts, name="Available Contexts")
available_subcontexts: EnumProperty(items=getSubcontexts, name="Available Subcontexts")
available_target_views: EnumProperty(items=getTargetViews, name="Available Target Views")
class MapConversion(PropertyGroup):
eastings: StringProperty(name="Eastings")
+36
View File
@@ -182,6 +182,42 @@ class BIM_PT_gis(Panel):
layout.row().prop(scene.TargetCRS, 'map_unit')
class BIM_PT_context(Panel):
bl_label = "Geometric Representation Contexts"
bl_idname = "BIM_PT_context"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "scene"
def draw(self, context):
layout = self.layout
scene = context.scene
props = scene.BIMProperties
row = layout.row(align=True)
row.prop(props, 'available_contexts', text='')
row.operator('bim.add_context', icon='ADD', text='')
for index, context in enumerate(props.contexts):
layout.label(text="Geometric Representation Context:")
row = layout.row(align=True)
row.prop(context, 'name', text='')
row.operator('bim.remove_context', icon='X', text='').index = index
row = layout.row(align=True)
row.prop(props, 'available_subcontexts', text='')
row.prop(props, 'available_target_views', text='')
row.operator('bim.add_subcontext', icon='ADD', text='').context_index = index
for subcontext_index, subcontext in enumerate(context.subcontexts):
row = layout.row(align=True)
row.prop(subcontext, 'name', text='')
row.prop(subcontext, 'target_view', text='')
row.operator('bim.remove_subcontext', icon='X', text='').indexes = '{}-{}'.format(index, subcontext_index)
class BIM_PT_bim(Panel):
bl_label = "Building Information Modeling"
bl_idname = "BIM_PT_bim"