G4ModelApplyCommandsT.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 //
00028 // Abstract model messenges. Derived classes should implement
00029 // the "Apply" method
00030 //
00031 // Jane Tinslay April 2006
00032 //
00033 #ifndef G4APPLYCOMMANDST_HH
00034 #define G4APPLYCOMMANDST_HH
00035 
00036 #include "G4Colour.hh"
00037 #include "G4String.hh"
00038 #include "G4UIcmdWithABool.hh"
00039 #include "G4UIcmdWithADouble.hh"
00040 #include "G4UIcmdWithADoubleAndUnit.hh"
00041 #include "G4UIcmdWithAnInteger.hh"
00042 #include "G4UIcmdWithAString.hh"
00043 #include "G4UIcommand.hh"
00044 #include "G4VModelCommand.hh"
00045 #include "G4VVisManager.hh"
00046 #include <sstream>
00047 
00049 // ApplyStringColour command
00050 template <typename M>
00051 class G4ModelCmdApplyStringColour : public G4VModelCommand<M> {
00052 
00053 public: // With description
00054 
00055   G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName);
00056 
00057   virtual ~G4ModelCmdApplyStringColour();
00058 
00059   void SetNewValue(G4UIcommand* command, G4String newValue);
00060 
00061 protected:
00062 
00063   // Implement in derived class
00064   virtual void Apply(const G4String&, const G4Colour&) = 0;
00065 
00066   G4UIcommand* StringCommand() {return fpStringCmd;}
00067   G4UIcommand* ComponentCommand() {return fpComponentCmd;}
00068 
00069 private:
00070 
00071   G4UIcommand* fpStringCmd;
00072   G4UIcommand* fpComponentCmd;
00073 
00074 };
00075 
00076 template <typename M>
00077 G4ModelCmdApplyStringColour<M>::G4ModelCmdApplyStringColour(M* model, const G4String& placement, const G4String& cmdName)
00078   :G4VModelCommand<M>(model, placement)
00079 {
00080   //Set variable colour through a string
00081   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00082   G4UIparameter* param(0);
00083 
00084   fpStringCmd = new G4UIcommand(dir, this);
00085   fpStringCmd->SetGuidance("Set variable colour through a string");   
00086   
00087   param = new G4UIparameter("Variable", 's', false);
00088   fpStringCmd->SetParameter(param);
00089 
00090   param = new G4UIparameter("Value", 's', false);
00091   fpStringCmd->SetParameter(param);
00092 
00093   //Set variable colour through RGBA components
00094   G4String componentDir = dir+"RGBA";
00095   
00096   fpComponentCmd = new G4UIcommand(componentDir, this);
00097   fpComponentCmd->SetGuidance("Set variable colour through red, green, blue and alpha components");   
00098   param = new G4UIparameter("Variable", 's', false);
00099   fpComponentCmd->SetParameter(param);
00100 
00101   param = new G4UIparameter("Red component", 'd', false);
00102   fpComponentCmd->SetParameter(param);
00103 
00104   param = new G4UIparameter("Green component", 'd', false);
00105   fpComponentCmd->SetParameter(param);
00106 
00107   param = new G4UIparameter("Blue component", 'd', false);
00108   fpComponentCmd->SetParameter(param);
00109 
00110   param = new G4UIparameter("Alpha component", 'd', false);
00111   fpComponentCmd->SetParameter(param);
00112 } 
00113 
00114 template <typename M>
00115 G4ModelCmdApplyStringColour<M>::~G4ModelCmdApplyStringColour()
00116 { 
00117   delete fpStringCmd;
00118   delete fpComponentCmd;
00119 }
00120 
00121 template <typename M>
00122 void G4ModelCmdApplyStringColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
00123 {
00124   G4Colour myColour;
00125   G4String parameter;
00126   
00127   if (cmd == fpStringCmd) {
00128     G4String colour;
00129     std::istringstream is (newValue);
00130     is >> parameter >> colour;
00131     
00132     // Colour key should exist
00133     if (!G4Colour::GetColour(colour, myColour)) {
00134       G4ExceptionDescription ed;
00135       ed << "G4Colour with key "<<colour<<" does not exist ";
00136       G4Exception
00137         ("G4ModelCmdApplyStringColour<M>::SetNewValue",
00138          "modeling0106", JustWarning, ed);
00139       return;
00140     }
00141   }
00142   
00143   if (cmd == fpComponentCmd) {
00144     G4double red(0), green(0), blue(0), alpha(0);
00145     std::istringstream is (newValue);
00146     is >> parameter >> red >> green >> blue >> alpha;
00147     
00148     G4Colour colour(red, green, blue, alpha);
00149     myColour = colour;
00150   }
00151 
00152   Apply(parameter, myColour);
00153   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00154   if (visManager) visManager->NotifyHandlers();
00155 }
00156 
00158 //ApplyColour command
00159 template <typename M>
00160 class G4ModelCmdApplyColour : public G4VModelCommand<M> {
00161 
00162 public: // With description
00163 
00164   G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName);
00165 
00166   virtual ~G4ModelCmdApplyColour();
00167 
00168   void SetNewValue(G4UIcommand* command, G4String newValue);
00169 
00170 protected:
00171 
00172   // Implement in derived class
00173   virtual void Apply(const G4Colour&) = 0;
00174 
00175   G4UIcommand* StringCommand() {return fpStringCmd;}
00176   G4UIcommand* ComponentCommand() {return fpComponentCmd;}
00177 
00178 private:
00179 
00180   G4UIcommand* fpStringCmd;
00181   G4UIcommand* fpComponentCmd;
00182 
00183 };
00184 
00185 template <typename M>
00186 G4ModelCmdApplyColour<M>::G4ModelCmdApplyColour(M* model, const G4String& placement, const G4String& cmdName)
00187   :G4VModelCommand<M>(model, placement)
00188 {
00189   //Set colour through a string
00190   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00191   G4UIparameter* param(0);
00192 
00193   fpStringCmd = new G4UIcommand(dir, this);
00194   fpStringCmd->SetGuidance("Set colour through a string");   
00195   
00196   param = new G4UIparameter("Variable", 's', false);
00197   fpStringCmd->SetParameter(param);
00198 
00199   //Set colour through RGBA components
00200   G4String componentDir = dir+"RGBA";
00201   
00202   fpComponentCmd = new G4UIcommand(componentDir, this);
00203   fpComponentCmd->SetGuidance("Set colour through red, green, blue and alpha components");   
00204   fpComponentCmd->SetGuidance("Four inputs are expected.");
00205 
00206   param = new G4UIparameter("Red component", 'd', false);
00207   fpComponentCmd->SetParameter(param);
00208 
00209   param = new G4UIparameter("Green component", 'd', false);
00210   fpComponentCmd->SetParameter(param);
00211 
00212   param = new G4UIparameter("Blue component", 'd', false);
00213   fpComponentCmd->SetParameter(param);
00214 
00215   param = new G4UIparameter("Alpha component", 'd', false);
00216   fpComponentCmd->SetParameter(param);
00217 } 
00218 
00219 template <typename M>
00220 G4ModelCmdApplyColour<M>::~G4ModelCmdApplyColour()
00221 { 
00222   delete fpStringCmd;
00223   delete fpComponentCmd;
00224 }
00225 
00226 template <typename M>
00227 void G4ModelCmdApplyColour<M>::SetNewValue(G4UIcommand* cmd, G4String newValue)
00228 {
00229   G4Colour myColour;
00230 
00231   if (cmd == fpStringCmd) {
00232     G4String colour;
00233     std::istringstream is (newValue);
00234     is >> colour;
00235     
00236     // Colour key should exist
00237     if (!G4Colour::GetColour(colour, myColour)) {
00238       G4ExceptionDescription ed;
00239       ed << "G4Colour with key "<<colour<<" does not exist ";
00240       G4Exception
00241         ("G4ModelCmdApplyColour<M>::SetNewValue",
00242          "modeling0107", JustWarning, ed);
00243       return;
00244     }
00245   }
00246 
00247   if (cmd == fpComponentCmd) {
00248     G4double red(0), green(0), blue(0), alpha(0);
00249     std::istringstream is (newValue);
00250     is >> red >> green >> blue >> alpha;
00251     
00252     G4Colour colour(red, green, blue, alpha);
00253     myColour = colour;
00254   }
00255 
00256   Apply(myColour);
00257   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00258   if (visManager) visManager->NotifyHandlers();
00259 }
00260 
00262 //ApplyBool command
00263 template <typename M>
00264 class G4ModelCmdApplyBool : public G4VModelCommand<M> {
00265 
00266 public: // With description
00267 
00268   G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName);
00269   virtual ~G4ModelCmdApplyBool();
00270 
00271   void SetNewValue(G4UIcommand* command, G4String newValue);
00272 
00273 protected:
00274 
00275   // Implement in derived class
00276   virtual void Apply(const G4bool&) = 0;
00277 
00278   G4UIcmdWithABool* Command() {return fpCmd;}
00279 
00280 private:
00281 
00282   G4UIcmdWithABool* fpCmd;
00283 
00284 };
00285 
00286 template <typename M>
00287 G4ModelCmdApplyBool<M>::G4ModelCmdApplyBool(M* model, const G4String& placement, const G4String& cmdName)
00288   :G4VModelCommand<M>(model, placement)
00289 {
00290   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00291   fpCmd = new G4UIcmdWithABool(dir, this);
00292 
00293   fpCmd->SetParameterName("Bool", false);
00294 }
00295  
00296 template <typename M>
00297 G4ModelCmdApplyBool<M>::~G4ModelCmdApplyBool()
00298 {  
00299   delete fpCmd;
00300 }
00301 
00302 template <typename M>
00303 void G4ModelCmdApplyBool<M>::SetNewValue(G4UIcommand*, G4String newValue)
00304 {
00305   Apply(fpCmd->GetNewBoolValue(newValue));
00306   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00307   if (visManager) visManager->NotifyHandlers();
00308 }
00309 
00311 //ApplyNull command
00312 template <typename M>
00313 class G4ModelCmdApplyNull : public G4VModelCommand<M> {
00314 
00315 public: // With description
00316 
00317   G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName);
00318 
00319   virtual ~G4ModelCmdApplyNull();
00320 
00321   void SetNewValue(G4UIcommand* command, G4String newValue);
00322 
00323 protected:
00324 
00325   // Implement in derived class
00326   virtual void Apply() = 0;
00327 
00328   G4UIcommand* Command() {return fpCmd;}
00329   
00330 private:
00331 
00332   G4UIcommand* fpCmd;
00333 
00334 };
00335 
00336 template <typename M>
00337 G4ModelCmdApplyNull<M>::G4ModelCmdApplyNull(M* model, const G4String& placement, const G4String& cmdName)
00338   :G4VModelCommand<M>(model, placement)
00339 {
00340   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00341   fpCmd = new G4UIcommand(dir, this);
00342 }
00343 
00344 template <typename M>
00345 G4ModelCmdApplyNull<M>::~G4ModelCmdApplyNull() 
00346 {
00347   delete fpCmd;
00348 }
00349 
00350 template <typename M>
00351 void G4ModelCmdApplyNull<M>::SetNewValue(G4UIcommand*, G4String)
00352 {
00353   Apply();
00354   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00355   if (visManager) visManager->NotifyHandlers();
00356 }
00357 
00359 //ApplyDouble command
00360 template <typename M>
00361 class G4ModelCmdApplyDouble : public G4VModelCommand<M> {
00362 
00363 public: // With description
00364 
00365   G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName);
00366 
00367   virtual ~G4ModelCmdApplyDouble();
00368 
00369   void SetNewValue(G4UIcommand* command, G4String newValue);
00370 
00371 protected:
00372 
00373   // Implement in derived class
00374   virtual void Apply(const G4double&) = 0;
00375 
00376   G4UIcmdWithADouble* Command() {return fpCmd;}
00377 
00378 private:
00379 
00380   G4UIcmdWithADouble* fpCmd;
00381 
00382 };
00383 
00384 template <typename M>
00385 G4ModelCmdApplyDouble<M>::G4ModelCmdApplyDouble(M* model, const G4String& placement, const G4String& cmdName)
00386   :G4VModelCommand<M>(model, placement)
00387 {
00388   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00389 
00390   fpCmd = new G4UIcmdWithADouble(dir, this);
00391   fpCmd->SetParameterName("Double", false);
00392 }
00393 
00394 template <typename M>
00395 G4ModelCmdApplyDouble<M>::~G4ModelCmdApplyDouble()
00396 {  
00397   delete fpCmd;
00398 }
00399 
00400 template <typename M>
00401 void G4ModelCmdApplyDouble<M>::SetNewValue(G4UIcommand*, G4String newValue)
00402 {
00403   Apply(fpCmd->GetNewDoubleValue(newValue));
00404   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00405   if (visManager) visManager->NotifyHandlers();
00406 }
00407 
00409 //ApplyDoubleAndUnit command
00410 template <typename M>
00411 class G4ModelCmdApplyDoubleAndUnit : public G4VModelCommand<M> {
00412 
00413 public: // With description
00414 
00415   G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName);
00416 
00417   virtual ~G4ModelCmdApplyDoubleAndUnit();
00418 
00419   void SetNewValue(G4UIcommand* command, G4String newValue);
00420 
00421 protected:
00422 
00423   // Implement in derived class
00424   virtual void Apply(const G4double&) = 0;
00425 
00426   G4UIcmdWithADoubleAndUnit* Command() {return fpCmd;}
00427 
00428 private:
00429 
00430   G4UIcmdWithADoubleAndUnit* fpCmd;
00431 
00432 };
00433 
00434 template <typename M>
00435 G4ModelCmdApplyDoubleAndUnit<M>::G4ModelCmdApplyDoubleAndUnit(M* model, const G4String& placement, const G4String& cmdName)
00436   :G4VModelCommand<M>(model, placement)
00437 {
00438   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00439 
00440   fpCmd = new G4UIcmdWithADoubleAndUnit(dir, this);
00441   fpCmd->SetParameterName("DoubleAndUnit", false);
00442 }
00443 
00444 template <typename M>
00445 G4ModelCmdApplyDoubleAndUnit<M>::~G4ModelCmdApplyDoubleAndUnit()
00446 {  
00447   delete fpCmd;
00448 }
00449 
00450 template <typename M>
00451 void G4ModelCmdApplyDoubleAndUnit<M>::SetNewValue(G4UIcommand*, G4String newValue)
00452 {
00453   Apply(fpCmd->GetNewDoubleValue(newValue));
00454   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00455   if (visManager) visManager->NotifyHandlers();
00456 }
00457 
00459 // ApplyInteger command
00460 template <typename M>
00461 class G4ModelCmdApplyInteger : public G4VModelCommand<M> {
00462 
00463 public: // With description
00464 
00465   G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName);
00466 
00467   virtual ~G4ModelCmdApplyInteger();
00468 
00469   void SetNewValue(G4UIcommand* command, G4String newValue);
00470 
00471 protected:
00472 
00473   // Implement in derived class
00474   virtual void Apply(const G4int&) = 0;
00475 
00476   G4UIcmdWithAnInteger* Command() {return fpCmd;}
00477 
00478 private:
00479 
00480   G4UIcmdWithAnInteger* fpCmd;
00481 };
00482 
00483 template <typename M>
00484 G4ModelCmdApplyInteger<M>::G4ModelCmdApplyInteger(M* model, const G4String& placement, const G4String& cmdName)
00485   :G4VModelCommand<M>(model, placement)
00486 {
00487   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00488 
00489   fpCmd = new G4UIcmdWithAnInteger(dir, this);
00490   fpCmd->SetParameterName("Integer", false);
00491 }
00492 
00493 template <typename M>
00494 G4ModelCmdApplyInteger<M>::~G4ModelCmdApplyInteger()
00495 {  
00496   delete fpCmd;
00497 }
00498 
00499 template <typename M>
00500 void G4ModelCmdApplyInteger<M>::SetNewValue(G4UIcommand*, G4String newValue)
00501 {
00502   Apply(fpCmd->GetNewIntValue(newValue));
00503   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00504   if (visManager) visManager->NotifyHandlers();
00505 }
00506 
00508 // ApplyString command
00509 template <typename M>
00510 class G4ModelCmdApplyString : public G4VModelCommand<M> {
00511 
00512 public: // With description
00513 
00514   G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName);
00515 
00516   virtual ~G4ModelCmdApplyString();
00517 
00518   void SetNewValue(G4UIcommand* command, G4String newValue);
00519 
00520 protected:
00521 
00522   // Implement in derived class
00523   virtual void Apply(const G4String&) = 0;
00524 
00525   G4UIcmdWithAString* Command() {return fpCmd;}
00526 
00527 private:
00528 
00529   G4UIcmdWithAString* fpCmd;
00530 
00531 };
00532 
00533 template <typename M>
00534 G4ModelCmdApplyString<M>::G4ModelCmdApplyString(M* model, const G4String& placement, const G4String& cmdName)
00535   :G4VModelCommand<M>(model, placement)
00536 {
00537   G4String dir = placement+"/"+model->Name()+"/"+cmdName;
00538 
00539   fpCmd = new G4UIcmdWithAString(dir, this);
00540 }
00541 
00542 template <typename M>
00543 G4ModelCmdApplyString<M>::~G4ModelCmdApplyString()
00544 {  
00545   delete fpCmd;
00546 }
00547 
00548 template <typename M>
00549 void G4ModelCmdApplyString<M>::SetNewValue(G4UIcommand*, G4String newValue)
00550 {
00551   Apply(newValue);
00552   G4VVisManager* visManager = G4VVisManager::GetConcreteInstance();
00553   if (visManager) visManager->NotifyHandlers();
00554 }
00555 
00556 #endif

Generated on Mon May 27 17:48:52 2013 for Geant4 by  doxygen 1.4.7