Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:22

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 //
0027 // Jane Tinslay, John Allison, Joseph Perl October 2005
0028 //
0029 // Class Description:
0030 // Templated create command for model factories. Factory generates new models
0031 // and associated messengers. 
0032 // Class Description - End:
0033 
0034 #ifndef G4VISCOMMANDSMODELCREATE_HH
0035 #define G4VISCOMMANDSMODELCREATE_HH
0036 
0037 #include "G4VVisCommand.hh"
0038 #include "G4String.hh"
0039 #include "G4UIcmdWithAString.hh"
0040 #include "G4UIcommand.hh"
0041 #include "G4UIdirectory.hh"
0042 #include <vector>
0043 
0044 template <typename Factory>
0045 class G4VisCommandModelCreate : public G4VVisCommand {
0046 
0047 public: // With description
0048 
0049   G4VisCommandModelCreate(Factory*, const G4String& placement);
0050   // Input factory and command placement
0051 
0052   virtual ~G4VisCommandModelCreate();
0053 
0054   G4String GetCurrentValue(G4UIcommand*);
0055   void SetNewValue (G4UIcommand* command, G4String newValue);
0056 
0057   G4String Placement() const;
0058 
0059 private:
0060 
0061   G4String NextName();
0062 
0063   // Data members
0064   Factory* fpFactory;
0065   G4String fPlacement;
0066   G4int fId;
0067   G4UIcmdWithAString* fpCommand;
0068   std::vector<G4UIcommand*>   fDirectoryList;
0069 
0070 };
0071 
0072 template <typename Factory>
0073 G4VisCommandModelCreate<Factory>::G4VisCommandModelCreate(Factory* factory, const G4String& placement)
0074   :fpFactory(factory)
0075   ,fPlacement(placement)
0076   ,fId(0)
0077 {  
0078   G4String factoryName = factory->Name();
0079 
0080   G4String command = Placement()+"/create/"+factoryName; 
0081   G4String guidance = "Create a "+factoryName+" model and associated messengers.";
0082 
0083   fpCommand = new G4UIcmdWithAString(command, this);      
0084   fpCommand->SetGuidance(guidance);
0085   fpCommand->SetGuidance("Generated model becomes current.");  
0086   fpCommand->SetParameterName("model-name", true);    
0087 }
0088 
0089 template <typename Factory>
0090 G4VisCommandModelCreate<Factory>::~G4VisCommandModelCreate()
0091 {
0092   delete fpCommand;
0093   
0094   unsigned i(0);
0095   for (i=0; i<fDirectoryList.size(); ++i) {
0096     delete fDirectoryList[i];
0097   }
0098 }
0099 
0100 template <typename Factory>
0101 G4String
0102 G4VisCommandModelCreate<Factory>::Placement() const
0103 {
0104   return fPlacement;
0105 }
0106 
0107 template <typename Factory>
0108 G4String
0109 G4VisCommandModelCreate<Factory>::NextName()
0110 {
0111   std::ostringstream oss;
0112   oss <<fpFactory->Name()<<"-" << fId++;
0113   return oss.str();
0114 }
0115 
0116 template <typename Factory>
0117 G4String 
0118 G4VisCommandModelCreate<Factory>::GetCurrentValue(G4UIcommand*) 
0119 {
0120   return "";
0121 }
0122 
0123 template <typename Factory>
0124 void G4VisCommandModelCreate<Factory>::SetNewValue(G4UIcommand*, G4String newName) 
0125 {
0126   if (newName.empty()) newName = NextName();
0127 
0128   assert (0 != fpFactory);
0129 
0130   // Create directory for new model commands
0131   G4String title = Placement()+"/"+newName+"/";
0132   G4String guidance = "Commands for "+newName+" model.";
0133 
0134   G4UIcommand* directory = new G4UIdirectory(title);
0135   directory->SetGuidance(guidance);
0136   fDirectoryList.push_back(directory);   
0137 
0138   // Create the model.
0139   typename Factory::ModelAndMessengers creation = fpFactory->Create(Placement(), newName);
0140 
0141   // Register model with vis manager
0142   fpVisManager->RegisterModel(creation.first);
0143 
0144   // Register associated messengers with vis manager
0145   typename Factory::Messengers::iterator iter = creation.second.begin();
0146 
0147   while (iter != creation.second.end()) {
0148     fpVisManager->RegisterMessenger(*iter);
0149     iter++;
0150   }
0151 }    
0152 
0153 #endif