-// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023 CEA, EDF
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <ModelAPI_Object.h>
#include <ModelAPI_Session.h>
#include <ModelAPI_AttributeString.h>
+#include <ModelAPI_AttributeSelectionList.h>
#include <list>
#include <string>
continue;
}
std::string aFormats = anArg.substr(0, aSepPos);
- std::transform(aFormats.begin(), aFormats.end(), aFormats.begin(), toupper);
+ std::transform(aFormats.begin(), aFormats.end(), aFormats.begin(),
+ [](char c) { return static_cast<char>(::toupper(c)); });
std::list<std::string> aFormatList = ExchangePlugin_Tools::split(aFormats, '|');
outFormats.insert(outFormats.end(), aFormatList.begin(), aFormatList.end());
}
ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats);
std::list<std::string>::const_iterator itFormats = aFormats.begin();
size_t aFileNameLen = aFileName.length();
- std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
+ std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(),
+ [](char c) { return static_cast<char>(::toupper(c)); });
// Is file name ends with the format
for (; itFormats != aFormats.end(); ++itFormats) {
std::string aFormat = "." + *itFormats;
theError = "File name does not end with any available format.";
return false;
}
+
+
+bool ExchangePlugin_InHistoryValidator::isValid(const AttributePtr& theAttribute,
+ const std::list<std::string>& theArguments,
+ Events_InfoMessage& theError) const
+{
+ std::string anAttributeType = theAttribute->attributeType();
+ if(anAttributeType == ModelAPI_AttributeSelection::typeId()) {
+ AttributeSelectionPtr anAttrSelection =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(theAttribute);
+ ResultPtr aContext = anAttrSelection->context();
+ if (!aContext.get()) {
+ theError = "Error: Context is empty.";
+ return false;
+ }
+
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aContext);
+ if (!aFeature->isInHistory()) {
+ theError = "Error: Feature is not in history.";
+ return false;
+ }
+ } else if(anAttributeType == ModelAPI_AttributeSelectionList::typeId()) {
+ AttributeSelectionListPtr anAttrSelectionList =
+ std::dynamic_pointer_cast<ModelAPI_AttributeSelectionList>(theAttribute);
+
+ // All objects should not be result constructions.
+ for(int anIndex = 0, aSize = anAttrSelectionList->size(); anIndex < aSize; ++anIndex) {
+ AttributeSelectionPtr anAttrSelection = anAttrSelectionList->value(anIndex);
+ if(!isValid(anAttrSelection, theArguments, theError)) {
+ return false;
+ }
+ }
+ } else {
+// LCOV_EXCL_START
+ theError = "Error: Attribute \"%1\" does not supported by this validator.";
+ theError.arg(anAttributeType);
+ return false;
+// LCOV_EXCL_STOP
+ }
+
+ return true;
+}