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 <stdexcept>
11
12namespace Mantid::Kernel {
13
20VisibleWhenProperty::VisibleWhenProperty(const std::string &otherPropName, ePropertyCriterion when,
21 const std::string &value)
22 : EnabledWhenProperty(otherPropName, when, value) {}
23
34 const VisibleWhenProperty &conditionTwo, eLogicOperator logicOperator)
35 : // For the python interface to be able to easily copy objects in
36 // Make a deep copy and turn into a shared pointer and forward on
37 VisibleWhenProperty(std::make_shared<VisibleWhenProperty>(conditionOne),
38 std::make_shared<VisibleWhenProperty>(conditionTwo), logicOperator) {}
39
50VisibleWhenProperty::VisibleWhenProperty(std::shared_ptr<VisibleWhenProperty> &&conditionOne,
51 std::shared_ptr<VisibleWhenProperty> &&conditionTwo,
52 eLogicOperator logicOperator)
53 : m_comparisonDetails{std::make_shared<ComparisonDetails<VisibleWhenProperty>>(
54 ComparisonDetails<VisibleWhenProperty>{std::move(conditionOne), std::move(conditionTwo), logicOperator})} {}
55
65 const auto &comparison = m_comparisonDetails;
66 const auto &objectOne = comparison->conditionOne;
67 const auto &objectTwo = comparison->conditionTwo;
68
69 switch (comparison->logicOperator) {
70 case AND:
71 return objectOne->isVisible(algo) && objectTwo->isVisible(algo);
72 break;
73 case OR:
74 return objectOne->isVisible(algo) || objectTwo->isVisible(algo);
75 break;
76 case XOR:
77 return objectOne->isVisible(algo) ^ objectTwo->isVisible(algo);
78 break;
79 default:
80 throw std::runtime_error("Unknown logic operator in EnabledWhenProperty");
81 }
82}
83
92 UNUSED_ARG(algo);
93 return true;
94}
95
105 if (m_propertyDetails) {
106 return checkCriterion(algo);
107 } else if (m_comparisonDetails) {
108 return checkComparison(algo);
109 } else {
110 throw std::runtime_error("Both PropertyDetails and ComparisonDetails were "
111 "null in VisibleWhenProperty");
112 }
113}
114
123
124} // 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:64
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...
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.