Commit 287be21a authored by John Tourtellott's avatar John Tourtellott

Update export panel to be more project-friendly

Also change "model_manager" to "model_resource"
parent 4e036753
......@@ -44,7 +44,11 @@ class Export(smtk.operation.Operation):
return smtk.operation.Operation.ableToOperate(self)
def operateInternal(self):
success = ExportCMB(self.parameters(), self.log)
try:
success = ExportCMB(self)
except:
print('Error', self.log().convertToString())
raise
# Return with success
result = self.createResult(smtk.operation.Operation.Outcome.SUCCEEDED)
......@@ -84,7 +88,7 @@ class Export(smtk.operation.Operation):
ExportScope = type('ExportScope', (object,), dict())
# ---------------------------------------------------------------------
def ExportCMB(operator_spec, log):
def ExportCMB(export_op):
'''Entry function, called by operator to write export files
Returns boolean indicating success
......@@ -92,34 +96,39 @@ def ExportCMB(operator_spec, log):
----------
spec: Attribute Resource specifying the export operation
'''
print 'Enter ExportCMB()', operator_spec, log
print 'Enter ExportCMB()', export_op
reload(utils)
# Initialize scope instance to store spec values and other info
scope = ExportScope()
scope.logger = log
scope.export_att = operator_spec
scope.sim_atts = smtk.attribute.Resource.CastTo(operator_spec.find('attributes').value())
scope.logger = export_op.log()
scope.export_att = export_op.parameters()
scope.sim_atts = smtk.attribute.Resource.CastTo(scope.export_att.find('attributes').value())
if scope.sim_atts is None:
msg = 'ERROR - No simlation attributes'
print msg
raise Exception(msg)
model_resource = smtk.model.Resource.CastTo(operator_spec.find('model').value())
if model_resource is None:
# Get model resource
model_entity = smtk.model.Entity.CastTo(scope.export_att.find('model').objectValue(0))
scope.model_resource = smtk.model.Resource.CastTo(model_entity.resource())
if scope.model_resource is None:
msg = 'ERROR - No model'
print msg
raise Exception(msg)
scope.model_manager = model_resource
scope.model_path = model_resource.location()
scope.model_file = os.path.basename(scope.model_path)
print(msg)
raise RuntimeError(msg)
# Get model
model_item = scope.export_att.findFile('MeshFile')
if model_item is None:
msg = 'MeshFile item not found -- cannot export'
raise RuntimeError(msg)
scope.model_path = model_item.value(0)
print 'scope.model_path %s' % scope.model_path
export_spec_att = operator_spec
scope.model_file = os.path.basename(scope.model_path)
# Initialize solver list
solver_item = export_spec_att.findString('Analysis')
solver_item = scope.export_att.findString('Analysis')
if solver_item is None:
msg = 'Missing \"Analysis\" item -- cannot export'
scope.logger.addError(msg)
......@@ -129,6 +138,9 @@ def ExportCMB(operator_spec, log):
scope.logger.addError(msg)
raise Exception(msg)
solver_string = solver_item.value(0)
print 'solver_string:', solver_string
scope.solver_list = solver_string.split('.')
......@@ -148,14 +160,19 @@ def ExportCMB(operator_spec, log):
# # And save for later
# scope.domain_source = source_item.value(0)
folder_item = export_spec_att.findDirectory('OutputFolder')
# Get output folder
folder_item = scope.export_att.findDirectory('OutputFolder')
if folder_item is None or not folder_item.isSet(0):
msg = 'Output folder not set -- cannot export'
scope.logger.addError(msg)
raise Exception(msg)
scope.output_folder = folder_item.value(0)
# Create output folder if needed
if not os.path.exists(scope.output_folder):
os.makedirs(scope.output_folder)
file_prefix_item = export_spec_att.findString('OutputFilePrefix')
# Get output file prefix
file_prefix_item = scope.export_att.findString('OutputFilePrefix')
if file_prefix_item is None or not file_prefix_item.isSet(0):
msg = 'Output file prefix not set -- cannot export'
scope.logger.addError(msg)
......@@ -264,7 +281,7 @@ def ExportCMB(operator_spec, log):
# (else)
# Check for NERSCSimulation item
sim_item = export_spec_att.find('NERSCSimulation')
sim_item = scope.export_att.find('NERSCSimulation')
if sim_item is not None and sim_item.isEnabled():
# Import nersc module (only when needed)
from internal.writers import nersc
......
<?xml version="1.0"?>
<SMTK_AttributeResource Version="3">
<Definitions>
<AttDef Type="ace3p-export" BaseType="operation" Label="Export to ACE3P">
<AttDef Type="ace3p-export" BaseType="operation" Label="Export to ACE3P" Version="1">
<BriefDescription>
Write ACE3P input file for selected program.
</BriefDescription>
<DetailedDescription>
Todo
</DetailedDescription>
<ItemDefinitions>
<Resource Name="model" Label="Model">
<Component Name="model" Label="Model" LockType="DoNotLock">
<Accepts>
<Resource Name="smtk::model::Resource"/>
<Resource Name="smtk::model::Resource" Filter="model" />
</Accepts>
</Resource>
</Component>
<Resource Name="attributes" Label="Attributes">
<Accepts>
<Resource Name="smtk::attribute::Resource"/>
</Accepts>
</Resource>
<File Name="MeshFile" Label="Mesh File" ShouldExist="True"
FileFilters="Exodus files (*.exo *.ex2 *.gen);;NetCDf files (*.ncdf);; All files (*.*)" Version="0"/>
<String Name="Analysis" Label="ACE3P Analysis" Version="0">
<ChildrenDefinitions>
<Directory Name="OutputFolder" Label="Export Folder" Version="0">
......
......@@ -260,7 +260,7 @@ class Track3PWriter(basewriter.BaseWriter):
ent_ref = model_ent_item.value(i)
ent = ent_ref.entity()
prop_idlist = self.scope.model_manager.integerProperty(ent, 'pedigree id')
prop_idlist = self.scope.model_resource.integerProperty(ent, 'pedigree id')
#print 'idlist', idlist
if prop_idlist:
#scope.output.write(' %d' % idlist[0])
......
......@@ -11,14 +11,14 @@ import smtk.model
def get_model_info(scope):
'''DEPRECATED Finds/updates model-related info on input scope object:
* scope.model_manager
* scope.model_resource
* scope.model_ent
* scope.model_file
* scope.model_path
'''
scope.model_manager = scope.sim_atts.refModelResource()
scope.model_resource = scope.sim_atts.refModelResource()
mask = int(smtk.model.MODEL_ENTITY)
model_ents = scope.model_manager.entitiesMatchingFlags(mask, True)
model_ents = scope.model_resource.entitiesMatchingFlags(mask, True)
#print 'model_ents', model_ents
if not model_ents:
msg = 'No model - cannot export'
......@@ -33,7 +33,7 @@ def get_model_info(scope):
# Get path to native model from string properties
# that *should* be on the model
urls = scope.model_manager.stringProperty(scope.model_ent, 'url')
urls = scope.model_resource.stringProperty(scope.model_ent, 'url')
if not urls:
msg = 'Model has to string property \"url\"'
print 'ERROR: %s' % msg
......@@ -51,7 +51,7 @@ def get_model_info(scope):
scope.model_path = url
else:
# Path to native model is relative to .smtk model file
smtk_urls = scope.model_manager.stringProperty(
smtk_urls = scope.model_resource.stringProperty(
scope.model_ent, 'smtk_url')
if not smtk_urls:
msg = 'Model has no string property \"smtk_url\". Cannot get path to native model'
......@@ -105,7 +105,7 @@ def get_entity_ids(scope, model_entity_item):
continue
ent = model_entity_item.objectValue(i)
prop_idlist = scope.model_manager.integerProperty(ent.id(), 'pedigree id')
prop_idlist = scope.model_resource.integerProperty(ent.id(), 'pedigree id')
if prop_idlist:
ent_idlist.append(prop_idlist[0])
......
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