[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 (); |
---|
[484] | 96 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
| 97 | if(UI!=NULL) UI->SetSession(this); // TO KEEP |
---|
[481] | 98 | |
---|
[494] | 99 | fMainWindow = new QMainWindow(); |
---|
| 100 | fMainWindow->setWindowTitle( "G4UI Session" ); |
---|
[500] | 101 | fMainWindow->resize(800,600); |
---|
[496] | 102 | |
---|
[498] | 103 | QSplitter *splitter = new QSplitter(Qt::Vertical); |
---|
| 104 | fTextArea = new QTextEdit(); |
---|
[490] | 105 | QPushButton *clearButton = new QPushButton("clear"); |
---|
[498] | 106 | connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback())); |
---|
| 107 | |
---|
| 108 | fCommandHistoryArea = new QTextEdit(); |
---|
| 109 | fCommandLabel = new QLabel(); |
---|
| 110 | |
---|
| 111 | fCommandArea = new QLineEdit(); |
---|
[500] | 112 | fCommandArea->activateWindow(); |
---|
[498] | 113 | connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback())); |
---|
[500] | 114 | fCommandArea->setFocusPolicy ( Qt::StrongFocus ); |
---|
| 115 | fCommandArea->setFocus(Qt::TabFocusReason); |
---|
[498] | 116 | fTextArea->setReadOnly(true); |
---|
| 117 | fCommandHistoryArea->setReadOnly(true); |
---|
| 118 | |
---|
[496] | 119 | |
---|
[498] | 120 | QVBoxLayout *layoutSplitter = new QVBoxLayout; |
---|
[497] | 121 | |
---|
[498] | 122 | QWidget* topWidget = new QWidget(); |
---|
| 123 | QVBoxLayout *layoutTop = new QVBoxLayout; |
---|
[481] | 124 | |
---|
[498] | 125 | QWidget* bottomWidget = new QWidget(); |
---|
| 126 | QVBoxLayout *layoutBottom = new QVBoxLayout; |
---|
[494] | 127 | |
---|
[490] | 128 | |
---|
[498] | 129 | layoutTop->addWidget(fTextArea); |
---|
| 130 | layoutTop->addWidget(clearButton); |
---|
| 131 | topWidget->setLayout(layoutTop); |
---|
[494] | 132 | |
---|
[498] | 133 | layoutBottom->addWidget(fCommandHistoryArea); |
---|
| 134 | layoutBottom->addWidget(fCommandLabel); |
---|
| 135 | layoutBottom->addWidget(fCommandArea); |
---|
| 136 | bottomWidget->setLayout(layoutBottom); |
---|
[490] | 137 | |
---|
[495] | 138 | |
---|
[498] | 139 | layoutSplitter->addWidget(topWidget); |
---|
| 140 | layoutSplitter->addWidget(bottomWidget); |
---|
| 141 | splitter->setLayout(layoutSplitter); |
---|
[495] | 142 | |
---|
[498] | 143 | fMainWindow->setCentralWidget(splitter); |
---|
[495] | 144 | |
---|
| 145 | |
---|
[501] | 146 | QMenu *fileMenu = fMainWindow->menuBar()->addMenu(tr("&File")); |
---|
| 147 | fileMenu->addAction("Quitter", this, SLOT(fMainWindow->close())); |
---|
| 148 | fileMenu->addAction("Quitter2", this, SLOT(fMainWindow->close())); |
---|
| 149 | fileMenu->addSeparator(); |
---|
[496] | 150 | |
---|
| 151 | |
---|
[484] | 152 | // QMainWindow top = (QMainWindow)interactorManager->GetMainInteractor(); |
---|
[481] | 153 | |
---|
| 154 | // if(getenv("XENVIRONMENT")==NULL) { |
---|
| 155 | // XrmDatabase database = XrmGetDatabase(XtDisplay(top)); |
---|
| 156 | // if(database!=NULL) { |
---|
| 157 | // XrmPutLineResource(&database,"*topShadowColor:white"); |
---|
| 158 | // XrmPutLineResource(&database,"*bottomShadowColor:black"); |
---|
| 159 | // XrmPutLineResource(&database,"*foreground:black"); |
---|
| 160 | // XrmPutLineResource(&database,"*background:lightgrey"); |
---|
| 161 | // XrmPutLineResource(&database,"*borderColor:lightgrey"); |
---|
| 162 | // XrmPutLineResource(&database,"*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1"); |
---|
| 163 | // XrmPutLineResource(&database,"*text.background:white"); |
---|
| 164 | // XrmPutLineResource(&database,"*text.fontList:*courier*-r-*--14-*"); |
---|
| 165 | // XrmPutLineResource(&database,"*text.maxLength:8000"); |
---|
| 166 | // } |
---|
| 167 | // } |
---|
| 168 | |
---|
| 169 | // Arg args[9]; |
---|
| 170 | // XtSetArg(args[0],XmNkeyboardFocusPolicy,XmPOINTER); // For completion. |
---|
| 171 | // shell = XtAppCreateShell ("G4UIXm","G4UIXm", |
---|
| 172 | // topLevelShellWidgetClass,XtDisplay(top), |
---|
| 173 | // args,1); |
---|
| 174 | // form = XmCreateForm (shell,(char*)"form",NULL,0); |
---|
| 175 | // XtManageChild (form); |
---|
| 176 | |
---|
| 177 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM); |
---|
| 178 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 179 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 180 | // menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3); |
---|
| 181 | |
---|
| 182 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE); |
---|
| 183 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 184 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 185 | // XtSetArg(args[3],XmNbottomAttachment ,XmATTACH_FORM); |
---|
| 186 | // command = XmCreateCommand (form,(char*)"command",args,4); |
---|
| 187 | // XtManageChild (command); |
---|
| 188 | |
---|
| 189 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE); |
---|
| 190 | // XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 191 | // XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 192 | // XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
| 193 | // XtSetArg(args[4],XmNbottomWidget ,command); |
---|
| 194 | // XmString cps = XmStringLtoRCreate((char*)"Clear",XmSTRING_DEFAULT_CHARSET); |
---|
| 195 | // XtSetArg (args[5],XmNlabelString,cps); |
---|
| 196 | // Widget clearButton = XmCreatePushButton(form,(char*)"clearButton",args,6); |
---|
| 197 | // XmStringFree (cps); |
---|
| 198 | // XtManageChild (clearButton); |
---|
| 199 | |
---|
| 200 | // XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET); |
---|
| 201 | // XtSetArg(args[1],XmNtopWidget ,menuBar); |
---|
| 202 | // XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM); |
---|
| 203 | // XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM); |
---|
| 204 | // XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET); |
---|
| 205 | // XtSetArg(args[5],XmNbottomWidget ,clearButton); |
---|
| 206 | // XtSetArg(args[6],XmNeditMode ,XmMULTI_LINE_EDIT); |
---|
| 207 | // XtSetArg(args[7],XmNrows ,12); |
---|
| 208 | // XtSetArg(args[8],XmNcolumns ,80); |
---|
[484] | 209 | // text = XmCreateSGcrolledText (form,(char*)"text",args,9); |
---|
[481] | 210 | // XtManageChild (text); |
---|
| 211 | |
---|
| 212 | // XtAddCallback(clearButton,XmNactivateCallback, |
---|
| 213 | // clearButtonCallback,(XtPointer)text); |
---|
| 214 | // XtAddCallback(command,XmNcommandEnteredCallback, |
---|
| 215 | // commandEnteredCallback,(XtPointer)this); |
---|
| 216 | |
---|
| 217 | // Widget commandText = XmCommandGetChild(command,XmDIALOG_COMMAND_TEXT); |
---|
| 218 | // XtAddEventHandler(commandText,KeyPressMask,False,keyHandler,(XtPointer)this); |
---|
| 219 | |
---|
| 220 | // XtRealizeWidget(shell); |
---|
| 221 | // XtMapWidget(shell); |
---|
| 222 | |
---|
[484] | 223 | if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP |
---|
[481] | 224 | } |
---|
| 225 | /***************************************************************************/ |
---|
| 226 | G4UIQt::~G4UIQt( |
---|
| 227 | ) |
---|
| 228 | /***************************************************************************/ |
---|
| 229 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 230 | { |
---|
[484] | 231 | G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP |
---|
| 232 | if(UI!=NULL) { // TO KEEP |
---|
| 233 | UI->SetSession(NULL); // TO KEEP |
---|
| 234 | UI->SetCoutDestination(NULL); // TO KEEP |
---|
[481] | 235 | } |
---|
[484] | 236 | |
---|
| 237 | |
---|
[494] | 238 | if (fMainWindow!=NULL) |
---|
| 239 | delete fMainWindow; |
---|
[481] | 240 | } |
---|
| 241 | /***************************************************************************/ |
---|
| 242 | /* |
---|
| 243 | Start the Qt main loop |
---|
| 244 | */ |
---|
| 245 | G4UIsession* G4UIQt::SessionStart ( |
---|
| 246 | ) |
---|
| 247 | /***************************************************************************/ |
---|
| 248 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 249 | { |
---|
[484] | 250 | |
---|
[496] | 251 | G4Qt* interactorManager = G4Qt::getInstance (); |
---|
[494] | 252 | fMainWindow->show(); |
---|
| 253 | Prompt("session"); |
---|
| 254 | exitSession = false; |
---|
[481] | 255 | |
---|
[496] | 256 | |
---|
| 257 | printf("disable secondary loop\n"); |
---|
| 258 | interactorManager->DisableSecondaryLoop (); // TO KEEP |
---|
| 259 | ((QApplication*)interactorManager->GetMainInteractor())->exec(); |
---|
| 260 | // on ne passe pas le dessous ? FIXME ???? |
---|
| 261 | |
---|
| 262 | |
---|
| 263 | |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | |
---|
[484] | 267 | // void* event; // TO KEEP |
---|
| 268 | // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 269 | // interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 270 | // if(exitSession==true) break; // TO KEEP |
---|
| 271 | // } // TO KEEP |
---|
[496] | 272 | interactorManager->EnableSecondaryLoop (); // TO KEEP |
---|
| 273 | printf("enable secondary loop\n"); |
---|
[484] | 274 | return this; // TO KEEP |
---|
[481] | 275 | } |
---|
| 276 | /***************************************************************************/ |
---|
[494] | 277 | |
---|
[481] | 278 | /** |
---|
| 279 | Display the prompt in the prompt area |
---|
| 280 | */ |
---|
| 281 | void G4UIQt::Prompt ( |
---|
| 282 | G4String aPrompt |
---|
| 283 | ) |
---|
| 284 | /***************************************************************************/ |
---|
| 285 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 286 | { |
---|
[500] | 287 | fCommandLabel->setText((char*)aPrompt.data()); |
---|
[481] | 288 | } |
---|
| 289 | /***************************************************************************/ |
---|
| 290 | void G4UIQt::SessionTerminate ( |
---|
| 291 | ) |
---|
| 292 | /***************************************************************************/ |
---|
| 293 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 294 | { |
---|
| 295 | } |
---|
| 296 | /***************************************************************************/ |
---|
| 297 | void G4UIQt::PauseSessionStart ( |
---|
| 298 | G4String a_state |
---|
| 299 | ) |
---|
| 300 | /***************************************************************************/ |
---|
| 301 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 302 | { |
---|
[501] | 303 | printf("G4UIQt::PauseSessionStart\n"); |
---|
[484] | 304 | if(a_state=="G4_pause> ") { // TO KEEP |
---|
| 305 | SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP |
---|
| 306 | } // TO KEEP |
---|
[481] | 307 | |
---|
[484] | 308 | if(a_state=="EndOfEvent") { // TO KEEP |
---|
[481] | 309 | // Picking with feed back in event data Done here !!! |
---|
[484] | 310 | SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP |
---|
| 311 | } // TO KEEP |
---|
[481] | 312 | } |
---|
| 313 | /***************************************************************************/ |
---|
[484] | 314 | void G4UIQt::SecondaryLoop ( |
---|
[481] | 315 | G4String a_prompt |
---|
| 316 | ) |
---|
| 317 | /***************************************************************************/ |
---|
| 318 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 319 | { |
---|
[501] | 320 | printf("G4UIQt::SecondaryLoop\n"); |
---|
[484] | 321 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 322 | Prompt(a_prompt); // TO KEEP |
---|
| 323 | exitPause = false; // TO KEEP |
---|
| 324 | void* event; // TO KEEP |
---|
| 325 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 326 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 327 | if(exitPause==true) break; // TO KEEP |
---|
| 328 | } // TO KEEP |
---|
| 329 | Prompt("session"); // TO KEEP |
---|
[481] | 330 | } |
---|
| 331 | /***************************************************************************/ |
---|
| 332 | /** |
---|
| 333 | Receive a cout from Geant4. We have to display it in the cout zone |
---|
| 334 | */ |
---|
[484] | 335 | G4int G4UIQt::ReceiveG4cout ( |
---|
[481] | 336 | G4String a_string |
---|
| 337 | ) |
---|
| 338 | /***************************************************************************/ |
---|
| 339 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 340 | { |
---|
[500] | 341 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
| 342 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
[495] | 343 | return 0; |
---|
[481] | 344 | } |
---|
| 345 | /***************************************************************************/ |
---|
| 346 | /** |
---|
| 347 | Receive a cerr from Geant4. We have to display it in the cout zone |
---|
| 348 | */ |
---|
[484] | 349 | G4int G4UIQt::ReceiveG4cerr ( |
---|
[481] | 350 | G4String a_string |
---|
| 351 | ) |
---|
| 352 | /***************************************************************************/ |
---|
| 353 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 354 | { |
---|
[500] | 355 | QColor previousColor = fTextArea->textColor(); |
---|
| 356 | fTextArea->setTextColor(Qt::red); |
---|
| 357 | fTextArea->append(QString((char*)a_string.data()).trimmed()); |
---|
| 358 | fTextArea->setTextColor(previousColor); |
---|
[501] | 359 | fTextArea->verticalScrollBar()->setSliderPosition(fTextArea->verticalScrollBar()->maximum()); |
---|
[495] | 360 | return 0; |
---|
[481] | 361 | } |
---|
| 362 | /***************************************************************************/ |
---|
[484] | 363 | G4bool G4UIQt::GetHelpChoice( |
---|
[481] | 364 | G4int& aInt |
---|
| 365 | ) |
---|
| 366 | /***************************************************************************/ |
---|
| 367 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 368 | { |
---|
[501] | 369 | printf("G4UIQt::GetHelpChoice\n"); |
---|
| 370 | |
---|
| 371 | fHelp = true; // TO KEEP |
---|
[484] | 372 | // // SecondaryLoop : // TO KEEP |
---|
[501] | 373 | G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ? |
---|
| 374 | Prompt("Help"); // TO KEEP |
---|
| 375 | exitHelp = false; // TO KEEP |
---|
| 376 | void* event; // TO KEEP |
---|
| 377 | while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP |
---|
| 378 | interactorManager->DispatchEvent(event); // TO KEEP |
---|
| 379 | if(exitHelp==true) break; // TO KEEP |
---|
| 380 | } // TO KEEP |
---|
| 381 | Prompt("session"); // TO KEEP |
---|
| 382 | // // TO KEEP |
---|
| 383 | if(fHelp==false) return false; // TO KEEP |
---|
| 384 | aInt = fHelpChoice; // TO KEEP |
---|
| 385 | fHelp = false; // TO KEEP |
---|
| 386 | return true; // TO KEEP |
---|
[481] | 387 | } |
---|
| 388 | /***************************************************************************/ |
---|
[484] | 389 | void G4UIQt::ExitHelp( |
---|
[481] | 390 | ) |
---|
| 391 | /***************************************************************************/ |
---|
| 392 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 393 | { |
---|
[501] | 394 | printf("G4UIQt::ExitHelp\n"); |
---|
[481] | 395 | } |
---|
[501] | 396 | |
---|
[481] | 397 | /***************************************************************************/ |
---|
[484] | 398 | void G4UIQt::AddMenu ( |
---|
[481] | 399 | const char* a_name |
---|
| 400 | ,const char* a_label |
---|
| 401 | ) |
---|
| 402 | /***************************************************************************/ |
---|
| 403 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 404 | { |
---|
[501] | 405 | printf("G4UIQt::AddMenu %s %s\n",a_name,a_label); |
---|
| 406 | QString *name = new QString(a_name); |
---|
| 407 | QString *label = new QString(a_label); |
---|
| 408 | menuName.push_back(name); |
---|
| 409 | menuLabel.push_back(label); |
---|
| 410 | |
---|
| 411 | // QMenu *menu = new QMenu("test");//a_label); |
---|
| 412 | // fMainWindow->menuBar()->addMenu(menu); |
---|
| 413 | |
---|
[481] | 414 | // if(menuBar==NULL) return; |
---|
| 415 | // if(a_name==NULL) return; |
---|
| 416 | // if(a_label==NULL) return; |
---|
| 417 | // XtManageChild (menuBar); |
---|
| 418 | // // Pulldown menu : |
---|
| 419 | // Widget widget; |
---|
| 420 | // widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0); |
---|
| 421 | // AddInteractor (a_name,(G4Interactor)widget); |
---|
| 422 | // // Cascade button : |
---|
| 423 | // Arg args[2]; |
---|
| 424 | // XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET); |
---|
| 425 | // XtSetArg (args[0],XmNlabelString,cps); |
---|
| 426 | // XtSetArg (args[1],XmNsubMenuId,widget); |
---|
| 427 | // widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2); |
---|
| 428 | // XmStringFree (cps); |
---|
| 429 | // XtManageChild (widget); |
---|
| 430 | // ExecuteChangeSizeFunction(form); |
---|
| 431 | } |
---|
| 432 | /***************************************************************************/ |
---|
[484] | 433 | void G4UIQt::AddButton ( |
---|
[481] | 434 | const char* a_menu |
---|
| 435 | ,const char* a_label |
---|
| 436 | ,const char* a_command |
---|
| 437 | ) |
---|
| 438 | /***************************************************************************/ |
---|
| 439 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 440 | { |
---|
[501] | 441 | printf("G4UIQt::AddButton %s %s %s\n",a_menu,a_label,a_command); |
---|
[484] | 442 | // if(a_menu==NULL) return; // TO KEEP |
---|
| 443 | // if(a_label==NULL) return; // TO KEEP |
---|
| 444 | // if(a_command==NULL) return; // TO KEEP |
---|
[481] | 445 | // Widget parent = (Widget)GetInteractor(a_menu); |
---|
| 446 | // if(parent==NULL) return; |
---|
| 447 | // Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0); |
---|
| 448 | // XtManageChild (widget); |
---|
| 449 | // XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this); |
---|
| 450 | // commands[widget] = a_command; |
---|
[491] | 451 | } |
---|
[481] | 452 | // /***************************************************************************/ |
---|
| 453 | // G4String G4UIXm::GetCommand ( |
---|
| 454 | // Widget a_widget |
---|
| 455 | // ) |
---|
| 456 | // /***************************************************************************/ |
---|
| 457 | // /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
| 458 | // { |
---|
| 459 | // return commands[a_widget]; |
---|
| 460 | // } |
---|
| 461 | /***************************************************************************/ |
---|
| 462 | /***************************************************************************/ |
---|
| 463 | /***************************************************************************/ |
---|
[494] | 464 | |
---|
[481] | 465 | /** |
---|
[494] | 466 | Callback call when "enter" clicked on the command zone. |
---|
[481] | 467 | Send the command to geant4 |
---|
| 468 | */ |
---|
[484] | 469 | // TODO ! |
---|
[494] | 470 | void G4UIQt::commandEnteredCallback ( |
---|
| 471 | ) |
---|
[481] | 472 | /***************************************************************************/ |
---|
| 473 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
[494] | 474 | { |
---|
[500] | 475 | G4String command (fCommandArea->text().toStdString().c_str()); |
---|
| 476 | if (fCommandArea->text().toStdString().c_str() != "") { |
---|
| 477 | fCommandHistoryArea->append(fCommandArea->text()); |
---|
| 478 | if(fHelp==true) { |
---|
| 479 | exitHelp = true; |
---|
| 480 | fHelp = ConvertStringToInt(command.data(),fHelpChoice); |
---|
| 481 | } else { |
---|
| 482 | ApplyShellCommand (command,exitSession,exitPause); |
---|
| 483 | } |
---|
| 484 | } |
---|
| 485 | fCommandArea->setText(""); |
---|
[494] | 486 | } |
---|
[488] | 487 | |
---|
| 488 | /***************************************************************************/ |
---|
[491] | 489 | void G4UIQt::clearButtonCallback ( |
---|
| 490 | ) |
---|
[481] | 491 | /***************************************************************************/ |
---|
| 492 | /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/ |
---|
[491] | 493 | { |
---|
[499] | 494 | fTextArea->clear(); |
---|
[491] | 495 | } |
---|
| 496 | |
---|
[481] | 497 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 498 | G4bool ConvertStringToInt( |
---|
| 499 | const char* aString |
---|
| 500 | ,int& aInt |
---|
| 501 | ) |
---|
| 502 | ////////////////////////////////////////////////////////////////////////////// |
---|
| 503 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!// |
---|
| 504 | { |
---|
[484] | 505 | aInt = 0; // TO KEEP |
---|
| 506 | if(aString==NULL) return false; // TO KEEP |
---|
| 507 | char* s; // TO KEEP |
---|
| 508 | long value = strtol(aString,&s,10); // TO KEEP |
---|
| 509 | if(s==aString) return false; // TO KEEP |
---|
| 510 | aInt = value; // TO KEEP |
---|
| 511 | return true; // TO KEEP |
---|
[481] | 512 | } |
---|
| 513 | |
---|
| 514 | #endif |
---|