X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FExchangePlugin%2FExchangePlugin_Validators.cpp;h=e0579464007a69089e5e9578d58dfcb40bb747bb;hb=e32f95642855a63da2727cb324ce2a75632a712f;hp=c001a0c3f41585bd42416e2b7ca68ec4822807d3;hpb=db0e21ea2f1117dd9af3320009ba8b50dc2e828b;p=modules%2Fshaper.git diff --git a/src/ExchangePlugin/ExchangePlugin_Validators.cpp b/src/ExchangePlugin/ExchangePlugin_Validators.cpp index c001a0c3f..e05794640 100644 --- a/src/ExchangePlugin/ExchangePlugin_Validators.cpp +++ b/src/ExchangePlugin/ExchangePlugin_Validators.cpp @@ -1,10 +1,13 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D -// File: SketchPlugin_Validators.cpp -// Created: 01 Aug 2014 -// Author: Vitaly SMETANNIKOV +// File: ExchangePlugin_Validators.cpp +// Created: Aug 01, 2014 +// Author: Sergey BELASH #include + +#include + #include #include #include @@ -14,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; @@ -26,39 +29,50 @@ 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::isValid(const AttributePtr& theAttribute, - const std::list& theArguments) const +bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute, + const std::list& theArguments, + std::string& theError) 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; - } + 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; } -