Commit 59ef2e24 authored by John Tourtellott's avatar John Tourtellott

Update the python writing scripts to use the new model & mesh items

Includes some fixes based on an updated AdHSurfaceWater regression test
parent 488c2ad4
...@@ -10,14 +10,14 @@ ...@@ -10,14 +10,14 @@
<SMTK_AttributeSystem Version="2"> <SMTK_AttributeSystem Version="2">
<Definitions> <Definitions>
<AttDef Type="ExportSpec" BaseType="" Version="0" Unique="true"> <AttDef Type="ExportSpec" BaseType="" Version="0" Unique="true">
<AssociationsDef Name="model" Label="Model" Version="0" <AssociationsDef Name="model" Label="Model" Version="0" NumberOfRequiredValues="1">
NumberOfRequiredValues="1">
<MembershipMask>model</MembershipMask> <MembershipMask>model</MembershipMask>
</AssociationsDef> </AssociationsDef>
<ItemDefinitions> <ItemDefinitions>
<String Name="AnalysisTypes" Label="Analysis Types" AdvanceLevel="99" Version="0" <String Name="AnalysisTypes" Label="Analysis Types" AdvanceLevel="99" Version="0"
Extensible="true" NumberOfRequiredValues="1"/> Extensible="true" NumberOfRequiredValues="0"/>
<MeshEntity Name="mesh" Label="Mesh" Version="0" NumberOfRequiredValues="1" /> <MeshEntity Name="mesh" Label="Mesh" Version="0" NumberOfRequiredValues="1"
Optional="true" IsEnabledByDefault="false" />
<Directory Name="OutputDirectory" Label="Output Directory" Version="1" NumberOfRequiredValues="1" /> <Directory Name="OutputDirectory" Label="Output Directory" Version="1" NumberOfRequiredValues="1" />
<String Name="FileBase" Label="FileName Base" Version="1" NumberOfRequiredValues="1"> <String Name="FileBase" Label="FileName Base" Version="1" NumberOfRequiredValues="1">
<BriefDescription>Common base name for output files (.2dm, .bc)</BriefDescription> <BriefDescription>Common base name for output files (.2dm, .bc)</BriefDescription>
......
...@@ -145,8 +145,9 @@ def ExportCMB(spec): ...@@ -145,8 +145,9 @@ def ExportCMB(spec):
print 'Analysis types:', scope.analysis_types print 'Analysis types:', scope.analysis_types
if not scope.analysis_types: if not scope.analysis_types:
msg = 'No analysis types selected' msg = 'No analysis types selected'
print 'WARNING:', msg print 'ERROR:', msg
scope.logger.addWarning(msg) scope.logger.addError(msg)
return False
else: else:
print 'Categories:', sorted(list(scope.categories)) print 'Categories:', sorted(list(scope.categories))
......
...@@ -138,32 +138,46 @@ def init_scope(spec): ...@@ -138,32 +138,46 @@ def init_scope(spec):
att = att_list[0] att = att_list[0]
# Get mesh # Get model & mesh
item = att.find('mesh') model_ent_item = att.associations()
if item is None: mesh_item = att.find('mesh')
raise Exception('Mesh attribute missing') if mesh_item:
mesh_item = smtk.attribute.to_concrete(mesh_item)
mesh_item = smtk.attribute.to_concrete(item) if mesh_item and mesh_item.isEnabled() and mesh_item.numberOfValues() > 0:
m = mesh_item.numberOfValues() meshset = mesh_item.value(0)
if m == 0: scope.mesh_collection = meshset.collection()
raise Exception('WARNING: No mesh specified') print 'mesh', scope.mesh_collection
meshset = mesh_item.value(0) # Get model that mesh is classified on
scope.mesh_collection = meshset.collection() model_manager = scope.sim_atts.refModelManager()
print 'mesh', scope.mesh_collection model_uuid = scope.mesh_collection.associatedModel()
scope.model = smtk.model.Model(model_manager, model_uuid)
# Get model print 'model', scope.model
model_manager = scope.sim_atts.refModelManager() elif model_ent_item and model_ent_item.numberOfValues() > 0:
model_uuid = scope.mesh_collection.associatedModel() model_ent = model_ent_item.value(0)
scope.model = smtk.model.Model(model_manager, model_uuid) scope.model = smtk.model.Model(model_ent)
print 'model', scope.model print 'model', scope.model
print 'Using model\'s internal geometry for the mesh'
converter = smtk.io.ModelToMesh()
#print 'converter', converter
scope.mesh_collection = converter(scope.model)
print 'mesh', scope.mesh_collection
else:
raise Exception('WARNING: No model or mesh specified')
if scope.mesh_collection is None:
raise Exception('ERROR: unable to obtain mesh object')
# Get mesh points - only from 2D entities since that is what gets
# written to the .2dm file
scope.mesh_points = scope.mesh_collection.cells(smtk.mesh.Dims2).points()
# Assign unique ids to all model cells # Assign unique ids to all model cells
# (although only *required* for face entities) # (although only *required* for face entities)
matid = 'id' matid = 'id'
#next_id = assign_model_entity_ids(model_manager, 0, matid, 1) #next_id = assign_model_entity_ids(model_manager, 0, matid, 1)
#next_id = assign_model_entity_ids(model_manager, 1, matid, next_id) #next_id = assign_model_entity_ids(model_manager, 1, matid, next_id)
next_id = assign_model_entity_ids(model_manager, 2, matid, 1) next_id = assign_model_entity_ids(scope.model.manager(), 2, matid, 1)
scope.matid_property_name = matid scope.matid_property_name = matid
# Output filebase # Output filebase
...@@ -274,8 +288,7 @@ def write_section(scope, att_type): ...@@ -274,8 +288,7 @@ def write_section(scope, att_type):
# Sort list by id # Sort list by id
att_list.sort(key=lambda x: x.id()) att_list.sort(key=lambda x: x.id())
for att in att_list: for att in att_list:
# if att_type == 'Constituent': #print 'att', att.name()
# print 'att', att.name(), 'mask'
format_list = scope.format_table.get(att.type()) format_list = scope.format_table.get(att.type())
if format_list is None: if format_list is None:
msg = 'empty format list for %s' % att.type() msg = 'empty format list for %s' % att.type()
...@@ -293,7 +306,7 @@ def write_section(scope, att_type): ...@@ -293,7 +306,7 @@ def write_section(scope, att_type):
# (else) # (else)
model_ent_item = att.associations() model_ent_item = att.associations()
if model_ent_item is None: if (model_ent_item is None) or (model_ent_item.numberOfValues() == 0):
print 'Expecting model association for attribute', att.name() print 'Expecting model association for attribute', att.name()
continue continue
...@@ -303,9 +316,9 @@ def write_section(scope, att_type): ...@@ -303,9 +316,9 @@ def write_section(scope, att_type):
if att.type() in ['Material', 'SolidMaterial']: if att.type() in ['Material', 'SolidMaterial']:
scope.output.write('! material -- %s\n' % att.name()) scope.output.write('! material -- %s\n' % att.name())
for i in range(model_ent_item.numberOfValues()): # Get id from first model entity
ent_id = model_ent_item.valueAsString(i) ent_id = model_ent_item.valueAsString(0)
ok = write_items(scope, att, format_list, ent_id) ok = write_items(scope, att, format_list, ent_id)
return True return True
...@@ -315,6 +328,8 @@ def render_card(scope, item, card_format, context_id=None, group_index=0): ...@@ -315,6 +328,8 @@ def render_card(scope, item, card_format, context_id=None, group_index=0):
'''Generates one line (card) of output for input item '''Generates one line (card) of output for input item
''' '''
#print 'render_card for item', item.name()
# Initially generate a list of strings # Initially generate a list of strings
output_list = list() output_list = list()
output_list.append(card_format.opcode) output_list.append(card_format.opcode)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment