Geant4_10
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
438  ,int
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  if (!aWidget) {
477  return false;
478  }
479 
480  // Remove Wt::WLabel
481 
482  // L.Garnier 26/05/2010 : not exactly the same in qt3. Could cause some
483  // troubles
484 
485 
486  // Problems with resize. The widgets are not realy drawn at this step,
487  // then we have to force them on order to check the size
488 
489  fViewerTabWidget->addTab(aWidget,name);
490 
491  // Change Color
492  aWidget->decorationStyle().setBackgroundColor (Wt::WColor(245,245,245));
493 
494  fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
495 
496  // Set visible
497  fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
498 
499  return true;
500 }
501 
502 
503 
504 void G4UIWt::CurrentChangedTabWidgetCallback(int tabNumber) {
505 #ifdef G4DEBUG_INTERFACES_BASIC
506  printf("G4UIWt::CurrentChangedTabWidget %d\n",tabNumber);
507 #endif
508  if ( fViewerTabWidget == NULL) {
509  fViewerTabWidget = new G4WTabWidget;
510  }
511 
512 #ifdef G4DEBUG_INTERFACES_BASIC
513  printf("G4UIWt::CurrentChangedTabWidget CALL REPAINT tabGL\n");
514 #endif
515 
516  fViewerTabWidget->setCurrentIndex(tabNumber);
517 
518  // Send this signal to unblock graphic updates !
519  fViewerTabWidget->setTabSelected(false);
520 
521  fViewerTabWidget->show();
522 
523  // This will send a paintEvent to OGL Viewers
524  fViewerTabWidget->setTabSelected(true);
525 
526 
527  Wt::WString text = fViewerTabWidget->tabText (tabNumber);
528 
529  Wt::WString paramSelect = Wt::WString("/vis/viewer/select ")+text;
531  if(UI != NULL) {
532  UI->ApplyCommand(paramSelect.toUTF8().c_str());
533  }
534 }
535 
536 
539 G4UIsession* G4UIWt::SessionStart (
540 )
541 {
542 #ifdef G4DEBUG_INTERFACES_BASIC
543  printf("G4UIWt::G4UIWt SessionStart 1\n");
544 #endif
545 
546  G4Wt* interactorManager = G4Wt::getInstance ();
547 
548  Prompt("Session :");
549  exitSession = false;
550 
551  fMainWindow->show();
552 
553 #ifdef G4DEBUG_INTERFACES_BASIC
554  printf("G4UIWt::G4UIWt SessionStart2\n");
555 #endif
556  interactorManager->DisableSecondaryLoop (); // TO KEEP
557 // if ((Wt::WApplication*)interactorManager->GetMainInteractor())
558 // ((Wt::WApplication*)interactorManager->GetMainInteractor())->exec();
559 
560  // on ne passe pas le dessous ? FIXME ????
561  // je ne pense pas 13/06
562 
563  // void* event; // TO KEEP
564  // while((event = interactorManager->GetEvent())!=NULL) { // TO KEEP
565  // interactorManager->DispatchEvent(event); // TO KEEP
566  // if(exitSession==true) break; // TO KEEP
567  // } // TO KEEP
568 
569  interactorManager->EnableSecondaryLoop ();
570  return this;
571 
572 }
573 
574 
580 void G4UIWt::Prompt (
581  G4String aPrompt
582  )
583 {
584  if (!aPrompt) return;
585  if (!fCommandLabel) return;
586 
587  fCommandLabel->setText((char*)aPrompt.data());
588 }
589 
590 
591 
592 void G4UIWt::SessionTerminate (
593 )
594 {
595  G4Wt* interactorManager = G4Wt::getInstance ();
596 
597  if ((Wt::WApplication*)interactorManager->GetMainInteractor()) {
598  // What to do here ?
599  }
600 }
601 
602 
603 
608 void G4UIWt::SecondaryLoop (
609  G4String aPrompt
610  )
611 {
612  if (!aPrompt) return;
613 
614  G4Wt* interactorManager = G4Wt::getInstance (); // TO KEEP ?
615  Prompt(aPrompt); // TO KEEP
616  fExitPause = false; // TO KEEP
617  void* eventTmp; // TO KEEP
618  while((eventTmp = interactorManager->GetEvent())!=NULL) { // TO KEEP
619  interactorManager->DispatchEvent(eventTmp); // TO KEEP
620  if(fExitPause==true) break; // TO KEEP
621  } // TO KEEP
622  Prompt("Session :"); // TO KEEP
623 }
624 
625 
629 void G4UIWt::CommandEnteredCallback (
630 )
631 {
632 #ifdef G4DEBUG_INTERFACES_BASIC
633  printf("G4UIWt::CommandEnteredCallback\n");
634 #endif
635 #ifdef G4DEBUG_INTERFACES_BASIC
636  printf("G4UIWt::CommandEnteredCallback 1\n");
637 #endif
638  G4String command (fCommandArea->text().toUTF8());
639  if (fCommandArea->text() != "") {
640 
641  printf("*** G4UIWt::CommandEnteredCallback, missing update on history \n");
642  /* FIXME
643  fHistoryTBTableList->addItem(fCommandArea->text());
644  fHistoryTBTableList->clearSelection();
645  fHistoryTBTableList->setCurrentIndex(0);
646 */
647  fCommandArea->setText("");
648 #ifdef G4DEBUG_INTERFACES_BASIC
649  printf("G4UIWt::CommandEnteredCallback 2\n");
650 #endif
651 
652  G4Wt* interactorManager = G4Wt::getInstance ();
653 #ifdef G4DEBUG_INTERFACES_BASIC
654  printf("G4UIWt::CommandEnteredCallback 3\n");
655 #endif
656  if (interactorManager) {
657  interactorManager->FlushAndWaitExecution();
658  }
659 #ifdef G4DEBUG_INTERFACES_BASIC
660  printf("G4UIWt::CommandEnteredCallback 4\n");
661 #endif
662  if (command(0,4) != "help") {
663  ApplyShellCommand (command,exitSession,exitPause);
664  } else {
665  ActivateCommand(command);
666  }
667 #ifdef G4DEBUG_INTERFACES_BASIC
668  printf("G4UIWt::CommandEnteredCallback 5\n");
669 #endif
670  // Rebuild help tree
671  FillHelpTree();
672 
673 #ifdef G4DEBUG_INTERFACES_BASIC
674  printf("G4UIWt::CommandEnteredCallback 6\n");
675 #endif
676  if(exitSession==true)
677  SessionTerminate();
678  }
679 #ifdef G4DEBUG_INTERFACES_BASIC
680  printf("G4UIWt::CommandEnteredCallback END\n");
681 #endif
682 
683  }
684 
685 
692 void G4UIWt::AddButton (
693  const char* aMenu
694  ,const char* aLabel
695  ,const char* aCommand
696  )
697 {
698  if(aMenu==NULL) return; // TO KEEP
699  if(aLabel==NULL) return; // TO KEEP
700  if(aCommand==NULL) return; // TO KEEP
701 
702  Wt::WMenu *parentTmp = (Wt::WMenu*)GetInteractor(aMenu);
703 
704  if(parentTmp==NULL) {
705  G4UImanager* UImanager = G4UImanager::GetUIpointer();
706  G4int verbose = UImanager->GetVerboseLevel();
707 
708  if (verbose >= 2) {
709  G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
710  }
711  return;
712  }
713 
714  // Find the command in the command tree
716  if(UI==NULL) return;
717  G4UIcommandTree * treeTop = UI->GetTree();
718 
719  G4String cmd = aCommand;
720  G4int cmdEndPos = cmd.find_first_of(" \t");
721  if(cmdEndPos!=G4int(std::string::npos)) {
722  cmd.erase(cmdEndPos);
723  }
724 
725  if(treeTop->FindPath(aCommand) == NULL) {
726  G4UImanager* UImanager = G4UImanager::GetUIpointer();
727  G4int verbose = UImanager->GetVerboseLevel();
728 
729  if (verbose >= 2) {
730  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
731  }
732  }
733 
734  printf("*** G4UIWt::AddButton, missing connection on menu callback \n");
735 /* FIXME
736  QSignalMapper *signalMapper = new QSignalMapper(this);
737  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));
738 
739  connect(signalMapper, SIGNAL(mapped(const char*)),this, SLOT(ButtonCallback(const char*)));
740  signalMapper->setMapping(action, aCommand);
741 */
742 }
743 
744 
748 void G4UIWt::AddIcon(const char* aLabel, const char* aIconFile, const char* aCommand, const char* /* aFileName */ ){
749  if(aLabel==NULL) return; // TO KEEP
750  // special case, aCommand could be NULL if aIconFile is not user_icon
751  if (aCommand==NULL) {
752  if (std::string(aIconFile) == "user_icon") {
753  return; // TO KEEP
754  }
755  }
756  printf("*** G4UIWt::AddIcon, missing icon creation \n");
757 /*
758  QPixmap pix;
759  bool userToolBar = false;
760 
761  if (std::string(aIconFile) == "user_icon") {
762  // try to open a file
763  pix = QPixmap(aFileName);
764  if (pix.isNull()) {
765  G4UImanager* UImanager = G4UImanager::GetUIpointer();
766  G4int verbose = UImanager->GetVerboseLevel();
767 
768  if (verbose >= 2) {
769  G4cout << "Warning: file '"<< aFileName <<"' is incorrect or does not exist, this command will not be build"<< G4endl;
770  }
771  return;
772  }
773  userToolBar = true;
774  } else if (std::string(aIconFile) == "open") {
775  const char * const xpm[]={
776  "32 32 33 1",
777  " c None",
778  "+ c #09091E",
779  "@ c #191B18",
780  "# c #5F615F",
781  "$ c #777977",
782  "% c #AEB1AF",
783  "& c #929491",
784  "* c #515250",
785  "= c #858784",
786  "- c #333533",
787  "; c #000100",
788  "> c #272926",
789  ", c #424341",
790  "' c #696C6A",
791  ") c #5F4927",
792  "! c #583D18",
793  "~ c #6E6A5B",
794  "{ c #47351D",
795  "] c #E0A554",
796  "^ c #FFD67B",
797  "/ c #EFB465",
798  "( c #FDBF6C",
799  "_ c #FFCD76",
800  ": c #806238",
801  "< c #362611",
802  "[ c #0B0D0A",
803  "} c #68471B",
804  "| c #523E22",
805  "1 c #B78A51",
806  "2 c #A17B44",
807  "3 c #D6A45E",
808  "4 c #C29354",
809  "5 c #A1A3A0",
810  " ",
811  " ",
812  " +@@@# ",
813  " $% +& * ",
814  " #= $ -; ",
815  " %>;+ ",
816  " ,;;+ ",
817  " &#$''#' >;;;+ ",
818  " =)!)!!!!~ *#$'' ",
819  " {]^/((_({- %%%%%%%%%%% ",
820  " {(^_^^^^:<{{{{{{{{{{{{{[& ",
821  " {/_/(((((/]]]]]]]]]]]/]!# ",
822  " {/^(((((_^^^^^^^^^^^^^^:# ",
823  " {/^(((_^^____________^^}$ ",
824  " {/^(((((/////////////((!# ",
825  " {/^/^_:<|||||||||||||||@@****1 ",
826  " {/^/^(<[)||||||||||||||))!!}<; ",
827  " {/^_(:|234444444444444444432)1 ",
828  " {/_^/<)34444444444444444443}, ",
829  " {/^(2{:41111111111111111142|5 ",
830  " {3^3<:31111111111111111143}- ",
831  " {/^2<:31111111111111111441|' ",
832  " {_/<:41111111111111111143}, ",
833  " {(4<:31111111111111111144!# ",
834  " )4))44111111111111111144}, ",
835  " )2<:31111111111111111144{# ",
836  " @|:14444444444444444444}* ",
837  " ;@434444444444444444434<# ",
838  " ;[))))))))))))))))))))!~ ",
839  " ++++++++++++++++++++++;% ",
840  " ",
841  " "}
842  ;
843  pix = QPixmap(xpm);
844 
845  } else if (std::string(aIconFile) == "save") {
846  const char * const xpm[]={
847  "32 32 24 1",
848  " c None",
849  "+ c #000200",
850  "@ c #141E43",
851  "# c #000C56",
852  "$ c #494A47",
853  "% c #636662",
854  "& c #312F2A",
855  "* c #191B19",
856  "= c #002992",
857  "- c #003DFF",
858  "; c #041DA5",
859  "> c #A8A9A3",
860  ", c #FDFFFC",
861  "' c #DDE0DD",
862  ") c #818783",
863  "! c #C9CBC8",
864  "~ c #0116C3",
865  "{ c #C5C8FA",
866  "] c #6596FC",
867  "^ c #A0B4F9",
868  "/ c #0B2AFD",
869  "( c #799BE3",
870  "_ c #5F4826",
871  ": c #D5D8D5",
872  " ",
873  " ",
874  " +++++++++++++++++++++++++ ",
875  " +@##+$%%%%%%%%%%%%%%%&*$%&+ ",
876  " +=-;@>,,''',,,,,,,',,)&!,)+ ",
877  " +;-~@>,,,,,,,,,,,,,,,>$!,)+ ",
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  pix = QPixmap(xpm);
906  } else if (std::string(aIconFile) == "move") {
907  const char * const xpm[]={
908  "32 32 16 1",
909  " c None",
910  ". c #F1F1F1",
911  "+ c #939393",
912  "@ c #282828",
913  "# c #787878",
914  "$ c #000000",
915  "% c #CCCCCC",
916  "& c #1A1A1A",
917  "* c #0D0D0D",
918  "= c #5D5D5D",
919  "- c #AEAEAE",
920  "; c #BBBBBB",
921  "> c #C9C9C9",
922  ", c #D6D6D6",
923  "' c #FFFFFF",
924  ") c #999999",
925  " ",
926  " ",
927  " ",
928  " ",
929  " .. ",
930  " ++ ",
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  pix = QPixmap(xpm);
959 
960  } else if (std::string(aIconFile) == "rotate") {
961  const char * const xpm[]={
962  "32 32 27 1",
963  " c None",
964  ". c #003333",
965  "+ c #000066",
966  "@ c #1A1A1A",
967  "# c #003399",
968  "$ c #3333CC",
969  "% c #000033",
970  "& c #353535",
971  "* c #434343",
972  "= c #336699",
973  "- c #3399FF",
974  "; c #003366",
975  "> c #5D5D5D",
976  ", c #282828",
977  "' c #3399CC",
978  ") c #333333",
979  "! c #3366CC",
980  "~ c #333399",
981  "{ c #505050",
982  "] c #666666",
983  "^ c #333366",
984  "/ c #0033CC",
985  "( c #3366FF",
986  "_ c #336666",
987  ": c #787878",
988  "< c #868686",
989  "[ c #6B6B6B",
990  " .++@ ",
991  " #$$%&* ",
992  " =--; *>, ",
993  " '-= )>& ",
994  " !-', ,>* ",
995  " !!=--= >* ",
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  pix = QPixmap(xpm);
1024 
1025  } else if (std::string(aIconFile) == "pick") {
1026  const char * const xpm[]={
1027  "32 32 2 1",
1028  " c None",
1029  ". c #000000",
1030  " ",
1031  " ",
1032  " ",
1033  " ",
1034  " ",
1035  " ",
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  pix = QPixmap(xpm);
1064  } else if (std::string(aIconFile) == "zoom_in") {
1065  const char * const xpm[]={
1066  "32 32 11 1",
1067  " c None",
1068  ". c #C9CBC8",
1069  "+ c #A8A9A3",
1070  "@ c #818783",
1071  "# c #D5D8D5",
1072  "$ c #9BCCCC",
1073  "% c #5FC7F4",
1074  "& c #FDFFFC",
1075  "* c #636662",
1076  "= c #9599CE",
1077  "- c #DDE0DD",
1078  " ",
1079  " ",
1080  " ",
1081  " ",
1082  " ",
1083  " .++@@++. ",
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  pix = QPixmap(xpm);
1112  } else if (std::string(aIconFile) == "zoom_out") {
1113  const char * const xpm[]={
1114  "32 32 11 1",
1115  " c None",
1116  ". c #C9CBC8",
1117  "+ c #A8A9A3",
1118  "@ c #818783",
1119  "# c #D5D8D5",
1120  "$ c #5FC7F4",
1121  "% c #9BCCCC",
1122  "& c #FDFFFC",
1123  "* c #636662",
1124  "= c #9599CE",
1125  "- c #DDE0DD",
1126  " ",
1127  " ",
1128  " ",
1129  " ",
1130  " ",
1131  " .++@@++. ",
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  pix = QPixmap(xpm);
1160  } else if (std::string(aIconFile) == "wireframe") {
1161  const char * const xpm[]={
1162  "32 32 24 1",
1163  " c None",
1164  "+ c #E4E4E4",
1165  "@ c #D5D5D5",
1166  "# c #E1E1E1",
1167  "$ c #E7E7E7",
1168  "% c #D8D8D8",
1169  "& c #A7A7A7",
1170  "* c #000000",
1171  "= c #989898",
1172  "- c #8A8A8A",
1173  "; c #B5B5B5",
1174  "> c #1B1B1B",
1175  ", c #676767",
1176  "' c #959595",
1177  ") c #4A4A4A",
1178  "! c #878787",
1179  "~ c #D3D3D3",
1180  "{ c #C4C4C4",
1181  "] c #A4A4A4",
1182  "^ c #5B5B5B",
1183  "/ c #B3B3B3",
1184  "( c #787878",
1185  "_ c #C7C7C7",
1186  ": c #585858",
1187  " ",
1188  " +@@# ",
1189  " $%@@@@@&****=+ ",
1190  " +&********&@-***; ",
1191  " +@@@&**&@@@@@@$ @*-&>&+ ",
1192  " +*****&+ %*@ ,**'# ",
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  pix = QPixmap(xpm);
1221  } else if (std::string(aIconFile) == "solid") {
1222  const char * const xpm[]={
1223  "32 32 33 1",
1224  " c None",
1225  "+ c #C2DEDE",
1226  "@ c #B5D7DF",
1227  "# c #ACD6E6",
1228  "$ c #60C0EC",
1229  "% c #4EB7EE",
1230  "& c #53B9ED",
1231  "* c #82CEEA",
1232  "= c #CFDDDA",
1233  "- c #94C9E8",
1234  "; c #0960FF",
1235  "> c #0943FF",
1236  ", c #0949FF",
1237  "' c #3CB3F0",
1238  ") c #71C7EB",
1239  "! c #73CBE5",
1240  "~ c #D3DDDB",
1241  "{ c #C4DDDE",
1242  "] c #B7D5DF",
1243  "^ c #2DACF5",
1244  "/ c #59C1ED",
1245  "( c #5FC0ED",
1246  "_ c #85CEE9",
1247  ": c #096BFF",
1248  "< c #2AACF6",
1249  "[ c #5CBEEC",
1250  "} c #7ACAE4",
1251  "| c #73CAEB",
1252  "1 c #71C8E5",
1253  "2 c #D1DDDA",
1254  "3 c #CBDDD9",
1255  "4 c #67C1EB",
1256  "5 c #80CDEA",
1257  " ",
1258  " ",
1259  " +@@@@@@#$%&*= ",
1260  " +-;>>>>>>>>>,')!~ ",
1261  " {]@@-;>>>>>>>>>>>>^/(_= ",
1262  " {:>>>>>>>>>>>>>>>>><//[)!= ",
1263  " ]>>>>>>>>>>>>>>>>>><////[)} ",
1264  " @>>>>>>>>>>>>>>>>>><//////| ",
1265  " @>>>>>>>>>>>>>>>>>><//////| ",
1266  " @>>>>>>>>>>>>>>>>>><//////| ",
1267  " @>>>>>>>>>>>>>>>>>><//////| ",
1268  " @>>>>>>>>>>>>>>>>>><//////| ",
1269  " @>>>>>>>>>>>>>>>>>><//////| ",
1270  " @>>>>>>>>>>>>>>>>>><//////| ",
1271  " @>>>>>>>>>>>>>>>>>><//////| ",
1272  " @>>>>>>>>>>>>>>>>>><//////| ",
1273  " @>>>>>>>>>>>>>>>>>><//////| ",
1274  " @>>>>>>>>>>>>>>>>>><//////| ",
1275  " @>>>>>>>>>>>>>>>>>><//////| ",
1276  " @>>>>>>>>>>>>>>>>>><//////| ",
1277  " @>>>>>>>>>>>>>>>>>><//////| ",
1278  " @>>>>>>>>>>>>>>>>>></////[1 ",
1279  " @>>>>>>>>>>>>>>>>>><////[*2 ",
1280  " {:>>>>>>>>>>>>>>>>><//[)12 ",
1281  " +@@@@@-;>>>>>>>>>><[)13 ",
1282  " {]@@@-;>>>,'*3 ",
1283  " +@@#452 ",
1284  " ",
1285  " ",
1286  " ",
1287  " ",
1288  " "}
1289  ;
1290  pix = QPixmap(xpm);
1291  } else if (std::string(aIconFile) == "hidden_line_removal") {
1292  const char * const xpm[]={
1293  "32 32 15 1",
1294  " c None",
1295  "+ c #D5D5D5",
1296  "@ c #C7C7C7",
1297  "# c #9C9C9C",
1298  "$ c #000000",
1299  "% c #8E8E8E",
1300  "& c #808080",
1301  "* c #A9A9A9",
1302  "= c #D8D8D8",
1303  "- c #CACACA",
1304  "; c #181818",
1305  "> c #9F9F9F",
1306  ", c #ACACAC",
1307  "' c #B9B9B9",
1308  ") c #555555",
1309  " ",
1310  " +@@+ ",
1311  " +@@@@@@#$$$$%+ ",
1312  " +#$$$$$$$$#@&$$$* ",
1313  " =-@@#$$#@@@@@-= @$&#;>= ",
1314  " =$$$$$#+ -$@ *$$%+ ",
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  pix = QPixmap(xpm);
1343  } else if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1344  const char * const xpm[]={
1345  "32 32 40 1",
1346  " c None",
1347  "+ c #FFFFFF",
1348  "@ c #89A2E9",
1349  "# c #5378E3",
1350  "$ c #A2B5ED",
1351  "% c #5379E3",
1352  "& c #5076E3",
1353  "* c #3E69E4",
1354  "= c #0C43F8",
1355  "- c #043FFE",
1356  "; c #CDD9ED",
1357  "> c #BDCDE9",
1358  ", c #FBFCFC",
1359  "' c #406AE4",
1360  ") c #0439FE",
1361  "! c #0137FF",
1362  "~ c #4F75E3",
1363  "{ c #9EB5E3",
1364  "] c #829FE0",
1365  "^ c #B6C6E7",
1366  "/ c #9DB4E3",
1367  "( c #7E9CE0",
1368  "_ c #B2C3E9",
1369  ": c #7E9AE0",
1370  "< c #86A2E1",
1371  "[ c #CAD6ED",
1372  "} c #5177E3",
1373  "| c #829CE0",
1374  "1 c #BCCCE9",
1375  "2 c #3A67E6",
1376  "3 c #0A43FA",
1377  "4 c #95ACE1",
1378  "5 c #BBCBE9",
1379  "6 c #A9BBE5",
1380  "7 c #96AFE1",
1381  "8 c #BDCBE9",
1382  "9 c #4067E4",
1383  "0 c #6485E5",
1384  "a c #E3EAF3",
1385  "b c #CAD6F3",
1386  " ",
1387  " ",
1388  " ++++ ",
1389  " ++++++++@#$+++ ",
1390  " ++@%####&*=-#+;>, ",
1391  " +++++@'=)))))))!)~+{]^++ ",
1392  " +$%&*=)!!!!!!!!!)~+/(]_+++ ",
1393  " +#-))!!!!!!!!!!!)~+/(::<[+ ",
1394  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1395  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1396  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1397  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1398  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1399  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1400  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1401  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1402  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1403  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1404  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1405  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1406  " +#)!!!!!!!!!!!!!!}+/::::{+ ",
1407  " +#)!!!!!!!!!!!!!!}+/:::|1+ ",
1408  " +$#}}~23!!!!!!!!)~+/(]45, ",
1409  " +++++++@#}}~23!!)~+678++ ",
1410  " ++++++@#~90+a++ ",
1411  " ++++b++ ",
1412  " ++ ",
1413  " ",
1414  " ",
1415  " ",
1416  " ",
1417  " "}
1418  ;
1419  pix = QPixmap(xpm);
1420  } else if (std::string(aIconFile) == "perspective") {
1421  const char * const xpm[]={
1422  "32 32 3 1",
1423  " c None",
1424  ". c #D5D8D5",
1425  "+ c #000000",
1426  " ",
1427  " ",
1428  " ",
1429  " ",
1430  " ",
1431  " ................ ",
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  pix = QPixmap(xpm);
1460  } else if (std::string(aIconFile) == "ortho") {
1461  const char * const xpm[]={
1462  "32 32 3 1",
1463  " c None",
1464  ". c #D5D8D5",
1465  "@ c #000000",
1466  " ",
1467  " ",
1468  " ",
1469  " ................... ",
1470  " ..@@@@@@@@@@@@@@@@@. ",
1471  " ..@@@.............@@@. ",
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  pix = QPixmap(xpm);
1500  } else {
1501  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1502  G4int verbose = UImanager->GetVerboseLevel();
1503 
1504  if (verbose >= 2) {
1505  G4cout << "Parameter"<< aIconFile <<" not defined"<< G4endl;
1506  }
1507  return;
1508  }
1509  Wt::WToolBar *currentToolbar = NULL;
1510  if (userToolBar) {
1511  if (fToolbarUser == NULL) {
1512  fToolbarUser = new Wt::WToolBar();
1513  fToolbarUser->setIconSize (QSize(20,20));
1514  fMainWindow->addToolBar(Wt::TopToolBarArea, fToolbarUser);
1515  }
1516  currentToolbar = fToolbarUser;
1517  } else {
1518  if (fToolbarApp == NULL) {
1519  fToolbarApp = new Wt::WToolBar();
1520  fToolbarApp->setIconSize (QSize(20,20));
1521  fMainWindow->addToolBar(Wt::TopToolBarArea, fToolbarApp);
1522  }
1523  currentToolbar = fToolbarApp;
1524  }
1525 
1526  QSignalMapper *signalMapper = new QSignalMapper(this);
1527  QAction *action = currentToolbar->addAction(pix,aLabel, signalMapper, SLOT(map()));
1528 
1529 
1530  // special cases :"open"
1531  if (std::string(aIconFile) == "open") {
1532  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(OpenIconCallback(const Wt::WString &)));
1533  Wt::WString txt = aCommand + fStringSeparator + aLabel;
1534  signalMapper->setMapping(action, Wt::WString(txt));
1535 
1536  // special cases :"save"
1537  } else if (std::string(aIconFile) == "save") {
1538  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(SaveIconCallback(const Wt::WString&)));
1539  Wt::WString txt = aCommand + fStringSeparator + aLabel;
1540  signalMapper->setMapping(action, Wt::WString(txt));
1541 
1542  // special cases : cursor style
1543  } else if ((std::string(aIconFile) == "move") ||
1544  (std::string(aIconFile) == "rotate") ||
1545  (std::string(aIconFile) == "pick") ||
1546  (std::string(aIconFile) == "zoom_out") ||
1547  (std::string(aIconFile) == "zoom_in")) {
1548  action->setCheckable(TRUE);
1549  action->setChecked(TRUE);
1550  action->setData(aIconFile);
1551 
1552  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangeCursorStyle(const Wt::WString&)));
1553  signalMapper->setMapping(action, Wt::WString(aIconFile));
1554 
1555  if (std::string(aIconFile) == "move") {
1556  SetIconMoveSelected();
1557  }
1558  if (std::string(aIconFile) == "rotate") {
1559  SetIconRotateSelected();
1560  }
1561  if (std::string(aIconFile) == "pick") {
1562  SetIconPickSelected();
1563  }
1564  if (std::string(aIconFile) == "zoom_in") {
1565  SetIconZoomInSelected();
1566  }
1567  if (std::string(aIconFile) == "zoom_out") {
1568  SetIconZoomOutSelected();
1569  }
1570 
1571  // special case : surface style
1572  } else if ((std::string(aIconFile) == "hidden_line_removal") ||
1573  (std::string(aIconFile) == "hidden_line_and_surface_removal") ||
1574  (std::string(aIconFile) == "solid") ||
1575  (std::string(aIconFile) == "wireframe")) {
1576  action->setCheckable(TRUE);
1577  action->setChecked(TRUE);
1578  action->setData(aIconFile);
1579  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangeSurfaceStyle(const Wt::WString&)));
1580  signalMapper->setMapping(action, Wt::WString(aIconFile));
1581 
1582  if (std::string(aIconFile) == "hidden_line_removal") {
1583  SetIconHLRSelected();
1584  }
1585  if (std::string(aIconFile) == "hidden_line_and_surface_removal") {
1586  SetIconHLHSRSelected();
1587  }
1588  if (std::string(aIconFile) == "solid") {
1589  SetIconSolidSelected();
1590  }
1591  if (std::string(aIconFile) == "wireframe") {
1592  SetIconWireframeSelected();
1593  }
1594 
1595  // special case : perspective/ortho
1596  } else if ((std::string(aIconFile) == "perspective") ||
1597  (std::string(aIconFile) == "ortho")) {
1598  action->setCheckable(TRUE);
1599  action->setChecked(TRUE);
1600  action->setData(aIconFile);
1601  connect(signalMapper, SIGNAL(mapped(const Wt::WString &)),this, SLOT(ChangePerspectiveOrthoCallback(const Wt::WString&)));
1602  signalMapper->setMapping(action, Wt::WString(aIconFile));
1603 
1604  if (std::string(aIconFile) == "perspective") {
1605  SetIconPerspectiveSelected();
1606  }
1607  if (std::string(aIconFile) == "ortho") {
1608  SetIconOrthoSelected();
1609  }
1610 
1611  } else {
1612 
1613  // Find the command in the command tree
1614  G4UImanager* UI = G4UImanager::GetUIpointer();
1615  if(UI==NULL) return;
1616  G4UIcommandTree * treeTop = UI->GetTree();
1617  if (aCommand != NULL) {
1618  if(treeTop->FindPath(aCommand) == NULL) {
1619  G4UImanager* UImanager = G4UImanager::GetUIpointer();
1620  G4int verbose = UImanager->GetVerboseLevel();
1621 
1622  if (verbose >= 2) {
1623  G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
1624  }
1625  }
1626  }
1627 
1628  connect(signalMapper, SIGNAL(mapped(const char *)),this, SLOT(ButtonCallback(const char *)));
1629  signalMapper->setMapping(action, aCommand);
1630  }
1631 */
1632 }
1633 
1634 
1640 bool G4UIWt::CreateCommandWidget(G4UIcommand* aCommand, Wt::WContainerWidget* aParent, bool isDialog) {
1641 
1642  if (aCommand == NULL) {
1643  return false;
1644  }
1645 
1646 
1647  // parameters
1648  G4int n_parameterEntry = aCommand->GetParameterEntries();
1649  if( n_parameterEntry > 0 ) {
1650  G4UIparameter *param;
1651 
1652  // Re-implementation of G4UIparameter.cc
1653  Wt::WContainerWidget* paramWidget = new Wt::WContainerWidget();
1654  Wt::WGridLayout* gridLayout = new Wt::WGridLayout(paramWidget);
1655 
1656  // Special case for colour, try to display a color chooser if we found red/green/blue parameter
1657  unsigned int nbColorParameter = 0;
1658  bool isStillColorParameter = false;
1659  bool isColorDialogAdded = false;
1660  Wt::WLabel* redLabel = NULL;
1661  Wt::WLabel* greenLabel = NULL;
1662  Wt::WString redDefaultStr = "";
1663  Wt::WString greenDefaultStr = "";
1664  Wt::WString blueDefaultStr = "";
1665  Wt::WWidget* redInput = NULL;
1666  Wt::WWidget* greenInput = NULL;
1667 
1668  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1669  Wt::WString txt;
1670  param = aCommand->GetParameter(i_thParameter);
1671  Wt::WLabel* label = new Wt::WLabel(Wt::WString((char*)(param->GetParameterName()).data()));
1672 
1673  if ((label->text() == "red") || (label->text() == "red_or_string")){
1674  nbColorParameter ++;
1675  isStillColorParameter = true;
1676  } else if ((label->text() == "green") && isStillColorParameter) {
1677  nbColorParameter ++;
1678  } else if ((label->text() == "blue") && isStillColorParameter) {
1679  nbColorParameter ++;
1680  } else if (!isColorDialogAdded) {
1681 
1682  // not following red/green/blue parameters ?
1683  if (nbColorParameter == 1) {
1684  gridLayout->addWidget(redLabel,i_thParameter-1,0);
1685  gridLayout->addWidget(redInput,i_thParameter-1,1);
1686  } else if (nbColorParameter == 2) {
1687  gridLayout->addWidget(redLabel,i_thParameter-2,0);
1688  gridLayout->addWidget(redInput,i_thParameter-2,1);
1689  gridLayout->addWidget(greenLabel,i_thParameter-1,0);
1690  gridLayout->addWidget(greenInput,i_thParameter-1,1);
1691  }
1692  nbColorParameter = 0;
1693  }
1694  // Check parameter type, could be NULL if not found
1695  Wt::WWidget* input = NULL;
1696  char paramType = param->GetParameterType();
1697  if ((paramType == 'd') || (paramType == 'i')) {
1698  input = new Wt::WLineEdit();
1699  // set default value
1700  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1701 
1702  if (((label->text() == "red") || (label->text() == "red_or_string")) && isStillColorParameter) {
1703  redDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1704  } else if ((label->text() == "green") && isStillColorParameter) {
1705  greenDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1706  } else if ((label->text() == "green") && isStillColorParameter) {
1707  blueDefaultStr = Wt::WString((char*)(param->GetDefaultValue()).data());
1708  }
1709 
1710  } else if (paramType == 'b') {
1711  input = new Wt::WContainerWidget();
1712  Wt::WHBoxLayout* layout = new Wt::WHBoxLayout(input);
1713 
1714  Wt::WButtonGroup* buttons = new Wt::WButtonGroup();
1715  Wt::WRadioButton* radioOff = new Wt::WRadioButton("0");
1716  Wt::WRadioButton* radioOn = new Wt::WRadioButton("1");
1717  buttons->addButton(radioOn);
1718  buttons->addButton(radioOff);
1719  layout->addWidget(radioOn);
1720  layout->addWidget(radioOff);
1721 
1722  // set default value
1723  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1724  if (defaultValue == "0") {
1725  radioOff->setChecked(true);
1726  } else if (defaultValue == "1") {
1727  radioOn->setChecked(true);
1728  }
1729  } else if ((paramType == 's') && (!param->GetParameterCandidates().isNull())) {
1730  input = new Wt::WComboBox();
1731  Wt::WString candidates = Wt::WString((char*)(param->GetParameterCandidates()).data());
1732  printf("*** G4UIWt::CreateCommandWidget, missing parameter management for 's'\n");
1733  /* QStringList list = candidates.split (" ");
1734 
1735  // add all candidates to widget
1736  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1737  for (int a=0; a<list.size(); a++) {
1738  dynamic_cast<Wt::WComboBox*>(input)->addItem(list.at(a));
1739  if (list.at(a) == defaultValue) {
1740  dynamic_cast<Wt::WComboBox*>(input)->setCurrentIndex(a);
1741  }
1742  }
1743 */
1744  } else if (paramType == 's') { // string
1745  input = new Wt::WLineEdit();
1746  // set default value
1747  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1748 
1749  } else if (paramType == 'c') { // on/off
1750  input = new Wt::WContainerWidget();
1751  Wt::WHBoxLayout* layout = new Wt::WHBoxLayout(input);
1752 
1753  Wt::WButtonGroup* buttons = new Wt::WButtonGroup();
1754  Wt::WRadioButton* radioOff = new Wt::WRadioButton("off");
1755  Wt::WRadioButton* radioOn = new Wt::WRadioButton("on");
1756  buttons->addButton(radioOn);
1757  buttons->addButton(radioOff);
1758  layout->addWidget(radioOn);
1759  layout->addWidget(radioOff);
1760 
1761  // set default value
1762  Wt::WString defaultValue = Wt::WString((char*)(param->GetDefaultValue()).data());
1763  if (defaultValue == "off") {
1764  radioOff->setChecked(true);
1765  } else if (defaultValue == "on") {
1766  radioOn->setChecked(true);
1767  }
1768 
1769  } else {
1770  input = new Wt::WLineEdit();
1771  dynamic_cast<Wt::WLineEdit*>(input)->setText(Wt::WString((char*)(param->GetDefaultValue()).data()));
1772  }
1773 
1774  txt += "\nParameter : " + Wt::WString((char*)(param->GetParameterName()).data()) + "\n";
1775  if( ! param->GetParameterGuidance().isNull() )
1776  txt += Wt::WString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
1777 
1778 // FIXME ?
1779  txt += Wt::WString(" Parameter type : ") + std::string(&paramType).c_str() + "\n";
1780  if(param->IsOmittable()){
1781  txt += " Omittable : True\n";
1782  } else {
1783  txt += " Omittable : False\n";
1784  }
1785  if( param->GetCurrentAsDefault() ) {
1786  txt += " Default value : taken from the current value\n";
1787  } else if( ! param->GetDefaultValue().isNull() ) {
1788  txt += " Default value : " + Wt::WString((char*)(param->GetDefaultValue()).data())+ "\n";
1789  }
1790  if( ! param->GetParameterRange().isNull() ) {
1791  txt += " Parameter range : " + Wt::WString((char*)(param->GetParameterRange()).data())+ "\n";
1792  }
1793  if( ! param->GetParameterCandidates().isNull() ) {
1794  txt += " Candidates : " + Wt::WString((char*)(param->GetParameterCandidates()).data())+ "\n";
1795  }
1796 
1797  if (isStillColorParameter && (nbColorParameter != 0)) {
1798  if ((label->text() == "red") || (label->text() == "red_or_string")) {
1799  redLabel = label;
1800  redInput = input;
1801  } else if (label->text() == "green") {
1802  greenLabel = label;
1803  greenInput = input;
1804  } else if (label->text() == "blue") {
1805 
1806  // we have all, then add a color chooser
1807 
1808  // Create a pixmap with the default color
1809  Wt::WColor wc;
1810  if ((redDefaultStr != "") && (redDefaultStr != "") && (redDefaultStr != "")) {
1811  // 255 max
1812  wc.setRgb(atof(redDefaultStr.toUTF8().c_str())*256,
1813  atof(greenDefaultStr.toUTF8().c_str())*256,
1814  atof(blueDefaultStr.toUTF8().c_str())*256);
1815  }
1816  printf("*** G4UIWt::CreateCommandWidget, missing icon on command widget\n");
1817 /*
1818  QPixmap pixmap = QPixmap(QSize(16, 16));
1819  pixmap.fill (wc);
1820  Wt::WPainter painter(&pixmap);
1821  painter.setPen(Wt::black);
1822  painter.drawRect(0,0,15,15); // Draw contour
1823 
1824  input = new Wt::WPushButton("Change color");
1825  dynamic_cast<Wt::WPushButton*>(input)->setIcon(pixmap);
1826  dynamic_cast<Wt::WPushButton*>(input)->setAccessibleName(redDefaultStr+" "+greenDefaultStr+" "+blueDefaultStr);
1827  label = new Wt::WLabel("Choose color");
1828 
1829  // less 1 because we have to add one to the row number
1830  nbColorParameter--;
1831  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1832  input->setToolTip("Select the current color");
1833  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1834 
1835  // Connect pushButton to ColorDialog in callback
1836  QSignalMapper* signalMapper = new QSignalMapper(this);
1837  signalMapper->setMapping(input,input);
1838  connect(input, SIGNAL(clicked()), signalMapper, SLOT(map()));
1839  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(ChangeColorCallback(Wt::WWidget*)));
1840 
1841 */
1842  isColorDialogAdded = true;
1843  isStillColorParameter = false;
1844  }
1845  } else {
1846  gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1847  input->setToolTip(txt);
1848  gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1849  }
1850  }
1851  // add command name in hidden value at last line position 0
1852  Wt::WLabel* name = new Wt::WLabel(Wt::WString((char*)(aCommand->GetCommandPath().data())));
1853  name->hide();
1854  gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
1855 
1856  Wt::WPushButton* applyButton = new Wt::WPushButton("Apply");
1857  if (!isDialog) {
1858 
1859  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
1860 
1861  printf("*** G4UIWt::CreateCommandWidget, missing connection on ApplyButton\n");
1862 /*
1863  QSignalMapper* signalMapper = new QSignalMapper(this);
1864  signalMapper->setMapping(applyButton, paramWidget);
1865  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
1866  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(VisParameterCallback(Wt::WWidget*)));
1867 */
1868  } else {
1869  // Apply/Cancel buttons
1870 
1871  printf("*** G4UIWt::CreateCommandWidget, missing connection on Apply/Cancel Button\n");
1872 /* applyButton->setAutoDefault( TRUE );
1873  applyButton->setDefault( TRUE );
1874  gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,0);
1875 
1876  Wt::WPushButton* cancelButton = new Wt::WPushButton( tr( "&Cancel" ));
1877  cancelButton->setAutoDefault( TRUE );
1878  gridLayout->addWidget(cancelButton,n_parameterEntry-nbColorParameter,1);
1879 
1880  QSignalMapper* signalMapper = new QSignalMapper(this);
1881  signalMapper->setMapping(applyButton, paramWidget);
1882  connect(applyButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
1883  connect(signalMapper, SIGNAL(mapped(Wt::WWidget*)),this, SLOT(VisParameterCallback(Wt::WWidget*)));
1884 
1885  Wt::WWidget * parentCheck = aParent;
1886  Wt::WDialog* parentDialog = NULL;
1887  bool found = false;
1888  while ((parentCheck->parentWidget()) != NULL) {
1889  parentCheck = (Wt::WWidget*) parentCheck->parentWidget();
1890  parentDialog = dynamic_cast<Wt::WDialog*>(parentCheck);
1891  if (parentDialog) {
1892  connect( applyButton, SIGNAL( clicked() ), parentDialog, SLOT( accept() ) );
1893  connect( cancelButton, SIGNAL( clicked() ), parentDialog, SLOT( reject() ) );
1894  found = true;
1895  }
1896  }
1897  if (!found) {
1898  return false;
1899  }
1900 */
1901  }
1902 
1903  if (!aParent->layout()) {
1904  aParent->setLayout(new Wt::WVBoxLayout());
1905  }
1906  aParent->layout()->addWidget(paramWidget);
1907  }
1908 
1909  return true;
1910 }
1911 
1912 
1920 bool G4UIWt::eventFilter( // Should stay with a minuscule eventFilter because of Wt
1921  Wt::WObject* /* aObj */
1922  ,Wt::WEvent* /* aEvent */
1923  )
1924 {
1925  bool res= false;
1926  printf("*** G4UIWt::eventFilter, missing eventFilter on everything\n");
1927 /*
1928  bool moveCommandCursor = false;
1929  if (aObj == NULL) return false;
1930  if (aEvent == NULL) return false;
1931 
1932  if (aObj == fHistoryTBTableList) {
1933  if (aEvent->type() == Wt::WEvent::KeyPress) {
1934  fCommandArea->setFocus();
1935  }
1936  }
1937  if (aObj == fCommandArea) {
1938  if (aEvent->type() == Wt::WEvent::KeyPress) {
1939  QKeyEvent *e = static_cast<QKeyEvent*>((QEvent*)aEvent);
1940  if ((e->key() == (Wt::Key_Down)) ||
1941  (e->key() == (Wt::Key_PageDown)) ||
1942  (e->key() == (Wt::Key_Up)) ||
1943  (e->key() == (Wt::Key_PageUp))) {
1944  int selection = fHistoryTBTableList->currentRow();
1945  if (fHistoryTBTableList->count()) {
1946  if (selection == -1) {
1947  selection = fHistoryTBTableList->count()-1;
1948  } else {
1949  if (e->key() == (Wt::Key_Down)) {
1950  if (selection <(fHistoryTBTableList->count()-1))
1951  selection++;
1952  } else if (e->key() == (Wt::Key_PageDown)) {
1953  selection = fHistoryTBTableList->count()-1;
1954  } else if (e->key() == (Wt::Key_Up)) {
1955  if (selection >0)
1956  selection --;
1957  } else if (e->key() == (Wt::Key_PageUp)) {
1958  selection = 0;
1959  }
1960  }
1961  fHistoryTBTableList->clearSelection();
1962  fHistoryTBTableList->item(selection)->setSelected(true);
1963  fHistoryTBTableList->setCurrentItem(fHistoryTBTableList->item(selection));
1964  }
1965  moveCommandCursor = true;
1966  } else if (e->key() == (Wt::Key_Tab)) {
1967  G4String ss = Complete(fCommandArea->text().toUTF8().c_str());
1968  fCommandArea->setText((char*)(ss.data()));
1969 
1970  // do not pass by parent, it will disable widget tab focus !
1971  return true;
1972  // L.Garnier : MetaModifier is CTRL for MAC, but I don't want to put a MAC
1973  // specific #ifdef
1974  } else if (((e->modifiers () == Wt::ControlModifier) || (e->modifiers () == Wt::MetaModifier)) && (e->key() == Wt::Key_A)) {
1975  fCommandArea->home(false);
1976  return true;
1977  } else if (((e->modifiers () == Wt::ControlModifier) || (e->modifiers () == Wt::MetaModifier)) && (e->key() == Wt::Key_E)) {
1978  fCommandArea->end(false);
1979  return true;
1980  }
1981  }
1982  }
1983  // change cursor position if needed
1984  if (moveCommandCursor == true) {
1985 #ifdef G4DEBUG_INTERFACES_BASIC
1986  printf("G4UIWt::eventFilter setCursor Position\n");
1987 #endif
1988  fCommandArea->setCursorPosition ( fCommandArea->text().length() );
1989  fCommandArea->setCursorPosition (4);
1990  } else {
1991  // pass the event on to the parent class
1992  res = QObject::eventFilter(aObj, aEvent);
1993  }
1994 */
1995  return res;
1996 }
1997 
1998 
2001 void G4UIWt::HelpTreeClicCallback (
2002 )
2003 {
2004  Wt::WTreeNode* item = NULL;
2005  if (!fHelpTreeWidget)
2006  return ;
2007 
2008  if (!fHelpArea)
2009  return;
2010 
2011  const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2012  if (list.empty())
2013  return;
2014  item = *list.begin();
2015  if (!item)
2016  return;
2017 
2019  if(UI==NULL) return;
2020  G4UIcommandTree * treeTop = UI->GetTree();
2021 
2022  std::string itemText = GetLongCommandPath(item).toUTF8();
2023 
2024  G4UIcommand* command = treeTop->FindPath(itemText.c_str());
2025 
2026  if (command) {
2027  fHelpArea->setText(GetCommandList(command));
2028  } else { // this is a command
2029  G4UIcommandTree* path = treeTop->FindCommandTree(itemText.c_str());
2030  if ( path) {
2031  // this is not a command, this is a sub directory
2032  // We display the Title
2033  fHelpArea->setText(path->GetTitle().data());
2034  }
2035  }
2036 }
2037 
2040 void G4UIWt::HelpTreeDoubleClicCallback (
2041 )
2042 {
2043  HelpTreeClicCallback();
2044 
2045  Wt::WTreeNode* item = NULL;
2046  if (!fHelpTreeWidget)
2047  return ;
2048 
2049  if (!fHelpArea)
2050  return;
2051 
2052  const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2053  if (list.empty())
2054  return;
2055  item = *list.begin();
2056  if (!item)
2057  return;
2058 
2059  fCommandArea->setText("");
2060  fCommandArea->setText(GetLongCommandPath(item));
2061 }
2062 
2063 
2069 G4int G4UIWt::ReceiveG4cout (
2070  const G4String& aString
2071  )
2072 {
2073  if (!aString) return 0;
2074 
2075  Wt::WStringListModel newStr;
2076 
2077  // Add to stringList
2078  std::string whiteSpaces( " \f\n\r\t\v" );
2079  std::string path = (char*)aString.data();
2080 
2081  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2082  path.erase( posR + 1 );
2083 
2084  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2085  path.erase( 0, posL );
2086 
2087  printf("*** G4UIWt::ReceiveG4cout, missing filtering\n");
2088 /* newStr = Wt::WString(path);
2089  fG4cout += newStr;
2090 
2091  QStringList result = newStr.filter(fCoutFilter->text());
2092 
2093  if (result.join("").isEmpty()) {
2094  return 0;
2095  }
2096  */
2097  if (!fCoutTBTextArea) {
2098  printf("*** G4UIWt::ReceiveG4cout, create a new fCoutTBTextArea \n");
2099  fCoutTBTextArea = new Wt::WTextArea();
2100  fCoutTBTextArea->setText("");
2101  }
2102  fCoutTBTextArea->setText(fCoutTBTextArea->text()+"\n"+path);
2103  fCoutTBTextArea->refresh();
2104 
2105  return 0;
2106 }
2107 
2108 
2114 G4int G4UIWt::ReceiveG4cerr (
2115  const G4String& aString
2116  )
2117 {
2118  if (!aString) return 0;
2119 
2120  Wt::WStringListModel newStr;
2121 
2122  // Add to stringList
2123  std::string whiteSpaces( " \f\n\r\t\v" );
2124  std::string path = (char*)aString.data();
2125 
2126  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2127  path.erase( posR + 1 );
2128 
2129  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2130  path.erase( 0, posL );
2131 
2132  printf("*** G4UIWt::ReceiveG4cerr, missing filtering\n");
2133  /* newStr = Wt::WStringList(path);
2134  fG4cout += newStr;
2135 
2136  QStringList result = newStr.filter(fCoutFilter->text());
2137 
2138  */
2139  // Suppress space, \n,\t,\r...
2140  if (path != "") {
2141  if ((G4StateManager::GetStateManager()->GetCurrentState() == G4State_Abort) ||
2142  (G4StateManager::GetStateManager()->GetCurrentState() == G4State_Quit )) {
2143  // In case of Abort or Quit, the useful error message should be in the last error message !
2144  Wt::WMessageBox::show("Error", Wt::WString(fLastErrMessage.data())+"\n"+aString.data(), Wt::Ok );
2145  }
2146 
2147  }
2148  printf("****ERR****: %s\n",path.c_str());
2149  if (!fCoutTBTextArea) {
2150  fCoutTBTextArea = new Wt::WTextArea();
2151  }
2152  fCoutTBTextArea->setText(fCoutTBTextArea->text()+"\n<font color='red'>"+path+"</font>");
2153  fCoutTBTextArea->refresh();
2154 
2155 
2156  if (path != "") {
2157  fLastErrMessage = aString;
2158  }
2159  return 0;
2160 }
2161 
2162 
2167 void G4UIWt::CommandEditedCallback(const Wt::WString &)
2168 {
2169  printf("*** G4UIWt::CommandEditedCallback, missing callback on command line edit\n");
2170 /* QStringList list = fCommandArea->text().split(QRegExp("[\r\n]"),QString::SkipEmptyParts);
2171 
2172  if (list.size() > 1) { // trigger ActivateCommand
2173  for (int a=0; a<list.size()-1; a++) {
2174  // set only the first part
2175  fCommandArea->setText(list[a]);
2176  // trigger callback
2177  CommandEnteredCallback();
2178  }
2179  // reset unfinished command
2180  fCommandArea->setText(list[list.size()-1]);
2181  }
2182 */
2183 }
2184 
2185 
2186 
2187 void G4UIWt::CoutFilterCallback(
2188  const Wt::WString & /* text */) {
2189  printf("*** G4UIWt::CoutFilterCallbackt, missing filtering\n");
2190 
2191 /* QStringList result = fG4cout.filter(text);
2192  fCoutTBTextArea->setPlainText(result.join("\n"));
2193 
2194  fCoutTBTextArea->repaint();
2195  fCoutTBTextArea->verticalScrollBar()->setSliderPosition(fCoutTBTextArea->verticalScrollBar()->maximum());
2196 
2197 */
2198 }
2199 
2200 
2201 
2202 
2203 
2209 void G4UIWt::AddMenu (
2210  const char* aName
2211  ,const char* aLabel
2212  )
2213 {
2214  if (aName == NULL) return;
2215  if (aLabel == NULL) return;
2216 
2217  printf("*** G4UIWt::AddMenu, missing \n");
2218 /* Wt::WMenu *fileMenu = new Wt::WMenu(aLabel);
2219  fMainWindow->menuBar()->addMenu(fileMenu);
2220 
2221  AddInteractor (aName,(G4Interactor)fileMenu);
2222 */
2223 }
2224 
2225 
2231 bool G4UIWt::CreateVisCommandGroupAndToolBox(
2232  G4UIcommand* /* aCommand */
2233  ,Wt::WWidget* /* aParent */
2234  ,int /* aDepthLevel */
2235  ,bool /* isDialog */
2236  )
2237 {
2238  printf("*** G4UIWt::CreateVisCommandGroupAndToolBox, missing \n");
2239  /*
2240  std::string str ((char*)(aCommand->GetCommandPath().data()));
2241  std::string str2 ("/");
2242  std::size_t pos = -1;
2243 
2244  for (int a=1; a<=-aDepthLevel; a++) {
2245  pos = str.find(str2, pos+1);
2246  }
2247 
2248  Wt::WString commandText2;
2249  std::string commandText = "";
2250  if (pos!=std::string::npos) {
2251  commandText = str.substr(pos);
2252  }
2253  // FIXME : commandText2 = Wt::WString((char*)(aCommand->GetCommandPath().data())).section("/",-aDepthLevel);
2254  // FIXME : printf(" CommandText : %s\n",commandText.toUTF8().c_str());
2255  // FIXME : printf(" CommandText2 : %s\n",commandText2.toUTF8().c_str());
2256 
2257  if (commandText == "") {
2258  return false;
2259  }
2260 
2261  // Look if groupBox is create
2262  // Wt::WGroupBox* gBoxCommandWidget;
2263  Wt::WWidget* newParentWidget = NULL;
2264  bool found = false;
2265 
2266  pos = commandText.find("/", 0);
2267  Wt::WString commandSection = "";
2268  if (pos!=std::string::npos) {
2269  commandSection = Wt::WString(str.substr(0,pos).c_str());
2270  }
2271 
2272  // FIXME : Wt::WString commandSection = commandText.left(commandText.indexOf("/"));
2273 
2274  if (aDepthLevel == 1) {
2275  Wt::WToolBox* currentParent = dynamic_cast<Wt::WToolBox*>(aParent);
2276  if (currentParent != 0){
2277 
2278  // already exists ?
2279  for (int a=0; a<currentParent->count(); a++) {
2280  if (currentParent->itemText(a) == commandSection) {
2281  found = true;
2282  newParentWidget = (Wt::WWidget*) currentParent->widget(a);
2283  }
2284  }
2285  }
2286  // Not found ? create it
2287  if (!found) {
2288  newParentWidget = new Wt::WGroupBox();
2289  // newParentWidget->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
2290  newParentWidget->setLayout(new Wt::WVBoxLayout());
2291  if (currentParent != 0){
2292  currentParent->addItem(newParentWidget,commandSection);
2293  } else {
2294  if (!aParent->layout()) {
2295  aParent->setLayout(new Wt::WVBoxLayout());
2296  }
2297  aParent->layout()->addWidget(newParentWidget);
2298  }
2299 
2300  if (commandText.find("/", 0) != std::string::npos) {
2301 
2302  // Guidance
2303  Wt::WString guidance;
2304  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2305  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2306  guidance += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2307  }
2308  newParentWidget->setToolTip(guidance);
2309  }
2310 
2311  Wt::WScrollArea* sc = dynamic_cast<Wt::WScrollArea*>(newParentWidget->parent()->parent());
2312  if (sc != 0) {
2313  sc->ensureWidgetVisible(newParentWidget);
2314  // sc->setSizePolicy (QSizePolicy(QSizePolicy::Maximum,QSizePolicy::Maximum));
2315 
2316  }
2317  }
2318  } else {
2319 
2320  // try to know if this level is already there
2321  Wt::WGroupBox* currentParent = dynamic_cast<Wt::WGroupBox*>(aParent);
2322  if (currentParent != 0){
2323 
2324  // if depth==2, then we add a [more parameters inside] to the toolBoxItem parent
2325  // Wt::WGroupBox > Wt::WWidget > Wt::WScrollArea > Wt::WToolBox
2326  if (aDepthLevel == 2){
2327  Wt::WToolBox* parentToolBox = dynamic_cast<Wt::WToolBox*>(((Wt::WWidget*) (currentParent))->parent()->parent()->parent());
2328  if (parentToolBox != 0) {
2329  // parentToolBox->setItemText(parentToolBox->indexOf(currentParent),"[more parameters inside]");
2330  }
2331  }
2332  for (int a=0; a<aParent->layout()->count(); a++) {
2333  Wt::WGroupBox* gb = dynamic_cast<Wt::WGroupBox*>(aParent->layout()->itemAt(a)->widget());
2334  if (gb != 0) {
2335  if (gb->title() == commandSection) {
2336  found = true;
2337  newParentWidget = gb;
2338  }
2339  }
2340  }
2341  }
2342 
2343  // Not found ? create it
2344  if (!found) {
2345  newParentWidget = new Wt::WGroupBox(commandSection);
2346  newParentWidget->setLayout(new Wt::WVBoxLayout());
2347  if (!aParent->layout()) {
2348  aParent->setLayout(new Wt::WVBoxLayout());
2349  }
2350  aParent->layout()->addWidget(newParentWidget);
2351 
2352  // set toolTip
2353  // Guidance
2354  Wt::WString guidance;
2355  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
2356  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
2357  guidance += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
2358  }
2359  newParentWidget->setToolTip(guidance);
2360  }
2361  }
2362 
2363  // fill command groupbox
2364  if (commandText.find("/", 0) != std::string::npos) {
2365  if (CreateCommandWidget(aCommand, newParentWidget,isDialog)) {
2366  return true;
2367  }
2368  } else {
2369  CreateVisCommandGroupAndToolBox(aCommand,newParentWidget, aDepthLevel-1,isDialog);
2370  }
2371 */
2372  return true;
2373 }
2374 
2375 
2378 void G4UIWt::VisParameterCallback(Wt::WContainerWidget* widget){
2379  if (widget == NULL) {
2380  return;
2381  }
2382  printf("*** G4UIWt::VisParameterCallback, missing \n");
2383 /*
2384  // Look in all the Grid layout, but only column 1 (0 is the parameter name)
2385  Wt::WGridLayout* grid = dynamic_cast<Wt::WGridLayout*>(widget->layout());
2386  if (grid == 0) {
2387  return;
2388  }
2389  Wt::WString command;
2390  Wt::WWidget* name = (Wt::WWidget*) (grid->itemAtPosition(grid->rowCount()-1,0)->widget());
2391  if (widget == NULL) {
2392  return;
2393  }
2394  if (dynamic_cast<Wt::WLabel*>(name) == 0) {
2395  return;
2396  }
2397  command += (dynamic_cast<Wt::WLabel*>(name))->text()+" ";
2398 
2399  for (int a=0;a<grid->rowCount()-1; a++) {
2400  Wt::WWidget* widgetTmp = (Wt::WWidget*) (grid->itemAtPosition(a,1)->widget());
2401 
2402  // 4 kind of widgets : Wt::WLineEdit / Wt::WComboBox / radioButtonsGroup / Wt::WPushButton (color chooser)
2403  if (widgetTmp != NULL) {
2404 
2405  if (dynamic_cast<Wt::WLineEdit*>(widgetTmp) != 0) {
2406  command += (dynamic_cast<Wt::WLineEdit*>(widgetTmp))->text()+" ";
2407 
2408  } else if (dynamic_cast<Wt::WComboBox*>(widgetTmp) != 0){
2409  command += (dynamic_cast<Wt::WComboBox*>(widgetTmp))->itemText((dynamic_cast<Wt::WComboBox*>(widgetTmp))->currentIndex())+" ";
2410 
2411  // Color chooser
2412  } else if (dynamic_cast<Wt::WPushButton*>(widgetTmp) != 0){
2413  command += widgetTmp->accessibleName()+" ";
2414 
2415  // Check for Button group
2416  } else if (dynamic_cast<Wt::WWidget*>(widgetTmp) != 0){
2417  if (widgetTmp->layout()->count() > 0){
2418  if (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()) != 0) {
2419  QAbstractButton * checked = (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton();
2420  if (checked != 0) {
2421  command += (dynamic_cast<Wt::WRadioButton*>(widgetTmp->layout()->itemAt(0)->widget()))->group()->checkedButton()->text()+" ";
2422  }
2423  }
2424  }
2425 
2426  }
2427  }
2428  }
2429  if (command != "") {
2430  G4UImanager* UI = G4UImanager::GetUIpointer();
2431  if(UI != NULL) {
2432  UI->ApplyCommand(command.toUTF8().c_str());
2433  }
2434  }
2435  */
2436 }
2437 
2438 
2442 void G4UIWt::CommandHistoryCallback(
2443 )
2444 {
2445  if (!fHistoryTBTableList)
2446  return ;
2447  fCommandArea->setText(fHistoryTBTableList->currentText ());
2448 #ifdef G4DEBUG_INTERFACES_BASIC
2449  printf("G4UIWt::CommandHistoryCallback change text\n");
2450 #endif
2451 }
2452 
2453 
2454 void G4UIWt::OpenHelpTreeOnCommand(
2455  const Wt::WString & /* searchText */
2456  )
2457 {
2458  printf("*** G4UIWt::OpenHelpTreeOnCommand, missing \n");
2459 /* // the help tree
2460  G4UImanager* UI = G4UImanager::GetUIpointer();
2461  if(UI==NULL) return;
2462  G4UIcommandTree * treeTop = UI->GetTree();
2463 
2464  G4int treeSize = treeTop->GetTreeEntry();
2465 
2466  // clear old help tree
2467  fHelpTreeWidget->clear();
2468 
2469  // look for new items
2470 
2471  int tmp = 0;
2472 
2473  QMap<int,Wt::WString> commandResultMap;
2474  QMap<int,Wt::WString> commandChildResultMap;
2475 
2476  for (int a=0;a<treeSize;a++) {
2477  G4UIcommand* command = treeTop->FindPath(treeTop->GetTree(a+1)->GetPathName().data());
2478  tmp = GetCommandList (command).count(searchText,Wt::CaseInsensitive);
2479  if (tmp >0) {
2480  commandResultMap.insertMulti(tmp,Wt::WString((char*)(treeTop->GetTree(a+1)->GetPathName()).data()));
2481  }
2482  // look for childs
2483  commandChildResultMap = LookForHelpStringInChildTree(treeTop->GetTree(a+1),searchText);
2484  // insert new childs
2485  if (!commandChildResultMap.empty()) {
2486  QMap<int,Wt::WString>::const_iterator i = commandChildResultMap.constBegin();
2487  while (i != commandChildResultMap.constEnd()) {
2488  commandResultMap.insertMulti(i.key(),i.value());
2489  i++;
2490  }
2491  commandChildResultMap.clear();
2492  }
2493  }
2494 
2495  // build new help tree
2496  fHelpTreeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
2497  fHelpTreeWidget->setColumnCount(2);
2498  Wt::WStringList labels;
2499  labels << Wt::WString("Command") << Wt::WString("Match");
2500  fHelpTreeWidget->setHeaderLabels(labels);
2501 
2502  if (commandResultMap.empty()) {
2503  fHelpArea->setText("No match found");
2504  return;
2505  }
2506 
2507  QMap<int,Wt::WString>::const_iterator i = commandResultMap.constEnd();
2508  i--;
2509  // 10 maximum progress values
2510  float multValue = 10.0/(float)(i.key());
2511  Wt::WString progressChar = "|";
2512  Wt::WString progressStr = "|";
2513 
2514  Wt::WTreeNode * newItem;
2515  bool end = false;
2516  while (!end) {
2517  if (i == commandResultMap.constBegin()) {
2518  end = true;
2519  }
2520  for(int a=0;a<int(i.key()*multValue);a++) {
2521  progressStr += progressChar;
2522  }
2523  newItem = new Wt::WTreeNode(fHelpTreeWidget);
2524  Wt::WString commandStr = i.value().trimmed();
2525 
2526  if (commandStr.indexOf("/") == 0) {
2527  commandStr = commandStr.right(commandStr.size()-1);
2528  }
2529 
2530  newItem->setText(0,commandStr);
2531  newItem->setText(1,progressStr);
2532 
2533  newItem->setForeground ( 1, QBrush(Wt::blue) );
2534  progressStr = "|";
2535  i--;
2536  }
2537  fHelpTreeWidget->resizeColumnToContents (0);
2538  fHelpTreeWidget->sortItems(1,Wt::DescendingOrder);
2539  // fHelpTreeWidget->setColumnWidth(1,10);//resizeColumnToContents (1);
2540 */
2541 }
2542 
2543 /*
2544 WMap<int,Wt::WString> G4UIWt::LookForHelpStringInChildTree(
2545  G4UIcommandTree *aCommandTree
2546  ,const Wt::WString & text
2547  )
2548 {
2549  QMap<int,Wt::WString> commandResultMap;
2550  if (aCommandTree == NULL) return commandResultMap;
2551 
2552 
2553  // Get the Sub directories
2554  int tmp = 0;
2555  QMap<int,Wt::WString> commandChildResultMap;
2556 
2557  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
2558  const G4UIcommand* command = aCommandTree->GetGuidance();
2559  tmp = GetCommandList (command).count(text,Wt::CaseInsensitive);
2560  if (tmp >0) {
2561  commandResultMap.insertMulti(tmp,Wt::WString((char*)(aCommandTree->GetTree(a+1)->GetPathName()).data()));
2562  }
2563  // look for childs
2564  commandChildResultMap = LookForHelpStringInChildTree(aCommandTree->GetTree(a+1),text);
2565 
2566  if (!commandChildResultMap.empty()) {
2567  // insert new childs
2568  QMap<int,Wt::WString>::const_iterator i = commandChildResultMap.constBegin();
2569  while (i != commandChildResultMap.constEnd()) {
2570  commandResultMap.insertMulti(i.key(),i.value());
2571  i++;
2572  }
2573  commandChildResultMap.clear();
2574  }
2575  }
2576  // Get the Commands
2577 
2578  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
2579  const G4UIcommand* command = aCommandTree->GetCommand(a+1);
2580  tmp = GetCommandList (command).count(text,Wt::CaseInsensitive);
2581  if (tmp >0) {
2582  commandResultMap.insertMulti(tmp,Wt::WString((char*)(aCommandTree->GetCommand(a+1)->GetCommandPath()).data()));
2583  }
2584 
2585  }
2586  return commandResultMap;
2587 }
2588 */
2589 
2590 
2591 void G4UIWt::ChangeColorCallback(Wt::WContainerWidget* widget) {
2592  if (widget == NULL) {
2593  return;
2594  }
2595  printf("*** G4UIWt::ChangeColorCallback, missing \n");
2596 /*
2597  Wt::WPushButton* button = dynamic_cast<Wt::WPushButton*>(widget);
2598  if (button == 0) {
2599  return;
2600  }
2601  Wt::WString value = button->accessibleName();
2602 
2603  Wt::WColor old;
2604  old.setRgbF(value.section(" ",0,1).toDouble(),
2605  value.section(" ",1,2).toDouble(),
2606  value.section(" ",2,3).toDouble());
2607  Wt::WColor color = Wt::WColorDialog::getColor(old,
2608  fUITabWidget,
2609  "Change color",
2610  Wt::WColorDialog::ShowAlphaChannel);
2611 
2612 
2613  if (color.isValid()) {
2614  // rebuild the widget icon
2615  QPixmap pixmap = QPixmap(QSize(16, 16));
2616  pixmap.fill (color);
2617  Wt::WPainter painter(&pixmap);
2618  painter.setPen(Wt::black);
2619  painter.drawRect(0,0,15,15); // Draw contour
2620 
2621  button->setAccessibleName(Wt::WString::number(color.redF())+" "+
2622  Wt::WString::number(color.greenF())+" "+
2623  Wt::WString::number(color.blueF())+" "
2624  );
2625  button->setIcon(pixmap);
2626 
2627 
2628  }
2629 */
2630 }
2631 
2632 void G4UIWt::ChangeCursorStyle(const Wt::WString& /* action */) {
2633 
2634  // Theses actions should be in the app toolbar
2635 
2636  fMoveSelected = true;
2637  fPickSelected = true;
2638  fRotateSelected = true;
2639  fZoomInSelected = true;
2640  fZoomOutSelected = true;
2641 
2642  printf("*** G4UIWt::ChangeCursorStyle, missing \n");
2643 /*
2644  if (fToolbarApp == NULL) return;
2645  QList<QAction *> list = fToolbarApp->actions ();
2646  for (int i = 0; i < list.size(); ++i) {
2647  if (list.at(i)->data().toString () == action) {
2648  list.at(i)->setChecked(TRUE);
2649  } else if (list.at(i)->data().toString () == "move") {
2650  fMoveSelected = false;
2651  list.at(i)->setChecked(FALSE);
2652  } else if (list.at(i)->data().toString () == "pick") {
2653  fPickSelected = false;
2654  list.at(i)->setChecked(FALSE);
2655  } else if (list.at(i)->data().toString () == "rotate") {
2656  fRotateSelected = false;
2657  list.at(i)->setChecked(FALSE);
2658  } else if (list.at(i)->data().toString () == "zoom_in") {
2659  fZoomInSelected = false;
2660  list.at(i)->setChecked(FALSE);
2661  } else if (list.at(i)->data().toString () == "zoom_out") {
2662  fZoomOutSelected = false;
2663  list.at(i)->setChecked(FALSE);
2664  }
2665  }
2666  // FIXME : Should connect this to Vis
2667 */
2668 }
2669 
2670 
2671 /* A little bit like "void G4OpenGLWtViewer::toggleDrawingAction(int aAction)"
2672  But for all viewers, not only Wt
2673 
2674  FIXME : Should be a feedback when changing viewer !
2675 
2676  */
2677 void G4UIWt::ChangeSurfaceStyle(const Wt::WString& /* action */) {
2678 
2679  // Theses actions should be in the app toolbar
2680 
2681  printf("*** G4UIWt::ChangeSurfaceStyle, missing \n");
2682 /* if (fToolbarApp == NULL) return;
2683  QList<QAction *> list = fToolbarApp->actions ();
2684  for (int i = 0; i < list.size(); ++i) {
2685  if (list.at(i)->data().toString () == action) {
2686  list.at(i)->setChecked(TRUE);
2687  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2688  list.at(i)->setChecked(FALSE);
2689  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2690  list.at(i)->setChecked(FALSE);
2691  } else if (list.at(i)->data().toString () == "solid") {
2692  list.at(i)->setChecked(FALSE);
2693  } else if (list.at(i)->data().toString () == "wireframe") {
2694  list.at(i)->setChecked(FALSE);
2695  }
2696  }
2697  // FIXME : Should connect this to Vis
2698 
2699  if (action == "hidden_line_removal") {
2700  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
2701  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
2702 
2703  } else if (action == "hidden_line_and_surface_removal") {
2704  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
2705  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 1");
2706 
2707  } else if (action == "solid") {
2708  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style s");
2709  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
2710 
2711  } else if (action == "wireframe") {
2712  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/style w");
2713  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/hiddenEdge 0");
2714  }
2715 */
2716 }
2717 
2718 void G4UIWt::OpenIconCallback(const Wt::WString& /* aParam */) {
2719 
2720  printf("*** G4UIWt::OpenIconCallback, missing \n");
2721 /*
2722  Wt::WString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
2723  Wt::WString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
2724 
2725  Wt::WString nomFich = Wt::WFileDialog::getOpenFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
2726  if (nomFich != "") {
2727  G4UImanager::GetUIpointer()->ApplyCommand((Wt::WString(aCommand)+ Wt::WString(" ")+ nomFich).toUTF8().c_str());
2728  QDir dir;
2729  fLastOpenPath = dir.absoluteFilePath(nomFich);
2730  }
2731 */
2732 }
2733 
2734 
2735 void G4UIWt::SaveIconCallback(const Wt::WString& /* aParam */) {
2736 
2737  printf("*** G4UIWt::SaveIconCallback, missing \n");
2738 
2739  /*
2740  Wt::WString aCommand = aParam.left(aParam.indexOf(fStringSeparator));
2741  Wt::WString aLabel = aParam.mid(aParam.indexOf(fStringSeparator)+fStringSeparator.length());
2742 
2743  Wt::WString nomFich = Wt::WFileDialog::getSaveFileName(fMainWindow, aLabel, fLastOpenPath, "Macro files (*.mac)");
2744  if (nomFich != "") {
2745  G4UImanager::GetUIpointer()->ApplyCommand((Wt::WString(aCommand)+ Wt::WString(" ")+nomFich).toUTF8().c_str());
2746  QDir dir;
2747  fLastOpenPath = dir.absoluteFilePath(nomFich);
2748  }
2749 */
2750 }
2751 
2752 
2753 void G4UIWt::ChangePerspectiveOrthoCallback(const Wt::WString& /* action */) {
2754 
2755  // Theses actions should be in the app toolbar
2756 
2757  printf("*** G4UIWt::ChangePerspectiveOrthoCallback, missing \n");
2758 /*
2759  if (fToolbarApp == NULL) return;
2760  QList<QAction *> list = fToolbarApp->actions ();
2761  Wt::WString checked = "";
2762  for (int i = 0; i < list.size(); ++i) {
2763  if (list.at(i)->data().toString () == action) {
2764  list.at(i)->setChecked(TRUE);
2765  checked = list.at(i)->data().toString ();
2766  } else if (list.at(i)->data().toString () == "persepective") {
2767  list.at(i)->setChecked(FALSE);
2768  } else if (list.at(i)->data().toString () == "ortho") {
2769  list.at(i)->setChecked(FALSE);
2770  }
2771  }
2772 
2773  if ((action == "ortho") && (checked == "ortho")) {
2774  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection o");
2775  } else if ((action == "perspective") && (checked == "perspective")) {
2776  G4UImanager::GetUIpointer()->ApplyCommand("/vis/viewer/set/projection p");
2777  }
2778 */
2779 }
2780 
2781 /*
2782 void G4UIWt::SetIconMoveSelected() {
2783  // Theses actions should be in the app toolbar
2784  fMoveSelected = true;
2785  fRotateSelected = false;
2786  fPickSelected = false;
2787  fZoomInSelected = false;
2788  fZoomOutSelected = false;
2789 
2790  if (fToolbarApp == NULL) return;
2791  QList<QAction *> list = fToolbarApp->actions ();
2792  for (int i = 0; i < list.size(); ++i) {
2793  if (list.at(i)->data().toString () == "move") {
2794  list.at(i)->setChecked(TRUE);
2795  } else if (list.at(i)->data().toString () == "rotate") {
2796  list.at(i)->setChecked(FALSE);
2797  } else if (list.at(i)->data().toString () == "pick") {
2798  list.at(i)->setChecked(FALSE);
2799  } else if (list.at(i)->data().toString () == "zoom_in") {
2800  list.at(i)->setChecked(FALSE);
2801  } else if (list.at(i)->data().toString () == "zoom_out") {
2802  list.at(i)->setChecked(FALSE);
2803  }
2804  }
2805 }
2806 
2807 
2808 void G4UIWt::SetIconRotateSelected() {
2809  // Theses actions should be in the app toolbar
2810  fRotateSelected = true;
2811  fMoveSelected = false;
2812  fPickSelected = false;
2813  fZoomInSelected = false;
2814  fZoomOutSelected = false;
2815 
2816  if (fToolbarApp == NULL) return;
2817  QList<QAction *> list = fToolbarApp->actions ();
2818  for (int i = 0; i < list.size(); ++i) {
2819  if (list.at(i)->data().toString () == "rotate") {
2820  list.at(i)->setChecked(TRUE);
2821  } else if (list.at(i)->data().toString () == "move") {
2822  list.at(i)->setChecked(FALSE);
2823  } else if (list.at(i)->data().toString () == "pick") {
2824  list.at(i)->setChecked(FALSE);
2825  } else if (list.at(i)->data().toString () == "zoom_in") {
2826  list.at(i)->setChecked(FALSE);
2827  } else if (list.at(i)->data().toString () == "zoom_out") {
2828  list.at(i)->setChecked(FALSE);
2829  }
2830  }
2831 }
2832 
2833 
2834 void G4UIWt::SetIconPickSelected() {
2835  // Theses actions should be in the app toolbar
2836  fPickSelected = true;
2837  fMoveSelected = false;
2838  fRotateSelected = false;
2839  fZoomInSelected = false;
2840  fZoomOutSelected = false;
2841 
2842  if (fToolbarApp == NULL) return;
2843  QList<QAction *> list = fToolbarApp->actions ();
2844  for (int i = 0; i < list.size(); ++i) {
2845  if (list.at(i)->data().toString () == "pick") {
2846  list.at(i)->setChecked(TRUE);
2847  } else if (list.at(i)->data().toString () == "move") {
2848  list.at(i)->setChecked(FALSE);
2849  } else if (list.at(i)->data().toString () == "rotate") {
2850  list.at(i)->setChecked(FALSE);
2851  } else if (list.at(i)->data().toString () == "zoom_in") {
2852  list.at(i)->setChecked(FALSE);
2853  } else if (list.at(i)->data().toString () == "zoom_out") {
2854  list.at(i)->setChecked(FALSE);
2855  }
2856  }
2857 }
2858 
2859 
2860 void G4UIWt::SetIconZoomInSelected() {
2861  // Theses actions should be in the app toolbar
2862  fZoomInSelected = true;
2863  fMoveSelected = false;
2864  fRotateSelected = false;
2865  fPickSelected = false;
2866  fZoomOutSelected = false;
2867 
2868  if (fToolbarApp == NULL) return;
2869  QList<QAction *> list = fToolbarApp->actions ();
2870  for (int i = 0; i < list.size(); ++i) {
2871  if (list.at(i)->data().toString () == "zoom_in") {
2872  list.at(i)->setChecked(TRUE);
2873  } else if (list.at(i)->data().toString () == "move") {
2874  list.at(i)->setChecked(FALSE);
2875  } else if (list.at(i)->data().toString () == "rotate") {
2876  list.at(i)->setChecked(FALSE);
2877  } else if (list.at(i)->data().toString () == "pick") {
2878  list.at(i)->setChecked(FALSE);
2879  } else if (list.at(i)->data().toString () == "zoom_out") {
2880  list.at(i)->setChecked(FALSE);
2881  }
2882  }
2883 }
2884 
2885 
2886 void G4UIWt::SetIconZoomOutSelected() {
2887  // Theses actions should be in the app toolbar
2888  fZoomOutSelected = true;
2889  fMoveSelected = false;
2890  fRotateSelected = false;
2891  fPickSelected = false;
2892  fZoomInSelected = false;
2893 
2894  if (fToolbarApp == NULL) return;
2895  QList<QAction *> list = fToolbarApp->actions ();
2896  for (int i = 0; i < list.size(); ++i) {
2897  if (list.at(i)->data().toString () == "zoom_out") {
2898  list.at(i)->setChecked(TRUE);
2899  } else if (list.at(i)->data().toString () == "move") {
2900  list.at(i)->setChecked(FALSE);
2901  } else if (list.at(i)->data().toString () == "rotate") {
2902  list.at(i)->setChecked(FALSE);
2903  } else if (list.at(i)->data().toString () == "pick") {
2904  list.at(i)->setChecked(FALSE);
2905  } else if (list.at(i)->data().toString () == "zoom_in") {
2906  list.at(i)->setChecked(FALSE);
2907  }
2908  }
2909 }
2910 
2911 
2912 void G4UIWt::SetIconSolidSelected() {
2913  // Theses actions should be in the app toolbar
2914 
2915  if (fToolbarApp == NULL) return;
2916  QList<QAction *> list = fToolbarApp->actions ();
2917  for (int i = 0; i < list.size(); ++i) {
2918  if (list.at(i)->data().toString () == "solid") {
2919  list.at(i)->setChecked(TRUE);
2920  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2921  list.at(i)->setChecked(FALSE);
2922  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2923  list.at(i)->setChecked(FALSE);
2924  } else if (list.at(i)->data().toString () == "wireframe") {
2925  list.at(i)->setChecked(FALSE);
2926  }
2927  }
2928 }
2929 
2930 
2931 void G4UIWt::SetIconWireframeSelected() {
2932  // Theses actions should be in the app toolbar
2933 
2934  if (fToolbarApp == NULL) return;
2935  QList<QAction *> list = fToolbarApp->actions ();
2936  for (int i = 0; i < list.size(); ++i) {
2937  if (list.at(i)->data().toString () == "wireframe") {
2938  list.at(i)->setChecked(TRUE);
2939  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2940  list.at(i)->setChecked(FALSE);
2941  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2942  list.at(i)->setChecked(FALSE);
2943  } else if (list.at(i)->data().toString () == "solid") {
2944  list.at(i)->setChecked(FALSE);
2945  }
2946  }
2947 }
2948 
2949 
2950 void G4UIWt::SetIconHLRSelected() {
2951  // Theses actions should be in the app toolbar
2952 
2953  if (fToolbarApp == NULL) return;
2954  QList<QAction *> list = fToolbarApp->actions ();
2955  for (int i = 0; i < list.size(); ++i) {
2956  if (list.at(i)->data().toString () == "hidden_line_removal") {
2957  list.at(i)->setChecked(TRUE);
2958  } else if (list.at(i)->data().toString () == "solid") {
2959  list.at(i)->setChecked(FALSE);
2960  } else if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2961  list.at(i)->setChecked(FALSE);
2962  } else if (list.at(i)->data().toString () == "wireframe") {
2963  list.at(i)->setChecked(FALSE);
2964  }
2965  }
2966 }
2967 
2968 
2969 void G4UIWt::SetIconHLHSRSelected() {
2970  // Theses actions should be in the app toolbar
2971 
2972  if (fToolbarApp == NULL) return;
2973  QList<QAction *> list = fToolbarApp->actions ();
2974  for (int i = 0; i < list.size(); ++i) {
2975  if (list.at(i)->data().toString () == "hidden_line_and_surface_removal") {
2976  list.at(i)->setChecked(TRUE);
2977  } else if (list.at(i)->data().toString () == "solid") {
2978  list.at(i)->setChecked(FALSE);
2979  } else if (list.at(i)->data().toString () == "hidden_line_removal") {
2980  list.at(i)->setChecked(FALSE);
2981  } else if (list.at(i)->data().toString () == "wireframe") {
2982  list.at(i)->setChecked(FALSE);
2983  }
2984  }
2985 }
2986 
2987 
2988 void G4UIWt::SetIconPerspectiveSelected() {
2989  // Theses actions should be in the app toolbar
2990 
2991  if (fToolbarApp == NULL) return;
2992  QList<QAction *> list = fToolbarApp->actions ();
2993  for (int i = 0; i < list.size(); ++i) {
2994  if (list.at(i)->data().toString () == "perspective") {
2995  list.at(i)->setChecked(TRUE);
2996  } else if (list.at(i)->data().toString () == "ortho") {
2997  list.at(i)->setChecked(FALSE);
2998  }
2999  }
3000 }
3001 
3002 
3003 
3004 void G4UIWt::SetIconOrthoSelected() {
3005  // Theses actions should be in the app toolbar
3006 
3007  if (fToolbarApp == NULL) return;
3008  QList<QAction *> list = fToolbarApp->actions ();
3009  for (int i = 0; i < list.size(); ++i) {
3010  if (list.at(i)->data().toString () == "ortho") {
3011  list.at(i)->setChecked(TRUE);
3012  } else if (list.at(i)->data().toString () == "perspective") {
3013  list.at(i)->setChecked(FALSE);
3014  }
3015  }
3016 }
3017 */
3018 
3019 
3026 void G4UIWt::FillHelpTree()
3027 {
3028  if (! fHelpTreeWidget ) {
3029  InitHelpTreeAndVisParametersWidget();
3030  }
3031 
3032  Wt::WString searchText = fHelpLine->text();
3033 
3034  if (searchText =="") {
3035  // clear old help tree
3036  // fHelpTreeWidget->clear();
3037  } else {
3038  return;
3039  }
3040 
3041  if (fHelpArea) {
3042  fHelpArea->setText("");
3043  }
3044 
3045  if (fHelpLine) {
3046  fHelpLine->setText("");
3047  }
3048 
3050  if(UI==NULL) return;
3051  G4UIcommandTree * treeTop = UI->GetTree();
3052 
3053  G4int treeSize = treeTop->GetTreeEntry();
3054  Wt::WTreeNode * newItem = NULL;
3055  Wt::WString commandText = "";
3056 
3057  for (int a=0;a<treeSize;a++) {
3058  // Creating new item
3059  newItem = NULL;
3060 
3061  // trim path
3062  std::string whiteSpaces( " \f\n\r\t\v" );
3063  std::string path = (treeTop->GetTree(a+1)->GetPathName()).data();
3064 
3065  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3066  path.erase( posR + 1 );
3067 
3068  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3069  path.erase( 0, posL );
3070 
3071  commandText = Wt::WString(path.c_str());
3072 
3073  // if already exist, don't create it !
3074  if (fHelpTreeWidget->treeRoot()) {
3075  for (int b=0;b<fHelpTreeWidget->treeRoot()->displayedChildCount();b++) {
3076  if (!newItem)
3077  newItem = FindTreeItem(fHelpTreeWidget->treeRoot()->childNodes()[b],path.c_str());
3078  }
3079  }
3080  if (newItem == NULL) {
3081  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0);
3082  fHelpTreeWidget->setTreeRoot(newItem);
3083  }
3084 
3085  // look for childs
3086  CreateHelpTree(newItem,treeTop->GetTree(a+1));
3087  }
3088 
3089 }
3090 
3091 
3092 
3101 void G4UIWt::PauseSessionStart (
3102  const G4String& aState
3103  )
3104 {
3105  if (!aState) return;
3106 
3107  if(aState=="G4_pause> ") { // TO KEEP
3108  SecondaryLoop ("Pause, type continue to exit this state"); // TO KEEP
3109  } // TO KEEP
3110 
3111  if(aState=="EndOfEvent") { // TO KEEP
3112  // Picking with feed back in event data Done here !!!
3113  SecondaryLoop ("End of event, type continue to exit this state"); // TO KEEP
3114  } // TO KEEP
3115 }
3116 
3117 
3118 
3119 
3120 
3121 
3122 
3123 
3124 void G4UIWt::ActivateCommand(
3125  G4String newCommand
3126  )
3127 {
3128  if (!fHelpTreeWidget) {
3129  return;
3130  }
3131  // Look for the choosen command "newCommand"
3132  size_t i = newCommand.index(" ");
3133  G4String targetCom ="";
3134  if( i != std::string::npos )
3135  {
3136  G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
3137  newValue.strip(G4String::both);
3138  targetCom = ModifyToFullPathCommand( newValue );
3139  }
3140 #ifdef G4DEBUG_INTERFACES_BASIC
3141  printf("G4UIWt::ActivateCommand found : %s \n",targetCom.data());
3142 #endif
3143  if (targetCom != "") {
3144  OpenHelpTreeOnCommand(targetCom.data());
3145  }
3146 
3147  fUITabWidget->setCurrentWidget(fHelpTBWidget);
3148 }
3149 
3150 
3151 
3158 void G4UIWt::InitHelpTreeAndVisParametersWidget()
3159 {
3160 
3161  if (! fHelpTreeWidget ) {
3162  fHelpTreeWidget = new Wt::WTree();
3163  }
3164 
3165  // build widget
3166  fHelpTreeWidget->setSelectionMode(Wt::SingleSelection);
3167 
3168  fHelpTreeWidget->itemSelectionChanged ().connect(this,&G4UIWt::HelpTreeClicCallback);
3169 }
3170 
3171 
3176 void G4UIWt::CreateHelpTree(
3177  Wt::WTreeNode *aParent
3178  ,G4UIcommandTree *aCommandTree
3179  )
3180 {
3181  if (aParent == NULL) return;
3182  if (aCommandTree == NULL) return;
3183 
3184 
3185  // Creating new item
3186  Wt::WTreeNode * newItem;
3187 
3188  Wt::WString commandText = "";
3189  // Get the Sub directories
3190  for (int a=0;a<aCommandTree->GetTreeEntry();a++) {
3191 
3192  // trim path
3193  std::string whiteSpaces( " \f\n\r\t\v" );
3194  std::string path = (aCommandTree->GetTree(a+1)->GetPathName()).data();
3195 
3196  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3197  path.erase( posR + 1 );
3198 
3199  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3200  path.erase( 0, posL );
3201 
3202  commandText = Wt::WString(path.c_str());
3203 
3204  // if already exist, don't create it !
3205  newItem = FindTreeItem(aParent,path.c_str());
3206  if (newItem == NULL) {
3207  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3208  }
3209  CreateHelpTree(newItem,aCommandTree->GetTree(a+1));
3210  }
3211 
3212  // Get the Commands
3213 
3214  for (int a=0;a<aCommandTree->GetCommandEntry();a++) {
3215 
3216  // trim path
3217  std::string whiteSpaces( " \f\n\r\t\v" );
3218  std::string path = (aCommandTree->GetCommand(a+1)->GetCommandPath()).data();
3219 
3220  std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3221  path.erase( posR + 1 );
3222 
3223  std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3224  path.erase( 0, posL );
3225 
3226  commandText = Wt::WString(path.c_str());
3227 
3228  // if already exist, don't create it !
3229  newItem = FindTreeItem(aParent,path.c_str());
3230  if (newItem == NULL) {
3231 
3232  newItem = new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3233 
3234  newItem->collapse();
3235  }
3236  }
3237 }
3238 
3239 
3240 
3241 
3242 
3243 
3244 
3249 Wt::WTreeNode* G4UIWt::FindTreeItem(
3250  Wt::WTreeNode *aParent
3251  ,const std::string& aCommand
3252  )
3253 {
3254  if (aParent == NULL) return NULL;
3255 
3256  // Suppress last "/"
3257  std::string myCommand = aCommand;
3258 
3259 
3260  if (myCommand.rfind("/") == (myCommand.size()-1)) {
3261  myCommand = myCommand.substr(0,myCommand.size()-1);
3262  }
3263 
3264  if (GetLongCommandPath(aParent) == Wt::WString(myCommand.c_str()))
3265  return aParent;
3266 
3267  Wt::WTreeNode * tmp = NULL;
3268  for (unsigned int a=0;a<aParent->childNodes().size();a++) {
3269  if (!tmp)
3270  tmp = FindTreeItem(aParent->childNodes().at(a),myCommand);
3271  }
3272  return tmp;
3273 }
3274 
3275 
3276 
3284 Wt::WString G4UIWt::GetCommandList (
3285  const G4UIcommand *aCommand
3286  )
3287 {
3288 
3289  Wt::WString txt ="";
3290  if (aCommand == NULL)
3291  return txt;
3292 
3293  G4String commandPath = aCommand->GetCommandPath();
3294  G4String rangeString = aCommand->GetRange();
3295  G4int n_guidanceEntry = aCommand->GetGuidanceEntries();
3296  G4int n_parameterEntry = aCommand->GetParameterEntries();
3297 
3298  if ((commandPath == "") &&
3299  (rangeString == "") &&
3300  (n_guidanceEntry == 0) &&
3301  (n_parameterEntry == 0)) {
3302  return txt;
3303  }
3304 
3305  if((commandPath.length()-1)!='/') {
3306  txt += "Command " + Wt::WString((char*)(commandPath).data()) + "\n";
3307  }
3308  txt += "Guidance :\n";
3309 
3310  for( G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3311  txt += Wt::WString((char*)(aCommand->GetGuidanceLine(i_thGuidance)).data()) + "\n";
3312  }
3313  if( ! rangeString.isNull() ) {
3314  txt += " Range of parameters : " + Wt::WString((char*)(rangeString).data()) + "\n";
3315  }
3316  if( n_parameterEntry > 0 ) {
3317  G4UIparameter *param;
3318 
3319  // Re-implementation of G4UIparameter.cc
3320 
3321  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3322  param = aCommand->GetParameter(i_thParameter);
3323  txt += "\nParameter : " + Wt::WString((char*)(param->GetParameterName()).data()) + "\n";
3324  if( ! param->GetParameterGuidance().isNull() )
3325  txt += Wt::WString((char*)(param->GetParameterGuidance()).data())+ "\n" ;
3326  char myChar = param->GetParameterType();
3327  txt += " Parameter type : " + Wt::WString(&myChar) + "\n";
3328  if(param->IsOmittable()){
3329  txt += " Omittable : True\n";
3330  } else {
3331  txt += " Omittable : False\n";
3332  }
3333  if( param->GetCurrentAsDefault() ) {
3334  txt += " Default value : taken from the current value\n";
3335  } else if( ! param->GetDefaultValue().isNull() ) {
3336  txt += " Default value : " + Wt::WString((char*)(param->GetDefaultValue()).data())+ "\n";
3337  }
3338  if( ! param->GetParameterRange().isNull() ) {
3339  txt += " Parameter range : " + Wt::WString((char*)(param->GetParameterRange()).data())+ "\n";
3340  }
3341  if( ! param->GetParameterCandidates().isNull() ) {
3342  txt += " Candidates : " + Wt::WString((char*)(param->GetParameterCandidates()).data())+ "\n";
3343  }
3344  }
3345  }
3346  return txt;
3347 }
3348 
3349 
3355 G4bool G4UIWt::IsGUICommand(
3356  const G4UIcommand *aCommand
3357  )
3358 {
3359  if (aCommand == NULL)
3360  return false;
3361 
3362  G4int n_parameterEntry = aCommand->GetParameterEntries();
3363 
3364  if( n_parameterEntry > 0 ) {
3365  G4UIparameter *param;
3366 
3367  // Re-implementation of G4UIparameter.cc
3368 
3369  for( G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3370  param = aCommand->GetParameter(i_thParameter);
3371  char myChar = param->GetParameterType();
3372  if (myChar == 'd') {
3373  return true;
3374  }
3375  if (myChar == 'b') {
3376  return true;
3377  }
3378  if (myChar == 'i') {
3379  return true;
3380  }
3381  if (myChar == 's' && (!param->GetParameterCandidates().isNull())) {
3382  return true;
3383  }
3384  }
3385  }
3386  return false;
3387 }
3388 
3389 
3393 G4bool G4UIWt::GetHelpChoice(
3394  G4int&
3395  )
3396 {
3397 #ifdef G4DEBUG_INTERFACES_BASIC
3398  printf("G4UIWt::GetHelpChoice SHOULD NEVER GO HERE");
3399 #endif
3400  return true;
3401 }
3402 
3403 
3404 
3405 
3406 
3407 /***************************************************************************/
3408 //
3409 // SLOTS DEFINITIONS
3410 //
3411 /***************************************************************************/
3412 
3415 void G4UIWt::ShowHelpCallback (
3416 )
3417 {
3418  TerminalHelp("");
3419 }
3420 
3421 
3424 void G4UIWt::ClearButtonCallback (
3425 )
3426 {
3427  fCoutTBTextArea->setText("");
3428  fG4cout.removeRows(0,fG4cout.rowCount());
3429 }
3430 
3433 void G4UIWt::ExitSession (
3434 )
3435 {
3436  SessionTerminate();
3437 }
3438 
3439 void G4UIWt::ExitHelp(
3440 ) const
3441 {
3442 }
3443 
3444 
3445 
3446 
3452 void G4UIWt::ButtonCallback (
3453  const char* aCommand
3454  )
3455 {
3456  G4String ss = G4String(aCommand);
3457  ss = ss.strip(G4String::leading);
3458 
3460  if(UI==NULL) return;
3461  G4UIcommandTree * treeTop = UI->GetTree();
3462 
3463  G4UIcommand* command = treeTop->FindPath(ss);
3464 
3465  if (command) {
3466  // if is GUI, then open a dialog
3467  if (IsGUICommand(command)) {
3468  Wt::WDialog* menuParameterDialog = new Wt::WDialog();
3469 
3470  if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,true)) {
3471  menuParameterDialog->setWindowTitle (aCommand);
3472 
3473  // exec this dialog, apply the command automaticaly, and return
3474  menuParameterDialog->exec();
3475  return;
3476  }
3477  }
3478  }
3479 
3480  ApplyShellCommand(ss,fExitSession,fExitPause);
3481 
3482  // Rebuild help tree
3483  FillHelpTree();
3484 
3485  if(fExitSession==true)
3486  SessionTerminate();
3487 }
3488 
3489 
3490 
3491 
3492 
3497 void G4UIWt::LookForHelpStringCallback(
3498 )
3499 {
3500  Wt::WString searchText = fHelpLine->text();
3501 
3502  fHelpArea->setText("");
3503  if (searchText =="") {
3504  // clear old help tree
3505  fHelpTreeWidget = new Wt::WTree();
3506 
3507  FillHelpTree();
3508 
3509  return;
3510  } else {
3511  OpenHelpTreeOnCommand(searchText);
3512  }
3513 }
3514 
3515 
3516 
3517 
3518 Wt::WString G4UIWt::GetShortCommandPath(
3519  const std::string& aTxt
3520  )
3521 {
3522  std::string commandPath;
3523  if (aTxt.find("/", 0) != std::string::npos) {
3524  // commandPath = commandPath.right(commandPath.size()-1);
3525  commandPath = aTxt.substr(aTxt.size()-1);
3526  }
3527 
3528  // commandPath = commandPath.right(commandPath.size()-commandPath.lastIndexOf("/",-2)-1);
3529  commandPath = commandPath.substr(commandPath.size()-commandPath.rfind("/",-2)-1);
3530 
3531  // if (commandPath.lastIndexOf("/") == (commandPath.size()-1)) {
3532  if (commandPath.rfind("/") == (commandPath.size()-1)) {
3533  // commandPath = commandPath.left(commandPath.size()-1);
3534  commandPath = commandPath.substr(0,commandPath.size()-1);
3535  }
3536 
3537  return commandPath.c_str();
3538 }
3539 
3540 
3541 Wt::WString G4UIWt::GetLongCommandPath(
3542  Wt::WTreeNode* item
3543  )
3544 {
3545  if (item == NULL) return "";
3546 
3547  // rebuild path:
3548  Wt::WString itemText = "";
3549  itemText = item->label()->text();
3550 
3551  while (item->parentNode() != NULL) {
3552  itemText = item->parentNode()->label()->text()+"/"+itemText;
3553  item = item->parentNode();
3554  }
3555  itemText = "/"+itemText;
3556 
3557  return itemText;
3558 }
3559 
3560 
3561 
3562 
3563 
3564 
3565 
3566 
3567 
3568 
3569 
3570 
3571 G4WTabWidget::G4WTabWidget(
3572  Wt::WContainerWidget*& /* split */
3573 ):
3574  Wt::WTabWidget()
3575 ,tabSelected(false)
3576 ,lastCreated(-1)
3577 {
3578 }
3579 
3580 G4WTabWidget::G4WTabWidget(
3581 ):Wt::WTabWidget()
3582 ,tabSelected(false)
3583 ,lastCreated(-1)
3584 {
3585 }
3586 
3587 
3588 
3589 void G4UIWt::TabCloseCallback(int a){
3590  Wt::WWidget* temp = fViewerTabWidget->widget(a);
3591  fViewerTabWidget->removeTab (temp);
3592 
3593  delete temp;
3594 
3595  if (fViewerTabWidget->count() == 0) {
3596  fEmptyViewerTabLabel->show();
3597  }
3598 
3599 }
3600 
3601 
3602 void G4UIWt::ToolBoxActivated(int a){
3603 
3604  if (fUITabWidget->widget(a) == fHelpTBWidget) {
3605  // Rebuild the help tree
3606  FillHelpTree();
3607  } else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3608  fSceneTreeComponentsTBWidget->hide();
3609  }
3610 }
3611 
3612 
3613 #endif
G4UIcommandTree * FindCommandTree(const char *commandPath)
Float_t tmp
Definition: plot.C:37
G4String GetParameterCandidates() const
char cmd[1024]
Definition: tracer.cxx:25
const G4String & GetRange() const
Definition: G4UIcommand.hh:133
tuple a
Definition: test.py:11
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
const XML_Char * name
Definition: expat.h:151
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()
tuple b
Definition: test.py:12
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:591
char GetParameterType() const
#define G4endl
Definition: G4ios.hh:61
printf("%d Experimental points found\n", nlines)
const G4String GetParameterGuidance() const
G4String GetParameterRange() const
G4int GetGuidanceEntries() const
Definition: G4UIcommand.hh:135
G4int GetParameterEntries() const
Definition: G4UIcommand.hh:143
G4bool GetCurrentAsDefault() const
G4bool isNull() const
const XML_Char const XML_Char * data
Definition: expat.h:268
G4int ApplyCommand(const char *aCommand)
Definition: G4UImanager.cc:419