30#ifdef G4UI_BUILD_WT_SESSION
43#include <Wt/WLineEdit>
44#include <Wt/WTextArea>
45#include <Wt/WMessageBox>
47#include <Wt/WRadioButton>
48#include <Wt/WButtonGroup>
49#include <Wt/WComboBox>
50#include <Wt/WVBoxLayout>
51#include <Wt/WHBoxLayout>
52#include <Wt/WGridLayout>
54#include <Wt/WSelectionBox>
57#define G4DEBUG_INTERFACES_BASIC 1
60static G4bool exitSession =
true;
61static G4bool exitPause =
true;
95,fHistoryTBTableList(NULL)
98,fHistoryTBWidget(NULL)
100,fSceneTreeComponentsTBWidget(NULL)
102,fViewerTabWidget(NULL)
104,fEmptyViewerTabLabel(NULL)
105,fMainSplitterWidget(NULL)
106,fRightSplitterWidget(NULL)
110,fStringSeparator(
"__$$$@%%###__")
113,fRotateSelected(true)
115,fZoomInSelected(false)
116,fZoomOutSelected(false)
122 G4Wt* interactorManager = G4Wt::getInstance (argc,argv,(
char*)
"Wt");
123 if (!(Wt::WApplication*)interactorManager->GetMainInteractor()) {
128 G4cout <<
"G4UIWt : Unable to init Wt. Aborted" <<
G4endl;
136 fMainWindow =
new Wt::WContainerWidget(wApp->root());
139 Wt::WVBoxLayout* mainWindowVLayout =
new Wt::WVBoxLayout();
140 fMainWindow->setLayout(mainWindowVLayout);
143#ifdef G4DEBUG_INTERFACES_BASIC
144 printf(
"G4UIWt::Initialise after main window creation +++++++++++\n");
149 fMainSplitterWidget =
new Wt::WContainerWidget();
150 Wt::WGridLayout* fMainSplitterWidgetLayout =
new Wt::WGridLayout();
153 fMainSplitterWidgetLayout->addWidget(CreateLeftSplitterWidget(),1,1);
154 fMainSplitterWidgetLayout->addWidget(CreateRightSplitterWidget(),1,2);
155 fMainSplitterWidgetLayout->setColumnResizable (1,
true,Wt::WLength(30,Wt::WLength::Percentage));
161 fMainSplitterWidget->setLayout(fMainSplitterWidgetLayout);
162 mainWindowVLayout->addWidget(fMainSplitterWidget);
166#ifdef G4DEBUG_INTERFACES_BASIC
167 printf(
"G4UIWt::G4UIWt :: 5\n");
173 wApp->setTitle(
"Wt application");
184#ifdef G4DEBUG_INTERFACES_BASIC
185 printf(
"G4UIWt::~G4UIWt Delete\n");
194 if (fMainWindow!=NULL) {
195#ifdef G4DEBUG_INTERFACES_BASIC
196 printf(
"G4UIWt::~G4UIWt DELETE fMainWindow\n");
204Wt::WWidget* G4UIWt::CreateHistoryTBWidget(
207 fHistoryTBWidget =
new Wt::WPanel();
208 fHistoryTBWidget->setCollapsed(
true);
209 fHistoryTBWidget->setCollapsible(
true);
211 fHistoryTBTableList =
new Wt::WSelectionBox();
212 fHistoryTBTableList->setSelectionMode(Wt::SingleSelection);
213 fHistoryTBTableList->changed().connect(
this,&G4UIWt::CommandHistoryCallback);
215 fHistoryTBWidget->setCentralWidget(fHistoryTBTableList);
216 return fHistoryTBWidget;
222Wt::WWidget* G4UIWt::CreateHelpTBWidget(
225 fHelpTBWidget =
new Wt::WPanel();
226 fHelpTBWidget->setCollapsible(
true);
228 Wt::WContainerWidget *helpWidget =
new Wt::WContainerWidget();
229 Wt::WHBoxLayout *helpLayout =
new Wt::WHBoxLayout();
230 Wt::WVBoxLayout *vLayout =
new Wt::WVBoxLayout();
232 fHelpVSplitter =
new Wt::WContainerWidget();
233 fHelpVSplitter->setLayout(
new Wt::WHBoxLayout());
235 Wt::WVBoxLayout* VHelpSplitterVLayout =
new Wt::WVBoxLayout();
236 fHelpVSplitter->setLayout(VHelpSplitterVLayout);
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");
250 fHelpArea =
new Wt::WTextArea(fHelpVSplitter);
251 fHelpArea->setReadOnly(
true);
255 if (fHelpTreeWidget) {
256 fHelpVSplitter->addWidget(fHelpTreeWidget);
258 fHelpVSplitter->addWidget(fHelpArea);
260 vLayout->addWidget(helpWidget);
261 vLayout->addWidget(fHelpVSplitter,1);
271 return fHelpTBWidget;
277Wt::WWidget* G4UIWt::CreateCoutTBWidget(
280 fCoutTBWidget =
new Wt::WPanel();
281 fCoutTBWidget->setCollapsible(
true);
282 fCoutTBWidget->setTitle(
"Output");
283 fCoutTBWidget->setCollapsed(
false);
285 Wt::WContainerWidget* myContainer =
new Wt::WContainerWidget();
286 Wt::WVBoxLayout *myContainerVLayout =
new Wt::WVBoxLayout();
287 myContainer->setLayout(myContainerVLayout);
290 if (!fCoutTBTextArea) {
291 fCoutTBTextArea =
new Wt::WTextArea(myContainer);
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);
299 Wt::WPushButton *coutTBClearButton =
new Wt::WPushButton (
"clear",myContainer);
306 fCoutTBTextArea->setReadOnly(
true);
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);
314 myContainerVLayout->addWidget(coutButtonWidget);
316 fCoutTBWidget->setCentralWidget(myContainer);
318 return fCoutTBWidget;
324Wt::WContainerWidget* G4UIWt::CreateVisParametersTBWidget(
333Wt::WWidget* G4UIWt::CreateUITabWidget(
336 fUITabWidget =
new Wt::WTabWidget();
339 fUITabWidget->addTab(CreateSceneTreeComponentsTBWidget(),
"Scene tree");
340 fUITabWidget->addTab(CreateHelpTBWidget(),
"Help");
341 fUITabWidget->addTab(CreateHistoryTBWidget(),
"History");
352Wt::WWidget* G4UIWt::CreateSceneTreeComponentsTBWidget(){
354 fSceneTreeComponentsTBWidget =
new Wt::WTabWidget();
356 fSceneTreeComponentsTBWidget->hide();
358 return fSceneTreeComponentsTBWidget;
362Wt::WContainerWidget* G4UIWt::CreateLeftSplitterWidget(){
364 fLeftSplitterWidget =
new Wt::WContainerWidget();
365 Wt::WVBoxLayout * layoutLeftSplitterWidget =
new Wt::WVBoxLayout();
366 fLeftSplitterWidget->setLayout(layoutLeftSplitterWidget);
368 layoutLeftSplitterWidget->addWidget(CreateUITabWidget());
370 return fLeftSplitterWidget;
374Wt::WContainerWidget* G4UIWt::CreateRightSplitterWidget(){
376 fRightSplitterWidget =
new Wt::WContainerWidget();
379 Wt::WVBoxLayout* VSplitterVLayout =
new Wt::WVBoxLayout();
380 fRightSplitterWidget->setLayout(VSplitterVLayout);
381 Wt::WContainerWidget* commandLineWidget =
new Wt::WContainerWidget();
383 Wt::WHBoxLayout *layoutCommandLine =
new Wt::WHBoxLayout();
384 commandLineWidget->setLayout(layoutCommandLine);
388 fCommandLabel =
new Wt::WLabel(
"",commandLineWidget);
389 fCommandArea =
new Wt::WLineEdit(commandLineWidget);
390 fCommandArea->setToolTip(
"Apply command");
393 layoutCommandLine->addWidget(fCommandLabel);
394 layoutCommandLine->addWidget(fCommandArea);
397 fViewerTabWidget =
new G4WTabWidget(fRightSplitterWidget);
399 fViewerTabWidget->tabClosed().connect(
this, &G4UIWt::TabCloseCallback);
401 fViewerTabWidget->currentChanged().connect(
this,&G4UIWt::CurrentChangedTabWidgetCallback);
404 fEmptyViewerTabLabel =
new Wt::WLabel(
" If you want to have a Viewer, please use /vis/open commands. ");
407 fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
408 fRightSplitterWidget->layout()->addWidget(fEmptyViewerTabLabel);
409 fRightSplitterWidget->layout()->addWidget(CreateCoutTBWidget());
410 fRightSplitterWidget->layout()->addWidget(commandLineWidget);
412 commandLineWidget->setMinimumSize(50,50);
415 fCommandArea->enterPressed().connect(
this,&G4UIWt::CommandEnteredCallback);
417 return fRightSplitterWidget;
423Wt::WTabWidget* G4UIWt::GetSceneTreeComponentsTBWidget(
426 return fSceneTreeComponentsTBWidget;
433bool G4UIWt::AddTabWidget(
456 if (!fViewerTabWidget->isVisible() ) {
457 if ( fRightSplitterWidget->isVisible()) {
458 fRightSplitterWidget->setHidden(
true);
459 fEmptyViewerTabLabel->setHidden(
true);
461#ifdef G4DEBUG_INTERFACES_BASIC
462 printf(
"G4UIWt::AddTabWidget +++++\n");
464 fViewerTabWidget->show();
465 fViewerTabWidget =
new G4WTabWidget(fRightSplitterWidget);
467 fViewerTabWidget->tabClosed().connect(
this, &G4UIWt::TabCloseCallback);
469 fViewerTabWidget->currentChanged().connect(
this,&G4UIWt::CurrentChangedTabWidgetCallback);
470 fRightSplitterWidget->layout()->addWidget(fViewerTabWidget);
492 fViewerTabWidget->addTab(
new Wt::WLabel(
"test"),
"test1");
493 fViewerTabWidget->addTab(aWidget,name);
494 fViewerTabWidget->addTab(
new Wt::WLabel(
"test"),
"test2");
497 aWidget->decorationStyle().setBackgroundColor (Wt::WColor(245,245,245));
499 fViewerTabWidget->setCurrentIndex(fViewerTabWidget->count()-1);
502 fViewerTabWidget->setLastTabCreated(fViewerTabWidget->currentIndex());
509void G4UIWt::CurrentChangedTabWidgetCallback(
int tabNumber) {
510#ifdef G4DEBUG_INTERFACES_BASIC
511 printf(
"G4UIWt::CurrentChangedTabWidget %d\n",tabNumber);
513 if ( fViewerTabWidget == NULL) {
514 fViewerTabWidget =
new G4WTabWidget;
517#ifdef G4DEBUG_INTERFACES_BASIC
518 printf(
"G4UIWt::CurrentChangedTabWidget CALL REPAINT tabGL\n");
521 fViewerTabWidget->setCurrentIndex(tabNumber);
524 fViewerTabWidget->setTabSelected(
false);
526 fViewerTabWidget->show();
529 fViewerTabWidget->setTabSelected(
true);
532 Wt::WString text = fViewerTabWidget->tabText (tabNumber);
534 Wt::WString paramSelect = Wt::WString(
"/vis/viewer/select ")+text;
547#ifdef G4DEBUG_INTERFACES_BASIC
548 printf(
"G4UIWt::G4UIWt SessionStart 1\n");
551 G4Wt* interactorManager = G4Wt::getInstance ();
558#ifdef G4DEBUG_INTERFACES_BASIC
559 printf(
"G4UIWt::G4UIWt SessionStart2\n");
561 interactorManager->DisableSecondaryLoop ();
574 interactorManager->EnableSecondaryLoop ();
589 if (!aPrompt)
return;
590 if (!fCommandLabel)
return;
592 fCommandLabel->setText((
char*)aPrompt.
data());
597void G4UIWt::SessionTerminate (
600 G4Wt* interactorManager = G4Wt::getInstance ();
602 if ((Wt::WApplication*)interactorManager->GetMainInteractor()) {
613void G4UIWt::SecondaryLoop (
617 if (!aPrompt)
return;
619 G4Wt* interactorManager = G4Wt::getInstance ();
623 while((eventTmp = interactorManager->GetEvent())!=NULL) {
624 interactorManager->DispatchEvent(eventTmp);
625 if(fExitPause==
true)
break;
634void G4UIWt::CommandEnteredCallback (
637#ifdef G4DEBUG_INTERFACES_BASIC
638 printf(
"G4UIWt::CommandEnteredCallback\n");
640#ifdef G4DEBUG_INTERFACES_BASIC
641 printf(
"G4UIWt::CommandEnteredCallback 1\n");
643 G4String command (fCommandArea->text().toUTF8());
644 if (fCommandArea->text() !=
"") {
646 printf(
"*** G4UIWt::CommandEnteredCallback, missing update on history \n");
652 fCommandArea->setText(
"");
653#ifdef G4DEBUG_INTERFACES_BASIC
654 printf(
"G4UIWt::CommandEnteredCallback 2\n");
657 G4Wt* interactorManager = G4Wt::getInstance ();
658#ifdef G4DEBUG_INTERFACES_BASIC
659 printf(
"G4UIWt::CommandEnteredCallback 3\n");
661 if (interactorManager) {
662 interactorManager->FlushAndWaitExecution();
664#ifdef G4DEBUG_INTERFACES_BASIC
665 printf(
"G4UIWt::CommandEnteredCallback 4\n");
667 if (command(0,4) !=
"help") {
668 ApplyShellCommand (command,exitSession,exitPause);
670 ActivateCommand(command);
672#ifdef G4DEBUG_INTERFACES_BASIC
673 printf(
"G4UIWt::CommandEnteredCallback 5\n");
678#ifdef G4DEBUG_INTERFACES_BASIC
679 printf(
"G4UIWt::CommandEnteredCallback 6\n");
681 if(exitSession==
true)
684#ifdef G4DEBUG_INTERFACES_BASIC
685 printf(
"G4UIWt::CommandEnteredCallback END\n");
697void G4UIWt::AddButton (
700 ,
const char* aCommand
703 if(aMenu==NULL)
return;
704 if(aLabel==NULL)
return;
705 if(aCommand==NULL)
return;
707 Wt::WMenu *parentTmp = (Wt::WMenu*)GetInteractor(aMenu);
709 if(parentTmp==NULL) {
714 G4cout <<
"Menu name " << aMenu<<
" does not exist, please define it before using it."<<
G4endl;
725 G4int cmdEndPos = cmd.find_first_of(
" \t");
726 if(cmdEndPos!=
G4int(std::string::npos)) {
727 cmd.erase(cmdEndPos);
730 if(treeTop->
FindPath(aCommand) == NULL) {
735 G4cout <<
"Warning: command '"<< aCommand <<
"' does not exist, please define it before using it."<<
G4endl;
739 printf(
"*** G4UIWt::AddButton, missing connection on menu callback \n");
753void G4UIWt::AddIcon(
const char* aLabel,
const char* aIconFile,
const char* aCommand,
const char* ){
754 if(aLabel==NULL)
return;
756 if (aCommand==NULL) {
757 if (std::string(aIconFile) ==
"user_icon") {
761 printf(
"*** G4UIWt::AddIcon, missing icon creation \n");
1645bool G4UIWt::CreateCommandWidget(
G4UIcommand* aCommand, Wt::WContainerWidget* aParent,
bool isDialog) {
1647 if (aCommand == NULL) {
1654 if( n_parameterEntry > 0 ) {
1658 Wt::WContainerWidget* paramWidget =
new Wt::WContainerWidget();
1659 Wt::WGridLayout* gridLayout =
new Wt::WGridLayout(paramWidget);
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;
1673 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
1676 Wt::WLabel* label =
new Wt::WLabel(Wt::WString((
char*)(param->
GetParameterName()).data()));
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) {
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);
1697 nbColorParameter = 0;
1700 Wt::WWidget* input = NULL;
1702 if ((paramType ==
'd') || (paramType ==
'i')) {
1703 input =
new Wt::WLineEdit();
1705 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
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());
1715 }
else if (paramType ==
'b') {
1716 input =
new Wt::WContainerWidget();
1717 Wt::WHBoxLayout* layout =
new Wt::WHBoxLayout(input);
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);
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);
1735 input =
new Wt::WComboBox();
1737 printf(
"*** G4UIWt::CreateCommandWidget, missing parameter management for 's'\n");
1749 }
else if (paramType ==
's') {
1750 input =
new Wt::WLineEdit();
1752 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
1754 }
else if (paramType ==
'c') {
1755 input =
new Wt::WContainerWidget();
1756 Wt::WHBoxLayout* layout =
new Wt::WHBoxLayout(input);
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);
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);
1775 input =
new Wt::WLineEdit();
1776 dynamic_cast<Wt::WLineEdit*
>(input)->setText(Wt::WString((
char*)(param->
GetDefaultValue()).data()));
1779 txt +=
"\nParameter : " + Wt::WString((
char*)(param->
GetParameterName()).data()) +
"\n";
1784 txt += Wt::WString(
" Parameter type : ") + std::string(¶mType).c_str() +
"\n";
1786 txt +=
" Omittable : True\n";
1788 txt +=
" Omittable : False\n";
1791 txt +=
" Default value : taken from the current value\n";
1793 txt +=
" Default value : " + Wt::WString((
char*)(param->
GetDefaultValue()).data())+
"\n";
1796 txt +=
" Parameter range : " + Wt::WString((
char*)(param->
GetParameterRange()).data())+
"\n";
1802 if (isStillColorParameter && (nbColorParameter != 0)) {
1803 if ((label->text() ==
"red") || (label->text() ==
"red_or_string")) {
1806 }
else if (label->text() ==
"green") {
1809 }
else if (label->text() ==
"blue") {
1815 if ((redDefaultStr !=
"") && (redDefaultStr !=
"") && (redDefaultStr !=
"")) {
1817 wc.setRgb(atof(redDefaultStr.toUTF8().c_str())*256,
1818 atof(greenDefaultStr.toUTF8().c_str())*256,
1819 atof(blueDefaultStr.toUTF8().c_str())*256);
1821 printf(
"*** G4UIWt::CreateCommandWidget, missing icon on command widget\n");
1847 isColorDialogAdded =
true;
1848 isStillColorParameter =
false;
1851 gridLayout->addWidget(label,i_thParameter-nbColorParameter,0);
1852 input->setToolTip(txt);
1853 gridLayout->addWidget(input,i_thParameter-nbColorParameter,1);
1859 gridLayout->addWidget(name,n_parameterEntry-nbColorParameter,0);
1861 Wt::WPushButton* applyButton =
new Wt::WPushButton(
"Apply");
1864 gridLayout->addWidget(applyButton,n_parameterEntry-nbColorParameter,1);
1866 printf(
"*** G4UIWt::CreateCommandWidget, missing connection on ApplyButton\n");
1876 printf(
"*** G4UIWt::CreateCommandWidget, missing connection on Apply/Cancel Button\n");
1908 if (!aParent->layout()) {
1909 aParent->setLayout(
new Wt::WVBoxLayout());
1911 aParent->layout()->addWidget(paramWidget);
1925bool G4UIWt::eventFilter(
1931 printf(
"*** G4UIWt::eventFilter, missing eventFilter on everything\n");
2006void G4UIWt::HelpTreeClicCallback (
2009 Wt::WTreeNode* item = NULL;
2010 if (!fHelpTreeWidget)
2016 const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2019 item = *list.begin();
2024 if(UI==NULL)
return;
2027 std::string itemText = GetLongCommandPath(item).toUTF8();
2032 fHelpArea->setText(GetCommandList(command));
2045void G4UIWt::HelpTreeDoubleClicCallback (
2048 HelpTreeClicCallback();
2050 Wt::WTreeNode* item = NULL;
2051 if (!fHelpTreeWidget)
2057 const Wt::WTree::WTreeNodeSet& list = fHelpTreeWidget->selectedNodes();
2060 item = *list.begin();
2064 fCommandArea->setText(
"");
2065 fCommandArea->setText(GetLongCommandPath(item));
2074G4int G4UIWt::ReceiveG4cout (
2078 if (!aString)
return 0;
2080 Wt::WStringListModel newStr;
2083 std::string whiteSpaces(
" \f\n\r\t\v" );
2084 std::string path = (
char*)aString.
data();
2086 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2087 path.erase( posR + 1 );
2089 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2090 path.erase( 0, posL );
2092 printf(
"*** G4UIWt::ReceiveG4cout, missing filtering\n");
2102 if (!fCoutTBTextArea) {
2103 printf(
"*** G4UIWt::ReceiveG4cout, create a new fCoutTBTextArea \n");
2104 fCoutTBTextArea =
new Wt::WTextArea();
2105 fCoutTBTextArea->setText(
"");
2107 fCoutTBTextArea->setText(fCoutTBTextArea->text()+
"\n"+path);
2108 fCoutTBTextArea->refresh();
2119G4int G4UIWt::ReceiveG4cerr (
2123 if (!aString)
return 0;
2125 Wt::WStringListModel newStr;
2128 std::string whiteSpaces(
" \f\n\r\t\v" );
2129 std::string path = (
char*)aString.
data();
2131 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
2132 path.erase( posR + 1 );
2134 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
2135 path.erase( 0, posL );
2137 printf(
"*** G4UIWt::ReceiveG4cerr, missing filtering\n");
2149 Wt::WMessageBox::show(
"Error", Wt::WString(fLastErrMessage.data())+
"\n"+aString.
data(), Wt::Ok );
2153 printf(
"****ERR****: %s\n",path.c_str());
2154 if (!fCoutTBTextArea) {
2155 fCoutTBTextArea =
new Wt::WTextArea();
2157 fCoutTBTextArea->setText(fCoutTBTextArea->text()+
"\n<font color='red'>"+path+
"</font>");
2158 fCoutTBTextArea->refresh();
2162 fLastErrMessage = aString;
2172void G4UIWt::CommandEditedCallback(
const Wt::WString &)
2174 printf(
"*** G4UIWt::CommandEditedCallback, missing callback on command line edit\n");
2192void G4UIWt::CoutFilterCallback(
2193 const Wt::WString & ) {
2194 printf(
"*** G4UIWt::CoutFilterCallbackt, missing filtering\n");
2214void G4UIWt::AddMenu (
2219 if (aName == NULL)
return;
2220 if (aLabel == NULL)
return;
2222 printf(
"*** G4UIWt::AddMenu, missing \n");
2236bool G4UIWt::CreateVisCommandGroupAndToolBox(
2243 printf(
"*** G4UIWt::CreateVisCommandGroupAndToolBox, missing \n");
2383void G4UIWt::VisParameterCallback(Wt::WContainerWidget* widget){
2384 if (widget == NULL) {
2387 printf(
"*** G4UIWt::VisParameterCallback, missing \n");
2447void G4UIWt::CommandHistoryCallback(
2450 if (!fHistoryTBTableList)
2452 fCommandArea->setText(fHistoryTBTableList->currentText ());
2453#ifdef G4DEBUG_INTERFACES_BASIC
2454 printf(
"G4UIWt::CommandHistoryCallback change text\n");
2459void G4UIWt::OpenHelpTreeOnCommand(
2463 printf(
"*** G4UIWt::OpenHelpTreeOnCommand, missing \n");
2596void G4UIWt::ChangeColorCallback(Wt::WContainerWidget* widget) {
2597 if (widget == NULL) {
2600 printf(
"*** G4UIWt::ChangeColorCallback, missing \n");
2637void G4UIWt::ChangeCursorStyle(
const Wt::WString& ) {
2641 fMoveSelected =
true;
2642 fPickSelected =
true;
2643 fRotateSelected =
true;
2644 fZoomInSelected =
true;
2645 fZoomOutSelected =
true;
2647 printf(
"*** G4UIWt::ChangeCursorStyle, missing \n");
2682void G4UIWt::ChangeSurfaceStyle(
const Wt::WString& ) {
2686 printf(
"*** G4UIWt::ChangeSurfaceStyle, missing \n");
2723void G4UIWt::OpenIconCallback(
const Wt::WString& ) {
2725 printf(
"*** G4UIWt::OpenIconCallback, missing \n");
2740void G4UIWt::SaveIconCallback(
const Wt::WString& ) {
2742 printf(
"*** G4UIWt::SaveIconCallback, missing \n");
2758void G4UIWt::ChangePerspectiveOrthoCallback(
const Wt::WString& ) {
2762 printf(
"*** G4UIWt::ChangePerspectiveOrthoCallback, missing \n");
3031void G4UIWt::FillHelpTree()
3033 if (! fHelpTreeWidget ) {
3034 InitHelpTreeAndVisParametersWidget();
3037 Wt::WString searchText = fHelpLine->text();
3039 if (searchText ==
"") {
3047 fHelpArea->setText(
"");
3051 fHelpLine->setText(
"");
3055 if(UI==NULL)
return;
3059 Wt::WTreeNode * newItem = NULL;
3060 Wt::WString commandText =
"";
3062 for (
int a=0;a<treeSize;a++) {
3067 std::string whiteSpaces(
" \f\n\r\t\v" );
3070 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3071 path.erase( posR + 1 );
3073 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3074 path.erase( 0, posL );
3076 commandText = Wt::WString(path.c_str());
3079 if (fHelpTreeWidget->treeRoot()) {
3080 for (
int b=0;b<fHelpTreeWidget->treeRoot()->displayedChildCount();b++) {
3082 newItem = FindTreeItem(fHelpTreeWidget->treeRoot()->childNodes()[b],path.c_str());
3085 if (newItem == NULL) {
3086 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0);
3087 fHelpTreeWidget->setTreeRoot(newItem);
3091 CreateHelpTree(newItem,treeTop->
GetTree(a+1));
3106void G4UIWt::PauseSessionStart (
3110 if (!aState)
return;
3112 if(aState==
"G4_pause> ") {
3113 SecondaryLoop (
"Pause, type continue to exit this state");
3116 if(aState==
"EndOfEvent") {
3118 SecondaryLoop (
"End of event, type continue to exit this state");
3129void G4UIWt::ActivateCommand(
3133 if (!fHelpTreeWidget) {
3137 size_t i = newCommand.
index(
" ");
3139 if( i != std::string::npos )
3141 G4String newValue = newCommand(i+1,newCommand.length()-(i+1));
3143 targetCom = ModifyToFullPathCommand( newValue );
3145#ifdef G4DEBUG_INTERFACES_BASIC
3146 printf(
"G4UIWt::ActivateCommand found : %s \n",targetCom.
data());
3148 if (targetCom !=
"") {
3149 OpenHelpTreeOnCommand(targetCom.
data());
3152 fUITabWidget->setCurrentWidget(fHelpTBWidget);
3163void G4UIWt::InitHelpTreeAndVisParametersWidget()
3166 if (! fHelpTreeWidget ) {
3167 fHelpTreeWidget =
new Wt::WTree();
3171 fHelpTreeWidget->setSelectionMode(Wt::SingleSelection);
3173 fHelpTreeWidget->itemSelectionChanged ().connect(
this,&G4UIWt::HelpTreeClicCallback);
3181void G4UIWt::CreateHelpTree(
3182 Wt::WTreeNode *aParent
3186 if (aParent == NULL)
return;
3187 if (aCommandTree == NULL)
return;
3191 Wt::WTreeNode * newItem;
3193 Wt::WString commandText =
"";
3198 std::string whiteSpaces(
" \f\n\r\t\v" );
3201 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3202 path.erase( posR + 1 );
3204 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3205 path.erase( 0, posL );
3207 commandText = Wt::WString(path.c_str());
3210 newItem = FindTreeItem(aParent,path.c_str());
3211 if (newItem == NULL) {
3212 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3214 CreateHelpTree(newItem,aCommandTree->
GetTree(a+1));
3222 std::string whiteSpaces(
" \f\n\r\t\v" );
3225 std::string::size_type posR = path.find_last_not_of( whiteSpaces );
3226 path.erase( posR + 1 );
3228 std::string::size_type posL = path.find_first_not_of( whiteSpaces );
3229 path.erase( 0, posL );
3231 commandText = Wt::WString(path.c_str());
3234 newItem = FindTreeItem(aParent,path.c_str());
3235 if (newItem == NULL) {
3237 newItem =
new Wt::WTreeNode(GetShortCommandPath(path), 0,aParent);
3239 newItem->collapse();
3254Wt::WTreeNode* G4UIWt::FindTreeItem(
3255 Wt::WTreeNode *aParent
3256 ,
const std::string& aCommand
3259 if (aParent == NULL)
return NULL;
3262 std::string myCommand = aCommand;
3265 if (myCommand.rfind(
"/") == (myCommand.size()-1)) {
3266 myCommand = myCommand.substr(0,myCommand.size()-1);
3269 if (GetLongCommandPath(aParent) == Wt::WString(myCommand.c_str()))
3272 Wt::WTreeNode * tmp = NULL;
3273 for (
unsigned int a=0;a<aParent->childNodes().size();a++) {
3275 tmp = FindTreeItem(aParent->childNodes().at(a),myCommand);
3289Wt::WString G4UIWt::GetCommandList (
3294 Wt::WString txt =
"";
3295 if (aCommand == NULL)
3303 if ((commandPath ==
"") &&
3304 (rangeString ==
"") &&
3305 (n_guidanceEntry == 0) &&
3306 (n_parameterEntry == 0)) {
3310 if((commandPath.length()-1)!=
'/') {
3311 txt +=
"Command " + Wt::WString((
char*)(commandPath).data()) +
"\n";
3313 txt +=
"Guidance :\n";
3315 for(
G4int i_thGuidance=0; i_thGuidance < n_guidanceEntry; i_thGuidance++ ) {
3316 txt += Wt::WString((
char*)(aCommand->
GetGuidanceLine(i_thGuidance)).data()) +
"\n";
3318 if( ! rangeString.
isNull() ) {
3319 txt +=
" Range of parameters : " + Wt::WString((
char*)(rangeString).data()) +
"\n";
3321 if( n_parameterEntry > 0 ) {
3326 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3328 txt +=
"\nParameter : " + Wt::WString((
char*)(param->
GetParameterName()).data()) +
"\n";
3332 txt +=
" Parameter type : " + Wt::WString(&myChar) +
"\n";
3334 txt +=
" Omittable : True\n";
3336 txt +=
" Omittable : False\n";
3339 txt +=
" Default value : taken from the current value\n";
3341 txt +=
" Default value : " + Wt::WString((
char*)(param->
GetDefaultValue()).data())+
"\n";
3344 txt +=
" Parameter range : " + Wt::WString((
char*)(param->
GetParameterRange()).data())+
"\n";
3360G4bool G4UIWt::IsGUICommand(
3364 if (aCommand == NULL)
3369 if( n_parameterEntry > 0 ) {
3374 for(
G4int i_thParameter=0; i_thParameter<n_parameterEntry; i_thParameter++ ) {
3377 if (myChar ==
'd') {
3380 if (myChar ==
'b') {
3383 if (myChar ==
'i') {
3398G4bool G4UIWt::GetHelpChoice(
3402#ifdef G4DEBUG_INTERFACES_BASIC
3403 printf(
"G4UIWt::GetHelpChoice SHOULD NEVER GO HERE");
3420void G4UIWt::ShowHelpCallback (
3429void G4UIWt::ClearButtonCallback (
3432 fCoutTBTextArea->setText(
"");
3433 fG4cout.removeRows(0,fG4cout.rowCount());
3438void G4UIWt::ExitSession (
3444void G4UIWt::ExitHelp(
3457void G4UIWt::ButtonCallback (
3458 const char* aCommand
3465 if(UI==NULL)
return;
3472 if (IsGUICommand(command)) {
3473 Wt::WDialog* menuParameterDialog =
new Wt::WDialog();
3475 if (CreateVisCommandGroupAndToolBox(command,menuParameterDialog,1,
true)) {
3476 menuParameterDialog->setWindowTitle (aCommand);
3479 menuParameterDialog->exec();
3485 ApplyShellCommand(ss,fExitSession,fExitPause);
3490 if(fExitSession==
true)
3502void G4UIWt::LookForHelpStringCallback(
3505 Wt::WString searchText = fHelpLine->text();
3507 fHelpArea->setText(
"");
3508 if (searchText ==
"") {
3510 fHelpTreeWidget =
new Wt::WTree();
3516 OpenHelpTreeOnCommand(searchText);
3523Wt::WString G4UIWt::GetShortCommandPath(
3524 const std::string& aTxt
3527 std::string commandPath;
3528 if (aTxt.find(
"/", 0) != std::string::npos) {
3530 commandPath = aTxt.substr(aTxt.size()-1);
3534 commandPath = commandPath.substr(commandPath.size()-commandPath.rfind(
"/",-2)-1);
3537 if (commandPath.rfind(
"/") == (commandPath.size()-1)) {
3539 commandPath = commandPath.substr(0,commandPath.size()-1);
3542 return commandPath.c_str();
3546Wt::WString G4UIWt::GetLongCommandPath(
3550 if (item == NULL)
return "";
3553 Wt::WString itemText =
"";
3554 itemText = item->label()->text();
3556 while (item->parentNode() != NULL) {
3557 itemText = item->parentNode()->label()->text()+
"/"+itemText;
3558 item = item->parentNode();
3560 itemText =
"/"+itemText;
3576G4WTabWidget::G4WTabWidget(
3577 Wt::WContainerWidget*&
3585G4WTabWidget::G4WTabWidget(
3594void G4UIWt::TabCloseCallback(
int a){
3595 Wt::WWidget* temp = fViewerTabWidget->widget(a);
3596 fViewerTabWidget->removeTab (temp);
3600 if (fViewerTabWidget->count() == 0) {
3601 fEmptyViewerTabLabel->show();
3607void G4UIWt::ToolBoxActivated(
int a){
3609 if (fUITabWidget->widget(a) == fHelpTBWidget) {
3612 }
else if (fUITabWidget->widget(a) == fSceneTreeComponentsTBWidget) {
3613 fSceneTreeComponentsTBWidget->hide();
G4GLOB_DLL std::ostream G4cout
static G4StateManager * GetStateManager()
str_size index(const char *, G4int pos=0) const
G4String strip(G4int strip_Type=trailing, char c=' ')
const char * data() const
G4int GetCommandEntry() const
G4UIcommand * GetCommand(G4int i)
const G4String & GetPathName() const
G4int GetTreeEntry() const
G4UIcommandTree * GetTree(G4int i)
G4UIcommandTree * FindCommandTree(const char *commandPath)
const G4String GetTitle() const
G4UIcommand * FindPath(const char *commandPath) const
std::size_t GetParameterEntries() const
const G4String & GetGuidanceLine(G4int i) const
G4UIparameter * GetParameter(G4int i) const
const G4String & GetCommandPath() const
std::size_t GetGuidanceEntries() const
const G4String & GetRange() const
void SetCoutDestination(G4UIsession *const value)
G4UIcommandTree * GetTree() const
G4int ApplyCommand(const char *aCommand)
G4int GetVerboseLevel() const
static G4UImanager * GetUIpointer()
void SetSession(G4UIsession *const value)
void SetG4UIWindow(G4UIsession *const value)
const G4String & GetParameterCandidates() const
const G4String & GetParameterGuidance() const
G4bool IsOmittable() const
const G4String & GetParameterRange() const
G4bool GetCurrentAsDefault() const
char GetParameterType() const
const G4String & GetParameterName() const
const G4String & GetDefaultValue() const
const char * name(G4int ptype)