From 4e6e69e320af58a1f1ca8bacb7caae08d974b6b2 Mon Sep 17 00:00:00 2001 From: tsole0 Date: Mon, 9 Sep 2024 14:25:07 -0400 Subject: [PATCH] add checkboxes for boolean flags in model editor --- src/sas/qtgui/Utilities/PluginDefinition.py | 6 ++ src/sas/qtgui/Utilities/TabbedModelEditor.py | 60 ++++++++++++++----- .../qtgui/Utilities/UI/PluginDefinitionUI.ui | 40 +++++++++++++ 3 files changed, 91 insertions(+), 15 deletions(-) diff --git a/src/sas/qtgui/Utilities/PluginDefinition.py b/src/sas/qtgui/Utilities/PluginDefinition.py index 2a575a516e..908dc4798c 100644 --- a/src/sas/qtgui/Utilities/PluginDefinition.py +++ b/src/sas/qtgui/Utilities/PluginDefinition.py @@ -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 diff --git a/src/sas/qtgui/Utilities/TabbedModelEditor.py b/src/sas/qtgui/Utilities/TabbedModelEditor.py index 003f99ab5f..3844aa71e8 100644 --- a/src/sas/qtgui/Utilities/TabbedModelEditor.py +++ b/src/sas/qtgui/Utilities/TabbedModelEditor.py @@ -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 @@ -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 @@ -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 = '''\ diff --git a/src/sas/qtgui/Utilities/UI/PluginDefinitionUI.ui b/src/sas/qtgui/Utilities/UI/PluginDefinitionUI.ui index 3fe3289619..b9fe568f7d 100755 --- a/src/sas/qtgui/Utilities/UI/PluginDefinitionUI.ui +++ b/src/sas/qtgui/Utilities/UI/PluginDefinitionUI.ui @@ -236,6 +236,46 @@ li.checked::marker { content: "\2612"; } + + + + Model Options + + + + + + Can use OpenCL + + + + + + + Can use single precision floating point values + + + true + + + + + + + Has F(Q) calculations + + + + + + + Can be used as structure factor + + + + + +