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] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /interfaces/core/src/G4InteractorMessenger.cc (Version 11.3.0) and /interfaces/core/src/G4InteractorMessenger.cc (Version 9.4.p3)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 //                                                
 27                                                   
 28 #include "G4InteractorMessenger.hh"               
 29                                                   
 30 #include "G4UIcommand.hh"                         
 31 #include "G4UIdirectory.hh"                       
 32 #include "G4VInteractiveSession.hh"               
 33                                                   
 34 #include <cstdlib>                                
 35 #include <cstring>                                
 36                                                   
 37 #define STRDUP(str) \                             
 38   ((str) != NULL ? (strcpy((char*)malloc((unsi    
 39 #define STRDEL(str)      \                        
 40   {                      \                        
 41     if ((str) != NULL) { \                        
 42       free(str);         \                        
 43       str = NULL;        \                        
 44     }                    \                        
 45   }                                               
 46                                                   
 47 static G4bool GetValues(G4String, G4int, G4Str    
 48                                                   
 49 G4InteractorMessenger::G4InteractorMessenger(G    
 50 {                                                 
 51   session = a_session;                            
 52                                                   
 53   G4UIparameter* parameter;                       
 54                                                   
 55   // gui commands should *not* be broadcast to    
 56   G4bool propagateToWorkers;                      
 57   interactorDirectory = new G4UIdirectory("/gu    
 58   interactorDirectory->SetGuidance("UI interac    
 59                                                   
 60   // /gui/addMenu :                               
 61   addMenu = new G4UIcommand("/gui/addMenu", th    
 62   addMenu->SetGuidance("Add a menu to menu bar    
 63   parameter = new G4UIparameter("Name", 's', f    
 64   parameter->SetDefaultValue("dummy");            
 65   addMenu->SetParameter(parameter);               
 66   parameter = new G4UIparameter("Label", 's',     
 67   parameter->SetDefaultValue("dummy");            
 68   addMenu->SetParameter(parameter);               
 69                                                   
 70   // /gui/addButton :                             
 71   addButton = new G4UIcommand("/gui/addButton"    
 72   addButton->SetGuidance("Add a button to menu    
 73   parameter = new G4UIparameter("Menu", 's', f    
 74   parameter->SetDefaultValue("dummy");            
 75   addButton->SetParameter(parameter);             
 76   parameter = new G4UIparameter("Label", 's',     
 77   parameter->SetDefaultValue("dummy");            
 78   addButton->SetParameter(parameter);             
 79   parameter = new G4UIparameter("Command", 's'    
 80   parameter->SetDefaultValue("");                 
 81   addButton->SetParameter(parameter);             
 82                                                   
 83   // /gui/defaultIcons :                          
 84   defaultIcons = new G4UIcommand("/gui/default    
 85   defaultIcons->SetGuidance("Set the Geant4 de    
 86   defaultIcons->SetGuidance("By default, Geant    
 87                                                   
 88   parameter = new G4UIparameter("bool", 'b', t    
 89   parameter->SetDefaultValue("true");             
 90   defaultIcons->SetParameter(parameter);          
 91                                                   
 92   // /gui/addIcon :                               
 93   addIcon = new G4UIcommand("/gui/addIcon", th    
 94   addIcon->SetGuidance("Add a non-checkable ic    
 95   addIcon->SetGuidance(                           
 96     "If the Icon parameter is set to \"user_ic    
 97     "format, otherwise you have to choose one     
 98   addIcon->SetGuidance(                           
 99     "A command given without parameters will d    
100     "parameters (if needed) for this command."    
101   addIcon->SetGuidance(                           
102     "E.g: /gui/addIcon \"Change background col    
103     "../Images/background.xpm");                  
104   addIcon->SetGuidance("Special cases for the     
105   addIcon->SetGuidance(                           
106     " - open: Open an open-file-selector that     
107   addIcon->SetGuidance(                           
108     " - save: Open a save-file-selector that c    
109   addIcon->SetGuidance(                           
110     " - move/rotate/pick/zoom_in/zoom_out: The    
111     "cursor action.");                            
112   addIcon->SetGuidance(                           
113     " - wireframe/solid/hidden_line_removal/hi    
114     "radio-button icons that can change drawin    
115   addIcon->SetGuidance(                           
116     " - perspective/ortho: These icons are rad    
117                                                   
118   parameter = new G4UIparameter("Label", 's',     
119   parameter->SetDefaultValue("");                 
120   addIcon->SetParameter(parameter);               
121                                                   
122   parameter = new G4UIparameter("Icon", 's', f    
123   parameter->SetDefaultValue("");                 
124   parameter->SetParameterCandidates(              
125     "open save move rotate pick zoom_in zoom_o    
126     "hidden_line_and_surface_removal perspecti    
127   addIcon->SetParameter(parameter);               
128                                                   
129   parameter = new G4UIparameter("Command", 's'    
130   parameter->SetDefaultValue("no_command");       
131   addIcon->SetParameter(parameter);               
132                                                   
133   parameter = new G4UIparameter("File", 's', t    
134   parameter->SetDefaultValue("no_file");          
135   addIcon->SetParameter(parameter);               
136                                                   
137   // /gui/system :                                
138   sys = new G4UIcommand("/gui/system", this);     
139   sys->SetGuidance("Send a command to the syst    
140   parameter = new G4UIparameter("Command", 's'    
141   parameter->SetDefaultValue("");                 
142   sys->SetParameter(parameter);                   
143                                                   
144   // /gui/outputStyle :                           
145   outputStyle = new G4UIcommand("/gui/outputSt    
146   outputStyle->SetGuidance("Set output style."    
147   outputStyle->SetGuidance("First parameter: d    
148   outputStyle->SetGuidance("Second parameter:     
149   outputStyle->SetGuidance(                       
150     "Note that highlight for cout refers only     
151     "\ncommands echoed by \"/control/verbose 2    
152   outputStyle->SetGuidance("Note also that pla    
153   parameter = new G4UIparameter("destination",    
154   const auto& outputStyles = session->GetOutpu    
155   G4String candidates;                            
156   for (const auto& style : outputStyles) {        
157     candidates += style.first + ' ';              
158   }                                               
159   candidates += "all";                            
160   parameter->SetParameterCandidates(candidates    
161   parameter->SetDefaultValue("all");              
162   outputStyle->SetParameter(parameter);           
163   parameter = new G4UIparameter("style", 's',     
164   parameter->SetParameterCandidates("fixed pro    
165   parameter->SetDefaultValue("fixed");            
166   outputStyle->SetParameter(parameter);           
167                                                   
168   // /gui/nativeMenuBar :                         
169   nativeMenu = new G4UIcommand("/gui/nativeMen    
170   nativeMenu->SetGuidance("Allow native menu b    
171   nativeMenu->SetGuidance("By default, enable.    
172                                                   
173   parameter = new G4UIparameter("bool", 'b', t    
174   parameter->SetDefaultValue("true");             
175   nativeMenu->SetParameter(parameter);            
176   // /gui/clearMenu                               
177   clearMenu = new G4UIcommand("/gui/clearMenu"    
178   clearMenu->SetGuidance("Clear menu bar, remo    
179 }                                                 
180                                                   
181 G4InteractorMessenger::~G4InteractorMessenger(    
182 {                                                 
183   delete clearMenu;                               
184   delete nativeMenu;                              
185   delete outputStyle;                             
186   delete sys;                                     
187   delete defaultIcons;                            
188   delete addIcon;                                 
189   delete addButton;                               
190   delete addMenu;                                 
191   delete interactorDirectory;                     
192 }                                                 
193                                                   
194 void G4InteractorMessenger::SetNewValue(G4UIco    
195 {                                                 
196   const auto paramn = command->GetParameterEnt    
197   auto params = new G4String[paramn];             
198   if (GetValues(newValue, (G4int)paramn, param    
199     if (command == addMenu) {                     
200       session->AddMenu((const char*)params[0],    
201     }                                             
202     else if (command == addButton) {              
203       session->AddButton((const char*)params[0    
204     }                                             
205     else if (command == addIcon) {                
206       session->AddIcon((const char*)params[0],    
207         (const char*)params[3]);                  
208     }                                             
209     else if (command == defaultIcons) {           
210       session->DefaultIcons(command->ConvertTo    
211     }                                             
212     else if (command == sys) {                    
213       G4int rc = system((const char*)params[0]    
214       if (rc < 0) {                               
215       }                                           
216     }                                             
217     else if (command == outputStyle) {            
218       session->SetOutputStyle((const char*)par    
219     }                                             
220     else if (command == nativeMenu) {             
221       session->NativeMenu(command->ConvertToBo    
222     }                                             
223     else if (command == clearMenu) {              
224       session->ClearMenu();                       
225     }                                             
226   }                                               
227   delete[] params;                                
228 }                                                 
229 G4bool GetValues(G4String newValue, G4int para    
230 {                                                 
231   char* value = STRDUP(newValue.data());          
232   if (value == nullptr) return false;             
233   char* tok = strtok(value, " ");                 
234   for (G4int i = 0; i < paramn; ++i) {            
235     if (tok == nullptr) {                         
236       STRDEL(value);                              
237       return false;                               
238     }                                             
239     G4String token = tok;                         
240     if (token[0] == '"') {                        
241       while (token.back() != '"') {               
242         tok = strtok(nullptr, " ");               
243         if ((tok == nullptr) || (*tok == '\0')    
244           STRDEL(value);                          
245           return false;                           
246         }                                         
247         token += " ";                             
248         token += tok;                             
249       }                                           
250       G4StrUtil::strip(token, '"');               
251     }                                             
252     if (token.empty()) {                          
253       STRDEL(value);                              
254       return false;                               
255     }                                             
256                                                   
257     params[i] = std::move(token);                 
258                                                   
259     tok = strtok(nullptr, " ");                   
260   }                                               
261   STRDEL(value);                                  
262   return true;                                    
263 }                                                 
264