Commit 82783614 authored by John Tourtellott's avatar John Tourtellott
Browse files

Add utils.passes_categories() to handle recent smtk API change

* item.isMemberOf() has been removed
* item.categories().passes() is the new logic
* ditto for attribute
parent 29ffb77d
......@@ -377,7 +377,7 @@ def write_boundarycondition(scope):
# Check for sigma and frequency items
added_text = None
sigma_item = att.findDouble('Sigma')
if sigma_item is not None and sigma_item.isMemberOf(scope.categories):
if sigma_item is not None and utils.passes_categories(sigma_item, scope.categories):
sigma = sigma_item.value(0)
line1 = ' ReferenceNumber: %s\n' % ent_string
line2 = ' Sigma: %g\n' % sigma
......@@ -385,7 +385,7 @@ def write_boundarycondition(scope):
# Frequency only set when Sigma is set (T3P Impedance)
freq_item = att.findDouble('Frequency')
if freq_item is not None and freq_item.isMemberOf(scope.categories):
if freq_item is not None and utils.passes_categories(freq_item, scope.categories):
freq = freq_item.value(0)
line3 = ' Frequency: %d\n' % freq
added_text += line3
......@@ -454,7 +454,7 @@ def write_materials(scope):
for item_info in items_todo:
name, label = item_info
item = att.findDouble(name)
if item and item.isEnabled() and item.isMemberOf(scope.categories):
if item and item.isEnabled() and utils.passes_categories(item, scope.categories):
value = item.value(0)
scope.output.write(' %s: %g\n' % (label, value))
......@@ -725,7 +725,7 @@ def write_monitor(scope):
['Point', 'TimeStart', 'TimeEnd', 'TimeStep', 'StartContour', 'EndContour', 'Smax']
for item_type in item_type_list:
item = att.find(item_type)
if item is None or not item.isMemberOf(scope.categories):
if item is None or not utils.passes_categories(item, scope.categories):
continue
if not item.isEnabled():
continue
......@@ -852,7 +852,7 @@ def write_postprocess(scope):
att = att_list[0]
# Not all solvers use PostProcess
if not att.isMemberOf(scope.categories):
if not utils.passes_categories(att, scope.categories):
return
print('Write PostProcess')
......
......@@ -7,6 +7,7 @@ import os
from . import cardformat
reload(cardformat)
from .cardformat import CardFormat
from . import utils
import smtk
......@@ -124,7 +125,7 @@ class BaseWriter(object):
if attribute_item.name() in set(skip_list):
return False
if not attribute_item.isMemberOf(self.scope.categories):
if not utils.passes_categories(attribute_item, self.scope.categories):
return False
if not attribute_item.isEnabled():
return False
......
......@@ -38,7 +38,7 @@ class CardFormat:
'''
# Check categories
if not item.isMemberOf(scope.categories):
if not utils.passes_categories(item, scope.categories):
return False
# Write void type
......
......@@ -272,7 +272,7 @@ class Tem3PWriter(basewriter.BaseWriter):
for att in att_list:
# Filter by cateogry
if not att.isMemberOf(self.scope.categories):
if not utils.passes_categories(att, scope.categories):
continue
att_type = att.type()
......
......@@ -7,6 +7,24 @@ import smtk
import smtk.model
# ---------------------------------------------------------------------
def passes_categories(item, categories):
"""Backward- and list/set-compatible category check
The isMemberOf() method was deleted early Jan 2020.
There is also some uncertainty whether the API argument
should be a list or set.
"""
if hasattr(item, 'isMemberOf'):
if isinstance(categories, list):
return item.isMemberOf(categories)
# (else)
return item.isMemberOf(list(categories))
elif isinstance(categories, set):
return item.categories().passes(categories)
else:
return item.categories().passes(set(categories))
# ---------------------------------------------------------------------
def get_model_info(scope):
'''DEPRECATED Finds/updates model-related info on input scope object:
......
Supports Markdown
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