Geant4 9.6.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4ModelApplyCommandsT.hh
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// $Id$
27//
28// Abstract model messenges. Derived classes should implement
29// the "Apply" method
30//
31// Jane Tinslay April 2006
32//
33#ifndef G4APPLYCOMMANDST_HH
34#define G4APPLYCOMMANDST_HH
35
36#include "G4Colour.hh"
37#include "G4String.hh"
38#include "G4UIcmdWithABool.hh"
39#include "G4UIcmdWithADouble.hh"
42#include "G4UIcmdWithAString.hh"
43#include "G4UIcommand.hh"
44#include "G4VModelCommand.hh"
45#include "G4VVisManager.hh"
46#include <sstream>
47
48///////////////////////////////////////////////////////////////////////////
49// ApplyStringColour command
50template <typename M>
52
53public: // With description
54
55 G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
56
58
59 void SetNewValue(G4UIcommand* command, G4String newValue);
60
61protected:
62
63 // Implement in derived class
64 virtual void Apply(const G4String&, const G4Colour&) = 0;
65
66 G4UIcommand* StringCommand() {return fpStringCmd;}
67 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
68
69private:
70
71 G4UIcommand* fpStringCmd;
72 G4UIcommand* fpComponentCmd;
73
74};
75
76template <typename M>
78 :G4VModelCommand<M>(model, placement)
79{
80 //Set variable colour through a string
81 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
82 G4UIparameter* param(0);
83
84 fpStringCmd = new G4UIcommand(dir, this);
85 fpStringCmd->SetGuidance("Set variable colour through a string");
86
87 param = new G4UIparameter("Variable", 's', false);
88 fpStringCmd->SetParameter(param);
89
90 param = new G4UIparameter("Value", 's', false);
91 fpStringCmd->SetParameter(param);
92
93 //Set variable colour through RGBA components
94 G4String componentDir = dir+"RGBA";
95
96 fpComponentCmd = new G4UIcommand(componentDir, this);
97 fpComponentCmd->SetGuidance("Set variable colour through red, green, blue and alpha components");
98 param = new G4UIparameter("Variable", 's', false);
99 fpComponentCmd->SetParameter(param);
100
101 param = new G4UIparameter("Red component", 'd', false);
102 fpComponentCmd->SetParameter(param);
103
104 param = new G4UIparameter("Green component", 'd', false);
105 fpComponentCmd->SetParameter(param);
106
107 param = new G4UIparameter("Blue component", 'd', false);
108 fpComponentCmd->SetParameter(param);
109
110 param = new G4UIparameter("Alpha component", 'd', false);
111 fpComponentCmd->SetParameter(param);
112}
113
114template <typename M>
116{
117 delete fpStringCmd;
118 delete fpComponentCmd;
119}
120
121template <typename M>
123{
124 G4Colour myColour;
125 G4String parameter;
126
127 if (cmd == fpStringCmd) {
128 G4String colour;
129 std::istringstream is (newValue);
130 is >> parameter >> colour;
131
132 // Colour key should exist
133 if (!G4Colour::GetColour(colour, myColour)) {
135 ed << "G4Colour with key "<<colour<<" does not exist ";
137 ("G4ModelCmdApplyStringColour<M>::SetNewValue",
138 "modeling0106", JustWarning, ed);
139 return;
140 }
141 }
142
143 if (cmd == fpComponentCmd) {
144 G4double red(0), green(0), blue(0), alpha(0);
145 std::istringstream is (newValue);
146 is >> parameter >> red >> green >> blue >> alpha;
147
148 G4Colour colour(red, green, blue, alpha);
149 myColour = colour;
150 }
151
152 Apply(parameter, myColour);
154 if (visManager) visManager->NotifyHandlers();
155}
156
157///////////////////////////////////////////////////////////////////////////
158//ApplyColour command
159template <typename M>
161
162public: // With description
163
164 G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName);
165
166 virtual ~G4ModelCmdApplyColour();
167
168 void SetNewValue(G4UIcommand* command, G4String newValue);
169
170protected:
171
172 // Implement in derived class
173 virtual void Apply(const G4Colour&) = 0;
174
175 G4UIcommand* StringCommand() {return fpStringCmd;}
176 G4UIcommand* ComponentCommand() {return fpComponentCmd;}
177
178private:
179
180 G4UIcommand* fpStringCmd;
181 G4UIcommand* fpComponentCmd;
182
183};
184
185template <typename M>
186G4ModelCmdApplyColour<M>::G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName)
187 :G4VModelCommand<M>(model, placement)
188{
189 //Set colour through a string
190 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
191 G4UIparameter* param(0);
192
193 fpStringCmd = new G4UIcommand(dir, this);
194 fpStringCmd->SetGuidance("Set colour through a string");
195
196 param = new G4UIparameter("Variable", 's', false);
197 fpStringCmd->SetParameter(param);
198
199 //Set colour through RGBA components
200 G4String componentDir = dir+"RGBA";
201
202 fpComponentCmd = new G4UIcommand(componentDir, this);
203 fpComponentCmd->SetGuidance("Set colour through red, green, blue and alpha components");
204 fpComponentCmd->SetGuidance("Four inputs are expected.");
205
206 param = new G4UIparameter("Red component", 'd', false);
207 fpComponentCmd->SetParameter(param);
208
209 param = new G4UIparameter("Green component", 'd', false);
210 fpComponentCmd->SetParameter(param);
211
212 param = new G4UIparameter("Blue component", 'd', false);
213 fpComponentCmd->SetParameter(param);
214
215 param = new G4UIparameter("Alpha component", 'd', false);
216 fpComponentCmd->SetParameter(param);
217}
218
219template <typename M>
221{
222 delete fpStringCmd;
223 delete fpComponentCmd;
224}
225
226template <typename M>
228{
229 G4Colour myColour;
230
231 if (cmd == fpStringCmd) {
232 G4String colour;
233 std::istringstream is (newValue);
234 is >> colour;
235
236 // Colour key should exist
237 if (!G4Colour::GetColour(colour, myColour)) {
239 ed << "G4Colour with key "<<colour<<" does not exist ";
241 ("G4ModelCmdApplyColour<M>::SetNewValue",
242 "modeling0107", JustWarning, ed);
243 return;
244 }
245 }
246
247 if (cmd == fpComponentCmd) {
248 G4double red(0), green(0), blue(0), alpha(0);
249 std::istringstream is (newValue);
250 is >> red >> green >> blue >> alpha;
251
252 G4Colour colour(red, green, blue, alpha);
253 myColour = colour;
254 }
255
256 Apply(myColour);
258 if (visManager) visManager->NotifyHandlers();
259}
260
261///////////////////////////////////////////////////////////////////////////
262//ApplyBool command
263template <typename M>
265
266public: // With description
267
268 G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName);
269 virtual ~G4ModelCmdApplyBool();
270
271 void SetNewValue(G4UIcommand* command, G4String newValue);
272
273protected:
274
275 // Implement in derived class
276 virtual void Apply(const G4bool&) = 0;
277
278 G4UIcmdWithABool* Command() {return fpCmd;}
279
280private:
281
282 G4UIcmdWithABool* fpCmd;
283
284};
285
286template <typename M>
287G4ModelCmdApplyBool<M>::G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName)
288 :G4VModelCommand<M>(model, placement)
289{
290 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
291 fpCmd = new G4UIcmdWithABool(dir, this);
292
293 fpCmd->SetParameterName("Bool", false);
294}
295
296template <typename M>
298{
299 delete fpCmd;
300}
301
302template <typename M>
304{
305 Apply(fpCmd->GetNewBoolValue(newValue));
307 if (visManager) visManager->NotifyHandlers();
308}
309
310///////////////////////////////////////////////////////////////////////////
311//ApplyNull command
312template <typename M>
314
315public: // With description
316
317 G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName);
318
319 virtual ~G4ModelCmdApplyNull();
320
321 void SetNewValue(G4UIcommand* command, G4String newValue);
322
323protected:
324
325 // Implement in derived class
326 virtual void Apply() = 0;
327
328 G4UIcommand* Command() {return fpCmd;}
329
330private:
331
332 G4UIcommand* fpCmd;
333
334};
335
336template <typename M>
337G4ModelCmdApplyNull<M>::G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName)
338 :G4VModelCommand<M>(model, placement)
339{
340 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
341 fpCmd = new G4UIcommand(dir, this);
342}
343
344template <typename M>
346{
347 delete fpCmd;
348}
349
350template <typename M>
352{
353 Apply();
355 if (visManager) visManager->NotifyHandlers();
356}
357
358///////////////////////////////////////////////////////////////////////////
359//ApplyDouble command
360template <typename M>
362
363public: // With description
364
365 G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName);
366
367 virtual ~G4ModelCmdApplyDouble();
368
369 void SetNewValue(G4UIcommand* command, G4String newValue);
370
371protected:
372
373 // Implement in derived class
374 virtual void Apply(const G4double&) = 0;
375
376 G4UIcmdWithADouble* Command() {return fpCmd;}
377
378private:
379
380 G4UIcmdWithADouble* fpCmd;
381
382};
383
384template <typename M>
385G4ModelCmdApplyDouble<M>::G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName)
386 :G4VModelCommand<M>(model, placement)
387{
388 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
389
390 fpCmd = new G4UIcmdWithADouble(dir, this);
391 fpCmd->SetParameterName("Double", false);
392}
393
394template <typename M>
396{
397 delete fpCmd;
398}
399
400template <typename M>
402{
403 Apply(fpCmd->GetNewDoubleValue(newValue));
405 if (visManager) visManager->NotifyHandlers();
406}
407
408///////////////////////////////////////////////////////////////////////////
409//ApplyDoubleAndUnit command
410template <typename M>
412
413public: // With description
414
415 G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
416
418
419 void SetNewValue(G4UIcommand* command, G4String newValue);
420
421protected:
422
423 // Implement in derived class
424 virtual void Apply(const G4double&) = 0;
425
427
428private:
429
431
432};
433
434template <typename M>
436 :G4VModelCommand<M>(model, placement)
437{
438 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
439
440 fpCmd = new G4UIcmdWithADoubleAndUnit(dir, this);
441 fpCmd->SetParameterName("DoubleAndUnit", false);
442}
443
444template <typename M>
446{
447 delete fpCmd;
448}
449
450template <typename M>
452{
453 Apply(fpCmd->GetNewDoubleValue(newValue));
455 if (visManager) visManager->NotifyHandlers();
456}
457
458///////////////////////////////////////////////////////////////////////////
459// ApplyInteger command
460template <typename M>
462
463public: // With description
464
465 G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName);
466
467 virtual ~G4ModelCmdApplyInteger();
468
469 void SetNewValue(G4UIcommand* command, G4String newValue);
470
471protected:
472
473 // Implement in derived class
474 virtual void Apply(const G4int&) = 0;
475
476 G4UIcmdWithAnInteger* Command() {return fpCmd;}
477
478private:
479
481};
482
483template <typename M>
484G4ModelCmdApplyInteger<M>::G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName)
485 :G4VModelCommand<M>(model, placement)
486{
487 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
488
489 fpCmd = new G4UIcmdWithAnInteger(dir, this);
490 fpCmd->SetParameterName("Integer", false);
491}
492
493template <typename M>
495{
496 delete fpCmd;
497}
498
499template <typename M>
501{
502 Apply(fpCmd->GetNewIntValue(newValue));
504 if (visManager) visManager->NotifyHandlers();
505}
506
507///////////////////////////////////////////////////////////////////////////
508// ApplyString command
509template <typename M>
511
512public: // With description
513
514 G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName);
515
516 virtual ~G4ModelCmdApplyString();
517
518 void SetNewValue(G4UIcommand* command, G4String newValue);
519
520protected:
521
522 // Implement in derived class
523 virtual void Apply(const G4String&) = 0;
524
525 G4UIcmdWithAString* Command() {return fpCmd;}
526
527private:
528
529 G4UIcmdWithAString* fpCmd;
530
531};
532
533template <typename M>
534G4ModelCmdApplyString<M>::G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName)
535 :G4VModelCommand<M>(model, placement)
536{
537 G4String dir = placement+"/"+model->Name()+"/"+cmdName;
538
539 fpCmd = new G4UIcmdWithAString(dir, this);
540}
541
542template <typename M>
544{
545 delete fpCmd;
546}
547
548template <typename M>
550{
551 Apply(newValue);
553 if (visManager) visManager->NotifyHandlers();
554}
555
556#endif
@ JustWarning
double G4double
Definition: G4Types.hh:64
int G4int
Definition: G4Types.hh:66
bool G4bool
Definition: G4Types.hh:67
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:123
G4UIcmdWithABool * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyBool(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4bool &)=0
G4ModelCmdApplyColour(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4Colour &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADoubleAndUnit * Command()
virtual void Apply(const G4double &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyDoubleAndUnit(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4double &)=0
G4ModelCmdApplyDouble(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
G4UIcmdWithADouble * Command()
G4ModelCmdApplyInteger(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4int &)=0
G4UIcmdWithAnInteger * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
G4ModelCmdApplyNull(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply()=0
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4String &, const G4Colour &)=0
G4ModelCmdApplyStringColour(M *model, const G4String &placement, const G4String &cmdName)
G4ModelCmdApplyString(M *model, const G4String &placement, const G4String &cmdName)
virtual void Apply(const G4String &)=0
G4UIcmdWithAString * Command()
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:147
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:156
virtual void NotifyHandlers()
static G4VVisManager * GetConcreteInstance()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76