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 "G4UIQtLineEdit.hh" |
---|
49 | |
---|
50 | #include "G4Qt.hh" |
---|
51 | |
---|
52 | #include <QtGui/qapplication.h> |
---|
53 | #include <QtGui/qwidget.h> |
---|
54 | #include <QtGui/qmenu.h> |
---|
55 | #include <QtGui/qmenubar.h> |
---|
56 | #include <QtGui/qboxlayout.h> |
---|
57 | #include <QtGui/qpushbutton.h> |
---|
58 | #include <QtGui/qlabel.h> |
---|
59 | #include <QtGui/qsplitter.h> |
---|
60 | #include <QtGui/qscrollbar.h> |
---|
61 | #include <QtGui/qdialog.h> |
---|
62 | |
---|
63 | #include <stdlib.h> |
---|
64 | |
---|
65 | // Pourquoi Static et non variables de classe ? |
---|
66 | static G4bool exitSession = true; |
---|
67 | static G4bool exitPause = 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 | :fHelpDialog(NULL) |
---|
94 | |
---|
95 | /***************************************************************************/ |
---|
96 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
97 | { |
---|
98 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
99 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
100 | if(UI!=NULL) UI->SetSession(this); |
---|
101 | |
---|
102 | fMainWindow = new QMainWindow(); |
---|
103 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
104 | fMainWindow->resize(800,600); |
---|
105 | fMainWindow->move(QPoint(300,100)); |
---|
106 | |
---|
107 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
108 | fTextArea = new QTextEdit(); |
---|
109 | QPushButton *clearButton = new QPushButton("clear"); |
---|
110 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
111 | |
---|
112 | fCommandHistoryArea = new QTextEdit(); |
---|
113 | fCommandLabel = new QLabel(); |
---|
114 | |
---|
115 | fCommandArea = new G4UIQtLineEdit(this); // must surcharge the keyPressEvent function |
---|
116 | fCommandArea->activateWindow(); |
---|
117 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
118 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
119 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
120 | fTextArea->setReadOnly(true); |
---|
121 | fCommandHistoryArea->setReadOnly(true); |
---|
122 | |
---|
123 | // virtual void keyPressEvent(QKeyEvent *e) { |
---|
124 | // if (e->key == Qt::Key_F9) { |
---|
125 | // Do something |
---|
126 | //} |
---|
127 | //} |
---|
128 | |
---|
129 | // Set layouts |
---|
130 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
131 | |
---|
132 | QWidget* topWidget = new QWidget(); |
---|
133 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
134 | |
---|
135 | QWidget* bottomWidget = new QWidget(); |
---|
136 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
137 | |
---|
138 | |
---|
139 | layoutTop->addWidget(fTextArea); |
---|
140 | layoutTop->addWidget(clearButton); |
---|
141 | topWidget->setLayout(layoutTop); |
---|
142 | |
---|
143 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
144 | layoutBottom->addWidget(fCommandLabel); |
---|
145 | layoutBottom->addWidget(fCommandArea); |
---|
146 | bottomWidget->setLayout(layoutBottom); |
---|
147 | |
---|
148 | |
---|
149 | layoutSplitter->addWidget(topWidget); |
---|
150 | layoutSplitter->addWidget(bottomWidget); |
---|
151 | splitter->setLayout(layoutSplitter); |
---|
152 | |
---|
153 | fMainWindow->setCentralWidget(splitter); |
---|
154 | |
---|
155 | // Add a quit subMenu |
---|
156 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
157 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close())); |
---|
158 | |
---|
159 | // Add a Help menu |
---|
160 | QMenu *helpMenu = fMainWindow->menuBar()->addMenu("Help"); |
---|
161 | helpMenu->addAction("Show Help", this, SLOT(showHelpCallback())); |
---|
162 | |
---|
163 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
164 | QList<int> vals = splitter->sizes(); |
---|
165 | if(vals.size()==2) { |
---|
166 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
167 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
168 | splitter->setSizes(vals); |
---|
169 | } |
---|
170 | |
---|
171 | |
---|
172 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
173 | } |
---|
174 | /***************************************************************************/ |
---|
175 | G4UIQt::~G4UIQt( |
---|
176 | ) |
---|
177 | /***************************************************************************/ |
---|
178 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
179 | { |
---|
180 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
181 | if(UI!=NULL) { // TO KEEP |
---|
182 | UI->SetSession(NULL); // TO KEEP |
---|
183 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | if (fMainWindow!=NULL) |
---|
188 | delete fMainWindow; |
---|
189 | } |
---|
190 | /***************************************************************************/ |
---|
191 | /* |
---|
192 | Start the Qt main loop |
---|
193 | */ |
---|
194 | G4UIsession* G4UIQt::SessionStart ( |
---|
195 | ) |
---|
196 | /***************************************************************************/ |
---|
197 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
198 | { |
---|
199 | |
---|
200 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
201 | fMainWindow->show(); |
---|
202 | Prompt("session"); |
---|
203 | exitSession = false; |
---|
204 | |
---|
205 | |
---|
206 | printf("disable secondary loop\n"); |
---|
207 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
208 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
209 | // on ne passe pas le dessous ? FIXME ???? |
---|
210 | // je ne pense pas 13/06 |
---|
211 | |
---|
212 | // void* event; // TO KEEP |
---|
213 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
214 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
215 | // if(exitSession==true) break; // TO KEEP |
---|
216 | // } // TO KEEP |
---|
217 | |
---|
218 | interactorManager->EnableSecondaryLoop (); |
---|
219 | printf("enable secondary loop\n"); |
---|
220 | return this; |
---|
221 | } |
---|
222 | /***************************************************************************/ |
---|
223 | |
---|
224 | /** |
---|
225 | Display the prompt in the prompt area |
---|
226 | */ |
---|
227 | void G4UIQt::Prompt ( |
---|
228 | G4String aPrompt |
---|
229 | ) |
---|
230 | /***************************************************************************/ |
---|
231 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
232 | { |
---|
233 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
234 | } |
---|
235 | /***************************************************************************/ |
---|
236 | void G4UIQt::SessionTerminate ( |
---|
237 | ) |
---|
238 | /***************************************************************************/ |
---|
239 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
240 | { |
---|
241 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
242 | fMainWindow->close(); |
---|
243 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
244 | } |
---|
245 | /***************************************************************************/ |
---|
246 | void G4UIQt::PauseSessionStart ( |
---|
247 | G4String a_state |
---|
248 | ) |
---|
249 | /***************************************************************************/ |
---|
250 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
251 | { |
---|
252 | printf("G4UIQt::PauseSessionStart\n"); |
---|
253 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
254 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
255 | } // TO KEEP |
---|
256 | |
---|
257 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
258 | // Picking with feed back in event data Done here !!! |
---|
259 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
260 | } // TO KEEP |
---|
261 | } |
---|
262 | /***************************************************************************/ |
---|
263 | void G4UIQt::SecondaryLoop ( |
---|
264 | G4String a_prompt |
---|
265 | ) |
---|
266 | /***************************************************************************/ |
---|
267 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
268 | { |
---|
269 | printf("G4UIQt::SecondaryLoop\n"); |
---|
270 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
271 | Prompt(a_prompt); // TO KEEP |
---|
272 | exitPause = false; // TO KEEP |
---|
273 | void* event; // TO KEEP |
---|
274 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
275 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
276 | if(exitPause==true) break; // TO KEEP |
---|
277 | } // TO KEEP |
---|
278 | Prompt("session"); // TO KEEP |
---|
279 | } |
---|
280 | /***************************************************************************/ |
---|
281 | /** |
---|
282 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
283 | */ |
---|
284 | G4int G4UIQt::ReceiveG4cout ( |
---|
285 | G4String a_string |
---|
286 | ) |
---|
287 | /***************************************************************************/ |
---|
288 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
289 | { |
---|
290 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
291 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
292 | return 0; |
---|
293 | } |
---|
294 | /***************************************************************************/ |
---|
295 | /** |
---|
296 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
297 | */ |
---|
298 | G4int G4UIQt::ReceiveG4cerr ( |
---|
299 | G4String a_string |
---|
300 | ) |
---|
301 | /***************************************************************************/ |
---|
302 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
303 | { |
---|
304 | QColor previousColor = fTextArea->textColor(); |
---|
305 | fTextArea->setTextColor(Qt::red); |
---|
306 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
307 | fTextArea->setTextColor(previousColor); |
---|
308 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
309 | return 0; |
---|
310 | } |
---|
311 | |
---|
312 | /***************************************************************************/ |
---|
313 | void G4UIQt::AddMenu ( |
---|
314 | const char* a_name |
---|
315 | ,const char* a_label |
---|
316 | ) |
---|
317 | /***************************************************************************/ |
---|
318 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
319 | { |
---|
320 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
321 | |
---|
322 | // QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label); |
---|
323 | QMenu *fileMenu = new QMenu(a_label); |
---|
324 | fMainWindow->menuBar()->insertMenu(fMainWindow->menuBar()->actions().last(),fileMenu); |
---|
325 | AddInteractor (a_name,(G4Interactor)fileMenu); |
---|
326 | } |
---|
327 | /***************************************************************************/ |
---|
328 | void G4UIQt::AddButton ( |
---|
329 | const char* a_menu |
---|
330 | ,const char* a_label |
---|
331 | ,const char* a_command |
---|
332 | ) |
---|
333 | /***************************************************************************/ |
---|
334 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
335 | { |
---|
336 | if(a_menu==NULL) return; // TO KEEP |
---|
337 | if(a_label==NULL) return; // TO KEEP |
---|
338 | if(a_command==NULL) return; // TO KEEP |
---|
339 | QMenu *parent = (QMenu*)GetInteractor(a_menu); |
---|
340 | if(parent==NULL) return; |
---|
341 | |
---|
342 | signalMapper = new QSignalMapper(this); |
---|
343 | QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
344 | signalMapper->setMapping(action, QString(a_command)); |
---|
345 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&))); |
---|
346 | } |
---|
347 | |
---|
348 | |
---|
349 | |
---|
350 | |
---|
351 | /** |
---|
352 | Open the help dialog in a separate window. |
---|
353 | This will be display as a tree widget |
---|
354 | Implementation of <b>void G4VBasicShell::TerminalHelp(G4String newCommand)</b> |
---|
355 | |
---|
356 | @param newCommand : open the tree widget item on this command if is set |
---|
357 | */ |
---|
358 | void G4UIQt::TerminalHelp(G4String newCommand) |
---|
359 | { |
---|
360 | |
---|
361 | |
---|
362 | if (!fHelpDialog) { |
---|
363 | fHelpDialog = new QDialog; |
---|
364 | |
---|
365 | QSplitter *splitter = new QSplitter(Qt::Horizontal); |
---|
366 | fHelpArea = new QTextEdit(); |
---|
367 | QPushButton *exitButton = new QPushButton("Exit"); |
---|
368 | connect(exitButton, SIGNAL(clicked()), fHelpDialog,SLOT(close())); |
---|
369 | fHelpArea->setReadOnly(true); |
---|
370 | |
---|
371 | // the help tree |
---|
372 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
373 | if(UI==NULL) return; |
---|
374 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
375 | |
---|
376 | |
---|
377 | // en test : creation de doc html |
---|
378 | |
---|
379 | |
---|
380 | treeTop->CreateHTML(); |
---|
381 | printf("************ create file : -%s-**********\n",((char*)treeTop->GetPathName().data())); |
---|
382 | |
---|
383 | |
---|
384 | |
---|
385 | |
---|
386 | |
---|
387 | |
---|
388 | |
---|
389 | // |
---|
390 | // build widget |
---|
391 | fHelpTreeWidget = new QTreeWidget(); |
---|
392 | fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection); |
---|
393 | fHelpTreeWidget->setColumnCount(2); |
---|
394 | fHelpTreeWidget->setColumnHidden(1,true); |
---|
395 | QStringList labels; |
---|
396 | labels << QString("Command") << QString("Description"); |
---|
397 | fHelpTreeWidget->setHeaderLabels(labels); |
---|
398 | |
---|
399 | QList<QTreeWidgetItem *> items; |
---|
400 | G4int treeSize = treeTop->GetTreeEntry(); |
---|
401 | QTreeWidgetItem * newItem; |
---|
402 | for (int a=0;a<treeSize;a++) { |
---|
403 | // Creating new item |
---|
404 | QStringList stringList; |
---|
405 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
406 | stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
407 | |
---|
408 | newItem = new QTreeWidgetItem(stringList); |
---|
409 | |
---|
410 | // look for childs |
---|
411 | CreateChildTree(newItem,treeTop->GetTree(a+1)); |
---|
412 | items.append(newItem); |
---|
413 | } |
---|
414 | fHelpTreeWidget->insertTopLevelItems(0, items); |
---|
415 | |
---|
416 | //connecting callback |
---|
417 | // QSignalMapper signalMapper = new QSignalMapper(this); |
---|
418 | |
---|
419 | connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); |
---|
420 | |
---|
421 | // Set layouts |
---|
422 | QHBoxLayout *splitterLayout = new QHBoxLayout; |
---|
423 | |
---|
424 | QVBoxLayout *vLayout = new QVBoxLayout; |
---|
425 | |
---|
426 | splitterLayout->addWidget(fHelpTreeWidget); |
---|
427 | splitterLayout->addWidget(fHelpArea); |
---|
428 | splitter->setLayout(splitterLayout); |
---|
429 | |
---|
430 | vLayout->addWidget(splitter); |
---|
431 | vLayout->addWidget(exitButton); |
---|
432 | fHelpDialog->setLayout(vLayout); |
---|
433 | |
---|
434 | } |
---|
435 | |
---|
436 | // Look for the choosen command "newCommand" |
---|
437 | size_t i = newCommand.index(" "); |
---|
438 | G4String targetCom=""; |
---|
439 | if( i != std::string::npos ) |
---|
440 | { |
---|
441 | G4String newValue = newCommand(i+1,newCommand.length()-(i+1)); |
---|
442 | newValue.strip(G4String::both); |
---|
443 | targetCom = ModifyToFullPathCommand( newValue ); |
---|
444 | printf("test : av:%s-- ap:%s--\n",((char*)newValue.data()),((char*)targetCom.data())); |
---|
445 | } |
---|
446 | if (targetCom != "") { |
---|
447 | QList<QTreeWidgetItem *> list = fHelpTreeWidget->findItems(QString(((char*)targetCom.data())),Qt::MatchFixedString,0); |
---|
448 | for (int a=0;a<13;a++) { |
---|
449 | printf("verif.... =%s= +%s+\n",fHelpTreeWidget->topLevelItem(a)->text(0).toStdString().c_str(),((char*)targetCom.data())); |
---|
450 | } |
---|
451 | |
---|
452 | if (!list.isEmpty()) { |
---|
453 | if (list.first()->childCount() >0) |
---|
454 | list.first()->setExpanded(true); |
---|
455 | |
---|
456 | //collapsed open item |
---|
457 | QList<QTreeWidgetItem *> selected; |
---|
458 | selected = fHelpTreeWidget->selectedItems(); |
---|
459 | if ( selected.count() != 0 ) { |
---|
460 | fHelpTreeWidget->collapseItem (selected.at( 0 ) ); |
---|
461 | } |
---|
462 | |
---|
463 | // clear old selection |
---|
464 | fHelpTreeWidget->clearSelection(); |
---|
465 | list.first()->setSelected(true); |
---|
466 | |
---|
467 | // Call the update of the right textArea |
---|
468 | helpTreeCallback(); |
---|
469 | } |
---|
470 | } |
---|
471 | fHelpDialog->setWindowTitle("Help on commands"); |
---|
472 | fHelpDialog->resize(800,600); |
---|
473 | fHelpDialog->move(QPoint(400,150)); |
---|
474 | fHelpDialog->show(); |
---|
475 | fHelpDialog->raise(); |
---|
476 | fHelpDialog->activateWindow(); |
---|
477 | } |
---|
478 | |
---|
479 | |
---|
480 | |
---|
481 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) { |
---|
482 | |
---|
483 | // Creating new item |
---|
484 | QTreeWidgetItem * newItem; |
---|
485 | |
---|
486 | |
---|
487 | // Get the Sub directories |
---|
488 | for (int a=0;a<a_commandTree->GetTreeEntry();a++) { |
---|
489 | |
---|
490 | QStringList stringList; |
---|
491 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
492 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
493 | newItem = new QTreeWidgetItem(stringList); |
---|
494 | |
---|
495 | CreateChildTree(newItem,a_commandTree->GetTree(a+1)); |
---|
496 | a_parent->addChild(newItem); |
---|
497 | } |
---|
498 | |
---|
499 | |
---|
500 | |
---|
501 | // Get the Commands |
---|
502 | |
---|
503 | for (int a=0;a<a_commandTree->GetCommandEntry();a++) { |
---|
504 | |
---|
505 | QStringList stringList; |
---|
506 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; |
---|
507 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; |
---|
508 | newItem = new QTreeWidgetItem(stringList); |
---|
509 | |
---|
510 | a_parent->addChild(newItem); |
---|
511 | newItem->setExpanded(false); |
---|
512 | } |
---|
513 | } |
---|
514 | |
---|
515 | |
---|
516 | /** |
---|
517 | This fonction return the command list parameters in a QString |
---|
518 | |
---|
519 | */ |
---|
520 | /***************************************************************************/ |
---|
521 | QString G4UIQt::GetCommandList ( |
---|
522 | G4UIcommand *a_command |
---|
523 | ) |
---|
524 | /***************************************************************************/ |
---|
525 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
526 | { |
---|
527 | |
---|
528 | QString txt; |
---|
529 | G4String commandPath = a_command->GetCommandPath(); |
---|
530 | G4String rangeString = a_command->GetRange(); |
---|
531 | |
---|
532 | if((commandPath.length()-1)!='/') |
---|
533 | { |
---|
534 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
535 | } |
---|
536 | txt += "Guidance :\n"; |
---|
537 | G4int n_guidanceEntry = a_command->GetGuidanceEntries(); |
---|
538 | |
---|
539 | for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) |
---|
540 | { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "\n"; } |
---|
541 | if( ! rangeString.isNull() ) |
---|
542 | { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; } |
---|
543 | G4int n_parameterEntry = a_command->GetParameterEntries(); |
---|
544 | if( n_parameterEntry > 0 ) |
---|
545 | { |
---|
546 | G4UIparameter *param; |
---|
547 | |
---|
548 | // Re-implementation of G4UIparameter.cc |
---|
549 | |
---|
550 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) |
---|
551 | { param = a_command->GetParameter(i_thParameter); |
---|
552 | txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n"; |
---|
553 | if( ! param->GetParameterGuidance().isNull() ) |
---|
554 | txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ; |
---|
555 | txt += " Parameter type : " + QString(param->GetParameterType())+ "\n"; |
---|
556 | if(param->IsOmittable()) |
---|
557 | { txt += " Omittable : True\n"; } |
---|
558 | else |
---|
559 | { txt += " Omittable : False\n"; } |
---|
560 | if( param->GetCurrentAsDefault() ) |
---|
561 | { txt += " Default value : taken from the current value\n"; } |
---|
562 | else if( ! param->GetDefaultValue().isNull() ) |
---|
563 | { txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; } |
---|
564 | if( ! param->GetParameterRange().isNull() ) |
---|
565 | txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n"; |
---|
566 | if( ! param->GetParameterCandidates().isNull() ) |
---|
567 | txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n"; |
---|
568 | } |
---|
569 | } |
---|
570 | return txt; |
---|
571 | } |
---|
572 | |
---|
573 | |
---|
574 | |
---|
575 | /***************************************************************************/ |
---|
576 | void G4UIQt::expandHelpItem ( |
---|
577 | QTreeWidgetItem *a_parent |
---|
578 | ,G4UIcommand* a_expandCommand |
---|
579 | ) |
---|
580 | /***************************************************************************/ |
---|
581 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
582 | { |
---|
583 | } |
---|
584 | |
---|
585 | /***************************************************************************/ |
---|
586 | G4bool G4UIQt::GetHelpChoice( |
---|
587 | G4int& aInt |
---|
588 | ) |
---|
589 | /***************************************************************************/ |
---|
590 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
591 | { |
---|
592 | printf("G4UIQt::GetHelpChoice SHOULD NEVER GO HERE"); |
---|
593 | } |
---|
594 | /***************************************************************************/ |
---|
595 | void G4UIQt::ExitHelp( |
---|
596 | ) |
---|
597 | /***************************************************************************/ |
---|
598 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
599 | { |
---|
600 | printf("G4UIQt::ExitHelp SHOULD NEVER GO HERE"); |
---|
601 | } |
---|
602 | |
---|
603 | |
---|
604 | /***************************************************************************/ |
---|
605 | // |
---|
606 | // SLOTS DEFINITIONS |
---|
607 | // |
---|
608 | /***************************************************************************/ |
---|
609 | |
---|
610 | /***************************************************************************/ |
---|
611 | void G4UIQt::showHelpCallback ( |
---|
612 | ) |
---|
613 | /***************************************************************************/ |
---|
614 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
615 | { |
---|
616 | TerminalHelp(""); |
---|
617 | } |
---|
618 | |
---|
619 | /***************************************************************************/ |
---|
620 | void G4UIQt::clearButtonCallback ( |
---|
621 | ) |
---|
622 | /***************************************************************************/ |
---|
623 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
624 | { |
---|
625 | fTextArea->clear(); |
---|
626 | } |
---|
627 | |
---|
628 | |
---|
629 | /** |
---|
630 | Callback call when "click on a menu entry. |
---|
631 | Send the associated command to geant4 |
---|
632 | */ |
---|
633 | void G4UIQt::commandEnteredCallback ( |
---|
634 | ) |
---|
635 | /***************************************************************************/ |
---|
636 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
637 | { |
---|
638 | printf ("debug : callback\n"); |
---|
639 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
640 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
641 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
642 | |
---|
643 | if (command(0,4) != "help") { |
---|
644 | ApplyShellCommand (command,exitSession,exitPause); |
---|
645 | } else { |
---|
646 | printf ("terminal help\n"); |
---|
647 | TerminalHelp(command); |
---|
648 | } |
---|
649 | if(exitSession==true) |
---|
650 | SessionTerminate(); |
---|
651 | } |
---|
652 | fCommandArea->setText(""); |
---|
653 | } |
---|
654 | |
---|
655 | /** |
---|
656 | Callback call when "enter" clicked on the command zone. |
---|
657 | Send the command to geant4 |
---|
658 | */ |
---|
659 | void G4UIQt::buttonCallback ( |
---|
660 | const QString& a_command |
---|
661 | ) |
---|
662 | /***************************************************************************/ |
---|
663 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
664 | { |
---|
665 | G4String ss = G4String(a_command.toStdString().c_str()); |
---|
666 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); |
---|
667 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
668 | if(exitSession==true) |
---|
669 | SessionTerminate(); |
---|
670 | } |
---|
671 | /** |
---|
672 | This callback is activated when user selected a item in the help tree |
---|
673 | */ |
---|
674 | void G4UIQt::helpTreeCallback ( |
---|
675 | ) |
---|
676 | /***************************************************************************/ |
---|
677 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
678 | { |
---|
679 | // G4bool GetHelpChoice(G4int&); |
---|
680 | QTreeWidgetItem* item = NULL; |
---|
681 | if (!fHelpTreeWidget) |
---|
682 | return ; |
---|
683 | |
---|
684 | if (!fHelpArea) |
---|
685 | return; |
---|
686 | |
---|
687 | QList<QTreeWidgetItem *> list =fHelpTreeWidget->selectedItems(); |
---|
688 | if (list.isEmpty()) |
---|
689 | return; |
---|
690 | item = list.first(); |
---|
691 | if (!item) |
---|
692 | return; |
---|
693 | |
---|
694 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
695 | if(UI==NULL) return; |
---|
696 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
697 | G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str()); |
---|
698 | if (command) { |
---|
699 | fHelpArea->setText(GetCommandList(command)); |
---|
700 | } else { |
---|
701 | // this is not a command, this is a sub directory |
---|
702 | // We display the Title |
---|
703 | fHelpArea->setText(item->text (1).toStdString().c_str()); |
---|
704 | } |
---|
705 | } |
---|
706 | |
---|
707 | |
---|
708 | #endif |
---|