X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=c001a0c3f41585bd42416e2b7ca68ec4822807d3;hb=04a8a265b25901dd54e34d449f8d0c64304f1e69;hp=f179e889bc0f7b632c7670555959636f208ab67f;hpb=daeab27f92af64bc3d0fd5328ce61d1d525c4802;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index f179e889b..c001a0c3f 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 @@ -6,16 +8,57 @@ #include #include #include +#include #include #include +#include +bool ExchangePlugin_ImportFormatValidator::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 aFormat = anArg.substr(0, aSepPos); + std::transform(aFormat.begin(), aFormat.end(), aFormat.begin(), toupper); + outFormats.push_back(aFormat); + } + return result; +} -bool ExchangePlugin_ImportFormatValidator::isValid( - const AttributePtr& theAttribute, const std::list& theArguments) const +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; + } + } + } + } return false; }