source: trunk/geant4/interfaces/basic/src/G4UIQt.cc@ 511

Last change on this file since 511 was 511, checked in by garnier, 18 years ago

r621@mac-90108: laurentgarnier | 2007-06-14 17:22:43 +0200
en progress

  • Property svn:mime-type set to text/cpp
File size: 25.1 KB
Line 
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
63static G4bool ConvertStringToInt(const char*,int&);
64
65static G4bool exitSession = true;
66static G4bool exitPause = true;
67static 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
89G4UIQt::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/***************************************************************************/
164G4UIQt::~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 */
183G4UIsession* 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 */
216void G4UIQt::Prompt (
217 G4String aPrompt
218)
219/***************************************************************************/
220/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
221{
222 fCommandLabel->setText((char*)aPrompt.data());
223}
224/***************************************************************************/
225void G4UIQt::SessionTerminate (
226)
227/***************************************************************************/
228/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
229{
230 G4Qt* interactorManager = G4Qt::getInstance ();
231 fMainWindow->close();
232 ((QApplication*)interactorManager->GetMainInteractor())->exit();
233}
234/***************************************************************************/
235void 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/***************************************************************************/
252void 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 */
273G4int 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 */
287G4int 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/***************************************************************************/
301G4bool 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/***************************************************************************/
327void G4UIQt::ExitHelp(
328)
329/***************************************************************************/
330/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
331{
332 printf("G4UIQt::ExitHelp\n");
333}
334
335/***************************************************************************/
336void 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/***************************************************************************/
370void 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 */
416void 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 */
434void 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/***************************************************************************/
463void G4UIQt::clearButtonCallback (
464)
465/***************************************************************************/
466/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
467{
468 fTextArea->clear();
469}
470
471//////////////////////////////////////////////////////////////////////////////
472G4bool 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
490void G4UIQt::TerminalHelp(G4String newCommand)
491{
492 QDialog *helpDialog = new QDialog;
493
494 QSplitter *splitter = new QSplitter(Qt::Horizontal);
495 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 treeWidget->setColumnHidden(1,true);
508 QStringList labels;
509 labels << QString("Summary") << QString("Description");
510 treeWidget->setHeaderLabels(labels);
511
512 QList<QTreeWidgetItem *> items;
513 G4int treeSize = treeTop->GetTreeEntry();
514 QTreeWidgetItem * newItem;
515 for (int a=0;a<treeSize;a++) {
516 // Creating new item
517 QStringList stringList;
518 stringList << QString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()).trimmed() ;
519 stringList << QString((char*)(treeTop->GetTree(a+1)->GetTitle()).data()).trimmed() ;
520
521 newItem = new QTreeWidgetItem(stringList);
522
523 // look for childs
524 CreateChildTree(newItem,treeTop->GetTree(a+1));
525 items.append(newItem);
526 }
527 treeWidget->insertTopLevelItems(0, items);
528
529 //connecting callback
530 signalMapper = new QSignalMapper(this);
531 connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),this, SLOT(helpTreeCallback(QTreeWidgetItem*, int)));
532
533 // Set layouts
534 QHBoxLayout *splitterLayout = new QHBoxLayout;
535
536 QVBoxLayout *vLayout = new QVBoxLayout;
537
538 splitterLayout->addWidget(treeWidget);
539 splitterLayout->addWidget(fHelpArea);
540 splitter->setLayout(splitterLayout);
541
542 vLayout->addWidget(splitter);
543 vLayout->addWidget(exitButton);
544 helpDialog->setLayout(vLayout);
545
546 helpDialog->resize(800,600);
547 helpDialog->move(QPoint(400,150));
548 helpDialog->show();
549 helpDialog->raise();
550 helpDialog->activateWindow();
551 ////////////////
552
553 printf ("G4UIQt::TerminalHelp \n");
554
555
556// size_t i = newCommand.index(" ");
557// if( i != std::string::npos )
558// {
559// G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
560// newValue.strip(G4String::both);
561// G4String targetCom = ModifyToFullPathCommand( newValue );
562// G4UIcommand* theCommand = treeTop->FindPath( targetCom );
563// if( theCommand != NULL )
564// {
565// theCommand->List();
566// return;
567// }
568// else
569// {
570// G4cout << "Command <" << newValue << " is not found." << G4endl;
571// return;
572// }
573// }
574
575// G4UIcommandTree * floor[10];
576// floor[0] = treeTop;
577// G4int iFloor = 0;
578// size_t prefixIndex = 1;
579// G4String prefix = GetCurrentWorkingDirectory();
580// while( prefixIndex < prefix.length()-1 )
581// {
582// size_t ii = prefix.index("/",prefixIndex);
583// floor[iFloor+1] =
584// floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
585// prefixIndex = ii+1;
586// iFloor++;
587// }
588// floor[iFloor]->ListCurrentWithNum();
589// // 1998 Oct 2 non-number input
590// while(1){
591// //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
592// G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
593// G4int i;
594// if(!GetHelpChoice(i)){
595// G4cout << G4endl << "Not a number, once more" << G4endl;
596// continue;
597// } else if( i < 0 ){
598// iFloor += i;
599// if( iFloor < 0 ) iFloor = 0;
600// floor[iFloor]->ListCurrentWithNum();
601// continue;
602// } else if(i == 0) {
603// break;
604// } else if( i > 0 ) {
605// G4int n_tree = floor[iFloor]->GetTreeEntry();
606// if( i > n_tree )
607// {
608// if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
609// {
610// floor[iFloor]->GetCommand(i-n_tree)->List();
611// }
612// }
613// else
614// {
615// floor[iFloor+1] = floor[iFloor]->GetTree(i);
616// iFloor++;
617// floor[iFloor]->ListCurrentWithNum();
618// }
619// }
620// }
621 G4cout << "Exit from HELP." << G4endl << G4endl;
622 //G4cout << G4endl;
623 ExitHelp();
624}
625void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) {
626
627 // Creating new item
628 QTreeWidgetItem * newItem;
629
630
631 // Get the Sub directories
632 for (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 (int a=0;a<a_commandTree->GetCommandEntry();a++) {
656
657 QStringList stringList;
658 stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetTitle()).data()).trimmed() ;
659 stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ;
660 newItem = new QTreeWidgetItem(stringList);
661
662 a_parent->addChild(newItem);
663
664 }
665}
666
667/**
668This callback is activated when user selected a item in the help tree
669 */
670/***************************************************************************/
671void G4UIQt::helpTreeCallback (
672 QTreeWidgetItem* a_treeItem
673,int a_index
674)
675/***************************************************************************/
676/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
677{
678 if (fHelpArea) {
679 G4UImanager* UI = G4UImanager::GetUIpointer();
680 if(UI==NULL) return;
681 G4UIcommandTree * treeTop = UI->GetTree();
682 G4UIcommand* command = treeTop->FindPath(a_treeItem->text (1).toStdString().c_str());
683 if (command) {
684 fHelpArea->setText(GetCommandList(command));
685 } else {
686 // this is not a command, this is a sub directory
687 // We display the Title
688 fHelpArea->setText(a_treeItem->text (1).toStdString().c_str());
689 }
690 }
691}
692
693/**
694 This fonction return the command list parameters in a QString
695
696 */
697/***************************************************************************/
698QString G4UIQt::GetCommandList (
699 G4UIcommand *a_command
700)
701/***************************************************************************/
702/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
703{
704
705 QString txt;
706 G4String commandPath = a_command->GetCommandPath();
707 G4String rangeString = a_command->GetRange();
708
709 if((commandPath.length()-1)!='/')
710 {
711 txt += "Command " + QString((char*)(commandPath).data()) + "\n";
712 }
713 txt += "Guidance :\n";
714 G4int n_guidanceEntry = a_command->GetGuidanceEntries();
715
716 for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
717 { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "---\n"; }
718 if( ! rangeString.isNull() )
719 { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; }
720 G4int n_parameterEntry = a_command->GetParameterEntries();
721 if( n_parameterEntry > 0 )
722 {
723 G4UIparameter *param;
724
725 // Re-implementation of G4UIparameter.cc
726
727 for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
728 { param = a_command->GetParameter(i_thParameter);
729 txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
730 if( ! param->GetParameterGuidance().isNull() )
731 txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
732 txt += " Parameter type : " + QString(param->GetParameterType())+ "\n";
733 if(param->IsOmittable())
734 { txt += " Omittable : True\n"; }
735 else
736 { txt += " Omittable : False\n"; }
737 if( param->GetCurrentAsDefault() )
738 { txt += " Default value : taken from the current value\n"; }
739 else if( ! param->GetDefaultValue().isNull() )
740 { txt += " Default value : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; }
741 if( ! param->GetParameterRange().isNull() )
742 txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
743 if( ! param->GetParameterCandidates().isNull() )
744 txt += " Candidates : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
745 }
746 }
747 return txt;
748}
Note: See TracBrowser for help on using the repository browser.