1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
3 // File: SketchPlugin_Validators.cpp
4 // Created: 01 Aug 2014
5 // Author: Vitaly SMETANNIKOV
7 #include <ExchangePlugin_Validators.h>
9 #include <ExchangePlugin_Tools.h>
11 #include <ModelAPI_Feature.h>
12 #include <ModelAPI_Object.h>
13 #include <ModelAPI_Session.h>
14 #include <ModelAPI_AttributeString.h>
20 bool ExchangePlugin_FormatValidator::parseFormats(const std::list<std::string>& theArguments,
21 std::list<std::string>& outFormats)
23 std::list<std::string>::const_iterator it = theArguments.begin();
25 for (; it != theArguments.end(); ++it) {
26 std::string anArg = *it;
27 int aSepPos = anArg.find(":");
28 if (aSepPos == std::string::npos) {
32 std::string aFormats = anArg.substr(0, aSepPos);
33 std::transform(aFormats.begin(), aFormats.end(), aFormats.begin(), toupper);
34 std::list<std::string> aFormatList = ExchangePlugin_Tools::split(aFormats, '|');
35 outFormats.insert(outFormats.end(), aFormatList.begin(), aFormatList.end());
40 bool ExchangePlugin_FormatValidator::isValid(const AttributePtr& theAttribute,
41 const std::list<std::string>& theArguments) const
43 if (!theAttribute->isInitialized())
46 const AttributeStringPtr aStrAttr =
47 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
51 std::string aFileName = aStrAttr->value();
52 if (aFileName.empty())
55 std::list<std::string> aFormats;
56 ExchangePlugin_FormatValidator::parseFormats(theArguments, aFormats);
57 std::list<std::string>::const_iterator itFormats = aFormats.begin();
58 size_t aFileNameLen = aFileName.length();
59 std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
60 // Is file name ends with the format
61 for (; itFormats != aFormats.end(); ++itFormats) {
62 if (aFileNameLen > (*itFormats).length()) {
63 size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
64 if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {