Problem 1389

Summary: Geant4.9.6b01: Warnings about not existent command in addButton command
Product: Geant4 Reporter: Alexey <alexey.radkov>
Component: interfacesAssignee: garnier
Status: RESOLVED FIXED    
Severity: trivial CC: garnier
Priority: P5    
Version: other   
Hardware: All   
OS: All   

Description Alexey 2012-11-14 23:12:42 CET
Hi.

When i run my gui.mac:

/gui/addMenu run Run
/gui/addButton run "Collect all events" "/control/execute mac/setup_all_events.mac"
/gui/addButton run "Collect interaction events" "/control/execute mac/setup_interaction_events.mac"
/gui/addButton run "Collect trigger events" "/control/execute mac/setup_trigger_events.mac"
/gui/addButton run "Run 1 event" "/run/beamOn 1"
/gui/addButton run "Run 5 events" "/run/beamOn 5"
/gui/addButton run "Run 10 events" "/run/beamOn 10"
/gui/addButton run "Run 100 events" "/run/beamOn 100"

/gui/addMenu viewer Viewer
/gui/addButton viewer "Draw world" "/control/execute mac/visQt.mac"
#/gui/addButton viewer "Draw world (OI)" "/control/execute mac/visOI.mac"
/gui/addButton viewer "Set style solid" "/vis/viewer/set/style solid"
/gui/addButton viewer "Set style wireframe" "/vis/viewer/set/style wire"
/gui/addButton viewer "Highlight inner crystals" "/cexmc/vis/hlIC"
/gui/addButton viewer "Unhighlight inner crystals" "/cexmc/vis/hlIC false"
/gui/addButton viewer "Update scene" "/vis/scene/notifyHandlers"


i get multiple warnings about not existent command for almost all commands:

/control/execute mac/gui.mac
/gui/addMenu run Run
/gui/addButton run "Collect all events" "/control/execute mac/setup_all_events.mac"
Warning: command '/control/execute' does not exist, please define it before using it.
/gui/addButton run "Collect interaction events" "/control/execute mac/setup_interaction_events.mac"
Warning: command '/control/execute' does not exist, please define it before using it.
/gui/addButton run "Collect trigger events" "/control/execute mac/setup_trigger_events.mac"
Warning: command '/control/execute' does not exist, please define it before using it.
/gui/addButton run "Run 1 event" "/run/beamOn 1"
Warning: command '/run/beamOn' does not exist, please define it before using it.
/gui/addButton run "Run 5 events" "/run/beamOn 5"
Warning: command '/run/beamOn' does not exist, please define it before using it.
/gui/addButton run "Run 10 events" "/run/beamOn 10"
Warning: command '/run/beamOn' does not exist, please define it before using it.
/gui/addButton run "Run 100 events" "/run/beamOn 100"
Warning: command '/run/beamOn' does not exist, please define it before using it.
/gui/addMenu viewer Viewer
/gui/addButton viewer "Draw world" "/control/execute mac/visQt.mac"
Warning: command '/control/execute' does not exist, please define it before using it.
/gui/addButton viewer "Set style solid" "/vis/viewer/set/style solid"
Warning: command '/vis/viewer/set/style' does not exist, please define it before using it.
/gui/addButton viewer "Set style wireframe" "/vis/viewer/set/style wire"
Warning: command '/vis/viewer/set/style' does not exist, please define it before using it.
/gui/addButton viewer "Highlight inner crystals" "/cexmc/vis/hlIC"
Warning: command '/cexmc/vis/hlIC' does not exist, please define it before using it.
/gui/addButton viewer "Unhighlight inner crystals" "/cexmc/vis/hlIC false"
Warning: command '/cexmc/vis/hlIC' does not exist, please define it before using it.
/gui/addButton viewer "Update scene" "/vis/scene/notifyHandlers"


My investigation has shown that this is due to incorrect argument passed in G4UIQt::AddButton() in treeTop->FindPath(aCommand). Here aCommand is the full path like "/control/execute mac/setup_all_events.mac", but as i understood from code trace it must be solely path without arguments like "/control/execute". The error finally emerges in piece

  if( i == G4int(std::string::npos) )
  {
    // Find command
    G4int n_commandEntry = command.size();
    for( G4int i_thCommand = 0; i_thCommand < n_commandEntry; i_thCommand++ )
    {
      if( remainingPath == command[i_thCommand]->GetCommandName() )
      { return command[i_thCommand]; }
    }
  }

of G4UIcommandTree::FindPath() where last part of the passed path is compared against available commands, as far as whole command with arguments is passed then check for equality of, for instance "style" and "style solid" fails. Arguments with "/" inside like in the first example bring even more mess. The fix is simple: pass only path, not arguments. Here is correct G4UIQt::AddButton():

void G4UIQt::AddButton (
 const char* aMenu
,const char* aLabel
,const char* aCommand
)
{
  if(aMenu==NULL) return; // TO KEEP
  if(aLabel==NULL) return; // TO KEEP
  if(aCommand==NULL) return; // TO KEEP

  QMenu *parentTmp = (QMenu*)GetInteractor(aMenu);

  if(parentTmp==NULL) {
    G4cout << "Menu name " << aMenu<< " does not exist, please define it before using it."<< G4endl;
  }
  
  // Find the command in the command tree
  G4UImanager* UI = G4UImanager::GetUIpointer();
  if(UI==NULL) return;
  G4UIcommandTree * treeTop = UI->GetTree();
  G4String cmd = aCommand;
  G4int cmdEndPos = cmd.find_first_of(" \t");
  if(cmdEndPos!=G4int(std::string::npos)) {
     cmd.erase(cmdEndPos);
  }

  if(treeTop->FindPath(cmd.c_str()) == NULL) {
    G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
  }

  QSignalMapper *signalMapper = new QSignalMapper(this);
  QAction *action = parentTmp->addAction(aLabel, signalMapper, SLOT(map()));

  connect(signalMapper, SIGNAL(mapped(const QString &)),this, SLOT(ButtonCallback(const QString&)));
  signalMapper->setMapping(action, QString(aCommand));
}


This fixes my issue.


Cheers, Alexey.
Comment 1 Alexey 2012-12-01 15:38:25 CET
Hi.

I see that part of the fix appeared in the latest released Geant4 9.6. Unfortunately this part makes no use without missed change of

  if(treeTop->FindPath(aCommand) == NULL) {
    G4cout << "Warning: command '"<< aCommand <<"' does not exist, please define it before using it."<< G4endl;
  }

to

  if(treeTop->FindPath(cmd.c_str()) == NULL) {
    G4cout << "Warning: command '"<< cmd <<"' does not exist, please define it before using it."<< G4endl;
  }

Cheers, Alexey.
Comment 2 garnier 2014-05-09 15:08:42 CEST
Fixed in Geant4.10