31 #ifdef G4UI_BUILD_WT_SESSION
44 #include <Wt/WLineedit>
45 #include <Wt/WTextarea>
46 #include <Wt/Wmessagebox>
48 #include <Wt/Wradiobutton>
49 #include <Wt/Wbuttongroup>
50 #include <Wt/Wcombobox>
51 #include <Wt/WVBoxLayout>
52 #include <Wt/WHBoxLayout>
53 #include <Wt/WGridLayout>
55 #include <Wt/WSelectionBox>
58 #define G4DEBUG_INTERFACES_BASIC 1
61 static G4bool exitSession =
true;
62 static G4bool exitPause =
true;
91 ,fCoutTBTextArea(NULL)
96 ,fHistoryTBTableList(NULL)
97 ,fHelpTreeWidget(NULL)
99 ,fHistoryTBWidget(NULL)
101 ,fSceneTreeComponentsTBWidget(NULL)
103 ,fViewerTabWidget(NULL)
105 ,fEmptyViewerTabLabel(NULL)
106 ,fMainSplitterWidget(NULL)
107 ,fRightSplitterWidget(NULL)
108 ,fHelpVSplitter(NULL)
111 ,fStringSeparator(
"__$$$@%%###__")
113 ,fMoveSelected(false)
114 ,fRotateSelected(true)
115 ,fPickSelected(false)
116 ,fZoomInSelected(false)
117 ,fZoomOutSelected(false)
123 G4Wt* interactorManager = G4Wt::getInstance (argc,argv,(
char*)
"Wt");
124 if (!(Wt::WApplication*)interactorManager->GetMainInteractor()) {
129 G4cout <<
"G4UIWt : Unable to init Wt. Aborted" <<
G4endl;
137 fMainWindow =
new Wt::WContainerWidget(wApp->root());
140 Wt::WVBoxLayout* mainWindowVLayout =
new Wt::WVBoxLayout();
141 fMainWindow->setLayout(mainWindowVLayout);
144 #ifdef G4DEBUG_INTERFACES_BASIC
145 printf(
"G4UIWt::Initialise after main window creation +++++++++++\n");
150 fMainSplitterWidget =
new Wt::WContainerWidget();
151 Wt::WGridLayout* fMainSplitterWidgetLayout =
new Wt::WGridLayout();
154 fMainSplitterWidgetLayout->addWidget(CreateLeftSplitterWidget(),1,1);
155 fMainSplitterWidgetLayout->addWidget(CreateRightSplitterWidget(),1,2);
156 fMainSplitterWidgetLayout->setColumnResizable (1,
true,Wt::WLength(30,Wt::WLength::Percentage));
162 fMainSplitterWidget->setLayout(fMainSplitterWidgetLayout);
163 mainWindowVLayout->addWidget(fMainSplitterWidget);
167 #ifdef G4DEBUG_INTERFACES_BASIC
168 printf(
"G4UIWt::G4UIWt :: 5\n");
174 wApp->setTitle(
"Wt application");
185 #ifdef G4DEBUG_INTERFACES_BASIC
186 printf(
"G4UIWt::~G4UIWt Delete\n");
195 if (fMainWindow!=NULL) {
196 #ifdef G4DEBUG_INTERFACES_BASIC
197 printf(
"G4UIWt::~G4UIWt DELETE fMainWindow\n");
205 Wt::WWidget* G4UIWt::CreateHistoryTBWidget(
208 fHistoryTBWidget =
new Wt::WPanel();
209 fHistoryTBWidget->setCollapsed(
true);
210 fHistoryTBWidget->setCollapsible(
true);
212 fHistoryTBTableList =
new Wt::WSelectionBox();
213 fHistoryTBTableList->setSelectionMode(Wt::SingleSelection);
214 fHistoryTBTableList->changed().connect(
this,&G4UIWt::CommandHistoryCallback);
216 fHistoryTBWidget->setCentralWidget(fHistoryTBTableList);
217 return fHistoryTBWidget;
223 Wt::WWidget* G4UIWt::CreateHelpTBWidget(
226 fHelpTBWidget =
new Wt::WPanel();
227 fHelpTBWidget->setCollapsible(
true);
229 Wt::WContainerWidget *helpWidget =
new Wt::WContainerWidget();
230 Wt::WHBoxLayout *helpLayout =
new Wt::WHBoxLayout();
231 Wt::WVBoxLayout *vLayout =
new Wt::WVBoxLayout();
233 fHelpVSplitter =
new Wt::WContainerWidget();
234 fHelpVSplitter->setLayout(
new Wt::WHBoxLayout());
236 Wt::WVBoxLayout* VHelpSplitterVLayout =
new Wt::WVBoxLayout();
237 fHelpVSplitter->setLayout(VHelpSplitterVLayout);
240 fHelpLine =
new Wt::WLineEdit();
241 fHelpTBWidget->setCentralWidget(helpWidget);
242 helpWidget->setLayout(helpLayout);
243 helpWidget->layout()->addWidget(
new Wt::WLabel(Wt::WString(
"Search :")));
244 helpWidget->layout()->addWidget(fHelpLine);
245 printf(
"*** G4UIWt::CreateHelpTBWidget, missing EnterPress connection\n");
251 fHelpArea =
new Wt::WTextArea(fHelpVSplitter);
252 fHelpArea->setReadOnly(
true);
256 if (fHelpTreeWidget) {
257 fHelpVSplitter->addWidget(fHelpTreeWidget);
259 fHelpVSplitter->addWidget(fHelpArea);
261 vLayout->addWidget(helpWidget);
262 vLayout->addWidget(fHelpVSplitter,1);
272 return fHelpTBWidget;
278 Wt::WWidget* G4UIWt::CreateCoutTBWidget(
281 fCoutTBWidget =
new Wt::WPanel();
282 fCoutTBWidget->setCollapsible(
true);
283 fCoutTBWidget->setTitle(
"Output");
284 fCoutTBWidget->setCollapsed(
false);
286 Wt::WContainerWidget* myContainer =
new Wt::WContainerWidget();
287 Wt::WVBoxLayout *myContainerVLayout =
new Wt::WVBoxLayout();
288 myContainer->setLayout(myContainerVLayout);
291 if (!fCoutTBTextArea) {
292 fCoutTBTextArea =
new Wt::WTextArea(myContainer);
294 fCoutFilter =
new Wt::WLineEdit();
295 Wt::WLabel* coutFilterLabel =
new Wt::WLabel(
"Filter : ");
296 myContainerVLayout->addWidget(fCoutTBTextArea);
297 myContainerVLayout->addWidget(fCoutFilter);
298 myContainerVLayout->addWidget(coutFilterLabel);
300 Wt::WPushButton *coutTBClearButton =
new Wt::WPushButton (
"clear",myContainer);
307 fCoutTBTextArea->setReadOnly(
true);
309 Wt::WContainerWidget* coutButtonWidget =
new Wt::WContainerWidget(myContainer);
310 Wt::WHBoxLayout* layoutCoutTBButtons =
new Wt::WHBoxLayout(coutButtonWidget);
311 layoutCoutTBButtons->addWidget(coutTBClearButton);
312 layoutCoutTBButtons->addWidget(coutFilterLabel);
313 layoutCoutTBButtons->addWidget(fCoutFilter);
315 myContainerVLayout->addWidget(coutButtonWidget);
317 fCoutTBWidget->setCentralWidget(myContainer);
319 return fCoutTBWidget;
325 Wt::WContainerWidget* G4UIWt::CreateVisParametersTBWidget(
334 Wt::WWidget* G4UIWt::CreateUITabWidget(
337 fUITabWidget =
new Wt::WTabWidget();
340 fUITabWidget->addTab(CreateSceneTreeComponentsTBWidget(),
"Scene tree");
341 fUITabWidget->addTab(CreateHelpTBWidget(),
"Help");
342 fUITabWidget->addTab(CreateHistoryTBWidget(),
"History");
353 Wt::WWidget* G4UIWt::CreateSceneTreeComponentsTBWidget(){
355 fSceneTreeComponentsTBWidget =
new Wt::WTabWidget();
357 fSceneTreeComponentsTBWidget->hide();
359 return fSceneTreeComponentsTBWidget;
363 Wt::WContainerWidget* G4UIWt::CreateLeftSplitterWidget(){
365 fLeftSplitterWidget =
new Wt::WContainerWidget();
366 Wt::WVBoxLayout * layoutLeftSplitterWidget =
new Wt::WVBoxLayout();
367 fLeftSplitterWidget->setLayout(layoutLeftSplitterWidget);
369 layoutLeftSplitterWidget->addWidget(CreateUITabWidget());
371 return fLeftSplitterWidget;
375 Wt::WContainerWidget* G4UIWt::CreateRightSplitterWidget(){
377 fRightSplitterWidget =
new Wt::WContainerWidget();
380 Wt::WVBoxLayout* VSplitterVLayout =
new Wt::WVBoxLayout();
381 fRightSplitterWidget->setLayout(VSplitterVLayout);
382 Wt::WContainerWidget* commandLineWidget =
new Wt::WContainerWidget();
384 Wt::WHBoxLayout *layoutCommandLine =
new Wt::WHBoxLayout();
385 commandLineWidget->setLayout(layoutCommandLine);
389 fCommandLabel =
new Wt::WLabel(
"",commandLineWidget);
390 fCommandArea =
new Wt::WLineEdit(commandLineWidget);
391 fCommandArea->setToolTip(
"Apply command");
394 layoutCommandLine->addWidget(fCommandLabel);
395 layoutCommandLine->addWidget(fCommandArea);
398 fViewerTabWidget =
new G4WTabWidget(fRightSplitterWidget);
400 fViewerTabWidget->tabClosed().connect(
this, &G4UIWt::TabCloseCallback);
402 fViewerTabWidget->currentChanged().connect(
this,&G4UIWt::CurrentChangedTabWidgetCallback);
405 fEmptyViewerTabLabel =
new Wt::WLabel(
" If you want to have a Viewer, please use /vis/open commands. ");
408 fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
409 fRightSplitterWidget->layout()->addWidget(fEmptyViewerTabLabel);
410 fRightSplitterWidget->layout()->addWidget(CreateCoutTBWidget());
411 fRightSplitterWidget->layout()->addWidget(commandLineWidget);
413 commandLineWidget->setMinimumSize(50,50);
416 fCommandArea->enterPressed().connect(
this,&G4UIWt::CommandEnteredCallback);
418 return fRightSplitterWidget;
424 Wt::WTabWidget* G4UIWt::GetSceneTreeComponentsTBWidget(
427 return fSceneTreeComponentsTBWidget;
434 bool G4UIWt::AddTabWidget(
457 if (!fViewerTabWidget->isVisible() ) {
458 if ( fRightSplitterWidget->isVisible()) {
459 fRightSplitterWidget->setHidden(
true);
460 fEmptyViewerTabLabel->setHidden(
true);
462 #ifdef G4DEBUG_INTERFACES_BASIC
463 printf(
"G4UIWt::AddTabWidget +++++\n");
465 fViewerTabWidget->show();
466 fViewerTabWidget =
new G4WTabWidget(fRightSplitterWidget);
468 fViewerTabWidget->tabClosed().connect(
this, &G4UIWt::TabCloseCallback);
470 fViewerTabWidget->currentChanged().connect(
this,&G4UIWt::CurrentChangedTabWidgetCallback);
471 fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
489 fViewerTabWidget->addTab(aWidget,name);
492 aWidget->decorationStyle().setBackgroundColor (Wt::WColor(245,245,245));
494 fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
497 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
504 void G4UIWt::CurrentChangedTabWidgetCallback(
int tabNumber) {
505 #ifdef G4DEBUG_INTERFACES_BASIC
506 printf(
"G4UIWt::CurrentChangedTabWidget %d\n",tabNumber);
508 if ( fViewerTabWidget == NULL) {
509 fViewerTabWidget =
new G4WTabWidget;
512 #ifdef G4DEBUG_INTERFACES_BASIC
513 printf(
"G4UIWt::CurrentChangedTabWidget CALL REPAINT tabGL\n");
516 fViewerTabWidget->setCurrentIndex(tabNumber);
519 fViewerTabWidget->setTabSelected(
false);
521 fViewerTabWidget->show();
524 fViewerTabWidget->setTabSelected(
true);
527 Wt::WString text = fViewerTabWidget->tabText (tabNumber);
529 Wt::WString paramSelect = Wt::WString(
"/vis/viewer/select ")+text;
542 #ifdef G4DEBUG_INTERFACES_BASIC
543 printf(
"G4UIWt::G4UIWt SessionStart 1\n");
546 G4Wt* interactorManager = G4Wt::getInstance ();
553 #ifdef G4DEBUG_INTERFACES_BASIC
554 printf(
"G4UIWt::G4UIWt SessionStart2\n");
556 interactorManager->DisableSecondaryLoop ();
569 interactorManager->EnableSecondaryLoop ();
580 void G4UIWt::Prompt (
584 if (!aPrompt)
return;
585 if (!fCommandLabel)
return;
587 fCommandLabel->setText((
char*)aPrompt.
data());
592 void G4UIWt::SessionTerminate (
595 G4Wt* interactorManager = G4Wt::getInstance ();
597 if ((Wt::WApplication*)interactorManager->GetMainInteractor()) {
608 void G4UIWt::SecondaryLoop (
612 if (!aPrompt)
return;
614 G4Wt* interactorManager = G4Wt::getInstance ();
618 while((eventTmp = interactorManager->GetEvent())!=NULL) {
619 interactorManager->DispatchEvent(eventTmp);
620 if(fExitPause==
true)
break;
629 void G4UIWt::CommandEnteredCallback (
632 #ifdef G4DEBUG_INTERFACES_BASIC
633 printf(
"G4UIWt::CommandEnteredCallback\n");
635 #ifdef G4DEBUG_INTERFACES_BASIC
636 printf(
"G4UIWt::CommandEnteredCallback 1\n");
638 G4String command (fCommandArea->text().toUTF8());
639 if (fCommandArea->text() !=
"") {
641 printf(
"*** G4UIWt::CommandEnteredCallback, missing update on history \n");
647 fCommandArea->setText(
"");
648 #ifdef G4DEBUG_INTERFACES_BASIC
649 printf(
"G4UIWt::CommandEnteredCallback 2\n");
652 G4Wt* interactorManager = G4Wt::getInstance ();
653 #ifdef G4DEBUG_INTERFACES_BASIC
654 printf(
"G4UIWt::CommandEnteredCallback 3\n");
656 if (interactorManager) {
657 interactorManager->FlushAndWaitExecution();
659 #ifdef G4DEBUG_INTERFACES_BASIC
660 printf(
"G4UIWt::CommandEnteredCallback 4\n");
662 if (command(0,4) !=
"help") {
663 ApplyShellCommand (command,exitSession,exitPause);
665 ActivateCommand(command);
667 #ifdef G4DEBUG_INTERFACES_BASIC
668 printf(
"G4UIWt::CommandEnteredCallback 5\n");
673 #ifdef G4DEBUG_INTERFACES_BASIC
674 printf(
"G4UIWt::CommandEnteredCallback 6\n");
676 if(exitSession==
true)
679 #ifdef G4DEBUG_INTERFACES_BASIC
680 printf(
"G4UIWt::CommandEnteredCallback END\n");
692 void G4UIWt::AddButton (
695 ,
const char* aCommand
698 if(aMenu==NULL)
return;
699 if(aLabel==NULL)
return;
700 if(aCommand==NULL)
return;
702 Wt::WMenu *parentTmp = (Wt::WMenu*)GetInteractor(aMenu);
704 if(parentTmp==NULL) {
709 G4cout <<
"Menu name " << aMenu<<
" does not exist, please define it before using it."<<
G4endl;
720 G4int cmdEndPos = cmd.find_first_of(
" \t");
721 if(cmdEndPos!=
G4int(std::string::npos)) {
722 cmd.erase(cmdEndPos);
725 if(treeTop->
FindPath(aCommand) == NULL) {
730 G4cout <<
"Warning: command '"<< aCommand <<
"' does not exist, please define it before using it."<<
G4endl;
734 printf(
"*** G4UIWt::AddButton, missing connection on menu callback \n");
748 void G4UIWt::AddIcon(
const char* aLabel,
const char* aIconFile,
const char* aCommand,
const char* ){
749 if(aLabel==NULL)
return;
751 if (aCommand==NULL) {
752 if (std::string(aIconFile) ==
"user_icon") {
756 printf(
"*** G4UIWt::AddIcon, missing icon creation \n");
1640 bool G4UIWt::CreateCommandWidget(
G4UIcommand* aCommand, Wt::WContainerWidget* aParent,
bool isDialog) {
1642 if (aCommand == NULL) {
1649 if( n_parameterEntry > 0 ) {
1653 Wt::WContainerWidget* paramWidget =
new Wt::WContainerWidget();
1654 Wt::WGridLayout* gridLayout =
new Wt::WGridLayout(paramWidget);
1657 unsigned int nbColorParameter = 0;
1658 bool isStillColorParameter =
false;
1659 bool isColorDialogAdded =
false;
1660 Wt::WLabel* redLabel = NULL;
1661 Wt::WLabel* greenLabel = NULL;
1662 Wt::WString redDefaultStr =
"";
1663 Wt::WString greenDefaultStr =
"";
1664 Wt::WString blueDefaultStr =
"";
1665 Wt::WWidget* redInput = NULL;
1666 Wt::WWidget* greenInput = NULL;
1668 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1671 Wt::WLabel* label =
new Wt::WLabel(Wt::WString((
char*)(param->
GetParameterName()).data()));
1673 if ((label->text() ==
"red") || (label->text() ==
"red_or_string")){
1674 nbColorParameter ++;
1675 isStillColorParameter =
true;
1676 }
else if ((label->text() ==
"green") && isStillColorParameter) {
1677 nbColorParameter ++;
1678 }
else if ((label->text() ==
"blue") && isStillColorParameter) {
1679 nbColorParameter ++;
1680 }
else if (!isColorDialogAdded) {
1683 if (nbColorParameter == 1) {
1684 gridLayout->addWidget(redLabel,i_thParameter-1,0);
1685 gridLayout->addWidget(redInput,i_thParameter-1,1);
1686 }
else if (nbColorParameter == 2) {
1687 gridLayout->addWidget(redLabel,i_thParameter-2,0);
1688 gridLayout->addWidget(redInput,i_thParameter-2,1);
1689 gridLayout->addWidget(greenLabel,i_thParameter-1,0);
1690 gridLayout->addWidget(greenInput,i_thParameter-1,1);
1692 nbColorParameter = 0;
1695 Wt::WWidget* input = NULL;
1697 if ((paramType ==
'd') || (paramType ==
'i')) {
1698 input =
new Wt::WLineEdit();
1700 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
1702 if (((label->text() ==
"red") || (label->text() ==
"red_or_string")) && isStillColorParameter) {
1703 redDefaultStr = Wt::WString((
char*)(param->
GetDefaultValue()).data());
1704 }
else if ((label->text() ==
"green") && isStillColorParameter) {
1705 greenDefaultStr = Wt::WString((
char*)(param->
GetDefaultValue()).data());
1706 }
else if ((label->text() ==
"green") && isStillColorParameter) {
1707 blueDefaultStr = Wt::WString((
char*)(param->
GetDefaultValue()).data());
1710 }
else if (paramType ==
'b') {
1711 input =
new Wt::WContainerWidget();
1712 Wt::WHBoxLayout* layout =
new Wt::WHBoxLayout(input);
1714 Wt::WButtonGroup* buttons =
new Wt::WButtonGroup();
1715 Wt::WRadioButton* radioOff =
new Wt::WRadioButton(
"0");
1716 Wt::WRadioButton* radioOn =
new Wt::WRadioButton(
"1");
1717 buttons->addButton(radioOn);
1718 buttons->addButton(radioOff);
1719 layout->addWidget(radioOn);
1720 layout->addWidget(radioOff);
1723 Wt::WString defaultValue = Wt::WString((
char*)(param->
GetDefaultValue()).data());
1724 if (defaultValue ==
"0") {
1725 radioOff->setChecked(
true);
1726 }
else if (defaultValue ==
"1") {
1727 radioOn->setChecked(
true);
1730 input =
new Wt::WComboBox();
1732 printf(
"*** G4UIWt::CreateCommandWidget, missing parameter management for 's'\n");
1744 }
else if (paramType ==
's') {
1745 input =
new Wt::WLineEdit();
1747 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
1749 }
else if (paramType ==
'c') {
1750 input =
new Wt::WContainerWidget();
1751 Wt::WHBoxLayout* layout =
new Wt::WHBoxLayout(input);
1753 Wt::WButtonGroup* buttons =
new Wt::WButtonGroup();
1754 Wt::WRadioButton* radioOff =
new Wt::WRadioButton(
"off");
1755 Wt::WRadioButton* radioOn =
new Wt::WRadioButton(
"on");
1756 buttons->addButton(radioOn);
1757 buttons->addButton(radioOff);
1758 layout->addWidget(radioOn);
1759 layout->addWidget(radioOff);
1762 Wt::WString defaultValue = Wt::WString((
char*)(param->
GetDefaultValue()).data());
1763 if (defaultValue ==
"off") {
1764 radioOff->setChecked(
true);
1765 }
else if (defaultValue ==
"on") {
1766 radioOn->setChecked(
true);
1770 input =
new Wt::WLineEdit();
1771 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
1774 txt +=
"\nParameter : " + Wt::WString((
char*)(param->
GetParameterName()).data()) +
"\n";
1779 txt += Wt::WString(
" Parameter type : ") + std::string(¶mType).c_str() +
"\n";
1781 txt +=
" Omittable : True\n";
1783 txt +=
" Omittable : False\n";
1786 txt +=
" Default value : taken from the current value\n";
1788 txt +=
" Default value : " + Wt::WString((
char*)(param->
GetDefaultValue()).data())+
"\n";
1791 txt +=
" Parameter range : " + Wt::WString((
char*)(param->
GetParameterRange()).data())+
"\n";
1797 if (isStillColorParameter && (nbColorParameter != 0)) {
1798 if ((label->text() ==
"red") || (label->text() ==
"red_or_string")) {
1801 }
else if (label->text() ==
"green") {
1804 }
else if (label->text() ==
"blue") {
1810 if ((redDefaultStr !=
"") && (redDefaultStr !=
"") && (redDefaultStr !=
"")) {
1812 wc.setRgb(atof(redDefaultStr.toUTF8().c_str())*256,
1813 atof(greenDefaultStr.toUTF8().c_str())*256,
1814 atof(blueDefaultStr.toUTF8().c_str())*256);
1816 printf(
"*** G4UIWt::CreateCommandWidget, missing icon on command widget\n");
1842 isColorDialogAdded =
true;
1843 isStillColorParameter =
false;
1846 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1847 input->setToolTip(txt);
1848 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1852 Wt::WLabel* name =
new Wt::WLabel(Wt::WString((
char*)(aCommand->
GetCommandPath().
data())));
1854 gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
1856 Wt::WPushButton* applyButton =
new Wt::WPushButton(
"Apply");
1859 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
1861 printf(
"*** G4UIWt::CreateCommandWidget, missing connection on ApplyButton\n");
1871 printf(
"*** G4UIWt::CreateCommandWidget, missing connection on Apply/Cancel Button\n");
1903 if (!aParent->layout()) {
1904 aParent->setLayout(
new Wt::WVBoxLayout());
1906 aParent->layout()->addWidget(paramWidget);
1920 bool G4UIWt::eventFilter(
1926 printf(
"*** G4UIWt::eventFilter, missing eventFilter on everything\n");
2001 void G4UIWt::HelpTreeClicCallback (
2004 Wt::WTreeNode* item = NULL;
2005 if (!fHelpTreeWidget)
2011 const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2014 item = *list.begin();
2019 if(UI==NULL)
return;
2022 std::string itemText = GetLongCommandPath(item).toUTF8();
2027 fHelpArea->setText(GetCommandList(command));
2040 void G4UIWt::HelpTreeDoubleClicCallback (
2043 HelpTreeClicCallback();
2045 Wt::WTreeNode* item = NULL;
2046 if (!fHelpTreeWidget)
2052 const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2055 item = *list.begin();
2059 fCommandArea->setText(
"");
2060 fCommandArea->setText(GetLongCommandPath(item));
2069 G4int G4UIWt::ReceiveG4cout (
2073 if (!aString)
return 0;
2075 Wt::WStringListModel newStr;
2078 std::string whiteSpaces(
" \f\n\r\t\v" );
2079 std::string path = (
char*)aString.
data();
2081 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2082 path.erase( posR + 1 );
2084 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2085 path.erase( 0, posL );
2087 printf(
"*** G4UIWt::ReceiveG4cout, missing filtering\n");
2097 if (!fCoutTBTextArea) {
2098 printf(
"*** G4UIWt::ReceiveG4cout, create a new fCoutTBTextArea \n");
2099 fCoutTBTextArea =
new Wt::WTextArea();
2100 fCoutTBTextArea->setText(
"");
2102 fCoutTBTextArea->setText(fCoutTBTextArea->text()+
"\n"+path);
2103 fCoutTBTextArea->refresh();
2114 G4int G4UIWt::ReceiveG4cerr (
2118 if (!aString)
return 0;
2120 Wt::WStringListModel newStr;
2123 std::string whiteSpaces(
" \f\n\r\t\v" );
2124 std::string path = (
char*)aString.
data();
2126 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2127 path.erase( posR + 1 );
2129 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2130 path.erase( 0, posL );
2132 printf(
"*** G4UIWt::ReceiveG4cerr, missing filtering\n");
2144 Wt::WMessageBox::show(
"Error", Wt::WString(fLastErrMessage.data())+
"\n"+aString.
data(), Wt::Ok );
2148 printf(
"****ERR****: %s\n",path.c_str());
2149 if (!fCoutTBTextArea) {
2150 fCoutTBTextArea =
new Wt::WTextArea();
2152 fCoutTBTextArea->setText(fCoutTBTextArea->text()+
"\n<font color='red'>"+path+
"</font>");
2153 fCoutTBTextArea->refresh();
2157 fLastErrMessage = aString;
2167 void G4UIWt::CommandEditedCallback(
const Wt::WString &)
2169 printf(
"*** G4UIWt::CommandEditedCallback, missing callback on command line edit\n");
2187 void G4UIWt::CoutFilterCallback(
2188 const Wt::WString & ) {
2189 printf(
"*** G4UIWt::CoutFilterCallbackt, missing filtering\n");
2209 void G4UIWt::AddMenu (
2214 if (aName == NULL)
return;
2215 if (aLabel == NULL)
return;
2217 printf(
"*** G4UIWt::AddMenu, missing \n");
2231 bool G4UIWt::CreateVisCommandGroupAndToolBox(
2238 printf(
"*** G4UIWt::CreateVisCommandGroupAndToolBox, missing \n");
2378 void G4UIWt::VisParameterCallback(Wt::WContainerWidget* widget){
2379 if (widget == NULL) {
2382 printf(
"*** G4UIWt::VisParameterCallback, missing \n");
2442 void G4UIWt::CommandHistoryCallback(
2445 if (!fHistoryTBTableList)
2447 fCommandArea->setText(fHistoryTBTableList->currentText ());
2448 #ifdef G4DEBUG_INTERFACES_BASIC
2449 printf(
"G4UIWt::CommandHistoryCallback change text\n");
2454 void G4UIWt::OpenHelpTreeOnCommand(
2458 printf(
"*** G4UIWt::OpenHelpTreeOnCommand, missing \n");
2591 void G4UIWt::ChangeColorCallback(Wt::WContainerWidget* widget) {
2592 if (widget == NULL) {
2595 printf(
"*** G4UIWt::ChangeColorCallback, missing \n");
2632 void G4UIWt::ChangeCursorStyle(
const Wt::WString& ) {
2636 fMoveSelected =
true;
2637 fPickSelected =
true;
2638 fRotateSelected =
true;
2639 fZoomInSelected =
true;
2640 fZoomOutSelected =
true;
2642 printf(
"*** G4UIWt::ChangeCursorStyle, missing \n");
2677 void G4UIWt::ChangeSurfaceStyle(
const Wt::WString& ) {
2681 printf(
"*** G4UIWt::ChangeSurfaceStyle, missing \n");
2718 void G4UIWt::OpenIconCallback(
const Wt::WString& ) {
2720 printf(
"*** G4UIWt::OpenIconCallback, missing \n");
2735 void G4UIWt::SaveIconCallback(
const Wt::WString& ) {
2737 printf(
"*** G4UIWt::SaveIconCallback, missing \n");
2753 void G4UIWt::ChangePerspectiveOrthoCallback(
const Wt::WString& ) {
2757 printf(
"*** G4UIWt::ChangePerspectiveOrthoCallback, missing \n");
3026 void G4UIWt::FillHelpTree()
3028 if (! fHelpTreeWidget ) {
3029 InitHelpTreeAndVisParametersWidget();
3032 Wt::WString searchText = fHelpLine->text();
3034 if (searchText ==
"") {
3042 fHelpArea->setText(
"");
3046 fHelpLine->setText(
"");
3050 if(UI==NULL)
return;
3054 Wt::WTreeNode * newItem = NULL;
3055 Wt::WString commandText =
"";
3057 for (
int a=0;
a<treeSize;
a++) {
3062 std::string whiteSpaces(
" \f\n\r\t\v" );
3065 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3066 path.erase( posR + 1 );
3068 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3069 path.erase( 0, posL );
3071 commandText = Wt::WString(path.c_str());
3074 if (fHelpTreeWidget->treeRoot()) {
3075 for (
int b=0;b<fHelpTreeWidget->treeRoot()->displayedChildCount();b++) {
3077 newItem = FindTreeItem(fHelpTreeWidget->treeRoot()->childNodes()[b],path.c_str());
3080 if (newItem == NULL) {
3081 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0);
3082 fHelpTreeWidget->setTreeRoot(newItem);
3086 CreateHelpTree(newItem,treeTop->
GetTree(
a+1));
3101 void G4UIWt::PauseSessionStart (
3105 if (!aState)
return;
3107 if(aState==
"G4_pause> ") {
3108 SecondaryLoop (
"Pause, type continue to exit this state");
3111 if(aState==
"EndOfEvent") {
3113 SecondaryLoop (
"End of event, type continue to exit this state");
3124 void G4UIWt::ActivateCommand(
3128 if (!fHelpTreeWidget) {
3132 size_t i = newCommand.
index(
" ");
3134 if( i != std::string::npos )
3136 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
3138 targetCom = ModifyToFullPathCommand( newValue );
3140 #ifdef G4DEBUG_INTERFACES_BASIC
3141 printf(
"G4UIWt::ActivateCommand found : %s \n",targetCom.
data());
3143 if (targetCom !=
"") {
3144 OpenHelpTreeOnCommand(targetCom.
data());
3147 fUITabWidget->setCurrentWidget(fHelpTBWidget);
3158 void G4UIWt::InitHelpTreeAndVisParametersWidget()
3161 if (! fHelpTreeWidget ) {
3162 fHelpTreeWidget =
new Wt::WTree();
3166 fHelpTreeWidget->setSelectionMode(Wt::SingleSelection);
3168 fHelpTreeWidget->itemSelectionChanged ().connect(
this,&G4UIWt::HelpTreeClicCallback);
3176 void G4UIWt::CreateHelpTree(
3177 Wt::WTreeNode *aParent
3181 if (aParent == NULL)
return;
3182 if (aCommandTree == NULL)
return;
3186 Wt::WTreeNode * newItem;
3188 Wt::WString commandText =
"";
3193 std::string whiteSpaces(
" \f\n\r\t\v" );
3196 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3197 path.erase( posR + 1 );
3199 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3200 path.erase( 0, posL );
3202 commandText = Wt::WString(path.c_str());
3205 newItem = FindTreeItem(aParent,path.c_str());
3206 if (newItem == NULL) {
3207 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3209 CreateHelpTree(newItem,aCommandTree->
GetTree(
a+1));
3217 std::string whiteSpaces(
" \f\n\r\t\v" );
3220 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3221 path.erase( posR + 1 );
3223 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3224 path.erase( 0, posL );
3226 commandText = Wt::WString(path.c_str());
3229 newItem = FindTreeItem(aParent,path.c_str());
3230 if (newItem == NULL) {
3232 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3234 newItem->collapse();
3249 Wt::WTreeNode* G4UIWt::FindTreeItem(
3250 Wt::WTreeNode *aParent
3251 ,
const std::string& aCommand
3254 if (aParent == NULL)
return NULL;
3257 std::string myCommand = aCommand;
3260 if (myCommand.rfind(
"/") == (myCommand.size()-1)) {
3261 myCommand = myCommand.substr(0,myCommand.size()-1);
3264 if (GetLongCommandPath(aParent) == Wt::WString(myCommand.c_str()))
3267 Wt::WTreeNode * tmp = NULL;
3268 for (
unsigned int a=0;
a<aParent->childNodes().size();
a++) {
3270 tmp = FindTreeItem(aParent->childNodes().at(
a),myCommand);
3284 Wt::WString G4UIWt::GetCommandList (
3289 Wt::WString txt =
"";
3290 if (aCommand == NULL)
3298 if ((commandPath ==
"") &&
3299 (rangeString ==
"") &&
3300 (n_guidanceEntry == 0) &&
3301 (n_parameterEntry == 0)) {
3305 if((commandPath.length()-1)!=
'/') {
3306 txt +=
"Command " + Wt::WString((
char*)(commandPath).data()) +
"\n";
3308 txt +=
"Guidance :\n";
3310 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3311 txt += Wt::WString((
char*)(aCommand->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
3313 if( ! rangeString.
isNull() ) {
3314 txt +=
" Range of parameters : " + Wt::WString((
char*)(rangeString).data()) +
"\n";
3316 if( n_parameterEntry > 0 ) {
3321 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3323 txt +=
"\nParameter : " + Wt::WString((
char*)(param->
GetParameterName()).data()) +
"\n";
3327 txt +=
" Parameter type : " + Wt::WString(&myChar) +
"\n";
3329 txt +=
" Omittable : True\n";
3331 txt +=
" Omittable : False\n";
3334 txt +=
" Default value : taken from the current value\n";
3336 txt +=
" Default value : " + Wt::WString((
char*)(param->
GetDefaultValue()).data())+
"\n";
3339 txt +=
" Parameter range : " + Wt::WString((
char*)(param->
GetParameterRange()).data())+
"\n";
3355 G4bool G4UIWt::IsGUICommand(
3359 if (aCommand == NULL)
3364 if( n_parameterEntry > 0 ) {
3369 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3372 if (myChar ==
'd') {
3375 if (myChar ==
'b') {
3378 if (myChar ==
'i') {
3393 G4bool G4UIWt::GetHelpChoice(
3397 #ifdef G4DEBUG_INTERFACES_BASIC
3398 printf(
"G4UIWt::GetHelpChoice SHOULD NEVER GO HERE");
3415 void G4UIWt::ShowHelpCallback (
3424 void G4UIWt::ClearButtonCallback (
3427 fCoutTBTextArea->setText(
"");
3428 fG4cout.removeRows(0,fG4cout.rowCount());
3433 void G4UIWt::ExitSession (
3439 void G4UIWt::ExitHelp(
3452 void G4UIWt::ButtonCallback (
3453 const char* aCommand
3460 if(UI==NULL)
return;
3467 if (IsGUICommand(command)) {
3468 Wt::WDialog* menuParameterDialog =
new Wt::WDialog();
3470 if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,
true)) {
3471 menuParameterDialog->setWindowTitle (aCommand);
3474 menuParameterDialog->exec();
3480 ApplyShellCommand(ss,fExitSession,fExitPause);
3485 if(fExitSession==
true)
3497 void G4UIWt::LookForHelpStringCallback(
3500 Wt::WString searchText = fHelpLine->text();
3502 fHelpArea->setText(
"");
3503 if (searchText ==
"") {
3505 fHelpTreeWidget =
new Wt::WTree();
3511 OpenHelpTreeOnCommand(searchText);
3518 Wt::WString G4UIWt::GetShortCommandPath(
3519 const std::string& aTxt
3522 std::string commandPath;
3523 if (aTxt.find(
"/", 0) != std::string::npos) {
3525 commandPath = aTxt.substr(aTxt.size()-1);
3529 commandPath = commandPath.substr(commandPath.size()-commandPath.rfind(
"/",-2)-1);
3532 if (commandPath.rfind(
"/") == (commandPath.size()-1)) {
3534 commandPath = commandPath.substr(0,commandPath.size()-1);
3537 return commandPath.c_str();
3541 Wt::WString G4UIWt::GetLongCommandPath(
3545 if (item == NULL)
return "";
3548 Wt::WString itemText =
"";
3549 itemText = item->label()->text();
3551 while (item->parentNode() != NULL) {
3552 itemText = item->parentNode()->label()->text()+
"/"+itemText;
3553 item = item->parentNode();
3555 itemText =
"/"+itemText;
3571 G4WTabWidget::G4WTabWidget(
3572 Wt::WContainerWidget*&
3580 G4WTabWidget::G4WTabWidget(
3589 void G4UIWt::TabCloseCallback(
int a){
3590 Wt::WWidget* temp = fViewerTabWidget->widget(a);
3591 fViewerTabWidget->removeTab (temp);
3595 if (fViewerTabWidget->count() == 0) {
3596 fEmptyViewerTabLabel->show();
3602 void G4UIWt::ToolBoxActivated(
int a){
3604 if (fUITabWidget->widget(a) == fHelpTBWidget) {
3607 }
else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3608 fSceneTreeComponentsTBWidget->hide();
G4UIcommandTree * FindCommandTree(const char *commandPath)
Try to match a command or a path with the one given.
G4String GetParameterCandidates() const
const G4String & GetRange() const
G4UIcommand * FindPath(const char *commandPath) const
G4String strip(G4int strip_Type=trailing, char c=' ')
G4int GetCommandEntry() const
G4String GetParameterName() const
G4UIcommand * GetCommand(G4int i)
G4int GetTreeEntry() const
G4int GetVerboseLevel() const
void SetSession(G4UIsession *const value)
const G4String & GetGuidanceLine(G4int i) const
void SetG4UIWindow(G4UIsession *const value)
static G4UImanager * GetUIpointer()
G4bool IsOmittable() const
static G4StateManager * GetStateManager()
G4GLOB_DLL std::ostream G4cout
str_size index(const char *, G4int pos=0) const
G4UIcommandTree * GetTree(G4int i)
G4UIparameter * GetParameter(G4int i) const
const G4String & GetCommandPath() const
const G4String GetPathName() const
const char * data() const
const G4String GetTitle() const
G4UIcommandTree * GetTree() const
G4String GetDefaultValue() const
void SetCoutDestination(G4UIsession *const value)
char GetParameterType() const
const G4String GetParameterGuidance() const
G4String GetParameterRange() const
G4int GetGuidanceEntries() const
G4int GetParameterEntries() const
G4bool GetCurrentAsDefault() const
G4int ApplyCommand(const char *aCommand)