Mantid
Loading...
Searching...
No Matches
EnabledWhenWorkspaceIsType.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2011 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 +
7#pragma once
8
9#include <utility>
10
18#include "MantidKernel/System.h"
19
20namespace Mantid {
21namespace API {
22
30public:
31 //--------------------------------------------------------------------------------------------
37 EnabledWhenWorkspaceIsType(std::string otherPropName, bool enabledSetting = true)
38 : IPropertySettings(), m_otherPropName(std::move(otherPropName)), m_enabledSetting(enabledSetting) {}
39
40 //--------------------------------------------------------------------------------------------
46 virtual bool checkCriterion(const Kernel::IPropertyManager *algo) const {
47 // Find the property
48 if (!algo)
49 return true;
50 Mantid::Kernel::Property *prop = nullptr;
51 try {
52 prop = algo->getPointerToProperty(m_otherPropName);
54 return true; // Property not found. Ignore
55 }
56 if (!prop)
57 return true;
58
59 // Value of the other property
60 std::string propValue = prop->value();
61 if (propValue.empty())
62 return true;
63
65 try {
66 ws = Mantid::API::AnalysisDataService::Instance().retrieve(propValue);
67 } catch (...) {
68 return true;
69 }
70 // Does it cast to the desired type?
71 std::shared_ptr<T> castWS = std::dynamic_pointer_cast<T>(ws);
72 if (castWS)
73 return m_enabledSetting;
74 else
75 return !m_enabledSetting;
76 }
77
78 //--------------------------------------------------------------------------------------------
81 bool isEnabled(const Kernel::IPropertyManager *algo) const override { return checkCriterion(algo); }
82
83 //--------------------------------------------------------------------------------------------
85 bool isVisible(const Kernel::IPropertyManager *) const override { return true; }
86
87 //--------------------------------------------------------------------------------------------
89 IPropertySettings *clone() const override {
90 return new EnabledWhenWorkspaceIsType<T>(m_otherPropName, m_enabledSetting);
91 }
92
93protected:
95 std::string m_otherPropName;
98};
99
100} // namespace API
101} // namespace Mantid
#define DLLExport
Definitions of the DLLImport compiler directives for MSVC.
Definition: System.h:53
Show a property as enabled when the workspace pointed to by another is of a given type.
bool isEnabled(const Kernel::IPropertyManager *algo) const override
Return true/false based on whether the other property satisfies the criterion.
virtual bool checkCriterion(const Kernel::IPropertyManager *algo) const
Does the validator fulfill the criterion based on the other property values?
std::string m_otherPropName
Name of the OTHER property that we will check.
bool isVisible(const Kernel::IPropertyManager *) const override
Return true always.
EnabledWhenWorkspaceIsType(std::string otherPropName, bool enabledSetting=true)
Constructor.
IPropertySettings * clone() const override
Make a copy of the present type of validator.
Exception for when an item is not found in a collection.
Definition: Exception.h:145
Interface to PropertyManager.
virtual Property * getPointerToProperty(const std::string &name) const =0
Get a pointer to property by name.
Interface for modifiers to Property's that specify if they should be enabled or visible in a GUI.
Base class for properties.
Definition: Property.h:94
virtual std::string value() const =0
Returns the value of the property as a string.
static T & Instance()
Return a reference to the Singleton instance, creating it if it does not already exist Creation is do...
std::shared_ptr< Workspace > Workspace_sptr
shared pointer to Mantid::API::Workspace
Definition: Workspace_fwd.h:20
Helper class which provides the Collimation Length for SANS instruments.
STL namespace.