[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> |
---|
[481] | 59 | |
---|
| 60 | #include <stdlib.h> |
---|
| 61 | |
---|
| 62 | static G4bool ConvertStringToInt(const char*,int&); |
---|
| 63 | |
---|
| 64 | static G4bool exitSession = true; |
---|
| 65 | static G4bool exitPause = true; |
---|
| 66 | static G4bool exitHelp = true; |
---|
| 67 | /***************************************************************************/ |
---|
| 68 | /** |
---|
| 69 | Build a Qt window with a menubar, output area and promt area |
---|
| 70 | +-----------------------+ |
---|
| 71 | |exit menu| | |
---|
| 72 | | | |
---|
| 73 | | +-------------------+ | |
---|
| 74 | | | | | |
---|
| 75 | | | Output area | | |
---|
| 76 | | | | | |
---|
| 77 | | +-------------------+ | |
---|
[488] | 78 | | | clear | | |
---|
[481] | 79 | | +-------------------+ | |
---|
[494] | 80 | | | promt history | | |
---|
| 81 | | +-------------------+ | |
---|
| 82 | | +-------------------+ | |
---|
[481] | 83 | | |> promt area | | |
---|
| 84 | | +-------------------+ | |
---|
[484] | 85 | +-----------------------+ |
---|
[481] | 86 | */ |
---|
| 87 | |
---|
| 88 | G4UIQt::G4UIQt ( |
---|
| 89 | int argc, |
---|
| 90 | char** argv |
---|
| 91 | ) |
---|
| 92 | /***************************************************************************/ |
---|
| 93 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 94 | { |
---|
[496] | 95 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
[505] | 96 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 97 | if(UI!=NULL) UI->SetSession(this); |
---|
[481] | 98 | |
---|
[494] | 99 | fMainWindow = new QMainWindow(); |
---|
| 100 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
[500] | 101 | fMainWindow->resize(800,600); |
---|
[505] | 102 | fMainWindow->move(QPoint(300,100)); |
---|
[496] | 103 | |
---|
[498] | 104 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
| 105 | fTextArea = new QTextEdit(); |
---|
[490] | 106 | QPushButton *clearButton = new QPushButton("clear"); |
---|
[498] | 107 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
| 108 | |
---|
| 109 | fCommandHistoryArea = new QTextEdit(); |
---|
| 110 | fCommandLabel = new QLabel(); |
---|
| 111 | |
---|
| 112 | fCommandArea = new QLineEdit(); |
---|
[500] | 113 | fCommandArea->activateWindow(); |
---|
[498] | 114 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
[500] | 115 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
| 116 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
[498] | 117 | fTextArea->setReadOnly(true); |
---|
| 118 | fCommandHistoryArea->setReadOnly(true); |
---|
| 119 | |
---|
[496] | 120 | |
---|
[505] | 121 | |
---|
| 122 | // Set layouts |
---|
[498] | 123 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
[497] | 124 | |
---|
[498] | 125 | QWidget* topWidget = new QWidget(); |
---|
| 126 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
[481] | 127 | |
---|
[498] | 128 | QWidget* bottomWidget = new QWidget(); |
---|
| 129 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
[494] | 130 | |
---|
[490] | 131 | |
---|
[498] | 132 | layoutTop->addWidget(fTextArea); |
---|
| 133 | layoutTop->addWidget(clearButton); |
---|
| 134 | topWidget->setLayout(layoutTop); |
---|
[494] | 135 | |
---|
[498] | 136 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
| 137 | layoutBottom->addWidget(fCommandLabel); |
---|
| 138 | layoutBottom->addWidget(fCommandArea); |
---|
| 139 | bottomWidget->setLayout(layoutBottom); |
---|
[490] | 140 | |
---|
[495] | 141 | |
---|
[498] | 142 | layoutSplitter->addWidget(topWidget); |
---|
| 143 | layoutSplitter->addWidget(bottomWidget); |
---|
| 144 | splitter->setLayout(layoutSplitter); |
---|
[495] | 145 | |
---|
[498] | 146 | fMainWindow->setCentralWidget(splitter); |
---|
[495] | 147 | |
---|
[504] | 148 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu("File"); |
---|
[503] | 149 | fileMenu->addAction("Quitter", fMainWindow, SLOT(close())); |
---|
[496] | 150 | |
---|
[505] | 151 | // Set the splitter size. The fTextArea sould be 2/3 on the fMainWindow |
---|
| 152 | QList<int> vals = splitter->sizes(); |
---|
| 153 | if(vals.size()==2) { |
---|
| 154 | vals[0] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*3/4; |
---|
| 155 | vals[1] = (splitter->orientation()==Qt::Vertical ? splitter->height() : splitter->width())*1/4; |
---|
| 156 | splitter->setSizes(vals); |
---|
| 157 | } |
---|
[481] | 158 | |
---|
| 159 | |
---|
[484] | 160 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
[481] | 161 | } |
---|
| 162 | /***************************************************************************/ |
---|
| 163 | G4UIQt::~G4UIQt( |
---|
| 164 | ) |
---|
| 165 | /***************************************************************************/ |
---|
| 166 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 167 | { |
---|
[484] | 168 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
| 169 | if(UI!=NULL) { // TO KEEP |
---|
| 170 | UI->SetSession(NULL); // TO KEEP |
---|
| 171 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
[481] | 172 | } |
---|
[484] | 173 | |
---|
| 174 | |
---|
[494] | 175 | if (fMainWindow!=NULL) |
---|
| 176 | delete fMainWindow; |
---|
[481] | 177 | } |
---|
| 178 | /***************************************************************************/ |
---|
| 179 | /* |
---|
| 180 | Start the Qt main loop |
---|
| 181 | */ |
---|
| 182 | G4UIsession* G4UIQt::SessionStart ( |
---|
| 183 | ) |
---|
| 184 | /***************************************************************************/ |
---|
| 185 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 186 | { |
---|
[484] | 187 | |
---|
[496] | 188 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
[494] | 189 | fMainWindow->show(); |
---|
| 190 | Prompt("session"); |
---|
| 191 | exitSession = false; |
---|
[481] | 192 | |
---|
[496] | 193 | |
---|
| 194 | printf("disable secondary loop\n"); |
---|
| 195 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
| 196 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
| 197 | // on ne passe pas le dessous ? FIXME ???? |
---|
| 198 | |
---|
| 199 | |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | |
---|
[484] | 204 | // void* event; // TO KEEP |
---|
| 205 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 206 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 207 | // if(exitSession==true) break; // TO KEEP |
---|
| 208 | // } // TO KEEP |
---|
[496] | 209 | interactorManager->EnableSecondaryLoop (); // TO KEEP |
---|
| 210 | printf("enable secondary loop\n"); |
---|
[484] | 211 | return this; // TO KEEP |
---|
[481] | 212 | } |
---|
| 213 | /***************************************************************************/ |
---|
[494] | 214 | |
---|
[481] | 215 | /** |
---|
| 216 | Display the prompt in the prompt area |
---|
| 217 | */ |
---|
| 218 | void G4UIQt::Prompt ( |
---|
| 219 | G4String aPrompt |
---|
| 220 | ) |
---|
| 221 | /***************************************************************************/ |
---|
| 222 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 223 | { |
---|
[500] | 224 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
[481] | 225 | } |
---|
| 226 | /***************************************************************************/ |
---|
| 227 | void G4UIQt::SessionTerminate ( |
---|
| 228 | ) |
---|
| 229 | /***************************************************************************/ |
---|
| 230 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 231 | { |
---|
[505] | 232 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
| 233 | fMainWindow->close(); |
---|
| 234 | ((QApplication*)interactorManager->GetMainInteractor())->exit(); |
---|
[481] | 235 | } |
---|
| 236 | /***************************************************************************/ |
---|
| 237 | void G4UIQt::PauseSessionStart ( |
---|
| 238 | G4String a_state |
---|
| 239 | ) |
---|
| 240 | /***************************************************************************/ |
---|
| 241 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 242 | { |
---|
[501] | 243 | printf("G4UIQt::PauseSessionStart\n"); |
---|
[484] | 244 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
| 245 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
| 246 | } // TO KEEP |
---|
[481] | 247 | |
---|
[484] | 248 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
[481] | 249 | // Picking with feed back in event data Done here !!! |
---|
[484] | 250 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
| 251 | } // TO KEEP |
---|
[481] | 252 | } |
---|
| 253 | /***************************************************************************/ |
---|
[484] | 254 | void G4UIQt::SecondaryLoop ( |
---|
[481] | 255 | G4String a_prompt |
---|
| 256 | ) |
---|
| 257 | /***************************************************************************/ |
---|
| 258 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 259 | { |
---|
[501] | 260 | printf("G4UIQt::SecondaryLoop\n"); |
---|
[484] | 261 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 262 | Prompt(a_prompt); // TO KEEP |
---|
| 263 | exitPause = false; // TO KEEP |
---|
| 264 | void* event; // TO KEEP |
---|
| 265 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 266 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 267 | if(exitPause==true) break; // TO KEEP |
---|
| 268 | } // TO KEEP |
---|
| 269 | Prompt("session"); // TO KEEP |
---|
[481] | 270 | } |
---|
| 271 | /***************************************************************************/ |
---|
| 272 | /** |
---|
| 273 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
| 274 | */ |
---|
[484] | 275 | G4int G4UIQt::ReceiveG4cout ( |
---|
[481] | 276 | G4String a_string |
---|
| 277 | ) |
---|
| 278 | /***************************************************************************/ |
---|
| 279 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 280 | { |
---|
[500] | 281 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
| 282 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
[495] | 283 | return 0; |
---|
[481] | 284 | } |
---|
| 285 | /***************************************************************************/ |
---|
| 286 | /** |
---|
| 287 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
| 288 | */ |
---|
[484] | 289 | G4int G4UIQt::ReceiveG4cerr ( |
---|
[481] | 290 | G4String a_string |
---|
| 291 | ) |
---|
| 292 | /***************************************************************************/ |
---|
| 293 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 294 | { |
---|
[500] | 295 | QColor previousColor = fTextArea->textColor(); |
---|
| 296 | fTextArea->setTextColor(Qt::red); |
---|
| 297 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
| 298 | fTextArea->setTextColor(previousColor); |
---|
[501] | 299 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
[495] | 300 | return 0; |
---|
[481] | 301 | } |
---|
| 302 | /***************************************************************************/ |
---|
[484] | 303 | G4bool G4UIQt::GetHelpChoice( |
---|
[481] | 304 | G4int& aInt |
---|
| 305 | ) |
---|
| 306 | /***************************************************************************/ |
---|
| 307 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 308 | { |
---|
[501] | 309 | printf("G4UIQt::GetHelpChoice\n"); |
---|
| 310 | |
---|
| 311 | fHelp = true; // TO KEEP |
---|
[484] | 312 | // // SecondaryLoop : // TO KEEP |
---|
[501] | 313 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 314 | Prompt("Help"); // TO KEEP |
---|
| 315 | exitHelp = false; // TO KEEP |
---|
| 316 | void* event; // TO KEEP |
---|
| 317 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 318 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 319 | if(exitHelp==true) break; // TO KEEP |
---|
| 320 | } // TO KEEP |
---|
| 321 | Prompt("session"); // TO KEEP |
---|
| 322 | // // TO KEEP |
---|
| 323 | if(fHelp==false) return false; // TO KEEP |
---|
| 324 | aInt = fHelpChoice; // TO KEEP |
---|
| 325 | fHelp = false; // TO KEEP |
---|
| 326 | return true; // TO KEEP |
---|
[481] | 327 | } |
---|
| 328 | /***************************************************************************/ |
---|
[484] | 329 | void G4UIQt::ExitHelp( |
---|
[481] | 330 | ) |
---|
| 331 | /***************************************************************************/ |
---|
| 332 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 333 | { |
---|
[501] | 334 | printf("G4UIQt::ExitHelp\n"); |
---|
[481] | 335 | } |
---|
[501] | 336 | |
---|
[481] | 337 | /***************************************************************************/ |
---|
[484] | 338 | void G4UIQt::AddMenu ( |
---|
[481] | 339 | const char* a_name |
---|
| 340 | ,const char* a_label |
---|
| 341 | ) |
---|
| 342 | /***************************************************************************/ |
---|
| 343 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 344 | { |
---|
[501] | 345 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
| 346 | |
---|
[504] | 347 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu(a_label); |
---|
| 348 | AddInteractor (a_name,(G4Interactor)fileMenu); |
---|
| 349 | |
---|
[501] | 350 | // QMenu *menu = new QMenu("test");//a_label); |
---|
| 351 | // fMainWindow->menuBar()->addMenu(menu); |
---|
| 352 | |
---|
[481] | 353 | // if(menuBar==NULL) return; |
---|
| 354 | // if(a_name==NULL) return; |
---|
| 355 | // if(a_label==NULL) return; |
---|
| 356 | // XtManageChild (menuBar); |
---|
| 357 | // // Pulldown menu : |
---|
| 358 | // Widget widget; |
---|
| 359 | // widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0); |
---|
| 360 | // AddInteractor (a_name,(G4Interactor)widget); |
---|
| 361 | // // Cascade button : |
---|
| 362 | // Arg args[2]; |
---|
| 363 | // XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET); |
---|
| 364 | // XtSetArg (args[0],XmNlabelString,cps); |
---|
| 365 | // XtSetArg (args[1],XmNsubMenuId,widget); |
---|
| 366 | // widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2); |
---|
| 367 | // XmStringFree (cps); |
---|
| 368 | // XtManageChild (widget); |
---|
| 369 | // ExecuteChangeSizeFunction(form); |
---|
| 370 | } |
---|
| 371 | /***************************************************************************/ |
---|
[484] | 372 | void G4UIQt::AddButton ( |
---|
[481] | 373 | const char* a_menu |
---|
| 374 | ,const char* a_label |
---|
| 375 | ,const char* a_command |
---|
| 376 | ) |
---|
| 377 | /***************************************************************************/ |
---|
| 378 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 379 | { |
---|
[504] | 380 | if(a_menu==NULL) return; // TO KEEP |
---|
| 381 | if(a_label==NULL) return; // TO KEEP |
---|
| 382 | if(a_command==NULL) return; // TO KEEP |
---|
| 383 | QMenu *parent = (QMenu*)GetInteractor(a_menu); |
---|
| 384 | if(parent==NULL) return; |
---|
| 385 | |
---|
| 386 | signalMapper = new QSignalMapper(this); |
---|
| 387 | QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
| 388 | signalMapper->setMapping(action, QString(a_command)); |
---|
| 389 | connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(buttonCallback(const QString&))); |
---|
| 390 | |
---|
| 391 | // std::string slot = SLOT(buttonCallback(std::string)); |
---|
[501] | 392 | printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command); |
---|
[504] | 393 | |
---|
[481] | 394 | // Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0); |
---|
| 395 | // XtManageChild (widget); |
---|
| 396 | // XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this); |
---|
[504] | 397 | // commands[action] = a_command; |
---|
[491] | 398 | } |
---|
[504] | 399 | |
---|
| 400 | |
---|
[481] | 401 | // /***************************************************************************/ |
---|
[504] | 402 | //G4String G4UIQt::GetCommand ( |
---|
| 403 | // QAction *a_widget |
---|
| 404 | //) |
---|
[481] | 405 | // /***************************************************************************/ |
---|
| 406 | // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 407 | // { |
---|
| 408 | // return commands[a_widget]; |
---|
| 409 | // } |
---|
| 410 | /***************************************************************************/ |
---|
| 411 | /***************************************************************************/ |
---|
| 412 | /***************************************************************************/ |
---|
[494] | 413 | |
---|
[481] | 414 | /** |
---|
[494] | 415 | Callback call when "enter" clicked on the command zone. |
---|
[481] | 416 | Send the command to geant4 |
---|
| 417 | */ |
---|
[504] | 418 | void G4UIQt::buttonCallback ( |
---|
| 419 | const QString& a_command |
---|
| 420 | ) |
---|
| 421 | /***************************************************************************/ |
---|
| 422 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 423 | { |
---|
| 424 | if(fHelp==true) return; // Disabled when in help. |
---|
| 425 | G4String ss = G4String(a_command.toStdString().c_str()); |
---|
[505] | 426 | printf ("debug : execute:\n-%s- %d %d \n",ss.data(),exitSession,exitPause); |
---|
[504] | 427 | ApplyShellCommand(ss,exitSession,exitPause); |
---|
[505] | 428 | if(exitSession==true) |
---|
| 429 | SessionTerminate(); |
---|
[504] | 430 | } |
---|
| 431 | |
---|
| 432 | /** |
---|
| 433 | Callback call when "click on a menu entry. |
---|
| 434 | Send the associated command to geant4 |
---|
| 435 | */ |
---|
[494] | 436 | void G4UIQt::commandEnteredCallback ( |
---|
| 437 | ) |
---|
[481] | 438 | /***************************************************************************/ |
---|
| 439 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
[494] | 440 | { |
---|
[505] | 441 | printf ("debug : callback\n"); |
---|
[500] | 442 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
| 443 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
| 444 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
| 445 | if(fHelp==true) { |
---|
| 446 | exitHelp = true; |
---|
| 447 | fHelp = ConvertStringToInt(command.data(),fHelpChoice); |
---|
| 448 | } else { |
---|
| 449 | ApplyShellCommand (command,exitSession,exitPause); |
---|
[505] | 450 | if(exitSession==true) |
---|
| 451 | SessionTerminate(); |
---|
[500] | 452 | } |
---|
| 453 | } |
---|
[505] | 454 | fCommandArea->setText(""); |
---|
[494] | 455 | } |
---|
[488] | 456 | |
---|
[504] | 457 | |
---|
| 458 | /***************************************************************************/ |
---|
[491] | 459 | void G4UIQt::clearButtonCallback ( |
---|
| 460 | ) |
---|
[481] | 461 | /***************************************************************************/ |
---|
| 462 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
[491] | 463 | { |
---|
[499] | 464 | fTextArea->clear(); |
---|
[491] | 465 | } |
---|
| 466 | |
---|
[481] | 467 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 468 | G4bool ConvertStringToInt( |
---|
| 469 | const char* aString |
---|
| 470 | ,int& aInt |
---|
| 471 | ) |
---|
| 472 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 473 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 474 | { |
---|
[484] | 475 | aInt = 0; // TO KEEP |
---|
| 476 | if(aString==NULL) return false; // TO KEEP |
---|
| 477 | char* s; // TO KEEP |
---|
| 478 | long value = strtol(aString,&s,10); // TO KEEP |
---|
| 479 | if(s==aString) return false; // TO KEEP |
---|
| 480 | aInt = value; // TO KEEP |
---|
| 481 | return true; // TO KEEP |
---|
[481] | 482 | } |
---|
| 483 | |
---|
| 484 | #endif |
---|