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