Mantid
Loading...
Searching...
No Matches
VisibleWhenProperty.cpp
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
8
9#include <memory>
10#include <set>
11#include <stdexcept>
12
13namespace Mantid::Kernel {
14
21VisibleWhenProperty::VisibleWhenProperty(const std::string &otherPropName, ePropertyCriterion when,
22 const std::string &value)
23 : EnabledWhenProperty(otherPropName, when, value) {}
24
35 const VisibleWhenProperty &conditionTwo, eLogicOperator logicOperator)
36 : // For the python interface to be able to easily copy objects in
37 // Make a deep copy and turn into a shared pointer and forward on
38 VisibleWhenProperty(std::make_shared<VisibleWhenProperty>(conditionOne),
39 std::make_shared<VisibleWhenProperty>(conditionTwo), logicOperator) {}
40
51VisibleWhenProperty::VisibleWhenProperty(std::shared_ptr<VisibleWhenProperty> &&conditionOne,
52 std::shared_ptr<VisibleWhenProperty> &&conditionTwo,
53 eLogicOperator logicOperator)
54 : m_comparisonDetails{std::make_shared<ComparisonDetails<VisibleWhenProperty>>(
55 ComparisonDetails<VisibleWhenProperty>{std::move(conditionOne), std::move(conditionTwo), logicOperator})} {}
56
66 const auto &comparison = m_comparisonDetails;
67 const auto &objectOne = comparison->conditionOne;
68 const auto &objectTwo = comparison->conditionTwo;
69
70 switch (comparison->logicOperator) {
71 case AND:
72 return objectOne->isVisible(algo) && objectTwo->isVisible(algo);
73 break;
74 case OR:
75 return objectOne->isVisible(algo) || objectTwo->isVisible(algo);
76 break;
77 case XOR:
78 return objectOne->isVisible(algo) ^ objectTwo->isVisible(algo);
79 break;
80 default:
81 throw std::runtime_error("Unknown logic operator in EnabledWhenProperty");
82 }
83}
84
93 UNUSED_ARG(algo);
94 return true;
95}
96
106 if (m_propertyDetails) {
107 return checkCriterion(algo);
108 } else if (m_comparisonDetails) {
109 return checkComparison(algo);
110 } else {
111 throw std::runtime_error("Both PropertyDetails and ComparisonDetails were "
112 "null in VisibleWhenProperty");
113 }
114}
115
117std::vector<std::string> VisibleWhenProperty::dependsOn(const std::string &thisProp) const {
118 if (m_propertyDetails) {
119 const std::string &otherProp = m_propertyDetails->otherPropName;
120 if (otherProp == thisProp)
121 throw std::runtime_error("VisibleWhenProperty: circular dependency detected");
122 return std::vector<std::string>{otherProp};
123 } else if (m_comparisonDetails) {
124 std::set<std::string> ps;
125 const auto ps1 = m_comparisonDetails->conditionOne->dependsOn(thisProp);
126 const auto ps2 = m_comparisonDetails->conditionTwo->dependsOn(thisProp);
127 ps.insert(ps1.cbegin(), ps1.cend());
128 ps.insert(ps2.cbegin(), ps2.cend());
129 return std::vector<std::string>(ps.cbegin(), ps.cend());
130 } else
131 return std::vector<std::string>{};
132}
133
142
143} // namespace Mantid::Kernel
double value
The value of the point.
Definition FitMW.cpp:51
#define UNUSED_ARG(x)
Function arguments are sometimes unused in certain implmentations but are required for documentation ...
Definition System.h:48
virtual bool checkCriterion(const IPropertyManager *algo) const
Checks that the specified property matches the criteria given.
std::shared_ptr< PropertyDetails > m_propertyDetails
Holds the various details used within the comparison.
Interface to PropertyManager.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
Same as EnabledWhenProperty, but returns the value for the isVisible() property instead of the isEnab...
std::vector< std::string > dependsOn(const std::string &thisProp) const override
Other properties that this property depends on.
IPropertySettings * clone() const override
Make a copy of the present type of validator.
bool isVisible(const IPropertyManager *algo) const override
Return true/false based on whether the other property satisfies the criterion.
bool isEnabled(const IPropertyManager *algo) const override
Return true always as we only consider visible.
std::shared_ptr< ComparisonDetails< VisibleWhenProperty > > m_comparisonDetails
Hold a copy of any existing VisibleWhenPropertyObjects.
VisibleWhenProperty(const std::string &otherPropName, ePropertyCriterion when, const std::string &value="")
Constructs a VisibleWhenProperty object which checks the property with name given and if it matches t...
virtual bool checkComparison(const IPropertyManager *algo) const override
Checks two VisisbleWhenProperty objects to determine the result of both of them.
ePropertyCriterion
Enum for use in EnabledWhenProperty.
eLogicOperator
Enum for use when combining two EnabledWhenPropertyItems.
STL namespace.
Struct which holds details for comparison between two EnabledWhenPropertyObjects.