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