Skip to content

Commit

Permalink
add checkboxes for boolean flags in model editor
Browse files Browse the repository at this point in the history
  • Loading branch information
tsole0 committed Sep 9, 2024
1 parent dc0df1c commit 4e6e69e
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 15 deletions.
6 changes: 6 additions & 0 deletions src/sas/qtgui/Utilities/PluginDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ def addSignals(self):
self.sendNewIqSignal.connect(lambda iq: self.txtFunction.setPlainText(iq))
self.sendNewFormVolumeSignal.connect(lambda form_volume: self.txtFormVolumeFunction.setPlainText(form_volume))

#Boolean flags
self.chkSingle.clicked.connect(self.modelModified.emit)
self.chkOpenCL.clicked.connect(self.modelModified.emit)
self.chkStructure.clicked.connect(self.modelModified.emit)
self.chkFQ.clicked.connect(self.modelModified.emit)

def onPluginNameChanged(self):
"""
Respond to changes in plugin name
Expand Down
60 changes: 45 additions & 15 deletions src/sas/qtgui/Utilities/TabbedModelEditor.py
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,48 @@ def generatePyModel(self, model, fname):
"""
generate model from the current plugin state
"""

def formatPythonFlags():
"""Get python flags for model and format into text"""
header = "\n# Optional flags (can be removed). Read documentation by pressing 'Help' for more information.\n\n"
flag_string = header
checkbox_defaults = {
'chkSingle': True,
'chkOpenCL': False,
'chkStructure': False,
'chkFQ': False
}
# Get the values of the checkboxes
checkbox_values = {}
for name in checkbox_defaults.keys():
checkbox_values[name] = getattr(self.plugin_widget, name).isChecked()
# Create output string
for name in checkbox_values.keys():
# Check to see if the checkbox is set to a non-default value
if checkbox_defaults[name] != checkbox_values[name]:
match name:
case 'chkSingle':
flag_string += """\
# single = True indicates that the model can be run using single precision floating point values. Defaults to True.
single = True\n\n"""
case 'chkOpenCL':
flag_string += """\
# opencl = False indicates that the model should not be run using OpenCL. Defaults to False.
opencl = False\n\n"""
case 'chkStructure':
flag_string += """\
# structure_factor = False indicates that the model cannot be used as a structure factor to account for interactions between particles. Defaults to False.
structure_factor = False\n\n"""
case 'chkFQ':
flag_string += """\
# have_fq = False indicates that the model does not define F(Q) calculations in a linked C model. Note that F(Q) calculations are only necessary for accomadating beta approximation. Defaults to False.
have_fq = False\n\n"""

if flag_string == header:
# If no flags are set, do not include the header
flag_string = ""
return flag_string.rstrip() + "\n" # Remove trailing newline

name = model['filename']
if not name:
model['filename'] = fname
Expand All @@ -808,7 +850,8 @@ def generatePyModel(self, model, fname):
model_text = CUSTOM_TEMPLATE.format(name = name,
title = 'User model for ' + name,
description = desc_str,
date = datetime.datetime.now().strftime('%Y-%m-%d')
date = datetime.datetime.now().strftime('%Y-%m-%d'),
flags= formatPythonFlags()
)

# Write out parameters
Expand Down Expand Up @@ -970,20 +1013,7 @@ def visit_FunctionDef(self, node):
name = "{name}"
title = "{title}"
description = """{description}"""
# Optional flags (can be removed). Read documentation by pressing 'Help' for more information.
# single = True indicates that the model can be run using single precision floating point values. Defaults to True.
single = True
# opencl = False indicates that the model should not be run using OpenCL. Defaults to False.
opencl = False
# structure_factor = False indicates that the model cannot be used as a structure factor to account for interactions between particles. Defaults to False.
structure_factor = False
# have_fq = False indicates that the model does not define F(Q) calculations in a linked C model. Note that F(Q) calculations are only necessary for accomadating beta approximation. Defaults to False.
have_fq = False
{flags}
'''

ER_VR_TEMPLATE = '''\
Expand Down
40 changes: 40 additions & 0 deletions src/sas/qtgui/Utilities/UI/PluginDefinitionUI.ui
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,46 @@ li.checked::marker { content: "\2612"; }
</layout>
</widget>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="boolGroupBox">
<property name="title">
<string>Model Options</string>
</property>
<layout class="QGridLayout" name="gridLayout_8">
<item row="1" column="0">
<widget class="QCheckBox" name="chkOpenCL">
<property name="text">
<string>Can use OpenCL</string>
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QCheckBox" name="chkSingle">
<property name="text">
<string>Can use single precision floating point values</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="chkFQ">
<property name="text">
<string>Has F(Q) calculations</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="chkStructure">
<property name="text">
<string>Can be used as structure factor</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<tabstops>
Expand Down

0 comments on commit 4e6e69e

Please sign in to comment.