Unverified Commit 069555d2 authored by Jose Borreguero's avatar Jose Borreguero Committed by GitHub
Browse files

Merge pull request #33056 from Kvieta1990/powgen_gui_new_element

Powgen gui new element
parents b6911d22 deb8a7d8
......@@ -9,6 +9,24 @@
#include <memory>
#include <sstream>
/**
* @brief Useful function for replacing all instances of characters in string.
*
* @param str the input string.
* @param from the substring to replace.
* @param to the string to replace with.
* @return std::string
*/
void replaceAll(std::string &str, const std::string &from, const std::string &to) {
if (from.empty())
return;
size_t start_pos = 0;
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
str.replace(start_pos, from.length(), to);
start_pos += to.length();
}
}
namespace Mantid::JsonHelpers {
/**
......@@ -28,6 +46,9 @@ std::string jsonToString(const Json::Value &json, const std::string &indentation
Json::StreamWriterBuilder builder;
builder.settings_["indentation"] = indentation;
auto string = Json::writeString(builder, json);
replaceAll(string, "\"{", "{");
replaceAll(string, "}\"", "}");
replaceAll(string, "\\\"", "\"");
return string;
}
......@@ -62,4 +83,4 @@ bool parse(const std::string &jsonString, Json::Value *jsonValue, std::string *e
return reader->parse(jsonString.c_str(), jsonString.c_str() + jsonString.length(), jsonValue, errors);
}
} // namespace Mantid::JsonHelpers
\ No newline at end of file
} // namespace Mantid::JsonHelpers
......@@ -9,6 +9,7 @@ Powder Diffraction
------------------
New features
############
- Add new input concerning sample height information from :ref:`SNSPowderReduction <algm-SNSPowderReduction>` to Powder Diffraction Reduction GUI.
- New algorithm :ref:`CalculatePlaczek <algm-CalculatePlaczek>` to compute both first and second Placzek correction factors.
- New algorithm :ref:`CalculatePlaczekSelfScattering2 <algm-CalculatePlaczekSelfScattering-v2>` utilizes :ref:`CalculatePlaczek <algm-CalculatePlaczek>` to compute first order correction.
- New algorithm :ref:`CombineDiffCal <algm-CombineDiffCal>` to calibrate groups of pixels after cross correlation so that diffraction peaks can be adjusted to the correct positions.
......
......@@ -170,6 +170,8 @@ class AdvancedSetupWidget(BaseWidget):
self._content.sampleformula_edit.setText(str(state.sampleformula))
self._content.numberdensity_edit.setText(str(state.samplenumberdensity))
self._content.massdensity_edit.setText(str(state.measuredmassdensity))
if state.samplegeometry:
self._content.sampleheight_edit.setText(str(state.samplegeometry['Height']))
self._content.containertype_combo.setCurrentIndex(
self._content.containertype_combo.findText(state.containershape))
self._content.correctiontype_combo.setCurrentIndex(
......@@ -219,6 +221,10 @@ class AdvancedSetupWidget(BaseWidget):
s.sampleformula = self._content.sampleformula_edit.text()
s.samplenumberdensity = self._content.numberdensity_edit.text()
s.measuredmassdensity = self._content.massdensity_edit.text()
try:
s.samplegeometry = {'Height': float(self._content.sampleheight_edit.text())}
except ValueError:
s.samplegeometry = {'Height': self._content.sampleheight_edit.text()}
s.containershape = self._content.containertype_combo.currentText()
s.typeofcorrection = self._content.correctiontype_combo.currentText()
......
......@@ -1039,6 +1039,9 @@
<item row="1" column="6">
<widget class="QLineEdit" name="massdensity_edit"/>
</item>
<item row="3" column="6">
<widget class="QLineEdit" name="sampleheight_edit"/>
</item>
<item row="2" column="5">
<widget class="QLabel" name="label_14">
<property name="text">
......@@ -1115,6 +1118,13 @@
</property>
</widget>
</item>
<item row="3" column="5">
<widget class="QLabel" name="label_sh">
<property name="text">
<string>Sample Height</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
......
......@@ -70,6 +70,7 @@ class AdvancedSetupScript(BaseScriptElement):
sampleformula = ""
samplenumberdensity = ""
measuredmassdensity = ""
samplegeometry = {}
containershape = ""
typeofcorrection = ""
parnamelist = None
......@@ -120,6 +121,7 @@ class AdvancedSetupScript(BaseScriptElement):
'TypeOfCorrection',
'SampleFormula',
'MeasuredMassDensity',
'SampleGeometry',
'SampleNumberDensity',
'ContainerShape',
# Caching options
......@@ -146,7 +148,10 @@ class AdvancedSetupScript(BaseScriptElement):
parvalue = "1"
elif str(parvalue) == "False":
parvalue = "0"
script += "%-10s = \"%s\",\n" % (parname, parvalue)
if not isinstance(parvalue, dict):
script += "%-10s = \"%s\",\n" % (parname, parvalue)
else:
script += "%-10s = %s,\n" % (parname, parvalue)
#ENDFOR
return script
......@@ -176,6 +181,7 @@ class AdvancedSetupScript(BaseScriptElement):
pardict["TypeOfCorrection"] = self.typeofcorrection
pardict["SampleFormula"] = self.sampleformula
pardict["MeasuredMassDensity"] = self.measuredmassdensity
pardict["SampleGeometry"] = self.samplegeometry
pardict["SampleNumberDensity"] = self.samplenumberdensity
pardict["ContainerShape"] = self.containershape
#Caching options
......@@ -279,6 +285,16 @@ class AdvancedSetupScript(BaseScriptElement):
self.measuredmassdensity = getFloatElement(instrument_dom, "measuredmassdensity",
AdvancedSetupScript.measuredmassdensity)
string_tmp = BaseScriptElement.getStringElement(instrument_dom, "samplegeometry",
default=AdvancedSetupScript.samplegeometry)
self.samplegeometry = {}
if string_tmp:
items = string_tmp.replace("{", "").replace("}", "").split(",")
keys_tmp = [item.split(":")[0].replace("'", "") for item in items]
vals_tmp = [float(item.split(":")[1].replace("'", "")) for item in items]
for count, value in enumerate(keys_tmp):
self.samplegeometry[value] = vals_tmp[count]
self.containershape = BaseScriptElement.getStringElement(instrument_dom, "containershape",
default=AdvancedSetupScript.containershape)
......
......@@ -334,7 +334,10 @@ class DiffractionReductionScripter(BaseReductionScripter):
continue
# Add to script
script += "{}{} = '{}',\n".format(DiffractionReductionScripter.WIDTH, propname, propvalue)
if '{' in propvalue and '}' in propvalue:
script += "{}{} = {},\n".format(DiffractionReductionScripter.WIDTH, propname, propvalue)
else:
script += "{}{} = '{}',\n".format(DiffractionReductionScripter.WIDTH, propname, propvalue)
# ENDFOR
# 3. Optional spliter workspace
......
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