Geant4  10.02.p02
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: G4ModelApplyCommandsT.hh 66373 2012-12-18 09:41:34Z gcosmo $
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"
41 #include "G4UIcmdWithAnInteger.hh"
42 #include "G4UIcmdWithAString.hh"
43 #include "G4UIcommand.hh"
44 #include "G4VModelCommand.hh"
45 #include "G4VVisManager.hh"
46 #include <sstream>
47 
49 // ApplyStringColour command
50 template <typename M>
52 
53 public: // With description
54 
55  G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
56 
58 
59  void SetNewValue(G4UIcommand* command, G4String newValue);
60 
61 protected:
62 
63  // Implement in derived class
64  virtual void Apply(const G4String&, const G4Colour&) = 0;
65 
68 
69 private:
70 
73 
74 };
75 
76 template <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);
100 
101  param = new G4UIparameter("Red component", 'd', false);
103 
104  param = new G4UIparameter("Green component", 'd', false);
106 
107  param = new G4UIparameter("Blue component", 'd', false);
109 
110  param = new G4UIparameter("Alpha component", 'd', false);
112 }
113 
114 template <typename M>
116 {
117  delete fpStringCmd;
118  delete fpComponentCmd;
119 }
120 
121 template <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 
158 //ApplyColour command
159 template <typename M>
161 
162 public: // 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 
170 protected:
171 
172  // Implement in derived class
173  virtual void Apply(const G4Colour&) = 0;
174 
177 
178 private:
179 
182 
183 };
184 
185 template <typename M>
186 G4ModelCmdApplyColour<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);
208 
209  param = new G4UIparameter("Green component", 'd', false);
211 
212  param = new G4UIparameter("Blue component", 'd', false);
214 
215  param = new G4UIparameter("Alpha component", 'd', false);
217 }
218 
219 template <typename M>
221 {
222  delete fpStringCmd;
223  delete fpComponentCmd;
224 }
225 
226 template <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 
262 //ApplyBool command
263 template <typename M>
265 
266 public: // 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 
273 protected:
274 
275  // Implement in derived class
276  virtual void Apply(const G4bool&) = 0;
277 
279 
280 private:
281 
283 
284 };
285 
286 template <typename M>
287 G4ModelCmdApplyBool<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 
296 template <typename M>
298 {
299  delete fpCmd;
300 }
301 
302 template <typename M>
304 {
305  Apply(fpCmd->GetNewBoolValue(newValue));
307  if (visManager) visManager->NotifyHandlers();
308 }
309 
311 //ApplyNull command
312 template <typename M>
314 
315 public: // 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 
323 protected:
324 
325  // Implement in derived class
326  virtual void Apply() = 0;
327 
328  G4UIcommand* Command() {return fpCmd;}
329 
330 private:
331 
333 
334 };
335 
336 template <typename M>
337 G4ModelCmdApplyNull<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 
344 template <typename M>
346 {
347  delete fpCmd;
348 }
349 
350 template <typename M>
352 {
353  Apply();
355  if (visManager) visManager->NotifyHandlers();
356 }
357 
359 //ApplyDouble command
360 template <typename M>
362 
363 public: // 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 
371 protected:
372 
373  // Implement in derived class
374  virtual void Apply(const G4double&) = 0;
375 
377 
378 private:
379 
381 
382 };
383 
384 template <typename M>
385 G4ModelCmdApplyDouble<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 
394 template <typename M>
396 {
397  delete fpCmd;
398 }
399 
400 template <typename M>
402 {
403  Apply(fpCmd->GetNewDoubleValue(newValue));
405  if (visManager) visManager->NotifyHandlers();
406 }
407 
409 //ApplyDoubleAndUnit command
410 template <typename M>
412 
413 public: // With description
414 
415  G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
416 
418 
419  void SetNewValue(G4UIcommand* command, G4String newValue);
420 
421 protected:
422 
423  // Implement in derived class
424  virtual void Apply(const G4double&) = 0;
425 
427 
428 private:
429 
431 
432 };
433 
434 template <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 
444 template <typename M>
446 {
447  delete fpCmd;
448 }
449 
450 template <typename M>
452 {
453  Apply(fpCmd->GetNewDoubleValue(newValue));
455  if (visManager) visManager->NotifyHandlers();
456 }
457 
459 // ApplyInteger command
460 template <typename M>
462 
463 public: // 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 
471 protected:
472 
473  // Implement in derived class
474  virtual void Apply(const G4int&) = 0;
475 
477 
478 private:
479 
481 };
482 
483 template <typename M>
484 G4ModelCmdApplyInteger<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 
493 template <typename M>
495 {
496  delete fpCmd;
497 }
498 
499 template <typename M>
501 {
502  Apply(fpCmd->GetNewIntValue(newValue));
504  if (visManager) visManager->NotifyHandlers();
505 }
506 
508 // ApplyString command
509 template <typename M>
511 
512 public: // 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 
520 protected:
521 
522  // Implement in derived class
523  virtual void Apply(const G4String&) = 0;
524 
526 
527 private:
528 
530 
531 };
532 
533 template <typename M>
534 G4ModelCmdApplyString<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 
542 template <typename M>
544 {
545  delete fpCmd;
546 }
547 
548 template <typename M>
550 {
551  Apply(newValue);
553  if (visManager) visManager->NotifyHandlers();
554 }
555 
556 #endif
G4UIcmdWithADoubleAndUnit * Command()
void SetParameter(G4UIparameter *const newParameter)
Definition: G4UIcommand.hh:152
G4ModelCmdApplyColour(M *model, const G4String &placement, const G4String &cmdName)
Definition: test07.cc:36
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4ModelCmdApplyDoubleAndUnit(M *model, const G4String &placement, const G4String &cmdName)
G4UIcmdWithAString * fpCmd
static G4VVisManager * GetConcreteInstance()
G4ModelCmdApplyString(M *model, const G4String &placement, const G4String &cmdName)
static G4bool GetColour(const G4String &key, G4Colour &result)
Definition: G4Colour.cc:126
virtual void Apply(const G4double &)=0
G4ModelCmdApplyDouble(M *model, const G4String &placement, const G4String &cmdName)
G4UIcmdWithADouble * fpCmd
virtual void Apply()=0
void SetNewValue(G4UIcommand *command, G4String newValue)
Definition: test07.cc:36
int G4int
Definition: G4Types.hh:78
G4UIcmdWithABool * fpCmd
G4UIcmdWithADouble * Command()
G4UIcmdWithADoubleAndUnit * fpCmd
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
virtual void Apply(const G4String &, const G4Colour &)=0
G4UIcmdWithAnInteger * Command()
G4UIcmdWithAString * Command()
bool G4bool
Definition: G4Types.hh:79
void SetGuidance(const char *aGuidance)
Definition: G4UIcommand.hh:161
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4int &)=0
G4UIcmdWithAnInteger * fpCmd
virtual void NotifyHandlers()
G4UIcmdWithABool * Command()
virtual void Apply(const G4Colour &)=0
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4ModelCmdApplyBool(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
G4ModelCmdApplyInteger(M *model, const G4String &placement, const G4String &cmdName)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4String &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4double &)=0
double G4double
Definition: G4Types.hh:76
G4ModelCmdApplyNull(M *model, const G4String &placement, const G4String &cmdName)
static const G4double alpha
G4ModelCmdApplyStringColour(M *model, const G4String &placement, const G4String &cmdName)
void SetParameterName(const char *theName, G4bool omittable, G4bool currentAsDefault=false)
void SetNewValue(G4UIcommand *command, G4String newValue)
virtual void Apply(const G4bool &)=0
void SetNewValue(G4UIcommand *command, G4String newValue)