1 // File: SketchPlugin_Validators.cpp
2 // Created: 01 Aug 2014
3 // Author: Vitaly SMETANNIKOV
5 #include <ExchangePlugin_Validators.h>
6 #include <ModelAPI_Feature.h>
7 #include <ModelAPI_Object.h>
8 #include <ModelAPI_Session.h>
9 #include <ModelAPI_AttributeString.h>
15 bool ExchangePlugin_ImportFormatValidator::parseFormats(const std::list<std::string>& theArguments,
16 std::list<std::string>& outFormats)
18 std::list<std::string>::const_iterator it = theArguments.begin();
20 for (; it != theArguments.end(); ++it) {
21 std::string anArg = *it;
22 int aSepPos = anArg.find(":");
23 if (aSepPos == std::string::npos) {
27 std::string aFormat = anArg.substr(0, aSepPos);
28 std::transform(aFormat.begin(), aFormat.end(), aFormat.begin(), toupper);
29 outFormats.push_back(aFormat);
34 bool ExchangePlugin_ImportFormatValidator::parsePlugins(const std::list<std::string>& theArguments,
35 std::list<std::string>& outPlugins)
37 std::list<std::string>::const_iterator it = theArguments.begin();
39 for (; it != theArguments.end(); ++it) {
40 std::string anArg = *it;
41 int aSepPos = anArg.find(":");
42 if (aSepPos == std::string::npos) {
46 outPlugins.push_back(anArg.substr(aSepPos + 1));
51 bool ExchangePlugin_ImportFormatValidator::isValid(const AttributePtr& theAttribute,
52 const std::list<std::string>& theArguments) const
54 SessionPtr aMgr = ModelAPI_Session::get();
55 ModelAPI_ValidatorsFactory* aFactory = aMgr->validators();
56 if (theAttribute->isInitialized()) {
57 const AttributeStringPtr aStrAttr =
58 std::dynamic_pointer_cast<ModelAPI_AttributeString>(theAttribute);
61 std::string aFileName = aStrAttr->value();
62 if (!aFileName.empty()) {
63 std::list<std::string> aFormats;
64 ExchangePlugin_ImportFormatValidator::parseFormats(theArguments, aFormats);
65 std::list<std::string>::const_iterator itFormats = aFormats.begin();
66 size_t aFileNameLen = aFileName.length();
67 std::transform(aFileName.begin(), aFileName.end(), aFileName.begin(), toupper);
68 // Is file name ends with the format
69 for (; itFormats != aFormats.end(); ++itFormats) {
70 size_t aFormatBeginPos = aFileNameLen - (*itFormats).length();
71 if (aFileName.compare(aFormatBeginPos, std::string::npos, *itFormats) == 0) {