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

Last change on this file since 498 was 498, checked in by garnier, 18 years ago

r591@mac-90108: laurentgarnier | 2007-06-08 16:46:47 +0200
le layout est bon, mais les signaux ne marchent plus...

  • Property svn:mime-type set to text/cpp
File size: 20.2 KB
Line 
1// TODO !
2
3//
4// ********************************************************************
5// * License and Disclaimer *
6// * *
7// * The Geant4 software is copyright of the Copyright Holders of *
8// * the Geant4 Collaboration. It is provided under the terms and *
9// * conditions of the Geant4 Software License, included in the file *
10// * LICENSE and available at http://cern.ch/geant4/license . These *
11// * include a list of copyright holders. *
12// * *
13// * Neither the authors of this software system, nor their employing *
14// * institutes,nor the agencies providing financial support for this *
15// * work make any representation or warranty, express or implied, *
16// * regarding this software system or assume any liability for its *
17// * use. Please see the license in the file LICENSE and URL above *
18// * for the full disclaimer and the limitation of liability. *
19// * *
20// * This code implementation is the result of the scientific and *
21// * technical work of the GEANT4 collaboration. *
22// * By using, copying, modifying or distributing the software (or *
23// * any work based on the software) you agree to acknowledge its *
24// * use in resulting scientific publications, and indicate your *
25// * acceptance of all terms of the Geant4 Software license. *
26// ********************************************************************
27//
28//
29// $Id: G4UIQt.cc,v 1.14 2007/05/29 11:09:49 $
30// GEANT4 tag $Name: geant4-08-01 $
31//
32// L. Garnier
33
34//#define DEBUG
35
36#ifdef G4UI_BUILD_QT_SESSION
37
38#include "G4Types.hh"
39
40#include <string.h>
41
42#include "G4UIQt.hh"
43#include "G4UImanager.hh"
44#include "G4StateManager.hh"
45#include "G4UIcommandTree.hh"
46#include "G4UIcommandStatus.hh"
47
48#include "G4Qt.hh"
49
50#include <QtGui/qapplication.h>
51#include <QtGui/qwidget.h>
52#include <QtGui/qmenu.h>
53#include <QtGui/qmenubar.h>
54#include <QtGui/qboxlayout.h>
55#include <QtGui/qpushbutton.h>
56#include <QtGui/qlabel.h>
57#include <QtGui/qsplitter.h>
58#include <QtGui/qlistview.h> // en test
59#include <QtGui/qtreeview.h> // en test
60
61#include <stdlib.h>
62
63static G4bool ConvertStringToInt(const char*,int&);
64//static void ExecuteChangeSizeFunction(Widget);
65
66static G4bool exitSession = true;
67static G4bool exitPause = true;
68static G4bool exitHelp = true;
69/***************************************************************************/
70/**
71 Build a Qt window with a menubar, output area and promt area
72 +-----------------------+
73 |exit menu| |
74 | |
75 | +-------------------+ |
76 | | | |
77 | | Output area | |
78 | | | |
79 | +-------------------+ |
80 | | clear | |
81 | +-------------------+ |
82 | | promt history | |
83 | +-------------------+ |
84 | +-------------------+ |
85 | |> promt area | |
86 | +-------------------+ |
87 +-----------------------+
88*/
89
90G4UIQt::G4UIQt (
91 int argc,
92 char** argv
93)
94/***************************************************************************/
95/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
96{
97 G4Qt* interactorManager = G4Qt::getInstance ();
98 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
99 if(UI!=NULL) UI->SetSession(this); // TO KEEP
100
101 fMainWindow = new QMainWindow();
102 fMainWindow->setWindowTitle( "G4UI Session" );
103
104
105 /*
106 QSplitter *splitter = new QSplitter(Qt::Vertical,central);
107 splitter->setMaximumSize(800,800);
108 QListView *listview = new QListView;
109 listview->setMaximumSize(800,800);
110 QTreeView *treeview = new QTreeView;
111 treeview->setMaximumSize(800,800);
112 */
113 QSplitter *splitter = new QSplitter(Qt::Vertical);
114 fTextArea = new QTextEdit();
115 QPushButton *clearButton = new QPushButton("clear");
116 connect(clearButton, SIGNAL(clicked()), SLOT(clearButtonCallback()));
117
118 fCommandHistoryArea = new QTextEdit();
119 fCommandLabel = new QLabel();
120
121 fCommandArea = new QLineEdit();
122 connect(fCommandArea, SIGNAL(returnPressed()), SLOT(commandEnteredCallback()));
123
124 fTextArea->setReadOnly(true);
125 fCommandHistoryArea->setReadOnly(true);
126
127
128 QVBoxLayout *layoutSplitter = new QVBoxLayout;
129
130 QWidget* topWidget = new QWidget();
131 QVBoxLayout *layoutTop = new QVBoxLayout;
132
133 QWidget* bottomWidget = new QWidget();
134 QVBoxLayout *layoutBottom = new QVBoxLayout;
135
136
137 layoutTop->addWidget(fTextArea);
138 layoutTop->addWidget(clearButton);
139 topWidget->setLayout(layoutTop);
140
141 layoutBottom->addWidget(fCommandHistoryArea);
142 layoutBottom->addWidget(fCommandLabel);
143 layoutBottom->addWidget(fCommandArea);
144 bottomWidget->setLayout(layoutBottom);
145
146
147 layoutSplitter->addWidget(topWidget);
148 layoutSplitter->addWidget(bottomWidget);
149 splitter->setLayout(layoutSplitter);
150
151 fMainWindow->setCentralWidget(splitter);
152
153
154 // QMenu *menuFile = new QMenu("File");
155 // fMainWindow->menuBar()->addMenu(menuFile);
156
157
158
159// QMainWindow top = (QMainWindow)interactorManager->GetMainInteractor();
160
161// if(getenv("XENVIRONMENT")==NULL) {
162// XrmDatabase database = XrmGetDatabase(XtDisplay(top));
163// if(database!=NULL) {
164// XrmPutLineResource(&database,"*topShadowColor:white");
165// XrmPutLineResource(&database,"*bottomShadowColor:black");
166// XrmPutLineResource(&database,"*foreground:black");
167// XrmPutLineResource(&database,"*background:lightgrey");
168// XrmPutLineResource(&database,"*borderColor:lightgrey");
169// XrmPutLineResource(&database,"*fontList:-*-helvetica-bold-r-*-*-*-120-*-*-*-*-iso8859-1");
170// XrmPutLineResource(&database,"*text.background:white");
171// XrmPutLineResource(&database,"*text.fontList:*courier*-r-*--14-*");
172// XrmPutLineResource(&database,"*text.maxLength:8000");
173// }
174// }
175
176// Arg args[9];
177// XtSetArg(args[0],XmNkeyboardFocusPolicy,XmPOINTER); // For completion.
178// shell = XtAppCreateShell ("G4UIXm","G4UIXm",
179// topLevelShellWidgetClass,XtDisplay(top),
180// args,1);
181// form = XmCreateForm (shell,(char*)"form",NULL,0);
182// XtManageChild (form);
183
184// XtSetArg(args[0],XmNtopAttachment ,XmATTACH_FORM);
185// XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
186// XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
187// menuBar = XmCreateMenuBar (form,(char*)"menuBar",args,3);
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_FORM);
193// command = XmCreateCommand (form,(char*)"command",args,4);
194// XtManageChild (command);
195
196// XtSetArg(args[0],XmNtopAttachment ,XmATTACH_NONE);
197// XtSetArg(args[1],XmNleftAttachment ,XmATTACH_FORM);
198// XtSetArg(args[2],XmNrightAttachment ,XmATTACH_FORM);
199// XtSetArg(args[3],XmNbottomAttachment,XmATTACH_WIDGET);
200// XtSetArg(args[4],XmNbottomWidget ,command);
201// XmString cps = XmStringLtoRCreate((char*)"Clear",XmSTRING_DEFAULT_CHARSET);
202// XtSetArg (args[5],XmNlabelString,cps);
203// Widget clearButton = XmCreatePushButton(form,(char*)"clearButton",args,6);
204// XmStringFree (cps);
205// XtManageChild (clearButton);
206
207// XtSetArg(args[0],XmNtopAttachment ,XmATTACH_WIDGET);
208// XtSetArg(args[1],XmNtopWidget ,menuBar);
209// XtSetArg(args[2],XmNleftAttachment ,XmATTACH_FORM);
210// XtSetArg(args[3],XmNrightAttachment ,XmATTACH_FORM);
211// XtSetArg(args[4],XmNbottomAttachment,XmATTACH_WIDGET);
212// XtSetArg(args[5],XmNbottomWidget ,clearButton);
213// XtSetArg(args[6],XmNeditMode ,XmMULTI_LINE_EDIT);
214// XtSetArg(args[7],XmNrows ,12);
215// XtSetArg(args[8],XmNcolumns ,80);
216// text = XmCreateSGcrolledText (form,(char*)"text",args,9);
217// XtManageChild (text);
218
219// XtAddCallback(clearButton,XmNactivateCallback,
220// clearButtonCallback,(XtPointer)text);
221// XtAddCallback(command,XmNcommandEnteredCallback,
222// commandEnteredCallback,(XtPointer)this);
223
224// Widget commandText = XmCommandGetChild(command,XmDIALOG_COMMAND_TEXT);
225// XtAddEventHandler(commandText,KeyPressMask,False,keyHandler,(XtPointer)this);
226
227// XtRealizeWidget(shell);
228// XtMapWidget(shell);
229
230 if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
231}
232/***************************************************************************/
233G4UIQt::~G4UIQt(
234)
235/***************************************************************************/
236/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
237{
238 G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
239 if(UI!=NULL) { // TO KEEP
240 UI->SetSession(NULL); // TO KEEP
241 UI->SetCoutDestination(NULL); // TO KEEP
242 }
243
244
245 if (fMainWindow!=NULL)
246 delete fMainWindow;
247}
248/***************************************************************************/
249/*
250 Start the Qt main loop
251 */
252G4UIsession* G4UIQt::SessionStart (
253)
254/***************************************************************************/
255/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
256{
257
258 G4Qt* interactorManager = G4Qt::getInstance ();
259 fMainWindow->show();
260 Prompt("session");
261 exitSession = false;
262
263
264 printf("disable secondary loop\n");
265 interactorManager->DisableSecondaryLoop (); // TO KEEP
266 ((QApplication*)interactorManager->GetMainInteractor())->exec();
267 // on ne passe pas le dessous ? FIXME ????
268
269
270
271
272
273
274// void* event; // TO KEEP
275// while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
276// interactorManager->DispatchEvent(event); // TO KEEP
277// if(exitSession==true) break; // TO KEEP
278// } // TO KEEP
279 interactorManager->EnableSecondaryLoop (); // TO KEEP
280 printf("enable secondary loop\n");
281 return this; // TO KEEP
282}
283/***************************************************************************/
284
285/**
286 Display the prompt in the prompt area
287 */
288void G4UIQt::Prompt (
289 G4String aPrompt
290)
291/***************************************************************************/
292/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
293{
294 // fCommandLabel->setText((char*)aPrompt.data());
295}
296/***************************************************************************/
297void G4UIQt::SessionTerminate (
298)
299/***************************************************************************/
300/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
301{
302}
303/***************************************************************************/
304void G4UIQt::PauseSessionStart (
305 G4String a_state
306)
307/***************************************************************************/
308/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
309{
310 if(a_state=="G4_pause> ") { // TO KEEP
311 SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
312 } // TO KEEP
313
314 if(a_state=="EndOfEvent") { // TO KEEP
315 // Picking with feed back in event data Done here !!!
316 SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
317 } // TO KEEP
318}
319/***************************************************************************/
320void G4UIQt::SecondaryLoop (
321 G4String a_prompt
322)
323/***************************************************************************/
324/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
325{
326 G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
327 Prompt(a_prompt); // TO KEEP
328 exitPause = false; // TO KEEP
329 void* event; // TO KEEP
330 while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
331 interactorManager->DispatchEvent(event); // TO KEEP
332 if(exitPause==true) break; // TO KEEP
333 } // TO KEEP
334 Prompt("session"); // TO KEEP
335}
336/***************************************************************************/
337/**
338 Receive a cout from Geant4. We have to display it in the cout zone
339 */
340G4int G4UIQt::ReceiveG4cout (
341 G4String a_string
342)
343/***************************************************************************/
344/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
345{
346 // fTextArea->append((char*)a_string.data());
347 return 0;
348}
349/***************************************************************************/
350/**
351 Receive a cerr from Geant4. We have to display it in the cout zone
352 */
353G4int G4UIQt::ReceiveG4cerr (
354 G4String a_string
355)
356/***************************************************************************/
357/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
358{
359 // fTextArea->append((char*)a_string.data());
360 return 0;
361}
362/***************************************************************************/
363G4bool G4UIQt::GetHelpChoice(
364 G4int& aInt
365)
366/***************************************************************************/
367/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
368{
369// fHelp = true; // TO KEEP
370// // SecondaryLoop : // TO KEEP
371// G4Qt* interactorManager = G4Qt::getInstance (); // TO KEEP ?
372// Prompt("Help"); // TO KEEP
373// exitHelp = false; // TO KEEP
374// void* event; // TO KEEP
375// while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
376// interactorManager->DispatchEvent(event); // TO KEEP
377// if(exitHelp==true) break; // TO KEEP
378// } // TO KEEP
379// Prompt("session"); // TO KEEP
380// // // TO KEEP
381// if(fHelp==false) return false; // TO KEEP
382// aInt = fHelpChoice; // TO KEEP
383// fHelp = false; // TO KEEP
384// return true; // TO KEEP
385}
386/***************************************************************************/
387void G4UIQt::ExitHelp(
388)
389/***************************************************************************/
390/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
391{
392}
393/***************************************************************************/
394void G4UIQt::AddMenu (
395 const char* a_name
396,const char* a_label
397)
398/***************************************************************************/
399/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
400{
401// if(menuBar==NULL) return;
402// if(a_name==NULL) return;
403// if(a_label==NULL) return;
404// XtManageChild (menuBar);
405// // Pulldown menu :
406// Widget widget;
407// widget = XmCreatePulldownMenu (menuBar,(char*)a_name,NULL,0);
408// AddInteractor (a_name,(G4Interactor)widget);
409// // Cascade button :
410// Arg args[2];
411// XmString cps = XmStringLtoRCreate((char*)a_label,XmSTRING_DEFAULT_CHARSET);
412// XtSetArg (args[0],XmNlabelString,cps);
413// XtSetArg (args[1],XmNsubMenuId,widget);
414// widget = XmCreateCascadeButton (menuBar,(char*)a_name,args,2);
415// XmStringFree (cps);
416// XtManageChild (widget);
417// ExecuteChangeSizeFunction(form);
418}
419/***************************************************************************/
420void G4UIQt::AddButton (
421 const char* a_menu
422,const char* a_label
423,const char* a_command
424)
425/***************************************************************************/
426/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
427{
428// if(a_menu==NULL) return; // TO KEEP
429// if(a_label==NULL) return; // TO KEEP
430// if(a_command==NULL) return; // TO KEEP
431// Widget parent = (Widget)GetInteractor(a_menu);
432// if(parent==NULL) return;
433// Widget widget = XmCreatePushButton(parent,(char*)a_label,NULL,0);
434// XtManageChild (widget);
435// XtAddCallback (widget,XmNactivateCallback,ButtonCallback,(XtPointer)this);
436// commands[widget] = a_command;
437}
438// /***************************************************************************/
439// G4String G4UIXm::GetCommand (
440// Widget a_widget
441// )
442// /***************************************************************************/
443// /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
444// {
445// return commands[a_widget];
446// }
447/***************************************************************************/
448/***************************************************************************/
449/***************************************************************************/
450
451/**
452 Callback call when "enter" clicked on the command zone.
453 Send the command to geant4
454 */
455// TODO !
456void G4UIQt::commandEnteredCallback (
457)
458/***************************************************************************/
459/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
460{
461 /* fCommandHistoryArea->append(fCommandArea->text());
462 G4String command (fCommandArea->text().toStdString().c_str());
463 if(fHelp==true) {
464 exitHelp = true;
465 fHelp = ConvertStringToInt(command.data(),fHelpChoice);
466 } else {
467 ApplyShellCommand (command,exitSession,exitPause);
468 }
469 fCommandArea->setText("");
470 */
471}
472// /***************************************************************************/
473// void G4UIXm::keyHandler (
474// Widget a_widget
475// ,XtPointer a_tag
476// ,XEvent* a_event
477// ,Boolean*
478// )
479// /***************************************************************************/
480// /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
481// {
482// KeySym keySym;
483// XLookupString(&(a_event->xkey),NULL,0,&keySym,NULL);
484// if(keySym!=XK_Tab) return;
485// G4UIXm* This = (G4UIXm*)a_tag;
486// char* s = XmTextGetString(a_widget);
487// G4String ss = This->Complete(s);
488// XmTextSetString(a_widget,(char*)ss.data());
489// XtFree(s);
490// XmTextSetInsertionPosition(a_widget,XmTextGetLastPosition(a_widget));
491//}
492
493 /***************************************************************************/
494void G4UIQt::clearButtonCallback (
495)
496/***************************************************************************/
497/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
498{
499 // fTextArea->clear();
500}
501
502/***************************************************************************/
503// TODO !
504//void G4UIQt::ButtonCallback (
505// Widget a_widget
506//,XtPointer a_tag
507//,XtPointer
508//)
509/***************************************************************************/
510/*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
511//{
512// G4UIXm* This = (G4UIXm*)a_tag;
513// if(This->fHelp==true) return; // Disabled when in help.
514// G4String ss = This->GetCommand (a_widget);
515// //printf ("debug : execute:\n%s\n",ss.data());
516// This->ApplyShellCommand(ss,exitSession,exitPause);
517//}
518/***************************************************************************/
519/***************************************************************************/
520/***************************************************************************/
521// char* XmConvertCompoundStringToString (
522// XmString a_cps
523// ,int a_number
524// )
525// /***************************************************************************/
526// /*!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!*/
527// {
528// if(a_cps==NULL) return NULL;
529// char* ss = NULL;
530// XmStringContext context;
531// XmStringInitContext(&context,a_cps);
532// int icount = 0;
533// Boolean Done = False;
534// while(Done==False) {
535// char* text = NULL;
536// XmStringCharSet charset = NULL;
537// XmStringDirection direct;
538// Boolean sep;
539// if(XmStringGetNextSegment(context,&text,&charset,&direct,&sep)==True) {
540// XtFree(charset);
541// if(sep==True) Done = True;
542// if(icount==a_number) {
543// ss = text;
544// break;
545// }
546// icount++;
547// XtFree(text);
548// }
549// else
550// Done = True;
551// }
552// XmStringFreeContext(context);
553// return ss;
554//}
555//////////////////////////////////////////////////////////////////////////////
556G4bool ConvertStringToInt(
557 const char* aString
558,int& aInt
559)
560//////////////////////////////////////////////////////////////////////////////
561//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
562{
563 aInt = 0; // TO KEEP
564 if(aString==NULL) return false; // TO KEEP
565 char* s; // TO KEEP
566 long value = strtol(aString,&s,10); // TO KEEP
567 if(s==aString) return false; // TO KEEP
568 aInt = value; // TO KEEP
569 return true; // TO KEEP
570}
571#include <X11/IntrinsicP.h>
572//////////////////////////////////////////////////////////////////////////////
573// void ExecuteChangeSizeFunction (
574// Widget aWidget
575// )
576// //////////////////////////////////////////////////////////////////////////////
577// //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
578// {
579// if(aWidget==NULL) return;
580// if(aWidget->core.widget_class->core_class.resize==NULL) return;
581// (aWidget->core.widget_class->core_class.resize)(aWidget);
582// }
583
584
585#endif
Note: See TracBrowser for help on using the repository browser.