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::parsePlugins(const std::list<std::string>& theArguments,
37 std::list<std::string>& outPlugins)
39 std::list<std::string>::const_iterator it = theArguments.begin();
41 for (; it != theArguments.end(); ++it) {
42 std::string anArg = *it;
43 int aSepPos = anArg.find(":");
44 if (aSepPos == std::string::npos) {
48 outPlugins.push_back(anArg.substr(aSepPos + 1));
53 bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
54 const std::list<std::string>& theArguments) const
56 SessionPtr aMgr = ModelAPI_Session::get();
57 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
58 if (theAttribute->isInitialized()) {
59 const AttributeStringPtr aStrAttr =
60 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
63 std::string aFileName = aStrAttr->value();
64 if (!aFileName.empty()) {
65 std::list<std::string> aFormats;
66 ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
67 std::list<std::string>::const_iterator itFormats = aFormats.begin();
68 size_t aFileNameLen = aFileName.length();
69 std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
70 // Is file name ends with the format
71 for (; itFormats != aFormats.end(); ++itFormats) {
72 size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
73 if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {