07593b23107ff2e7804b9358e3b91d3278ad2501
19 /*******************************************************************************
20 * FUI : used to save and recall the state of the user interface
21 * This class provides essentially two new methods saveState() and recallState()
22 * used to save on file and recall from file the state of the user interface.
23 * The file is human readble and editable
24 ******************************************************************************/
28 stack
<string
> fGroupStack
;
29 vector
<string
> fNameList
;
30 map
<string
, float*> fName2Zone
;
34 // labels are normalized by replacing white spaces by underscores and by
35 // removing parenthesis
36 string
normalizeLabel(const char* label
)
41 while ((c
=*label
++)) {
42 if (isspace(c
)) { s
+= '_'; }
43 //else if ((c == '(') | (c == ')') ) { }
49 // add an element by relating its full name and memory zone
50 virtual void addElement (const char* label
, float* zone
)
52 string
fullname (fGroupStack
.top() + '/' + normalizeLabel(label
));
53 fNameList
.push_back(fullname
);
54 fName2Zone
[fullname
] = zone
;
57 // keep track of full group names in a stack
58 virtual void pushGroupLabel(const char* label
)
60 if (fGroupStack
.empty()) {
61 fGroupStack
.push(normalizeLabel(label
));
63 fGroupStack
.push(fGroupStack
.top() + '/' + normalizeLabel(label
));
67 virtual void popGroupLabel()
77 // -- Save and recall methods
79 // save the zones values and full names
80 virtual void saveState(const char* filename
)
84 for (unsigned int i
=0; i
<fNameList
.size(); i
++) {
85 string n
= fNameList
[i
];
86 float* z
= fName2Zone
[n
];
87 f
<< *z
<< ' ' << n
<< endl
;
94 // recall the zones values and full names
95 virtual void recallState(const char* filename
)
103 if (fName2Zone
.count(n
)>0) {
104 *(fName2Zone
[n
]) = v
;
106 cerr
<< "recallState : parameter not found : " << n
<< " with value : " << v
<< endl
;
113 // -- widget's layouts (just keep track of group labels)
115 virtual void openFrameBox(const char* label
) { pushGroupLabel(label
); }
116 virtual void openTabBox(const char* label
) { pushGroupLabel(label
); }
117 virtual void openHorizontalBox(const char* label
) { pushGroupLabel(label
); }
118 virtual void openVerticalBox(const char* label
) { pushGroupLabel(label
); }
119 virtual void closeBox() { popGroupLabel(); };
121 // -- active widgets (just add an element)
123 virtual void addButton(const char* label
, float* zone
) { addElement(label
, zone
); }
124 virtual void addToggleButton(const char* label
, float* zone
) { addElement(label
, zone
); }
125 virtual void addCheckButton(const char* label
, float* zone
) { addElement(label
, zone
); }
126 virtual void addVerticalSlider(const char* label
, float* zone
, float , float , float , float )
127 { addElement(label
, zone
); }
128 virtual void addHorizontalSlider(const char* label
, float* zone
, float , float , float , float )
129 { addElement(label
, zone
); }
130 virtual void addNumEntry(const char* label
, float* zone
, float , float , float , float )
131 { addElement(label
, zone
); }
133 // -- passive widgets (are ignored)
135 virtual void addNumDisplay(const char* , float* , int ) {};
136 virtual void addTextDisplay(const char* , float* , const char*[], float , float ) {};
137 virtual void addHorizontalBargraph(const char* , float* , float , float ) {};
138 virtual void addVerticalBargraph(const char* , float* , float , float ) {};
140 // -- metadata are not used
142 virtual void declare(float* , const char* , const char* ) {}