X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=5a62fea8f048dd260110e69fc81d83bc46547948;hb=eaa34d7803a364b8da51b6dde8b0ee3c469ae27a;hp=99e14bea9f76ad8363769dfff6a9a9b3fbb3fd1d;hpb=542c9d721fbef80eb2040ef248fdd431cad2e631;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index 99e14bea9..5a62fea8f 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: SketchPlugin_Validators.cpp // Created: 01 Aug 2014 // Author: Vitaly SMETANNIKOV @@ -5,18 +7,62 @@ #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; + int aSepPos = anArg.find(":"); + if (aSepPos == std::string::npos) { + result = false; + continue; + } + std::string aFormatList = anArg.substr(0, aSepPos); + std::transform(aFormatList.begin(), aFormatList.end(), aFormatList.begin(), toupper); + std::istringstream aStream(aFormatList); + std::string aFormat; + while (std::getline(aStream, aFormat, '|')) + outFormats.push_back(aFormat); + } + 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) const { - PluginManagerPtr aMgr = ModelAPI_PluginManager::get(); - ModelAPI_ValidatorsFactory* aFactory = aMgr->validators(); + if (!theAttribute->isInitialized()) + return false; + + 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) { + size_t aFormatBeginPos = aFileNameLen - (*itFormats).length(); + if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) { + return true; + } + } return false; } -