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 | #include <QtGui/qdialog.h> |
---|
60 | |
---|
61 | #include <stdlib.h> |
---|
62 | |
---|
63 | static G4bool ConvertStringToInt(const char*,int&); |
---|
64 | |
---|
65 | static G4bool exitSession = true; |
---|
66 | static G4bool exitPause = true; |
---|
67 | static G4bool exitHelp = true; |
---|
68 | /***************************************************************************/ |
---|
69 | /** |
---|
70 | Build a Qt window with a menubar, output area and promt area |
---|
71 | +-----------------------+ |
---|
72 | |exit menu| | |
---|
73 | | | |
---|
74 | | +-------------------+ | |
---|
75 | | | | | |
---|
76 | | | Output area | | |
---|
77 | | | | | |
---|
78 | | +-------------------+ | |
---|
79 | | | clear | | |
---|
80 | | +-------------------+ | |
---|
81 | | | promt history | | |
---|
82 | | +-------------------+ | |
---|
83 | | +-------------------+ | |
---|
84 | | |> promt area | | |
---|
85 | | +-------------------+ | |
---|
86 | +-----------------------+ |
---|
87 | */ |
---|
88 | |
---|
89 | G4UIQt::G4UIQt ( |
---|
90 | int argc, |
---|
91 | char** argv |
---|
92 | ) |
---|
93 | /***************************************************************************/ |
---|
94 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
95 | { |
---|
96 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
97 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
98 | if(UI!=NULL) UI->SetSession(this); |
---|
99 | |
---|
100 | fMainWindow = new QMainWindow(); |
---|
101 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
102 | fMainWindow->resize(800,600); |
---|
103 | fMainWindow->move(QPoint(300,100)); |
---|
104 | |
---|
105 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
106 | fTextArea = new QTextEdit(); |
---|
107 | QPushButton *clearButton = new QPushButton("clear"); |
---|
108 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
109 | |
---|
110 | fCommandHistoryArea = new QTextEdit(); |
---|
111 | fCommandLabel = new QLabel(); |
---|
112 | |
---|
113 | fCommandArea = new QLineEdit(); |
---|
114 | fCommandArea->activateWindow(); |
---|
115 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
116 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
117 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
118 | fTextArea->setReadOnly(true); |
---|
119 | fCommandHistoryArea->setReadOnly(true); |
---|
120 | |
---|
121 | |
---|
122 | |
---|
123 | // Set layouts |
---|
124 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
125 | |
---|
126 | QWidget* topWidget = new QWidget(); |
---|
127 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
128 | |
---|
129 | QWidget* bottomWidget = new QWidget(); |
---|
130 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
131 | |
---|
132 | |
---|
133 | layoutTop->addWidget(fTextArea); |
---|
134 | layoutTop->addWidget(clearButton); |
---|
135 | topWidget->setLayout(layoutTop); |
---|
136 | |
---|
137 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
138 | layoutBottom->addWidget(fCommandLabel); |
---|
139 | layoutBottom->addWidget(fCommandArea); |
---|
140 | bottomWidget->setLayout(layoutBottom); |
---|
141 | |
---|
142 | |
---|
143 | layoutSplitter->addWidget(topWidget); |
---|
144 | layoutSplitter->addWidget(bottomWidget); |
---|
145 | splitter->setLayout(layoutSplitter); |
---|
146 | |
---|
147 | fMainWindow->setCentralWidget(splitter); |
---|
148 | |
---|
149 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
150 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close())); |
---|
151 | |
---|
152 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
153 | QList<int> vals = splitter->sizes(); |
---|
154 | if(vals.size()==2) { |
---|
155 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
156 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
157 | splitter->setSizes(vals); |
---|
158 | } |
---|
159 | |
---|
160 | |
---|
161 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
162 | } |
---|
163 | /***************************************************************************/ |
---|
164 | G4UIQt::~G4UIQt( |
---|
165 | ) |
---|
166 | /***************************************************************************/ |
---|
167 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
168 | { |
---|
169 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
170 | if(UI!=NULL) { // TO KEEP |
---|
171 | UI->SetSession(NULL); // TO KEEP |
---|
172 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
173 | } |
---|
174 | |
---|
175 | |
---|
176 | if (fMainWindow!=NULL) |
---|
177 | delete fMainWindow; |
---|
178 | } |
---|
179 | /***************************************************************************/ |
---|
180 | /* |
---|
181 | Start the Qt main loop |
---|
182 | */ |
---|
183 | G4UIsession* G4UIQt::SessionStart ( |
---|
184 | ) |
---|
185 | /***************************************************************************/ |
---|
186 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
187 | { |
---|
188 | |
---|
189 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
190 | fMainWindow->show(); |
---|
191 | Prompt("session"); |
---|
192 | exitSession = false; |
---|
193 | |
---|
194 | |
---|
195 | printf("disable secondary loop\n"); |
---|
196 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
197 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
198 | // on ne passe pas le dessous ? FIXME ???? |
---|
199 | // je ne pense pas 13/06 |
---|
200 | |
---|
201 | // void* event; // TO KEEP |
---|
202 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
203 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
204 | // if(exitSession==true) break; // TO KEEP |
---|
205 | // } // TO KEEP |
---|
206 | |
---|
207 | interactorManager->EnableSecondaryLoop (); |
---|
208 | printf("enable secondary loop\n"); |
---|
209 | return this; |
---|
210 | } |
---|
211 | /***************************************************************************/ |
---|
212 | |
---|
213 | /** |
---|
214 | Display the prompt in the prompt area |
---|
215 | */ |
---|
216 | void G4UIQt::Prompt ( |
---|
217 | G4String aPrompt |
---|
218 | ) |
---|
219 | /***************************************************************************/ |
---|
220 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
221 | { |
---|
222 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
223 | } |
---|
224 | /***************************************************************************/ |
---|
225 | void G4UIQt::SessionTerminate ( |
---|
226 | ) |
---|
227 | /***************************************************************************/ |
---|
228 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
229 | { |
---|
230 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
231 | fMainWindow->close(); |
---|
232 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
233 | } |
---|
234 | /***************************************************************************/ |
---|
235 | void G4UIQt::PauseSessionStart ( |
---|
236 | G4String a_state |
---|
237 | ) |
---|
238 | /***************************************************************************/ |
---|
239 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
240 | { |
---|
241 | printf("G4UIQt::PauseSessionStart\n"); |
---|
242 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
243 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
244 | } // TO KEEP |
---|
245 | |
---|
246 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
247 | // Picking with feed back in event data Done here !!! |
---|
248 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
249 | } // TO KEEP |
---|
250 | } |
---|
251 | /***************************************************************************/ |
---|
252 | void G4UIQt::SecondaryLoop ( |
---|
253 | G4String a_prompt |
---|
254 | ) |
---|
255 | /***************************************************************************/ |
---|
256 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
257 | { |
---|
258 | printf("G4UIQt::SecondaryLoop\n"); |
---|
259 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
260 | Prompt(a_prompt); // TO KEEP |
---|
261 | exitPause = false; // TO KEEP |
---|
262 | void* event; // TO KEEP |
---|
263 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
264 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
265 | if(exitPause==true) break; // TO KEEP |
---|
266 | } // TO KEEP |
---|
267 | Prompt("session"); // TO KEEP |
---|
268 | } |
---|
269 | /***************************************************************************/ |
---|
270 | /** |
---|
271 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
272 | */ |
---|
273 | G4int G4UIQt::ReceiveG4cout ( |
---|
274 | G4String a_string |
---|
275 | ) |
---|
276 | /***************************************************************************/ |
---|
277 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
278 | { |
---|
279 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
280 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
281 | return 0; |
---|
282 | } |
---|
283 | /***************************************************************************/ |
---|
284 | /** |
---|
285 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
286 | */ |
---|
287 | G4int G4UIQt::ReceiveG4cerr ( |
---|
288 | G4String a_string |
---|
289 | ) |
---|
290 | /***************************************************************************/ |
---|
291 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
292 | { |
---|
293 | QColor previousColor = fTextArea->textColor(); |
---|
294 | fTextArea->setTextColor(Qt::red); |
---|
295 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
296 | fTextArea->setTextColor(previousColor); |
---|
297 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
298 | return 0; |
---|
299 | } |
---|
300 | /***************************************************************************/ |
---|
301 | G4bool G4UIQt::GetHelpChoice( |
---|
302 | G4int& aInt |
---|
303 | ) |
---|
304 | /***************************************************************************/ |
---|
305 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
306 | { |
---|
307 | printf("G4UIQt::GetHelpChoice\n"); |
---|
308 | |
---|
309 | fHelp = true; // TO KEEP |
---|
310 | // // SecondaryLoop : // TO KEEP |
---|
311 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
312 | Prompt("Help"); // TO KEEP |
---|
313 | exitHelp = false; // TO KEEP |
---|
314 | void* event; // TO KEEP |
---|
315 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
316 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
317 | if(exitHelp==true) break; // TO KEEP |
---|
318 | } // TO KEEP |
---|
319 | Prompt("session"); // TO KEEP |
---|
320 | // // TO KEEP |
---|
321 | if(fHelp==false) return false; // TO KEEP |
---|
322 | aInt = fHelpChoice; // TO KEEP |
---|
323 | fHelp = false; // TO KEEP |
---|
324 | return true; // TO KEEP |
---|
325 | } |
---|
326 | /***************************************************************************/ |
---|
327 | void G4UIQt::ExitHelp( |
---|
328 | ) |
---|
329 | /***************************************************************************/ |
---|
330 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
331 | { |
---|
332 | printf("G4UIQt::ExitHelp\n"); |
---|
333 | } |
---|
334 | |
---|
335 | /***************************************************************************/ |
---|
336 | void G4UIQt::AddMenu ( |
---|
337 | const char* a_name |
---|
338 | ,const char* a_label |
---|
339 | ) |
---|
340 | /***************************************************************************/ |
---|
341 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
342 | { |
---|
343 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
344 | |
---|
345 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label); |
---|
346 | AddInteractor (a_name,(G4Interactor)fileMenu); |
---|
347 | |
---|
348 | // QMenu *menu = new QMenu("test");//a_label); |
---|
349 | // fMainWindow->menuBar()->addMenu(menu); |
---|
350 | |
---|
351 | // if(menuBar==NULL) return; |
---|
352 | // if(a_name==NULL) return; |
---|
353 | // if(a_label==NULL) return; |
---|
354 | // XtManageChild (menuBar); |
---|
355 | // // Pulldown menu : |
---|
356 | // Widget widget; |
---|
357 | // widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0); |
---|
358 | // AddInteractor (a_name,(G4Interactor)widget); |
---|
359 | // // Cascade button : |
---|
360 | // Arg args[2]; |
---|
361 | // XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET); |
---|
362 | // XtSetArg (args[0],XmNlabelString,cps); |
---|
363 | // XtSetArg (args[1],XmNsubMenuId,widget); |
---|
364 | // widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2); |
---|
365 | // XmStringFree (cps); |
---|
366 | // XtManageChild (widget); |
---|
367 | // ExecuteChangeSizeFunction(form); |
---|
368 | } |
---|
369 | /***************************************************************************/ |
---|
370 | void G4UIQt::AddButton ( |
---|
371 | const char* a_menu |
---|
372 | ,const char* a_label |
---|
373 | ,const char* a_command |
---|
374 | ) |
---|
375 | /***************************************************************************/ |
---|
376 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
377 | { |
---|
378 | if(a_menu==NULL) return; // TO KEEP |
---|
379 | if(a_label==NULL) return; // TO KEEP |
---|
380 | if(a_command==NULL) return; // TO KEEP |
---|
381 | QMenu *parent = (QMenu*)GetInteractor(a_menu); |
---|
382 | if(parent==NULL) return; |
---|
383 | |
---|
384 | signalMapper = new QSignalMapper(this); |
---|
385 | QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
386 | signalMapper->setMapping(action, QString(a_command)); |
---|
387 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&))); |
---|
388 | |
---|
389 | // std::string slot = SLOT(buttonCallback(std::string)); |
---|
390 | printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command); |
---|
391 | |
---|
392 | // Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0); |
---|
393 | // XtManageChild (widget); |
---|
394 | // XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this); |
---|
395 | // commands[action] = a_command; |
---|
396 | } |
---|
397 | |
---|
398 | |
---|
399 | // /***************************************************************************/ |
---|
400 | //G4String G4UIQt::GetCommand ( |
---|
401 | // QAction *a_widget |
---|
402 | //) |
---|
403 | // /***************************************************************************/ |
---|
404 | // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
405 | // { |
---|
406 | // return commands[a_widget]; |
---|
407 | // } |
---|
408 | /***************************************************************************/ |
---|
409 | /***************************************************************************/ |
---|
410 | /***************************************************************************/ |
---|
411 | |
---|
412 | /** |
---|
413 | Callback call when "enter" clicked on the command zone. |
---|
414 | Send the command to geant4 |
---|
415 | */ |
---|
416 | void G4UIQt::buttonCallback ( |
---|
417 | const QString& a_command |
---|
418 | ) |
---|
419 | /***************************************************************************/ |
---|
420 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
421 | { |
---|
422 | if(fHelp==true) return; // Disabled when in help. |
---|
423 | G4String ss = G4String(a_command.toStdString().c_str()); |
---|
424 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); |
---|
425 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
426 | if(exitSession==true) |
---|
427 | SessionTerminate(); |
---|
428 | } |
---|
429 | |
---|
430 | /** |
---|
431 | Callback call when "click on a menu entry. |
---|
432 | Send the associated command to geant4 |
---|
433 | */ |
---|
434 | void G4UIQt::commandEnteredCallback ( |
---|
435 | ) |
---|
436 | /***************************************************************************/ |
---|
437 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
438 | { |
---|
439 | printf ("debug : callback\n"); |
---|
440 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
441 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
442 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
443 | if(fHelp==true) { |
---|
444 | printf ("ne doit plus passer ici\n"); |
---|
445 | exitHelp = true; |
---|
446 | fHelp = ConvertStringToInt(command.data(),fHelpChoice); |
---|
447 | } else { |
---|
448 | if (command(0,4) != "help") { |
---|
449 | ApplyShellCommand (command,exitSession,exitPause); |
---|
450 | } else { |
---|
451 | printf ("terminal help\n"); |
---|
452 | TerminalHelp(command); |
---|
453 | } |
---|
454 | if(exitSession==true) |
---|
455 | SessionTerminate(); |
---|
456 | } |
---|
457 | } |
---|
458 | fCommandArea->setText(""); |
---|
459 | } |
---|
460 | |
---|
461 | |
---|
462 | /***************************************************************************/ |
---|
463 | void G4UIQt::clearButtonCallback ( |
---|
464 | ) |
---|
465 | /***************************************************************************/ |
---|
466 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
467 | { |
---|
468 | fTextArea->clear(); |
---|
469 | } |
---|
470 | |
---|
471 | ////////////////////////////////////////////////////////////////////////////// |
---|
472 | G4bool ConvertStringToInt( |
---|
473 | const char* aString |
---|
474 | ,int& aInt |
---|
475 | ) |
---|
476 | ////////////////////////////////////////////////////////////////////////////// |
---|
477 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
478 | { |
---|
479 | aInt = 0; // TO KEEP |
---|
480 | if(aString==NULL) return false; // TO KEEP |
---|
481 | char* s; // TO KEEP |
---|
482 | long value = strtol(aString,&s,10); // TO KEEP |
---|
483 | if(s==aString) return false; // TO KEEP |
---|
484 | aInt = value; // TO KEEP |
---|
485 | return true; // TO KEEP |
---|
486 | } |
---|
487 | |
---|
488 | #endif |
---|
489 | |
---|
490 | void G4UIQt::TerminalHelp(G4String newCommand) |
---|
491 | { |
---|
492 | QDialog *helpDialog = new QDialog; |
---|
493 | |
---|
494 | QSplitter *splitter = new QSplitter(Qt::Horizontal); |
---|
495 | QTextEdit *fhelpArea = new QTextEdit(); |
---|
496 | QPushButton *exitButton = new QPushButton("Exit"); |
---|
497 | connect(exitButton, SIGNAL(clicked()), helpDialog,SLOT(close())); |
---|
498 | fHelpArea->setReadOnly(true); |
---|
499 | |
---|
500 | // the help tree |
---|
501 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
502 | if(UI==NULL) return; |
---|
503 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
504 | |
---|
505 | QTreeWidget *treeWidget = new QTreeWidget(); |
---|
506 | treeWidget->setColumnCount(2); |
---|
507 | QStringList labels; |
---|
508 | labels << QString("Summary") << QString("Description"); |
---|
509 | treeWidget->setHeaderLabels(labels); |
---|
510 | |
---|
511 | QList<QTreeWidgetItem *> items; |
---|
512 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
513 | QTreeWidgetItem * newItem; |
---|
514 | for (unsigned int a=0;a<treeSize;a++) { |
---|
515 | // Creating new item |
---|
516 | QStringList stringList; |
---|
517 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
518 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
519 | |
---|
520 | newItem = new QTreeWidgetItem(stringList); |
---|
521 | |
---|
522 | // look for childs |
---|
523 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
524 | |
---|
525 | items.append(newItem); |
---|
526 | } |
---|
527 | treeWidget->insertTopLevelItems(0, items); |
---|
528 | |
---|
529 | |
---|
530 | // Set layouts |
---|
531 | QHBoxLayout *splitterLayout = new QHBoxLayout; |
---|
532 | |
---|
533 | QWidget* topWidget = new QWidget(); |
---|
534 | QVBoxLayout *vLayout = new QVBoxLayout; |
---|
535 | |
---|
536 | splitterLayout->addWidget(treeWidget); |
---|
537 | splitterLayout->addWidget(fHelpArea); |
---|
538 | splitter->setLayout(splitterLayout); |
---|
539 | |
---|
540 | vLayout->addWidget(splitter); |
---|
541 | vLayout->addWidget(exitButton); |
---|
542 | helpDialog->setLayout(vLayout); |
---|
543 | |
---|
544 | helpDialog->resize(800,600); |
---|
545 | helpDialog->move(QPoint(400,150)); |
---|
546 | helpDialog->show(); |
---|
547 | helpDialog->raise(); |
---|
548 | helpDialog->activateWindow(); |
---|
549 | //////////////// |
---|
550 | |
---|
551 | printf ("G4UIQt::TerminalHelp \n"); |
---|
552 | |
---|
553 | |
---|
554 | // size_t i = newCommand.index(" "); |
---|
555 | // if( i != std::string::npos ) |
---|
556 | // { |
---|
557 | // G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
558 | // newValue.strip(G4String::both); |
---|
559 | // G4String targetCom = ModifyToFullPathCommand( newValue ); |
---|
560 | // G4UIcommand* theCommand = treeTop->FindPath( targetCom ); |
---|
561 | // if( theCommand != NULL ) |
---|
562 | // { |
---|
563 | // theCommand->List(); |
---|
564 | // return; |
---|
565 | // } |
---|
566 | // else |
---|
567 | // { |
---|
568 | // G4cout << "Command <" << newValue << " is not found." << G4endl; |
---|
569 | // return; |
---|
570 | // } |
---|
571 | // } |
---|
572 | |
---|
573 | // G4UIcommandTree * floor[10]; |
---|
574 | // floor[0] = treeTop; |
---|
575 | // G4int iFloor = 0; |
---|
576 | // size_t prefixIndex = 1; |
---|
577 | // G4String prefix = GetCurrentWorkingDirectory(); |
---|
578 | // while( prefixIndex < prefix.length()-1 ) |
---|
579 | // { |
---|
580 | // size_t ii = prefix.index("/",prefixIndex); |
---|
581 | // floor[iFloor+1] = |
---|
582 | // floor[iFloor]->GetTree(G4String(prefix(0,ii+1))); |
---|
583 | // prefixIndex = ii+1; |
---|
584 | // iFloor++; |
---|
585 | // } |
---|
586 | // floor[iFloor]->ListCurrentWithNum(); |
---|
587 | // // 1998 Oct 2 non-number input |
---|
588 | // while(1){ |
---|
589 | // //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush; |
---|
590 | // G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl; |
---|
591 | // G4int i; |
---|
592 | // if(!GetHelpChoice(i)){ |
---|
593 | // G4cout << G4endl << "Not a number, once more" << G4endl; |
---|
594 | // continue; |
---|
595 | // } else if( i < 0 ){ |
---|
596 | // iFloor += i; |
---|
597 | // if( iFloor < 0 ) iFloor = 0; |
---|
598 | // floor[iFloor]->ListCurrentWithNum(); |
---|
599 | // continue; |
---|
600 | // } else if(i == 0) { |
---|
601 | // break; |
---|
602 | // } else if( i > 0 ) { |
---|
603 | // G4int n_tree = floor[iFloor]->GetTreeEntry(); |
---|
604 | // if( i > n_tree ) |
---|
605 | // { |
---|
606 | // if( i <= n_tree + floor[iFloor]->GetCommandEntry() ) |
---|
607 | // { |
---|
608 | // floor[iFloor]->GetCommand(i-n_tree)->List(); |
---|
609 | // } |
---|
610 | // } |
---|
611 | // else |
---|
612 | // { |
---|
613 | // floor[iFloor+1] = floor[iFloor]->GetTree(i); |
---|
614 | // iFloor++; |
---|
615 | // floor[iFloor]->ListCurrentWithNum(); |
---|
616 | // } |
---|
617 | // } |
---|
618 | // } |
---|
619 | G4cout << "Exit from HELP." << G4endl << G4endl; |
---|
620 | //G4cout << G4endl; |
---|
621 | ExitHelp(); |
---|
622 | } |
---|
623 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) { |
---|
624 | printf ("G4UIQt::CreateChildTree \n"); |
---|
625 | |
---|
626 | // Creating new item |
---|
627 | QTreeWidgetItem * newItem; |
---|
628 | |
---|
629 | // QSignalMapper *signalMapper = new QSignalMapper(this); |
---|
630 | |
---|
631 | // Get the Sub directories |
---|
632 | for (unsigned int a=0;a<a_commandTree->GetTreeEntry();a++) { |
---|
633 | |
---|
634 | QStringList stringList; |
---|
635 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
636 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
637 | newItem = new QTreeWidgetItem(stringList); |
---|
638 | |
---|
639 | //connecting callback |
---|
640 | // signalMapper = new QSignalMapper(this); |
---|
641 | // QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
642 | |
---|
643 | // signalMapper->setMapping(action, QString(a_command)); |
---|
644 | // connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&))); |
---|
645 | //QTreeWidget::itemActivated ( QTreeWidgetItem * item, int column ) [signal] |
---|
646 | |
---|
647 | CreateChildTree(newItem,a_commandTree->GetTree(a+1)); |
---|
648 | a_parent->addChild(newItem); |
---|
649 | } |
---|
650 | |
---|
651 | |
---|
652 | |
---|
653 | // Get the Commands |
---|
654 | |
---|
655 | for (unsigned int a=0;a<a_commandTree->GetCommandEntry();a++) { |
---|
656 | |
---|
657 | QStringList stringList; |
---|
658 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandName()).data()).trimmed() ; |
---|
659 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetTitle()).data()).trimmed() ; |
---|
660 | newItem = new QTreeWidgetItem(stringList); |
---|
661 | |
---|
662 | //connecting callback |
---|
663 | signalMapper = new QSignalMapper(this); |
---|
664 | connect(newItem, SIGNAL(itemActivated(QTreeWidgetItem*, int)), signalMapper, SLOT(map())); |
---|
665 | signalMapper->setMapping(newItem, GetCommandList(a_commandTree->GetCommand(a+1))); |
---|
666 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&))); |
---|
667 | |
---|
668 | a_parent->addChild(newItem); |
---|
669 | |
---|
670 | } |
---|
671 | |
---|
672 | printf ("G4UIQt::CreateChildTree end of for loop\n"); |
---|
673 | } |
---|
674 | |
---|
675 | /** |
---|
676 | This callback is activated when user selected a item in the help tree |
---|
677 | */ |
---|
678 | /***************************************************************************/ |
---|
679 | void G4UIQt::helpTreeCallback ( |
---|
680 | const QString & a_txt |
---|
681 | ) |
---|
682 | /***************************************************************************/ |
---|
683 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
684 | { |
---|
685 | fHelpArea->setText(a_txt); |
---|
686 | } |
---|
687 | |
---|
688 | /** |
---|
689 | */ |
---|
690 | /***************************************************************************/ |
---|
691 | QString G4UIQt::GetCommandList ( |
---|
692 | G4UIcommand *a_command |
---|
693 | ) |
---|
694 | /***************************************************************************/ |
---|
695 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
696 | { |
---|
697 | QString txt; |
---|
698 | G4String commandPath = a_command->GetCommandPath(); |
---|
699 | G4String rangeString = a_command->GetRange(); |
---|
700 | |
---|
701 | if((commandPath.length()-1)!='/') |
---|
702 | { |
---|
703 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
704 | } |
---|
705 | txt += "Guidance :\n"; |
---|
706 | G4int n_guidanceEntry = a_command->GetGuidanceEntries(); |
---|
707 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) |
---|
708 | { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "\n"; } |
---|
709 | if( ! rangeString.isNull() ) |
---|
710 | { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; } |
---|
711 | G4int n_parameterEntry = a_command->GetParameterEntries(); |
---|
712 | if( n_parameterEntry > 0 ) |
---|
713 | { |
---|
714 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) |
---|
715 | { a_command->GetParameter(i_thParameter)->List(); } |
---|
716 | } |
---|
717 | return txt; |
---|
718 | } |
---|