Geant4  10.01.p02
G4VisCommandsSet.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 // $Id: G4VisCommands.cc,v 1.24 2009-03-09 12:42:00 allison Exp $
28 
29 // /vis/set - John Allison 21st March 2012
30 // Set quantities for use in appropriate future commands.
31 
32 #include "G4VisCommandsSet.hh"
33 
34 #include "G4UIcommand.hh"
35 #include "G4UIcmdWithADouble.hh"
36 #include "G4UIcmdWithAString.hh"
37 #include <cctype>
38 #include <sstream>
39 
41 
43 {
44  G4bool omitable;
45  fpCommand = new G4UIcommand("/vis/set/colour", this);
47  ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
49  ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)");
50  fpCommand->SetGuidance("Default: white and opaque.");
51  G4UIparameter* parameter;
52  parameter = new G4UIparameter ("red", 's', omitable = true);
53  parameter->SetGuidance
54  ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
55  parameter->SetDefaultValue ("1.");
56  fpCommand->SetParameter (parameter);
57  parameter = new G4UIparameter ("green", 'd', omitable = true);
58  parameter->SetDefaultValue (1.);
59  fpCommand->SetParameter (parameter);
60  parameter = new G4UIparameter ("blue", 'd', omitable = true);
61  parameter->SetDefaultValue (1.);
62  fpCommand->SetParameter (parameter);
63  parameter = new G4UIparameter ("alpha", 'd', omitable = true);
64  parameter->SetDefaultValue (1.);
65  parameter->SetGuidance ("Opacity");
66  fpCommand->SetParameter (parameter);
67 }
68 
70 {
71  delete fpCommand;
72 }
73 
75 {
76  return G4String();
77 }
78 
80 {
82 
83  G4String redOrString;
84  G4double green, blue, opacity;
85  std::istringstream iss(newValue);
86  iss >> redOrString >> green >> blue >> opacity;
87 
88  G4Colour colour(1,1,1,1); // Default white and opaque.
89  if (std::isalpha(redOrString(0))) {
90  if (!G4Colour::GetColour(redOrString, colour)) {
91  if (verbosity >= G4VisManager::warnings) {
92  G4cout << "WARNING: Colour \"" << redOrString
93  << "\" not found. Defaulting to white and opaque."
94  << G4endl;
95  }
96  }
97  } else {
98  colour = G4Colour
99  (G4UIcommand::ConvertToDouble(redOrString), green, blue);
100  }
101  // Add opacity
103  (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
104 
105  if (verbosity >= G4VisManager::confirmations) {
106  G4cout <<
107  "Colour for future \"/vis/scene/add/\" commands has been set to "
108  << fCurrentColour <<
109  ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)"
110  << G4endl;
111  }
112 }
113 
115 
117 {
118  G4bool omitable;
119  fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
121  ("Defines line width for future \"/vis/scene/add/\" commands.");
122  fpCommand->SetParameterName ("lineWidth", omitable = true);
124  fpCommand->SetRange("lineWidth >= 1.");
125 }
126 
128 {
129  delete fpCommand;
130 }
131 
133 {
134  return G4String();
135 }
136 
138 {
140 
142 
143  if (verbosity >= G4VisManager::confirmations) {
144  G4cout <<
145  "Line width for future \"/vis/scene/add/\" commands has been set to "
147  << G4endl;
148  }
149 }
150 
152 
154 {
155  G4bool omitable;
156  fpCommand = new G4UIcommand("/vis/set/textColour", this);
158  ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
159  fpCommand->SetGuidance("Default: blue and opaque.");
160  G4UIparameter* parameter;
161  parameter = new G4UIparameter ("red", 's', omitable = true);
162  parameter->SetGuidance
163  ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
164  parameter->SetDefaultValue ("0.");
165  fpCommand->SetParameter (parameter);
166  parameter = new G4UIparameter ("green", 'd', omitable = true);
167  parameter->SetDefaultValue (0.);
168  fpCommand->SetParameter (parameter);
169  parameter = new G4UIparameter ("blue", 'd', omitable = true);
170  parameter->SetDefaultValue (1.);
171  fpCommand->SetParameter (parameter);
172  parameter = new G4UIparameter ("alpha", 'd', omitable = true);
173  parameter->SetDefaultValue (1.);
174  parameter->SetGuidance ("Opacity");
175  fpCommand->SetParameter (parameter);
176 }
177 
179 {
180  delete fpCommand;
181 }
182 
184 {
185  return G4String();
186 }
187 
189 {
191 
192  G4String redOrString;
193  G4double green, blue, opacity;
194  std::istringstream iss(newValue);
195  iss >> redOrString >> green >> blue >> opacity;
196 
197  G4Colour colour(0,0,1,1); // Default blue and opaque.
198  if (std::isalpha(redOrString(0))) {
199  if (!G4Colour::GetColour(redOrString, colour)) {
200  if (verbosity >= G4VisManager::warnings) {
201  G4cout << "WARNING: Text colour \"" << redOrString
202  << "\" not found. Defaulting to blue and opaque."
203  << G4endl;
204  }
205  }
206  } else {
207  colour = G4Colour
208  (G4UIcommand::ConvertToDouble(redOrString), green, blue);
209  }
210  // Add opacity
212  (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
213 
214  if (verbosity >= G4VisManager::confirmations) {
215  G4cout <<
216  "Colour for future \"/vis/scene/add/text\" commands has been set to "
217  << fCurrentTextColour << '.'
218  << G4endl;
219  }
220 }
221 
223 
225 {
226  G4bool omitable;
227  fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
229  ("Defines layout future \"/vis/scene/add/text\" commands.");
231  ("\"left\" (default) for left justification to provided coordinate.");
233  ("\"centre\" or \"center\" for text centered on provided coordinate.");
235  ("\"right\" for right justification to provided coordinate.");
236  fpCommand->SetGuidance("Default: left.");
237  fpCommand->SetParameterName("layout", omitable = true);
238  fpCommand->SetCandidates ("left centre center right");
239  fpCommand->SetDefaultValue ("left");
240 }
241 
243 {
244  delete fpCommand;
245 }
246 
248 {
249  return G4String();
250 }
251 
253 {
254  G4Text::Layout layout = G4Text::left;
255  if (newValue == "left") layout = G4Text::left;
256  else if (newValue == "centre" || newValue == "center")
257  layout = G4Text::centre;
258  else if (newValue == "right") layout = G4Text::right;
259 
260  fCurrentTextLayout = layout;
261 
263  if (verbosity >= G4VisManager::confirmations) {
264  G4cout << "Text layout (for future \"text\" commands) has been set to \""
265  << fCurrentTextLayout << "\"."
266  << G4endl;
267  }
268 }
269 
271 
273 {
274  G4bool omitable;
275  fpCommand = new G4UIcmdWithADouble("/vis/set/textSize", this);
277  ("Defines text size (pixels) for future \"/vis/scene/add/\" commands.");
278  fpCommand->SetParameterName ("textSize", omitable = true);
279  fpCommand->SetDefaultValue (12.); // pixels
280  fpCommand->SetRange("textSize >= 1.");
281 }
282 
284 {
285  delete fpCommand;
286 }
287 
289 {
290  return G4String();
291 }
292 
294 {
296 
298 
299  if (verbosity >= G4VisManager::confirmations) {
300  G4cout <<
301  "Text size for future \"/vis/scene/add/\" commands has been set to "
303  << G4endl;
304  }
305 }
306 
308 
310 {
311  G4bool omitable;
312  G4UIparameter* parameter;
313  fpCommand = new G4UIcommand("/vis/set/touchable", this);
315  ("Defines touchable for future \"/vis/touchable/set/\" commands.");
317  ("Please provide a list of space-separated physical volume names and"
318  "\ncopy number pairs starting at the world volume, e.g:"
319  "\n /vis/set/touchable World 0 Envelope 0 Shape1 0"
320  "\n(To get list of touchables, use \"/vis/drawTree\")"
321  "\n(To save, use \"/vis/viewer/save\")");
322  parameter = new G4UIparameter ("list", 's', omitable = false);
323  parameter->SetGuidance
324  ("List of physical volume names and copy number pairs");
325  fpCommand->SetParameter (parameter);
326 }
327 
329 {
330  delete fpCommand;
331 }
332 
334 {
335  return G4String();
336 }
337 
339 {
341 
342  G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
343 
344  // Algorithm from Josuttis p.476.
345  G4String::size_type iBegin, iEnd;
346  iBegin = newValue.find_first_not_of(' ');
347  while (iBegin != G4String::npos) {
348  iEnd = newValue.find_first_of(' ',iBegin);
349  if (iEnd == G4String::npos) {
350  iEnd = newValue.length();
351  }
352  G4String name(newValue.substr(iBegin,iEnd-iBegin));
353  iBegin = newValue.find_first_not_of(' ',iEnd);
354  if (iBegin == G4String::npos) {
355  if (verbosity >= G4VisManager::warnings) {
356  G4cout <<
357  "WARNING: G4VisCommandSetTouchable::SetNewValue"
358  "\n A pair not found. (Did you have an even number of parameters?)"
359  "\n Command ignored."
360  << G4endl;
361  return;
362  }
363  }
364  iEnd = newValue.find_first_of(' ',iBegin);
365  if (iEnd == G4String::npos) {
366  iEnd = newValue.length();
367  }
368  G4int copyNo;
369  std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
370  if (!(iss >> copyNo)) {
371  if (verbosity >= G4VisManager::warnings) {
372  G4cout <<
373  "WARNING: G4VisCommandSetTouchable::SetNewValue"
374  "\n Error reading copy number - it was not numeric?"
375  "\n Command ignored."
376  << G4endl;
377  return;
378  }
379  }
380  currentTouchablePath.push_back
382  iBegin = newValue.find_first_not_of(' ',iEnd);
383  }
384 
385  fCurrentTouchablePath = currentTouchablePath;
386 
387  if (verbosity >= G4VisManager::confirmations) {
389  << G4endl;
390  }
391 }
392 
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
G4UIcmdWithADouble * fpCommand
static G4Colour fCurrentColour
G4String name
Definition: TRTMaterials.hh:40
static G4Text::Layout fCurrentTextLayout
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
void SetDefaultValue(const char *theDefaultValue)
G4UIcmdWithAString * fpCommand
G4double GetBlue() const
Definition: G4Colour.hh:141
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4double fCurrentTextSize
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
void SetNewValue(G4UIcommand *command, G4String newValue)
G4GLOB_DLL std::ostream G4cout
G4double GetRed() const
Definition: G4Colour.hh:139
bool G4bool
Definition: G4Types.hh:79
G4double GetGreen() const
Definition: G4Colour.hh:140
static G4double GetNewDoubleValue(const char *paramString)
void SetRange(const char *rs)
Definition: G4UIcommand.hh:125
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:443
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
std::vector< PVNameCopyNo > PVNameCopyNoPath
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4UIcmdWithADouble * fpCommand
void SetDefaultValue(G4double defVal)
void SetNewValue(G4UIcommand *command, G4String newValue)
Layout
Definition: G4Text.hh:77
static G4double fCurrentLineWidth
static G4Colour fCurrentTextColour
static Verbosity GetVerbosity()
void SetCandidates(const char *candidateList)
#define G4endl
Definition: G4ios.hh:61
G4String GetCurrentValue(G4UIcommand *command)
double G4double
Definition: G4Types.hh:76
void SetGuidance(const char *theGuidance)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
static G4VisManager * fpVisManager