source: trunk/source/visualization/modeling/include/G4ModelApplyCommandsT.hh~ @ 1350

Last change on this file since 1350 was 1350, checked in by garnier, 13 years ago

update to last version 4.9.4

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