Salome HOME
8457a58adca12d563d71749ba69391a24188d790
[modules/yacs.git] / src / genericgui / YACSGuiLoader.cxx
1 // Copyright (C) 2006-2023  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
18 //
19
20 #include "YACSGuiLoader.hxx"
21 #include "Proc.hxx"
22 #include "Node.hxx"
23
24 //#define _DEVDEBUG_
25 #include "YacsTrace.hxx"
26
27 using namespace std;
28 using namespace YACS::HMI;
29 using namespace YACS::ENGINE;
30
31 static presentationtype_parser presentation_parser;
32
33 YACSGuiLoader::YACSGuiLoader()
34   : YACSLoader()
35 {
36   presentation_parser.collector_ = this;
37   _defaultParsersMap.insert(make_pair("presentation", &presentation_parser));
38   _inputMap.clear();
39   _prsMap.clear();
40 }
41
42 YACSGuiLoader::~YACSGuiLoader()
43 {
44 }
45
46 void YACSGuiLoader::reset()
47 {
48   _inputMap.clear();
49 }
50
51 YACS::ENGINE::Proc* YACSGuiLoader::load(const char *filename)
52 {
53   _inputMap.clear();
54   return YACS::YACSLoader::load(filename);
55 }
56
57 std::map<YACS::ENGINE::Node*, PrsData> YACSGuiLoader::getPrsData(YACS::ENGINE::Proc* proc)
58 {
59   _prsMap.clear();
60
61   if (_defaultParsersMap.empty()) return _prsMap;
62
63   for (map<string, PrsData>::iterator it = _inputMap.begin(); it != _inputMap.end(); ++it)
64   {
65     Node* node = 0;
66     string name = (*it).first;
67
68     if (name == "__ROOT__")
69       node = proc;
70     else
71       {
72         try
73           {
74             node = proc->getChildByName(name);
75           }
76         catch(Exception& ex)
77           {
78             continue;
79           }
80       }
81     _prsMap[node] = (*it).second;
82   }
83   return _prsMap;
84 }
85
86 void YACSGuiLoader::process(std::string theElement, bool theNewLink)
87 {
88   if(theElement == "presentation")
89   {
90     if ( _defaultParsersMap["presentation"] )
91     {
92       presentationtype_parser* aP = (presentationtype_parser*)_defaultParsersMap["presentation"];
93       _inputMap[aP->name_] = PrsData(aP->x_, aP->y_, aP->width_, aP->height_, aP->expx_, aP->expy_,
94                                      aP->expWidth_, aP->expHeight_, aP->expanded_, aP->shownState_);
95       DEBTRACE(aP->name_ << " " << aP->x_ << " " << aP->y_ << " " <<  aP->width_ << " " << aP->height_ << " " 
96                << aP->expx_ << " " << aP->expy_ << " " << aP->expWidth_ << " " << aP->expHeight_ << " " << aP->expanded_ << " " << aP->shownState_);
97     }
98   }
99 }