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

Last change on this file since 512 was 512, checked in by garnier, 17 years ago

r622@mac-90108: laurentgarnier | 2007-06-14 17:43:07 +0200
le meme, mais en plus beau

  • Property svn:mime-type set to text/cpp
File size: 25.3 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  fHelpTreeWidget = new QTreeWidget();
506  fHelpTreeWidget->setColumnCount(2);
507  fHelpTreeWidget->setColumnHidden(1,true);
508  QStringList labels;
509  labels << QString("Summary") << QString("Description");
510  fHelpTreeWidget->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  fHelpTreeWidget->insertTopLevelItems(0, items);
528
529  //connecting callback
530  //  QSignalMapper signalMapper = new QSignalMapper(this);
531
532  connect(fHelpTreeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),this, SLOT(helpTreeCallback(QTreeWidgetItem*, int))); 
533  connect(fHelpTreeWidget, SIGNAL(itemSelectionChanged ()),this, SLOT(helpTreeCallback())); 
534
535  // Set layouts
536  QHBoxLayout *splitterLayout = new QHBoxLayout;
537
538  QVBoxLayout *vLayout = new QVBoxLayout;
539
540  splitterLayout->addWidget(fHelpTreeWidget);
541  splitterLayout->addWidget(fHelpArea);
542  splitter->setLayout(splitterLayout);
543
544  vLayout->addWidget(splitter);
545  vLayout->addWidget(exitButton);
546  helpDialog->setLayout(vLayout);
547
548  helpDialog->resize(800,600);
549  helpDialog->move(QPoint(400,150));
550  helpDialog->show();
551  helpDialog->raise();
552  helpDialog->activateWindow();
553  ////////////////
554
555  printf ("G4UIQt::TerminalHelp \n");
556
557
558//   size_t i = newCommand.index(" ");
559//   if( i != std::string::npos )
560//   {
561//     G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
562//     newValue.strip(G4String::both);
563//     G4String targetCom = ModifyToFullPathCommand( newValue );
564//     G4UIcommand* theCommand = treeTop->FindPath( targetCom );
565//     if( theCommand != NULL )
566//     {
567//       theCommand->List();
568//       return;
569//     }
570//     else
571//     {
572//       G4cout << "Command <" << newValue << " is not found." << G4endl;
573//       return;
574//     }
575//   }
576
577//   G4UIcommandTree * floor[10];
578//   floor[0] = treeTop;
579//   G4int iFloor = 0;
580//   size_t prefixIndex = 1;
581//   G4String prefix = GetCurrentWorkingDirectory();
582//   while( prefixIndex < prefix.length()-1 )
583//   {
584//     size_t ii = prefix.index("/",prefixIndex);
585//     floor[iFloor+1] =
586//       floor[iFloor]->GetTree(G4String(prefix(0,ii+1)));
587//     prefixIndex = ii+1;
588//     iFloor++;
589//   }
590//   floor[iFloor]->ListCurrentWithNum();
591//   // 1998 Oct 2 non-number input
592//   while(1){
593//    //G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<std::flush;
594//     G4cout << G4endl << "Type the number ( 0:end, -n:n level back ) : "<<G4endl;
595//     G4int i;
596//     if(!GetHelpChoice(i)){
597//       G4cout << G4endl << "Not a number, once more" << G4endl;
598//       continue;
599//     } else if( i < 0 ){
600//       iFloor += i;
601//       if( iFloor < 0 ) iFloor = 0;
602//       floor[iFloor]->ListCurrentWithNum();
603//       continue;
604//     } else if(i == 0) {
605//       break;
606//     } else if( i > 0 ) {
607//       G4int n_tree = floor[iFloor]->GetTreeEntry();
608//       if( i > n_tree )
609//       {
610//         if( i <= n_tree + floor[iFloor]->GetCommandEntry() )
611//         {
612//           floor[iFloor]->GetCommand(i-n_tree)->List();
613//         }
614//       }
615//       else
616//       {
617//         floor[iFloor+1] = floor[iFloor]->GetTree(i);
618//         iFloor++;
619//         floor[iFloor]->ListCurrentWithNum();
620//       }
621//     }
622//   }
623  G4cout << "Exit from HELP." << G4endl << G4endl;
624  //G4cout << G4endl;
625  ExitHelp();
626}
627void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) {
628
629  // Creating new item
630  QTreeWidgetItem * newItem;
631
632
633  // Get the Sub directories
634  for (int a=0;a<a_commandTree->GetTreeEntry();a++) {
635   
636    QStringList stringList;
637    stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed()  ;
638    stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed()  ;
639    newItem = new QTreeWidgetItem(stringList);
640
641    //connecting callback
642    //    signalMapper = new QSignalMapper(this);
643    //    QAction *action = parent->addAction(a_label, signalMapper, SLOT(map()));
644   
645    //  signalMapper->setMapping(action, QString(a_command));
646    //  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&)));
647    //QTreeWidget::itemActivated ( QTreeWidgetItem * item, int column )   [signal]
648
649    CreateChildTree(newItem,a_commandTree->GetTree(a+1));
650    a_parent->addChild(newItem);
651  }
652
653
654
655  // Get the Commands
656
657  for (int a=0;a<a_commandTree->GetCommandEntry();a++) {
658   
659    QStringList stringList;
660    stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetTitle()).data()).trimmed()  ;
661    stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed()  ;
662    newItem = new QTreeWidgetItem(stringList);
663     
664    a_parent->addChild(newItem);
665
666  }
667}
668
669/**
670This callback is activated when user selected a item in the help tree
671 */
672void G4UIQt::helpTreeCallback (
673)
674/***************************************************************************/
675/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
676{
677  printf ("G4UIQt::TerminalHelp ===========================\n");
678  QTreeWidgetItem* item =  NULL;
679  if (!fHelpTreeWidget)
680    return ;
681
682  if (!fHelpArea)
683    return;
684 
685  item = fHelpTreeWidget->selectedItems().first();
686  if (!item)
687    return;
688 
689  G4UImanager* UI = G4UImanager::GetUIpointer();
690  if(UI==NULL) return;
691  G4UIcommandTree * treeTop = UI->GetTree();
692  G4UIcommand* command = treeTop->FindPath(item->text (1).toStdString().c_str());
693  if (command) {
694    fHelpArea->setText(GetCommandList(command));
695  } else {
696    // this is not a command, this is a sub directory
697    // We display the Title
698    fHelpArea->setText(item->text (1).toStdString().c_str());
699  }
700}
701
702/**
703  This fonction return the command list parameters in a QString
704
705 */
706/***************************************************************************/
707QString G4UIQt::GetCommandList (
708  G4UIcommand *a_command
709)
710/***************************************************************************/
711/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
712{
713
714  QString txt;
715  G4String commandPath = a_command->GetCommandPath();
716  G4String rangeString = a_command->GetRange();
717
718  if((commandPath.length()-1)!='/')
719  {
720    txt += "Command " + QString((char*)(commandPath).data()) + "\n";
721  }
722  txt += "Guidance :\n";
723  G4int n_guidanceEntry = a_command->GetGuidanceEntries();
724
725  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ )
726    { txt += QString((char*)(a_command->GetGuidanceLine(i_thGuidance)).data()) + "\n"; }
727  if( ! rangeString.isNull() )
728    { txt += " Range of parameters : " + QString((char*)(rangeString).data()) + "\n"; }
729  G4int n_parameterEntry = a_command->GetParameterEntries();
730  if( n_parameterEntry > 0 )
731    {
732      G4UIparameter *param;
733
734      // Re-implementation of G4UIparameter.cc
735
736      for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ )
737        { param = a_command->GetParameter(i_thParameter);
738          txt += "\nParameter : " + QString((char*)(param->GetParameterName()).data()) + "\n";
739          if( ! param->GetParameterGuidance().isNull() )
740            txt += QString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
741          txt += " Parameter type  : " + QString(param->GetParameterType())+ "\n";
742          if(param->IsOmittable())
743            { txt += " Omittable       : True\n"; }
744          else
745            { txt += " Omittable       : False\n"; }
746          if( param->GetCurrentAsDefault() )
747            { txt += " Default value   : taken from the current value\n"; }
748          else if( ! param->GetDefaultValue().isNull() )
749            { txt += " Default value   : " + QString((char*)(param->GetDefaultValue()).data())+ "\n"; }
750          if( ! param->GetParameterRange().isNull() )
751            txt += " Parameter range : " + QString((char*)(param->GetParameterRange()).data())+ "\n";
752          if( ! param->GetParameterCandidates().isNull() )
753            txt += " Candidates      : " + QString((char*)(param->GetParameterCandidates()).data())+ "\n";
754        }
755    }
756  return txt;
757}
Note: See TracBrowser for help on using the repository browser.