File: Fl_ALogs_Manager.cpp

package info (click to toggle)
rtai 3.6.1-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 18,448 kB
  • ctags: 13,674
  • sloc: ansic: 64,656; sh: 11,769; cpp: 10,387; makefile: 1,324; yacc: 575; lex: 366; php: 313; asm: 173; perl: 108; xml: 73
file content (316 lines) | stat: -rw-r--r-- 7,606 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
/*
COPYRIGHT (C) 2003  Lorenzo Dozio (dozio@aero.polimi.it)
	 Adapted by Alberto Sechi (albertosechi@libero.it)	

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
*/

#include <Fl_ALogs_Manager.h>

extern int Num_ALogs;
extern Target_ALogs_T *ALogs;
extern Fl_Tool_Button *RLG_ALogs_Mgr_Button;
extern Fl_Menu_Bar *RLG_Main_Menu;
extern Fl_Main_Window *RLG_Main_Window;
extern Fl_Menu_Item RLG_Main_Menu_Table[];

int Fl_ALogs_Manager::x()
{
	return ALWin->x();
}

int Fl_ALogs_Manager::y()
{
	return ALWin->y();
}

int Fl_ALogs_Manager::w()
{
	return ALWin->w() - ALWin->box()->dw();
}

int Fl_ALogs_Manager::h()
{
	return ALWin->h() - ALWin->titlebar()->h() - ALWin->box()->dh();
}

void Fl_ALogs_Manager::show()
{
        ALWin->show();
}

void Fl_ALogs_Manager::hide()
{
        ALWin->hide();
}

int Fl_ALogs_Manager::visible()
{
        return ALWin->visible();
}

int Fl_ALogs_Manager::start_saving(int n)
{
	return Save_Flag[n];
}

/*int Fl_Logs_Manager::points_time(int n)
{
	return (int)(Save_Type[n]->value());
}

void Fl_Logs_Manager::points_time(int n, bool v)
{
	if (v) {
		Save_Type[n]->set();
		Save_Points[n]->activate();
		Save_Time[n]->deactivate();
	} else {
		Save_Type[n]->clear();
		Save_Points[n]->deactivate();
		Save_Time[n]->activate();
	}
	Logs_Tabs[n]->redraw();
}

int Fl_Logs_Manager::p_save(int n)
{
	int val = (int)atoi(Save_Points[n]->value());
	return val;
}

void Fl_Logs_Manager::p_save(int n, int val)
{
	char buf[20];

	if (val > 0) {
		sprintf(buf, "%d", val);
		Save_Points[n]->value(buf);
	}
}

float Fl_Logs_Manager::t_save(int n)
{
	float val = (float)atof(Save_Time[n]->value());
	return val;
}

void Fl_Logs_Manager::t_save(int n, float val)
{
	char buf[20];

	if (val > 0.) {
		sprintf(buf, "%.4f", val);
		Save_Time[n]->value(buf);
	}
}*/

const char *Fl_ALogs_Manager::file_name(int n)
{
	return (strdup(Save_File[n]->value()));
}

void Fl_ALogs_Manager::file_name(int n, const char *fn)
{
	Save_File[n]->value(strdup(fn));
	ALogs_Tabs[n]->redraw();
}

/*int Fl_ALogs_Manager::n_points_to_save(int n)
{
	int n_points;

	if (Save_Type[n]->value()) {
		n_points = (int)atoi(Save_Points[n]->value());
		if (n_points < 0) return 0;
	} else {
		n_points = (int)(atof(Save_Time[n]->value())/Logs[n].dt);
		if (n_points < 0) return 0;
	}
	return n_points;
}*/

void Fl_ALogs_Manager::stop_saving(int n)
{
	fclose(Save_File_Pointer[n]);
	/*Save_Type[n]->activate();
	if (Save_Type[n]->value()) {
		Save_Points[n]->activate();
	} else {
		Save_Time[n]->activate();
	}
	Save_File[n]->activate();
	Save[n]->activate();
	Save[n]->value(0);
	Save[n]->label("Save");*/
	ALogs_Tabs[n]->redraw();
	Save_Flag[n] = false;
}

FILE *Fl_ALogs_Manager::save_file(int n)
{
	return Save_File_Pointer[n];
}

inline void Fl_ALogs_Manager::select_log_i(Fl_Browser *b, void *v)
{
	int n = b->value();
	for (int i = 0; i < Num_ALogs; i++) {
		ALogs_Tabs[i]->hide();
	}
	ALogs_Tabs[n]->show();
}

void Fl_ALogs_Manager::select_log(Fl_Browser *b, void *v)
{
	((Fl_ALogs_Manager *)(b->parent()->parent()->user_data()))->select_log_i(b,v);
}

inline void Fl_ALogs_Manager::select_save_i(Fl_Check_Button *b, void *v)
{
	int n = (int)v;
	if (b->value()) {
		Save_Points[n]->activate();
		Save_Time[n]->deactivate();
	} else {
		Save_Points[n]->deactivate();
		Save_Time[n]->activate();
	}
	ALogs_Tabs[n]->redraw();
}

void Fl_ALogs_Manager::select_save(Fl_Check_Button *b, void *v)
{
	((Fl_ALogs_Manager *)(b->parent()->parent()->parent()->parent()->user_data()))->select_save_i(b,v);
}

inline void Fl_ALogs_Manager::enable_saving_i(Fl_Light_Button *b, void *v)
{
	int n = (int)v;
	if (b->value()) {
		if ((Save_File_Pointer[n] = fopen(Save_File[n]->value(), "a+")) == NULL) {
			fl_alert("Error in opening file %s", Save_File[n]->value());
			return;
		}
		b->deactivate();
		/*Save_Type[n]->deactivate();
		Save_Time[n]->deactivate();
		Save_Points[n]->deactivate();
		Save_File[n]->deactivate();
		Save[n]->label("Saving...");*/
		ALogs_Tabs[n]->redraw();
		Save_Flag[n] = true;
	}
}

void Fl_ALogs_Manager::enable_saving(Fl_Light_Button *b, void *v)
{
	((Fl_ALogs_Manager *)(b->parent()->parent()->parent()->parent()->user_data()))->enable_saving_i(b,v);
}

inline void Fl_ALogs_Manager::close_i(Fl_Button *b, void *v)
{
	ALWin->hide();
	RLG_ALogs_Mgr_Button->clear();
	RLG_Main_Menu_Table[12].clear();
	RLG_Main_Menu->menu(RLG_Main_Menu_Table);
	RLG_Main_Menu->redraw();
	RLG_Main_Window->redraw();
}

void Fl_ALogs_Manager::close(Fl_Button *b, void *v)
{
	((Fl_ALogs_Manager *)(b->parent()->parent()->user_data()))->close_i(b,v);
}

Fl_ALogs_Manager::Fl_ALogs_Manager(int x, int y, int width, int height, Fl_MDI_Viewport *s, const char *name)
{
	Fl::lock();

	s->begin();
	Fl_MDI_Window *w = ALWin = new Fl_MDI_Window(0, 0, width, height, name);
	w->user_data((void *)this);
	w->resizable(w->view());

	w->titlebar()->close_button()->hide();

	w->view()->begin();

	ALogs_Tabs = new Fl_Tabs*[Num_ALogs];
	/*Save_Type = new Fl_Check_Button*[Num_Logs];
	Save_Points = new Fl_Int_Input*[Num_Logs];
	Save_Time = new Fl_Float_Input*[Num_Logs];*/
	Save_File = new Fl_Input*[Num_ALogs];
	Save = new Fl_Light_Button*[Num_ALogs];
	Save_Flag = new int[Num_ALogs];
	Save_File_Pointer = new FILE*[Num_ALogs];

	for (int i = 0; i < Num_ALogs; i++) {
		Save_Flag[i] = false;
		{ Fl_Tabs *o = ALogs_Tabs[i] = new Fl_Tabs(160, 5, width-165, height-40);
		  o->new_page("Saving");
		  /*{ Fl_Check_Button *o = Save_Type[i] = new Fl_Check_Button(10, 25, 100, 20, "Points/Time");
		    o->value(1);
		    o->callback((Fl_Callback *)select_save, (void *)i);
		  }
		  { Fl_Int_Input *o = Save_Points[i] = new Fl_Int_Input(70, 50, 60, 20, "N Points: ");
		    o->align(FL_ALIGN_LEFT);
		    o->value("1000");
		  }
		  { Fl_Float_Input *o = Save_Time[i] = new Fl_Float_Input(70, 75, 60, 20, "Time [s]:  ");
		    o->align(FL_ALIGN_LEFT);
		    o->value("1.0");
		    o->deactivate();
		  }*/
		  { Fl_Input *o = Save_File[i] = new Fl_Input(70, 100, 0, 0, " ");
		    char buf[100];
		    o->align(FL_ALIGN_LEFT);
		    sprintf(buf, "%s", ALogs[i].name);
		    o->value(buf);
		  }
		  /*{ Fl_Light_Button *o = Save[i] = new Fl_Light_Button(10, 130, 90, 25, "Save");
		    o->selection_color(FL_BLACK);
		    o->callback((Fl_Callback *)enable_saving, (void *)i);
		  }*/
		  o->end();
		  Fl_Group::current()->resizable(w);
		}
	}
	for (int i = 1; i < Num_ALogs; i++) {
		ALogs_Tabs[i]->hide();
	}
	ALogs_Tabs[0]->show();

	Help = new Fl_Button(width-150, height-30, 70, 25, "Help");
	Close = new Fl_Button(width-75, height-30, 70, 25, "Close");
	Close->callback((Fl_Callback *)close);

	Fl_Browser *o = ALogs_Tree = new Fl_Browser(5, 5, 150, height-10);
	o->indented(1);
	o->callback((Fl_Callback *)select_log);
	for (int i = 0; i < Num_ALogs; i++) {
		add_paper(ALogs_Tree, ALogs[i].name, Fl_Image::read_xpm(0, folder_asmall));
	}

	w->view()->end();

	s->end();

	w->titlebar()->h(15);
	w->titlebar()->color(FL_BLACK);
	w->position(x, y);

	Fl::unlock();
}