Salome HOME
Send information message for translation
[modules/shaper.git] / src / Config / Config_DataModelReader.cpp
1 // Copyright (C) 2014-20xx CEA/DEN, EDF R&D
2
3 /*
4  * Config_DataModelReader.cpp
5  *
6  *  Created on: Jul 21, 2015
7  *      Author: vsv
8  */
9
10 #include "Config_DataModelReader.h"
11 #include <Config_Keywords.h>
12 #include "Config_Common.h"
13
14 #include <Events_Error.h>
15 #include <Events_InfoMessage.h>
16
17
18 Config_DataModelReader::Config_DataModelReader()
19     : Config_XMLReader(DATAMODEL_FILE), isRootReading(true), myIsResultLink(false)
20 {
21 }
22
23 Config_DataModelReader::~Config_DataModelReader()
24 {
25 }
26
27 void Config_DataModelReader::processNode(xmlNodePtr theNode)
28 {
29   if (isNode(theNode, NODE_FOLDER, NULL)) {
30     std::string aName = getProperty(theNode, FOLDER_NAME);
31     std::string aGroupType = getProperty(theNode, GROUP_TYPE);
32     if (aName.empty() || aGroupType.empty())
33       Events_InfoMessage("Config_DataModelReader", "Reading dataModel.xml: wrong folder definition.").send();
34    
35     std::string aIcon = getProperty(theNode, NODE_ICON);
36     std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
37     std::string aFeatures = getProperty(theNode, FOLDER_FEATURES);
38     std::string::iterator aIt;
39     for (aIt = aEmpty.begin(); aIt != aEmpty.end(); aIt++) {
40       (*aIt) = toupper(*aIt);
41     }
42     bool aIsEmpty = (aEmpty == "FALSE")? false : true;
43
44    if (isRootReading) {
45       myRootFolderNames.push_back(aName);
46       myRootFolderTypes.push_back(aGroupType);
47       myRootFolderIcons.push_back(aIcon);
48       myRootFolderShowEmpty.push_back(aIsEmpty);
49       myRootFeaturesList.push_back(aFeatures);
50    } else {
51       mySubFolderNames.push_back(aName);
52       mySubFolderTypes.push_back(aGroupType);
53       mySubFolderIcons.push_back(aIcon);
54       mySubFolderShowEmpty.push_back(aIsEmpty);
55       mySubFeaturesList.push_back(aFeatures);
56    }
57   } else if  (isNode(theNode, ROOT_DOCUMENT, NULL)) {
58     isRootReading = true;
59     myRootTypes = getProperty(theNode, GROUP_TYPE);
60   } else if  (isNode(theNode, SUB_DOCUMENT, NULL)) {
61     isRootReading = false;
62     mySubTypes = getProperty(theNode, GROUP_TYPE);
63     std::string isResult = getProperty(theNode, LINK_ITEM);
64     std::string::iterator aIt;
65     for (aIt = isResult.begin(); aIt != isResult.end(); aIt++) {
66       (*aIt) = toupper(*aIt);
67     }
68     myIsResultLink = (isResult == "TRUE")? true : false;
69   }
70 }
71
72 int Config_DataModelReader::rootFolderId(std::string theType) const
73 {
74   std::vector<std::string>::const_iterator aIt;
75   int aId;
76   for (aIt = myRootFolderTypes.cbegin(), aId = 0; aIt != myRootFolderTypes.cend(); ++aIt, ++aId) {
77     if ((*aIt) == theType)
78       return aId;
79   }
80   return -1;
81 }
82
83 int Config_DataModelReader::subFolderId(std::string theType) const
84 {
85   std::vector<std::string>::const_iterator aIt;
86   int aId;
87   for (aIt = mySubFolderTypes.cbegin(), aId = 0; aIt != mySubFolderTypes.cend(); ++aIt, ++aId) {
88     if ((*aIt) == theType)
89       return aId;
90   }
91   return -1;
92 }
93
94 std::string getFolderFeatures(const std::string& theFolderName, 
95                     const std::vector<std::string>& theNames,
96                     const std::vector<std::string>& theFeatures)
97 {
98   int aId;
99   bool aFound = false;
100   std::vector<std::string>::const_iterator aIt;
101   for(aIt = theNames.cbegin(), aId = 0; aIt != theNames.cend(); ++aIt, ++aId) {
102     if ((*aIt) == theFolderName) {
103       aFound = true;
104       break;
105     }
106   }
107   if (aFound)
108     return theFeatures.at(aId);
109   return std::string();
110 }
111
112 std::string Config_DataModelReader::
113   subFolderFeatures(const std::string& theFolderName) const
114 {
115   return getFolderFeatures(theFolderName, mySubFolderNames, mySubFeaturesList);
116 }
117
118
119 std::string Config_DataModelReader::
120   rootFolderFeatures(const std::string& theFolderName) const
121 {
122   return getFolderFeatures(theFolderName, myRootFolderNames, myRootFeaturesList);
123 }
124