Salome HOME
Merge branch 'master' into cgt/devCEA
[modules/shaper.git] / src / Config / Config_DataModelReader.cpp
1 // Copyright (C) 2014-2017  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License, or (at your option) any later version.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or
18 // email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
19 //
20
21 #include "Config_DataModelReader.h"
22 #include <Config_Keywords.h>
23 #include "Config_Common.h"
24
25 #include <Events_InfoMessage.h>
26
27
28 Config_DataModelReader::Config_DataModelReader()
29     : Config_XMLReader(DATAMODEL_FILE), isRootReading(true), myIsResultLink(false)
30 {
31 }
32
33 Config_DataModelReader::~Config_DataModelReader()
34 {
35 }
36
37 void Config_DataModelReader::processNode(xmlNodePtr theNode)
38 {
39   if (isNode(theNode, NODE_FOLDER, NULL)) {
40     std::string aName = getProperty(theNode, FOLDER_NAME);
41     std::string aGroupType = getProperty(theNode, GROUP_TYPE);
42     if (aName.empty() || aGroupType.empty())
43       Events_InfoMessage("Config_DataModelReader",
44         "Reading dataModel.xml: wrong folder definition.").send();
45
46     std::string aIcon = getProperty(theNode, NODE_ICON);
47     std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
48     std::string aFeatures = getProperty(theNode, FOLDER_FEATURES);
49     std::string::iterator aIt;
50     for (aIt = aEmpty.begin(); aIt != aEmpty.end(); aIt++) {
51       (*aIt) = toupper(*aIt);
52     }
53     bool aIsEmpty = (aEmpty == "FALSE")? false : true;
54
55    if (isRootReading) {
56       myRootFolderNames.push_back(aName);
57       myRootFolderTypes.push_back(aGroupType);
58       myRootFolderIcons.push_back(aIcon);
59       myRootFolderShowEmpty.push_back(aIsEmpty);
60       myRootFeaturesList.push_back(aFeatures);
61    } else {
62       mySubFolderNames.push_back(aName);
63       mySubFolderTypes.push_back(aGroupType);
64       mySubFolderIcons.push_back(aIcon);
65       mySubFolderShowEmpty.push_back(aIsEmpty);
66       mySubFeaturesList.push_back(aFeatures);
67    }
68   } else if  (isNode(theNode, ROOT_DOCUMENT, NULL)) {
69     isRootReading = true;
70     myRootTypes = getProperty(theNode, GROUP_TYPE);
71   } else if  (isNode(theNode, SUB_DOCUMENT, NULL)) {
72     isRootReading = false;
73     mySubTypes = getProperty(theNode, GROUP_TYPE);
74     std::string isResult = getProperty(theNode, LINK_ITEM);
75     std::string::iterator aIt;
76     for (aIt = isResult.begin(); aIt != isResult.end(); aIt++) {
77       (*aIt) = toupper(*aIt);
78     }
79     myIsResultLink = (isResult == "TRUE")? true : false;
80   }
81 }
82
83 int Config_DataModelReader::rootFolderId(std::string theType) const
84 {
85   std::vector<std::string>::const_iterator aIt;
86   int aId;
87   for (aIt = myRootFolderTypes.cbegin(), aId = 0; aIt != myRootFolderTypes.cend(); ++aIt, ++aId) {
88     if ((*aIt) == theType)
89       return aId;
90   }
91   return -1;
92 }
93
94 int Config_DataModelReader::subFolderId(std::string theType) const
95 {
96   std::vector<std::string>::const_iterator aIt;
97   int aId;
98   for (aIt = mySubFolderTypes.cbegin(), aId = 0; aIt != mySubFolderTypes.cend(); ++aIt, ++aId) {
99     if ((*aIt) == theType)
100       return aId;
101   }
102   return -1;
103 }
104
105 std::string getFolderFeatures(const std::string& theFolderName,
106                     const std::vector<std::string>& theNames,
107                     const std::vector<std::string>& theFeatures)
108 {
109   int aId;
110   bool aFound = false;
111   std::vector<std::string>::const_iterator aIt;
112   for(aIt = theNames.cbegin(), aId = 0; aIt != theNames.cend(); ++aIt, ++aId) {
113     if ((*aIt) == theFolderName) {
114       aFound = true;
115       break;
116     }
117   }
118   if (aFound)
119     return theFeatures.at(aId);
120   return std::string();
121 }
122
123 std::string Config_DataModelReader::
124   subFolderFeatures(const std::string& theFolderName) const
125 {
126   return getFolderFeatures(theFolderName, mySubFolderNames, mySubFeaturesList);
127 }
128
129
130 std::string Config_DataModelReader::
131   rootFolderFeatures(const std::string& theFolderName) const
132 {
133   return getFolderFeatures(theFolderName, myRootFolderNames, myRootFeaturesList);
134 }
135