1 | // TODO ! |
---|
2 | |
---|
3 | // |
---|
4 | // ******************************************************************** |
---|
5 | // * License and Disclaimer * |
---|
6 | // * * |
---|
7 | // * The Geant4 software is copyright of the Copyright Holders of * |
---|
8 | // * the Geant4 Collaboration. It is provided under the terms and * |
---|
9 | // * conditions of the Geant4 Software License, included in the file * |
---|
10 | // * LICENSE and available at http://cern.ch/geant4/license . These * |
---|
11 | // * include a list of copyright holders. * |
---|
12 | // * * |
---|
13 | // * Neither the authors of this software system, nor their employing * |
---|
14 | // * institutes,nor the agencies providing financial support for this * |
---|
15 | // * work make any representation or warranty, express or implied, * |
---|
16 | // * regarding this software system or assume any liability for its * |
---|
17 | // * use. Please see the license in the file LICENSE and URL above * |
---|
18 | // * for the full disclaimer and the limitation of liability. * |
---|
19 | // * * |
---|
20 | // * This code implementation is the result of the scientific and * |
---|
21 | // * technical work of the GEANT4 collaboration. * |
---|
22 | // * By using, copying, modifying or distributing the software (or * |
---|
23 | // * any work based on the software) you agree to acknowledge its * |
---|
24 | // * use in resulting scientific publications, and indicate your * |
---|
25 | // * acceptance of all terms of the Geant4 Software license. * |
---|
26 | // ******************************************************************** |
---|
27 | // |
---|
28 | // |
---|
29 | // $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $ |
---|
30 | // GEANT4 tag $Name: geant4-08-01 $ |
---|
31 | // |
---|
32 | // L. Garnier |
---|
33 | |
---|
34 | //#define DEBUG |
---|
35 | |
---|
36 | #ifdef G4UI_BUILD_QT_SESSION |
---|
37 | |
---|
38 | #include "G4Types.hh" |
---|
39 | |
---|
40 | #include <string.h> |
---|
41 | |
---|
42 | #include "G4UIQt.hh" |
---|
43 | #include "G4UImanager.hh" |
---|
44 | #include "G4StateManager.hh" |
---|
45 | #include "G4UIcommandTree.hh" |
---|
46 | #include "G4UIcommandStatus.hh" |
---|
47 | |
---|
48 | #include "G4Qt.hh" |
---|
49 | |
---|
50 | #include <QtGui/qapplication.h> |
---|
51 | #include <QtGui/qwidget.h> |
---|
52 | #include <QtGui/qmenu.h> |
---|
53 | #include <QtGui/qmenubar.h> |
---|
54 | #include <QtGui/qboxlayout.h> |
---|
55 | #include <QtGui/qpushbutton.h> |
---|
56 | #include <QtGui/qlabel.h> |
---|
57 | #include <QtGui/qsplitter.h> |
---|
58 | #include <QtGui/qscrollbar.h> |
---|
59 | |
---|
60 | #include <stdlib.h> |
---|
61 | |
---|
62 | static G4bool ConvertStringToInt(const char*,int&); |
---|
63 | |
---|
64 | static G4bool exitSession = true; |
---|
65 | static G4bool exitPause = true; |
---|
66 | static G4bool exitHelp = true; |
---|
67 | /***************************************************************************/ |
---|
68 | /** |
---|
69 | Build a Qt window with a menubar, output area and promt area |
---|
70 | +-----------------------+ |
---|
71 | |exit menu| | |
---|
72 | | | |
---|
73 | | +-------------------+ | |
---|
74 | | | | | |
---|
75 | | | Output area | | |
---|
76 | | | | | |
---|
77 | | +-------------------+ | |
---|
78 | | | clear | | |
---|
79 | | +-------------------+ | |
---|
80 | | | promt history | | |
---|
81 | | +-------------------+ | |
---|
82 | | +-------------------+ | |
---|
83 | | |> promt area | | |
---|
84 | | +-------------------+ | |
---|
85 | +-----------------------+ |
---|
86 | */ |
---|
87 | |
---|
88 | G4UIQt::G4UIQt ( |
---|
89 | int argc, |
---|
90 | char** argv |
---|
91 | ) |
---|
92 | /***************************************************************************/ |
---|
93 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
94 | { |
---|
95 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
96 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
97 | if(UI!=NULL) UI->SetSession(this); // TO KEEP |
---|
98 | |
---|
99 | fMainWindow = new QMainWindow(); |
---|
100 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
101 | fMainWindow->resize(800,600); |
---|
102 | |
---|
103 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
104 | fTextArea = new QTextEdit(); |
---|
105 | QPushButton *clearButton = new QPushButton("clear"); |
---|
106 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
107 | |
---|
108 | fCommandHistoryArea = new QTextEdit(); |
---|
109 | fCommandLabel = new QLabel(); |
---|
110 | |
---|
111 | fCommandArea = new QLineEdit(); |
---|
112 | fCommandArea->activateWindow(); |
---|
113 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
114 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
115 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
116 | fTextArea->setReadOnly(true); |
---|
117 | fCommandHistoryArea->setReadOnly(true); |
---|
118 | |
---|
119 | |
---|
120 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
121 | |
---|
122 | QWidget* topWidget = new QWidget(); |
---|
123 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
124 | |
---|
125 | QWidget* bottomWidget = new QWidget(); |
---|
126 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
127 | |
---|
128 | |
---|
129 | layoutTop->addWidget(fTextArea); |
---|
130 | layoutTop->addWidget(clearButton); |
---|
131 | topWidget->setLayout(layoutTop); |
---|
132 | |
---|
133 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
134 | layoutBottom->addWidget(fCommandLabel); |
---|
135 | layoutBottom->addWidget(fCommandArea); |
---|
136 | bottomWidget->setLayout(layoutBottom); |
---|
137 | |
---|
138 | |
---|
139 | layoutSplitter->addWidget(topWidget); |
---|
140 | layoutSplitter->addWidget(bottomWidget); |
---|
141 | splitter->setLayout(layoutSplitter); |
---|
142 | |
---|
143 | fMainWindow->setCentralWidget(splitter); |
---|
144 | |
---|
145 | |
---|
146 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu(tr("&File")); |
---|
147 | fileMenu->addAction("Quitter", this, SLOT(fMainWindow->close())); |
---|
148 | fileMenu->addAction("Quitter2", this, SLOT(fMainWindow->close())); |
---|
149 | fileMenu->addSeparator(); |
---|
150 | |
---|
151 | |
---|
152 | // QMainWindow top = (QMainWindow)interactorManager->GetMainInteractor(); |
---|
153 | |
---|
154 | // if(getenv("XENVIRONMENT")==NULL) { |
---|
155 | // XrmDatabase database = XrmGetDatabase(XtDisplay(top)); |
---|
156 | // if(database!=NULL) { |
---|
157 | // XrmPutLineResource(&database,"*topShadowColor:white"); |
---|
158 | // XrmPutLineResource(&database,"*bottomShadowColor:black"); |
---|
159 | // XrmPutLineResource(&database,"*foreground:black"); |
---|
160 | // XrmPutLineResource(&database,"*background:lightgrey"); |
---|
161 | // XrmPutLineResource(&database,"*borderColor:lightgrey"); |
---|
162 | // XrmPutLineResource(&database,"*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"); |
---|
163 | // XrmPutLineResource(&database,"*text.background:white"); |
---|
164 | // XrmPutLineResource(&database,"*text.fontList:*courier*-r-*--14-*"); |
---|
165 | // XrmPutLineResource(&database,"*text.maxLength:8000"); |
---|
166 | // } |
---|
167 | // } |
---|
168 | |
---|
169 | // Arg args[9]; |
---|
170 | // XtSetArg(args[0],XmNkeyboardFocusPolicy,XmPOINTER); // For completion. |
---|
171 | // shell = XtAppCreateShell ("G4UIXm","G4UIXm", |
---|
172 | // topLevelShellWidgetClass,XtDisplay(top), |
---|
173 | // args,1); |
---|
174 | // form = XmCreateForm (shell,(char*)"form",NULL,0); |
---|
175 | // XtManageChild (form); |
---|
176 | |
---|
177 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
178 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
179 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
180 | // menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3); |
---|
181 | |
---|
182 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE); |
---|
183 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
184 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
185 | // XtSetArg(args[3],XmNbottomAttachment ,XmATTACH_FORM); |
---|
186 | // command = XmCreateCommand (form,(char*)"command",args,4); |
---|
187 | // XtManageChild (command); |
---|
188 | |
---|
189 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE); |
---|
190 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
191 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
192 | // XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
193 | // XtSetArg(args[4],XmNbottomWidget ,command); |
---|
194 | // XmString cps = XmStringLtoRCreate((char*)"Clear",XmSTRING_DEFAULT_CHARSET); |
---|
195 | // XtSetArg (args[5],XmNlabelString,cps); |
---|
196 | // Widget clearButton = XmCreatePushButton(form,(char*)"clearButton",args,6); |
---|
197 | // XmStringFree (cps); |
---|
198 | // XtManageChild (clearButton); |
---|
199 | |
---|
200 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET); |
---|
201 | // XtSetArg(args[1],XmNtopWidget ,menuBar); |
---|
202 | // XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM); |
---|
203 | // XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM); |
---|
204 | // XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
205 | // XtSetArg(args[5],XmNbottomWidget ,clearButton); |
---|
206 | // XtSetArg(args[6],XmNeditMode ,XmMULTI_LINE_EDIT); |
---|
207 | // XtSetArg(args[7],XmNrows ,12); |
---|
208 | // XtSetArg(args[8],XmNcolumns ,80); |
---|
209 | // text = XmCreateSGcrolledText (form,(char*)"text",args,9); |
---|
210 | // XtManageChild (text); |
---|
211 | |
---|
212 | // XtAddCallback(clearButton,XmNactivateCallback, |
---|
213 | // clearButtonCallback,(XtPointer)text); |
---|
214 | // XtAddCallback(command,XmNcommandEnteredCallback, |
---|
215 | // commandEnteredCallback,(XtPointer)this); |
---|
216 | |
---|
217 | // Widget commandText = XmCommandGetChild(command,XmDIALOG_COMMAND_TEXT); |
---|
218 | // XtAddEventHandler(commandText,KeyPressMask,False,keyHandler,(XtPointer)this); |
---|
219 | |
---|
220 | // XtRealizeWidget(shell); |
---|
221 | // XtMapWidget(shell); |
---|
222 | |
---|
223 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
224 | } |
---|
225 | /***************************************************************************/ |
---|
226 | G4UIQt::~G4UIQt( |
---|
227 | ) |
---|
228 | /***************************************************************************/ |
---|
229 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
230 | { |
---|
231 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
232 | if(UI!=NULL) { // TO KEEP |
---|
233 | UI->SetSession(NULL); // TO KEEP |
---|
234 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
235 | } |
---|
236 | |
---|
237 | |
---|
238 | if (fMainWindow!=NULL) |
---|
239 | delete fMainWindow; |
---|
240 | } |
---|
241 | /***************************************************************************/ |
---|
242 | /* |
---|
243 | Start the Qt main loop |
---|
244 | */ |
---|
245 | G4UIsession* G4UIQt::SessionStart ( |
---|
246 | ) |
---|
247 | /***************************************************************************/ |
---|
248 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
249 | { |
---|
250 | |
---|
251 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
252 | fMainWindow->show(); |
---|
253 | Prompt("session"); |
---|
254 | exitSession = false; |
---|
255 | |
---|
256 | |
---|
257 | printf("disable secondary loop\n"); |
---|
258 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
259 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
260 | // on ne passe pas le dessous ? FIXME ???? |
---|
261 | |
---|
262 | |
---|
263 | |
---|
264 | |
---|
265 | |
---|
266 | |
---|
267 | // void* event; // TO KEEP |
---|
268 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
269 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
270 | // if(exitSession==true) break; // TO KEEP |
---|
271 | // } // TO KEEP |
---|
272 | interactorManager->EnableSecondaryLoop (); // TO KEEP |
---|
273 | printf("enable secondary loop\n"); |
---|
274 | return this; // TO KEEP |
---|
275 | } |
---|
276 | /***************************************************************************/ |
---|
277 | |
---|
278 | /** |
---|
279 | Display the prompt in the prompt area |
---|
280 | */ |
---|
281 | void G4UIQt::Prompt ( |
---|
282 | G4String aPrompt |
---|
283 | ) |
---|
284 | /***************************************************************************/ |
---|
285 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
286 | { |
---|
287 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
288 | } |
---|
289 | /***************************************************************************/ |
---|
290 | void G4UIQt::SessionTerminate ( |
---|
291 | ) |
---|
292 | /***************************************************************************/ |
---|
293 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
294 | { |
---|
295 | } |
---|
296 | /***************************************************************************/ |
---|
297 | void G4UIQt::PauseSessionStart ( |
---|
298 | G4String a_state |
---|
299 | ) |
---|
300 | /***************************************************************************/ |
---|
301 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
302 | { |
---|
303 | printf("G4UIQt::PauseSessionStart\n"); |
---|
304 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
305 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
306 | } // TO KEEP |
---|
307 | |
---|
308 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
309 | // Picking with feed back in event data Done here !!! |
---|
310 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
311 | } // TO KEEP |
---|
312 | } |
---|
313 | /***************************************************************************/ |
---|
314 | void G4UIQt::SecondaryLoop ( |
---|
315 | G4String a_prompt |
---|
316 | ) |
---|
317 | /***************************************************************************/ |
---|
318 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
319 | { |
---|
320 | printf("G4UIQt::SecondaryLoop\n"); |
---|
321 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
322 | Prompt(a_prompt); // TO KEEP |
---|
323 | exitPause = false; // TO KEEP |
---|
324 | void* event; // TO KEEP |
---|
325 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
326 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
327 | if(exitPause==true) break; // TO KEEP |
---|
328 | } // TO KEEP |
---|
329 | Prompt("session"); // TO KEEP |
---|
330 | } |
---|
331 | /***************************************************************************/ |
---|
332 | /** |
---|
333 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
334 | */ |
---|
335 | G4int G4UIQt::ReceiveG4cout ( |
---|
336 | G4String a_string |
---|
337 | ) |
---|
338 | /***************************************************************************/ |
---|
339 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
340 | { |
---|
341 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
342 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
343 | return 0; |
---|
344 | } |
---|
345 | /***************************************************************************/ |
---|
346 | /** |
---|
347 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
348 | */ |
---|
349 | G4int G4UIQt::ReceiveG4cerr ( |
---|
350 | G4String a_string |
---|
351 | ) |
---|
352 | /***************************************************************************/ |
---|
353 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
354 | { |
---|
355 | QColor previousColor = fTextArea->textColor(); |
---|
356 | fTextArea->setTextColor(Qt::red); |
---|
357 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
358 | fTextArea->setTextColor(previousColor); |
---|
359 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
360 | return 0; |
---|
361 | } |
---|
362 | /***************************************************************************/ |
---|
363 | G4bool G4UIQt::GetHelpChoice( |
---|
364 | G4int& aInt |
---|
365 | ) |
---|
366 | /***************************************************************************/ |
---|
367 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
368 | { |
---|
369 | printf("G4UIQt::GetHelpChoice\n"); |
---|
370 | |
---|
371 | fHelp = true; // TO KEEP |
---|
372 | // // SecondaryLoop : // TO KEEP |
---|
373 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
374 | Prompt("Help"); // TO KEEP |
---|
375 | exitHelp = false; // TO KEEP |
---|
376 | void* event; // TO KEEP |
---|
377 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
378 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
379 | if(exitHelp==true) break; // TO KEEP |
---|
380 | } // TO KEEP |
---|
381 | Prompt("session"); // TO KEEP |
---|
382 | // // TO KEEP |
---|
383 | if(fHelp==false) return false; // TO KEEP |
---|
384 | aInt = fHelpChoice; // TO KEEP |
---|
385 | fHelp = false; // TO KEEP |
---|
386 | return true; // TO KEEP |
---|
387 | } |
---|
388 | /***************************************************************************/ |
---|
389 | void G4UIQt::ExitHelp( |
---|
390 | ) |
---|
391 | /***************************************************************************/ |
---|
392 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
393 | { |
---|
394 | printf("G4UIQt::ExitHelp\n"); |
---|
395 | } |
---|
396 | |
---|
397 | /***************************************************************************/ |
---|
398 | void G4UIQt::AddMenu ( |
---|
399 | const char* a_name |
---|
400 | ,const char* a_label |
---|
401 | ) |
---|
402 | /***************************************************************************/ |
---|
403 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
404 | { |
---|
405 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
406 | QString *name = new QString(a_name); |
---|
407 | QString *label = new QString(a_label); |
---|
408 | menuName.push_back(name); |
---|
409 | menuLabel.push_back(label); |
---|
410 | |
---|
411 | // QMenu *menu = new QMenu("test");//a_label); |
---|
412 | // fMainWindow->menuBar()->addMenu(menu); |
---|
413 | |
---|
414 | // if(menuBar==NULL) return; |
---|
415 | // if(a_name==NULL) return; |
---|
416 | // if(a_label==NULL) return; |
---|
417 | // XtManageChild (menuBar); |
---|
418 | // // Pulldown menu : |
---|
419 | // Widget widget; |
---|
420 | // widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0); |
---|
421 | // AddInteractor (a_name,(G4Interactor)widget); |
---|
422 | // // Cascade button : |
---|
423 | // Arg args[2]; |
---|
424 | // XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET); |
---|
425 | // XtSetArg (args[0],XmNlabelString,cps); |
---|
426 | // XtSetArg (args[1],XmNsubMenuId,widget); |
---|
427 | // widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2); |
---|
428 | // XmStringFree (cps); |
---|
429 | // XtManageChild (widget); |
---|
430 | // ExecuteChangeSizeFunction(form); |
---|
431 | } |
---|
432 | /***************************************************************************/ |
---|
433 | void G4UIQt::AddButton ( |
---|
434 | const char* a_menu |
---|
435 | ,const char* a_label |
---|
436 | ,const char* a_command |
---|
437 | ) |
---|
438 | /***************************************************************************/ |
---|
439 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
440 | { |
---|
441 | printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command); |
---|
442 | // if(a_menu==NULL) return; // TO KEEP |
---|
443 | // if(a_label==NULL) return; // TO KEEP |
---|
444 | // if(a_command==NULL) return; // TO KEEP |
---|
445 | // Widget parent = (Widget)GetInteractor(a_menu); |
---|
446 | // if(parent==NULL) return; |
---|
447 | // Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0); |
---|
448 | // XtManageChild (widget); |
---|
449 | // XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this); |
---|
450 | // commands[widget] = a_command; |
---|
451 | } |
---|
452 | // /***************************************************************************/ |
---|
453 | // G4String G4UIXm::GetCommand ( |
---|
454 | // Widget a_widget |
---|
455 | // ) |
---|
456 | // /***************************************************************************/ |
---|
457 | // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
458 | // { |
---|
459 | // return commands[a_widget]; |
---|
460 | // } |
---|
461 | /***************************************************************************/ |
---|
462 | /***************************************************************************/ |
---|
463 | /***************************************************************************/ |
---|
464 | |
---|
465 | /** |
---|
466 | Callback call when "enter" clicked on the command zone. |
---|
467 | Send the command to geant4 |
---|
468 | */ |
---|
469 | // TODO ! |
---|
470 | void G4UIQt::commandEnteredCallback ( |
---|
471 | ) |
---|
472 | /***************************************************************************/ |
---|
473 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
474 | { |
---|
475 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
476 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
477 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
478 | if(fHelp==true) { |
---|
479 | exitHelp = true; |
---|
480 | fHelp = ConvertStringToInt(command.data(),fHelpChoice); |
---|
481 | } else { |
---|
482 | ApplyShellCommand (command,exitSession,exitPause); |
---|
483 | } |
---|
484 | } |
---|
485 | fCommandArea->setText(""); |
---|
486 | } |
---|
487 | |
---|
488 | /***************************************************************************/ |
---|
489 | void G4UIQt::clearButtonCallback ( |
---|
490 | ) |
---|
491 | /***************************************************************************/ |
---|
492 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
493 | { |
---|
494 | fTextArea->clear(); |
---|
495 | } |
---|
496 | |
---|
497 | ////////////////////////////////////////////////////////////////////////////// |
---|
498 | G4bool ConvertStringToInt( |
---|
499 | const char* aString |
---|
500 | ,int& aInt |
---|
501 | ) |
---|
502 | ////////////////////////////////////////////////////////////////////////////// |
---|
503 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
504 | { |
---|
505 | aInt = 0; // TO KEEP |
---|
506 | if(aString==NULL) return false; // TO KEEP |
---|
507 | char* s; // TO KEEP |
---|
508 | long value = strtol(aString,&s,10); // TO KEEP |
---|
509 | if(s==aString) return false; // TO KEEP |
---|
510 | aInt = value; // TO KEEP |
---|
511 | return true; // TO KEEP |
---|
512 | } |
---|
513 | |
---|
514 | #endif |
---|