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