G4VisCommandModelCreate.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 // Jane Tinslay, John Allison, Joseph Perl October 2005
00029 //
00030 // Class Description:
00031 // Templated create command for model factories. Factory generates new models
00032 // and associated messengers. 
00033 // Class Description - End:
00034 
00035 #ifndef G4VISCOMMANDSMODELCREATE_HH
00036 #define G4VISCOMMANDSMODELCREATE_HH
00037 
00038 #include "G4VVisCommand.hh"
00039 #include "G4String.hh"
00040 #include "G4UIcmdWithAString.hh"
00041 #include "G4UIcommand.hh"
00042 #include "G4UIdirectory.hh"
00043 #include <vector>
00044 
00045 template <typename Factory>
00046 class G4VisCommandModelCreate : public G4VVisCommand {
00047 
00048 public: // With description
00049 
00050   G4VisCommandModelCreate(Factory*, const G4String& placement);
00051   // Input factory and command placement
00052 
00053   virtual ~G4VisCommandModelCreate();
00054 
00055   G4String GetCurrentValue(G4UIcommand*);
00056   void SetNewValue (G4UIcommand* command, G4String newValue);
00057 
00058   G4String Placement() const;
00059 
00060 private:
00061 
00062   G4String NextName();
00063 
00064   // Data members
00065   Factory* fpFactory;
00066   G4String fPlacement;
00067   G4int fId;
00068   G4UIcmdWithAString* fpCommand;
00069   std::vector<G4UIcommand*>   fDirectoryList;
00070 
00071 };
00072 
00073 template <typename Factory>
00074 G4VisCommandModelCreate<Factory>::G4VisCommandModelCreate(Factory* factory, const G4String& placement)
00075   :fpFactory(factory)
00076   ,fPlacement(placement)
00077   ,fId(0)
00078 {  
00079   G4String factoryName = factory->Name();
00080 
00081   G4String command = Placement()+"/create/"+factoryName; 
00082   G4String guidance = "Create a "+factoryName+" model and associated messengers.";
00083 
00084   fpCommand = new G4UIcmdWithAString(command, this);      
00085   fpCommand->SetGuidance(guidance);
00086   fpCommand->SetGuidance("Generated model becomes current.");  
00087   fpCommand->SetParameterName("model-name", true);    
00088 }
00089 
00090 template <typename Factory>
00091 G4VisCommandModelCreate<Factory>::~G4VisCommandModelCreate()
00092 {
00093   delete fpCommand;
00094   
00095   unsigned i(0);
00096   for (i=0; i<fDirectoryList.size(); ++i) {
00097     delete fDirectoryList[i];
00098   }
00099 }
00100 
00101 template <typename Factory>
00102 G4String
00103 G4VisCommandModelCreate<Factory>::Placement() const
00104 {
00105   return fPlacement;
00106 }
00107 
00108 template <typename Factory>
00109 G4String
00110 G4VisCommandModelCreate<Factory>::NextName()
00111 {
00112   std::ostringstream oss;
00113   oss <<fpFactory->Name()<<"-" << fId++;
00114   return oss.str();
00115 }
00116 
00117 template <typename Factory>
00118 G4String 
00119 G4VisCommandModelCreate<Factory>::GetCurrentValue(G4UIcommand*) 
00120 {
00121   return "";
00122 }
00123 
00124 template <typename Factory>
00125 void G4VisCommandModelCreate<Factory>::SetNewValue(G4UIcommand*, G4String newName) 
00126 {
00127   if (newName.isNull()) newName = NextName();
00128 
00129   assert (0 != fpFactory);
00130 
00131   // Create directory for new model commands
00132   G4String title = Placement()+"/"+newName+"/";
00133   G4String guidance = "Commands for "+newName+" model.";
00134 
00135   G4UIcommand* directory = new G4UIdirectory(title);
00136   directory->SetGuidance(guidance);
00137   fDirectoryList.push_back(directory);   
00138 
00139   // Create the model.
00140   typename Factory::ModelAndMessengers creation = fpFactory->Create(Placement(), newName);
00141 
00142   // Register model with vis manager
00143   fpVisManager->RegisterModel(creation.first);
00144 
00145   // Register associated messengers with vis manager
00146   typename Factory::Messengers::iterator iter = creation.second.begin();
00147 
00148   while (iter != creation.second.end()) {
00149     fpVisManager->RegisterMessenger(*iter);
00150     iter++;
00151   }
00152 }    
00153 
00154 #endif

Generated on Mon May 27 17:50:14 2013 for Geant4 by  doxygen 1.4.7