Version: 8.3.0
YACSGuiLoader.hxx
Go to the documentation of this file.
1 // Copyright (C) 2006-2016 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 #ifndef _YACSGUILOADER_HXX_
21 #define _YACSGUILOADER_HXX_
22 
23 #include <parsers.hxx>
24 
25 #include <map>
26 #include <string>
27 #include <QString>
28 
29 namespace YACS
30 {
31  namespace ENGINE
32  {
33  class Node;
34  class Proc;
35  }
36 
37  namespace HMI
38  {
39 
40  struct PrsData
41  {
42  float _x, _y;
43  float _width, _height;
44  float _expx, _expy;
46  bool _expanded;
48 
50  {
51  _x = _y = 0;
52  _width = _height = 1.;
53  _expx = _expy = 0;
54  _expWidth = _expHeight = 0;
55  _expanded = true;
56  _shownState = 0;
57  }
58 
59  PrsData(float x,
60  float y,
61  float width,
62  float height,
63  float expx,
64  float expy,
65  float expWidth,
66  float expHeight,
67  bool expanded,
68  int shownState)
69  {
70  _x = x;
71  _y = y;
72  _width = width;
73  _height = height;
74  _expx = expx;
75  _expy = expy;
76  _expWidth = expWidth;
77  _expHeight = expHeight;
78  _expanded = expanded;
80  }
81  };
82 
88  {
89  public:
90  YACSGuiLoader();
91  virtual ~YACSGuiLoader();
92  virtual void reset();
93 
94  virtual YACS::ENGINE::Proc* load (const char *filename);
95  std::map<YACS::ENGINE::Node*, PrsData> getPrsData(YACS::ENGINE::Proc* proc);
96 
97  void process(std::string element, bool newLink = false);
98 
99  private:
100  std::map<YACS::ENGINE::Node*, PrsData> _prsMap;
101  std::map<std::string, PrsData> _inputMap;
102  };
103 
108  {
109  std::string name_;
110  float x_, y_;
111  float width_, height_;
112  float expx_, expy_;
114  bool expanded_;
116 
118 
120  {
121  collector_ = 0;
122  }
123 
124  virtual void onStart(const XML_Char* el, const XML_Char** attr)
125  {
126  std::string element(el);
127  parser* pp=&main_parser;
128  SetUserDataAndPush(pp);
129  pp->init();
130  pp->pre();
131  pp->buildAttr(attr);
132  }
133 
134  virtual void buildAttr(const XML_Char** attr)
135  {
136  required("name",attr);
137  required("x",attr);
138  required("y",attr);
139  required("width",attr);
140  required("height",attr);
141  //required("expanded", attr);
142  for (int i = 0; attr[i]; i += 2)
143  {
144  if(std::string(attr[i]) == "name") name(attr[i+1]);
145  if(std::string(attr[i]) == "x") x(attr[i+1]);
146  if(std::string(attr[i]) == "y") y(attr[i+1]);
147  if(std::string(attr[i]) == "width") width(attr[i+1]);
148  if(std::string(attr[i]) == "height") height(attr[i+1]);
149  if(std::string(attr[i]) == "expx") expx(attr[i+1]);
150  if(std::string(attr[i]) == "expy") expy(attr[i+1]);
151  if(std::string(attr[i]) == "expWidth") expWidth(attr[i+1]);
152  if(std::string(attr[i]) == "expHeight") expHeight(attr[i+1]);
153  if(std::string(attr[i]) == "expanded") expanded(attr[i+1]);
154  if(std::string(attr[i]) == "shownState") shownState(attr[i+1]);
155  }
156 
157  if ( collector_ )
158  collector_->process("presentation");
159  }
160 
161  virtual void pre ()
162  {
163  name_ = "";
164  x_ = y_ = 0.;
165  width_ = height_ = 1;
166  expx_ = expy_ = 0.;
167  expanded_ = true;
168  shownState_ = 0;
169  }
170 
171  virtual void name(const std::string& name)
172  {
173  name_ = name;
174  }
175 
176  virtual void x(const std::string& x)
177  {
178  x_ = QString(x.c_str()).toFloat();
179  }
180 
181  virtual void y(const std::string& y)
182  {
183  y_ = QString(y.c_str()).toFloat();
184  }
185 
186  virtual void width(const std::string& width)
187  {
188  width_ = QString(width.c_str()).toFloat();
189  }
190 
191  virtual void height(const std::string& height)
192  {
193  height_ = QString(height.c_str()).toFloat();
194  }
195 
196  virtual void expx(const std::string& x)
197  {
198  expx_ = QString(x.c_str()).toFloat();
199  }
200 
201  virtual void expy(const std::string& y)
202  {
203  expy_ = QString(y.c_str()).toFloat();
204  }
205 
206  virtual void expWidth(const std::string& x)
207  {
208  expWidth_ = QString(x.c_str()).toFloat();
209  }
210 
211  virtual void expHeight(const std::string& y)
212  {
213  expHeight_ = QString(y.c_str()).toFloat();
214  }
215 
216  virtual void expanded(const std::string& expanded)
217  {
218  expanded_ = QString(expanded.c_str()).toInt();
219  }
220 
221  virtual void shownState(const std::string& shownState)
222  {
223  shownState_ = QString(shownState.c_str()).toInt();
224  }
225  };
226 
227 
228  }
229 }
230 
231 #endif