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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 11.2)


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