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