X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=d13b2c478248d939d940492b18b45ae6a1f08dc1;hb=4ca3fd41634c37f840d0cbb3f896fa97c2d3c457;hp=2582ca76e115063bcb941e10ab4d0e586e9e69b4;hpb=4783f146b71a48c651523fcf0e12367bcf3d1fa8;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index 2582ca76e..d13b2c478 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -1,8 +1,13 @@ -// 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 @@ -12,8 +17,8 @@ #include #include -bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list& theArguments, - std::list& outFormats) +bool ExchangePlugin_FormatValidator::parseFormats(const std::list& theArguments, + std::list& outFormats) { std::list::const_iterator it = theArguments.begin(); bool result = true; @@ -24,56 +29,43 @@ bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list aFormatList = ExchangePlugin_Tools::split(aFormats, '|'); + outFormats.insert(outFormats.end(), aFormatList.begin(), aFormatList.end()); } return result; } -bool ExchangePlugin_ImportFormatValidator::parsePlugins(const std::list& theArguments, - std::list& outPlugins) +bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) const { - std::list::const_iterator it = theArguments.begin(); - bool result = true; - for (; it != theArguments.end(); ++it) { - std::string anArg = *it; - int aSepPos = anArg.find(":"); - if (aSepPos == std::string::npos) { - result = false; - continue; - } - outPlugins.push_back(anArg.substr(aSepPos + 1)); - } - return result; -} + if (!theAttribute->isInitialized()) + return false; -bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const -{ - SessionPtr aMgr = ModelAPI_Session::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); - if (theAttribute->isInitialized()) { - const AttributeStringPtr aStrAttr = - std::dynamic_pointer_cast(theAttribute); - if(!aStrAttr) - return false; - std::string aFileName = aStrAttr->value(); - if (!aFileName.empty()) { - std::list aFormats; - ExchangePlugin_ImportFormatValidator::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) { - size_t aFormatBeginPos = aFileNameLen - (*itFormats).length(); - if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) { - return true; - } + const AttributeStringPtr aStrAttr = + std::dynamic_pointer_cast(theAttribute); + if (!aStrAttr) + return false; + + std::string aFileName = aStrAttr->value(); + if (aFileName.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; } } } return false; } -