Geant4  10.01
G4UIWt.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4UIWt.cc,v 1.53 2010-11-02 15:38:51 lgarnier Exp $
28 //
29 // L. Garnier
30 
31 #ifdef G4UI_BUILD_WT_SESSION
32 
33 
34 #include <string.h>
35 
36 #include "G4UIWt.hh"
37 #include "G4UImanager.hh"
38 #include "G4StateManager.hh"
39 #include "G4UIcommandTree.hh"
40 
41 #include "G4Wt.hh"
42 
43 #include <Wt/WLabel>
44 #include <Wt/WLineEdit>
45 #include <Wt/WTextArea>
46 #include <Wt/WMessageBox>
47 #include <Wt/WLayout>
48 #include <Wt/WRadioButton>
49 #include <Wt/WButtonGroup>
50 #include <Wt/WComboBox>
51 #include <Wt/WVBoxLayout>
52 #include <Wt/WHBoxLayout>
53 #include <Wt/WGridLayout>
54 #include <Wt/WPanel>
55 #include <Wt/WSelectionBox>
56 #include <Wt/WLength>
57 
58 #define G4DEBUG_INTERFACES_BASIC 1
59 
60 // Pourquoi Static et non variables de classe ?
61 static G4bool exitSession = true;
62 static G4bool exitPause = true;
63 
84 G4UIWt::G4UIWt (
85  int argc
86 ,char** argv
87 )
88 :fMainWindow(NULL)
89 ,fCommandLabel(NULL)
90 ,fCommandArea(NULL)
91 ,fCoutTBTextArea(NULL)
92 ,fHelpArea(NULL)
93 ,fUITabWidget(NULL)
94 ,fG4cout()
95 ,fCoutFilter(NULL)
96 ,fHistoryTBTableList(NULL)
97 ,fHelpTreeWidget(NULL)
98 ,fHelpTBWidget(NULL)
99 ,fHistoryTBWidget(NULL)
100 ,fCoutTBWidget(NULL)
101 ,fSceneTreeComponentsTBWidget(NULL)
102 ,fHelpLine(NULL)
103 ,fViewerTabWidget(NULL)
104 ,fCoutText("Output")
105 ,fEmptyViewerTabLabel(NULL)
106 ,fMainSplitterWidget(NULL)
107 ,fRightSplitterWidget(NULL)
108 ,fHelpVSplitter(NULL)
109 ,fToolbarApp(NULL)
110 ,fToolbarUser(NULL)
111 ,fStringSeparator("__$$$@%%###__")
112 ,fLastOpenPath("")
113 ,fMoveSelected(false)
114 ,fRotateSelected(true)
115 ,fPickSelected(false)
116 ,fZoomInSelected(false)
117 ,fZoomOutSelected(false)
118 ,fExitSession(true)
119 ,fExitPause(true)
120 
121 {
122 
123  G4Wt* interactorManager = G4Wt::getInstance (argc,argv,(char*)"Wt");
124  if (!(Wt::WApplication*)interactorManager->GetMainInteractor()) {
125  G4UImanager* UImanager = G4UImanager::GetUIpointer();
126  G4int verbose = UImanager->GetVerboseLevel();
127 
128  if (verbose >= 2) {
129  G4cout << "G4UIWt : Unable to init Wt. Aborted" << G4endl;
130  }
131  }
132 
134  if(UI!=NULL) UI->SetSession(this);
135  if(UI!=NULL) UI->SetG4UIWindow(this);
136 
137  fMainWindow = new Wt::WContainerWidget(wApp->root());
138 
139  // resize to a big size in order to gave space for the viewer
140  Wt::WVBoxLayout* mainWindowVLayout = new Wt::WVBoxLayout();
141  fMainWindow->setLayout(mainWindowVLayout);
142 
143 
144 #ifdef G4DEBUG_INTERFACES_BASIC
145  printf("G4UIWt::Initialise after main window creation +++++++++++\n");
146 #endif
147 
148 
149  // the splitter
150  fMainSplitterWidget = new Wt::WContainerWidget();
151  Wt::WGridLayout* fMainSplitterWidgetLayout = new Wt::WGridLayout();
152 
153 
154  fMainSplitterWidgetLayout->addWidget(CreateLeftSplitterWidget(),1,1);
155  fMainSplitterWidgetLayout->addWidget(CreateRightSplitterWidget(),1,2);
156  fMainSplitterWidgetLayout->setColumnResizable (1,true,Wt::WLength(30,Wt::WLength::Percentage));
157 
158  // create vis tab widget
159 // Wt::WTabWidget* tabWidget = new Wt::WTabWidget();
160 
161 
162  fMainSplitterWidget->setLayout(fMainSplitterWidgetLayout);
163  mainWindowVLayout->addWidget(fMainSplitterWidget);
164 
165 
166 
167 #ifdef G4DEBUG_INTERFACES_BASIC
168  printf("G4UIWt::G4UIWt :: 5\n");
169 #endif
170 
171 
172  if(UI!=NULL) UI->SetCoutDestination(this); // TO KEEP
173 
174  wApp->setTitle("Wt application");
175 
176  // Set not visible until session start
177  fMainWindow->hide();
178 }
179 
180 
181 
182 G4UIWt::~G4UIWt(
183 )
184 {
185 #ifdef G4DEBUG_INTERFACES_BASIC
186  printf("G4UIWt::~G4UIWt Delete\n");
187 #endif
188  G4UImanager* UI = G4UImanager::GetUIpointer(); // TO KEEP
189  if(UI!=NULL) { // TO KEEP
190  UI->SetSession(NULL); // TO KEEP
191  UI->SetG4UIWindow(NULL);
192  UI->SetCoutDestination(NULL); // TO KEEP
193  }
194 
195  if (fMainWindow!=NULL) {
196 #ifdef G4DEBUG_INTERFACES_BASIC
197  printf("G4UIWt::~G4UIWt DELETE fMainWindow\n");
198 #endif
199  delete fMainWindow;
200  }
201 }
202 
205 Wt::WWidget* G4UIWt::CreateHistoryTBWidget(
206 )
207 {
208  fHistoryTBWidget = new Wt::WPanel();
209  fHistoryTBWidget->setCollapsed(true);
210  fHistoryTBWidget->setCollapsible(true);
211 
212  fHistoryTBTableList = new Wt::WSelectionBox();
213  fHistoryTBTableList->setSelectionMode(Wt::SingleSelection);
214  fHistoryTBTableList->changed().connect(this,&G4UIWt::CommandHistoryCallback);
215 
216  fHistoryTBWidget->setCentralWidget(fHistoryTBTableList);
217  return fHistoryTBWidget;
218 }
219 
220 
223 Wt::WWidget* G4UIWt::CreateHelpTBWidget(
224 )
225 {
226  fHelpTBWidget = new Wt::WPanel();
227  fHelpTBWidget->setCollapsible(true);
228 
229  Wt::WContainerWidget *helpWidget = new Wt::WContainerWidget();
230  Wt::WHBoxLayout *helpLayout = new Wt::WHBoxLayout();
231  Wt::WVBoxLayout *vLayout = new Wt::WVBoxLayout();
232 
233  fHelpVSplitter = new Wt::WContainerWidget();
234  fHelpVSplitter->setLayout(new Wt::WHBoxLayout());
235 
236  Wt::WVBoxLayout* VHelpSplitterVLayout = new Wt::WVBoxLayout();
237  fHelpVSplitter->setLayout(VHelpSplitterVLayout);
238 
239 
240  fHelpLine = new Wt::WLineEdit();
241  fHelpTBWidget->setCentralWidget(helpWidget);
242  helpWidget->setLayout(helpLayout);
243  helpWidget->layout()->addWidget(new Wt::WLabel(Wt::WString("Search :")));
244  helpWidget->layout()->addWidget(fHelpLine);
245  printf("*** G4UIWt::CreateHelpTBWidget, missing EnterPress connection\n");
246  // fHelpLine->enterPressed().connect(this, &G4UIWt::LookForHelpStringCallback );
247 
248  // Create Help tree
249  FillHelpTree();
250 
251  fHelpArea = new Wt::WTextArea(fHelpVSplitter);
252  fHelpArea->setReadOnly(true);
253 
254  // Set layouts
255 
256  if (fHelpTreeWidget) {
257  fHelpVSplitter->addWidget(fHelpTreeWidget);
258  }
259  fHelpVSplitter->addWidget(fHelpArea);
260 
261  vLayout->addWidget(helpWidget);
262  vLayout->addWidget(fHelpVSplitter,1);
263 
264  // ((Wt::WPanel*) fHelpTBWidget)->setMinimumSize(50,50);
265  // fHelpTBWidget->setSizePolicy (WSizePolicy(WSizePolicy::Minimum,WSizePolicy::Minimum));
266  // set the splitter size
267  // Wt::WList<int> list;
268  // list.append( 50 );
269  // list.append( 50 );
270  // fHelpVSplitter->setSizes(list);
271 
272  return fHelpTBWidget;
273 }
274 
275 
278 Wt::WWidget* G4UIWt::CreateCoutTBWidget(
279 )
280 {
281  fCoutTBWidget = new Wt::WPanel();
282  fCoutTBWidget->setCollapsible(true);
283  fCoutTBWidget->setTitle("Output");
284  fCoutTBWidget->setCollapsed(false);
285 
286  Wt::WContainerWidget* myContainer = new Wt::WContainerWidget();
287  Wt::WVBoxLayout *myContainerVLayout = new Wt::WVBoxLayout();
288  myContainer->setLayout(myContainerVLayout);
289 
290  // Could have been created if any err ou cout *before* sessionStart()
291  if (!fCoutTBTextArea) {
292  fCoutTBTextArea = new Wt::WTextArea(myContainer);
293  }
294  fCoutFilter = new Wt::WLineEdit();
295  Wt::WLabel* coutFilterLabel = new Wt::WLabel("Filter : ");
296  myContainerVLayout->addWidget(fCoutTBTextArea);
297  myContainerVLayout->addWidget(fCoutFilter);
298  myContainerVLayout->addWidget(coutFilterLabel);
299 
300  Wt::WPushButton *coutTBClearButton = new Wt::WPushButton ("clear",myContainer);
301 
302  // fCoutFilter->changed().connect(this, (&G4UIWt::CoutFilterCallback));
303 
304  // SIGNAL/SLOT connection
305  // To be implemented
306 
307  fCoutTBTextArea->setReadOnly(true);
308 
309  Wt::WContainerWidget* coutButtonWidget = new Wt::WContainerWidget(myContainer);
310  Wt::WHBoxLayout* layoutCoutTBButtons = new Wt::WHBoxLayout(coutButtonWidget);
311  layoutCoutTBButtons->addWidget(coutTBClearButton);
312  layoutCoutTBButtons->addWidget(coutFilterLabel);
313  layoutCoutTBButtons->addWidget(fCoutFilter);
314 
315  myContainerVLayout->addWidget(coutButtonWidget);
316 
317  fCoutTBWidget->setCentralWidget(myContainer);
318 
319  return fCoutTBWidget;
320 }
321 
322 
325 Wt::WContainerWidget* G4UIWt::CreateVisParametersTBWidget(
326 )
327 {
328  return NULL;
329 }
330 
331 
334 Wt::WWidget* G4UIWt::CreateUITabWidget(
335 )
336 {
337  fUITabWidget = new Wt::WTabWidget();
338 
339  // the right splitter
340  fUITabWidget->addTab(CreateSceneTreeComponentsTBWidget(),"Scene tree");
341  fUITabWidget->addTab(CreateHelpTBWidget(),"Help");
342  fUITabWidget->addTab(CreateHistoryTBWidget(),"History");
343  // fUITabWidget->setCurrentWidget(fSceneTreeComponentsTBWidget);
344 
345  // SIGNAL/SLOT connection
346  // To be implemented
347 
348 
349  return fUITabWidget;
350 }
351 
352 
353 Wt::WWidget* G4UIWt::CreateSceneTreeComponentsTBWidget(){
354 
355  fSceneTreeComponentsTBWidget = new Wt::WTabWidget();
356 
357  fSceneTreeComponentsTBWidget->hide();
358 
359  return fSceneTreeComponentsTBWidget;
360 }
361 
362 
363 Wt::WContainerWidget* G4UIWt::CreateLeftSplitterWidget(){
364 
365  fLeftSplitterWidget = new Wt::WContainerWidget();
366  Wt::WVBoxLayout * layoutLeftSplitterWidget = new Wt::WVBoxLayout();
367  fLeftSplitterWidget->setLayout(layoutLeftSplitterWidget);
368 
369  layoutLeftSplitterWidget->addWidget(CreateUITabWidget());
370 
371  return fLeftSplitterWidget;
372 }
373 
374 
375 Wt::WContainerWidget* G4UIWt::CreateRightSplitterWidget(){
376 
377  fRightSplitterWidget = new Wt::WContainerWidget();
378 
379  // Set layouts
380  Wt::WVBoxLayout* VSplitterVLayout = new Wt::WVBoxLayout();
381  fRightSplitterWidget->setLayout(VSplitterVLayout);
382  Wt::WContainerWidget* commandLineWidget = new Wt::WContainerWidget();
383 
384  Wt::WHBoxLayout *layoutCommandLine = new Wt::WHBoxLayout();
385  commandLineWidget->setLayout(layoutCommandLine);
386 
387  // fill them
388 
389  fCommandLabel = new Wt::WLabel("",commandLineWidget);
390  fCommandArea = new Wt::WLineEdit(commandLineWidget);
391  fCommandArea->setToolTip("Apply command");
392 
393 
394  layoutCommandLine->addWidget(fCommandLabel);
395  layoutCommandLine->addWidget(fCommandArea);
396 
397 
398  fViewerTabWidget = new G4WTabWidget(fRightSplitterWidget);
399 
400  fViewerTabWidget->tabClosed().connect(this, &G4UIWt::TabCloseCallback);
401 
402  fViewerTabWidget->currentChanged().connect(this,&G4UIWt::CurrentChangedTabWidgetCallback);
403 
404 
405  fEmptyViewerTabLabel = new Wt::WLabel(" If you want to have a Viewer, please use /vis/open commands. ");
406 
407  // UI Specific fonctions
408  fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
409  fRightSplitterWidget->layout()->addWidget(fEmptyViewerTabLabel);
410  fRightSplitterWidget->layout()->addWidget(CreateCoutTBWidget());
411  fRightSplitterWidget->layout()->addWidget(commandLineWidget);
412 
413  commandLineWidget->setMinimumSize(50,50);
414 
415  // Connect signal
416  fCommandArea->enterPressed().connect(this,&G4UIWt::CommandEnteredCallback);
417 
418  return fRightSplitterWidget;
419 }
420 
421 
424 Wt::WTabWidget* G4UIWt::GetSceneTreeComponentsTBWidget(
425 )
426 {
427  return fSceneTreeComponentsTBWidget;
428 }
429 
430 
434 bool G4UIWt::AddTabWidget(
435  Wt::WWidget* aWidget
436  ,Wt::WString name
437  ,int /* width */
438  ,int /* height */
439  )
440 {
441 /*
442  if (fViewerTabWidget == NULL) {
443 #ifdef G4DEBUG_INTERFACES_BASIC
444  printf("G4UIWt::AddTabWidget +++++\n");
445 #endif
446 
447  fViewerTabWidget = new G4WTabWidget(fRightSplitterWidget);
448 
449  fViewerTabWidget->tabClosed().connect(this, &G4UIWt::TabCloseCallback);
450 
451  fViewerTabWidget->currentChanged().connect(this,&G4UIWt::CurrentChangedTabWidgetCallback);
452  fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
453 // fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
454 
455  }
456 */
457  if (!fViewerTabWidget->isVisible() ) {
458  if ( fRightSplitterWidget->isVisible()) {
459  fRightSplitterWidget->setHidden(true);
460  fEmptyViewerTabLabel->setHidden(true);
461  }
462 #ifdef G4DEBUG_INTERFACES_BASIC
463  printf("G4UIWt::AddTabWidget +++++\n");
464 #endif
465  fViewerTabWidget->show();
466  fViewerTabWidget = new G4WTabWidget(fRightSplitterWidget);
467 
468  fViewerTabWidget->tabClosed().connect(this, &G4UIWt::TabCloseCallback);
469 
470  fViewerTabWidget->currentChanged().connect(this,&G4UIWt::CurrentChangedTabWidgetCallback);
471  fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
472  // fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
473 
474  }
475 
476 
477  if (!aWidget) {
478  return false;
479  }
480 
481  // Remove Wt::WLabel
482 
483  // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
484  // troubles
485 
486 
487  // Problems with resize. The widgets are not realy drawn at this step,
488  // then we have to force them on order to check the size
489 
490 // aWidget->resize(width,height);
491 // aWidget->resize(600,600);
492 // fViewerTabWidget->resize(620,621);
493  fViewerTabWidget->addTab(new Wt::WLabel("test"),"test1");
494  fViewerTabWidget->addTab(aWidget,name);
495  fViewerTabWidget->addTab(new Wt::WLabel("test"),"test2");
496 
497  // Change Color
498  aWidget->decorationStyle().setBackgroundColor (Wt::WColor(245,245,245));
499 
500  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
501 
502  // Set visible
503  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
504 
505  return true;
506 }
507 
508 
509 
510 void G4UIWt::CurrentChangedTabWidgetCallback(int tabNumber) {
511 #ifdef G4DEBUG_INTERFACES_BASIC
512  printf("G4UIWt::CurrentChangedTabWidget %d\n",tabNumber);
513 #endif
514  if ( fViewerTabWidget == NULL) {
515  fViewerTabWidget = new G4WTabWidget;
516  }
517 
518 #ifdef G4DEBUG_INTERFACES_BASIC
519  printf("G4UIWt::CurrentChangedTabWidget CALL REPAINT tabGL\n");
520 #endif
521 
522  fViewerTabWidget->setCurrentIndex(tabNumber);
523 
524  // Send this signal to unblock graphic updates !
525  fViewerTabWidget->setTabSelected(false);
526 
527  fViewerTabWidget->show();
528 
529  // This will send a paintEvent to OGL Viewers
530  fViewerTabWidget->setTabSelected(true);
531 
532 
533  Wt::WString text = fViewerTabWidget->tabText (tabNumber);
534 
535  Wt::WString paramSelect = Wt::WString("/vis/viewer/select ")+text;
537  if(UI != NULL) {
538  UI->ApplyCommand(paramSelect.toUTF8().c_str());
539  }
540 }
541 
542 
545 G4UIsession* G4UIWt::SessionStart (
546 )
547 {
548 #ifdef G4DEBUG_INTERFACES_BASIC
549  printf("G4UIWt::G4UIWt SessionStart 1\n");
550 #endif
551 
552  G4Wt* interactorManager = G4Wt::getInstance ();
553 
554  Prompt("Session :");
555  exitSession = false;
556 
557  fMainWindow->show();
558 
559 #ifdef G4DEBUG_INTERFACES_BASIC
560  printf("G4UIWt::G4UIWt SessionStart2\n");
561 #endif
562  interactorManager->DisableSecondaryLoop (); // TO KEEP
563 // if ((Wt::WApplication*)interactorManager->GetMainInteractor())
564 // ((Wt::WApplication*)interactorManager->GetMainInteractor())->exec();
565 
566  // on ne passe pas le dessous ? FIXME ????
567  // je ne pense pas 13/06
568 
569  // void* event; // TO KEEP
570  // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
571  // interactorManager->DispatchEvent(event); // TO KEEP
572  // if(exitSession==true) break; // TO KEEP
573  // } // TO KEEP
574 
575  interactorManager->EnableSecondaryLoop ();
576  return this;
577 
578 }
579 
580 
586 void G4UIWt::Prompt (
587  G4String aPrompt
588  )
589 {
590  if (!aPrompt) return;
591  if (!fCommandLabel) return;
592 
593  fCommandLabel->setText((char*)aPrompt.data());
594 }
595 
596 
597 
598 void G4UIWt::SessionTerminate (
599 )
600 {
601  G4Wt* interactorManager = G4Wt::getInstance ();
602 
603  if ((Wt::WApplication*)interactorManager->GetMainInteractor()) {
604  // What to do here ?
605  }
606 }
607 
608 
609 
614 void G4UIWt::SecondaryLoop (
615  G4String aPrompt
616  )
617 {
618  if (!aPrompt) return;
619 
620  G4Wt* interactorManager = G4Wt::getInstance (); // TO KEEP ?
621  Prompt(aPrompt); // TO KEEP
622  fExitPause = false; // TO KEEP
623  void* eventTmp; // TO KEEP
624  while((eventTmp = interactorManager->GetEvent())!=NULL) { // TO KEEP
625  interactorManager->DispatchEvent(eventTmp); // TO KEEP
626  if(fExitPause==true) break; // TO KEEP
627  } // TO KEEP
628  Prompt("Session :"); // TO KEEP
629 }
630 
631 
635 void G4UIWt::CommandEnteredCallback (
636 )
637 {
638 #ifdef G4DEBUG_INTERFACES_BASIC
639  printf("G4UIWt::CommandEnteredCallback\n");
640 #endif
641 #ifdef G4DEBUG_INTERFACES_BASIC
642  printf("G4UIWt::CommandEnteredCallback 1\n");
643 #endif
644  G4String command (fCommandArea->text().toUTF8());
645  if (fCommandArea->text() != "") {
646 
647  printf("*** G4UIWt::CommandEnteredCallback, missing update on history \n");
648  /* FIXME
649  fHistoryTBTableList->addItem(fCommandArea->text());
650  fHistoryTBTableList->clearSelection();
651  fHistoryTBTableList->setCurrentIndex(0);
652 */
653  fCommandArea->setText("");
654 #ifdef G4DEBUG_INTERFACES_BASIC
655  printf("G4UIWt::CommandEnteredCallback 2\n");
656 #endif
657 
658  G4Wt* interactorManager = G4Wt::getInstance ();
659 #ifdef G4DEBUG_INTERFACES_BASIC
660  printf("G4UIWt::CommandEnteredCallback 3\n");
661 #endif
662  if (interactorManager) {
663  interactorManager->FlushAndWaitExecution();
664  }
665 #ifdef G4DEBUG_INTERFACES_BASIC
666  printf("G4UIWt::CommandEnteredCallback 4\n");
667 #endif
668  if (command(0,4) != "help") {
669  ApplyShellCommand (command,exitSession,exitPause);
670  } else {
671  ActivateCommand(command);
672  }
673 #ifdef G4DEBUG_INTERFACES_BASIC
674  printf("G4UIWt::CommandEnteredCallback 5\n");
675 #endif
676  // Rebuild help tree
677  FillHelpTree();
678 
679 #ifdef G4DEBUG_INTERFACES_BASIC
680  printf("G4UIWt::CommandEnteredCallback 6\n");
681 #endif
682  if(exitSession==true)
683  SessionTerminate();
684  }
685 #ifdef G4DEBUG_INTERFACES_BASIC
686  printf("G4UIWt::CommandEnteredCallback END\n");
687 #endif
688 
689  }
690 
691 
698 void G4UIWt::AddButton (
699  const char* aMenu
700  ,const char* aLabel
701  ,const char* aCommand
702  )
703 {
704  if(aMenu==NULL) return; // TO KEEP
705  if(aLabel==NULL) return; // TO KEEP
706  if(aCommand==NULL) return; // TO KEEP
707 
708  Wt::WMenu *parentTmp = (Wt::WMenu*)GetInteractor(aMenu);
709 
710  if(parentTmp==NULL) {
711  G4UImanager* UImanager = G4UImanager::GetUIpointer();
712  G4int verbose = UImanager->GetVerboseLevel();
713 
714  if (verbose >= 2) {
715  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
716  }
717  return;
718  }
719 
720  // Find the command in the command tree
722  if(UI==NULL) return;
723  G4UIcommandTree * treeTop = UI->GetTree();
724 
725  G4String cmd = aCommand;
726  G4int cmdEndPos = cmd.find_first_of(" \t");
727  if(cmdEndPos!=G4int(std::string::npos)) {
728  cmd.erase(cmdEndPos);
729  }
730 
731  if(treeTop->FindPath(aCommand) == NULL) {
732  G4UImanager* UImanager = G4UImanager::GetUIpointer();
733  G4int verbose = UImanager->GetVerboseLevel();
734 
735  if (verbose >= 2) {
736  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
737  }
738  }
739 
740  printf("*** G4UIWt::AddButton, missing connection on menu callback \n");
741 /* FIXME
742  QSignalMapper *signalMapper = new QSignalMapper(this);
743  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
744 
745  connect(signalMapper, SIGNAL(mapped(const char*)),this, SLOT(ButtonCallback(const char*)));
746  signalMapper->setMapping(action, aCommand);
747 */
748 }
749 
750 
754 void G4UIWt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* /* aFileName */ ){
755  if(aLabel==NULL) return; // TO KEEP
756  // special case, aCommand could be NULL if aIconFile is not user_icon
757  if (aCommand==NULL) {
758  if (std::string(aIconFile) == "user_icon") {
759  return; // TO KEEP
760  }
761  }
762  printf("*** G4UIWt::AddIcon, missing icon creation \n");
763 /*
764  QPixmap pix;
765  bool userToolBar = false;
766 
767  if (std::string(aIconFile) == "user_icon") {
768  // try to open a file
769  pix = QPixmap(aFileName);
770  if (pix.isNull()) {
771  G4UImanager* UImanager = G4UImanager::GetUIpointer();
772  G4int verbose = UImanager->GetVerboseLevel();
773 
774  if (verbose >= 2) {
775  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
776  }
777  return;
778  }
779  userToolBar = true;
780  } else if (std::string(aIconFile) == "open") {
781  const char * const xpm[]={
782  "32 32 33 1",
783  " c None",
784  "+ c #09091E",
785  "@ c #191B18",
786  "# c #5F615F",
787  "$ c #777977",
788  "% c #AEB1AF",
789  "& c #929491",
790  "* c #515250",
791  "= c #858784",
792  "- c #333533",
793  "; c #000100",
794  "> c #272926",
795  ", c #424341",
796  "' c #696C6A",
797  ") c #5F4927",
798  "! c #583D18",
799  "~ c #6E6A5B",
800  "{ c #47351D",
801  "] c #E0A554",
802  "^ c #FFD67B",
803  "/ c #EFB465",
804  "( c #FDBF6C",
805  "_ c #FFCD76",
806  ": c #806238",
807  "< c #362611",
808  "[ c #0B0D0A",
809  "} c #68471B",
810  "| c #523E22",
811  "1 c #B78A51",
812  "2 c #A17B44",
813  "3 c #D6A45E",
814  "4 c #C29354",
815  "5 c #A1A3A0",
816  " ",
817  " ",
818  " +@@@# ",
819  " $% +& * ",
820  " #= $ -; ",
821  " %>;+ ",
822  " ,;;+ ",
823  " &#$''#' >;;;+ ",
824  " =)!)!!!!~ *#$'' ",
825  " {]^/((_({- %%%%%%%%%%% ",
826  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
827  " {/_/(((((/]]]]]]]]]]]/]!# ",
828  " {/^(((((_^^^^^^^^^^^^^^:# ",
829  " {/^(((_^^____________^^}$ ",
830  " {/^(((((/////////////((!# ",
831  " {/^/^_:<|||||||||||||||@@****1 ",
832  " {/^/^(<[)||||||||||||||))!!}<; ",
833  " {/^_(:|234444444444444444432)1 ",
834  " {/_^/<)34444444444444444443}, ",
835  " {/^(2{:41111111111111111142|5 ",
836  " {3^3<:31111111111111111143}- ",
837  " {/^2<:31111111111111111441|' ",
838  " {_/<:41111111111111111143}, ",
839  " {(4<:31111111111111111144!# ",
840  " )4))44111111111111111144}, ",
841  " )2<:31111111111111111144{# ",
842  " @|:14444444444444444444}* ",
843  " ;@434444444444444444434<# ",
844  " ;[))))))))))))))))))))!~ ",
845  " ++++++++++++++++++++++;% ",
846  " ",
847  " "}
848  ;
849  pix = QPixmap(xpm);
850 
851  } else if (std::string(aIconFile) == "save") {
852  const char * const xpm[]={
853  "32 32 24 1",
854  " c None",
855  "+ c #000200",
856  "@ c #141E43",
857  "# c #000C56",
858  "$ c #494A47",
859  "% c #636662",
860  "& c #312F2A",
861  "* c #191B19",
862  "= c #002992",
863  "- c #003DFF",
864  "; c #041DA5",
865  "> c #A8A9A3",
866  ", c #FDFFFC",
867  "' c #DDE0DD",
868  ") c #818783",
869  "! c #C9CBC8",
870  "~ c #0116C3",
871  "{ c #C5C8FA",
872  "] c #6596FC",
873  "^ c #A0B4F9",
874  "/ c #0B2AFD",
875  "( c #799BE3",
876  "_ c #5F4826",
877  ": c #D5D8D5",
878  " ",
879  " ",
880  " +++++++++++++++++++++++++ ",
881  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
882  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
883  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
884  " +=-~@>,,,,,{]]]]]^,,,>*&$&+ ",
885  " +=-~@>,,,,,'{^{^^{,,,>*#=#+ ",
886  " +=-~@>,,,,,,,,,,,,,,,>@~/=+ ",
887  " +=-~@>,,,{{{''''{',,,>@~-=+ ",
888  " +=-~@>,,'^]]]]]]({,,,>@~-=+ ",
889  " +=-~@>,,,{{{{{{{{{,,,>@~-=+ ",
890  " +=-~@>,,,,,'{^{{^{,,,>@~-=+ ",
891  " +=-~@>,,,,,]]]]]]],,,>@~-=+ ",
892  " +=-~*>,,,,,,,,,,,,,,,>@~-=+ ",
893  " +=-~@>,,,,,,,,,,,,,,,>@~-=+ ",
894  " +=-/=$%%%%%%%%%%%%%%%$=/-=+ ",
895  " +=---;###############;---=+ ",
896  " +=---////////////////----=+ ",
897  " +=----------------///----=+ ",
898  " +=---=@##############@#--=+ ",
899  " +=---@+++++++++++*%))_+~-=+ ",
900  " +=---#+++++++++++&:,,>@~-=+ ",
901  " +=---#+++++++++++$',,>@~-=+ ",
902  " +=---#+++++++++++&!,,>@~-=+ ",
903  " +=/--#+++++++++++&',,>@~-=+ ",
904  " @;--#+++++++++++$',,>@~-=+ ",
905  " @;;@+++++++++++*)!>%@=;#+ ",
906  " @++++++++++++++*&**++@++ ",
907  " ",
908  " ",
909  " "}
910  ;
911  pix = QPixmap(xpm);
912  } else if (std::string(aIconFile) == "move") {
913  const char * const xpm[]={
914  "32 32 16 1",
915  " c None",
916  ". c #F1F1F1",
917  "+ c #939393",
918  "@ c #282828",
919  "# c #787878",
920  "$ c #000000",
921  "% c #CCCCCC",
922  "& c #1A1A1A",
923  "* c #0D0D0D",
924  "= c #5D5D5D",
925  "- c #AEAEAE",
926  "; c #BBBBBB",
927  "> c #C9C9C9",
928  ", c #D6D6D6",
929  "' c #FFFFFF",
930  ") c #999999",
931  " ",
932  " ",
933  " ",
934  " ",
935  " .. ",
936  " ++ ",
937  " .@@. ",
938  " #$$# ",
939  " %&$$*% ",
940  " =$$$$= ",
941  " -**$$**- ",
942  " %;%&*>;% ",
943  " -% @& %- ",
944  " ,=*; @& ;*=, ",
945  " .#*$$> >$$*#. ",
946  " ')&$$$$*@@ @@*$$$$&)' ",
947  " ')&$$$$*@@ @@*$$$$&+' ",
948  " .#*$$> >$$*#. ",
949  " ,=*; @& ;*=, ",
950  " -% @& %- ",
951  " %;%&*>>% ",
952  " -**$$**- ",
953  " =$$$$= ",
954  " %&$$*% ",
955  " #$$# ",
956  " .@@. ",
957  " ++ ",
958  " .. ",
959  " ",
960  " ",
961  " ",
962  " "}
963  ;
964  pix = QPixmap(xpm);
965 
966  } else if (std::string(aIconFile) == "rotate") {
967  const char * const xpm[]={
968  "32 32 27 1",
969  " c None",
970  ". c #003333",
971  "+ c #000066",
972  "@ c #1A1A1A",
973  "# c #003399",
974  "$ c #3333CC",
975  "% c #000033",
976  "& c #353535",
977  "* c #434343",
978  "= c #336699",
979  "- c #3399FF",
980  "; c #003366",
981  "> c #5D5D5D",
982  ", c #282828",
983  "' c #3399CC",
984  ") c #333333",
985  "! c #3366CC",
986  "~ c #333399",
987  "{ c #505050",
988  "] c #666666",
989  "^ c #333366",
990  "/ c #0033CC",
991  "( c #3366FF",
992  "_ c #336666",
993  ": c #787878",
994  "< c #868686",
995  "[ c #6B6B6B",
996  " .++@ ",
997  " #$$%&* ",
998  " =--; *>, ",
999  " '-= )>& ",
1000  " !-', ,>* ",
1001  " !!=--= >* ",
1002  " =------!!~@&)@ ",
1003  " --------!*{{{*&, ",
1004  " -------=){*{{{>>{) ",
1005  " ,!-----= ){& ,&{{@",
1006  " ,*>!----= &>& )@",
1007  " ){>)~---= *]) @",
1008  " @*>, --! ,&@ ",
1009  " @{* '! ,-!=~^,@ ",
1010  " @& == {/(----!^ ",
1011  " _ ]:;(----' ",
1012  " ==_ >{+(----~ ",
1013  " !-!!======!!(((---! ",
1014  " ='--------------! ",
1015  " =!!!!'!!=; !-! ",
1016  " &<* !~ ",
1017  " @. *[* ; ",
1018  " ;+)>* ",
1019  " @@ ",
1020  " ",
1021  " ",
1022  " ",
1023  " ",
1024  " ",
1025  " ",
1026  " ",
1027  " "}
1028  ;
1029  pix = QPixmap(xpm);
1030 
1031  } else if (std::string(aIconFile) == "pick") {
1032  const char * const xpm[]={
1033  "32 32 2 1",
1034  " c None",
1035  ". c #000000",
1036  " ",
1037  " ",
1038  " ",
1039  " ",
1040  " ",
1041  " ",
1042  " ",
1043  " . ",
1044  " .. ",
1045  " ... ",
1046  " .... ",
1047  " ..... ",
1048  " ...... ",
1049  " ....... ",
1050  " ....... ",
1051  " ........ ",
1052  " ..... ",
1053  " ...... ",
1054  " .. .. ",
1055  " . .. ",
1056  " ... ",
1057  " .. ",
1058  " .. ",
1059  " ",
1060  " ",
1061  " ",
1062  " ",
1063  " ",
1064  " ",
1065  " ",
1066  " ",
1067  " "}
1068  ;
1069  pix = QPixmap(xpm);
1070  } else if (std::string(aIconFile) == "zoom_in") {
1071  const char * const xpm[]={
1072  "32 32 11 1",
1073  " c None",
1074  ". c #C9CBC8",
1075  "+ c #A8A9A3",
1076  "@ c #818783",
1077  "# c #D5D8D5",
1078  "$ c #9BCCCC",
1079  "% c #5FC7F4",
1080  "& c #FDFFFC",
1081  "* c #636662",
1082  "= c #9599CE",
1083  "- c #DDE0DD",
1084  " ",
1085  " ",
1086  " ",
1087  " ",
1088  " ",
1089  " .++@@++. ",
1090  " +++..#.+++ ",
1091  " .@+...++++#+@. ",
1092  " @$.%%+&&&@%..@ ",
1093  " ++.%%%+&&&*%%.++ ",
1094  " .+#%%%%+&&&*%%.#+ ",
1095  " ++..%%%+&&&*%%%.++ ",
1096  " +#.+++++&&&*++++.+ ",
1097  " @.+&&&&&&&&&&&&&+@ ",
1098  " @#+&&&&&&&&&&&&&+@ ",
1099  " @.+&&&&&&&&&&&&&+. ",
1100  " +++@***+&&&****@+. ",
1101  " ....++++&&&*++++.. ",
1102  " ++.===+&&&*%=.++ ",
1103  " @..==+&&&*=..@#& ",
1104  " .@+#.+&&&@-+@@*@ ",
1105  " +++.++++++ *+@* ",
1106  " .+@@@++. @**+* ",
1107  " .*@*+* ",
1108  " .*@*+* ",
1109  " +*@@* ",
1110  " .**+ ",
1111  " ",
1112  " ",
1113  " ",
1114  " ",
1115  " "}
1116  ;
1117  pix = QPixmap(xpm);
1118  } else if (std::string(aIconFile) == "zoom_out") {
1119  const char * const xpm[]={
1120  "32 32 11 1",
1121  " c None",
1122  ". c #C9CBC8",
1123  "+ c #A8A9A3",
1124  "@ c #818783",
1125  "# c #D5D8D5",
1126  "$ c #5FC7F4",
1127  "% c #9BCCCC",
1128  "& c #FDFFFC",
1129  "* c #636662",
1130  "= c #9599CE",
1131  "- c #DDE0DD",
1132  " ",
1133  " ",
1134  " ",
1135  " ",
1136  " ",
1137  " .++@@++. ",
1138  " +++..#.+++ ",
1139  " .@+..$$$$.#+@. ",
1140  " @%.$$$$$$$$..@ ",
1141  " ++.$$$$$$$$$$.++ ",
1142  " .+#$$$$$$$$$$$.#+ ",
1143  " ++..$$$$$$$$$$$.++ ",
1144  " +#.+++++++++++++.+ ",
1145  " @.+&&&&&&&&&&&&&+@ ",
1146  " @#+&&&&&&&&&&&&&+@ ",
1147  " @.+&&&&&&&&&&&&&+. ",
1148  " +++@***********@+. ",
1149  " ....++++++++++++.. ",
1150  " ++.===$$$$$$=.++ ",
1151  " @..===$$$$=..@#& ",
1152  " .@+#.$$$..-+@@*@ ",
1153  " +++#--.+++ *+@* ",
1154  " .+@@@++. @**+* ",
1155  " .*@*+* ",
1156  " .*@*+* ",
1157  " +*@@* ",
1158  " .**+ ",
1159  " ",
1160  " ",
1161  " ",
1162  " ",
1163  " "}
1164  ;
1165  pix = QPixmap(xpm);
1166  } else if (std::string(aIconFile) == "wireframe") {
1167  const char * const xpm[]={
1168  "32 32 24 1",
1169  " c None",
1170  "+ c #E4E4E4",
1171  "@ c #D5D5D5",
1172  "# c #E1E1E1",
1173  "$ c #E7E7E7",
1174  "% c #D8D8D8",
1175  "& c #A7A7A7",
1176  "* c #000000",
1177  "= c #989898",
1178  "- c #8A8A8A",
1179  "; c #B5B5B5",
1180  "> c #1B1B1B",
1181  ", c #676767",
1182  "' c #959595",
1183  ") c #4A4A4A",
1184  "! c #878787",
1185  "~ c #D3D3D3",
1186  "{ c #C4C4C4",
1187  "] c #A4A4A4",
1188  "^ c #5B5B5B",
1189  "/ c #B3B3B3",
1190  "( c #787878",
1191  "_ c #C7C7C7",
1192  ": c #585858",
1193  " ",
1194  " +@@# ",
1195  " $%@@@@@&****=+ ",
1196  " +&********&@-***; ",
1197  " +@@@&**&@@@@@@$ @*-&>&+ ",
1198  " +*****&+ %*@ ,**'# ",
1199  " @***)!~ @*{&*****+ ",
1200  " @*!]***&+ +-*^**'~!*@ ",
1201  " @*~ +@&**&@@@@@@&****&+ ~*@ ",
1202  " @*@ +&********&-*= @*@ ",
1203  " @*@ $%@-*-@$ @*@ @*@ ",
1204  " @*@ @*@ %*% @*@ ",
1205  " @*@ %*% %*% @*@ ",
1206  " @*@ %*% %*% @*@ ",
1207  " @*@ %*% %*% @*@ ",
1208  " @*@ %*% %*% @*@ ",
1209  " @*@ %*% %*% @*@ ",
1210  " @*@ @*@ %*% @*@ ",
1211  " @*@ =*-+ @*@ @*@ ",
1212  " @*@ $%@@&****&@-*-+ @*@ ",
1213  " @*@ $@&*****&@@&******&~~!*@ ",
1214  " @*{****&@@%$ $@-*-&*****+ ",
1215  " @*)*)(-~ @*@ ~)**] ",
1216  " +*******&@@@@+ %*_+]**] ",
1217  " +@@@@@&******&@%+_*^**]# ",
1218  " $%@@@&****:**&+ ",
1219  " +%@&**& ",
1220  " ++ ",
1221  " ",
1222  " ",
1223  " ",
1224  " "}
1225  ;
1226  pix = QPixmap(xpm);
1227  } else if (std::string(aIconFile) == "solid") {
1228  const char * const xpm[]={
1229  "32 32 33 1",
1230  " c None",
1231  "+ c #C2DEDE",
1232  "@ c #B5D7DF",
1233  "# c #ACD6E6",
1234  "$ c #60C0EC",
1235  "% c #4EB7EE",
1236  "& c #53B9ED",
1237  "* c #82CEEA",
1238  "= c #CFDDDA",
1239  "- c #94C9E8",
1240  "; c #0960FF",
1241  "> c #0943FF",
1242  ", c #0949FF",
1243  "' c #3CB3F0",
1244  ") c #71C7EB",
1245  "! c #73CBE5",
1246  "~ c #D3DDDB",
1247  "{ c #C4DDDE",
1248  "] c #B7D5DF",
1249  "^ c #2DACF5",
1250  "/ c #59C1ED",
1251  "( c #5FC0ED",
1252  "_ c #85CEE9",
1253  ": c #096BFF",
1254  "< c #2AACF6",
1255  "[ c #5CBEEC",
1256  "} c #7ACAE4",
1257  "| c #73CAEB",
1258  "1 c #71C8E5",
1259  "2 c #D1DDDA",
1260  "3 c #CBDDD9",
1261  "4 c #67C1EB",
1262  "5 c #80CDEA",
1263  " ",
1264  " ",
1265  " +@@@@@@#$%&*= ",
1266  " +-;>>>>>>>>>,')!~ ",
1267  " {]@@-;>>>>>>>>>>>>^/(_= ",
1268  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1269  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1270  " @>>>>>>>>>>>>>>>>>><//////| ",
1271  " @>>>>>>>>>>>>>>>>>><//////| ",
1272  " @>>>>>>>>>>>>>>>>>><//////| ",
1273  " @>>>>>>>>>>>>>>>>>><//////| ",
1274  " @>>>>>>>>>>>>>>>>>><//////| ",
1275  " @>>>>>>>>>>>>>>>>>><//////| ",
1276  " @>>>>>>>>>>>>>>>>>><//////| ",
1277  " @>>>>>>>>>>>>>>>>>><//////| ",
1278  " @>>>>>>>>>>>>>>>>>><//////| ",
1279  " @>>>>>>>>>>>>>>>>>><//////| ",
1280  " @>>>>>>>>>>>>>>>>>><//////| ",
1281  " @>>>>>>>>>>>>>>>>>><//////| ",
1282  " @>>>>>>>>>>>>>>>>>><//////| ",
1283  " @>>>>>>>>>>>>>>>>>><//////| ",
1284  " @>>>>>>>>>>>>>>>>>></////[1 ",
1285  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1286  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1287  " +@@@@@-;>>>>>>>>>><[)13 ",
1288  " {]@@@-;>>>,'*3 ",
1289  " +@@#452 ",
1290  " ",
1291  " ",
1292  " ",
1293  " ",
1294  " "}
1295  ;
1296  pix = QPixmap(xpm);
1297  } else if (std::string(aIconFile) == "hidden_line_removal") {
1298  const char * const xpm[]={
1299  "32 32 15 1",
1300  " c None",
1301  "+ c #D5D5D5",
1302  "@ c #C7C7C7",
1303  "# c #9C9C9C",
1304  "$ c #000000",
1305  "% c #8E8E8E",
1306  "& c #808080",
1307  "* c #A9A9A9",
1308  "= c #D8D8D8",
1309  "- c #CACACA",
1310  "; c #181818",
1311  "> c #9F9F9F",
1312  ", c #ACACAC",
1313  "' c #B9B9B9",
1314  ") c #555555",
1315  " ",
1316  " +@@+ ",
1317  " +@@@@@@#$$$$%+ ",
1318  " +#$$$$$$$$#@&$$$* ",
1319  " =-@@#$$#@@@@@-= @$&#;>= ",
1320  " =$$$$$#+ -$@ *$$%+ ",
1321  " -$&@-= -$- #$$$= ",
1322  " -$@ -$- +&$- ",
1323  " @$@ @$@ @$@ ",
1324  " @$@ @$@ @$@ ",
1325  " @$@ @$@ @$@ ",
1326  " @$@ @$@ @$@ ",
1327  " @$@ @$@ @$@ ",
1328  " @$@ @$@ @$@ ",
1329  " @$@ @$@ @$@ ",
1330  " @$@ @$@ @$@ ",
1331  " @$@ @$@ @$@ ",
1332  " @$@ @$@ @$@ ",
1333  " @$@ @$@ @$@ ",
1334  " @$@ @$@ @$@ ",
1335  " @$@ @$@ @$@ ",
1336  " @$@ @$@ #$= ",
1337  " -$&@@@-= -$- =>;, ",
1338  " =$$$$$$$#@@@-= -$'+#$$, ",
1339  " =-@@@@#$$$$$$#@-+'$)$$#+ ",
1340  " =-@@@#$$$$)$$#+ ",
1341  " +@@#$$# ",
1342  " ++ ",
1343  " ",
1344  " ",
1345  " ",
1346  " "}
1347  ;
1348  pix = QPixmap(xpm);
1349  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1350  const char * const xpm[]={
1351  "32 32 40 1",
1352  " c None",
1353  "+ c #FFFFFF",
1354  "@ c #89A2E9",
1355  "# c #5378E3",
1356  "$ c #A2B5ED",
1357  "% c #5379E3",
1358  "& c #5076E3",
1359  "* c #3E69E4",
1360  "= c #0C43F8",
1361  "- c #043FFE",
1362  "; c #CDD9ED",
1363  "> c #BDCDE9",
1364  ", c #FBFCFC",
1365  "' c #406AE4",
1366  ") c #0439FE",
1367  "! c #0137FF",
1368  "~ c #4F75E3",
1369  "{ c #9EB5E3",
1370  "] c #829FE0",
1371  "^ c #B6C6E7",
1372  "/ c #9DB4E3",
1373  "( c #7E9CE0",
1374  "_ c #B2C3E9",
1375  ": c #7E9AE0",
1376  "< c #86A2E1",
1377  "[ c #CAD6ED",
1378  "} c #5177E3",
1379  "| c #829CE0",
1380  "1 c #BCCCE9",
1381  "2 c #3A67E6",
1382  "3 c #0A43FA",
1383  "4 c #95ACE1",
1384  "5 c #BBCBE9",
1385  "6 c #A9BBE5",
1386  "7 c #96AFE1",
1387  "8 c #BDCBE9",
1388  "9 c #4067E4",
1389  "0 c #6485E5",
1390  "a c #E3EAF3",
1391  "b c #CAD6F3",
1392  " ",
1393  " ",
1394  " ++++ ",
1395  " ++++++++@#$+++ ",
1396  " ++@%####&*=-#+;>, ",
1397  " +++++@'=)))))))!)~+{]^++ ",
1398  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1399  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1400  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1401  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1402  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1403  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1404  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1405  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1406  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1407  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1408  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1409  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1410  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1411  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1412  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1413  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1414  " +$#}}~23!!!!!!!!)~+/(]45, ",
1415  " +++++++@#}}~23!!)~+678++ ",
1416  " ++++++@#~90+a++ ",
1417  " ++++b++ ",
1418  " ++ ",
1419  " ",
1420  " ",
1421  " ",
1422  " ",
1423  " "}
1424  ;
1425  pix = QPixmap(xpm);
1426  } else if (std::string(aIconFile) == "perspective") {
1427  const char * const xpm[]={
1428  "32 32 3 1",
1429  " c None",
1430  ". c #D5D8D5",
1431  "+ c #000000",
1432  " ",
1433  " ",
1434  " ",
1435  " ",
1436  " ",
1437  " ................ ",
1438  " ....+++++++++++++++. ",
1439  " ...++++..+.........+++. ",
1440  " ..++..............++..+. ",
1441  " .+++++++++++++++++.. .+. ",
1442  " .+...............+. .+. ",
1443  " .+. .+. .+. .+. ",
1444  " .+. .+. .+. .+. ",
1445  " .+. .+. .+. .+. ",
1446  " .+. .+. .+. .+. ",
1447  " .+. .+. .+. .+. ",
1448  " .+. .+. .+. .+. ",
1449  " .+. .+. .+. .+. ",
1450  " .+. .+. .+. .+. ",
1451  " .+. .+......+....+. ",
1452  " .+. ..++++++.+.++++. ",
1453  " .+. .++.......+...+.. ",
1454  " .+. .++. .+..++. ",
1455  " .+. ..+.. .+..+. ",
1456  " .+..++. .+.+. ",
1457  " .+.++. .+++. ",
1458  " .+++.............++. ",
1459  " .+++++++++++++++++. ",
1460  " ................... ",
1461  " ",
1462  " ",
1463  " "}
1464  ;
1465  pix = QPixmap(xpm);
1466  } else if (std::string(aIconFile) == "ortho") {
1467  const char * const xpm[]={
1468  "32 32 3 1",
1469  " c None",
1470  ". c #D5D8D5",
1471  "@ c #000000",
1472  " ",
1473  " ",
1474  " ",
1475  " ................... ",
1476  " ..@@@@@@@@@@@@@@@@@. ",
1477  " ..@@@.............@@@. ",
1478  " ..@@.@. ..@..@. ",
1479  " ..@@ ..@. .@@...@. ",
1480  " ..@@..............@@.. .@. ",
1481  " .@@@@@@@@@@@@@@@@@.. .@. ",
1482  " .@...............@. .@. ",
1483  " .@. .@. .@. .@. ",
1484  " .@. .@. .@. .@. ",
1485  " .@. .@. .@. .@. ",
1486  " .@. .@. .@. .@. ",
1487  " .@. .@. .@. .@. ",
1488  " .@. .@. .@. .@. ",
1489  " .@. .@. .@. .@. ",
1490  " .@. .@. .@. .@. ",
1491  " .@. .@. .@. .@. ",
1492  " .@. .@. .@. .@. ",
1493  " .@. .@........@......@. ",
1494  " .@. .@@@@@@@@@.@.@@@@@@. ",
1495  " .@. .@@+........@....@@.. ",
1496  " .@...@. .@...@... ",
1497  " .@.@@. .@.@@ . ",
1498  " .@@@.............@@@.. ",
1499  " .@@@@@@@@@@@@@@@@@... ",
1500  " ................... ",
1501  " ",
1502  " ",
1503  " "}
1504  ;
1505  pix = QPixmap(xpm);
1506  } else {
1507  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1508  G4int verbose = UImanager->GetVerboseLevel();
1509 
1510  if (verbose >= 2) {
1511  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1512  }
1513  return;
1514  }
1515  Wt::WToolBar *currentToolbar = NULL;
1516  if (userToolBar) {
1517  if (fToolbarUser == NULL) {
1518  fToolbarUser = new Wt::WToolBar();
1519  fToolbarUser->setIconSize (QSize(20,20));
1520  fMainWindow->addToolBar(Wt::TopToolBarArea, fToolbarUser);
1521  }
1522  currentToolbar = fToolbarUser;
1523  } else {
1524  if (fToolbarApp == NULL) {
1525  fToolbarApp = new Wt::WToolBar();
1526  fToolbarApp->setIconSize (QSize(20,20));
1527  fMainWindow->addToolBar(Wt::TopToolBarArea, fToolbarApp);
1528  }
1529  currentToolbar = fToolbarApp;
1530  }
1531 
1532  QSignalMapper *signalMapper = new QSignalMapper(this);
1533  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1534 
1535 
1536  // special cases :"open"
1537  if (std::string(aIconFile) == "open") {
1538  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(OpenIconCallback(const Wt::WString &)));
1539  Wt::WString txt = aCommand + fStringSeparator + aLabel;
1540  signalMapper->setMapping(action, Wt::WString(txt));
1541 
1542  // special cases :"save"
1543  } else if (std::string(aIconFile) == "save") {
1544  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(SaveIconCallback(const Wt::WString&)));
1545  Wt::WString txt = aCommand + fStringSeparator + aLabel;
1546  signalMapper->setMapping(action, Wt::WString(txt));
1547 
1548  // special cases : cursor style
1549  } else if ((std::string(aIconFile) == "move") ||
1550  (std::string(aIconFile) == "rotate") ||
1551  (std::string(aIconFile) == "pick") ||
1552  (std::string(aIconFile) == "zoom_out") ||
1553  (std::string(aIconFile) == "zoom_in")) {
1554  action->setCheckable(TRUE);
1555  action->setChecked(TRUE);
1556  action->setData(aIconFile);
1557 
1558  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangeCursorStyle(const Wt::WString&)));
1559  signalMapper->setMapping(action, Wt::WString(aIconFile));
1560 
1561  if (std::string(aIconFile) == "move") {
1562  SetIconMoveSelected();
1563  }
1564  if (std::string(aIconFile) == "rotate") {
1565  SetIconRotateSelected();
1566  }
1567  if (std::string(aIconFile) == "pick") {
1568  SetIconPickSelected();
1569  }
1570  if (std::string(aIconFile) == "zoom_in") {
1571  SetIconZoomInSelected();
1572  }
1573  if (std::string(aIconFile) == "zoom_out") {
1574  SetIconZoomOutSelected();
1575  }
1576 
1577  // special case : surface style
1578  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1579  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1580  (std::string(aIconFile) == "solid") ||
1581  (std::string(aIconFile) == "wireframe")) {
1582  action->setCheckable(TRUE);
1583  action->setChecked(TRUE);
1584  action->setData(aIconFile);
1585  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangeSurfaceStyle(const Wt::WString&)));
1586  signalMapper->setMapping(action, Wt::WString(aIconFile));
1587 
1588  if (std::string(aIconFile) == "hidden_line_removal") {
1589  SetIconHLRSelected();
1590  }
1591  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1592  SetIconHLHSRSelected();
1593  }
1594  if (std::string(aIconFile) == "solid") {
1595  SetIconSolidSelected();
1596  }
1597  if (std::string(aIconFile) == "wireframe") {
1598  SetIconWireframeSelected();
1599  }
1600 
1601  // special case : perspective/ortho
1602  } else if ((std::string(aIconFile) == "perspective") ||
1603  (std::string(aIconFile) == "ortho")) {
1604  action->setCheckable(TRUE);
1605  action->setChecked(TRUE);
1606  action->setData(aIconFile);
1607  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangePerspectiveOrthoCallback(const Wt::WString&)));
1608  signalMapper->setMapping(action, Wt::WString(aIconFile));
1609 
1610  if (std::string(aIconFile) == "perspective") {
1611  SetIconPerspectiveSelected();
1612  }
1613  if (std::string(aIconFile) == "ortho") {
1614  SetIconOrthoSelected();
1615  }
1616 
1617  } else {
1618 
1619  // Find the command in the command tree
1620  G4UImanager* UI = G4UImanager::GetUIpointer();
1621  if(UI==NULL) return;
1622  G4UIcommandTree * treeTop = UI->GetTree();
1623  if (aCommand != NULL) {
1624  if(treeTop->FindPath(aCommand) == NULL) {
1625  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1626  G4int verbose = UImanager->GetVerboseLevel();
1627 
1628  if (verbose >= 2) {
1629  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1630  }
1631  }
1632  }
1633 
1634  connect(signalMapper, SIGNAL(mapped(const char *)),this, SLOT(ButtonCallback(const char *)));
1635  signalMapper->setMapping(action, aCommand);
1636  }
1637 */
1638 }
1639 
1640 
1646 bool G4UIWt::CreateCommandWidget(G4UIcommand* aCommand, Wt::WContainerWidget* aParent, bool isDialog) {
1647 
1648  if (aCommand == NULL) {
1649  return false;
1650  }
1651 
1652 
1653  // parameters
1654  G4int n_parameterEntry = aCommand->GetParameterEntries();
1655  if( n_parameterEntry > 0 ) {
1656  G4UIparameter *param;
1657 
1658  // Re-implementation of G4UIparameter.cc
1659  Wt::WContainerWidget* paramWidget = new Wt::WContainerWidget();
1660  Wt::WGridLayout* gridLayout = new Wt::WGridLayout(paramWidget);
1661 
1662  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
1663  unsigned int nbColorParameter = 0;
1664  bool isStillColorParameter = false;
1665  bool isColorDialogAdded = false;
1666  Wt::WLabel* redLabel = NULL;
1667  Wt::WLabel* greenLabel = NULL;
1668  Wt::WString redDefaultStr = "";
1669  Wt::WString greenDefaultStr = "";
1670  Wt::WString blueDefaultStr = "";
1671  Wt::WWidget* redInput = NULL;
1672  Wt::WWidget* greenInput = NULL;
1673 
1674  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1675  Wt::WString txt;
1676  param = aCommand->GetParameter(i_thParameter);
1677  Wt::WLabel* label = new Wt::WLabel(Wt::WString((char*)(param->GetParameterName()).data()));
1678 
1679  if ((label->text() == "red") || (label->text() == "red_or_string")){
1680  nbColorParameter ++;
1681  isStillColorParameter = true;
1682  } else if ((label->text() == "green") && isStillColorParameter) {
1683  nbColorParameter ++;
1684  } else if ((label->text() == "blue") && isStillColorParameter) {
1685  nbColorParameter ++;
1686  } else if (!isColorDialogAdded) {
1687 
1688  // not following red/green/blue parameters ?
1689  if (nbColorParameter == 1) {
1690  gridLayout->addWidget(redLabel,i_thParameter-1,0);
1691  gridLayout->addWidget(redInput,i_thParameter-1,1);
1692  } else if (nbColorParameter == 2) {
1693  gridLayout->addWidget(redLabel,i_thParameter-2,0);
1694  gridLayout->addWidget(redInput,i_thParameter-2,1);
1695  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
1696  gridLayout->addWidget(greenInput,i_thParameter-1,1);
1697  }
1698  nbColorParameter = 0;
1699  }
1700  // Check parameter type, could be NULL if not found
1701  Wt::WWidget* input = NULL;
1702  char paramType = param->GetParameterType();
1703  if ((paramType == 'd') || (paramType == 'i')) {
1704  input = new Wt::WLineEdit();
1705  // set default value
1706  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1707 
1708  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
1709  redDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1710  } else if ((label->text() == "green") && isStillColorParameter) {
1711  greenDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1712  } else if ((label->text() == "green") && isStillColorParameter) {
1713  blueDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1714  }
1715 
1716  } else if (paramType == 'b') {
1717  input = new Wt::WContainerWidget();
1718  Wt::WHBoxLayout* layout = new Wt::WHBoxLayout(input);
1719 
1720  Wt::WButtonGroup* buttons = new Wt::WButtonGroup();
1721  Wt::WRadioButton* radioOff = new Wt::WRadioButton("0");
1722  Wt::WRadioButton* radioOn = new Wt::WRadioButton("1");
1723  buttons->addButton(radioOn);
1724  buttons->addButton(radioOff);
1725  layout->addWidget(radioOn);
1726  layout->addWidget(radioOff);
1727 
1728  // set default value
1729  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1730  if (defaultValue == "0") {
1731  radioOff->setChecked(true);
1732  } else if (defaultValue == "1") {
1733  radioOn->setChecked(true);
1734  }
1735  } else if ((paramType == 's') && (!param->GetParameterCandidates().isNull())) {
1736  input = new Wt::WComboBox();
1737  Wt::WString candidates = Wt::WString((char*)(param->GetParameterCandidates()).data());
1738  printf("*** G4UIWt::CreateCommandWidget, missing parameter management for 's'\n");
1739  /* QStringList list = candidates.split (" ");
1740 
1741  // add all candidates to widget
1742  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1743  for (int a=0; a<list.size(); a++) {
1744  dynamic_cast<Wt::WComboBox*>(input)->addItem(list.at(a));
1745  if (list.at(a) == defaultValue) {
1746  dynamic_cast<Wt::WComboBox*>(input)->setCurrentIndex(a);
1747  }
1748  }
1749 */
1750  } else if (paramType == 's') { // string
1751  input = new Wt::WLineEdit();
1752  // set default value
1753  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1754 
1755  } else if (paramType == 'c') { // on/off
1756  input = new Wt::WContainerWidget();
1757  Wt::WHBoxLayout* layout = new Wt::WHBoxLayout(input);
1758 
1759  Wt::WButtonGroup* buttons = new Wt::WButtonGroup();
1760  Wt::WRadioButton* radioOff = new Wt::WRadioButton("off");
1761  Wt::WRadioButton* radioOn = new Wt::WRadioButton("on");
1762  buttons->addButton(radioOn);
1763  buttons->addButton(radioOff);
1764  layout->addWidget(radioOn);
1765  layout->addWidget(radioOff);
1766 
1767  // set default value
1768  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1769  if (defaultValue == "off") {
1770  radioOff->setChecked(true);
1771  } else if (defaultValue == "on") {
1772  radioOn->setChecked(true);
1773  }
1774 
1775  } else {
1776  input = new Wt::WLineEdit();
1777  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1778  }
1779 
1780  txt += "\nParameter : " + Wt::WString((char*)(param->GetParameterName()).data()) + "\n";
1781  if( ! param->GetParameterGuidance().isNull() )
1782  txt += Wt::WString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
1783 
1784 // FIXME ?
1785  txt += Wt::WString(" Parameter type : ") + std::string(&paramType).c_str() + "\n";
1786  if(param->IsOmittable()){
1787  txt += " Omittable : True\n";
1788  } else {
1789  txt += " Omittable : False\n";
1790  }
1791  if( param->GetCurrentAsDefault() ) {
1792  txt += " Default value : taken from the current value\n";
1793  } else if( ! param->GetDefaultValue().isNull() ) {
1794  txt += " Default value : " + Wt::WString((char*)(param->GetDefaultValue()).data())+ "\n";
1795  }
1796  if( ! param->GetParameterRange().isNull() ) {
1797  txt += " Parameter range : " + Wt::WString((char*)(param->GetParameterRange()).data())+ "\n";
1798  }
1799  if( ! param->GetParameterCandidates().isNull() ) {
1800  txt += " Candidates : " + Wt::WString((char*)(param->GetParameterCandidates()).data())+ "\n";
1801  }
1802 
1803  if (isStillColorParameter && (nbColorParameter != 0)) {
1804  if ((label->text() == "red") || (label->text() == "red_or_string")) {
1805  redLabel = label;
1806  redInput = input;
1807  } else if (label->text() == "green") {
1808  greenLabel = label;
1809  greenInput = input;
1810  } else if (label->text() == "blue") {
1811 
1812  // we have all, then add a color chooser
1813 
1814  // Create a pixmap with the default color
1815  Wt::WColor wc;
1816  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
1817  // 255 max
1818  wc.setRgb(atof(redDefaultStr.toUTF8().c_str())*256,
1819  atof(greenDefaultStr.toUTF8().c_str())*256,
1820  atof(blueDefaultStr.toUTF8().c_str())*256);
1821  }
1822  printf("*** G4UIWt::CreateCommandWidget, missing icon on command widget\n");
1823 /*
1824  QPixmap pixmap = QPixmap(QSize(16, 16));
1825  pixmap.fill (wc);
1826  Wt::WPainter painter(&pixmap);
1827  painter.setPen(Wt::black);
1828  painter.drawRect(0,0,15,15); // Draw contour
1829 
1830  input = new Wt::WPushButton("Change color");
1831  dynamic_cast<Wt::WPushButton*>(input)->setIcon(pixmap);
1832  dynamic_cast<Wt::WPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
1833  label = new Wt::WLabel("Choose color");
1834 
1835  // less 1 because we have to add one to the row number
1836  nbColorParameter--;
1837  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1838  input->setToolTip("Select the current color");
1839  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1840 
1841  // Connect pushButton to ColorDialog in callback
1842  QSignalMapper* signalMapper = new QSignalMapper(this);
1843  signalMapper->setMapping(input,input);
1844  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
1845  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(ChangeColorCallback(Wt::WWidget*)));
1846 
1847 */
1848  isColorDialogAdded = true;
1849  isStillColorParameter = false;
1850  }
1851  } else {
1852  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1853  input->setToolTip(txt);
1854  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1855  }
1856  }
1857  // add command name in hidden value at last line position 0
1858  Wt::WLabel* name = new Wt::WLabel(Wt::WString((char*)(aCommand->GetCommandPath().data())));
1859  name->hide();
1860  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
1861 
1862  Wt::WPushButton* applyButton = new Wt::WPushButton("Apply");
1863  if (!isDialog) {
1864 
1865  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
1866 
1867  printf("*** G4UIWt::CreateCommandWidget, missing connection on ApplyButton\n");
1868 /*
1869  QSignalMapper* signalMapper = new QSignalMapper(this);
1870  signalMapper->setMapping(applyButton, paramWidget);
1871  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
1872  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(VisParameterCallback(Wt::WWidget*)));
1873 */
1874  } else {
1875  // Apply/Cancel buttons
1876 
1877  printf("*** G4UIWt::CreateCommandWidget, missing connection on Apply/Cancel Button\n");
1878 /* applyButton->setAutoDefault( TRUE );
1879  applyButton->setDefault( TRUE );
1880  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
1881 
1882  Wt::WPushButton* cancelButton = new Wt::WPushButton( tr( "&Cancel" ));
1883  cancelButton->setAutoDefault( TRUE );
1884  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
1885 
1886  QSignalMapper* signalMapper = new QSignalMapper(this);
1887  signalMapper->setMapping(applyButton, paramWidget);
1888  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
1889  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(VisParameterCallback(Wt::WWidget*)));
1890 
1891  Wt::WWidget * parentCheck = aParent;
1892  Wt::WDialog* parentDialog = NULL;
1893  bool found = false;
1894  while ((parentCheck->parentWidget()) != NULL) {
1895  parentCheck = (Wt::WWidget*) parentCheck->parentWidget();
1896  parentDialog = dynamic_cast<Wt::WDialog*>(parentCheck);
1897  if (parentDialog) {
1898  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
1899  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
1900  found = true;
1901  }
1902  }
1903  if (!found) {
1904  return false;
1905  }
1906 */
1907  }
1908 
1909  if (!aParent->layout()) {
1910  aParent->setLayout(new Wt::WVBoxLayout());
1911  }
1912  aParent->layout()->addWidget(paramWidget);
1913  }
1914 
1915  return true;
1916 }
1917 
1918 
1926 bool G4UIWt::eventFilter( // Should stay with a minuscule eventFilter because of Wt
1927  Wt::WObject* /* aObj */
1928  ,Wt::WEvent* /* aEvent */
1929  )
1930 {
1931  bool res= false;
1932  printf("*** G4UIWt::eventFilter, missing eventFilter on everything\n");
1933 /*
1934  bool moveCommandCursor = false;
1935  if (aObj == NULL) return false;
1936  if (aEvent == NULL) return false;
1937 
1938  if (aObj == fHistoryTBTableList) {
1939  if (aEvent->type() == Wt::WEvent::KeyPress) {
1940  fCommandArea->setFocus();
1941  }
1942  }
1943  if (aObj == fCommandArea) {
1944  if (aEvent->type() == Wt::WEvent::KeyPress) {
1945  QKeyEvent *e = static_cast<QKeyEvent*>((QEvent*)aEvent);
1946  if ((e->key() == (Wt::Key_Down)) ||
1947  (e->key() == (Wt::Key_PageDown)) ||
1948  (e->key() == (Wt::Key_Up)) ||
1949  (e->key() == (Wt::Key_PageUp))) {
1950  int selection = fHistoryTBTableList->currentRow();
1951  if (fHistoryTBTableList->count()) {
1952  if (selection == -1) {
1953  selection = fHistoryTBTableList->count()-1;
1954  } else {
1955  if (e->key() == (Wt::Key_Down)) {
1956  if (selection <(fHistoryTBTableList->count()-1))
1957  selection++;
1958  } else if (e->key() == (Wt::Key_PageDown)) {
1959  selection = fHistoryTBTableList->count()-1;
1960  } else if (e->key() == (Wt::Key_Up)) {
1961  if (selection >0)
1962  selection --;
1963  } else if (e->key() == (Wt::Key_PageUp)) {
1964  selection = 0;
1965  }
1966  }
1967  fHistoryTBTableList->clearSelection();
1968  fHistoryTBTableList->item(selection)->setSelected(true);
1969  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
1970  }
1971  moveCommandCursor = true;
1972  } else if (e->key() == (Wt::Key_Tab)) {
1973  G4String ss = Complete(fCommandArea->text().toUTF8().c_str());
1974  fCommandArea->setText((char*)(ss.data()));
1975 
1976  // do not pass by parent, it will disable widget tab focus !
1977  return true;
1978  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
1979  // specific #ifdef
1980  } else if (((e->modifiers () == Wt::ControlModifier) || (e->modifiers () == Wt::MetaModifier)) && (e->key() == Wt::Key_A)) {
1981  fCommandArea->home(false);
1982  return true;
1983  } else if (((e->modifiers () == Wt::ControlModifier) || (e->modifiers () == Wt::MetaModifier)) && (e->key() == Wt::Key_E)) {
1984  fCommandArea->end(false);
1985  return true;
1986  }
1987  }
1988  }
1989  // change cursor position if needed
1990  if (moveCommandCursor == true) {
1991 #ifdef G4DEBUG_INTERFACES_BASIC
1992  printf("G4UIWt::eventFilter setCursor Position\n");
1993 #endif
1994  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
1995  fCommandArea->setCursorPosition (4);
1996  } else {
1997  // pass the event on to the parent class
1998  res = QObject::eventFilter(aObj, aEvent);
1999  }
2000 */
2001  return res;
2002 }
2003 
2004 
2007 void G4UIWt::HelpTreeClicCallback (
2008 )
2009 {
2010  Wt::WTreeNode* item = NULL;
2011  if (!fHelpTreeWidget)
2012  return ;
2013 
2014  if (!fHelpArea)
2015  return;
2016 
2017  const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2018  if (list.empty())
2019  return;
2020  item = *list.begin();
2021  if (!item)
2022  return;
2023 
2025  if(UI==NULL) return;
2026  G4UIcommandTree * treeTop = UI->GetTree();
2027 
2028  std::string itemText = GetLongCommandPath(item).toUTF8();
2029 
2030  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
2031 
2032  if (command) {
2033  fHelpArea->setText(GetCommandList(command));
2034  } else { // this is a command
2035  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
2036  if ( path) {
2037  // this is not a command, this is a sub directory
2038  // We display the Title
2039  fHelpArea->setText(path->GetTitle().data());
2040  }
2041  }
2042 }
2043 
2046 void G4UIWt::HelpTreeDoubleClicCallback (
2047 )
2048 {
2049  HelpTreeClicCallback();
2050 
2051  Wt::WTreeNode* item = NULL;
2052  if (!fHelpTreeWidget)
2053  return ;
2054 
2055  if (!fHelpArea)
2056  return;
2057 
2058  const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2059  if (list.empty())
2060  return;
2061  item = *list.begin();
2062  if (!item)
2063  return;
2064 
2065  fCommandArea->setText("");
2066  fCommandArea->setText(GetLongCommandPath(item));
2067 }
2068 
2069 
2075 G4int G4UIWt::ReceiveG4cout (
2076  const G4String& aString
2077  )
2078 {
2079  if (!aString) return 0;
2080 
2081  Wt::WStringListModel newStr;
2082 
2083  // Add to stringList
2084  std::string whiteSpaces( " \f\n\r\t\v" );
2085  std::string path = (char*)aString.data();
2086 
2087  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2088  path.erase( posR + 1 );
2089 
2090  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2091  path.erase( 0, posL );
2092 
2093  printf("*** G4UIWt::ReceiveG4cout, missing filtering\n");
2094 /* newStr = Wt::WString(path);
2095  fG4cout += newStr;
2096 
2097  QStringList result = newStr.filter(fCoutFilter->text());
2098 
2099  if (result.join("").isEmpty()) {
2100  return 0;
2101  }
2102  */
2103  if (!fCoutTBTextArea) {
2104  printf("*** G4UIWt::ReceiveG4cout, create a new fCoutTBTextArea \n");
2105  fCoutTBTextArea = new Wt::WTextArea();
2106  fCoutTBTextArea->setText("");
2107  }
2108  fCoutTBTextArea->setText(fCoutTBTextArea->text()+"\n"+path);
2109  fCoutTBTextArea->refresh();
2110 
2111  return 0;
2112 }
2113 
2114 
2120 G4int G4UIWt::ReceiveG4cerr (
2121  const G4String& aString
2122  )
2123 {
2124  if (!aString) return 0;
2125 
2126  Wt::WStringListModel newStr;
2127 
2128  // Add to stringList
2129  std::string whiteSpaces( " \f\n\r\t\v" );
2130  std::string path = (char*)aString.data();
2131 
2132  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2133  path.erase( posR + 1 );
2134 
2135  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2136  path.erase( 0, posL );
2137 
2138  printf("*** G4UIWt::ReceiveG4cerr, missing filtering\n");
2139  /* newStr = Wt::WStringList(path);
2140  fG4cout += newStr;
2141 
2142  QStringList result = newStr.filter(fCoutFilter->text());
2143 
2144  */
2145  // Suppress space, \n,\t,\r...
2146  if (path != "") {
2147  if ((G4StateManager::GetStateManager()->GetCurrentState() == G4State_Abort) ||
2148  (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Quit )) {
2149  // In case of Abort or Quit, the useful error message should be in the last error message !
2150  Wt::WMessageBox::show("Error", Wt::WString(fLastErrMessage.data())+"\n"+aString.data(), Wt::Ok );
2151  }
2152 
2153  }
2154  printf("****ERR****: %s\n",path.c_str());
2155  if (!fCoutTBTextArea) {
2156  fCoutTBTextArea = new Wt::WTextArea();
2157  }
2158  fCoutTBTextArea->setText(fCoutTBTextArea->text()+"\n<font color='red'>"+path+"</font>");
2159  fCoutTBTextArea->refresh();
2160 
2161 
2162  if (path != "") {
2163  fLastErrMessage = aString;
2164  }
2165  return 0;
2166 }
2167 
2168 
2173 void G4UIWt::CommandEditedCallback(const Wt::WString &)
2174 {
2175  printf("*** G4UIWt::CommandEditedCallback, missing callback on command line edit\n");
2176 /* QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2177 
2178  if (list.size() > 1) { // trigger ActivateCommand
2179  for (int a=0; a<list.size()-1; a++) {
2180  // set only the first part
2181  fCommandArea->setText(list[a]);
2182  // trigger callback
2183  CommandEnteredCallback();
2184  }
2185  // reset unfinished command
2186  fCommandArea->setText(list[list.size()-1]);
2187  }
2188 */
2189 }
2190 
2191 
2192 
2193 void G4UIWt::CoutFilterCallback(
2194  const Wt::WString & /* text */) {
2195  printf("*** G4UIWt::CoutFilterCallbackt, missing filtering\n");
2196 
2197 /* QStringList result = fG4cout.filter(text);
2198  fCoutTBTextArea->setPlainText(result.join("\n"));
2199 
2200  fCoutTBTextArea->repaint();
2201  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
2202 
2203 */
2204 }
2205 
2206 
2207 
2208 
2209 
2215 void G4UIWt::AddMenu (
2216  const char* aName
2217  ,const char* aLabel
2218  )
2219 {
2220  if (aName == NULL) return;
2221  if (aLabel == NULL) return;
2222 
2223  printf("*** G4UIWt::AddMenu, missing \n");
2224 /* Wt::WMenu *fileMenu = new Wt::WMenu(aLabel);
2225  fMainWindow->menuBar()->addMenu(fileMenu);
2226 
2227  AddInteractor (aName,(G4Interactor)fileMenu);
2228 */
2229 }
2230 
2231 
2237 bool G4UIWt::CreateVisCommandGroupAndToolBox(
2238  G4UIcommand* /* aCommand */
2239  ,Wt::WWidget* /* aParent */
2240  ,int /* aDepthLevel */
2241  ,bool /* isDialog */
2242  )
2243 {
2244  printf("*** G4UIWt::CreateVisCommandGroupAndToolBox, missing \n");
2245  /*
2246  std::string str ((char*)(aCommand->GetCommandPath().data()));
2247  std::string str2 ("/");
2248  std::size_t pos = -1;
2249 
2250  for (int a=1; a<=-aDepthLevel; a++) {
2251  pos = str.find(str2, pos+1);
2252  }
2253 
2254  Wt::WString commandText2;
2255  std::string commandText = "";
2256  if (pos!=std::string::npos) {
2257  commandText = str.substr(pos);
2258  }
2259  // FIXME : commandText2 = Wt::WString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
2260  // FIXME : printf(" CommandText : %s\n",commandText.toUTF8().c_str());
2261  // FIXME : printf(" CommandText2 : %s\n",commandText2.toUTF8().c_str());
2262 
2263  if (commandText == "") {
2264  return false;
2265  }
2266 
2267  // Look if groupBox is create
2268  // Wt::WGroupBox* gBoxCommandWidget;
2269  Wt::WWidget* newParentWidget = NULL;
2270  bool found = false;
2271 
2272  pos = commandText.find("/", 0);
2273  Wt::WString commandSection = "";
2274  if (pos!=std::string::npos) {
2275  commandSection = Wt::WString(str.substr(0,pos).c_str());
2276  }
2277 
2278  // FIXME : Wt::WString commandSection = commandText.left(commandText.indexOf("/"));
2279 
2280  if (aDepthLevel == 1) {
2281  Wt::WToolBox* currentParent = dynamic_cast<Wt::WToolBox*>(aParent);
2282  if (currentParent != 0){
2283 
2284  // already exists ?
2285  for (int a=0; a<currentParent->count(); a++) {
2286  if (currentParent->itemText(a) == commandSection) {
2287  found = true;
2288  newParentWidget = (Wt::WWidget*) currentParent->widget(a);
2289  }
2290  }
2291  }
2292  // Not found ? create it
2293  if (!found) {
2294  newParentWidget = new Wt::WGroupBox();
2295  // newParentWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
2296  newParentWidget->setLayout(new Wt::WVBoxLayout());
2297  if (currentParent != 0){
2298  currentParent->addItem(newParentWidget,commandSection);
2299  } else {
2300  if (!aParent->layout()) {
2301  aParent->setLayout(new Wt::WVBoxLayout());
2302  }
2303  aParent->layout()->addWidget(newParentWidget);
2304  }
2305 
2306  if (commandText.find("/", 0) != std::string::npos) {
2307 
2308  // Guidance
2309  Wt::WString guidance;
2310  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2311  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2312  guidance += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2313  }
2314  newParentWidget->setToolTip(guidance);
2315  }
2316 
2317  Wt::WScrollArea* sc = dynamic_cast<Wt::WScrollArea*>(newParentWidget->parent()->parent());
2318  if (sc != 0) {
2319  sc->ensureWidgetVisible(newParentWidget);
2320  // sc->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
2321 
2322  }
2323  }
2324  } else {
2325 
2326  // try to know if this level is already there
2327  Wt::WGroupBox* currentParent = dynamic_cast<Wt::WGroupBox*>(aParent);
2328  if (currentParent != 0){
2329 
2330  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
2331  // Wt::WGroupBox > Wt::WWidget > Wt::WScrollArea > Wt::WToolBox
2332  if (aDepthLevel == 2){
2333  Wt::WToolBox* parentToolBox = dynamic_cast<Wt::WToolBox*>(((Wt::WWidget*) (currentParent))->parent()->parent()->parent());
2334  if (parentToolBox != 0) {
2335  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2336  }
2337  }
2338  for (int a=0; a<aParent->layout()->count(); a++) {
2339  Wt::WGroupBox* gb = dynamic_cast<Wt::WGroupBox*>(aParent->layout()->itemAt(a)->widget());
2340  if (gb != 0) {
2341  if (gb->title() == commandSection) {
2342  found = true;
2343  newParentWidget = gb;
2344  }
2345  }
2346  }
2347  }
2348 
2349  // Not found ? create it
2350  if (!found) {
2351  newParentWidget = new Wt::WGroupBox(commandSection);
2352  newParentWidget->setLayout(new Wt::WVBoxLayout());
2353  if (!aParent->layout()) {
2354  aParent->setLayout(new Wt::WVBoxLayout());
2355  }
2356  aParent->layout()->addWidget(newParentWidget);
2357 
2358  // set toolTip
2359  // Guidance
2360  Wt::WString guidance;
2361  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2362  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2363  guidance += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2364  }
2365  newParentWidget->setToolTip(guidance);
2366  }
2367  }
2368 
2369  // fill command groupbox
2370  if (commandText.find("/", 0) != std::string::npos) {
2371  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2372  return true;
2373  }
2374  } else {
2375  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2376  }
2377 */
2378  return true;
2379 }
2380 
2381 
2384 void G4UIWt::VisParameterCallback(Wt::WContainerWidget* widget){
2385  if (widget == NULL) {
2386  return;
2387  }
2388  printf("*** G4UIWt::VisParameterCallback, missing \n");
2389 /*
2390  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
2391  Wt::WGridLayout* grid = dynamic_cast<Wt::WGridLayout*>(widget->layout());
2392  if (grid == 0) {
2393  return;
2394  }
2395  Wt::WString command;
2396  Wt::WWidget* name = (Wt::WWidget*) (grid->itemAtPosition(grid->rowCount()-1,0)->widget());
2397  if (widget == NULL) {
2398  return;
2399  }
2400  if (dynamic_cast<Wt::WLabel*>(name) == 0) {
2401  return;
2402  }
2403  command += (dynamic_cast<Wt::WLabel*>(name))->text()+" ";
2404 
2405  for (int a=0;a<grid->rowCount()-1; a++) {
2406  Wt::WWidget* widgetTmp = (Wt::WWidget*) (grid->itemAtPosition(a,1)->widget());
2407 
2408  // 4 kind of widgets : Wt::WLineEdit / Wt::WComboBox / radioButtonsGroup / Wt::WPushButton (color chooser)
2409  if (widgetTmp != NULL) {
2410 
2411  if (dynamic_cast<Wt::WLineEdit*>(widgetTmp) != 0) {
2412  command += (dynamic_cast<Wt::WLineEdit*>(widgetTmp))->text()+" ";
2413 
2414  } else if (dynamic_cast<Wt::WComboBox*>(widgetTmp) != 0){
2415  command += (dynamic_cast<Wt::WComboBox*>(widgetTmp))->itemText((dynamic_cast<Wt::WComboBox*>(widgetTmp))->currentIndex())+" ";
2416 
2417  // Color chooser
2418  } else if (dynamic_cast<Wt::WPushButton*>(widgetTmp) != 0){
2419  command += widgetTmp->accessibleName()+" ";
2420 
2421  // Check for Button group
2422  } else if (dynamic_cast<Wt::WWidget*>(widgetTmp) != 0){
2423  if (widgetTmp->layout()->count() > 0){
2424  if (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
2425  QAbstractButton * checked = (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
2426  if (checked != 0) {
2427  command += (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
2428  }
2429  }
2430  }
2431 
2432  }
2433  }
2434  }
2435  if (command != "") {
2436  G4UImanager* UI = G4UImanager::GetUIpointer();
2437  if(UI != NULL) {
2438  UI->ApplyCommand(command.toUTF8().c_str());
2439  }
2440  }
2441  */
2442 }
2443 
2444 
2448 void G4UIWt::CommandHistoryCallback(
2449 )
2450 {
2451  if (!fHistoryTBTableList)
2452  return ;
2453  fCommandArea->setText(fHistoryTBTableList->currentText ());
2454 #ifdef G4DEBUG_INTERFACES_BASIC
2455  printf("G4UIWt::CommandHistoryCallback change text\n");
2456 #endif
2457 }
2458 
2459 
2460 void G4UIWt::OpenHelpTreeOnCommand(
2461  const Wt::WString & /* searchText */
2462  )
2463 {
2464  printf("*** G4UIWt::OpenHelpTreeOnCommand, missing \n");
2465 /* // the help tree
2466  G4UImanager* UI = G4UImanager::GetUIpointer();
2467  if(UI==NULL) return;
2468  G4UIcommandTree * treeTop = UI->GetTree();
2469 
2470  G4int treeSize = treeTop->GetTreeEntry();
2471 
2472  // clear old help tree
2473  fHelpTreeWidget->clear();
2474 
2475  // look for new items
2476 
2477  int tmp = 0;
2478 
2479  QMap<int,Wt::WString> commandResultMap;
2480  QMap<int,Wt::WString> commandChildResultMap;
2481 
2482  for (int a=0;a<treeSize;a++) {
2483  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
2484  tmp = GetCommandList (command).count(searchText,Wt::CaseInsensitive);
2485  if (tmp >0) {
2486  commandResultMap.insertMulti(tmp,Wt::WString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
2487  }
2488  // look for childs
2489  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
2490  // insert new childs
2491  if (!commandChildResultMap.empty()) {
2492  QMap<int,Wt::WString>::const_iterator i = commandChildResultMap.constBegin();
2493  while (i != commandChildResultMap.constEnd()) {
2494  commandResultMap.insertMulti(i.key(),i.value());
2495  i++;
2496  }
2497  commandChildResultMap.clear();
2498  }
2499  }
2500 
2501  // build new help tree
2502  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2503  fHelpTreeWidget->setColumnCount(2);
2504  Wt::WStringList labels;
2505  labels << Wt::WString("Command") << Wt::WString("Match");
2506  fHelpTreeWidget->setHeaderLabels(labels);
2507 
2508  if (commandResultMap.empty()) {
2509  fHelpArea->setText("No match found");
2510  return;
2511  }
2512 
2513  QMap<int,Wt::WString>::const_iterator i = commandResultMap.constEnd();
2514  i--;
2515  // 10 maximum progress values
2516  float multValue = 10.0/(float)(i.key());
2517  Wt::WString progressChar = "|";
2518  Wt::WString progressStr = "|";
2519 
2520  Wt::WTreeNode * newItem;
2521  bool end = false;
2522  while (!end) {
2523  if (i == commandResultMap.constBegin()) {
2524  end = true;
2525  }
2526  for(int a=0;a<int(i.key()*multValue);a++) {
2527  progressStr += progressChar;
2528  }
2529  newItem = new Wt::WTreeNode(fHelpTreeWidget);
2530  Wt::WString commandStr = i.value().trimmed();
2531 
2532  if (commandStr.indexOf("/") == 0) {
2533  commandStr = commandStr.right(commandStr.size()-1);
2534  }
2535 
2536  newItem->setText(0,commandStr);
2537  newItem->setText(1,progressStr);
2538 
2539  newItem->setForeground ( 1, QBrush(Wt::blue) );
2540  progressStr = "|";
2541  i--;
2542  }
2543  fHelpTreeWidget->resizeColumnToContents (0);
2544  fHelpTreeWidget->sortItems(1,Wt::DescendingOrder);
2545  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
2546 */
2547 }
2548 
2549 /*
2550 WMap<int,Wt::WString> G4UIWt::LookForHelpStringInChildTree(
2551  G4UIcommandTree *aCommandTree
2552  ,const Wt::WString & text
2553  )
2554 {
2555  QMap<int,Wt::WString> commandResultMap;
2556  if (aCommandTree == NULL) return commandResultMap;
2557 
2558 
2559  // Get the Sub directories
2560  int tmp = 0;
2561  QMap<int,Wt::WString> commandChildResultMap;
2562 
2563  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2564  const G4UIcommand* command = aCommandTree->GetGuidance();
2565  tmp = GetCommandList (command).count(text,Wt::CaseInsensitive);
2566  if (tmp >0) {
2567  commandResultMap.insertMulti(tmp,Wt::WString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
2568  }
2569  // look for childs
2570  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
2571 
2572  if (!commandChildResultMap.empty()) {
2573  // insert new childs
2574  QMap<int,Wt::WString>::const_iterator i = commandChildResultMap.constBegin();
2575  while (i != commandChildResultMap.constEnd()) {
2576  commandResultMap.insertMulti(i.key(),i.value());
2577  i++;
2578  }
2579  commandChildResultMap.clear();
2580  }
2581  }
2582  // Get the Commands
2583 
2584  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2585  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
2586  tmp = GetCommandList (command).count(text,Wt::CaseInsensitive);
2587  if (tmp >0) {
2588  commandResultMap.insertMulti(tmp,Wt::WString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
2589  }
2590 
2591  }
2592  return commandResultMap;
2593 }
2594 */
2595 
2596 
2597 void G4UIWt::ChangeColorCallback(Wt::WContainerWidget* widget) {
2598  if (widget == NULL) {
2599  return;
2600  }
2601  printf("*** G4UIWt::ChangeColorCallback, missing \n");
2602 /*
2603  Wt::WPushButton* button = dynamic_cast<Wt::WPushButton*>(widget);
2604  if (button == 0) {
2605  return;
2606  }
2607  Wt::WString value = button->accessibleName();
2608 
2609  Wt::WColor old;
2610  old.setRgbF(value.section(" ",0,1).toDouble(),
2611  value.section(" ",1,2).toDouble(),
2612  value.section(" ",2,3).toDouble());
2613  Wt::WColor color = Wt::WColorDialog::getColor(old,
2614  fUITabWidget,
2615  "Change color",
2616  Wt::WColorDialog::ShowAlphaChannel);
2617 
2618 
2619  if (color.isValid()) {
2620  // rebuild the widget icon
2621  QPixmap pixmap = QPixmap(QSize(16, 16));
2622  pixmap.fill (color);
2623  Wt::WPainter painter(&pixmap);
2624  painter.setPen(Wt::black);
2625  painter.drawRect(0,0,15,15); // Draw contour
2626 
2627  button->setAccessibleName(Wt::WString::number(color.redF())+" "+
2628  Wt::WString::number(color.greenF())+" "+
2629  Wt::WString::number(color.blueF())+" "
2630  );
2631  button->setIcon(pixmap);
2632 
2633 
2634  }
2635 */
2636 }
2637 
2638 void G4UIWt::ChangeCursorStyle(const Wt::WString& /* action */) {
2639 
2640  // Theses actions should be in the app toolbar
2641 
2642  fMoveSelected = true;
2643  fPickSelected = true;
2644  fRotateSelected = true;
2645  fZoomInSelected = true;
2646  fZoomOutSelected = true;
2647 
2648  printf("*** G4UIWt::ChangeCursorStyle, missing \n");
2649 /*
2650  if (fToolbarApp == NULL) return;
2651  QList<QAction *> list = fToolbarApp->actions ();
2652  for (int i = 0; i < list.size(); ++i) {
2653  if (list.at(i)->data().toString () == action) {
2654  list.at(i)->setChecked(TRUE);
2655  } else if (list.at(i)->data().toString () == "move") {
2656  fMoveSelected = false;
2657  list.at(i)->setChecked(FALSE);
2658  } else if (list.at(i)->data().toString () == "pick") {
2659  fPickSelected = false;
2660  list.at(i)->setChecked(FALSE);
2661  } else if (list.at(i)->data().toString () == "rotate") {
2662  fRotateSelected = false;
2663  list.at(i)->setChecked(FALSE);
2664  } else if (list.at(i)->data().toString () == "zoom_in") {
2665  fZoomInSelected = false;
2666  list.at(i)->setChecked(FALSE);
2667  } else if (list.at(i)->data().toString () == "zoom_out") {
2668  fZoomOutSelected = false;
2669  list.at(i)->setChecked(FALSE);
2670  }
2671  }
2672  // FIXME : Should connect this to Vis
2673 */
2674 }
2675 
2676 
2677 /* A little bit like "void G4OpenGLWtViewer::toggleDrawingAction(int aAction)"
2678  But for all viewers, not only Wt
2679 
2680  FIXME : Should be a feedback when changing viewer !
2681 
2682  */
2683 void G4UIWt::ChangeSurfaceStyle(const Wt::WString& /* action */) {
2684 
2685  // Theses actions should be in the app toolbar
2686 
2687  printf("*** G4UIWt::ChangeSurfaceStyle, missing \n");
2688 /* if (fToolbarApp == NULL) return;
2689  QList<QAction *> list = fToolbarApp->actions ();
2690  for (int i = 0; i < list.size(); ++i) {
2691  if (list.at(i)->data().toString () == action) {
2692  list.at(i)->setChecked(TRUE);
2693  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2694  list.at(i)->setChecked(FALSE);
2695  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2696  list.at(i)->setChecked(FALSE);
2697  } else if (list.at(i)->data().toString () == "solid") {
2698  list.at(i)->setChecked(FALSE);
2699  } else if (list.at(i)->data().toString () == "wireframe") {
2700  list.at(i)->setChecked(FALSE);
2701  }
2702  }
2703  // FIXME : Should connect this to Vis
2704 
2705  if (action == "hidden_line_removal") {
2706  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
2707  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
2708 
2709  } else if (action == "hidden_line_and_surface_removal") {
2710  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
2711  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
2712 
2713  } else if (action == "solid") {
2714  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
2715  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
2716 
2717  } else if (action == "wireframe") {
2718  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
2719  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
2720  }
2721 */
2722 }
2723 
2724 void G4UIWt::OpenIconCallback(const Wt::WString& /* aParam */) {
2725 
2726  printf("*** G4UIWt::OpenIconCallback, missing \n");
2727 /*
2728  Wt::WString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
2729  Wt::WString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
2730 
2731  Wt::WString nomFich = Wt::WFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
2732  if (nomFich != "") {
2733  G4UImanager::GetUIpointer()->ApplyCommand((Wt::WString(aCommand)+ Wt::WString(" ")+ nomFich).toUTF8().c_str());
2734  QDir dir;
2735  fLastOpenPath = dir.absoluteFilePath(nomFich);
2736  }
2737 */
2738 }
2739 
2740 
2741 void G4UIWt::SaveIconCallback(const Wt::WString& /* aParam */) {
2742 
2743  printf("*** G4UIWt::SaveIconCallback, missing \n");
2744 
2745  /*
2746  Wt::WString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
2747  Wt::WString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
2748 
2749  Wt::WString nomFich = Wt::WFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
2750  if (nomFich != "") {
2751  G4UImanager::GetUIpointer()->ApplyCommand((Wt::WString(aCommand)+ Wt::WString(" ")+nomFich).toUTF8().c_str());
2752  QDir dir;
2753  fLastOpenPath = dir.absoluteFilePath(nomFich);
2754  }
2755 */
2756 }
2757 
2758 
2759 void G4UIWt::ChangePerspectiveOrthoCallback(const Wt::WString& /* action */) {
2760 
2761  // Theses actions should be in the app toolbar
2762 
2763  printf("*** G4UIWt::ChangePerspectiveOrthoCallback, missing \n");
2764 /*
2765  if (fToolbarApp == NULL) return;
2766  QList<QAction *> list = fToolbarApp->actions ();
2767  Wt::WString checked = "";
2768  for (int i = 0; i < list.size(); ++i) {
2769  if (list.at(i)->data().toString () == action) {
2770  list.at(i)->setChecked(TRUE);
2771  checked = list.at(i)->data().toString ();
2772  } else if (list.at(i)->data().toString () == "persepective") {
2773  list.at(i)->setChecked(FALSE);
2774  } else if (list.at(i)->data().toString () == "ortho") {
2775  list.at(i)->setChecked(FALSE);
2776  }
2777  }
2778 
2779  if ((action == "ortho") && (checked == "ortho")) {
2780  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
2781  } else if ((action == "perspective") && (checked == "perspective")) {
2782  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
2783  }
2784 */
2785 }
2786 
2787 /*
2788 void G4UIWt::SetIconMoveSelected() {
2789  // Theses actions should be in the app toolbar
2790  fMoveSelected = true;
2791  fRotateSelected = false;
2792  fPickSelected = false;
2793  fZoomInSelected = false;
2794  fZoomOutSelected = false;
2795 
2796  if (fToolbarApp == NULL) return;
2797  QList<QAction *> list = fToolbarApp->actions ();
2798  for (int i = 0; i < list.size(); ++i) {
2799  if (list.at(i)->data().toString () == "move") {
2800  list.at(i)->setChecked(TRUE);
2801  } else if (list.at(i)->data().toString () == "rotate") {
2802  list.at(i)->setChecked(FALSE);
2803  } else if (list.at(i)->data().toString () == "pick") {
2804  list.at(i)->setChecked(FALSE);
2805  } else if (list.at(i)->data().toString () == "zoom_in") {
2806  list.at(i)->setChecked(FALSE);
2807  } else if (list.at(i)->data().toString () == "zoom_out") {
2808  list.at(i)->setChecked(FALSE);
2809  }
2810  }
2811 }
2812 
2813 
2814 void G4UIWt::SetIconRotateSelected() {
2815  // Theses actions should be in the app toolbar
2816  fRotateSelected = true;
2817  fMoveSelected = false;
2818  fPickSelected = false;
2819  fZoomInSelected = false;
2820  fZoomOutSelected = false;
2821 
2822  if (fToolbarApp == NULL) return;
2823  QList<QAction *> list = fToolbarApp->actions ();
2824  for (int i = 0; i < list.size(); ++i) {
2825  if (list.at(i)->data().toString () == "rotate") {
2826  list.at(i)->setChecked(TRUE);
2827  } else if (list.at(i)->data().toString () == "move") {
2828  list.at(i)->setChecked(FALSE);
2829  } else if (list.at(i)->data().toString () == "pick") {
2830  list.at(i)->setChecked(FALSE);
2831  } else if (list.at(i)->data().toString () == "zoom_in") {
2832  list.at(i)->setChecked(FALSE);
2833  } else if (list.at(i)->data().toString () == "zoom_out") {
2834  list.at(i)->setChecked(FALSE);
2835  }
2836  }
2837 }
2838 
2839 
2840 void G4UIWt::SetIconPickSelected() {
2841  // Theses actions should be in the app toolbar
2842  fPickSelected = true;
2843  fMoveSelected = false;
2844  fRotateSelected = false;
2845  fZoomInSelected = false;
2846  fZoomOutSelected = false;
2847 
2848  if (fToolbarApp == NULL) return;
2849  QList<QAction *> list = fToolbarApp->actions ();
2850  for (int i = 0; i < list.size(); ++i) {
2851  if (list.at(i)->data().toString () == "pick") {
2852  list.at(i)->setChecked(TRUE);
2853  } else if (list.at(i)->data().toString () == "move") {
2854  list.at(i)->setChecked(FALSE);
2855  } else if (list.at(i)->data().toString () == "rotate") {
2856  list.at(i)->setChecked(FALSE);
2857  } else if (list.at(i)->data().toString () == "zoom_in") {
2858  list.at(i)->setChecked(FALSE);
2859  } else if (list.at(i)->data().toString () == "zoom_out") {
2860  list.at(i)->setChecked(FALSE);
2861  }
2862  }
2863 }
2864 
2865 
2866 void G4UIWt::SetIconZoomInSelected() {
2867  // Theses actions should be in the app toolbar
2868  fZoomInSelected = true;
2869  fMoveSelected = false;
2870  fRotateSelected = false;
2871  fPickSelected = false;
2872  fZoomOutSelected = false;
2873 
2874  if (fToolbarApp == NULL) return;
2875  QList<QAction *> list = fToolbarApp->actions ();
2876  for (int i = 0; i < list.size(); ++i) {
2877  if (list.at(i)->data().toString () == "zoom_in") {
2878  list.at(i)->setChecked(TRUE);
2879  } else if (list.at(i)->data().toString () == "move") {
2880  list.at(i)->setChecked(FALSE);
2881  } else if (list.at(i)->data().toString () == "rotate") {
2882  list.at(i)->setChecked(FALSE);
2883  } else if (list.at(i)->data().toString () == "pick") {
2884  list.at(i)->setChecked(FALSE);
2885  } else if (list.at(i)->data().toString () == "zoom_out") {
2886  list.at(i)->setChecked(FALSE);
2887  }
2888  }
2889 }
2890 
2891 
2892 void G4UIWt::SetIconZoomOutSelected() {
2893  // Theses actions should be in the app toolbar
2894  fZoomOutSelected = true;
2895  fMoveSelected = false;
2896  fRotateSelected = false;
2897  fPickSelected = false;
2898  fZoomInSelected = false;
2899 
2900  if (fToolbarApp == NULL) return;
2901  QList<QAction *> list = fToolbarApp->actions ();
2902  for (int i = 0; i < list.size(); ++i) {
2903  if (list.at(i)->data().toString () == "zoom_out") {
2904  list.at(i)->setChecked(TRUE);
2905  } else if (list.at(i)->data().toString () == "move") {
2906  list.at(i)->setChecked(FALSE);
2907  } else if (list.at(i)->data().toString () == "rotate") {
2908  list.at(i)->setChecked(FALSE);
2909  } else if (list.at(i)->data().toString () == "pick") {
2910  list.at(i)->setChecked(FALSE);
2911  } else if (list.at(i)->data().toString () == "zoom_in") {
2912  list.at(i)->setChecked(FALSE);
2913  }
2914  }
2915 }
2916 
2917 
2918 void G4UIWt::SetIconSolidSelected() {
2919  // Theses actions should be in the app toolbar
2920 
2921  if (fToolbarApp == NULL) return;
2922  QList<QAction *> list = fToolbarApp->actions ();
2923  for (int i = 0; i < list.size(); ++i) {
2924  if (list.at(i)->data().toString () == "solid") {
2925  list.at(i)->setChecked(TRUE);
2926  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2927  list.at(i)->setChecked(FALSE);
2928  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2929  list.at(i)->setChecked(FALSE);
2930  } else if (list.at(i)->data().toString () == "wireframe") {
2931  list.at(i)->setChecked(FALSE);
2932  }
2933  }
2934 }
2935 
2936 
2937 void G4UIWt::SetIconWireframeSelected() {
2938  // Theses actions should be in the app toolbar
2939 
2940  if (fToolbarApp == NULL) return;
2941  QList<QAction *> list = fToolbarApp->actions ();
2942  for (int i = 0; i < list.size(); ++i) {
2943  if (list.at(i)->data().toString () == "wireframe") {
2944  list.at(i)->setChecked(TRUE);
2945  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2946  list.at(i)->setChecked(FALSE);
2947  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2948  list.at(i)->setChecked(FALSE);
2949  } else if (list.at(i)->data().toString () == "solid") {
2950  list.at(i)->setChecked(FALSE);
2951  }
2952  }
2953 }
2954 
2955 
2956 void G4UIWt::SetIconHLRSelected() {
2957  // Theses actions should be in the app toolbar
2958 
2959  if (fToolbarApp == NULL) return;
2960  QList<QAction *> list = fToolbarApp->actions ();
2961  for (int i = 0; i < list.size(); ++i) {
2962  if (list.at(i)->data().toString () == "hidden_line_removal") {
2963  list.at(i)->setChecked(TRUE);
2964  } else if (list.at(i)->data().toString () == "solid") {
2965  list.at(i)->setChecked(FALSE);
2966  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2967  list.at(i)->setChecked(FALSE);
2968  } else if (list.at(i)->data().toString () == "wireframe") {
2969  list.at(i)->setChecked(FALSE);
2970  }
2971  }
2972 }
2973 
2974 
2975 void G4UIWt::SetIconHLHSRSelected() {
2976  // Theses actions should be in the app toolbar
2977 
2978  if (fToolbarApp == NULL) return;
2979  QList<QAction *> list = fToolbarApp->actions ();
2980  for (int i = 0; i < list.size(); ++i) {
2981  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2982  list.at(i)->setChecked(TRUE);
2983  } else if (list.at(i)->data().toString () == "solid") {
2984  list.at(i)->setChecked(FALSE);
2985  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2986  list.at(i)->setChecked(FALSE);
2987  } else if (list.at(i)->data().toString () == "wireframe") {
2988  list.at(i)->setChecked(FALSE);
2989  }
2990  }
2991 }
2992 
2993 
2994 void G4UIWt::SetIconPerspectiveSelected() {
2995  // Theses actions should be in the app toolbar
2996 
2997  if (fToolbarApp == NULL) return;
2998  QList<QAction *> list = fToolbarApp->actions ();
2999  for (int i = 0; i < list.size(); ++i) {
3000  if (list.at(i)->data().toString () == "perspective") {
3001  list.at(i)->setChecked(TRUE);
3002  } else if (list.at(i)->data().toString () == "ortho") {
3003  list.at(i)->setChecked(FALSE);
3004  }
3005  }
3006 }
3007 
3008 
3009 
3010 void G4UIWt::SetIconOrthoSelected() {
3011  // Theses actions should be in the app toolbar
3012 
3013  if (fToolbarApp == NULL) return;
3014  QList<QAction *> list = fToolbarApp->actions ();
3015  for (int i = 0; i < list.size(); ++i) {
3016  if (list.at(i)->data().toString () == "ortho") {
3017  list.at(i)->setChecked(TRUE);
3018  } else if (list.at(i)->data().toString () == "perspective") {
3019  list.at(i)->setChecked(FALSE);
3020  }
3021  }
3022 }
3023 */
3024 
3025 
3032 void G4UIWt::FillHelpTree()
3033 {
3034  if (! fHelpTreeWidget ) {
3035  InitHelpTreeAndVisParametersWidget();
3036  }
3037 
3038  Wt::WString searchText = fHelpLine->text();
3039 
3040  if (searchText =="") {
3041  // clear old help tree
3042  // fHelpTreeWidget->clear();
3043  } else {
3044  return;
3045  }
3046 
3047  if (fHelpArea) {
3048  fHelpArea->setText("");
3049  }
3050 
3051  if (fHelpLine) {
3052  fHelpLine->setText("");
3053  }
3054 
3056  if(UI==NULL) return;
3057  G4UIcommandTree * treeTop = UI->GetTree();
3058 
3059  G4int treeSize = treeTop->GetTreeEntry();
3060  Wt::WTreeNode * newItem = NULL;
3061  Wt::WString commandText = "";
3062 
3063  for (int a=0;a<treeSize;a++) {
3064  // Creating new item
3065  newItem = NULL;
3066 
3067  // trim path
3068  std::string whiteSpaces( " \f\n\r\t\v" );
3069  std::string path = (treeTop->GetTree(a+1)->GetPathName()).data();
3070 
3071  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3072  path.erase( posR + 1 );
3073 
3074  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3075  path.erase( 0, posL );
3076 
3077  commandText = Wt::WString(path.c_str());
3078 
3079  // if already exist, don't create it !
3080  if (fHelpTreeWidget->treeRoot()) {
3081  for (int b=0;b<fHelpTreeWidget->treeRoot()->displayedChildCount();b++) {
3082  if (!newItem)
3083  newItem = FindTreeItem(fHelpTreeWidget->treeRoot()->childNodes()[b],path.c_str());
3084  }
3085  }
3086  if (newItem == NULL) {
3087  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0);
3088  fHelpTreeWidget->setTreeRoot(newItem);
3089  }
3090 
3091  // look for childs
3092  CreateHelpTree(newItem,treeTop->GetTree(a+1));
3093  }
3094 
3095 }
3096 
3097 
3098 
3107 void G4UIWt::PauseSessionStart (
3108  const G4String& aState
3109  )
3110 {
3111  if (!aState) return;
3112 
3113  if(aState=="G4_pause> ") { // TO KEEP
3114  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
3115  } // TO KEEP
3116 
3117  if(aState=="EndOfEvent") { // TO KEEP
3118  // Picking with feed back in event data Done here !!!
3119  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
3120  } // TO KEEP
3121 }
3122 
3123 
3124 
3125 
3126 
3127 
3128 
3129 
3130 void G4UIWt::ActivateCommand(
3131  G4String newCommand
3132  )
3133 {
3134  if (!fHelpTreeWidget) {
3135  return;
3136  }
3137  // Look for the choosen command "newCommand"
3138  size_t i = newCommand.index(" ");
3139  G4String targetCom ="";
3140  if( i != std::string::npos )
3141  {
3142  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
3143  newValue.strip(G4String::both);
3144  targetCom = ModifyToFullPathCommand( newValue );
3145  }
3146 #ifdef G4DEBUG_INTERFACES_BASIC
3147  printf("G4UIWt::ActivateCommand found : %s \n",targetCom.data());
3148 #endif
3149  if (targetCom != "") {
3150  OpenHelpTreeOnCommand(targetCom.data());
3151  }
3152 
3153  fUITabWidget->setCurrentWidget(fHelpTBWidget);
3154 }
3155 
3156 
3157 
3164 void G4UIWt::InitHelpTreeAndVisParametersWidget()
3165 {
3166 
3167  if (! fHelpTreeWidget ) {
3168  fHelpTreeWidget = new Wt::WTree();
3169  }
3170 
3171  // build widget
3172  fHelpTreeWidget->setSelectionMode(Wt::SingleSelection);
3173 
3174  fHelpTreeWidget->itemSelectionChanged ().connect(this,&G4UIWt::HelpTreeClicCallback);
3175 }
3176 
3177 
3182 void G4UIWt::CreateHelpTree(
3183  Wt::WTreeNode *aParent
3184  ,G4UIcommandTree *aCommandTree
3185  )
3186 {
3187  if (aParent == NULL) return;
3188  if (aCommandTree == NULL) return;
3189 
3190 
3191  // Creating new item
3192  Wt::WTreeNode * newItem;
3193 
3194  Wt::WString commandText = "";
3195  // Get the Sub directories
3196  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3197 
3198  // trim path
3199  std::string whiteSpaces( " \f\n\r\t\v" );
3200  std::string path = (aCommandTree->GetTree(a+1)->GetPathName()).data();
3201 
3202  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3203  path.erase( posR + 1 );
3204 
3205  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3206  path.erase( 0, posL );
3207 
3208  commandText = Wt::WString(path.c_str());
3209 
3210  // if already exist, don't create it !
3211  newItem = FindTreeItem(aParent,path.c_str());
3212  if (newItem == NULL) {
3213  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3214  }
3215  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
3216  }
3217 
3218  // Get the Commands
3219 
3220  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3221 
3222  // trim path
3223  std::string whiteSpaces( " \f\n\r\t\v" );
3224  std::string path = (aCommandTree->GetCommand(a+1)->GetCommandPath()).data();
3225 
3226  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3227  path.erase( posR + 1 );
3228 
3229  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3230  path.erase( 0, posL );
3231 
3232  commandText = Wt::WString(path.c_str());
3233 
3234  // if already exist, don't create it !
3235  newItem = FindTreeItem(aParent,path.c_str());
3236  if (newItem == NULL) {
3237 
3238  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3239 
3240  newItem->collapse();
3241  }
3242  }
3243 }
3244 
3245 
3246 
3247 
3248 
3249 
3250 
3255 Wt::WTreeNode* G4UIWt::FindTreeItem(
3256  Wt::WTreeNode *aParent
3257  ,const std::string& aCommand
3258  )
3259 {
3260  if (aParent == NULL) return NULL;
3261 
3262  // Suppress last "/"
3263  std::string myCommand = aCommand;
3264 
3265 
3266  if (myCommand.rfind("/") == (myCommand.size()-1)) {
3267  myCommand = myCommand.substr(0,myCommand.size()-1);
3268  }
3269 
3270  if (GetLongCommandPath(aParent) == Wt::WString(myCommand.c_str()))
3271  return aParent;
3272 
3273  Wt::WTreeNode * tmp = NULL;
3274  for (unsigned int a=0;a<aParent->childNodes().size();a++) {
3275  if (!tmp)
3276  tmp = FindTreeItem(aParent->childNodes().at(a),myCommand);
3277  }
3278  return tmp;
3279 }
3280 
3281 
3282 
3290 Wt::WString G4UIWt::GetCommandList (
3291  const G4UIcommand *aCommand
3292  )
3293 {
3294 
3295  Wt::WString txt ="";
3296  if (aCommand == NULL)
3297  return txt;
3298 
3299  G4String commandPath = aCommand->GetCommandPath();
3300  G4String rangeString = aCommand->GetRange();
3301  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
3302  G4int n_parameterEntry = aCommand->GetParameterEntries();
3303 
3304  if ((commandPath == "") &&
3305  (rangeString == "") &&
3306  (n_guidanceEntry == 0) &&
3307  (n_parameterEntry == 0)) {
3308  return txt;
3309  }
3310 
3311  if((commandPath.length()-1)!='/') {
3312  txt += "Command " + Wt::WString((char*)(commandPath).data()) + "\n";
3313  }
3314  txt += "Guidance :\n";
3315 
3316  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3317  txt += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
3318  }
3319  if( ! rangeString.isNull() ) {
3320  txt += " Range of parameters : " + Wt::WString((char*)(rangeString).data()) + "\n";
3321  }
3322  if( n_parameterEntry > 0 ) {
3323  G4UIparameter *param;
3324 
3325  // Re-implementation of G4UIparameter.cc
3326 
3327  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3328  param = aCommand->GetParameter(i_thParameter);
3329  txt += "\nParameter : " + Wt::WString((char*)(param->GetParameterName()).data()) + "\n";
3330  if( ! param->GetParameterGuidance().isNull() )
3331  txt += Wt::WString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
3332  char myChar = param->GetParameterType();
3333  txt += " Parameter type : " + Wt::WString(&myChar) + "\n";
3334  if(param->IsOmittable()){
3335  txt += " Omittable : True\n";
3336  } else {
3337  txt += " Omittable : False\n";
3338  }
3339  if( param->GetCurrentAsDefault() ) {
3340  txt += " Default value : taken from the current value\n";
3341  } else if( ! param->GetDefaultValue().isNull() ) {
3342  txt += " Default value : " + Wt::WString((char*)(param->GetDefaultValue()).data())+ "\n";
3343  }
3344  if( ! param->GetParameterRange().isNull() ) {
3345  txt += " Parameter range : " + Wt::WString((char*)(param->GetParameterRange()).data())+ "\n";
3346  }
3347  if( ! param->GetParameterCandidates().isNull() ) {
3348  txt += " Candidates : " + Wt::WString((char*)(param->GetParameterCandidates()).data())+ "\n";
3349  }
3350  }
3351  }
3352  return txt;
3353 }
3354 
3355 
3361 G4bool G4UIWt::IsGUICommand(
3362  const G4UIcommand *aCommand
3363  )
3364 {
3365  if (aCommand == NULL)
3366  return false;
3367 
3368  G4int n_parameterEntry = aCommand->GetParameterEntries();
3369 
3370  if( n_parameterEntry > 0 ) {
3371  G4UIparameter *param;
3372 
3373  // Re-implementation of G4UIparameter.cc
3374 
3375  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3376  param = aCommand->GetParameter(i_thParameter);
3377  char myChar = param->GetParameterType();
3378  if (myChar == 'd') {
3379  return true;
3380  }
3381  if (myChar == 'b') {
3382  return true;
3383  }
3384  if (myChar == 'i') {
3385  return true;
3386  }
3387  if (myChar == 's' && (!param->GetParameterCandidates().isNull())) {
3388  return true;
3389  }
3390  }
3391  }
3392  return false;
3393 }
3394 
3395 
3399 G4bool G4UIWt::GetHelpChoice(
3400  G4int&
3401  )
3402 {
3403 #ifdef G4DEBUG_INTERFACES_BASIC
3404  printf("G4UIWt::GetHelpChoice SHOULD NEVER GO HERE");
3405 #endif
3406  return true;
3407 }
3408 
3409 
3410 
3411 
3412 
3413 /***************************************************************************/
3414 //
3415 // SLOTS DEFINITIONS
3416 //
3417 /***************************************************************************/
3418 
3421 void G4UIWt::ShowHelpCallback (
3422 )
3423 {
3424  TerminalHelp("");
3425 }
3426 
3427 
3430 void G4UIWt::ClearButtonCallback (
3431 )
3432 {
3433  fCoutTBTextArea->setText("");
3434  fG4cout.removeRows(0,fG4cout.rowCount());
3435 }
3436 
3439 void G4UIWt::ExitSession (
3440 )
3441 {
3442  SessionTerminate();
3443 }
3444 
3445 void G4UIWt::ExitHelp(
3446 ) const
3447 {
3448 }
3449 
3450 
3451 
3452 
3458 void G4UIWt::ButtonCallback (
3459  const char* aCommand
3460  )
3461 {
3462  G4String ss = G4String(aCommand);
3463  ss = ss.strip(G4String::leading);
3464 
3466  if(UI==NULL) return;
3467  G4UIcommandTree * treeTop = UI->GetTree();
3468 
3469  G4UIcommand* command = treeTop->FindPath(ss);
3470 
3471  if (command) {
3472  // if is GUI, then open a dialog
3473  if (IsGUICommand(command)) {
3474  Wt::WDialog* menuParameterDialog = new Wt::WDialog();
3475 
3476  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
3477  menuParameterDialog->setWindowTitle (aCommand);
3478 
3479  // exec this dialog, apply the command automaticaly, and return
3480  menuParameterDialog->exec();
3481  return;
3482  }
3483  }
3484  }
3485 
3486  ApplyShellCommand(ss,fExitSession,fExitPause);
3487 
3488  // Rebuild help tree
3489  FillHelpTree();
3490 
3491  if(fExitSession==true)
3492  SessionTerminate();
3493 }
3494 
3495 
3496 
3497 
3498 
3503 void G4UIWt::LookForHelpStringCallback(
3504 )
3505 {
3506  Wt::WString searchText = fHelpLine->text();
3507 
3508  fHelpArea->setText("");
3509  if (searchText =="") {
3510  // clear old help tree
3511  fHelpTreeWidget = new Wt::WTree();
3512 
3513  FillHelpTree();
3514 
3515  return;
3516  } else {
3517  OpenHelpTreeOnCommand(searchText);
3518  }
3519 }
3520 
3521 
3522 
3523 
3524 Wt::WString G4UIWt::GetShortCommandPath(
3525  const std::string& aTxt
3526  )
3527 {
3528  std::string commandPath;
3529  if (aTxt.find("/", 0) != std::string::npos) {
3530  // commandPath = commandPath.right(commandPath.size()-1);
3531  commandPath = aTxt.substr(aTxt.size()-1);
3532  }
3533 
3534  // commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3535  commandPath = commandPath.substr(commandPath.size()-commandPath.rfind("/",-2)-1);
3536 
3537  // if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3538  if (commandPath.rfind("/") == (commandPath.size()-1)) {
3539  // commandPath = commandPath.left(commandPath.size()-1);
3540  commandPath = commandPath.substr(0,commandPath.size()-1);
3541  }
3542 
3543  return commandPath.c_str();
3544 }
3545 
3546 
3547 Wt::WString G4UIWt::GetLongCommandPath(
3548  Wt::WTreeNode* item
3549  )
3550 {
3551  if (item == NULL) return "";
3552 
3553  // rebuild path:
3554  Wt::WString itemText = "";
3555  itemText = item->label()->text();
3556 
3557  while (item->parentNode() != NULL) {
3558  itemText = item->parentNode()->label()->text()+"/"+itemText;
3559  item = item->parentNode();
3560  }
3561  itemText = "/"+itemText;
3562 
3563  return itemText;
3564 }
3565 
3566 
3567 
3568 
3569 
3570 
3571 
3572 
3573 
3574 
3575 
3576 
3577 G4WTabWidget::G4WTabWidget(
3578  Wt::WContainerWidget*& /* split */
3579 ):
3580  Wt::WTabWidget()
3581 ,tabSelected(false)
3582 ,lastCreated(-1)
3583 {
3584 }
3585 
3586 G4WTabWidget::G4WTabWidget(
3587 ):Wt::WTabWidget()
3588 ,tabSelected(false)
3589 ,lastCreated(-1)
3590 {
3591 }
3592 
3593 
3594 
3595 void G4UIWt::TabCloseCallback(int a){
3596  Wt::WWidget* temp = fViewerTabWidget->widget(a);
3597  fViewerTabWidget->removeTab (temp);
3598 
3599  delete temp;
3600 
3601  if (fViewerTabWidget->count() == 0) {
3602  fEmptyViewerTabLabel->show();
3603  }
3604 
3605 }
3606 
3607 
3608 void G4UIWt::ToolBoxActivated(int a){
3609 
3610  if (fUITabWidget->widget(a) == fHelpTBWidget) {
3611  // Rebuild the help tree
3612  FillHelpTree();
3613  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3614  fSceneTreeComponentsTBWidget->hide();
3615  }
3616 }
3617 
3618 
3619 #endif
G4UIcommandTree * FindCommandTree(const char *commandPath)
Try to match a command or a path with the one given.
G4String GetParameterCandidates() const
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String name
Definition: TRTMaterials.hh:40
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4double a
Definition: TRTMaterials.hh:39
G4int GetVerboseLevel() const
Definition: G4UImanager.hh:227
void SetSession(G4UIsession *const value)
Definition: G4UImanager.hh:213
int G4int
Definition: G4Types.hh:78
const G4String & GetGuidanceLine(G4int i) const
Definition: G4UIcommand.hh:137
void SetG4UIWindow(G4UIsession *const value)
Definition: G4UImanager.hh:215
static G4UImanager * GetUIpointer()
Definition: G4UImanager.cc:58
G4bool IsOmittable() const
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
bool G4bool
Definition: G4Types.hh:79
G4UIparameter * GetParameter(G4int i) const
Definition: G4UIcommand.hh:145
const G4String & GetCommandPath() const
Definition: G4UIcommand.hh:139
const G4String GetPathName() const
const char * data() const
const G4String GetTitle() const
G4UIcommandTree * GetTree() const
Definition: G4UImanager.hh:206
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
Definition: G4UImanager.cc:604
char GetParameterType() const
#define G4endl
Definition: G4ios.hh:61
const G4String GetParameterGuidance() const
G4UImanager * UI
Definition: G4UIterminal.hh:73
G4String GetParameterRange() const
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool GetCurrentAsDefault() const
G4bool isNull() const
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:432