Geant4-11
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,int,G4String*);
41
43 G4VInteractiveSession* a_session
44)
45{
46 session = a_session;
47
48 G4UIparameter* parameter;
49
51 interactorDirectory->SetGuidance("UI interactors commands.");
52
53 // /gui/addMenu :
54 addMenu = new G4UIcommand("/gui/addMenu",this);
55 addMenu->SetGuidance("Add a menu to menu bar.");
56 parameter = new G4UIparameter("Name",'s',false);
57 parameter->SetDefaultValue("dummy");
58 addMenu->SetParameter (parameter);
59 parameter = new G4UIparameter("Label",'s',false);
60 parameter->SetDefaultValue("dummy");
61 addMenu->SetParameter (parameter);
62
63 // /gui/addButton :
64 addButton = new G4UIcommand("/gui/addButton",this);
65 addButton->SetGuidance("Add a button to menu.");
66 parameter = new G4UIparameter("Menu",'s',false);
67 parameter->SetDefaultValue("dummy");
68 addButton->SetParameter (parameter);
69 parameter = new G4UIparameter("Label",'s',false);
70 parameter->SetDefaultValue("dummy");
71 addButton->SetParameter (parameter);
72 parameter = new G4UIparameter("Command",'s',false);
73 parameter->SetDefaultValue("");
74 addButton->SetParameter (parameter);
75
76 // /gui/defaultIcons :
77 defaultIcons = new G4UIcommand("/gui/defaultIcons",this);
78 defaultIcons->SetGuidance("Set the Geant4 defaults icons in Qt driver.");
79 defaultIcons->SetGuidance("By default, Geant4 icons are enable.");
80
81 parameter = new G4UIparameter("bool",'b',true);
82 parameter->SetDefaultValue("true");
83 defaultIcons->SetParameter (parameter);
84
85 // /gui/addIcon :
86 addIcon = new G4UIcommand("/gui/addIcon",this);
88 ("Add a non-checkable icon to the Icon toolbar.");
90 ("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");
92 ("A command given without parameters will display a window that will allow one to choose the parameters (if needed) for this command.");
94 ("E.g: /gui/addIcon \"Change background color\" user_icon /vis/viewer/set/background ../Images/background.xpm");
96 ("Special cases for the Icon parameter:");
98 (" - open: Open an open-file-selector that can run the Command with File as argument.");
100 (" - save: Open a save-file-selector that can run the Command with File as argument.");
102 (" - move/rotate/pick/zoom_in/zoom_out: Theses icons are radio-button icons that can change cursor action.");
104 (" - wireframe/solid/hidden_line_removal/hidden_line_and_surface_removal: These icons are radio-button icons that can change drawing style.");
106 (" - perspective/ortho: These icons are radio-button icons that can change projection style.");
107
108 parameter = new G4UIparameter("Label",'s',false);
109 parameter->SetDefaultValue("");
110 addIcon->SetParameter (parameter);
111
112 parameter = new G4UIparameter("Icon",'s',false);
113 parameter->SetDefaultValue("");
114 parameter->SetParameterCandidates
115 ("open save move rotate pick zoom_in zoom_out wireframe solid hidden_line_removal hidden_line_and_surface_removal perspective ortho exit user_icon");
116 addIcon->SetParameter (parameter);
117
118 parameter = new G4UIparameter("Command",'s',true);
119 parameter->SetDefaultValue("no_command");
120 addIcon->SetParameter (parameter);
121
122 parameter = new G4UIparameter("File",'s',true);
123 parameter->SetDefaultValue("no_file");
124 addIcon->SetParameter (parameter);
125
126 // /gui/system :
127 sys = new G4UIcommand("/gui/system",this);
128 sys->SetGuidance("Send a command to the system.");
129 parameter = new G4UIparameter("Command",'s',false);
130 parameter->SetDefaultValue("");
131 sys->SetParameter (parameter);
132
133 // /gui/outputStyle :
134 outputStyle = new G4UIcommand("/gui/outputStyle",this);
135 outputStyle->SetGuidance("Set output style.");
136 outputStyle->SetGuidance("Highlights commands if requested and if /control/verbose > 0.");
137 parameter = new G4UIparameter("destination",'s',true); // Omitable
138 parameter->SetParameterCandidates("cout cerr warnings errors all");
139 parameter->SetDefaultValue("all");
140 outputStyle->SetParameter (parameter);
141 parameter = new G4UIparameter("type",'s',true); // Omitable
142 parameter->SetParameterCandidates("fixed proportional");
143 parameter->SetDefaultValue("fixed");
144 outputStyle->SetParameter (parameter);
145 parameter = new G4UIparameter("highlight",'s',true); // Omitable
146 parameter->SetParameterCandidates("highlight no-highlight");
147 parameter->SetDefaultValue("highlight");
148 outputStyle->SetParameter (parameter);
149
150 // /gui/nativeMenuBar :
151 nativeMenu = new G4UIcommand("/gui/nativeMenuBar",this);
152 nativeMenu->SetGuidance("Allow native menu bar in Geant4 Qt driver.");
153 nativeMenu->SetGuidance("By default, enable.");
154
155 parameter = new G4UIparameter("bool",'b',true);
156 parameter->SetDefaultValue("true");
157 nativeMenu->SetParameter (parameter);
158 // /gui/clearMenu
159 clearMenu = new G4UIcommand("/gui/clearMenu",this);
160 clearMenu->SetGuidance("Clear menu bar, remove all user defined menu entries.");
161}
162
164{
165 delete clearMenu;
166 delete nativeMenu;
167 delete outputStyle;
168 delete sys;
169 delete defaultIcons;
170 delete addIcon;
171 delete addButton;
172 delete addMenu;
173 delete interactorDirectory;
174}
175
177 G4UIcommand* command
178,G4String newValue
179)
180{
181 int paramn = command->GetParameterEntries();
182 G4String* params = new G4String [paramn];
183 if(GetValues(newValue,paramn,params)==true) {
184 if(command==addMenu) {
185 session->AddMenu((const char*)params[0],(const char*)params[1]);
186 } else if(command==addButton) {
187 session->AddButton((const char*)params[0],(const char*)params[1],(const char*)params[2]);
188 } else if(command==addIcon) {
189 session->AddIcon((const char*)params[0],(const char*)params[1],(const char*)params[2],(const char*)params[3]);
190 } else if(command==defaultIcons) {
191 session->DefaultIcons(command->ConvertToBool(newValue));
192 } else if(command==sys) {
193 int rc = system((const char*)params[0]);
194 if ( rc < 0 ){ }
195 } else if(command==outputStyle) {
196 session->OutputStyle((const char*)params[0],(const char*)params[1],(const char*)params[2]);
197 } else if(command==nativeMenu) {
198 session->NativeMenu(command->ConvertToBool(newValue));
199 } else if(command==clearMenu) {
200 session->ClearMenu();
201 }
202 }
203 delete [] params;
204}
206 G4String newValue
207,int paramn
208,G4String* params
209)
210{
211 char* value = STRDUP(newValue.data());
212 if(value==NULL) return false;
213 char* tok = strtok(value," ");
214 for( int i=0; i<paramn;i++ ) {
215 if(tok==NULL) {
216 STRDEL(value);
217 return false;
218 }
219 G4String token = tok;
220 if( token[0]=='"' ) {
221 while( token.back() != '"' ) {
222 tok = strtok(NULL," ");
223 if( (tok==NULL) || (*tok=='\0')) {
224 STRDEL(value);
225 return false;
226 }
227 token += " ";
228 token += tok;
229 }
230 G4StrUtil::strip(token, '"');
231 }
232 if( token.empty() ) {
233 STRDEL(value);
234 return false;
235 } else {
236 params[i] = token;
237 }
238 tok = strtok(NULL," ");
239 }
240 STRDEL(value);
241 return true;
242}
243
244
static G4bool GetValues(G4String, int, G4String *)
#define STRDUP(str)
#define STRDEL(str)
bool G4bool
Definition: G4Types.hh:86
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIdirectory * interactorDirectory
G4InteractorMessenger(G4VInteractiveSession *session)
std::size_t GetParameterEntries() const
Definition: G4UIcommand.hh:138
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:146
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
static G4bool ConvertToBool(const char *st)
Definition: G4UIcommand.cc:545
void SetDefaultValue(const char *theDefaultValue)
void SetParameterCandidates(const char *theString)
void strip(G4String &str, char c=' ')
Remove leading and trailing characters from string.