| [484] | 1 | // TODO !
|
|---|
| 2 |
|
|---|
| [481] | 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 | //
|
|---|
| [484] | 29 | // $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $
|
|---|
| [481] | 30 | // GEANT4 tag $Name: geant4-08-01 $
|
|---|
| 31 | //
|
|---|
| [484] | 32 | // L. Garnier
|
|---|
| [481] | 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>
|
|---|
| [487] | 52 | #include <QtGui/qmenu.h>
|
|---|
| 53 | #include <QtGui/qmenubar.h>
|
|---|
| 54 | #include <QtGui/qboxlayout.h>
|
|---|
| [488] | 55 | #include <QtGui/qpushbutton.h>
|
|---|
| 56 | #include <QtGui/qlabel.h>
|
|---|
| [495] | 57 | #include <QtGui/qsplitter.h>
|
|---|
| [500] | 58 | #include <QtGui/qscrollbar.h>
|
|---|
| [506] | 59 | #include <QtGui/qdialog.h>
|
|---|
| [481] | 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 | | +-------------------+ |
|
|---|
| [488] | 79 | | | clear | |
|
|---|
| [481] | 80 | | +-------------------+ |
|
|---|
| [494] | 81 | | | promt history | |
|
|---|
| 82 | | +-------------------+ |
|
|---|
| 83 | | +-------------------+ |
|
|---|
| [481] | 84 | | |> promt area | |
|
|---|
| 85 | | +-------------------+ |
|
|---|
| [484] | 86 | +-----------------------+
|
|---|
| [481] | 87 | */
|
|---|
| 88 |
|
|---|
| 89 | G4UIQt::G4UIQt (
|
|---|
| 90 | int argc,
|
|---|
| 91 | char** argv
|
|---|
| 92 | )
|
|---|
| 93 | /***************************************************************************/
|
|---|
| 94 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 95 | {
|
|---|
| [496] | 96 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| [505] | 97 | G4UImanager* UI = G4UImanager::GetUIpointer();
|
|---|
| 98 | if(UI!=NULL) UI->SetSession(this);
|
|---|
| [481] | 99 |
|
|---|
| [494] | 100 | fMainWindow = new QMainWindow();
|
|---|
| 101 | fMainWindow->setWindowTitle( "G4UI Session" );
|
|---|
| [500] | 102 | fMainWindow->resize(800,600);
|
|---|
| [505] | 103 | fMainWindow->move(QPoint(300,100));
|
|---|
| [496] | 104 |
|
|---|
| [498] | 105 | QSplitter *splitter = new QSplitter(Qt::Vertical);
|
|---|
| 106 | fTextArea = new QTextEdit();
|
|---|
| [490] | 107 | QPushButton *clearButton = new QPushButton("clear");
|
|---|
| [498] | 108 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback()));
|
|---|
| 109 |
|
|---|
| 110 | fCommandHistoryArea = new QTextEdit();
|
|---|
| 111 | fCommandLabel = new QLabel();
|
|---|
| 112 |
|
|---|
| 113 | fCommandArea = new QLineEdit();
|
|---|
| [500] | 114 | fCommandArea->activateWindow();
|
|---|
| [498] | 115 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback()));
|
|---|
| [500] | 116 | fCommandArea->setFocusPolicy ( Qt::StrongFocus );
|
|---|
| 117 | fCommandArea->setFocus(Qt::TabFocusReason);
|
|---|
| [498] | 118 | fTextArea->setReadOnly(true);
|
|---|
| 119 | fCommandHistoryArea->setReadOnly(true);
|
|---|
| 120 |
|
|---|
| [496] | 121 |
|
|---|
| [505] | 122 |
|
|---|
| 123 | // Set layouts
|
|---|
| [498] | 124 | QVBoxLayout *layoutSplitter = new QVBoxLayout;
|
|---|
| [497] | 125 |
|
|---|
| [498] | 126 | QWidget* topWidget = new QWidget();
|
|---|
| 127 | QVBoxLayout *layoutTop = new QVBoxLayout;
|
|---|
| [481] | 128 |
|
|---|
| [498] | 129 | QWidget* bottomWidget = new QWidget();
|
|---|
| 130 | QVBoxLayout *layoutBottom = new QVBoxLayout;
|
|---|
| [494] | 131 |
|
|---|
| [490] | 132 |
|
|---|
| [498] | 133 | layoutTop->addWidget(fTextArea);
|
|---|
| 134 | layoutTop->addWidget(clearButton);
|
|---|
| 135 | topWidget->setLayout(layoutTop);
|
|---|
| [494] | 136 |
|
|---|
| [498] | 137 | layoutBottom->addWidget(fCommandHistoryArea);
|
|---|
| 138 | layoutBottom->addWidget(fCommandLabel);
|
|---|
| 139 | layoutBottom->addWidget(fCommandArea);
|
|---|
| 140 | bottomWidget->setLayout(layoutBottom);
|
|---|
| [490] | 141 |
|
|---|
| [495] | 142 |
|
|---|
| [498] | 143 | layoutSplitter->addWidget(topWidget);
|
|---|
| 144 | layoutSplitter->addWidget(bottomWidget);
|
|---|
| 145 | splitter->setLayout(layoutSplitter);
|
|---|
| [495] | 146 |
|
|---|
| [498] | 147 | fMainWindow->setCentralWidget(splitter);
|
|---|
| [495] | 148 |
|
|---|
| [504] | 149 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File");
|
|---|
| [503] | 150 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close()));
|
|---|
| [496] | 151 |
|
|---|
| [505] | 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 | }
|
|---|
| [481] | 159 |
|
|---|
| 160 |
|
|---|
| [484] | 161 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
|
|---|
| [481] | 162 | }
|
|---|
| 163 | /***************************************************************************/
|
|---|
| 164 | G4UIQt::~G4UIQt(
|
|---|
| 165 | )
|
|---|
| 166 | /***************************************************************************/
|
|---|
| 167 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 168 | {
|
|---|
| [484] | 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
|
|---|
| [481] | 173 | }
|
|---|
| [484] | 174 |
|
|---|
| 175 |
|
|---|
| [494] | 176 | if (fMainWindow!=NULL)
|
|---|
| 177 | delete fMainWindow;
|
|---|
| [481] | 178 | }
|
|---|
| 179 | /***************************************************************************/
|
|---|
| 180 | /*
|
|---|
| 181 | Start the Qt main loop
|
|---|
| 182 | */
|
|---|
| 183 | G4UIsession* G4UIQt::SessionStart (
|
|---|
| 184 | )
|
|---|
| 185 | /***************************************************************************/
|
|---|
| 186 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 187 | {
|
|---|
| [484] | 188 |
|
|---|
| [496] | 189 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| [494] | 190 | fMainWindow->show();
|
|---|
| 191 | Prompt("session");
|
|---|
| 192 | exitSession = false;
|
|---|
| [481] | 193 |
|
|---|
| [496] | 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 ????
|
|---|
| [506] | 199 | // je ne pense pas 13/06
|
|---|
| [496] | 200 |
|
|---|
| [484] | 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
|
|---|
| [506] | 206 |
|
|---|
| 207 | interactorManager->EnableSecondaryLoop ();
|
|---|
| [496] | 208 | printf("enable secondary loop\n");
|
|---|
| [506] | 209 | return this;
|
|---|
| [481] | 210 | }
|
|---|
| 211 | /***************************************************************************/
|
|---|
| [494] | 212 |
|
|---|
| [481] | 213 | /**
|
|---|
| 214 | Display the prompt in the prompt area
|
|---|
| 215 | */
|
|---|
| 216 | void G4UIQt::Prompt (
|
|---|
| 217 | G4String aPrompt
|
|---|
| 218 | )
|
|---|
| 219 | /***************************************************************************/
|
|---|
| 220 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 221 | {
|
|---|
| [500] | 222 | fCommandLabel->setText((char*)aPrompt.data());
|
|---|
| [481] | 223 | }
|
|---|
| 224 | /***************************************************************************/
|
|---|
| 225 | void G4UIQt::SessionTerminate (
|
|---|
| 226 | )
|
|---|
| 227 | /***************************************************************************/
|
|---|
| 228 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 229 | {
|
|---|
| [505] | 230 | G4Qt* interactorManager = G4Qt::getInstance ();
|
|---|
| 231 | fMainWindow->close();
|
|---|
| 232 | ((QApplication*)interactorManager->GetMainInteractor())->exit();
|
|---|
| [481] | 233 | }
|
|---|
| 234 | /***************************************************************************/
|
|---|
| 235 | void G4UIQt::PauseSessionStart (
|
|---|
| 236 | G4String a_state
|
|---|
| 237 | )
|
|---|
| 238 | /***************************************************************************/
|
|---|
| 239 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 240 | {
|
|---|
| [501] | 241 | printf("G4UIQt::PauseSessionStart\n");
|
|---|
| [484] | 242 | if(a_state=="G4_pause> ") { // TO KEEP
|
|---|
| 243 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
|
|---|
| 244 | } // TO KEEP
|
|---|
| [481] | 245 |
|
|---|
| [484] | 246 | if(a_state=="EndOfEvent") { // TO KEEP
|
|---|
| [481] | 247 | // Picking with feed back in event data Done here !!!
|
|---|
| [484] | 248 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
|
|---|
| 249 | } // TO KEEP
|
|---|
| [481] | 250 | }
|
|---|
| 251 | /***************************************************************************/
|
|---|
| [484] | 252 | void G4UIQt::SecondaryLoop (
|
|---|
| [481] | 253 | G4String a_prompt
|
|---|
| 254 | )
|
|---|
| 255 | /***************************************************************************/
|
|---|
| 256 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 257 | {
|
|---|
| [501] | 258 | printf("G4UIQt::SecondaryLoop\n");
|
|---|
| [484] | 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
|
|---|
| [481] | 268 | }
|
|---|
| 269 | /***************************************************************************/
|
|---|
| 270 | /**
|
|---|
| 271 | Receive a cout from Geant4. We have to display it in the cout zone
|
|---|
| 272 | */
|
|---|
| [484] | 273 | G4int G4UIQt::ReceiveG4cout (
|
|---|
| [481] | 274 | G4String a_string
|
|---|
| 275 | )
|
|---|
| 276 | /***************************************************************************/
|
|---|
| 277 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 278 | {
|
|---|
| [500] | 279 | fTextArea->append(QString((char*)a_string.data()).trimmed());
|
|---|
| 280 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
|
|---|
| [495] | 281 | return 0;
|
|---|
| [481] | 282 | }
|
|---|
| 283 | /***************************************************************************/
|
|---|
| 284 | /**
|
|---|
| 285 | Receive a cerr from Geant4. We have to display it in the cout zone
|
|---|
| 286 | */
|
|---|
| [484] | 287 | G4int G4UIQt::ReceiveG4cerr (
|
|---|
| [481] | 288 | G4String a_string
|
|---|
| 289 | )
|
|---|
| 290 | /***************************************************************************/
|
|---|
| 291 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 292 | {
|
|---|
| [500] | 293 | QColor previousColor = fTextArea->textColor();
|
|---|
| 294 | fTextArea->setTextColor(Qt::red);
|
|---|
| 295 | fTextArea->append(QString((char*)a_string.data()).trimmed());
|
|---|
| 296 | fTextArea->setTextColor(previousColor);
|
|---|
| [501] | 297 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum());
|
|---|
| [495] | 298 | return 0;
|
|---|
| [481] | 299 | }
|
|---|
| 300 | /***************************************************************************/
|
|---|
| [484] | 301 | G4bool G4UIQt::GetHelpChoice(
|
|---|
| [481] | 302 | G4int& aInt
|
|---|
| 303 | )
|
|---|
| 304 | /***************************************************************************/
|
|---|
| 305 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 306 | {
|
|---|
| [501] | 307 | printf("G4UIQt::GetHelpChoice\n");
|
|---|
| 308 |
|
|---|
| 309 | fHelp = true; // TO KEEP
|
|---|
| [484] | 310 | // // SecondaryLoop : // TO KEEP
|
|---|
| [501] | 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
|
|---|
| [481] | 325 | }
|
|---|
| 326 | /***************************************************************************/
|
|---|
| [484] | 327 | void G4UIQt::ExitHelp(
|
|---|
| [481] | 328 | )
|
|---|
| 329 | /***************************************************************************/
|
|---|
| 330 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 331 | {
|
|---|
| [501] | 332 | printf("G4UIQt::ExitHelp\n");
|
|---|
| [481] | 333 | }
|
|---|
| [501] | 334 |
|
|---|
| [481] | 335 | /***************************************************************************/
|
|---|
| [484] | 336 | void G4UIQt::AddMenu (
|
|---|
| [481] | 337 | const char* a_name
|
|---|
| 338 | ,const char* a_label
|
|---|
| 339 | )
|
|---|
| 340 | /***************************************************************************/
|
|---|
| 341 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 342 | {
|
|---|
| [501] | 343 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label);
|
|---|
| 344 |
|
|---|
| [504] | 345 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label);
|
|---|
| 346 | AddInteractor (a_name,(G4Interactor)fileMenu);
|
|---|
| 347 |
|
|---|
| [501] | 348 | // QMenu *menu = new QMenu("test");//a_label);
|
|---|
| 349 | // fMainWindow->menuBar()->addMenu(menu);
|
|---|
| 350 |
|
|---|
| [481] | 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 | /***************************************************************************/
|
|---|
| [484] | 370 | void G4UIQt::AddButton (
|
|---|
| [481] | 371 | const char* a_menu
|
|---|
| 372 | ,const char* a_label
|
|---|
| 373 | ,const char* a_command
|
|---|
| 374 | )
|
|---|
| 375 | /***************************************************************************/
|
|---|
| 376 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 377 | {
|
|---|
| [504] | 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));
|
|---|
| [501] | 390 | printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command);
|
|---|
| [504] | 391 |
|
|---|
| [481] | 392 | // Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0);
|
|---|
| 393 | // XtManageChild (widget);
|
|---|
| 394 | // XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this);
|
|---|
| [504] | 395 | // commands[action] = a_command;
|
|---|
| [491] | 396 | }
|
|---|
| [504] | 397 |
|
|---|
| 398 |
|
|---|
| [481] | 399 | // /***************************************************************************/
|
|---|
| [504] | 400 | //G4String G4UIQt::GetCommand (
|
|---|
| 401 | // QAction *a_widget
|
|---|
| 402 | //)
|
|---|
| [481] | 403 | // /***************************************************************************/
|
|---|
| 404 | // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| 405 | // {
|
|---|
| 406 | // return commands[a_widget];
|
|---|
| 407 | // }
|
|---|
| 408 | /***************************************************************************/
|
|---|
| 409 | /***************************************************************************/
|
|---|
| 410 | /***************************************************************************/
|
|---|
| [494] | 411 |
|
|---|
| [481] | 412 | /**
|
|---|
| [494] | 413 | Callback call when "enter" clicked on the command zone.
|
|---|
| [481] | 414 | Send the command to geant4
|
|---|
| 415 | */
|
|---|
| [504] | 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());
|
|---|
| [505] | 424 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause);
|
|---|
| [504] | 425 | ApplyShellCommand(ss,exitSession,exitPause);
|
|---|
| [505] | 426 | if(exitSession==true)
|
|---|
| 427 | SessionTerminate();
|
|---|
| [504] | 428 | }
|
|---|
| 429 |
|
|---|
| 430 | /**
|
|---|
| 431 | Callback call when "click on a menu entry.
|
|---|
| 432 | Send the associated command to geant4
|
|---|
| 433 | */
|
|---|
| [494] | 434 | void G4UIQt::commandEnteredCallback (
|
|---|
| 435 | )
|
|---|
| [481] | 436 | /***************************************************************************/
|
|---|
| 437 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| [494] | 438 | {
|
|---|
| [505] | 439 | printf ("debug : callback\n");
|
|---|
| [500] | 440 | G4String command (fCommandArea->text().toStdString().c_str());
|
|---|
| 441 | if (fCommandArea->text().toStdString().c_str() != "") {
|
|---|
| 442 | fCommandHistoryArea->append(fCommandArea->text());
|
|---|
| 443 | if(fHelp==true) {
|
|---|
| [506] | 444 | printf ("ne doit plus passer ici\n");
|
|---|
| [500] | 445 | exitHelp = true;
|
|---|
| 446 | fHelp = ConvertStringToInt(command.data(),fHelpChoice);
|
|---|
| 447 | } else {
|
|---|
| [506] | 448 | if (command(0,4) != "help") {
|
|---|
| 449 | ApplyShellCommand (command,exitSession,exitPause);
|
|---|
| 450 | } else {
|
|---|
| 451 | printf ("terminal help\n");
|
|---|
| 452 | TerminalHelp(command);
|
|---|
| 453 | }
|
|---|
| [505] | 454 | if(exitSession==true)
|
|---|
| 455 | SessionTerminate();
|
|---|
| [500] | 456 | }
|
|---|
| 457 | }
|
|---|
| [505] | 458 | fCommandArea->setText("");
|
|---|
| [494] | 459 | }
|
|---|
| [488] | 460 |
|
|---|
| [504] | 461 |
|
|---|
| 462 | /***************************************************************************/
|
|---|
| [491] | 463 | void G4UIQt::clearButtonCallback (
|
|---|
| 464 | )
|
|---|
| [481] | 465 | /***************************************************************************/
|
|---|
| 466 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
|
|---|
| [491] | 467 | {
|
|---|
| [499] | 468 | fTextArea->clear();
|
|---|
| [491] | 469 | }
|
|---|
| 470 |
|
|---|
| [481] | 471 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 472 | G4bool ConvertStringToInt(
|
|---|
| 473 | const char* aString
|
|---|
| 474 | ,int& aInt
|
|---|
| 475 | )
|
|---|
| 476 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 477 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
|
|---|
| 478 | {
|
|---|
| [484] | 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
|
|---|
| [481] | 486 | }
|
|---|
| 487 |
|
|---|
| 488 | #endif
|
|---|
| [506] | 489 |
|
|---|
| 490 | void G4UIQt::TerminalHelp(G4String newCommand)
|
|---|
| 491 | {
|
|---|
| 492 | QDialog *helpDialog = new QDialog;
|
|---|
| 493 |
|
|---|
| 494 | QSplitter *splitter = new QSplitter(Qt::Horizontal);
|
|---|
| 495 | QTextEdit *textArea = new QTextEdit();
|
|---|
| 496 | QPushButton *exitButton = new QPushButton("Exit");
|
|---|
| 497 | connect(exitButton, SIGNAL(clicked()), helpDialog,SLOT(close()));
|
|---|
| 498 | textArea->setReadOnly(true);
|
|---|
| 499 |
|
|---|
| [507] | 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();
|
|---|
| [508] | 506 | treeWidget->setColumnCount(2);
|
|---|
| 507 | QStringList labels;
|
|---|
| 508 | labels << QString("Summary") << QString("Description");
|
|---|
| 509 | treeWidget->setHeaderLabels(labels);
|
|---|
| 510 |
|
|---|
| [507] | 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 |
|
|---|
| [506] | 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(textArea);
|
|---|
| 538 | splitter->setLayout(splitterLayout);
|
|---|
| 539 |
|
|---|
| 540 | vLayout->addWidget(splitter);
|
|---|
| 541 | vLayout->addWidget(exitButton);
|
|---|
| 542 | helpDialog->setLayout(vLayout);
|
|---|
| 543 |
|
|---|
| [508] | 544 | helpDialog->resize(800,600);
|
|---|
| 545 | helpDialog->move(QPoint(400,150));
|
|---|
| [506] | 546 | helpDialog->show();
|
|---|
| 547 | helpDialog->raise();
|
|---|
| 548 | helpDialog->activateWindow();
|
|---|
| 549 | ////////////////
|
|---|
| 550 |
|
|---|
| 551 | printf ("G4UIQt::TerminalHelp \n");
|
|---|
| [507] | 552 |
|
|---|
| 553 |
|
|---|
| [506] | 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 | }
|
|---|
| [507] | 623 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) {
|
|---|
| 624 | printf ("G4UIQt::CreateChildTree \n");
|
|---|
| [506] | 625 |
|
|---|
| [507] | 626 | // Creating new item
|
|---|
| 627 | QTreeWidgetItem * newItem;
|
|---|
| [506] | 628 |
|
|---|
| [508] | 629 | // QSignalMapper *signalMapper = new QSignalMapper(this);
|
|---|
| [506] | 630 |
|
|---|
| [508] | 631 | // Get the Sub directories
|
|---|
| 632 | for (unsigned int a=0;a<a_commandTree->GetTreeEntry();a++) {
|
|---|
| 633 |
|
|---|
| [507] | 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);
|
|---|
| [508] | 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 |
|
|---|
| [507] | 647 | CreateChildTree(newItem,a_commandTree->GetTree(a+1));
|
|---|
| [508] | 648 | a_parent->addChild(newItem);
|
|---|
| [507] | 649 | }
|
|---|
| [506] | 650 |
|
|---|
| [508] | 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 | // QAction *action = parent->addAction(a_label, signalMapper, SLOT(map()));
|
|---|
| 665 |
|
|---|
| 666 | // signalMapper->setMapping(action, QString(a_command));
|
|---|
| 667 | // connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&)));
|
|---|
| 668 | //QTreeWidget::itemActivated ( QTreeWidgetItem * item, int column ) [signal]
|
|---|
| 669 |
|
|---|
| 670 | // CreateChildTree(newItem,a_commandTree->GetCommand(a+1));
|
|---|
| 671 | a_parent->addChild(newItem);
|
|---|
| 672 |
|
|---|
| 673 | }
|
|---|
| 674 |
|
|---|
| [507] | 675 | printf ("G4UIQt::CreateChildTree end of for loop\n");
|
|---|
| 676 | }
|
|---|