Salome HOME
Add copyright header according to request of CEA from 06.06.2017
[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 email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
18 //
19
20 /*
21  * Config_DataModelReader.cpp
22  *
23  *  Created on: Jul 21, 2015
24  *      Author: vsv
25  */
26
27 #include "Config_DataModelReader.h"
28 #include <Config_Keywords.h>
29 #include "Config_Common.h"
30
31 #include <Events_InfoMessage.h>
32
33
34 Config_DataModelReader::Config_DataModelReader()
35     : Config_XMLReader(DATAMODEL_FILE), isRootReading(true), myIsResultLink(false)
36 {
37 }
38
39 Config_DataModelReader::~Config_DataModelReader()
40 {
41 }
42
43 void Config_DataModelReader::processNode(xmlNodePtr theNode)
44 {
45   if (isNode(theNode, NODE_FOLDER, NULL)) {
46     std::string aName = getProperty(theNode, FOLDER_NAME);
47     std::string aGroupType = getProperty(theNode, GROUP_TYPE);
48     if (aName.empty() || aGroupType.empty())
49       Events_InfoMessage("Config_DataModelReader",
50         "Reading dataModel.xml: wrong folder definition.").send();
51
52     std::string aIcon = getProperty(theNode, NODE_ICON);
53     std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
54     std::string aFeatures = getProperty(theNode, FOLDER_FEATURES);
55     std::string::iterator aIt;
56     for (aIt = aEmpty.begin(); aIt != aEmpty.end(); aIt++) {
57       (*aIt) = toupper(*aIt);
58     }
59     bool aIsEmpty = (aEmpty == "FALSE")? false : true;
60
61    if (isRootReading) {
62       myRootFolderNames.push_back(aName);
63       myRootFolderTypes.push_back(aGroupType);
64       myRootFolderIcons.push_back(aIcon);
65       myRootFolderShowEmpty.push_back(aIsEmpty);
66       myRootFeaturesList.push_back(aFeatures);
67    } else {
68       mySubFolderNames.push_back(aName);
69       mySubFolderTypes.push_back(aGroupType);
70       mySubFolderIcons.push_back(aIcon);
71       mySubFolderShowEmpty.push_back(aIsEmpty);
72       mySubFeaturesList.push_back(aFeatures);
73    }
74   } else if  (isNode(theNode, ROOT_DOCUMENT, NULL)) {
75     isRootReading = true;
76     myRootTypes = getProperty(theNode, GROUP_TYPE);
77   } else if  (isNode(theNode, SUB_DOCUMENT, NULL)) {
78     isRootReading = false;
79     mySubTypes = getProperty(theNode, GROUP_TYPE);
80     std::string isResult = getProperty(theNode, LINK_ITEM);
81     std::string::iterator aIt;
82     for (aIt = isResult.begin(); aIt != isResult.end(); aIt++) {
83       (*aIt) = toupper(*aIt);
84     }
85     myIsResultLink = (isResult == "TRUE")? true : false;
86   }
87 }
88
89 int Config_DataModelReader::rootFolderId(std::string theType) const
90 {
91   std::vector<std::string>::const_iterator aIt;
92   int aId;
93   for (aIt = myRootFolderTypes.cbegin(), aId = 0; aIt != myRootFolderTypes.cend(); ++aIt, ++aId) {
94     if ((*aIt) == theType)
95       return aId;
96   }
97   return -1;
98 }
99
100 int Config_DataModelReader::subFolderId(std::string theType) const
101 {
102   std::vector<std::string>::const_iterator aIt;
103   int aId;
104   for (aIt = mySubFolderTypes.cbegin(), aId = 0; aIt != mySubFolderTypes.cend(); ++aIt, ++aId) {
105     if ((*aIt) == theType)
106       return aId;
107   }
108   return -1;
109 }
110
111 std::string getFolderFeatures(const std::string& theFolderName,
112                     const std::vector<std::string>& theNames,
113                     const std::vector<std::string>& theFeatures)
114 {
115   int aId;
116   bool aFound = false;
117   std::vector<std::string>::const_iterator aIt;
118   for(aIt = theNames.cbegin(), aId = 0; aIt != theNames.cend(); ++aIt, ++aId) {
119     if ((*aIt) == theFolderName) {
120       aFound = true;
121       break;
122     }
123   }
124   if (aFound)
125     return theFeatures.at(aId);
126   return std::string();
127 }
128
129 std::string Config_DataModelReader::
130   subFolderFeatures(const std::string& theFolderName) const
131 {
132   return getFolderFeatures(theFolderName, mySubFolderNames, mySubFeaturesList);
133 }
134
135
136 std::string Config_DataModelReader::
137   rootFolderFeatures(const std::string& theFolderName) const
138 {
139   return getFolderFeatures(theFolderName, myRootFolderNames, myRootFeaturesList);
140 }
141