Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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// GEANT4 tag $Name: not supported by cvs2svn $
29
30// /vis/set - John Allison 21st March 2012
31// Set quantities for use in appropriate future commands.
32
33#include "G4VisCommandsSet.hh"
34
35#include "G4UIcommand.hh"
36#include "G4UIcmdWithADouble.hh"
37#include "G4UIcmdWithAString.hh"
38#include <cctype>
39#include <sstream>
40
41////////////// /vis/set/colour ////////////////////////////////////
42
44{
45 G4bool omitable;
46 fpCommand = new G4UIcommand("/vis/set/colour", this);
47 fpCommand->SetGuidance
48 ("Defines colour and opacity for future \"/vis/scene/add/\" commands.");
49 fpCommand->SetGuidance
50 ("(Except \"/vis/scene/add/text\" commands - see \"/vis/set/textColour\".)");
51 fpCommand->SetGuidance("Default: white and opaque.");
52 G4UIparameter* parameter;
53 parameter = new G4UIparameter ("red", 's', omitable = true);
54 parameter->SetGuidance
55 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
56 parameter->SetDefaultValue ("1.");
57 fpCommand->SetParameter (parameter);
58 parameter = new G4UIparameter ("green", 'd', omitable = true);
59 parameter->SetDefaultValue (1.);
60 fpCommand->SetParameter (parameter);
61 parameter = new G4UIparameter ("blue", 'd', omitable = true);
62 parameter->SetDefaultValue (1.);
63 fpCommand->SetParameter (parameter);
64 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
65 parameter->SetDefaultValue (1.);
66 parameter->SetGuidance ("Opacity");
67 fpCommand->SetParameter (parameter);
68}
69
71{
72 delete fpCommand;
73}
74
76{
77 return G4String();
78}
79
81{
83
84 G4String redOrString;
85 G4double green, blue, opacity;
86 std::istringstream iss(newValue);
87 iss >> redOrString >> green >> blue >> opacity;
88
89 G4Colour colour(1,1,1,1); // Default white and opaque.
90 if (std::isalpha(redOrString(0))) {
91 if (!G4Colour::GetColour(redOrString, colour)) {
92 if (verbosity >= G4VisManager::warnings) {
93 G4cout << "WARNING: Colour \"" << redOrString
94 << "\" not found. Defaulting to white and opaque."
95 << G4endl;
96 }
97 }
98 } else {
99 colour = G4Colour
100 (G4UIcommand::ConvertToDouble(redOrString), green, blue);
101 }
102 // Add opacity
104 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
105
106 if (verbosity >= G4VisManager::confirmations) {
107 G4cout <<
108 "Colour for future \"/vis/scene/add/\" commands has been set to "
109 << fCurrentColour <<
110 ".\n(Except \"/vis/scene/add/text\" commands - use \"/vis/set/textColour\".)"
111 << G4endl;
112 }
113}
114
115////////////// /vis/set/lineWidth ////////////////////////////////////
116
118{
119 G4bool omitable;
120 fpCommand = new G4UIcmdWithADouble("/vis/set/lineWidth", this);
121 fpCommand->SetGuidance
122 ("Defines lineWidth for future \"/vis/scene/add/\" commands.");
123 fpCommand->SetParameterName ("lineWidth", omitable = true);
124 fpCommand->SetDefaultValue (1.);
125 fpCommand->SetRange("lineWidth >= 1.");
126}
127
129{
130 delete fpCommand;
131}
132
134{
135 return G4String();
136}
137
139{
141
142 fCurrentLineWidth = fpCommand->GetNewDoubleValue(newValue);
143
144 if (verbosity >= G4VisManager::confirmations) {
145 G4cout <<
146 "Line width for future \"/vis/scene/add/\" commands has been set to "
148 << G4endl;
149 }
150}
151
152////////////// /vis/set/textColour ////////////////////////////////////
153
155{
156 G4bool omitable;
157 fpCommand = new G4UIcommand("/vis/set/textColour", this);
158 fpCommand->SetGuidance
159 ("Defines colour and opacity for future \"/vis/scene/add/text\" commands.");
160 fpCommand->SetGuidance("Default: blue and opaque.");
161 G4UIparameter* parameter;
162 parameter = new G4UIparameter ("red", 's', omitable = true);
163 parameter->SetGuidance
164 ("Red component or a string, e.g., \"cyan\" (green and blue parameters are ignored).");
165 parameter->SetDefaultValue ("0.");
166 fpCommand->SetParameter (parameter);
167 parameter = new G4UIparameter ("green", 'd', omitable = true);
168 parameter->SetDefaultValue (0.);
169 fpCommand->SetParameter (parameter);
170 parameter = new G4UIparameter ("blue", 'd', omitable = true);
171 parameter->SetDefaultValue (1.);
172 fpCommand->SetParameter (parameter);
173 parameter = new G4UIparameter ("alpha", 'd', omitable = true);
174 parameter->SetDefaultValue (1.);
175 parameter->SetGuidance ("Opacity");
176 fpCommand->SetParameter (parameter);
177}
178
180{
181 delete fpCommand;
182}
183
185{
186 return G4String();
187}
188
190{
192
193 G4String redOrString;
194 G4double green, blue, opacity;
195 std::istringstream iss(newValue);
196 iss >> redOrString >> green >> blue >> opacity;
197
198 G4Colour colour(0,0,1,1); // Default blue and opaque.
199 if (std::isalpha(redOrString(0))) {
200 if (!G4Colour::GetColour(redOrString, colour)) {
201 if (verbosity >= G4VisManager::warnings) {
202 G4cout << "WARNING: Text colour \"" << redOrString
203 << "\" not found. Defaulting to blue and opaque."
204 << G4endl;
205 }
206 }
207 } else {
208 colour = G4Colour
209 (G4UIcommand::ConvertToDouble(redOrString), green, blue);
210 }
211 // Add opacity
213 (colour.GetRed(), colour.GetGreen(), colour.GetBlue(), opacity);
214
215 if (verbosity >= G4VisManager::confirmations) {
216 G4cout <<
217 "Colour for future \"/vis/scene/add/text\" commands has been set to "
218 << fCurrentTextColour << '.'
219 << G4endl;
220 }
221}
222
223////////////// /vis/set/textLayout ////////////////////////////////////
224
226{
227 G4bool omitable;
228 fpCommand = new G4UIcmdWithAString("/vis/set/textLayout", this);
229 fpCommand->SetGuidance
230 ("Defines layout future \"/vis/scene/add/text\" commands.");
231 fpCommand->SetGuidance
232 ("\"left\" (default) for left justification to provided coordinate.");
233 fpCommand->SetGuidance
234 ("\"centre\" or \"center\" for text centered on provided coordinate.");
235 fpCommand->SetGuidance
236 ("\"right\" for right justification to provided coordinate.");
237 fpCommand->SetGuidance("Default: left.");
238 fpCommand->SetParameterName("layout", omitable = true);
239 fpCommand->SetCandidates ("left centre center right");
240 fpCommand->SetDefaultValue ("left");
241}
242
244{
245 delete fpCommand;
246}
247
249{
250 return G4String();
251}
252
254{
256 if (newValue == "left") layout = G4Text::left;
257 else if (newValue == "centre" || newValue == "center")
258 layout = G4Text::centre;
259 else if (newValue == "right") layout = G4Text::right;
260
261 fCurrentTextLayout = layout;
262
264 if (verbosity >= G4VisManager::confirmations) {
265 G4cout << "Text layout (for future \"text\" commands) has been set to \""
266 << fCurrentTextLayout << "\"."
267 << G4endl;
268 }
269}
270
271////////////// /vis/set/touchable ////////////////////////////////////
272
274{
275 G4bool omitable;
276 G4UIparameter* parameter;
277 fpCommand = new G4UIcommand("/vis/set/touchable", this);
278 fpCommand->SetGuidance
279 ("Defines touchable for future \"/vis/touchable/set/\" commands.");
280 fpCommand->SetGuidance
281 ("Please provide a list of space-separated physical volume names and"
282 "\ncopy number pairs starting at the world volume, e.g:"
283 "\n/vis/set/touchable World 0 Envelope 0 Shape1 0");
284 parameter = new G4UIparameter ("list", 's', omitable = false);
285 parameter->SetGuidance
286 ("List of physical volume names and copy number pairs");
287 fpCommand->SetParameter (parameter);
288}
289
291{
292 delete fpCommand;
293}
294
296{
297 return G4String();
298}
299
301{
303
304 G4ModelingParameters::PVNameCopyNoPath currentTouchablePath;
305
306 // Algorithm from Josuttis p.476.
307 G4String::size_type iBegin, iEnd;
308 iBegin = newValue.find_first_not_of(' ');
309 while (iBegin != G4String::npos) {
310 iEnd = newValue.find_first_of(' ',iBegin);
311 if (iEnd == G4String::npos) {
312 iEnd = newValue.length();
313 }
314 G4String name(newValue.substr(iBegin,iEnd-iBegin));
315 iBegin = newValue.find_first_not_of(' ',iEnd);
316 if (iBegin == G4String::npos) {
317 if (verbosity >= G4VisManager::warnings) {
318 G4cout <<
319 "WARNING: G4VisCommandSetTouchable::SetNewValue"
320 "\n A pair not found. (Did you have an even number of parameters?)"
321 "\n Command ignored."
322 << G4endl;
323 return;
324 }
325 }
326 iEnd = newValue.find_first_of(' ',iBegin);
327 if (iEnd == G4String::npos) {
328 iEnd = newValue.length();
329 }
330 G4int copyNo;
331 std::istringstream iss(newValue.substr(iBegin,iEnd-iBegin));
332 if (!(iss >> copyNo)) {
333 if (verbosity >= G4VisManager::warnings) {
334 G4cout <<
335 "WARNING: G4VisCommandSetTouchable::SetNewValue"
336 "\n Error reading copy number - it was not numeric?"
337 "\n Command ignored."
338 << G4endl;
339 return;
340 }
341 }
342 currentTouchablePath.push_back
344 iBegin = newValue.find_first_not_of(' ',iEnd);
345 }
346
347 fCurrentTouchablePath = currentTouchablePath;
348
349 if (verbosity >= G4VisManager::confirmations) {
351 << G4endl;
352 }
353}
354
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
#define G4endl
Definition: G4ios.hh:52
G4DLLIMPORT std::ostream G4cout
G4double GetBlue() const
Definition: G4Colour.hh:140
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:123
G4double GetRed() const
Definition: G4Colour.hh:138
G4double GetGreen() const
Definition: G4Colour.hh:139
std::vector< PVNameCopyNo > PVNameCopyNoPath
Layout
Definition: G4Text.hh:77
@ centre
Definition: G4Text.hh:77
@ right
Definition: G4Text.hh:77
@ left
Definition: G4Text.hh:77
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
static G4double GetNewDoubleValue(const char *paramString)
void SetDefaultValue(G4double defVal)
void SetCandidates(const char *candidateList)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetDefaultValue(const char *defVal)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
void SetRange(const char *rs)
Definition: G4UIcommand.hh:120
static G4double ConvertToDouble(const char *st)
Definition: G4UIcommand.cc:421
void SetDefaultValue(const char *theDefaultValue)
void SetGuidance(const char *theGuidance)
static G4Colour fCurrentTextColour
static G4ModelingParameters::PVNameCopyNoPath fCurrentTouchablePath
static G4VisManager * fpVisManager
static G4Text::Layout fCurrentTextLayout
static G4double fCurrentLineWidth
static G4Colour fCurrentColour
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4String GetCurrentValue(G4UIcommand *command)
static Verbosity GetVerbosity()