Line data Source code
1 : /*
2 : * configuration.cpp
3 : *
4 : * Created on: Mar 22, 2016
5 : * Author: Leonidas Georgopoulos
6 : */
7 :
8 : #include "dbe/config_ui_info.hpp"
9 : #include "dbe/config_api_info.hpp"
10 : #include "dbe/GraphicalClass.hpp"
11 : #include "dbe/messenger.hpp"
12 : #include "dbe/Conversion.hpp"
13 :
14 : #include "dbe/config_api_get.hpp"
15 : #include "dbe/config_api_graph.hpp"
16 :
17 : #include <QStringList>
18 :
19 : #include <map>
20 : #include <vector>
21 :
22 : using namespace dunedaq::conffwk;
23 :
24 0 : dbe::ui::config::info::info ( std::vector<std::string> const & full_file_name )
25 0 : : this_full_filenames ( full_file_name )
26 : {
27 0 : parse();
28 0 : }
29 :
30 0 : dbe::GraphicalClass dbe::ui::config::info::graphical ( std::string const & name ) const
31 : {
32 0 : std::map<std::string, GraphicalClass>::const_iterator it = this_graphical.find ( name );
33 :
34 0 : if ( it != this_graphical.end() )
35 : {
36 0 : return it->second;
37 : }
38 : else
39 : {
40 0 : return
41 0 : {};
42 : }
43 0 : }
44 :
45 0 : dbe::ViewConfiguration dbe::ui::config::info::view ( std::string const & name ) const
46 : {
47 0 : std::map<std::string, ViewConfiguration>::const_iterator it = this_views.find ( name );
48 :
49 0 : if ( it != this_views.end() )
50 : {
51 0 : return it->second;
52 : }
53 : else
54 : {
55 0 : return
56 0 : {};
57 : }
58 0 : }
59 :
60 0 : dbe::Window dbe::ui::config::info::window ( std::string const & name ) const
61 : {
62 0 : std::map<std::string, Window>::const_iterator it = this_windows.find ( name );
63 :
64 0 : if ( it != this_windows.end() )
65 : {
66 0 : return it->second;
67 : }
68 : else
69 : {
70 0 : return
71 0 : {};
72 : }
73 0 : }
74 :
75 0 : void dbe::ui::config::info::parse()
76 : {
77 0 : for ( std::string const & fname : this_full_filenames )
78 : {
79 0 : std::string Implementation = "oksconflibs:" + fname;
80 :
81 0 : try
82 : {
83 0 : std::shared_ptr<Configuration> ConfigFile ( new Configuration ( Implementation ) );
84 0 : std::vector<ConfigObject> objects;
85 :
86 0 : ConfigFile->get ( "Class", objects );
87 :
88 0 : for ( ConfigObject & aclass : objects )
89 : {
90 0 : parse_graphical ( ConfigFile, aclass );
91 : }
92 :
93 0 : objects.clear();
94 0 : ConfigFile->get ( "Window", objects );
95 :
96 0 : for ( ConfigObject & awindow : objects )
97 : {
98 0 : parse_window ( ConfigFile, awindow );
99 : }
100 0 : }
101 0 : catch ( dunedaq::conffwk::Exception const & ex )
102 : {
103 0 : ERROR ( "Configuration database load did not succeed",
104 0 : dbe::config::errors::parse ( ex ).c_str() );
105 0 : }
106 0 : }
107 0 : }
108 :
109 0 : void dbe::ui::config::info::parse_graphical ( std::shared_ptr<Configuration> ConfigFile,
110 : ConfigObject & Object )
111 : {
112 0 : GraphicalClass GraphicalClassObject;
113 :
114 0 : GraphicalClassObject.GraphicalUID = QString ( Object.UID().c_str() );
115 0 : dunedaq::conffwk::class_t cinfo = ConfigFile->get_class_info ( Object.class_name(), false );
116 :
117 0 : std::vector<dunedaq::conffwk::attribute_t> const & attributes = cinfo.p_attributes;
118 0 : std::vector<dunedaq::conffwk::relationship_t> const & relations = cinfo.p_relationships;
119 :
120 0 : for ( dunedaq::conffwk::attribute_t const & attr : attributes )
121 : {
122 0 : QStringList data = dbe::config::api::get::direct::attribute<QStringList> ( Object, attr );
123 :
124 0 : if ( attr.p_name == "Name" )
125 : {
126 0 : GraphicalClassObject.DatabaseClassName = data.at ( 0 );
127 : }
128 0 : else if ( attr.p_name == "Generic Pixmap File" )
129 : {
130 0 : GraphicalClassObject.GenericPixmapFile = data.at ( 0 );
131 : }
132 0 : else if ( attr.p_name == "Used Pixmap File" )
133 : {
134 0 : GraphicalClassObject.UsedPixmapFile = data.at ( 0 );
135 : }
136 0 : else if ( attr.p_name == "Icon Bitmap File" )
137 : {
138 0 : GraphicalClassObject.BitmapFile = data.at ( 0 );
139 : }
140 0 : else if ( attr.p_name == "Icon Mask Bitmap File" )
141 : {
142 0 : GraphicalClassObject.BitmapMaskFile = data.at ( 0 );
143 : }
144 0 : else if ( attr.p_name == "Show All Attributes" )
145 : {
146 0 : GraphicalClassObject.ShowAllAttributes = convert::to<bool> (
147 0 : data, attr.p_int_format );
148 : }
149 0 : else if ( attr.p_name == "Attributes" )
150 : {
151 0 : GraphicalClassObject.Attributes = data;
152 : }
153 0 : else if ( attr.p_name == "Show All Relationships" )
154 : {
155 0 : GraphicalClassObject.ShowAllRelationships = convert::to<bool> (
156 0 : data, attr.p_int_format );
157 : }
158 0 : else if ( attr.p_name == "Relationships" )
159 : {
160 0 : GraphicalClassObject.Relationships = data;
161 :
162 : }
163 0 : else if ( attr.p_name == "Icon Title" )
164 : {
165 0 : GraphicalClassObject.IconTitle = data.at ( 0 );
166 : }
167 0 : }
168 :
169 0 : for ( dunedaq::conffwk::relationship_t const & relation : relations )
170 : {
171 0 : QStringList data;
172 0 : std::vector<ConfigObject> neighboring
173 : { };
174 :
175 0 : if ( dbe::config::api::info::relation::is_simple ( relation ) )
176 : {
177 0 : neighboring.push_back (
178 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( Object, relation ) );
179 : }
180 : else
181 : {
182 0 : std::vector<ConfigObject> objects = dbe::config::api::graph::direct::linked <
183 0 : std::vector<ConfigObject >> ( Object, relation );
184 0 : neighboring.insert ( std::end ( neighboring ), std::begin ( objects ),
185 : std::end ( objects ) );
186 0 : }
187 :
188 0 : for ( ConfigObject & RelObject : neighboring )
189 : {
190 0 : dunedaq::conffwk::class_t RelClassInfo = ConfigFile->get_class_info ( RelObject.class_name(),
191 0 : false );
192 0 : std::vector<dunedaq::conffwk::attribute_t> AttributeRelList = RelClassInfo.p_attributes;
193 :
194 0 : if ( RelObject.class_name() == "Dual Relationship" )
195 : {
196 0 : DualRelationship DRel;
197 :
198 0 : for ( dunedaq::conffwk::attribute_t & Attribute : AttributeRelList )
199 : {
200 0 : data = dbe::config::api::get::direct::attribute<QStringList> ( RelObject,
201 0 : Attribute );
202 :
203 0 : if ( Attribute.p_name == "Direct" )
204 : {
205 0 : DRel.Direct = data.at ( 0 );
206 : }
207 0 : else if ( Attribute.p_name == "Reverse" )
208 : {
209 0 : DRel.Reverse = data.at ( 0 );
210 : }
211 : }
212 :
213 0 : GraphicalClassObject.DualRelationships.push_back ( DRel );
214 0 : }
215 0 : else if ( RelObject.class_name() == "Init Attribute Value" )
216 : {
217 0 : InitAttributeFromEnv IRel;
218 :
219 0 : for ( dunedaq::conffwk::attribute_t & Attribute : AttributeRelList )
220 : {
221 0 : data = dbe::config::api::get::direct::attribute<QStringList> ( RelObject,
222 0 : Attribute );
223 :
224 0 : if ( Attribute.p_name == "Attribute Name" )
225 : {
226 0 : IRel.AttributeName = data.at ( 0 );
227 : }
228 0 : else if ( Attribute.p_name == "Environment Variables" )
229 : {
230 0 : IRel.EnvNames = data;
231 : }
232 : }
233 :
234 0 : GraphicalClassObject.NeedToInitialize.push_back ( IRel );
235 0 : }
236 0 : }
237 0 : }
238 :
239 0 : this_graphical.emplace ( GraphicalClassObject.GraphicalUID.toStdString(),
240 : GraphicalClassObject );
241 :
242 0 : }
243 :
244 0 : void dbe::ui::config::info::parse_window ( std::shared_ptr<Configuration> database,
245 : ConfigObject & object )
246 : {
247 0 : Window WindowObject;
248 0 : dunedaq::conffwk::class_t ClassInfo = database->get_class_info ( object.class_name(), false );
249 0 : std::vector<dunedaq::conffwk::attribute_t> const & attributes = ClassInfo.p_attributes;
250 0 : std::vector<dunedaq::conffwk::relationship_t> const & relations = ClassInfo.p_relationships;
251 :
252 0 : for ( dunedaq::conffwk::attribute_t const & attribute : attributes )
253 : {
254 0 : if ( attribute.p_name == "Title" )
255 : {
256 0 : WindowObject.Title = dbe::config::api::get::direct::attribute<QStringList> ( object,
257 : attribute ).at (
258 0 : 0 );
259 : }
260 : }
261 :
262 0 : for ( dunedaq::conffwk::relationship_t const & relation : relations )
263 : {
264 0 : std::vector<ConfigObject> linkedobjects;
265 :
266 0 : if ( dbe::config::api::info::relation::is_simple ( relation ) )
267 : {
268 0 : linkedobjects.push_back (
269 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( object, relation ) );
270 : }
271 : else
272 : {
273 0 : std::vector<ConfigObject> voisins = dbe::config::api::graph::direct::linked <
274 0 : std::vector<ConfigObject >> ( object, relation );
275 :
276 0 : if ( not voisins.empty() )
277 : {
278 0 : linkedobjects.insert ( std::end ( linkedobjects ), std::begin ( voisins ),
279 : std::end ( voisins ) );
280 : }
281 0 : }
282 :
283 0 : for ( ConfigObject & neighbor : linkedobjects )
284 : {
285 0 : dunedaq::conffwk::class_t classinfo = database->get_class_info ( neighbor.class_name(),
286 0 : false );
287 0 : std::vector<dunedaq::conffwk::attribute_t> const & AttributeRelList = classinfo
288 : .p_attributes;
289 0 : std::vector<dunedaq::conffwk::relationship_t> const & RelationshipRelList = classinfo
290 : .p_relationships;
291 :
292 0 : if ( neighbor.class_name() != "Window Separator" )
293 : {
294 0 : for ( dunedaq::conffwk::attribute_t const & Attribute : AttributeRelList )
295 : {
296 0 : if ( Attribute.p_name == "Shown with children" )
297 : {
298 0 : QStringList neighbor_names
299 0 : { dbe::config::api::get::direct::attribute<QStringList> ( neighbor, Attribute ) };
300 :
301 0 : if ( neighbor_names.at ( 0 ) != "none" )
302 : {
303 0 : WindowObject.ShowChildren = true;
304 : }
305 : else
306 : {
307 0 : WindowObject.ShowChildren = false;
308 : }
309 0 : }
310 : }
311 :
312 0 : for ( dunedaq::conffwk::relationship_t const & RelationshipRel : RelationshipRelList )
313 : {
314 0 : QStringList RelDataList;
315 0 : std::vector<ConfigObject> neighboring_nodes;
316 :
317 0 : if ( dbe::config::api::info::relation::is_simple ( RelationshipRel ) )
318 : {
319 0 : neighboring_nodes.push_back (
320 0 : dbe::config::api::graph::direct::linked<ConfigObject> ( neighbor,
321 : RelationshipRel ) );
322 : }
323 : else
324 : {
325 :
326 0 : std::vector<ConfigObject> neighbors = dbe::config::api::graph::direct::linked <
327 0 : std::vector<ConfigObject >> ( neighbor, RelationshipRel );
328 :
329 0 : neighboring_nodes.insert ( std::end ( neighboring_nodes ), std::begin ( neighbors ),
330 : std::end ( neighbors ) );
331 0 : }
332 :
333 0 : for ( ConfigObject & RelDataObject : neighboring_nodes )
334 : {
335 0 : RelDataList.push_back ( QString ( RelDataObject.UID().c_str() ) );
336 : }
337 :
338 0 : WindowObject.GraphicalClassesList.push_back ( RelDataList.at ( 0 ) );
339 0 : }
340 : }
341 0 : }
342 0 : }
343 :
344 0 : this_windows.emplace ( WindowObject.Title.toStdString(), WindowObject );
345 0 : }
346 :
347 0 : std::vector<dbe::Window> dbe::ui::config::info::windows() const
348 : {
349 0 : std::vector<dbe::Window> windows;
350 :
351 0 : for ( auto const & x : this_windows )
352 : {
353 0 : windows.push_back ( x.second );
354 : }
355 :
356 0 : return windows;
357 0 : }
358 :
359 0 : std::vector<dbe::ViewConfiguration> dbe::ui::config::info::views() const
360 : {
361 0 : std::vector<dbe::ViewConfiguration> views;
362 :
363 0 : for ( auto const & x : this_views )
364 : {
365 0 : views.push_back ( x.second );
366 : }
367 :
368 0 : return views;
369 0 : }
370 :
371 0 : std::vector<dbe::GraphicalClass> dbe::ui::config::info::graphicals() const
372 : {
373 0 : std::vector<dbe::GraphicalClass> the_graphicals;
374 :
375 0 : for ( auto const & x : this_graphical )
376 : {
377 0 : the_graphicals.push_back ( x.second );
378 : }
379 :
380 0 : return the_graphicals;
381 0 : }
382 :
|