Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
40 ////////////// /vis/set/colour ////////////////////////////////////
41 
43 {
44  G4bool omitable;
45  fpCommand = new G4UIcommand("/vis/set/colour", this);
46  fpCommand->SetGuidance
47  ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
48  fpCommand->SetGuidance
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 
114 ////////////// /vis/set/lineWidth ////////////////////////////////////
115 
117 {
118  G4bool omitable;
119  fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
120  fpCommand->SetGuidance
121  ("Defines lineWidth for future \"/vis/scene/add/\" commands.");
122  fpCommand->SetParameterName ("lineWidth", omitable = true);
123  fpCommand->SetDefaultValue (1.);
124  fpCommand->SetRange("lineWidth >= 1.");
125 }
126 
128 {
129  delete fpCommand;
130 }
131 
133 {
134  return G4String();
135 }
136 
138 {
140 
141  fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue);
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 
151 ////////////// /vis/set/textColour ////////////////////////////////////
152 
154 {
155  G4bool omitable;
156  fpCommand = new G4UIcommand("/vis/set/textColour", this);
157  fpCommand->SetGuidance
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 
222 ////////////// /vis/set/textLayout ////////////////////////////////////
223 
225 {
226  G4bool omitable;
227  fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
228  fpCommand->SetGuidance
229  ("Defines layout future \"/vis/scene/add/text\" commands.");
230  fpCommand->SetGuidance
231  ("\"left\" (default) for left justification to provided coordinate.");
232  fpCommand->SetGuidance
233  ("\"centre\" or \"center\" for text centered on provided coordinate.");
234  fpCommand->SetGuidance
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 
270 ////////////// /vis/set/touchable ////////////////////////////////////
271 
273 {
274  G4bool omitable;
275  G4UIparameter* parameter;
276  fpCommand = new G4UIcommand("/vis/set/touchable", this);
277  fpCommand->SetGuidance
278  ("Defines touchable for future \"/vis/touchable/set/\" commands.");
279  fpCommand->SetGuidance
280  ("Please provide a list of space-separated physical volume names and"
281  "\ncopy number pairs starting at the world volume, e.g:"
282  "\n /vis/set/touchable World 0 Envelope 0 Shape1 0"
283  "\n(To get list of touchables, use \"/vis/drawTree\")"
284  "\n(To save, use \"/vis/viewer/save\")");
285  parameter = new G4UIparameter ("list", 's', omitable = false);
286  parameter->SetGuidance
287  ("List of physical volume names and copy number pairs");
288  fpCommand->SetParameter (parameter);
289 }
290 
292 {
293  delete fpCommand;
294 }
295 
297 {
298  return G4String();
299 }
300 
302 {
304 
305  G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
306 
307  // Algorithm from Josuttis p.476.
308  G4String::size_type iBegin, iEnd;
309  iBegin = newValue.find_first_not_of(' ');
310  while (iBegin != G4String::npos) {
311  iEnd = newValue.find_first_of(' ',iBegin);
312  if (iEnd == G4String::npos) {
313  iEnd = newValue.length();
314  }
315  G4String name(newValue.substr(iBegin,iEnd-iBegin));
316  iBegin = newValue.find_first_not_of(' ',iEnd);
317  if (iBegin == G4String::npos) {
318  if (verbosity >= G4VisManager::warnings) {
319  G4cout <<
320  "WARNING: G4VisCommandSetTouchable::SetNewValue"
321  "\n A pair not found. (Did you have an even number of parameters?)"
322  "\n Command ignored."
323  << G4endl;
324  return;
325  }
326  }
327  iEnd = newValue.find_first_of(' ',iBegin);
328  if (iEnd == G4String::npos) {
329  iEnd = newValue.length();
330  }
331  G4int copyNo;
332  std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
333  if (!(iss >> copyNo)) {
334  if (verbosity >= G4VisManager::warnings) {
335  G4cout <<
336  "WARNING: G4VisCommandSetTouchable::SetNewValue"
337  "\n Error reading copy number - it was not numeric?"
338  "\n Command ignored."
339  << G4endl;
340  return;
341  }
342  }
343  currentTouchablePath.push_back
345  iBegin = newValue.find_first_not_of(' ',iEnd);
346  }
347 
348  fCurrentTouchablePath = currentTouchablePath;
349 
350  if (verbosity >= G4VisManager::confirmations) {
352  << G4endl;
353  }
354 }
355 
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
static G4Colour fCurrentColour
static G4Text::Layout fCurrentTextLayout
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
void SetDefaultValue(const char *theDefaultValue)
const XML_Char * name
G4double GetBlue() const
Definition: G4Colour.hh:141
void SetNewValue(G4UIcommand *command, G4String newValue)
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:429
G4String GetCurrentValue(G4UIcommand *command)
std::vector< PVNameCopyNo > PVNameCopyNoPath
void SetDefaultValue(const char *defVal)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
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