Salome HOME
updated copyright message
[modules/shaper.git] / src / Config / Config_DataModelReader.cpp
1 // Copyright (C) 2014-2023  CEA, EDF
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
18 //
19
20 #include "Config_DataModelReader.h"
21 #include <Config_Keywords.h>
22 #include "Config_Common.h"
23
24 #include <Events_InfoMessage.h>
25
26 #include <algorithm>
27
28 // used only for GUI xml data reading
29 // LCOV_EXCL_START
30 Config_DataModelReader::Config_DataModelReader()
31     : Config_XMLReader(DATAMODEL_FILE), isRootReading(true), myIsResultLink(false)
32 {
33 }
34
35 Config_DataModelReader::~Config_DataModelReader()
36 {
37 }
38
39 void Config_DataModelReader::processNode(xmlNodePtr theNode)
40 {
41   if (isNode(theNode, NODE_FOLDER, NULL)) {
42     std::string aName = getProperty(theNode, FOLDER_NAME);
43     std::string aGroupType = getProperty(theNode, GROUP_TYPE);
44     if (aName.empty() || aGroupType.empty())
45       Events_InfoMessage("Config_DataModelReader",
46         "Reading dataModel.xml: wrong folder definition.").send();
47
48     std::string aIcon = getProperty(theNode, NODE_ICON);
49     std::string aEmpty = getProperty(theNode, SHOW_EMPTY);
50     std::string aFeatures = getProperty(theNode, FOLDER_FEATURES);
51
52     std::transform(aEmpty.begin(), aEmpty.end(), aEmpty.begin(),
53                    [](char c) { return static_cast<char>(::toupper(c)); });
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::transform(isResult.begin(), isResult.end(), isResult.begin(),
77                    [](char c) { return static_cast<char>(::toupper(c)); });
78     myIsResultLink = (isResult == "TRUE")? true : false;
79   }
80 }
81
82 int Config_DataModelReader::rootFolderId(std::string theType) const
83 {
84   std::vector<std::string>::const_iterator aIt;
85   int aId;
86   for (aIt = myRootFolderTypes.cbegin(), aId = 0; aIt != myRootFolderTypes.cend(); ++aIt, ++aId) {
87     if ((*aIt) == theType)
88       return aId;
89   }
90   return -1;
91 }
92
93 int Config_DataModelReader::subFolderId(std::string theType) const
94 {
95   std::vector<std::string>::const_iterator aIt;
96   int aId;
97   for (aIt = mySubFolderTypes.cbegin(), aId = 0; aIt != mySubFolderTypes.cend(); ++aIt, ++aId) {
98     if ((*aIt) == theType)
99       return aId;
100   }
101   return -1;
102 }
103
104 std::string getFolderFeatures(const std::string& theFolderName,
105                     const std::vector<std::string>& theNames,
106                     const std::vector<std::string>& theFeatures)
107 {
108   int aId;
109   bool aFound = false;
110   std::vector<std::string>::const_iterator aIt;
111   for(aIt = theNames.cbegin(), aId = 0; aIt != theNames.cend(); ++aIt, ++aId) {
112     if ((*aIt) == theFolderName) {
113       aFound = true;
114       break;
115     }
116   }
117   if (aFound)
118     return theFeatures.at(aId);
119   return std::string();
120 }
121
122 std::string Config_DataModelReader::
123   subFolderFeatures(const std::string& theFolderName) const
124 {
125   return getFolderFeatures(theFolderName, mySubFolderNames, mySubFeaturesList);
126 }
127
128
129 std::string Config_DataModelReader::
130   rootFolderFeatures(const std::string& theFolderName) const
131 {
132   return getFolderFeatures(theFolderName, myRootFolderNames, myRootFeaturesList);
133 }
134 // LCOV_EXCL_STOP