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>
8 #include <ModelAPI_Feature.h>
9 #include <ModelAPI_Object.h>
10 #include <ModelAPI_Session.h>
11 #include <ModelAPI_AttributeString.h>
17 bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
18 std::list<std::string>& outFormats)
20 std::list<std::string>::const_iterator it = theArguments.begin();
22 for (; it != theArguments.end(); ++it) {
23 std::string anArg = *it;
24 int aSepPos = anArg.find(":");
25 if (aSepPos == std::string::npos) {
29 std::string aFormat = anArg.substr(0, aSepPos);
30 std::transform(aFormat.begin(), aFormat.end(), aFormat.begin(), toupper);
31 outFormats.push_back(aFormat);
36 bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
37 const std::list<std::string>& theArguments) const
39 SessionPtr aMgr = ModelAPI_Session::get();
40 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
41 if (theAttribute->isInitialized()) {
42 const AttributeStringPtr aStrAttr =
43 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
46 std::string aFileName = aStrAttr->value();
47 if (!aFileName.empty()) {
48 std::list<std::string> aFormats;
49 ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
50 std::list<std::string>::const_iterator itFormats = aFormats.begin();
51 size_t aFileNameLen = aFileName.length();
52 std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
53 // Is file name ends with the format
54 for (; itFormats != aFormats.end(); ++itFormats) {
55 size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
56 if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {