[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); |
---|
[510] | 495 | fHelpArea = new QTextEdit(); |
---|
[506] | 496 | QPushButton *exitButton = new QPushButton("Exit"); |
---|
| 497 | connect(exitButton, SIGNAL(clicked()), helpDialog,SLOT(close())); |
---|
[509] | 498 | fHelpArea->setReadOnly(true); |
---|
[506] | 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; |
---|
[510] | 514 | for (int a=0;a<treeSize;a++) { |
---|
[507] | 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 | |
---|
[510] | 529 | //connecting callback |
---|
| 530 | signalMapper = new QSignalMapper(this); |
---|
| 531 | connect(treeWidget, SIGNAL(itemClicked(QTreeWidgetItem*, int)),this, SLOT(helpTreeCallback(QTreeWidgetItem*, int))); |
---|
[507] | 532 | |
---|
[506] | 533 | // Set layouts |
---|
| 534 | QHBoxLayout *splitterLayout = new QHBoxLayout; |
---|
| 535 | |
---|
| 536 | QVBoxLayout *vLayout = new QVBoxLayout; |
---|
| 537 | |
---|
| 538 | splitterLayout->addWidget(treeWidget); |
---|
[509] | 539 | splitterLayout->addWidget(fHelpArea); |
---|
[506] | 540 | splitter->setLayout(splitterLayout); |
---|
| 541 | |
---|
| 542 | vLayout->addWidget(splitter); |
---|
| 543 | vLayout->addWidget(exitButton); |
---|
| 544 | helpDialog->setLayout(vLayout); |
---|
| 545 | |
---|
[508] | 546 | helpDialog->resize(800,600); |
---|
| 547 | helpDialog->move(QPoint(400,150)); |
---|
[506] | 548 | helpDialog->show(); |
---|
| 549 | helpDialog->raise(); |
---|
| 550 | helpDialog->activateWindow(); |
---|
| 551 | //////////////// |
---|
| 552 | |
---|
| 553 | printf ("G4UIQt::TerminalHelp \n"); |
---|
[507] | 554 | |
---|
| 555 | |
---|
[506] | 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 | } |
---|
[507] | 625 | void G4UIQt::CreateChildTree(QTreeWidgetItem *a_parent,G4UIcommandTree *a_commandTree) { |
---|
| 626 | printf ("G4UIQt::CreateChildTree \n"); |
---|
[506] | 627 | |
---|
[507] | 628 | // Creating new item |
---|
| 629 | QTreeWidgetItem * newItem; |
---|
[506] | 630 | |
---|
| 631 | |
---|
[508] | 632 | // Get the Sub directories |
---|
[510] | 633 | for (int a=0;a<a_commandTree->GetTreeEntry();a++) { |
---|
[508] | 634 | |
---|
[507] | 635 | QStringList stringList; |
---|
| 636 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetPathName()).data()).trimmed() ; |
---|
| 637 | stringList << QString((char*)(a_commandTree->GetTree(a+1)->GetTitle()).data()).trimmed() ; |
---|
| 638 | newItem = new QTreeWidgetItem(stringList); |
---|
[508] | 639 | |
---|
| 640 | //connecting callback |
---|
| 641 | // signalMapper = new QSignalMapper(this); |
---|
| 642 | // QAction *action = parent->addAction(a_label, signalMapper, SLOT(map())); |
---|
| 643 | |
---|
| 644 | // signalMapper->setMapping(action, QString(a_command)); |
---|
| 645 | // connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(helpTreeCallback(const QString&))); |
---|
| 646 | //QTreeWidget::itemActivated ( QTreeWidgetItem * item, int column ) [signal] |
---|
| 647 | |
---|
[507] | 648 | CreateChildTree(newItem,a_commandTree->GetTree(a+1)); |
---|
[508] | 649 | a_parent->addChild(newItem); |
---|
[507] | 650 | } |
---|
[506] | 651 | |
---|
[508] | 652 | |
---|
| 653 | |
---|
| 654 | // Get the Commands |
---|
| 655 | |
---|
[510] | 656 | for (int a=0;a<a_commandTree->GetCommandEntry();a++) { |
---|
[508] | 657 | |
---|
| 658 | QStringList stringList; |
---|
[510] | 659 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetCommandPath()).data()).trimmed() ; |
---|
[508] | 660 | stringList << QString((char*)(a_commandTree->GetCommand(a+1)->GetTitle()).data()).trimmed() ; |
---|
| 661 | newItem = new QTreeWidgetItem(stringList); |
---|
[509] | 662 | |
---|
[508] | 663 | a_parent->addChild(newItem); |
---|
| 664 | |
---|
| 665 | } |
---|
| 666 | |
---|
[507] | 667 | printf ("G4UIQt::CreateChildTree end of for loop\n"); |
---|
| 668 | } |
---|
[509] | 669 | |
---|
| 670 | /** |
---|
| 671 | This callback is activated when user selected a item in the help tree |
---|
| 672 | */ |
---|
| 673 | /***************************************************************************/ |
---|
| 674 | void G4UIQt::helpTreeCallback ( |
---|
[510] | 675 | QTreeWidgetItem* a_treeItem |
---|
| 676 | ,int a_index |
---|
[509] | 677 | ) |
---|
| 678 | /***************************************************************************/ |
---|
| 679 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 680 | { |
---|
[510] | 681 | if (fHelpArea) { |
---|
| 682 | G4UImanager* UI = G4UImanager::GetUIpointer(); |
---|
| 683 | if(UI==NULL) return; |
---|
| 684 | G4UIcommandTree * treeTop = UI->GetTree(); |
---|
| 685 | G4UIcommand* command = treeTop->FindPath(a_treeItem->text (0).toStdString().c_str()); |
---|
| 686 | if (command) { |
---|
| 687 | printf ("G4UIQt::CreateChildTree end of for loop ========\n"); |
---|
| 688 | fHelpArea->setText(GetCommandList(treeTop->FindPath(a_treeItem->text (0).toStdString().c_str()))); |
---|
| 689 | } else { |
---|
| 690 | printf ("G4UIQt::CreateChildTree end of for loop ********\n"); |
---|
| 691 | } |
---|
| 692 | } |
---|
[509] | 693 | } |
---|
| 694 | |
---|
| 695 | /** |
---|
| 696 | */ |
---|
| 697 | /***************************************************************************/ |
---|
| 698 | QString G4UIQt::GetCommandList ( |
---|
| 699 | G4UIcommand *a_command |
---|
| 700 | ) |
---|
| 701 | /***************************************************************************/ |
---|
| 702 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 703 | { |
---|
[510] | 704 | printf ("G4UIQt::CreateChildTree %s --\n",(char*)(a_command->GetCommandName()).data()) ; |
---|
| 705 | |
---|
[509] | 706 | QString txt; |
---|
| 707 | G4String commandPath = a_command->GetCommandPath(); |
---|
| 708 | G4String rangeString = a_command->GetRange(); |
---|
| 709 | |
---|
| 710 | if((commandPath.length()-1)!='/') |
---|
| 711 | { |
---|
| 712 | txt += "Command " + QString((char*)(commandPath).data()) + "\n"; |
---|
| 713 | } |
---|
| 714 | txt += "Guidance :\n"; |
---|
| 715 | G4int n_guidanceEntry = a_command->GetGuidanceEntries(); |
---|
| 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 | for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) |
---|
| 724 | { a_command->GetParameter(i_thParameter)->List(); } |
---|
| 725 | } |
---|
| 726 | return txt; |
---|
| 727 | } |
---|