X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=a0117d84ef3131ef50cdd11088287c60c8fb31cc;hb=5905e018e30ae6867720c08ed2ba7745a0f94585;hp=99e14bea9f76ad8363769dfff6a9a9b3fbb3fd1d;hpb=b97f4d67421685f99412ee79484c7a8482da1d2e;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index 99e14bea9..a0117d84e 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -1,22 +1,80 @@ -// File: SketchPlugin_Validators.cpp -// Created: 01 Aug 2014 -// Author: Vitaly SMETANNIKOV +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: ExchangePlugin_Validators.cpp +// Created: Aug 01, 2014 +// Author: Sergey BELASH #include + +#include + +#include + #include #include -#include +#include +#include #include #include +#include +bool ExchangePlugin_FormatValidator::parseFormats(const std::list& theArguments, + std::list& outFormats) +{ + std::list::const_iterator it = theArguments.begin(); + bool result = true; + for (; it != theArguments.end(); ++it) { + std::string anArg = *it; + size_t aSepPos = anArg.find(":"); + if (aSepPos == std::string::npos) { + result = false; + continue; + } + std::string aFormats = anArg.substr(0, aSepPos); + std::transform(aFormats.begin(), aFormats.end(), aFormats.begin(), toupper); + std::list aFormatList = ExchangePlugin_Tools::split(aFormats, '|'); + outFormats.insert(outFormats.end(), aFormatList.begin(), aFormatList.end()); + } + return result; +} -bool ExchangePlugin_ImportFormatValidator::isValid(const FeaturePtr& theFeature, - const std::list& theArguments, - const ObjectPtr& theObject) const +bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + Events_InfoMessage& theError) const { - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + if (!theAttribute->isInitialized()) { + theError = "Is not initialized."; + return false; + } + + const AttributeStringPtr aStrAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aStrAttr) { + theError = "Is not a string attribute."; + return false; + } + + std::string aFileName = aStrAttr->value(); + if (aFileName.empty()) { + theError = "File name is empty."; + return false; + } + + std::list aFormats; + ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats); + std::list::const_iterator itFormats = aFormats.begin(); + size_t aFileNameLen = aFileName.length(); + std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper); + // Is file name ends with the format + for (; itFormats != aFormats.end(); ++itFormats) { + if (aFileNameLen > (*itFormats).length()) { + size_t aFormatBeginPos = aFileNameLen - (*itFormats).length(); + if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) { + return true; + } + } + } + theError = "File name does not end with any available format."; return false; } -